From 5103900bfeb0feced5b58d68924479bfc73d8ec5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 4 May 2014 12:56:35 +0200 Subject: Lots of fixes, cleanup, refactoring * Added command line option to set the base path where images can be accessed locally, in case NFS/CIFS is used. * Sorted command line options in source file to make it easier to add new options (prevent accidental shortopt collisions). * Disable "My Courses" button if the list is empty. * Added some TODO notes :> --- src/dialog.cpp | 609 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 300 insertions(+), 309 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 009da02..ecfc097 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -23,6 +23,9 @@ Dialog::Dialog(QWidget *parent) model_[2] = new SessionTreeModel(parent); ui->setupUi(this); + tabs_[0] = ui->tabButtonLocal; + tabs_[1] = ui->tabButtonMyClasses; + tabs_[2] = ui->tabButtonAllClasses; pvsSettings_ = NULL; ui->PVSOptionsGroupBox->hide(); @@ -38,13 +41,13 @@ Dialog::Dialog(QWidget *parent) ui->tabButtonLocal->setChecked(true); ui->filterEdit->setEnabled(false); - ui->helpBox->hide(); - ui->newsBox->hide(); - - setListModel(model_[0]); + ui->helpBox->hide(); + ui->newsBox->hide(); QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), - this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); + this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); + + this->onTabButtonChanged(2); } Dialog::~Dialog() { @@ -76,7 +79,7 @@ void Dialog::on_treeView_activated(QModelIndex index) { // no valid session has been selected, do nothing return; } - + // Run session start script if (QFile::exists(sessionStartScript)) { QProcess scriptProcess; @@ -99,24 +102,27 @@ void Dialog::on_treeView_activated(QModelIndex index) { } void Dialog::addItems(const QList& entries, int tab) { - if (tab < 0 || tab > 2) { - return; - } + if (tab < 0 || tab > 2) { + return; + } this->model_[tab]->addItems(entries); + tabs_[tab]->setEnabled(this->model_[tab]->rowCount() != 0); } void Dialog::addLabelItem(const QString& label, int tab) { - if (tab < 0 || tab > 2) { - return; - } - this->model_[tab]->addLabelItem(label); + if (tab < 0 || tab > 2) { + return; + } + this->model_[tab]->addLabelItem(label); + tabs_[tab]->setEnabled(this->model_[tab]->rowCount() != 0); } void Dialog::removeItem(const QString& name, int tab) { - if (tab < 0 || tab > 2) { - return; - } - this->model_[tab]->removeItem(name); + if (tab < 0 || tab > 2) { + return; + } + this->model_[tab]->removeItem(name); + tabs_[tab]->setEnabled(this->model_[tab]->rowCount() != 0); } void Dialog::on_pushButtonAbort_clicked() { @@ -190,39 +196,39 @@ bool Dialog::selectSession(const QString& name) { QModelIndex root(ui->treeView->rootIndex()); for (int tab = 0; tab <= 2; ++tab) { - for (int i = 0; i < model_[tab]->rowCount(root); ++i) { - QModelIndex index = model_[tab]->index(i, 0, root); - if (!index.isValid()) { - break; - } - SessionTreeItem* item = static_cast(index.internalPointer()); - const Session* s(item->session()); - if (!s) { - continue; - } - if (s->shortDescription() == name) { - // change the tab - onTabButtonChanged(tab); - // set selection - ui->treeView->selectionModel()->clearSelection(); - ui->treeView->selectionModel() - ->setCurrentIndex(index, QItemSelectionModel::Select); - return true; - } - } + for (int i = 0; i < model_[tab]->rowCount(root); ++i) { + QModelIndex index = model_[tab]->index(i, 0, root); + if (!index.isValid()) { + break; + } + SessionTreeItem* item = static_cast(index.internalPointer()); + const Session* s(item->session()); + if (!s) { + continue; + } + if (s->shortDescription() == name) { + // change the tab + onTabButtonChanged(tab); + // set selection + ui->treeView->selectionModel()->clearSelection(); + ui->treeView->selectionModel() + ->setCurrentIndex(index, QItemSelectionModel::Select); + return true; + } + } } return false; } void Dialog::selectPreviousSession() { - if (!ChooserSettings::getSetting("last-session").isEmpty()) { - ui->treeView->clearSelection(); - if (!selectSession(ChooserSettings::getSetting("last-session"))) { - // could not find last session, change to last used tab - this->onTabButtonChanged(ChooserSettings::getSetting("last-tab").toInt()); - } - } + if (!ChooserSettings::getSetting("last-session").isEmpty()) { + ui->treeView->clearSelection(); + if (!selectSession(ChooserSettings::getSetting("last-session"))) { + // could not find last session, change to last used tab + this->onTabButtonChanged(ChooserSettings::getSetting("last-tab").toInt()); + } + } } void Dialog::startSession(const QString& name) { @@ -240,38 +246,38 @@ void Dialog::showSettingsPVS() { } void Dialog::setTheme() { - QString label_l_style, label_r_style; - QString backgroundColor, imageLeft, imageRight; - QString themePathBase, themePathIni, themePathImgLeft, themePathImgRight; + QString label_l_style, label_r_style; + QString backgroundColor, imageLeft, imageRight; + QString themePathBase, themePathIni, themePathImgLeft, themePathImgRight; - if (theme.isEmpty()) return; + if (theme.isEmpty()) return; - themePathBase = QString("%1/%2/").arg(VMCHOOSER_THEME_BASE).arg(theme); - themePathIni = QString("%1%2.ini").arg(themePathBase).arg(theme); + themePathBase = QString("%1/%2/").arg(VMCHOOSER_THEME_BASE).arg(theme); + themePathIni = QString("%1%2.ini").arg(themePathBase).arg(theme); - if (!QFile::exists(themePathIni)) return; + if (!QFile::exists(themePathIni)) return; - QSettings themeSettings(themePathIni, QSettings::IniFormat); - backgroundColor = themeSettings.value("background-color").toString(); - imageLeft = themeSettings.value("image-left").toString(); - imageRight = themeSettings.value("image-right").toString(); + QSettings themeSettings(themePathIni, QSettings::IniFormat); + backgroundColor = themeSettings.value("background-color").toString(); + imageLeft = themeSettings.value("image-left").toString(); + imageRight = themeSettings.value("image-right").toString(); - themePathImgLeft = QString("%1%2").arg(themePathBase).arg(imageLeft); - themePathImgRight = QString("%1%2").arg(themePathBase).arg(imageRight); + themePathImgLeft = QString("%1%2").arg(themePathBase).arg(imageLeft); + themePathImgRight = QString("%1%2").arg(themePathBase).arg(imageRight); - QRegExp re; + QRegExp re; - ui->label_l->setPixmap(QPixmap(themePathImgLeft)); - ui->label_r->setPixmap(QPixmap(themePathImgRight)); - label_l_style = ui->label_l->styleSheet(); - label_r_style = ui->label_r->styleSheet(); - backgroundColor.prepend("\\1").append("\\2"); - label_l_style.replace(QRegExp("(.*background-color:)#[^;]*(;.*)"), backgroundColor); - label_r_style.replace(QRegExp("(.*background-color:)#[^;]*(;.*)"), backgroundColor); + ui->label_l->setPixmap(QPixmap(themePathImgLeft)); + ui->label_r->setPixmap(QPixmap(themePathImgRight)); + label_l_style = ui->label_l->styleSheet(); + label_r_style = ui->label_r->styleSheet(); + backgroundColor.prepend("\\1").append("\\2"); + label_l_style.replace(QRegExp("(.*background-color:)#[^;]*(;.*)"), backgroundColor); + label_r_style.replace(QRegExp("(.*background-color:)#[^;]*(;.*)"), backgroundColor); //qDebug() << label_r_style << label_l_style; - ui->label_l->setStyleSheet(label_l_style); - ui->label_r->setStyleSheet(label_r_style); + ui->label_l->setStyleSheet(label_l_style); + ui->label_r->setStyleSheet(label_r_style); } void Dialog::onCenterTimer() { @@ -294,58 +300,56 @@ 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_filename); - - if (!backup_file.open(QIODevice::ReadOnly)) { - if (debugMode) { - 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_filename; - } - backup_file.close(); - - QList sessions = VSession::readXmlFile(xml_filename); - qSort(sessions.begin(), sessions.end(), myLessThan); - this->addItems(sessions, 1); - } else { - QByteArray data = reply->readAll(); - - // 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 sessions = VSession::readXmlFile(temp_filename); - - this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1); - - if (!sessions.isEmpty()) { - qSort(sessions.begin(), sessions.end(), myLessThan); - this->addItems(sessions, 1); - } else { - this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), 1); - } - - // select last-session - selectPreviousSession(); + QString temp_filename; + + if (reply->error() != QNetworkReply::NoError) { + if (debugMode) { + qDebug() << "Error reading from URL: " << reply->error(); + } + + QFile backup_file(xml_filename); + + if (!backup_file.open(QIODevice::ReadOnly)) { + if (debugMode) { + 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() << "Using backup file " << xml_filename; + } + backup_file.close(); + + temp_filename = xml_filename; + } else { + QByteArray data = reply->readAll(); + + // 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 sessions = VSession::readXmlFile(temp_filename); + + this->removeItem(QCoreApplication::instance()->translate("Dialog", "Loading..."), 1); + + if (!sessions.isEmpty()) { + qSort(sessions.begin(), sessions.end(), myLessThan); + this->addItems(sessions, 2); // TODO: No magic number; handle user specific classes + } else { + this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "No Items"), 1); + } + + // select last-session + selectPreviousSession(); } void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelIndex&) { @@ -354,253 +358,240 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI const Session* s(item->session()); if (!s) { - if (debugMode) { - qDebug() << "invalid selection"; - } + if (debugMode) { + qDebug() << "invalid selection"; + } // no valid session has been selected, do nothing return; } if (s->type() == Session::VSESSION) { - const VSession* vs = (VSession*) s; + const VSession* vs = (VSession*) s; - ui->label_name->setText(vs->getAttribute("short_description", "param")); - ui->label_name->setToolTip(vs->getAttribute("short_description", "param")); + ui->label_name->setText(vs->getAttribute("short_description", "param")); + ui->label_name->setToolTip(vs->getAttribute("short_description", "param")); - ui->label_creator->setText(vs->getAttribute("creator", "param")); - ui->label_creator->setToolTip(vs->getAttribute("creator", "param")); + ui->label_creator->setText(vs->getAttribute("creator", "param")); + ui->label_creator->setToolTip(vs->getAttribute("creator", "param")); - ui->label_os->setText(vs->getAttribute("os", "param")); - ui->label_os->setToolTip(vs->getAttribute("os", "param")); + ui->label_os->setText(vs->getAttribute("os", "param")); + ui->label_os->setToolTip(vs->getAttribute("os", "param")); - QString description(vs->getAttribute("long_description", "param") + "\n\nKeywords: "); - for (int i = 0; i < vs->keywords().length(); ++i) { - description += vs->keywords()[i] + ", "; - } + QString description(vs->getAttribute("long_description", "param") + "\n\nKeywords: "); + for (int i = 0; i < vs->keywords().length(); ++i) { + description += vs->keywords()[i] + ", "; + } - ui->textBrowser->setText(description); + ui->textBrowser->setText(description); } else { - ui->label_name->setText(s->shortDescription()); - ui->label_creator->setText(""); - ui->label_os->setText(QCoreApplication::instance()->translate("Dialog", "Native")); - ui->textBrowser->setPlainText(QCoreApplication::instance()->translate("Dialog", "Running on this machine.")); + ui->label_name->setText(s->shortDescription()); + ui->label_creator->setText(""); + ui->label_os->setText(QCoreApplication::instance()->translate("Dialog", "Native")); + ui->textBrowser->setPlainText(QCoreApplication::instance()->translate("Dialog", "Running on this machine.")); } } void Dialog::on_tabButtonLocal_clicked() { - onTabButtonChanged(0); + onTabButtonChanged(0); } void Dialog::on_tabButtonMyClasses_clicked() { - onTabButtonChanged(1); + onTabButtonChanged(1); } void Dialog::on_tabButtonAllClasses_clicked() { - onTabButtonChanged(2); + onTabButtonChanged(2); } void Dialog::onTabButtonChanged(int tab) { - if (tab < 0 || tab > 2) { - // no valid button - return; - } - - // give focus to treeView - ui->treeView->setFocus(); - - // when button was pressed disable the other buttons - if (tab == 0) { - ui->tabButtonLocal->setChecked(true); - ui->tabButtonMyClasses->setChecked(false); - ui->tabButtonAllClasses->setChecked(false); - ui->filterEdit->setEnabled(false); - } else if (tab == 1) { - ui->tabButtonLocal->setChecked(false); - ui->tabButtonMyClasses->setChecked(true); - ui->tabButtonAllClasses->setChecked(false); - ui->filterEdit->setEnabled(true); - } else { - ui->tabButtonLocal->setChecked(false); - ui->tabButtonMyClasses->setChecked(false); - ui->tabButtonAllClasses->setChecked(true); - ui->filterEdit->setEnabled(true); - } - - // clear filter if necessary - if (activeTab != tab) { - this->ui->filterEdit->setText(""); - } - - // load the new list - setListModel(model_[tab]); - this->activeTab = tab; + if (tab < 0 || tab > 2) { + // no valid button + return; + } + + // give focus to treeView + ui->treeView->setFocus(); + + // Update pressed status of buttons + for (int i = 0; i < 3; ++i) { + tabs_[i]->setChecked(tab == i); + } + + // clear filter if necessary + if (activeTab != tab) { + this->ui->filterEdit->setText(""); + } + + // load the new list + setListModel(model_[tab]); + this->activeTab = tab; } void Dialog::on_filterEdit_textChanged() { - SessionTreeModel *newModel; - - // filter the current model - if (ui->filterEdit->text() != "" && ui->filterEdit->text().replace(" ", "").length() > 2) { - newModel = new SessionTreeModel(this); - newModel->addItems(this->model_[activeTab]->lookForItem(ui->filterEdit->text())); - } else { - newModel = model_[activeTab]; - } - setListModel(newModel); + SessionTreeModel *newModel; + + // filter the current model + if (ui->filterEdit->text() != "" && ui->filterEdit->text().replace(" ", "").length() > 2) { + newModel = new SessionTreeModel(this); + newModel->addItems(this->model_[activeTab]->lookForItem(ui->filterEdit->text())); + } else { + newModel = model_[activeTab]; + } + setListModel(newModel); } void Dialog::setListModel(QAbstractItemModel *model) { - if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) { - } else { - ui->treeView->model()->deleteLater(); - } - ui->treeView->setModel(model); + if (ui->treeView->model() == model_[0] || ui->treeView->model() == model_[1] || ui->treeView->model() == model_[2]) { + } else { + ui->treeView->model()->deleteLater(); + } + ui->treeView->setModel(model); - // reconnect the treeModel + // reconnect the treeModel QObject::connect(ui->treeView->selectionModel(), SIGNAL(currentChanged ( const QModelIndex&, const QModelIndex&)), - this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); + this, SLOT(treeView_selectionChanged(const QModelIndex&, const QModelIndex&))); - if (ui->treeView->selectionModel()->selectedRows(0).count() == 0) { - ui->treeView->selectionModel()->clearSelection(); - ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select); - } + if (ui->treeView->selectionModel()->selectedRows(0).count() == 0) { + ui->treeView->selectionModel()->clearSelection(); + ui->treeView->selectionModel()->setCurrentIndex(ui->treeView->model()->index(0, 0, ui->treeView->rootIndex()), QItemSelectionModel::Select); + } } void Dialog::on_helpNewsButton_clicked() { - if (ui->helpBox->isVisible()) { - ui->helpBox->hide(); - ui->newsBox->hide(); - } else { - ui->helpBox->show(); - ui->newsBox->show(); - } + if (ui->helpBox->isVisible()) { + ui->helpBox->hide(); + ui->newsBox->hide(); + } else { + ui->helpBox->show(); + ui->newsBox->show(); + } } void Dialog::addNewsAfterDownload(QNetworkReply* reply) { - if (reply->error() != QNetworkReply::NoError) { - if (debugMode) { - qDebug() << "Could not get news. Try to get cached news."; - } - - // try to get cached news - QFile backup_file(news_backup_filename); - - if (!backup_file.open(QIODevice::ReadOnly)) { - if (debugMode) { - qDebug() << "Cannot read backup file " << news_backup_filename << " either"; - } - this->ui->newsTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get news.")); - return; - } - if (debugMode) { - qDebug() << "Used backup file " << news_backup_filename; - } - backup_file.close(); - return; - } - QByteArray data = reply->readAll(); - QDomDocument doc; - if (!doc.setContent(data)) { - qDebug() << "News XML contains errors."; - return; - } + if (reply->error() != QNetworkReply::NoError) { + if (debugMode) { + qDebug() << "Could not get news. Try to get cached news."; + } + + // try to get cached news + QFile backup_file(news_backup_filename); + + if (!backup_file.open(QIODevice::ReadOnly)) { + if (debugMode) { + qDebug() << "Cannot read backup file " << news_backup_filename << " either"; + } + this->ui->newsTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get news.")); + return; + } + if (debugMode) { + qDebug() << "Used backup file " << news_backup_filename; + } + backup_file.close(); + return; + } + QByteArray data = reply->readAll(); + QDomDocument doc; + if (!doc.setContent(data)) { + qDebug() << "News XML contains errors."; + return; + } QDomElement newsNode = doc.firstChildElement("news"); QDateTime timestamp; timestamp.setTime_t(newsNode.firstChildElement("date").text().toInt()); // format and print news ui->newsTextBrowser->setText(QString("

" + newsNode.firstChildElement("headline").text() + "

" - + timestamp.toString(Qt::SystemLocaleShortDate) + "

" - + newsNode.firstChildElement("info").text() + "

")); + + timestamp.toString(Qt::SystemLocaleShortDate) + "

" + + newsNode.firstChildElement("info").text() + "

")); if (ChooserSettings::getSetting("last-news").toUInt() < timestamp.toTime_t()) { - // show news if not seen before - on_helpNewsButton_clicked(); + // show news if not seen before + on_helpNewsButton_clicked(); } // update ini ChooserSettings::setSetting("last-news", QString::number(timestamp.toTime_t())); - // make backup - QFile file(news_backup_filename); - if (!file.open(QIODevice::WriteOnly)) { - if (debugMode) { - qDebug() << "Could not write XML to " << xml_filename; - } - return; - } - - 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(); + // make backup + QFile file(news_backup_filename); + if (!file.open(QIODevice::WriteOnly)) { + if (debugMode) { + qDebug() << "Could not write XML to " << news_backup_filename; + } + return; + } + + 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(); } void Dialog::addHelpAfterDownload(QNetworkReply* reply) { - if (reply->error() != QNetworkReply::NoError) { - if (debugMode) { - qDebug() << "Could not get help xml. Try to get cached help..."; - } - - // try to get cached news - QFile backup_file(help_backup_filename); - - if (!backup_file.open(QIODevice::ReadOnly)) { - if (debugMode) { - qDebug() << "Cannot read backup file " << help_backup_filename << " either"; - } - this->ui->helpTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get help.")); - return; - } - if (debugMode) { - qDebug() << "Used backup file " << help_backup_filename; - } - backup_file.close(); - return; - } - - QByteArray data = reply->readAll(); - QDomDocument doc; - - if (!doc.setContent(data)) { - if (debugMode) { - qDebug() << "Help file contains errors."; - } - return; - } - - ui->helpTextBrowser->setText(QString(data)); - - // make backup - QFile file(help_backup_filename); - if (!file.open(QIODevice::WriteOnly)) { - if (debugMode) { - qDebug() << "Could not write XML to " << xml_filename; - } - return; - } - - 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: " << help_backup_filename; - } - } - file.close(); + if (reply->error() != QNetworkReply::NoError) { + if (debugMode) { + qDebug() << "Could not get help xml. Try to get cached help..."; + } + + // try to get cached news + QFile backup_file(help_backup_filename); + + if (!backup_file.open(QIODevice::ReadOnly)) { + if (debugMode) { + qDebug() << "Cannot read backup file " << help_backup_filename << " either"; + } + this->ui->helpTextBrowser->setText(QCoreApplication::instance()->translate("Dialog", "Could not get help.")); + return; + } + if (debugMode) { + qDebug() << "Used backup file " << help_backup_filename; + } + backup_file.close(); + return; + } + + QByteArray data = reply->readAll(); + QDomDocument doc; + + if (!doc.setContent(data)) { + if (debugMode) { + qDebug() << "Help file contains errors."; + } + return; + } + + ui->helpTextBrowser->setText(QString(data)); + + // make backup + QFile file(help_backup_filename); + if (!file.open(QIODevice::WriteOnly)) { + if (debugMode) { + qDebug() << "Could not write XML to " << help_backup_filename; + } + return; + } + + 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: " << help_backup_filename; + } + } + file.close(); } void Dialog::keyPressEvent(QKeyEvent* event) { - switch(event->key()) { - case Qt::Key_Return: this->on_pushButtonStart_clicked(); break; - case Qt::Key_Escape: this->on_pushButtonAbort_clicked(); break; - case Qt::Key_H: this->on_helpNewsButton_clicked(); break; - } + switch(event->key()) { + case Qt::Key_Return: this->on_pushButtonStart_clicked(); break; + case Qt::Key_Escape: this->on_pushButtonAbort_clicked(); break; + case Qt::Key_H: this->on_helpNewsButton_clicked(); break; + } } -- cgit v1.2.3-55-g7522