diff options
-rw-r--r-- | src/bookmarks/bookmarkprovider.cpp | 16 | ||||
-rw-r--r-- | src/history/historymanager.cpp | 14 | ||||
-rw-r--r-- | src/urlbar/listitem.cpp | 17 | ||||
-rw-r--r-- | src/websnap.cpp | 13 |
4 files changed, 40 insertions, 20 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))); } diff --git a/src/websnap.cpp b/src/websnap.cpp index 1405fb6e..afa08c64 100644 --- a/src/websnap.cpp +++ b/src/websnap.cpp @@ -185,18 +185,7 @@ QString WebSnap::imagePathFromUrl(const KUrl &url) { QUrl temp = QUrl(url.url()); QString name = temp.toString(QUrl::RemoveScheme | QUrl::RemoveUserInfo | QUrl::StripTrailingSlash); - - // TODO learn Regular Expressions :) - // and implement something better here.. - name.remove('/'); - name.remove('&'); - name.remove('.'); - name.remove('-'); - name.remove('_'); - name.remove('?'); - name.remove('='); - name.remove('+'); - + name.remove(QRegExp(QL1S("[&+=_?./-]"))); return KStandardDirs::locateLocal("cache", QString("thumbs/") + name + ".png", true); } |