kleopatra
selftestcommand.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <config-kleopatra.h>
00034
00035 #include "selftestcommand.h"
00036
00037 #include "command_p.h"
00038
00039 #include <dialogs/selftestdialog.h>
00040
00041 #ifdef Q_OS_WIN
00042 # include <selftest/registrycheck.h>
00043 #endif
00044 #include <selftest/enginecheck.h>
00045 #include <selftest/gpgconfcheck.h>
00046 #ifdef HAVE_KLEOPATRACLIENT_LIBRARY
00047 # include <selftest/uiservercheck.h>
00048 #endif
00049
00050 #include <utils/stl_util.h>
00051
00052 #include <KLocale>
00053 #include <KGlobal>
00054 #include <KConfigGroup>
00055 #include <KSplashScreen>
00056
00057 #include <boost/shared_ptr.hpp>
00058 #include <boost/mem_fn.hpp>
00059
00060 #include <vector>
00061
00062 using namespace Kleo;
00063 using namespace Kleo::Commands;
00064 using namespace Kleo::Dialogs;
00065 using namespace boost;
00066
00067 static const char * const components[] = {
00068 0,
00069 "gpg",
00070 "gpg-agent",
00071 "scdaemon",
00072 "gpgsm",
00073 "dirmngr",
00074 };
00075 static const unsigned int numComponents = sizeof components / sizeof *components;
00076
00077 class SelfTestCommand::Private : Command::Private {
00078 friend class ::Kleo::Commands::SelfTestCommand;
00079 SelfTestCommand * q_func() const { return static_cast<SelfTestCommand*>( q ); }
00080 public:
00081 explicit Private( SelfTestCommand * qq, KeyListController * c );
00082 ~Private();
00083
00084 private:
00085 void init();
00086
00087 void ensureDialogCreated() {
00088 if ( dialog )
00089 return;
00090 dialog = new SelfTestDialog( parentWidgetOrView() );
00091 dialog->setAttribute( Qt::WA_DeleteOnClose );
00092
00093 connect( dialog, SIGNAL(updateRequested()),
00094 q, SLOT(slotUpdateRequested()) );
00095 connect( dialog, SIGNAL(accepted()),
00096 q, SLOT(slotDialogAccepted()) );
00097 connect( dialog, SIGNAL(rejected()),
00098 q, SLOT(slotDialogRejected()) );
00099
00100 dialog->setRunAtStartUp( runAtStartUp() );
00101 dialog->setAutomaticMode( automatic );
00102 }
00103
00104 void ensureDialogShown() {
00105 ensureDialogCreated();
00106 if ( dialog->isVisible() )
00107 dialog->raise();
00108 else
00109 dialog->show();
00110 if ( splash )
00111 splash->finish( dialog );
00112 }
00113
00114 bool runAtStartUp() const {
00115 const KConfigGroup config( KGlobal::config(), "Self-Test" );
00116 return config.readEntry( "run-at-startup", true );
00117 }
00118
00119 void setRunAtStartUp( bool on ) {
00120 KConfigGroup config( KGlobal::config(), "Self-Test" );
00121 config.writeEntry( "run-at-startup", on );
00122 }
00123
00124 void runTests() {
00125 std::vector< shared_ptr<Kleo::SelfTest> > tests;
00126
00127 #ifdef Q_OS_WIN
00128
00129 tests.push_back( makeGpgProgramRegistryCheckSelfTest() );
00130 #endif
00131
00132 tests.push_back( makeGpgEngineCheckSelfTest() );
00133
00134 tests.push_back( makeGpgSmEngineCheckSelfTest() );
00135
00136 tests.push_back( makeGpgConfEngineCheckSelfTest() );
00137 for ( unsigned int i = 0 ; i < numComponents ; ++i ) {
00138
00139 tests.push_back( makeGpgConfCheckConfigurationSelfTest( components[i] ) );
00140 }
00141 #ifdef HAVE_KLEOPATRACLIENT_LIBRARY
00142
00143 tests.push_back( makeUiServerConnectivitySelfTest() );
00144 #endif
00145
00146 if ( !dialog && kdtools::none_of( tests, mem_fn( &Kleo::SelfTest::failed ) ) ) {
00147 finished();
00148 return;
00149 }
00150
00151 ensureDialogCreated();
00152
00153 dialog->clear();
00154 dialog->addSelfTests( tests );
00155
00156 ensureDialogShown();
00157 }
00158
00159 private:
00160 void slotDialogAccepted() {
00161 setRunAtStartUp( dialog->runAtStartUp() );
00162 finished();
00163 }
00164 void slotDialogRejected() {
00165 if ( automatic ) {
00166 canceled = true;
00167 Command::Private::canceled();
00168 } else {
00169 slotDialogAccepted();
00170 }
00171 }
00172 void slotUpdateRequested() {
00173 runTests();
00174 }
00175
00176 private:
00177 QPointer<KSplashScreen> splash;
00178 QPointer<SelfTestDialog> dialog;
00179 bool canceled;
00180 bool automatic;
00181 };
00182
00183 SelfTestCommand::Private * SelfTestCommand::d_func() { return static_cast<Private*>( d.get() ); }
00184 const SelfTestCommand::Private * SelfTestCommand::d_func() const { return static_cast<const Private*>( d.get() ); }
00185
00186 #define d d_func()
00187 #define q q_func()
00188
00189 SelfTestCommand::Private::Private( SelfTestCommand * qq, KeyListController * c )
00190 : Command::Private( qq, c ),
00191 splash(),
00192 dialog(),
00193 canceled( false ),
00194 automatic( false )
00195 {
00196
00197 }
00198
00199 SelfTestCommand::Private::~Private() {
00200
00201 }
00202
00203 SelfTestCommand::SelfTestCommand( KeyListController * c )
00204 : Command( new Private( this, c ) )
00205 {
00206 d->init();
00207 }
00208
00209 SelfTestCommand::SelfTestCommand( QAbstractItemView * v, KeyListController * c )
00210 : Command( v, new Private( this, c ) )
00211 {
00212 d->init();
00213 }
00214
00215 void SelfTestCommand::Private::init() {
00216
00217 }
00218
00219 SelfTestCommand::~SelfTestCommand() {}
00220
00221 void SelfTestCommand::setAutomaticMode( bool on ) {
00222 d->automatic = on;
00223 if ( d->dialog )
00224 d->dialog->setAutomaticMode( on );
00225 }
00226
00227 void SelfTestCommand::setSplashScreen( KSplashScreen * splash ) {
00228 d->splash = splash;
00229 }
00230
00231 bool SelfTestCommand::isCanceled() const {
00232 return d->canceled;
00233 }
00234
00235 void SelfTestCommand::doStart() {
00236
00237 if ( d->automatic ) {
00238 if ( !d->runAtStartUp() ) {
00239 d->finished();
00240 return;
00241 }
00242 } else {
00243 d->ensureDialogCreated();
00244 }
00245
00246 d->runTests();
00247
00248 }
00249
00250 void SelfTestCommand::doCancel() {
00251 d->canceled = true;
00252 if ( d->dialog )
00253 d->dialog->close();
00254 d->dialog = 0;
00255 }
00256
00257 #undef d
00258 #undef q
00259
00260 #include "moc_selftestcommand.cpp"