make the caching workg again

This commit is contained in:
Patrick von Reth 2014-01-14 13:38:54 +01:00
parent 39e70977cf
commit 188adb974d
3 changed files with 22 additions and 11 deletions

View File

@ -60,12 +60,9 @@ const QImage &Icon::image() const{
return d->image(); return d->image();
} }
QString Icon::localUrl()const{ QString Icon::localUrl()const
if(!QFile(d->m_localUrl).exists())
{ {
image().save(d->m_localUrl ,"PNG"); return d->localUrl();
}
return d->m_localUrl;
} }
const QByteArray &Icon::imageData() const{ const QByteArray &Icon::imageData() const{

View File

@ -30,22 +30,19 @@ using namespace Snore;
IconData::IconData(const QString &url): IconData::IconData(const QString &url):
m_url(url), m_url(url),
m_hash(SnoreCorePrivate::computeHash(m_url.toLatin1())), m_hash(SnoreCorePrivate::computeHash(m_url.toLatin1())),
m_localUrl(QString("%1%2.png").arg(SnoreCorePrivate::snoreTMP(), m_hash)),
m_isLocalFile(false), m_isLocalFile(false),
m_isResource(m_url.startsWith(":/")) m_isResource(m_url.startsWith(":/"))
{ {
if(!m_isResource && QFile(url).exists()) if(!m_isResource && QFile(url).exists())
{ {
m_isLocalFile = true; m_isLocalFile = true;
m_localUrl = url;
} }
m_isRemoteFile = !m_isLocalFile && ! m_isResource; m_isRemoteFile = !m_isLocalFile && ! m_isResource;
} }
IconData::IconData(const QImage &img): IconData::IconData(const QImage &img):
m_img(img), m_img(img),
m_hash(QString::number(img.cacheKey(), 16)), m_hash(SnoreCorePrivate::computeHash((char*)img.constBits())),
m_localUrl(QString("%1%2.png").arg(SnoreCorePrivate::snoreTMP(), m_hash)),
m_isLocalFile(false), m_isLocalFile(false),
m_isResource(false), m_isResource(false),
m_isRemoteFile(false) m_isRemoteFile(false)
@ -96,6 +93,23 @@ const QImage &IconData::image()
return m_img; return m_img;
} }
QString IconData::localUrl()
{
if(m_isLocalFile)
{
return m_url;
}
else
{
QString out(QString("%1%2.png").arg(SnoreCorePrivate::snoreTMP(), m_hash));
if(!QFile(out).exists())
{
image().save(out ,"PNG");
}
return out;
}
}
void IconData::download() void IconData::download()
{ {

View File

@ -41,13 +41,13 @@ public:
const QByteArray &imageData(); const QByteArray &imageData();
const QImage &image(); const QImage &image();
QString localUrl();
void download(); void download();
QImage m_img; QImage m_img;
QByteArray m_data; QByteArray m_data;
QString m_url; QString m_url;
QString m_hash; QString m_hash;
QString m_localUrl;
bool m_isLocalFile; bool m_isLocalFile;
bool m_isResource; bool m_isResource;
bool m_isRemoteFile; bool m_isRemoteFile;