Commit 0509ff5e authored by Felix Tiede's avatar Felix Tiede Committed by Ingo Klöcker
Browse files

Refactor and const IdentityManager.

See !16 (comment 427791)

As per the comment, mailIdManager has been moved from a class static
variable into a file static function.
This revealed that it is only required to get hold of the identity
associated with a certain mail sender address. Thus the class code using
the IdentityManager has been refactored into the same function and it no
longer returns an IdentityManager, but instead directly returns the
identity requested, or the default identity if a mail address has no
associated identity.
parent 08e71eee
......@@ -18,6 +18,7 @@
#include <gpgme++/key.h>
#include <kidentitymanagement/identity.h>
#include <kidentitymanagement/identitymanager.h>
#include <MailTransport/TransportManager>
#include <MailTransportAkonadi/MessageQueueJob>
......@@ -30,7 +31,15 @@ using namespace Kleo;
using namespace Kleo::Commands;
using namespace GpgME;
const KIdentityManagement::IdentityManager *ExportOpenPGPCertToProviderCommand::mailIdManager = new KIdentityManagement::IdentityManager(true);
static const KIdentityManagement::Identity identityForAddress(const QString &senderAddress) {
static const KIdentityManagement::IdentityManager *idManager = new KIdentityManagement::IdentityManager(true);
const KIdentityManagement::Identity identity = idManager->identityForAddress(senderAddress);
if (identity.isNull())
return idManager->defaultIdentity();
else
return identity;
}
ExportOpenPGPCertToProviderCommand::ExportOpenPGPCertToProviderCommand(QAbstractItemView *v, KeyListController *c)
: GnuPGProcessCommand(v, c)
......@@ -53,9 +62,7 @@ bool ExportOpenPGPCertToProviderCommand::preStartHook(QWidget *parent) const
{
QString sender = senderAddress();
KIdentityManagement::Identity identity = ExportOpenPGPCertToProviderCommand::mailIdManager->identityForAddress(sender);
if (identity.isNull())
identity = ExportOpenPGPCertToProviderCommand::mailIdManager->defaultIdentity();
KIdentityManagement::Identity identity = identityForAddress(sender);
if (identity.transport().isEmpty()) {
KMessageBox::error(parent,
......@@ -86,9 +93,7 @@ void ExportOpenPGPCertToProviderCommand::postSuccessHook(QWidget *parent)
{
QString sender = senderAddress();
KIdentityManagement::Identity identity = ExportOpenPGPCertToProviderCommand::mailIdManager->identityForAddress(sender);
if (identity.isNull())
identity = ExportOpenPGPCertToProviderCommand::mailIdManager->defaultIdentity();
KIdentityManagement::Identity identity = identityForAddress(sender);
MailTransport::Transport *transport = MailTransport::TransportManager::self()->transportByName(
identity.transport());
......
......@@ -12,8 +12,6 @@
#include <commands/gnupgprocesscommand.h>
#include <kidentitymanagement/identitymanager.h>
#include <QtCore/QTemporaryFile>
#include <gpgme++/key.h>
......@@ -55,7 +53,6 @@ private:
GpgME::UserID uid;
QTemporaryFile wksMail;
static const KIdentityManagement::IdentityManager *mailIdManager;
};
}
......
Supports Markdown
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