Better wording
[kdepim.git] / kleopatra / commands / selftestcommand.cpp
blob18e77ca1a2b4f1bd0fde986f9fb8b70826c3fd86
1 /* -*- mode: c++; c-basic-offset:4 -*-
2 commands/selftestcommand.cpp
4 This file is part of Kleopatra, the KDE keymanager
5 Copyright (c) 2008 Klarälvdalens Datakonsult AB
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.
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.
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
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.
33 #include <config-kleopatra.h>
35 #include "selftestcommand.h"
37 #include "command_p.h"
39 #include <dialogs/selftestdialog.h>
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>
52 #include <kleo/stl_util.h>
54 #include <KLocale>
55 #include <KGlobal>
56 #include <KConfigGroup>
57 #include <KSplashScreen>
59 #include <boost/shared_ptr.hpp>
60 #include <boost/mem_fn.hpp>
62 #include <vector>
64 using namespace Kleo;
65 using namespace Kleo::Commands;
66 using namespace Kleo::Dialogs;
67 using namespace boost;
69 static const char * const components[] = {
70 0, // gpgconf
71 "gpg",
72 "gpg-agent",
73 "scdaemon",
74 "gpgsm",
75 "dirmngr",
77 static const unsigned int numComponents = sizeof components / sizeof *components;
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();
86 private:
87 void init();
89 void ensureDialogCreated() {
90 if ( dialog )
91 return;
92 dialog = new SelfTestDialog;
93 applyWindowID( dialog );
94 dialog->setAttribute( Qt::WA_DeleteOnClose );
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()) );
103 dialog->setRunAtStartUp( runAtStartUp() );
104 dialog->setAutomaticMode( automatic );
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
119 bool runAtStartUp() const {
120 const KConfigGroup config( KGlobal::config(), "Self-Test" );
121 return config.readEntry( "run-at-startup", true );
124 void setRunAtStartUp( bool on ) {
125 KConfigGroup config( KGlobal::config(), "Self-Test" );
126 config.writeEntry( "run-at-startup", on );
129 void runTests() {
130 std::vector< shared_ptr<Kleo::SelfTest> > tests;
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] ) );
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
159 if ( !dialog && kdtools::none_of( tests, mem_fn( &Kleo::SelfTest::failed ) ) ) {
160 finished();
161 return;
164 ensureDialogCreated();
166 dialog->clear();
167 dialog->addSelfTests( tests );
169 ensureDialogShown();
172 private:
173 void slotDialogAccepted() {
174 setRunAtStartUp( dialog->runAtStartUp() );
175 finished();
177 void slotDialogRejected() {
178 if ( automatic ) {
179 canceled = true;
180 Command::Private::canceled();
181 } else {
182 slotDialogAccepted();
185 void slotUpdateRequested() {
186 runTests();
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;
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() ); }
201 #define d d_func()
202 #define q q_func()
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 )
216 SelfTestCommand::Private::~Private() {
220 SelfTestCommand::SelfTestCommand( KeyListController * c )
221 : Command( new Private( this, c ) )
223 d->init();
226 SelfTestCommand::SelfTestCommand( QAbstractItemView * v, KeyListController * c )
227 : Command( v, new Private( this, c ) )
229 d->init();
232 void SelfTestCommand::Private::init() {
236 SelfTestCommand::~SelfTestCommand() {}
238 void SelfTestCommand::setAutomaticMode( bool on ) {
239 d->automatic = on;
240 if ( d->dialog )
241 d->dialog->setAutomaticMode( on );
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
252 bool SelfTestCommand::isCanceled() const {
253 return d->canceled;
256 void SelfTestCommand::doStart() {
258 if ( d->automatic ) {
259 if ( !d->runAtStartUp() ) {
260 d->finished();
261 return;
263 } else {
264 d->ensureDialogCreated();
267 d->runTests();
271 void SelfTestCommand::doCancel() {
272 d->canceled = true;
273 if ( d->dialog )
274 d->dialog->close();
275 d->dialog = 0;
278 #undef d
279 #undef q
281 #include "moc_selftestcommand.cpp"