Commit 8eedb44f authored by Fushan Wen's avatar Fushan Wen Committed by Nate Graham
Browse files

dataengines/potd: Use PotdProviderData in the initializer of SaveImageThread

We need to save more information in the thread.
parent 4427e0e9
......@@ -29,20 +29,18 @@ void LoadImageThread::run()
Q_EMIT done(image);
}
SaveImageThread::SaveImageThread(const QString &identifier, const QImage &image)
: m_image(image)
, m_identifier(identifier)
SaveImageThread::SaveImageThread(const QString &identifier, const PotdProviderData &data)
: m_identifier(identifier)
, m_data(data)
{
}
void SaveImageThread::run()
{
const QString path = CachedProvider::identifierToPath(m_identifier);
m_image.save(path, "JPEG");
PotdProviderData data;
data.wallpaperImage = m_image;
data.wallpaperLocalUrl = path;
Q_EMIT done(m_identifier, data);
m_data.wallpaperLocalUrl = CachedProvider::identifierToPath(m_identifier);
m_data.wallpaperImage.save(m_data.wallpaperLocalUrl, "JPEG");
Q_EMIT done(m_identifier, m_data);
}
QString CachedProvider::identifierToPath(const QString &identifier)
......
......@@ -75,15 +75,15 @@ class SaveImageThread : public QObject, public QRunnable
Q_OBJECT
public:
SaveImageThread(const QString &identifier, const QImage &image);
SaveImageThread(const QString &identifier, const PotdProviderData &data);
void run() override;
Q_SIGNALS:
void done(const QString &source, const PotdProviderData &data);
private:
QImage m_image;
QString m_identifier;
PotdProviderData m_data;
};
#endif
......@@ -320,10 +320,14 @@ void PotdProviderModel::slotFinished(PotdProvider *provider)
}
setImage(provider->image());
setInfoUrl(provider->infoUrl());
setRemoteUrl(provider->remoteUrl());
setTitle(provider->title());
setAuthor(provider->author());
// Store in cache if it's not the response of a CachedProvider
if (qobject_cast<CachedProvider *>(provider) == nullptr && !m_data.wallpaperImage.isNull()) {
SaveImageThread *thread = new SaveImageThread(m_identifier, m_data.wallpaperImage);
SaveImageThread *thread = new SaveImageThread(m_identifier, m_data);
connect(thread, &SaveImageThread::done, this, &PotdProviderModel::slotCachingFinished);
QThreadPool::globalInstance()->start(thread);
} else {
......@@ -344,6 +348,10 @@ void PotdProviderModel::slotCachingFinished(const QString &source, const PotdPro
Q_UNUSED(source)
setImage(data.wallpaperImage);
setLocalUrl(data.wallpaperLocalUrl);
setInfoUrl(data.wallpaperInfoUrl);
setRemoteUrl(data.wallpaperRemoteUrl);
setTitle(data.wallpaperTitle);
setAuthor(data.wallpaperAuthor);
}
void PotdProviderModel::slotError(PotdProvider *provider)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment