Improved code performance
Fixed a "bug" in the checkForUpdates() function which caused the program to delay about 400 milliseconds.
This commit is contained in:
parent
7b0444263e
commit
56c132a21e
@ -27,8 +27,8 @@ DownloadDialog::DownloadDialog (QWidget *parent)
|
|||||||
connect (ui->openButton, SIGNAL (clicked()), this, SLOT (installUpdate()));
|
connect (ui->openButton, SIGNAL (clicked()), this, SLOT (installUpdate()));
|
||||||
|
|
||||||
// Configure open button
|
// Configure open button
|
||||||
ui->openButton->setEnabled(false);
|
ui->openButton->setEnabled (false);
|
||||||
ui->openButton->setVisible(false);
|
ui->openButton->setVisible (false);
|
||||||
|
|
||||||
// Initialize the network access manager
|
// Initialize the network access manager
|
||||||
m_manager = new QNetworkAccessManager (this);
|
m_manager = new QNetworkAccessManager (this);
|
||||||
@ -38,7 +38,7 @@ DownloadDialog::DownloadDialog (QWidget *parent)
|
|||||||
SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadDialog::~DownloadDialog(void) {
|
DownloadDialog::~DownloadDialog (void) {
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,15 +66,15 @@ void DownloadDialog::beginDownload (const QUrl& url) {
|
|||||||
showNormal();
|
showNormal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadDialog::installUpdate(void) {
|
void DownloadDialog::installUpdate (void) {
|
||||||
QMessageBox msg;
|
QMessageBox msg;
|
||||||
msg.setIcon(QMessageBox::Question);
|
msg.setIcon (QMessageBox::Question);
|
||||||
msg.setText("<b>" +
|
msg.setText ("<b>" +
|
||||||
tr("To apply the update(s), you must first quit %1")
|
tr ("To apply the update(s), you must first quit %1")
|
||||||
.arg(qApp->applicationName()) +
|
.arg (qApp->applicationName()) +
|
||||||
"</b>");
|
"</b>");
|
||||||
msg.setInformativeText(tr("Do you want to quit %1 now?").arg(qApp->applicationName()));
|
msg.setInformativeText (tr ("Do you want to quit %1 now?").arg (qApp->applicationName()));
|
||||||
msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
msg.setStandardButtons (QMessageBox::Yes | QMessageBox::No);
|
||||||
|
|
||||||
if (msg.exec() == QMessageBox::Yes) {
|
if (msg.exec() == QMessageBox::Yes) {
|
||||||
openDownload();
|
openDownload();
|
||||||
@ -82,13 +82,13 @@ void DownloadDialog::installUpdate(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
ui->openButton->setEnabled(true);
|
ui->openButton->setEnabled (true);
|
||||||
ui->openButton->setVisible(true);
|
ui->openButton->setVisible (true);
|
||||||
ui->timeLabel->setText (tr ("Click the \"Open\" button to apply the update"));
|
ui->timeLabel->setText (tr ("Click the \"Open\" button to apply the update"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadDialog::openDownload(void) {
|
void DownloadDialog::openDownload (void) {
|
||||||
if (!m_path.isEmpty()) {
|
if (!m_path.isEmpty()) {
|
||||||
QString url = m_path;
|
QString url = m_path;
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ void DownloadDialog::openDownload(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadDialog::cancelDownload(void) {
|
void DownloadDialog::cancelDownload (void) {
|
||||||
if (!m_reply->isFinished()) {
|
if (!m_reply->isFinished()) {
|
||||||
QMessageBox _message;
|
QMessageBox _message;
|
||||||
_message.setWindowTitle (tr ("Updater"));
|
_message.setWindowTitle (tr ("Updater"));
|
||||||
@ -120,7 +120,7 @@ void DownloadDialog::cancelDownload(void) {
|
|||||||
hide();
|
hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadDialog::downloadFinished(void) {
|
void DownloadDialog::downloadFinished (void) {
|
||||||
ui->stopButton->setText (tr ("Close"));
|
ui->stopButton->setText (tr ("Close"));
|
||||||
ui->downloadLabel->setText (tr ("Download complete!"));
|
ui->downloadLabel->setText (tr ("Download complete!"));
|
||||||
ui->timeLabel->setText (tr ("The installer will open in a separate window..."));
|
ui->timeLabel->setText (tr ("The installer will open in a separate window..."));
|
||||||
|
@ -33,21 +33,21 @@ class DownloadDialog;
|
|||||||
class DownloadDialog : public QWidget {
|
class DownloadDialog : public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit DownloadDialog (QWidget *parent = 0);
|
explicit DownloadDialog (QWidget *parent = 0);
|
||||||
~DownloadDialog(void);
|
~DownloadDialog (void);
|
||||||
|
|
||||||
void beginDownload (const QUrl& url);
|
void beginDownload (const QUrl& url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void openDownload(void);
|
void openDownload (void);
|
||||||
void installUpdate(void);
|
void installUpdate (void);
|
||||||
void cancelDownload(void);
|
void cancelDownload (void);
|
||||||
void downloadFinished(void);
|
void downloadFinished (void);
|
||||||
void updateProgress (qint64 received, qint64 total);
|
void updateProgress (qint64 received, qint64 total);
|
||||||
void ignoreSslErrors (QNetworkReply *reply, const QList<QSslError>& error);
|
void ignoreSslErrors (QNetworkReply *reply, const QList<QSslError>& error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::DownloadDialog *ui;
|
Ui::DownloadDialog *ui;
|
||||||
|
|
||||||
QString m_path;
|
QString m_path;
|
||||||
|
@ -20,30 +20,27 @@ QSimpleUpdater::QSimpleUpdater (QObject *parent)
|
|||||||
, m_version_check_finished (false)
|
, m_version_check_finished (false)
|
||||||
, m_new_version_available (false) {
|
, m_new_version_available (false) {
|
||||||
m_downloadDialog = new DownloadDialog();
|
m_downloadDialog = new DownloadDialog();
|
||||||
|
|
||||||
|
m_manager = new QNetworkAccessManager (this);
|
||||||
|
connect (m_manager, SIGNAL (finished (QNetworkReply *)), this,
|
||||||
|
SLOT (checkDownloadedVersion (QNetworkReply *)));
|
||||||
|
connect (m_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)),
|
||||||
|
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QSimpleUpdater::changeLog() const {
|
QString QSimpleUpdater::changeLog() const {
|
||||||
return m_changelog;
|
return m_changelog;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSimpleUpdater::checkForUpdates(void) {
|
void QSimpleUpdater::checkForUpdates (void) {
|
||||||
if (!m_reference_url.isEmpty()) {
|
if (!m_reference_url.isEmpty())
|
||||||
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
m_manager->get (QNetworkRequest (m_reference_url));
|
||||||
|
|
||||||
connect (_manager, SIGNAL (finished (QNetworkReply *)), this,
|
|
||||||
SLOT (checkDownloadedVersion (QNetworkReply *)));
|
|
||||||
|
|
||||||
connect (_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)),
|
|
||||||
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
|
||||||
|
|
||||||
_manager->get (QNetworkRequest (m_reference_url));
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
else
|
||||||
qDebug() << "QSimpleUpdater: Invalid reference URL";
|
qDebug() << "QSimpleUpdater: Invalid reference URL";
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSimpleUpdater::openDownloadLink(void) {
|
void QSimpleUpdater::openDownloadLink (void) {
|
||||||
if (!m_download_url.isEmpty())
|
if (!m_download_url.isEmpty())
|
||||||
QDesktopServices::openUrl (m_download_url);
|
QDesktopServices::openUrl (m_download_url);
|
||||||
}
|
}
|
||||||
@ -56,7 +53,7 @@ QString QSimpleUpdater::installedVersion() const {
|
|||||||
return m_installed_version;
|
return m_installed_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSimpleUpdater::downloadLatestVersion(void) {
|
void QSimpleUpdater::downloadLatestVersion (void) {
|
||||||
if (!m_download_url.isEmpty())
|
if (!m_download_url.isEmpty())
|
||||||
m_downloadDialog->beginDownload (m_download_url);
|
m_downloadDialog->beginDownload (m_download_url);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
class QSimpleUpdater : public QObject {
|
class QSimpleUpdater : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
QSimpleUpdater (QObject *parent = 0);
|
QSimpleUpdater (QObject *parent = 0);
|
||||||
|
|
||||||
/// Returns the downloaded change log
|
/// Returns the downloaded change log
|
||||||
@ -53,17 +53,17 @@ public:
|
|||||||
|
|
||||||
/// Checks for updates and calls the appropriate
|
/// Checks for updates and calls the appropriate
|
||||||
/// signals when finished
|
/// signals when finished
|
||||||
void checkForUpdates(void);
|
void checkForUpdates (void);
|
||||||
|
|
||||||
/// Opens the download URL in a a web browser.
|
/// Opens the download URL in a a web browser.
|
||||||
/// The URL is referenced by the \c setDownloadUrl() function
|
/// The URL is referenced by the \c setDownloadUrl() function
|
||||||
void openDownloadLink(void);
|
void openDownloadLink (void);
|
||||||
|
|
||||||
/// Shows a dialog that downloads the file in the
|
/// Shows a dialog that downloads the file in the
|
||||||
/// URL referenced by the \c setDownloadUrl() function
|
/// URL referenced by the \c setDownloadUrl() function
|
||||||
void downloadLatestVersion(void);
|
void downloadLatestVersion (void);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
/// Changes the URL that we can open in a web browser or
|
/// Changes the URL that we can open in a web browser or
|
||||||
/// download. Its recommended to use fixed URLs if you
|
/// download. Its recommended to use fixed URLs if you
|
||||||
@ -89,20 +89,21 @@ public slots:
|
|||||||
/// copy of your application.
|
/// copy of your application.
|
||||||
void setApplicationVersion (const QString& version);
|
void setApplicationVersion (const QString& version);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void checkDownloadedVersion (QNetworkReply *reply);
|
void checkDownloadedVersion (QNetworkReply *reply);
|
||||||
void processDownloadedChangelog (QNetworkReply *reply);
|
void processDownloadedChangelog (QNetworkReply *reply);
|
||||||
void ignoreSslErrors (QNetworkReply *reply, const QList<QSslError>& error);
|
void ignoreSslErrors (QNetworkReply *reply, const QList<QSslError>& error);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void checkingFinished(void);
|
void checkingFinished (void);
|
||||||
void versionCheckFinished(void);
|
void versionCheckFinished (void);
|
||||||
void changelogDownloadFinished(void);
|
void changelogDownloadFinished (void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_changelog;
|
QString m_changelog;
|
||||||
QString m_latest_version;
|
QString m_latest_version;
|
||||||
QString m_installed_version;
|
QString m_installed_version;
|
||||||
|
QNetworkAccessManager *m_manager;
|
||||||
|
|
||||||
QUrl m_download_url;
|
QUrl m_download_url;
|
||||||
QUrl m_reference_url;
|
QUrl m_reference_url;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user