diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f699fa5d7..3bc4e4189 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -98,11 +98,7 @@ using namespace libtorrent; *****************************************************/ // Constructor -MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMainWindow(parent), m_posInitialized(false), force_exit(false) -#if defined(Q_WS_WIN) || defined(Q_WS_MAC) - ,checkingProgramUpdate(false) -#endif -{ +MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMainWindow(parent), m_posInitialized(false), force_exit(false) { setupUi(this); Preferences pref; @@ -216,7 +212,7 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa connect(actionMinimize, SIGNAL(triggered()), SLOT(minimizeWindow())); #if defined(Q_WS_WIN) || defined(Q_WS_MAC) - programUpdateTimer.setInterval(15*60*1000); + programUpdateTimer.setInterval(60*60*1000); programUpdateTimer.setSingleShot(true); connect(&programUpdateTimer, SIGNAL(timeout()), SLOT(checkProgramUpdate())); connect(actionCheck_for_updates, SIGNAL(triggered()), SLOT(checkProgramUpdate())); @@ -1349,35 +1345,31 @@ void MainWindow::on_actionDownload_from_URL_triggered() { #if defined(Q_WS_WIN) || defined(Q_WS_MAC) -void MainWindow::handleUpdateCheckFinished(bool update_available, QString new_version) +void MainWindow::handleUpdateCheckFinished(bool update_available, QString new_version, bool invokedByUser) { + QMessageBox::StandardButton answer = QMessageBox::Yes; if (update_available) { - if (QMessageBox::question(this, tr("A newer version is available"), - tr("A newer version of qBittorrent is available on Sourceforge.\nWould you like to update qBittorrent to version %1?").arg(new_version), - QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) { + answer = QMessageBox::question(this, tr("A new version is available"), + tr("A new version of qBittorrent is available on Sourceforge.\nWould you like to update qBittorrent to version %1?").arg(new_version), + QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); + if (answer == QMessageBox::Yes) { // The user want to update, let's download the update ProgramUpdater* updater = dynamic_cast(sender()); - connect(updater, SIGNAL(updateInstallFinished(QString)), SLOT(handleUpdateInstalled(QString))); updater->updateProgram(); - return; } } + else if (invokedByUser) { + QMessageBox::information(this, tr("There isn't a new version available"), + tr("There isn't a new version of qBittorrent available on Sourceforge")); + } sender()->deleteLater(); - checkingProgramUpdate = false; actionCheck_for_updates->setEnabled(true); actionCheck_for_updates->setText(tr("Check for updates")); actionCheck_for_updates->setToolTip(tr("Check for program updates")); - if (Preferences().isUpdateCheckEnabled()) + // Don't bother the user again in this session if he chose to ignore the update + if (Preferences().isUpdateCheckEnabled() && answer == QMessageBox::Yes) programUpdateTimer.start(); } - -void MainWindow::handleUpdateInstalled(QString error_msg) -{ - if (!error_msg.isEmpty()) { - QMessageBox::critical(this, tr("Impossible to update qBittorrent"), tr("qBittorrent failed to update, reason: %1").arg(error_msg)); - } -} - #endif void MainWindow::on_actionDonate_money_triggered() @@ -1462,14 +1454,13 @@ QIcon MainWindow::getSystrayIcon() const #if defined(Q_WS_WIN) || defined(Q_WS_MAC) void MainWindow::checkProgramUpdate() { - if (checkingProgramUpdate) - return; - checkingProgramUpdate = true; + programUpdateTimer.stop(); // If the user had clicked the menu item actionCheck_for_updates->setEnabled(false); actionCheck_for_updates->setText(tr("Checking for updates...")); actionCheck_for_updates->setToolTip(tr("Already checking for program updates in the background")); - ProgramUpdater *updater = new ProgramUpdater(this); - connect(updater, SIGNAL(updateCheckFinished(bool, QString)), SLOT(handleUpdateCheckFinished(bool, QString))); + bool invokedByUser = actionCheck_for_updates == qobject_cast(sender()); + ProgramUpdater *updater = new ProgramUpdater(this, invokedByUser); + connect(updater, SIGNAL(updateCheckFinished(bool, QString, bool)), SLOT(handleUpdateCheckFinished(bool, QString, bool))); updater->checkForUpdates(); } #endif diff --git a/src/mainwindow.h b/src/mainwindow.h index f811d98a8..abdc61486 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -140,8 +140,7 @@ protected slots: // HTTP slots void on_actionDownload_from_URL_triggered(); #if defined(Q_WS_WIN) || defined(Q_WS_MAC) - void handleUpdateCheckFinished(bool update_available, QString new_version); - void handleUpdateInstalled(QString error_msg); + void handleUpdateCheckFinished(bool update_available, QString new_version, bool invokedByUser); #endif protected: @@ -200,7 +199,6 @@ private: QTimer *preventTimer; #if defined(Q_WS_WIN) || defined(Q_WS_MAC) QTimer programUpdateTimer; - bool checkingProgramUpdate; #endif private slots: diff --git a/src/programupdater.cpp b/src/programupdater.cpp index ce3f59895..6739d7333 100644 --- a/src/programupdater.cpp +++ b/src/programupdater.cpp @@ -49,8 +49,8 @@ const QString FILE_EXT = "EXE"; using namespace libtorrent; -ProgramUpdater::ProgramUpdater(QObject *parent) : - QObject(parent) +ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser) : + QObject(parent), m_invokedByUser(invokedByUser) { mp_manager = new QNetworkAccessManager(this); Preferences pref; @@ -140,7 +140,7 @@ void ProgramUpdater::rssDownloadFinished(QNetworkReply *reply) } } } - emit updateCheckFinished(!m_updateUrl.isEmpty(), new_version); + emit updateCheckFinished(!m_updateUrl.isEmpty(), new_version, m_invokedByUser); // Clean up reply->deleteLater(); } @@ -150,50 +150,8 @@ void ProgramUpdater::updateProgram() Q_ASSERT(!m_updateUrl.isEmpty()); QDesktopServices::openUrl(m_updateUrl); return; - /*connect(mp_manager, SIGNAL(finished(QNetworkReply*)), - this, SLOT(saveUpdate(QNetworkReply*))); - // Send the request - mp_manager->get(QNetworkRequest(QUrl(m_updateUrl)));*/ } -/*void ProgramUpdater::saveUpdate(QNetworkReply *reply) -{ - // Disconnect SIGNAL/SLOT - disconnect(mp_manager, 0, this, 0); - // Process the download - if (!reply->error()) { - // Save the file - const QString installer_path = QDir::temp().absoluteFilePath("qbittorrent_update."+FILE_EXT.toLower()); - QFile update_installer(installer_path); - if (update_installer.exists()) { - update_installer.remove(); - } - if (update_installer.open(QIODevice::WriteOnly)) { - update_installer.write(reply->readAll()); - reply->close(); - update_installer.close(); - // Install the update - installUpdate(installer_path); - } else { - emit updateInstallFinished(tr("Could not create the file %1").arg(installer_path)); - } - } else { - emit updateInstallFinished(tr("Failed to download the update at %1", "%1 is an URL").arg(m_updateUrl)); - } - reply->deleteLater(); - deleteLater(); -}*/ - -/*void ProgramUpdater::installUpdate(QString update_path) -{ - qDebug("Installing the update at %s...", qPrintable(update_path)); -#ifdef Q_WS_WIN - QDesktopServices::openUrl(QUrl(QString("file:///")+update_path, QUrl::TolerantMode)); -#else - QDesktopServices::openUrl(QUrl(QString("file://")+update_path, QUrl::TolerantMode)); -#endif -}*/ - // title on Windows: /qbittorrent-win32/qbittorrent-2.4.7/qbittorrent_2.4.7_setup.exe // title on Mac: /qbittorrent-mac/qbittorrent-2.4.4/qbittorrent-2.4.4.dmg QString ProgramUpdater::extractVersionNumber(const QString& title) const diff --git a/src/programupdater.h b/src/programupdater.h index 1f32e441c..dff58f932 100644 --- a/src/programupdater.h +++ b/src/programupdater.h @@ -41,7 +41,7 @@ class ProgramUpdater : public QObject { Q_OBJECT public: - explicit ProgramUpdater(QObject *parent = 0); + explicit ProgramUpdater(QObject *parent = 0, bool invokedByUser = false); ~ProgramUpdater(); void checkForUpdates(); void updateProgram(); @@ -52,17 +52,15 @@ protected: protected slots: void rssDownloadFinished(QNetworkReply* reply); - //void installUpdate(QString update_path); - //void saveUpdate(QNetworkReply* reply); void setUpdateUrl(QString title); signals: - void updateCheckFinished(bool update_available, QString version); - void updateInstallFinished(QString error); + void updateCheckFinished(bool update_available, QString version, bool invokedByUser); private: QString m_updateUrl; QNetworkAccessManager *mp_manager; + bool m_invokedByUser; }; #endif // PROGRAMUPDATER_H