File indexing completed on 2025-01-26 04:52:43
0001 /* -*- mode: c++; c-basic-offset:4 -*- 0002 core/selectcertificatecommand.cpp 0003 0004 This file is part of KleopatraClient, the Kleopatra interface library 0005 SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #include "selectcertificatecommand.h" 0011 #include "libkleopatraclientcore_debug.h" 0012 0013 using namespace KleopatraClientCopy; 0014 0015 SelectCertificateCommand::SelectCertificateCommand(QObject *p) 0016 : Command(p) 0017 { 0018 setCommand("SELECT_CERTIFICATE"); 0019 } 0020 0021 SelectCertificateCommand::~SelectCertificateCommand() 0022 { 0023 } 0024 0025 void SelectCertificateCommand::setMultipleCertificatesAllowed(bool allow) 0026 { 0027 if (allow) { 0028 setOption("multi", true); 0029 } else { 0030 unsetOption("multi"); 0031 } 0032 } 0033 0034 bool SelectCertificateCommand::multipleCertificatesAllowed() const 0035 { 0036 return isOptionSet("multi"); 0037 } 0038 0039 void SelectCertificateCommand::setOnlySigningCertificatesAllowed(bool allow) 0040 { 0041 if (allow) { 0042 setOption("sign-only", true); 0043 } else { 0044 unsetOption("sign-only"); 0045 } 0046 } 0047 0048 bool SelectCertificateCommand::onlySigningCertificatesAllowed() const 0049 { 0050 return isOptionSet("sign-only"); 0051 } 0052 0053 void SelectCertificateCommand::setOnlyEncryptionCertificatesAllowed(bool allow) 0054 { 0055 if (allow) { 0056 setOption("encrypt-only", true); 0057 } else { 0058 unsetOption("encrypt-only"); 0059 } 0060 } 0061 0062 bool SelectCertificateCommand::onlyEncryptionCertificatesAllowed() const 0063 { 0064 return isOptionSet("encrypt-only"); 0065 } 0066 0067 void SelectCertificateCommand::setOnlyOpenPGPCertificatesAllowed(bool allow) 0068 { 0069 if (allow) { 0070 setOption("openpgp-only", true); 0071 } else { 0072 unsetOption("openpgp-only"); 0073 } 0074 } 0075 0076 bool SelectCertificateCommand::onlyOpenPGPCertificatesAllowed() const 0077 { 0078 return isOptionSet("openpgp-only"); 0079 } 0080 0081 void SelectCertificateCommand::setOnlyX509CertificatesAllowed(bool allow) 0082 { 0083 if (allow) { 0084 setOption("x509-only", true); 0085 } else { 0086 unsetOption("x509-only"); 0087 } 0088 } 0089 0090 bool SelectCertificateCommand::onlyX509CertificatesAllowed() const 0091 { 0092 return isOptionSet("x509-only"); 0093 } 0094 0095 void SelectCertificateCommand::setOnlySecretKeysAllowed(bool allow) 0096 { 0097 if (allow) { 0098 setOption("secret-only", true); 0099 } else { 0100 unsetOption("secret-only"); 0101 } 0102 } 0103 0104 bool SelectCertificateCommand::onlySecretKeysAllowed() const 0105 { 0106 return isOptionSet("secret-only"); 0107 } 0108 0109 void SelectCertificateCommand::setSelectedCertificates(const QStringList &certs) 0110 { 0111 QByteArray data; 0112 for (const QString &s : certs) 0113 if (s.isEmpty()) { 0114 qCWarning(LIBKLEOPATRACLIENTCORE_LOG) << "SelectCertificateCommand::setSelectedCertificates: empty certificate!"; 0115 } else { 0116 data += s.toUtf8() += '\n'; 0117 } 0118 setInquireData("SELECTED_CERTIFICATES", data); 0119 } 0120 0121 QStringList SelectCertificateCommand::selectedCertificates() const 0122 { 0123 const QByteArray data = receivedData(); 0124 return QString::fromLatin1(data.data(), data.size()).split(QLatin1Char('\n'), Qt::SkipEmptyParts); 0125 } 0126 0127 void SelectCertificateCommand::setSelectedCertificate(const QString &cert) 0128 { 0129 setSelectedCertificates(QStringList(cert)); 0130 } 0131 0132 QString SelectCertificateCommand::selectedCertificate() const 0133 { 0134 const QStringList sl = selectedCertificates(); 0135 return sl.empty() ? QString() : sl.front(); 0136 } 0137 0138 #include "moc_selectcertificatecommand.cpp"