• 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
dumpcrlcachecommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/dumpcrlcachecommand.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 "dumpcrlcachecommand.h"
36 
37 #include "command_p.h"
38 
39 #include <utils/kdlogtextwidget.h>
40 #include <utils/gnupg-helper.h>
41 
42 #include <KProcess>
43 #include <KMessageBox>
44 #include <KLocale>
45 #include <KPushButton>
46 #include <KStandardGuiItem>
47 #include <KGlobalSettings>
48 
49 #include <QString>
50 #include <QByteArray>
51 #include <QTimer>
52 #include <QLayout>
53 
54 
55 static const int PROCESS_TERMINATE_TIMEOUT = 5000; // milliseconds
56 
57 namespace {
58  class DumpCrlCacheDialog : public QDialog {
59  Q_OBJECT
60  public:
61  explicit DumpCrlCacheDialog( QWidget * parent=0 )
62  : QDialog( parent ), ui( this )
63  {
64 
65  }
66 
67  Q_SIGNALS:
68  void updateRequested();
69 
70  public Q_SLOTS:
71  void append( const QString & line ) {
72  ui.logTextWidget.message( line );
73  }
74  void clear() {
75  ui.logTextWidget.clear();
76  }
77 
78  private:
79  struct Ui {
80  KDLogTextWidget logTextWidget;
81  KPushButton updateButton, closeButton;
82  QVBoxLayout vlay;
83  QHBoxLayout hlay;
84 
85  explicit Ui( DumpCrlCacheDialog * q )
86  : logTextWidget( q ),
87  updateButton( i18nc("@action:button Update the log text widget", "&Update"), q ),
88  closeButton( KStandardGuiItem::close(), q ),
89  vlay( q ),
90  hlay()
91  {
92  KDAB_SET_OBJECT_NAME( logTextWidget );
93  KDAB_SET_OBJECT_NAME( updateButton );
94  KDAB_SET_OBJECT_NAME( closeButton );
95  KDAB_SET_OBJECT_NAME( vlay );
96  KDAB_SET_OBJECT_NAME( hlay );
97 
98  logTextWidget.setFont( KGlobalSettings::fixedFont() );
99  logTextWidget.setMinimumVisibleLines( 25 );
100  logTextWidget.setMinimumVisibleColumns( 80 );
101 
102  vlay.addWidget( &logTextWidget, 1 );
103  vlay.addLayout( &hlay );
104 
105  hlay.addWidget( &updateButton );
106  hlay.addStretch( 1 );
107  hlay.addWidget( &closeButton );
108 
109  connect( &updateButton, SIGNAL(clicked()),
110  q, SIGNAL(updateRequested()) );
111  connect( &closeButton, SIGNAL(clicked()),
112  q, SLOT(close()) );
113  }
114  } ui;
115  };
116 }
117 
118 using namespace Kleo;
119 using namespace Kleo::Commands;
120 
121 static QByteArray chomped( QByteArray ba ) {
122  while ( ba.endsWith( '\n' ) || ba.endsWith( '\r' ) )
123  ba.chop( 1 );
124  return ba;
125 }
126 
127 class DumpCrlCacheCommand::Private : Command::Private {
128  friend class ::Kleo::Commands::DumpCrlCacheCommand;
129  DumpCrlCacheCommand * q_func() const { return static_cast<DumpCrlCacheCommand*>( q ); }
130 public:
131  explicit Private( DumpCrlCacheCommand * qq, KeyListController * c );
132  ~Private();
133 
134  QString errorString() const {
135  return QString::fromLocal8Bit( errorBuffer );
136  }
137 
138 private:
139  void init();
140  void refreshView();
141 
142 private:
143  void slotProcessFinished( int, QProcess::ExitStatus );
144 
145  void slotProcessReadyReadStandardOutput() {
146  while ( process.canReadLine() ) {
147  const QByteArray line = chomped( process.readLine() );
148  if ( dialog )
149  dialog->append( QString::fromLocal8Bit( line ) );
150  }
151  }
152 
153  void slotProcessReadyReadStandardError() {
154  errorBuffer += process.readAllStandardError();
155  }
156 
157  void slotUpdateRequested() {
158  if ( process.state() == QProcess::NotRunning )
159  refreshView();
160  }
161 
162  void slotDialogDestroyed() {
163  dialog = 0;
164  if ( process.state() != QProcess::NotRunning )
165  q->cancel();
166  else
167  finished();
168  }
169 
170 private:
171  DumpCrlCacheDialog * dialog;
172  KProcess process;
173  QByteArray errorBuffer;
174  bool canceled;
175 };
176 
177 DumpCrlCacheCommand::Private * DumpCrlCacheCommand::d_func() { return static_cast<Private*>( d.get() ); }
178 const DumpCrlCacheCommand::Private * DumpCrlCacheCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
179 
180 #define d d_func()
181 #define q q_func()
182 
183 DumpCrlCacheCommand::Private::Private( DumpCrlCacheCommand * qq, KeyListController * c )
184  : Command::Private( qq, c ),
185  dialog(0),
186  process(),
187  errorBuffer(),
188  canceled( false )
189 {
190  process.setOutputChannelMode( KProcess::SeparateChannels );
191  process.setReadChannel( KProcess::StandardOutput );
192  process << gpgSmPath() << QLatin1String("--call-dirmngr") << QLatin1String("listcrls");
193 }
194 
195 DumpCrlCacheCommand::Private::~Private() {
196  if ( dialog && !dialog->isVisible() )
197  delete dialog;
198 }
199 
200 DumpCrlCacheCommand::DumpCrlCacheCommand( KeyListController * c )
201  : Command( new Private( this, c ) )
202 {
203  d->init();
204 }
205 
206 DumpCrlCacheCommand::DumpCrlCacheCommand( QAbstractItemView * v, KeyListController * c )
207  : Command( v, new Private( this, c ) )
208 {
209  d->init();
210 }
211 
212 void DumpCrlCacheCommand::Private::init() {
213  connect( &process, SIGNAL(finished(int,QProcess::ExitStatus)),
214  q, SLOT(slotProcessFinished(int,QProcess::ExitStatus)) );
215  connect( &process, SIGNAL(readyReadStandardError()),
216  q, SLOT(slotProcessReadyReadStandardError()) );
217  connect( &process, SIGNAL(readyReadStandardOutput()),
218  q, SLOT(slotProcessReadyReadStandardOutput()) );
219 }
220 
221 DumpCrlCacheCommand::~DumpCrlCacheCommand() {}
222 
223 void DumpCrlCacheCommand::doStart() {
224 
225  d->dialog = new DumpCrlCacheDialog;
226  d->dialog->setAttribute( Qt::WA_DeleteOnClose );
227  d->dialog->setWindowTitle( i18n("CRL Cache Dump") );
228 
229  connect( d->dialog, SIGNAL(updateRequested()),
230  this, SLOT(slotUpdateRequested()) );
231  connect( d->dialog, SIGNAL(destroyed()),
232  this, SLOT(slotDialogDestroyed()) );
233 
234  d->refreshView();
235 }
236 
237 void DumpCrlCacheCommand::Private::refreshView() {
238 
239  dialog->clear();
240 
241  process.start();
242 
243  if ( process.waitForStarted() ) {
244  dialog->show();
245  } else {
246  KMessageBox::error( dialog ? static_cast<QWidget*>( dialog ) : parentWidgetOrView(),
247  i18n( "Unable to start process gpgsm. "
248  "Please check your installation." ),
249  i18n( "Dump CRL Cache Error" ) );
250  finished();
251  }
252 }
253 
254 void DumpCrlCacheCommand::doCancel() {
255  d->canceled = true;
256  if ( d->process.state() != QProcess::NotRunning ) {
257  d->process.terminate();
258  QTimer::singleShot( PROCESS_TERMINATE_TIMEOUT, &d->process, SLOT(kill()) );
259  }
260  if ( d->dialog )
261  d->dialog->close();
262  d->dialog = 0;
263 }
264 
265 void DumpCrlCacheCommand::Private::slotProcessFinished( int code, QProcess::ExitStatus status ) {
266  if ( !canceled ) {
267  if ( status == QProcess::CrashExit )
268  KMessageBox::error( dialog,
269  i18n( "The GpgSM process that tried to dump the CRL cache "
270  "ended prematurely because of an unexpected error. "
271  "Please check the output of gpgsm --call-dirmngr listcrls for details." ),
272  i18n( "Dump CRL Cache Error" ) );
273  else if ( code )
274  KMessageBox::error( dialog,
275  i18n( "An error occurred while trying to dump the CRL cache. "
276  "The output from GpgSM was:\n%1", errorString() ),
277  i18n( "Dump CRL Cache Error" ) );
278  }
279 }
280 
281 #undef d
282 #undef q
283 
284 #include "moc_dumpcrlcachecommand.cpp"
285 #include "dumpcrlcachecommand.moc"
Kleo::Commands::DumpCrlCacheCommand::DumpCrlCacheCommand
DumpCrlCacheCommand(QAbstractItemView *view, KeyListController *parent)
Definition: dumpcrlcachecommand.cpp:206
Kleo::Command::finished
void finished()
Kleo::Commands::DumpCrlCacheCommand
Definition: dumpcrlcachecommand.h:41
Kleo::Commands::DumpCrlCacheCommand::~DumpCrlCacheCommand
~DumpCrlCacheCommand()
Definition: dumpcrlcachecommand.cpp:221
Kleo::Command::Private
Definition: commands/command_p.h:52
QDialog
KDLogTextWidget
A high-speed text display widget.
Definition: kdlogtextwidget.h:34
Kleo::KeyListController
Definition: keylistcontroller.h:55
QWidget
chomped
static QByteArray chomped(QByteArray ba)
Definition: dumpcrlcachecommand.cpp:121
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::gpgSmPath
QString gpgSmPath()
Definition: gnupg-helper.cpp:82
KDAB_SET_OBJECT_NAME
#define KDAB_SET_OBJECT_NAME(x)
Definition: kdtoolsglobal.h:66
kdtools::pimpl_ptr::get
T * get()
Definition: pimpl_ptr.h:39
q
#define q
Definition: dumpcrlcachecommand.cpp:181
dumpcrlcachecommand.h
gnupg-helper.h
command_p.h
Kleo::Command::canceled
void canceled()
kdlogtextwidget.h
PROCESS_TERMINATE_TIMEOUT
static const int PROCESS_TERMINATE_TIMEOUT
Definition: dumpcrlcachecommand.cpp:55
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