Commit c55ffdca authored by Alexander Lohnau's avatar Alexander Lohnau 💬

BoorkmarksRunner: Set QIcon instead of Favicon pointer in BookmarkMatch

Summary:
Before: A pointer to the favicon gets written in the BookmarkMatch and using this pointer the icon gets created when the Plasma::QueryMatch gets created.
Now: Using the favicon pointer the icon gets created and written to the BookmarkMatch, when the QueryMatch is created the icon value is read.

This makes the code easier to understand and the BookmarkMatch is independent of the Favicon class.

Test Plan: Should compile and display icons.

Reviewers: apol, broulik, davidedmundson

Reviewed By: davidedmundson

Subscribers: bruns, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28439
parent 40fc426b
......@@ -21,18 +21,17 @@
#include "bookmarkmatch.h"
#include <QVariant>
#include "favicon.h"
// TODO: test
BookmarkMatch::BookmarkMatch(Favicon *favicon, const QString& searchTerm, const QString& bookmarkTitle, const QString& bookmarkURL, const QString& description )
: m_favicon(favicon), m_searchTerm(searchTerm), m_bookmarkTitle(bookmarkTitle), m_bookmarkURL(bookmarkURL), m_description(description)
BookmarkMatch::BookmarkMatch(const QIcon &icon, const QString& searchTerm, const QString& bookmarkTitle, const QString& bookmarkURL, const QString& description )
: m_icon(icon), m_searchTerm(searchTerm), m_bookmarkTitle(bookmarkTitle), m_bookmarkURL(bookmarkURL), m_description(description)
{
}
Plasma::QueryMatch BookmarkMatch::asQueryMatch( Plasma::AbstractRunner* runner )
{
Plasma::QueryMatch::Type type = Plasma::QueryMatch::NoMatch;
Plasma::QueryMatch::Type type;
qreal relevance = 0;
if (m_bookmarkTitle.compare(m_searchTerm, Qt::CaseInsensitive) == 0 ||
......@@ -60,7 +59,7 @@ Plasma::QueryMatch BookmarkMatch::asQueryMatch( Plasma::AbstractRunner* runner )
Plasma::QueryMatch match(runner);
match.setType(type);
match.setRelevance(relevance);
match.setIcon(m_favicon->iconFor(m_bookmarkURL));
match.setIcon(m_icon);
match.setSubtext(m_bookmarkURL);
// Try to set the following as text in this order: name, description, url
......
......@@ -24,19 +24,19 @@
#include <QString>
#include <QList>
#include <krunner/querymatch.h>
#include <KRunner/QueryMatch>
#include <QIcon>
class Favicon;
class BookmarkMatch
{
public:
BookmarkMatch(Favicon *favicon, const QString &searchTerm, const QString &bookmarkTitle, const QString &bookmarkURL, const QString &description = QString());
BookmarkMatch(const QIcon &icon, const QString &searchTerm, const QString &bookmarkTitle, const QString &bookmarkURL, const QString &description = QString());
void addTo(QList< BookmarkMatch >& listOfResults, bool addEvenOnNoMatch);
Plasma::QueryMatch asQueryMatch(Plasma::AbstractRunner *runner);
private:
bool matches(const QString &search, const QString &matchingField);
private:
Favicon * m_favicon;
QIcon m_icon;
QString m_searchTerm;
QString m_bookmarkTitle;
QString m_bookmarkURL;
......
......@@ -82,12 +82,11 @@ QList<BookmarkMatch> Chrome::match(const QString &term, bool addEveryThing, Prof
QList<BookmarkMatch> results;
const auto bookmarks = profileBookmarks->bookmarks();
Favicon *favicon = profileBookmarks->profile().favicon();
for (const QJsonValue &bookmarkValue : bookmarks) {
const QJsonObject bookmark = bookmarkValue.toObject();
QString url = bookmark.value(QStringLiteral("url")).toString();
BookmarkMatch bookmarkMatch(profileBookmarks->profile().favicon(), term, bookmark.value(QStringLiteral("name")).toString(), url);
const QString url = bookmark.value(QStringLiteral("url")).toString();
BookmarkMatch bookmarkMatch(favicon->iconFor(url), term, bookmark.value(QStringLiteral("name")).toString(), url);
bookmarkMatch.addTo(results, addEveryThing);
}
return results;
......
......@@ -137,7 +137,8 @@ QList< BookmarkMatch > Firefox::match(const QString& term, bool addEverything)
}
for (auto result = uniqueResults.constKeyValueBegin(); result != uniqueResults.constKeyValueEnd(); ++result) {
BookmarkMatch bookmarkMatch(m_favicon, term, (*result).second, (*result).first);
const QString url = (*result).first;
BookmarkMatch bookmarkMatch(m_favicon->iconFor(url), term, (*result).second, url);
bookmarkMatch.addTo(matches, addEverything);
}
......
......@@ -84,8 +84,9 @@ QList< BookmarkMatch > KDEBrowser::match(const QString& term, bool addEverything
continue;
}
BookmarkMatch bookmarkMatch(m_favicon, term, bookmark.text(), bookmark.url().url() );
const QString url = bookmark.url().url();
BookmarkMatch bookmarkMatch(m_favicon->iconFor(url), term, bookmark.text(), url);
bookmarkMatch.addTo(matches, addEverything);
bookmark = bookmarkGroup.next(bookmark);
......
......@@ -61,7 +61,7 @@ QList<BookmarkMatch> Opera::match( const QString& term, bool addEverything )
}
}
BookmarkMatch bookmarkMatch(m_favicon, term, name, url, description);
BookmarkMatch bookmarkMatch(m_favicon->iconFor(url), term, name, url, description);
bookmarkMatch.addTo(matches, addEverything);
}
return matches;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment