mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
Drop the threaded icon loading completely
Also fix icons in buttons in bookmarks toolbar
This commit is contained in:
parent
c2d38dfb7d
commit
34cc74ab18
|
@ -87,9 +87,7 @@ void BookmarksMenu::menuAboutToShow()
|
|||
foreach (QAction *action, menu->actions()) {
|
||||
BookmarkItem *item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
||||
if (item && item->type() == BookmarkItem::Url && action->icon().isNull()) {
|
||||
IconProvider::imageForUrlAsync(item->url(), action, [=](const QImage &img) {
|
||||
action->setIcon(QIcon(QPixmap::fromImage(img)));
|
||||
});
|
||||
action->setIcon(item->icon());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,12 +126,19 @@ void BookmarksToolbarButton::createMenu()
|
|||
Menu* m = qobject_cast<Menu*>(menu());
|
||||
Q_ASSERT(m);
|
||||
|
||||
foreach (BookmarkItem* child, m_bookmark->children()) {
|
||||
BookmarksTools::addActionToMenu(this, m, child);
|
||||
}
|
||||
BookmarksTools::addFolderContentsToMenu(this, m, m_bookmark);
|
||||
}
|
||||
|
||||
if (m->isEmpty()) {
|
||||
m->addAction(Bookmarks::tr("Empty"))->setDisabled(true);
|
||||
void BookmarksToolbarButton::menuAboutToShow()
|
||||
{
|
||||
Q_ASSERT(qobject_cast<Menu*>(sender()));
|
||||
Menu *menu = static_cast<Menu*>(sender());
|
||||
|
||||
foreach (QAction *action, menu->actions()) {
|
||||
BookmarkItem *item = static_cast<BookmarkItem*>(action->data().value<void*>());
|
||||
if (item && item->type() == BookmarkItem::Url && action->icon().isNull()) {
|
||||
action->setIcon(item->icon());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -216,9 +223,8 @@ void BookmarksToolbarButton::init()
|
|||
|
||||
if (m_bookmark->isFolder()) {
|
||||
Menu* m = new Menu(this);
|
||||
connect(m, SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||
connect(m, SIGNAL(menuMiddleClicked(Menu*)), this, SLOT(menuMiddleClicked(Menu*)));
|
||||
setMenu(m);
|
||||
createMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ public:
|
|||
private slots:
|
||||
void createMenu();
|
||||
|
||||
void menuAboutToShow();
|
||||
void menuMiddleClicked(Menu* menu);
|
||||
void bookmarkActivated(BookmarkItem* item = 0);
|
||||
void bookmarkCtrlActivated(BookmarkItem* item = 0);
|
||||
|
|
|
@ -365,20 +365,12 @@ void BookmarksTools::addFolderToMenu(QObject* receiver, Menu* menu, BookmarkItem
|
|||
QString title = QFontMetrics(m->font()).elidedText(folder->title(), Qt::ElideRight, 250);
|
||||
m->setTitle(title);
|
||||
m->setIcon(folder->icon());
|
||||
QObject::connect(m, SIGNAL(aboutToShow()), receiver, SLOT(menuAboutToShow()));
|
||||
QObject::connect(m, SIGNAL(menuMiddleClicked(Menu*)), receiver, SLOT(menuMiddleClicked(Menu*)));
|
||||
|
||||
addFolderContentsToMenu(receiver, m, folder);
|
||||
|
||||
QAction* act = menu->addMenu(m);
|
||||
act->setData(QVariant::fromValue<void*>(static_cast<void*>(folder)));
|
||||
act->setIconVisibleInMenu(true);
|
||||
|
||||
foreach (BookmarkItem* child, folder->children()) {
|
||||
addActionToMenu(receiver, m, child);
|
||||
}
|
||||
|
||||
if (m->isEmpty()) {
|
||||
m->addAction(Bookmarks::tr("Empty"))->setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void BookmarksTools::addUrlToMenu(QObject* receiver, Menu* menu, BookmarkItem* bookmark)
|
||||
|
@ -390,7 +382,6 @@ 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(false));
|
||||
act->setData(QVariant::fromValue<void*>(static_cast<void*>(bookmark)));
|
||||
act->setIconVisibleInMenu(true);
|
||||
|
||||
|
@ -411,6 +402,20 @@ void BookmarksTools::addSeparatorToMenu(Menu* menu, BookmarkItem* separator)
|
|||
menu->addSeparator();
|
||||
}
|
||||
|
||||
void BookmarksTools::addFolderContentsToMenu(QObject *receiver, Menu *menu, BookmarkItem *folder)
|
||||
{
|
||||
QObject::connect(menu, SIGNAL(aboutToShow()), receiver, SLOT(menuAboutToShow()));
|
||||
QObject::connect(menu, SIGNAL(menuMiddleClicked(Menu*)), receiver, SLOT(menuMiddleClicked(Menu*)));
|
||||
|
||||
foreach (BookmarkItem* child, folder->children()) {
|
||||
addActionToMenu(receiver, menu, child);
|
||||
}
|
||||
|
||||
if (menu->isEmpty()) {
|
||||
menu->addAction(Bookmarks::tr("Empty"))->setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool BookmarksTools::migrateBookmarksIfNecessary(Bookmarks* bookmarks)
|
||||
{
|
||||
QSqlQuery query;
|
||||
|
|
|
@ -97,6 +97,7 @@ public:
|
|||
static void addFolderToMenu(QObject* receiver, Menu* menu, BookmarkItem* folder);
|
||||
static void addUrlToMenu(QObject* receiver, Menu* menu, BookmarkItem* bookmark);
|
||||
static void addSeparatorToMenu(Menu* menu, BookmarkItem* separator);
|
||||
static void addFolderContentsToMenu(QObject* receiver, Menu* menu, BookmarkItem* folder);
|
||||
|
||||
// Migration from Sql Bookmarks (returns true if bookmarks migrated)
|
||||
static bool migrateBookmarksIfNecessary(Bookmarks* bookmarks);
|
||||
|
|
|
@ -99,14 +99,11 @@ void HistoryMenu::aboutToShow()
|
|||
|
||||
Action* act = new Action(title);
|
||||
act->setData(url);
|
||||
act->setIcon(IconProvider::iconForUrl(url));
|
||||
connect(act, SIGNAL(triggered()), this, SLOT(historyEntryActivated()));
|
||||
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(historyEntryCtrlActivated()));
|
||||
connect(act, SIGNAL(shiftTriggered()), this, SLOT(historyEntryShiftActivated()));
|
||||
addAction(act);
|
||||
|
||||
IconProvider::imageForUrlAsync(url, act, [=](const QImage &img) {
|
||||
act->setIcon(QIcon(QPixmap::fromImage(img)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,14 +123,11 @@ void HistoryMenu::aboutToShowMostVisited()
|
|||
foreach (const HistoryEntry &entry, mostVisited) {
|
||||
Action* act = new Action(QzTools::truncatedText(entry.title, 40));
|
||||
act->setData(entry.url);
|
||||
act->setIcon(IconProvider::iconForUrl(entry.url));
|
||||
connect(act, SIGNAL(triggered()), this, SLOT(historyEntryActivated()));
|
||||
connect(act, SIGNAL(ctrlTriggered()), this, SLOT(historyEntryCtrlActivated()));
|
||||
connect(act, SIGNAL(shiftTriggered()), this, SLOT(historyEntryShiftActivated()));
|
||||
m_menuMostVisited->addAction(act);
|
||||
|
||||
IconProvider::imageForUrlAsync(entry.url, act, [=](const QImage &img) {
|
||||
act->setIcon(QIcon(QPixmap::fromImage(img)));
|
||||
});
|
||||
}
|
||||
|
||||
if (m_menuMostVisited->isEmpty()) {
|
||||
|
|
|
@ -190,16 +190,6 @@ QImage IconProvider::imageForUrl(const QUrl &url, bool allowEmpty)
|
|||
return allowEmpty ? QImage() : IconProvider::emptyWebImage();
|
||||
}
|
||||
|
||||
void IconProvider::imageForUrlAsync(const QUrl &url, const QObject *receiver, std::function<void(const QImage &)> callback)
|
||||
{
|
||||
QFutureWatcher<QImage> *watcher = new QFutureWatcher<QImage>();
|
||||
connect(watcher, &QFutureWatcher<QImage>::finished, receiver, [=]() {
|
||||
watcher->deleteLater();
|
||||
callback(watcher->result());
|
||||
});
|
||||
watcher->setFuture(QtConcurrent::run(imageForUrl, url, false));
|
||||
}
|
||||
|
||||
QIcon IconProvider::iconForDomain(const QUrl &url, bool allowEmpty)
|
||||
{
|
||||
return instance()->iconFromImage(imageForDomain(url, allowEmpty));
|
||||
|
|
|
@ -61,7 +61,6 @@ public:
|
|||
// Icon for url (only available for urls in history)
|
||||
static QIcon iconForUrl(const QUrl &url, bool allowEmpty = false);
|
||||
static QImage imageForUrl(const QUrl &url, bool allowEmpty = false);
|
||||
static void imageForUrlAsync(const QUrl &url, const QObject *receiver, std::function<void(const QImage&)> callback);
|
||||
|
||||
// Icon for domain (only available for urls in history)
|
||||
static QIcon iconForDomain(const QUrl &url, bool allowEmpty = false);
|
||||
|
|
Loading…
Reference in New Issue
Block a user