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