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

kleopatra

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

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