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