Commit cf9b98e6 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Disable actions for signing clipboard content if needed keys are missing

parent c3635355
Pipeline #102793 passed with stage
in 5 minutes and 30 seconds
......@@ -30,7 +30,7 @@ option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF)
# Standalone build. Find / include everything necessary.
set(KF5_MIN_VERSION "5.88.0")
set(KMIME_VERSION "5.19.40")
set(LIBKLEO_VERSION "5.19.45")
set(LIBKLEO_VERSION "5.19.46")
set(QT_REQUIRED_VERSION "5.15.2")
set(GPGME_REQUIRED_VERSION "1.13.1")
set(BOOST_REQUIRED_VERSION "1.58")
......
......@@ -20,6 +20,8 @@
#include <utils/input.h>
#include <utils/output.h>
#include <Libkleo/Algorithm>
#include <Libkleo/KeyCache>
#include <Libkleo/Stl_Util>
#include <KLocalizedString>
......@@ -29,6 +31,8 @@
#include <QClipboard>
#include <QMimeData>
#include <gpgme++/key.h>
#include <exception>
using namespace Kleo;
......@@ -119,13 +123,19 @@ SignClipboardCommand::~SignClipboardCommand()
}
// static
bool SignClipboardCommand::canSignCurrentClipboard()
bool SignClipboardCommand::canSignCurrentClipboard(GpgME::Protocol protocol)
{
if (const QClipboard *clip = QApplication::clipboard())
if (const QMimeData *mime = clip->mimeData()) {
return mime->hasText();
bool canSign = false;
if (const QClipboard *const clip = QApplication::clipboard()) {
if (const QMimeData *const mime = clip->mimeData()) {
canSign = mime->hasText();
}
return false;
}
if (canSign) {
canSign &= Kleo::any_of(KeyCache::instance()->secretKeys(),
[](const auto &k) { return k.hasSecret(); });
}
return canSign;
}
void SignClipboardCommand::doStart()
......
......@@ -30,7 +30,7 @@ public:
explicit SignClipboardCommand(GpgME::Protocol protocol, KeyListController *parent);
~SignClipboardCommand() override;
static bool canSignCurrentClipboard();
static bool canSignCurrentClipboard(GpgME::Protocol protocol);
private:
void doStart() override;
......
......@@ -115,9 +115,9 @@ void ClipboardMenu::slotEnableDisableActions()
const QSignalBlocker blocker(QApplication::clipboard());
mImportClipboardAction->setEnabled(ImportCertificateFromClipboardCommand::canImportCurrentClipboard());
mEncryptClipboardAction->setEnabled(EncryptClipboardCommand::canEncryptCurrentClipboard());
mOpenPGPSignClipboardAction->setEnabled(SignClipboardCommand::canSignCurrentClipboard());
mOpenPGPSignClipboardAction->setEnabled(SignClipboardCommand::canSignCurrentClipboard(GpgME::OpenPGP));
if (mSmimeSignClipboardAction) {
mSmimeSignClipboardAction->setEnabled(SignClipboardCommand::canSignCurrentClipboard());
mSmimeSignClipboardAction->setEnabled(SignClipboardCommand::canSignCurrentClipboard(GpgME::CMS));
}
mDecryptVerifyClipboardAction->setEnabled(DecryptVerifyClipboardCommand::canDecryptVerifyCurrentClipboard());
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment