• 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
  • commands
importcrlcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/importcrlcommand.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 "importcrlcommand.h"
36 
37 #include "command_p.h"
38 
39 #include <QString>
40 #include <QByteArray>
41 #include <QTimer>
42 #include <QFileDialog>
43 
44 #include <KProcess>
45 #include <KMessageBox>
46 #include <KLocale>
47 
48 static const int PROCESS_TERMINATE_TIMEOUT = 5000; // milliseconds
49 
50 using namespace Kleo;
51 using namespace Kleo::Commands;
52 
53 class ImportCrlCommand::Private : Command::Private {
54  friend class ::Kleo::Commands::ImportCrlCommand;
55  ImportCrlCommand * q_func() const { return static_cast<ImportCrlCommand*>( q ); }
56 public:
57  explicit Private( ImportCrlCommand * qq, KeyListController * c );
58  ~Private();
59 
60  QString errorString() const {
61  return QString::fromLocal8Bit( errorBuffer );
62  }
63 
64 private:
65  void init();
66 #ifndef QT_NO_FILEDIALOG
67  QStringList getFileNames() {
68  // loadcrl can only work with DER encoded files
69  // (verified with dirmngr 1.0.3)
70  const QString filter = i18n("Certificate Revocation Lists, DER encoded (*.crl *.arl *-crl.der *-arl.der)");
71  return QFileDialog::getOpenFileNames( parentWidgetOrView(), i18n("Select CRL File to Import"),
72  QString(), filter );
73  }
74 #endif // QT_NO_FILEDIALOG
75 
76 private:
77  void slotProcessFinished( int, QProcess::ExitStatus );
78  void slotProcessReadyReadStandardError();
79 
80 private:
81  QStringList files;
82  KProcess process;
83  QByteArray errorBuffer;
84  bool canceled;
85 };
86 
87 ImportCrlCommand::Private * ImportCrlCommand::d_func() { return static_cast<Private*>( d.get() ); }
88 const ImportCrlCommand::Private * ImportCrlCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
89 
90 #define d d_func()
91 #define q q_func()
92 
93 ImportCrlCommand::Private::Private( ImportCrlCommand * qq, KeyListController * c )
94  : Command::Private( qq, c ),
95  files(),
96  process(),
97  errorBuffer(),
98  canceled( false )
99 {
100  process.setOutputChannelMode( KProcess::OnlyStderrChannel );
101  process << QLatin1String("gpgsm") << QLatin1String("--call-dirmngr") << QLatin1String("loadcrl");
102 }
103 
104 ImportCrlCommand::Private::~Private() {}
105 
106 ImportCrlCommand::ImportCrlCommand( KeyListController * c )
107  : Command( new Private( this, c ) )
108 {
109  d->init();
110 }
111 
112 ImportCrlCommand::ImportCrlCommand( QAbstractItemView * v, KeyListController * c )
113  : Command( v, new Private( this, c ) )
114 {
115  d->init();
116 }
117 
118 ImportCrlCommand::ImportCrlCommand( const QStringList & files, KeyListController * c )
119  : Command( new Private( this, c ) )
120 {
121  d->init();
122  d->files = files;
123 }
124 
125 ImportCrlCommand::ImportCrlCommand( const QStringList & files, QAbstractItemView * v, KeyListController * c )
126  : Command( v, new Private( this, c ) )
127 {
128  d->init();
129  d->files = files;
130 }
131 
132 void ImportCrlCommand::Private::init() {
133  connect( &process, SIGNAL(finished(int,QProcess::ExitStatus)),
134  q, SLOT(slotProcessFinished(int,QProcess::ExitStatus)) );
135  connect( &process, SIGNAL(readyReadStandardError()),
136  q, SLOT(slotProcessReadyReadStandardError()) );
137 }
138 
139 ImportCrlCommand::~ImportCrlCommand() {}
140 
141 void ImportCrlCommand::setFiles( const QStringList & files ) {
142  d->files = files;
143 }
144 
145 void ImportCrlCommand::doStart() {
146 
147 #ifndef QT_NO_FILEDIALOG
148  if ( d->files.empty() )
149  d->files = d->getFileNames();
150 #endif // QT_NO_FILEDIALOG
151  if ( d->files.empty() ) {
152  emit canceled();
153  d->finished();
154  }
155 
156  d->process << d->files;
157 
158  d->process.start();
159 
160  if ( !d->process.waitForStarted() ) {
161  d->error( i18n( "Unable to start process dirmngr. "
162  "Please check your installation." ),
163  i18n( "Clear CRL Cache Error" ) );
164  d->finished();
165  }
166 }
167 
168 void ImportCrlCommand::doCancel() {
169  d->canceled = true;
170  if ( d->process.state() != QProcess::NotRunning ) {
171  d->process.terminate();
172  QTimer::singleShot( PROCESS_TERMINATE_TIMEOUT, &d->process, SLOT(kill()) );
173  }
174 }
175 
176 void ImportCrlCommand::Private::slotProcessFinished( int code, QProcess::ExitStatus status ) {
177  if ( !canceled ) {
178  if ( status == QProcess::CrashExit )
179  error( i18n( "The GpgSM process that tried to import the CRL file "
180  "ended prematurely because of an unexpected error. "
181  "Please check the output of gpgsm --call-dirmngr loadcrl &lt;filename&gt; for details." ),
182  i18n( "Import CRL Error" ) );
183  else if ( code )
184  error( i18n( "An error occurred while trying to import the CRL file. "
185  "The output from gpgsm was:\n%1", errorString() ),
186  i18n( "Import CRL Error" ) );
187  else
188  information( i18n( "CRL file imported successfully." ),
189  i18n( "Import CRL Finished" ) );
190  }
191  finished();
192 }
193 
194 void ImportCrlCommand::Private::slotProcessReadyReadStandardError() {
195  errorBuffer += process.readAllStandardError();
196 }
197 
198 #undef d
199 #undef q
200 
201 #include "moc_importcrlcommand.cpp"
Kleo::Commands::ImportCrlCommand::setFiles
void setFiles(const QStringList &files)
Definition: importcrlcommand.cpp:141
Kleo::Command::Private
Definition: commands/command_p.h:52
Kleo::KeyListController
Definition: keylistcontroller.h:55
q
#define q
Definition: importcrlcommand.cpp:91
Kleo::Commands::ImportCrlCommand::ImportCrlCommand
ImportCrlCommand(QAbstractItemView *view, KeyListController *parent)
Definition: importcrlcommand.cpp:112
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
status
VerifyChecksumsDialog::Status status
Definition: verifychecksumscontroller.cpp:512
process
static QString process(const Dir &dir, bool *fatal)
Definition: createchecksumscontroller.cpp:532
Kleo::Commands::ImportCrlCommand
Definition: importcrlcommand.h:43
kdtools::pimpl_ptr::get
T * get()
Definition: pimpl_ptr.h:39
Kleo::FileDialog::getOpenFileNames
QStringList getOpenFileNames(QWidget *parent=0, const QString &caption=QString(), const QString &dirID=QString(), const QString &filter=QString())
Definition: filedialog.cpp:115
importcrlcommand.h
command_p.h
Kleo::Commands::ImportCrlCommand::~ImportCrlCommand
~ImportCrlCommand()
Definition: importcrlcommand.cpp:139
Kleo::Command::canceled
void canceled()
PROCESS_TERMINATE_TIMEOUT
static const int PROCESS_TERMINATE_TIMEOUT
Definition: importcrlcommand.cpp:48
Kleo::Command
Definition: commands/command.h:58
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