mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
[Bookmarks] Use keyword as a shortcut for bookmark url in LocationBar
It is now possible to load bookmarks only with entering its keyword in LocationBar and then pressing Enter (no need to select the bookmark from popup completion).
This commit is contained in:
parent
6bdc6f90ce
commit
19800b174b
|
@ -116,6 +116,13 @@ QList<BookmarkItem*> Bookmarks::searchBookmarks(const QString &string, int limit
|
|||
return items;
|
||||
}
|
||||
|
||||
QList<BookmarkItem*> Bookmarks::searchKeyword(const QString &keyword) const
|
||||
{
|
||||
QList<BookmarkItem*> 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<BookmarkItem*>* items, BookmarkItem* parent, const
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Bookmarks::searchKeyword(QList<BookmarkItem*>* 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
QList<BookmarkItem*> searchBookmarks(const QUrl &url) const;
|
||||
// Search bookmarks for contains match through all properties
|
||||
QList<BookmarkItem*> searchBookmarks(const QString &string, int limit = -1, Qt::CaseSensitivity sensitive = Qt::CaseInsensitive) const;
|
||||
// Search bookmarks for exact match of keyword
|
||||
QList<BookmarkItem*> 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<BookmarkItem*>* items, BookmarkItem* parent, const QUrl &url) const;
|
||||
void search(QList<BookmarkItem*>* items, BookmarkItem* parent, const QString &string, int limit, Qt::CaseSensitivity sensitive) const;
|
||||
void searchKeyword(QList<BookmarkItem*>* items, BookmarkItem* parent, const QString &keyword) const;
|
||||
|
||||
BookmarkItem* m_root;
|
||||
BookmarkItem* m_folderToolbar;
|
||||
|
|
|
@ -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<BookmarkItem*> 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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user