From d2be02fceb3b2f1cd2fe4720560acc85a6c331be Mon Sep 17 00:00:00 2001 From: Nils Schwabe Date: Mon, 31 Mar 2014 16:32:44 +0200 Subject: Help/News improvement, added ini settings, made some translations for new text elemtents, cleaned code --- src/dialog.cpp | 61 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 34 deletions(-) (limited to 'src/dialog.cpp') diff --git a/src/dialog.cpp b/src/dialog.cpp index 4e65d16..6236208 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -202,6 +202,7 @@ bool Dialog::selectSession(const QString& name) { // change the tab onTabButtonChanged(tab); // set selection + ui->treeView->selectionModel()->clearSelection(); ui->treeView->selectionModel() ->setCurrentIndex(index, QItemSelectionModel::Select); return true; @@ -213,8 +214,10 @@ bool Dialog::selectSession(const QString& name) { } void Dialog::selectPreviousSession() { - qDebug() << "selecting previous session"; - selectSession(ChooserSettings::getSetting("last-session")); + if (!ChooserSettings::getSetting("last-session").isEmpty()) { + ui->treeView->clearSelection(); + selectSession(ChooserSettings::getSetting("last-session")); + } } void Dialog::startSession(const QString& name) { @@ -301,23 +304,16 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { this->addLabelItem(QCoreApplication::instance()->translate("Dialog", "URL Error"), 1); return; } - if (debugMode) { qDebug() << "Used backup file " << xml_backup_filename; } - backup_file.close(); QList sessions = VSession::readXmlFile(xml_backup_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; @@ -326,11 +322,9 @@ void Dialog::addSessionsAfterDownload(QNetworkReply* reply) { } QByteArray data = reply->readAll(); - if (file.write(data) != data.length()) { return; } - file.close(); } @@ -373,7 +367,6 @@ void Dialog::treeView_selectionChanged(const QModelIndex& current, const QModelI ui->label_os->setText(vs->getAttribute("os", "param")); ui->label_os->setToolTip(vs->getAttribute("os", "param")); - //ui->textBrowser->setText(vs->getAttribute("long_description", "param")); QString description(vs->getAttribute("long_description", "param") + "\n\nKeywords: "); for (int i = 0; i < vs->keywords().length(); ++i) { description += vs->keywords()[i] + ", "; @@ -410,18 +403,6 @@ void Dialog::onTabButtonChanged(int tab) { // give focus to treeView ui->treeView->setFocus(); - // one button needs to be enabled - if (this->activeTab == tab) { - switch (tab) { - case 0: ui->tabButtonLocal->setChecked(true); break; - case 1: ui->tabButtonMyClasses->setChecked(true); break; - case 2: ui->tabButtonAllClasses->setChecked(true); break; - } - } - - - this->activeTab = tab; - // when button was pressed disable the other buttons if (tab == 0) { ui->tabButtonLocal->setChecked(true); @@ -442,26 +423,26 @@ void Dialog::onTabButtonChanged(int tab) { // 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().length() > 2) { + 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->model()->deleteLater(); } ui->treeView->setModel(model); @@ -502,16 +483,18 @@ void Dialog::addNewsAfterDownload(QNetworkReply* reply) { QDateTime timestamp; timestamp.setTime_t(newsNode.firstChildElement("date").text().toInt()); - if (ChooserSettings::getSetting("last-news").toUInt() > timestamp.toTime_t()) { - return; - } - // format and print news ui->newsTextBrowser->setText(QString("

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

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

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

")); - on_helpNewsButton_clicked(); + if (ChooserSettings::getSetting("last-news").toUInt() < timestamp.toTime_t()) { + // show news if not seen before + on_helpNewsButton_clicked(); + } + + // update ini + ChooserSettings::setSetting("last-news", QString::number(timestamp.toTime_t())); } void Dialog::addHelpAfterDownload(QNetworkReply* reply) { @@ -521,14 +504,24 @@ void Dialog::addHelpAfterDownload(QNetworkReply* reply) { } return; } - QByteArray data = reply->readAll(); + QByteArray data = reply->readAll(); QDomDocument doc; + if (!doc.setContent(data)) { - qDebug() << "Help file contains errors."; + if (debugMode) { + qDebug() << "Help file contains errors."; + } return; } ui->helpTextBrowser->setText(QString(data)); +} +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; + } } -- cgit v1.2.3-55-g7522