KIO::FavIconRequestJob Class

FavIconRequestJob handles the retrieval of a favicon (either from the local cache or from the internet). More...

Header: #include <KIO/FavIconRequestJob>
CMake: find_package(KF6 REQUIRED COMPONENTS KIO)
target_link_libraries(mytarget PRIVATE KIOGui)
Since: KDE Frameworks 5.19
Inherits: KCompositeJob

Public Functions

FavIconRequestJob(const QUrl &hostUrl, KIO::LoadType reload = KIO::NoReload, QObject *parent = nullptr)
virtual ~FavIconRequestJob() override
(since 5.20) QUrl hostUrl() const
QString iconFile() const
void setIconUrl(const QUrl &iconUrl)

Detailed Description

For instance, the icon for http://www.google.com exists at http://www.google.com/favicon.ico This job will (the first time) download the favicon, and make it available as a local PNG for fast lookups afterwards.

Usage: Create a FavIconRequestJob, connect to result(KJob *), and from there use iconFile().

// Let's say we want to show the icon for QUrl m_url
KIO::FavIconRequestJob *job = new KIO::FavIconRequestJob(m_url);
connect(job, &KIO::FavIconRequestJob::result, this, [job, this](KJob *){
    if (!job->error()) {
        // show the icon using QIcon(job->iconFile())
    }
});

For a given HTTP URL, you can find out if a favicon is available by calling KIO::favIconForUrl() in KIOCore. It is however not necessary to check this first, FavIconRequestJob will do this first and emit result right away if a cached icon is available and not too old.

In Web Browsers, additional information exists: the HTML for a given page can specify something like &lt;link rel="shortcut icon" href="another_favicon.ico" /&gt; To handle this, call job->setIconUrl(iconUrl). (KParts-based web engines use the signal BrowserExtension::setIconUrl to call back into the web browser application, which should then call this). The signal urlIconChanged will be emitted once the icon has been downloaded.

The on-disk cache is shared between processes.

Member Function Documentation

[explicit] FavIconRequestJob::FavIconRequestJob(const QUrl &hostUrl, KIO::LoadType reload = KIO::NoReload, QObject *parent = nullptr)

FavIconRequestJob constructor

hostUrl The web page URL. We only use the scheme and host.

reload set this to reload to skip the cache and force a refresh of the favicon.

parent parent object

[override virtual noexcept] FavIconRequestJob::~FavIconRequestJob()

Destructor. You do not need to delete the job, it will delete automatically, unless you call setAutoDelete(false).

[since 5.20] QUrl FavIconRequestJob::hostUrl() const

Returns the URL passed to the constructor

This function was introduced in KDE Frameworks 5.20.

QString FavIconRequestJob::iconFile() const

Returns the full local path to the icon from the cache. Only call this in the slot connected to the result(KJob*) signal. Returns the path to the icon file

void FavIconRequestJob::setIconUrl(const QUrl &iconUrl)

setIconUrl allows to set, for a specific URL, a different icon URL than the default one for the host (http://host/favicon.ico)

This information is stored in the on-disk cache, so that other FavIconRequestJobs for this url and KIO::favIconForUrl will return the icon specified here.

iconUrl the URL to the icon, usually parsed from the HTML