mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
SearchEngines: Return SearchResult on all searches
This commit is contained in:
parent
8a5a4017d6
commit
c9ff4f1c94
@ -183,6 +183,5 @@ void ProfileUpdater::update140()
|
|||||||
mApp->connectDatabase();
|
mApp->connectDatabase();
|
||||||
|
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.exec("ALTER TABLE search_engines ADD COLUMN method TEXT");
|
query.exec("ALTER TABLE search_engines ADD COLUMN postData TEXT");
|
||||||
query.exec("UPDATE search_engines SET method='GET'");
|
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
@ -205,13 +205,19 @@ void WebSearchBar::instantSearchChanged(bool enable)
|
|||||||
void WebSearchBar::search()
|
void WebSearchBar::search()
|
||||||
{
|
{
|
||||||
p_QupZilla->weView()->setFocus();
|
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()
|
void WebSearchBar::searchInNewTab()
|
||||||
{
|
{
|
||||||
p_QupZilla->weView()->setFocus();
|
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)
|
void WebSearchBar::completeMenuWithAvailableEngines(QMenu* menu)
|
||||||
|
@ -67,15 +67,16 @@ void SearchEnginesManager::loadSettings()
|
|||||||
m_settingsLoaded = true;
|
m_settingsLoaded = true;
|
||||||
|
|
||||||
QSqlQuery query;
|
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()) {
|
while (query.next()) {
|
||||||
Engine en;
|
Engine en;
|
||||||
en.name = query.value(0).toString();
|
en.name = query.value(0).toString();
|
||||||
en.icon = qIconProvider->iconFromBase64(query.value(1).toByteArray());
|
en.icon = qIconProvider->iconFromBase64(query.value(1).toByteArray());
|
||||||
en.url = query.value(2).toString();
|
en.url = query.value(2).toString();
|
||||||
en.shortcut = query.value(3).toString();
|
en.shortcut = query.value(3).toString();
|
||||||
en.method = query.value(4).toString();
|
en.suggestionsUrl = query.value(4).toString();
|
||||||
en.suggestionsUrl = query.value(5).toString();
|
en.suggestionsParameters = query.value(5).toByteArray();
|
||||||
|
en.postData = query.value(6).toByteArray();
|
||||||
|
|
||||||
m_allEngines.append(en);
|
m_allEngines.append(en);
|
||||||
|
|
||||||
@ -110,19 +111,26 @@ SearchEngine SearchEnginesManager::engineForShortcut(const QString &shortcut)
|
|||||||
return returnEngine;
|
return returnEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl SearchEnginesManager::searchUrl(const Engine &engine, const QString &string)
|
SearchEnginesManager::SearchResult SearchEnginesManager::searchResult(const Engine &engine, const QString &string)
|
||||||
{
|
{
|
||||||
ENSURE_LOADED;
|
ENSURE_LOADED;
|
||||||
|
|
||||||
QByteArray url = engine.url.toUtf8();
|
QByteArray url = engine.url.toUtf8();
|
||||||
url.replace(QLatin1String("%s"), QUrl::toPercentEncoding(string));
|
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;
|
const Engine en = qzSettings->searchWithDefaultEngine ? m_defaultEngine : m_activeEngine;
|
||||||
return searchUrl(en, string);
|
return searchResult(en, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchEnginesManager::restoreDefaults()
|
void SearchEnginesManager::restoreDefaults()
|
||||||
@ -447,14 +455,14 @@ void SearchEnginesManager::saveSettings()
|
|||||||
query.exec("DELETE FROM search_engines");
|
query.exec("DELETE FROM search_engines");
|
||||||
|
|
||||||
foreach (const Engine &en, m_allEngines) {
|
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(en.name);
|
||||||
query.addBindValue(qIconProvider->iconToBase64(en.icon));
|
query.addBindValue(qIconProvider->iconToBase64(en.icon));
|
||||||
query.addBindValue(en.url);
|
query.addBindValue(en.url);
|
||||||
query.addBindValue(en.shortcut);
|
query.addBindValue(en.shortcut);
|
||||||
query.addBindValue(en.method);
|
|
||||||
query.addBindValue(en.suggestionsUrl);
|
query.addBindValue(en.suggestionsUrl);
|
||||||
query.addBindValue(en.suggestionsParameters);
|
query.addBindValue(en.suggestionsParameters);
|
||||||
|
query.addBindValue(en.postData);
|
||||||
|
|
||||||
query.exec();
|
query.exec();
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
|
||||||
#include "qz_namespace.h"
|
#include "qz_namespace.h"
|
||||||
#include "opensearchengine.h"
|
#include "opensearchengine.h"
|
||||||
@ -41,10 +42,10 @@ public:
|
|||||||
QIcon icon;
|
QIcon icon;
|
||||||
QString url;
|
QString url;
|
||||||
QString shortcut;
|
QString shortcut;
|
||||||
QString method;
|
|
||||||
|
|
||||||
QString suggestionsUrl;
|
QString suggestionsUrl;
|
||||||
QByteArray suggestionsParameters;
|
QByteArray suggestionsParameters;
|
||||||
|
QByteArray postData;
|
||||||
|
|
||||||
bool operator==(const Engine &other) const {
|
bool operator==(const Engine &other) const {
|
||||||
return (this->name == other.name &&
|
return (this->name == other.name &&
|
||||||
@ -53,8 +54,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QUrl searchUrl(const Engine &engine, const QString &string);
|
struct SearchResult {
|
||||||
QUrl searchUrl(const QString &string);
|
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(const QUrl &url);
|
||||||
void addEngine(OpenSearchEngine* engine);
|
void addEngine(OpenSearchEngine* engine);
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "qupzilla.h"
|
#include "qupzilla.h"
|
||||||
#include "tabwidget.h"
|
#include "tabwidget.h"
|
||||||
|
#include "tabbedwebview.h"
|
||||||
#include "iconprovider.h"
|
#include "iconprovider.h"
|
||||||
#include "enhancedmenu.h"
|
#include "enhancedmenu.h"
|
||||||
|
|
||||||
@ -59,18 +60,19 @@ QWidget* PopupWebView::overlayForJsAlert()
|
|||||||
return this;
|
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)
|
Q_UNUSED(position)
|
||||||
|
|
||||||
QupZilla* window = mApp->getWindow();
|
QupZilla* window = mApp->getWindow();
|
||||||
|
|
||||||
if (window) {
|
if (window) {
|
||||||
QNetworkRequest req(urla);
|
QNetworkRequest r(req);
|
||||||
req.setRawHeader("Referer", url().toEncoded());
|
r.setRawHeader("Referer", url().toEncoded());
|
||||||
req.setRawHeader("X-QupZilla-UserLoadAction", QByteArray("1"));
|
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();
|
window->raise();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,8 @@ public:
|
|||||||
PopupWebPage* webPage();
|
PopupWebPage* webPage();
|
||||||
|
|
||||||
QWidget* overlayForJsAlert();
|
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:
|
signals:
|
||||||
|
|
||||||
|
@ -237,6 +237,16 @@ void TabbedWebView::closeView()
|
|||||||
emit wantsCloseTab(tabIndex());
|
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)
|
void TabbedWebView::contextMenuEvent(QContextMenuEvent* event)
|
||||||
{
|
{
|
||||||
m_menu->clear();
|
m_menu->clear();
|
||||||
@ -270,15 +280,6 @@ void TabbedWebView::stop()
|
|||||||
slotLoadFinished();
|
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()
|
void TabbedWebView::openNewTab()
|
||||||
{
|
{
|
||||||
tabWidget()->addView(QUrl());
|
tabWidget()->addView(QUrl());
|
||||||
|
@ -69,7 +69,8 @@ public slots:
|
|||||||
void userLoadAction(const QUrl &url);
|
void userLoadAction(const QUrl &url);
|
||||||
|
|
||||||
void closeView();
|
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();
|
void openNewTab();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -196,8 +196,10 @@ void WebView::load(const QNetworkRequest &request, QNetworkAccessManager::Operat
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QUrl &searchUrl = mApp->searchEnginesManager()->searchUrl(reqUrl.toString());
|
SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(reqUrl.toString());
|
||||||
QWebView::load(searchUrl);
|
const QUrl &searchUrl = res.request.url();
|
||||||
|
|
||||||
|
QWebView::load(res.request, res.operation, res.data);
|
||||||
|
|
||||||
emit urlChanged(searchUrl);
|
emit urlChanged(searchUrl);
|
||||||
m_aboutToLoadUrl = searchUrl;
|
m_aboutToLoadUrl = searchUrl;
|
||||||
@ -517,6 +519,11 @@ void WebView::savePageAs()
|
|||||||
dManager->download(request, info);
|
dManager->download(request, info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebView::openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position)
|
||||||
|
{
|
||||||
|
loadInNewTab(QNetworkRequest(url), QNetworkAccessManager::GetOperation, QByteArray(), position);
|
||||||
|
}
|
||||||
|
|
||||||
void WebView::downloadUrlToDisk()
|
void WebView::downloadUrlToDisk()
|
||||||
{
|
{
|
||||||
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||||
@ -571,8 +578,8 @@ void WebView::searchSelectedText()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QUrl &urlToLoad = mApp->searchEnginesManager()->searchUrl(engine, selectedText());
|
SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(engine, selectedText());
|
||||||
openUrlInNewTab(urlToLoad, Qz::NT_SelectedTab);
|
loadInNewTab(res.request, res.operation, res.data, Qz::NT_SelectedTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::searchSelectedTextInBackgroundTab()
|
void WebView::searchSelectedTextInBackgroundTab()
|
||||||
@ -584,8 +591,8 @@ void WebView::searchSelectedTextInBackgroundTab()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const QUrl &urlToLoad = mApp->searchEnginesManager()->searchUrl(engine, selectedText());
|
SearchEnginesManager::SearchResult res = mApp->searchEnginesManager()->searchResult(engine, selectedText());
|
||||||
openUrlInNewTab(urlToLoad, Qz::NT_NotSelectedTab);
|
loadInNewTab(res.request, res.operation, res.data, Qz::NT_NotSelectedTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::bookmarkLink()
|
void WebView::bookmarkLink()
|
||||||
|
@ -83,9 +83,12 @@ public slots:
|
|||||||
void sendPageByMail();
|
void sendPageByMail();
|
||||||
void savePageAs();
|
void savePageAs();
|
||||||
|
|
||||||
|
void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position);
|
||||||
|
|
||||||
virtual void closeView() = 0;
|
virtual void closeView() = 0;
|
||||||
virtual void openUrlInNewTab(const QUrl &url, Qz::NewTabPositionFlag position) = 0;
|
|
||||||
virtual void openNewTab() { }
|
virtual void openNewTab() { }
|
||||||
|
virtual void loadInNewTab(const QNetworkRequest &req, QNetworkAccessManager::Operation op,
|
||||||
|
const QByteArray &data, Qz::NewTabPositionFlag position) = 0;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void slotLoadStarted();
|
void slotLoadStarted();
|
||||||
|
Loading…
Reference in New Issue
Block a user