annotate ui/certificatetablemodel.cpp @ 872:02e357826417

(issue81) Add desktop file
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 06 Aug 2014 18:56:23 +0200
parents 320a64d58e62
children ff9cd05e861e
rev   line source
404
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 397
diff changeset
1 /* Copyright (C) 2014 by Bundesamt für Sicherheit in der Informationstechnik
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 397
diff changeset
2 * Software engineering by Intevation GmbH
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 397
diff changeset
3 *
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 397
diff changeset
4 * This file is Free Software under the GNU GPL (v>=2)
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 397
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY!
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 397
diff changeset
6 * See LICENSE.txt for details.
17e1c8f37d72 Add License
Andre Heinecke <aheinecke@intevation.de>
parents: 397
diff changeset
7 */
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
8 #include "certificatetablemodel.h"
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
9
397
8752aae8aad8 Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents: 396
diff changeset
10 #include <QFont>
8752aae8aad8 Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents: 396
diff changeset
11
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
12 CertificateTabelModel::CertificateTabelModel(QObject *parent)
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
13 : QAbstractTableModel(parent)
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
14 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
15 header.append("");
380
1220b741cd51 Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents: 378
diff changeset
16 header.append(tr("Subject CN"));
1220b741cd51 Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents: 378
diff changeset
17 header.append(tr("Subject O"));
416
847fdfd33a22 Fixed wording in certificate table header.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
18 header.append(tr("Valid from"));
847fdfd33a22 Fixed wording in certificate table header.
Raimund Renkert <rrenkert@intevation.de>
parents: 404
diff changeset
19 header.append(tr("Valid to"));
661
320a64d58e62 (UI) Updated English strings. Removed Issuer fields.
Emanuel Schuetze <emanuel@intevation.de>
parents: 463
diff changeset
20 header.append(tr("Fingerprint (SHA1)"));
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
21
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
22 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
23
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
24 void CertificateTabelModel::addCertificate(const Certificate& certificate,
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
25 bool editable)
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
26 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
27 beginInsertRows(QModelIndex(), rowCount(), rowCount());
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
28 mCertificates.append(certificate);
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
29 mCertificates.last().setEditable(editable);
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
30 endInsertRows();
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
31 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
32
376
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
33 bool CertificateTabelModel::removeRows(int row, int count,
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
34 const QModelIndex &index)
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
35 {
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
36 beginRemoveRows(QModelIndex(), row, row + count - 1);
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
37 if ((row + count - 1) > mCertificates.size()) {
376
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
38 return false;
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
39 }
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
40 for (int i = row + count - 1; i >= row; i--) {
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
41 mCertificates.removeAt(i);
376
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
42 }
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
43 endRemoveRows();
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
44 return true;
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
45 }
9731d28b95af Implemented 'remove certificate' in administrator app.
Raimund Renkert <rrenkert@intevation.de>
parents: 358
diff changeset
46
396
26651cc0cc47 Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents: 380
diff changeset
47 bool CertificateTabelModel::removeAll()
26651cc0cc47 Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents: 380
diff changeset
48 {
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
49 return removeRows(0, mCertificates.size(), QModelIndex());
396
26651cc0cc47 Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents: 380
diff changeset
50 }
26651cc0cc47 Remove all certificates if a new list is loaded from file.
Raimund Renkert <rrenkert@intevation.de>
parents: 380
diff changeset
51
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
52 QVariant CertificateTabelModel::data(const QModelIndex &index,
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
53 int role) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
54 {
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
55 if (index.row() > mCertificates.size() || index.row() < 0) {
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
56 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
57 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
58
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
59 if (role == Qt::DisplayRole) {
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
60 Certificate cert = mCertificates.at(index.row());
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
61 QVariant ret;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
62 switch(index.column()) {
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
63 case 0: ret = cert.isInstallCert(); break;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
64 case 1: ret = cert.subjectCN(); break;
380
1220b741cd51 Add some more fields for a certificate
Andre Heinecke <andre.heinecke@intevation.de>
parents: 378
diff changeset
65 case 2: ret = cert.subjectO(); break;
661
320a64d58e62 (UI) Updated English strings. Removed Issuer fields.
Emanuel Schuetze <emanuel@intevation.de>
parents: 463
diff changeset
66 case 3: ret = cert.validFrom(); break;
320a64d58e62 (UI) Updated English strings. Removed Issuer fields.
Emanuel Schuetze <emanuel@intevation.de>
parents: 463
diff changeset
67 case 4: ret = cert.validTo(); break;
320a64d58e62 (UI) Updated English strings. Removed Issuer fields.
Emanuel Schuetze <emanuel@intevation.de>
parents: 463
diff changeset
68 case 5: ret = cert.fingerprint(); break;
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
69 default: ;
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
70 }
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
71 return ret;
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
72 }
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
73 if (role == Qt::UserRole) {
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
74 Certificate cert = mCertificates.at(index.row());
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
75 return cert.isEditable();
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
76 }
397
8752aae8aad8 Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents: 396
diff changeset
77 if (role == Qt::FontRole && index.column() == 7) {
8752aae8aad8 Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents: 396
diff changeset
78 QFont block("DejaVu Sans Mono");
8752aae8aad8 Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents: 396
diff changeset
79 return block;
8752aae8aad8 Set DejaVu Sans Mono as font for fingerprint column.
Raimund Renkert <rrenkert@intevation.de>
parents: 396
diff changeset
80 }
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
81
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
82 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
83 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
84
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
85 bool CertificateTabelModel::setData(const QModelIndex &index,
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
86 const QVariant &value, int role)
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
87 {
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
88 if (index.row() > mCertificates.size() || index.row() < 0) {
353
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
89 return false;
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
90 }
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
91
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
92 bool newValue = value.toBool();
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
93 Certificate &cert = mCertificates[index.row()];
358
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
94 if (!cert.isEditable()) {
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
95 return false;
9ba7b4b4c1de Implemented the load from certificate file and set the edit state of certificates.
Raimund Renkert <rrenkert@intevation.de>
parents: 353
diff changeset
96 }
353
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
97 cert.setInstallCert(newValue);
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
98
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
99 emit dataChanged(index, index);
666abcfab229 Implemented setData in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 348
diff changeset
100
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
101 return true;
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
102 }
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
103
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
104 QVariant CertificateTabelModel::headerData(int section,
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
105 Qt::Orientation orientation, int role) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
106 {
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
107 if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
108 return header.at(section);
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
109 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
110 return QVariant();
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
111 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
112
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
113 int CertificateTabelModel::rowCount(const QModelIndex&) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
114 {
463
5200b8e9b2ae Rename tablemodel certificates and add accessors
Andre Heinecke <aheinecke@intevation.de>
parents: 416
diff changeset
115 return mCertificates.size();
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
116 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
117
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
118 int CertificateTabelModel::columnCount(const QModelIndex&) const
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
119 {
342
fba80767fd7a Fixed member variables in certificate table model.
Raimund Renkert <rrenkert@intevation.de>
parents: 334
diff changeset
120 return header.size();
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
121 }
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
122
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
123 Qt::ItemFlags CertificateTabelModel::flags(const QModelIndex &index) const
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
124 {
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
125 if (!index.isValid ())
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
126 return Qt::ItemIsSelectable;
334
36be67070dcb Added table model for certificates.
Raimund Renkert <rrenkert@intevation.de>
parents:
diff changeset
127
348
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
128 if (index.column() == 0) {
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
129 return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
130 }
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
131
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
132 return QAbstractTableModel::flags(index);
e6aa82466420 Use the table item delegate for certificates and make the model editable.
Raimund Renkert <rrenkert@intevation.de>
parents: 342
diff changeset
133 }

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