summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-08-05 07:55:22 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-08-05 07:57:29 (GMT)
commitca707754b5d5cf6f3f4f6a9ed289f9e40729ed4b (patch)
tree8ee0a6889627a3e6e00b31013a13927a634c4f50
parent80988b90092d5a973fe90c31bcd54c4266771ca9 (diff)
Replace certificatecombobox with KeySelectionCombo
This moves back the certificatecombo code into the certificateselectionline and removes it as an extra class.
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/crypto/gui/certificatecombobox.cpp117
-rw-r--r--src/crypto/gui/certificatecombobox.h74
-rw-r--r--src/crypto/gui/certificateselectionline.cpp120
-rw-r--r--src/crypto/gui/certificateselectionline.h6
-rw-r--r--src/crypto/gui/signencryptwidget.cpp29
-rw-r--r--src/crypto/gui/signencryptwidget.h6
8 files changed, 119 insertions, 236 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index a26afeb..7a061fa 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,7 +9,7 @@ option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF)
set(KF5_VERSION "5.17.0")
set(GPGMEPP_VERSION "5.2.81")
set(KMIME_VERSION "5.1.40")
-set(LIBKLEO_VERSION "5.3.41")
+set(LIBKLEO_VERSION "5.3.42")
set(QT_REQUIRED_VERSION "5.4.0")
find_package(ECM ${KF5_VERSION} REQUIRED NO_MODULE)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 3b92e66..82e643d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -136,7 +136,6 @@ set(_kleopatra_SRCS
crypto/gui/wizardpage.cpp
crypto/gui/certificateselectionline.cpp
- crypto/gui/certificatecombobox.cpp
crypto/gui/certificatelineedit.cpp
crypto/gui/signingcertificateselectionwidget.cpp
crypto/gui/signingcertificateselectiondialog.cpp
diff --git a/src/crypto/gui/certificatecombobox.cpp b/src/crypto/gui/certificatecombobox.cpp
deleted file mode 100644
index 5d6ea7a..0000000
--- a/src/crypto/gui/certificatecombobox.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/* crypto/gui/certificatecombobox.cpp
-
- This file is part of Kleopatra, the KDE keymanager
- Copyright (c) 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 "certificatecombobox.h"
-
-#include <Libkleo/KeyListModelInterface>
-
-#include <QStylePainter>
-#include <QStyleOptionComboBox>
-#include <QStyle>
-
-#include <gpgme++/key.h>
-using namespace Kleo;
-
-Q_DECLARE_METATYPE(GpgME::Key);
-
-CertificateComboBox::CertificateComboBox(const QIcon &initialIcon,
- const QString &initialText,
- QWidget *parent)
- : QComboBox(parent),
- m_initialText(initialText),
- m_initialIcon(initialIcon)
-{
-}
-
-QString CertificateComboBox::initialText() const
-{
- return m_initialText;
-}
-
-QIcon CertificateComboBox::initialIcon() const
-{
- return m_initialIcon;
-}
-
-void CertificateComboBox::setInitialText(const QString &txt)
-{
- if (txt == m_initialText) {
- return;
- }
- m_initialText = txt;
- if (currentIndex() == -1) {
- update();
- }
-}
-
-void CertificateComboBox::setInitialIcon(const QIcon &icon)
-{
- if (icon.cacheKey() == m_initialIcon.cacheKey()) {
- return;
- }
- m_initialIcon = icon;
- if (currentIndex() == -1) {
- update();
- }
-}
-
-void CertificateComboBox::paintEvent(QPaintEvent *)
-{
- QStylePainter p(this);
- p.setPen(palette().color(QPalette::Text));
- QStyleOptionComboBox opt;
- initStyleOption(&opt);
- if (currentIndex() == -1)
- {
- opt.currentText = m_initialText;
- opt.currentIcon = m_initialIcon;
- }
- if (count() > 1) {
- p.drawComplexControl(QStyle::CC_ComboBox, opt);
- p.drawControl(QStyle::CE_ComboBoxLabel, opt);
- } else {
- style()->drawPrimitive (QStyle::PE_Frame, &opt, &p, this);
- style()->drawItemText (&p, rect(), Qt::AlignLeft, palette(), isEnabled(), opt.currentText);
- }
-}
-
-void CertificateComboBox::showPopup()
-{
- if (count() <= 1) {
- return;
- }
- QComboBox::showPopup();
-}
-
-GpgME::Key CertificateComboBox::key() const
-{
- return currentData(KeyListModelInterface::KeyRole).value<GpgME::Key>();
-}
diff --git a/src/crypto/gui/certificatecombobox.h b/src/crypto/gui/certificatecombobox.h
deleted file mode 100644
index 9989c50..0000000
--- a/src/crypto/gui/certificatecombobox.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/* crypto/gui/certificatecombobox.h
-
- This file is part of Kleopatra, the KDE keymanager
- Copyright (c) 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_CERTIFICATECOMBOBOX_H
-#define CRYPTO_GUI_CERTIFICATECOMBOBOX_H
-
-#include <QComboBox>
-#include <QIcon>
-#include <QString>
-
-namespace GpgME
-{
- class Key;
-}
-
-namespace Kleo {
-/** A QComboBox with an initial text for certificates.
- *
- * Becomes flat and without arrow if there is only one element.
- */
-class CertificateComboBox : public QComboBox
-{
- Q_OBJECT
-public:
- explicit CertificateComboBox(const QIcon &initialIcon, const QString &initialText, QWidget *parent = Q_NULLPTR);
- explicit CertificateComboBox(QWidget *parent = Q_NULLPTR) :
- CertificateComboBox(QIcon(), QString(), parent) {}
- explicit CertificateComboBox(const QString &initialText, QWidget *parent = Q_NULLPTR) :
- CertificateComboBox(QIcon(), initialText, parent) {}
-
- QString initialText() const;
- QIcon initialIcon() const;
-
- GpgME::Key key() const;
-
-public Q_SLOTS:
- void setInitialText(const QString &txt);
- void setInitialIcon(const QIcon &icon);
- void showPopup() Q_DECL_OVERRIDE;
-protected:
- void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
-private:
- QString m_initialText;
- QIcon m_initialIcon;
-};
-} // namespace kleo
-#endif // CRYPTO_GUI_CERTIFICATECOMBOBOX_H
diff --git a/src/crypto/gui/certificateselectionline.cpp b/src/crypto/gui/certificateselectionline.cpp
index c86be3b..83bbb09 100644
--- a/src/crypto/gui/certificateselectionline.cpp
+++ b/src/crypto/gui/certificateselectionline.cpp
@@ -35,9 +35,11 @@
#include <QLabel>
#include <QStackedWidget>
#include <QComboBox>
+#include <QStylePainter>
+#include <QStyleOptionComboBox>
+#include <QStyle>
#include "utils/kleo_assert.h"
-#include "certificatecombobox.h"
#include <KLocalizedString>
@@ -61,18 +63,104 @@ static QString make_initial_text(const std::vector<Key> &keys)
}
}
-}
+// 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::MyCertificateComboBox : public CertificateComboBox
+class Kleo::KeysComboBox : public ComboBox
{
Q_OBJECT
public:
- explicit MyCertificateComboBox(QWidget *parent = Q_NULLPTR)
- : CertificateComboBox(parent) {}
- explicit MyCertificateComboBox(const QString &initialText, QWidget *parent = Q_NULLPTR)
- : CertificateComboBox(initialText, parent) {}
- explicit MyCertificateComboBox(const std::vector<Key> &keys, QWidget *parent = Q_NULLPTR)
- : CertificateComboBox(make_initial_text(keys), parent)
+ 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);
}
@@ -123,9 +211,9 @@ CertificateSelectionLine::CertificateSelectionLine(const QString &toFrom, const
mToFromLB(new QLabel(toFrom, q)),
mMailboxLB(new QLabel(mailbox, q)),
mSbox(new QStackedWidget(q)),
- mPgpCB(new MyCertificateComboBox(pgp, mSbox)),
- mCmsCB(new MyCertificateComboBox(cms, mSbox)),
- noProtocolCB(new MyCertificateComboBox(i18n("(please choose between OpenPGP and S/MIME first)"), mSbox)),
+ 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;
@@ -174,7 +262,7 @@ QString CertificateSelectionLine::mailboxText() const
void CertificateSelectionLine::addAndSelectCertificate(const Key &key) const
{
- if (MyCertificateComboBox *const cb = comboBox(key.protocol())) {
+ if (KeysComboBox *const cb = comboBox(key.protocol())) {
cb->addAndSelectCertificate(key);
cb->setEnabled(true);
}
@@ -214,14 +302,14 @@ bool CertificateSelectionLine::wasInitiallyAmbiguous(Protocol proto) const
bool CertificateSelectionLine::isStillAmbiguous(Protocol proto) const
{
kleo_assert(proto == OpenPGP || proto == CMS);
- const MyCertificateComboBox *const cb = comboBox(proto);
+ const KeysComboBox *const cb = comboBox(proto);
return cb->currentIndex() == -1;
}
Key CertificateSelectionLine::key(Protocol proto) const
{
kleo_assert(proto == OpenPGP || proto == CMS);
- const MyCertificateComboBox *const cb = comboBox(proto);
+ const KeysComboBox *const cb = comboBox(proto);
return cb->currentKey();
}
@@ -238,7 +326,7 @@ void CertificateSelectionLine::kill()
delete mToolTB;
}
-MyCertificateComboBox *CertificateSelectionLine::comboBox(Protocol proto) const
+KeysComboBox *CertificateSelectionLine::comboBox(Protocol proto) const
{
if (proto == OpenPGP) {
return mPgpCB;
diff --git a/src/crypto/gui/certificateselectionline.h b/src/crypto/gui/certificateselectionline.h
index 6c877f6..fdf0628 100644
--- a/src/crypto/gui/certificateselectionline.h
+++ b/src/crypto/gui/certificateselectionline.h
@@ -46,7 +46,7 @@ class QStackedWidget;
namespace Kleo
{
-class MyCertificateComboBox;
+class KeysComboBox;
class CertificateSelectionLine
{
@@ -92,7 +92,7 @@ public:
void kill();
- MyCertificateComboBox *comboBox(GpgME::Protocol proto) const;
+ KeysComboBox *comboBox(GpgME::Protocol proto) const;
private:
bool pgpAmbiguous : 1;
@@ -101,7 +101,7 @@ private:
QLabel *mToFromLB;
QLabel *mMailboxLB;
QStackedWidget *mSbox;
- MyCertificateComboBox *mPgpCB,
+ KeysComboBox *mPgpCB,
*mCmsCB,
*noProtocolCB;
QToolButton *mToolTB;
diff --git a/src/crypto/gui/signencryptwidget.cpp b/src/crypto/gui/signencryptwidget.cpp
index 33c0c6f..99779ce 100644
--- a/src/crypto/gui/signencryptwidget.cpp
+++ b/src/crypto/gui/signencryptwidget.cpp
@@ -33,7 +33,6 @@
#include "kleopatra_debug.h"
-#include "certificatecombobox.h"
#include "certificatelineedit.h"
#include <QVBoxLayout>
@@ -44,6 +43,7 @@
#include <Libkleo/DefaultKeyFilter>
#include <Libkleo/KeyListModel>
+#include <Libkleo/KeySelectionCombo>
#include <Libkleo/KeyListSortFilterProxyModel>
#include <KLocalizedString>
@@ -105,14 +105,8 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent)
QCheckBox *sigChk = new QCheckBox(QStringLiteral("Sign as:"));
sigChk->setChecked(true);
- KeyListSortFilterProxyModel *sigModel = new KeyListSortFilterProxyModel(this);
- sigModel->setKeyFilter(boost::shared_ptr<KeyFilter>(new SignCertificateFilter()));
- sigModel->setSourceModel(mModel);
- mModel->setParent(this);
-
- mSigSelect = new CertificateComboBox(i18n("No valid secret keys found."));
- mSigSelect->setModel(sigModel);
- mSigSelect->setModelColumn(KeyListModelInterface::Summary);
+ mSigSelect = new KeySelectionCombo();
+ mSigSelect->setKeyFilter(boost::shared_ptr<KeyFilter>(new SignCertificateFilter()));
sigLay->addWidget(sigChk);
sigLay->addStretch(1);
@@ -122,7 +116,7 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent)
connect(sigChk, &QCheckBox::toggled, mSigSelect, &QWidget::setEnabled);
connect(sigChk, &QCheckBox::toggled, this, &SignEncryptWidget::updateOp);
- connect(mSigSelect, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
+ connect(mSigSelect, &KeySelectionCombo::currentKeyChanged,
this, &SignEncryptWidget::updateOp);
/* Recipient selection */
@@ -148,14 +142,7 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent)
QCheckBox *encSelfChk = new QCheckBox(QStringLiteral("Own certificate:"));
encSelfChk->setChecked(true);
- KeyListSortFilterProxyModel *encModel = new KeyListSortFilterProxyModel(this);
- encModel->setKeyFilter(boost::shared_ptr<KeyFilter>(new EncryptSelfCertificateFilter()));
- encModel->setSourceModel(mModel);
- mModel->setParent(this);
-
- mSelfSelect = new CertificateComboBox(i18n("No valid secret keys found."));
- mSelfSelect->setModel(encModel);
- mSelfSelect->setModelColumn(KeyListModelInterface::Summary);
+ mSelfSelect = new KeySelectionCombo();
encSelfLay->addWidget(encSelfChk);
encSelfLay->addWidget(mSelfSelect);
@@ -163,7 +150,7 @@ SignEncryptWidget::SignEncryptWidget(QWidget *parent)
connect(encSelfChk, &QCheckBox::toggled, mSelfSelect, &QWidget::setEnabled);
connect(encSelfChk, &QCheckBox::toggled, this, &SignEncryptWidget::updateOp);
- connect(mSelfSelect, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
+ connect(mSelfSelect, &KeySelectionCombo::currentKeyChanged,
this, &SignEncryptWidget::updateOp);
lay->addWidget(encBox);
@@ -217,7 +204,7 @@ void SignEncryptWidget::recipientsChanged()
Key SignEncryptWidget::signKey() const
{
if (mSigSelect->isEnabled()) {
- return mSigSelect->key();
+ return mSigSelect->currentKey();
}
return Key();
}
@@ -225,7 +212,7 @@ Key SignEncryptWidget::signKey() const
Key SignEncryptWidget::selfKey() const
{
if (mSelfSelect->isEnabled()) {
- return mSelfSelect->key();
+ return mSelfSelect->currentKey();
}
return Key();
}
diff --git a/src/crypto/gui/signencryptwidget.h b/src/crypto/gui/signencryptwidget.h
index 4706fbc..229b725 100644
--- a/src/crypto/gui/signencryptwidget.h
+++ b/src/crypto/gui/signencryptwidget.h
@@ -41,7 +41,7 @@ class QGridLayout;
namespace Kleo
{
class CertificateLineEdit;
-class CertificateComboBox;
+class KeySelectionCombo;
class AbstractKeyListModel;
class SignEncryptWidget: public QWidget
@@ -83,8 +83,8 @@ Q_SIGNALS:
void keysChanged();
private:
- CertificateComboBox *mSigSelect,
- *mSelfSelect;
+ KeySelectionCombo *mSigSelect,
+ *mSelfSelect;
QVector<CertificateLineEdit *> mRecpWidgets;
QGridLayout *mRecpLayout;
QString mOp;