comparison ui/mainwindow.cpp @ 1339:64f812a63de6

(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.
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 23 Oct 2014 16:14:18 +0200
parents 5c6294c201c2
children c2b76c8a8b82
comparison
equal deleted inserted replaced
1338:ba7e36306085 1339:64f812a63de6
49 49
50 // The amount of time in minutes stay silent if we have 50 // The amount of time in minutes stay silent if we have
51 // something to say 51 // something to say
52 #define NAG_INTERVAL_MINUTES 70 52 #define NAG_INTERVAL_MINUTES 70
53 53
54 /** @def The interval in which the update check in tray mode is placed
55 *
56 * The interval should be given in minutes. The first update check will
57 * be placed randomly inside this interval. */
58 #define FIRST_CHECK_INTERVAL_MINUTES 180
59
60 #define DATETIME_FORMAT "d. MMM yyyy HH:mm" 54 #define DATETIME_FORMAT "d. MMM yyyy HH:mm"
61 55
62 #ifndef APPNAME 56 #ifndef APPNAME
63 #define APPNAME "TrustBridge" 57 #define APPNAME "TrustBridge"
64 #endif 58 #endif
102 #endif 96 #endif
103 97
104 static void activateDetailsButton(QPushButton *); 98 static void activateDetailsButton(QPushButton *);
105 static void deactivateDetailsButton(QPushButton *); 99 static void deactivateDetailsButton(QPushButton *);
106 100
101 /** @brief get the interval in milliseconds until the next update try.
102 *
103 * @param [in] tries the number of unsuccessful tries already done.
104 *
105 * @returns a positive value for the time in ms that should be waited.
106 * -1 in case the software should abort. */
107 static int getNextUpdateInterval(int tries)
108 {
109 if (tries < 2) {
110 // 5-10 minutes for the first two checks
111 return ((5 + (qrand() % 5)) * 60 * 1000);
112 }
113 if (tries < 4) {
114 // 15 minutes
115 return 15 * 60 * 1000;
116 }
117 if (tries < 6) {
118 // 30 minutes
119 return 30 * 60 * 1000;
120 }
121 if (tries < 7) {
122 return 60;
123 }
124 return -1;
125 }
126
107 MainWindow::MainWindow(bool trayMode): 127 MainWindow::MainWindow(bool trayMode):
108 mTrayMode(trayMode), 128 mTrayMode(trayMode),
109 mManualDetailsShown(false) 129 mManualDetailsShown(false),
130 mFailedConnections(0)
110 { 131 {
111 createActions(); 132 createActions();
112 createTrayIcon(); 133 createTrayIcon();
113 setupGUI(); 134 setupGUI();
114 resize(900, 600); 135 resize(900, 600);
121 142
122 mMessageTimer = new QTimer(this); 143 mMessageTimer = new QTimer(this);
123 connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage())); 144 connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage()));
124 mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000); 145 mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000);
125 mMessageTimer->start(); 146 mMessageTimer->start();
126 if (trayMode) { 147 checkUpdates();
127 /* Place the first update in a random interval in the first 3h
128 * after start. */
129 QTimer::singleShot(qrand() % (FIRST_CHECK_INTERVAL_MINUTES * 60 * 1000), this, SLOT(checkUpdates()));
130 } else {
131 checkUpdates();
132 }
133 loadUnselectedCertificates(); 148 loadUnselectedCertificates();
134 loadCertificateList(); 149 loadCertificateList();
135 150
136 if (mSettings.value("ShowOnNextStart").toBool()) { 151 if (mSettings.value("ShowOnNextStart").toBool()) {
137 mSettings.remove("ShowOnNextStart"); 152 mSettings.remove("ShowOnNextStart");
649 if (error == SSLConnection::InvalidCertificate) { 664 if (error == SSLConnection::InvalidCertificate) {
650 handleLTE(lteInvalidCertificate); 665 handleLTE(lteInvalidCertificate);
651 } else { 666 } else {
652 handleLTE(lteNoConnection); 667 handleLTE(lteNoConnection);
653 } 668 }
669 setState(TransferError);
654 #ifdef IS_TAG_BUILD 670 #ifdef IS_TAG_BUILD
655 /* During tag build it should never happen that an url checked is not available 671 /* During tag build it should never happen that an url checked is not available
656 * during development this is normal as each revision produces a new url. */ 672 * during development this is normal as each revision produces a new url. */
657 setState(TransferError);
658 if (!isVisible()) { 673 if (!isVisible()) {
659 mCurMessage = message; 674 mCurMessage = message;
660 mTrayIcon->show(); 675 mTrayIcon->show();
661 showMessage(); 676 showMessage();
662 } else { 677 } else {
1755 mLastUpdateCheckContents->show(); 1770 mLastUpdateCheckContents->show();
1756 mLastUpdateCheck->show(); 1771 mLastUpdateCheck->show();
1757 syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData()); 1772 syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData());
1758 handleLTE(lteNoConnection, true); /* Reset error state */ 1773 handleLTE(lteNoConnection, true); /* Reset error state */
1759 handleLTE(lteInvalidCertificate, true); 1774 handleLTE(lteInvalidCertificate, true);
1775 mFailedConnections = 0;
1776 } else if (!isVisible()) {
1777 int waitInterval = getNextUpdateInterval(mFailedConnections++);
1778 if (waitInterval < 0) {
1779 qDebug() << "Shutting down after " << mFailedConnections <<
1780 " tries to get an update connection.";
1781 closeApp();
1782 return;
1783 }
1784 qDebug() << "Waiting for " << waitInterval / 1000 << " seconds until the next try.";
1785 QTimer::singleShot(waitInterval, this, SLOT(checkUpdates()));
1786 return;
1760 } 1787 }
1761 if ((getState() != NewSoftwareAvailable && getState() != NewListAvailable && mTrayMode) 1788 if ((getState() != NewSoftwareAvailable && getState() != NewListAvailable && mTrayMode)
1762 && !isVisible()) { 1789 && !isVisible()) {
1763 qDebug() << "Shutting down as no list or Software is available."; 1790 qDebug() << "Shutting down as no list or Software is available.";
1764 closeApp(); 1791 closeApp();

http://wald.intevation.org/projects/trustbridge/