Browse Source

Check for program updates every 15min and allow the user to manually check for updates through the help menu.

adaptive-webui-19844
sledgehammer999 11 years ago
parent
commit
cc92f172e3
  1. 46
      src/mainwindow.cpp
  2. 7
      src/mainwindow.h
  3. 9
      src/mainwindow.ui

46
src/mainwindow.cpp

@ -98,7 +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), checkingProgramUpdate(false) {
setupUi(this); setupUi(this);
Preferences pref; Preferences pref;
@ -211,6 +211,15 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
connect(actionToggleVisibility, SIGNAL(triggered()), this, SLOT(toggleVisibility())); connect(actionToggleVisibility, SIGNAL(triggered()), this, SLOT(toggleVisibility()));
connect(actionMinimize, SIGNAL(triggered()), SLOT(minimizeWindow())); connect(actionMinimize, SIGNAL(triggered()), SLOT(minimizeWindow()));
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
programUpdateTimer.setInterval(15*60*1000);
programUpdateTimer.setSingleShot(true);
connect(&programUpdateTimer, SIGNAL(timeout()), SLOT(checkProgramUpdate()));
connect(actionCheck_for_updates, SIGNAL(triggered()), SLOT(checkProgramUpdate()));
#else
actionCheck_for_updates->setVisible(false);
#endif
m_pwr = new PowerManagement(this); m_pwr = new PowerManagement(this);
preventTimer = new QTimer(this); preventTimer = new QTimer(this);
connect(preventTimer, SIGNAL(timeout()), SLOT(checkForActiveTorrents())); connect(preventTimer, SIGNAL(timeout()), SLOT(checkForActiveTorrents()));
@ -310,14 +319,6 @@ MainWindow::MainWindow(QWidget *parent, const QStringList& torrentCmdLine) : QMa
#ifdef Q_WS_MAC #ifdef Q_WS_MAC
qt_mac_set_dock_menu(getTrayIconMenu()); qt_mac_set_dock_menu(getTrayIconMenu());
#endif #endif
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
// Check for update
if (pref.isUpdateCheckEnabled()) {
ProgramUpdater *updater = new ProgramUpdater(this);
connect(updater, SIGNAL(updateCheckFinished(bool, QString)), SLOT(handleUpdateCheckFinished(bool, QString)));
updater->checkForUpdates();
}
#endif
// Make sure the Window is visible if we don't have a tray icon // Make sure the Window is visible if we don't have a tray icon
if (!systrayIcon) { if (!systrayIcon) {
@ -1110,6 +1111,13 @@ void MainWindow::loadPreferences(bool configure_session) {
if (configure_session) if (configure_session)
QBtSession::instance()->configureSession(); QBtSession::instance()->configureSession();
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
if (pref.isUpdateCheckEnabled())
checkProgramUpdate();
else
programUpdateTimer.stop();
#endif
qDebug("GUI settings loaded"); qDebug("GUI settings loaded");
} }
@ -1358,6 +1366,12 @@ void MainWindow::handleUpdateCheckFinished(bool update_available, QString new_ve
} }
} }
sender()->deleteLater(); 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())
programUpdateTimer.start();
} }
void MainWindow::handleUpdateInstalled(QString error_msg) void MainWindow::handleUpdateInstalled(QString error_msg)
@ -1448,3 +1462,17 @@ QIcon MainWindow::getSystrayIcon() const
} }
return icon; return icon;
} }
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
void MainWindow::checkProgramUpdate() {
if (checkingProgramUpdate)
return;
checkingProgramUpdate = true;
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)));
updater->checkForUpdates();
}
#endif

7
src/mainwindow.h

@ -199,6 +199,10 @@ private:
// Power Management // Power Management
PowerManagement *m_pwr; PowerManagement *m_pwr;
QTimer *preventTimer; QTimer *preventTimer;
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
QTimer programUpdateTimer;
bool checkingProgramUpdate;
#endif
private slots: private slots:
void on_actionSearch_engine_triggered(); void on_actionSearch_engine_triggered();
@ -213,6 +217,9 @@ private slots:
void on_actionAutoShutdown_system_toggled(bool ); void on_actionAutoShutdown_system_toggled(bool );
// Check for active torrents and set preventing from suspend state // Check for active torrents and set preventing from suspend state
void checkForActiveTorrents(); void checkForActiveTorrents();
#if defined(Q_WS_WIN) || defined(Q_WS_MAC)
void checkProgramUpdate();
#endif
}; };
#endif #endif

9
src/mainwindow.ui

@ -53,6 +53,7 @@
<addaction name="actionWebsite"/> <addaction name="actionWebsite"/>
<addaction name="actionDocumentation"/> <addaction name="actionDocumentation"/>
<addaction name="actionDonate_money"/> <addaction name="actionDonate_money"/>
<addaction name="actionCheck_for_updates"/>
<addaction name="actionAbout"/> <addaction name="actionAbout"/>
</widget> </widget>
<widget class="QMenu" name="menu_Options"> <widget class="QMenu" name="menu_Options">
@ -381,6 +382,14 @@
<string>Statistics</string> <string>Statistics</string>
</property> </property>
</action> </action>
<action name="actionCheck_for_updates">
<property name="text">
<string>Check for updates</string>
</property>
<property name="toolTip">
<string>Check for program updates</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="icons.qrc"/> <include location="icons.qrc"/>

Loading…
Cancel
Save