Mercurial > trustbridge
changeset 377:e3f825a7257e
merged.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 15 Apr 2014 12:34:04 +0200 |
parents | 9731d28b95af (current diff) 9e38a4bcd44e (diff) |
children | 31079bd54036 |
files | |
diffstat | 9 files changed, 113 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/build.sh Tue Apr 15 12:32:34 2014 +0200 +++ b/build.sh Tue Apr 15 12:34:04 2014 +0200 @@ -17,11 +17,12 @@ cd .. mkdir -p build-windows cd build-windows +MXEPATH=~/ubuntu/src/mxe/usr/i686-w64-mingw32.static/ cmake .. \ - -DCMAKE_PREFIX_PATH="~/ubuntu/src/mxe/usr/i686-w64-mingw32.static/qt5;~/ubuntu/src/mxe/usr/i686-w64-mingw32.static;" \ + -DCMAKE_PREFIX_PATH="$MXEPATH/qt5;$MXEPATH;" \ -DNSS_INCLUDEDIR="/nss-3.12.7/include;/nss-3.12.7/public/nss" \ -DNSS_LIBDIR="/nss-3.12.7/lib" \ - -DCMAKE_TOOLCHAIN_FILE='~/ubuntu/src/mxe/usr/i686-w64-mingw32.static/share/cmake/mxe-conf.cmake' \ + -DCMAKE_TOOLCHAIN_FILE="$MXEPATH/share/cmake/mxe-conf.cmake" \ -DCMAKE_VERBOSE_MAKEFILE=True nice make -j8 cd ..
--- a/ui/certificate.h Tue Apr 15 12:32:34 2014 +0200 +++ b/ui/certificate.h Tue Apr 15 12:34:04 2014 +0200 @@ -20,11 +20,12 @@ { public: + /** @brief the Status compared to the last installed list. */ enum Status { - InstallNew = 1, - InstallOld, - RemoveNew, - RemoveOld + InstallNew = 1, /* Never seen this before */ + InstallOld, /* Already contained in last list */ + RemoveNew, /* Was an Install certificate in the last list */ + RemoveOld /* Already removed in the last list */ }; /** @brief construct a certificate from a line of a certificate list.
--- a/ui/certificateitemdelegate.cpp Tue Apr 15 12:32:34 2014 +0200 +++ b/ui/certificateitemdelegate.cpp Tue Apr 15 12:34:04 2014 +0200 @@ -1,6 +1,7 @@ #include <QtWidgets> #include "certificate.h" +#include "mainwindow.h" #include "certificateitemdelegate.h" void CertificateItemDelegate::paint(QPainter *painter, @@ -8,7 +9,7 @@ { // Save the current painter. painter->save(); - int status = index.data(Qt::UserRole + 1).toInt(); + int status = index.data(StatusRole).toInt(); if (status == 0) { // This status is not known, so draw the default item. QStyledItemDelegate::paint(painter, option, index);
--- a/ui/certificateitemdelegate.h Tue Apr 15 12:32:34 2014 +0200 +++ b/ui/certificateitemdelegate.h Tue Apr 15 12:34:04 2014 +0200 @@ -25,6 +25,13 @@ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; + /** @brief different roles for this tiem */ + enum ItemRole { + DetailsRole = Qt::UserRole, /* The certificate details for the window */ + StatusRole, /* Certificate status */ + B64LineRole /* The I:/R: <cert> line */ + }; + private: /**
--- a/ui/mainwindow.cpp Tue Apr 15 12:32:34 2014 +0200 +++ b/ui/mainwindow.cpp Tue Apr 15 12:34:04 2014 +0200 @@ -56,6 +56,7 @@ if (!trayMode) { show(); } + loadUnselectedCertificates(); } void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason) @@ -316,7 +317,6 @@ void MainWindow::loadCertificateList() { - qDebug() << "display certificates"; mCertListWidget->clear(); int i = 0; foreach (const Certificate &cert, mListToInstall.getCertificates()) { @@ -326,18 +326,19 @@ } QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); SeparatorItemDelegate *separator = new SeparatorItemDelegate(); - item->setData(Qt::UserRole, cert.details()); + item->setData(CertificateItemDelegate::DetailsRole, cert.details()); + item->setData(CertificateItemDelegate::B64LineRole, cert.base64Line()); + Qt::CheckState checkedState = mPreviouslyUnselected.contains(cert.base64Line()) ? + Qt::Unchecked : Qt::Checked; if (cert.isInstallCert()) { // This if statements is for testing! @TODO Remove this! if (i <= 2) { - item->setData(Qt::UserRole + 1, Certificate::InstallOld); + item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallOld); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState(Qt::Checked); } else { - item->setData(Qt::UserRole + 1, Certificate::InstallNew); + item->setData(CertificateItemDelegate::StatusRole, Certificate::InstallNew); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState(Qt::Checked); } if (i == 3) { QListWidgetItem *sep = new QListWidgetItem("New certificates"); @@ -345,16 +346,17 @@ mCertListWidget->addItem(sep); i++; } + item->setCheckState(checkedState); } else { // This if statements is for testing! @TODO Remove this! if (i > 35) { - item->setData(Qt::UserRole + 1, Certificate::RemoveNew); + item->setData(CertificateItemDelegate::StatusRole, Certificate::RemoveNew); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState(Qt::Checked); + item->setCheckState(checkedState); } else { - item->setData(Qt::UserRole + 1, Certificate::RemoveOld); + item->setData(CertificateItemDelegate::StatusRole, Certificate::RemoveOld); item->setFlags(item->flags() | Qt::ItemIsUserCheckable); } } @@ -391,7 +393,7 @@ void MainWindow::showDetails(QListWidgetItem *item) { - QString details = item->data(Qt::UserRole).toString(); + QString details = item->data(CertificateItemDelegate::DetailsRole).toString(); certificateDetails->setPlainText(details); } @@ -411,10 +413,10 @@ for (int i = 0; i < mCertListWidget->count(); i++) { QListWidgetItem *item = mCertListWidget->item(i); if (item->checkState() == Qt::Checked) { - choices << item->data(Qt::UserRole).toString(); + choices << item->data(CertificateItemDelegate::B64LineRole).toString(); continue; } - QString certLine = item->data(Qt::UserRole).toString(); + QString certLine = item->data(CertificateItemDelegate::B64LineRole).toString(); if (certLine.startsWith("I:")) { certLine[0] = 'R'; choices << certLine; @@ -440,4 +442,34 @@ this, SLOT(installerError(const QString &))); instWrap->start(); + if (!saveUnselectedCertificates()) { + qWarning() << "Failed to save previosly unselected certificates."; + } } + +void MainWindow::loadUnselectedCertificates() +{ + mPreviouslyUnselected.clear(); + mSettings.beginGroup("unselected"); + QStringList keys = mSettings.allKeys(); + foreach (const QString &key, keys) { + mPreviouslyUnselected << mSettings.value(key, QString()).toString(); + } + mSettings.endGroup(); +} + +bool MainWindow::saveUnselectedCertificates() +{ + mSettings.beginGroup("unselected"); + mSettings.remove(""); /* Clears old choices */ + for (int i = 0; i < mCertListWidget->count(); i++) { + QListWidgetItem *item = mCertListWidget->item(i); + if (item->checkState() != Qt::Checked) { + mSettings.setValue(QString::fromLatin1("cert%1").arg(i), + item->data(CertificateItemDelegate::B64LineRole).toString()); + } + } + mSettings.endGroup(); + mSettings.sync(); + return mSettings.status() == QSettings::NoError; +}
--- a/ui/mainwindow.h Tue Apr 15 12:32:34 2014 +0200 +++ b/ui/mainwindow.h Tue Apr 15 12:34:04 2014 +0200 @@ -45,7 +45,6 @@ NewSoftwareAvailable, TransferError }; - CurrentState getState() {return mCurState;} void setState(CurrentState state) {mCurState = state;} @@ -67,6 +66,27 @@ void installerError(const QString& errMsg); void installCerts(); + /** @brief saves the currently unselected certificates + * + * This creates / updates a qsettings section that + * [unselected] that contains the certificates that + * were unselected previously. + * + * Unselected are certificates that are unchecked + * in the certListWidget + * + * Returns false on error. + */ + bool saveUnselectedCertificates(); + + /** @brief loads previously unselected certificates from settings + * + * The certificates are strored in the list mPreviouslyUnselected. + * + * On error mPreviouslyUnselected is empty after this call. + */ + void loadUnselectedCertificates(); + private: /** @brief check the integrity of available files. * @@ -100,7 +120,11 @@ CurrentState mCurState; QMenuBar *mMenuBar; + /* The current list that should be installed */ CertificateList mListToInstall; + /* Previously made "unselect" choices in the form of + * base64lines with I:/R: prefix */ + QStringList mPreviouslyUnselected; QListWidget *mCertListWidget; QTextEdit *certificateDetails;
--- a/ui/tests/data/testdata.qrc Tue Apr 15 12:32:34 2014 +0200 +++ b/ui/tests/data/testdata.qrc Tue Apr 15 12:34:04 2014 +0200 @@ -1,6 +1,7 @@ <!DOCTYPE RCC><RCC version="1.0"> <qresource> <file>list-valid-signed.txt</file> + <file>list-valid-signed-release.txt</file> <file>list-invalid-signed.txt</file> <file>list-valid-other-signature.txt</file> <file>nss/cert8.db</file>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ui/tests/data/testkey-rel.pem Tue Apr 15 12:34:04 2014 +0200 @@ -0,0 +1,19 @@ +-----BEGIN PUBLIC KEY----- +MIIDIjANBgkqhkiG9w0BAQEFAAOCAw8AMIIDCgKCAYEArUZK1sMV8cWeP48nExEh +YiyIB5PMjjfvP9kJCTvfz0VKgD7H9KiTnRddLeYTAQTUmyr6NfgbLP3XMg1FNveN +4JON1K+nkqNljQSzV8KzTokrmgKFA6PbVNh1pH7r44ZHygAbL8spymjYsuIiZYDj +Ci2gxFza0bt67i+Z25iNZbppefVXrnkzFOFSjXp61BEcD6AbVIXE1MJkQ0dMavvl +NAFgMsRaIWREKs4Ar9v9ez1L+RcJv4MaKvF1FtWN9oPwA+6OrCiYq4nJxKFQhu/T +zTEEGAj5UChFRPzpmYlUQooaQ1V0O/aNqGQ35RvAth2xMr1WpykeqsF9dpwhAIKR +HvrCwtWT7OE37GnL/VLcLbEa5Ns1OMu+U557AVYpachGIRf6DAt8nbwNEHCsPXz0 +LCwu7FKuw7/SitzlWwV4pHBkEQmb99CBg+Tr246BKdarE1JWuIBZJiVa4qiSPOd3 +9mSeWa9ObVY6HBgmSu5LjVL+GLK9tb7qU9Rj70kaUtYRAoIBgQCZHx2nfiyVPNtf +viKdUcds44KQiAQMnngkZscDDuckq+gFKlzfDamPEMvkV+tdnn8N0ReNeMjPmMHU +9HxcoF1OEYFAgbRp8ukih6Rw3sy9LurOzhkU13hKU9onz76I2Dq8sJXlxDh6Ar6y +038gRg1q1RRsTHjuYApkTkyelQpTJMojbAhxCk5QxTuOsrmXDU2udnX2KrLAVmXV +XJw4AEtSph2KBtHwzrWOaE45KtrtCgRiJlUWp6QjVOzQab7hHZP4azyRrOEqoOar +czfQp4Bm83ylpfoWmjN6O8cQ33Dk0U2uiRsydHZ8279qbHFqhEK70+On+B/jXHvb +/CeouejmQ4EaEcYePxdhiX3nTb/tZgzMx4VnRaX/dP84lJqMuQgpyx7bU3FbOZ6g +dY996wJMMlvO+o16AoRyOYmGNr12tNTRABVAxWDNt3lmXSNkqZTFWCZ1jDxdTFIP +UIgOq9QtcyVuyyblizSKNtKaFNHtOMA5UNcKLNZ98GbFCBs3S1s= +-----END PUBLIC KEY-----
--- a/ui/tests/nsstest.cpp Tue Apr 15 12:32:34 2014 +0200 +++ b/ui/tests/nsstest.cpp Tue Apr 15 12:34:04 2014 +0200 @@ -62,7 +62,11 @@ QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8")); /* use system default */ /* Set up a temporary list */ +#ifdef RELEASE_BUILD + QFile res(":/list-valid-signed-release.txt"); +#else QFile res(":/list-valid-signed.txt"); +#endif res.open(QIODevice::ReadOnly); validListFile.open(); validListFile.write(res.readAll()); @@ -73,6 +77,8 @@ validList = CertificateList(validListFile.fileName().toLocal8Bit().data()); + QVERIFY(validList.isValid()); + /* Create the profiles.ini `s set environment variables*/ // fakeHome.setAutoRemove(false); #ifndef WIN32 @@ -134,6 +140,7 @@ cert.base64Line().size() - 2); } QVERIFY((size_t) instList.size() == strv_length(to_install)); + QVERIFY(strv_length(to_install) != 0); QVERIFY(write_stores_nss(to_install, to_remove) == 0);