summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-04-27 13:45:37 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-07-22 09:10:27 (GMT)
commitcdead29b6bfaa8bd6c5a938073e84bd324854fcb (patch)
tree8fecf6ce48f540f07c608a1138cb4edde91010db
parentb2c8f4d901abc0d140ece2c321bc5defa4fb9a07 (diff)
Refactor Line class into certificateselectionline
Ideally we want to unify more certificate selection UI Elements. The API of the certificateselectionline is currently specifically tailored to the signencryptemailconfigdialog but it might be useful in other places.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/crypto/gui/certificateselectionline.cpp341
-rw-r--r--src/crypto/gui/certificateselectionline.h112
-rw-r--r--src/crypto/gui/signencryptemailconflictdialog.cpp358
4 files changed, 474 insertions, 338 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 62abc96..1ad70e0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -144,6 +144,7 @@ set(_kleopatra_SRCS
crypto/gui/wizard.cpp
crypto/gui/wizardpage.cpp
+ crypto/gui/certificateselectionline.cpp
crypto/gui/signingcertificateselectionwidget.cpp
crypto/gui/signingcertificateselectiondialog.cpp
diff --git a/src/crypto/gui/certificateselectionline.cpp b/src/crypto/gui/certificateselectionline.cpp
new file mode 100644
index 0000000..9f697eb
--- /dev/null
+++ b/src/crypto/gui/certificateselectionline.cpp
@@ -0,0 +1,341 @@
+/* crypto/gui/certificateselectionline.cpp
+
+ This file is part of Kleopatra, the KDE keymanager
+ Copyright (c) 2009 Klarälvdalens Datakonsult AB
+ 2016 Intevation GmbH
+
+ Kleopatra is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Kleopatra is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+#include "certificateselectionline.h"
+
+#include <QToolButton>
+#include <QLabel>
+#include <QStackedWidget>
+#include <QComboBox>
+#include <QStylePainter>
+#include <QStyleOptionComboBox>
+#include <QStyle>
+
+#include "utils/formatting.h"
+#include "utils/kleo_assert.h"
+
+#include <KLocalizedString>
+
+#include <Libkleo/Predicates>
+
+
+using namespace Kleo;
+using namespace GpgME;
+
+Q_DECLARE_METATYPE(GpgME::Key)
+
+namespace
+{
+
+static QString make_initial_text(const std::vector<Key> &keys)
+{
+ if (keys.empty()) {
+ return i18n("(no matching certificates found)");
+ } else {
+ return i18n("Please select a certificate");
+ }
+}
+
+// A QComboBox with an initial text (as known from web browsers)
+//
+// only works with read-only QComboBoxen, doesn't affect sizeHint
+// as it should...
+//
+class ComboBox : public QComboBox
+{
+ Q_OBJECT
+ Q_PROPERTY(QString initialText READ initialText WRITE setInitialText)
+ Q_PROPERTY(QIcon initialIcon READ initialIcon WRITE setInitialIcon)
+public:
+ explicit ComboBox(QWidget *parent = Q_NULLPTR)
+ : QComboBox(parent),
+ m_initialText(),
+ m_initialIcon()
+ {
+
+ }
+
+ explicit ComboBox(const QString &initialText, QWidget *parent = Q_NULLPTR)
+ : QComboBox(parent),
+ m_initialText(initialText),
+ m_initialIcon()
+ {
+
+ }
+
+ explicit ComboBox(const QIcon &initialIcon, const QString &initialText, QWidget *parent = Q_NULLPTR)
+ : QComboBox(parent),
+ m_initialText(initialText),
+ m_initialIcon(initialIcon)
+ {
+
+ }
+
+ QString initialText() const
+ {
+ return m_initialText;
+ }
+ QIcon initialIcon() const
+ {
+ return m_initialIcon;
+ }
+
+public Q_SLOTS:
+ void setInitialText(const QString &txt)
+ {
+ if (txt == m_initialText) {
+ return;
+ }
+ m_initialText = txt;
+ if (currentIndex() == -1) {
+ update();
+ }
+ }
+ void setInitialIcon(const QIcon &icon)
+ {
+ if (icon.cacheKey() == m_initialIcon.cacheKey()) {
+ return;
+ }
+ m_initialIcon = icon;
+ if (currentIndex() == -1) {
+ update();
+ }
+ }
+
+protected:
+ void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE {
+ QStylePainter p(this);
+ p.setPen(palette().color(QPalette::Text));
+ QStyleOptionComboBox opt;
+ initStyleOption(&opt);
+ p.drawComplexControl(QStyle::CC_ComboBox, opt);
+
+ if (currentIndex() == -1)
+ {
+ opt.currentText = m_initialText;
+ opt.currentIcon = m_initialIcon;
+ }
+ p.drawControl(QStyle::CE_ComboBoxLabel, opt);
+ }
+
+private:
+ QString m_initialText;
+ QIcon m_initialIcon;
+};
+} // anonymous namespace
+
+class Kleo::KeysComboBox : public ComboBox
+{
+ Q_OBJECT
+public:
+ explicit KeysComboBox(QWidget *parent = Q_NULLPTR)
+ : ComboBox(parent) {}
+ explicit KeysComboBox(const QString &initialText, QWidget *parent = Q_NULLPTR)
+ : ComboBox(initialText, parent) {}
+ explicit KeysComboBox(const std::vector<Key> &keys, QWidget *parent = Q_NULLPTR)
+ : ComboBox(make_initial_text(keys), parent)
+ {
+ setKeys(keys);
+ }
+
+ void setKeys(const std::vector<Key> &keys)
+ {
+ clear();
+ Q_FOREACH (const Key &key, keys) {
+ addItem(Formatting::formatForComboBox(key), qVariantFromValue(key));
+ }
+ }
+
+ std::vector<Key> keys() const
+ {
+ std::vector<Key> result;
+ result.reserve(count());
+ for (int i = 0, end = count(); i != end; ++i) {
+ result.push_back(qvariant_cast<Key>(itemData(i)));
+ }
+ return result;;
+ }
+
+ int findOrAdd(const Key &key)
+ {
+ for (int i = 0, end = count(); i != end; ++i)
+ if (_detail::ByFingerprint<std::equal_to>()(key, qvariant_cast<Key>(itemData(i)))) {
+ return i;
+ }
+ insertItem(0, Formatting::formatForComboBox(key), qVariantFromValue(key));
+ return 0;
+ }
+
+ void addAndSelectCertificate(const Key &key)
+ {
+ setCurrentIndex(findOrAdd(key));
+ }
+
+ Key currentKey() const
+ {
+ return qvariant_cast<Key>(itemData(currentIndex()));
+ }
+
+};
+
+CertificateSelectionLine::CertificateSelectionLine(const QString &toFrom, const QString &mailbox, const std::vector<Key> &pgp, bool pgpAmbig, const std::vector<Key> &cms, bool cmsAmbig, QWidget *q, QGridLayout &glay)
+ : pgpAmbiguous(pgpAmbig),
+ cmsAmbiguous(cmsAmbig),
+ mToFromLB(new QLabel(toFrom, q)),
+ mMailboxLB(new QLabel(mailbox, q)),
+ mSbox(new QStackedWidget(q)),
+ mPgpCB(new KeysComboBox(pgp, mSbox)),
+ mCmsCB(new KeysComboBox(cms, mSbox)),
+ noProtocolCB(new KeysComboBox(i18n("(please choose between OpenPGP and S/MIME first)"), mSbox)),
+ mToolTB(new QToolButton(q))
+{
+ QFont bold;
+ bold.setBold(true);
+ mToFromLB->setFont(bold);
+
+ mMailboxLB->setTextFormat(Qt::PlainText);
+ mToolTB->setText(i18n("..."));
+
+ mPgpCB->setEnabled(!pgp.empty());
+ mCmsCB->setEnabled(!cms.empty());
+ noProtocolCB->setEnabled(false);
+
+ mPgpCB->setKeys(pgp);
+ if (pgpAmbiguous) {
+ mPgpCB->setCurrentIndex(-1);
+ }
+
+ mCmsCB->setKeys(cms);
+ if (cmsAmbiguous) {
+ mCmsCB->setCurrentIndex(-1);
+ }
+
+ mSbox->addWidget(mPgpCB);
+ mSbox->addWidget(mCmsCB);
+ mSbox->addWidget(noProtocolCB);
+ mSbox->setCurrentWidget(noProtocolCB);
+
+ const int row = glay.rowCount();
+ unsigned int col = 0;
+ glay.addWidget(mToFromLB, row, col++);
+ glay.addWidget(mMailboxLB, row, col++);
+ glay.addWidget(mSbox, row, col++);
+ glay.addWidget(mToolTB, row, col++);
+ assert(col == NumColumns);
+
+ q->connect(mPgpCB, SIGNAL(currentIndexChanged(int)), SLOT(slotCompleteChanged()));
+ q->connect(mCmsCB, SIGNAL(currentIndexChanged(int)), SLOT(slotCompleteChanged()));
+ q->connect(mToolTB, SIGNAL(clicked()), SLOT(slotCertificateSelectionDialogRequested()));
+}
+
+QString CertificateSelectionLine::mailboxText() const
+{
+ return mMailboxLB->text();
+}
+
+void CertificateSelectionLine::addAndSelectCertificate(const Key &key) const
+{
+ if (KeysComboBox *const cb = comboBox(key.protocol())) {
+ cb->addAndSelectCertificate(key);
+ cb->setEnabled(true);
+ }
+}
+
+void CertificateSelectionLine::showHide(Protocol proto, bool &first, bool showAll, bool op) const
+{
+ if (op && (showAll || wasInitiallyAmbiguous(proto))) {
+
+ mToFromLB->setVisible(first);
+ first = false;
+
+ QFont font = mMailboxLB->font();
+ font.setBold(wasInitiallyAmbiguous(proto));
+ mMailboxLB->setFont(font);
+
+ mSbox->setCurrentIndex(proto);
+
+ mMailboxLB->show();
+ mSbox->show();
+ mToolTB->show();
+ } else {
+ mToFromLB->hide();
+ mMailboxLB->hide();
+ mSbox->hide();
+ mToolTB->hide();
+ }
+
+}
+
+bool CertificateSelectionLine::wasInitiallyAmbiguous(Protocol proto) const
+{
+ return (proto == OpenPGP && pgpAmbiguous)
+ || (proto == CMS && cmsAmbiguous);
+}
+
+bool CertificateSelectionLine::isStillAmbiguous(Protocol proto) const
+{
+ kleo_assert(proto == OpenPGP || proto == CMS);
+ const KeysComboBox *const cb = comboBox(proto);
+ return cb->currentIndex() == -1;
+}
+
+Key CertificateSelectionLine::key(Protocol proto) const
+{
+ kleo_assert(proto == OpenPGP || proto == CMS);
+ const KeysComboBox *const cb = comboBox(proto);
+ return cb->currentKey();
+}
+
+const QToolButton *CertificateSelectionLine::toolButton() const
+{
+ return mToolTB;
+}
+
+void CertificateSelectionLine::kill()
+{
+ delete mToFromLB;
+ delete mMailboxLB;
+ delete mSbox;
+ delete mToolTB;
+}
+
+KeysComboBox *CertificateSelectionLine::comboBox(Protocol proto) const
+{
+ if (proto == OpenPGP) {
+ return mPgpCB;
+ }
+ if (proto == CMS) {
+ return mCmsCB;
+ }
+ return 0;
+}
+
+#include "certificateselectionline.moc"
diff --git a/src/crypto/gui/certificateselectionline.h b/src/crypto/gui/certificateselectionline.h
new file mode 100644
index 0000000..fdf0628
--- /dev/null
+++ b/src/crypto/gui/certificateselectionline.h
@@ -0,0 +1,112 @@
+/* crypto/gui/certificateselectionline.h
+
+ This file is part of Kleopatra, the KDE keymanager
+ Copyright (c) 2009 Klarälvdalens Datakonsult AB
+ 2016 Intevation GmbH
+
+ Kleopatra is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ Kleopatra is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+ In addition, as a special exception, the copyright holders give
+ permission to link the code of this program with any edition of
+ the Qt library by Trolltech AS, Norway (or with modified versions
+ of Qt that use the same license as Qt), and distribute linked
+ combinations including the two. You must obey the GNU General
+ Public License in all respects for all of the code used other than
+ Qt. If you modify this file, you may extend this exception to
+ your version of the file, but you are not obligated to do so. If
+ you do not wish to do so, delete this exception statement from
+ your version.
+*/
+
+#ifndef CRYPTO_GUI_CERTIFICATESELECTIONLINE_H
+#define CRYPTO_GUI_CERTIFICATESELECTIONLINE_H
+
+#include <QString>
+#include <vector>
+#include <QGridLayout>
+
+#include <gpgme++/key.h>
+
+class QToolButton;
+class QLabel;
+class QStackedWidget;
+
+namespace Kleo
+{
+
+class KeysComboBox;
+
+class CertificateSelectionLine
+{
+public:
+ /** Number of columns needed in the gridlayout. */
+ static const unsigned int NumColumns = 4;
+
+ /** Create a certificateselection line that distinguishes between protocols.
+ *
+ * Ambiguity means here that there is not a single valid choice or that
+ * soemthing is not selected. There are basically two modes here, one is
+ * for a protocol specific selection, that is used mainly by GpgOL over assuan.
+ * This is the constructor for that mode. The second mode does not care about
+ * protocols.
+ *
+ * @param toFrom: An optional label.
+ * @param mailbox: The Mailbox for which the certificate should be selected.
+ * @param pgp: List of PGP Certificates.
+ * @param pgpAmbig: Whether or not the PGP Cert is ambigous.
+ * @param cms: List of CMS Certificates.
+ * @param cmsAmbig: Whether or not the CMS Cert is ambigous.
+ * @param q: Parent widget.
+ * @param glay: Layout to add the widgets to.
+ */
+ CertificateSelectionLine(const QString &toFrom, const QString &mailbox,
+ const std::vector<GpgME::Key> &pgp, bool pgpAmbig,
+ const std::vector<GpgME::Key> &cms, bool cmsAmbig,
+ QWidget *q, QGridLayout &glay);
+
+ void showHide(GpgME::Protocol proto, bool &first, bool showAll, bool op) const;
+
+ bool wasInitiallyAmbiguous(GpgME::Protocol proto) const;
+
+ bool isStillAmbiguous(GpgME::Protocol proto) const;
+
+ QString mailboxText() const;
+
+ void addAndSelectCertificate(const GpgME::Key &key) const;
+
+ GpgME::Key key(GpgME::Protocol proto) const;
+
+ const QToolButton *toolButton() const;
+
+ void kill();
+
+ KeysComboBox *comboBox(GpgME::Protocol proto) const;
+
+private:
+ bool pgpAmbiguous : 1;
+ bool cmsAmbiguous : 1;
+
+ QLabel *mToFromLB;
+ QLabel *mMailboxLB;
+ QStackedWidget *mSbox;
+ KeysComboBox *mPgpCB,
+ *mCmsCB,
+ *noProtocolCB;
+ QToolButton *mToolTB;
+};
+
+} // namespace Kleo
+
+#endif // CRYPTO_GUI_CERTIFICATESELECTIONLINE_H
diff --git a/src/crypto/gui/signencryptemailconflictdialog.cpp b/src/crypto/gui/signencryptemailconflictdialog.cpp
index c3aab07..ad14efb 100644
--- a/src/crypto/gui/signencryptemailconflictdialog.cpp
+++ b/src/crypto/gui/signencryptemailconflictdialog.cpp
@@ -37,12 +37,10 @@
#include <crypto/sender.h>
#include <crypto/recipient.h>
-#include <dialogs/certificateselectiondialog.h>
-
-#include <Libkleo/Predicates>
+#include "dialogs/certificateselectiondialog.h"
+#include "certificateselectionline.h"
#include <utils/gui-helper.h>
-#include <utils/formatting.h>
#include <utils/kleo_assert.h>
#include <utils/kdsignalblocker.h>
@@ -64,8 +62,6 @@
#include <QCheckBox>
#include <QRadioButton>
#include <QPushButton>
-#include <QStylePainter>
-#include <QStyle>
#include <QPointer>
#include <boost/shared_ptr.hpp>
@@ -83,320 +79,6 @@ using namespace boost;
Q_DECLARE_METATYPE(GpgME::Key)
Q_DECLARE_METATYPE(GpgME::UserID)
-namespace
-{
-
-// A QComboBox with an initial text (as known from web browsers)
-//
-// only works with read-only QComboBoxen, doesn't affect sizeHint
-// as it should...
-//
-class ComboBox : public QComboBox
-{
- Q_OBJECT
- Q_PROPERTY(QString initialText READ initialText WRITE setInitialText)
- Q_PROPERTY(QIcon initialIcon READ initialIcon WRITE setInitialIcon)
-public:
- explicit ComboBox(QWidget *parent = Q_NULLPTR)
- : QComboBox(parent),
- m_initialText(),
- m_initialIcon()
- {
-
- }
-
- explicit ComboBox(const QString &initialText, QWidget *parent = Q_NULLPTR)
- : QComboBox(parent),
- m_initialText(initialText),
- m_initialIcon()
- {
-
- }
-
- explicit ComboBox(const QIcon &initialIcon, const QString &initialText, QWidget *parent = Q_NULLPTR)
- : QComboBox(parent),
- m_initialText(initialText),
- m_initialIcon(initialIcon)
- {
-
- }
-
- QString initialText() const
- {
- return m_initialText;
- }
- QIcon initialIcon() const
- {
- return m_initialIcon;
- }
-
-public Q_SLOTS:
- void setInitialText(const QString &txt)
- {
- if (txt == m_initialText) {
- return;
- }
- m_initialText = txt;
- if (currentIndex() == -1) {
- update();
- }
- }
- void setInitialIcon(const QIcon &icon)
- {
- if (icon.cacheKey() == m_initialIcon.cacheKey()) {
- return;
- }
- m_initialIcon = icon;
- if (currentIndex() == -1) {
- update();
- }
- }
-
-protected:
- void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE {
- QStylePainter p(this);
- p.setPen(palette().color(QPalette::Text));
- QStyleOptionComboBox opt;
- initStyleOption(&opt);
- p.drawComplexControl(QStyle::CC_ComboBox, opt);
-
- if (currentIndex() == -1)
- {
- opt.currentText = m_initialText;
- opt.currentIcon = m_initialIcon;
- }
- p.drawControl(QStyle::CE_ComboBoxLabel, opt);
- }
-
-private:
- QString m_initialText;
- QIcon m_initialIcon;
-};
-
-static QString make_initial_text(const std::vector<Key> &keys)
-{
- if (keys.empty()) {
- return i18n("(no matching certificates found)");
- } else {
- return i18n("Please select a certificate");
- }
-}
-
-class KeysComboBox : public ComboBox
-{
- Q_OBJECT
-public:
- explicit KeysComboBox(QWidget *parent = Q_NULLPTR)
- : ComboBox(parent) {}
- explicit KeysComboBox(const QString &initialText, QWidget *parent = Q_NULLPTR)
- : ComboBox(initialText, parent) {}
- explicit KeysComboBox(const std::vector<Key> &keys, QWidget *parent = Q_NULLPTR)
- : ComboBox(make_initial_text(keys), parent)
- {
- setKeys(keys);
- }
-
- void setKeys(const std::vector<Key> &keys)
- {
- clear();
- Q_FOREACH (const Key &key, keys) {
- addItem(Formatting::formatForComboBox(key), qVariantFromValue(key));
- }
- }
-
- std::vector<Key> keys() const
- {
- std::vector<Key> result;
- result.reserve(count());
- for (int i = 0, end = count(); i != end; ++i) {
- result.push_back(qvariant_cast<Key>(itemData(i)));
- }
- return result;;
- }
-
- int findOrAdd(const Key &key)
- {
- for (int i = 0, end = count(); i != end; ++i)
- if (_detail::ByFingerprint<std::equal_to>()(key, qvariant_cast<Key>(itemData(i)))) {
- return i;
- }
- insertItem(0, Formatting::formatForComboBox(key), qVariantFromValue(key));
- return 0;
- }
-
- void addAndSelectCertificate(const Key &key)
- {
- setCurrentIndex(findOrAdd(key));
- }
-
- Key currentKey() const
- {
- return qvariant_cast<Key>(itemData(currentIndex()));
- }
-
-};
-
-class Line
-{
-public:
- static const unsigned int NumColumns = 4;
-
- Line(const QString &toFrom, const QString &mailbox, const std::vector<Key> &pgp, bool pgpAmbig, const std::vector<Key> &cms, bool cmsAmbig, QWidget *q, QGridLayout &glay)
- : pgpAmbiguous(pgpAmbig),
- cmsAmbiguous(cmsAmbig),
- toFromLB(new QLabel(toFrom, q)),
- mailboxLB(new QLabel(mailbox, q)),
- sbox(new QStackedWidget(q)),
- pgpCB(new KeysComboBox(pgp, sbox)),
- cmsCB(new KeysComboBox(cms, sbox)),
- noProtocolCB(new KeysComboBox(i18n("(please choose between OpenPGP and S/MIME first)"), sbox)),
- toolTB(new QToolButton(q))
- {
- KDAB_SET_OBJECT_NAME(toFromLB);
- KDAB_SET_OBJECT_NAME(mailboxLB);
- KDAB_SET_OBJECT_NAME(noProtocolCB);
- KDAB_SET_OBJECT_NAME(pgpCB);
- KDAB_SET_OBJECT_NAME(cmsCB);
- KDAB_SET_OBJECT_NAME(sbox);
- KDAB_SET_OBJECT_NAME(toolTB);
-
- QFont bold;
- bold.setBold(true);
- toFromLB->setFont(bold);
-
- mailboxLB->setTextFormat(Qt::PlainText);
- toolTB->setText(i18n("..."));
-
- pgpCB->setEnabled(!pgp.empty());
- cmsCB->setEnabled(!cms.empty());
- noProtocolCB->setEnabled(false);
-
- pgpCB->setKeys(pgp);
- if (pgpAmbiguous) {
- pgpCB->setCurrentIndex(-1);
- }
-
- cmsCB->setKeys(cms);
- if (cmsAmbiguous) {
- cmsCB->setCurrentIndex(-1);
- }
-
- sbox->addWidget(pgpCB);
- sbox->addWidget(cmsCB);
- sbox->addWidget(noProtocolCB);
- sbox->setCurrentWidget(noProtocolCB);
-
- const int row = glay.rowCount();
- unsigned int col = 0;
- glay.addWidget(toFromLB, row, col++);
- glay.addWidget(mailboxLB, row, col++);
- glay.addWidget(sbox, row, col++);
- glay.addWidget(toolTB, row, col++);
- assert(col == NumColumns);
-
- q->connect(pgpCB, SIGNAL(currentIndexChanged(int)), SLOT(slotCompleteChanged()));
- q->connect(cmsCB, SIGNAL(currentIndexChanged(int)), SLOT(slotCompleteChanged()));
- q->connect(toolTB, SIGNAL(clicked()), SLOT(slotCertificateSelectionDialogRequested()));
- }
-
- KeysComboBox *comboBox(Protocol proto) const
- {
- if (proto == OpenPGP) {
- return pgpCB;
- }
- if (proto == CMS) {
- return cmsCB;
- }
- return 0;
- }
-
- QString mailboxText() const
- {
- return mailboxLB->text();
- }
-
- void addAndSelectCertificate(const Key &key) const
- {
- if (KeysComboBox *const cb = comboBox(key.protocol())) {
- cb->addAndSelectCertificate(key);
- cb->setEnabled(true);
- }
- }
-
- void showHide(Protocol proto, bool &first, bool showAll, bool op) const
- {
- if (op && (showAll || wasInitiallyAmbiguous(proto))) {
-
- toFromLB->setVisible(first);
- first = false;
-
- QFont font = mailboxLB->font();
- font.setBold(wasInitiallyAmbiguous(proto));
- mailboxLB->setFont(font);
-
- sbox->setCurrentIndex(proto);
-
- mailboxLB->show();
- sbox->show();
- toolTB->show();
- } else {
- toFromLB->hide();
- mailboxLB->hide();
- sbox->hide();
- toolTB->hide();
- }
-
- }
-
- bool wasInitiallyAmbiguous(Protocol proto) const
- {
- return (proto == OpenPGP && pgpAmbiguous)
- || (proto == CMS && cmsAmbiguous);
- }
-
- bool isStillAmbiguous(Protocol proto) const
- {
- kleo_assert(proto == OpenPGP || proto == CMS);
- const KeysComboBox *const cb = comboBox(proto);
- return cb->currentIndex() == -1;
- }
-
- Key key(Protocol proto) const
- {
- kleo_assert(proto == OpenPGP || proto == CMS);
- const KeysComboBox *const cb = comboBox(proto);
- return cb->currentKey();
- }
-
- const QToolButton *toolButton() const
- {
- return toolTB;
- }
-
- void kill()
- {
- delete toFromLB;
- delete mailboxLB;
- delete sbox;
- delete toolTB;
- }
-
-private:
- bool pgpAmbiguous : 1;
- bool cmsAmbiguous : 1;
-
- QLabel *toFromLB;
- QLabel *mailboxLB;
- QStackedWidget *sbox;
- KeysComboBox *pgpCB;
- KeysComboBox *cmsCB;
- KeysComboBox *noProtocolCB;
- QToolButton *toolTB;
-
-};
-
-}
-
static CertificateSelectionDialog *
create_certificate_selection_dialog(QWidget *parent, Protocol proto)
{
@@ -498,13 +180,13 @@ private:
bool first;
first = true;
- Q_FOREACH (const Line &line, ui.signers) {
+ Q_FOREACH (const CertificateSelectionLine &line, ui.signers) {
line.showHide(proto, first, showAll, sign);
}
ui.selectSigningCertificatesGB.setVisible(sign && (showAll || !first));
first = true;
- Q_FOREACH (const Line &line, ui.recipients) {
+ Q_FOREACH (const CertificateSelectionLine &line, ui.recipients) {
line.showHide(proto, first, showAll, encrypt);
}
ui.selectEncryptionCertificatesGB.setVisible(encrypt && (showAll || !first));
@@ -513,12 +195,12 @@ private:
bool needShowAllRecipients(Protocol proto) const
{
if (sign)
- if (const unsigned int num = kdtools::count_if(ui.signers, boost::bind(&Line::wasInitiallyAmbiguous, _1, proto)))
+ if (const unsigned int num = kdtools::count_if(ui.signers, boost::bind(&CertificateSelectionLine::wasInitiallyAmbiguous, _1, proto)))
if (num != ui.signers.size()) {
return true;
}
if (encrypt)
- if (const unsigned int num = kdtools::count_if(ui.recipients, boost::bind(&Line::wasInitiallyAmbiguous, _1, proto)))
+ if (const unsigned int num = kdtools::count_if(ui.recipients, boost::bind(&CertificateSelectionLine::wasInitiallyAmbiguous, _1, proto)))
if (num != ui.recipients.size()) {
return true;
}
@@ -598,7 +280,7 @@ private:
const QObject *const s = q->sender();
const Protocol proto = q->selectedProtocol();
QPointer<CertificateSelectionDialog> dlg;
- Q_FOREACH (const Line &l, ui.signers)
+ Q_FOREACH (const CertificateSelectionLine &l, ui.signers)
if (s == l.toolButton()) {
dlg = create_signing_certificate_selection_dialog(q, proto, l.mailboxText());
if (dlg->exec()) {
@@ -607,7 +289,7 @@ private:
// ### switch to key.protocol(), in case proto == UnknownProtocol
break;
}
- Q_FOREACH (const Line &l, ui.recipients)
+ Q_FOREACH (const CertificateSelectionLine &l, ui.recipients)
if (s == l.toolButton()) {
dlg = create_encryption_certificate_selection_dialog(q, proto, l.mailboxText());
if (dlg->exec()) {
@@ -639,7 +321,7 @@ private:
QVBoxLayout vlay;
QHBoxLayout hlay;
QGridLayout glay;
- std::vector<Line> signers, recipients;
+ std::vector<CertificateSelectionLine> signers, recipients;
void setOkButtonEnabled(bool enable)
{
@@ -719,29 +401,29 @@ private:
void clearSendersAndRecipients()
{
- std::vector<Line> sig, enc;
+ std::vector<CertificateSelectionLine> sig, enc;
sig.swap(signers);
enc.swap(recipients);
- kdtools::for_each(sig, mem_fn(&Line::kill));
- kdtools::for_each(enc, mem_fn(&Line::kill));
+ kdtools::for_each(sig, mem_fn(&CertificateSelectionLine::kill));
+ kdtools::for_each(enc, mem_fn(&CertificateSelectionLine::kill));
glay.removeWidget(&selectSigningCertificatesGB);
glay.removeWidget(&selectEncryptionCertificatesGB);
}
void addSelectSigningCertificatesGB()
{
- glay.addWidget(&selectSigningCertificatesGB, glay.rowCount(), 0, 1, Line::NumColumns);
+ glay.addWidget(&selectSigningCertificatesGB, glay.rowCount(), 0, 1, CertificateSelectionLine::NumColumns);
}
void addSelectEncryptionCertificatesGB()
{
- glay.addWidget(&selectEncryptionCertificatesGB, glay.rowCount(), 0, 1, Line::NumColumns);
+ glay.addWidget(&selectEncryptionCertificatesGB, glay.rowCount(), 0, 1, CertificateSelectionLine::NumColumns);
}
void addSigner(const QString &mailbox,
const std::vector<Key> &pgp, bool pgpAmbiguous,
const std::vector<Key> &cms, bool cmsAmbiguous, QWidget *q)
{
- Line line(i18n("From:"), mailbox, pgp, pgpAmbiguous, cms, cmsAmbiguous, q, glay);
+ CertificateSelectionLine line(i18n("From:"), mailbox, pgp, pgpAmbiguous, cms, cmsAmbiguous, q, glay);
signers.push_back(line);
}
@@ -749,7 +431,7 @@ private:
const std::vector<Key> &pgp, bool pgpAmbiguous,
const std::vector<Key> &cms, bool cmsAmbiguous, QWidget *q)
{
- Line line(i18n("To:"), mailbox, pgp, pgpAmbiguous, cms, cmsAmbiguous, q, glay);
+ CertificateSelectionLine line(i18n("To:"), mailbox, pgp, pgpAmbiguous, cms, cmsAmbiguous, q, glay);
recipients.push_back(line);
}
@@ -866,12 +548,12 @@ bool SignEncryptEMailConflictDialog::isComplete() const
bool SignEncryptEMailConflictDialog::Private::isComplete(Protocol proto) const
{
- return (!sign || kdtools::none_of(ui.signers, boost::bind(&Line::isStillAmbiguous, _1, proto)))
- && (!encrypt || kdtools::none_of(ui.recipients, boost::bind(&Line::isStillAmbiguous, _1, proto)))
+ return (!sign || kdtools::none_of(ui.signers, boost::bind(&CertificateSelectionLine::isStillAmbiguous, _1, proto)))
+ && (!encrypt || kdtools::none_of(ui.recipients, boost::bind(&CertificateSelectionLine::isStillAmbiguous, _1, proto)))
;
}
-static std::vector<Key> get_keys(const std::vector<Line> &lines, Protocol proto)
+static std::vector<Key> get_keys(const std::vector<CertificateSelectionLine> &lines, Protocol proto)
{
if (proto == UnknownProtocol) {
return std::vector<Key>();
@@ -881,7 +563,7 @@ static std::vector<Key> get_keys(const std::vector<Line> &lines, Protocol proto)
std::vector<Key> keys;
keys.reserve(lines.size());
kdtools::transform(lines, std::back_inserter(keys),
- boost::bind(&Line::key, _1, proto));
+ boost::bind(&CertificateSelectionLine::key, _1, proto));
kleo_assert(kdtools::none_of(keys, mem_fn(&Key::isNull)));
return keys;
}