[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r3167: If 'check for updates' is enabled at startup, start a timer (vidalia/trunk/src/vidalia)



Author: edmanm
Date: 2008-09-29 22:22:57 -0400 (Mon, 29 Sep 2008)
New Revision: 3167

Modified:
   vidalia/trunk/src/vidalia/mainwindow.cpp
   vidalia/trunk/src/vidalia/mainwindow.h
Log:
If 'check for updates' is enabled at startup, start a timer with the interval
given by GliderProcess (which I totally made up). When the timer expires, kick
off a check for updates, and remember that we did so. If it's been so long
since we checked for updates, start the check now.


Modified: vidalia/trunk/src/vidalia/mainwindow.cpp
===================================================================
--- vidalia/trunk/src/vidalia/mainwindow.cpp	2008-09-30 02:19:38 UTC (rev 3166)
+++ vidalia/trunk/src/vidalia/mainwindow.cpp	2008-09-30 02:22:57 UTC (rev 3167)
@@ -161,6 +161,9 @@
   connect(vApp, SIGNAL(running()), this, SLOT(running()));
   connect(vApp, SIGNAL(shutdown()), this, SLOT(shutdown()));
 
+  /* Create a timer used to remind us to check for software updates */
+  connect(&_updateTimer, SIGNAL(timeout()), this, SLOT(checkForUpdates()));
+
 #if defined(USE_MINIUPNPC)
   /* Catch UPnP-related signals */
   connect(UPNPControl::instance(), SIGNAL(error(UPNPControl::UPNPError)),
@@ -248,6 +251,19 @@
   /* Start the proxy server, if configured */
   if (settings.runProxyAtStart())
     startProxy();
+
+  if (settings.isAutoUpdateEnabled()) {
+    QDateTime lastCheckedAt = settings.lastCheckedForUpdates();
+    if (GliderProcess::shouldCheckForUpdates(lastCheckedAt)) {
+      /* Initiate a background check for updates */
+      checkForUpdates();
+    } else {
+      /* Schedule the next time to check for updates */
+      QDateTime nextCheckAt = GliderProcess::nextCheckForUpdates(lastCheckedAt);
+      QDateTime now = QDateTime::currentDateTime().toUTC();
+      _updateTimer.start((nextCheckAt.toTime_t() - now.toTime_t()) * 1000);
+    }
+  }
 }
 
 /** Terminate the Tor process if it is being run under Vidalia, disconnect all
@@ -1447,3 +1463,18 @@
 }
 #endif
 
+void
+MainWindow::checkForUpdates()
+{
+  /* TODO: Initiate a check for available software updates. This check will
+   *       be done in the background, notifying the user only if there are
+   *       updates to be installed.
+   */
+
+  VidaliaSettings settings;
+  settings.setLastCheckedForUpdates(QDateTime::currentDateTime().toUTC());
+
+  /* Restart the "Check for Updates" timer */
+  _updateTimer.start(GliderProcess::checkForUpdatesInterval() * 1000);
+}
+

Modified: vidalia/trunk/src/vidalia/mainwindow.h
===================================================================
--- vidalia/trunk/src/vidalia/mainwindow.h	2008-09-30 02:19:38 UTC (rev 3166)
+++ vidalia/trunk/src/vidalia/mainwindow.h	2008-09-30 02:22:57 UTC (rev 3167)
@@ -18,6 +18,7 @@
 #define _MAINWINDOW_H
 
 #include <QMainWindow>
+#include <QTimer>
 #include <torcontrol.h>
 #include <bootstrapstatusevent.h>
 
@@ -32,6 +33,7 @@
 #include "ui_mainwindow.h"
 #include "helperprocess.h"
 #include "config.h"
+#include "gliderprocess.h"
 
 #if defined(USE_MINIUPNPC)
 #include "config/upnpcontrol.h"
@@ -110,6 +112,9 @@
   void onIMFailed(QString errmsg);
   /** Called when the proxy server fails to start */
   void onProxyFailed(QString errmsg);
+  /** Called when the update interval timer expires, notifying Vidalia that
+   * we should check for updates again. */
+  void checkForUpdates();
 
 #if defined(USE_MINIUPNPC)
   /** Called when a UPnP error occurs. */
@@ -203,7 +208,9 @@
   bool _useSavedPassword;
   /** The Vidalia icon that sits in the tray. */
   TrayIcon _trayIcon;
- 
+  /** Timer used to remind us to check for software updates. */
+  QTimer _updateTimer;
+
   /** Defines the actions for the tray menu */
   QAction* _controlPanelAct;
   QAction* _startStopAct;