aheinecke@71: #include "listupdatedialog.h" aheinecke@127: #include aheinecke@71: #include aheinecke@127: #include aheinecke@127: #include aheinecke@85: #include aheinecke@80: #include aheinecke@80: #include aheinecke@80: #include aheinecke@80: #include aheinecke@80: #include rrenkert@213: #include aheinecke@257: #include aheinecke@257: aheinecke@257: aheinecke@80: #include "certificate.h" aheinecke@257: #include "installwrapper.h" aheinecke@71: rrenkert@153: ListUpdateDialog::ListUpdateDialog(QMainWindow *parent, aheinecke@71: const CertificateList &listToInstall) : aheinecke@71: QDialog(parent), aheinecke@71: mCertificateList(listToInstall) aheinecke@71: { aheinecke@71: setupGUI(); aheinecke@71: } aheinecke@71: aheinecke@71: void ListUpdateDialog::setupGUI() aheinecke@71: { aheinecke@80: /* Top level layout / widgets */ aheinecke@80: QVBoxLayout *topLayout = new QVBoxLayout; rrenkert@213: QHBoxLayout *headerLayout = new QHBoxLayout; aheinecke@80: QHBoxLayout *listLayout = new QHBoxLayout; rrenkert@213: QHBoxLayout *bottomLayout = new QHBoxLayout; rrenkert@213: rrenkert@213: QImage *logoImage = new QImage(":/img/logo-small.png"); rrenkert@213: QLabel *logo = new QLabel; rrenkert@213: logo->setBackgroundRole(QPalette::Base); rrenkert@213: logo->setPixmap(QPixmap::fromImage(*logoImage)); rrenkert@213: QLabel *title = new QLabel("

" + tr("Update Certificate") + "

"); rrenkert@213: headerLayout->addWidget(logo); rrenkert@213: headerLayout->addWidget(title); rrenkert@213: headerLayout->setStretch(0, 0); rrenkert@213: headerLayout->setStretch(1, 10); rrenkert@213: aheinecke@80: QPushButton *executeUpdate = new QPushButton(tr("Update Stores")); aheinecke@85: connect(executeUpdate, &QPushButton::clicked, aheinecke@85: this, &ListUpdateDialog::executeUpdate); rrenkert@213: QPushButton *install = new QPushButton(tr("Install selected")); rrenkert@213: QPushButton *later = new QPushButton(tr("Remind me later")); rrenkert@213: bottomLayout->insertStretch(0, 10); rrenkert@213: bottomLayout->addWidget(executeUpdate); rrenkert@213: bottomLayout->addWidget(install); rrenkert@213: bottomLayout->addWidget(later); aheinecke@80: rrenkert@213: /* The certificate groups */ rrenkert@213: mCertListWidget = new QListWidget; rrenkert@213: connect(mCertListWidget, SIGNAL(itemClicked(QListWidgetItem*)), rrenkert@213: this, SLOT(showDetails(QListWidgetItem*))); rrenkert@213: mDetailWidget = new QTextEdit; rrenkert@213: mDetailWidget->setReadOnly(true); rrenkert@213: listLayout->addWidget(mCertListWidget); rrenkert@213: listLayout->addWidget(mDetailWidget); rrenkert@213: QGroupBox *certGroup = new QGroupBox(tr("Select certificates")); rrenkert@213: certGroup->setLayout(listLayout); rrenkert@213: aheinecke@249: foreach (const Certificate& cert, mCertificateList.getCertificates()) { rrenkert@213: if (!cert.isValid()) { rrenkert@213: qWarning() << "Invalid certificate in list"; rrenkert@213: continue; rrenkert@213: } rrenkert@213: QListWidgetItem* item = new QListWidgetItem(cert.shortDescription()); rrenkert@213: item->setFlags(item->flags() | Qt::ItemIsUserCheckable); rrenkert@213: item->setData(Qt::ToolTipRole, cert.details()); rrenkert@213: item->setData(Qt::UserRole, cert.base64Line()); rrenkert@213: item->setCheckState(Qt::Checked); aheinecke@249: QIcon *certIcon = cert.isInstallCert() ? new QIcon(":/img/list-add.png") : aheinecke@249: new QIcon(":/img/list-remove.png"); rrenkert@213: item->setIcon(*certIcon); aheinecke@249: rrenkert@213: mCertListWidget->addItem(item); rrenkert@213: } aheinecke@80: aheinecke@80: /* Fill top level layout */ rrenkert@213: topLayout->addLayout(headerLayout); rrenkert@213: topLayout->addWidget(certGroup); rrenkert@213: topLayout->addLayout(bottomLayout); aheinecke@80: aheinecke@80: setLayout(topLayout); aheinecke@80: aheinecke@71: return; aheinecke@71: } aheinecke@82: aheinecke@257: void ListUpdateDialog::installerError(const QString& errMsg) { aheinecke@257: QMessageBox::warning(this, tr("Installation Error"), errMsg); aheinecke@257: } aheinecke@257: aheinecke@82: void ListUpdateDialog::executeUpdate() { aheinecke@257: aheinecke@257: QStringList instructions; aheinecke@257: aheinecke@257: for (int i = 0; i < mCertListWidget->count(); i++) { aheinecke@257: QListWidgetItem *item = mCertListWidget->item(i); aheinecke@257: if (item->checkState() == Qt::Checked) { aheinecke@257: instructions << item->data(Qt::UserRole).toString(); aheinecke@257: } aheinecke@257: aheinecke@257: /* TODO: Check if it was an install instruction for an old certificate aheinecke@257: * (already installed) and remove it in case it is unchecked. */ aheinecke@257: } aheinecke@257: aheinecke@257: InstallWrapper *instWrap = new InstallWrapper(this, aheinecke@257: mCertificateList.fileName(), aheinecke@257: instructions); aheinecke@257: connect(instWrap, SIGNAL(finished()), instWrap, SLOT(deleteLater())); aheinecke@257: connect(instWrap, SIGNAL(error(const QString &)), aheinecke@257: this, SLOT(installerError(const QString &))); aheinecke@257: instWrap->start(); aheinecke@257: aheinecke@257: #if 0 aheinecke@85: /* TODO move this in another dialog and call it async*/ aheinecke@85: QProcess installerProcess; aheinecke@127: QFileInfo fi(QCoreApplication::applicationFilePath()); aheinecke@127: QDir myDir = fi.absoluteDir(); aheinecke@127: QString instProcName = "cinst"; aheinecke@127: if (!fi.suffix().isEmpty()) { aheinecke@127: instProcName += "." + fi.suffix(); aheinecke@127: } aheinecke@127: QString instPath = myDir.absoluteFilePath(instProcName); aheinecke@82: aheinecke@127: installerProcess.setProgram(instPath); aheinecke@85: installerProcess.start(); aheinecke@85: installerProcess.waitForStarted(); aheinecke@98: if (installerProcess.state() == QProcess::NotRunning) { aheinecke@98: qWarning() << "Failed to start installer Process."; aheinecke@98: /* TODO ERROR message for the user */ aheinecke@98: return; aheinecke@98: } aheinecke@128: aheinecke@85: installerProcess.write("-----BEGIN CERTIFICATE LIST-----\r\n"); aheinecke@85: installerProcess.write(mCertificateList.rawData().toLatin1()); aheinecke@85: installerProcess.write("-----END CERTIFICATE LIST-----\r\n"); aheinecke@85: aheinecke@128: /* Items to install */ rrenkert@213: for (int i = 0; i < mCertListWidget->count(); i++) { rrenkert@213: QListWidgetItem *item = mCertListWidget->item(i); aheinecke@221: if (item->checkState() != Qt::Checked && rrenkert@213: item->data(Qt::UserRole).toString().startsWith("I:")) { aheinecke@128: continue; aheinecke@128: } aheinecke@128: installerProcess.write(item->data(Qt::UserRole).toString().toLatin1()); aheinecke@128: installerProcess.write("\r\n"); aheinecke@128: } aheinecke@85: aheinecke@128: /* Items to remove */ rrenkert@213: for (int i = 0; i < mCertListWidget->count(); i++) { rrenkert@213: QListWidgetItem *item = mCertListWidget->item(i); andre@214: if (!item->checkState() != Qt::Checked && rrenkert@213: item->data(Qt::UserRole).toString().startsWith("R:")) { aheinecke@128: continue; aheinecke@128: } aheinecke@85: installerProcess.write(item->data(Qt::UserRole).toString().toLatin1()); aheinecke@85: installerProcess.write("\r\n"); aheinecke@85: } aheinecke@85: andre@214: installerProcess.waitForBytesWritten(); aheinecke@85: installerProcess.closeWriteChannel(); aheinecke@85: installerProcess.waitForFinished(); aheinecke@98: aheinecke@98: if (installerProcess.exitStatus() == QProcess::CrashExit) { aheinecke@98: /* Woops */ aheinecke@98: qWarning() << "Installer process crashed"; aheinecke@98: } else if (installerProcess.exitStatus() != QProcess::NormalExit) { aheinecke@98: /* Can not Happen. there are only those two values but maybe aheinecke@98: * qt changed.. */ aheinecke@98: qWarning() << "Exit status neither normal nor crash."; aheinecke@98: return; aheinecke@98: } aheinecke@98: aheinecke@98: if (installerProcess.exitCode() == 0) { aheinecke@98: qDebug() << "Success!"; aheinecke@129: qDebug() << "output: " << installerProcess.readAllStandardOutput(); aheinecke@98: } else { aheinecke@98: /* TODO handle errors defined by errorcodes.h */ aheinecke@98: qDebug() << "Installer Process returned: " << installerProcess.exitCode(); aheinecke@98: qDebug() << "output: " << installerProcess.readAllStandardOutput(); aheinecke@98: return; aheinecke@98: } aheinecke@257: #endif aheinecke@82: } rrenkert@213: rrenkert@213: void ListUpdateDialog::showDetails(QListWidgetItem *item) rrenkert@213: { rrenkert@213: QString details = item->data(Qt::ToolTipRole).toString(); rrenkert@213: mDetailWidget->setPlainText(details); rrenkert@213: }