Code format changes
This commit is contained in:
parent
0104c18332
commit
df6feef57f
@ -11,14 +11,16 @@ QT += widgets
|
|||||||
QT += network
|
QT += network
|
||||||
|
|
||||||
HEADERS += $$PWD/src/qsimpleupdater.h \
|
HEADERS += $$PWD/src/qsimpleupdater.h \
|
||||||
$$PWD/src/dialogs/download_dialog.h
|
$$PWD/src/dialogs/download_dialog.h
|
||||||
|
|
||||||
SOURCES += $$PWD/src/qsimpleupdater.cpp \
|
SOURCES += $$PWD/src/qsimpleupdater.cpp \
|
||||||
$$PWD/src/dialogs/download_dialog.cpp
|
$$PWD/src/dialogs/download_dialog.cpp
|
||||||
|
|
||||||
OTHER_FILES += $$PWD/src/QSimpleUpdater
|
OTHER_FILES += $$PWD/src/QSimpleUpdater
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/src
|
INCLUDEPATH += $$PWD/src
|
||||||
|
|
||||||
macx || linux:!android {
|
unix:!android {
|
||||||
LIBS += -lcrypto -lssl
|
LIBS += -lcrypto -lssl
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,5 +30,4 @@ win32* {
|
|||||||
|
|
||||||
RESOURCES += $$PWD/res/qsu_resources.qrc
|
RESOURCES += $$PWD/res/qsu_resources.qrc
|
||||||
|
|
||||||
FORMS += \
|
FORMS += $$PWD/src/dialogs/download_dialog.ui
|
||||||
$$PWD/src/dialogs/download_dialog.ui
|
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
#include "download_dialog.h"
|
#include "download_dialog.h"
|
||||||
#include "ui_download_dialog.h"
|
#include "ui_download_dialog.h"
|
||||||
|
|
||||||
DownloadDialog::DownloadDialog (QWidget *parent) :
|
DownloadDialog::DownloadDialog (QWidget *parent)
|
||||||
QWidget (parent),
|
: QWidget (parent)
|
||||||
ui (new Ui::DownloadDialog) {
|
, ui (new Ui::DownloadDialog) {
|
||||||
// Setup the UI
|
// Setup the UI
|
||||||
ui->setupUi (this);
|
ui->setupUi (this);
|
||||||
|
|
||||||
@ -22,15 +22,15 @@ DownloadDialog::DownloadDialog (QWidget *parent) :
|
|||||||
m_manager = new QNetworkAccessManager (this);
|
m_manager = new QNetworkAccessManager (this);
|
||||||
|
|
||||||
// Avoid SSL issues
|
// Avoid SSL issues
|
||||||
connect (m_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)),
|
connect (m_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)), this,
|
||||||
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadDialog::~DownloadDialog() {
|
DownloadDialog::~DownloadDialog() {
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadDialog::beginDownload (const QUrl &url) {
|
void DownloadDialog::beginDownload (const QUrl& url) {
|
||||||
Q_ASSERT (!url.isEmpty());
|
Q_ASSERT (!url.isEmpty());
|
||||||
|
|
||||||
// Reset the UI
|
// Reset the UI
|
||||||
@ -44,8 +44,8 @@ void DownloadDialog::beginDownload (const QUrl &url) {
|
|||||||
m_start_time = QDateTime::currentDateTime().toTime_t();
|
m_start_time = QDateTime::currentDateTime().toTime_t();
|
||||||
|
|
||||||
// Update the progress bar value automatically
|
// Update the progress bar value automatically
|
||||||
connect (m_reply, SIGNAL (downloadProgress (qint64, qint64)),
|
connect (m_reply, SIGNAL (downloadProgress (qint64, qint64)), this,
|
||||||
this, SLOT (updateProgress (qint64, qint64)));
|
SLOT (updateProgress (qint64, qint64)));
|
||||||
|
|
||||||
// Write the file to the hard disk once the download is finished
|
// Write the file to the hard disk once the download is finished
|
||||||
connect (m_reply, SIGNAL (finished()), this, SLOT (downloadFinished()));
|
connect (m_reply, SIGNAL (finished()), this, SLOT (downloadFinished()));
|
||||||
@ -157,9 +157,7 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total) {
|
|||||||
_received_string = tr ("%1 MB").arg (_received);
|
_received_string = tr ("%1 MB").arg (_received);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui->downloadLabel->setText (tr ("Downloading updates") + " (" +
|
ui->downloadLabel->setText (tr ("Downloading updates") + " (" + _received_string + " " + tr ("of") + " " + _total_string + ")");
|
||||||
_received_string + " " + tr ("of") + " " +
|
|
||||||
_total_string + ")");
|
|
||||||
|
|
||||||
uint _diff = QDateTime::currentDateTime().toTime_t() - m_start_time;
|
uint _diff = QDateTime::currentDateTime().toTime_t() - m_start_time;
|
||||||
|
|
||||||
@ -184,7 +182,8 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We do not know the size of the download, so we improvise...
|
// We do not know the size of the download, so we avoid scaring the shit out
|
||||||
|
// of the user
|
||||||
else {
|
else {
|
||||||
ui->progressBar->setValue (-1);
|
ui->progressBar->setValue (-1);
|
||||||
ui->progressBar->setMinimum (0);
|
ui->progressBar->setMinimum (0);
|
||||||
@ -194,7 +193,8 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadDialog::ignoreSslErrors (QNetworkReply *reply, const QList<QSslError> &error) {
|
void DownloadDialog::ignoreSslErrors (QNetworkReply *reply,
|
||||||
|
const QList<QSslError>& error) {
|
||||||
#ifndef Q_OS_IOS
|
#ifndef Q_OS_IOS
|
||||||
reply->ignoreSslErrors (error);
|
reply->ignoreSslErrors (error);
|
||||||
#else
|
#else
|
||||||
@ -203,6 +203,6 @@ void DownloadDialog::ignoreSslErrors (QNetworkReply *reply, const QList<QSslErro
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
float DownloadDialog::roundNumber (const float &input) {
|
float DownloadDialog::roundNumber (const float& input) {
|
||||||
return roundf (input * 100) / 100;
|
return roundf (input * 100) / 100;
|
||||||
}
|
}
|
||||||
|
@ -18,33 +18,33 @@ 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();
|
~DownloadDialog();
|
||||||
|
|
||||||
void beginDownload (const QUrl &url);
|
void beginDownload (const QUrl& url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void openDownload();
|
void openDownload();
|
||||||
void cancelDownload();
|
void cancelDownload();
|
||||||
void downloadFinished();
|
void downloadFinished();
|
||||||
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;
|
||||||
bool m_download_paused;
|
bool m_download_paused;
|
||||||
|
|
||||||
QNetworkReply *m_reply;
|
QNetworkReply *m_reply;
|
||||||
QNetworkAccessManager *m_manager;
|
QNetworkAccessManager *m_manager;
|
||||||
|
|
||||||
uint m_start_time;
|
uint m_start_time;
|
||||||
|
|
||||||
float roundNumber (const float &input);
|
float roundNumber (const float& input);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,8 +29,8 @@ void QSimpleUpdater::checkForUpdates() {
|
|||||||
if (!m_reference_url.isEmpty()) {
|
if (!m_reference_url.isEmpty()) {
|
||||||
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
||||||
|
|
||||||
connect (_manager, SIGNAL (finished (QNetworkReply *)),
|
connect (_manager, SIGNAL (finished (QNetworkReply *)), this,
|
||||||
this, SLOT (checkDownloadedVersion (QNetworkReply *)));
|
SLOT (checkDownloadedVersion (QNetworkReply *)));
|
||||||
|
|
||||||
connect (_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)),
|
connect (_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)),
|
||||||
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
||||||
@ -84,7 +84,7 @@ bool QSimpleUpdater::newerVersionAvailable() const {
|
|||||||
return m_new_version_available;
|
return m_new_version_available;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSimpleUpdater::setDownloadUrl (const QString &url) {
|
void QSimpleUpdater::setDownloadUrl (const QString& url) {
|
||||||
Q_ASSERT (!url.isEmpty());
|
Q_ASSERT (!url.isEmpty());
|
||||||
|
|
||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
@ -94,7 +94,7 @@ void QSimpleUpdater::setDownloadUrl (const QString &url) {
|
|||||||
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSimpleUpdater::setReferenceUrl (const QString &url) {
|
void QSimpleUpdater::setReferenceUrl (const QString& url) {
|
||||||
Q_ASSERT (!url.isEmpty());
|
Q_ASSERT (!url.isEmpty());
|
||||||
|
|
||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
@ -104,7 +104,7 @@ void QSimpleUpdater::setReferenceUrl (const QString &url) {
|
|||||||
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSimpleUpdater::setChangelogUrl (const QString &url) {
|
void QSimpleUpdater::setChangelogUrl (const QString& url) {
|
||||||
Q_ASSERT (!url.isEmpty());
|
Q_ASSERT (!url.isEmpty());
|
||||||
|
|
||||||
if (!url.isEmpty())
|
if (!url.isEmpty())
|
||||||
@ -114,7 +114,7 @@ void QSimpleUpdater::setChangelogUrl (const QString &url) {
|
|||||||
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
qDebug() << "QSimpleUpdater: input URL cannot be empty!";
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSimpleUpdater::setApplicationVersion (const QString &version) {
|
void QSimpleUpdater::setApplicationVersion (const QString& version) {
|
||||||
Q_ASSERT (!version.isEmpty());
|
Q_ASSERT (!version.isEmpty());
|
||||||
|
|
||||||
if (!version.isEmpty())
|
if (!version.isEmpty())
|
||||||
@ -165,8 +165,8 @@ void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply) {
|
|||||||
if (!m_changelog_url.isEmpty() && newerVersionAvailable()) {
|
if (!m_changelog_url.isEmpty() && newerVersionAvailable()) {
|
||||||
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
||||||
|
|
||||||
connect (_manager, SIGNAL (finished (QNetworkReply *)),
|
connect (_manager, SIGNAL (finished (QNetworkReply *)), this,
|
||||||
this, SLOT (processDownloadedChangelog (QNetworkReply *)));
|
SLOT (processDownloadedChangelog (QNetworkReply *)));
|
||||||
|
|
||||||
connect (_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)),
|
connect (_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)),
|
||||||
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
|
||||||
@ -192,7 +192,8 @@ void QSimpleUpdater::processDownloadedChangelog (QNetworkReply *reply) {
|
|||||||
emit checkingFinished();
|
emit checkingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QSimpleUpdater::ignoreSslErrors (QNetworkReply *reply, const QList<QSslError> &error) {
|
void QSimpleUpdater::ignoreSslErrors (QNetworkReply *reply,
|
||||||
|
const QList<QSslError>& error) {
|
||||||
#ifndef Q_OS_IOS
|
#ifndef Q_OS_IOS
|
||||||
reply->ignoreSslErrors (error);
|
reply->ignoreSslErrors (error);
|
||||||
#else
|
#else
|
||||||
|
@ -17,87 +17,87 @@
|
|||||||
#include "dialogs/download_dialog.h"
|
#include "dialogs/download_dialog.h"
|
||||||
|
|
||||||
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
|
||||||
QString changeLog() const;
|
QString changeLog() const;
|
||||||
|
|
||||||
/// Returns the downloaded version string
|
/// Returns the downloaded version string
|
||||||
QString latestVersion() const;
|
QString latestVersion() const;
|
||||||
|
|
||||||
/// Returns the local version, referenced by
|
/// Returns the local version, referenced by
|
||||||
/// the setApplicationVersion() function
|
/// the setApplicationVersion() function
|
||||||
QString installedVersion() const;
|
QString installedVersion() const;
|
||||||
|
|
||||||
/// Returns \c true if there's a newer version available
|
/// Returns \c true if there's a newer version available
|
||||||
bool newerVersionAvailable() const;
|
bool newerVersionAvailable() const;
|
||||||
|
|
||||||
/// Checks for updates and calls the appropriate
|
/// Checks for updates and calls the appropriate
|
||||||
/// signals when finished
|
/// signals when finished
|
||||||
void checkForUpdates();
|
void checkForUpdates();
|
||||||
|
|
||||||
/// 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 openDownloadLink();
|
||||||
|
|
||||||
/// 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 downloadLatestVersion();
|
||||||
|
|
||||||
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
|
||||||
/// want to automatically download and install your updates
|
/// want to automatically download and install your updates
|
||||||
void setDownloadUrl (const QString &url);
|
void setDownloadUrl (const QString& url);
|
||||||
|
|
||||||
/// Changes the reference URL, which contains ONLY the latest
|
/// Changes the reference URL, which contains ONLY the latest
|
||||||
/// version of your application as a plain text file.
|
/// version of your application as a plain text file.
|
||||||
/// Examples include:
|
/// Examples include:
|
||||||
/// - 1.2.3
|
/// - 1.2.3
|
||||||
/// - 5.4.0
|
/// - 5.4.0
|
||||||
/// - 0.1.2
|
/// - 0.1.2
|
||||||
/// - etc.
|
/// - etc.
|
||||||
void setReferenceUrl (const QString &url);
|
void setReferenceUrl (const QString& url);
|
||||||
|
|
||||||
/// Changes the change log URL, which contains the change log
|
/// Changes the change log URL, which contains the change log
|
||||||
/// of your application. The change log can be any file you
|
/// of your application. The change log can be any file you
|
||||||
/// like, however, its recommended to write it in plain text,
|
/// like, however, its recommended to write it in plain text,
|
||||||
/// such as TXT, HTML and RTF files.
|
/// such as TXT, HTML and RTF files.
|
||||||
void setChangelogUrl (const QString &url);
|
void setChangelogUrl (const QString& url);
|
||||||
|
|
||||||
/// Tells the updater the version of the installed
|
/// Tells the updater the version of the installed
|
||||||
/// 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 checkingFinished();
|
||||||
void versionCheckFinished();
|
void versionCheckFinished();
|
||||||
void changelogDownloadFinished();
|
void changelogDownloadFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_changelog;
|
QString m_changelog;
|
||||||
QString m_latest_version;
|
QString m_latest_version;
|
||||||
QString m_installed_version;
|
QString m_installed_version;
|
||||||
|
|
||||||
QUrl m_download_url;
|
QUrl m_download_url;
|
||||||
QUrl m_reference_url;
|
QUrl m_reference_url;
|
||||||
QUrl m_changelog_url;
|
QUrl m_changelog_url;
|
||||||
|
|
||||||
bool m_changelog_downloaded;
|
bool m_changelog_downloaded;
|
||||||
bool m_version_check_finished;
|
bool m_version_check_finished;
|
||||||
|
|
||||||
bool m_new_version_available;
|
bool m_new_version_available;
|
||||||
|
|
||||||
DownloadDialog *m_downloadDialog;
|
DownloadDialog *m_downloadDialog;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user