Mercurial > trustbridge
comparison ui/mainwindow.cpp @ 71:f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Wed, 19 Mar 2014 11:32:25 +0000 |
parents | c6125d73faf4 |
children | 7e304573ebd1 |
comparison
equal
deleted
inserted
replaced
70:64c8c6350e60 | 71:f22a99f7cb69 |
---|---|
14 // something to say | 14 // something to say |
15 #define NAG_INTERVAL_MINUTES 2 | 15 #define NAG_INTERVAL_MINUTES 2 |
16 | 16 |
17 #include "certificatelist.h" | 17 #include "certificatelist.h" |
18 #include "downloader.h" | 18 #include "downloader.h" |
19 #include "listupdatedialog.h" | |
19 | 20 |
20 MainWindow::MainWindow() { | 21 MainWindow::MainWindow() { |
21 createActions(); | 22 createActions(); |
22 createTrayIcon(); | 23 createTrayIcon(); |
23 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode"); | 24 qRegisterMetaType<SSLConnection::ErrorCode>("SSLConnection::ErrorCode"); |
27 | 28 |
28 mMessageTimer = new QTimer(this); | 29 mMessageTimer = new QTimer(this); |
29 connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage())); | 30 connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage())); |
30 mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000); | 31 mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000); |
31 mMessageTimer->start(); | 32 mMessageTimer->start(); |
33 checkUpdates(); | |
32 } | 34 } |
33 | 35 |
34 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) | 36 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) |
35 { | 37 { |
36 switch (reason) { | 38 switch (reason) { |
44 default: | 46 default: |
45 ; | 47 ; |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
51 void MainWindow::messageClicked() | |
52 { | |
53 if (mCurState == NewListAvailable) { | |
54 ListUpdateDialog *listUpdateDialog = new ListUpdateDialog(this, | |
55 mListToInstall); | |
56 listUpdateDialog->show(); | |
57 qDebug() << "NewListAvailable"; | |
58 } | |
59 } | |
60 | |
49 void MainWindow::showMessage() | 61 void MainWindow::showMessage() |
50 { | 62 { |
51 if (!mCurMessage.isEmpty()) { | 63 if (!mCurMessage.isEmpty()) { |
52 mTrayIcon->showMessage(QApplication::applicationName(), mCurMessage, | 64 mTrayIcon->showMessage(QApplication::applicationName(), mCurMessage, |
53 QSystemTrayIcon::Information, 5000); | 65 QSystemTrayIcon::Information, 5000); |
54 mMessageTimer->start(); // Restart the timer so that we don't spam | 66 mMessageTimer->start(); // Restart the timer so that we don't spam |
55 } | 67 } |
56 } | 68 } |
57 | 69 |
58 /** @brief check the integrity of available files. | |
59 * | |
60 * Do not use this as a trust check as this only works on | |
61 * FileNames where the underlying files can change. This | |
62 * is just meant to check if the downloaded data was somehow | |
63 * removed or corrupted. | |
64 * | |
65 */ | |
66 void MainWindow::verifyAvailableData() | 70 void MainWindow::verifyAvailableData() |
67 { | 71 { |
68 QString listFileName = mSettings.value("List/available").toString(); | 72 QString listFileName = mSettings.value("List/available").toString(); |
69 QString swFileName = mSettings.value("Software/available").toString(); | 73 QString swFileName = mSettings.value("Software/available").toString(); |
70 | 74 |
71 if (!listFileName.isEmpty()) { | 75 if (!listFileName.isEmpty()) { |
72 const char *cFileName = listFileName.toLocal8Bit().constData(); | 76 mListToInstall.readList(listFileName.toLocal8Bit().constData()); |
73 char *data = NULL; | 77 if (!mListToInstall.isValid()) { |
74 size_t size; | |
75 | |
76 if (read_and_verify_list(cFileName, &data, &size) != Valid) { | |
77 // Probably a bug when Qt fileName is encoded and cFileName | 78 // Probably a bug when Qt fileName is encoded and cFileName |
78 // fails because of this. This needs a unit test! | 79 // fails because of this. This needs a unit test! |
79 // Maybe check that the file is in our data directory | 80 // Maybe check that the file is in our data directory |
80 QFile::remove(listFileName); | 81 QFile::remove(listFileName); |
81 mSettings.remove("List/available"); | 82 mSettings.remove("List/available"); |
82 mSettings.remove("List/availableDate"); | 83 mSettings.remove("List/availableDate"); |
83 } | 84 } |
84 | |
85 free(data); // We only needed verify | |
86 } else { | 85 } else { |
87 // Make sure the available notation is also removed | 86 // Make sure the available notation is also removed |
88 mSettings.remove("List/available"); | 87 mSettings.remove("List/available"); |
89 mSettings.remove("List/availableDate"); | 88 mSettings.remove("List/availableDate"); |
90 } | 89 } |
96 mSettings.remove("Software/availableDate"); | 95 mSettings.remove("Software/availableDate"); |
97 } | 96 } |
98 } | 97 } |
99 | 98 |
100 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) { | 99 void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) { |
100 mSettings.setValue("List/available", fileName); | |
101 mSettings.setValue("List/availableDate", modDate); | |
101 | 102 |
103 verifyAvailableData(); | |
104 if (!mListToInstall.isValid()) { | |
105 /* Downloader provided invalid files */ | |
106 /* TODO: Error count. Error handling. Otherwise | |
107 * we can go into an endless loop here */ | |
108 | |
109 /* Retry the download again in 10 - 20 minutes */ | |
110 QTimer::singleShot(600000 + (qrand() % 60000), this, SLOT(checkUpdates())); | |
111 } | |
102 mCurMessage = tr("An updated certificate list is available. Click here to install."); | 112 mCurMessage = tr("An updated certificate list is available. Click here to install."); |
103 setState(NewListAvailable); | 113 setState(NewListAvailable); |
104 mSettings.setValue("List/available", fileName); | |
105 mSettings.setValue("List/availableDate", modDate); | |
106 showMessage(); | 114 showMessage(); |
107 } | 115 } |
108 | 116 |
109 void MainWindow::handleNewSW(const QString& fileName, const QDateTime& modDate) { | 117 void MainWindow::handleNewSW(const QString& fileName, const QDateTime& modDate) { |
110 mCurMessage = tr("An update for %1 is available. Click here to install.").arg( | 118 mCurMessage = tr("An update for %1 is available. Click here to install.").arg( |
166 | 174 |
167 mTrayIcon->setIcon(trayImg); | 175 mTrayIcon->setIcon(trayImg); |
168 setWindowIcon(trayImg); | 176 setWindowIcon(trayImg); |
169 mTrayIcon->show(); | 177 mTrayIcon->show(); |
170 mTrayIcon->setToolTip(tr("m13ui")); | 178 mTrayIcon->setToolTip(tr("m13ui")); |
179 | |
180 connect(mTrayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); | |
171 } | 181 } |