changeset 358:9ba7b4b4c1de

Implemented the load from certificate file and set the edit state of certificates.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 10 Apr 2014 17:06:37 +0200
parents d56f952ba817
children f6ce186cebc2
files ui/administratorwindow.cpp ui/administratorwindow.h ui/certificatetabledelegate.cpp ui/certificatetablemodel.cpp ui/certificatetablemodel.h
diffstat 5 files changed, 35 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ui/administratorwindow.cpp	Thu Apr 10 17:04:41 2014 +0200
+++ b/ui/administratorwindow.cpp	Thu Apr 10 17:06:37 2014 +0200
@@ -95,6 +95,7 @@
     loadButton = new QPushButton(tr("Load"));
     connect(loadButton, SIGNAL(clicked()), this, SLOT(loadCertificateFile()));
     addButton = new QPushButton(tr("Add"));
+    connect(addButton, SIGNAL(clicked()), this, SLOT(addCertificates()));
     removeButton = new QPushButton(tr("Remove"));
     bottomLayout->addWidget(saveButton);
     bottomLayout->addWidget(loadButton);
@@ -129,9 +130,24 @@
     }
 }
 
+void AdministratorWindow::addCertificates()
+{
+    QString certFile = QFileDialog::getOpenFileName(
+        this, tr("Select certificate"), "/home/rrenkert/local-home/projects/m13/src/repo/ui/tests/data/", "*.pem *.der");
+    QList<Certificate> certs = Certificate::fromFileName(certFile);
+    addToCertificateTable(certs);
+}
+
 void AdministratorWindow::loadCertificateTable() {
     foreach(const Certificate &cert, certList.getCertificates()) {
-        certificateModel->addCertificate(cert);
+        certificateModel->addCertificate(cert, true);
+    }
+}
+
+void AdministratorWindow::addToCertificateTable(const QList<Certificate> &certs)
+{
+    foreach(const Certificate &cert, certs) {
+        certificateModel->addCertificate(cert, false);
     }
 }
 
--- a/ui/administratorwindow.h	Thu Apr 10 17:04:41 2014 +0200
+++ b/ui/administratorwindow.h	Thu Apr 10 17:06:37 2014 +0200
@@ -31,12 +31,14 @@
     void showHelp();
     void showAbout();
     void loadCertificateFile();
+    void addCertificates();
 
 private:
     void createActions();
     void createMenuBar();
     void createContent();
     void loadCertificateTable();
+    void addToCertificateTable(const QList<Certificate> &certs);
 
     QSettings settings;
 
--- a/ui/certificatetabledelegate.cpp	Thu Apr 10 17:04:41 2014 +0200
+++ b/ui/certificatetabledelegate.cpp	Thu Apr 10 17:06:37 2014 +0200
@@ -38,10 +38,14 @@
 QWidget *CertificateTableDelegate::drawComboBox(QWidget *parent,
     const QStyleOptionViewItem &option, const QModelIndex &index) const
 {
+    bool editable = index.data(Qt::UserRole).toBool();
     // Create a combobox and add two items for install/remove.
     QComboBox *comboBox = new QComboBox(parent);
     comboBox->addItem(QIcon(":/img/list-add.png"), QString(""), QVariant("true"));
-    comboBox->addItem(QIcon(":/img/list-remove.png"), QString(""), QVariant("false"));
+    if (editable) {
+        comboBox->addItem(QIcon(":/img/list-remove.png"),
+            QString(""), QVariant("false"));
+    }
     return comboBox;
 }
 
--- a/ui/certificatetablemodel.cpp	Thu Apr 10 17:04:41 2014 +0200
+++ b/ui/certificatetablemodel.cpp	Thu Apr 10 17:06:37 2014 +0200
@@ -11,10 +11,12 @@
 
 }
 
-void CertificateTabelModel::addCertificate(const Certificate& certificate)
+void CertificateTabelModel::addCertificate(const Certificate& certificate,
+    bool editable)
 {
     beginInsertRows(QModelIndex(), rowCount(), rowCount());
     certificates.append(certificate);
+    certificates.last().setEditable(editable);
     endInsertRows();
 }
 
@@ -38,6 +40,10 @@
         }
         return ret;
     }
+    if (role == Qt::UserRole) {
+        Certificate cert = certificates.at(index.row());
+        return cert.isEditable();
+    }
 
     return QVariant();
 }
@@ -51,6 +57,9 @@
 
     bool newValue = value.toBool();
     Certificate &cert = certificates[index.row()];
+    if (!cert.isEditable()) {
+        return false;
+    }
     cert.setInstallCert(newValue);
 
     emit dataChanged(index, index);
--- a/ui/certificatetablemodel.h	Thu Apr 10 17:04:41 2014 +0200
+++ b/ui/certificatetablemodel.h	Thu Apr 10 17:06:37 2014 +0200
@@ -17,7 +17,7 @@
 public:
     CertificateTabelModel(QObject *parent = 0);
 
-    void addCertificate(const Certificate &certificate);
+    void addCertificate(const Certificate &certificate, bool editable);
     int rowCount(const QModelIndex &parent = QModelIndex()) const;
     int columnCount(const QModelIndex &parent = QModelIndex()) const;
 

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