diff ui/mainwindow.cpp @ 377:e3f825a7257e

merged.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 15 Apr 2014 12:34:04 +0200
parents 9e38a4bcd44e
children 3be838c3e4d8
line wrap: on
line diff
--- 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;
+}

http://wald.intevation.org/projects/trustbridge/