diff --git a/src/lib/bookmarks/bookmarks.cpp b/src/lib/bookmarks/bookmarks.cpp index fcfa58f99..cfb1b5852 100644 --- a/src/lib/bookmarks/bookmarks.cpp +++ b/src/lib/bookmarks/bookmarks.cpp @@ -116,6 +116,13 @@ QList Bookmarks::searchBookmarks(const QString &string, int limit return items; } +QList Bookmarks::searchKeyword(const QString &keyword) const +{ + QList items; + searchKeyword(&items, m_root, keyword); + return items; +} + void Bookmarks::addBookmark(BookmarkItem* parent, BookmarkItem* item) { Q_ASSERT(parent); @@ -432,3 +439,25 @@ void Bookmarks::search(QList* items, BookmarkItem* parent, const break; } } + +void Bookmarks::searchKeyword(QList* items, BookmarkItem* parent, const QString &keyword) const +{ + Q_ASSERT(items); + Q_ASSERT(parent); + + switch (parent->type()) { + case BookmarkItem::Root: + case BookmarkItem::Folder: + foreach (BookmarkItem* child, parent->children()) + searchKeyword(items, child, keyword); + break; + + case BookmarkItem::Url: + if (parent->keyword() == keyword) + items->append(parent); + break; + + default: + break; + } +} diff --git a/src/lib/bookmarks/bookmarks.h b/src/lib/bookmarks/bookmarks.h index 7b71c8967..2bc621e93 100644 --- a/src/lib/bookmarks/bookmarks.h +++ b/src/lib/bookmarks/bookmarks.h @@ -55,6 +55,8 @@ public: QList searchBookmarks(const QUrl &url) const; // Search bookmarks for contains match through all properties QList searchBookmarks(const QString &string, int limit = -1, Qt::CaseSensitivity sensitive = Qt::CaseInsensitive) const; + // Search bookmarks for exact match of keyword + QList searchKeyword(const QString &keyword) const; void addBookmark(BookmarkItem* parent, BookmarkItem* item); void insertBookmark(BookmarkItem* parent, int row, BookmarkItem* item); @@ -88,6 +90,7 @@ private: void search(QList* items, BookmarkItem* parent, const QUrl &url) const; void search(QList* items, BookmarkItem* parent, const QString &string, int limit, Qt::CaseSensitivity sensitive) const; + void searchKeyword(QList* items, BookmarkItem* parent, const QString &keyword) const; BookmarkItem* m_root; BookmarkItem* m_folderToolbar; diff --git a/src/lib/navigation/locationbar.cpp b/src/lib/navigation/locationbar.cpp index 16d22401d..5a494f493 100644 --- a/src/lib/navigation/locationbar.cpp +++ b/src/lib/navigation/locationbar.cpp @@ -22,6 +22,8 @@ #include "webpage.h" #include "tabwidget.h" #include "bookmarksicon.h" +#include "bookmarks.h" +#include "bookmarkitem.h" #include "siteicon.h" #include "goicon.h" #include "rssicon.h" @@ -177,14 +179,20 @@ LoadRequest LocationBar::createLoadRequest() const } } + // Check for Bookmark keyword + QList items = mApp->bookmarks()->searchKeyword(text()); + if (!items.isEmpty()) { + BookmarkItem* item = items.first(); + item->updateVisitCount(); + req.setUrl(item->url()); + } + if (req.isEmpty()) { - QUrl guessedUrl = WebView::guessUrlFromString(text()); - if (!guessedUrl.isEmpty()) { + const QUrl guessedUrl = WebView::guessUrlFromString(text()); + if (!guessedUrl.isEmpty()) req.setUrl(guessedUrl); - } - else { + else req.setUrl(QUrl::fromEncoded(text().toUtf8())); - } } return req;