1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

SearchEngines: Return SearchResult on all searches

This commit is contained in:
nowrep 2013-11-09 13:32:03 +01:00
parent 8a5a4017d6
commit c9ff4f1c94
11 changed files with 74 additions and 39 deletions

View File

@ -183,6 +183,5 @@ void ProfileUpdater::update140()
mApp->connectDatabase();
QSqlQuery query;
query.exec("ALTER TABLE search_engines ADD COLUMN method TEXT");
query.exec("UPDATE search_engines SET method='GET'");
query.exec("ALTER TABLE search_engines ADD COLUMN postData TEXT");
}

Binary file not shown.

View File

@ -205,13 +205,19 @@ void WebSearchBar::instantSearchChanged(bool enable)
void WebSearchBar::search()
{
p_QupZilla->weView()->setFocus();
p_QupZilla->weView()->load(m_searchManager->searchUrl(m_activeEngine, text()));
SearchEnginesManager::SearchResult res = m_searchManager->searchResult(m_activeEngine, text());
p_QupZilla->weView()->load(res.request, res.operation, res.data);
}
void WebSearchBar::searchInNewTab()
{
p_QupZilla->weView()->setFocus();
p_QupZilla->tabWidget()->addView(m_searchManager->searchUrl(m_activeEngine, text()));
int index = p_QupZilla->tabWidget()->addView(QUrl());
SearchEnginesManager::SearchResult res = m_searchManager->searchResult(m_activeEngine, text());
p_QupZilla->weView(index)->load(res.request, res.operation, res.data);
}
void WebSearchBar::completeMenuWithAvailableEngines(QMenu* menu)

View File

@ -67,15 +67,16 @@ void SearchEnginesManager::loadSettings()
m_settingsLoaded = true;
QSqlQuery query;
query.exec("SELECT name, icon, url, shortcut, method, suggestionsUrl FROM search_engines");
query.exec("SELECT name, icon, url, shortcut, suggestionsUrl, suggestionsParameters, postData FROM search_engines");
while (query.next()) {
Engine en;
en.name = query.value(0).toString();
en.icon = qIconProvider->iconFromBase64(query.value(1).toByteArray());
en.url = query.value(2).toString();
en.shortcut = query.value(3).toString();
en.method = query.value(4).toString();
en.suggestionsUrl = query.value(5).toString();
en.suggestionsUrl = query.value(4).toString();
en.suggestionsParameters = query.value(5).toByteArray();
en.postData = query.value(6).toByteArray();
m_allEngines.append(en);
@ -110,19 +111,26 @@ SearchEngine SearchEnginesManager::engineForShortcut(const QString &shortcut)
return returnEngine;
}
QUrl SearchEnginesManager::searchUrl(const Engine &engine, const QString &string)
SearchEnginesManager::SearchResult SearchEnginesManager::searchResult(const Engine &engine, const QString &string)
{
ENSURE_LOADED;
QByteArray url = engine.url.toUtf8();
url.replace(QLatin1String("%s"), QUrl::toPercentEncoding(string));
return QUrl::fromEncoded(url);
SearchResult result;
result.request = QNetworkRequest(QUrl::fromEncoded(url));
result.operation = QNetworkAccessManager::GetOperation;
return result;
}
QUrl SearchEnginesManager::searchUrl(const QString &string)
SearchEnginesManager::SearchResult SearchEnginesManager::searchResult(const QString &string)
{
ENSURE_LOADED;
const Engine en = qzSettings->searchWithDefaultEngine ? m_defaultEngine : m_activeEngine;
return searchUrl(en, string);
return searchResult(en, string);
}
void SearchEnginesManager::restoreDefaults()
@ -447,14 +455,14 @@ void SearchEnginesManager::saveSettings()
query.exec("DELETE FROM search_engines");
foreach (const Engine &en, m_allEngines) {
query.prepare("INSERT INTO search_engines (name, icon, url, shortcut, method, suggestionsUrl, suggestionsParameters) VALUES (?, ?, ?, ?, ?, ?)");
query.prepare("INSERT INTO search_engines (name, icon, url, shortcut, suggestionsUrl, suggestionsParameters, postData) VALUES (?, ?, ?, ?, ?, ?)");
query.addBindValue(en.name);
query.addBindValue(qIconProvider->iconToBase64(en.icon));
query.addBindValue(en.url);
query.addBindValue(en.shortcut);
query.addBindValue(en.method);
query.addBindValue(en.suggestionsUrl);
query.addBindValue(en.suggestionsParameters);
query.addBindValue(en.postData);
query.exec();
}

View File

@ -22,6 +22,7 @@
#include <QIcon>
#include <QList>
#include <QVariant>
#include <QNetworkRequest>
#include "qz_namespace.h"
#include "opensearchengine.h"
@ -41,10 +42,10 @@ public:
QIcon icon;
QString url;
QString shortcut;
QString method;
QString suggestionsUrl;
QByteArray suggestionsParameters;
QByteArray postData;
bool operator==(const Engine &other) const {
return (this->name == other.name &&
@ -53,8 +54,14 @@ public:
}
};
QUrl searchUrl(const Engine &engine, const QString &string);
QUrl searchUrl(const QString &string);
struct SearchResult {
QNetworkRequest request;
QNetworkAccessManager::Operation operation;
QByteArray data;
};
SearchResult searchResult(const Engine &engine, const QString &string);
SearchResult searchResult(const QString &string);
void addEngine(const QUrl &url);
void addEngine(OpenSearchEngine* engine);

View File

@ -20,6 +20,7 @@
#include "mainapplication.h"
#include "qupzilla.h"
#include "tabwidget.h"
#include "tabbedwebview.h"
#include "iconprovider.h"
#include "enhancedmenu.h"
@ -59,18 +60,19 @@ QWidget* PopupWebView::overlayForJsAlert()
return this;
}
void PopupWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position)
void PopupWebView::loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op, const QByteArray &data, Qz::NewTabPositionFlag position)
{
Q_UNUSED(position)
QupZilla* window = mApp->getWindow();
if (window) {
QNetworkRequest req(urla);
req.setRawHeader("Referer", url().toEncoded());
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
QNetworkRequest r(req);
r.setRawHeader("Referer", url().toEncoded());
r.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
window->tabWidget()->addView(req, Qz::NT_SelectedTab);
int index = window->tabWidget()->addView(QUrl(), Qz::NT_SelectedTab);
window->weView(index)->load(r, op, data);
window->raise();
}
}

View File

@ -34,7 +34,8 @@ public:
PopupWebPage* webPage();
QWidget* overlayForJsAlert();
void openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position);
void loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op,
const QByteArray &data, Qz::NewTabPositionFlag position);
signals:

View File

@ -237,6 +237,16 @@ void TabbedWebView::closeView()
emit wantsCloseTab(tabIndex());
}
void TabbedWebView::loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op, const QByteArray &data, Qz::NewTabPositionFlag position)
{
QNetworkRequest r(req);
r.setRawHeader("Referer", url().toEncoded());
r.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
int index = tabWidget()->addView(QUrl(), position);
p_QupZilla->weView(index)->load(r, op, data);
}
void TabbedWebView::contextMenuEvent(QContextMenuEvent* event)
{
m_menu->clear();
@ -270,15 +280,6 @@ void TabbedWebView::stop()
slotLoadFinished();
}
void TabbedWebView::openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position)
{
QNetworkRequest req(urla);
req.setRawHeader("Referer", url().toEncoded());
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
tabWidget()->addView(req, position);
}
void TabbedWebView::openNewTab()
{
tabWidget()->addView(QUrl());

View File

@ -69,7 +69,8 @@ public slots:
void userLoadAction(const QUrl &url);
void closeView();
void openUrlInNewTab(const QUrl &urla, Qz::NewTabPositionFlag position);
void loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op,
const QByteArray &data, Qz::NewTabPositionFlag position);
void openNewTab();
private slots:

View File

@ -196,8 +196,10 @@ void WebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operat
return;
}
const QUrl &searchUrl = mApp->searchEnginesManager()->searchUrl(reqUrl.toString());
QWebView::load(searchUrl);
SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(reqUrl.toString());
const QUrl &searchUrl = res.request.url();
QWebView::load(res.request, res.operation, res.data);
emit urlChanged(searchUrl);
m_aboutToLoadUrl = searchUrl;
@ -517,6 +519,11 @@ void WebView::savePageAs()
dManager->download(request, info);
}
void WebView::openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position)
{
loadInNewTab(QNetworkRequest(url), QNetworkAccessManager::GetOperation, QByteArray(), position);
}
void WebView::downloadUrlToDisk()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
@ -571,8 +578,8 @@ void WebView::searchSelectedText()
}
}
const QUrl &urlToLoad = mApp->searchEnginesManager()->searchUrl(engine, selectedText());
openUrlInNewTab(urlToLoad, Qz::NT_SelectedTab);
SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(engine, selectedText());
loadInNewTab(res.request, res.operation, res.data, Qz::NT_SelectedTab);
}
void WebView::searchSelectedTextInBackgroundTab()
@ -584,8 +591,8 @@ void WebView::searchSelectedTextInBackgroundTab()
}
}
const QUrl &urlToLoad = mApp->searchEnginesManager()->searchUrl(engine, selectedText());
openUrlInNewTab(urlToLoad, Qz::NT_NotSelectedTab);
SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(engine, selectedText());
loadInNewTab(res.request, res.operation, res.data, Qz::NT_NotSelectedTab);
}
void WebView::bookmarkLink()

View File

@ -83,9 +83,12 @@ public slots:
void sendPageByMail();
void savePageAs();
void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position);
virtual void closeView() = 0;
virtual void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position) = 0;
virtual void openNewTab() { }
virtual void loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op,
const QByteArray &data, Qz::NewTabPositionFlag position) = 0;
protected slots:
void slotLoadStarted();