From 04e8df6e480389925169853134f38d994888fe60 Mon Sep 17 00:00:00 2001 From: Franz Fellner Date: Thu, 27 Sep 2012 11:59:09 +0200 Subject: [PATCH] Add option to set a default search engine and use that for searching in address bar. --- src/lib/3rdparty/msvc2008.h | 160 ++++++++++---------- src/lib/navigation/locationbar.cpp | 6 +- src/lib/navigation/websearchbar.cpp | 4 +- src/lib/opensearch/searchenginesdialog.cpp | 94 ++++++++++-- src/lib/opensearch/searchenginesdialog.h | 3 + src/lib/opensearch/searchenginesdialog.ui | 9 +- src/lib/opensearch/searchenginesmanager.cpp | 28 +++- src/lib/opensearch/searchenginesmanager.h | 9 +- src/lib/other/qzsettings.cpp | 1 + src/lib/other/qzsettings.h | 1 + src/lib/other/sourceviewersearch.cpp | 3 +- src/lib/preferences/preferences.cpp | 8 + src/lib/preferences/preferences.ui | 10 ++ 13 files changed, 234 insertions(+), 102 deletions(-) diff --git a/src/lib/3rdparty/msvc2008.h b/src/lib/3rdparty/msvc2008.h index 062384832..209d8866e 100644 --- a/src/lib/3rdparty/msvc2008.h +++ b/src/lib/3rdparty/msvc2008.h @@ -38,66 +38,66 @@ typedef interface IObjectCollection IObjectCollection; #ifdef __cplusplus extern "C" { #endif -/* - **************************************************************************************************** - IObjectArray + /* + **************************************************************************************************** + IObjectArray - - **************************************************************************************************** -*/ + + **************************************************************************************************** + */ #ifndef __IObjectArray_INTERFACE_DEFINED__ #define __IObjectArray_INTERFACE_DEFINED__ -/* interface IObjectArray */ -/* [unique][object][uuid][helpstring] */ + /* interface IObjectArray */ + /* [unique][object][uuid][helpstring] */ -EXTERN_C const IID IID_IObjectArray; + EXTERN_C const IID IID_IObjectArray; -MIDL_INTERFACE("92CA9DCD-5622-4bba-A805-5E9F541BD8C9") + MIDL_INTERFACE("92CA9DCD-5622-4bba-A805-5E9F541BD8C9") IObjectArray : public IUnknown { -public: - virtual HRESULT STDMETHODCALLTYPE GetCount( - /* [out] */ __RPC__out UINT * pcObjects) = 0; + public: + virtual HRESULT STDMETHODCALLTYPE GetCount( + /* [out] */ __RPC__out UINT * pcObjects) = 0; - virtual HRESULT STDMETHODCALLTYPE GetAt( - /* [in] */ UINT uiIndex, - /* [in] */ __RPC__in REFIID riid, - /* [iid_is][out] */ __RPC__deref_out_opt void** ppv) = 0; + virtual HRESULT STDMETHODCALLTYPE GetAt( + /* [in] */ UINT uiIndex, + /* [in] */ __RPC__in REFIID riid, + /* [iid_is][out] */ __RPC__deref_out_opt void** ppv) = 0; -}; + }; #endif /* __IObjectArray_INTERFACE_DEFINED__ */ #ifndef __IObjectCollection_INTERFACE_DEFINED__ #define __IObjectCollection_INTERFACE_DEFINED__ -/* interface IObjectCollection */ -/* [unique][object][uuid] */ + /* interface IObjectCollection */ + /* [unique][object][uuid] */ -EXTERN_C const IID IID_IObjectCollection; + EXTERN_C const IID IID_IObjectCollection; -MIDL_INTERFACE("5632b1a4-e38a-400a-928a-d4cd63230295") + MIDL_INTERFACE("5632b1a4-e38a-400a-928a-d4cd63230295") IObjectCollection : public IObjectArray { -public: - virtual HRESULT STDMETHODCALLTYPE AddObject( - /* [in] */ __RPC__in_opt IUnknown * punk) = 0; + public: + virtual HRESULT STDMETHODCALLTYPE AddObject( + /* [in] */ __RPC__in_opt IUnknown * punk) = 0; - virtual HRESULT STDMETHODCALLTYPE AddFromArray( - /* [in] */ __RPC__in_opt IObjectArray * poaSource) = 0; + virtual HRESULT STDMETHODCALLTYPE AddFromArray( + /* [in] */ __RPC__in_opt IObjectArray * poaSource) = 0; - virtual HRESULT STDMETHODCALLTYPE RemoveObjectAt( - /* [in] */ UINT uiIndex) = 0; + virtual HRESULT STDMETHODCALLTYPE RemoveObjectAt( + /* [in] */ UINT uiIndex) = 0; - virtual HRESULT STDMETHODCALLTYPE Clear(void) = 0; + virtual HRESULT STDMETHODCALLTYPE Clear(void) = 0; -}; + }; #endif /* __IObjectCollection_INTERFACE_DEFINED__ */ -/* Additional Prototypes for ALL interfaces */ -/* end of Additional Prototypes */ + /* Additional Prototypes for ALL interfaces */ + /* end of Additional Prototypes */ #ifdef __cplusplus } @@ -189,13 +189,13 @@ class DECLSPEC_UUID("77f10cf0-3db5-4966-b520-b7c54fd35ed6") */ #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \ extern "C++" { \ - inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) | ((int)b)); } \ - inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) |= ((int)b)); } \ - inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) & ((int)b)); } \ - inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) &= ((int)b)); } \ - inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((int)a)); } \ - inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) ^ ((int)b)); } \ - inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) ^= ((int)b)); } \ + inline ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) | ((int)b)); } \ + inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) |= ((int)b)); } \ + inline ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) & ((int)b)); } \ + inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) &= ((int)b)); } \ + inline ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((int)a)); } \ + inline ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((int)a) ^ ((int)b)); } \ + inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((int &)a) ^= ((int)b)); } \ } #ifdef MIDL_PASS @@ -261,57 +261,57 @@ EXTERN_C const IID IID_ITaskbarList3; MIDL_INTERFACE("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf") ITaskbarList3 : public ITaskbarList2 { public: -virtual HRESULT STDMETHODCALLTYPE SetProgressValue( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ ULONGLONG ullCompleted, - /* [in] */ ULONGLONG ullTotal) = 0; + virtual HRESULT STDMETHODCALLTYPE SetProgressValue( + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ ULONGLONG ullCompleted, + /* [in] */ ULONGLONG ullTotal) = 0; -virtual HRESULT STDMETHODCALLTYPE SetProgressState( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ TBPFLAG tbpFlags) = 0; + virtual HRESULT STDMETHODCALLTYPE SetProgressState( + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ TBPFLAG tbpFlags) = 0; -virtual HRESULT STDMETHODCALLTYPE RegisterTab( - /* [in] */ __RPC__in HWND hwndTab, - /* [in] */ __RPC__in HWND hwndMDI) = 0; + virtual HRESULT STDMETHODCALLTYPE RegisterTab( + /* [in] */ __RPC__in HWND hwndTab, + /* [in] */ __RPC__in HWND hwndMDI) = 0; -virtual HRESULT STDMETHODCALLTYPE UnregisterTab( - /* [in] */ __RPC__in HWND hwndTab) = 0; + virtual HRESULT STDMETHODCALLTYPE UnregisterTab( + /* [in] */ __RPC__in HWND hwndTab) = 0; -virtual HRESULT STDMETHODCALLTYPE SetTabOrder( - /* [in] */ __RPC__in HWND hwndTab, - /* [in] */ __RPC__in HWND hwndInsertBefore) = 0; + virtual HRESULT STDMETHODCALLTYPE SetTabOrder( + /* [in] */ __RPC__in HWND hwndTab, + /* [in] */ __RPC__in HWND hwndInsertBefore) = 0; -virtual HRESULT STDMETHODCALLTYPE SetTabActive( - /* [in] */ __RPC__in HWND hwndTab, - /* [in] */ __RPC__in HWND hwndMDI, - /* [in] */ DWORD dwReserved) = 0; + virtual HRESULT STDMETHODCALLTYPE SetTabActive( + /* [in] */ __RPC__in HWND hwndTab, + /* [in] */ __RPC__in HWND hwndMDI, + /* [in] */ DWORD dwReserved) = 0; -virtual HRESULT STDMETHODCALLTYPE ThumbBarAddButtons( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ UINT cButtons, - /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; + virtual HRESULT STDMETHODCALLTYPE ThumbBarAddButtons( + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ UINT cButtons, + /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; -virtual HRESULT STDMETHODCALLTYPE ThumbBarUpdateButtons( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ UINT cButtons, - /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; + virtual HRESULT STDMETHODCALLTYPE ThumbBarUpdateButtons( + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ UINT cButtons, + /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; -virtual HRESULT STDMETHODCALLTYPE ThumbBarSetImageList( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ __RPC__in_opt HIMAGELIST himl) = 0; + virtual HRESULT STDMETHODCALLTYPE ThumbBarSetImageList( + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ __RPC__in_opt HIMAGELIST himl) = 0; -virtual HRESULT STDMETHODCALLTYPE SetOverlayIcon( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ __RPC__in HICON hIcon, - /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszDescription) = 0; + virtual HRESULT STDMETHODCALLTYPE SetOverlayIcon( + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ __RPC__in HICON hIcon, + /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszDescription) = 0; -virtual HRESULT STDMETHODCALLTYPE SetThumbnailTooltip( - /* [in] */ __RPC__in HWND hwnd, - /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszTip) = 0; + virtual HRESULT STDMETHODCALLTYPE SetThumbnailTooltip( + /* [in] */ __RPC__in HWND hwnd, + /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszTip) = 0; -virtual HRESULT STDMETHODCALLTYPE SetThumbnailClip( - /* [in] */ __RPC__in HWND hwnd, - /* [in] */ __RPC__in RECT * prcClip) = 0; + virtual HRESULT STDMETHODCALLTYPE SetThumbnailClip( + /* [in] */ __RPC__in HWND hwnd, + /* [in] */ __RPC__in RECT * prcClip) = 0; }; #endif //_MSC_VER >= 1500 && _MSC_VER < 1600 diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 54e35bac3..1832d5120 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -89,6 +89,7 @@ LocationBar::LocationBar(QupZilla* mainClass) connect(m_bookmarkIcon, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked())); connect(down, SIGNAL(clicked(QPoint)), this, SLOT(showMostVisited())); connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText())); + connect(mApp->searchEnginesManager(), SIGNAL(defaultEngineChanged()), this, SLOT(updatePlaceHolderText())); connect(mApp, SIGNAL(message(Qz::AppMessageType, bool)), SLOT(onMessage(Qz::AppMessageType, bool))); loadSettings(); @@ -114,7 +115,10 @@ void LocationBar::setText(const QString &text) void LocationBar::updatePlaceHolderText() { - setPlaceholderText(tr("Enter URL address or search on %1").arg(mApp->searchEnginesManager()->activeEngine().name)); + QString engineName = qzSettings->searchWithDefaultEngine ? + mApp->searchEnginesManager()->defaultEngine().name : + mApp->searchEnginesManager()->activeEngine().name; + setPlaceholderText(tr("Enter URL address or search on %1").arg(engineName)); } void LocationBar::showCompletion(const QString &newText) diff --git a/src/lib/navigation/websearchbar.cpp b/src/lib/navigation/websearchbar.cpp index a02ad65fe..c3459dae3 100644 --- a/src/lib/navigation/websearchbar.cpp +++ b/src/lib/navigation/websearchbar.cpp @@ -192,7 +192,7 @@ void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item) void WebSearchBar::instantSearchChanged(bool enable) { - + Settings settings; settings.beginGroup("SearchEngines"); settings.setValue("SearchOnEngineChange", enable); @@ -312,7 +312,7 @@ void WebSearchBar::contextMenuEvent(QContextMenuEvent* event) act->setChecked(qzSettings->showSearchSuggestions); connect(act, SIGNAL(triggered(bool)), this, SLOT(enableSearchSuggestions(bool))); - QAction *instantSearch = m_menu->addAction(tr("Search when engine changed")); + QAction* instantSearch = m_menu->addAction(tr("Search when engine changed")); instantSearch->setToolTip(tr("If checked an instant search is triggered when the search engine is changed")); instantSearch->setCheckable(true); instantSearch->setChecked(qzSettings->searchOnEngineChange); diff --git a/src/lib/opensearch/searchenginesdialog.cpp b/src/lib/opensearch/searchenginesdialog.cpp index 0c9c5b56c..6b2942da2 100644 --- a/src/lib/opensearch/searchenginesdialog.cpp +++ b/src/lib/opensearch/searchenginesdialog.cpp @@ -20,6 +20,41 @@ #include "editsearchengine.h" #include "searchenginesmanager.h" #include "mainapplication.h" +#include + +namespace +{ +const int EngineRole = Qt::UserRole; +const int DefaultRole = Qt::UserRole + 1; + +bool isDefault(QTreeWidgetItem* item) +{ + return item->data(0, DefaultRole).toBool(); +} + +SearchEngine getEngine(QTreeWidgetItem* item) +{ + return item->data(0, EngineRole).value(); +} + +void setEngine(QTreeWidgetItem* item, SearchEngine engine) +{ + QVariant v; + v.setValue(engine); + item->setData(0, EngineRole, v); +} + +void changeItemToDefault(QTreeWidgetItem* item, bool isDefault) +{ + QString txt = item->data(0, EngineRole).value().name; + if (isDefault) { + txt.append(QString(" (%1)").arg(QObject::tr("Default"))); + } + + item->setText(0, txt); + item->setData(0, DefaultRole, isDefault); +} +} SearchEnginesDialog::SearchEnginesDialog(QWidget* parent) : QDialog(parent) @@ -32,6 +67,7 @@ SearchEnginesDialog::SearchEnginesDialog(QWidget* parent) connect(ui->add, SIGNAL(clicked()), this, SLOT(addEngine())); connect(ui->remove, SIGNAL(clicked()), this, SLOT(removeEngine())); connect(ui->edit, SIGNAL(clicked()), this, SLOT(editEngine())); + connect(ui->setAsDefault, SIGNAL(clicked()), this, SLOT(setDefaultEngine())); connect(ui->defaults, SIGNAL(clicked()), this, SLOT(defaults())); connect(ui->moveUp, SIGNAL(clicked()), this, SLOT(moveUp())); connect(ui->moveDown, SIGNAL(clicked()), this, SLOT(moveDown())); @@ -62,11 +98,9 @@ void SearchEnginesDialog::addEngine() } QTreeWidgetItem* item = new QTreeWidgetItem(); - QVariant v; - v.setValue(engine); - item->setData(0, Qt::UserRole, v); + setEngine(item, engine); - item->setText(0, engine.name); + changeItemToDefault(item, false); item->setIcon(0, engine.icon); item->setText(1, engine.shortcut); @@ -80,7 +114,15 @@ void SearchEnginesDialog::removeEngine() return; } - delete item; + if (isDefault(item)) { + SearchEngine en = getEngine(item); + QMessageBox::warning(this, tr("Remove Engine"), + tr("You can't remove the default search engine.
" + "Set a different engine as Default before removing %1.").arg(en.name)); + } + else { + delete item; + } } void SearchEnginesDialog::editEngine() @@ -90,7 +132,7 @@ void SearchEnginesDialog::editEngine() return; } - SearchEngine engine = item->data(0, Qt::UserRole).value(); + SearchEngine engine = getEngine(item); EditSearchEngine dialog(tr("Edit Search Engine"), this); @@ -112,15 +154,34 @@ void SearchEnginesDialog::editEngine() return; } - QVariant v; - v.setValue(engine); - item->setData(0, Qt::UserRole, v); + setEngine(item, engine); - item->setText(0, engine.name); + changeItemToDefault(item, isDefault(item)); item->setIcon(0, engine.icon); item->setText(1, engine.shortcut); } +void SearchEnginesDialog::setDefaultEngine() +{ + QTreeWidgetItem* item = ui->treeWidget->currentItem(); + if (!item) { + return; + } + + for (int j = 0; j < ui->treeWidget->topLevelItemCount(); ++j) { + QTreeWidgetItem* i = ui->treeWidget->topLevelItem(j); + if (isDefault(i)) { + if (i == item) { + return; + } + changeItemToDefault(i, false); + break; + } + } + + changeItemToDefault(item, true); +} + void SearchEnginesDialog::defaults() { m_manager->restoreDefaults(); @@ -158,15 +219,14 @@ void SearchEnginesDialog::moveDown() void SearchEnginesDialog::reloadEngines() { ui->treeWidget->clear(); + const QString defaultEngineName = mApp->searchEnginesManager()->defaultEngine().name; foreach(const SearchEngine & en, m_manager->allEngines()) { QTreeWidgetItem* item = new QTreeWidgetItem(); + setEngine(item, en); + changeItemToDefault(item, en.name == defaultEngineName); item->setIcon(0, en.icon); - item->setText(0, en.name); item->setText(1, en.shortcut); - QVariant v; - v.setValue(en); - item->setData(0, Qt::UserRole, v); ui->treeWidget->addTopLevelItem(item); } @@ -186,8 +246,12 @@ void SearchEnginesDialog::accept() continue; } - SearchEngine engine = item->data(0, Qt::UserRole).value(); + SearchEngine engine = getEngine(item); allEngines.append(engine); + + if (isDefault(item)) { + m_manager->setDefaultEngine(engine); + } } m_manager->setAllEngines(allEngines); diff --git a/src/lib/opensearch/searchenginesdialog.h b/src/lib/opensearch/searchenginesdialog.h index 2c643dd3e..14203bdff 100644 --- a/src/lib/opensearch/searchenginesdialog.h +++ b/src/lib/opensearch/searchenginesdialog.h @@ -22,6 +22,8 @@ #include +class QTreeWidgetItem; + namespace Ui { class SearchEnginesDialog; @@ -43,6 +45,7 @@ private slots: void addEngine(); void removeEngine(); void editEngine(); + void setDefaultEngine(); void moveUp(); void moveDown(); diff --git a/src/lib/opensearch/searchenginesdialog.ui b/src/lib/opensearch/searchenginesdialog.ui index f672f65ce..32a2a5d85 100644 --- a/src/lib/opensearch/searchenginesdialog.ui +++ b/src/lib/opensearch/searchenginesdialog.ui @@ -6,7 +6,7 @@ 0 0 - 460 + 465 299 @@ -37,6 +37,13 @@ + + + + Set as Default + + + diff --git a/src/lib/opensearch/searchenginesmanager.cpp b/src/lib/opensearch/searchenginesmanager.cpp index 99a6cb972..049c2aca7 100644 --- a/src/lib/opensearch/searchenginesmanager.cpp +++ b/src/lib/opensearch/searchenginesmanager.cpp @@ -25,6 +25,7 @@ #include "opensearchengine.h" #include "databasewriter.h" #include "settings.h" +#include "qzsettings.h" #include "webview.h" #include @@ -51,6 +52,7 @@ SearchEnginesManager::SearchEnginesManager() Settings settings; settings.beginGroup("SearchEngines"); m_startingEngineName = settings.value("activeEngine", "Google").toString(); + m_defaultEngineName = settings.value("DefaultEngine", "Google").toString(); settings.endGroup(); connect(this, SIGNAL(enginesChanged()), this, SLOT(scheduleSave())); @@ -71,11 +73,19 @@ void SearchEnginesManager::loadSettings() en.suggestionsUrl = query.value(4).toString(); m_allEngines.append(en); + + if (en.name == m_defaultEngineName) { + m_defaultEngine = en; + } } if (m_allEngines.isEmpty()) { restoreDefaults(); } + + if (m_defaultEngine.name.isEmpty()) { + m_defaultEngine = m_allEngines[0]; + } } SearchEngine SearchEnginesManager::engineForShortcut(const QString &shortcut) @@ -106,7 +116,8 @@ QUrl SearchEnginesManager::searchUrl(const Engine &engine, const QString &string QUrl SearchEnginesManager::searchUrl(const QString &string) { - return searchUrl(m_activeEngine, string); + const Engine &en = qzSettings->searchWithDefaultEngine ? m_defaultEngine : m_activeEngine; + return searchUrl(en, string); } void SearchEnginesManager::restoreDefaults() @@ -143,6 +154,8 @@ void SearchEnginesManager::restoreDefaults() addEngine(yt); addEngine(duck); + m_defaultEngine = google; + emit enginesChanged(); } @@ -344,6 +357,18 @@ void SearchEnginesManager::setActiveEngine(const Engine &engine) emit activeEngineChanged(); } +void SearchEnginesManager::setDefaultEngine(const SearchEnginesManager::Engine &engine) +{ + ENSURE_LOADED; + + if (!m_allEngines.contains(engine)) { + return; + } + + m_defaultEngine = engine; + emit defaultEngineChanged(); +} + void SearchEnginesManager::removeEngine(const Engine &engine) { ENSURE_LOADED; @@ -382,6 +407,7 @@ void SearchEnginesManager::saveSettings() Settings settings; settings.beginGroup("SearchEngines"); settings.setValue("activeEngine", m_activeEngine.name); + settings.setValue("DefaultEngine", m_defaultEngine.name); settings.endGroup(); if (!m_saveScheduled) { diff --git a/src/lib/opensearch/searchenginesmanager.h b/src/lib/opensearch/searchenginesmanager.h index 05b91f53e..09a891429 100644 --- a/src/lib/opensearch/searchenginesmanager.h +++ b/src/lib/opensearch/searchenginesmanager.h @@ -66,7 +66,11 @@ public: void removeEngine(const Engine &engine); void setActiveEngine(const Engine &engine); - Engine activeEngine() { return m_activeEngine; } + Engine activeEngine() const { return m_activeEngine; } + + void setDefaultEngine(const Engine &engine); + Engine defaultEngine() const { return m_defaultEngine; } + void editEngine(const Engine &before, const Engine &after); Engine engineForShortcut(const QString &shortcut); @@ -84,6 +88,7 @@ public: signals: void enginesChanged(); void activeEngineChanged(); + void defaultEngineChanged(); public slots: @@ -102,8 +107,10 @@ private: bool m_saveScheduled; QString m_startingEngineName; + QString m_defaultEngineName; QList m_allEngines; Engine m_activeEngine; + Engine m_defaultEngine; }; diff --git a/src/lib/other/qzsettings.cpp b/src/lib/other/qzsettings.cpp index 43e2eb1e6..d0aae3d10 100644 --- a/src/lib/other/qzsettings.cpp +++ b/src/lib/other/qzsettings.cpp @@ -37,6 +37,7 @@ void QzSettings::loadSettings() settings.beginGroup("SearchEngines"); showSearchSuggestions = settings.value("showSuggestions", true).toBool(); searchOnEngineChange = settings.value("SearchOnEngineChange", true).toBool(); + searchWithDefaultEngine = settings.value("SearchWithDefaultEngine", false).toBool(); settings.endGroup(); settings.beginGroup("Web-Browser-Settings"); diff --git a/src/lib/other/qzsettings.h b/src/lib/other/qzsettings.h index b5e52009e..f341e6ba2 100644 --- a/src/lib/other/qzsettings.h +++ b/src/lib/other/qzsettings.h @@ -41,6 +41,7 @@ public: // SearchEngines bool showSearchSuggestions; bool searchOnEngineChange; + bool searchWithDefaultEngine; // Web-Browser-Settings int defaultZoom; diff --git a/src/lib/other/sourceviewersearch.cpp b/src/lib/other/sourceviewersearch.cpp index bc2d8f8e8..066c4a0d1 100644 --- a/src/lib/other/sourceviewersearch.cpp +++ b/src/lib/other/sourceviewersearch.cpp @@ -77,7 +77,8 @@ void SourceViewerSearch::searchWholeWords() { if (ui->wholeWords->isChecked()) { m_findFlags |= QTextDocument::FindWholeWords; - } else { + } + else { m_findFlags &= (~QTextDocument::FindWholeWords); } } diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 7df6ec089..c77c4d977 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -210,6 +210,10 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) connect(ui->setProgressBarColorToHighlightButton, SIGNAL(clicked()), SLOT(setProgressBarColorIcon())); settings.endGroup(); + settings.beginGroup("SearchEngines"); + ui->searchWithDefaultEngine->setChecked(settings.value("SearchWithDefaultEngine", false).toBool()); + settings.endGroup(); + //BROWSING settings.beginGroup("Web-Browser-Settings"); ui->allowPlugins->setChecked(settings.value("allowFlash", true).toBool()); @@ -897,6 +901,10 @@ void Preferences::saveSettings() settings.setValue("CustomProgressColor", ui->customColorToolButton->property("ProgressColor").value()); settings.endGroup(); + settings.beginGroup("SearchEngines"); + settings.setValue("SearchWithDefaultEngine", ui->searchWithDefaultEngine->isChecked()); + settings.endGroup(); + //Languages settings.beginGroup("Language"); settings.setValue("language", ui->languages->itemData(ui->languages->currentIndex()).toString()); diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index e7c2daa55..21da75d0f 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -888,6 +888,16 @@ + + + + <html><head/><body><p>If enabled the default engine will be taken for searching without search shortcut in the address bar instead of the engine currently selected in the web search bar.</p></body></html> + + + Search with Default Engine + + +