LoadRequest LocationCompleter::createLoadRequest(const QModelIndex &index) { LoadRequest request; 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()) { const QString text = index.data(LocationCompleterModel::TitleRole).toString(); request = mApp->searchEnginesManager()->searchResult(LocationBar::searchEngine(), text); } else if (index.data(LocationCompleterModel::VisitSearchItemRole).toBool()) { const auto action = LocationBar::loadAction(m_originalText); switch (action.type) { case LocationBar::LoadAction::Url: case LocationBar::LoadAction::Search: request = action.loadRequest; break; case LocationBar::LoadAction::Bookmark: bookmark = action.bookmark; break; default: break; } } if (bookmark) { bookmark->updateVisitCount(); request = bookmark->url(); } return request; }
LoadRequest LocationBar::createLoadRequest() const { LoadRequest req; // Check for Search Engine shortcut int firstSpacePos = text().indexOf(QLatin1Char(' ')); if (firstSpacePos != -1) { const QString shortcut = text().left(firstSpacePos); const QString searchedString = text().mid(firstSpacePos).trimmed(); SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut); if (!en.name.isEmpty()) { req = mApp->searchEnginesManager()->searchResult(en, searchedString); } } // Check for Bookmark keyword QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(text()); if (!items.isEmpty()) { BookmarkItem* item = items.first(); item->updateVisitCount(); req.setUrl(item->url()); } if (req.isEmpty()) { const QUrl guessedUrl = WebView::guessUrlFromString(text()); if (!guessedUrl.isEmpty()) req.setUrl(guessedUrl); else req.setUrl(QUrl::fromEncoded(text().toUtf8())); } return req; }
void LocationCompleter::indexShiftActivated(const QModelIndex &index) { Q_ASSERT(index.isValid()); 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 int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt(); // Load url (instead of switching to tab) with shift activation if (tabPos > -1) { loadUrl(url); return; } closePopup(); // Clear locationbar emit clearCompletion(); // Open new window mApp->createWindow(Qz::BW_NewWindow, url); }
LoadRequest LocationBar::createLoadRequest() const { LoadRequest req; const QString &t = text().trimmed(); // Check for Search Engine shortcut int firstSpacePos = t.indexOf(QLatin1Char(' ')); if (firstSpacePos != -1) { const QString shortcut = t.left(firstSpacePos); const QString searchedString = t.mid(firstSpacePos).trimmed(); SearchEngine en = mApp->searchEnginesManager()->engineForShortcut(shortcut); if (!en.name.isEmpty()) { req = mApp->searchEnginesManager()->searchResult(en, searchedString); } } // Check for Bookmark keyword QList<BookmarkItem*> items = mApp->bookmarks()->searchKeyword(t); if (!items.isEmpty()) { BookmarkItem* item = items.at(0); item->updateVisitCount(); req.setUrl(item->url()); } if (req.isEmpty()) { // 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; }
void LocationCompleter::indexCtrlActivated(const QModelIndex &index) { Q_ASSERT(index.isValid()); 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(); // Clear locationbar emit clearCompletion(); // Open url in new tab m_window->tabWidget()->addView(url, title, Qz::NT_CleanSelectedTab); }
void LocationCompleter::indexActivated(const QModelIndex &index) { Q_ASSERT(index.isValid()); const QUrl url = index.data(LocationCompleterModel::UrlRole).toUrl(); const int tabPos = index.data(LocationCompleterModel::TabPositionTabRole).toInt(); // Switch to tab with simple index activation if (tabPos > -1) { BrowserWindow* window = static_cast<BrowserWindow*>(index.data(LocationCompleterModel::TabPositionWindowRole).value<void*>()); Q_ASSERT(window); switchToTab(window, tabPos); return; } if (index.data(LocationCompleterModel::BookmarkRole).toBool()) { BookmarkItem* bookmark = static_cast<BookmarkItem*>(index.data(LocationCompleterModel::BookmarkItemRole).value<void*>()); bookmark->updateVisitCount(); } loadUrl(url); }