# HG changeset patch # User Andre Heinecke # Date 1410795836 -7200 # Node ID 6f7b7d88f0483d34d0ab6338355c436b0153003d # Parent 0c60ec9c24610400ec905027b95980d1edbc822a (issue115) Rework CertificateListWidgets to have a ToolButton instead of a combobox diff -r 0c60ec9c2461 -r 6f7b7d88f048 ui/certificateitemwidget.cpp --- a/ui/certificateitemwidget.cpp Mon Sep 15 17:43:02 2014 +0200 +++ b/ui/certificateitemwidget.cpp Mon Sep 15 17:43:56 2014 +0200 @@ -10,46 +10,27 @@ #include #include #include +#include CertificateItemWidget::CertificateItemWidget(QWidget *parent, const Certificate &cert, bool state, - bool editable, - const QString &installLabel, - const QString &removeLabel) : + QToolButton *btn) : QWidget(parent), - mInstallLabel (installLabel), - mRemoveLabel (removeLabel) + mButton(btn) { - if (mInstallLabel.isEmpty()) { - mInstallLabel = tr("Install"); - } - if (mRemoveLabel.isEmpty()) { - mRemoveLabel = tr("Remove"); - } mCertificate = cert; mState = state; - mEditable = editable; + /* We carry the state explicitly to be better prepared for future + * changes */ + btn->setCheckable(true); + btn->setChecked(!state); setupGUI(); } - -/* We use the label as data to hide it in the normal dropdown menu and only - * show it when the popup is shown.*/ - void CertificateItemWidget::setupGUI() { mLabel = new QLabel; - mComboBox = new IconOnlyTextPopupBox; - QStyle *fusionStyle = QStyleFactory::create("Fusion"); - if (!fusionStyle) { - qDebug() << "Failed to create fusion style"; - } else { - mComboBox->setStyle(fusionStyle); - } - - mComboBox->setIconSize(QSize(32, 32)); - mComboBox->setFixedWidth(64); setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); @@ -67,18 +48,22 @@ mLabel->setTextInteractionFlags( Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); - mComboBox->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); - connect(mComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(currentStateChanged(int))); + mButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + connect(mButton, SIGNAL(toggled (bool)), + this, SLOT(currentStateChanged(bool))); QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(mButton); + mButton->setFixedSize(64, 64); + mButton->setIconSize(QSize(48, 48)); + /* if (mCertificate.isInstallCert()) { mComboBox->addItem(QIcon(":/img/security-high.png"), QString(), mInstallLabel); mComboBox->addItem(QIcon(":/img/security-low.png"), QString(), mRemoveLabel); if (mState) { mComboBox->setCurrentIndex(0); mComboBox->setToolTip(tr("This certificate is currently installed.")); - } + } else { mComboBox->setCurrentIndex(1); mComboBox->setToolTip(tr("This certificate is currently not installed.")); @@ -105,16 +90,18 @@ } layout->addWidget(mComboBox); } + */ layout->addWidget(mLabel); this->setLayout(layout); } bool CertificateItemWidget::state() { - if (!mEditable) { + if (!mButton->isEnabled()) { return true; } + /* const QString currentString = mComboBox->currentData().toString(); if (!mCertificate.isInstallCert()) { @@ -122,21 +109,14 @@ } return currentString == mInstallLabel; + */ + return mState; } void CertificateItemWidget::setState(bool state) { - disconnect(mComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(currentStateChanged(int))); - - if (state) { - mComboBox->setCurrentIndex(0); - } - else { - mComboBox->setCurrentIndex(1); - } - connect(mComboBox, SIGNAL(currentIndexChanged(int)), - this, SLOT(currentStateChanged(int))); + mState = state; + mButton->setChecked(!state); } Certificate* CertificateItemWidget::certificate() @@ -144,22 +124,8 @@ return &mCertificate; } -void CertificateItemWidget::currentStateChanged(int) +void CertificateItemWidget::currentStateChanged(bool state) { - bool state = !mComboBox->currentIndex(); - emit stateChanged(state, mCertificate); + mState = !state; + emit stateChanged(mState, mCertificate); } - -void IconOnlyTextPopupBox::showPopup() { - for (int i = 0; i < count(); i++) { - setItemText(i, itemData(i).toString()); - } - QComboBox::showPopup(); -} - -void IconOnlyTextPopupBox::hidePopup() { - for (int i = 0; i < count(); i++) { - setItemText(i, QString()); - } - QComboBox::hidePopup(); -} diff -r 0c60ec9c2461 -r 6f7b7d88f048 ui/certificateitemwidget.h --- a/ui/certificateitemwidget.h Mon Sep 15 17:43:02 2014 +0200 +++ b/ui/certificateitemwidget.h Mon Sep 15 17:43:56 2014 +0200 @@ -14,20 +14,10 @@ */ #include #include -#include #include "certificate.h" -/** @brief A combo box that shows the text only in the popup - * - * The text shown is the data set as Qt::UserRole - */ -class IconOnlyTextPopupBox : public QComboBox -{ -protected: - virtual void showPopup(); - virtual void hidePopup(); -}; +class QToolButton; class CertificateItemWidget : public QWidget { @@ -37,9 +27,7 @@ QWidget *parent = 0, const Certificate &cert = Certificate(), bool state = false, - bool editable = true, - const QString& installLabel = QString(), - const QString& removeLabel = QString()); + QToolButton * btn = NULL); bool state(); void setState(bool state); @@ -50,14 +38,11 @@ Certificate mCertificate; bool mState; - bool mEditable; QLabel *mLabel; - IconOnlyTextPopupBox *mComboBox; - QString mInstallLabel; - QString mRemoveLabel; + QToolButton *mButton; private slots: - void currentStateChanged(int ndx); + void currentStateChanged(bool state); signals: void stateChanged(bool state, const Certificate &cert); diff -r 0c60ec9c2461 -r 6f7b7d88f048 ui/certificatelistwidget.cpp --- a/ui/certificatelistwidget.cpp Mon Sep 15 17:43:02 2014 +0200 +++ b/ui/certificatelistwidget.cpp Mon Sep 15 17:43:56 2014 +0200 @@ -25,13 +25,10 @@ void CertificateListWidget::addCertificate( const Certificate &certificate, bool state, - bool editable, - const QString &installLabel, - const QString &removeLabel) + QToolButton *button) { CertificateItemWidget *widget = - new CertificateItemWidget(this, certificate, state, editable, - installLabel, removeLabel); + new CertificateItemWidget(this, certificate, state, button); connect(widget, SIGNAL(stateChanged(bool, const Certificate&)), this, SLOT(certStateChanged(bool, const Certificate&))); diff -r 0c60ec9c2461 -r 6f7b7d88f048 ui/certificatelistwidget.h --- a/ui/certificatelistwidget.h Mon Sep 15 17:43:02 2014 +0200 +++ b/ui/certificatelistwidget.h Mon Sep 15 17:43:56 2014 +0200 @@ -22,6 +22,7 @@ */ class CertificateItemWidget; +class QToolButton; Q_DECLARE_METATYPE(Certificate); class CertificateListWidget : public QWidget @@ -31,9 +32,7 @@ CertificateListWidget(QWidget *parent, Qt::WindowFlags flags = 0); void addCertificate(const Certificate &certificate, bool state, - bool editable = true, - const QString& installLabel = QString(), - const QString& removeLabel = QString()); + QToolButton *btn); void removeCertificate(const Certificate &cert); void activateCertificate(const Certificate &cert); void deactivateCertificate(const Certificate &cert); diff -r 0c60ec9c2461 -r 6f7b7d88f048 ui/l10n/trustbridge_de_DE.ts --- a/ui/l10n/trustbridge_de_DE.ts Mon Sep 15 17:43:02 2014 +0200 +++ b/ui/l10n/trustbridge_de_DE.ts Mon Sep 15 17:43:56 2014 +0200 @@ -59,51 +59,42 @@ Entfernen - Install - Installieren + Installieren - Remove - Entfernen + Entfernen - + Validity: %1 until %2 Gültigkeit: %1 bis %2 - + Fingerprint (SHA1): <code>%1</code> Fingerabdruck (SHA1): <code>%1</code> - - This certificate is currently installed. - Dieses Zertifikat ist aktuell installiert. - - - - This certificate is currently not installed. - Dieses Zertifikat ist aktuell nicht installiert. + Dieses Zertifikat ist aktuell installiert. - - This certificate was uninstalled. - Dieses Zertifikat wurde deinstalliert. + This certificate is currently not installed. + Dieses Zertifikat ist aktuell nicht installiert. - - - uninstall - Deinstallieren + This certificate was uninstalled. + Dieses Zertifikat wurde deinstalliert. - + uninstall + Deinstallieren + + keep - Behalten + Behalten @@ -473,14 +464,12 @@ Änderungen (%1) - install - Installieren + Installieren - ignore - Ignorieren + Ignorieren Installed certificates from: %1 @@ -495,7 +484,7 @@ Letzte erfolgreiche Prüfung nach Aktualisierungen: %1 - + Sucessfully checked for updates. Suche nach neuen Empfehlungen erfolgreich. @@ -636,37 +625,37 @@ Neue empfohlene Änderungen (%1) - + Error executing update Fehler bei der Aktualisierung - + Installation with standard user account Installation mit Standardbenutzerkonto - + Windows will now ask you to confirm each root certificate modification because TrustBridge does not have the necessary privileges to install root certificates into the Windows certificate store silently. Windows wird Sie nun bitten, jede Wurzelzertifikatsänderung zu bestätigen. Grund dafür: TrustBridge besitzt nicht die nötigen Privilegien, um Wurzelzertifikate ohne Nachfrage in den Windows-Zertifikatsspeicher zu installieren. - + Installing certificates... Wurzelzertifikate werden geändert... - + Error! Fehler! - + Failed to find the manual Fehler beim Finden des Handbuchs - + TrustBridge error TrustBridge Fehler @@ -739,22 +728,22 @@ Automatische Aktualisierungsprüfung von TrustBridge. - + Hide details Details ausblenden - + Less Weniger - + Show details Details einblenden - + Details Details diff -r 0c60ec9c2461 -r 6f7b7d88f048 ui/mainwindow.cpp --- a/ui/mainwindow.cpp Mon Sep 15 17:43:02 2014 +0200 +++ b/ui/mainwindow.cpp Mon Sep 15 17:43:56 2014 +0200 @@ -1131,11 +1131,30 @@ bool state = !mPreviouslyUnselected.contains(cert.base64Line()); if (cert.isInstallCert()) { oldInstallCerts.append(cert); - mInstallList->addCertificate(cert, state); + QToolButton* actionBtn = new QToolButton(); + QIcon btnIcon; + if (!state) { + btnIcon.addFile(":/img/write-into-48.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + btnIcon.addFile(":/img/security-low.png", QSize(48, 48), QIcon::Normal, QIcon::On); + } else { + btnIcon.addFile(":/img/security-high.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + btnIcon.addFile(":/img/write-remove-48.png", QSize(48, 48), QIcon::Normal, QIcon::On); + } + actionBtn->setIcon(btnIcon); + mInstallList->addCertificate(cert, state, actionBtn); } else { oldRemoveCerts.append(cert); - mRemoveList->addCertificate(cert, state, !state); + QToolButton* actionBtn = new QToolButton(); + QIcon btnIcon; + btnIcon.addFile(":/img/write-remove-48.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + btnIcon.addFile(":/img/security-medium.png", QSize(48, 48), QIcon::Normal, QIcon::On); + btnIcon.addFile(":/img/trash-empty.png", QSize(48, 48), QIcon::Disabled, QIcon::Off); + actionBtn->setIcon(btnIcon); + if (state) { + actionBtn->setEnabled(false); + } + mRemoveList->addCertificate(cert, state, actionBtn); } } } @@ -1148,13 +1167,22 @@ if (mInstalledList.getCertificates().contains(cert)) { // Was in the old list. oldInstallCerts.append(cert); - mInstallList->addCertificate(cert, state); + QToolButton* actionBtn = new QToolButton(); + QIcon btnIcon; + btnIcon.addFile(":/img/security-high.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + btnIcon.addFile(":/img/security-low.png", QSize(48, 48), QIcon::Normal, QIcon::On); + actionBtn->setIcon(btnIcon); + mInstallList->addCertificate(cert, state, actionBtn); } else { // Is a brand new certificate newInstallCerts.append(cert); - mUpdatesNew->addCertificate(cert, state, true, - tr("install"), tr("ignore")); + QToolButton* actionBtn = new QToolButton(); + QIcon btnIcon; + btnIcon.addFile(":/img/write-into-48.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + btnIcon.addFile(":/img/security-low.png", QSize(48, 48), QIcon::Normal, QIcon::On); + actionBtn->setIcon(btnIcon); + mUpdatesNew->addCertificate(cert, state, actionBtn); } } else { @@ -1163,13 +1191,27 @@ // Was in the old list. oldRemoveCerts.append(cert); // Is removed, so set editable to false. - mRemoveList->addCertificate(cert, state, !state); + QToolButton* actionBtn = new QToolButton(); + QIcon btnIcon; + btnIcon.addFile(":/img/write-remove-48.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + btnIcon.addFile(":/img/security-medium.png", QSize(48, 48), QIcon::Normal, QIcon::On); + btnIcon.addFile(":/img/trash-empty.png", QSize(48, 48), QIcon::Disabled, QIcon::Off); + actionBtn->setIcon(btnIcon); + if (state) { + actionBtn->setEnabled(false); + } + mRemoveList->addCertificate(cert, state, actionBtn); } else { // Was in the old list with status "install" and now has the // status "remove". newRemoveCerts.append(cert); - mUpdatesRemove->addCertificate(cert, state); + QToolButton* actionBtn = new QToolButton(); + QIcon btnIcon; + btnIcon.addFile(":/img/write-remove-48.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + btnIcon.addFile(":/img/security-medium.png", QSize(48, 48), QIcon::Normal, QIcon::On); + actionBtn->setIcon(btnIcon); + mUpdatesRemove->addCertificate(cert, state, actionBtn); } } } @@ -1338,7 +1380,17 @@ void MainWindow::toggleInManual(bool state, const Certificate &cert) { if (!mUpdatesManual->contains(cert)) { - mUpdatesManual->addCertificate(cert, state); + QToolButton* actionBtn = new QToolButton(); + QIcon btnIcon; + if (cert.isInstallCert()) { + btnIcon.addFile(":/img/write-into-48.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + btnIcon.addFile(":/img/write-remove-48.png", QSize(48, 48), QIcon::Normal, QIcon::On); + } else { + btnIcon.addFile(":/img/write-into-48.png", QSize(48, 48), QIcon::Normal, QIcon::On); + btnIcon.addFile(":/img/write-remove-48.png", QSize(48, 48), QIcon::Normal, QIcon::Off); + } + actionBtn->setIcon(btnIcon); + mUpdatesManual->addCertificate(cert, state, actionBtn); } else { if (cert.isActive()) {