1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

LocationCompleter: Handle creating LoadRequest

Instead of just passing string that LocationBar should somehow
parse and decide what to do (which may not correspond to what was
indicated in completion entry), make the LocationCompleter create
it with all needed info and pass it to LocationBar to load.

This fixes issue where search completions may have been loaded
with different search engine when suggestion starts with search
engine shortcut (which would also get cut in the search).

This also removes the possibility to open new window from completer
with activating entry with Shift key.
This commit is contained in:
David Rosca 2018-01-25 16:29:48 +01:00
parent 8d45c910bf
commit 09ee6007e9
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
3 changed files with 53 additions and 45 deletions

View File

@ -213,18 +213,7 @@ void LocationCompleter::indexActivated(const QModelIndex &index)
return; return;
} }
if (index.data(LocationCompleterModel::BookmarkRole).toBool()) { loadRequest(createLoadRequest(index));
BookmarkItem* bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
bookmark->updateVisitCount();
}
QString urlString = index.data(LocationCompleterModel::UrlRole).toString();
if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
urlString = m_originalText;
}
loadString(urlString);
} }
void LocationCompleter::indexCtrlActivated(const QModelIndex &index) void LocationCompleter::indexCtrlActivated(const QModelIndex &index)
@ -232,48 +221,26 @@ void LocationCompleter::indexCtrlActivated(const QModelIndex &index)
Q_ASSERT(index.isValid()); Q_ASSERT(index.isValid());
Q_ASSERT(m_window); Q_ASSERT(m_window);
if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
BookmarkItem* bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
bookmark->updateVisitCount();
}
const QUrl url = index.data(LocationCompleterModel::UrlRole).toUrl();
const QString title = index.data(LocationCompleterModel::TitleRole).toString();
closePopup(); closePopup();
// Clear locationbar // Clear locationbar
emit clearCompletion(); emit clearCompletion();
// Open url in new tab // Load request in new tab
m_window->tabWidget()->addView(url, title, Qz::NT_CleanSelectedTab); m_window->tabWidget()->addView(createLoadRequest(index), Qz::NT_CleanSelectedTab);
} }
void LocationCompleter::indexShiftActivated(const QModelIndex &index) void LocationCompleter::indexShiftActivated(const QModelIndex &index)
{ {
Q_ASSERT(index.isValid()); Q_ASSERT(index.isValid());
if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
BookmarkItem* bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
bookmark->updateVisitCount();
}
const QString urlString = index.data(LocationCompleterModel::UrlRole).toString();
const int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt();
// Load url (instead of switching to tab) with shift activation
if (tabPos > -1) {
loadString(urlString);
return;
}
closePopup(); closePopup();
// Clear locationbar // Clear locationbar
emit clearCompletion(); emit clearCompletion();
// Open new window // Load request
mApp->createWindow(Qz::BW_NewWindow, QUrl(urlString)); loadRequest(createLoadRequest(index));
} }
void LocationCompleter::indexDeleteRequested(const QModelIndex &index) void LocationCompleter::indexDeleteRequested(const QModelIndex &index)
@ -305,6 +272,48 @@ void LocationCompleter::indexDeleteRequested(const QModelIndex &index)
} }
} }
LoadRequest LocationCompleter::createLoadRequest(const QModelIndex &index)
{
LoadRequest request;
QString searchString;
SearchEngine searchEngine;
BookmarkItem *bookmark = nullptr;
if (index.data(LocationCompleterModel::HistoryRole).toBool()) {
request = index.data(LocationCompleterModel::UrlRole).toUrl();
} else if (index.data(LocationCompleterModel::BookmarkRole).toBool()) {
bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>());
} else if (index.data(LocationCompleterModel::SearchSuggestionRole).toBool()) {
searchEngine = LocationBar::searchEngine();
searchString = index.data(LocationCompleterModel::TitleRole).toString();
} else if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) {
const auto action = LocationBar::loadAction(m_originalText);
switch (action.type) {
case LocationBar::LoadAction::Url:
request = action.loadRequest;
break;
case LocationBar::LoadAction::Bookmark:
bookmark = action.bookmark;
break;
case LocationBar::LoadAction::Search:
searchEngine = action.searchEngine;
searchString = m_originalText;
break;
default:
break;
}
}
if (bookmark) {
bookmark->updateVisitCount();
request = bookmark->url();
} else if (searchEngine.isValid()) {
request = mApp->searchEnginesManager()->searchResult(searchEngine, searchString);
}
return request;
}
void LocationCompleter::switchToTab(BrowserWindow* window, int tab) void LocationCompleter::switchToTab(BrowserWindow* window, int tab)
{ {
Q_ASSERT(window); Q_ASSERT(window);
@ -328,15 +337,15 @@ void LocationCompleter::switchToTab(BrowserWindow* window, int tab)
} }
} }
void LocationCompleter::loadString(const QString &urlString) void LocationCompleter::loadRequest(const LoadRequest &request)
{ {
closePopup(); closePopup();
// Show url in locationbar // Show url in locationbar
emit showCompletion(urlString, false); emit showCompletion(request.url().toString(), false);
// Load url // Load request
emit loadCompletion(); emit loadRequested(request);
} }
void LocationCompleter::showPopup() void LocationCompleter::showPopup()

View File

@ -50,7 +50,6 @@ public slots:
signals: signals:
void showCompletion(const QString &completion, bool completeDomain); void showCompletion(const QString &completion, bool completeDomain);
void showDomainCompletion(const QString &completion); void showDomainCompletion(const QString &completion);
void loadCompletion();
void clearCompletion(); void clearCompletion();
void popupClosed(); void popupClosed();
void cancelRefreshJob(); void cancelRefreshJob();
@ -68,8 +67,9 @@ private slots:
void indexDeleteRequested(const QModelIndex &index); void indexDeleteRequested(const QModelIndex &index);
private: private:
LoadRequest createLoadRequest(const QModelIndex &index);
void switchToTab(BrowserWindow* window, int tab); void switchToTab(BrowserWindow* window, int tab);
void loadString(const QString &url); void loadRequest(const LoadRequest &reqeust);
void showPopup(); void showPopup();
void adjustPopupSize(); void adjustPopupSize();

View File

@ -75,7 +75,6 @@ LocationBar::LocationBar(BrowserWindow* window)
m_completer->setLocationBar(this); m_completer->setLocationBar(this);
connect(m_completer, SIGNAL(showCompletion(QString,bool)), this, SLOT(showCompletion(QString,bool))); connect(m_completer, SIGNAL(showCompletion(QString,bool)), this, SLOT(showCompletion(QString,bool)));
connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString))); connect(m_completer, SIGNAL(showDomainCompletion(QString)), this, SLOT(showDomainCompletion(QString)));
connect(m_completer, SIGNAL(loadCompletion()), this, SLOT(requestLoadUrl()));
connect(m_completer, SIGNAL(clearCompletion()), this, SLOT(clearCompletion())); connect(m_completer, SIGNAL(clearCompletion()), this, SLOT(clearCompletion()));
connect(m_completer, &LocationCompleter::loadRequested, this, &LocationBar::loadRequest); connect(m_completer, &LocationCompleter::loadRequested, this, &LocationBar::loadRequest);