[PATCH 1 of 2] Some code cleanup

Wald Commits scm-commit at wald.intevation.org
Tue Jun 24 17:43:03 CEST 2014


# HG changeset patch
# User Raimund Renkert <rrenkert at intevation.de>
# Date 1403624440 -7200
# Branch trustbridge-refactor
# Node ID a7c3ab273d414315fa5bb545e4016dae97cb85b1
# Parent  626507197360418fe2ba0e76e96ab2d0cd25bec9
Some code cleanup.

diff -r 626507197360 -r a7c3ab273d41 ui/mainwindow.cpp
--- 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)) {
diff -r 626507197360 -r a7c3ab273d41 ui/mainwindow.h
--- a/ui/mainwindow.h	Tue Jun 24 17:07:49 2014 +0200
+++ b/ui/mainwindow.h	Tue Jun 24 17:40:40 2014 +0200
@@ -71,19 +71,12 @@
     void downloaderError(const QString &message, SSLConnection::ErrorCode error);
     /** @brief Trigger the appropiate action depending on the state */
     void messageClicked();
-    void showHelp();
-    void showAbout();
-    void showDetails(QListWidgetItem*);
-    void resizeButtons();
     void installerError(const QString& errMsg);
     void installerSuccess();
     void installCerts();
     void toggleInManual(bool state, const Certificate &cert);
     void removeFromManual(bool state, const Certificate &cert);
 
-    void saveAutoUpdate(int state);
-    void saveAutoStart(int state);
-
     void togglePages(int button);
     void toggleUpdatesNew();
     void toggleUpdatesRemove();
@@ -157,31 +150,6 @@
     void createContent();
     void loadCertificateList();
 
-    /** @brief Create a separator item for the certificate list.
-     *
-     * The item uses a SeparatorItemDelegate for layout and styling at the given
-     * index.
-     *
-     * @param[in] text  The text for the item.
-     * @param[in] index The index of the item.
-     *
-     * @return The new separator item.
-     */
-    QListWidgetItem* createSeparator(const QString &text, int index);
-
-    /** @brief Create a certificate list item for the list.
-     *
-     * The item uses a CertificateItemDelegate for layout and styling.
-     *
-     * @param[in] text   The certificate to display.
-     * @param[in] status The certificate status.
-     * @param[in] index  The index of the item.
-     *
-     * @return The new separator item.
-     */
-    QListWidgetItem* createListItem(const Certificate &certificate,
-        Certificate::Status status, int index);
-
     /* Are we running in tray mode ?*/
     const bool mTrayMode;
     /* The message currently shown at intervals */
@@ -207,25 +175,9 @@
      * base64lines with I:/R: prefix */
     QStringList mPreviouslyUnselected;
 
-    QListWidget *mCertListWidget;
-
-    QLabel *mSubjectCN;
-    QLabel *mSubjectO;
-    QLabel *mIssuerCN;
-    QLabel *mIssuerO;
-    QLabel *mValidFrom;
-    QLabel *mValidTo;
-    QLabel *mFingerprint;
-
     QLabel *mCurrentListDate;
     QLabel *mNewListDate;
 
-    QCheckBox *mAutoUpdateOption;
-    QCheckBox *mAutoStartOption;
-
-    QPushButton *installButton;
-    QPushButton *quitButton;
-
     QButtonGroup *mButtonGroup;
     QScrollArea *mUpdatesPanel;
     QWidget *mUpdatesWidget;


More information about the Trustbridge-commits mailing list