mirror of
https://github.com/status-im/snorenotify.git
synced 2025-02-10 07:26:22 +00:00
its better to not cache ..
This commit is contained in:
parent
f90397a370
commit
a7aff40dc2
@ -20,6 +20,7 @@
|
||||
#include <QCryptographichash>
|
||||
#include <QBuffer>
|
||||
#include <QHash>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
@ -35,14 +36,21 @@ public:
|
||||
SnoreIconData(const QImage &img):
|
||||
_img(img),
|
||||
_isLocalFile(false)
|
||||
{ }
|
||||
{}
|
||||
|
||||
SnoreIconData(const QString &url){
|
||||
if(QFile(url).exists()){
|
||||
_isLocalFile = true;
|
||||
_localFileName = url;
|
||||
}
|
||||
}
|
||||
~SnoreIconData()
|
||||
{ }
|
||||
|
||||
|
||||
QImage _img;
|
||||
QByteArray _data;
|
||||
QString _localFileName;
|
||||
QString _hash;
|
||||
bool _isLocalFile;
|
||||
|
||||
@ -60,10 +68,14 @@ SnoreIcon::SnoreIcon()
|
||||
}
|
||||
|
||||
SnoreIcon::SnoreIcon(const QImage &img)
|
||||
{
|
||||
{
|
||||
d = QSharedPointer<SnoreIconData>(new SnoreIconData(img));
|
||||
}
|
||||
|
||||
SnoreIcon::SnoreIcon(const QString &url){
|
||||
d = QSharedPointer<SnoreIconData>(new SnoreIconData(url));
|
||||
}
|
||||
|
||||
SnoreIcon::SnoreIcon(const SnoreIcon &other):
|
||||
d(other.d)
|
||||
{ }
|
||||
@ -72,28 +84,25 @@ SnoreIcon::~SnoreIcon()
|
||||
{ }
|
||||
|
||||
|
||||
const QString &SnoreIcon::hash() const{
|
||||
if(d->_hash.isEmpty()){
|
||||
QCryptographicHash h(QCryptographicHash::Md5);
|
||||
h.addData(imageData());
|
||||
d->_hash = h.result().toHex();
|
||||
}
|
||||
return d->_hash;
|
||||
}
|
||||
|
||||
const QImage &SnoreIcon::image() const{
|
||||
if(d->_img.isNull() && d->_isLocalFile){
|
||||
d->_img = QImage(d->_localFileName);
|
||||
}
|
||||
return d->_img;
|
||||
}
|
||||
|
||||
const QString &SnoreIcon::localUrl()const{
|
||||
QString h = hash();
|
||||
if(hasedImages.contains(h))
|
||||
return hasedImages[h];
|
||||
QString fp = SnoreServer::snoreTMP();
|
||||
fp = fp.append("/").append(h).append(".png");
|
||||
d->_img.save(fp,"PNG");
|
||||
hasedImages[h] = fp;
|
||||
return hasedImages[h];
|
||||
if(d->_localFileName.isEmpty()){
|
||||
if(hasedImages.contains(hash())){
|
||||
d->_localFileName = hasedImages[hash()];
|
||||
}else{
|
||||
d->_localFileName = SnoreServer::snoreTMP();
|
||||
d->_localFileName = d->_localFileName .append("/").append(hash()).append(".png");
|
||||
hasedImages[hash()] = d->_localFileName;
|
||||
d->_img.save(d->_localFileName ,"PNG");
|
||||
}
|
||||
}
|
||||
return d->_localFileName;
|
||||
}
|
||||
|
||||
const QByteArray &SnoreIcon::imageData() const{
|
||||
@ -105,6 +114,15 @@ const QByteArray &SnoreIcon::imageData() const{
|
||||
return d->_data;
|
||||
}
|
||||
|
||||
const QString &SnoreIcon::hash() const{
|
||||
if(d->_hash.isEmpty()){
|
||||
QCryptographicHash h(QCryptographicHash::Md5);
|
||||
h.addData(imageData());
|
||||
d->_hash = h.result().toHex();
|
||||
}
|
||||
return d->_hash;
|
||||
}
|
||||
|
||||
const bool SnoreIcon::isLocalFile() const
|
||||
{
|
||||
return d->_isLocalFile;
|
||||
|
@ -26,25 +26,25 @@
|
||||
class SNORE_EXPORT SnoreIcon
|
||||
{
|
||||
public:
|
||||
SnoreIcon();
|
||||
SnoreIcon();
|
||||
SnoreIcon(const QImage &img);
|
||||
SnoreIcon(const QByteArray &img);
|
||||
SnoreIcon(const SnoreIcon &other);
|
||||
~SnoreIcon();
|
||||
SnoreIcon(const class QString &url);
|
||||
SnoreIcon(const SnoreIcon &other);
|
||||
~SnoreIcon();
|
||||
|
||||
const QImage &image() const;
|
||||
const QString &localUrl() const;
|
||||
const QByteArray &imageData() const;
|
||||
const bool isLocalFile() const;
|
||||
const QImage &image() const;
|
||||
const QString &localUrl() const;
|
||||
const QByteArray &imageData() const;
|
||||
const QString &hash() const;
|
||||
const bool isLocalFile() const;
|
||||
|
||||
|
||||
private:
|
||||
static QHash<QString,QString> hasedImages;
|
||||
static QHash<QString,QString> hasedImages;
|
||||
private:
|
||||
class SnoreIconData;
|
||||
QSharedPointer<SnoreIconData> d;
|
||||
class SnoreIconData;
|
||||
QSharedPointer<SnoreIconData> d;
|
||||
|
||||
const QString &hash() const;
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user