Update code format scripts
This commit is contained in:
parent
5a65ec3ed9
commit
c52b815c6a
0
etc/resources/qsimpleupdater.qrc
Executable file → Normal file
0
etc/resources/qsimpleupdater.qrc
Executable file → Normal file
@ -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.
|
||||
|
@ -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
|
||||
|
@ -35,11 +35,11 @@
|
||||
#include <QObject>
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
|
47
src/Downloader.cpp
Executable file → Normal file
47
src/Downloader.cpp
Executable file → Normal file
@ -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;
|
||||
}
|
||||
|
15
src/Downloader.h
Executable file → Normal file
15
src/Downloader.h
Executable file → Normal file
@ -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;
|
||||
|
0
src/Downloader.ui
Executable file → Normal file
0
src/Downloader.ui
Executable file → Normal file
@ -33,7 +33,8 @@
|
||||
static QList<QString> URLS;
|
||||
static QList<Updater*> 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);
|
||||
|
@ -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 (".");
|
||||
|
||||
|
@ -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;
|
||||
|
3
tests/Test_Downloader.h
Executable file → Normal file
3
tests/Test_Downloader.h
Executable file → Normal file
@ -26,7 +26,8 @@
|
||||
#include <QtTest>
|
||||
#include <Downloader.h>
|
||||
|
||||
class Test_Downloader : public QObject {
|
||||
class Test_Downloader : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
3
tests/Test_QSimpleUpdater.h
Executable file → Normal file
3
tests/Test_QSimpleUpdater.h
Executable file → Normal file
@ -26,7 +26,8 @@
|
||||
#include <QtTest>
|
||||
#include <QSimpleUpdater.h>
|
||||
|
||||
class Test_QSimpleUpdater : public QObject {
|
||||
class Test_QSimpleUpdater : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
3
tests/Test_Updater.h
Executable file → Normal file
3
tests/Test_Updater.h
Executable file → Normal file
@ -26,7 +26,8 @@
|
||||
#include <QtTest>
|
||||
#include <Updater.h>
|
||||
|
||||
class Test_Updater : public QObject {
|
||||
class Test_Updater : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
};
|
||||
|
||||
|
0
tests/Tests.pro
Executable file → Normal file
0
tests/Tests.pro
Executable file → Normal file
3
tests/main.cpp
Executable file → Normal file
3
tests/main.cpp
Executable file → Normal file
@ -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");
|
||||
|
@ -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: <p><pre>" +
|
||||
QString::fromUtf8 (reply) +
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user