diff --git a/src/conf/cryptooperationsconfigwidget.cpp b/src/conf/cryptooperationsconfigwidget.cpp index d7c40131a..08dd07a26 100644 --- a/src/conf/cryptooperationsconfigwidget.cpp +++ b/src/conf/cryptooperationsconfigwidget.cpp @@ -1,405 +1,405 @@ /* cryptooperationsconfigwidget.cpp This file is part of kleopatra, the KDE key manager Copyright (c) 2010 Klarälvdalens Datakonsult AB 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by Intevation GmbH Libkleopatra 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. Libkleopatra 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 #include "cryptooperationsconfigwidget.h" #include "kleopatra_debug.h" #include "emailoperationspreferences.h" #include "fileoperationspreferences.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Config; CryptoOperationsConfigWidget::CryptoOperationsConfigWidget(QWidget *p, Qt::WindowFlags f) : QWidget(p, f), mApplyBtn(nullptr) { setupGui(); } static void resetDefaults() { auto config = QGpgME::cryptoConfig(); if (!config) { qCWarning(KLEOPATRA_LOG) << "Failed to obtain config"; return; } for (const auto &compName: config->componentList()) { auto comp = config->component(compName); if (!comp) { qCWarning(KLEOPATRA_LOG) << "Failed to find component:" << comp; return; } for (const auto &grpName: comp->groupList()) { auto grp = comp->group(grpName); if (!grp) { qCWarning(KLEOPATRA_LOG) << "Failed to find group:" << grp << "in component:" << compName; return; } for (const auto &entryName: grp->entryList()) { auto entry = grp->entry(entryName); if (!entry) { qCWarning(KLEOPATRA_LOG) << "Failed to find entry:" << entry << "in group:"<< grp << "in component:" << compName; return; } entry->resetToDefault(); } } } config->sync(true); return; } void CryptoOperationsConfigWidget::applyProfile(const QString &profile) { if (profile.isEmpty()) { return; } qCDebug(KLEOPATRA_LOG) << "Applying profile " << profile; if (profile == i18n("default")) { if (KMessageBox::warningYesNo( this, i18n("This means that every configuration option of the GnuPG System will be reset to its default."), i18n("Apply profile"), KStandardGuiItem::apply(), KStandardGuiItem::no()) != KMessageBox::Yes) { return; } resetDefaults(); KeyFilterManager::instance()->reload(); return; } mApplyBtn->setEnabled(false); QDir datadir(QString::fromLocal8Bit(GpgME::dirInfo("datadir")) + QStringLiteral("/../doc/gnupg/examples")); const auto path = datadir.filePath(profile + QStringLiteral(".prf")); auto gpgconf = new QProcess; const auto ei = GpgME::engineInfo(GpgME::GpgConfEngine); Q_ASSERT (ei.fileName()); gpgconf->setProgram(QFile::decodeName(ei.fileName())); gpgconf->setProcessChannelMode(QProcess::MergedChannels); gpgconf->setArguments(QStringList() << QStringLiteral("--runtime") << QStringLiteral("--apply-profile") << path); qDebug() << "Starting" << ei.fileName() << "with args" << gpgconf->arguments(); connect(gpgconf, static_cast(&QProcess::finished), this, [this, gpgconf, profile] () { mApplyBtn->setEnabled(true); if (gpgconf->exitStatus() != QProcess::NormalExit) { KMessageBox::error(this, QStringLiteral("
%1
").arg(QString::fromLocal8Bit(gpgconf->readAll()))); delete gpgconf; return; } delete gpgconf; KMessageBox::information(this, i18nc("%1 is the name of the profile", "The configuration profile \"%1\" was applied.", profile), i18n("GnuPG Profile - Kleopatra")); auto config = QGpgME::cryptoConfig(); if (config) { config->clear(); } KeyFilterManager::instance()->reload(); }); gpgconf->start(); } // Get a list of available profile files and add a configuration // group if there are any. void CryptoOperationsConfigWidget::setupProfileGui(QBoxLayout *layout) { qCDebug(KLEOPATRA_LOG) << "Engine version "; if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.20" || !layout) { // Profile support is new in 2.1.20 qCDebug(KLEOPATRA_LOG) << "Engine version false"; return; } QDir datadir(QString::fromLocal8Bit(GpgME::dirInfo("datadir")) + QStringLiteral("/../doc/gnupg/examples")); if (!datadir.exists()) { qCDebug(KLEOPATRA_LOG) << "Failed to find gnupg's example profile directory" << datadir.path(); return; } const auto profiles = datadir.entryInfoList(QStringList() << QStringLiteral("*.prf"), QDir::Readable | QDir::Files, QDir::Name); if (profiles.isEmpty()) { qCDebug(KLEOPATRA_LOG) << "Failed to find any profiles in: " << datadir.path(); return; } auto genGrp = new QGroupBox(i18nc("@title", "General Operations")); auto profLayout = new QHBoxLayout; genGrp->setLayout(profLayout); layout->addWidget(genGrp); auto profLabel = new QLabel(i18n("Activate GnuPG Profile:")); profLabel->setToolTip(i18n("A profile consists of various settings that can apply to multiple components of the GnuPG system.")); auto combo = new QComboBox; profLabel->setBuddy(combo); // Add an empty Item to avoid the impression that this GUI element // shows the currently selected profile. combo->addItem(QString()); // We don't translate "default" here because the other profile names are // also not translated as they are taken directly from file. combo->addItem(i18n("default")); for (const auto &profile: profiles) { combo->addItem(profile.baseName()); } mApplyBtn = new QPushButton(i18n("Apply")); mApplyBtn->setEnabled(false); profLayout->addWidget(profLabel); profLayout->addWidget(combo); profLayout->addWidget(mApplyBtn); profLayout->addStretch(1); connect(mApplyBtn, &QPushButton::clicked, this, [this, combo] () { applyProfile(combo->currentText()); }); connect(combo, QOverload::of(&QComboBox::currentIndexChanged), this, [this] (const QString &text) { mApplyBtn->setEnabled(!text.isEmpty()); }); } void CryptoOperationsConfigWidget::setupGui() { QVBoxLayout *baseLay = new QVBoxLayout(this); baseLay->setContentsMargins(0, 0, 0, 0); QGroupBox *mailGrp = new QGroupBox(i18n("EMail Operations")); QVBoxLayout *mailGrpLayout = new QVBoxLayout; mQuickSignCB = new QCheckBox(i18n("Don't confirm signing certificate if there is only one valid certificate for the identity")); mQuickEncryptCB = new QCheckBox(i18n("Don't confirm encryption certificates if there is exactly one valid certificate for each recipient")); mailGrpLayout->addWidget(mQuickSignCB); mailGrpLayout->addWidget(mQuickEncryptCB); mailGrp->setLayout(mailGrpLayout); baseLay->addWidget(mailGrp); QGroupBox *fileGrp = new QGroupBox(i18n("File Operations")); QVBoxLayout *fileGrpLay = new QVBoxLayout; mPGPFileExtCB = new QCheckBox(i18n("Create OpenPGP encrypted files with \".pgp\" file extensions instead of \".gpg\"")); mASCIIArmorCB = new QCheckBox(i18n("Create signed or encrypted files as text files.")); mASCIIArmorCB->setToolTip(i18nc("@info", "Set this option to encode encrypted or signed files as base64 encoded text. " "So that they can be opened with an editor or sent in a mail body. " "This will increase file size by one third.")); mAutoDecryptVerifyCB = new QCheckBox(i18n("Automatically start operation based on input detection for decrypt/verify.")); mTmpDirCB = new QCheckBox(i18n("Create temporary decrypted files in the folder of the encrypted file.")); mTmpDirCB->setToolTip(i18nc("@info", "Set this option to avoid using the users temporary directory.")); fileGrpLay->addWidget(mPGPFileExtCB); fileGrpLay->addWidget(mAutoDecryptVerifyCB); fileGrpLay->addWidget(mASCIIArmorCB); fileGrpLay->addWidget(mTmpDirCB); QGridLayout *comboLay = new QGridLayout; QLabel *chkLabel = new QLabel(i18n("Checksum program to use when creating checksum files:")); comboLay->addWidget(chkLabel, 0, 0); mChecksumDefinitionCB = new QComboBox; comboLay->addWidget(mChecksumDefinitionCB, 0, 1); QLabel *archLabel = new QLabel(i18n("Archive command to use when archiving files:")); comboLay->addWidget(archLabel, 1, 0); mArchiveDefinitionCB = new QComboBox; comboLay->addWidget(mArchiveDefinitionCB, 1, 1); fileGrpLay->addLayout(comboLay); fileGrp->setLayout(fileGrpLay); baseLay->addWidget(fileGrp); setupProfileGui(baseLay); baseLay->addStretch(1); if (!GpgME::hasFeature(0, GpgME::BinaryAndFineGrainedIdentify)) { /* Auto handling requires a working identify in GpgME. * so that classify in kleoaptra can correctly detect the input.*/ mAutoDecryptVerifyCB->setVisible(false); } connect(mQuickSignCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed); connect(mQuickEncryptCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed); connect(mChecksumDefinitionCB, static_cast(&QComboBox::currentIndexChanged), this, &CryptoOperationsConfigWidget::changed); connect(mArchiveDefinitionCB, static_cast(&QComboBox::currentIndexChanged), this, &CryptoOperationsConfigWidget::changed); connect(mPGPFileExtCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed); connect(mAutoDecryptVerifyCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed); connect(mASCIIArmorCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed); connect(mTmpDirCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed); } CryptoOperationsConfigWidget::~CryptoOperationsConfigWidget() {} void CryptoOperationsConfigWidget::defaults() { EMailOperationsPreferences emailPrefs; emailPrefs.setDefaults(); mQuickSignCB->setChecked(emailPrefs.quickSignEMail()); mQuickEncryptCB->setChecked(emailPrefs.quickEncryptEMail()); FileOperationsPreferences filePrefs; filePrefs.setDefaults(); mPGPFileExtCB->setChecked(filePrefs.usePGPFileExt()); mAutoDecryptVerifyCB->setChecked(filePrefs.autoDecryptVerify()); if (mChecksumDefinitionCB->count()) { mChecksumDefinitionCB->setCurrentIndex(0); } if (mArchiveDefinitionCB->count()) { mArchiveDefinitionCB->setCurrentIndex(0); } } Q_DECLARE_METATYPE(std::shared_ptr) void CryptoOperationsConfigWidget::load() { const EMailOperationsPreferences emailPrefs; mQuickSignCB ->setChecked(emailPrefs.quickSignEMail()); mQuickEncryptCB->setChecked(emailPrefs.quickEncryptEMail()); const FileOperationsPreferences filePrefs; mPGPFileExtCB->setChecked(filePrefs.usePGPFileExt()); mAutoDecryptVerifyCB->setChecked(filePrefs.autoDecryptVerify()); mASCIIArmorCB->setChecked(filePrefs.addASCIIArmor()); mTmpDirCB->setChecked(filePrefs.dontUseTmpDir()); const std::vector< std::shared_ptr > cds = ChecksumDefinition::getChecksumDefinitions(); const std::shared_ptr default_cd = ChecksumDefinition::getDefaultChecksumDefinition(cds); mChecksumDefinitionCB->clear(); mArchiveDefinitionCB->clear(); for (const std::shared_ptr &cd : cds) { - mChecksumDefinitionCB->addItem(cd->label(), qVariantFromValue(cd)); + mChecksumDefinitionCB->addItem(cd->label(), QVariant::fromValue(cd)); if (cd == default_cd) { mChecksumDefinitionCB->setCurrentIndex(mChecksumDefinitionCB->count() - 1); } } const QString ad_default_id = filePrefs.archiveCommand(); // This is a weird hack but because we are a KCM we can't link // against ArchiveDefinition which pulls in loads of other classes. // So we do the parsing which archive definitions exist here ourself. if (KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("libkleopatrarc"))) { const QStringList groups = config->groupList().filter(QRegularExpression(QStringLiteral("^Archive Definition #"))); for (const QString &group : groups) { const KConfigGroup cGroup(config, group); const QString id = cGroup.readEntryUntranslated(QStringLiteral("id")); const QString name = cGroup.readEntry("Name"); mArchiveDefinitionCB->addItem(name, QVariant(id)); if (id == ad_default_id) { mArchiveDefinitionCB->setCurrentIndex(mArchiveDefinitionCB->count() - 1); } } } } void CryptoOperationsConfigWidget::save() { EMailOperationsPreferences emailPrefs; emailPrefs.setQuickSignEMail(mQuickSignCB ->isChecked()); emailPrefs.setQuickEncryptEMail(mQuickEncryptCB->isChecked()); emailPrefs.save(); FileOperationsPreferences filePrefs; filePrefs.setUsePGPFileExt(mPGPFileExtCB->isChecked()); filePrefs.setAutoDecryptVerify(mAutoDecryptVerifyCB->isChecked()); filePrefs.setAddASCIIArmor(mASCIIArmorCB->isChecked()); filePrefs.setDontUseTmpDir(mTmpDirCB->isChecked()); const int idx = mChecksumDefinitionCB->currentIndex(); if (idx >= 0) { const std::shared_ptr cd = qvariant_cast< std::shared_ptr >(mChecksumDefinitionCB->itemData(idx)); ChecksumDefinition::setDefaultChecksumDefinition(cd); } const int aidx = mArchiveDefinitionCB->currentIndex(); if (aidx >= 0) { const QString id = mArchiveDefinitionCB->itemData(aidx).toString(); filePrefs.setArchiveCommand(id); } filePrefs.save(); } diff --git a/src/crypto/gui/certificateselectionline.cpp b/src/crypto/gui/certificateselectionline.cpp index b768e4683..85d378a4b 100644 --- a/src/crypto/gui/certificateselectionline.cpp +++ b/src/crypto/gui/certificateselectionline.cpp @@ -1,342 +1,342 @@ /* crypto/gui/certificateselectionline.cpp This file is part of Kleopatra, the KDE keymanager Copyright (c) 2009 Klarälvdalens Datakonsult AB 2016 by Bundesamt für Sicherheit in der Informationstechnik Software engineering by 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 #include #include #include #include #include #include #include "utils/kleo_assert.h" #include #include #include using namespace Kleo; using namespace GpgME; Q_DECLARE_METATYPE(GpgME::Key) namespace { static QString make_initial_text(const std::vector &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 = nullptr) : QComboBox(parent), m_initialText(), m_initialIcon() { } explicit ComboBox(const QString &initialText, QWidget *parent = nullptr) : QComboBox(parent), m_initialText(initialText), m_initialIcon() { } explicit ComboBox(const QIcon &initialIcon, const QString &initialText, QWidget *parent = 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 *) 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 = nullptr) : ComboBox(parent) {} explicit KeysComboBox(const QString &initialText, QWidget *parent = nullptr) : ComboBox(initialText, parent) {} explicit KeysComboBox(const std::vector &keys, QWidget *parent = nullptr) : ComboBox(make_initial_text(keys), parent) { setKeys(keys); } void setKeys(const std::vector &keys) { clear(); for (const Key &key : keys) { - addItem(Formatting::formatForComboBox(key), qVariantFromValue(key)); + addItem(Formatting::formatForComboBox(key), QVariant::fromValue(key)); } } std::vector keys() const { std::vector result; result.reserve(count()); for (int i = 0, end = count(); i != end; ++i) { result.push_back(qvariant_cast(itemData(i))); } return result; } int findOrAdd(const Key &key) { for (int i = 0, end = count(); i != end; ++i) if (_detail::ByFingerprint()(key, qvariant_cast(itemData(i)))) { return i; } - insertItem(0, Formatting::formatForComboBox(key), qVariantFromValue(key)); + insertItem(0, Formatting::formatForComboBox(key), QVariant::fromValue(key)); return 0; } void addAndSelectCertificate(const Key &key) { setCurrentIndex(findOrAdd(key)); } Key currentKey() const { return qvariant_cast(itemData(currentIndex())); } }; CertificateSelectionLine::CertificateSelectionLine(const QString &toFrom, const QString &mailbox, const std::vector &pgp, bool pgpAmbig, const std::vector &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(); int col = 0; glay.addWidget(mToFromLB, row, col++); glay.addWidget(mMailboxLB, row, col++); glay.addWidget(mSbox, row, col++); glay.addWidget(mToolTB, row, col++); Q_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 nullptr; } #include "certificateselectionline.moc" diff --git a/src/crypto/gui/decryptverifyoperationwidget.cpp b/src/crypto/gui/decryptverifyoperationwidget.cpp index be9d2409b..936e0ebd3 100644 --- a/src/crypto/gui/decryptverifyoperationwidget.cpp +++ b/src/crypto/gui/decryptverifyoperationwidget.cpp @@ -1,260 +1,260 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/decryptverifyoperationwidget.cpp This file is part of Kleopatra, the KDE keymanager Copyright (c) 2007 Klarälvdalens Datakonsult AB 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 #include "decryptverifyoperationwidget.h" #include #include "Libkleo/FileNameRequester" #include #include #include #include #include using namespace Kleo; using namespace Kleo::Crypto::Gui; class DecryptVerifyOperationWidget::Private { friend class ::Kleo::Crypto::Gui::DecryptVerifyOperationWidget; DecryptVerifyOperationWidget *const q; public: explicit Private(DecryptVerifyOperationWidget *qq); ~Private(); void enableDisableWidgets() { const bool detached = ui.verifyDetachedCB.isChecked(); const bool archive = ui.archiveCB.isChecked(); ui.archiveCB.setEnabled(!detached); ui.archivesCB.setEnabled(archive && !detached); } private: struct UI { QGridLayout glay; QLabel inputLB; QStackedLayout inputStack; QLabel inputFileNameLB; FileNameRequester inputFileNameRQ; //------ QCheckBox verifyDetachedCB; //------ QLabel signedDataLB; QStackedLayout signedDataStack; QLabel signedDataFileNameLB; FileNameRequester signedDataFileNameRQ; //------ QHBoxLayout hlay; QCheckBox archiveCB; QComboBox archivesCB; explicit UI(DecryptVerifyOperationWidget *q); } ui; }; DecryptVerifyOperationWidget::Private::UI::UI(DecryptVerifyOperationWidget *q) : glay(q), inputLB(i18n("Input file:"), q), inputStack(), inputFileNameLB(q), inputFileNameRQ(q), verifyDetachedCB(i18n("&Input file is a detached signature"), q), signedDataLB(i18n("&Signed data:"), q), signedDataStack(), signedDataFileNameLB(q), signedDataFileNameRQ(q), hlay(), archiveCB(i18n("&Input file is an archive; unpack with:"), q), archivesCB(q) { KDAB_SET_OBJECT_NAME(glay); KDAB_SET_OBJECT_NAME(inputLB); KDAB_SET_OBJECT_NAME(inputStack); KDAB_SET_OBJECT_NAME(inputFileNameLB); KDAB_SET_OBJECT_NAME(inputFileNameRQ); KDAB_SET_OBJECT_NAME(verifyDetachedCB); KDAB_SET_OBJECT_NAME(signedDataLB); KDAB_SET_OBJECT_NAME(signedDataStack); KDAB_SET_OBJECT_NAME(signedDataFileNameLB); KDAB_SET_OBJECT_NAME(signedDataFileNameRQ); KDAB_SET_OBJECT_NAME(hlay); KDAB_SET_OBJECT_NAME(archiveCB); KDAB_SET_OBJECT_NAME(archivesCB); inputStack.setContentsMargins(0, 0, 0, 0); signedDataStack.setContentsMargins(0, 0, 0, 0); signedDataLB.setEnabled(false); signedDataFileNameLB.setEnabled(false); signedDataFileNameRQ.setEnabled(false); archivesCB.setEnabled(false); glay.setContentsMargins(0, 0, 0, 0); glay.addWidget(&inputLB, 0, 0); glay.addLayout(&inputStack, 0, 1); inputStack.addWidget(&inputFileNameLB); inputStack.addWidget(&inputFileNameRQ); glay.addWidget(&verifyDetachedCB, 1, 0, 1, 2); glay.addWidget(&signedDataLB, 2, 0); glay.addLayout(&signedDataStack, 2, 1); signedDataStack.addWidget(&signedDataFileNameLB); signedDataStack.addWidget(&signedDataFileNameRQ); glay.addLayout(&hlay, 3, 0, 1, 2); hlay.addWidget(&archiveCB); hlay.addWidget(&archivesCB, 1); connect(&verifyDetachedCB, &QCheckBox::toggled, &signedDataLB, &QLabel::setEnabled); connect(&verifyDetachedCB, &QCheckBox::toggled, &signedDataFileNameLB, &QLabel::setEnabled); connect(&verifyDetachedCB, &QCheckBox::toggled, &signedDataFileNameRQ, &FileNameRequester::setEnabled); connect(&verifyDetachedCB, SIGNAL(toggled(bool)), q, SLOT(enableDisableWidgets())); connect(&archiveCB, SIGNAL(toggled(bool)), q, SLOT(enableDisableWidgets())); } DecryptVerifyOperationWidget::Private::Private(DecryptVerifyOperationWidget *qq) : q(qq), ui(q) { } DecryptVerifyOperationWidget::Private::~Private() {} DecryptVerifyOperationWidget::DecryptVerifyOperationWidget(QWidget *p) : QWidget(p), d(new Private(this)) { setMode(DecryptVerifyOpaque); } DecryptVerifyOperationWidget::~DecryptVerifyOperationWidget() {} void DecryptVerifyOperationWidget::setArchiveDefinitions(const std::vector< std::shared_ptr > &archiveDefinitions) { d->ui.archivesCB.clear(); for (const std::shared_ptr &ad : archiveDefinitions) { - d->ui.archivesCB.addItem(ad->label(), qVariantFromValue(ad)); + d->ui.archivesCB.addItem(ad->label(), QVariant::fromValue(ad)); } } void DecryptVerifyOperationWidget::setMode(Mode mode) { setMode(mode, std::shared_ptr()); } void DecryptVerifyOperationWidget::setMode(Mode mode, const std::shared_ptr &ad) { d->ui.verifyDetachedCB.setChecked(mode != DecryptVerifyOpaque); QWidget *inputWidget; QWidget *signedDataWidget; if (mode == VerifyDetachedWithSignedData) { inputWidget = &d->ui.inputFileNameRQ; signedDataWidget = &d->ui.signedDataFileNameLB; } else { inputWidget = &d->ui.inputFileNameLB; signedDataWidget = &d->ui.signedDataFileNameRQ; } d->ui.inputStack.setCurrentWidget(inputWidget); d->ui.signedDataStack.setCurrentWidget(signedDataWidget); d->ui.inputLB.setBuddy(inputWidget); d->ui.signedDataLB.setBuddy(signedDataWidget); d->ui.archiveCB.setChecked(ad.get() != nullptr); for (int i = 0, end = d->ui.archivesCB.count(); i != end; ++i) if (ad == d->ui.archivesCB.itemData(i).value< std::shared_ptr >()) { d->ui.archivesCB.setCurrentIndex(i); return; } } DecryptVerifyOperationWidget::Mode DecryptVerifyOperationWidget::mode() const { if (d->ui.verifyDetachedCB.isChecked()) if (d->ui.inputStack.currentIndex() == 0) { return VerifyDetachedWithSignature; } else { return VerifyDetachedWithSignedData; } else { return DecryptVerifyOpaque; } } void DecryptVerifyOperationWidget::setInputFileName(const QString &name) { d->ui.inputFileNameLB.setText(name); d->ui.inputFileNameRQ.setFileName(name); } QString DecryptVerifyOperationWidget::inputFileName() const { if (d->ui.inputStack.currentIndex() == 0) { return d->ui.inputFileNameLB.text(); } else { return d->ui.inputFileNameRQ.fileName(); } } void DecryptVerifyOperationWidget::setSignedDataFileName(const QString &name) { d->ui.signedDataFileNameLB.setText(name); d->ui.signedDataFileNameRQ.setFileName(name); } QString DecryptVerifyOperationWidget::signedDataFileName() const { if (d->ui.signedDataStack.currentIndex() == 0) { return d->ui.signedDataFileNameLB.text(); } else { return d->ui.signedDataFileNameRQ.fileName(); } } std::shared_ptr DecryptVerifyOperationWidget::selectedArchiveDefinition() const { if (mode() == DecryptVerifyOpaque && d->ui.archiveCB.isChecked()) { return d->ui.archivesCB.itemData(d->ui.archivesCB.currentIndex()).value< std::shared_ptr >(); } else { return std::shared_ptr(); } } #include "moc_decryptverifyoperationwidget.cpp"