summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPierre Rossi <pierre.rossi@nokia.com>2010-08-24 13:06:02 +0200
committerPierre Rossi <pierre.rossi@nokia.com>2010-08-25 11:02:57 +0200
commit8021b32b5288de901ec2c1defb3712211598925a (patch)
treed7810d9e3c205b5ae8520d07bce6507112e4ef57 /src
parentSVN_SILENT made messages (.desktop file) (diff)
downloadrekonq-8021b32b5288de901ec2c1defb3712211598925a.tar.xz
Awesome bar: support for multiple word search.
Also support searches starting by i (without messing with the <i> for urls) and page titles with characters such as '<' or '>'.
Diffstat (limited to 'src')
-rw-r--r--src/bookmarks/bookmarkprovider.cpp16
-rw-r--r--src/history/historymanager.cpp14
-rw-r--r--src/urlbar/listitem.cpp17
3 files changed, 39 insertions, 8 deletions
diff --git a/src/bookmarks/bookmarkprovider.cpp b/src/bookmarks/bookmarkprovider.cpp
index f07c5164..ec02ed31 100644
--- a/src/bookmarks/bookmarkprovider.cpp
+++ b/src/bookmarks/bookmarkprovider.cpp
@@ -253,9 +253,21 @@ void BookmarkProvider::find(QList<KBookmark> *list, const KBookmark &bookmark, c
for (KBookmark bm = group.first(); !bm.isNull(); bm = group.next(bm))
find(list, bm, text);
}
- else if (bookmark.url().url().contains(text) || bookmark.fullText().contains(text))
+ else
{
- *list << bookmark;
+ QStringList words = text.split(" ");
+ bool matches = true;
+ foreach (const QString &word, words)
+ {
+ if (!bookmark.url().url().contains(word, Qt::CaseInsensitive)
+ && !bookmark.fullText().contains(word, Qt::CaseInsensitive))
+ {
+ matches = false;
+ break;
+ }
+ }
+ if (matches)
+ *list << bookmark;
}
}
diff --git a/src/history/historymanager.cpp b/src/history/historymanager.cpp
index 5cd85cd7..4a3039f3 100644
--- a/src/history/historymanager.cpp
+++ b/src/history/historymanager.cpp
@@ -239,8 +239,18 @@ QList<HistoryItem> HistoryManager::find(const QString &text)
{
int index = m_historyFilterModel->historyLocation(url);
HistoryItem item = m_history.at(index);
-
- if(url.contains(text) || item.title.contains(text))
+
+ QStringList words = text.split(" ");
+ bool matches = true;
+ foreach (const QString &word, words)
+ {
+ if (!url.contains(word, Qt::CaseInsensitive)
+ && !item.title.contains(word, Qt::CaseInsensitive)) {
+ matches = false;
+ break;
+ }
+ }
+ if (matches)
list << item;
}
diff --git a/src/urlbar/listitem.cpp b/src/urlbar/listitem.cpp
index e9bb6fbb..5bd2253f 100644
--- a/src/urlbar/listitem.cpp
+++ b/src/urlbar/listitem.cpp
@@ -200,8 +200,17 @@ TextLabel::TextLabel(const QString &text, const QString &textToPointOut, QWidget
: QLabel(parent)
{
QString t = text;
- if (!textToPointOut.isEmpty())
- t = t.replace(QRegExp('(' + textToPointOut + ')', Qt::CaseInsensitive), "<b>\\1</b>");
+ const bool wasItalic = t.startsWith("<i>");
+ if (wasItalic)
+ t.remove(QRegExp("<[/ib]*>"));
+ t = Qt::escape(t);
+ QStringList words = textToPointOut.split(" ");
+ foreach (const QString &wordToPointOut, words) {
+ if (!wordToPointOut.isEmpty())
+ t.replace(QRegExp('(' + wordToPointOut + ')', Qt::CaseInsensitive), "<b>\\1</b>");
+ }
+ if (wasItalic)
+ t = QL1S("<i>") + t + QL1S("</i>");
setText(t);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum);
@@ -286,7 +295,7 @@ SearchListItem::SearchListItem(const UrlSearchItem &item, const QString &text, Q
m_url = SearchEngine::buildQuery(engine, query);
m_iconLabel = new IconLabel("edit-find", this); //TODO: get the default engine icon (will be easy in KDE SC 4.5)
- m_titleLabel = new TextLabel(searchItemTitle(engine->name(), query), QString(), this);
+ m_titleLabel = new TextLabel(searchItemTitle(engine->name(), query), query, this);
m_engineBar = new EngineBar(engine, parent);
QHBoxLayout *hLayout = new QHBoxLayout;
@@ -312,7 +321,7 @@ QString SearchListItem::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)));
+ return QString(i18nc("%1=search engine, e.g. Google, Wikipedia %2=text to search for", "Search %1 for %2", engine, Qt::escape(text)));
}