Work on updating...
This commit is contained in:
parent
2d2c371943
commit
dd1c1e64e5
@ -1,6 +1,7 @@
|
|||||||
#include "core/systemfactory.h"
|
#include "core/systemfactory.h"
|
||||||
|
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
|
#include "core/networkfactory.h"
|
||||||
|
|
||||||
#if defined(Q_OS_WIN)
|
#if defined(Q_OS_WIN)
|
||||||
#include "qtsingleapplication/qtsingleapplication.h"
|
#include "qtsingleapplication/qtsingleapplication.h"
|
||||||
@ -148,19 +149,32 @@ bool SystemFactory::setAutoStartStatus(const AutoStartStatus &new_status) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<UpdateInfo> SystemFactory::parseUpdatesFile(const QByteArray &updates_file) {
|
QPair<UpdateInfo, QNetworkReply::NetworkError> SystemFactory::checkForUpdates() {
|
||||||
QList<UpdateInfo> updates;
|
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);
|
QDomDocument document; document.setContent(updates_file, false);
|
||||||
QDomNodeList releases = document.elementsByTagName("release");
|
QDomNodeList releases = document.elementsByTagName("release");
|
||||||
|
|
||||||
for (int i = 0; i < releases.size(); i++) {
|
if (releases.size() == 1) {
|
||||||
UpdateInfo info;
|
|
||||||
QDomElement rel_elem = releases.at(0).toElement();
|
QDomElement rel_elem = releases.at(0).toElement();
|
||||||
QString type = rel_elem.attributes().namedItem("type").toAttr().value();
|
QString type = rel_elem.attributes().namedItem("type").toAttr().value();
|
||||||
|
|
||||||
info.m_availableVersion = rel_elem.attributes().namedItem("version").toAttr().value();
|
update.m_availableVersion = rel_elem.attributes().namedItem("version").toAttr().value();
|
||||||
info.m_changes = rel_elem.namedItem("changes").toElement().text();
|
update.m_changes = rel_elem.namedItem("changes").toElement().text();
|
||||||
|
|
||||||
QDomNodeList urls = rel_elem.elementsByTagName("url");
|
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_os = url_elem.attributes().namedItem("os").toAttr().value();
|
||||||
url.m_platform = url_elem.attributes().namedItem("platform").toAttr().value();
|
url.m_platform = url_elem.attributes().namedItem("platform").toAttr().value();
|
||||||
|
|
||||||
info.m_urls.insert(url.m_os,
|
update.m_urls.insert(url.m_os,
|
||||||
url);
|
url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == "maintenance") {
|
if (type == "maintenance") {
|
||||||
info.m_type = UpdateInfo::Maintenance;
|
update.m_type = UpdateInfo::Maintenance;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
info.m_type = UpdateInfo::Evolution;
|
update.m_type = UpdateInfo::Evolution;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
update.m_availableVersion = QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
updates.append(info);
|
|
||||||
}
|
|
||||||
|
|
||||||
return updates;
|
return update;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QMetaType>
|
#include <QMetaType>
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
|
#include <QPair>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
|
||||||
|
|
||||||
class UpdateUrl {
|
class UpdateUrl {
|
||||||
@ -39,6 +41,9 @@ class SystemFactory : public QObject {
|
|||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
explicit SystemFactory(QObject *parent = 0);
|
explicit SystemFactory(QObject *parent = 0);
|
||||||
|
|
||||||
|
// Performs parsing of downloaded file with list of updates.
|
||||||
|
UpdateInfo parseUpdatesFile(const QByteArray &updates_file);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
virtual ~SystemFactory();
|
virtual ~SystemFactory();
|
||||||
@ -64,7 +69,8 @@ class SystemFactory : public QObject {
|
|||||||
QString getAutostartDesktopFileLocation();
|
QString getAutostartDesktopFileLocation();
|
||||||
#endif
|
#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.
|
// Access to application-wide close lock.
|
||||||
inline QMutex *applicationCloseLock() const {
|
inline QMutex *applicationCloseLock() const {
|
||||||
|
@ -446,7 +446,8 @@ void FormSettings::loadDataStorage() {
|
|||||||
onMysqlPasswordChanged(QString());
|
onMysqlPasswordChanged(QString());
|
||||||
|
|
||||||
m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Information,
|
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.
|
// Load SQLite.
|
||||||
m_ui->m_cmbDatabaseDriver->addItem(
|
m_ui->m_cmbDatabaseDriver->addItem(
|
||||||
@ -517,16 +518,19 @@ void FormSettings::mysqlTestConnection() {
|
|||||||
m_ui->m_spinMysqlPort->value(),
|
m_ui->m_spinMysqlPort->value(),
|
||||||
m_ui->m_txtMysqlUsername->lineEdit()->text(),
|
m_ui->m_txtMysqlUsername->lineEdit()->text(),
|
||||||
m_ui->m_txtMysqlPassword->lineEdit()->text());
|
m_ui->m_txtMysqlPassword->lineEdit()->text());
|
||||||
|
QString interpretation = DatabaseFactory::instance()->mysqlInterpretErrorCode(error_code);
|
||||||
|
|
||||||
switch (error_code) {
|
switch (error_code) {
|
||||||
case DatabaseFactory::MySQLOk:
|
case DatabaseFactory::MySQLOk:
|
||||||
m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Ok,
|
m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Ok,
|
||||||
DatabaseFactory::instance()->mysqlInterpretErrorCode(error_code));
|
interpretation,
|
||||||
|
interpretation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Error,
|
m_ui->m_lblMysqlTestResult->setStatus(WidgetWithStatus::Error,
|
||||||
DatabaseFactory::instance()->mysqlInterpretErrorCode(error_code));
|
interpretation,
|
||||||
|
interpretation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,11 +257,13 @@ void FormStandardFeedDetails::guessFeed() {
|
|||||||
Qt::MatchFixedString));
|
Qt::MatchFixedString));
|
||||||
|
|
||||||
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Ok,
|
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Ok,
|
||||||
|
tr("Feed metada fetched."),
|
||||||
tr("Feed metadata fetched successfully."));
|
tr("Feed metadata fetched successfully."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// No feed guessed, even no icon available.
|
// No feed guessed, even no icon available.
|
||||||
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Error,
|
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Error,
|
||||||
|
tr("Error occurred."),
|
||||||
tr("Error occurred."));
|
tr("Error occurred."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -377,6 +379,7 @@ void FormStandardFeedDetails::initialize() {
|
|||||||
|
|
||||||
// Set feed metadata fetch label.
|
// Set feed metadata fetch label.
|
||||||
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Information,
|
m_ui->m_lblFetchMetadata->setStatus(WidgetWithStatus::Information,
|
||||||
|
tr("No metadata fetched so far."),
|
||||||
tr("No metadata fetched so far."));
|
tr("No metadata fetched so far."));
|
||||||
|
|
||||||
// Setup auto-update options.
|
// Setup auto-update options.
|
||||||
|
@ -24,11 +24,7 @@ FormUpdate::FormUpdate(QWidget *parent)
|
|||||||
MessageBox::iconify(m_ui->m_buttonBox);
|
MessageBox::iconify(m_ui->m_buttonBox);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
connect(m_ui->m_cmbAvailableRelease->comboBox(), SIGNAL(currentIndexChanged(int)),
|
|
||||||
this, SLOT(updateChanges(int)));
|
|
||||||
|
|
||||||
m_ui->m_lblCurrentRelease->setText(APP_VERSION);
|
m_ui->m_lblCurrentRelease->setText(APP_VERSION);
|
||||||
|
|
||||||
checkForUpdates();
|
checkForUpdates();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,52 +39,37 @@ FormUpdate::~FormUpdate() {
|
|||||||
// asi. jednotlivy URL souborů pro danej release
|
// asi. jednotlivy URL souborů pro danej release
|
||||||
// sou dostupny v qhashi podle klice podle OS.
|
// sou dostupny v qhashi podle klice podle OS.
|
||||||
|
|
||||||
void FormUpdate::updateChanges(int new_release_index) {
|
void FormUpdate::checkForUpdates() {
|
||||||
if (new_release_index >= 0) {
|
QPair<UpdateInfo, QNetworkReply::NetworkError> update = SystemFactory::instance()->checkForUpdates();
|
||||||
UpdateInfo info = m_ui->m_cmbAvailableRelease->comboBox()->itemData(new_release_index).value<UpdateInfo>();
|
|
||||||
|
|
||||||
m_ui->m_txtChanges->setText(info.m_changes);
|
if (update.second != QNetworkReply::NoError) {
|
||||||
|
m_ui->m_lblAvailableRelease->setText(tr("unknown"));
|
||||||
if (info.m_availableVersion > APP_VERSION) {
|
m_ui->m_txtChanges->clear();
|
||||||
m_ui->m_cmbAvailableRelease->setStatus(WidgetWithStatus::Ok,
|
m_ui->m_lblStatus->setStatus(WidgetWithStatus::Error,
|
||||||
tr("This is new version which can be\ndownloaded and installed."));
|
tr("Connection error occurred."),
|
||||||
|
tr("List with updates was "
|
||||||
|
"not\ndownloaded successfully."));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m_ui->m_cmbAvailableRelease->setStatus(WidgetWithStatus::Warning,
|
m_ui->m_lblAvailableRelease->setText(update.first.m_availableVersion);
|
||||||
|
m_ui->m_txtChanges->setText(update.first.m_changes);
|
||||||
|
|
||||||
|
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_lblStatus->setStatus(WidgetWithStatus::Warning,
|
||||||
|
tr("No new releases available."),
|
||||||
tr("This release is not newer than\ncurrently installed one.."));
|
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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ class FormUpdate : public QDialog {
|
|||||||
virtual ~FormUpdate();
|
virtual ~FormUpdate();
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void updateChanges(int new_release_index);
|
|
||||||
void checkForUpdates();
|
void checkForUpdates();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>405</width>
|
||||||
<height>226</height>
|
<height>259</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@ -36,13 +36,10 @@
|
|||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="label_3">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Available releaseS</string>
|
<string>Available release</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="ComboBoxWithStatus" name="m_cmbAvailableRelease" native="true"/>
|
|
||||||
</item>
|
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -52,6 +49,15 @@
|
|||||||
</item>
|
</item>
|
||||||
<item row="3" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QTextEdit" name="m_txtChanges">
|
<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">
|
<property name="readOnly">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
@ -67,17 +73,24 @@ p, li { white-space: pre-wrap; }
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLabel" name="m_lblAvailableRelease">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="label_2">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Supported platforms</string>
|
<string>Status</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="1">
|
<item row="2" column="1">
|
||||||
<widget class="QLabel" name="m_lblPlatforms">
|
<widget class="LabelWithStatus" name="m_lblStatus" native="true">
|
||||||
<property name="text">
|
<property name="layoutDirection">
|
||||||
<string/>
|
<enum>Qt::RightToLeft</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -97,9 +110,9 @@ p, li { white-space: pre-wrap; }
|
|||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>ComboBoxWithStatus</class>
|
<class>LabelWithStatus</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header>comboboxwithstatus.h</header>
|
<header>labelwithstatus.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
@ -10,8 +10,8 @@ LabelWithStatus::LabelWithStatus(QWidget *parent)
|
|||||||
m_wdgInput = new QLabel(this);
|
m_wdgInput = new QLabel(this);
|
||||||
|
|
||||||
// Set correct size for the tool button.
|
// Set correct size for the tool button.
|
||||||
int txt_input_height = m_wdgInput->sizeHint().height();
|
int label_height = m_wdgInput->sizeHint().height();
|
||||||
m_btnStatus->setFixedSize(txt_input_height + 4, txt_input_height + 4);
|
m_btnStatus->setFixedSize(label_height, label_height);
|
||||||
|
|
||||||
// Compose the layout.
|
// Compose the layout.
|
||||||
m_layout->addWidget(m_wdgInput);
|
m_layout->addWidget(m_wdgInput);
|
||||||
@ -22,7 +22,8 @@ LabelWithStatus::~LabelWithStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LabelWithStatus::setStatus(WidgetWithStatus::StatusType status,
|
void LabelWithStatus::setStatus(WidgetWithStatus::StatusType status,
|
||||||
const QString &label_text) {
|
const QString &label_text,
|
||||||
WidgetWithStatus::setStatus(status, label_text);
|
const QString &status_text) {
|
||||||
|
WidgetWithStatus::setStatus(status, status_text);
|
||||||
label()->setText(label_text);
|
label()->setText(label_text);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ class LabelWithStatus : public WidgetWithStatus {
|
|||||||
explicit LabelWithStatus(QWidget *parent = 0);
|
explicit LabelWithStatus(QWidget *parent = 0);
|
||||||
virtual ~LabelWithStatus();
|
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.
|
// Access to label.
|
||||||
inline QLabel *label() const {
|
inline QLabel *label() const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user