Mercurial > trustbridge
diff ui/mainwindow.cpp @ 641:a7c3ab273d41 trustbridge-refactor
Some code cleanup.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Tue, 24 Jun 2014 17:40:40 +0200 |
parents | 626507197360 |
children | dd738ef17715 |
line wrap: on
line diff
--- a/ui/mainwindow.cpp Tue Jun 24 17:07:49 2014 +0200 +++ b/ui/mainwindow.cpp Tue Jun 24 17:40:40 2014 +0200 @@ -530,12 +530,18 @@ this, SLOT(removeFromManual(bool, const Certificate&))); QHBoxLayout *updatesBottomLayout = new QHBoxLayout; - quitButton = new QPushButton(tr("Quit without saving")); - QPushButton *saveButton = new QPushButton(tr("Update")); + QPushButton *quitButton = new QPushButton(tr("Quit without saving")); + QPushButton *installButton = new QPushButton(tr("Update")); +#ifdef Q_OS_WIN + if (is_admin()) { + QIcon uacShield = QApplication::style()->standardIcon(QStyle::SP_VistaShield); + installButton->setIcon(uacShield); + } +#endif connect(quitButton, SIGNAL(clicked()), this, SLOT(closeApp())); - connect(saveButton, SIGNAL(clicked()), this, SLOT(installCerts())); + connect(installButton, SIGNAL(clicked()), this, SLOT(installCerts())); updatesBottomLayout->insertStretch(0, 10); - updatesBottomLayout->addWidget(saveButton); + updatesBottomLayout->addWidget(installButton); updatesBottomLayout->addWidget(quitButton); updatesBottomLayout->setAlignment(Qt::AlignBottom); @@ -705,100 +711,6 @@ centerLayout->addLayout(buttonBarLayout); centerLayout->addLayout(containerLayout); - -/* - // The certificate list - QGroupBox *certBox = new QGroupBox(tr("Managed Certificates")); - mCertListWidget = new QListWidget; - connect(mCertListWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), - this, SLOT(showDetails(QListWidgetItem*))); - certLayout->addWidget(mCertListWidget); - - mCurrentListDate = new QLabel(tr("Current List Date: %1").arg("")); - mNewListDate = new QLabel(""); - listInfoLayout->addWidget(mCurrentListDate); - listInfoLayout->addWidget(mNewListDate); - certLayout->addLayout(listInfoLayout); - - certBox->setLayout(certLayout); - - - // The settings. - QGroupBox *settingsBox = new QGroupBox(tr("Settings")); - mAutoUpdateOption = new QCheckBox(tr("Autoupdate")); - mAutoStartOption = new QCheckBox(tr("Autostart")); - settingsLayout->addWidget(mAutoUpdateOption); - settingsLayout->addWidget(mAutoStartOption); - settingsBox->setLayout(settingsLayout); - connect(mAutoUpdateOption, SIGNAL(stateChanged(int)), - this, SLOT(saveAutoUpdate(int))); - connect(mAutoStartOption, SIGNAL(stateChanged(int)), - this, SLOT(saveAutoStart(int))); - mSettings.beginGroup("settings"); - bool autoUpdate = mSettings.value("autoupdate", false).toBool(); - bool autoStart = mSettings.value("autostart", true).toBool(); - mSettings.endGroup(); - mAutoUpdateOption->setCheckState(autoUpdate ? Qt::Checked : Qt::Unchecked); - mAutoStartOption->setCheckState(autoStart ? Qt::Checked : Qt::Unchecked); - - -#ifdef Q_OS_WIN - if (is_admin()) { - QIcon uacShield = QApplication::style()->standardIcon(QStyle::SP_VistaShield); - installButton->setIcon(uacShield); - } -#endif - - // The certificate details - QGroupBox *detailBox = new QGroupBox(tr("Details")); - QLabel *subjectCN = new QLabel(tr("Subject Common Name:")); - QLabel *subjectOU = new QLabel(tr("Subject Organisation:")); - QLabel *issuerCN = new QLabel(tr("Issuer Common Name:")); - QLabel *issuerOU = new QLabel(tr("Issuer Organisation:")); - QLabel *validFrom = new QLabel(tr("Valid from:")); - QLabel *validTo = new QLabel(tr("Valid to:")); - QLabel *fingerprint = new QLabel(tr("Fingerprint:")); - detailLabelLayout->addWidget(subjectCN); - detailLabelLayout->addWidget(subjectOU); - detailLabelLayout->addWidget(issuerCN); - detailLabelLayout->addWidget(issuerOU); - detailLabelLayout->addWidget(validFrom); - detailLabelLayout->addWidget(validTo); - detailLabelLayout->addWidget(fingerprint); - mSubjectCN = new QLabel(tr("")); - mSubjectO = new QLabel(tr("")); - mIssuerCN = new QLabel(tr("")); - mIssuerO = new QLabel(tr("")); - mValidFrom = new QLabel(tr("")); - mValidTo = new QLabel(tr("")); - mFingerprint = new QLabel(tr("")); - mFingerprint->setFont(QFont("DejaVu Sans Mono")); - detailContentLayout->addWidget(mSubjectCN); - detailContentLayout->addWidget(mSubjectO); - detailContentLayout->addWidget(mIssuerCN); - detailContentLayout->addWidget(mIssuerO); - detailContentLayout->addWidget(mValidFrom); - detailContentLayout->addWidget(mValidTo); - detailContentLayout->addWidget(mFingerprint); - detailLayout->addLayout(detailLabelLayout); - detailLayout->addLayout(detailContentLayout); - detailBox->setLayout(detailLayout); - - infoLayout->addSpacing(20); - infoLayout->addLayout(headerLayout); - //infoLayout->addWidget(detailBox); - //infoLayout->addWidget(settingsBox); - infoLayout->addLayout(bottomLayout); - - //mainLayout->addWidget(certBox); - mainLayout->addLayout(infoLayout); - mainLayout->setStretchFactor(certBox, 37); - mainLayout->setStretchFactor(infoLayout, 63); - - // QMainWindow allready has a layout. All child layouts and widgets are - // managed in the central widget. - */ - QFrame *topSeparator = new QFrame(); topSeparator->setFrameShape(QFrame::HLine); topSeparator->setFrameShadow(QFrame::Sunken); @@ -831,9 +743,6 @@ void MainWindow::loadCertificateList() { - //mCertListWidget->clear(); - //int i = 0; - /* TODO: if nothing is available (neither old nor new) add some progress * indication */ mInstallList->clear(); @@ -919,103 +828,6 @@ mUpdatesManualCertificates->setText("<h3>" + tr("Manualy changed Certificates (%1)").arg(0) + "</h3>"); -/* - // Add separators and certificates to list widget. - if (!newInstallCerts.isEmpty()) { - mCertListWidget->addItem(createSeparator(tr("New certificates to install"), i++)); - foreach (const Certificate &cert, newInstallCerts) { - mCertListWidget->addItem(createListItem(cert, Certificate::InstallNew, i++)); - } - } - - if (!newRemoveCerts.isEmpty()) { - mCertListWidget->addItem(createSeparator(tr("New certificates to remove"), i++)); - foreach (const Certificate &cert, newRemoveCerts) { - mCertListWidget->addItem(createListItem(cert, Certificate::RemoveNew, i++)); - } - } - - if (!oldInstallCerts.isEmpty()) { - mCertListWidget->addItem(createSeparator(tr("Old certificates to install"), i++)); - foreach (const Certificate &cert, oldInstallCerts) { - mCertListWidget->addItem(createListItem(cert, Certificate::InstallOld, i++)); - } - } - - if (!oldRemoveCerts.isEmpty()) { - mCertListWidget->addItem(createSeparator(tr("Old certificates to remove"), i++)); - foreach (const Certificate &cert, oldRemoveCerts) { - mCertListWidget->addItem(createListItem(cert, Certificate::RemoveOld, i++)); - } - } - */ -} - -QListWidgetItem* MainWindow::createSeparator(const QString &text, int index) -{ - SeparatorItemDelegate *separatorDelegate = new SeparatorItemDelegate(); - QListWidgetItem *separator = new QListWidgetItem(text); - mCertListWidget->setItemDelegateForRow(index, separatorDelegate); - separator->setFlags(separator->flags() ^ Qt::ItemIsUserCheckable); - return separator; -} - -QListWidgetItem* MainWindow::createListItem(const Certificate &certificate, - Certificate::Status status, int index) -{ - CertificateItemDelegate *certDelegate = new CertificateItemDelegate(); - QListWidgetItem* item = new QListWidgetItem(certificate.shortDescription()); - item->setData(CertificateItemDelegate::DataRole, - QVariant::fromValue(certificate)); - item->setData(CertificateItemDelegate::StatusRole, status); - if (!mPreviouslyUnselected.contains(certificate.base64Line()) && - status == Certificate::RemoveOld) { - item->setFlags(item->flags() ^ Qt::ItemIsUserCheckable); - } - else { - Qt::CheckState checkedState = - mPreviouslyUnselected.contains(certificate.base64Line()) ? - Qt::Unchecked : Qt::Checked; - item->setFlags(item->flags() | Qt::ItemIsUserCheckable); - item->setCheckState(checkedState); - } - mCertListWidget->setItemDelegateForRow(index, certDelegate); - return item; -} - -void MainWindow::showHelp() -{ - qDebug() << "show helpdialog"; - HelpDialog *help = new HelpDialog(this); - help->show(); -} - -void MainWindow::showAbout() -{ - qDebug() << "show aboutdialog"; - AboutDialog *about = new AboutDialog(this); - about->show(); -} - -void MainWindow::showDetails(QListWidgetItem *item) -{ - if (item == NULL) { - return; - } - Certificate cert = item->data(CertificateItemDelegate::DataRole).value<Certificate>(); - mSubjectCN->setText(cert.subjectCN()); - mSubjectO->setText(cert.subjectO()); - mIssuerCN->setText(cert.issuerCN()); - mIssuerO->setText(cert.issuerO()); - mValidFrom->setText(cert.validFrom().toString()); - mValidTo->setText(cert.validTo().toString()); - mFingerprint->setText(cert.fingerprint()); -} - -void MainWindow::resizeButtons() -{ - installButton->setFixedHeight(20); - quitButton->setFixedHeight(80); } void MainWindow::installerError(const QString& errMsg) { @@ -1068,19 +880,6 @@ unselected << mInstallList->unselectedCertificates(); unselected << mRemoveList->unselectedCertificates(); -/* for (int i = 0; i < mCertListWidget->count(); i++) { - QListWidgetItem *item = mCertListWidget->item(i); - if (item->checkState() == Qt::Checked) { - choices << item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line(); - continue; - } - QString certLine = item->data(CertificateItemDelegate::DataRole).value<Certificate>().base64Line(); - if (certLine.startsWith("I:")) { - certLine[0] = 'R'; - choices << certLine; - } - } -*/ QProgressDialog *progress = new QProgressDialog(this); progress->setWindowModality(Qt::WindowModal); progress->setLabelText(tr("Installing certificates...")); @@ -1137,20 +936,6 @@ return mSettings.status() == QSettings::NoError; } -void MainWindow::saveAutoUpdate(int state) -{ - mSettings.beginGroup("settings"); - mSettings.setValue("autoupdate", state != Qt::Unchecked); - mSettings.endGroup(); -} - -void MainWindow::saveAutoStart(int state) -{ - mSettings.beginGroup("settings"); - mSettings.setValue("autostart", state != Qt::Unchecked); - mSettings.endGroup(); -} - void MainWindow::toggleInManual(bool state, const Certificate &cert) { if (!mUpdatesManual->contains(cert)) {