Mercurial > trustbridge
comparison ui/mainwindow.cpp @ 399:55cbe0a482ce
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 16 Apr 2014 10:01:02 +0200 |
parents | ae2ef965a41b |
children | 17e1c8f37d72 |
comparison
equal
deleted
inserted
replaced
398:9e6a2c2033ed | 399:55cbe0a482ce |
---|---|
51 mMessageTimer = new QTimer(this); | 51 mMessageTimer = new QTimer(this); |
52 connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage())); | 52 connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage())); |
53 mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000); | 53 mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000); |
54 mMessageTimer->start(); | 54 mMessageTimer->start(); |
55 checkUpdates(); | 55 checkUpdates(); |
56 loadUnselectedCertificates(); | |
57 loadCertificateList(); | |
56 if (!trayMode) { | 58 if (!trayMode) { |
57 show(); | 59 show(); |
58 } | 60 } |
59 loadUnselectedCertificates(); | |
60 } | 61 } |
61 | 62 |
62 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) | 63 void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) |
63 { | 64 { |
64 switch (reason) { | 65 switch (reason) { |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
93 void MainWindow::verifyAvailableData() | 94 void MainWindow::verifyAvailableData() |
94 { | 95 { |
95 QString listFileName = mSettings.value("List/available").toString(); | 96 QString availableFileName = mSettings.value("List/available").toString(); |
97 QString installedFileName = mSettings.value("List/installed").toString(); | |
96 QString swFileName = mSettings.value("Software/available").toString(); | 98 QString swFileName = mSettings.value("Software/available").toString(); |
97 | 99 |
98 if (!listFileName.isEmpty()) { | 100 if (!availableFileName.isEmpty()) { |
99 mListToInstall.readList(listFileName.toLocal8Bit().constData()); | 101 mListToInstall.readList(availableFileName.toLocal8Bit().constData()); |
100 if (!mListToInstall.isValid()) { | 102 if (!mListToInstall.isValid()) { |
101 mCurState = TransferError; | 103 mCurState = TransferError; |
102 // Probably a bug when Qt fileName is encoded and cFileName | 104 // Probably a bug when Qt fileName is encoded and cFileName |
103 // fails because of this. This needs a unit test! | 105 // fails because of this. This needs a unit test! |
104 // Maybe check that the file is in our data directory | 106 // Maybe check that the file is in our data directory |
105 QFile::remove(listFileName); | 107 QFile::remove(availableFileName); |
106 mSettings.remove("List/available"); | 108 mSettings.remove("List/available"); |
107 mSettings.remove("List/availableDate"); | 109 mSettings.remove("List/availableDate"); |
108 } | 110 } |
109 } else { | 111 } else { |
110 // Make sure the available notation is also removed | 112 // Make sure the available notation is also removed |
111 mSettings.remove("List/available"); | 113 mSettings.remove("List/available"); |
112 mSettings.remove("List/availableDate"); | 114 mSettings.remove("List/availableDate"); |
115 } | |
116 | |
117 if (!installedFileName.isEmpty()) { | |
118 mInstalledList.readList(installedFileName.toLocal8Bit().constData()); | |
119 if (!mInstalledList.isValid()) { | |
120 // Probably a bug when Qt fileName is encoded and cFileName | |
121 // fails because of this. This needs a unit test! | |
122 // Maybe check that the file is in our data directory | |
123 QFile::remove(installedFileName); | |
124 mSettings.remove("List/installed"); | |
125 mSettings.remove("List/installedDate"); | |
126 } | |
127 } else { | |
128 // Make sure the available notation is also removed | |
129 mSettings.remove("List/installed"); | |
130 mSettings.remove("List/installedDate"); | |
113 } | 131 } |
114 | 132 |
115 if (!swFileName.isEmpty()) { | 133 if (!swFileName.isEmpty()) { |
116 // TODO | 134 // TODO |
117 } else { | 135 } else { |
156 verifyAvailableData(); | 174 verifyAvailableData(); |
157 | 175 |
158 QDateTime listInstalledLastMod = mSettings.value("List/installedDate").toDateTime(); | 176 QDateTime listInstalledLastMod = mSettings.value("List/installedDate").toDateTime(); |
159 QDateTime swInstalledLastMod = mSettings.value("Software/installedDate").toDateTime(); | 177 QDateTime swInstalledLastMod = mSettings.value("Software/installedDate").toDateTime(); |
160 | 178 |
179 QString listResource = QString::fromLatin1(LIST_RESOURCE); | |
180 QString swResource = QString::fromLatin1(SW_RESOURCE); | |
181 | |
182 #ifndef RELEASE_BUILD | |
183 /* Use this for testing to specify another file name for updates */ | |
184 listResource = mSettings.value("List/resource", listResource).toString(); | |
185 swResource = mSettings.value("Software/resource", swResource).toString(); | |
186 #endif | |
187 | |
188 | |
161 Downloader* downloader = new Downloader(this, | 189 Downloader* downloader = new Downloader(this, |
162 QString::fromLatin1(SERVER_URL), | 190 QString::fromLatin1(SERVER_URL), |
163 QByteArray(), | 191 QByteArray(), |
164 QDateTime::currentDateTime(), | 192 QDateTime::currentDateTime(), |
165 // swInstalledLastMod, | 193 // TODO swInstalledLastMod, |
166 listInstalledLastMod, | 194 listInstalledLastMod, |
167 QString::fromLatin1(SW_RESOURCE), | 195 QString::fromLatin1(SW_RESOURCE), |
168 QString::fromLatin1(LIST_RESOURCE)); | 196 QString::fromLatin1(LIST_RESOURCE)); |
169 | 197 |
170 connect(downloader, SIGNAL(newListAvailable(const QString&, const QDateTime&)), | 198 connect(downloader, SIGNAL(newListAvailable(const QString&, const QDateTime&)), |
317 | 345 |
318 void MainWindow::loadCertificateList() | 346 void MainWindow::loadCertificateList() |
319 { | 347 { |
320 mCertListWidget->clear(); | 348 mCertListWidget->clear(); |
321 int i = 0; | 349 int i = 0; |
322 foreach (const Certificate &cert, mListToInstall.getCertificates()) { | 350 |
351 /* TODO: if nothing is available (neither old nor new) add some progress | |
352 * indication */ | |
353 | |
354 foreach (const Certificate &cert, mListToInstall.isValid() ? | |
355 mListToInstall.getCertificates() : | |
356 mInstalledList.getCertificates()) { | |
323 if (!cert.isValid()) { | 357 if (!cert.isValid()) { |
324 qWarning() << "Invalid certificate in list"; | 358 qWarning() << "Invalid certificate in list"; |
325 continue; | 359 continue; |
326 } | 360 } |
327 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); | 361 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); |
328 SeparatorItemDelegate *separator = new SeparatorItemDelegate(); | 362 SeparatorItemDelegate *separator = new SeparatorItemDelegate(); |
329 item->setData(CertificateItemDelegate::DetailsRole, cert.details()); | 363 item->setData(CertificateItemDelegate::DetailsRole, cert.details()); |
330 item->setData(CertificateItemDelegate::B64LineRole, cert.base64Line()); | 364 item->setData(CertificateItemDelegate::B64LineRole, cert.base64Line()); |
331 Qt::CheckState checkedState = mPreviouslyUnselected.contains(cert.base64Line()) ? | 365 Qt::CheckState checkedState = mPreviouslyUnselected.contains(cert.base64Line()) ? |
332 Qt::Unchecked : Qt::Checked; | 366 Qt::Unchecked : Qt::Checked; |
367 | |
368 bool isOld = mInstalledList.getCertificates().contains(cert); | |
369 qDebug() << "Found old certificate."; | |
370 /* TODO properly work with that information. */ | |
371 | |
333 if (cert.isInstallCert()) { | 372 if (cert.isInstallCert()) { |
334 // This if statements is for testing! @TODO Remove this! | 373 // This if statements is for testing! @TODO Remove this! |
335 if (i <= 2) { | 374 if (isOld) { |
336 item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallOld); | 375 item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallOld); |
337 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); | 376 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); |
338 } | 377 } |
339 else { | 378 else { |
340 item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallNew); | 379 item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallNew); |
405 | 444 |
406 void MainWindow::installerError(const QString& errMsg) { | 445 void MainWindow::installerError(const QString& errMsg) { |
407 QMessageBox::warning(this, tr("Error executing update"), errMsg); | 446 QMessageBox::warning(this, tr("Error executing update"), errMsg); |
408 } | 447 } |
409 | 448 |
449 void MainWindow::installerSuccess() { | |
450 if (mCurState == NewListAvailable) { | |
451 mCurState = NothingChanged; | |
452 mCurMessage = QString(); | |
453 | |
454 QString listFileName = mSettings.value("List/available").toString(); | |
455 QDateTime listFileDate = mSettings.value("List/availableDate").toDateTime(); | |
456 | |
457 mSettings.remove("List/available"); | |
458 mSettings.remove("List/availableDate"); | |
459 | |
460 if (listFileName.isEmpty() || !listFileDate.isValid()) { | |
461 qWarning() << "Error accessing settings"; | |
462 return; /* Try again with next check */ | |
463 } | |
464 | |
465 mSettings.setValue("List/installed", listFileName); | |
466 mSettings.setValue("List/installedDate", listFileDate); | |
467 } | |
468 } | |
469 | |
410 void MainWindow::installCerts() { | 470 void MainWindow::installCerts() { |
411 QStringList choices; | 471 QStringList choices; |
412 | 472 |
413 for (int i = 0; i < mCertListWidget->count(); i++) { | 473 for (int i = 0; i < mCertListWidget->count(); i++) { |
414 QListWidgetItem *item = mCertListWidget->item(i); | 474 QListWidgetItem *item = mCertListWidget->item(i); |
430 progress->setRange(0,0); | 490 progress->setRange(0,0); |
431 progress->setMinimumDuration(0); | 491 progress->setMinimumDuration(0); |
432 progress->show(); | 492 progress->show(); |
433 | 493 |
434 InstallWrapper *instWrap = new InstallWrapper(this, | 494 InstallWrapper *instWrap = new InstallWrapper(this, |
435 mListToInstall.fileName(), | 495 mListToInstall.isValid() ? |
496 mListToInstall.fileName() : | |
497 mInstalledList.fileName(), | |
436 choices); | 498 choices); |
437 /* Clean up object and progress dialog */ | 499 /* Clean up object and progress dialog */ |
438 connect(instWrap, SIGNAL(finished()), instWrap, SLOT(deleteLater())); | 500 connect(instWrap, SIGNAL(finished()), instWrap, SLOT(deleteLater())); |
439 connect(instWrap, SIGNAL(finished()), progress, SLOT(deleteLater())); | 501 connect(instWrap, SIGNAL(finished()), progress, SLOT(deleteLater())); |
440 connect(instWrap, SIGNAL(finished()), progress, SLOT(cancel())); | 502 connect(instWrap, SIGNAL(finished()), progress, SLOT(cancel())); |
503 connect(instWrap, SIGNAL(installationSuccessful()), | |
504 this, SLOT(installerSuccess())); | |
441 connect(instWrap, SIGNAL(error(const QString &)), | 505 connect(instWrap, SIGNAL(error(const QString &)), |
442 this, SLOT(installerError(const QString &))); | 506 this, SLOT(installerError(const QString &))); |
443 instWrap->start(); | 507 instWrap->start(); |
444 | 508 |
445 if (!saveUnselectedCertificates()) { | 509 if (!saveUnselectedCertificates()) { |
446 qWarning() << "Failed to save previosly unselected certificates."; | 510 qWarning() << "Failed to save previosly unselected certificates."; |
447 } | 511 } |