cleaned up icon
This commit is contained in:
parent
8e45af0901
commit
58f95602ce
|
@ -25,6 +25,15 @@
|
||||||
|
|
||||||
using namespace Snore;
|
using namespace Snore;
|
||||||
|
|
||||||
|
QByteArray Icon::dataFromImage(const QImage &image)
|
||||||
|
{
|
||||||
|
QByteArray data;
|
||||||
|
QBuffer buffer( &data );
|
||||||
|
buffer.open( QBuffer::WriteOnly );
|
||||||
|
image.save( &buffer, "PNG" );
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
Icon::Icon() :
|
Icon::Icon() :
|
||||||
d(NULL)
|
d(NULL)
|
||||||
{
|
{
|
||||||
|
@ -65,10 +74,6 @@ QString Icon::localUrl()const
|
||||||
return d->localUrl();
|
return d->localUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QByteArray &Icon::imageData() const{
|
|
||||||
return d->imageData();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Icon::isLocalFile() const
|
bool Icon::isLocalFile() const
|
||||||
{
|
{
|
||||||
return d->m_isLocalFile;
|
return d->m_isLocalFile;
|
||||||
|
@ -79,6 +84,11 @@ bool Icon::isValid() const
|
||||||
return d && !(d->m_img.isNull() && d->m_url.isEmpty());
|
return d && !(d->m_img.isNull() && d->m_url.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Icon Icon::scaled(const QSize &s) const
|
||||||
|
{
|
||||||
|
return Icon(image().scaled(s,Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||||
|
}
|
||||||
|
|
||||||
QString Icon::url() const
|
QString Icon::url() const
|
||||||
{
|
{
|
||||||
return d->m_url;
|
return d->m_url;
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <QSharedData>
|
#include <QSharedData>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
namespace Snore{
|
namespace Snore{
|
||||||
class Icon;
|
class Icon;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +42,9 @@ class IconData;
|
||||||
class SNORE_EXPORT Icon
|
class SNORE_EXPORT Icon
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
static QByteArray dataFromImage(const QImage &image);
|
||||||
|
|
||||||
Icon();
|
Icon();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,12 +91,6 @@ public:
|
||||||
*/
|
*/
|
||||||
QString url() const;
|
QString url() const;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return a QByteArray containing the data of a png representing the Icon
|
|
||||||
*/
|
|
||||||
const QByteArray &imageData() const ;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return whether the Icon was created from a local file
|
* @return whether the Icon was created from a local file
|
||||||
|
@ -111,6 +109,8 @@ public:
|
||||||
*/
|
*/
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
|
Icon scaled(const QSize &s) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QExplicitlySharedDataPointer<IconData> d;
|
QExplicitlySharedDataPointer<IconData> d;
|
||||||
friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Icon &);
|
friend SNORE_EXPORT QDebug (::operator<<) ( QDebug, const Snore::Icon &);
|
||||||
|
|
|
@ -46,8 +46,7 @@ IconData::IconData(const QString &url):
|
||||||
|
|
||||||
IconData::IconData(const QImage &img):
|
IconData::IconData(const QImage &img):
|
||||||
m_img(img),
|
m_img(img),
|
||||||
m_data(dataFromImage(img)),
|
m_hash(SnoreCorePrivate::computeHash(Icon::dataFromImage(img))),
|
||||||
m_hash(SnoreCorePrivate::computeHash(m_data)),
|
|
||||||
m_localUrl(createLocalFileName(m_hash)),
|
m_localUrl(createLocalFileName(m_hash)),
|
||||||
m_isLocalFile(false),
|
m_isLocalFile(false),
|
||||||
m_isResource(false),
|
m_isResource(false),
|
||||||
|
@ -60,20 +59,6 @@ IconData::~IconData()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const QByteArray &Snore::IconData::imageData()
|
|
||||||
{
|
|
||||||
QMutexLocker lock(&m_mutex);
|
|
||||||
if(m_data.isEmpty())
|
|
||||||
{
|
|
||||||
if(m_isRemoteFile)
|
|
||||||
{
|
|
||||||
download();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QImage &IconData::image()
|
const QImage &IconData::image()
|
||||||
{
|
{
|
||||||
QMutexLocker lock(&m_mutex);
|
QMutexLocker lock(&m_mutex);
|
||||||
|
@ -107,7 +92,7 @@ QString IconData::localUrl()
|
||||||
|
|
||||||
void IconData::download()
|
void IconData::download()
|
||||||
{
|
{
|
||||||
if(m_isRemoteFile && m_data.isEmpty())
|
if(m_isRemoteFile)
|
||||||
{
|
{
|
||||||
if(!QFile(m_localUrl).exists())
|
if(!QFile(m_localUrl).exists())
|
||||||
{
|
{
|
||||||
|
@ -122,15 +107,13 @@ void IconData::download()
|
||||||
loop.exec();
|
loop.exec();
|
||||||
if(reply->isFinished())
|
if(reply->isFinished())
|
||||||
{
|
{
|
||||||
m_data = reply->readAll();
|
m_img = QImage::fromData(reply->readAll(), "PNG");
|
||||||
m_img = QImage::fromData(m_data, "PNG");
|
|
||||||
m_img.save(m_localUrl,"PNG");
|
m_img.save(m_localUrl,"PNG");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_img = QImage(m_localUrl);
|
m_img = QImage(m_localUrl);
|
||||||
m_data = dataFromImage(m_img);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,15 +41,12 @@ public:
|
||||||
IconData(const QImage &img);
|
IconData(const QImage &img);
|
||||||
~IconData();
|
~IconData();
|
||||||
|
|
||||||
|
|
||||||
const QByteArray &imageData();
|
|
||||||
const QImage &image();
|
const QImage &image();
|
||||||
QString localUrl();
|
QString localUrl();
|
||||||
void download();
|
void download();
|
||||||
|
|
||||||
|
|
||||||
QImage m_img;
|
QImage m_img;
|
||||||
QByteArray m_data;
|
|
||||||
QString m_url;
|
QString m_url;
|
||||||
QString m_hash;
|
QString m_hash;
|
||||||
QString m_localUrl;
|
QString m_localUrl;
|
||||||
|
@ -61,15 +58,6 @@ public:
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(IconData)
|
Q_DISABLE_COPY(IconData)
|
||||||
|
|
||||||
inline QByteArray dataFromImage(const QImage &image)
|
|
||||||
{
|
|
||||||
QByteArray data;
|
|
||||||
QBuffer buffer( &data );
|
|
||||||
buffer.open( QBuffer::WriteOnly );
|
|
||||||
image.save( &buffer, "PNG" );
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline QString createLocalFileName(const QString &hash)
|
inline QString createLocalFileName(const QString &hash)
|
||||||
{
|
{
|
||||||
static QString tmp;
|
static QString tmp;
|
||||||
|
|
|
@ -222,6 +222,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
||||||
|
|
||||||
ULONG32 id = 0;
|
ULONG32 id = 0;
|
||||||
snoreDebug( SNORE_DEBUG ) << notification.icon();
|
snoreDebug( SNORE_DEBUG ) << notification.icon();
|
||||||
|
|
||||||
if(!notification.isUpdate())
|
if(!notification.isUpdate())
|
||||||
{
|
{
|
||||||
id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(),
|
id = snarlInterface->Notify(notification.alert().name().toUtf8().constData(),
|
||||||
|
@ -229,7 +230,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
||||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||||
notification.timeout(),
|
notification.timeout(),
|
||||||
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
||||||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
!notification.icon().isLocalFile()?Icon::dataFromImage(notification.icon().image()).toBase64().constData():0,
|
||||||
priority);
|
priority);
|
||||||
|
|
||||||
foreach(const Action &a, notification.actions())
|
foreach(const Action &a, notification.actions())
|
||||||
|
@ -249,7 +250,7 @@ void SnarlBackend::slotNotify(Notification notification){
|
||||||
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
Snore::toPlainText(notification.text()).toUtf8().constData(),
|
||||||
notification.timeout(),
|
notification.timeout(),
|
||||||
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
notification.icon().isLocalFile()?notification.icon().localUrl().toUtf8().constData():0,
|
||||||
!notification.icon().isLocalFile()?notification.icon().imageData().toBase64().constData():0,
|
!notification.icon().isLocalFile()?Icon::dataFromImage(notification.icon().image()).toBase64().constData():0,
|
||||||
priority);
|
priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue