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
33 #include <config-kleopatra.h>
35 #include "selftestcommand.h"
37 #include "command_p.h"
39 #include <dialogs/selftestdialog.h>
42 # include <selftest/registrycheck.h>
44 #include <selftest/enginecheck.h>
45 #include <selftest/gpgconfcheck.h>
46 #ifdef HAVE_KLEOPATRACLIENT_LIBRARY
47 # include <selftest/uiservercheck.h>
49 #include <selftest/gpgagentcheck.h>
50 #include <selftest/libkleopatrarccheck.h>
52 #include <kleo/stl_util.h>
56 #include <KConfigGroup>
57 #include <KSplashScreen>
59 #include <boost/shared_ptr.hpp>
60 #include <boost/mem_fn.hpp>
65 using namespace Kleo::Commands
;
66 using namespace Kleo::Dialogs
;
67 using namespace boost
;
69 static const char * const components
[] = {
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
); }
83 explicit Private( SelfTestCommand
* qq
, KeyListController
* c
);
89 void ensureDialogCreated() {
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() )
113 #ifndef QT_NO_SPLASHSCREEN
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
);
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() );
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() );
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
] ) );
148 #if defined( HAVE_KLEOPATRACLIENT_LIBRARY ) && !defined ( Q_OS_WINCE )
149 //emit q->info( i18n("Checking Ui Server connectivity...") );
150 tests
.push_back( makeUiServerConnectivitySelfTest() );
153 tests
.push_back( makeGpgAgentConnectivitySelfTest() );
156 tests
.push_back( makeLibKleopatraRcSelfTest() );
159 if ( !dialog
&& kdtools::none_of( tests
, mem_fn( &Kleo::SelfTest::failed
) ) ) {
164 ensureDialogCreated();
167 dialog
->addSelfTests( tests
);
173 void slotDialogAccepted() {
174 setRunAtStartUp( dialog
->runAtStartUp() );
177 void slotDialogRejected() {
180 Command::Private::canceled();
182 slotDialogAccepted();
185 void slotUpdateRequested() {
190 #ifndef QT_NO_SPLASHSCREEN
191 QPointer
<KSplashScreen
> splash
;
192 #endif // QT_NO_SPLASHSCREEN
193 QPointer
<SelfTestDialog
> dialog
;
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() ); }
204 SelfTestCommand::Private::Private( SelfTestCommand
* qq
, KeyListController
* c
)
205 : Command::Private( qq
, c
),
206 #ifndef QT_NO_SPLASHSCREEN
208 #endif // QT_NO_SPLASHSCREEN
216 SelfTestCommand::Private::~Private() {
220 SelfTestCommand::SelfTestCommand( KeyListController
* c
)
221 : Command( new Private( this, c
) )
226 SelfTestCommand::SelfTestCommand( QAbstractItemView
* v
, KeyListController
* c
)
227 : Command( v
, new Private( this, c
) )
232 void SelfTestCommand::Private::init() {
236 SelfTestCommand::~SelfTestCommand() {}
238 void SelfTestCommand::setAutomaticMode( bool on
) {
241 d
->dialog
->setAutomaticMode( on
);
244 void SelfTestCommand::setSplashScreen( KSplashScreen
* splash
) {
245 #ifndef QT_NO_SPLASHSCREEN
249 #endif // QT_NO_SPLASHSCREEN
252 bool SelfTestCommand::isCanceled() const {
256 void SelfTestCommand::doStart() {
258 if ( d
->automatic
) {
259 if ( !d
->runAtStartUp() ) {
264 d
->ensureDialogCreated();
271 void SelfTestCommand::doCancel() {
281 #include "moc_selftestcommand.cpp"