annotate ui/listupdatedialog.cpp @ 127:04dcc0fb1eca

Set cinst process path to be the directory of the executable running
author Andre Heinecke <aheinecke@intevation.de>
date Mon, 24 Mar 2014 10:16:16 +0000
parents 6090e673c707
children 95d35ec93bbe
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"
127
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
2 #include <QCoreApplication>
71
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 #include <QDebug>
127
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
4 #include <QDir>
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
5 #include <QFileInfo>
85
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
6 #include <QProcess>
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
7 #include <QPushButton>
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
8 #include <QGroupBox>
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
9 #include <QHBoxLayout>
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
10 #include <QListWidget>
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
11 #include <QVBoxLayout>
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
12 #include "certificate.h"
71
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14 ListUpdateDialog::ListUpdateDialog(QDialog *parent,
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 const CertificateList &listToInstall) :
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 QDialog(parent),
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 mCertificateList(listToInstall)
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 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
20 setupGUI();
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21 }
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23 void ListUpdateDialog::setupGUI()
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
24 {
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
25 /* Top level layout / widgets */
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
26 QVBoxLayout *topLayout = new QVBoxLayout;
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
27 QHBoxLayout *listLayout = new QHBoxLayout;
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
28 QPushButton *executeUpdate = new QPushButton(tr("Update Stores"));
85
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
29 connect(executeUpdate, &QPushButton::clicked,
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
30 this, &ListUpdateDialog::executeUpdate);
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
31
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
32 /* The remove groups */
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
33 QVBoxLayout *removeGroupLayout = new QVBoxLayout;
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
34 mRemoveListWidget = new QListWidget;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
35 removeGroupLayout->addWidget(mRemoveListWidget);
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
36 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
37 removeGroup->setLayout(removeGroupLayout);
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
38
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
39 foreach (const Certificate& cert, mCertificateList.getRemoveCertificates()) {
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
40 if (!cert.isValid()) {
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
41 qWarning() << "Invalid certificate in list";
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
42 continue;
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
43 }
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
44 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
45 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
46 item->setCheckState(Qt::Checked);
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
47 mRemoveListWidget->addItem(item);
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
48 }
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
49
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
50 /* The install group */
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
51 QVBoxLayout *installGroupLayout = new QVBoxLayout;
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
52 mInstallListWidget = new QListWidget;
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
53 QGroupBox *installGroup = new QGroupBox(tr("Select certificates to install"));
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
54 installGroupLayout->addWidget(mInstallListWidget);
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
55 installGroup->setLayout(installGroupLayout);
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
56
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
57 foreach (const Certificate& cert, mCertificateList.getInstallCertificates()) {
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
58 if (!cert.isValid()) {
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
59 qWarning() << "Invalid certificate in list";
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
60 continue;
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
61 }
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
62 QListWidgetItem* item = new QListWidgetItem(cert.shortDescription());
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
63 item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
85
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
64 item->setData(Qt::ToolTipRole, cert.details());
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
65 item->setData(Qt::UserRole, cert.base64Line());
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
66 item->setCheckState(Qt::Checked);
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
67 mInstallListWidget->addItem(item);
80
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
68 }
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
69
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
70 /* Add groups to layout */
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
71 listLayout->addWidget(installGroup);
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
72 listLayout->addWidget(removeGroup);
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
73
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
74 /* Fill top level layout */
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
75 topLayout->addLayout(listLayout);
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
76 topLayout->addWidget(executeUpdate);
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
77
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
78 setLayout(topLayout);
01286d0872ca Add some UI in listupdatedialog
Andre Heinecke <aheinecke@intevation.de>
parents: 71
diff changeset
79
71
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80 return;
f22a99f7cb69 Add certificatelist to install as member. Look for updates on startup
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 }
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
83 void ListUpdateDialog::executeUpdate() {
85
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
84 /* 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
85 QProcess installerProcess;
127
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
86 QFileInfo fi(QCoreApplication::applicationFilePath());
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
87 QDir myDir = fi.absoluteDir();
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
88 QString instProcName = "cinst";
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
89 if (!fi.suffix().isEmpty()) {
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
90 instProcName += "." + fi.suffix();
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
91 }
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
92 QString instPath = myDir.absoluteFilePath(instProcName);
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
93
127
04dcc0fb1eca Set cinst process path to be the directory of the executable running
Andre Heinecke <aheinecke@intevation.de>
parents: 98
diff changeset
94 installerProcess.setProgram(instPath);
85
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
95 installerProcess.start();
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
96 installerProcess.waitForStarted();
98
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
97 if (installerProcess.state() == QProcess::NotRunning) {
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
98 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
99 /* 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
100 return;
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
101 }
85
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
102 installerProcess.write("-----BEGIN CERTIFICATE LIST-----\r\n");
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
103 installerProcess.write(mCertificateList.rawData().toLatin1());
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
104 installerProcess.write("-----END CERTIFICATE LIST-----\r\n");
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
105
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
106 QList<QListWidgetItem *> selectedItems = mInstallListWidget->selectedItems();
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
107 selectedItems << mRemoveListWidget->selectedItems();
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
108
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
109 foreach (const QListWidgetItem * item, selectedItems) {
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
110 installerProcess.write(item->data(Qt::UserRole).toString().toLatin1());
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
111 installerProcess.write("\r\n");
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
112 }
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
113
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
114 installerProcess.closeWriteChannel();
e52df5870c4f Add basic interaction with another process
Andre Heinecke <aheinecke@intevation.de>
parents: 82
diff changeset
115 installerProcess.waitForFinished();
98
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.exitStatus() == QProcess::CrashExit) {
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
118 /* Woops */
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
119 qWarning() << "Installer process crashed";
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
120 } 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
121 /* 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
122 * qt changed.. */
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
123 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
124 return;
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
125 }
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
126
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
127 if (installerProcess.exitCode() == 0) {
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
128 qDebug() << "Success!";
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
129 } else {
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
130 /* 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
131 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
132 qDebug() << "output: " << installerProcess.readAllStandardOutput();
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
133 return;
6090e673c707 Add some error handling. Change process path for testing
Andre Heinecke <aheinecke@intevation.de>
parents: 85
diff changeset
134 }
82
1f27d6db5ee3 Polarssl based certificate handling
Andre Heinecke <aheinecke@intevation.de>
parents: 80
diff changeset
135 }

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