A lot of changes
- Added qDoc support - Implemented a progress dialog while checking for updates - Automatically show a message box when an update is found or when you have the latest version
This commit is contained in:
parent
de00c961e5
commit
db79a3071d
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
int main (int argc, char *argv[]) {
|
int main (int argc, char *argv[]) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
app.setApplicationName("QSimpleUpdater Example");
|
||||||
|
|
||||||
// Create the dialog and show it
|
// Create the dialog and show it
|
||||||
Example example;
|
Example example;
|
||||||
@ -69,6 +70,10 @@ void Example::checkForUpdates() {
|
|||||||
// 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
|
||||||
|
updater->setSilent(false);
|
||||||
|
updater->setShowNewestVersionMessage(true);
|
||||||
|
|
||||||
// Finally, check for updates...
|
// Finally, check for updates...
|
||||||
updater->checkForUpdates();
|
updater->checkForUpdates();
|
||||||
}
|
}
|
||||||
@ -78,36 +83,4 @@ void Example::onCheckingFinished() {
|
|||||||
// 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");
|
||||||
|
|
||||||
// There's a newer version of the application available, so we inform
|
|
||||||
// the user that there's a newer version available and we replace the text
|
|
||||||
// of the changelog text edit with the downloaded change log
|
|
||||||
if (updater->newerVersionAvailable()) {
|
|
||||||
ui->changelogTextEdit->setPlainText(updater->changeLog());
|
|
||||||
|
|
||||||
// Create and configure a message box
|
|
||||||
QMessageBox _messagebox;
|
|
||||||
_messagebox.setIcon(QMessageBox::Information);
|
|
||||||
_messagebox.setWindowTitle(tr("Update available"));
|
|
||||||
_messagebox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
||||||
_messagebox.setText(tr("There's an update available!"));
|
|
||||||
_messagebox.setInformativeText(tr("The latest version of the application is") + " " +
|
|
||||||
updater->latestVersion() + ", " +
|
|
||||||
tr("do you want to download it?"));
|
|
||||||
|
|
||||||
// If the user clicks "yes" open the download dialog
|
|
||||||
if (_messagebox.exec() == QMessageBox::Yes)
|
|
||||||
updater->downloadLatestVersion();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The installed version is equal or greater to the "official" latest version,
|
|
||||||
// so we inform the user and clear the text of the change log text edit
|
|
||||||
else {
|
|
||||||
ui->changelogTextEdit->setPlainText("");
|
|
||||||
ui->changelogTextEdit->setPlainText("The change log was not downloaded because you "
|
|
||||||
"are running the latest version of the application...");
|
|
||||||
|
|
||||||
QMessageBox::information(this, tr("No updates available"),
|
|
||||||
tr("Congratulations! You are running the latest version of the application!"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
14
QSimpleUpdater/doc/QSimpleUpdater.qdocconf
Normal file
14
QSimpleUpdater/doc/QSimpleUpdater.qdocconf
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Project info
|
||||||
|
project = QSimpleUpdater
|
||||||
|
url = http://qsimpleupdater.sf.net/doc
|
||||||
|
description = A simple auto-updating system for Qt projects
|
||||||
|
|
||||||
|
# Import sources and headers
|
||||||
|
headerdirs = ../src
|
||||||
|
sourcedirs = ../src
|
||||||
|
sources.fileextensions = "*.cpp *.qdoc *.mm *.qml"
|
||||||
|
headers.fileextensions = "*.h *.ch *.h++ *.hh *.hpp *.hxx"
|
||||||
|
|
||||||
|
# Output as HTML
|
||||||
|
outputdir = doc-html
|
||||||
|
outputformats = HTML
|
@ -11,10 +11,12 @@ QT += widgets
|
|||||||
QT += network
|
QT += network
|
||||||
|
|
||||||
HEADERS += $$PWD/src/qsimpleupdater.h \
|
HEADERS += $$PWD/src/qsimpleupdater.h \
|
||||||
$$PWD/src/dialogs/download_dialog.h
|
$$PWD/src/dialogs/download_dialog.h \
|
||||||
|
$$PWD/src/dialogs/progress_dialog.h
|
||||||
|
|
||||||
SOURCES += $$PWD/src/qsimpleupdater.cpp \
|
SOURCES += $$PWD/src/qsimpleupdater.cpp \
|
||||||
$$PWD/src/dialogs/download_dialog.cpp
|
$$PWD/src/dialogs/download_dialog.cpp \
|
||||||
|
$$PWD/src/dialogs/progress_dialog.cpp
|
||||||
|
|
||||||
OTHER_FILES += $$PWD/src/QSimpleUpdater
|
OTHER_FILES += $$PWD/src/QSimpleUpdater
|
||||||
|
|
||||||
@ -30,4 +32,5 @@ win32* {
|
|||||||
|
|
||||||
RESOURCES += $$PWD/res/qsu_resources.qrc
|
RESOURCES += $$PWD/res/qsu_resources.qrc
|
||||||
|
|
||||||
FORMS += $$PWD/src/dialogs/download_dialog.ui
|
FORMS += $$PWD/src/dialogs/download_dialog.ui \
|
||||||
|
$$PWD/src/dialogs/progress_dialog.ui
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
--------------
|
|
||||||
PREFACE
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Many websites today use the HTTPS protocol, which means that you will need SSL in order to communicate with them. If your project needs to access such a webiste (for example GitHub), you will need to carefully read the following information in order to ensure that QSimpleUpdater works with those websites (both in your machine and in the final users' machine).
|
|
||||||
|
|
||||||
This readme guide is extremely important for any developer wishing to deploy his or her applications under the Windows platform, because the application will depend on the libraries provided by QSimpleUpdater.
|
|
||||||
|
|
||||||
--------------
|
|
||||||
LINUX
|
|
||||||
--------------
|
|
||||||
|
|
||||||
Make sure that you have installed the following libraries in your system:
|
|
||||||
|
|
||||||
- lssl
|
|
||||||
- lcrypto
|
|
||||||
|
|
||||||
--------------
|
|
||||||
MAC OSX
|
|
||||||
--------------
|
|
||||||
|
|
||||||
The libraries required by QSimpleUpdater are the same as Linux, however, these libraries are installed by default in most Mac OS X installations.
|
|
||||||
|
|
||||||
--------------
|
|
||||||
WINDOWS
|
|
||||||
--------------
|
|
||||||
|
|
||||||
QSimpleUpdater makes use of the OpenSSL-Win32 project, make sure that have it installed and that the project knows where to find them (the default location is C:/OpenSSL-Win32) and that you deploy the following libraries with your compiled project:
|
|
||||||
|
|
||||||
- libeay32.dll
|
|
||||||
- ssleay32.dll
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
@ -6,8 +6,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>490</width>
|
<width>464</width>
|
||||||
<height>199</height>
|
<height>164</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
@ -17,7 +17,7 @@
|
|||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Updater</string>
|
<string>Software Updater</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="spacing">
|
<property name="spacing">
|
||||||
|
41
QSimpleUpdater/src/dialogs/progress_dialog.cpp
Normal file
41
QSimpleUpdater/src/dialogs/progress_dialog.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* (C) Copyright 2014 Alex Spataru
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the GNU Lesser General Public License
|
||||||
|
* (LGPL) version 2.1 which accompanies this distribution, and is available at
|
||||||
|
* http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "progress_dialog.h"
|
||||||
|
#include "ui_progress_dialog.h"
|
||||||
|
|
||||||
|
ProgressDialog::ProgressDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ProgressDialog)
|
||||||
|
{
|
||||||
|
// Create and configure UI
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
// Make the window look like a dialog
|
||||||
|
QIcon _blank;
|
||||||
|
setWindowIcon (_blank);
|
||||||
|
setWindowModality (Qt::WindowModal);
|
||||||
|
setWindowFlags (Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
|
||||||
|
|
||||||
|
// Close dialog when cancel button is clicked
|
||||||
|
connect(ui->ui_cancel_button, SIGNAL(clicked()), this, SLOT(cancel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ProgressDialog::~ProgressDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ProgressDialog::cancel(void) {
|
||||||
|
hide();
|
||||||
|
emit cancelClicked();
|
||||||
|
}
|
42
QSimpleUpdater/src/dialogs/progress_dialog.h
Normal file
42
QSimpleUpdater/src/dialogs/progress_dialog.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* (C) Copyright 2014 Alex Spataru
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the GNU Lesser General Public License
|
||||||
|
* (LGPL) version 2.1 which accompanies this distribution, and is available at
|
||||||
|
* http://www.gnu.org/licenses/lgpl-2.1.html
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PROGRESS_DIALOG_H
|
||||||
|
#define PROGRESS_DIALOG_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ProgressDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProgressDialog : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ProgressDialog(QWidget *parent = 0);
|
||||||
|
~ProgressDialog();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void cancelClicked();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void cancel (void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::ProgressDialog *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PROGRESS_DIALOG_H
|
121
QSimpleUpdater/src/dialogs/progress_dialog.ui
Normal file
121
QSimpleUpdater/src/dialogs/progress_dialog.ui
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ProgressDialog</class>
|
||||||
|
<widget class="QDialog" name="ProgressDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>410</width>
|
||||||
|
<height>152</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Software Updater</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<property name="sizeConstraint">
|
||||||
|
<enum>QLayout::SetMinimumSize</enum>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="ui_icon">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="pixmap">
|
||||||
|
<pixmap resource="../../res/qsu_resources.qrc">:/icons/update.png</pixmap>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="ui_progress_bar">
|
||||||
|
<property name="text">
|
||||||
|
<string>Checking for updates...</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QProgressBar" name="progressBar">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>250</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>-1</number>
|
||||||
|
</property>
|
||||||
|
<property name="invertedAppearance">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="button_widget" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="ui_cancel_button">
|
||||||
|
<property name="text">
|
||||||
|
<string>Cancel</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="../../res/qsu_resources.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -12,13 +12,85 @@
|
|||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*! \class QSimpleUpdater
|
||||||
|
* \brief A simple auto-updater system for Qt
|
||||||
|
*
|
||||||
|
* QSimpleUpdater is an implementation of an auto-updating system to be used with Qt projects.
|
||||||
|
* Aside from notifying you if there's a newer version, it allows you to download the change log in any
|
||||||
|
* format (such as HTML or RTF) and download the updates directly from your application using a dialog.
|
||||||
|
* QSimpleUpdater is free and open source LGPL software,
|
||||||
|
* which means that you can use it for both open source and proprietary applications.
|
||||||
|
*
|
||||||
|
* \chapter Installation
|
||||||
|
*
|
||||||
|
* \list
|
||||||
|
* \o Copy the QSimpleUpdater folder in your "3rd-party" folder.
|
||||||
|
* \o Include the QSimpleUpdater project include (pri) file using the include() function.
|
||||||
|
* \o That's all! Check the example project as a reference for your project.
|
||||||
|
* \endlist
|
||||||
|
*
|
||||||
|
* \chapter Running the example project
|
||||||
|
*
|
||||||
|
* \list
|
||||||
|
* \o Navigate to the Example folder and open example.pro with Qt Creator.
|
||||||
|
* \o Compile the project and play with it :)
|
||||||
|
* \endlist
|
||||||
|
*
|
||||||
|
* \chapter Warnings
|
||||||
|
* Many websites today use the HTTP Secure protocol, which means that you will need SSL
|
||||||
|
* in order to communicate with them.
|
||||||
|
* If your project needs to access such a webiste (for example GitHub),
|
||||||
|
* you will need to carefully read the following information in order to ensure that
|
||||||
|
* QSimpleUpdater works with those websites (both in your machine and in the final users' machine).
|
||||||
|
*
|
||||||
|
* This section is extremely important for any developers wishing to deploy their applications under
|
||||||
|
* the Windows platform, because the application will depend on the OpenSSL libaries in order to work.
|
||||||
|
*
|
||||||
|
* \bold {Linux}
|
||||||
|
*
|
||||||
|
* Make sure that you have installed the following libraries in your system:
|
||||||
|
*
|
||||||
|
* \list
|
||||||
|
* \o lssl
|
||||||
|
* \o lcrypto
|
||||||
|
* \endlist
|
||||||
|
*
|
||||||
|
* \bold {Mac OS X}
|
||||||
|
*
|
||||||
|
* The libraries required by QSimpleUpdater are the same as Linux, however, these libraries
|
||||||
|
* are installed by default in most Mac OS X installations.
|
||||||
|
*
|
||||||
|
* \bold {Microsoft Windows}
|
||||||
|
*
|
||||||
|
* QSimpleUpdater makes use of the OpenSSL-Win32 project, make sure that have it installed
|
||||||
|
* and that the project knows where to find them (the default location is C:/OpenSSL-Win32).
|
||||||
|
* Finally, deploy the following libraries with your compiled project:
|
||||||
|
*
|
||||||
|
* \list
|
||||||
|
* \o libeay32.dll
|
||||||
|
* \o ssleay32.dll
|
||||||
|
* \endlist
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \fn QSimpleUpdater::checkingFinished (void)
|
||||||
|
* This signal is triggered when the updater system finishes downloading
|
||||||
|
* and proccessing the version data and changelog data.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "qsimpleupdater.h"
|
#include "qsimpleupdater.h"
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
* Initializes and configures the class.
|
||||||
|
*/
|
||||||
|
|
||||||
QSimpleUpdater::QSimpleUpdater (QObject *parent)
|
QSimpleUpdater::QSimpleUpdater (QObject *parent)
|
||||||
: QObject (parent)
|
: QObject (parent)
|
||||||
, m_changelog_downloaded (false)
|
, m_silent (false)
|
||||||
, m_version_check_finished (false)
|
, m_show_newest_version (true)
|
||||||
|
, m_show_update_available (true)
|
||||||
, m_new_version_available (false) {
|
, m_new_version_available (false) {
|
||||||
|
|
||||||
|
m_progressDialog = new ProgressDialog();
|
||||||
m_downloadDialog = new DownloadDialog();
|
m_downloadDialog = new DownloadDialog();
|
||||||
|
|
||||||
m_manager = new QNetworkAccessManager (this);
|
m_manager = new QNetworkAccessManager (this);
|
||||||
@ -26,70 +98,308 @@ QSimpleUpdater::QSimpleUpdater (QObject *parent)
|
|||||||
SLOT (checkDownloadedVersion (QNetworkReply *)));
|
SLOT (checkDownloadedVersion (QNetworkReply *)));
|
||||||
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 (this, SIGNAL (checkingFinished()), this, SLOT (onCheckingFinished()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Returns the downloaded change log as a \c QString.
|
||||||
|
*
|
||||||
|
* \sa setChangelogUrl()
|
||||||
|
*/
|
||||||
|
|
||||||
QString QSimpleUpdater::changeLog() const {
|
QString QSimpleUpdater::changeLog() const {
|
||||||
return m_changelog;
|
return m_changelog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Checks for updates and calls the appropiate functions
|
||||||
|
* when finished.
|
||||||
|
*
|
||||||
|
* \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())
|
||||||
|
m_progressDialog->show();
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
qDebug() << "QSimpleUpdater: Invalid reference URL";
|
qDebug() << "QSimpleUpdater: Invalid reference URL";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Opens the download link in a web browser.
|
||||||
|
*
|
||||||
|
* \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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Returns the latest version as a \c QString.
|
||||||
|
*
|
||||||
|
* \sa setReferenceUrl(), checkForUpdates()
|
||||||
|
*/
|
||||||
|
|
||||||
QString QSimpleUpdater::latestVersion() const {
|
QString QSimpleUpdater::latestVersion() const {
|
||||||
return m_latest_version;
|
return m_latest_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Returns the local version of the application.
|
||||||
|
*
|
||||||
|
* \sa setApplicationVersion()
|
||||||
|
*/
|
||||||
|
|
||||||
QString QSimpleUpdater::installedVersion() const {
|
QString QSimpleUpdater::installedVersion() const {
|
||||||
return m_installed_version;
|
return m_installed_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Downloads the latest version of the application
|
||||||
|
* and displays download info in a dialog.
|
||||||
|
*
|
||||||
|
* \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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Returns \c true if the system detected that there is
|
||||||
|
* a newer version of the application available online.
|
||||||
|
*
|
||||||
|
* \sa setReferenceUrl(), checkForUpdates()
|
||||||
|
*/
|
||||||
|
|
||||||
bool QSimpleUpdater::newerVersionAvailable() const {
|
bool QSimpleUpdater::newerVersionAvailable() const {
|
||||||
return m_new_version_available;
|
return m_new_version_available;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Returns \c true if the system is set to
|
||||||
|
* hide the progress dialog.
|
||||||
|
*
|
||||||
|
* \sa setSilent()
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool QSimpleUpdater::silent() const {
|
||||||
|
return m_silent;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Tells the system from where to download the update packages
|
||||||
|
* with the \a url parameter.
|
||||||
|
*
|
||||||
|
* Its recommended to use fixed URLs if you
|
||||||
|
* want to automatically download and install your updates using
|
||||||
|
* the bundled download dialog.
|
||||||
|
*
|
||||||
|
* \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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Tells the updater system from where to download the file
|
||||||
|
* that indicates the latest version using the \a url parameter.
|
||||||
|
*
|
||||||
|
* The reference file should contain \bold {ONLY} the latest version
|
||||||
|
* in a plain text format. For example:
|
||||||
|
*
|
||||||
|
* \list
|
||||||
|
* \o 1
|
||||||
|
* \o 0.1
|
||||||
|
* \o 1.0.1
|
||||||
|
* \o 2.2.12
|
||||||
|
* \o etc
|
||||||
|
* \endlist
|
||||||
|
*
|
||||||
|
* \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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Tells the updater system from where to download the
|
||||||
|
* change log using the \a url parameter.
|
||||||
|
* The change log can be any file you like, however,
|
||||||
|
* its recommended to write it in plain text,
|
||||||
|
* such as TXT, HTML and RTF files.
|
||||||
|
*
|
||||||
|
* \sa changeLog()
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Tells the updater the version of the installed
|
||||||
|
* copy of your application using the \a version parameter.
|
||||||
|
*
|
||||||
|
* Calling this function is optional, as the default
|
||||||
|
* values are loaded from QApplication class.
|
||||||
|
*
|
||||||
|
* \sa installedVersion(), checkForUpdates()
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
*
|
||||||
|
* \list
|
||||||
|
* \o If \a silent is set to \c true, no dialogs will be shown while checking
|
||||||
|
* for updates or when a newer version of the application is found.
|
||||||
|
* \o If \a silent is set to \c false, a dialog will be shown while checking for
|
||||||
|
* updates or when a newer version of the application is found.
|
||||||
|
* \endlist
|
||||||
|
*
|
||||||
|
* \sa silent()
|
||||||
|
*/
|
||||||
|
|
||||||
|
void QSimpleUpdater::setSilent (bool silent) {
|
||||||
|
m_silent = silent;
|
||||||
|
|
||||||
|
if (m_silent)
|
||||||
|
setShowNewestVersionMessage(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* If the \a show parameter is set to \c true, the updater system will show a
|
||||||
|
* message box notifying the user when there's an update available.
|
||||||
|
*
|
||||||
|
* \sa checkForUpdates()
|
||||||
|
*/
|
||||||
|
|
||||||
|
void QSimpleUpdater::setShowUpdateAvailableMessage(bool show) {
|
||||||
|
m_show_update_available = show;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* If the \a show parameter is set to \c true, the updater system will show a
|
||||||
|
* message box notifying the user when the latest version is already installed.
|
||||||
|
*
|
||||||
|
* For example, this configuration is useful when the user manually calls this function.
|
||||||
|
* \i {Eg:} when he or she clicks the "Check for updates" menu item.
|
||||||
|
*
|
||||||
|
* \sa checkForUpdates()
|
||||||
|
*/
|
||||||
|
|
||||||
|
void QSimpleUpdater::setShowNewestVersionMessage(bool show) {
|
||||||
|
m_show_newest_version = show;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
* Disconnects the network access manager when the user
|
||||||
|
* clicks on the "cancel" button in the progress dialog.
|
||||||
|
*/
|
||||||
|
|
||||||
|
void QSimpleUpdater::cancel(void) {
|
||||||
|
m_manager->disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
* Alerts the user when the download of version information
|
||||||
|
* data is corrupted.
|
||||||
|
*
|
||||||
|
* \sa checkDownloadedVersion()
|
||||||
|
*/
|
||||||
|
|
||||||
|
void QSimpleUpdater::showErrorMessage (void) {
|
||||||
|
if (!silent())
|
||||||
|
QMessageBox::warning(NULL, tr("Software Updater"),
|
||||||
|
tr("An unknown error occured while checking for updates"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
* Informs the user if there's a newer version available for download
|
||||||
|
* or if he or she is running the latest version of the application.
|
||||||
|
*
|
||||||
|
* \sa checkDownloadedVersion()
|
||||||
|
*/
|
||||||
|
|
||||||
|
void QSimpleUpdater::onCheckingFinished (void) {
|
||||||
|
// Get the application icon as a pixmap
|
||||||
|
QPixmap _icon = qApp->windowIcon().pixmap(
|
||||||
|
qApp->windowIcon().actualSize(QSize(96, 96)));
|
||||||
|
|
||||||
|
// If the icon is invalid, use default icon
|
||||||
|
if (_icon.isNull())
|
||||||
|
_icon = QPixmap(":/icons/update.png");
|
||||||
|
|
||||||
|
QMessageBox _message;
|
||||||
|
_message.setIconPixmap (_icon);
|
||||||
|
|
||||||
|
// Ask user if he/she wants to download newer version
|
||||||
|
if (newerVersionAvailable() && m_show_update_available) {
|
||||||
|
_message.setDetailedText (changeLog());
|
||||||
|
_message.setStandardButtons (QMessageBox::Yes | QMessageBox::No);
|
||||||
|
_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?")
|
||||||
|
.arg(qApp->applicationName())
|
||||||
|
.arg(latestVersion())
|
||||||
|
.arg(installedVersion()));
|
||||||
|
|
||||||
|
if (_message.exec() == QMessageBox::Yes)
|
||||||
|
downloadLatestVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tell user that he/she is up to date (only if necessary)
|
||||||
|
else if (!silent() && m_show_newest_version && !m_latest_version.isEmpty()) {
|
||||||
|
_message.setStandardButtons (QMessageBox::Ok);
|
||||||
|
_message.setText ("<b>" + tr ("You're up-to-date!") +
|
||||||
|
" </b>");
|
||||||
|
_message.setInformativeText (
|
||||||
|
tr ("%1 %2 is currently the newest version available")
|
||||||
|
.arg (qApp->applicationName())
|
||||||
|
.arg (installedVersion()));
|
||||||
|
|
||||||
|
_message.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
* Compares downloaded version information with local version information
|
||||||
|
* and decides if there's a newer version available.
|
||||||
|
*
|
||||||
|
* Finally, the function downloads the changelog if there's a newer version
|
||||||
|
* available online.
|
||||||
|
*
|
||||||
|
* \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() && _reply.contains (".")) {
|
if (!_reply.isEmpty()) {
|
||||||
m_latest_version = _reply;
|
m_latest_version = _reply;
|
||||||
|
|
||||||
QStringList _download = m_latest_version.split (".");
|
QStringList _download = m_latest_version.split (".");
|
||||||
@ -118,7 +428,9 @@ void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_new_version_available = _new_update;
|
m_new_version_available = _new_update;
|
||||||
emit versionCheckFinished();
|
|
||||||
|
else
|
||||||
|
showErrorMessage();
|
||||||
|
|
||||||
if (!m_changelog_url.isEmpty() && newerVersionAvailable()) {
|
if (!m_changelog_url.isEmpty() && newerVersionAvailable()) {
|
||||||
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
QNetworkAccessManager *_manager = new QNetworkAccessManager (this);
|
||||||
@ -136,17 +448,27 @@ void QSimpleUpdater::checkDownloadedVersion (QNetworkReply *reply) {
|
|||||||
emit checkingFinished();
|
emit checkingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
* Reads the downloaded changelog data and transforms it into a QString.
|
||||||
|
*
|
||||||
|
* \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())
|
||||||
m_changelog = _reply;
|
m_changelog = _reply;
|
||||||
emit changelogDownloadFinished();
|
|
||||||
}
|
|
||||||
|
|
||||||
emit checkingFinished();
|
emit checkingFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! \internal
|
||||||
|
* Allows the download process to continue even if there are SSL errors.
|
||||||
|
*
|
||||||
|
* \sa checkForUpdates()
|
||||||
|
*/
|
||||||
|
|
||||||
void QSimpleUpdater::ignoreSslErrors (QNetworkReply *reply,
|
void QSimpleUpdater::ignoreSslErrors (QNetworkReply *reply,
|
||||||
const QList<QSslError>& error) {
|
const QList<QSslError>& error) {
|
||||||
#if SUPPORTS_SSL
|
#if SUPPORTS_SSL
|
||||||
|
@ -19,6 +19,10 @@
|
|||||||
#define SUPPORTS_SSL !defined(Q_OS_IOS)
|
#define SUPPORTS_SSL !defined(Q_OS_IOS)
|
||||||
|
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QApplication>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
@ -31,6 +35,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "dialogs/download_dialog.h"
|
#include "dialogs/download_dialog.h"
|
||||||
|
#include "dialogs/progress_dialog.h"
|
||||||
|
|
||||||
class QSimpleUpdater : public QObject {
|
class QSimpleUpdater : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -38,66 +43,36 @@ class QSimpleUpdater : public QObject {
|
|||||||
public:
|
public:
|
||||||
QSimpleUpdater (QObject *parent = 0);
|
QSimpleUpdater (QObject *parent = 0);
|
||||||
|
|
||||||
/// Returns the downloaded change log
|
|
||||||
QString changeLog() const;
|
QString changeLog() const;
|
||||||
|
|
||||||
/// Returns the downloaded version string
|
|
||||||
QString latestVersion() const;
|
QString latestVersion() const;
|
||||||
|
|
||||||
/// Returns the local version, referenced by
|
|
||||||
/// the setApplicationVersion() function
|
|
||||||
QString installedVersion() const;
|
QString installedVersion() const;
|
||||||
|
|
||||||
/// Returns \c true if there's a newer version available
|
bool silent() const;
|
||||||
bool newerVersionAvailable() const;
|
bool newerVersionAvailable() const;
|
||||||
|
|
||||||
/// Checks for updates and calls the appropriate
|
|
||||||
/// signals when finished
|
|
||||||
void checkForUpdates (void);
|
void checkForUpdates (void);
|
||||||
|
|
||||||
/// Opens the download URL in a a web browser.
|
|
||||||
/// The URL is referenced by the \c setDownloadUrl() function
|
|
||||||
void openDownloadLink (void);
|
void openDownloadLink (void);
|
||||||
|
|
||||||
/// Shows a dialog that downloads the file in the
|
|
||||||
/// URL referenced by the \c setDownloadUrl() function
|
|
||||||
void downloadLatestVersion (void);
|
void downloadLatestVersion (void);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void setSilent (bool silent);
|
||||||
/// Changes the URL that we can open in a web browser or
|
|
||||||
/// download. Its recommended to use fixed URLs if you
|
|
||||||
/// want to automatically download and install your updates
|
|
||||||
void setDownloadUrl (const QString& url);
|
void setDownloadUrl (const QString& url);
|
||||||
|
|
||||||
/// Changes the reference URL, which contains ONLY the latest
|
|
||||||
/// version of your application as a plain text file.
|
|
||||||
/// Examples include:
|
|
||||||
/// - 1.2.3
|
|
||||||
/// - 5.4.0
|
|
||||||
/// - 0.1.2
|
|
||||||
/// - etc.
|
|
||||||
void setReferenceUrl (const QString& url);
|
void setReferenceUrl (const QString& url);
|
||||||
|
|
||||||
/// Changes the change log URL, which contains the change log
|
|
||||||
/// of your application. The change log can be any file you
|
|
||||||
/// like, however, its recommended to write it in plain text,
|
|
||||||
/// such as TXT, HTML and RTF files.
|
|
||||||
void setChangelogUrl (const QString& url);
|
void setChangelogUrl (const QString& url);
|
||||||
|
void setShowNewestVersionMessage(bool show);
|
||||||
/// Tells the updater the version of the installed
|
void setShowUpdateAvailableMessage(bool show);
|
||||||
/// copy of your application.
|
|
||||||
void setApplicationVersion (const QString& version);
|
void setApplicationVersion (const QString& version);
|
||||||
|
|
||||||
private slots:
|
|
||||||
void checkDownloadedVersion (QNetworkReply *reply);
|
|
||||||
void processDownloadedChangelog (QNetworkReply *reply);
|
|
||||||
void ignoreSslErrors (QNetworkReply *reply, const QList<QSslError>& error);
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void checkingFinished (void);
|
void checkingFinished (void);
|
||||||
void versionCheckFinished (void);
|
|
||||||
void changelogDownloadFinished (void);
|
private slots:
|
||||||
|
void cancel (void);
|
||||||
|
void showErrorMessage (void);
|
||||||
|
void onCheckingFinished (void);
|
||||||
|
void checkDownloadedVersion (QNetworkReply *reply);
|
||||||
|
void processDownloadedChangelog (QNetworkReply *reply);
|
||||||
|
void ignoreSslErrors (QNetworkReply *reply, const QList<QSslError>& error);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_changelog;
|
QString m_changelog;
|
||||||
@ -109,12 +84,13 @@ class QSimpleUpdater : public QObject {
|
|||||||
QUrl m_reference_url;
|
QUrl m_reference_url;
|
||||||
QUrl m_changelog_url;
|
QUrl m_changelog_url;
|
||||||
|
|
||||||
bool m_changelog_downloaded;
|
bool m_silent;
|
||||||
bool m_version_check_finished;
|
bool m_show_newest_version;
|
||||||
|
bool m_show_update_available;
|
||||||
bool m_new_version_available;
|
bool m_new_version_available;
|
||||||
|
|
||||||
DownloadDialog *m_downloadDialog;
|
DownloadDialog *m_downloadDialog;
|
||||||
|
ProgressDialog *m_progressDialog;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -19,7 +19,7 @@ QSimpleUpdater is **free and open source [LGPL software](https://www.gnu.org/lic
|
|||||||
|
|
||||||
## Warnings
|
## Warnings
|
||||||
|
|
||||||
Many websites today use the HTTPS protocol, which means that you will need SSL in order to communicate with them. If your project needs to access such a webiste (for example GitHub), you will need to carefully read the following information in order to ensure that QSimpleUpdater works with those websites (both in your machine and in the final users' machine).
|
Many websites today use the [HTTP Secure](http://en.wikipedia.org/wiki/HTTP_Secure) protocol, which means that you will need [SSL](https://www.globalsign.com/en/ssl-information-center/what-ssl/) in order to communicate with them. If your project needs to access such a webiste (for example GitHub), you will need to carefully read the following information in order to ensure that QSimpleUpdater works with those websites (both in your machine and in the final users' machine).
|
||||||
|
|
||||||
This section is extremely important for any developer wishing to deploy his or her applications under the Windows platform, because the application will depend on the libraries provided by QSimpleUpdater.
|
This section is extremely important for any developer wishing to deploy his or her applications under the Windows platform, because the application will depend on the libraries provided by QSimpleUpdater.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user