From 821b8abe4d40227ada5bf2a3852dcff440bb53e3 Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Thu, 6 Mar 2014 17:18:26 +0100 Subject: added backup file functionallity --- src/dialog.cpp | 56 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'src/dialog.cpp') 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")); } -- cgit v1.2.3-55-g7522