diff options
Diffstat (limited to 'src/urlbar')
-rw-r--r-- | src/urlbar/bookmarkwidget.cpp | 2 | ||||
-rw-r--r-- | src/urlbar/bookmarkwidget.h | 2 | ||||
-rw-r--r-- | src/urlbar/completionwidget.cpp | 9 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 59 | ||||
-rw-r--r-- | src/urlbar/listitem.h | 20 | ||||
-rw-r--r-- | src/urlbar/urlbar.cpp | 25 | ||||
-rw-r--r-- | src/urlbar/urlresolver.cpp | 301 | ||||
-rw-r--r-- | src/urlbar/urlresolver.h | 31 |
8 files changed, 304 insertions, 145 deletions
diff --git a/src/urlbar/bookmarkwidget.cpp b/src/urlbar/bookmarkwidget.cpp index bcf85e1f..0e05e776 100644 --- a/src/urlbar/bookmarkwidget.cpp +++ b/src/urlbar/bookmarkwidget.cpp @@ -30,7 +30,7 @@ // Local includes #include "application.h" -#include "bookmarksmanager.h" +#include "bookmarkprovider.h" #include "bookmarkowner.h" // KDE Includes diff --git a/src/urlbar/bookmarkwidget.h b/src/urlbar/bookmarkwidget.h index cdab328e..c3c15e18 100644 --- a/src/urlbar/bookmarkwidget.h +++ b/src/urlbar/bookmarkwidget.h @@ -44,7 +44,7 @@ class BookmarkWidget : public QFrame Q_OBJECT public: - BookmarkWidget(const KBookmark &bookmark, QWidget *parent = 0); + explicit BookmarkWidget(const KBookmark &bookmark, QWidget *parent = 0); ~BookmarkWidget(); void showAt(const QPoint &pos); diff --git a/src/urlbar/completionwidget.cpp b/src/urlbar/completionwidget.cpp index b77e2d7c..a9203bf7 100644 --- a/src/urlbar/completionwidget.cpp +++ b/src/urlbar/completionwidget.cpp @@ -153,13 +153,10 @@ void CompletionWidget::activateCurrentListItem() //update text of the url bar bar->blockSignals(true); //without compute suggestions - if (!widget->inherits("SearchListItem")) - bar->setQUrl( widget->url() ); - else - bar->setQUrl( _typedString ); + bar->setQUrl(widget->text()); bar->blockSignals(false); bar->setFocus(); - bar->setCursorPosition( bar->text().length() ); + bar->setCursorPosition(bar->text().length()); } @@ -240,7 +237,7 @@ bool CompletionWidget::eventFilter(QObject *obj, QEvent *ev) if( _currentIndex == -1) _currentIndex = 0; child = findChild<ListItem *>(QString::number(_currentIndex)); - if(child && _typedString == w->text()) + if(child) { emit chosenUrl(child->url(), Rekonq::CurrentTab); } diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp index f10cefd7..e9bb6fbb 100644 --- a/src/urlbar/listitem.cpp +++ b/src/urlbar/listitem.cpp @@ -139,6 +139,12 @@ KUrl ListItem::url() } +QString ListItem::text() +{ + return m_url.url(); +} + + void ListItem::nextItemSubChoice() { //will be override @@ -161,6 +167,7 @@ TypeIconLabel::TypeIconLabel(int type, QWidget *parent) if (type & UrlSearchItem::Browse) hLayout->addWidget(getIcon("applications-internet")); if (type & UrlSearchItem::Bookmark) hLayout->addWidget(getIcon("rating")); if (type & UrlSearchItem::History) hLayout->addWidget(getIcon("view-history")); + if (type & UrlSearchItem::Suggestion) hLayout->addWidget(getIcon("help-hint")); } @@ -297,6 +304,12 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q } +QString SearchListItem::text() +{ + return m_text; +} + + QString SearchListItem::searchItemTitle(QString engine, QString text) { return QString(i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for <b>%2</b>", engine, Qt::escape(text))); @@ -390,6 +403,42 @@ void EngineBar::selectNextEngine() // --------------------------------------------------------------- +SuggestionListItem::SuggestionListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) + : ListItem(item, parent) + , m_text(item.title) +{ + QHBoxLayout *hLayout = new QHBoxLayout; + hLayout->setSpacing(4); + + QString query = item.title; + KService::Ptr engine = SearchEngine::fromString(query); + if (engine) + { + query = query.remove(0, text.indexOf(SearchEngine::delimiter()) + 1); + } + else + { + engine = qobject_cast<CompletionWidget *>(parent)->searchEngine(); + } + + m_url = SearchEngine::buildQuery(engine, query); + + hLayout->addWidget(new IconLabel(SearchEngine::buildQuery(engine, ""), this)); + hLayout->addWidget(new TextLabel(item.title, text, this)); + hLayout->addWidget(new TypeIconLabel(item.type, this)); + + setLayout(hLayout); +} + + +QString SuggestionListItem::text() +{ + return m_text; +} + +// --------------------------------------------------------------- + + BrowseListItem::BrowseListItem(const UrlSearchItem &item, const QString &text, QWidget *parent) : ListItem(item, parent) { @@ -427,7 +476,15 @@ ListItem *ListItemFactory::create(const UrlSearchItem &item, const QString &text } else { - newItem = new PreviewListItem(item, text, parent); + + if (item.type & UrlSearchItem::Suggestion) + { + newItem = new SuggestionListItem(item, text, parent); + } + else + { + newItem = new PreviewListItem(item, text, parent); + } } } diff --git a/src/urlbar/listitem.h b/src/urlbar/listitem.h index dcb4f76d..06a02b80 100644 --- a/src/urlbar/listitem.h +++ b/src/urlbar/listitem.h @@ -61,7 +61,8 @@ public: void deactivate(); KUrl url(); - + virtual QString text(); + public slots: virtual void nextItemSubChoice(); @@ -153,6 +154,7 @@ class SearchListItem : public ListItem public: explicit SearchListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + QString text(); public slots: virtual void nextItemSubChoice(); @@ -174,6 +176,22 @@ private: // ------------------------------------------------------------------------- +class SuggestionListItem : public ListItem +{ + Q_OBJECT + +public: + SuggestionListItem(const UrlSearchItem &item, const QString &text, QWidget *parent = 0); + QString text(); + +private: + QString m_text; +}; + + +// ------------------------------------------------------------------------- + + class PreviewListItem : public ListItem { Q_OBJECT diff --git a/src/urlbar/urlbar.cpp b/src/urlbar/urlbar.cpp index e64959bd..c272d819 100644 --- a/src/urlbar/urlbar.cpp +++ b/src/urlbar/urlbar.cpp @@ -41,10 +41,11 @@ #include "webpage.h" #include "webview.h" #include "completionwidget.h" -#include "bookmarksmanager.h" +#include "bookmarkprovider.h" #include "bookmarkwidget.h" // KDE Includes +#include <KBookmarkManager> #include <KCompletionBox> #include <KStandardDirs> @@ -105,7 +106,7 @@ UrlBar::UrlBar(QWidget *parent) _tab = qobject_cast<WebTab *>(parent); connect(_tab, SIGNAL(loadProgressing()), this, SLOT(update())); - + connect(_tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(setQUrl(const QUrl &))); connect(_tab->view(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); connect(_tab->view(), SIGNAL(loadStarted()), this, SLOT(clearRightIcons())); @@ -114,13 +115,13 @@ UrlBar::UrlBar(QWidget *parent) _icon->setIcon(KIcon("bookmarks").pixmap(32,32, QIcon::Disabled)); connect(Application::bookmarkProvider()->bookmarkManager(), SIGNAL(changed(const QString &, const QString &)), this, SLOT(onBookmarksChanged())); connect(_icon, SIGNAL(clicked(const QPoint &)), this, SLOT(showBookmarkInfo(const QPoint &))); - + // load typed urls connect(this, SIGNAL(returnPressed(const QString &)), this, SLOT(loadTyped(const QString &))); _suggestionTimer->setSingleShot(true); connect(_suggestionTimer, SIGNAL(timeout()), this, SLOT(suggest())); - + activateSuggestions(true); } @@ -163,10 +164,10 @@ void UrlBar::activated(const KUrl& url, Rekonq::OpenType type) void UrlBar::paintEvent(QPaintEvent *event) -{ +{ QColor backgroundColor; QColor foregroundColor; - + if (_privateMode) { backgroundColor = QColor(220, 220, 220); // light gray @@ -199,7 +200,7 @@ void UrlBar::paintEvent(QPaintEvent *event) int r = (highlight.red()+2*backgroundColor.red())/3; int g = (highlight.green()+2*backgroundColor.green())/3; int b = (highlight.blue()+2*backgroundColor.blue())/3; - + QColor loadingColor(r, g, b); if (abs(loadingColor.lightness() - backgroundColor.lightness()) < 20) //eg. Gaia color scheme @@ -320,7 +321,7 @@ void UrlBar::loadFinished() _icon->setIcon(KIcon("bookmarks")); _icon->setToolTip(i18n("Edit this bookmark")); } - + // show KGet downloads?? if (!KStandardDirs::findExe("kget").isNull() && ReKonfig::kgetList()) { @@ -343,7 +344,7 @@ void UrlBar::loadFinished() } // we need to update urlbar after the right icon settings - // removing this code (where setStyleSheet automatically calls update) needs adding again + // removing this code (where setStyleSheet automatically calls update) needs adding again // an update call kDebug() << "resetting stylesheet"; int rightIconWidth = 25 * (_rightIconsList.count()); @@ -355,7 +356,7 @@ void UrlBar::showBookmarkInfo(const QPoint &pos) { if( _tab->url().scheme() == QL1S("about") ) return; - + KBookmark bookmark = Application::bookmarkProvider()->bookmarkForUrl(_tab->url()); IconButton *bt = qobject_cast<IconButton *>(this->sender()); @@ -367,7 +368,7 @@ void UrlBar::showBookmarkInfo(const QPoint &pos) bookmark = Application::bookmarkProvider()->rootGroup().addBookmark(_tab->view()->title(), _tab->url()); Application::bookmarkProvider()->bookmarkManager()->emitChanged(); } - + BookmarkWidget *widget = new BookmarkWidget(bookmark, window()); widget->showAt(pos); } @@ -480,7 +481,7 @@ void UrlBar::detectTypedString(const QString &typed) QTimer::singleShot(0, this, SLOT(suggest())); return; } - + if(_suggestionTimer->isActive()) _suggestionTimer->stop(); _suggestionTimer->start(50); diff --git a/src/urlbar/urlresolver.cpp b/src/urlbar/urlresolver.cpp index b762716a..d60dc563 100644 --- a/src/urlbar/urlresolver.cpp +++ b/src/urlbar/urlresolver.cpp @@ -30,10 +30,11 @@ // Local Includes #include "application.h" #include "historymanager.h" -#include "bookmarksmanager.h" +#include "bookmarkprovider.h" #include "searchengine.h" // KDE Includes +#include <KBookmark> #include <KUriFilter> #include <KCompletion> #include <KService> @@ -45,9 +46,9 @@ // defines #define MAX_ELEMENTS 10 +#define MIN_SUGGESTIONS 3 - -// NOTE +// NOTE // default kurifilter plugin list (at least in my box): // 1. "kshorturifilter" // 2. "kurisearchfilter" @@ -63,23 +64,24 @@ QRegExp UrlResolver::_browseRegexp; QRegExp UrlResolver::_searchEnginesRegexp; UrlResolver::UrlResolver(const QString &typedUrl) - : _typedString(typedUrl.trimmed()) + : QObject() + , _typedString(typedUrl.trimmed()) { if ( _browseRegexp.isEmpty() ) { kDebug() << "browse regexp empty. Setting value.."; - + QString protocol = "^(http://|https://|file://|ftp://|man:|info:|apt:)"; - + QString localhost = "^localhost"; - + QString local = "^/"; - + QString ipv4 = "^0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"\ "\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.0*([1-9]?\\d|1\\d\\d|2[0-4]\\d|25[0-5])"; - + QString ipv6 = "^([0-9a-fA-F]{4}|0)(\\:([0-9a-fA-F]{4}|0)){7}"; - + QString address = "[\\d\\w-.]+\\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|"\ "c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|"\ "h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|"\ @@ -87,19 +89,21 @@ UrlResolver::UrlResolver(const QString &typedUrl) "s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|"\ "y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|"\ "pro)"; - + _browseRegexp = QRegExp('(' + protocol + ")|(" + localhost + ")|(" + local + ")|(" + address + ")|(" + ipv6 + ")|(" + ipv4 +')'); } - + if ( _searchEnginesRegexp.isEmpty() ) { QString reg; QString engineUrl; - foreach(KService::Ptr s, SearchEngine::favorites()) + Q_FOREACH(KService::Ptr s, SearchEngine::favorites()) { engineUrl = QRegExp::escape(s->property("Query").toString()).replace("\\\\\\{@\\}","[\\d\\w-.]+"); - if (reg.isEmpty()) reg = "(" + engineUrl + ")"; - else reg = reg + "|(" + engineUrl + ")"; + if (reg.isEmpty()) + reg = '(' + engineUrl + ')'; + else + reg = reg + "|(" + engineUrl + ')'; } _searchEnginesRegexp = QRegExp(reg); } @@ -108,20 +112,9 @@ UrlResolver::UrlResolver(const QString &typedUrl) UrlSearchList UrlResolver::orderedSearchItems() { - // NOTE - // the logic here is : "we wanna suggest (at least) 10 elements" - // so we have (more or less) 2 from first results (1 from QUrl Resolutions, 1 from - // search engines). - // There are 8 remaining: if bookmarkResults + historyResults <= 8, catch all, else - // catch first 4 results from the two resulting lists :) - - QTime myTime; - myTime.start(); - - UrlSearchList list; - if( _typedString == QL1S("about:") ) { + UrlSearchList list; UrlSearchItem home(UrlSearchItem::Browse, QString("about:home"), QL1S("home") ); list << home; UrlSearchItem favs(UrlSearchItem::Browse, QString("about:favorites"), QL1S("favorites") ); @@ -137,147 +130,188 @@ UrlSearchList UrlResolver::orderedSearchItems() return list; } - + + _computedListsCount = 0; + + //compute lists + computeSuggestions(); + computeQurlFromUserInput(); + computeWebSearches(); + computeBookmarks(); + computeHistory(); + + QTime time; + time.start(); + + while (_computedListsCount < 5 && time.msec() < 1000) + { + Application::instance()->processEvents(QEventLoop::WaitForMoreEvents | QEventLoop::ExcludeUserInputEvents); + } + + return orderLists(); +} + + +UrlSearchList UrlResolver::orderLists() +{ + // NOTE + // the logic here is : "we wanna suggest (at least) 10 elements" + // so we have (more or less) 2 from first results (1 from QUrl Resolutions, 1 from + // search engines). + // There are 8 remaining: if bookmarkResults + historyResults <= 8, catch all, else + // catch first 4 results from the two resulting lists :) + + QTime myTime; + myTime.start(); + + UrlSearchList list; + if(_browseRegexp.indexIn(_typedString) != -1) { - list << qurlFromUserInputResolution(); - list << webSearchesResolution(); + list << _qurlFromUserInput; + list << _webSearches; } else { - list << webSearchesResolution(); - list << qurlFromUserInputResolution(); + list << _webSearches; + list << _qurlFromUserInput; } //find the history items that match the typed string - UrlSearchList historyList = historyResolution(); - UrlSearchItem privileged = privilegedItem(&historyList); - int historyResults = historyList.count(); - + UrlSearchItem privileged = privilegedItem(&_history); + int historyCount = _history.count(); + //find the bookmarks items that match the typed string - UrlSearchList bookmarksList = bookmarksResolution(); if (privileged.type == UrlSearchItem::Undefined) { - privileged = privilegedItem(&bookmarksList); + privileged = privilegedItem(&_bookmarks); } - else if(privileged.type == UrlSearchItem::History && bookmarksList.removeOne(privileged)) + else if(privileged.type == UrlSearchItem::History && _bookmarks.removeOne(privileged)) { privileged.type |= UrlSearchItem::Bookmark; } - int bookmarksResults = bookmarksList.count(); - + int bookmarksCount = _bookmarks.count(); + if (privileged.type != UrlSearchItem::Undefined) { list.prepend(privileged); } - - int availableEntries = MAX_ELEMENTS - list.count(); - - UrlSearchList commonList; - int commonResutls = 0; + + int availableEntries = MAX_ELEMENTS - list.count() - MIN_SUGGESTIONS; + + UrlSearchList common; + int commonCount = 0; //prefer items which are history items als well bookmarks item //if there are more than 1000 bookmark results, the performance impact is noticeable - if(bookmarksResults < 1000) + if(bookmarksCount < 1000) { //add as many items to the common list as there are available entries in the dropdown list UrlSearchItem urlSearchItem; - for(int i = 0; i < historyList.count(); i++) + for(int i = 0; i < _history.count(); i++) { - if (bookmarksList.removeOne(historyList.at(i))) + if (_bookmarks.removeOne(_history.at(i))) { - urlSearchItem = historyList.takeAt(i); + urlSearchItem = _history.takeAt(i); urlSearchItem.type |= UrlSearchItem::Bookmark; - commonList << urlSearchItem; - commonResutls++; - if(commonResutls >= availableEntries) + common << urlSearchItem; + commonCount++; + if(commonCount >= availableEntries) { break; } } } - - commonResutls = commonList.count(); - if(commonResutls >= availableEntries) + + commonCount = common.count(); + if(commonCount >= availableEntries) { - commonList = commonList.mid(0, availableEntries); - historyList = UrlSearchList(); - bookmarksList = UrlSearchList(); + common = common.mid(0, availableEntries); + _history = UrlSearchList(); + _bookmarks = UrlSearchList(); availableEntries = 0; } else //remove all items from the history and bookmarks list up to the remaining entries in the dropdown list { - availableEntries -= commonResutls; - if(historyResults >= availableEntries) + availableEntries -= commonCount; + if(historyCount >= availableEntries) { - historyList = historyList.mid(0, availableEntries); + _history = _history.mid(0, availableEntries); } - if(bookmarksResults >= availableEntries) + if(bookmarksCount >= availableEntries) { - bookmarksList = bookmarksList.mid(0, availableEntries); + _bookmarks = _bookmarks.mid(0, availableEntries); } } } else //if there are too many bookmarks items, remove all items up to the remaining entries in the dropdown list { - - if(historyResults >= availableEntries) + + if(historyCount >= availableEntries) { - historyList = historyList.mid(0, availableEntries); + _history = _history.mid(0, availableEntries); } - if(bookmarksResults >= availableEntries) + if(bookmarksCount >= availableEntries) { - bookmarksList = bookmarksList.mid(0, availableEntries); + _bookmarks = _bookmarks.mid(0, availableEntries); } UrlSearchItem urlSearchItem; - for(int i = 0; i < historyList.count(); i++) + for(int i = 0; i < _history.count(); i++) { - if (bookmarksList.removeOne(historyList.at(i))) + if (_bookmarks.removeOne(_history.at(i))) { - urlSearchItem = historyList.takeAt(i); + urlSearchItem = _history.takeAt(i); urlSearchItem.type |= UrlSearchItem::Bookmark; - commonList << urlSearchItem; + common << urlSearchItem; } } - - availableEntries -= commonList.count(); + + availableEntries -= common.count(); } - - historyResults = historyList.count(); - bookmarksResults = bookmarksList.count(); - commonResutls = commonList.count(); - + + historyCount = _history.count(); + bookmarksCount = _bookmarks.count(); + commonCount = common.count(); + //now fill the list to MAX_ELEMENTS if(availableEntries > 0) { int historyEntries = ((int) (availableEntries / 2)) + availableEntries % 2; int bookmarksEntries = availableEntries - historyEntries; - - if (historyResults >= historyEntries && bookmarksResults >= bookmarksEntries) + + if (historyCount >= historyEntries && bookmarksCount >= bookmarksEntries) { - historyList = historyList.mid(0, historyEntries); - bookmarksList = bookmarksList.mid(0, bookmarksEntries); + _history = _history.mid(0, historyEntries); + _bookmarks = _bookmarks.mid(0, bookmarksEntries); } - else if (historyResults < historyEntries && bookmarksResults >= bookmarksEntries) + else if (historyCount < historyEntries && bookmarksCount >= bookmarksEntries) { - if(historyResults + bookmarksResults > availableEntries) + if(historyCount + bookmarksCount > availableEntries) { - bookmarksList = bookmarksList.mid(0, availableEntries - historyResults); + _bookmarks = _bookmarks.mid(0, availableEntries - historyCount); } } - else if (historyResults >= historyEntries && bookmarksResults < bookmarksEntries) + else if (historyCount >= historyEntries && bookmarksCount < bookmarksEntries) { - if(historyResults + bookmarksResults > availableEntries) + if(historyCount + bookmarksCount > availableEntries) { - historyList = historyList.mid(0, availableEntries - bookmarksResults); + _history = _history.mid(0, availableEntries - bookmarksCount); } } } - - list = list + historyList + commonList + bookmarksList; + + availableEntries -= _history.count(); + availableEntries -= _bookmarks.count(); + + if (_suggestions.count() > availableEntries + MIN_SUGGESTIONS) + { + _suggestions = _suggestions.mid(0, availableEntries + MIN_SUGGESTIONS); + } + + list = list + _history + common + _bookmarks + _suggestions; qWarning() << "orderedSearchItems leave: " << " elapsed: " << myTime.elapsed(); - + return list; } @@ -286,70 +320,103 @@ UrlSearchList UrlResolver::orderedSearchItems() // PRIVATE ENGINES -// STEP 1 = QUrl from User Input (easily the best solution... ) -UrlSearchList UrlResolver::qurlFromUserInputResolution() +//QUrl from User Input (easily the best solution... ) +void UrlResolver::computeQurlFromUserInput() { - UrlSearchList list; - QString url2 = _typedString; - QUrl urlFromUserInput = QUrl::fromUserInput(url2); + QString url = _typedString; + QUrl urlFromUserInput = QUrl::fromUserInput(url); if (urlFromUserInput.isValid()) { QString gTitle = i18nc("Browse a website", "Browse"); UrlSearchItem gItem(UrlSearchItem::Browse, urlFromUserInput.toString(), gTitle); - list << gItem; + _qurlFromUserInput << gItem; } - return list; + _computedListsCount++; } -// STEP 2 = Web Searches -UrlSearchList UrlResolver::webSearchesResolution() +//webSearches +void UrlResolver::computeWebSearches() { - return UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, QString(), QString()); + _webSearches = (UrlSearchList() << UrlSearchItem(UrlSearchItem::Search, QString(), QString())); + _computedListsCount++; } -// STEP 3 = history completion -UrlSearchList UrlResolver::historyResolution() +//history +void UrlResolver::computeHistory() { QList<HistoryItem> found = Application::historyManager()->find(_typedString); qSort(found); - UrlSearchList list; - foreach (HistoryItem i, found) + Q_FOREACH(const HistoryItem &i, found) { if (_searchEnginesRegexp.indexIn(i.url) == -1) //filter all urls that are search engine results { UrlSearchItem gItem(UrlSearchItem::History, i.url, i.title); - list << gItem; + _history << gItem; } } - return list; + + _computedListsCount++; } -// STEP 4 = bookmarks completion -UrlSearchList UrlResolver::bookmarksResolution() +// bookmarks +void UrlResolver::computeBookmarks() { - UrlSearchList list; QList<KBookmark> found = Application::bookmarkProvider()->find(_typedString); - foreach (KBookmark b, found) + + Q_FOREACH(const KBookmark &b, found) { UrlSearchItem gItem(UrlSearchItem::Bookmark, b.url().url(), b.fullText()); - list << gItem; + _bookmarks << gItem; } - return list; + + _computedListsCount++; +} + + +//opensearch suggestion +void UrlResolver::computeSuggestions() +{ + if (Application::opensearchManager()->isSuggestionAvailable()) + { + connect(Application::opensearchManager(), + SIGNAL(suggestionReceived(const QStringList &)), + this, + SLOT(suggestionsReceived(const QStringList &))); + + Application::opensearchManager()->requestSuggestion(_typedString); + } + else + { + _computedListsCount++; + } +} + + +void UrlResolver::suggestionsReceived(const QStringList &suggestion) +{ + + foreach (QString s, suggestion) + { + UrlSearchItem gItem(UrlSearchItem::Suggestion, s, s); + _suggestions << gItem; + } + + _computedListsCount++; } UrlSearchItem UrlResolver::privilegedItem(UrlSearchList* list) { UrlSearchItem item; - QString dot = QString(QL1C('.')); + QString dot = QString(QL1C('.')); QString test1 = QString(QL1C('/')) + _typedString + dot; QString test2 = dot + _typedString + dot; - + for(int i = 0; i<list->count(); i++) { item = list->at(i); diff --git a/src/urlbar/urlresolver.h b/src/urlbar/urlresolver.h index c79ce184..f72d6731 100644 --- a/src/urlbar/urlresolver.h +++ b/src/urlbar/urlresolver.h @@ -38,6 +38,7 @@ // Qt Includes #include <QString> #include <QList> +#include <QStringList> class UrlSearchItem { @@ -50,6 +51,7 @@ public: Browse = 0x00000010, History = 0x00000100, Bookmark = 0x00001000, + Suggestion = 0x00010000, }; int type; @@ -93,8 +95,10 @@ typedef QList <UrlSearchItem> UrlSearchList; // ---------------------------------------------------------------------- -class UrlResolver +class UrlResolver : public QObject { + Q_OBJECT + public: UrlResolver(const QString &typedUrl); @@ -103,14 +107,29 @@ public: private: QString _typedString; - UrlSearchList webSearchesResolution(); - UrlSearchList historyResolution(); - UrlSearchList qurlFromUserInputResolution(); - UrlSearchList bookmarksResolution(); + UrlSearchList _webSearches; + UrlSearchList _qurlFromUserInput; + UrlSearchList _history; + UrlSearchList _bookmarks; + UrlSearchList _suggestions; + + void computeWebSearches(); + void computeHistory(); + void computeQurlFromUserInput(); + void computeBookmarks(); + void computeSuggestions(); + + int _computedListsCount; + UrlSearchItem privilegedItem(UrlSearchList* list); - + UrlSearchList orderLists(); + static QRegExp _browseRegexp; static QRegExp _searchEnginesRegexp; + +private slots: + void suggestionsReceived(const QStringList &suggestion); + }; // ------------------------------------------------------------------------------ |