diff --git a/etc/resources/qsimpleupdater.qrc b/etc/resources/qsimpleupdater.qrc old mode 100755 new mode 100644 diff --git a/etc/scripts/format-code.bat b/etc/scripts/format-code.bat index 8f4f36b..941bfda 100644 --- a/etc/scripts/format-code.bat +++ b/etc/scripts/format-code.bat @@ -9,7 +9,7 @@ title Code Formatter cd /d %~dp0 :: Style and format the source code recursively -astyle --pad-oper --pad-first-paren-out --align-pointer=type --remove-brackets --convert-tabs --max-code-length=80 --style=google --lineend=windows --suffix=none --recursive ../../*.h ../../*.cpp ../../*.c +astyle --style=linux --indent=spaces --align-pointer=type --indent-preproc-block --indent-preproc-define --indent-col1-comments --pad-first-paren-out --pad-oper --attach-namespaces --remove-brackets --convert-tabs --close-templates --max-code-length=100 --max-instatement-indent=50 --lineend=windows --suffix=none --recursive ../../*.h ../../*.cpp ../../*.c :: Notify the user that we have finished echo. diff --git a/etc/scripts/format-code.sh b/etc/scripts/format-code.sh index 9bfc1b2..694973e 100644 --- a/etc/scripts/format-code.sh +++ b/etc/scripts/format-code.sh @@ -1,2 +1,2 @@ # Style and format recursively -astyle --pad-oper --pad-first-paren-out --align-pointer=type --remove-brackets --convert-tabs --max-code-length=80 --style=google --lineend=windows --suffix=none --recursive ../../*.h ../../*.cpp ../../*.c +astyle --style=linux --indent=spaces --align-pointer=type --indent-preproc-block --indent-preproc-define --indent-col1-comments --pad-first-paren-out --pad-oper --attach-namespaces --remove-brackets --convert-tabs --close-templates --max-code-length=100 --max-instatement-indent=50 --lineend=windows --suffix=none --recursive ../../*.h ../../*.c ../../*.cpp ../../*.cc diff --git a/include/QSimpleUpdater.h b/include/QSimpleUpdater.h index 22f7eaa..6b71260 100644 --- a/include/QSimpleUpdater.h +++ b/include/QSimpleUpdater.h @@ -35,11 +35,11 @@ #include #if defined (QSU_SHARED) -#define QSU_DECL Q_DECL_EXPORT + #define QSU_DECL Q_DECL_EXPORT #elif defined (QSU_IMPORT) -#define QSU_DECL Q_DECL_IMPORT + #define QSU_DECL Q_DECL_IMPORT #else -#define QSU_DECL + #define QSU_DECL #endif class Updater; @@ -63,15 +63,16 @@ class Updater; * By default, the downloader will try to open the file as if you opened it * from a file manager or a web browser (with the "file:*" url). */ -class QSU_DECL QSimpleUpdater : public QObject { +class QSU_DECL QSimpleUpdater : public QObject +{ Q_OBJECT - signals: +signals: void checkingFinished (const QString& url); void appcastDownloaded (const QString& url, const QByteArray& data); void downloadFinished (const QString& url, const QString& filepath); - public: +public: static QSimpleUpdater* getInstance(); bool usesCustomAppcast (const QString& url) const; @@ -89,7 +90,7 @@ class QSU_DECL QSimpleUpdater : public QObject { QString getLatestVersion (const QString& url) const; QString getModuleVersion (const QString& url) const; - public slots: +public slots: void checkForUpdates (const QString& url); void setModuleName (const QString& url, const QString& name); void setNotifyOnUpdate (const QString& url, const bool notify); @@ -100,10 +101,10 @@ class QSU_DECL QSimpleUpdater : public QObject { void setUseCustomAppcast (const QString& url, const bool customAppcast); void setUseCustomInstallProcedures (const QString& url, const bool custom); - protected: +protected: ~QSimpleUpdater(); - private: +private: Updater* getUpdater (const QString& url) const; }; diff --git a/src/Downloader.cpp b/src/Downloader.cpp old mode 100755 new mode 100644 index eb91de9..9633bf6 --- a/src/Downloader.cpp +++ b/src/Downloader.cpp @@ -42,7 +42,8 @@ static const QString PARTIAL_DOWN (".part"); static const QDir DOWNLOAD_DIR (QDir::homePath() + "/Downloads/"); -Downloader::Downloader (QWidget* parent) : QWidget (parent) { +Downloader::Downloader (QWidget* parent) : QWidget (parent) +{ m_ui = new Ui::Downloader; m_ui->setupUi (this); @@ -71,7 +72,8 @@ Downloader::Downloader (QWidget* parent) : QWidget (parent) { setFixedSize (minimumSizeHint()); } -Downloader::~Downloader() { +Downloader::~Downloader() +{ delete m_ui; delete m_reply; delete m_manager; @@ -82,7 +84,8 @@ Downloader::~Downloader() { * finished (you can use the \c QSimpleUpdater signals to know when the * download is completed). */ -bool Downloader::useCustomInstallProcedures() const { +bool Downloader::useCustomInstallProcedures() const +{ return m_useCustomProcedures; } @@ -93,14 +96,16 @@ bool Downloader::useCustomInstallProcedures() const { * \note the \a url parameter is not the download URL, it is the URL of * the AppCast file */ -void Downloader::setUrlId (const QString& url) { +void Downloader::setUrlId (const QString& url) +{ m_url = url; } /** * Begins downloading the file at the given \a url */ -void Downloader::startDownload (const QUrl& url) { +void Downloader::startDownload (const QUrl& url) +{ /* Reset UI */ m_ui->progressBar->setValue (0); m_ui->stopButton->setText (tr ("Stop")); @@ -131,7 +136,8 @@ void Downloader::startDownload (const QUrl& url) { /** * Changes the name of the downloaded file */ -void Downloader::setFileName (const QString& file) { +void Downloader::setFileName (const QString& file) +{ m_fileName = file; if (m_fileName.isEmpty()) @@ -143,10 +149,11 @@ void Downloader::setFileName (const QString& file) { * \note If the downloaded file is not found, then the function will alert the * user about the error. */ -void Downloader::openDownload() { +void Downloader::openDownload() +{ if (!m_fileName.isEmpty()) QDesktopServices::openUrl (QUrl::fromLocalFile (DOWNLOAD_DIR.filePath ( - m_fileName))); + m_fileName))); else { QMessageBox::critical (this, @@ -164,7 +171,8 @@ void Downloader::openDownload() { * signals fired by the \c QSimpleUpdater to install the update with your * own implementations/code. */ -void Downloader::installUpdate() { +void Downloader::installUpdate() +{ if (useCustomInstallProcedures()) return; @@ -204,7 +212,8 @@ void Downloader::installUpdate() { * Prompts the user if he/she wants to cancel the download and cancels the * download if the user agrees to do that. */ -void Downloader::cancelDownload() { +void Downloader::cancelDownload() +{ if (!m_reply->isFinished()) { QMessageBox box; box.setWindowTitle (tr ("Updater")); @@ -225,7 +234,8 @@ void Downloader::cancelDownload() { /** * Writes the downloaded data to the disk */ -void Downloader::saveFile (qint64 received, qint64 total) { +void Downloader::saveFile (qint64 received, qint64 total) +{ /* Check if we need to redirect */ QUrl url = m_reply->attribute ( QNetworkRequest::RedirectionTargetAttribute).toUrl(); @@ -262,7 +272,8 @@ void Downloader::saveFile (qint64 received, qint64 total) { * data and the total download size. Then, this function proceeds to update the * dialog controls/UI. */ -void Downloader::calculateSizes (qint64 received, qint64 total) { +void Downloader::calculateSizes (qint64 received, qint64 total) +{ QString totalSize; QString receivedSize; @@ -293,7 +304,8 @@ void Downloader::calculateSizes (qint64 received, qint64 total) { * Uses the \a received and \a total parameters to get the download progress * and update the progressbar value on the dialog. */ -void Downloader::updateProgress (qint64 received, qint64 total) { +void Downloader::updateProgress (qint64 received, qint64 total) +{ if (total > 0) { m_ui->progressBar->setMinimum (0); m_ui->progressBar->setMaximum (100); @@ -323,7 +335,8 @@ void Downloader::updateProgress (qint64 received, qint64 total) { * (hours, minutes or seconds) and constructs a user-friendly string, which * is displayed in the dialog. */ -void Downloader::calculateTimeRemaining (qint64 received, qint64 total) { +void Downloader::calculateTimeRemaining (qint64 received, qint64 total) +{ uint difference = QDateTime::currentDateTime().toTime_t() - m_startTime; if (difference > 0) { @@ -366,7 +379,8 @@ void Downloader::calculateTimeRemaining (qint64 received, qint64 total) { /** * Rounds the given \a input to two decimal places */ -qreal Downloader::round (const qreal& input) { +qreal Downloader::round (const qreal& input) +{ return roundf (input * 100) / 100; } @@ -377,6 +391,7 @@ qreal Downloader::round (const qreal& input) { * Use the signals fired by the \c QSimpleUpdater to implement your own install * procedures. */ -void Downloader::setUseCustomInstallProcedures (const bool custom) { +void Downloader::setUseCustomInstallProcedures (const bool custom) +{ m_useCustomProcedures = custom; } diff --git a/src/Downloader.h b/src/Downloader.h old mode 100755 new mode 100644 index 89e3d84..3a4b0b8 --- a/src/Downloader.h +++ b/src/Downloader.h @@ -43,25 +43,26 @@ class QNetworkAccessManager; /** * \brief Implements an integrated file downloader with a nice UI */ -class Downloader : public QWidget { +class Downloader : public QWidget +{ Q_OBJECT - signals: +signals: void downloadFinished (const QString& url, const QString& filepath); - public: +public: explicit Downloader (QWidget* parent = 0); ~Downloader(); bool useCustomInstallProcedures() const; - public slots: +public slots: void setUrlId (const QString& url); void startDownload (const QUrl& url); void setFileName (const QString& file); void setUseCustomInstallProcedures (const bool custom); - private slots: +private slots: void openDownload(); void installUpdate(); void cancelDownload(); @@ -70,10 +71,10 @@ class Downloader : public QWidget { void updateProgress (qint64 received, qint64 total); void calculateTimeRemaining (qint64 received, qint64 total); - private: +private: qreal round (const qreal& input); - private: +private: QString m_url; uint m_startTime; QString m_fileName; diff --git a/src/Downloader.ui b/src/Downloader.ui old mode 100755 new mode 100644 diff --git a/src/QSimpleUpdater.cpp b/src/QSimpleUpdater.cpp index 7b1ec95..89b6606 100644 --- a/src/QSimpleUpdater.cpp +++ b/src/QSimpleUpdater.cpp @@ -33,7 +33,8 @@ static QList URLS; static QList UPDATERS; -QSimpleUpdater::~QSimpleUpdater() { +QSimpleUpdater::~QSimpleUpdater() +{ URLS.clear(); foreach (Updater* updater, UPDATERS) @@ -45,7 +46,8 @@ QSimpleUpdater::~QSimpleUpdater() { /** * Returns the only instance of the class */ -QSimpleUpdater* QSimpleUpdater::getInstance() { +QSimpleUpdater* QSimpleUpdater::getInstance() +{ static QSimpleUpdater updater; return &updater; } @@ -58,7 +60,8 @@ QSimpleUpdater* QSimpleUpdater::getInstance() { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -bool QSimpleUpdater::usesCustomAppcast (const QString& url) const { +bool QSimpleUpdater::usesCustomAppcast (const QString& url) const +{ return getUpdater (url)->customAppcast(); } @@ -69,7 +72,8 @@ bool QSimpleUpdater::usesCustomAppcast (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -bool QSimpleUpdater::getNotifyOnUpdate (const QString& url) const { +bool QSimpleUpdater::getNotifyOnUpdate (const QString& url) const +{ return getUpdater (url)->notifyOnUpdate(); } @@ -80,7 +84,8 @@ bool QSimpleUpdater::getNotifyOnUpdate (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -bool QSimpleUpdater::getNotifyOnFinish (const QString& url) const { +bool QSimpleUpdater::getNotifyOnFinish (const QString& url) const +{ return getUpdater (url)->notifyOnFinish(); } @@ -92,7 +97,8 @@ bool QSimpleUpdater::getNotifyOnFinish (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -bool QSimpleUpdater::getUpdateAvailable (const QString& url) const { +bool QSimpleUpdater::getUpdateAvailable (const QString& url) const +{ return getUpdater (url)->updateAvailable(); } @@ -103,7 +109,8 @@ bool QSimpleUpdater::getUpdateAvailable (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -bool QSimpleUpdater::getDownloaderEnabled (const QString& url) const { +bool QSimpleUpdater::getDownloaderEnabled (const QString& url) const +{ return getUpdater (url)->downloaderEnabled(); } @@ -118,7 +125,8 @@ bool QSimpleUpdater::getDownloaderEnabled (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -bool QSimpleUpdater::usesCustomInstallProcedures (const QString& url) const { +bool QSimpleUpdater::usesCustomInstallProcedures (const QString& url) const +{ return getUpdater (url)->useCustomInstallProcedures(); } @@ -131,7 +139,8 @@ bool QSimpleUpdater::usesCustomInstallProcedures (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -QString QSimpleUpdater::getOpenUrl (const QString& url) const { +QString QSimpleUpdater::getOpenUrl (const QString& url) const +{ return getUpdater (url)->openUrl(); } @@ -143,7 +152,8 @@ QString QSimpleUpdater::getOpenUrl (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -QString QSimpleUpdater::getChangelog (const QString& url) const { +QString QSimpleUpdater::getChangelog (const QString& url) const +{ return getUpdater (url)->changelog(); } @@ -156,7 +166,8 @@ QString QSimpleUpdater::getChangelog (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -QString QSimpleUpdater::getModuleName (const QString& url) const { +QString QSimpleUpdater::getModuleName (const QString& url) const +{ return getUpdater (url)->moduleName(); } @@ -168,7 +179,8 @@ QString QSimpleUpdater::getModuleName (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -QString QSimpleUpdater::getDownloadUrl (const QString& url) const { +QString QSimpleUpdater::getDownloadUrl (const QString& url) const +{ return getUpdater (url)->downloadUrl(); } @@ -185,7 +197,8 @@ QString QSimpleUpdater::getDownloadUrl (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -QString QSimpleUpdater::getPlatformKey (const QString& url) const { +QString QSimpleUpdater::getPlatformKey (const QString& url) const +{ return getUpdater (url)->platformKey(); } @@ -197,7 +210,8 @@ QString QSimpleUpdater::getPlatformKey (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -QString QSimpleUpdater::getLatestVersion (const QString& url) const { +QString QSimpleUpdater::getLatestVersion (const QString& url) const +{ return getUpdater (url)->latestVersion(); } @@ -210,7 +224,8 @@ QString QSimpleUpdater::getLatestVersion (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -QString QSimpleUpdater::getModuleVersion (const QString& url) const { +QString QSimpleUpdater::getModuleVersion (const QString& url) const +{ return getUpdater (url)->moduleVersion(); } @@ -221,7 +236,8 @@ QString QSimpleUpdater::getModuleVersion (const QString& url) const { * \note If an \c Updater instance registered with the given \a url is not * found, that \c Updater instance will be initialized automatically */ -void QSimpleUpdater::checkForUpdates (const QString& url) { +void QSimpleUpdater::checkForUpdates (const QString& url) +{ getUpdater (url)->checkForUpdates(); } @@ -234,7 +250,8 @@ void QSimpleUpdater::checkForUpdates (const QString& url) { * \note The module name is used on the user prompts. If the module name is * empty, then the prompts will show the name of the application. */ -void QSimpleUpdater::setModuleName (const QString& url, const QString& name) { +void QSimpleUpdater::setModuleName (const QString& url, const QString& name) +{ getUpdater (url)->setModuleName (name); } @@ -246,7 +263,8 @@ void QSimpleUpdater::setModuleName (const QString& url, const QString& name) { * found, that \c Updater instance will be initialized automatically */ void QSimpleUpdater::setNotifyOnUpdate (const QString& url, - const bool notify) { + const bool notify) +{ getUpdater (url)->setNotifyOnUpdate (notify); } @@ -259,7 +277,8 @@ void QSimpleUpdater::setNotifyOnUpdate (const QString& url, * found, that \c Updater instance will be initialized automatically */ void QSimpleUpdater::setNotifyOnFinish (const QString& url, - const bool notify) { + const bool notify) +{ getUpdater (url)->setNotifyOnFinish (notify); } @@ -278,7 +297,8 @@ void QSimpleUpdater::setNotifyOnFinish (const QString& url, * found, that \c Updater instance will be initialized automatically */ void QSimpleUpdater::setPlatformKey (const QString& url, - const QString& platform) { + const QString& platform) +{ getUpdater (url)->setPlatformKey (platform); } @@ -291,7 +311,8 @@ void QSimpleUpdater::setPlatformKey (const QString& url, * application version. */ void QSimpleUpdater::setModuleVersion (const QString& url, - const QString& version) { + const QString& version) +{ getUpdater (url)->setModuleVersion (version); } @@ -304,7 +325,8 @@ void QSimpleUpdater::setModuleVersion (const QString& url, * found, that \c Updater instance will be initialized automatically */ void QSimpleUpdater::setDownloaderEnabled (const QString& url, - const bool enabled) { + const bool enabled) +{ getUpdater (url)->setDownloaderEnabled (enabled); } @@ -318,7 +340,8 @@ void QSimpleUpdater::setDownloaderEnabled (const QString& url, * found, that \c Updater instance will be initialized automatically */ void QSimpleUpdater::setUseCustomAppcast (const QString& url, - const bool customAppcast) { + const bool customAppcast) +{ getUpdater (url)->setUseCustomAppcast (customAppcast); } @@ -334,7 +357,8 @@ void QSimpleUpdater::setUseCustomAppcast (const QString& url, * found, that \c Updater instance will be initialized automatically */ void QSimpleUpdater::setUseCustomInstallProcedures (const QString& url, - const bool custom) { + const bool custom) +{ getUpdater (url)->setUseCustomInstallProcedures (custom); } @@ -344,7 +368,8 @@ void QSimpleUpdater::setUseCustomInstallProcedures (const QString& url, * If an \c Updater instance registered with teh given \a url does not exist, * this function will create it and configure it automatically. */ -Updater* QSimpleUpdater::getUpdater (const QString& url) const { +Updater* QSimpleUpdater::getUpdater (const QString& url) const +{ if (!URLS.contains (url)) { Updater* updater = new Updater; updater->setUrl (url); diff --git a/src/Updater.cpp b/src/Updater.cpp index 54aabc0..22c38f8 100644 --- a/src/Updater.cpp +++ b/src/Updater.cpp @@ -37,7 +37,8 @@ #include "Updater.h" #include "Downloader.h" -Updater::Updater() { +Updater::Updater() +{ m_url = ""; m_openUrl = ""; m_changelog = ""; @@ -72,14 +73,16 @@ Updater::Updater() { this, SLOT (onReply (QNetworkReply*))); } -Updater::~Updater() { +Updater::~Updater() +{ delete m_downloader; } /** * Returns the URL of the update definitions file */ -QString Updater::url() const { +QString Updater::url() const +{ return m_url; } @@ -89,7 +92,8 @@ QString Updater::url() const { * * \warning You should call \c checkForUpdates() before using this functio */ -QString Updater::openUrl() const { +QString Updater::openUrl() const +{ return m_openUrl; } @@ -97,14 +101,16 @@ QString Updater::openUrl() const { * Returns the changelog defined by the update definitions file. * \warning You should call \c checkForUpdates() before using this function */ -QString Updater::changelog() const { +QString Updater::changelog() const +{ return m_changelog; } /** * Returns the name of the module (if defined) */ -QString Updater::moduleName() const { +QString Updater::moduleName() const +{ return m_moduleName; } @@ -118,7 +124,8 @@ QString Updater::moduleName() const { * - On GNU/Linux: \c linux * - On Microsoft Windows: \c windows */ -QString Updater::platformKey() const { +QString Updater::platformKey() const +{ return m_platform; } @@ -126,7 +133,8 @@ QString Updater::platformKey() const { * Returns the download URL defined by the update definitions file. * \warning You should call \c checkForUpdates() before using this function */ -QString Updater::downloadUrl() const { +QString Updater::downloadUrl() const +{ return m_downloadUrl; } @@ -134,14 +142,16 @@ QString Updater::downloadUrl() const { * Returns the latest version defined by the update definitions file. * \warning You should call \c checkForUpdates() before using this function */ -QString Updater::latestVersion() const { +QString Updater::latestVersion() const +{ return m_latestVersion; } /** * Returns the "local" version of the installed module */ -QString Updater::moduleVersion() const { +QString Updater::moduleVersion() const +{ return m_moduleVersion; } @@ -150,7 +160,8 @@ QString Updater::moduleVersion() const { * This is useful if you need to store more variables (or information) in the * JSON file or use another appcast format (e.g. XML) */ -bool Updater::customAppcast() const { +bool Updater::customAppcast() const +{ return m_customAppcast; } @@ -158,7 +169,8 @@ bool Updater::customAppcast() const { * Returns \c true if the updater should notify the user when an update is * available. */ -bool Updater::notifyOnUpdate() const { +bool Updater::notifyOnUpdate() const +{ return m_notifyOnUpdate; } @@ -169,7 +181,8 @@ bool Updater::notifyOnUpdate() const { * \note If set to \c true, the \c Updater will notify the user even when there * are no updates available (by congratulating him/her about being smart) */ -bool Updater::notifyOnFinish() const { +bool Updater::notifyOnFinish() const +{ return m_notifyOnFinish; } @@ -177,7 +190,8 @@ bool Updater::notifyOnFinish() const { * Returns \c true if there is an update available. * \warning You should call \c checkForUpdates() before using this function */ -bool Updater::updateAvailable() const { +bool Updater::updateAvailable() const +{ return m_updateAvailable; } @@ -186,7 +200,8 @@ bool Updater::updateAvailable() const { * \note If set to \c true, the \c Updater will open the downloader dialog if * the user agrees to download the update. */ -bool Updater::downloaderEnabled() const { +bool Updater::downloaderEnabled() const +{ return m_downloaderEnabled; } @@ -195,7 +210,8 @@ bool Updater::downloaderEnabled() const { * finished (you can use the \c QSimpleUpdater signals to know when the * download is completed). */ -bool Updater::useCustomInstallProcedures() const { +bool Updater::useCustomInstallProcedures() const +{ return m_downloader->useCustomInstallProcedures(); } @@ -203,7 +219,8 @@ bool Updater::useCustomInstallProcedures() const { * Downloads and interpets the update definitions file referenced by the * \c url() function. */ -void Updater::checkForUpdates() { +void Updater::checkForUpdates() +{ m_manager->get (QNetworkRequest (url())); } @@ -211,7 +228,8 @@ void Updater::checkForUpdates() { * Changes the \c url in which the \c Updater can find the update definitions * file. */ -void Updater::setUrl (const QString& url) { +void Updater::setUrl (const QString& url) +{ m_url = url; } @@ -220,7 +238,8 @@ void Updater::setUrl (const QString& url) { * \note The module name is used on the user prompts. If the module name is * empty, then the prompts will show the name of the application. */ -void Updater::setModuleName (const QString& name) { +void Updater::setModuleName (const QString& name) +{ m_moduleName = name; } @@ -228,7 +247,8 @@ void Updater::setModuleName (const QString& name) { * If \a notify is set to \c true, then the \c Updater will notify the user * when an update is available. */ -void Updater::setNotifyOnUpdate (const bool notify) { +void Updater::setNotifyOnUpdate (const bool notify) +{ m_notifyOnUpdate = notify; } @@ -236,7 +256,8 @@ void Updater::setNotifyOnUpdate (const bool notify) { * If \a notify is set to \c true, then the \c Updater will notify the user * when it has finished interpreting the update definitions file. */ -void Updater::setNotifyOnFinish (const bool notify) { +void Updater::setNotifyOnFinish (const bool notify) +{ m_notifyOnFinish = notify; } @@ -246,7 +267,8 @@ void Updater::setNotifyOnFinish (const bool notify) { * If the \a version parameter is empty, then the \c Updater will use the * application version (referenced by \c qApp) */ -void Updater::setModuleVersion (const QString& version) { +void Updater::setModuleVersion (const QString& version) +{ m_moduleVersion = version; } @@ -254,7 +276,8 @@ void Updater::setModuleVersion (const QString& version) { * If the \a enabled parameter is set to \c true, the \c Updater will open the * integrated downloader if the user agrees to install the update (if any) */ -void Updater::setDownloaderEnabled (const bool enabled) { +void Updater::setDownloaderEnabled (const bool enabled) +{ m_downloaderEnabled = enabled; } @@ -267,7 +290,8 @@ void Updater::setDownloaderEnabled (const bool enabled) { * - On GNU/Linux: \c linux * - On Microsoft Windows: \c windows */ -void Updater::setPlatformKey (const QString& platformKey) { +void Updater::setPlatformKey (const QString& platformKey) +{ m_platform = platformKey; } @@ -277,7 +301,8 @@ void Updater::setPlatformKey (const QString& platformKey) { * emit the \c appcastDownloaded() signal, which allows the application to * read and interpret the appcast file by itself */ -void Updater::setUseCustomAppcast (const bool customAppcast) { +void Updater::setUseCustomAppcast (const bool customAppcast) +{ m_customAppcast = customAppcast; } @@ -286,14 +311,16 @@ void Updater::setUseCustomAppcast (const bool customAppcast) { * to open the downloaded file. Use the signals fired by the \c QSimpleUpdater * to install the update from the downloaded file by yourself. */ -void Updater::setUseCustomInstallProcedures (const bool custom) { +void Updater::setUseCustomInstallProcedures (const bool custom) +{ m_downloader->setUseCustomInstallProcedures (custom); } /** * Called when the download of the update definitions file is finished. */ -void Updater::onReply (QNetworkReply* reply) { +void Updater::onReply (QNetworkReply* reply) +{ /* Check if we need to redirect */ QUrl redirect = reply->attribute ( QNetworkRequest::RedirectionTargetAttribute).toUrl(); @@ -339,7 +366,8 @@ void Updater::onReply (QNetworkReply* reply) { * Prompts the user based on the value of the \a available parameter and the * settings of this instance of the \c Updater class. */ -void Updater::setUpdateAvailable (const bool available) { +void Updater::setUpdateAvailable (const bool available) +{ m_updateAvailable = available; QMessageBox box; @@ -391,7 +419,8 @@ void Updater::setUpdateAvailable (const bool available) { * - If \a y is greater than \x, this function returns \c false. * - If both versions are the same, this function returns \c false. */ -bool Updater::compare (const QString& x, const QString& y) { +bool Updater::compare (const QString& x, const QString& y) +{ QStringList versionsX = x.split ("."); QStringList versionsY = y.split ("."); diff --git a/src/Updater.h b/src/Updater.h index 7061d09..939ed8d 100644 --- a/src/Updater.h +++ b/src/Updater.h @@ -42,15 +42,16 @@ class Downloader; /** * \brief Downloads and interprests the update definition file */ -class QSU_DECL Updater : public QObject { +class QSU_DECL Updater : public QObject +{ Q_OBJECT - signals: +signals: void checkingFinished (const QString& url); void downloadFinished (const QString& url, const QString& filepath); void appcastDownloaded (const QString& url, const QByteArray& data); - public: +public: Updater(); ~Updater(); @@ -70,7 +71,7 @@ class QSU_DECL Updater : public QObject { bool downloaderEnabled() const; bool useCustomInstallProcedures() const; - public slots: +public slots: void checkForUpdates(); void setUrl (const QString& url); void setModuleName (const QString& name); @@ -82,14 +83,14 @@ class QSU_DECL Updater : public QObject { void setUseCustomAppcast (const bool customAppcast); void setUseCustomInstallProcedures (const bool custom); - private slots: +private slots: void onReply (QNetworkReply* reply); void setUpdateAvailable (const bool available); - private: +private: bool compare (const QString& x, const QString& y); - private: +private: QString m_url; bool m_customAppcast; diff --git a/tests/Test_Downloader.h b/tests/Test_Downloader.h old mode 100755 new mode 100644 index 1515931..a8c4e9b --- a/tests/Test_Downloader.h +++ b/tests/Test_Downloader.h @@ -26,7 +26,8 @@ #include #include -class Test_Downloader : public QObject { +class Test_Downloader : public QObject +{ Q_OBJECT }; diff --git a/tests/Test_QSimpleUpdater.h b/tests/Test_QSimpleUpdater.h old mode 100755 new mode 100644 index 7bba295..0e78a3f --- a/tests/Test_QSimpleUpdater.h +++ b/tests/Test_QSimpleUpdater.h @@ -26,7 +26,8 @@ #include #include -class Test_QSimpleUpdater : public QObject { +class Test_QSimpleUpdater : public QObject +{ Q_OBJECT }; diff --git a/tests/Test_Updater.h b/tests/Test_Updater.h old mode 100755 new mode 100644 index 14eef67..cb354d8 --- a/tests/Test_Updater.h +++ b/tests/Test_Updater.h @@ -26,7 +26,8 @@ #include #include -class Test_Updater : public QObject { +class Test_Updater : public QObject +{ Q_OBJECT }; diff --git a/tests/Tests.pro b/tests/Tests.pro old mode 100755 new mode 100644 diff --git a/tests/main.cpp b/tests/main.cpp old mode 100755 new mode 100644 index 37db880..787818e --- a/tests/main.cpp +++ b/tests/main.cpp @@ -24,7 +24,8 @@ #include "Test_Downloader.h" #include "Test_QSimpleUpdater.h" -int main (int argc, char* argv[]) { +int main (int argc, char* argv[]) +{ QApplication app (argc, argv); app.setApplicationName ("QSimpleUpdater Tests"); diff --git a/tutorial/src/Window.cpp b/tutorial/src/Window.cpp index 250ee21..b5d07a2 100644 --- a/tutorial/src/Window.cpp +++ b/tutorial/src/Window.cpp @@ -23,7 +23,8 @@ static const QString DEFS_URL = "https://raw.githubusercontent.com/" // Window::Window //============================================================================== -Window::Window (QWidget* parent) : QMainWindow (parent) { +Window::Window (QWidget* parent) : QMainWindow (parent) +{ m_ui = new Ui::Window; m_ui->setupUi (this); @@ -58,7 +59,8 @@ Window::Window (QWidget* parent) : QMainWindow (parent) { // Window::~Window //============================================================================== -Window::~Window() { +Window::~Window() +{ delete m_ui; } @@ -66,7 +68,8 @@ Window::~Window() { // Window::checkForUpdates //============================================================================== -void Window::resetFields() { +void Window::resetFields() +{ m_ui->installedVersion->setText ("0.1"); m_ui->customAppcast->setChecked (false); m_ui->enableDownloader->setChecked (true); @@ -78,7 +81,8 @@ void Window::resetFields() { // Window::checkForUpdates //============================================================================== -void Window::checkForUpdates() { +void Window::checkForUpdates() +{ /* Get settings from the UI */ QString version = m_ui->installedVersion->text(); bool customAppcast = m_ui->customAppcast->isChecked(); @@ -101,7 +105,8 @@ void Window::checkForUpdates() { // Window::updateChangelog //============================================================================== -void Window::updateChangelog (const QString& url) { +void Window::updateChangelog (const QString& url) +{ if (url == DEFS_URL) m_ui->changelogText->setText (m_updater->getChangelog (url)); } @@ -111,7 +116,8 @@ void Window::updateChangelog (const QString& url) { // Window::displayAppcast //============================================================================== -void Window::displayAppcast (const QString& url, const QByteArray& reply) { +void Window::displayAppcast (const QString& url, const QByteArray& reply) +{ if (url == DEFS_URL) { QString text = "This is the downloaded appcast:

" +
                        QString::fromUtf8 (reply) +
diff --git a/tutorial/src/Window.h b/tutorial/src/Window.h
index 7fa75b1..027508e 100644
--- a/tutorial/src/Window.h
+++ b/tutorial/src/Window.h
@@ -18,20 +18,21 @@ class Window;
 
 class QSimpleUpdater;
 
-class Window : public QMainWindow {
+class Window : public QMainWindow
+{
     Q_OBJECT
 
-  public:
+public:
     explicit Window (QWidget* parent = 0);
     ~Window();
 
-  public slots:
+public slots:
     void resetFields();
     void checkForUpdates();
     void updateChangelog (const QString& url);
     void displayAppcast (const QString& url, const QByteArray& reply);
 
-  private:
+private:
     Ui::Window* m_ui;
     QSimpleUpdater* m_updater;
 };
diff --git a/tutorial/src/main.cpp b/tutorial/src/main.cpp
index 1f1962e..85c31ba 100644
--- a/tutorial/src/main.cpp
+++ b/tutorial/src/main.cpp
@@ -8,7 +8,8 @@
 
 #include "Window.h"
 
-int main (int argc, char** argv) {
+int main (int argc, char** argv)
+{
     QApplication app (argc, argv);
     app.setApplicationVersion ("1.0");
     app.setApplicationName ("Bob's Badass App");