Work on updating...

This commit is contained in:
Martin Rotter 2014-02-20 17:08:12 +01:00
parent 2d2c371943
commit dd1c1e64e5
9 changed files with 109 additions and 84 deletions

View File

@ -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<UpdateInfo> SystemFactory::parseUpdatesFile(const QByteArray &updates_file) {
QList<UpdateInfo> updates;
QPair<UpdateInfo, QNetworkReply::NetworkError> SystemFactory::checkForUpdates() {
QPair<UpdateInfo, QNetworkReply::NetworkError> 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<UpdateInfo> 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;
}

View File

@ -6,6 +6,8 @@
#include <QMutex>
#include <QMetaType>
#include <QHash>
#include <QPair>
#include <QNetworkReply>
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<UpdateInfo> parseUpdatesFile(const QByteArray &updates_file);
// Tries to download list with new updates.
QPair<UpdateInfo, QNetworkReply::NetworkError> checkForUpdates();
// Access to application-wide close lock.
inline QMutex *applicationCloseLock() const {

View File

@ -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;

View File

@ -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.

View File

@ -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<UpdateInfo>();
void FormUpdate::checkForUpdates() {
QPair<UpdateInfo, QNetworkReply::NetworkError> 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<UpdateInfo> 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));
}
}

View File

@ -19,7 +19,6 @@ class FormUpdate : public QDialog {
virtual ~FormUpdate();
protected slots:
void updateChanges(int new_release_index);
void checkForUpdates();
private:

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>226</height>
<width>405</width>
<height>259</height>
</rect>
</property>
<property name="windowTitle">
@ -36,13 +36,10 @@
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Available releaseS</string>
<string>Available release</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="ComboBoxWithStatus" name="m_cmbAvailableRelease" native="true"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
@ -52,6 +49,15 @@
</item>
<item row="3" column="1">
<widget class="QTextEdit" name="m_txtChanges">
<property name="tabChangesFocus">
<bool>true</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="lineWrapMode">
<enum>QTextEdit::NoWrap</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
@ -67,17 +73,24 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="m_lblAvailableRelease">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Supported platforms</string>
<string>Status</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="m_lblPlatforms">
<property name="text">
<string/>
<widget class="LabelWithStatus" name="m_lblStatus" native="true">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
</widget>
</item>
@ -97,9 +110,9 @@ p, li { white-space: pre-wrap; }
</widget>
<customwidgets>
<customwidget>
<class>ComboBoxWithStatus</class>
<class>LabelWithStatus</class>
<extends>QWidget</extends>
<header>comboboxwithstatus.h</header>
<header>labelwithstatus.h</header>
<container>1</container>
</customwidget>
</customwidgets>

View File

@ -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);
}

View File

@ -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 {