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