aheinecke@404: /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik aheinecke@404: * Software engineering by Intevation GmbH aheinecke@404: * aheinecke@404: * This file is Free Software under the GNU GPL (v>=2) aheinecke@404: * and comes with ABSOLUTELY NO WARRANTY! aheinecke@404: * See LICENSE.txt for details. aheinecke@404: */ aheinecke@0: #include "mainwindow.h" aheinecke@0: aheinecke@0: #include aheinecke@551: #include aheinecke@365: #include aheinecke@0: #include aheinecke@0: #include aheinecke@0: #include aheinecke@0: #include aheinecke@563: #include aheinecke@0: #include aheinecke@2: #include aheinecke@16: #include aheinecke@19: #include rrenkert@187: #include rrenkert@187: #include emanuel@709: #include rrenkert@187: #include rrenkert@189: #include rrenkert@205: #include rrenkert@205: #include rrenkert@250: #include rrenkert@584: #include rrenkert@584: #include aheinecke@19: andre@609: #include "certificatelist.h" andre@609: #include "downloader.h" andre@609: #include "helpdialog.h" andre@609: #include "aboutdialog.h" andre@609: #include "separatoritemdelegate.h" andre@609: #include "installwrapper.h" andre@609: #include "util.h" andre@609: #include "logging.h" andre@609: #include "binverify.h" andre@609: #include "processhelp.h" andre@609: #include "processwaitdialog.h" andre@609: aheinecke@19: // The amount of time in minutes stay silent if we have aheinecke@19: // something to say aheinecke@548: #define NAG_INTERVAL_MINUTES 70 aheinecke@0: andre@714: #define DATETIME_FORMAT "dddd, d.MMMM yyyy HH:mm:ss" andre@714: aheinecke@409: #ifndef APPNAME aheinecke@409: #define APPNAME "TrustBridge" aheinecke@409: #endif aheinecke@409: aheinecke@409: #define SERVER_URL "https://files.intevation.de:443" aheinecke@72: andre@607: #ifdef RELEASE_BUILD andre@607: # define LIST_RESOURCE "/users/aheinecke/zertifikatsliste.txt" andre@607: # ifdef Q_OS_WIN andre@607: # define SW_RESOURCE_VERSION "/users/aheinecke/TrustBridge-%1.exe" andre@664: # define SW_RESOURCE "/users/aheinecke/TrustBridge.exe" andre@607: # else andre@607: # define SW_RESOURCE_VERSION "/users/aheinecke/TrustBridge-%1.sh" andre@664: # define SW_RESOURCE "/users/aheinecke/TrustBridge.sh" andre@607: # endif andre@607: #else // RELEASE_BUILD andre@607: # define LIST_RESOURCE "/users/aheinecke/development/zertifikatsliste.txt" andre@607: # ifdef Q_OS_WIN andre@607: # define SW_RESOURCE_VERSION "/users/aheinecke/development/TrustBridge-development.exe" andre@664: # define SW_RESOURCE "/users/aheinecke/development/TrustBridge.exe" andre@607: # else andre@607: # define SW_RESOURCE_VERSION "/users/aheinecke/development/TrustBridge-development.sh" andre@664: # define SW_RESOURCE "/users/aheinecke/development/TrustBridge.sh" andre@607: # endif rrenkert@486: #endif aheinecke@7: aheinecke@365: MainWindow::MainWindow(bool trayMode): aheinecke@365: mTrayMode(trayMode) aheinecke@365: { aheinecke@0: createActions(); aheinecke@0: createTrayIcon(); andre@739: setupGUI(); emanuel@709: resize(1065, 600); emanuel@709: setMinimumWidth(760); aheinecke@45: qRegisterMetaType("SSLConnection::ErrorCode"); rrenkert@265: qRegisterMetaType("Certificate::Status"); aheinecke@0: aheinecke@0: connect(mTrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), aheinecke@0: this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); aheinecke@19: aheinecke@19: mMessageTimer = new QTimer(this); aheinecke@19: connect(mMessageTimer, SIGNAL(timeout()), this, SLOT(showMessage())); aheinecke@19: mMessageTimer->setInterval(NAG_INTERVAL_MINUTES * 60 * 1000); aheinecke@19: mMessageTimer->start(); aheinecke@71: checkUpdates(); andre@389: loadUnselectedCertificates(); andre@389: loadCertificateList(); aheinecke@365: if (!trayMode) { aheinecke@365: show(); aheinecke@365: } aheinecke@0: } aheinecke@0: aheinecke@0: void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) aheinecke@0: { aheinecke@0: switch (reason) { aheinecke@0: case QSystemTrayIcon::Trigger: aheinecke@0: case QSystemTrayIcon::MiddleClick: aheinecke@0: showMessage(); aheinecke@0: break; aheinecke@16: case QSystemTrayIcon::DoubleClick: aheinecke@365: show(); aheinecke@16: break; aheinecke@0: default: aheinecke@0: ; aheinecke@0: } aheinecke@0: } aheinecke@0: aheinecke@71: void MainWindow::messageClicked() aheinecke@71: { aheinecke@71: if (mCurState == NewListAvailable) { aheinecke@365: show(); aheinecke@71: } aheinecke@551: aheinecke@551: if (mCurState == NewSoftwareAvailable) { aheinecke@587: verifySWData(); aheinecke@587: QString swFileName = mSettings.value("Software/available").toString(); aheinecke@587: if (swFileName.isEmpty()) { aheinecke@587: checkUpdates(true); aheinecke@587: mCurState = DownloadingSW; aheinecke@587: return; aheinecke@587: } aheinecke@587: installNewSW(swFileName, aheinecke@587: mSettings.value("Software/availableDate").toDateTime()); aheinecke@551: } aheinecke@71: } aheinecke@71: aheinecke@0: void MainWindow::showMessage() aheinecke@0: { aheinecke@591: if (mCurMessage.isEmpty()) { aheinecke@591: return; aheinecke@591: } aheinecke@591: if (mCurState == NewSoftwareAvailable || !isVisible()) { aheinecke@16: mTrayIcon->showMessage(QApplication::applicationName(), mCurMessage, aheinecke@591: QSystemTrayIcon::Information, 10000); aheinecke@19: mMessageTimer->start(); // Restart the timer so that we don't spam aheinecke@16: } aheinecke@0: } aheinecke@16: aheinecke@587: void MainWindow::verifyListData() aheinecke@0: { andre@389: QString availableFileName = mSettings.value("List/available").toString(); andre@389: QString installedFileName = mSettings.value("List/installed").toString(); andre@389: if (!availableFileName.isEmpty()) { andre@389: mListToInstall.readList(availableFileName.toLocal8Bit().constData()); aheinecke@71: if (!mListToInstall.isValid()) { aheinecke@82: mCurState = TransferError; aheinecke@16: // Probably a bug when Qt fileName is encoded and cFileName aheinecke@16: // fails because of this. This needs a unit test! aheinecke@16: // Maybe check that the file is in our data directory andre@389: QFile::remove(availableFileName); aheinecke@16: mSettings.remove("List/available"); aheinecke@16: mSettings.remove("List/availableDate"); aheinecke@16: } aheinecke@16: } else { aheinecke@16: // Make sure the available notation is also removed aheinecke@16: mSettings.remove("List/available"); aheinecke@16: mSettings.remove("List/availableDate"); aheinecke@16: } aheinecke@16: andre@389: if (!installedFileName.isEmpty()) { andre@389: mInstalledList.readList(installedFileName.toLocal8Bit().constData()); andre@389: if (!mInstalledList.isValid()) { andre@389: // Probably a bug when Qt fileName is encoded and cFileName andre@389: // fails because of this. This needs a unit test! andre@389: // Maybe check that the file is in our data directory andre@389: QFile::remove(installedFileName); andre@389: mSettings.remove("List/installed"); andre@389: mSettings.remove("List/installedDate"); andre@389: } andre@389: } else { andre@389: mSettings.remove("List/installed"); andre@389: mSettings.remove("List/installedDate"); andre@389: } aheinecke@587: } andre@389: aheinecke@587: void MainWindow::verifySWData() aheinecke@587: { aheinecke@587: QString swFileName = mSettings.value("Software/available").toString(); andre@389: aheinecke@591: if (swFileName.isEmpty()) { aheinecke@591: mSettings.remove("Software/availableDate"); aheinecke@591: return; aheinecke@591: } aheinecke@591: aheinecke@591: QFileInfo fi(swFileName); aheinecke@591: if (!fi.exists()) { aheinecke@16: mSettings.remove("Software/available"); aheinecke@16: mSettings.remove("Software/availableDate"); aheinecke@591: qDebug() << "Software does not yet exist."; aheinecke@591: return; aheinecke@591: } aheinecke@591: if (!fi.isExecutable()) { aheinecke@591: qWarning() << "Downloaded file: " << swFileName << " is not executable."; aheinecke@591: QFile::remove(swFileName); aheinecke@591: mSettings.remove("Software/available"); aheinecke@591: mSettings.remove("Software/availableDate"); aheinecke@591: return; aheinecke@591: } aheinecke@591: bin_verify_result verifyResult = verify_binary(swFileName.toUtf8().constData(), aheinecke@591: swFileName.toUtf8().size()); aheinecke@591: qDebug() << "Binary verify result: " << verifyResult; aheinecke@591: if (verifyResult != VerifyValid) { aheinecke@591: qDebug() << "Failed to verify downloaded data."; aheinecke@591: QFile::remove(swFileName); aheinecke@591: mSettings.remove("Software/available"); aheinecke@591: mSettings.remove("Software/availableDate"); aheinecke@591: return; aheinecke@16: } aheinecke@16: } aheinecke@16: aheinecke@16: void MainWindow::handleNewList(const QString& fileName, const QDateTime& modDate) { rrenkert@628: qDebug() << "new list available"; aheinecke@71: mSettings.setValue("List/available", fileName); aheinecke@71: mSettings.setValue("List/availableDate", modDate); aheinecke@16: aheinecke@587: verifyListData(); aheinecke@71: if (!mListToInstall.isValid()) { aheinecke@71: /* Downloader provided invalid files */ aheinecke@71: /* TODO: Error count. Error handling. Otherwise aheinecke@71: * we can go into an endless loop here */ aheinecke@71: aheinecke@71: /* Retry the download again in 10 - 20 minutes */ aheinecke@71: QTimer::singleShot(600000 + (qrand() % 60000), this, SLOT(checkUpdates())); aheinecke@82: } else { aheinecke@82: mCurMessage = tr("An updated certificate list is available. Click here to install."); aheinecke@82: setState(NewListAvailable); aheinecke@82: showMessage(); rrenkert@189: loadCertificateList(); aheinecke@71: } aheinecke@16: } aheinecke@16: aheinecke@16: void MainWindow::handleNewSW(const QString& fileName, const QDateTime& modDate) { aheinecke@555: mCurMessage = tr("An update for %1 is available.\n" aheinecke@551: "Click here to download and install the update.").arg( aheinecke@16: QApplication::applicationName()); aheinecke@16: setState(NewSoftwareAvailable); aheinecke@16: mSettings.setValue("Software/available", fileName); aheinecke@16: mSettings.setValue("Software/availableDate", modDate); aheinecke@16: aheinecke@16: mSettings.sync(); aheinecke@16: showMessage(); aheinecke@16: } aheinecke@16: aheinecke@551: void MainWindow::installNewSW(const QString& fileName, const QDateTime& modDate) { aheinecke@551: QFileInfo instProcInfo = QFileInfo(fileName); aheinecke@563: QString filePath = QDir::toNativeSeparators(instProcInfo.absoluteFilePath()); aheinecke@592: aheinecke@592: if (verify_binary(filePath.toUtf8().constData(), aheinecke@592: filePath.toUtf8().size()) != VerifyValid) { aheinecke@592: qDebug() << "Invalid software. Not installing"; aheinecke@551: return; aheinecke@592: } aheinecke@592: QFileInfo fi(QCoreApplication::applicationFilePath()); aheinecke@592: QDir installDir = fi.absoluteDir(); aheinecke@592: aheinecke@551: #ifdef WIN32 aheinecke@594: QString parameters = QString::fromLatin1("/S /UPDATE=1 /D=") + aheinecke@594: installDir.path().replace("/", "\\") + ""; aheinecke@594: aheinecke@551: SHELLEXECUTEINFOW shExecInfo; aheinecke@563: memset (&shExecInfo, 0, sizeof(SHELLEXECUTEINFOW)); aheinecke@563: shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW); aheinecke@563: aheinecke@563: shExecInfo.lpFile = reinterpret_cast (filePath.utf16()); aheinecke@594: shExecInfo.lpParameters = reinterpret_cast (parameters.utf16()); aheinecke@563: aheinecke@594: // shExecInfo.fMask = SEE_MASK_NOASYNC; aheinecke@594: shExecInfo.nShow = SW_SHOWDEFAULT; aheinecke@551: aheinecke@551: if (!is_admin()) { aheinecke@551: shExecInfo.lpVerb = L"open"; aheinecke@551: } else { aheinecke@551: shExecInfo.lpVerb = L"runas"; aheinecke@551: } aheinecke@551: aheinecke@594: qDebug() << "Starting process: " << filePath aheinecke@594: << " with arguments: " << parameters; aheinecke@551: aheinecke@551: if (!ShellExecuteExW(&shExecInfo)) { aheinecke@551: /* Execution failed, maybe the user aborted the UAC check? */ aheinecke@551: char* errmsg = getLastErrorMsg(); aheinecke@551: QString qerrmsg = QString::fromUtf8(errmsg); aheinecke@551: free(errmsg); aheinecke@551: qDebug() << "Failed to start process: " << qerrmsg; aheinecke@551: setState(NewSoftwareAvailable); aheinecke@551: return; aheinecke@551: } aheinecke@551: #else /* WIN32 */ aheinecke@594: QStringList parameters; aheinecke@594: parameters << "/S" << "/UPDATE=1" aheinecke@594: << QString::fromLatin1("/D=%1").arg(installDir.path()); aheinecke@551: aheinecke@594: qDebug() << "Starting process " << filePath << " args: " << parameters; aheinecke@594: aheinecke@594: if (!QProcess::startDetached(filePath, parameters)) { aheinecke@551: qDebug() << "Failed to start process."; aheinecke@551: return; aheinecke@551: } aheinecke@551: #endif aheinecke@551: /* Installer process should now be running. We exit */ aheinecke@551: aheinecke@551: closeApp(); aheinecke@551: } aheinecke@551: rrenkert@461: void MainWindow::checkUpdates(bool downloadSW) aheinecke@16: { aheinecke@587: verifyListData(); aheinecke@16: aheinecke@551: if (!mSettings.contains("Software/installedDate") || aheinecke@551: mSettings.value("Software/installedVersion").toString() != QApplication::applicationVersion()) { aheinecke@551: /* This should only happen on initial startup and after an update has aheinecke@551: * been installed */ aheinecke@551: getLastModForCurrentVersion(); rrenkert@486: return; rrenkert@486: } aheinecke@17: QDateTime listInstalledLastMod = mSettings.value("List/installedDate").toDateTime(); aheinecke@17: QDateTime swInstalledLastMod = mSettings.value("Software/installedDate").toDateTime(); aheinecke@16: andre@389: QString listResource = QString::fromLatin1(LIST_RESOURCE); andre@389: QString swResource = QString::fromLatin1(SW_RESOURCE); andre@389: andre@389: #ifndef RELEASE_BUILD andre@389: /* Use this for testing to specify another file name for updates */ andre@389: listResource = mSettings.value("List/resource", listResource).toString(); andre@389: swResource = mSettings.value("Software/resource", swResource).toString(); andre@389: #endif andre@389: andre@389: aheinecke@72: Downloader* downloader = new Downloader(this, aheinecke@72: QString::fromLatin1(SERVER_URL), aheinecke@72: QByteArray(), aheinecke@551: swInstalledLastMod, aheinecke@72: listInstalledLastMod, aheinecke@437: swResource, rrenkert@461: listResource, rrenkert@461: downloadSW); aheinecke@17: aheinecke@16: connect(downloader, SIGNAL(newListAvailable(const QString&, const QDateTime&)), aheinecke@16: this, SLOT(handleNewList(const QString&, const QDateTime&))); rrenkert@461: if (!downloadSW) { andre@708: setState(BeforeDownload); rrenkert@461: connect(downloader, SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&)), aheinecke@551: this, SLOT(handleNewSW(const QString&, const QDateTime&))); aheinecke@551: } else { andre@708: setState(DownloadingSW); aheinecke@551: connect(downloader, SIGNAL(newSoftwareAvailable(const QString&, const QDateTime&)), aheinecke@551: this, SLOT(installNewSW(const QString&, const QDateTime&))); rrenkert@461: } aheinecke@551: aheinecke@16: connect(downloader, SIGNAL(finished()), downloader, SLOT(deleteLater())); andre@708: connect(downloader, SIGNAL(finished()), this, SLOT(updateCheckSuccess())); aheinecke@45: connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), aheinecke@45: this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); aheinecke@10: downloader->start(); aheinecke@0: } aheinecke@0: aheinecke@551: void MainWindow::getLastModForCurrentVersion() rrenkert@486: { rrenkert@486: QString softwareVersion = QString::fromLatin1(SW_RESOURCE_VERSION).arg( rrenkert@486: QApplication::applicationVersion()); rrenkert@486: qDebug() << softwareVersion; rrenkert@486: QString listResource = QString::fromLatin1(LIST_RESOURCE); rrenkert@486: Downloader* downloader = new Downloader(this, rrenkert@486: QString::fromLatin1(SERVER_URL), rrenkert@486: QByteArray(), rrenkert@486: QDateTime::currentDateTime(), rrenkert@486: QDateTime::currentDateTime(), rrenkert@486: softwareVersion, rrenkert@486: listResource, rrenkert@486: false); rrenkert@486: connect(downloader, SIGNAL(finished()), downloader, SLOT(deleteLater())); rrenkert@486: connect(downloader, SIGNAL(error(const QString &, SSLConnection::ErrorCode)), rrenkert@486: this, SLOT(downloaderError(const QString &, SSLConnection::ErrorCode))); rrenkert@486: connect(downloader, SIGNAL(lastModifiedDate(const QDateTime&)), aheinecke@551: this, SLOT(setLastModifiedSWDate(const QDateTime&))); rrenkert@486: rrenkert@486: downloader->start(); rrenkert@486: } rrenkert@486: aheinecke@551: void MainWindow::setLastModifiedSWDate(const QDateTime &date) rrenkert@486: { rrenkert@486: mSettings.beginGroup("Software"); rrenkert@486: mSettings.setValue("installedDate", date); aheinecke@551: mSettings.setValue("installedVersion", QApplication::applicationVersion()); rrenkert@486: mSettings.endGroup(); rrenkert@486: checkUpdates(); rrenkert@486: } rrenkert@486: aheinecke@45: void MainWindow::downloaderError(const QString &message, SSLConnection::ErrorCode error) aheinecke@16: { aheinecke@551: /* TODO logging and handle error according to a plan */ andre@708: syslog_error_printf ("Failed to check for updates: %s", message.toUtf8().constData()); aheinecke@16: mCurMessage = message; andre@27: showMessage(); aheinecke@551: setState(TransferError); aheinecke@16: } aheinecke@16: aheinecke@0: void MainWindow::createActions() aheinecke@0: { aheinecke@0: mCheckUpdates = new QAction(tr("Check for Updates"), this); aheinecke@16: connect(mCheckUpdates, SIGNAL(triggered()), this, SLOT(checkUpdates())); aheinecke@2: mQuitAction = new QAction(tr("Quit"), this); aheinecke@2: connect(mQuitAction, SIGNAL(triggered()), qApp, SLOT(quit())); aheinecke@0: } aheinecke@0: aheinecke@0: void MainWindow::createTrayIcon() aheinecke@0: { aheinecke@11: QIcon trayImg(":/img/tray_22.png"); aheinecke@0: aheinecke@0: mTrayMenu = new QMenu(this); aheinecke@0: mTrayMenu->addAction(mCheckUpdates); aheinecke@2: mTrayMenu->addAction(mQuitAction); aheinecke@0: aheinecke@0: mTrayIcon = new QSystemTrayIcon(this); aheinecke@0: mTrayIcon->setContextMenu(mTrayMenu); aheinecke@0: aheinecke@0: mTrayIcon->setIcon(trayImg); aheinecke@0: setWindowIcon(trayImg); aheinecke@0: mTrayIcon->show(); aheinecke@407: mTrayIcon->setToolTip(tr("TrustBridge")); aheinecke@71: aheinecke@71: connect(mTrayIcon, SIGNAL(messageClicked()), this, SLOT(messageClicked())); aheinecke@0: } rrenkert@155: andre@743: QWidget * MainWindow::createInfoWidget() andre@739: { andre@743: QWidget *theWidget = new QWidget; andre@739: QVBoxLayout *infoPanelLayout = new QVBoxLayout; andre@739: QHBoxLayout *infoHeaderLayout = new QHBoxLayout; andre@739: QVBoxLayout *infoHeaderTextLayout = new QVBoxLayout; andre@739: QVBoxLayout *infoCenterLayout = new QVBoxLayout; andre@739: andre@739: QImage *infoLogoImage = new QImage(":/img/logo.png"); andre@739: QLabel *infoLogo = new QLabel; andre@739: infoLogo->setBackgroundRole(QPalette::Base); andre@739: infoLogo->setPixmap(QPixmap::fromImage(*infoLogoImage)); andre@743: QLabel *infoTitle = new QLabel("

" + tr("TrustBridge") + "

"); andre@743: QString infoVersion = tr("Version: "); andre@739: infoVersion.append(QApplication::applicationVersion()); andre@739: QLabel *appVersion = new QLabel(infoVersion); andre@739: appVersion->setTextInteractionFlags( andre@739: Qt::TextSelectableByMouse | andre@739: Qt::TextSelectableByKeyboard); andre@739: andre@739: QFrame *infoHeaderSeparator = new QFrame(); andre@739: infoHeaderSeparator->setFrameShape(QFrame::HLine); andre@739: infoHeaderSeparator->setFrameShadow(QFrame::Sunken); andre@739: andre@739: infoHeaderTextLayout->addWidget(infoTitle); andre@739: infoHeaderTextLayout->addWidget(appVersion); andre@739: infoHeaderLayout->addWidget(infoLogo); andre@739: infoHeaderLayout->addLayout(infoHeaderTextLayout); andre@739: infoHeaderLayout->insertStretch(2, 10); andre@739: andre@743: QLabel *textDesc = new QLabel(tr("TrustBridge is a root certificate" andre@739: " installer for Windows and Linux.")); andre@739: textDesc->setTextInteractionFlags( andre@739: Qt::TextSelectableByMouse | andre@739: Qt::TextSelectableByKeyboard); andre@743: QLabel *textManage = new QLabel(tr("The root certificate lists are managed" andre@739: " by the German " andre@739: "Federal Office for Information Security (BSI).\n\n")); andre@739: textManage->setTextInteractionFlags( andre@739: Qt::TextBrowserInteraction | andre@739: Qt::TextSelectableByKeyboard); andre@743: QLabel *textDevel = new QLabel(tr("The software was developed by the companies" andre@739: " Intevation GmbH and " andre@739: " DN-Systems GmbH,
" andre@739: " contracted by the German Federal Office for Information Security (BSI).\n\n")); andre@739: textDevel->setTextInteractionFlags( andre@739: Qt::TextBrowserInteraction | andre@739: Qt::TextSelectableByKeyboard); andre@743: QLabel *textLicense = new QLabel(tr("TrustBridge is Free Software licensed" andre@739: " under GNU GPL v2+.\n\nCopyright (C) 2014 by Bundesamt für Sicherheit" andre@739: " in der Informationstechnik")); andre@739: textLicense->setTextInteractionFlags( andre@739: Qt::TextSelectableByMouse | andre@739: Qt::TextSelectableByKeyboard); andre@739: andre@739: infoCenterLayout->addWidget(infoHeaderSeparator); andre@739: infoCenterLayout->addWidget(textDesc); andre@739: infoCenterLayout->addWidget(textManage); andre@739: infoCenterLayout->addWidget(textDevel); andre@739: infoCenterLayout->addWidget(textLicense); andre@739: infoCenterLayout->insertSpacing(2, 10); andre@739: infoCenterLayout->insertSpacing(4, 10); andre@739: infoCenterLayout->insertSpacing(6, 10); andre@739: infoCenterLayout->insertStretch(8, 10); andre@739: andre@739: infoPanelLayout->addLayout(infoHeaderLayout); andre@739: infoPanelLayout->addLayout(infoCenterLayout); andre@743: theWidget->setLayout(infoPanelLayout); andre@743: andre@743: return theWidget; andre@743: } andre@743: andre@743: QWidget * MainWindow::createUpdatesWidget() andre@743: { andre@743: QWidget * theWidget = new QWidget; andre@743: QVBoxLayout *updatesMainLayout = new QVBoxLayout; andre@743: andre@743: /* The header */ andre@743: QGridLayout *updatesHeaderLayout = new QGridLayout; andre@743: andre@743: /* Header 1: Update date and search button */ andre@787: QHBoxLayout *updateDateAndSearchButton = new QHBoxLayout; andre@743: mUpdatesHeader = andre@743: new QLabel("

" + tr("Certificates unchanged")+ "

"); andre@743: mLastCertUpdate = andre@754: new QLabel(tr("Installed certificates from:")); andre@754: mLastCertUpdateContents = new QLabel(QString()); andre@743: mLastCertUpdate->hide(); andre@754: mLastCertUpdateContents->hide(); andre@743: mSoftwareVersionLabel = andre@754: new QLabel(tr("TrustBridge Version:")); andre@754: mSoftwareVersionContents = new QLabel(QApplication::applicationVersion()); andre@787: andre@743: const QDateTime lastCheck = mSettings.value("lastUpdateCheck").toDateTime().toLocalTime(); andre@743: if (lastCheck.isValid()) { andre@743: const QString lastUpdateCheck = QLocale::system().toString(lastCheck, DATETIME_FORMAT); andre@743: mLastUpdateCheck = andre@781: new QLabel(tr("Last successful update check:")); andre@754: mLastUpdateCheckContents = new QLabel(lastUpdateCheck); andre@743: } else { andre@754: mLastUpdateCheck = new QLabel(tr("Last successful update check:")); andre@754: mLastUpdateCheckContents = new QLabel(QString()); andre@743: mLastUpdateCheck->hide(); andre@754: mLastUpdateCheckContents->hide(); andre@743: } andre@787: QPushButton *searchUpdates = new QPushButton(); andre@787: searchUpdates->setStyleSheet("QPushButton {border-style: outset; border-width: 0px;}"); andre@787: searchUpdates->setToolTip(tr("Check for updates")); andre@787: searchUpdates->setIcon(QIcon(":/img/update-list.png")); andre@743: connect(searchUpdates, SIGNAL(clicked()), this, SLOT(checkUpdates())); andre@787: updateDateAndSearchButton->addWidget(mLastUpdateCheckContents); andre@787: updateDateAndSearchButton->addWidget(searchUpdates); andre@743: andre@743: // addWidget(*Widget, row, column, rowspan, colspan, [Qt::Alignment]) andre@743: updatesHeaderLayout->addWidget(mUpdatesHeader, 0, 0, 1, 2); andre@743: updatesHeaderLayout->addWidget(mSoftwareVersionLabel, 1, 0, 1, 1); andre@754: updatesHeaderLayout->addWidget(mSoftwareVersionContents, 1, 1, 1, 1); andre@743: updatesHeaderLayout->addWidget(mLastUpdateCheck, 2, 0, 1, 1); andre@787: updatesHeaderLayout->addLayout(updateDateAndSearchButton, 2, 1, 1, 1); andre@787: // updatesHeaderLayout->addWidget(mLastUpdateCheckContents, 2, 1, 1, 1); andre@743: updatesHeaderLayout->addWidget(mLastCertUpdate, 3, 0, 1, 1); andre@754: updatesHeaderLayout->addWidget(mLastCertUpdateContents, 3, 1, 1, 1); andre@754: updatesHeaderLayout->setColumnStretch(3, 1); andre@754: andre@787: // updatesHeaderLayout->addWidget(searchUpdates, 1, 4, 1, 2, Qt::AlignRight); andre@743: updatesHeaderLayout->setRowMinimumHeight(4, 15); andre@743: andre@743: /* Header 2: Action text and buttons */ andre@743: mUpdatesTip = andre@743: new QLabel(tr("There are currently no changes for your certificate stores.")); andre@743: mUpdatesTip->setWordWrap(true); andre@743: QHBoxLayout *updatesHeaderActionButtonLayout = new QHBoxLayout; andre@743: mQuitButton = new QPushButton(" " + tr("Quit without saving")); andre@743: mQuitButton->setIcon(QIcon(":/img/application-exit.png")); andre@743: mQuitButton->setFixedHeight(30); andre@743: andre@743: mInstallButton = new QPushButton(" " + tr("Install certificates again")); andre@743: mInstallButton->setFixedHeight(30); andre@743: #ifdef Q_OS_WIN andre@743: if (is_admin()) { andre@743: QIcon uacShield = QApplication::style()->standardIcon(QStyle::SP_VistaShield); andre@743: mInstallButton->setIcon(uacShield); andre@743: } andre@743: #else andre@743: mInstallButton->setIcon(QIcon(":/img/view-refresh_16px.png")); andre@743: #endif andre@743: connect(mQuitButton, SIGNAL(clicked()), this, SLOT(closeApp())); andre@743: connect(mInstallButton, SIGNAL(clicked()), this, SLOT(checkAndInstallCerts())); andre@743: andre@743: // addWidget(*Widget, row, column, rowspan, colspan) andre@754: updatesHeaderLayout->addWidget(mUpdatesTip, 5, 0, 1, 4); andre@743: updatesHeaderActionButtonLayout->addWidget(mInstallButton); andre@743: updatesHeaderActionButtonLayout->addWidget(mQuitButton); andre@754: updatesHeaderLayout->addLayout(updatesHeaderActionButtonLayout, 6, 0, 1, 3, Qt::AlignLeft); andre@743: updatesHeaderLayout->setRowMinimumHeight(7, 10); andre@743: andre@743: /* The central panels. */ andre@743: QScrollArea *centralScrollArea = new QScrollArea; andre@743: QVBoxLayout *updatesCenterLayout = new QVBoxLayout; andre@743: QHBoxLayout *updatesNewLayout = new QHBoxLayout; andre@743: QHBoxLayout *updatesRemoveLayout = new QHBoxLayout; andre@743: QHBoxLayout *updatesManualLayout = new QHBoxLayout; andre@743: mUpdatesNewCertificates = andre@743: new QLabel("

" + andre@743: tr("Install new trusted certificates (%1/%2)").arg(0).arg(0) + andre@743: "

"); andre@743: mUpdatesDetailsNew = new QPushButton(tr("Show details")); andre@743: connect(mUpdatesDetailsNew, andre@743: SIGNAL(clicked()), andre@743: this, andre@743: SLOT(toggleUpdatesNew())); andre@743: updatesNewLayout->addWidget(mUpdatesNewCertificates); andre@743: updatesNewLayout->addStretch(1); andre@743: updatesNewLayout->addWidget(mUpdatesDetailsNew); andre@743: mUpdatesNew = new CertificateListWidget(this); andre@743: connect(mUpdatesNew, SIGNAL(certListChanged(int)), andre@743: this, SLOT(listChanged(int))); andre@743: mUpdatesNew->hide(); andre@743: andre@743: mUpdatesRemoveCertificates = andre@743: new QLabel("

" + andre@743: tr("Remove revoked certificates (%1/%2)").arg(0).arg(0) + andre@743: "

"); andre@743: mUpdatesDetailsRemove = new QPushButton(tr("Show details")); andre@743: connect(mUpdatesDetailsRemove, andre@743: SIGNAL(clicked()), andre@743: this, andre@743: SLOT(toggleUpdatesRemove())); andre@743: updatesRemoveLayout->addWidget(mUpdatesRemoveCertificates); andre@746: updatesRemoveLayout->addStretch(1); andre@743: updatesRemoveLayout->addWidget(mUpdatesDetailsRemove); andre@743: mUpdatesRemove = new CertificateListWidget(this); andre@743: connect(mUpdatesRemove, SIGNAL(certListChanged(int)), andre@743: this, SLOT(listChanged(int))); andre@743: mUpdatesRemove->hide(); andre@743: andre@743: mUpdatesManualCertificates = andre@743: new QLabel("

" + andre@743: tr("Manually changed certificates (%1)").arg(0) + andre@743: "

"); andre@743: mUpdatesDetailsManual = new QPushButton(tr("Show details")); andre@743: connect(mUpdatesDetailsManual, andre@743: SIGNAL(clicked()), andre@743: this, andre@743: SLOT(toggleUpdatesManual())); andre@743: mUpdatesDetailsManual->hide(); andre@743: mUpdatesManualCertificates->hide(); andre@743: updatesManualLayout->addWidget(mUpdatesManualCertificates); andre@747: updatesManualLayout->addStretch(1); andre@743: updatesManualLayout->addWidget(mUpdatesDetailsManual); andre@743: mUpdatesManual = new CertificateListWidget(this); andre@743: mUpdatesManual->hide(); andre@743: connect(mUpdatesManual, SIGNAL(certChanged(bool, const Certificate&)), andre@743: this, SLOT(removeFromManual(bool, const Certificate&))); andre@743: connect(mUpdatesManual, SIGNAL(certListChanged(int)), andre@743: this, SLOT(listChanged(int))); andre@743: andre@743: updatesNewLayout->setAlignment(Qt::AlignTop); andre@743: updatesRemoveLayout->setAlignment(Qt::AlignTop); andre@743: updatesManualLayout->setAlignment(Qt::AlignTop); andre@743: updatesCenterLayout->addLayout(updatesNewLayout); andre@743: updatesCenterLayout->addWidget(mUpdatesNew); andre@743: updatesCenterLayout->addLayout(updatesRemoveLayout); andre@743: updatesCenterLayout->addWidget(mUpdatesRemove); andre@743: updatesCenterLayout->addLayout(updatesManualLayout); andre@743: updatesCenterLayout->addWidget(mUpdatesManual); andre@743: andre@743: QWidget *dummyWidget = new QWidget; andre@743: dummyWidget->setLayout(updatesCenterLayout); andre@743: centralScrollArea->setWidgetResizable(true); andre@743: centralScrollArea->setWidget(dummyWidget); andre@743: centralScrollArea->setFrameShape(QFrame::NoFrame); andre@743: centralScrollArea->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); andre@743: andre@743: updatesMainLayout->addLayout(updatesHeaderLayout); andre@743: updatesMainLayout->addWidget(centralScrollArea); andre@743: updatesCenterLayout->addSpacerItem(new QSpacerItem(0, 0, andre@743: QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding)); andre@743: theWidget->setLayout(updatesMainLayout); andre@743: return theWidget; andre@743: } andre@743: andre@743: andre@743: QWidget *MainWindow::createInstallWidget() andre@743: { andre@743: QWidget *theWidget = new QWidget; andre@743: QScrollArea *scrollArea = new QScrollArea; andre@743: QVBoxLayout *installPanelLayout = new QVBoxLayout; andre@743: QVBoxLayout *installHeaderLayout = new QVBoxLayout; andre@743: QVBoxLayout *installCenterLayout = new QVBoxLayout; andre@743: andre@743: QLabel *installHeaderLabel = andre@743: new QLabel("

" + tr("Trusted certificates") + "

"); andre@743: QLabel *installHeaderText = new QLabel(tr("The following list of trusted root" andre@743: " certificates is managed by the BSI. The BSI validates independently the" andre@743: " authenticity, security and actuality of these certificates.")); andre@743: installHeaderText->setWordWrap(true); andre@743: installHeaderLayout->addWidget(installHeaderLabel); andre@743: installHeaderLayout->addWidget(installHeaderText); andre@743: andre@743: QLabel *installCenterText = new QLabel(tr("Please choose the certificates" andre@743: " you want to trust or untrust. TrustBridge will install these certificates for your" andre@743: " secure communication for email and internet.")); andre@743: installCenterText->setWordWrap(true); andre@743: installCenterLayout->addWidget(installCenterText); andre@743: andre@743: installPanelLayout->addLayout(installHeaderLayout); andre@743: installPanelLayout->addLayout(installCenterLayout); andre@743: andre@743: mInstallList = new CertificateListWidget(this); andre@743: connect(mInstallList, SIGNAL(certChanged(bool, const Certificate&)), andre@743: this, SLOT(toggleInManual(bool, const Certificate&))); andre@743: andre@743: scrollArea->setWidgetResizable(true); andre@743: scrollArea->setWidget(mInstallList); andre@743: scrollArea->setFrameShape(QFrame::NoFrame); andre@743: andre@743: installPanelLayout->addWidget(scrollArea); andre@743: andre@743: theWidget->setLayout(installPanelLayout); andre@743: andre@743: return theWidget; andre@743: } andre@743: andre@743: QWidget *MainWindow::createRemoveWidget() andre@743: { andre@743: QWidget * theWidget = new QWidget; andre@743: QScrollArea *scrollArea = new QScrollArea; andre@743: QVBoxLayout *removePanelLayout = new QVBoxLayout; andre@743: QVBoxLayout *removeHeaderLayout = new QVBoxLayout; andre@743: QVBoxLayout *removeCenterLayout = new QVBoxLayout; andre@743: andre@743: QLabel *removeHeaderLabel = andre@743: new QLabel("

" + tr("Revoked certificates") + "

"); andre@743: QLabel *removeHeaderText = new QLabel(tr("Certificates can be corrupted" andre@743: " or stolen and misused in many ways. Therefore the BSI recommends" andre@743: " to remove all revoked certificates from your system.")); andre@743: removeHeaderText->setWordWrap(true); andre@743: removeHeaderLayout->addWidget(removeHeaderLabel); andre@743: removeHeaderLayout->addWidget(removeHeaderText); andre@743: andre@743: QLabel *removeCenterText = new QLabel(tr("The follwing unsecure certificates were" andre@743: " revoked by the BSI. Already uninstalled certificates cannot be reinstalled." andre@743: " It is recommended that you select all certificates to uninstall if you still" andre@743: " have revoked certificates installed.")); andre@743: removeCenterText->setWordWrap(true); andre@743: removeCenterLayout->addWidget(removeCenterText); andre@743: mRemoveList = new CertificateListWidget(this); andre@743: connect(mRemoveList, SIGNAL(certChanged(bool, const Certificate&)), andre@743: this, SLOT(toggleInManual(bool, const Certificate&))); andre@743: andre@743: removePanelLayout->addLayout(removeHeaderLayout); andre@743: removePanelLayout->addLayout(removeCenterLayout); andre@743: andre@743: scrollArea->setWidgetResizable(true); andre@743: scrollArea->setWidget(mRemoveList); andre@743: scrollArea->setFrameShape(QFrame::NoFrame); andre@743: removePanelLayout->addWidget(scrollArea); andre@743: theWidget->setLayout(removePanelLayout); andre@743: andre@743: return theWidget; andre@739: } andre@739: andre@739: void MainWindow::setupGUI() rrenkert@187: { rrenkert@187: // Create a central widget containing the main layout. rrenkert@187: QWidget *base = new QWidget; rrenkert@187: rrenkert@250: // Layouts and Container rrenkert@584: QVBoxLayout *mainLayout = new QVBoxLayout; rrenkert@205: QHBoxLayout *headerLayout = new QHBoxLayout; rrenkert@205: QVBoxLayout *headerTextLayout = new QVBoxLayout; rrenkert@584: QHBoxLayout *centerLayout = new QHBoxLayout; rrenkert@584: QVBoxLayout *buttonBarLayout = new QVBoxLayout; rrenkert@271: QHBoxLayout *bottomLayout = new QHBoxLayout; rrenkert@584: QHBoxLayout *containerLayout = new QHBoxLayout; rrenkert@187: rrenkert@584: // The header (icon, about text) rrenkert@584: QImage *logoImage = new QImage(":/img/logo.png"); rrenkert@584: QLabel *logo = new QLabel; rrenkert@584: logo->setBackgroundRole(QPalette::Base); rrenkert@584: logo->setPixmap(QPixmap::fromImage(*logoImage)); rrenkert@584: QLabel *title = new QLabel("

" + QString::fromLatin1(APPNAME) + "

"); emanuel@689: QLabel *subTitle = new QLabel(tr("Trust in your digital communication")); rrenkert@584: headerTextLayout->addWidget(title); rrenkert@584: headerTextLayout->addWidget(subTitle); rrenkert@584: headerLayout->addWidget(logo); rrenkert@584: headerLayout->addLayout(headerTextLayout); rrenkert@584: headerLayout->setStretch(0, 0); rrenkert@584: headerLayout->setStretch(1, 10); rrenkert@584: rrenkert@652: /*********************************** rrenkert@652: * The Buttonbar on the left side. rrenkert@652: ***********************************/ rrenkert@584: mButtonGroup = new QButtonGroup; rrenkert@584: andre@722: TextOverlayButton *updatesButton = new TextOverlayButton; rrenkert@584: updatesButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); rrenkert@584: updatesButton->setIcon(QIcon(":/img/view-refresh.png")); emanuel@732: updatesButton->setIconSize(QSize(48, 48)); emanuel@713: updatesButton->setText(tr("Updates")); emanuel@663: updatesButton->setFixedWidth(120); emanuel@732: updatesButton->setFixedHeight(90); rrenkert@584: updatesButton->setCheckable(true); rrenkert@584: updatesButton->setChecked(true); rrenkert@584: andre@722: connect(this, SIGNAL(changesChanged(const QString&)), andre@722: updatesButton, SLOT(setOverlay(const QString&))); andre@722: rrenkert@584: QToolButton *allInstallButton = new QToolButton; rrenkert@584: allInstallButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); rrenkert@584: allInstallButton->setIcon(QIcon(":/img/document-encrypt.png")); emanuel@732: allInstallButton->setIconSize(QSize(48, 48)); emanuel@659: allInstallButton->setText(tr("Trusted\ncertificates")); emanuel@663: allInstallButton->setFixedWidth(120); emanuel@732: allInstallButton->setFixedHeight(90); rrenkert@584: allInstallButton->setCheckable(true); rrenkert@584: rrenkert@584: QToolButton *allRemoveButton = new QToolButton; rrenkert@584: allRemoveButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); emanuel@673: allRemoveButton->setIcon(QIcon(":/img/dialog-warning.png")); emanuel@732: allRemoveButton->setIconSize(QSize(48, 48)); emanuel@661: allRemoveButton->setText(tr("Revoked\ncertificates")); emanuel@663: allRemoveButton->setFixedWidth(120); emanuel@732: allRemoveButton->setFixedHeight(90); rrenkert@584: allRemoveButton->setCheckable(true); rrenkert@584: rrenkert@584: QToolButton *infoButton = new QToolButton; rrenkert@584: infoButton->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); rrenkert@584: infoButton->setIcon(QIcon(":/img/dialog-information.png")); emanuel@732: infoButton->setIconSize(QSize(48, 48)); emanuel@659: infoButton->setText(tr("Information\nand help")); emanuel@663: infoButton->setFixedWidth(120); emanuel@732: infoButton->setFixedHeight(90); rrenkert@584: infoButton->setCheckable(true); rrenkert@584: rrenkert@584: mButtonGroup->addButton(updatesButton); rrenkert@584: mButtonGroup->addButton(allInstallButton); rrenkert@584: mButtonGroup->addButton(allRemoveButton); rrenkert@584: mButtonGroup->addButton(infoButton); rrenkert@584: mButtonGroup->setId(updatesButton, 0); rrenkert@584: mButtonGroup->setId(allInstallButton, 1); rrenkert@584: mButtonGroup->setId(allRemoveButton, 2); rrenkert@584: mButtonGroup->setId(infoButton, 3); rrenkert@584: rrenkert@584: connect(mButtonGroup, SIGNAL(buttonClicked(int)), rrenkert@584: this, SLOT(togglePages(int))); rrenkert@584: buttonBarLayout->addWidget(updatesButton); rrenkert@584: buttonBarLayout->addWidget(allInstallButton); rrenkert@584: buttonBarLayout->addWidget(allRemoveButton); rrenkert@584: buttonBarLayout->insertStretch(3, 10); rrenkert@584: buttonBarLayout->addWidget(infoButton); rrenkert@584: andre@743: /* The main pages.*/ rrenkert@584: andre@743: /* The updates page. */ andre@743: mUpdatesWidget = createUpdatesWidget(); rrenkert@584: andre@743: /* Install (trusted certs) Page */ andre@743: mInstallWidget = createInstallWidget(); rrenkert@584: rrenkert@652: /********************************** andre@743: * Page for certificates to be removed. rrenkert@652: **********************************/ andre@743: mRemoveWidget = createRemoveWidget(); rrenkert@584: rrenkert@652: /********************************** andre@743: * The info page. rrenkert@652: **********************************/ andre@743: mInfoWidget = createInfoWidget(); rrenkert@584: rrenkert@652: /******************************** rrenkert@652: * The main layout for pages. rrenkert@652: ********************************/ andre@743: mInstallWidget->hide(); andre@743: mRemoveWidget->hide(); andre@743: mInfoWidget->hide(); andre@743: containerLayout->addWidget(mUpdatesWidget); andre@743: containerLayout->addWidget(mInstallWidget); andre@743: containerLayout->addWidget(mRemoveWidget); andre@743: containerLayout->addWidget(mInfoWidget); rrenkert@584: rrenkert@584: centerLayout->addLayout(buttonBarLayout); rrenkert@584: centerLayout->addLayout(containerLayout); rrenkert@584: rrenkert@584: mainLayout->addLayout(headerLayout); rrenkert@584: mainLayout->addLayout(centerLayout); rrenkert@584: mainLayout->addLayout(bottomLayout); rrenkert@187: base->setLayout(mainLayout); rrenkert@187: setCentralWidget(base); rrenkert@187: } rrenkert@187: rrenkert@628: void MainWindow::listChanged(int selected) rrenkert@628: { andre@716: Q_UNUSED (selected); andre@722: setChangeCount(mUpdatesRemove->selectedCertCount() + andre@722: mUpdatesNew->selectedCertCount() + mUpdatesManual->certificates().size()); andre@696: andre@718: /* Show a different tip in case of manual changes, updates aviailable, updates and manual andre@718: * changes available */ andre@718: if (changeCount() && !mUpdatesManual->certificates().size()) { andre@718: mUpdatesTip->setText( andre@718: tr("You should apply the following, recommended changes to your certificate stores.")); andre@718: } else if (changeCount()) { andre@718: mUpdatesTip->setText( andre@718: tr("You can apply the following, changes to your certificate stores.")); andre@718: } else { andre@718: mUpdatesTip->setText( andre@718: tr("There are currently no changes for your certificate stores.")); andre@718: } andre@718: andre@716: if (!changeCount()) { andre@693: /* No changes */ andre@702: mQuitButton->setText(" " + tr("Quit")); andre@696: mUpdatesHeader->setText("

" + tr("Certificates unchanged") + andre@696: "

"); andre@718: mInstallButton->setText(" " + tr("Install certificates again")); andre@693: } else { andre@702: mQuitButton->setText(" " + tr("Quit without saving")); emanuel@713: mUpdatesHeader->setText("

" + tr("Changes to certificate stores (%1)") andre@716: .arg(changeCount()) + andre@696: "

"); andre@718: mInstallButton->setText(" " + tr("Apply changes")); andre@693: } andre@693: andre@719: if (mUpdatesManual->certificates().size()) { andre@719: mUpdatesDetailsManual->show(); andre@719: mUpdatesDetailsManual->setText(tr("Show details")); andre@719: mUpdatesManualCertificates->show(); andre@719: } else { andre@719: mUpdatesDetailsManual->hide(); andre@719: mUpdatesManualCertificates->hide(); andre@719: mUpdatesManual->hide(); andre@719: } andre@719: andre@717: if (mUpdatesNew->certificates().size()) { andre@717: mUpdatesNewCertificates->setText("

" + andre@717: tr("Install new trusted certificates (%1/%2)") andre@717: .arg(mUpdatesNew->selectedCertCount()) andre@717: .arg(mUpdatesNew->certificates().size()) + andre@717: "

"); andre@717: mUpdatesDetailsNew->show(); andre@719: mUpdatesDetailsNew->setText(tr("Show details")); andre@717: mUpdatesNewCertificates->show(); andre@717: } else { andre@717: mUpdatesDetailsNew->hide(); andre@719: mUpdatesNew->hide(); andre@717: mUpdatesNewCertificates->hide(); andre@717: } andre@717: andre@717: if (mUpdatesRemove->certificates().size()) { andre@717: mUpdatesRemoveCertificates->setText("

" + andre@717: tr("Remove revoked certificates (%1/%2)") andre@717: .arg(mUpdatesRemove->selectedCertCount()) andre@717: .arg(mUpdatesRemove->certificates().size()) + andre@717: "

"); andre@717: mUpdatesRemoveCertificates->show(); andre@719: mUpdatesDetailsRemove->setText(tr("Show details")); andre@717: mUpdatesDetailsRemove->show(); andre@717: } else { andre@717: mUpdatesRemoveCertificates->hide(); andre@717: mUpdatesDetailsRemove->hide(); andre@719: mUpdatesRemove->hide(); andre@717: } rrenkert@628: } rrenkert@628: rrenkert@189: void MainWindow::loadCertificateList() rrenkert@189: { andre@389: /* TODO: if nothing is available (neither old nor new) add some progress andre@389: * indication */ rrenkert@628: mInstallList->clear(); andre@684: mRemoveList->clear(); rrenkert@628: mUpdatesNew->clear(); rrenkert@628: mUpdatesRemove->clear(); rrenkert@445: QList newInstallCerts; rrenkert@445: QList newRemoveCerts; rrenkert@445: QList oldInstallCerts; rrenkert@445: QList oldRemoveCerts; andre@389: rrenkert@445: if (mListToInstall.getCertificates().isEmpty()) { rrenkert@445: // No new list available, add old certificates. rrenkert@445: foreach (const Certificate &cert, mInstalledList.getCertificates()) { rrenkert@640: bool state = !mPreviouslyUnselected.contains(cert.base64Line()); rrenkert@445: if (cert.isInstallCert()) { rrenkert@445: oldInstallCerts.append(cert); rrenkert@640: mInstallList->addCertificate(cert, state); rrenkert@267: } rrenkert@267: else { rrenkert@445: oldRemoveCerts.append(cert); rrenkert@640: mRemoveList->addCertificate(cert, state, !state); rrenkert@267: } rrenkert@267: } rrenkert@445: } rrenkert@445: else { rrenkert@445: // Sort and filter both lists. rrenkert@445: foreach (const Certificate &cert, mListToInstall.getCertificates()) { rrenkert@640: bool state = !mPreviouslyUnselected.contains(cert.base64Line()); rrenkert@445: if (cert.isInstallCert()) { rrenkert@445: // Certificate with status "install". rrenkert@445: if (mInstalledList.getCertificates().contains(cert)) { rrenkert@445: // Was in the old list. rrenkert@445: oldInstallCerts.append(cert); rrenkert@640: mInstallList->addCertificate(cert, state); rrenkert@445: } rrenkert@445: else { rrenkert@445: // Is a brand new certificate rrenkert@445: newInstallCerts.append(cert); andre@687: mUpdatesNew->addCertificate(cert, state, true, andre@687: tr("install"), tr("ignore")); rrenkert@445: } rrenkert@267: } rrenkert@267: else { rrenkert@445: // Certificate with status "remove". rrenkert@445: if (mInstalledList.getCertificates().contains(cert)) { rrenkert@445: // Was in the old list. rrenkert@445: oldRemoveCerts.append(cert); rrenkert@640: // Is removed, so set editable to false. rrenkert@640: mRemoveList->addCertificate(cert, state, !state); rrenkert@445: } rrenkert@445: else { rrenkert@445: // Was in the old list with status "install" and now has the rrenkert@445: // status "remove". rrenkert@445: newRemoveCerts.append(cert); rrenkert@640: mUpdatesRemove->addCertificate(cert, state); rrenkert@445: } rrenkert@267: } rrenkert@267: } andre@691: } andre@692: andre@708: if (mInstalledList.date().isValid()) { andre@754: mLastCertUpdateContents->setText(QLocale::system().toString(mInstalledList.date().toLocalTime(), andre@754: DATETIME_FORMAT)); andre@708: mLastCertUpdate->show(); andre@754: mLastCertUpdateContents->show(); andre@708: } rrenkert@628: mUpdatesManualCertificates->setText("

" + emanuel@659: tr("Manually changed certificates (%1)").arg(0) + rrenkert@628: "

"); andre@692: listChanged(0); rrenkert@271: } aheinecke@365: aheinecke@365: void MainWindow::installerError(const QString& errMsg) { aheinecke@365: QMessageBox::warning(this, tr("Error executing update"), errMsg); aheinecke@365: } aheinecke@365: andre@389: void MainWindow::installerSuccess() { andre@389: if (mCurState == NewListAvailable) { andre@389: mCurState = NothingChanged; andre@389: mCurMessage = QString(); andre@389: andre@389: QString listFileName = mSettings.value("List/available").toString(); andre@389: QDateTime listFileDate = mSettings.value("List/availableDate").toDateTime(); andre@389: andre@389: mSettings.remove("List/available"); andre@389: mSettings.remove("List/availableDate"); andre@389: andre@389: if (listFileName.isEmpty() || !listFileDate.isValid()) { andre@389: qWarning() << "Error accessing settings"; andre@389: return; /* Try again with next check */ andre@389: } andre@389: andre@389: mSettings.setValue("List/installed", listFileName); andre@389: mSettings.setValue("List/installedDate", listFileDate); rrenkert@480: mInstalledList = mListToInstall; rrenkert@480: mListToInstall = CertificateList(); andre@389: } andre@684: mUpdatesManual->clear(); rrenkert@628: loadCertificateList(); andre@389: } andre@389: aheinecke@365: void MainWindow::installCerts() { aheinecke@365: QStringList choices; rrenkert@640: QStringList unselected; aheinecke@365: rrenkert@640: choices << mUpdatesNew->selectedCertificates(); rrenkert@640: choices << mUpdatesRemove->selectedCertificates(); rrenkert@640: andre@669: choices << mUpdatesManual->selectedCertificates(); andre@669: andre@669: /* Also include the old certificates */ andre@669: choices << mInstallList->selectedCertificates(); andre@669: choices << mRemoveList->selectedCertificates(); andre@669: rrenkert@640: QStringList unselectedManuals = mUpdatesManual->unselectedCertificates(); rrenkert@640: for(int i = 0; i < unselectedManuals.size(); i++) { rrenkert@640: if (unselectedManuals.at(i).startsWith("I:")) { rrenkert@640: QString certLine = unselectedManuals.at(i); rrenkert@640: certLine[0] = 'R'; rrenkert@640: choices << certLine; rrenkert@640: } rrenkert@640: } rrenkert@640: rrenkert@640: unselected << mUpdatesNew->unselectedCertificates(); rrenkert@640: unselected << mUpdatesRemove->unselectedCertificates(); rrenkert@640: unselected << mInstallList->unselectedCertificates(); rrenkert@640: unselected << mRemoveList->unselectedCertificates(); rrenkert@628: aheinecke@365: QProgressDialog *progress = new QProgressDialog(this); aheinecke@365: progress->setWindowModality(Qt::WindowModal); aheinecke@365: progress->setLabelText(tr("Installing certificates...")); aheinecke@365: progress->setCancelButton(0); aheinecke@365: progress->setRange(0,0); aheinecke@365: progress->setMinimumDuration(0); aheinecke@365: progress->show(); aheinecke@365: aheinecke@365: InstallWrapper *instWrap = new InstallWrapper(this, andre@393: mListToInstall.isValid() ? andre@393: mListToInstall.fileName() : andre@393: mInstalledList.fileName(), aheinecke@365: choices); aheinecke@365: /* Clean up object and progress dialog */ aheinecke@365: connect(instWrap, SIGNAL(finished()), instWrap, SLOT(deleteLater())); aheinecke@365: connect(instWrap, SIGNAL(finished()), progress, SLOT(deleteLater())); aheinecke@365: connect(instWrap, SIGNAL(finished()), progress, SLOT(cancel())); andre@389: connect(instWrap, SIGNAL(installationSuccessful()), andre@389: this, SLOT(installerSuccess())); aheinecke@365: connect(instWrap, SIGNAL(error(const QString &)), andre@389: this, SLOT(installerError(const QString &))); aheinecke@365: instWrap->start(); rrenkert@640: rrenkert@640: if (!saveUnselectedCertificates(unselected)) { andre@372: qWarning() << "Failed to save previosly unselected certificates."; andre@372: } rrenkert@640: aheinecke@365: } andre@372: andre@372: void MainWindow::loadUnselectedCertificates() andre@372: { andre@372: mPreviouslyUnselected.clear(); andre@372: mSettings.beginGroup("unselected"); andre@372: QStringList keys = mSettings.allKeys(); andre@372: foreach (const QString &key, keys) { andre@372: mPreviouslyUnselected << mSettings.value(key, QString()).toString(); andre@372: } andre@372: mSettings.endGroup(); andre@372: } andre@372: rrenkert@640: bool MainWindow::saveUnselectedCertificates(QStringList unselected) andre@372: { rrenkert@479: mPreviouslyUnselected.clear(); andre@372: mSettings.beginGroup("unselected"); andre@372: mSettings.remove(""); /* Clears old choices */ rrenkert@640: for (int i = 0; i < unselected.size(); i++) { rrenkert@640: QString key = QString::fromLatin1("cert%1").arg(i); rrenkert@640: QString value = unselected.at(i); rrenkert@640: mSettings.setValue(key, value); rrenkert@640: mPreviouslyUnselected << value; andre@372: } andre@372: mSettings.endGroup(); andre@372: mSettings.sync(); andre@372: return mSettings.status() == QSettings::NoError; andre@372: } rrenkert@447: rrenkert@640: void MainWindow::toggleInManual(bool state, const Certificate &cert) rrenkert@640: { rrenkert@640: if (!mUpdatesManual->contains(cert)) { rrenkert@640: mUpdatesManual->addCertificate(cert, state); rrenkert@640: } rrenkert@640: else { rrenkert@640: mUpdatesManual->removeCertificate(cert); rrenkert@640: } rrenkert@640: rrenkert@640: mUpdatesManualCertificates->setText("

" + emanuel@661: tr("Manually changed certificates (%1)") rrenkert@640: .arg(mUpdatesManual->certificates().size()) + rrenkert@640: "

"); rrenkert@640: } rrenkert@640: rrenkert@640: void MainWindow::removeFromManual(bool state, const Certificate &cert) rrenkert@640: { rrenkert@640: mUpdatesManual->removeCertificate(cert); rrenkert@640: rrenkert@640: mUpdatesManualCertificates->setText("

" + emanuel@661: tr("Manually changed certificates (%1)") rrenkert@640: .arg(mUpdatesManual->certificates().size()) + rrenkert@640: "

"); rrenkert@640: rrenkert@640: if (cert.isInstallCert()) { rrenkert@640: mInstallList->setCertState(state, cert); rrenkert@640: } rrenkert@640: else { rrenkert@640: mRemoveList->setCertState(state, cert); rrenkert@640: } rrenkert@640: } rrenkert@640: rrenkert@447: void MainWindow::closeApp() rrenkert@447: { wilde@782: ProcessHelp::cleanUp(); rrenkert@447: qApp->quit(); rrenkert@447: } rrenkert@584: andre@609: void MainWindow::checkAndInstallCerts() andre@609: { andre@609: /* Checking before opening the dialog should be cheaper */ andre@609: QList pids = ProcessHelp::getProcessesIdForName("firefox"); andre@609: pids.append(ProcessHelp::getProcessesIdForName("thunderbird")); andre@609: andre@609: if (pids.isEmpty()) { andre@609: installCerts(); andre@609: return; andre@609: } andre@609: andre@609: QStringList pNames; andre@609: pNames << "firefox" << "thunderbird"; andre@609: andre@609: ProcessWaitDialog *waitDialog = new ProcessWaitDialog(this, pNames); andre@609: andre@609: connect(waitDialog, SIGNAL(accepted()), this, SLOT(installCerts())); andre@609: connect(waitDialog, SIGNAL(accepted()), waitDialog, SLOT(deleteLater())); andre@609: andre@609: waitDialog->exec(); andre@609: return; andre@609: } andre@654: rrenkert@584: void MainWindow::togglePages(int button) rrenkert@584: { andre@743: mUpdatesWidget->hide(); andre@743: mInstallWidget->hide(); andre@743: mRemoveWidget->hide(); andre@743: mInfoWidget->hide(); rrenkert@584: switch(button) { andre@743: case 0: mUpdatesWidget->show(); break; andre@743: case 1: mInstallWidget->show(); break; andre@743: case 2: mRemoveWidget->show(); break; andre@743: case 3: mInfoWidget->show(); break; andre@743: default: mUpdatesWidget->show(); break; rrenkert@584: } rrenkert@584: return; rrenkert@584: } rrenkert@584: rrenkert@584: void MainWindow::toggleUpdatesNew() { rrenkert@584: if (!mUpdatesNew->isVisible()) { emanuel@659: mUpdatesDetailsNew->setText(tr("Hide details")); rrenkert@584: mUpdatesNew->show(); rrenkert@584: } rrenkert@584: else { rrenkert@653: mUpdatesNew->hide(); emanuel@659: mUpdatesDetailsNew->setText(tr("Show details")); rrenkert@584: } rrenkert@584: } rrenkert@584: rrenkert@584: void MainWindow::toggleUpdatesRemove() { rrenkert@584: if (!mUpdatesRemove->isVisible()) { emanuel@659: mUpdatesDetailsRemove->setText(tr("Hide details")); rrenkert@584: mUpdatesRemove->show(); rrenkert@584: } rrenkert@584: else { rrenkert@653: mUpdatesRemove->hide(); emanuel@659: mUpdatesDetailsRemove->setText(tr("Show details")); rrenkert@584: } rrenkert@584: } rrenkert@584: rrenkert@584: void MainWindow::toggleUpdatesManual() { rrenkert@584: if (!mUpdatesManual->isVisible()) { emanuel@659: mUpdatesDetailsManual->setText(tr("Hide details")); rrenkert@584: mUpdatesManual->show(); rrenkert@584: } rrenkert@584: else { emanuel@659: mUpdatesDetailsManual->setText(tr("Show details")); rrenkert@653: mUpdatesManual->hide(); rrenkert@584: } rrenkert@584: } andre@690: andre@690: void MainWindow::closeEvent(QCloseEvent *event) andre@690: { andre@690: if (getState() == NewListAvailable) { andre@690: /* Only minimize to tray if there is a new list */ andre@690: QMainWindow::closeEvent(event); andre@690: return; andre@690: } andre@690: return closeApp(); andre@690: } andre@708: andre@708: void MainWindow::updateCheckSuccess() andre@708: { andre@708: if (getState() != TransferError) { andre@708: const QDateTime now = QDateTime::currentDateTime(); andre@708: mSettings.setValue("lastUpdateCheck", now); andre@754: mLastUpdateCheckContents->setText(QLocale::system().toString(now, DATETIME_FORMAT)); andre@754: mLastUpdateCheckContents->show(); andre@708: mLastUpdateCheck->show(); andre@708: syslog_info_printf(tr("Sucessfully checked for updates.").toUtf8().constData()); andre@708: } andre@708: } andre@716: andre@716: int MainWindow::changeCount() andre@716: { andre@716: return mChangeCount; andre@716: } andre@722: andre@722: void MainWindow::setChangeCount(int cnt) andre@722: { andre@722: if (mChangeCount != cnt) { andre@722: mChangeCount = cnt; andre@722: emit changesChanged(QString("%1").arg(cnt)); andre@722: } andre@722: }