diff options
Diffstat (limited to 'src/sessionsiconholder.cpp')
-rw-r--r-- | src/sessionsiconholder.cpp | 66 |
1 files changed, 27 insertions, 39 deletions
diff --git a/src/sessionsiconholder.cpp b/src/sessionsiconholder.cpp index 5180658..8eecf26 100644 --- a/src/sessionsiconholder.cpp +++ b/src/sessionsiconholder.cpp @@ -1,10 +1,3 @@ -/* - * sessionsiconholder.cpp - * - * Created on: Mar 7, 2014 - * Author: nils - */ - #include <QHash> #include <QtDebug> #include <QFile> @@ -29,34 +22,6 @@ SessionsIconHolder::SessionsIconHolder() { QDir().mkpath(TEMP_PATH_ICONS); } -void SessionsIconHolder::afterDownload(const QUrl& url, const QByteArray& downloadedData) { - // save the data to disk - QString strUrl(url.toString()); - QString file_path(url2filename(strUrl)); - QFile file(file_path); - if (!file.open(QFile::WriteOnly)) { - if (g_debugMode) { - qDebug() << "Could not write file: " << file_path; - } - return; - } - file.write(downloadedData); - - if (file.write(downloadedData) != downloadedData.length()) { - if (g_debugMode) { - qDebug() << "Could not write file: " << file_path; - } - return; - } - - file.close(); - - QIcon icon(file_path); - icons.insert(strUrl, icon); - - emit iconDownloaded(url, icon); -} - QIcon SessionsIconHolder::getIcon(const QString& name) { // check if icon was loaded before if (icons.contains(name)) { @@ -100,10 +65,33 @@ QIcon SessionsIconHolder::getIcon(const QUrl& url) { icons.insert(strUrl, QIcon()); // else load icon from url - FileDownloader* fileDownloader = new FileDownloader(url, this); - QObject::connect(fileDownloader, SIGNAL(downloaded(const QUrl&, const QByteArray&)), - this, SLOT(afterDownload(const QUrl&, const QByteArray&))); - fileDownloader->downloadFile(); + FileDownloader::download(url, [this, url](QNetworkReply::NetworkError, const QByteArray &downloadedData) { + // save the data to disk + QString strUrl(url.toString()); + QString file_path(url2filename(strUrl)); + QFile file(file_path); + if (!file.open(QFile::WriteOnly)) { + if (g_debugMode) { + qDebug() << "Could not write file: " << file_path; + } + return; + } + file.write(downloadedData); + + if (file.write(downloadedData) != downloadedData.length()) { + if (g_debugMode) { + qDebug() << "Could not write file: " << file_path; + } + return; + } + + file.close(); + + QIcon icon(file_path); + icons.insert(strUrl, icon); + + emit iconDownloaded(url, icon); + }); return QIcon(); } |