• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kleopatra

  • sources
  • kde-4.12
  • kdepim
  • kleopatra
  • dialogs
exportsecretkeydialog.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  dialogs/exportsecretkeydialog.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 Klarälvdalens Datakonsult AB
6 
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.
11 
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.
16 
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
20 
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
30  your version.
31 */
32 
33 #include <config-kleopatra.h>
34 
35 #include "exportsecretkeydialog.h"
36 
37 #include "ui_exportsecretkeydialog.h"
38 
39 #include <utils/formatting.h>
40 
41 #include <gpgme++/key.h>
42 
43 #include <KDebug>
44 #include <KMessageBox>
45 #include <KLocalizedString>
46 
47 #include <cassert>
48 
49 using namespace Kleo;
50 using namespace Kleo::Dialogs;
51 using namespace GpgME;
52 
53 // This comes from gnupg's sources, agent/minip12.c
54 // In fact, any charset supported by iconv would work, but we don't link to iconv directly...
55 static const char *charsets[] = {
56  "utf8",
57  "iso-8859-1",
58  "iso-8859-15",
59  "iso-8859-2",
60  "iso-8859-3",
61  "iso-8859-4",
62  "iso-8859-5",
63  "iso-8859-6",
64  "iso-8859-7",
65  "iso-8859-8",
66  "iso-8859-9",
67  "koi8-r",
68  "ibm437",
69  "ibm850",
70  "euc-jp",
71  "big5",
72 };
73 static const unsigned int numCharsets = sizeof charsets / sizeof *charsets;
74 
75 class ExportSecretKeyDialog::Private {
76  friend class ::Kleo::Dialogs::ExportSecretKeyDialog;
77  ExportSecretKeyDialog * const q;
78 public:
79  explicit Private( ExportSecretKeyDialog * qq )
80  : q( qq ),
81  ui( q )
82  {
83 
84  }
85 
86 private:
87  void updateWidgets() {
88  const bool x509 = key.protocol() == CMS;
89  ui.charsetCB->setVisible( x509 );
90  ui.charsetLB->setVisible( x509 );
91  }
92 
93  void updateFileName() {
94  const bool x509 = key.protocol() == CMS;
95  const bool armor = q->useArmor();
96 
97  static const char * extensions[] = {
98  ".gpg", ".asc", ".p12", ".pem"
99  };
100  const unsigned int idx = 2*x509+armor;
101  const char * const extension = extensions[idx];
102 
103  const QString nf = i18n("Secret Key Files") + QString::fromLatin1("(*%1 *%2 *%3 *%4 *.pgp)")
104  .arg( QLatin1String(extensions[idx]), QLatin1String(extensions[(idx+1)%4]), QLatin1String(extensions[(idx+2)%4]), QLatin1String(extensions[(idx+3)%4]) );
105  ui.outputFileFR->setNameFilter( nf );
106 
107  QString fn = q->fileName();
108  if ( fn.isEmpty() )
109  return;
110 
111  bool found = false;
112  for ( unsigned int i = 0 ; i < sizeof extensions / sizeof *extensions ; ++i )
113  if ( fn.endsWith( QLatin1String(extensions[i]), Qt::CaseInsensitive ) ) {
114  fn.chop( 4 );
115  found = true;
116  break;
117  }
118  if ( found )
119  q->setFileName( fn + QLatin1String(extension) );
120  }
121 
122  void updateLabel() {
123  ui.descriptionLB->setText( i18nc("@info",
124  "Please select export options for %1:",
125  Formatting::formatForComboBox( key ) ) );
126  }
127 private:
128  Key key;
129 
130  struct UI : public Ui_ExportSecretKeyDialog {
131  explicit UI( Dialogs::ExportSecretKeyDialog * qq )
132  : Ui_ExportSecretKeyDialog()
133  {
134  setupUi( qq );
135 
136  outputFileFR->setExistingOnly( false );
137  outputFileFR->setFilter( QDir::Files );
138  outputFileFR->setNameFilter( i18n("Secret Key Files (*.pem *.p12 *.gpg *.asc *.pgp)") );
139 
140  for ( unsigned int i = 0 ; i < numCharsets ; ++i )
141  charsetCB->addItem( QString::fromLatin1( charsets[i] ) );
142  charsetCB->setCurrentIndex( 0 );
143 
144  }
145  } ui;
146 };
147 
148 ExportSecretKeyDialog::ExportSecretKeyDialog( QWidget * p, Qt::WindowFlags f )
149  : QDialog( p, f ), d( new Private( this ) )
150 {
151 
152 }
153 
154 ExportSecretKeyDialog::~ExportSecretKeyDialog() {}
155 
156 
157 void ExportSecretKeyDialog::setKey( const Key & key ) {
158  if ( qstricmp( key.primaryFingerprint(), d->key.primaryFingerprint() ) == 0 )
159  return;
160  d->key = key;
161  d->updateWidgets();
162  d->updateLabel();
163  d->updateFileName();
164 }
165 
166 Key ExportSecretKeyDialog::key() const {
167  return d->key;
168 }
169 
170 void ExportSecretKeyDialog::setFileName( const QString & fileName ) {
171  d->ui.outputFileFR->setFileName( fileName );
172 }
173 
174 QString ExportSecretKeyDialog::fileName() const {
175  return d->ui.outputFileFR->fileName();
176 }
177 
178 void ExportSecretKeyDialog::setCharset( const QByteArray & charset ) {
179  for ( unsigned int i = 0 ; i < sizeof charsets / sizeof *charsets ; ++i )
180  if ( charset == charsets[i] ) {
181  d->ui.charsetCB->setCurrentIndex( i );
182  return;
183  }
184 }
185 
186 QByteArray ExportSecretKeyDialog::charset() const {
187  if ( d->ui.charsetCB->isVisible() )
188  return d->ui.charsetCB->currentText().toLatin1();
189  else
190  return QByteArray();
191 }
192 
193 void ExportSecretKeyDialog::setUseArmor( bool on ) {
194  d->ui.armorCB->setChecked( on );
195 }
196 
197 bool ExportSecretKeyDialog::useArmor() const {
198  return d->ui.armorCB->isChecked();
199 }
200 
201 void ExportSecretKeyDialog::accept() {
202  d->updateFileName();
203  const QString fn = fileName();
204  if ( fn.isEmpty() ) {
205  KMessageBox::information( this, i18nc("@info",
206  "You have to enter an output filename." ),
207  i18nc("@title", "Incomplete data") );
208  d->ui.outputFileFR->setFocus();
209  return;
210  }
211 
212  const QByteArray cs = charset();
213  if ( d->key.protocol() == CMS && cs.isEmpty() ) {
214  KMessageBox::information( this, i18nc("@info",
215  "You have to choose a passphrase character set." ),
216  i18nc("@title", "Incomplete data") );
217  d->ui.charsetCB->setFocus();
218  return;
219  }
220 
221  QDialog::accept();
222 }
223 
224 #include "moc_exportsecretkeydialog.cpp"
QDialog
Kleo::Dialogs::ExportSecretKeyDialog::ExportSecretKeyDialog
ExportSecretKeyDialog(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: exportsecretkeydialog.cpp:148
Kleo::Dialogs::ExportSecretKeyDialog::key
GpgME::Key key() const
Definition: exportsecretkeydialog.cpp:166
Kleo::Dialogs::ExportSecretKeyDialog::setCharset
void setCharset(const QByteArray &charset)
Definition: exportsecretkeydialog.cpp:178
QWidget
formatting.h
Kleo::Dialogs::ExportSecretKeyDialog::setUseArmor
void setUseArmor(bool armor)
Definition: exportsecretkeydialog.cpp:193
Kleo::Dialogs::ExportSecretKeyDialog::setFileName
void setFileName(const QString &fileName)
Definition: exportsecretkeydialog.cpp:170
Kleo::Formatting::formatForComboBox
QString formatForComboBox(const GpgME::Key &key)
Definition: formatting.cpp:497
d
#define d
Definition: adduseridcommand.cpp:90
numCharsets
static const unsigned int numCharsets
Definition: exportsecretkeydialog.cpp:73
Kleo::Dialogs::ExportSecretKeyDialog::fileName
QString fileName() const
Definition: exportsecretkeydialog.cpp:174
Kleo::Dialogs::ExportSecretKeyDialog
Definition: exportsecretkeydialog.h:49
Kleo::Dialogs::ExportSecretKeyDialog::accept
void accept()
Definition: exportsecretkeydialog.cpp:201
Kleo::Class::CMS
Definition: classify.h:48
Kleo::Dialogs::ExportSecretKeyDialog::~ExportSecretKeyDialog
~ExportSecretKeyDialog()
Definition: exportsecretkeydialog.cpp:154
Kleo::Dialogs::ExportSecretKeyDialog::charset
QByteArray charset() const
Definition: exportsecretkeydialog.cpp:186
charsets
static const char * charsets[]
Definition: exportsecretkeydialog.cpp:55
q
#define q
Definition: adduseridcommand.cpp:91
exportsecretkeydialog.h
Kleo::Dialogs::ExportSecretKeyDialog::setKey
void setKey(const GpgME::Key &key)
Definition: exportsecretkeydialog.cpp:157
extension
static const char * extension(bool pgp, bool sign, bool encrypt, bool ascii, bool detached)
Definition: signencryptfilescontroller.cpp:285
Kleo::Dialogs::ExportSecretKeyDialog::useArmor
bool useArmor() const
Definition: exportsecretkeydialog.cpp:197
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal