summaryrefslogtreecommitdiffstats
path: root/src/sessionsiconholder.cpp
diff options
context:
space:
mode:
authorSimon Rettberg2018-06-15 14:05:25 +0200
committerSimon Rettberg2018-06-15 14:05:25 +0200
commitba3c5aa40274c11f9cefd4e9842be3488cad07b4 (patch)
tree2865703ae78ed397f24fa32fca642332ac7b3a49 /src/sessionsiconholder.cpp
parentfileDownloader.* -> filedownloader.* (diff)
downloadvmchooser2-ba3c5aa40274c11f9cefd4e9842be3488cad07b4.tar.gz
vmchooser2-ba3c5aa40274c11f9cefd4e9842be3488cad07b4.tar.xz
vmchooser2-ba3c5aa40274c11f9cefd4e9842be3488cad07b4.zip
Fix indentation, cleanup, refactoring, deletions
* Remove unused methods for adding hostname and user to xml * Avoid copying/(de)serializing XML a thousand times * Fix Session::isValid() or rather make it a bit more usable (although it's unused currently) * baseDir is global, not per VSession, which doesn't make any sense without the legacy approach of recusively loading one xml file per entry
Diffstat (limited to 'src/sessionsiconholder.cpp')
-rw-r--r--src/sessionsiconholder.cpp144
1 files changed, 72 insertions, 72 deletions
diff --git a/src/sessionsiconholder.cpp b/src/sessionsiconholder.cpp
index 61616ad..872df07 100644
--- a/src/sessionsiconholder.cpp
+++ b/src/sessionsiconholder.cpp
@@ -22,88 +22,88 @@
SessionsIconHolder* SessionsIconHolder::instance = NULL;
static inline QString url2filename(const QString& url) {
- return iconsTempPath + QString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex());
+ return iconsTempPath + QString(QCryptographicHash::hash(url.toUtf8(), QCryptographicHash::Md5).toHex());
}
SessionsIconHolder::SessionsIconHolder() {
- QDir().mkpath(iconsTempPath);
+ QDir().mkpath(iconsTempPath);
}
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 (debugMode) {
- qDebug() << "Could not write file: " << file_path;
- }
- return;
- }
- file.write(downloadedData);
-
- if (file.write(downloadedData) != downloadedData.length()) {
- if (debugMode) {
- qDebug() << "Could not write file: " << file_path;
- }
- return;
- }
-
- file.close();
-
- QIcon icon(file_path);
- icons.insert(strUrl, icon);
-
- emit iconDownloaded(url, icon);
+ // save the data to disk
+ QString strUrl(url.toString());
+ QString file_path(url2filename(strUrl));
+ QFile file(file_path);
+ if (!file.open(QFile::WriteOnly)) {
+ if (debugMode) {
+ qDebug() << "Could not write file: " << file_path;
+ }
+ return;
+ }
+ file.write(downloadedData);
+
+ if (file.write(downloadedData) != downloadedData.length()) {
+ if (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)) {
- return icons[name];
- }
-
- // else load icon from resource
- QIcon icon;
- QString resName(":" + name.toLower());
- if (QResource(resName).isValid()) {
- icon = QIcon(resName);
- } else if (QFileInfo(name).isAbsolute() && QFile::exists(name)) {
- // absolute icon path and file exists
- icon = QIcon(name);
- } else {
- icon = QIcon();
- }
-
- // insert icon to hash table
- icons.insert(name, icon);
- return icon;
+ // check if icon was loaded before
+ if (icons.contains(name)) {
+ return icons[name];
+ }
+
+ // else load icon from resource
+ QIcon icon;
+ QString resName(":" + name.toLower());
+ if (QResource(resName).isValid()) {
+ icon = QIcon(resName);
+ } else if (QFileInfo(name).isAbsolute() && QFile::exists(name)) {
+ // absolute icon path and file exists
+ icon = QIcon(name);
+ } else {
+ icon = QIcon();
+ }
+
+ // insert icon to hash table
+ icons.insert(name, icon);
+ return icon;
}
QIcon SessionsIconHolder::getIcon(const QUrl& url) {
- // check if icon was loaded before
- if (icons.contains(url.toString())) {
- return icons[url.toString()];
- }
-
- // search the icon in the tmp folder
- QString strUrl(url.toString());
- QString file_path(url2filename(strUrl));
-
- if (QFile::exists(file_path)) {
- QIcon icon(file_path);
- icons.insert(strUrl, icon);
- return icon;
- }
- // Put empty icon in map while we're downloading, so successive calls won't trigger
- // more downloads before the running download finishes
- 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();
-
- return QIcon();
+ // check if icon was loaded before
+ if (icons.contains(url.toString())) {
+ return icons[url.toString()];
+ }
+
+ // search the icon in the tmp folder
+ QString strUrl(url.toString());
+ QString file_path(url2filename(strUrl));
+
+ if (QFile::exists(file_path)) {
+ QIcon icon(file_path);
+ icons.insert(strUrl, icon);
+ return icon;
+ }
+ // Put empty icon in map while we're downloading, so successive calls won't trigger
+ // more downloads before the running download finishes
+ 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();
+
+ return QIcon();
}