Marble
6 #include "RemoteIconLoader.h"
16 #include <QCryptographicHash>
19 #include "HttpDownloadManager.h"
20 #include "FileStoragePolicy.h"
21 #include "MarbleDirs.h"
22 #include "MarbleGlobal.h"
23 #include "MarbleDebug.h"
28 class RemoteIconLoaderPrivate
31 RemoteIconLoaderPrivate()
32 : m_storagePolicy(MarbleDirs::localPath() +
QLatin1String(
"/cache/icons/")),
33 m_downloadManager( &m_storagePolicy )
37 FileStoragePolicy m_storagePolicy;
38 HttpDownloadManager m_downloadManager;
43 bool isCached(
const QUrl& url )
const;
53 bool loadFromDiskCache(
const QUrl& url );
59 void initiateDownload(
const QUrl& url );
67 bool RemoteIconLoaderPrivate::isCached(
const QUrl& url )
const
69 return m_iconCache.contains( url );
72 QImage RemoteIconLoaderPrivate::cachedIcon(
const QUrl& url )
const
74 return m_iconCache.value( url );
77 bool RemoteIconLoaderPrivate::loadFromDiskCache(
const QUrl& url )
82 m_iconCache.insert( url, icon );
88 void RemoteIconLoaderPrivate::initiateDownload(
const QUrl& url )
91 m_downloadManager.setDownloadEnabled(
true);
92 QString fileName = cacheFileName( url );
93 m_downloadManager.addJob(url, fileName, url.
toString(), usage );
96 QString RemoteIconLoaderPrivate::cacheFileName(
const QUrl &url)
104 RemoteIconLoader::RemoteIconLoader(
QObject *parent )
106 d ( new RemoteIconLoaderPrivate() )
108 connect( &d->m_downloadManager, SIGNAL(downloadComplete(
QByteArray,
QString)),
this,
112 RemoteIconLoader::~RemoteIconLoader()
118 QImage RemoteIconLoader::load(
const QUrl& url )
126 if ( d->isCached( url ) ) {
127 return d->cachedIcon( url );
136 else if ( d->loadFromDiskCache( url ) ) {
137 return d->cachedIcon( url );
142 d->initiateDownload( url );
148 void RemoteIconLoader::storeIcon(
const QByteArray &data,
const QString &fileName)
151 d->m_iconCache.insert(
QUrl(fileName), icon );
157 #include "moc_RemoteIconLoader.cpp"
@ DownloadBrowse
Browsing mode, normal operation of Marble, like a web browser.
QByteArray toEncoded(QUrl::FormattingOptions options) const const
DownloadUsage
This enum is used to describe the type of download.
QString suffix() const const
bool exists() const const
QString toString(QUrl::FormattingOptions options) const const
bool isNull() const const
Binds a QML item to a specific geodetic location in screen coordinates.
QByteArray hash(const QByteArray &data, QCryptographicHash::Algorithm method)
QByteArray toHex() const const
QString path(QUrl::ComponentFormattingOptions options) const const
QString path(const QString &relativePath)
QString fromLatin1(const char *str, int size)
QImage fromData(const uchar *data, int size, const char *format)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Thu Sep 21 2023 04:12:28 by
doxygen 1.8.17 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.