Commit d821bffe authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Icon Applet] Get favicon for website shortcuts

When creating an icon for a website use its favicon if possible.

Differential Revision: https://phabricator.kde.org/D6163
parent 447f71b8
......@@ -11,6 +11,7 @@ kcoreaddons_desktop_to_json(plasma_applet_icon package/metadata.desktop)
target_link_libraries(plasma_applet_icon
KF5::I18n
KF5::KIOCore # for OpenFileManagerWindowJob
KF5::KIOGui # for FavIconRequestJob
KF5::KIOWidgets # for KRun
KF5::Plasma)
......
......@@ -44,6 +44,7 @@
#include <KRun>
#include <KIO/DropJob>
#include <KIO/FavIconRequestJob>
#include <KIO/OpenFileManagerWindowJob>
#include <KIO/StatJob>
......@@ -202,6 +203,18 @@ void IconApplet::populate()
iconName = KIO::iconNameForUrl(url);
}
bool downloadFavIcon = false;
if (url.scheme().startsWith(QLatin1String("http"))) {
const QString favIcon = KIO::favIconForUrl(url);
if (!favIcon.isEmpty()) {
iconName = favIcon;
} else {
downloadFavIcon = true;
}
}
KDesktopFile linkDesktopFile(backingDesktopFile);
auto desktopGroup = linkDesktopFile.desktopGroup();
......@@ -217,6 +230,18 @@ void IconApplet::populate()
populateFromDesktopFile(backingDesktopFile);
setLocalPath(backingDesktopFile);
if (downloadFavIcon) {
KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(m_url);
connect(job, &KIO::FavIconRequestJob::result, this, [job, backingDesktopFile, this](KJob *){
if (!job->error()) {
KDesktopFile(backingDesktopFile).desktopGroup().writeEntry(QStringLiteral("Icon"), job->iconFile());
m_iconName = job->iconFile();
emit iconNameChanged(m_iconName);
}
});
}
});
}
......
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