summaryrefslogtreecommitdiffstats
path: root/src/dialog.cpp
diff options
context:
space:
mode:
authorNils Schwabe2014-03-06 17:18:26 +0100
committerNils Schwabe2014-03-06 17:18:26 +0100
commit821b8abe4d40227ada5bf2a3852dcff440bb53e3 (patch)
tree00dd62dbc3af40f85d0dd9e4d984441802b3fb8d /src/dialog.cpp
parentvmchooser is now able to get vsessions from a given url (diff)
downloadvmchooser2-821b8abe4d40227ada5bf2a3852dcff440bb53e3.tar.gz
vmchooser2-821b8abe4d40227ada5bf2a3852dcff440bb53e3.tar.xz
vmchooser2-821b8abe4d40227ada5bf2a3852dcff440bb53e3.zip
added backup file functionallity
Diffstat (limited to 'src/dialog.cpp')
-rw-r--r--src/dialog.cpp56
1 files changed, 39 insertions, 17 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index def152c..38711c3 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -26,7 +26,7 @@ Dialog::Dialog(QWidget *parent)
QRect desktopRect = QApplication::desktop()->availableGeometry(this);
oldCenter_ = desktopRect.center();
centerTimer_ = new QTimer(this);
- connect(centerTimer_, SIGNAL(timeout()), this, SLOT(on_centerTimer()));
+ connect(centerTimer_, SIGNAL(timeout()), this, SLOT(onCenterTimer()));
centerTimer_->start(1000);
}
@@ -228,7 +228,7 @@ void Dialog::setTheme() {
ui->label_r->setStyleSheet(label_r_style);
}
-void Dialog::on_centerTimer() {
+void Dialog::onCenterTimer() {
if (!autoStartEntry_.isEmpty()) {
if (this->selectSession(autoStartEntry_)) {
this->on_treeView_activated(ui->treeView->selectionModel()->currentIndex());
@@ -248,29 +248,51 @@ void Dialog::on_centerTimer() {
}
void Dialog::addSessionsAfterDownload(QNetworkReply* reply) {
+ QString filename = "/tmp/vmchooser2.xml";
+ QString backup_filename = "/tmp/vmchooser2_backup.xml";
+
if (reply->error() != QNetworkReply::NoError) {
- qDebug() << "Error reading from URL: " << reply->error();
- return;
- }
+ if (debugMode) {
+ qDebug() << "Error reading from URL: " << reply->error();
+ }
- QString xml_doc(reply->readAll());
+ QFile backup_file(backup_filename);
+
+ if (!backup_file.open(QIODevice::ReadOnly)) {
+ if (debugMode) {
+ qDebug() << "Cannot read backup file " << backup_filename << " either";
+ }
+ return;
+ }
- QFile file("/tmp/vmchooser2.xml");
- if (!file.open(QIODevice::WriteOnly)) {
if (debugMode) {
- qDebug() << "Could not write XML to /tmp";
+ qDebug() << "Used backup file " << backup_filename;
}
- return;
- }
- QByteArray data = xml_doc.toUtf8();
+ backup_file.close();
+ this->addItems(VSession::readXmlFile(backup_filename), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
- if (file.write(data) != data.length()) {
- return;
- }
+ } else {
- file.close();
+ QString xml_doc(reply->readAll());
+ QFile file(filename);
+
+ if (!file.open(QIODevice::WriteOnly)) {
+ if (debugMode) {
+ qDebug() << "Could not write XML to " << filename;
+ }
+ return;
+ }
+
+ QByteArray data = xml_doc.toUtf8();
+
+ if (file.write(data) != data.length()) {
+ return;
+ }
+
+ file.close();
+ }
- this->addItems(VSession::readXmlFile(file.fileName()), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
+ this->addItems(VSession::readXmlFile(filename), QCoreApplication::instance()->translate("Dialog", "Virtual Sessions"));
}