Mercurial > trustbridge
changeset 389:3be838c3e4d8
Handle installation success. Save / load last installed list.
This also adds a feature that you can specifiy the download
resource when release build is not set so that you can
update a list without modifying the server data.
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 15 Apr 2014 19:05:49 +0200 |
parents | a507e5f1b999 |
children | eab288779e07 |
files | ui/mainwindow.cpp ui/mainwindow.h |
diffstat | 2 files changed, 78 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/ui/mainwindow.cpp Tue Apr 15 19:03:56 2014 +0200 +++ b/ui/mainwindow.cpp Tue Apr 15 19:05:49 2014 +0200 @@ -53,10 +53,11 @@ mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000); mMessageTimer->start(); checkUpdates(); + loadUnselectedCertificates(); + loadCertificateList(); if (!trayMode) { show(); } - loadUnselectedCertificates(); } void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) @@ -92,17 +93,18 @@ void MainWindow::verifyAvailableData() { - QString listFileName = mSettings.value("List/available").toString(); + QString availableFileName = mSettings.value("List/available").toString(); + QString installedFileName = mSettings.value("List/installed").toString(); QString swFileName = mSettings.value("Software/available").toString(); - if (!listFileName.isEmpty()) { - mListToInstall.readList(listFileName.toLocal8Bit().constData()); + if (!availableFileName.isEmpty()) { + mListToInstall.readList(availableFileName.toLocal8Bit().constData()); if (!mListToInstall.isValid()) { mCurState = TransferError; // Probably a bug when Qt fileName is encoded and cFileName // fails because of this. This needs a unit test! // Maybe check that the file is in our data directory - QFile::remove(listFileName); + QFile::remove(availableFileName); mSettings.remove("List/available"); mSettings.remove("List/availableDate"); } @@ -112,6 +114,22 @@ mSettings.remove("List/availableDate"); } + if (!installedFileName.isEmpty()) { + mInstalledList.readList(installedFileName.toLocal8Bit().constData()); + if (!mInstalledList.isValid()) { + // Probably a bug when Qt fileName is encoded and cFileName + // fails because of this. This needs a unit test! + // Maybe check that the file is in our data directory + QFile::remove(installedFileName); + mSettings.remove("List/installed"); + mSettings.remove("List/installedDate"); + } + } else { + // Make sure the available notation is also removed + mSettings.remove("List/installed"); + mSettings.remove("List/installedDate"); + } + if (!swFileName.isEmpty()) { // TODO } else { @@ -158,11 +176,21 @@ QDateTime listInstalledLastMod = mSettings.value("List/installedDate").toDateTime(); QDateTime swInstalledLastMod = mSettings.value("Software/installedDate").toDateTime(); + QString listResource = QString::fromLatin1(LIST_RESOURCE); + QString swResource = QString::fromLatin1(SW_RESOURCE); + +#ifndef RELEASE_BUILD + /* Use this for testing to specify another file name for updates */ + listResource = mSettings.value("List/resource", listResource).toString(); + swResource = mSettings.value("Software/resource", swResource).toString(); +#endif + + Downloader* downloader = new Downloader(this, QString::fromLatin1(SERVER_URL), QByteArray(), QDateTime::currentDateTime(), -// swInstalledLastMod, +// TODO swInstalledLastMod, listInstalledLastMod, QString::fromLatin1(SW_RESOURCE), QString::fromLatin1(LIST_RESOURCE)); @@ -319,7 +347,13 @@ { mCertListWidget->clear(); int i = 0; - foreach (const Certificate &cert, mListToInstall.getCertificates()) { + + /* TODO: if nothing is available (neither old nor new) add some progress + * indication */ + + foreach (const Certificate &cert, mListToInstall.isValid() ? + mListToInstall.getCertificates() : + mInstalledList.getCertificates()) { if (!cert.isValid()) { qWarning() << "Invalid certificate in list"; continue; @@ -330,9 +364,14 @@ item->setData(CertificateItemDelegate::B64LineRole, cert.base64Line()); Qt::CheckState checkedState = mPreviouslyUnselected.contains(cert.base64Line()) ? Qt::Unchecked : Qt::Checked; + + bool isOld = mInstalledList.getCertificates().contains(cert); + qDebug() << "Found old certificate."; + /* TODO properly work with that information. */ + if (cert.isInstallCert()) { // This if statements is for testing! @TODO Remove this! - if (i <= 2) { + if (isOld) { item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallOld); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); } @@ -407,6 +446,27 @@ QMessageBox::warning(this, tr("Error executing update"), errMsg); } +void MainWindow::installerSuccess() { + if (mCurState == NewListAvailable) { + mCurState = NothingChanged; + mCurMessage = QString(); + + QString listFileName = mSettings.value("List/available").toString(); + QDateTime listFileDate = mSettings.value("List/availableDate").toDateTime(); + + mSettings.remove("List/available"); + mSettings.remove("List/availableDate"); + + if (listFileName.isEmpty() || !listFileDate.isValid()) { + qWarning() << "Error accessing settings"; + return; /* Try again with next check */ + } + + mSettings.setValue("List/installed", listFileName); + mSettings.setValue("List/installedDate", listFileDate); + } +} + void MainWindow::installCerts() { QStringList choices; @@ -438,8 +498,10 @@ connect(instWrap, SIGNAL(finished()), instWrap, SLOT(deleteLater())); connect(instWrap, SIGNAL(finished()), progress, SLOT(deleteLater())); connect(instWrap, SIGNAL(finished()), progress, SLOT(cancel())); + connect(instWrap, SIGNAL(installationSuccessful()), + this, SLOT(installerSuccess())); connect(instWrap, SIGNAL(error(const QString &)), - this, SLOT(installerError(const QString &))); + this, SLOT(installerError(const QString &))); instWrap->start(); if (!saveUnselectedCertificates()) {
--- a/ui/mainwindow.h Tue Apr 15 19:03:56 2014 +0200 +++ b/ui/mainwindow.h Tue Apr 15 19:05:49 2014 +0200 @@ -43,7 +43,8 @@ BeforeDownload, NewListAvailable, NewSoftwareAvailable, - TransferError + TransferError, + NothingChanged }; CurrentState getState() {return mCurState;} void setState(CurrentState state) {mCurState = state;} @@ -64,6 +65,7 @@ void showDetails(QListWidgetItem*); void resizeButtons(); void installerError(const QString& errMsg); + void installerSuccess(); void installCerts(); /** @brief saves the currently unselected certificates @@ -93,8 +95,8 @@ * Do not use this as a trust check as this only works on * FileNames where the underlying files can change. This * is just meant to check if the downloaded data was somehow - * removed or corrupted. - * + * removed or corrupted. It also initializes mListToInstall + * and mInstalledList. */ void verifyAvailableData(); void createTrayIcon(); @@ -122,6 +124,8 @@ /* The current list that should be installed */ CertificateList mListToInstall; + /* The last list that we installed */ + CertificateList mInstalledList; /* Previously made "unselect" choices in the form of * base64lines with I:/R: prefix */ QStringList mPreviouslyUnselected;