Commit 531d7d2c authored by Stefan Brüns's avatar Stefan Brüns

[Bookmarks Runner] Remove BuildQuery Functor class

Instead of constructing the query string on each favicon fetch just use
the (fixed) sql query string.

Test Plan:
Switch default "Web browser" in Applications to Chrome/Chromium
Query bookmark with krunner, or e.g.
qdbus-qt5 org.kde.krunner /App org.kde.krunner.App.querySingleRunner bookmarks Phabricator

Reviewers: #frameworks, davidedmundson

Reviewed By: davidedmundson

Subscribers: plasma-devel

Tags: #plasma

Differential Revision:
parent c7e6b584
......@@ -35,17 +35,6 @@
#include <QSqlError>
#include <QSqlRecord>
class StaticQuery : public BuildQuery {
StaticQuery(const QString &query) : m_query(query) {}
QString query() const override {
return m_query;
const QString m_query;
FaviconFromBlob *FaviconFromBlob::chrome(const QString &profileDirectory, QObject *parent)
QString profileName = QFileInfo(profileDirectory).fileName();
......@@ -65,7 +54,7 @@ FaviconFromBlob *FaviconFromBlob::chrome(const QString &profileDirectory, QObjec
"WHERE page_url = :url LIMIT 1;");
return new FaviconFromBlob(profileName, new StaticQuery(faviconQuery), QStringLiteral("image_data"), fetchSqlite, parent);
return new FaviconFromBlob(profileName, faviconQuery, QStringLiteral("image_data"), fetchSqlite, parent);
FaviconFromBlob *FaviconFromBlob::firefox(FetchSqlite *fetchSqlite, QObject *parent)
......@@ -75,12 +64,12 @@ FaviconFromBlob *FaviconFromBlob::firefox(FetchSqlite *fetchSqlite, QObject *par
" INNER JOIN moz_icons_to_pages ON = moz_icons_to_pages.icon_id" \
" INNER JOIN moz_pages_w_icons ON moz_icons_to_pages.page_id =" \
" WHERE moz_pages_w_icons.page_url = :url LIMIT 1;");
return new FaviconFromBlob(QStringLiteral("firefox-default"), new StaticQuery(faviconQuery), QStringLiteral("data"), fetchSqlite, parent);
return new FaviconFromBlob(QStringLiteral("firefox-default"), faviconQuery, QStringLiteral("data"), fetchSqlite, parent);
FaviconFromBlob::FaviconFromBlob(const QString &profileName, BuildQuery *buildQuery, const QString &blobColumn, FetchSqlite *fetchSqlite, QObject *parent)
: Favicon(parent), m_buildQuery(buildQuery), m_blobcolumn(blobColumn), m_fetchsqlite(fetchSqlite)
FaviconFromBlob::FaviconFromBlob(const QString &profileName, const QString &query, const QString &blobColumn, FetchSqlite *fetchSqlite, QObject *parent)
: Favicon(parent), m_query(query), m_blobcolumn(blobColumn), m_fetchsqlite(fetchSqlite)
m_profileCacheDirectory = QStringLiteral("%1/KRunner-Favicons-%2")
.arg(QStandardPaths::writableLocation(QStandardPaths::CacheLocation), profileName);
......@@ -92,7 +81,6 @@ FaviconFromBlob::FaviconFromBlob(const QString &profileName, BuildQuery *buildQu
delete m_buildQuery;
void FaviconFromBlob::prepare()
......@@ -120,7 +108,7 @@ QIcon FaviconFromBlob::iconFor(const QString &url)
if(!iconFile.exists()) {
QMap<QString,QVariant> bindVariables;
bindVariables.insert(QStringLiteral(":url"), url);
QList<QVariantMap> faviconFound = m_fetchsqlite->query(m_buildQuery, bindVariables);
QList<QVariantMap> faviconFound = m_fetchsqlite->query(m_query, bindVariables);
if(faviconFound.isEmpty()) return defaultIcon();
QByteArray iconData = faviconFound.first().value(m_blobcolumn).toByteArray();
......@@ -39,9 +39,9 @@ public Q_SLOTS:
void teardown() override;
FaviconFromBlob(const QString &profileName, BuildQuery *buildQuery, const QString &blobColumn, FetchSqlite *fetchSqlite, QObject *parent = nullptr);
FaviconFromBlob(const QString &profileName, const QString &query, const QString &blobColumn, FetchSqlite *fetchSqlite, QObject *parent = nullptr);
QString m_profileCacheDirectory;
BuildQuery *m_buildQuery;
QString m_query;
QString const m_blobcolumn;
FetchSqlite *m_fetchsqlite;
void cleanCacheDirectory();
......@@ -65,11 +65,6 @@ void FetchSqlite::teardown()
QList<QVariantMap> FetchSqlite::query(BuildQuery *buildQuery, QMap<QString, QVariant> bindObjects)
return query(buildQuery->query(), bindObjects);
QList<QVariantMap> FetchSqlite::query(const QString &sql, QMap<QString, QVariant> bindObjects)
QMutexLocker lock(&m_mutex);
......@@ -31,12 +31,6 @@
#include <QMutex>
class BuildQuery {
virtual QString query() const = 0;
virtual ~BuildQuery() {}
class FetchSqlite : public QObject
......@@ -46,7 +40,6 @@ public:
void prepare();
void teardown();
QList<QVariantMap> query(const QString &sql, QMap<QString,QVariant> bindObjects);
QList<QVariantMap> query(BuildQuery *buildQuery, QMap<QString,QVariant> bindObjects);
QList<QVariantMap> query(const QString &sql);
QStringList tables(QSql::TableType type = QSql::Tables);
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