1 /* -*- mode: c++; c-basic-offset:4 -*-
2 commands/exportsecretkeycommand.cpp
4 This file is part of Kleopatra, the KDE keymanager
5 Copyright (c) 2008 Klarälvdalens Datakonsult AB
7 Kleopatra is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 Kleopatra is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 In addition, as a special exception, the copyright holders give
22 permission to link the code of this program with any edition of
23 the Qt library by Trolltech AS, Norway (or with modified versions
24 of Qt that use the same license as Qt), and distribute linked
25 combinations including the two. You must obey the GNU General
26 Public License in all respects for all of the code used other than
27 Qt. If you modify this file, you may extend this exception to
28 your version of the file, but you are not obligated to do so. If
29 you do not wish to do so, delete this exception statement from
33 #include <config-kleopatra.h>
35 #include "exportsecretkeycommand.h"
37 #include "command_p.h"
39 #include <dialogs/exportsecretkeydialog.h>
41 #include <utils/gnupg-helper.h>
43 #include <gpgme++/key.h>
45 #include <KLocalizedString>
48 using namespace Kleo::Commands
;
49 using namespace Kleo::Dialogs
;
50 using namespace GpgME
;
52 ExportSecretKeyCommand::ExportSecretKeyCommand(KeyListController
*c
)
53 : GnuPGProcessCommand(c
)
57 ExportSecretKeyCommand::ExportSecretKeyCommand(QAbstractItemView
*v
, KeyListController
*c
)
58 : GnuPGProcessCommand(v
, c
)
62 ExportSecretKeyCommand::ExportSecretKeyCommand(const Key
&key
)
63 : GnuPGProcessCommand(key
)
67 ExportSecretKeyCommand::~ExportSecretKeyCommand() {}
69 void ExportSecretKeyCommand::setFileName(const QString
&fileName
)
71 m_filename
= fileName
;
74 void ExportSecretKeyCommand::setPassphraseCharset(const QByteArray
&charset
)
79 void ExportSecretKeyCommand::setUseArmor(bool armor
)
84 bool ExportSecretKeyCommand::preStartHook(QWidget
*parent
) const
86 if (!m_filename
.isEmpty()) {
90 ExportSecretKeyDialog
dlg(parent
);
96 m_filename
= dlg
.fileName();
97 m_armor
= dlg
.useArmor();
98 m_charset
= dlg
.charset();
103 QStringList
ExportSecretKeyCommand::arguments() const
105 const Key key
= d
->key();
108 if (key
.protocol() == OpenPGP
) {
109 result
<< gpgPath() << QStringLiteral("--batch");
111 result
<< gpgSmPath();
114 result
<< QStringLiteral("--output") << m_filename
;
117 result
<< QStringLiteral("--armor");
120 if (key
.protocol() == CMS
&& !m_charset
.isEmpty()) {
121 result
<< QStringLiteral("--p12-charset") << QLatin1String(m_charset
);
124 if (key
.protocol() == OpenPGP
) {
125 result
<< QStringLiteral("--export-secret-key");
127 result
<< QStringLiteral("--export-secret-key-p12");
130 result
<< QLatin1String(key
.primaryFingerprint());
135 QString
ExportSecretKeyCommand::errorCaption() const
137 return i18nc("@title:window", "Secret Key Export Error");
140 QString
ExportSecretKeyCommand::successCaption() const
142 return i18nc("@title:window", "Secret Key Export Finished");
145 QString
ExportSecretKeyCommand::crashExitMessage(const QStringList
&args
) const
147 return xi18nc("@info",
148 "<para>The GPG or GpgSM process that tried to export the secret key "
149 "ended prematurely because of an unexpected error.</para>"
150 "<para>Please check the output of <icode>%1</icode> for details.</para>", args
.join(QStringLiteral(" "))) ;
153 QString
ExportSecretKeyCommand::errorExitMessage(const QStringList
&args
) const
155 return xi18nc("@info",
156 "<para>An error occurred while trying to export the secret key.</para> "
157 "<para>The output from <command>%1</command> was: <message>%2</message></para>",
158 args
[0], errorString());
161 QString
ExportSecretKeyCommand::successMessage(const QStringList
&) const
163 return i18nc("@info", "Secret key successfully exported.");