Added developer documentation links in readme file

- Added developer documentation links in read me
- Added aytostyle scripts
This commit is contained in:
Alex Spataru 2015-01-25 17:27:18 -06:00
parent 14ad5b9db9
commit 23999faf4e
12 changed files with 266 additions and 148 deletions

View File

@ -1,9 +1,10 @@
#include "example.h" #include "example.h"
#include "ui_example.h" #include "ui_example.h"
int main (int argc, char *argv[]) { int main (int argc, char *argv[])
QApplication app(argc, argv); {
app.setApplicationName("QSimpleUpdater Example"); QApplication app (argc, argv);
app.setApplicationName ("QSimpleUpdater Example");
// Create the dialog and show it // Create the dialog and show it
Example example; Example example;
@ -13,74 +14,76 @@ int main (int argc, char *argv[]) {
return app.exec(); return app.exec();
} }
Example::Example (QWidget *parent) : QDialog(parent), ui(new Ui::Example) { Example::Example (QWidget *parent) : QDialog (parent), ui (new Ui::Example)
{
// Create and configure the user interface // Create and configure the user interface
ui->setupUi(this); ui->setupUi (this);
ui->versionLineEdit->setText("0.1"); ui->versionLineEdit->setText ("0.1");
ui->versionLineEdit->setPlaceholderText("0.1"); ui->versionLineEdit->setPlaceholderText ("0.1");
ui->changelogTextEdit->setPlainText("Click the \"Check for updates\" button to download the change log"); ui->changelogTextEdit->setPlainText ("Click the \"Check for updates\" button to download the change log");
// Close the dialog when the close button is clicked // Close the dialog when the close button is clicked
connect (ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); connect (ui->closeButton, SIGNAL (clicked()), this, SLOT (close()));
// Check for updates when the updates button is clicked // Check for updates when the updates button is clicked
connect (ui->updatesButton, SIGNAL(clicked()), this, SLOT(checkForUpdates())); connect (ui->updatesButton, SIGNAL (clicked()), this, SLOT (checkForUpdates()));
// Initialize the updater // Initialize the updater
updater = new QSimpleUpdater(this); updater = new QSimpleUpdater (this);
// When the updater finishes checking for updates, show a message box // When the updater finishes checking for updates, show a message box
// and show the change log of the latest version // and show the change log of the latest version
connect (updater, SIGNAL(checkingFinished()), this, SLOT(onCheckingFinished())); connect (updater, SIGNAL (checkingFinished()), this, SLOT (onCheckingFinished()));
} }
Example::~Example() { Example::~Example()
{
delete ui; delete ui;
} }
void Example::checkForUpdates() { void Example::checkForUpdates()
{
// Disable the check for updates button while the updater // Disable the check for updates button while the updater
// is checking for updates // is checking for updates
ui->updatesButton->setEnabled(false); ui->updatesButton->setEnabled (false);
ui->updatesButton->setText("Checking for updates..."); ui->updatesButton->setText ("Checking for updates...");
// If the user changed the text of the versionLineEdit, then change the // If the user changed the text of the versionLineEdit, then change the
// application version in the updater too // application version in the updater too
if (!ui->versionLineEdit->text().isEmpty()) { if (!ui->versionLineEdit->text().isEmpty())
updater->setApplicationVersion(ui->versionLineEdit->text()); updater->setApplicationVersion (ui->versionLineEdit->text());
}
// If the versionLineEdit is empty, then set the application version // If the versionLineEdit is empty, then set the application version
// to "0.1" // to "0.1"
else { else
updater->setApplicationVersion("0.1"); updater->setApplicationVersion ("0.1");
}
// Tell the updater where we should download the changelog, note that // Tell the updater where we should download the changelog, note that
// the changelog can be any file you want, // the changelog can be any file you want,
// such as an HTML page or (as in this example), a text file // such as an HTML page or (as in this example), a text file
updater->setChangelogUrl("https://raw.githubusercontent.com/alex-97/" updater->setChangelogUrl ("https://raw.githubusercontent.com/alex-97/"
"QSimpleUpdater/Files-for-example-project/changelog.txt"); "QSimpleUpdater/Files-for-example-project/changelog.txt");
// Tell the updater where we can find the file that tells us the latest version // Tell the updater where we can find the file that tells us the latest version
// of the application // of the application
updater->setReferenceUrl("https://raw.githubusercontent.com/alex-97/" updater->setReferenceUrl ("https://raw.githubusercontent.com/alex-97/"
"QSimpleUpdater/Files-for-example-project/current_version.txt"); "QSimpleUpdater/Files-for-example-project/current_version.txt");
// Tell the updater where to download the update, its recommended to use direct links // Tell the updater where to download the update, its recommended to use direct links
updater->setDownloadUrl("https://codeload.github.com/alex-97/QSimpleUpdater/zip/master"); updater->setDownloadUrl ("https://codeload.github.com/alex-97/QSimpleUpdater/zip/master");
// Show the progress dialog and show messages when checking is finished // Show the progress dialog and show messages when checking is finished
updater->setSilent(false); updater->setSilent (false);
updater->setShowNewestVersionMessage(true); updater->setShowNewestVersionMessage (true);
// Finally, check for updates... // Finally, check for updates...
updater->checkForUpdates(); updater->checkForUpdates();
} }
void Example::onCheckingFinished() { void Example::onCheckingFinished()
{
// Enable the updatesButton and change its text to let the user know // Enable the updatesButton and change its text to let the user know
// that he/she can check for updates again // that he/she can check for updates again
ui->updatesButton->setEnabled(true); ui->updatesButton->setEnabled (true);
ui->updatesButton->setText("Check for updates"); ui->updatesButton->setText ("Check for updates");
} }

View File

@ -5,7 +5,8 @@
#include <QMessageBox> #include <QMessageBox>
#include <QSimpleUpdater> #include <QSimpleUpdater>
namespace Ui { namespace Ui
{
class Example; class Example;
} }
@ -13,15 +14,15 @@ class Example : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Example(QWidget *parent = 0); explicit Example (QWidget *parent = 0);
~Example(); ~Example();
public slots: public slots:
void checkForUpdates(); void checkForUpdates();
void onCheckingFinished(); void onCheckingFinished();
private: private:
Ui::Example *ui; Ui::Example *ui;
QString m_installed_version; QString m_installed_version;

View File

@ -18,7 +18,8 @@
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);
@ -45,11 +46,13 @@ DownloadDialog::DownloadDialog (QWidget *parent)
SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>))); SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
} }
DownloadDialog::~DownloadDialog (void) { DownloadDialog::~DownloadDialog (void)
{
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
@ -73,7 +76,8 @@ void DownloadDialog::beginDownload (const QUrl& url) {
showNormal(); showNormal();
} }
void DownloadDialog::installUpdate (void) { void DownloadDialog::installUpdate (void)
{
QMessageBox msg; QMessageBox msg;
msg.setIcon (QMessageBox::Question); msg.setIcon (QMessageBox::Question);
msg.setText ("<b>" + msg.setText ("<b>" +
@ -83,20 +87,24 @@ void DownloadDialog::installUpdate (void) {
msg.setInformativeText (tr ("Do you want to quit %1 now?").arg (qApp->applicationName())); msg.setInformativeText (tr ("Do you want to quit %1 now?").arg (qApp->applicationName()));
msg.setStandardButtons (QMessageBox::Yes | QMessageBox::No); msg.setStandardButtons (QMessageBox::Yes | QMessageBox::No);
if (msg.exec() == QMessageBox::Yes) { if (msg.exec() == QMessageBox::Yes)
{
openDownload(); openDownload();
qApp->closeAllWindows(); qApp->closeAllWindows();
} }
else { else
{
ui->openButton->setEnabled (true); ui->openButton->setEnabled (true);
ui->openButton->setVisible (true); ui->openButton->setVisible (true);
ui->timeLabel->setText (tr ("Click the \"Open\" button to apply the update")); ui->timeLabel->setText (tr ("Click the \"Open\" button to apply the update"));
} }
} }
void DownloadDialog::openDownload (void) { void DownloadDialog::openDownload (void)
if (!m_path.isEmpty()) { {
if (!m_path.isEmpty())
{
QString url = m_path; QString url = m_path;
if (url.startsWith ("/")) if (url.startsWith ("/"))
@ -109,15 +117,18 @@ void DownloadDialog::openDownload (void) {
} }
} }
void DownloadDialog::cancelDownload (void) { void DownloadDialog::cancelDownload (void)
if (!m_reply->isFinished()) { {
if (!m_reply->isFinished())
{
QMessageBox _message; QMessageBox _message;
_message.setWindowTitle (tr ("Updater")); _message.setWindowTitle (tr ("Updater"));
_message.setIcon (QMessageBox::Question); _message.setIcon (QMessageBox::Question);
_message.setStandardButtons (QMessageBox::Yes | QMessageBox::No); _message.setStandardButtons (QMessageBox::Yes | QMessageBox::No);
_message.setText (tr ("Are you sure you want to cancel the download?")); _message.setText (tr ("Are you sure you want to cancel the download?"));
if (_message.exec() == QMessageBox::Yes) { if (_message.exec() == QMessageBox::Yes)
{
hide(); hide();
m_reply->abort(); m_reply->abort();
} }
@ -127,18 +138,21 @@ void DownloadDialog::cancelDownload (void) {
hide(); hide();
} }
void DownloadDialog::downloadFinished (void) { void DownloadDialog::downloadFinished (void)
{
ui->stopButton->setText (tr ("Close")); ui->stopButton->setText (tr ("Close"));
ui->downloadLabel->setText (tr ("Download complete!")); ui->downloadLabel->setText (tr ("Download complete!"));
ui->timeLabel->setText (tr ("The installer will open in a separate window...")); ui->timeLabel->setText (tr ("The installer will open in a separate window..."));
QByteArray data = m_reply->readAll(); QByteArray data = m_reply->readAll();
if (!data.isEmpty()) { if (!data.isEmpty())
{
QStringList list = m_reply->url().toString().split ("/"); QStringList list = m_reply->url().toString().split ("/");
QFile file (QDir::tempPath() + "/" + list.at (list.count() - 1)); QFile file (QDir::tempPath() + "/" + list.at (list.count() - 1));
if (file.open (QIODevice::WriteOnly)) { if (file.open (QIODevice::WriteOnly))
{
file.write (data); file.write (data);
m_path = file.fileName(); m_path = file.fileName();
} }
@ -148,9 +162,11 @@ void DownloadDialog::downloadFinished (void) {
} }
} }
void DownloadDialog::updateProgress (qint64 received, qint64 total) { void DownloadDialog::updateProgress (qint64 received, qint64 total)
{
// We know the size of the download, so we can calculate the progress.... // We know the size of the download, so we can calculate the progress....
if (total > 0 && received > 0) { if (total > 0 && received > 0)
{
ui->progressBar->setMinimum (0); ui->progressBar->setMinimum (0);
ui->progressBar->setMaximum (100); ui->progressBar->setMaximum (100);
@ -166,12 +182,14 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total) {
if (_total < 1024) if (_total < 1024)
_total_string = tr ("%1 bytes").arg (_total); _total_string = tr ("%1 bytes").arg (_total);
else if (_total < 1024 * 1024) { else if (_total < 1024 * 1024)
{
_total = roundNumber (_total / 1024); _total = roundNumber (_total / 1024);
_total_string = tr ("%1 KB").arg (_total); _total_string = tr ("%1 KB").arg (_total);
} }
else { else
{
_total = roundNumber (_total / (1024 * 1024)); _total = roundNumber (_total / (1024 * 1024));
_total_string = tr ("%1 MB").arg (_total); _total_string = tr ("%1 MB").arg (_total);
} }
@ -179,12 +197,14 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total) {
if (_received < 1024) if (_received < 1024)
_received_string = tr ("%1 bytes").arg (_received); _received_string = tr ("%1 bytes").arg (_received);
else if (received < 1024 * 1024) { else if (received < 1024 * 1024)
{
_received = roundNumber (_received / 1024); _received = roundNumber (_received / 1024);
_received_string = tr ("%1 KB").arg (_received); _received_string = tr ("%1 KB").arg (_received);
} }
else { else
{
_received = roundNumber (_received / (1024 * 1024)); _received = roundNumber (_received / (1024 * 1024));
_received_string = tr ("%1 MB").arg (_received); _received_string = tr ("%1 MB").arg (_received);
} }
@ -193,16 +213,19 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total) {
uint _diff = QDateTime::currentDateTime().toTime_t() - m_start_time; uint _diff = QDateTime::currentDateTime().toTime_t() - m_start_time;
if (_diff > 0) { if (_diff > 0)
{
QString _time_string; QString _time_string;
float _time_remaining = total / (received / _diff); float _time_remaining = total / (received / _diff);
if (_time_remaining > 7200) { if (_time_remaining > 7200)
{
_time_remaining /= 3600; _time_remaining /= 3600;
_time_string = tr ("About %1 hours").arg (int (_time_remaining + 0.5)); _time_string = tr ("About %1 hours").arg (int (_time_remaining + 0.5));
} }
else if (_time_remaining > 60) { else if (_time_remaining > 60)
{
_time_remaining /= 60; _time_remaining /= 60;
_time_string = tr ("About %1 minutes").arg (int (_time_remaining + 0.5)); _time_string = tr ("About %1 minutes").arg (int (_time_remaining + 0.5));
} }
@ -216,7 +239,8 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total) {
// We do not know the size of the download, so we avoid scaring the shit out // We do not know the size of the download, so we avoid scaring the shit out
// of the user // of the user
else { else
{
ui->progressBar->setValue (-1); ui->progressBar->setValue (-1);
ui->progressBar->setMinimum (0); ui->progressBar->setMinimum (0);
ui->progressBar->setMaximum (0); ui->progressBar->setMaximum (0);
@ -226,7 +250,8 @@ void DownloadDialog::updateProgress (qint64 received, qint64 total) {
} }
void DownloadDialog::ignoreSslErrors (QNetworkReply *reply, void DownloadDialog::ignoreSslErrors (QNetworkReply *reply,
const QList<QSslError>& error) { const QList<QSslError>& error)
{
#ifndef Q_OS_IOS #ifndef Q_OS_IOS
reply->ignoreSslErrors (error); reply->ignoreSslErrors (error);
#else #else
@ -235,6 +260,7 @@ void DownloadDialog::ignoreSslErrors (QNetworkReply *reply,
#endif #endif
} }
float DownloadDialog::roundNumber (const float& input) { float DownloadDialog::roundNumber (const float& input)
{
return roundf (input * 100) / 100; return roundf (input * 100) / 100;
} }

View File

@ -26,11 +26,13 @@
#include <math.h> #include <math.h>
namespace Ui { namespace Ui
{
class DownloadDialog; class DownloadDialog;
} }
class DownloadDialog : public QWidget { class DownloadDialog : public QWidget
{
Q_OBJECT Q_OBJECT
public: public:

View File

@ -15,10 +15,10 @@
#include "progress_dialog.h" #include "progress_dialog.h"
#include "ui_progress_dialog.h" #include "ui_progress_dialog.h"
ProgressDialog::ProgressDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ProgressDialog) ProgressDialog::ProgressDialog (QWidget *parent) : QDialog (parent), ui (new Ui::ProgressDialog)
{ {
// Create and configure UI // Create and configure UI
ui->setupUi(this); ui->setupUi (this);
// Make the window look like a dialog // Make the window look like a dialog
QIcon _blank; QIcon _blank;
@ -27,7 +27,7 @@ ProgressDialog::ProgressDialog(QWidget *parent) : QDialog(parent), ui(new Ui::Pr
setWindowFlags (Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint); setWindowFlags (Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
// Close dialog when cancel button is clicked // Close dialog when cancel button is clicked
connect(ui->ui_cancel_button, SIGNAL(clicked()), this, SLOT(cancel())); connect (ui->ui_cancel_button, SIGNAL (clicked()), this, SLOT (cancel()));
} }
ProgressDialog::~ProgressDialog() ProgressDialog::~ProgressDialog()
@ -35,7 +35,8 @@ ProgressDialog::~ProgressDialog()
delete ui; delete ui;
} }
void ProgressDialog::cancel(void) { void ProgressDialog::cancel (void)
{
hide(); hide();
emit cancelClicked(); emit cancelClicked();
} }

View File

@ -17,7 +17,8 @@
#include <QDialog> #include <QDialog>
namespace Ui { namespace Ui
{
class ProgressDialog; class ProgressDialog;
} }
@ -25,17 +26,17 @@ class ProgressDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ProgressDialog(QWidget *parent = 0); explicit ProgressDialog (QWidget *parent = 0);
~ProgressDialog(); ~ProgressDialog();
signals: signals:
void cancelClicked(); void cancelClicked();
private slots: private slots:
void cancel (void); void cancel (void);
private: private:
Ui::ProgressDialog *ui; Ui::ProgressDialog *ui;
}; };

View File

@ -88,7 +88,8 @@ QSimpleUpdater::QSimpleUpdater (QObject *parent)
, m_silent (false) , m_silent (false)
, m_show_newest_version (true) , m_show_newest_version (true)
, m_show_update_available (true) , m_show_update_available (true)
, m_new_version_available (false) { , m_new_version_available (false)
{
m_progressDialog = new ProgressDialog(); m_progressDialog = new ProgressDialog();
m_downloadDialog = new DownloadDialog(); m_downloadDialog = new DownloadDialog();
@ -99,7 +100,7 @@ QSimpleUpdater::QSimpleUpdater (QObject *parent)
connect (m_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)), connect (m_manager, SIGNAL (sslErrors (QNetworkReply *, QList<QSslError>)),
this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>))); this, SLOT (ignoreSslErrors (QNetworkReply *, QList<QSslError>)));
connect (m_progressDialog, SIGNAL(cancelClicked()), this, SLOT(cancel())); connect (m_progressDialog, SIGNAL (cancelClicked()), this, SLOT (cancel()));
connect (this, SIGNAL (checkingFinished()), this, SLOT (onCheckingFinished())); connect (this, SIGNAL (checkingFinished()), this, SLOT (onCheckingFinished()));
} }
@ -109,7 +110,8 @@ QSimpleUpdater::QSimpleUpdater (QObject *parent)
* \sa setChangelogUrl() * \sa setChangelogUrl()
*/ */
QString QSimpleUpdater::changeLog() const { QString QSimpleUpdater::changeLog() const
{
return m_changelog; return m_changelog;
} }
@ -120,8 +122,10 @@ QString QSimpleUpdater::changeLog() const {
* \sa setDownloadUrl(), setReferenceUrl() * \sa setDownloadUrl(), setReferenceUrl()
*/ */
void QSimpleUpdater::checkForUpdates (void) { void QSimpleUpdater::checkForUpdates (void)
if (!m_reference_url.isEmpty()) { {
if (!m_reference_url.isEmpty())
{
m_manager->get (QNetworkRequest (m_reference_url)); m_manager->get (QNetworkRequest (m_reference_url));
if (!silent()) if (!silent())
@ -138,7 +142,8 @@ void QSimpleUpdater::checkForUpdates (void) {
* \sa setDownloadUrl() * \sa setDownloadUrl()
*/ */
void QSimpleUpdater::openDownloadLink (void) { void QSimpleUpdater::openDownloadLink (void)
{
if (!m_download_url.isEmpty()) if (!m_download_url.isEmpty())
QDesktopServices::openUrl (m_download_url); QDesktopServices::openUrl (m_download_url);
} }
@ -149,7 +154,8 @@ void QSimpleUpdater::openDownloadLink (void) {
* \sa setReferenceUrl(), checkForUpdates() * \sa setReferenceUrl(), checkForUpdates()
*/ */
QString QSimpleUpdater::latestVersion() const { QString QSimpleUpdater::latestVersion() const
{
return m_latest_version; return m_latest_version;
} }
@ -159,7 +165,8 @@ QString QSimpleUpdater::latestVersion() const {
* \sa setApplicationVersion() * \sa setApplicationVersion()
*/ */
QString QSimpleUpdater::installedVersion() const { QString QSimpleUpdater::installedVersion() const
{
return m_installed_version; return m_installed_version;
} }
@ -170,7 +177,8 @@ QString QSimpleUpdater::installedVersion() const {
* \sa setDownloadUrl(), checkForUpdates() * \sa setDownloadUrl(), checkForUpdates()
*/ */
void QSimpleUpdater::downloadLatestVersion (void) { void QSimpleUpdater::downloadLatestVersion (void)
{
if (!m_download_url.isEmpty()) if (!m_download_url.isEmpty())
m_downloadDialog->beginDownload (m_download_url); m_downloadDialog->beginDownload (m_download_url);
} }
@ -182,7 +190,8 @@ void QSimpleUpdater::downloadLatestVersion (void) {
* \sa setReferenceUrl(), checkForUpdates() * \sa setReferenceUrl(), checkForUpdates()
*/ */
bool QSimpleUpdater::newerVersionAvailable() const { bool QSimpleUpdater::newerVersionAvailable() const
{
return m_new_version_available; return m_new_version_available;
} }
@ -193,7 +202,8 @@ bool QSimpleUpdater::newerVersionAvailable() const {
* \sa setSilent() * \sa setSilent()
*/ */
bool QSimpleUpdater::silent() const { bool QSimpleUpdater::silent() const
{
return m_silent; return m_silent;
} }
@ -208,7 +218,8 @@ bool QSimpleUpdater::silent() const {
* \sa downloadLatestVersion(), openDownloadLink() * \sa downloadLatestVersion(), openDownloadLink()
*/ */
void QSimpleUpdater::setDownloadUrl (const QString& url) { void QSimpleUpdater::setDownloadUrl (const QString& url)
{
Q_ASSERT (!url.isEmpty()); Q_ASSERT (!url.isEmpty());
m_download_url.setUrl (url); m_download_url.setUrl (url);
} }
@ -231,7 +242,8 @@ void QSimpleUpdater::setDownloadUrl (const QString& url) {
* \sa latestVersion() * \sa latestVersion()
*/ */
void QSimpleUpdater::setReferenceUrl (const QString& url) { void QSimpleUpdater::setReferenceUrl (const QString& url)
{
Q_ASSERT (!url.isEmpty()); Q_ASSERT (!url.isEmpty());
m_reference_url.setUrl (url); m_reference_url.setUrl (url);
} }
@ -247,7 +259,8 @@ void QSimpleUpdater::setReferenceUrl (const QString& url) {
*/ */
void QSimpleUpdater::setChangelogUrl (const QString& url) { void QSimpleUpdater::setChangelogUrl (const QString& url)
{
Q_ASSERT (!url.isEmpty()); Q_ASSERT (!url.isEmpty());
m_changelog_url.setUrl (url); m_changelog_url.setUrl (url);
} }
@ -263,7 +276,8 @@ void QSimpleUpdater::setChangelogUrl (const QString& url) {
*/ */
void QSimpleUpdater::setApplicationVersion (const QString& version) { void QSimpleUpdater::setApplicationVersion (const QString& version)
{
Q_ASSERT (!version.isEmpty()); Q_ASSERT (!version.isEmpty());
m_installed_version = version; m_installed_version = version;
} }
@ -280,11 +294,12 @@ void QSimpleUpdater::setApplicationVersion (const QString& version) {
* \sa silent() * \sa silent()
*/ */
void QSimpleUpdater::setSilent (bool silent) { void QSimpleUpdater::setSilent (bool silent)
{
m_silent = silent; m_silent = silent;
if (m_silent) if (m_silent)
setShowNewestVersionMessage(false); setShowNewestVersionMessage (false);
} }
/*! /*!
@ -294,7 +309,8 @@ void QSimpleUpdater::setSilent (bool silent) {
* \sa checkForUpdates() * \sa checkForUpdates()
*/ */
void QSimpleUpdater::setShowUpdateAvailableMessage(bool show) { void QSimpleUpdater::setShowUpdateAvailableMessage (bool show)
{
m_show_update_available = show; m_show_update_available = show;
} }
@ -308,7 +324,8 @@ void QSimpleUpdater::setShowUpdateAvailableMessage(bool show) {
* \sa checkForUpdates() * \sa checkForUpdates()
*/ */
void QSimpleUpdater::setShowNewestVersionMessage(bool show) { void QSimpleUpdater::setShowNewestVersionMessage (bool show)
{
m_show_newest_version = show; m_show_newest_version = show;
} }
@ -317,7 +334,8 @@ void QSimpleUpdater::setShowNewestVersionMessage(bool show) {
* clicks on the "cancel" button in the progress dialog. * clicks on the "cancel" button in the progress dialog.
*/ */
void QSimpleUpdater::cancel(void) { void QSimpleUpdater::cancel (void)
{
m_manager->disconnect(); m_manager->disconnect();
} }
@ -328,10 +346,14 @@ void QSimpleUpdater::cancel(void) {
* \sa checkDownloadedVersion() * \sa checkDownloadedVersion()
*/ */
void QSimpleUpdater::showErrorMessage (void) { void QSimpleUpdater::showErrorMessage (void)
{
if (!silent()) if (!silent())
QMessageBox::warning(NULL, tr("Software Updater"), {
tr("An unknown error occured while checking for updates")); m_progressDialog->hide();
QMessageBox::warning (NULL, tr ("Software Updater"),
tr ("An unknown error occured while checking for updates"));
}
} }
/*! \internal /*! \internal
@ -341,34 +363,40 @@ void QSimpleUpdater::showErrorMessage (void) {
* \sa checkDownloadedVersion() * \sa checkDownloadedVersion()
*/ */
void QSimpleUpdater::onCheckingFinished (void) { void QSimpleUpdater::onCheckingFinished (void)
{
// Hide the progress dialog
m_progressDialog->hide();
// Get the application icon as a pixmap // Get the application icon as a pixmap
QPixmap _icon = qApp->windowIcon().pixmap( QPixmap _icon = qApp->windowIcon().pixmap (
qApp->windowIcon().actualSize(QSize(96, 96))); qApp->windowIcon().actualSize (QSize (96, 96)));
// If the icon is invalid, use default icon // If the icon is invalid, use default icon
if (_icon.isNull()) if (_icon.isNull())
_icon = QPixmap(":/icons/update.png"); _icon = QPixmap (":/icons/update.png");
QMessageBox _message; QMessageBox _message;
_message.setIconPixmap (_icon); _message.setIconPixmap (_icon);
// Ask user if he/she wants to download newer version // Ask user if he/she wants to download newer version
if (newerVersionAvailable() && m_show_update_available) { if (newerVersionAvailable() && m_show_update_available)
{
_message.setDetailedText (changeLog()); _message.setDetailedText (changeLog());
_message.setStandardButtons (QMessageBox::Yes | QMessageBox::No); _message.setStandardButtons (QMessageBox::Yes | QMessageBox::No);
_message.setText ("<b>" + tr ("A new version of %1 is available!").arg(qApp->applicationName()) + "</b>"); _message.setText ("<b>" + tr ("A new version of %1 is available!").arg (qApp->applicationName()) + "</b>");
_message.setInformativeText (tr("%1 %2 is available - you have %3. Would you like to download it now?") _message.setInformativeText (tr ("%1 %2 is available - you have %3. Would you like to download it now?")
.arg(qApp->applicationName()) .arg (qApp->applicationName())
.arg(latestVersion()) .arg (latestVersion())
.arg(installedVersion())); .arg (installedVersion()));
if (_message.exec() == QMessageBox::Yes) if (_message.exec() == QMessageBox::Yes)
downloadLatestVersion(); downloadLatestVersion();
} }
// Tell user that he/she is up to date (only if necessary) // Tell user that he/she is up to date (only if necessary)
else if (!silent() && m_show_newest_version && !m_latest_version.isEmpty()) { else if (!silent() && m_show_newest_version && !m_latest_version.isEmpty())
{
_message.setStandardButtons (QMessageBox::Ok); _message.setStandardButtons (QMessageBox::Ok);
_message.setText ("<b>" + tr ("You're up-to-date!") + _message.setText ("<b>" + tr ("You're up-to-date!") +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>"); "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>");
@ -391,34 +419,41 @@ void QSimpleUpdater::onCheckingFinished (void) {
* \sa checkForUpdates() * \sa checkForUpdates()
*/ */
void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply) { void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply)
{
bool _new_update = false; bool _new_update = false;
m_progressDialog->hide();
QString _reply = QString::fromUtf8 (reply->readAll()); QString _reply = QString::fromUtf8 (reply->readAll());
_reply.replace (" ", ""); _reply.replace (" ", "");
_reply.replace ("\n", ""); _reply.replace ("\n", "");
if (!_reply.isEmpty()) { if (!_reply.isEmpty())
{
m_latest_version = _reply; m_latest_version = _reply;
QStringList _download = m_latest_version.split ("."); QStringList _download = m_latest_version.split (".");
QStringList _installed = m_installed_version.split ("."); QStringList _installed = m_installed_version.split (".");
for (int i = 0; i <= _download.count() - 1; ++i) { for (int i = 0; i <= _download.count() - 1; ++i)
if (_download.count() - 1 >= i && _installed.count() - 1 >= i) { {
if (_download.at (i) > _installed.at (i)) { if (_download.count() - 1 >= i && _installed.count() - 1 >= i)
{
if (_download.at (i) > _installed.at (i))
{
_new_update = true; _new_update = true;
break; break;
} }
} }
else { else
if (_installed.count() < _download.count()) { {
if (_installed.count() < _download.count())
{
if (_installed.at (i - 1) == _download.at (i - 1)) if (_installed.at (i - 1) == _download.at (i - 1))
break; break;
else { else
{
_new_update = true; _new_update = true;
break; break;
} }
@ -432,7 +467,8 @@ void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply) {
m_new_version_available = _new_update; m_new_version_available = _new_update;
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 *)), this, connect (_manager, SIGNAL (finished (QNetworkReply *)), this,
@ -454,7 +490,8 @@ void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply) {
* \sa setChangelogUrl(), changeLog() * \sa setChangelogUrl(), changeLog()
*/ */
void QSimpleUpdater::processDownloadedChangelog (QNetworkReply *reply) { void QSimpleUpdater::processDownloadedChangelog (QNetworkReply *reply)
{
QString _reply = QString::fromUtf8 (reply->readAll()); QString _reply = QString::fromUtf8 (reply->readAll());
if (!_reply.isEmpty()) if (!_reply.isEmpty())
@ -470,7 +507,8 @@ void QSimpleUpdater::processDownloadedChangelog (QNetworkReply *reply) {
*/ */
void QSimpleUpdater::ignoreSslErrors (QNetworkReply *reply, void QSimpleUpdater::ignoreSslErrors (QNetworkReply *reply,
const QList<QSslError>& error) { const QList<QSslError>& error)
{
#if SUPPORTS_SSL #if SUPPORTS_SSL
reply->ignoreSslErrors (error); reply->ignoreSslErrors (error);
#else #else

View File

@ -37,7 +37,8 @@
#include "dialogs/download_dialog.h" #include "dialogs/download_dialog.h"
#include "dialogs/progress_dialog.h" #include "dialogs/progress_dialog.h"
class QSimpleUpdater : public QObject { class QSimpleUpdater : public QObject
{
Q_OBJECT Q_OBJECT
public: public:
@ -59,8 +60,8 @@ class QSimpleUpdater : public QObject {
void setDownloadUrl (const QString& url); void setDownloadUrl (const QString& url);
void setReferenceUrl (const QString& url); void setReferenceUrl (const QString& url);
void setChangelogUrl (const QString& url); void setChangelogUrl (const QString& url);
void setShowNewestVersionMessage(bool show); void setShowNewestVersionMessage (bool show);
void setShowUpdateAvailableMessage(bool show); void setShowUpdateAvailableMessage (bool show);
void setApplicationVersion (const QString& version); void setApplicationVersion (const QString& version);
signals: signals:

View File

@ -6,6 +6,10 @@ QSimpleUpdater is an implementation of an auto-updating system to be used with Q
QSimpleUpdater is **free and open source [LGPL software](https://www.gnu.org/licenses/lgpl.html)**, which means that you can use it for both open source and proprietary applications. QSimpleUpdater is **free and open source [LGPL software](https://www.gnu.org/licenses/lgpl.html)**, which means that you can use it for both open source and proprietary applications.
## Developer Documentation
You can find the developer documentation for QSimpleUpdater [here](http://qsimpleupdater.sourceforge.net/doc/).
## Using QSimpleUpdater ## Using QSimpleUpdater
1. Copy the *QSimpleUpdater* folder in your "3rd-party" folder. 1. Copy the *QSimpleUpdater* folder in your "3rd-party" folder.

21
bin/autostyle.cmd Normal file
View File

@ -0,0 +1,21 @@
:: Description: This script changes the style format of
:: all the source code of the project.
:: Setup the command line
@echo off
title Autostyle
:: Go to the directory where the script is run
cd /d %~dp0
:: Style and format the source code recursively
astyle --style=allman -C -S -xG -Y -XW -w -f -F -p -xd -k3 -y -xj -c -K -L --suffix=none --recursive ../*.cpp ../*.h ../*.hxx ../*.cxx
:: Notify the user that we have finished
echo.
echo Code styling complete!
echo.
:: Let the user see the output
pause

19
bin/autostyle.sh Normal file
View File

@ -0,0 +1,19 @@
#!/bin/bash
# Description: This script changes the style format of
# all the source code of the project.
# Run only on the directory of the script
cd "$(dirname ${BASH_SOURCE[0]})"
# Style and format recursively
astyle --style=allman -C -S -xG -Y -XW -w -f -F -p -xd -k3 -y -xj -c -K -L --suffix=none --recursive ../*.cpp ../*.h ../*.hxx ../*.cxx
# Notify the user that we are done
echo
echo "Code styling complete!"
echo
# Let the user see the output
read -n1 -r -p "Press any key to continue..." key
clear

1
bin/readme.txt Normal file
View File

@ -0,0 +1 @@
The scripts contained in this folder will require you to install the [astyle](http://astyle.sf.net) source code styler.