Bug fixes & new features

This commit is contained in:
Alex Spataru 2014-11-06 19:24:38 -06:00
parent 4ed4fe027f
commit 34c1e3eaa0
5 changed files with 52 additions and 40 deletions

View File

@ -15,6 +15,9 @@ int main (int argc, char *argv[]) {
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->setPlaceholderText("0.1");
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()));
@ -81,18 +84,28 @@ void Example::onCheckingFinished() {
// of the changelog text edit with the downloaded change log // of the changelog text edit with the downloaded change log
if (updater->newerVersionAvailable()) { if (updater->newerVersionAvailable()) {
ui->changelogTextEdit->setPlainText(updater->changeLog()); ui->changelogTextEdit->setPlainText(updater->changeLog());
QMessageBox::information(this, tr("Update available"),
tr("There's a newer version available! The latest version is ") + // Create and configure a message box
updater->latestVersion()); QMessageBox _messagebox;
updater->downloadLatestVersion(); _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, // 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 // so we inform the user and clear the text of the change log text edit
else { else {
ui->changelogTextEdit->setPlainText(""); ui->changelogTextEdit->setPlainText("");
//ui->changelogTextEdit->setPlaceholderText("The change log was not downloaded because you " ui->changelogTextEdit->setPlainText("The change log was not downloaded because you "
// "are running the latest version of the application..."); "are running the latest version of the application...");
QMessageBox::information(this, tr("No updates available"), QMessageBox::information(this, tr("No updates available"),
tr("Congratulations! You are running the latest version of the application!")); tr("Congratulations! You are running the latest version of the application!"));

View File

@ -38,6 +38,7 @@ void DownloadDialog::beginDownload(const QUrl &url)
{ {
// Reset the UI // Reset the UI
ui->progressBar->setValue(0); ui->progressBar->setValue(0);
ui->cancelButton->setText("Cancel");
ui->installButton->setEnabled(false); ui->installButton->setEnabled(false);
ui->downloadLabel->setText(tr("Downloading update...")); ui->downloadLabel->setText(tr("Downloading update..."));
@ -87,6 +88,7 @@ void DownloadDialog::cancelDownload()
void DownloadDialog::downloadFinished() void DownloadDialog::downloadFinished()
{ {
// Setup the UI // Setup the UI
ui->cancelButton->setText("Close");
ui->installButton->setEnabled(true); ui->installButton->setEnabled(true);
// Write the file // Write the file

View File

@ -2,6 +2,7 @@
#define DOWNLOAD_DIALOG_H #define DOWNLOAD_DIALOG_H
#include <QDir> #include <QDir>
#include <QDebug>
#include <QWidget> #include <QWidget>
#include <QNetworkReply> #include <QNetworkReply>
#include <QDesktopServices> #include <QDesktopServices>

View File

@ -21,8 +21,8 @@ QSimpleUpdater::QSimpleUpdater(QObject *parent)
// Return the contents of the downloaded changelog // Return the contents of the downloaded changelog
QString QSimpleUpdater::changeLog() const { QString QSimpleUpdater::changeLog() const {
if (m_changelog.isEmpty()) { if (m_changelog.isEmpty()) {
qWarning() << "QSimpleUpdater: change log is empty," qDebug() << "QSimpleUpdater: change log is empty,"
<< "did you call setChangelogUrl() and checkForUpdates()?"; << "did you call setChangelogUrl() and checkForUpdates()?";
} }
return m_changelog; return m_changelog;
} }
@ -50,11 +50,10 @@ void QSimpleUpdater::checkForUpdates() {
// Issue a warning message in the case that the reference URL is empty... // Issue a warning message in the case that the reference URL is empty...
else { else {
qWarning() << "QSimpleUpdater: Invalid reference URL"; qDebug() << "QSimpleUpdater: Invalid reference URL";
} }
} }
<<<<<<< HEAD
void QSimpleUpdater::openDownloadLink() { void QSimpleUpdater::openDownloadLink() {
// Open the download URL in a web browser // Open the download URL in a web browser
if (!m_download_url.isEmpty()) { if (!m_download_url.isEmpty()) {
@ -63,38 +62,28 @@ void QSimpleUpdater::openDownloadLink() {
// The m_download_url is empty, so we issue another warning message // The m_download_url is empty, so we issue another warning message
else { else {
qWarning() << "QSimpleUpdater: cannot download latest version," qDebug() << "QSimpleUpdater: cannot download latest version,"
<< "did you call setDownloadUrl() and checkForUpdates()?"; << "did you call setDownloadUrl() and checkForUpdates()?";
======= // Return the application version referenced by the string
// that we downloaded
}
}
// Return the application version referenced by the string // Return the application version referenced by the string
// that we downloaded // that we downloaded
QString QSimpleUpdater::latestVersion() const { QString QSimpleUpdater::latestVersion() const {
if (m_latest_version.isEmpty()) { if (m_latest_version.isEmpty()) {
qWarning() << "QSimpleUpdater: latest version is empty," qDebug() << "QSimpleUpdater: latest version is empty,"
<< "did you call checkForUpdates() and setReferenceUrl()?"; << "did you call checkForUpdates() and setReferenceUrl()?";
>>>>>>> FETCH_HEAD
} }
return m_latest_version; return m_latest_version;
} }
<<<<<<< HEAD
// Return the application version referenced by the string
// that we downloaded
QString QSimpleUpdater::latestVersion() const {
if (m_latest_version.isEmpty()) {
qWarning() << "QSimpleUpdater: latest version is empty,"
<< "did you call checkForUpdates() and setReferenceUrl()?";
}
return m_latest_version;
}
=======
>>>>>>> FETCH_HEAD
// Return the string issued by the user in the setApplicationVersion() function // Return the string issued by the user in the setApplicationVersion() function
QString QSimpleUpdater::installedVersion() const { QString QSimpleUpdater::installedVersion() const {
if (m_installed_version.isEmpty()) { if (m_installed_version.isEmpty()) {
qWarning() << "QSimpleUpdater: installed version is empty," qDebug() << "QSimpleUpdater: installed version is empty,"
<< "did you call setApplicationVersion()?"; << "did you call setApplicationVersion()?";
} }
return m_installed_version; return m_installed_version;
@ -108,8 +97,8 @@ void QSimpleUpdater::downloadLatestVersion() {
// The m_download_url is empty, so we issue another warning message // The m_download_url is empty, so we issue another warning message
else { else {
qWarning() << "QSimpleUpdater: cannot download latest version," qDebug() << "QSimpleUpdater: cannot download latest version,"
<< "did you call setDownloadUrl() and checkForUpdates()?"; << "did you call setDownloadUrl() and checkForUpdates()?";
} }
} }
@ -124,7 +113,7 @@ void QSimpleUpdater::setDownloadUrl(const QString &url) {
if (!url.isEmpty()) { if (!url.isEmpty()) {
m_download_url.setUrl(url); m_download_url.setUrl(url);
} else { } else {
qWarning() << "QSimpleUpdater: input URL cannot be empty!"; qDebug() << "QSimpleUpdater: input URL cannot be empty!";
} }
} }
@ -135,7 +124,7 @@ void QSimpleUpdater::setReferenceUrl(const QString &url) {
if (!url.isEmpty()) { if (!url.isEmpty()) {
m_reference_url.setUrl(url); m_reference_url.setUrl(url);
} else { } else {
qWarning() << "QSimpleUpdater: input URL cannot be empty!"; qDebug() << "QSimpleUpdater: input URL cannot be empty!";
} }
} }
@ -146,7 +135,7 @@ void QSimpleUpdater::setChangelogUrl(const QString &url) {
if (!url.isEmpty()) { if (!url.isEmpty()) {
m_changelog_url.setUrl(url); m_changelog_url.setUrl(url);
} else { } else {
qWarning() << "QSimpleUpdater: input URL cannot be empty!"; qDebug() << "QSimpleUpdater: input URL cannot be empty!";
} }
} }
@ -157,7 +146,7 @@ void QSimpleUpdater::setApplicationVersion(const QString &version) {
if (!version.isEmpty()) { if (!version.isEmpty()) {
m_installed_version = version; m_installed_version = version;
} else { } else {
qWarning() << "QSimpleUpdater: input string cannot be empty!"; qDebug() << "QSimpleUpdater: input string cannot be empty!";
} }
} }
@ -212,8 +201,14 @@ void QSimpleUpdater::checkDownloadedVersion(QNetworkReply *reply) {
// the "3" in both the downloaded and the installed version. // the "3" in both the downloaded and the installed version.
else { else {
if (_installed.count() < _download.count()) { if (_installed.count() < _download.count()) {
_new_update = true;
break; if (_installed.at (i - 1) == _download.at (i - 1))
break;
else {
_new_update = true;
break;
}
} }
} }
} }
@ -262,7 +257,7 @@ void QSimpleUpdater::processDownloadedChangelog(QNetworkReply *reply) {
// Issue a warning in the case that the changelog is empty // Issue a warning in the case that the changelog is empty
else { else {
qWarning() << "QSimpleUpdater: downloaded change log is empty!"; qDebug() << "QSimpleUpdater: downloaded change log is empty!";
} }
// Tell our parent that we are done checking for updates // Tell our parent that we are done checking for updates

View File

@ -3,6 +3,7 @@
#include <QSsl> #include <QSsl>
#include <QUrl> #include <QUrl>
#include <QDebug>
#include <QString> #include <QString>
#include <QSslError> #include <QSslError>
#include <QByteArray> #include <QByteArray>