• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

kleopatra

selftestcommand.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset:4 -*-
00002     commands/selftestcommand.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2008 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
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, // gpgconf
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         //emit q->info( i18n("Checking Windows Registry...") );
00129         tests.push_back( makeGpgProgramRegistryCheckSelfTest() );
00130 #endif
00131         //emit q->info( i18n("Checking gpg installation...") );
00132         tests.push_back( makeGpgEngineCheckSelfTest() );
00133         //emit q->info( i18n("Checking gpgsm installation...") );
00134         tests.push_back( makeGpgSmEngineCheckSelfTest() );
00135         //emit q->info( i18n("Checking gpgconf installation...") );
00136         tests.push_back( makeGpgConfEngineCheckSelfTest() );
00137         for ( unsigned int i = 0 ; i < numComponents ; ++i ) {
00138             //emit q->info( i18n("Checking %1 configuration...", components[i]) );
00139             tests.push_back( makeGpgConfCheckConfigurationSelfTest( components[i] ) );
00140         }
00141 #ifdef HAVE_KLEOPATRACLIENT_LIBRARY
00142         //emit q->info( i18n("Checking Ui Server connectivity...") );
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"

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal