mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
Bring back support for searching one-word terms from locationbar
This commit is contained in:
parent
5f6cfdc62a
commit
800cc14dcd
|
@ -173,11 +173,13 @@ LoadRequest LocationBar::createLoadRequest() const
|
|||
{
|
||||
LoadRequest req;
|
||||
|
||||
const QString &t = text().trimmed();
|
||||
|
||||
// Check for Search Engine shortcut
|
||||
int firstSpacePos = text().indexOf(QLatin1Char(' '));
|
||||
int firstSpacePos = t.indexOf(QLatin1Char(' '));
|
||||
if (firstSpacePos != -1) {
|
||||
const QString shortcut = text().left(firstSpacePos);
|
||||
const QString searchedString = text().mid(firstSpacePos).trimmed();
|
||||
const QString shortcut = t.left(firstSpacePos);
|
||||
const QString searchedString = t.mid(firstSpacePos).trimmed();
|
||||
|
||||
SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut);
|
||||
if (!en.name.isEmpty()) {
|
||||
|
@ -186,7 +188,7 @@ LoadRequest LocationBar::createLoadRequest() const
|
|||
}
|
||||
|
||||
// Check for Bookmark keyword
|
||||
QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(text());
|
||||
QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(t);
|
||||
if (!items.isEmpty()) {
|
||||
BookmarkItem* item = items.first();
|
||||
item->updateVisitCount();
|
||||
|
@ -194,11 +196,18 @@ LoadRequest LocationBar::createLoadRequest() const
|
|||
}
|
||||
|
||||
if (req.isEmpty()) {
|
||||
const QUrl guessedUrl = QUrl::fromUserInput(text());
|
||||
if (!guessedUrl.isEmpty())
|
||||
req.setUrl(guessedUrl);
|
||||
else
|
||||
req.setUrl(QUrl::fromEncoded(text().toUtf8()));
|
||||
// One word needs special handling, because QUrl::fromUserInput
|
||||
// would convert it to QUrl("http://WORD")
|
||||
if (!t.contains(QL1C(' ')) && !t.contains(QL1C('.'))) {
|
||||
req.setUrl(QUrl(t));
|
||||
}
|
||||
else {
|
||||
const QUrl &guessed = QUrl::fromUserInput(t);
|
||||
if (!guessed.isEmpty())
|
||||
req.setUrl(guessed);
|
||||
else
|
||||
req.setUrl(QUrl::fromEncoded(t.toUtf8()));
|
||||
}
|
||||
}
|
||||
|
||||
return req;
|
||||
|
|
|
@ -312,12 +312,6 @@ void WebPage::windowCloseRequested()
|
|||
view()->closeView();
|
||||
}
|
||||
|
||||
void WebPage::doWebSearch(const QString &text)
|
||||
{
|
||||
const LoadRequest searchRequest = mApp->searchEnginesManager()->searchResult(text);
|
||||
view()->load(searchRequest);
|
||||
}
|
||||
|
||||
void WebPage::featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature)
|
||||
{
|
||||
mApp->html5PermissionsManager()->requestPermissions(this, origin, feature);
|
||||
|
|
|
@ -83,10 +83,7 @@ protected slots:
|
|||
private slots:
|
||||
void cleanBlockedObjects();
|
||||
void urlChanged(const QUrl &url);
|
||||
|
||||
void watchedFileChanged(const QString &file);
|
||||
void doWebSearch(const QString &text);
|
||||
|
||||
void windowCloseRequested();
|
||||
void featurePermissionRequested(const QUrl &origin, const QWebEnginePage::Feature &feature);
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include <QNetworkRequest>
|
||||
#include <QWebEngineHistory>
|
||||
#include <QClipboard>
|
||||
#include <QHostInfo>
|
||||
|
||||
bool WebView::s_forceContextMenuOnMouseRelease = false;
|
||||
|
||||
|
@ -59,10 +60,10 @@ WebView::WebView(QWidget* parent)
|
|||
, m_firstLoad(false)
|
||||
, m_rwhvqt(0)
|
||||
{
|
||||
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
|
||||
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
|
||||
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
|
||||
connect(this, SIGNAL(iconUrlChanged(QUrl)), this, SLOT(slotIconUrlChanged(QUrl)));
|
||||
connect(this, &QWebEngineView::loadStarted, this, &WebView::slotLoadStarted);
|
||||
connect(this, &QWebEngineView::loadProgress, this, &WebView::slotLoadProgress);
|
||||
connect(this, &QWebEngineView::loadFinished, this, &WebView::slotLoadFinished);
|
||||
connect(this, &QWebEngineView::iconUrlChanged, this, &WebView::slotIconUrlChanged);
|
||||
|
||||
m_currentZoomLevel = zoomLevels().indexOf(100);
|
||||
|
||||
|
@ -156,6 +157,9 @@ void WebView::load(const LoadRequest &request)
|
|||
{
|
||||
const QUrl reqUrl = request.url();
|
||||
|
||||
if (reqUrl.isEmpty())
|
||||
return;
|
||||
|
||||
if (reqUrl.scheme() == QL1S("javascript")) {
|
||||
const QString scriptSource = reqUrl.toString().mid(11);
|
||||
// Is the javascript source percent encoded or not?
|
||||
|
@ -167,7 +171,7 @@ void WebView::load(const LoadRequest &request)
|
|||
return;
|
||||
}
|
||||
|
||||
if (reqUrl.isEmpty() || isUrlValid(reqUrl)) {
|
||||
if (isUrlValid(reqUrl)) {
|
||||
loadRequest(request);
|
||||
return;
|
||||
}
|
||||
|
@ -178,10 +182,14 @@ void WebView::load(const LoadRequest &request)
|
|||
!reqUrl.path().contains(QL1C(' ')) &&
|
||||
!reqUrl.path().contains(QL1C('.'))
|
||||
) {
|
||||
LoadRequest req = request;
|
||||
req.setUrl(QUrl(QSL("http://") + reqUrl.path()));
|
||||
loadRequest(req);
|
||||
return;
|
||||
// FIXME: This is blocking...
|
||||
QHostInfo info = QHostInfo::fromName(reqUrl.path());
|
||||
if (info.error() != QHostInfo::HostNotFound) {
|
||||
LoadRequest req = request;
|
||||
req.setUrl(QUrl(QSL("http://") + reqUrl.path()));
|
||||
loadRequest(req);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const LoadRequest searchRequest = mApp->searchEnginesManager()->searchResult(request.urlString());
|
||||
|
@ -371,11 +379,12 @@ void WebView::slotLoadProgress(int progress)
|
|||
m_progress = progress;
|
||||
}
|
||||
|
||||
void WebView::slotLoadFinished()
|
||||
void WebView::slotLoadFinished(bool ok)
|
||||
{
|
||||
m_progress = 100;
|
||||
|
||||
mApp->history()->addHistoryEntry(this);
|
||||
if (ok)
|
||||
mApp->history()->addHistoryEntry(this);
|
||||
}
|
||||
|
||||
void WebView::slotIconUrlChanged(const QUrl &url)
|
||||
|
|
|
@ -109,7 +109,7 @@ public slots:
|
|||
protected slots:
|
||||
void slotLoadStarted();
|
||||
void slotLoadProgress(int progress);
|
||||
void slotLoadFinished();
|
||||
void slotLoadFinished(bool ok);
|
||||
void slotIconUrlChanged(const QUrl &url);
|
||||
|
||||
// Context menu slots
|
||||
|
@ -178,7 +178,6 @@ private:
|
|||
QPoint m_clickedPos;
|
||||
|
||||
WebPage* m_page;
|
||||
bool m_actionsInitialized;
|
||||
bool m_firstLoad;
|
||||
|
||||
QObject *m_rwhvqt;
|
||||
|
|
Loading…
Reference in New Issue
Block a user