use a mutex to protect some things in icon

This commit is contained in:
Patrick von Reth 2014-01-15 18:49:12 +01:00
parent 135d0d470d
commit b4cb329145
2 changed files with 9 additions and 3 deletions

View File

@ -60,6 +60,7 @@ IconData::~IconData()
const QByteArray &Snore::IconData::imageData()
{
QMutexLocker lock(&m_mutex);
if(m_data.isEmpty())
{
if(m_isRemoteFile)
@ -72,6 +73,7 @@ const QByteArray &Snore::IconData::imageData()
const QImage &IconData::image()
{
QMutexLocker lock(&m_mutex);
if(m_img.isNull())
{
if(!m_isRemoteFile )
@ -89,6 +91,7 @@ const QImage &IconData::image()
QString IconData::localUrl()
{
QMutexLocker lock(&m_mutex);
if(!m_isLocalFile && !QFile(m_localUrl).exists())
{
image().save(m_localUrl ,"PNG");
@ -114,9 +117,9 @@ void IconData::download()
loop.exec();
if(reply->isFinished())
{
m_data = reply->readAll();
m_img = QImage::fromData(m_data, "PNG");
m_img.save(m_localUrl,"PNG");
m_data = reply->readAll();
m_img = QImage::fromData(m_data, "PNG");
m_img.save(m_localUrl,"PNG");
}
}
else

View File

@ -29,6 +29,8 @@
#include <QFile>
#include <QDebug>
#include <QMutex>
namespace Snore{
class IconData : public QSharedData
@ -61,6 +63,7 @@ public:
bool m_isLocalFile;
bool m_isResource;
bool m_isRemoteFile;
QMutex m_mutex;
private:
Q_DISABLE_COPY(IconData)