• 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
selftestcommand.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  commands/selftestcommand.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 "selftestcommand.h"
36 
37 #include "command_p.h"
38 
39 #include <dialogs/selftestdialog.h>
40 
41 #ifdef Q_OS_WIN
42 # include <selftest/registrycheck.h>
43 #endif
44 #include <selftest/enginecheck.h>
45 #include <selftest/gpgconfcheck.h>
46 #ifdef HAVE_KLEOPATRACLIENT_LIBRARY
47 # include <selftest/uiservercheck.h>
48 #endif
49 #include <selftest/gpgagentcheck.h>
50 #include <selftest/libkleopatrarccheck.h>
51 
52 #include <kleo/stl_util.h>
53 
54 #include <KLocalizedString>
55 #include <KGlobal>
56 #include <KConfigGroup>
57 #include <KSplashScreen>
58 #include <KSharedConfig>
59 
60 #ifndef Q_MOC_RUN
61 #include <boost/shared_ptr.hpp>
62 #include <boost/mem_fn.hpp>
63 #endif
64 
65 #include <vector>
66 
67 using namespace Kleo;
68 using namespace Kleo::Commands;
69 using namespace Kleo::Dialogs;
70 using namespace boost;
71 
72 static const char * const components[] = {
73  0, // gpgconf
74  "gpg",
75  "gpg-agent",
76  "scdaemon",
77  "gpgsm",
78  "dirmngr",
79 };
80 static const unsigned int numComponents = sizeof components / sizeof *components;
81 
82 class SelfTestCommand::Private : Command::Private {
83  friend class ::Kleo::Commands::SelfTestCommand;
84  SelfTestCommand * q_func() const { return static_cast<SelfTestCommand*>( q ); }
85 public:
86  explicit Private( SelfTestCommand * qq, KeyListController * c );
87  ~Private();
88 
89 private:
90  void init();
91 
92  void ensureDialogCreated() {
93  if ( dialog )
94  return;
95  dialog = new SelfTestDialog;
96  applyWindowID( dialog );
97  dialog->setAttribute( Qt::WA_DeleteOnClose );
98 
99  connect( dialog, SIGNAL(updateRequested()),
100  q_func(), SLOT(slotUpdateRequested()) );
101  connect( dialog, SIGNAL(accepted()),
102  q_func(), SLOT(slotDialogAccepted()) );
103  connect( dialog, SIGNAL(rejected()),
104  q_func(), SLOT(slotDialogRejected()) );
105 
106  dialog->setRunAtStartUp( runAtStartUp() );
107  dialog->setAutomaticMode( automatic );
108  }
109 
110  void ensureDialogShown() {
111  ensureDialogCreated();
112  if ( dialog->isVisible() )
113  dialog->raise();
114  else
115  dialog->show();
116 #ifndef QT_NO_SPLASHSCREEN
117  if ( splash )
118  splash->finish( dialog );
119 #endif // QT_NO_SPLASHSCREEN
120  }
121 
122  bool runAtStartUp() const {
123  const KConfigGroup config( KGlobal::config(), "Self-Test" );
124  return config.readEntry( "run-at-startup", true );
125  }
126 
127  void setRunAtStartUp( bool on ) {
128  KConfigGroup config( KGlobal::config(), "Self-Test" );
129  config.writeEntry( "run-at-startup", on );
130  }
131 
132  void runTests() {
133  std::vector< shared_ptr<Kleo::SelfTest> > tests;
134 
135 #if defined(Q_OS_WIN)
136  //emit q->info( i18n("Checking Windows Registry...") );
137  tests.push_back( makeGpgProgramRegistryCheckSelfTest() );
138 #endif
139  //emit q->info( i18n("Checking gpg installation...") );
140  tests.push_back( makeGpgEngineCheckSelfTest() );
141  //emit q->info( i18n("Checking gpgsm installation...") );
142  tests.push_back( makeGpgSmEngineCheckSelfTest() );
143  //emit q->info( i18n("Checking gpgconf installation...") );
144  tests.push_back( makeGpgConfEngineCheckSelfTest() );
145  for ( unsigned int i = 0 ; i < numComponents ; ++i ) {
146  //emit q->info( i18n("Checking %1 configuration...", components[i]) );
147  tests.push_back( makeGpgConfCheckConfigurationSelfTest( components[i] ) );
148  }
149 #if defined( HAVE_KLEOPATRACLIENT_LIBRARY )
150  //emit q->info( i18n("Checking Ui Server connectivity...") );
151  tests.push_back( makeUiServerConnectivitySelfTest() );
152 #endif
153 #ifndef Q_OS_WIN
154  tests.push_back( makeGpgAgentConnectivitySelfTest() );
155 #endif
156  tests.push_back( makeLibKleopatraRcSelfTest() );
157 
158  if ( !dialog && kdtools::none_of( tests, mem_fn( &Kleo::SelfTest::failed ) ) ) {
159  finished();
160  return;
161  }
162 
163  ensureDialogCreated();
164 
165  dialog->clear();
166  dialog->addSelfTests( tests );
167 
168  ensureDialogShown();
169  }
170 
171 private:
172  void slotDialogAccepted() {
173  setRunAtStartUp( dialog->runAtStartUp() );
174  finished();
175  }
176  void slotDialogRejected() {
177  if ( automatic ) {
178  canceled = true;
179  Command::Private::canceled();
180  } else {
181  slotDialogAccepted();
182  }
183  }
184  void slotUpdateRequested() {
185  runTests();
186  }
187 
188 private:
189 #ifndef QT_NO_SPLASHSCREEN
190  QPointer<KSplashScreen> splash;
191 #endif // QT_NO_SPLASHSCREEN
192  QPointer<SelfTestDialog> dialog;
193  bool canceled;
194  bool automatic;
195 };
196 
197 SelfTestCommand::Private * SelfTestCommand::d_func() { return static_cast<Private*>( d.get() ); }
198 const SelfTestCommand::Private * SelfTestCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
199 
200 #define d d_func()
201 #define q q_func()
202 
203 SelfTestCommand::Private::Private( SelfTestCommand * qq, KeyListController * c )
204  : Command::Private( qq, c ),
205 #ifndef QT_NO_SPLASHSCREEN
206  splash(),
207 #endif // QT_NO_SPLASHSCREEN
208  dialog(),
209  canceled( false ),
210  automatic( false )
211 {
212 
213 }
214 
215 SelfTestCommand::Private::~Private() {
216 
217 }
218 
219 SelfTestCommand::SelfTestCommand( KeyListController * c )
220  : Command( new Private( this, c ) )
221 {
222  d->init();
223 }
224 
225 SelfTestCommand::SelfTestCommand( QAbstractItemView * v, KeyListController * c )
226  : Command( v, new Private( this, c ) )
227 {
228  d->init();
229 }
230 
231 void SelfTestCommand::Private::init() {
232 
233 }
234 
235 SelfTestCommand::~SelfTestCommand() {}
236 
237 void SelfTestCommand::setAutomaticMode( bool on ) {
238  d->automatic = on;
239  if ( d->dialog )
240  d->dialog->setAutomaticMode( on );
241 }
242 
243 void SelfTestCommand::setSplashScreen( KSplashScreen * splash ) {
244 #ifndef QT_NO_SPLASHSCREEN
245  d->splash = splash;
246 #else
247  Q_UNUSED( splash );
248 #endif // QT_NO_SPLASHSCREEN
249 }
250 
251 bool SelfTestCommand::isCanceled() const {
252  return d->canceled;
253 }
254 
255 void SelfTestCommand::doStart() {
256 
257  if ( d->automatic ) {
258  if ( !d->runAtStartUp() ) {
259  d->finished();
260  return;
261  }
262  } else {
263  d->ensureDialogCreated();
264  }
265 
266  d->runTests();
267 
268 }
269 
270 void SelfTestCommand::doCancel() {
271  d->canceled = true;
272  if ( d->dialog )
273  d->dialog->close();
274  d->dialog = 0;
275 }
276 
277 #undef d
278 #undef q
279 
280 #include "moc_selftestcommand.cpp"
Kleo::Command::Private::canceled
void canceled()
Definition: commands/command_p.h:78
Kleo::makeUiServerConnectivitySelfTest
boost::shared_ptr< SelfTest > makeUiServerConnectivitySelfTest()
Definition: uiservercheck.cpp:105
QAbstractItemView
gpgagentcheck.h
Kleo::Command::Private
Definition: commands/command_p.h:52
libkleopatrarccheck.h
Kleo::Commands::SelfTestCommand::isCanceled
bool isCanceled() const
Definition: selftestcommand.cpp:251
Kleo::KeyListController
Definition: keylistcontroller.h:55
registrycheck.h
QPointer< KSplashScreen >
Kleo::Commands::SelfTestCommand::~SelfTestCommand
~SelfTestCommand()
Definition: selftestcommand.cpp:235
Kleo::makeGpgProgramRegistryCheckSelfTest
boost::shared_ptr< SelfTest > makeGpgProgramRegistryCheckSelfTest()
Definition: registrycheck.cpp:120
uiservercheck.h
Kleo::Commands::SelfTestCommand::setAutomaticMode
void setAutomaticMode(bool automatic)
Definition: selftestcommand.cpp:237
Kleo::Command::d
kdtools::pimpl_ptr< Private > d
Definition: commands/command.h:129
Kleo::makeGpgAgentConnectivitySelfTest
boost::shared_ptr< SelfTest > makeGpgAgentConnectivitySelfTest()
Definition: gpgagentcheck.cpp:129
components
static const char *const components[]
Definition: selftestcommand.cpp:72
Kleo::SelfTest::failed
bool failed() const
Definition: selftest.h:54
Kleo::Commands::SelfTestCommand
Definition: selftestcommand.h:43
Kleo::Commands::SelfTestCommand::setSplashScreen
void setSplashScreen(KSplashScreen *splash)
Definition: selftestcommand.cpp:243
Kleo::makeGpgSmEngineCheckSelfTest
boost::shared_ptr< SelfTest > makeGpgSmEngineCheckSelfTest()
Definition: enginecheck.cpp:147
gpgconfcheck.h
selftestcommand.h
command_p.h
Kleo::Commands::SelfTestCommand::SelfTestCommand
SelfTestCommand(QAbstractItemView *view, KeyListController *parent)
Definition: selftestcommand.cpp:225
numComponents
static const unsigned int numComponents
Definition: selftestcommand.cpp:80
q
#define q
Definition: selftestcommand.cpp:201
selftestdialog.h
Kleo::makeGpgConfCheckConfigurationSelfTest
boost::shared_ptr< SelfTest > makeGpgConfCheckConfigurationSelfTest(const char *component=0)
Definition: gpgconfcheck.cpp:154
d
#define d
Definition: selftestcommand.cpp:200
Kleo::Dialogs::SelfTestDialog
Definition: selftestdialog.h:52
enginecheck.h
Kleo::makeLibKleopatraRcSelfTest
boost::shared_ptr< SelfTest > makeLibKleopatraRcSelfTest()
Definition: libkleopatrarccheck.cpp:87
Kleo::makeGpgConfEngineCheckSelfTest
boost::shared_ptr< SelfTest > makeGpgConfEngineCheckSelfTest()
Definition: enginecheck.cpp:151
Kleo::Command
Definition: commands/command.h:58
Kleo::makeGpgEngineCheckSelfTest
boost::shared_ptr< SelfTest > makeGpgEngineCheckSelfTest()
Definition: enginecheck.cpp:143
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