From 47a69e593d2d816374d263076b87a9ffb987459a Mon Sep 17 00:00:00 2001 From: Andrea Diamantini Date: Mon, 17 Nov 2008 00:42:18 +0100 Subject: Ported search bar. 1st implementation. For Now, just Google Search. --- src/CMakeLists.txt | 5 +- src/browsermainwindow.cpp | 19 +++---- src/browsermainwindow.h | 6 +- src/searchbar.cpp | 62 +++++++++++++++++++++ src/searchbar.h | 52 +++++++++++++++++ src/toolbarsearch.cpp | 139 ---------------------------------------------- src/toolbarsearch.h | 63 --------------------- src/urlbar.cpp | 25 +++++++++ src/urlbar.h | 28 ++++++++++ src/urllineedit.cpp | 6 +- 10 files changed, 184 insertions(+), 221 deletions(-) create mode 100644 src/searchbar.cpp create mode 100644 src/searchbar.h delete mode 100644 src/toolbarsearch.cpp delete mode 100644 src/toolbarsearch.h create mode 100644 src/urlbar.cpp create mode 100644 src/urlbar.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f4ebb9b..edcfd561 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,11 +11,10 @@ SET( rekonq_SRCS networkaccessmanager.cpp searchlineedit.cpp findbar.cpp - findwidget.cpp + searchbar.cpp settings.cpp squeezelabel.cpp - tabwidget.cpp - toolbarsearch.cpp + tabwidget.cpp urllineedit.cpp webview.cpp main.cpp diff --git a/src/browsermainwindow.cpp b/src/browsermainwindow.cpp index 46510384..4ea1d444 100644 --- a/src/browsermainwindow.cpp +++ b/src/browsermainwindow.cpp @@ -27,7 +27,7 @@ #include "history.h" #include "settings.h" #include "tabwidget.h" -#include "toolbarsearch.h" +// #include "toolbarsearch.h" #include "webview.h" // UI Includes @@ -289,9 +289,6 @@ void BrowserMainWindow::setupMenu() viewMenu->addSeparator(); m_stop = (KAction *) viewMenu->addAction( KIcon( "process-stop" ), i18n("&Stop") ); -// QList shortcuts; -// shortcuts.append(QKeySequence(Qt::CTRL | Qt::Key_Period)); -// shortcuts.append(Qt::Key_Escape); m_stop->setShortcut( QKeySequence(Qt::CTRL | Qt::Key_Period) ); m_tabWidget->addWebAction(m_stop, QWebPage::Stop); @@ -397,10 +394,12 @@ void BrowserMainWindow::setupToolBar() m_navigationBar->addWidget(m_tabWidget->lineEditStack()); - m_toolbarSearch = new ToolbarSearch(m_navigationBar); - m_navigationBar->addWidget(m_toolbarSearch); - - connect(m_toolbarSearch, SIGNAL(search(const QUrl&)), SLOT(loadUrl(const QUrl&))); + m_searchBar = new SearchBar(m_navigationBar); + m_navigationBar->addWidget(m_searchBar); + connect(m_searchBar, SIGNAL(search(const QUrl&)), this, SLOT(loadUrl(const QUrl&))); +// m_toolbarSearch = new ToolbarSearch(m_navigationBar); +// m_navigationBar->addWidget(m_toolbarSearch); +// connect(m_toolbarSearch, SIGNAL(search(const QUrl&)), SLOT(loadUrl(const QUrl&))); } @@ -766,8 +765,8 @@ void BrowserMainWindow::slotHome() void BrowserMainWindow::slotWebSearch() { - m_toolbarSearch->lineEdit()->selectAll(); - m_toolbarSearch->lineEdit()->setFocus(); +// m_toolbarSearch->lineEdit()->selectAll(); +// m_toolbarSearch->lineEdit()->setFocus(); } diff --git a/src/browsermainwindow.h b/src/browsermainwindow.h index cc206626..c5db7bba 100644 --- a/src/browsermainwindow.h +++ b/src/browsermainwindow.h @@ -24,6 +24,7 @@ // Local Includes #include "findbar.h" +#include "searchbar.h" // KDE Includes #include @@ -40,7 +41,7 @@ class AutoSaver; class QWebFrame; class TabWidget; -class ToolbarSearch; +// class ToolbarSearch; class WebView; /*! @@ -126,7 +127,8 @@ private: private: KToolBar *m_navigationBar; - ToolbarSearch *m_toolbarSearch; +// ToolbarSearch *m_toolbarSearch; + SearchBar *m_searchBar; TabWidget *m_tabWidget; AutoSaver *m_autoSaver; diff --git a/src/searchbar.cpp b/src/searchbar.cpp new file mode 100644 index 00000000..deb8d631 --- /dev/null +++ b/src/searchbar.cpp @@ -0,0 +1,62 @@ +/* ============================================================ + * + * This file is a part of the reKonq project + * + * Copyright (C) 2008 by Andrea Diamantini + * + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * ============================================================ */ + +// Local Includes +#include "searchbar.h" +#include "searchbar.moc" + +// Qt Includes +#include + +SearchBar::SearchBar(QWidget *parent) : + QWidget(parent), + m_lineEdit(0) +{ + m_lineEdit = new KLineEdit(this); + m_lineEdit->setClearButtonShown( true ); + + QVBoxLayout *layout = new QVBoxLayout; + layout->addWidget(m_lineEdit); + setLayout(layout); + + connect( lineEdit() , SIGNAL( returnPressed() ) , this , SLOT( searchNow() ) ); +} + +SearchBar::~SearchBar() +{ +} + +void SearchBar::searchNow() +{ + QString searchText = m_lineEdit->text(); + + QUrl url(QLatin1String("http://www.google.com/search")); + url.addQueryItem(QLatin1String("q"), searchText); + url.addQueryItem(QLatin1String("ie"), QLatin1String("UTF-8")); + url.addQueryItem(QLatin1String("oe"), QLatin1String("UTF-8")); + url.addQueryItem(QLatin1String("client"), QLatin1String("reKonq")); + emit search(url); + +} + +KLineEdit *SearchBar::lineEdit() +{ + return m_lineEdit; +} + diff --git a/src/searchbar.h b/src/searchbar.h new file mode 100644 index 00000000..40235891 --- /dev/null +++ b/src/searchbar.h @@ -0,0 +1,52 @@ +/* ============================================================ + * + * This file is a part of the reKonq project + * + * Copyright (C) 2008 by Andrea Diamantini + * + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * ============================================================ */ + + +#ifndef SEARCHBAR_H +#define SEARCHBAR_H + +// KDE Includes +#include + +// Qt Includes +#include +#include + +class SearchBar : public QWidget +{ +Q_OBJECT + +public: + SearchBar(QWidget *parent = 0); + ~SearchBar(); + + KLineEdit *lineEdit(); + +public slots: + void searchNow(); + +private: + KLineEdit *m_lineEdit; + +signals: + void search(const QUrl &url); + +}; + +#endif diff --git a/src/toolbarsearch.cpp b/src/toolbarsearch.cpp deleted file mode 100644 index 4fd3aa51..00000000 --- a/src/toolbarsearch.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* ============================================================ - * - * This file is a part of the reKonq project - * - * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved - * Copyright (C) 2008 by Andrea Diamantini - * - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - * GNU General Public License for more details. - * - * ============================================================ */ - -// Local Includes -#include "toolbarsearch.h" -#include "autosaver.h" - -// Qt Includes -#include -#include -#include -#include -#include -#include - -/* - ToolbarSearch is a very basic search widget that also contains a small history. - Searches are turned into urls that use Google to perform search - */ -ToolbarSearch::ToolbarSearch(QWidget *parent) - : SearchLineEdit(parent) - , m_autosaver(new AutoSaver(this)) - , m_maxSavedSearches(10) - , m_stringListModel(new QStringListModel(this)) -{ - QMenu *m = menu(); - connect(m, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMenu())); - connect(m, SIGNAL(triggered(QAction*)), this, SLOT(triggeredMenuAction(QAction*))); - - QCompleter *completer = new QCompleter(m_stringListModel, this); - completer->setCompletionMode(QCompleter::InlineCompletion); - lineEdit()->setCompleter(completer); - - connect(lineEdit(), SIGNAL(returnPressed()), SLOT(searchNow())); - setInactiveText("Google"); - load(); -} - -ToolbarSearch::~ToolbarSearch() -{ - m_autosaver->saveIfNeccessary(); -} - -void ToolbarSearch::save() -{ - QSettings settings; - settings.beginGroup(QLatin1String("toolbarsearch")); - settings.setValue(QLatin1String("recentSearches"), m_stringListModel->stringList()); - settings.setValue(QLatin1String("maximumSaved"), m_maxSavedSearches); - settings.endGroup(); -} - -void ToolbarSearch::load() -{ - QSettings settings; - settings.beginGroup(QLatin1String("toolbarsearch")); - QStringList list = settings.value(QLatin1String("recentSearches")).toStringList(); - m_maxSavedSearches = settings.value(QLatin1String("maximumSaved"), m_maxSavedSearches).toInt(); - m_stringListModel->setStringList(list); - settings.endGroup(); -} - -void ToolbarSearch::searchNow() -{ - QString searchText = lineEdit()->text(); - QStringList newList = m_stringListModel->stringList(); - if (newList.contains(searchText)) - newList.removeAt(newList.indexOf(searchText)); - newList.prepend(searchText); - if (newList.size() >= m_maxSavedSearches) - newList.removeLast(); - - QWebSettings *globalSettings = QWebSettings::globalSettings(); - if (!globalSettings->testAttribute(QWebSettings::PrivateBrowsingEnabled)) { - m_stringListModel->setStringList(newList); - m_autosaver->changeOccurred(); - } - - QUrl url(QLatin1String("http://www.google.com/search")); - url.addQueryItem(QLatin1String("q"), searchText); - url.addQueryItem(QLatin1String("ie"), QLatin1String("UTF-8")); - url.addQueryItem(QLatin1String("oe"), QLatin1String("UTF-8")); - url.addQueryItem(QLatin1String("client"), QLatin1String("reKonq")); - emit search(url); -} - -void ToolbarSearch::aboutToShowMenu() -{ - lineEdit()->selectAll(); - QMenu *m = menu(); - m->clear(); - QStringList list = m_stringListModel->stringList(); - if (list.isEmpty()) { - m->addAction( tr("No Recent Searches") ); - return; - } - - QAction *recent = m->addAction( tr("Recent Searches") ); - recent->setEnabled(false); - for (int i = 0; i < list.count(); ++i) { - QString text = list.at(i); - m->addAction(text)->setData(text); - } - m->addSeparator(); - m->addAction( tr("Clear Recent Searches"), this, SLOT(clear())); -} - -void ToolbarSearch::triggeredMenuAction(QAction *action) -{ - QVariant v = action->data(); - if (v.canConvert()) { - QString text = v.toString(); - lineEdit()->setText(text); - searchNow(); - } -} - -void ToolbarSearch::clear() -{ - m_stringListModel->setStringList(QStringList()); - m_autosaver->changeOccurred();; -} diff --git a/src/toolbarsearch.h b/src/toolbarsearch.h deleted file mode 100644 index 81f06180..00000000 --- a/src/toolbarsearch.h +++ /dev/null @@ -1,63 +0,0 @@ -/* ============================================================ - * - * This file is a part of the reKonq project - * - * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved - * Copyright (C) 2008 by Andrea Diamantini - * - * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General - * Public License as published by the Free Software Foundation; - * either version 2, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the - * GNU General Public License for more details. - * - * ============================================================ */ - -#ifndef TOOLBARSEARCH_H -#define TOOLBARSEARCH_H - -#include "searchlineedit.h" - -QT_BEGIN_NAMESPACE -class QUrl; -class QAction; -class QStringListModel; -QT_END_NAMESPACE - -class AutoSaver; - -class ToolbarSearch : public SearchLineEdit -{ - Q_OBJECT - -signals: - void search(const QUrl &url); - -public: - ToolbarSearch(QWidget *parent = 0); - ~ToolbarSearch(); - -public slots: - void clear(); - void searchNow(); - -private slots: - void save(); - void aboutToShowMenu(); - void triggeredMenuAction(QAction *action); - -private: - void load(); - - AutoSaver *m_autosaver; - int m_maxSavedSearches; - QStringListModel *m_stringListModel; -}; - -#endif // TOOLBARSEARCH_H - diff --git a/src/urlbar.cpp b/src/urlbar.cpp new file mode 100644 index 00000000..62b28614 --- /dev/null +++ b/src/urlbar.cpp @@ -0,0 +1,25 @@ +/* ============================================================ + * + * This file is a part of the reKonq project + * + * Copyright (C) 2008 by Andrea Diamantini + * + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * ============================================================ */ + + + + + + + diff --git a/src/urlbar.h b/src/urlbar.h new file mode 100644 index 00000000..13c4c320 --- /dev/null +++ b/src/urlbar.h @@ -0,0 +1,28 @@ +/* ============================================================ + * + * This file is a part of the reKonq project + * + * Copyright (C) 2008 by Andrea Diamantini + * + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * ============================================================ */ + +#ifndef URLBAR_H +#define URLBAR_H + + + + + + +#endif diff --git a/src/urllineedit.cpp b/src/urllineedit.cpp index bd48bb03..88ce28c4 100644 --- a/src/urllineedit.cpp +++ b/src/urllineedit.cpp @@ -64,10 +64,8 @@ ExLineEdit::ExLineEdit(QWidget *parent) // clearButton m_clearButton = new ClearButton(this); - connect(m_clearButton, SIGNAL(clicked()), - m_lineEdit, SLOT(clear())); - connect(m_lineEdit, SIGNAL(textChanged(const QString&)), - m_clearButton, SLOT(textChanged(const QString&))); + connect(m_clearButton, SIGNAL(clicked()), m_lineEdit, SLOT(clear())); + connect(m_lineEdit, SIGNAL(textChanged(const QString&)), m_clearButton, SLOT(textChanged(const QString&))); } void ExLineEdit::setLeftWidget(QWidget *widget) -- cgit v1.2.1