[PATCH] (issue170) Keep checking for updates in intervals
Wald Commits
scm-commit at wald.intevation.org
Thu Oct 23 16:14:38 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1414073658 -7200
# Node ID 64f812a63de6139f3799c9f61590ad7a2b0df519
# Parent ba7e363060852051ba40bf13159e08ec736bc216
(issue170) Keep checking for updates in intervals
When the connection fails in tray mode this will keep
the software alive and have it checking for some time until
a limit is reached.
diff -r ba7e36306085 -r 64f812a63de6 ui/mainwindow.cpp
--- a/ui/mainwindow.cpp Thu Oct 16 15:00:52 2014 +0200
+++ b/ui/mainwindow.cpp Thu Oct 23 16:14:18 2014 +0200
@@ -51,12 +51,6 @@
// something to say
#define NAG_INTERVAL_MINUTES 70
-/** @def The interval in which the update check in tray mode is placed
- *
- * The interval should be given in minutes. The first update check will
- * be placed randomly inside this interval. */
-#define FIRST_CHECK_INTERVAL_MINUTES 180
-
#define DATETIME_FORMAT "d. MMM yyyy HH:mm"
#ifndef APPNAME
@@ -104,9 +98,36 @@
static void activateDetailsButton(QPushButton *);
static void deactivateDetailsButton(QPushButton *);
+/** @brief get the interval in milliseconds until the next update try.
+ *
+ * @param [in] tries the number of unsuccessful tries already done.
+ *
+ * @returns a positive value for the time in ms that should be waited.
+ * -1 in case the software should abort. */
+static int getNextUpdateInterval(int tries)
+{
+ if (tries < 2) {
+ // 5-10 minutes for the first two checks
+ return ((5 + (qrand() % 5)) * 60 * 1000);
+ }
+ if (tries < 4) {
+ // 15 minutes
+ return 15 * 60 * 1000;
+ }
+ if (tries < 6) {
+ // 30 minutes
+ return 30 * 60 * 1000;
+ }
+ if (tries < 7) {
+ return 60;
+ }
+ return -1;
+}
+
MainWindow::MainWindow(bool trayMode):
mTrayMode(trayMode),
- mManualDetailsShown(false)
+ mManualDetailsShown(false),
+ mFailedConnections(0)
{
createActions();
createTrayIcon();
@@ -123,13 +144,7 @@
connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage()));
mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000);
mMessageTimer->start();
- if (trayMode) {
- /* Place the first update in a random interval in the first 3h
- * after start. */
- QTimer::singleShot(qrand() % (FIRST_CHECK_INTERVAL_MINUTES * 60 * 1000), this, SLOT(checkUpdates()));
- } else {
- checkUpdates();
- }
+ checkUpdates();
loadUnselectedCertificates();
loadCertificateList();
@@ -651,10 +666,10 @@
} else {
handleLTE(lteNoConnection);
}
+ setState(TransferError);
#ifdef IS_TAG_BUILD
/* During tag build it should never happen that an url checked is not available
* during development this is normal as each revision produces a new url. */
- setState(TransferError);
if (!isVisible()) {
mCurMessage = message;
mTrayIcon->show();
@@ -1757,6 +1772,18 @@
syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData());
handleLTE(lteNoConnection, true); /* Reset error state */
handleLTE(lteInvalidCertificate, true);
+ mFailedConnections = 0;
+ } else if (!isVisible()) {
+ int waitInterval = getNextUpdateInterval(mFailedConnections++);
+ if (waitInterval < 0) {
+ qDebug() << "Shutting down after " << mFailedConnections <<
+ " tries to get an update connection.";
+ closeApp();
+ return;
+ }
+ qDebug() << "Waiting for " << waitInterval / 1000 << " seconds until the next try.";
+ QTimer::singleShot(waitInterval, this, SLOT(checkUpdates()));
+ return;
}
if ((getState() != NewSoftwareAvailable && getState() != NewListAvailable && mTrayMode)
&& !isVisible()) {
diff -r ba7e36306085 -r 64f812a63de6 ui/mainwindow.h
--- a/ui/mainwindow.h Thu Oct 16 15:00:52 2014 +0200
+++ b/ui/mainwindow.h Thu Oct 23 16:14:18 2014 +0200
@@ -379,6 +379,7 @@
QPushButton *mInstallButton;
int mChangeCount;
bool mManualDetailsShown;
+ int mFailedConnections;
};
#endif // MAINWINDOW_H
More information about the Trustbridge-commits
mailing list