Browse Source

Improvements on the behavior of the program updater(closes #1282):

1. Check for updates every hour
2. Don't check again for this session if the user chose to ignore the new version
3. Display a message if the user checked for updates via the menu item and there isn't one
4. Remove dead code
adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
b7f84dabf5
  1. 45
      src/mainwindow.cpp
  2. 4
      src/mainwindow.h
  3. 48
      src/programupdater.cpp
  4. 8
      src/programupdater.h

45
src/mainwindow.cpp

@ -98,11 +98,7 @@ using namespace libtorrent;
*****************************************************/ *****************************************************/
// Constructor // Constructor
MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMainWindow(parent), m_posInitialized(false), force_exit(false) 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
{
setupUi(this); setupUi(this);
Preferences pref; Preferences pref;
@ -216,7 +212,7 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
connect(actionMinimize, SIGNAL(triggered()), SLOT(minimizeWindow())); connect(actionMinimize, SIGNAL(triggered()), SLOT(minimizeWindow()));
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
programUpdateTimer.setInterval(15*60*1000); programUpdateTimer.setInterval(60*60*1000);
programUpdateTimer.setSingleShot(true); programUpdateTimer.setSingleShot(true);
connect(&programUpdateTimer, SIGNAL(timeout()), SLOT(checkProgramUpdate())); connect(&programUpdateTimer, SIGNAL(timeout()), SLOT(checkProgramUpdate()));
connect(actionCheck_for_updates, SIGNAL(triggered()), 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) #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 (update_available) {
if (QMessageBox::question(this, tr("A newer version is available"), answer = QMessageBox::question(this, tr("A new 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), 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) == QMessageBox::Yes) { QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes);
if (answer == QMessageBox::Yes) {
// The user want to update, let's download the update // The user want to update, let's download the update
ProgramUpdater* updater = dynamic_cast<ProgramUpdater*>(sender()); ProgramUpdater* updater = dynamic_cast<ProgramUpdater*>(sender());
connect(updater, SIGNAL(updateInstallFinished(QString)), SLOT(handleUpdateInstalled(QString)));
updater->updateProgram(); 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(); sender()->deleteLater();
checkingProgramUpdate = false;
actionCheck_for_updates->setEnabled(true); actionCheck_for_updates->setEnabled(true);
actionCheck_for_updates->setText(tr("Check for updates")); actionCheck_for_updates->setText(tr("Check for updates"));
actionCheck_for_updates->setToolTip(tr("Check for program 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(); 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 #endif
void MainWindow::on_actionDonate_money_triggered() void MainWindow::on_actionDonate_money_triggered()
@ -1462,14 +1454,13 @@ QIcon MainWindow::getSystrayIcon() const
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
void MainWindow::checkProgramUpdate() { void MainWindow::checkProgramUpdate() {
if (checkingProgramUpdate) programUpdateTimer.stop(); // If the user had clicked the menu item
return;
checkingProgramUpdate = true;
actionCheck_for_updates->setEnabled(false); actionCheck_for_updates->setEnabled(false);
actionCheck_for_updates->setText(tr("Checking for updates...")); actionCheck_for_updates->setText(tr("Checking for updates..."));
actionCheck_for_updates->setToolTip(tr("Already checking for program updates in the background")); actionCheck_for_updates->setToolTip(tr("Already checking for program updates in the background"));
ProgramUpdater *updater = new ProgramUpdater(this); bool invokedByUser = actionCheck_for_updates == qobject_cast<QAction*>(sender());
connect(updater, SIGNAL(updateCheckFinished(bool, QString)), SLOT(handleUpdateCheckFinished(bool, QString))); ProgramUpdater *updater = new ProgramUpdater(this, invokedByUser);
connect(updater, SIGNAL(updateCheckFinished(bool, QString, bool)), SLOT(handleUpdateCheckFinished(bool, QString, bool)));
updater->checkForUpdates(); updater->checkForUpdates();
} }
#endif #endif

4
src/mainwindow.h

@ -140,8 +140,7 @@ protected slots:
// HTTP slots // HTTP slots
void on_actionDownload_from_URL_triggered(); void on_actionDownload_from_URL_triggered();
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
void handleUpdateCheckFinished(bool update_available, QString new_version); void handleUpdateCheckFinished(bool update_available, QString new_version, bool invokedByUser);
void handleUpdateInstalled(QString error_msg);
#endif #endif
protected: protected:
@ -200,7 +199,6 @@ private:
QTimer *preventTimer; QTimer *preventTimer;
#if defined(Q_WS_WIN) || defined(Q_WS_MAC) #if defined(Q_WS_WIN) || defined(Q_WS_MAC)
QTimer programUpdateTimer; QTimer programUpdateTimer;
bool checkingProgramUpdate;
#endif #endif
private slots: private slots:

48
src/programupdater.cpp

@ -49,8 +49,8 @@ const QString FILE_EXT = "EXE";
using namespace libtorrent; using namespace libtorrent;
ProgramUpdater::ProgramUpdater(QObject *parent) : ProgramUpdater::ProgramUpdater(QObject *parent, bool invokedByUser) :
QObject(parent) QObject(parent), m_invokedByUser(invokedByUser)
{ {
mp_manager = new QNetworkAccessManager(this); mp_manager = new QNetworkAccessManager(this);
Preferences pref; 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 // Clean up
reply->deleteLater(); reply->deleteLater();
} }
@ -150,50 +150,8 @@ void ProgramUpdater::updateProgram()
Q_ASSERT(!m_updateUrl.isEmpty()); Q_ASSERT(!m_updateUrl.isEmpty());
QDesktopServices::openUrl(m_updateUrl); QDesktopServices::openUrl(m_updateUrl);
return; 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 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 // title on Mac: /qbittorrent-mac/qbittorrent-2.4.4/qbittorrent-2.4.4.dmg
QString ProgramUpdater::extractVersionNumber(const QString& title) const QString ProgramUpdater::extractVersionNumber(const QString& title) const

8
src/programupdater.h

@ -41,7 +41,7 @@ class ProgramUpdater : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit ProgramUpdater(QObject *parent = 0); explicit ProgramUpdater(QObject *parent = 0, bool invokedByUser = false);
~ProgramUpdater(); ~ProgramUpdater();
void checkForUpdates(); void checkForUpdates();
void updateProgram(); void updateProgram();
@ -52,17 +52,15 @@ protected:
protected slots: protected slots:
void rssDownloadFinished(QNetworkReply* reply); void rssDownloadFinished(QNetworkReply* reply);
//void installUpdate(QString update_path);
//void saveUpdate(QNetworkReply* reply);
void setUpdateUrl(QString title); void setUpdateUrl(QString title);
signals: signals:
void updateCheckFinished(bool update_available, QString version); void updateCheckFinished(bool update_available, QString version, bool invokedByUser);
void updateInstallFinished(QString error);
private: private:
QString m_updateUrl; QString m_updateUrl;
QNetworkAccessManager *mp_manager; QNetworkAccessManager *mp_manager;
bool m_invokedByUser;
}; };
#endif // PROGRAMUPDATER_H #endif // PROGRAMUPDATER_H

Loading…
Cancel
Save