Page MenuHome GnuPG

No OneTemporary

diff --git a/commands/lookupcertificatescommand.cpp b/commands/lookupcertificatescommand.cpp
index a3797112b..1931d2ec6 100644
--- a/commands/lookupcertificatescommand.cpp
+++ b/commands/lookupcertificatescommand.cpp
@@ -1,446 +1,446 @@
/* -*- mode: c++; c-basic-offset:4 -*-
commands/lookupcertificatescommand.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2008, 2009 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 <config-kleopatra.h>
#include "lookupcertificatescommand.h"
#include "importcertificatescommand_p.h"
#include "detailscommand.h"
#include <dialogs/lookupcertificatesdialog.h>
#include <utils/formatting.h>
#include <kleo/stl_util.h>
#include <kleo/importfromkeyserverjob.h>
#include <kleo/keylistjob.h>
#include <kleo/cryptobackendfactory.h>
#include <kleo/cryptobackend.h>
#include <kleo/cryptoconfig.h>
#include <gpgme++/key.h>
#include <gpgme++/keylistresult.h>
#include <gpgme++/importresult.h>
#include <KLocalizedString>
#include <KMessageBox>
#include "kleopatra_debug.h"
#include <QRegExp>
#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <vector>
#include <map>
#include <algorithm>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Commands;
using namespace Kleo::Dialogs;
using namespace GpgME;
using namespace boost;
class LookupCertificatesCommand::Private : public ImportCertificatesCommand::Private
{
friend class ::Kleo::Commands::LookupCertificatesCommand;
LookupCertificatesCommand *q_func() const
{
return static_cast<LookupCertificatesCommand *>(q);
}
public:
explicit Private(LookupCertificatesCommand *qq, KeyListController *c);
~Private();
QString fingerPrint;
void init();
private:
void slotSearchTextChanged(const QString &str);
void slotNextKey(const Key &key)
{
keyListing.keys.push_back(key);
}
void slotKeyListResult(const KeyListResult &result);
void slotImportRequested(const std::vector<Key> &keys);
void slotDetailsRequested(const Key &key);
void slotSaveAsRequested(const std::vector<Key> &keys);
void slotDialogRejected()
{
canceled();
}
private:
using ImportCertificatesCommand::Private::showError;
void showError(QWidget *parent, const KeyListResult &result);
void showResult(QWidget *parent, const KeyListResult &result);
void createDialog();
KeyListJob *createKeyListJob(GpgME::Protocol proto) const
{
const CryptoBackend::Protocol *const cbp = CryptoBackendFactory::instance()->protocol(proto);
return cbp ? cbp->keyListJob(true) : 0 ;
}
ImportFromKeyserverJob *createImportJob(GpgME::Protocol proto) const
{
const CryptoBackend::Protocol *const cbp = CryptoBackendFactory::instance()->protocol(proto);
return cbp ? cbp->importFromKeyserverJob() : 0 ;
}
void startKeyListJob(GpgME::Protocol proto, const QString &str);
bool checkConfig() const;
QWidget *dialogOrParentWidgetOrView() const
{
if (dialog) {
return dialog;
} else {
return parentWidgetOrView();
}
}
private:
QPointer<LookupCertificatesDialog> dialog;
struct KeyListingVariables {
QPointer<KeyListJob> cms, openpgp;
KeyListResult result;
std::vector<Key> keys;
void reset()
{
*this = KeyListingVariables();
}
} keyListing;
};
LookupCertificatesCommand::Private *LookupCertificatesCommand::d_func()
{
return static_cast<Private *>(d.get());
}
const LookupCertificatesCommand::Private *LookupCertificatesCommand::d_func() const
{
return static_cast<const Private *>(d.get());
}
#define d d_func()
#define q q_func()
LookupCertificatesCommand::Private::Private(LookupCertificatesCommand *qq, KeyListController *c)
: ImportCertificatesCommand::Private(qq, c),
dialog()
{
}
LookupCertificatesCommand::Private::~Private()
{
qCDebug(KLEOPATRA_LOG);
delete dialog;
}
LookupCertificatesCommand::LookupCertificatesCommand(KeyListController *c)
: ImportCertificatesCommand(new Private(this, c))
{
d->init();
}
LookupCertificatesCommand::LookupCertificatesCommand(const QString &fingerPrint, KeyListController *c)
: ImportCertificatesCommand(new Private(this, c))
{
d->init();
d->fingerPrint = fingerPrint;
}
LookupCertificatesCommand::LookupCertificatesCommand(QAbstractItemView *v, KeyListController *c)
: ImportCertificatesCommand(v, new Private(this, c))
{
d->init();
}
void LookupCertificatesCommand::Private::init()
{
}
LookupCertificatesCommand::~LookupCertificatesCommand()
{
qCDebug(KLEOPATRA_LOG);
}
void LookupCertificatesCommand::doStart()
{
if (!d->checkConfig()) {
d->finished();
return;
}
d->createDialog();
assert(d->dialog);
// if have prespecified fingerPrint, load into find field
// and start search
if (! d->fingerPrint.isEmpty()) {
if (!d->fingerPrint.startsWith(QStringLiteral("0x"))) {
d->fingerPrint = QLatin1String("0x") + d->fingerPrint;
}
d->dialog->setSearchText(d->fingerPrint);
// Start Search
d->slotSearchTextChanged(d->fingerPrint);
}
d->dialog->setPassive(false);
d->dialog->show();
}
void LookupCertificatesCommand::Private::createDialog()
{
if (dialog) {
return;
}
dialog = new LookupCertificatesDialog;
applyWindowID(dialog);
dialog->setAttribute(Qt::WA_DeleteOnClose);
connect(dialog, SIGNAL(searchTextChanged(QString)),
q, SLOT(slotSearchTextChanged(QString)));
connect(dialog, SIGNAL(saveAsRequested(std::vector<GpgME::Key>)),
q, SLOT(slotSaveAsRequested(std::vector<GpgME::Key>)));
connect(dialog, SIGNAL(importRequested(std::vector<GpgME::Key>)),
q, SLOT(slotImportRequested(std::vector<GpgME::Key>)));
connect(dialog, SIGNAL(detailsRequested(GpgME::Key)),
q, SLOT(slotDetailsRequested(GpgME::Key)));
connect(dialog, SIGNAL(rejected()),
q, SLOT(slotDialogRejected()));
}
void LookupCertificatesCommand::Private::slotSearchTextChanged(const QString &str)
{
// pressing return might trigger both search and dialog destruction (search focused and default key set)
// On Windows, the dialog is then destroyed before this slot is called
if (dialog) { //thus test
dialog->setPassive(true);
dialog->setCertificates(std::vector<Key>());
}
const QRegExp rx(QStringLiteral("(?:0x|0X)?[0-9a-fA-F]{6,}"));
if (rx.exactMatch(str))
information(str.startsWith(QStringLiteral("0x"), Qt::CaseInsensitive)
? i18n("<p>You seem to be searching for a fingerPrint or a key-id.</p>"
"<p>Different keyservers expect different ways to search for these. "
"Some require a \"0x\" prefix, while others require there be no such prefix.</p>"
"<p>If your search does not yield any results, try removing the 0x prefix from your search.</p>")
: i18n("<p>You seem to be searching for a fingerPrint or a key-id.</p>"
"<p>Different keyservers expect different ways to search for these. "
"Some require a \"0x\" prefix, while others require there be no such prefix.</p>"
"<p>If your search does not yield any results, try adding the 0x prefix to your search.</p>"),
i18n("Hex-String Search"),
QStringLiteral("lookup-certificates-warn-0x-prefix"));
startKeyListJob(CMS, str);
startKeyListJob(OpenPGP, str);
}
void LookupCertificatesCommand::Private::startKeyListJob(GpgME::Protocol proto, const QString &str)
{
KeyListJob *const klj = createKeyListJob(proto);
if (!klj) {
return;
}
connect(klj, SIGNAL(result(GpgME::KeyListResult)),
q, SLOT(slotKeyListResult(GpgME::KeyListResult)));
connect(klj, SIGNAL(nextKey(GpgME::Key)),
q, SLOT(slotNextKey(GpgME::Key)));
if (const Error err = klj->start(QStringList(str))) {
keyListing.result.mergeWith(KeyListResult(err));
} else if (proto == CMS) {
keyListing.cms = klj;
} else {
keyListing.openpgp = klj;
}
}
void LookupCertificatesCommand::Private::slotKeyListResult(const KeyListResult &r)
{
if (q->sender() == keyListing.cms) {
keyListing.cms = 0;
} else if (q->sender() == keyListing.openpgp) {
keyListing.openpgp = 0;
} else {
qCDebug(KLEOPATRA_LOG) << "unknown sender()" << q->sender();
}
keyListing.result.mergeWith(r);
if (keyListing.cms || keyListing.openpgp) { // still waiting for jobs to complete
return;
}
if (keyListing.result.error() && !keyListing.result.error().isCanceled()) {
showError(dialog, keyListing.result);
}
if (keyListing.result.isTruncated()) {
showResult(dialog, keyListing.result);
}
if (dialog) {
dialog->setPassive(false);
dialog->setCertificates(keyListing.keys);
} else {
finished();
}
keyListing.reset();
}
void LookupCertificatesCommand::Private::slotImportRequested(const std::vector<Key> &keys)
{
dialog = 0;
assert(!keys.empty());
assert(kdtools::none_of(keys, mem_fn(&Key::isNull)));
std::vector<Key> pgp, cms;
pgp.reserve(keys.size());
cms.reserve(keys.size());
kdtools::separate_if(keys.begin(), keys.end(),
std::back_inserter(pgp),
std::back_inserter(cms),
boost::bind(&Key::protocol, _1) == OpenPGP);
setWaitForMoreJobs(true);
if (!pgp.empty())
startImport(OpenPGP, pgp,
i18nc("@title %1:\"OpenPGP\" or \"CMS\"",
"%1 Certificate Server",
Formatting::displayName(OpenPGP)));
if (!cms.empty())
startImport(CMS, cms,
i18nc("@title %1:\"OpenPGP\" or \"CMS\"",
"%1 Certificate Server",
Formatting::displayName(CMS)));
setWaitForMoreJobs(false);
}
void LookupCertificatesCommand::Private::slotSaveAsRequested(const std::vector<Key> &keys)
{
Q_UNUSED(keys);
qCDebug(KLEOPATRA_LOG) << "not implemented";
}
void LookupCertificatesCommand::Private::slotDetailsRequested(const Key &key)
{
Command *const cmd = new DetailsCommand(key, view(), controller());
cmd->setParentWidget(dialogOrParentWidgetOrView());
cmd->start();
}
void LookupCertificatesCommand::doCancel()
{
ImportCertificatesCommand::doCancel();
if (QDialog *const dlg = d->dialog) {
d->dialog = 0;
dlg->close();
}
}
void LookupCertificatesCommand::Private::showError(QWidget *parent, const KeyListResult &result)
{
if (!result.error()) {
return;
}
KMessageBox::information(parent, i18nc("@info",
"Failed to search on certificate server. The error returned was:\n%1",
QString::fromLocal8Bit(result.error().asString())));
}
void LookupCertificatesCommand::Private::showResult(QWidget *parent, const KeyListResult &result)
{
if (result.isTruncated())
KMessageBox::information(parent,
xi18nc("@info",
"<para>The query result has been truncated.</para>"
"<para>Either the local or a remote limit on "
"the maximum number of returned hits has "
"been exceeded.</para>"
"<para>You can try to increase the local limit "
"in the configuration dialog, but if one "
"of the configured servers is the limiting "
"factor, you have to refine your search.</para>"),
i18nc("@title", "Result Truncated"),
QStringLiteral("lookup-certificates-truncated-result"));
}
static bool haveOpenPGPKeyserverConfigured()
{
const Kleo::CryptoConfig *const config = Kleo::CryptoBackendFactory::instance()->config();
if (!config) {
return false;
}
const Kleo::CryptoConfigEntry *const entry = config->entry(QStringLiteral("gpg"), QStringLiteral("Keyserver"), QStringLiteral("keyserver"));
return entry && !entry->stringValue().isEmpty();
}
static bool haveX509DirectoryServerConfigured()
{
const Kleo::CryptoConfig *const config = Kleo::CryptoBackendFactory::instance()->config();
if (!config) {
return false;
}
const Kleo::CryptoConfigEntry *entry = config->entry(QStringLiteral("dirmngr"), QStringLiteral("LDAP"), QStringLiteral("LDAP Server"));
bool entriesExist = entry && !entry->urlValueList().empty();
entry = config->entry(QStringLiteral("gpgsm"), QStringLiteral("Configuration"), QStringLiteral("keyserver"));
- entriesExist |= entry && !entry->stringValueList().empty();
+ entriesExist |= entry && !entry->urlValueList().empty();
return entriesExist;
}
bool LookupCertificatesCommand::Private::checkConfig() const
{
const bool ok = haveOpenPGPKeyserverConfigured() || haveX509DirectoryServerConfigured();
if (!ok)
information(xi18nc("@info",
"<para>You do not have any directory servers configured.</para>"
"<para>You need to configure at least one directory server to "
"search on one.</para>"
"<para>You can configure directory servers here: "
"<interface>Settings->Configure Kleopatra</interface>.</para>"),
i18nc("@title", "No Directory Servers Configured"));
return ok;
}
#undef d
#undef q
#include "moc_lookupcertificatescommand.cpp"
diff --git a/conf/dirservconfigpage.cpp b/conf/dirservconfigpage.cpp
index fce85744c..0b9825678 100644
--- a/conf/dirservconfigpage.cpp
+++ b/conf/dirservconfigpage.cpp
@@ -1,418 +1,404 @@
/* -*- mode: c++; c-basic-offset:4 -*-
conf/dirservconfigpage.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2004,2008 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 <config-kleopatra.h>
#include "dirservconfigpage.h"
#include "libkleo/ui/directoryserviceswidget.h"
#include "libkleo/ui/cryptoconfigmodule.h"
#include "libkleo/kleo/cryptobackendfactory.h"
#include <kmessagebox.h>
#include <KLocalizedString>
#include "kleopatra_debug.h"
#include <kconfig.h>
#include <QDialog>
#include <QSpinBox>
#include <QLabel>
#include <qdatetimeedit.h>
#include <QCheckBox>
#include <QLayout>
#include <KConfigGroup>
using namespace Kleo;
#if 0 // disabled, since it is apparently confusing
// For sync'ing kabldaprc
class KABSynchronizer
{
public:
KABSynchronizer()
: mConfig("kabldaprc")
{
mConfig.setGroup("LDAP");
}
KUrl::List readCurrentList() const
{
KUrl::List lst;
// stolen from kabc/ldapclient.cpp
const uint numHosts = mConfig.readEntry("NumSelectedHosts");
for (uint j = 0; j < numHosts; j++) {
const QString num = QString::number(j);
KUrl url;
url.setProtocol("ldap");
url.setPath("/"); // workaround KUrl parsing bug
const QString host = mConfig.readEntry(QString("SelectedHost") + num).trimmed();
url.setHost(host);
const int port = mConfig.readEntry(QString("SelectedPort") + num);
if (port != 0) {
url.setPort(port);
}
const QString base = mConfig.readEntry(QString("SelectedBase") + num).trimmed();
url.setQuery(base);
const QString bindDN = mConfig.readEntry(QString("SelectedBind") + num).trimmed();
url.setUser(bindDN);
const QString pwdBindDN = mConfig.readEntry(QString("SelectedPwdBind") + num).trimmed();
url.setPass(pwdBindDN);
lst.append(url);
}
return lst;
}
void writeList(const KUrl::List &lst)
{
mConfig.writeEntry("NumSelectedHosts", lst.count());
KUrl::List::const_iterator it = lst.begin();
KUrl::List::const_iterator end = lst.end();
unsigned j = 0;
for (; it != end; ++it, ++j) {
const QString num = QString::number(j);
KUrl url = *it;
Q_ASSERT(url.scheme() == "ldap");
mConfig.writeEntry(QString("SelectedHost") + num, url.host());
mConfig.writeEntry(QString("SelectedPort") + num, url.port());
// KUrl automatically encoded the query (e.g. for spaces inside it),
// so decode it before writing it out
const QString base = KUrl::decode_string(url.query().mid(1));
mConfig.writeEntry(QString("SelectedBase") + num, base);
mConfig.writeEntry(QString("SelectedBind") + num, url.user());
mConfig.writeEntry(QString("SelectedPwdBind") + num, url.pass());
}
mConfig.sync();
}
private:
KConfig mConfig;
};
#endif
static const char s_x509services_componentName[] = "dirmngr";
static const char s_x509services_groupName[] = "LDAP";
static const char s_x509services_entryName[] = "LDAP Server";
static const char s_x509services_new_componentName[] = "gpgsm";
static const char s_x509services_new_groupName[] = "Configuration";
static const char s_x509services_new_entryName[] = "keyserver";
static const char s_pgpservice_componentName[] = "gpg";
static const char s_pgpservice_groupName[] = "Keyserver";
static const char s_pgpservice_entryName[] = "keyserver";
static const char s_timeout_componentName[] = "dirmngr";
static const char s_timeout_groupName[] = "LDAP";
static const char s_timeout_entryName[] = "ldaptimeout";
static const char s_maxitems_componentName[] = "dirmngr";
static const char s_maxitems_groupName[] = "LDAP";
static const char s_maxitems_entryName[] = "max-replies";
#ifdef NOT_USEFUL_CURRENTLY
static const char s_addnewservers_componentName[] = "dirmngr";
static const char s_addnewservers_groupName[] = "LDAP";
static const char s_addnewservers_entryName[] = "add-servers";
#endif
DirectoryServicesConfigurationPage::DirectoryServicesConfigurationPage(QWidget *parent, const QVariantList &args)
: KCModule(parent, args)
{
mConfig = Kleo::CryptoBackendFactory::instance()->config();
QGridLayout *glay = new QGridLayout(this);
glay->setMargin(0);
int row = 0;
mWidget = new Kleo::DirectoryServicesWidget(this);
if (QLayout *l = mWidget->layout()) {
l->setMargin(0);
}
glay->addWidget(mWidget, row, 0, 1, 3);
connect(mWidget, SIGNAL(changed()), this, SLOT(changed()));
// LDAP timeout
++row;
QLabel *label = new QLabel(i18n("LDAP &timeout (minutes:seconds):"), this);
mTimeout = new QTimeEdit(this);
mTimeout->setDisplayFormat(QStringLiteral("mm:ss"));
connect(mTimeout, SIGNAL(timeChanged(QTime)), this, SLOT(changed()));
label->setBuddy(mTimeout);
glay->addWidget(label, row, 0);
glay->addWidget(mTimeout, row, 1);
// Max number of items returned by queries
++row;
mMaxItemsLabel = new QLabel(i18n("&Maximum number of items returned by query:"), this);
mMaxItems = new QSpinBox(this);
mMaxItems->setMinimum(0);
mMaxItemsLabel->setBuddy(mMaxItems);
connect(mMaxItems, SIGNAL(valueChanged(int)), this, SLOT(changed()));
glay->addWidget(mMaxItemsLabel, row, 0);
glay->addWidget(mMaxItems, row, 1);
#ifdef NOT_USEFUL_CURRENTLY
++row
mAddNewServersCB = new QCheckBox(i18n("Automatically add &new servers discovered in CRL distribution points"), this);
connect(mAddNewServersCB, SIGNAL(clicked()), this, SLOT(changed()));
glay->addWidget(mAddNewServersCB, row, 0, 1, 3);
#endif
glay->setRowStretch(++row, 1);
glay->setColumnStretch(2, 1);
load();
}
-static KUrl::List string2urls(const QString &str)
+static QList<QUrl> string2urls(const QString &str)
{
- return str.isEmpty() ? KUrl::List() : KUrl(str) ;
+ QList<QUrl> ret;
+ if (str.isEmpty()) {
+ return ret;
+ }
+ ret << QUrl::fromPercentEncoding(str.toLocal8Bit());
+ return ret;
}
-static KUrl::List strings2urls(const QStringList &strs)
+static QList<QUrl> strings2urls(const QStringList &strs)
{
- KUrl::List urls;
- Q_FOREACH (const QString &str, strs)
+ QList<QUrl> urls;
+ Q_FOREACH (const QString &str, strs) {
if (!str.isEmpty()) {
- urls.push_back(KUrl(str));
+ urls.push_back(QUrl::fromPercentEncoding(str.toLocal8Bit()));
}
- return urls;
-}
-
-static QStringList urls2strings(const KUrl::List &urls)
-{
- QStringList result;
- Q_FOREACH (const KUrl &url, urls) {
- result.push_back(url.url());
}
- return result;
+ return urls;
}
void DirectoryServicesConfigurationPage::load()
{
mWidget->clear();
- // gpgsm/Configuration/keyserver is not provided by older gpgconf versions; it's type changed from String to LDAPURL
+ // gpgsm/Configuration/keyserver is not provided by older gpgconf versions;
if ((mX509ServicesEntry = configEntry(s_x509services_new_componentName, s_x509services_new_groupName, s_x509services_new_entryName,
Kleo::CryptoConfigEntry::ArgType_LDAPURL, /*isList=*/true, /*showError=*/false))) {
mWidget->addX509Services(mX509ServicesEntry->urlValueList());
- } else if ((mX509ServicesEntry = configEntry(s_x509services_new_componentName, s_x509services_new_groupName, s_x509services_new_entryName,
- Kleo::CryptoConfigEntry::ArgType_String, /*isList=*/true, /*showError=*/false))) {
- mWidget->addX509Services(strings2urls(mX509ServicesEntry->stringValueList()));
} else if ((mX509ServicesEntry = configEntry(s_x509services_componentName, s_x509services_groupName, s_x509services_entryName,
Kleo::CryptoConfigEntry::ArgType_LDAPURL, true))) {
mWidget->addX509Services(mX509ServicesEntry->urlValueList());
}
mWidget->setX509ReadOnly(mX509ServicesEntry && mX509ServicesEntry->isReadOnly());
mOpenPGPServiceEntry = configEntry(s_pgpservice_componentName, s_pgpservice_groupName, s_pgpservice_entryName,
Kleo::CryptoConfigEntry::ArgType_String, false);
if (mOpenPGPServiceEntry) {
mWidget->addOpenPGPServices(string2urls(parseKeyserver(mOpenPGPServiceEntry->stringValue()).url));
}
mWidget->setOpenPGPReadOnly(mOpenPGPServiceEntry && mOpenPGPServiceEntry->isReadOnly());
if (mX509ServicesEntry)
if (mOpenPGPServiceEntry) {
mWidget->setAllowedProtocols(DirectoryServicesWidget::AllProtocols);
} else {
mWidget->setAllowedProtocols(DirectoryServicesWidget::X509Protocol);
}
else if (mOpenPGPServiceEntry) {
mWidget->setAllowedProtocols(DirectoryServicesWidget::OpenPGPProtocol);
} else {
mWidget->setDisabled(true);
}
DirectoryServicesWidget::Protocols readOnlyProtocols;
if (mX509ServicesEntry && mX509ServicesEntry->isReadOnly()) {
readOnlyProtocols = DirectoryServicesWidget::X509Protocol;
}
mTimeoutConfigEntry = configEntry(s_timeout_componentName, s_timeout_groupName, s_timeout_entryName, Kleo::CryptoConfigEntry::ArgType_UInt, false);
if (mTimeoutConfigEntry) {
QTime time = QTime().addSecs(mTimeoutConfigEntry->uintValue());
//qCDebug(KLEOPATRA_LOG) <<"timeout:" << mTimeoutConfigEntry->uintValue() <<" ->" << time;
mTimeout->setTime(time);
}
mMaxItemsConfigEntry = configEntry(s_maxitems_componentName, s_maxitems_groupName, s_maxitems_entryName, Kleo::CryptoConfigEntry::ArgType_UInt, false);
if (mMaxItemsConfigEntry) {
mMaxItems->blockSignals(true); // KNumInput emits valueChanged from setValue!
mMaxItems->setValue(mMaxItemsConfigEntry->uintValue());
mMaxItems->blockSignals(false);
}
const bool maxItemsEnabled = mMaxItemsConfigEntry && !mMaxItemsConfigEntry->isReadOnly();
mMaxItems->setEnabled(maxItemsEnabled);
mMaxItemsLabel->setEnabled(maxItemsEnabled);
#ifdef NOT_USEFUL_CURRENTLY
mAddNewServersConfigEntry = configEntry(s_addnewservers_componentName, s_addnewservers_groupName, s_addnewservers_entryName, Kleo::CryptoConfigEntry::ArgType_None, false);
if (mAddNewServersConfigEntry) {
mAddNewServersCB->setChecked(mAddNewServersConfigEntry->boolValue());
}
#endif
}
void DirectoryServicesConfigurationPage::save()
{
if (mX509ServicesEntry) {
- if (mX509ServicesEntry->argType() == Kleo::CryptoConfigEntry::ArgType_LDAPURL) {
- mX509ServicesEntry->setURLValueList(mWidget->x509Services());
- } else {
- mX509ServicesEntry->setStringValueList(urls2strings(mWidget->x509Services()));
- }
+ mX509ServicesEntry->setURLValueList(mWidget->x509Services());
}
if (mOpenPGPServiceEntry) {
- const KUrl::List serv = mWidget->openPGPServices();
+ const QList<QUrl> serv = mWidget->openPGPServices();
if (serv.empty()) {
mOpenPGPServiceEntry->setStringValue(QString());
} else {
ParsedKeyserver pks = parseKeyserver(mOpenPGPServiceEntry->stringValue());
pks.url = serv.front().url();
mOpenPGPServiceEntry->setStringValue(assembleKeyserver(pks));
}
}
QTime time(mTimeout->time());
unsigned int timeout = time.minute() * 60 + time.second();
if (mTimeoutConfigEntry && mTimeoutConfigEntry->uintValue() != timeout) {
mTimeoutConfigEntry->setUIntValue(timeout);
}
if (mMaxItemsConfigEntry && mMaxItemsConfigEntry->uintValue() != (uint)mMaxItems->value()) {
mMaxItemsConfigEntry->setUIntValue(mMaxItems->value());
}
#ifdef NOT_USEFUL_CURRENTLY
if (mAddNewServersConfigEntry && mAddNewServersConfigEntry->boolValue() != mAddNewServersCB->isChecked()) {
mAddNewServersConfigEntry->setBoolValue(mAddNewServersCB->isChecked());
}
#endif
mConfig->sync(true);
#if 0
// Also write the LDAP URLs to kabldaprc so that they are used by kaddressbook
KABSynchronizer sync;
const KUrl::List toAdd = mWidget->urlList();
KUrl::List currentList = sync.readCurrentList();
KUrl::List::const_iterator it = toAdd.begin();
KUrl::List::const_iterator end = toAdd.end();
for (; it != end; ++it) {
// check if the URL is already in currentList
if (currentList.find(*it) == currentList.end())
// if not, add it
{
currentList.append(*it);
}
}
sync.writeList(currentList);
#endif
}
void DirectoryServicesConfigurationPage::defaults()
{
// these guys don't have a default, to clear them:
if (mX509ServicesEntry) {
- if (mX509ServicesEntry->argType() == Kleo::CryptoConfigEntry::ArgType_LDAPURL) {
- mX509ServicesEntry->setURLValueList(KUrl());
- } else {
- mX509ServicesEntry->setStringValueList(QStringList());
- }
+ mX509ServicesEntry->setURLValueList(QList<QUrl>());
}
if (mOpenPGPServiceEntry) {
mOpenPGPServiceEntry->setStringValue(QString());
}
// these presumably have a default, use that one:
if (mTimeoutConfigEntry) {
mTimeoutConfigEntry->resetToDefault();
}
if (mMaxItemsConfigEntry) {
mMaxItemsConfigEntry->resetToDefault();
}
#ifdef NOT_USEFUL_CURRENTLY
if (mAddNewServersConfigEntry) {
mAddNewServersConfigEntry->resetToDefault();
}
#endif
load();
}
extern "C"
{
Q_DECL_EXPORT KCModule *create_kleopatra_config_dirserv(QWidget *parent = Q_NULLPTR, const QVariantList &args = QVariantList())
{
DirectoryServicesConfigurationPage *page =
new DirectoryServicesConfigurationPage(parent, args);
page->setObjectName(QStringLiteral("kleopatra_config_dirserv"));
return page;
}
}
// Find config entry for ldap servers. Implements runtime checks on the configuration option.
Kleo::CryptoConfigEntry *DirectoryServicesConfigurationPage::configEntry(const char *componentName,
const char *groupName,
const char *entryName,
Kleo::CryptoConfigEntry::ArgType argType,
bool isList,
bool showError)
{
Kleo::CryptoConfigEntry *entry = mConfig->entry(QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName));
if (!entry) {
if (showError) {
KMessageBox::error(this, i18n("Backend error: gpgconf does not seem to know the entry for %1/%2/%3", QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName)));
}
return 0;
}
if (entry->argType() != argType || entry->isList() != isList) {
if (showError) {
KMessageBox::error(this, i18n("Backend error: gpgconf has wrong type for %1/%2/%3: %4 %5", QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName), entry->argType(), entry->isList()));
}
return 0;
}
return entry;
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Jul 12, 10:26 AM (1 d, 11 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
f5/5f/1b8022a8322fab09ab14232705d2

Event Timeline