summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorNils Schwabe2014-04-04 16:46:11 +0200
committerNils Schwabe2014-04-04 16:46:11 +0200
commitaf289133d4df82dc55cd9fd2df8541d9c08949cc (patch)
tree8ae15aca72b63df0abc0afe4d6262980b6a94aff /src/dialog.cpp
parentchanged permissions of xml and backup xml to 666 (diff)
downloadvmchooser2-af289133d4df82dc55cd9fd2df8541d9c08949cc.tar.gz
vmchooser2-af289133d4df82dc55cd9fd2df8541d9c08949cc.tar.xz
vmchooser2-af289133d4df82dc55cd9fd2df8541d9c08949cc.zip
simplified the xml caching
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp40
1 files changed, 17 insertions, 23 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 0967d8c..009da02 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -8,6 +8,7 @@
#include <QTimer>
#include <QDesktopWidget>
#include <QDateTime>
+#include <QTemporaryFile>
#include "ui_dialog.h"
#include "sessiontreeitem.h"
@@ -293,53 +294,46 @@ void Dialog::onCenterTimer() {
}
void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
+ QString temp_filename;
+
if (reply->error() != QNetworkReply::NoError) {
if (debugMode) {
qDebug() << "Error reading from URL: " << reply->error();
}
- QFile backup_file(xml_backup_filename);
+ QFile backup_file(xml_filename);
if (!backup_file.open(QIODevice::ReadOnly)) {
if (debugMode) {
- qDebug() << "Cannot read backup file " << xml_backup_filename << " either";
+ qDebug() << "Cannot read backup file " << xml_filename << " either";
}
this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1);
this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "URL Error"), 1);
return;
}
if (debugMode) {
- qDebug() << "Used backup file " << xml_backup_filename;
+ qDebug() << "Used backup file " << xml_filename;
}
backup_file.close();
- QList<Session*> sessions = VSession::readXmlFile(xml_backup_filename);
+ QList<Session*> sessions = VSession::readXmlFile(xml_filename);
qSort(sessions.begin(), sessions.end(), myLessThan);
this->addItems(sessions, 1);
} else {
- QFile file(xml_filename);
- if (!file.open(QIODevice::WriteOnly)) {
- if (debugMode) {
- qDebug() << "Could not write XML to " << xml_filename;
- }
- return;
- }
-
QByteArray data = reply->readAll();
- if (file.write(data) != data.length()) {
- return;
- }
-
- if (!file.setPermissions(QFile::ReadUser | QFile::ReadGroup | QFile::ReadOther | QFile::WriteUser | QFile::WriteGroup | QFile::WriteOther)) {
- if (debugMode) {
- qDebug() << "Could not change permissions of file: " << news_backup_filename;
- }
- }
- file.close();
+ // write xml to temporary file
+ temp_filename = QDir::tempPath() + "/vmchooser2/vmchooser-XXXXXX.xml";
+ QTemporaryFile tmpfile(temp_filename);
+ if (!tmpfile.open() || tmpfile.write(data) == -1) {
+ return;
+ }
+ tmpfile.close();
+ tmpfile.setAutoRemove(false);
+ temp_filename = tmpfile.fileName();
}
- QList<Session*> sessions = VSession::readXmlFile(xml_filename);
+ QList<Session*> sessions = VSession::readXmlFile(temp_filename);
this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1);