1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 18:56:34 +01:00

Add option to set a default search engine and use that for searching in address bar.

This commit is contained in:
Franz Fellner 2012-09-27 11:59:09 +02:00
parent 40f97c73ab
commit 04e8df6e48
13 changed files with 234 additions and 102 deletions

View File

@ -38,66 +38,66 @@ typedef interface IObjectCollection IObjectCollection;
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* /*
**************************************************************************************************** ****************************************************************************************************
IObjectArray IObjectArray
<from ObjectArray.h> <from ObjectArray.h>
**************************************************************************************************** ****************************************************************************************************
*/ */
#ifndef __IObjectArray_INTERFACE_DEFINED__ #ifndef __IObjectArray_INTERFACE_DEFINED__
#define __IObjectArray_INTERFACE_DEFINED__ #define __IObjectArray_INTERFACE_DEFINED__
/* interface IObjectArray */ /* interface IObjectArray */
/* [unique][object][uuid][helpstring] */ /* [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 { IObjectArray : public IUnknown {
public: public:
virtual HRESULT STDMETHODCALLTYPE GetCount( virtual HRESULT STDMETHODCALLTYPE GetCount(
/* [out] */ __RPC__out UINT * pcObjects) = 0; /* [out] */ __RPC__out UINT * pcObjects) = 0;
virtual HRESULT STDMETHODCALLTYPE GetAt( virtual HRESULT STDMETHODCALLTYPE GetAt(
/* [in] */ UINT uiIndex, /* [in] */ UINT uiIndex,
/* [in] */ __RPC__in REFIID riid, /* [in] */ __RPC__in REFIID riid,
/* [iid_is][out] */ __RPC__deref_out_opt void** ppv) = 0; /* [iid_is][out] */ __RPC__deref_out_opt void** ppv) = 0;
}; };
#endif /* __IObjectArray_INTERFACE_DEFINED__ */ #endif /* __IObjectArray_INTERFACE_DEFINED__ */
#ifndef __IObjectCollection_INTERFACE_DEFINED__ #ifndef __IObjectCollection_INTERFACE_DEFINED__
#define __IObjectCollection_INTERFACE_DEFINED__ #define __IObjectCollection_INTERFACE_DEFINED__
/* interface IObjectCollection */ /* interface IObjectCollection */
/* [unique][object][uuid] */ /* [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 { IObjectCollection : public IObjectArray {
public: public:
virtual HRESULT STDMETHODCALLTYPE AddObject( virtual HRESULT STDMETHODCALLTYPE AddObject(
/* [in] */ __RPC__in_opt IUnknown * punk) = 0; /* [in] */ __RPC__in_opt IUnknown * punk) = 0;
virtual HRESULT STDMETHODCALLTYPE AddFromArray( virtual HRESULT STDMETHODCALLTYPE AddFromArray(
/* [in] */ __RPC__in_opt IObjectArray * poaSource) = 0; /* [in] */ __RPC__in_opt IObjectArray * poaSource) = 0;
virtual HRESULT STDMETHODCALLTYPE RemoveObjectAt( virtual HRESULT STDMETHODCALLTYPE RemoveObjectAt(
/* [in] */ UINT uiIndex) = 0; /* [in] */ UINT uiIndex) = 0;
virtual HRESULT STDMETHODCALLTYPE Clear(void) = 0; virtual HRESULT STDMETHODCALLTYPE Clear(void) = 0;
}; };
#endif /* __IObjectCollection_INTERFACE_DEFINED__ */ #endif /* __IObjectCollection_INTERFACE_DEFINED__ */
/* Additional Prototypes for ALL interfaces */ /* Additional Prototypes for ALL interfaces */
/* end of Additional Prototypes */ /* end of Additional Prototypes */
#ifdef __cplusplus #ifdef __cplusplus
} }
@ -189,13 +189,13 @@ class DECLSPEC_UUID("77f10cf0-3db5-4966-b520-b7c54fd35ed6")
*/ */
#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \ #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
extern "C++" { \ 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, 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) { 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)); } \
} }
#ifdef MIDL_PASS #ifdef MIDL_PASS
@ -261,57 +261,57 @@ EXTERN_C const IID IID_ITaskbarList3;
MIDL_INTERFACE("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf") MIDL_INTERFACE("ea1afb91-9e28-4b86-90e9-9e9f8a5eefaf")
ITaskbarList3 : public ITaskbarList2 { ITaskbarList3 : public ITaskbarList2 {
public: public:
virtual HRESULT STDMETHODCALLTYPE SetProgressValue( virtual HRESULT STDMETHODCALLTYPE SetProgressValue(
/* [in] */ __RPC__in HWND hwnd, /* [in] */ __RPC__in HWND hwnd,
/* [in] */ ULONGLONG ullCompleted, /* [in] */ ULONGLONG ullCompleted,
/* [in] */ ULONGLONG ullTotal) = 0; /* [in] */ ULONGLONG ullTotal) = 0;
virtual HRESULT STDMETHODCALLTYPE SetProgressState( virtual HRESULT STDMETHODCALLTYPE SetProgressState(
/* [in] */ __RPC__in HWND hwnd, /* [in] */ __RPC__in HWND hwnd,
/* [in] */ TBPFLAG tbpFlags) = 0; /* [in] */ TBPFLAG tbpFlags) = 0;
virtual HRESULT STDMETHODCALLTYPE RegisterTab( virtual HRESULT STDMETHODCALLTYPE RegisterTab(
/* [in] */ __RPC__in HWND hwndTab, /* [in] */ __RPC__in HWND hwndTab,
/* [in] */ __RPC__in HWND hwndMDI) = 0; /* [in] */ __RPC__in HWND hwndMDI) = 0;
virtual HRESULT STDMETHODCALLTYPE UnregisterTab( virtual HRESULT STDMETHODCALLTYPE UnregisterTab(
/* [in] */ __RPC__in HWND hwndTab) = 0; /* [in] */ __RPC__in HWND hwndTab) = 0;
virtual HRESULT STDMETHODCALLTYPE SetTabOrder( virtual HRESULT STDMETHODCALLTYPE SetTabOrder(
/* [in] */ __RPC__in HWND hwndTab, /* [in] */ __RPC__in HWND hwndTab,
/* [in] */ __RPC__in HWND hwndInsertBefore) = 0; /* [in] */ __RPC__in HWND hwndInsertBefore) = 0;
virtual HRESULT STDMETHODCALLTYPE SetTabActive( virtual HRESULT STDMETHODCALLTYPE SetTabActive(
/* [in] */ __RPC__in HWND hwndTab, /* [in] */ __RPC__in HWND hwndTab,
/* [in] */ __RPC__in HWND hwndMDI, /* [in] */ __RPC__in HWND hwndMDI,
/* [in] */ DWORD dwReserved) = 0; /* [in] */ DWORD dwReserved) = 0;
virtual HRESULT STDMETHODCALLTYPE ThumbBarAddButtons( virtual HRESULT STDMETHODCALLTYPE ThumbBarAddButtons(
/* [in] */ __RPC__in HWND hwnd, /* [in] */ __RPC__in HWND hwnd,
/* [in] */ UINT cButtons, /* [in] */ UINT cButtons,
/* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0;
virtual HRESULT STDMETHODCALLTYPE ThumbBarUpdateButtons( virtual HRESULT STDMETHODCALLTYPE ThumbBarUpdateButtons(
/* [in] */ __RPC__in HWND hwnd, /* [in] */ __RPC__in HWND hwnd,
/* [in] */ UINT cButtons, /* [in] */ UINT cButtons,
/* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0; /* [size_is][in] */ __RPC__in_ecount_full(cButtons) LPTHUMBBUTTON pButton) = 0;
virtual HRESULT STDMETHODCALLTYPE ThumbBarSetImageList( virtual HRESULT STDMETHODCALLTYPE ThumbBarSetImageList(
/* [in] */ __RPC__in HWND hwnd, /* [in] */ __RPC__in HWND hwnd,
/* [in] */ __RPC__in_opt HIMAGELIST himl) = 0; /* [in] */ __RPC__in_opt HIMAGELIST himl) = 0;
virtual HRESULT STDMETHODCALLTYPE SetOverlayIcon( virtual HRESULT STDMETHODCALLTYPE SetOverlayIcon(
/* [in] */ __RPC__in HWND hwnd, /* [in] */ __RPC__in HWND hwnd,
/* [in] */ __RPC__in HICON hIcon, /* [in] */ __RPC__in HICON hIcon,
/* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszDescription) = 0; /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszDescription) = 0;
virtual HRESULT STDMETHODCALLTYPE SetThumbnailTooltip( virtual HRESULT STDMETHODCALLTYPE SetThumbnailTooltip(
/* [in] */ __RPC__in HWND hwnd, /* [in] */ __RPC__in HWND hwnd,
/* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszTip) = 0; /* [string][unique][in] */ __RPC__in_opt_string LPCWSTR pszTip) = 0;
virtual HRESULT STDMETHODCALLTYPE SetThumbnailClip( virtual HRESULT STDMETHODCALLTYPE SetThumbnailClip(
/* [in] */ __RPC__in HWND hwnd, /* [in] */ __RPC__in HWND hwnd,
/* [in] */ __RPC__in RECT * prcClip) = 0; /* [in] */ __RPC__in RECT * prcClip) = 0;
}; };
#endif //_MSC_VER >= 1500 && _MSC_VER < 1600 #endif //_MSC_VER >= 1500 && _MSC_VER < 1600

View File

@ -89,6 +89,7 @@ LocationBar::LocationBar(QupZilla* mainClass)
connect(m_bookmarkIcon, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked())); connect(m_bookmarkIcon, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked()));
connect(down, SIGNAL(clicked(QPoint)), this, SLOT(showMostVisited())); connect(down, SIGNAL(clicked(QPoint)), this, SLOT(showMostVisited()));
connect(mApp->searchEnginesManager(), SIGNAL(activeEngineChanged()), this, SLOT(updatePlaceHolderText())); 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))); connect(mApp, SIGNAL(message(Qz::AppMessageType, bool)), SLOT(onMessage(Qz::AppMessageType, bool)));
loadSettings(); loadSettings();
@ -114,7 +115,10 @@ void LocationBar::setText(const QString &text)
void LocationBar::updatePlaceHolderText() 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) void LocationBar::showCompletion(const QString &newText)

View File

@ -192,7 +192,7 @@ void WebSearchBar::searchChanged(const ButtonWithMenu::Item &item)
void WebSearchBar::instantSearchChanged(bool enable) void WebSearchBar::instantSearchChanged(bool enable)
{ {
Settings settings; Settings settings;
settings.beginGroup("SearchEngines"); settings.beginGroup("SearchEngines");
settings.setValue("SearchOnEngineChange", enable); settings.setValue("SearchOnEngineChange", enable);
@ -312,7 +312,7 @@ void WebSearchBar::contextMenuEvent(QContextMenuEvent* event)
act->setChecked(qzSettings->showSearchSuggestions); act->setChecked(qzSettings->showSearchSuggestions);
connect(act, SIGNAL(triggered(bool)), this, SLOT(enableSearchSuggestions(bool))); 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->setToolTip(tr("If checked an instant search is triggered when the search engine is changed"));
instantSearch->setCheckable(true); instantSearch->setCheckable(true);
instantSearch->setChecked(qzSettings->searchOnEngineChange); instantSearch->setChecked(qzSettings->searchOnEngineChange);

View File

@ -20,6 +20,41 @@
#include "editsearchengine.h" #include "editsearchengine.h"
#include "searchenginesmanager.h" #include "searchenginesmanager.h"
#include "mainapplication.h" #include "mainapplication.h"
#include <QMessageBox>
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<SearchEngine>();
}
void setEngine(QTreeWidgetItem* item, SearchEngine engine)
{
QVariant v;
v.setValue<SearchEngine>(engine);
item->setData(0, EngineRole, v);
}
void changeItemToDefault(QTreeWidgetItem* item, bool isDefault)
{
QString txt = item->data(0, EngineRole).value<SearchEngine>().name;
if (isDefault) {
txt.append(QString(" (%1)").arg(QObject::tr("Default")));
}
item->setText(0, txt);
item->setData(0, DefaultRole, isDefault);
}
}
SearchEnginesDialog::SearchEnginesDialog(QWidget* parent) SearchEnginesDialog::SearchEnginesDialog(QWidget* parent)
: QDialog(parent) : QDialog(parent)
@ -32,6 +67,7 @@ SearchEnginesDialog::SearchEnginesDialog(QWidget* parent)
connect(ui->add, SIGNAL(clicked()), this, SLOT(addEngine())); connect(ui->add, SIGNAL(clicked()), this, SLOT(addEngine()));
connect(ui->remove, SIGNAL(clicked()), this, SLOT(removeEngine())); connect(ui->remove, SIGNAL(clicked()), this, SLOT(removeEngine()));
connect(ui->edit, SIGNAL(clicked()), this, SLOT(editEngine())); 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->defaults, SIGNAL(clicked()), this, SLOT(defaults()));
connect(ui->moveUp, SIGNAL(clicked()), this, SLOT(moveUp())); connect(ui->moveUp, SIGNAL(clicked()), this, SLOT(moveUp()));
connect(ui->moveDown, SIGNAL(clicked()), this, SLOT(moveDown())); connect(ui->moveDown, SIGNAL(clicked()), this, SLOT(moveDown()));
@ -62,11 +98,9 @@ void SearchEnginesDialog::addEngine()
} }
QTreeWidgetItem* item = new QTreeWidgetItem(); QTreeWidgetItem* item = new QTreeWidgetItem();
QVariant v; setEngine(item, engine);
v.setValue<SearchEngine>(engine);
item->setData(0, Qt::UserRole, v);
item->setText(0, engine.name); changeItemToDefault(item, false);
item->setIcon(0, engine.icon); item->setIcon(0, engine.icon);
item->setText(1, engine.shortcut); item->setText(1, engine.shortcut);
@ -80,7 +114,15 @@ void SearchEnginesDialog::removeEngine()
return; 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.<br>"
"Set a different engine as Default before removing %1.").arg(en.name));
}
else {
delete item;
}
} }
void SearchEnginesDialog::editEngine() void SearchEnginesDialog::editEngine()
@ -90,7 +132,7 @@ void SearchEnginesDialog::editEngine()
return; return;
} }
SearchEngine engine = item->data(0, Qt::UserRole).value<SearchEngine>(); SearchEngine engine = getEngine(item);
EditSearchEngine dialog(tr("Edit Search Engine"), this); EditSearchEngine dialog(tr("Edit Search Engine"), this);
@ -112,15 +154,34 @@ void SearchEnginesDialog::editEngine()
return; return;
} }
QVariant v; setEngine(item, engine);
v.setValue<SearchEngine>(engine);
item->setData(0, Qt::UserRole, v);
item->setText(0, engine.name); changeItemToDefault(item, isDefault(item));
item->setIcon(0, engine.icon); item->setIcon(0, engine.icon);
item->setText(1, engine.shortcut); 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() void SearchEnginesDialog::defaults()
{ {
m_manager->restoreDefaults(); m_manager->restoreDefaults();
@ -158,15 +219,14 @@ void SearchEnginesDialog::moveDown()
void SearchEnginesDialog::reloadEngines() void SearchEnginesDialog::reloadEngines()
{ {
ui->treeWidget->clear(); ui->treeWidget->clear();
const QString defaultEngineName = mApp->searchEnginesManager()->defaultEngine().name;
foreach(const SearchEngine & en, m_manager->allEngines()) { foreach(const SearchEngine & en, m_manager->allEngines()) {
QTreeWidgetItem* item = new QTreeWidgetItem(); QTreeWidgetItem* item = new QTreeWidgetItem();
setEngine(item, en);
changeItemToDefault(item, en.name == defaultEngineName);
item->setIcon(0, en.icon); item->setIcon(0, en.icon);
item->setText(0, en.name);
item->setText(1, en.shortcut); item->setText(1, en.shortcut);
QVariant v;
v.setValue<SearchEngine>(en);
item->setData(0, Qt::UserRole, v);
ui->treeWidget->addTopLevelItem(item); ui->treeWidget->addTopLevelItem(item);
} }
@ -186,8 +246,12 @@ void SearchEnginesDialog::accept()
continue; continue;
} }
SearchEngine engine = item->data(0, Qt::UserRole).value<SearchEngine>(); SearchEngine engine = getEngine(item);
allEngines.append(engine); allEngines.append(engine);
if (isDefault(item)) {
m_manager->setDefaultEngine(engine);
}
} }
m_manager->setAllEngines(allEngines); m_manager->setAllEngines(allEngines);

View File

@ -22,6 +22,8 @@
#include <QDialog> #include <QDialog>
class QTreeWidgetItem;
namespace Ui namespace Ui
{ {
class SearchEnginesDialog; class SearchEnginesDialog;
@ -43,6 +45,7 @@ private slots:
void addEngine(); void addEngine();
void removeEngine(); void removeEngine();
void editEngine(); void editEngine();
void setDefaultEngine();
void moveUp(); void moveUp();
void moveDown(); void moveDown();

View File

@ -6,7 +6,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>460</width> <width>465</width>
<height>299</height> <height>299</height>
</rect> </rect>
</property> </property>
@ -37,6 +37,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="setAsDefault">
<property name="text">
<string>Set as Default</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer"> <spacer name="verticalSpacer">
<property name="orientation"> <property name="orientation">

View File

@ -25,6 +25,7 @@
#include "opensearchengine.h" #include "opensearchengine.h"
#include "databasewriter.h" #include "databasewriter.h"
#include "settings.h" #include "settings.h"
#include "qzsettings.h"
#include "webview.h" #include "webview.h"
#include <QNetworkReply> #include <QNetworkReply>
@ -51,6 +52,7 @@ SearchEnginesManager::SearchEnginesManager()
Settings settings; Settings settings;
settings.beginGroup("SearchEngines"); settings.beginGroup("SearchEngines");
m_startingEngineName = settings.value("activeEngine", "Google").toString(); m_startingEngineName = settings.value("activeEngine", "Google").toString();
m_defaultEngineName = settings.value("DefaultEngine", "Google").toString();
settings.endGroup(); settings.endGroup();
connect(this, SIGNAL(enginesChanged()), this, SLOT(scheduleSave())); connect(this, SIGNAL(enginesChanged()), this, SLOT(scheduleSave()));
@ -71,11 +73,19 @@ void SearchEnginesManager::loadSettings()
en.suggestionsUrl = query.value(4).toString(); en.suggestionsUrl = query.value(4).toString();
m_allEngines.append(en); m_allEngines.append(en);
if (en.name == m_defaultEngineName) {
m_defaultEngine = en;
}
} }
if (m_allEngines.isEmpty()) { if (m_allEngines.isEmpty()) {
restoreDefaults(); restoreDefaults();
} }
if (m_defaultEngine.name.isEmpty()) {
m_defaultEngine = m_allEngines[0];
}
} }
SearchEngine SearchEnginesManager::engineForShortcut(const QString &shortcut) 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) 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() void SearchEnginesManager::restoreDefaults()
@ -143,6 +154,8 @@ void SearchEnginesManager::restoreDefaults()
addEngine(yt); addEngine(yt);
addEngine(duck); addEngine(duck);
m_defaultEngine = google;
emit enginesChanged(); emit enginesChanged();
} }
@ -344,6 +357,18 @@ void SearchEnginesManager::setActiveEngine(const Engine &engine)
emit activeEngineChanged(); 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) void SearchEnginesManager::removeEngine(const Engine &engine)
{ {
ENSURE_LOADED; ENSURE_LOADED;
@ -382,6 +407,7 @@ void SearchEnginesManager::saveSettings()
Settings settings; Settings settings;
settings.beginGroup("SearchEngines"); settings.beginGroup("SearchEngines");
settings.setValue("activeEngine", m_activeEngine.name); settings.setValue("activeEngine", m_activeEngine.name);
settings.setValue("DefaultEngine", m_defaultEngine.name);
settings.endGroup(); settings.endGroup();
if (!m_saveScheduled) { if (!m_saveScheduled) {

View File

@ -66,7 +66,11 @@ public:
void removeEngine(const Engine &engine); void removeEngine(const Engine &engine);
void setActiveEngine(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); void editEngine(const Engine &before, const Engine &after);
Engine engineForShortcut(const QString &shortcut); Engine engineForShortcut(const QString &shortcut);
@ -84,6 +88,7 @@ public:
signals: signals:
void enginesChanged(); void enginesChanged();
void activeEngineChanged(); void activeEngineChanged();
void defaultEngineChanged();
public slots: public slots:
@ -102,8 +107,10 @@ private:
bool m_saveScheduled; bool m_saveScheduled;
QString m_startingEngineName; QString m_startingEngineName;
QString m_defaultEngineName;
QList<Engine> m_allEngines; QList<Engine> m_allEngines;
Engine m_activeEngine; Engine m_activeEngine;
Engine m_defaultEngine;
}; };

View File

@ -37,6 +37,7 @@ void QzSettings::loadSettings()
settings.beginGroup("SearchEngines"); settings.beginGroup("SearchEngines");
showSearchSuggestions = settings.value("showSuggestions", true).toBool(); showSearchSuggestions = settings.value("showSuggestions", true).toBool();
searchOnEngineChange = settings.value("SearchOnEngineChange", true).toBool(); searchOnEngineChange = settings.value("SearchOnEngineChange", true).toBool();
searchWithDefaultEngine = settings.value("SearchWithDefaultEngine", false).toBool();
settings.endGroup(); settings.endGroup();
settings.beginGroup("Web-Browser-Settings"); settings.beginGroup("Web-Browser-Settings");

View File

@ -41,6 +41,7 @@ public:
// SearchEngines // SearchEngines
bool showSearchSuggestions; bool showSearchSuggestions;
bool searchOnEngineChange; bool searchOnEngineChange;
bool searchWithDefaultEngine;
// Web-Browser-Settings // Web-Browser-Settings
int defaultZoom; int defaultZoom;

View File

@ -77,7 +77,8 @@ void SourceViewerSearch::searchWholeWords()
{ {
if (ui->wholeWords->isChecked()) { if (ui->wholeWords->isChecked()) {
m_findFlags |= QTextDocument::FindWholeWords; m_findFlags |= QTextDocument::FindWholeWords;
} else { }
else {
m_findFlags &= (~QTextDocument::FindWholeWords); m_findFlags &= (~QTextDocument::FindWholeWords);
} }
} }

View File

@ -210,6 +210,10 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent)
connect(ui->setProgressBarColorToHighlightButton, SIGNAL(clicked()), SLOT(setProgressBarColorIcon())); connect(ui->setProgressBarColorToHighlightButton, SIGNAL(clicked()), SLOT(setProgressBarColorIcon()));
settings.endGroup(); settings.endGroup();
settings.beginGroup("SearchEngines");
ui->searchWithDefaultEngine->setChecked(settings.value("SearchWithDefaultEngine", false).toBool());
settings.endGroup();
//BROWSING //BROWSING
settings.beginGroup("Web-Browser-Settings"); settings.beginGroup("Web-Browser-Settings");
ui->allowPlugins->setChecked(settings.value("allowFlash", true).toBool()); ui->allowPlugins->setChecked(settings.value("allowFlash", true).toBool());
@ -897,6 +901,10 @@ void Preferences::saveSettings()
settings.setValue("CustomProgressColor", ui->customColorToolButton->property("ProgressColor").value<QColor>()); settings.setValue("CustomProgressColor", ui->customColorToolButton->property("ProgressColor").value<QColor>());
settings.endGroup(); settings.endGroup();
settings.beginGroup("SearchEngines");
settings.setValue("SearchWithDefaultEngine", ui->searchWithDefaultEngine->isChecked());
settings.endGroup();
//Languages //Languages
settings.beginGroup("Language"); settings.beginGroup("Language");
settings.setValue("language", ui->languages->itemData(ui->languages->currentIndex()).toString()); settings.setValue("language", ui->languages->itemData(ui->languages->currentIndex()).toString());

View File

@ -888,6 +888,16 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="searchWithDefaultEngine">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;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.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Search with Default Engine</string>
</property>
</widget>
</item>
<item> <item>
<spacer name="verticalSpacer_7"> <spacer name="verticalSpacer_7">
<property name="orientation"> <property name="orientation">