diff --git a/src/lib/bookmarks/bookmarkstools.cpp b/src/lib/bookmarks/bookmarkstools.cpp index f522fdfcc..888360754 100644 --- a/src/lib/bookmarks/bookmarkstools.cpp +++ b/src/lib/bookmarks/bookmarkstools.cpp @@ -389,7 +389,9 @@ void BookmarksTools::addUrlToMenu(QObject* receiver, Menu* menu, BookmarkItem* b Action* act = new Action(menu); QString title = QFontMetrics(act->font()).elidedText(bookmark->title(), Qt::ElideRight, 250); act->setText(title); - act->setIcon(bookmark->icon()); + IconProvider::imageForUrlAsync(bookmark->url(), act, [=](const QImage &img) { + act->setIcon(QIcon(QPixmap::fromImage(img))); + }); act->setData(QVariant::fromValue(static_cast(bookmark))); act->setIconVisibleInMenu(true); diff --git a/src/lib/tools/iconprovider.cpp b/src/lib/tools/iconprovider.cpp index 2bf80e045..661c7bec5 100644 --- a/src/lib/tools/iconprovider.cpp +++ b/src/lib/tools/iconprovider.cpp @@ -25,6 +25,8 @@ #include #include +#include +#include Q_GLOBAL_STATIC(IconProvider, qz_icon_provider) @@ -179,7 +181,7 @@ QImage IconProvider::imageForUrl(const QUrl &url) query.addBindValue(QString("%1%").arg(QzTools::escapeSqlString(QString::fromUtf8(url.toEncoded(QUrl::RemoveFragment))))); query.addBindValue(QL1S("!")); - query.exec(); + query = SqlDatabase::instance()->exec(query); if (query.next()) { return QImage::fromData(query.value(0).toByteArray()); @@ -188,6 +190,16 @@ QImage IconProvider::imageForUrl(const QUrl &url) return IconProvider::emptyWebImage(); } +void IconProvider::imageForUrlAsync(const QUrl &url, QObject *receiver, std::function callback) +{ + QFutureWatcher *watcher = new QFutureWatcher(); + connect(watcher, &QFutureWatcher::finished, receiver, [=]() { + watcher->deleteLater(); + callback(watcher->result()); + }); + watcher->setFuture(QtConcurrent::run(imageForUrl, url)); +} + QIcon IconProvider::iconForDomain(const QUrl &url) { return instance()->iconFromImage(imageForDomain(url)); diff --git a/src/lib/tools/iconprovider.h b/src/lib/tools/iconprovider.h index c2e85b59e..e7543757b 100644 --- a/src/lib/tools/iconprovider.h +++ b/src/lib/tools/iconprovider.h @@ -23,6 +23,8 @@ #include #include +#include + #include "qzcommon.h" class QIcon; @@ -59,6 +61,7 @@ class QUPZILLA_EXPORT IconProvider : public QWidget // Icon for url (only available for urls in history) static QIcon iconForUrl(const QUrl &url); static QImage imageForUrl(const QUrl &url); + static void imageForUrlAsync(const QUrl &url, QObject *receiver, std::function callback); // Icon for domain (only available for urls in history) static QIcon iconForDomain(const QUrl &url);