[PATCH 2 of 7] (issue115) Rework CertificateListWidgets to have a ToolButton instead of a combobox
Wald Commits
scm-commit at wald.intevation.org
Mon Sep 15 19:11:20 CEST 2014
# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# 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 <QHBoxLayout>
#include <QDebug>
#include <QStyleFactory>
+#include <QToolButton>
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 <QWidget>
#include <QLabel>
-#include <QComboBox>
#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 @@
<translation type="vanished">Entfernen</translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="25"/>
<source>Install</source>
- <translation>Installieren</translation>
+ <translation type="vanished">Installieren</translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="28"/>
<source>Remove</source>
- <translation>Entfernen</translation>
+ <translation type="vanished">Entfernen</translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="56"/>
+ <location filename="../certificateitemwidget.cpp" line="37"/>
<source>Validity: %1 until %2</source>
<translation>Gültigkeit: %1 bis %2</translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="59"/>
+ <location filename="../certificateitemwidget.cpp" line="40"/>
<source>Fingerprint (SHA1): <code>%1</code></source>
<translation>Fingerabdruck (SHA1): <code>%1</code></translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="80"/>
- <location filename="../certificateitemwidget.cpp" line="100"/>
<source>This certificate is currently installed.</source>
- <translation>Dieses Zertifikat ist aktuell installiert.</translation>
+ <translation type="vanished">Dieses Zertifikat ist aktuell installiert.</translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="84"/>
<source>This certificate is currently not installed.</source>
- <translation>Dieses Zertifikat ist aktuell nicht installiert.</translation>
+ <translation type="vanished">Dieses Zertifikat ist aktuell nicht installiert.</translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="94"/>
<source>This certificate was uninstalled.</source>
- <translation>Dieses Zertifikat wurde deinstalliert.</translation>
+ <translation type="vanished">Dieses Zertifikat wurde deinstalliert.</translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="98"/>
- <location filename="../certificateitemwidget.cpp" line="121"/>
<source>uninstall</source>
- <translation>Deinstallieren</translation>
+ <translation type="vanished">Deinstallieren</translation>
</message>
<message>
- <location filename="../certificateitemwidget.cpp" line="99"/>
<source>keep</source>
- <translation>Behalten</translation>
+ <translation type="vanished">Behalten</translation>
</message>
</context>
<context>
@@ -473,14 +464,12 @@
<translation type="vanished">Änderungen (%1)</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1157"/>
<source>install</source>
- <translation>Installieren</translation>
+ <translation type="vanished">Installieren</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1157"/>
<source>ignore</source>
- <translation>Ignorieren</translation>
+ <translation type="vanished">Ignorieren</translation>
</message>
<message>
<source>Installed certificates from: %1</source>
@@ -495,7 +484,7 @@
<translation type="vanished">Letzte erfolgreiche Prüfung nach Aktualisierungen: %1</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1477"/>
+ <location filename="../mainwindow.cpp" line="1529"/>
<source>Sucessfully checked for updates.</source>
<translation>Suche nach neuen Empfehlungen erfolgreich.</translation>
</message>
@@ -636,37 +625,37 @@
<translation type="vanished">Neue empfohlene Änderungen (%1)</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1182"/>
+ <location filename="../mainwindow.cpp" line="1224"/>
<source>Error executing update</source>
<translation>Fehler bei der Aktualisierung</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1269"/>
+ <location filename="../mainwindow.cpp" line="1311"/>
<source>Installation with standard user account</source>
<translation>Installation mit Standardbenutzerkonto</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1270"/>
+ <location filename="../mainwindow.cpp" line="1312"/>
<source>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.</source>
<translation>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.</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1278"/>
+ <location filename="../mainwindow.cpp" line="1320"/>
<source>Installing certificates...</source>
<translation>Wurzelzertifikate werden geändert...</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1519"/>
+ <location filename="../mainwindow.cpp" line="1571"/>
<source>Error!</source>
<translation>Fehler!</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1519"/>
+ <location filename="../mainwindow.cpp" line="1571"/>
<source>Failed to find the manual</source>
<translation>Fehler beim Finden des Handbuchs</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1533"/>
+ <location filename="../mainwindow.cpp" line="1585"/>
<source>TrustBridge error</source>
<translation>TrustBridge Fehler</translation>
</message>
@@ -739,22 +728,22 @@
<translation>Automatische Aktualisierungsprüfung von TrustBridge.</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1414"/>
+ <location filename="../mainwindow.cpp" line="1466"/>
<source>Hide details</source>
<translation>Details ausblenden</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1415"/>
+ <location filename="../mainwindow.cpp" line="1467"/>
<source>Less</source>
<translation>Weniger</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1420"/>
+ <location filename="../mainwindow.cpp" line="1472"/>
<source>Show details</source>
<translation>Details einblenden</translation>
</message>
<message>
- <location filename="../mainwindow.cpp" line="1421"/>
+ <location filename="../mainwindow.cpp" line="1473"/>
<source>Details</source>
<translation>Details</translation>
</message>
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()) {
More information about the Trustbridge-commits
mailing list