From dd1c1e64e5b6e9119abe8a80bcc2a7ea92b11e25 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 20 Feb 2014 17:08:12 +0100 Subject: [PATCH] Work on updating... --- src/core/systemfactory.cpp | 48 ++++++++++++------- src/core/systemfactory.h | 8 +++- src/gui/formsettings.cpp | 10 ++-- src/gui/formstandardfeeddetails.cpp | 3 ++ src/gui/formupdate.cpp | 73 +++++++++++------------------ src/gui/formupdate.h | 1 - src/gui/formupdate.ui | 37 ++++++++++----- src/gui/labelwithstatus.cpp | 9 ++-- src/gui/labelwithstatus.h | 4 +- 9 files changed, 109 insertions(+), 84 deletions(-) diff --git a/src/core/systemfactory.cpp b/src/core/systemfactory.cpp index 86415350d..5df203eee 100644 --- a/src/core/systemfactory.cpp +++ b/src/core/systemfactory.cpp @@ -1,6 +1,7 @@ #include "core/systemfactory.h" #include "core/defs.h" +#include "core/networkfactory.h" #if defined(Q_OS_WIN) #include "qtsingleapplication/qtsingleapplication.h" @@ -33,10 +34,10 @@ SystemFactory::AutoStartStatus SystemFactory::getAutoStartStatus() { // User registry way to auto-start the application on Windows. #if defined(Q_OS_WIN) QSettings registry_key("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", - QSettings::NativeFormat); + QSettings::NativeFormat); bool autostart_enabled = registry_key.value(APP_LOW_NAME, - "").toString().replace('\\', - '/') == + "").toString().replace('\\', + '/') == QtSingleApplication::applicationFilePath(); if (autostart_enabled) { @@ -148,19 +149,32 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) { #endif } -QList SystemFactory::parseUpdatesFile(const QByteArray &updates_file) { - QList updates; +QPair SystemFactory::checkForUpdates() { + QPair result; + QByteArray releases_xml; + result.second = NetworkFactory::downloadFeedFile(RELEASES_LIST, + 5000, + releases_xml); + + if (result.second == QNetworkReply::NoError) { + result.first = SystemFactory::instance()->parseUpdatesFile(releases_xml); + } + + return result; +} + +UpdateInfo SystemFactory::parseUpdatesFile(const QByteArray &updates_file) { + UpdateInfo update; QDomDocument document; document.setContent(updates_file, false); QDomNodeList releases = document.elementsByTagName("release"); - for (int i = 0; i < releases.size(); i++) { - UpdateInfo info; + if (releases.size() == 1) { QDomElement rel_elem = releases.at(0).toElement(); QString type = rel_elem.attributes().namedItem("type").toAttr().value(); - info.m_availableVersion = rel_elem.attributes().namedItem("version").toAttr().value(); - info.m_changes = rel_elem.namedItem("changes").toElement().text(); + update.m_availableVersion = rel_elem.attributes().namedItem("version").toAttr().value(); + update.m_changes = rel_elem.namedItem("changes").toElement().text(); QDomNodeList urls = rel_elem.elementsByTagName("url"); @@ -172,19 +186,21 @@ QList SystemFactory::parseUpdatesFile(const QByteArray &updates_file url.m_os = url_elem.attributes().namedItem("os").toAttr().value(); url.m_platform = url_elem.attributes().namedItem("platform").toAttr().value(); - info.m_urls.insert(url.m_os, - url); + update.m_urls.insert(url.m_os, + url); } if (type == "maintenance") { - info.m_type = UpdateInfo::Maintenance; + update.m_type = UpdateInfo::Maintenance; } else { - info.m_type = UpdateInfo::Evolution; + update.m_type = UpdateInfo::Evolution; } - - updates.append(info); + } + else { + update.m_availableVersion = QString(); } - return updates; + + return update; } diff --git a/src/core/systemfactory.h b/src/core/systemfactory.h index 334a58903..410b895dd 100644 --- a/src/core/systemfactory.h +++ b/src/core/systemfactory.h @@ -6,6 +6,8 @@ #include #include #include +#include +#include class UpdateUrl { @@ -39,6 +41,9 @@ class SystemFactory : public QObject { // Constructors and destructors. explicit SystemFactory(QObject *parent = 0); + // Performs parsing of downloaded file with list of updates. + UpdateInfo parseUpdatesFile(const QByteArray &updates_file); + public: // Constructors and destructors. virtual ~SystemFactory(); @@ -64,7 +69,8 @@ class SystemFactory : public QObject { QString getAutostartDesktopFileLocation(); #endif - QList parseUpdatesFile(const QByteArray &updates_file); + // Tries to download list with new updates. + QPair checkForUpdates(); // Access to application-wide close lock. inline QMutex *applicationCloseLock() const { diff --git a/src/gui/formsettings.cpp b/src/gui/formsettings.cpp index 6389f8155..f048ff20d 100755 --- a/src/gui/formsettings.cpp +++ b/src/gui/formsettings.cpp @@ -446,7 +446,8 @@ void FormSettings::loadDataStorage() { onMysqlPasswordChanged(QString()); m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Information, - tr("No connection test triggered so far.")); + tr("No connection test triggered so far."), + tr("You dit not executed any connection test yet.")); // Load SQLite. m_ui->m_cmbDatabaseDriver->addItem( @@ -517,16 +518,19 @@ void FormSettings::mysqlTestConnection() { m_ui->m_spinMysqlPort->value(), m_ui->m_txtMysqlUsername->lineEdit()->text(), m_ui->m_txtMysqlPassword->lineEdit()->text()); + QString interpretation = DatabaseFactory::instance()->mysqlInterpretErrorCode(error_code); switch (error_code) { case DatabaseFactory::MySQLOk: m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Ok, - DatabaseFactory::instance()->mysqlInterpretErrorCode(error_code)); + interpretation, + interpretation); break; default: m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Error, - DatabaseFactory::instance()->mysqlInterpretErrorCode(error_code)); + interpretation, + interpretation); break; diff --git a/src/gui/formstandardfeeddetails.cpp b/src/gui/formstandardfeeddetails.cpp index 4ea04cf10..efb3bd1ce 100644 --- a/src/gui/formstandardfeeddetails.cpp +++ b/src/gui/formstandardfeeddetails.cpp @@ -257,11 +257,13 @@ void FormStandardFeedDetails::guessFeed() { Qt::MatchFixedString)); m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Ok, + tr("Feed metada fetched."), tr("Feed metadata fetched successfully.")); } else { // No feed guessed, even no icon available. m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Error, + tr("Error occurred."), tr("Error occurred.")); } } @@ -377,6 +379,7 @@ void FormStandardFeedDetails::initialize() { // Set feed metadata fetch label. m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Information, + tr("No metadata fetched so far."), tr("No metadata fetched so far.")); // Setup auto-update options. diff --git a/src/gui/formupdate.cpp b/src/gui/formupdate.cpp index 702678408..b693593c9 100755 --- a/src/gui/formupdate.cpp +++ b/src/gui/formupdate.cpp @@ -24,11 +24,7 @@ FormUpdate::FormUpdate(QWidget *parent) MessageBox::iconify(m_ui->m_buttonBox); #endif - connect(m_ui->m_cmbAvailableRelease->comboBox(), SIGNAL(currentIndexChanged(int)), - this, SLOT(updateChanges(int))); - m_ui->m_lblCurrentRelease->setText(APP_VERSION); - checkForUpdates(); } @@ -43,52 +39,37 @@ FormUpdate::~FormUpdate() { // asi. jednotlivy URL souborů pro danej release // sou dostupny v qhashi podle klice podle OS. -void FormUpdate::updateChanges(int new_release_index) { - if (new_release_index >= 0) { - UpdateInfo info = m_ui->m_cmbAvailableRelease->comboBox()->itemData(new_release_index).value(); +void FormUpdate::checkForUpdates() { + QPair update = SystemFactory::instance()->checkForUpdates(); - m_ui->m_txtChanges->setText(info.m_changes); + if (update.second != QNetworkReply::NoError) { + m_ui->m_lblAvailableRelease->setText(tr("unknown")); + m_ui->m_txtChanges->clear(); + m_ui->m_lblStatus->setStatus(WidgetWithStatus::Error, + tr("Connection error occurred."), + tr("List with updates was " + "not\ndownloaded successfully.")); + } + else { + m_ui->m_lblAvailableRelease->setText(update.first.m_availableVersion); + m_ui->m_txtChanges->setText(update.first.m_changes); - if (info.m_availableVersion > APP_VERSION) { - m_ui->m_cmbAvailableRelease->setStatus(WidgetWithStatus::Ok, - tr("This is new version which can be\ndownloaded and installed.")); + if (update.first.m_availableVersion > APP_VERSION) { +#if defined(Q_OS_WIN) || defined(Q_OS_OS2) + m_ui->m_lblStatus->setStatus(WidgetWithStatus::Ok, + tr("New release available."), + tr("This is new version which can be\ndownloaded and installed.")); + // TODO: Display "update" button. +#else + m_ui->m_lblStatus->setStatus(WidgetWithStatus::Ok, + tr("New release available."), + tr("This is new version. Upgrade to it manually or via your system package manager.")); +#endif } else { - m_ui->m_cmbAvailableRelease->setStatus(WidgetWithStatus::Warning, - tr("This release is not newer than\ncurrently installed one..")); + m_ui->m_lblStatus->setStatus(WidgetWithStatus::Warning, + tr("No new releases available."), + tr("This release is not newer than\ncurrently installed one..")); } - - m_ui->m_lblPlatforms->setText(QStringList(info.m_urls.keys()).join(", ")); - - // TODO: PODLE definice OS_ID (defs.h) se zjisti esli info.m_urls.keys() - // obsahuje instalacni soubor pro danou platformu - // a pokud ano tak se umoznuje update (jen windows a os2) - // budou zahrnuty i "prazdne" soubory pro ostatni platformy - // ale na tech nebude mozno updatovat. - } -} - -void FormUpdate::checkForUpdates() { - QByteArray releases_xml; - QNetworkReply::NetworkError download_result = NetworkFactory::downloadFeedFile(RELEASES_LIST, - 5000, - releases_xml); - - m_ui->m_cmbAvailableRelease->comboBox()->clear(); - - if (download_result != QNetworkReply::NoError) { - m_ui->m_lblPlatforms->setText("-"); - m_ui->m_cmbAvailableRelease->setEnabled(false); - m_ui->m_cmbAvailableRelease->setStatus(WidgetWithStatus::Error, - tr("List with updates was not\ndownloaded successfully.")); - - return; - } - - QList releases_list = SystemFactory::instance()->parseUpdatesFile(releases_xml); - - foreach (const UpdateInfo &release, releases_list) { - m_ui->m_cmbAvailableRelease->comboBox()->addItem(release.m_availableVersion, - QVariant::fromValue(release)); } } diff --git a/src/gui/formupdate.h b/src/gui/formupdate.h index 87c3f2133..24fd49f3a 100644 --- a/src/gui/formupdate.h +++ b/src/gui/formupdate.h @@ -19,7 +19,6 @@ class FormUpdate : public QDialog { virtual ~FormUpdate(); protected slots: - void updateChanges(int new_release_index); void checkForUpdates(); private: diff --git a/src/gui/formupdate.ui b/src/gui/formupdate.ui index aa9a9aa52..fcb82482f 100755 --- a/src/gui/formupdate.ui +++ b/src/gui/formupdate.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 226 + 405 + 259 @@ -36,13 +36,10 @@ - Available releaseS + Available release - - - @@ -52,6 +49,15 @@ + + true + + + false + + + QTextEdit::NoWrap + true @@ -67,17 +73,24 @@ p, li { white-space: pre-wrap; } + + + + + + + - Supported platforms + Status - - - + + + Qt::RightToLeft @@ -97,9 +110,9 @@ p, li { white-space: pre-wrap; } - ComboBoxWithStatus + LabelWithStatus QWidget -
comboboxwithstatus.h
+
labelwithstatus.h
1
diff --git a/src/gui/labelwithstatus.cpp b/src/gui/labelwithstatus.cpp index caf599bf1..ef23db0b1 100644 --- a/src/gui/labelwithstatus.cpp +++ b/src/gui/labelwithstatus.cpp @@ -10,8 +10,8 @@ LabelWithStatus::LabelWithStatus(QWidget *parent) m_wdgInput = new QLabel(this); // Set correct size for the tool button. - int txt_input_height = m_wdgInput->sizeHint().height(); - m_btnStatus->setFixedSize(txt_input_height + 4, txt_input_height + 4); + int label_height = m_wdgInput->sizeHint().height(); + m_btnStatus->setFixedSize(label_height, label_height); // Compose the layout. m_layout->addWidget(m_wdgInput); @@ -22,7 +22,8 @@ LabelWithStatus::~LabelWithStatus() { } void LabelWithStatus::setStatus(WidgetWithStatus::StatusType status, - const QString &label_text) { - WidgetWithStatus::setStatus(status, label_text); + const QString &label_text, + const QString &status_text) { + WidgetWithStatus::setStatus(status, status_text); label()->setText(label_text); } diff --git a/src/gui/labelwithstatus.h b/src/gui/labelwithstatus.h index 355f66409..62b3cf4bb 100644 --- a/src/gui/labelwithstatus.h +++ b/src/gui/labelwithstatus.h @@ -14,7 +14,9 @@ class LabelWithStatus : public WidgetWithStatus { explicit LabelWithStatus(QWidget *parent = 0); virtual ~LabelWithStatus(); - void setStatus(StatusType status, const QString &label_text); + void setStatus(StatusType status, + const QString &label_text, + const QString &status_text); // Access to label. inline QLabel *label() const {