Mercurial > trustbridge
annotate ui/listupdatedialog.cpp @ 122:65941f3d5db8
Added missing stuff from last commit.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Mon, 24 Mar 2014 10:06:43 +0100 |
parents | 6090e673c707 |
children | 04dcc0fb1eca |
rev | line source |
---|---|
71
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
1 #include "listupdatedialog.h" |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
2 #include <QDebug> |
85
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
3 #include <QProcess> |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
4 #include <QPushButton> |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
5 #include <QGroupBox> |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
6 #include <QHBoxLayout> |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
7 #include <QListWidget> |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
8 #include <QVBoxLayout> |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
9 #include "certificate.h" |
71
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
10 |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
11 ListUpdateDialog::ListUpdateDialog(QDialog *parent, |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
12 const CertificateList &listToInstall) : |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
13 QDialog(parent), |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
14 mCertificateList(listToInstall) |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
15 { |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
16 qDebug() << "I am a happy list update dialog"; |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
17 setupGUI(); |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
18 } |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
19 |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
20 void ListUpdateDialog::setupGUI() |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 { |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
22 /* Top level layout / widgets */ |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
23 QVBoxLayout *topLayout = new QVBoxLayout; |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
24 QHBoxLayout *listLayout = new QHBoxLayout; |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
25 QPushButton *executeUpdate = new QPushButton(tr("Update Stores")); |
85
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
26 connect(executeUpdate, &QPushButton::clicked, |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
27 this, &ListUpdateDialog::executeUpdate); |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
28 |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
29 /* The remove groups */ |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
30 QVBoxLayout *removeGroupLayout = new QVBoxLayout; |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
31 mRemoveListWidget = new QListWidget; |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
32 removeGroupLayout->addWidget(mRemoveListWidget); |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
33 QGroupBox *removeGroup = new QGroupBox(tr("Select certificates to be removed")); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
34 removeGroup->setLayout(removeGroupLayout); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
35 |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
36 foreach (const Certificate& cert, mCertificateList.getRemoveCertificates()) { |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
37 if (!cert.isValid()) { |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
38 qWarning() << "Invalid certificate in list"; |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
39 continue; |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
40 } |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
41 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
42 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
43 item->setCheckState(Qt::Checked); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
44 mRemoveListWidget->addItem(item); |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
45 } |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
46 |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
47 /* The install group */ |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
48 QVBoxLayout *installGroupLayout = new QVBoxLayout; |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
49 mInstallListWidget = new QListWidget; |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
50 QGroupBox *installGroup = new QGroupBox(tr("Select certificates to install")); |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
51 installGroupLayout->addWidget(mInstallListWidget); |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
52 installGroup->setLayout(installGroupLayout); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
53 |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
54 foreach (const Certificate& cert, mCertificateList.getInstallCertificates()) { |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
55 if (!cert.isValid()) { |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
56 qWarning() << "Invalid certificate in list"; |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
57 continue; |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
58 } |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
59 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
60 item->setFlags(item->flags() | Qt::ItemIsUserCheckable); |
85
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
61 item->setData(Qt::ToolTipRole, cert.details()); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
62 item->setData(Qt::UserRole, cert.base64Line()); |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
63 item->setCheckState(Qt::Checked); |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
64 mInstallListWidget->addItem(item); |
80
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
65 } |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
66 |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
67 /* Add groups to layout */ |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
68 listLayout->addWidget(installGroup); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
69 listLayout->addWidget(removeGroup); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
70 |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
71 /* Fill top level layout */ |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
72 topLayout->addLayout(listLayout); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
73 topLayout->addWidget(executeUpdate); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
74 |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
75 setLayout(topLayout); |
01286d0872ca
Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents:
71
diff
changeset
|
76 |
71
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
77 return; |
f22a99f7cb69
Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
78 } |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
79 |
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
80 void ListUpdateDialog::executeUpdate() { |
85
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
81 /* TODO move this in another dialog and call it async*/ |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
82 QProcess installerProcess; |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
83 |
98
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
84 installerProcess.setProgram("../cinst/cinst"); |
85
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
85 installerProcess.start(); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
86 installerProcess.waitForStarted(); |
98
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
87 if (installerProcess.state() == QProcess::NotRunning) { |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
88 qWarning() << "Failed to start installer Process."; |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
89 /* TODO ERROR message for the user */ |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
90 return; |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
91 } |
85
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
92 installerProcess.write("-----BEGIN CERTIFICATE LIST-----\r\n"); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
93 installerProcess.write(mCertificateList.rawData().toLatin1()); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
94 installerProcess.write("-----END CERTIFICATE LIST-----\r\n"); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
95 |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
96 QList<QListWidgetItem *> selectedItems = mInstallListWidget->selectedItems(); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
97 selectedItems << mRemoveListWidget->selectedItems(); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
98 |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
99 foreach (const QListWidgetItem * item, selectedItems) { |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
100 installerProcess.write(item->data(Qt::UserRole).toString().toLatin1()); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
101 installerProcess.write("\r\n"); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
102 } |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
103 |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
104 installerProcess.closeWriteChannel(); |
e52df5870c4f
Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents:
82
diff
changeset
|
105 installerProcess.waitForFinished(); |
98
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
106 |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
107 if (installerProcess.exitStatus() == QProcess::CrashExit) { |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
108 /* Woops */ |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
109 qWarning() << "Installer process crashed"; |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
110 } else if (installerProcess.exitStatus() != QProcess::NormalExit) { |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
111 /* Can not Happen. there are only those two values but maybe |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
112 * qt changed.. */ |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
113 qWarning() << "Exit status neither normal nor crash."; |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
114 return; |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
115 } |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
116 |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
117 if (installerProcess.exitCode() == 0) { |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
118 qDebug() << "Success!"; |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
119 } else { |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
120 /* TODO handle errors defined by errorcodes.h */ |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
121 qDebug() << "Installer Process returned: " << installerProcess.exitCode(); |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
122 qDebug() << "output: " << installerProcess.readAllStandardOutput(); |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
123 return; |
6090e673c707
Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents:
85
diff
changeset
|
124 } |
82
1f27d6db5ee3
Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents:
80
diff
changeset
|
125 } |