33 #include <config-kleopatra.h>
45 #ifdef HAVE_USABLE_ASSUAN
69 #include <kleo/checksumdefinition.h>
71 #ifdef KDEPIM_MOBILE_UI
72 # include <kdeclarativeapplication.h>
76 #include <kcmdlineargs.h>
78 #include <kiconloader.h>
79 #include <ksplashscreen.h>
80 #include <kmessagebox.h>
82 #include <QTextDocument>
83 #include <QStringList>
84 #include <QMessageBox>
88 #include <QThreadPool>
90 #include <gpgme++/global.h>
91 #include <gpgme++/error.h>
93 #include <boost/shared_ptr.hpp>
97 using namespace boost;
102 template <
typename T>
112 KIconLoader *
const il = KIconLoader::global();
114 const QString iconPath = il->iconPath( QLatin1String( name ), KIconLoader::User );
115 return iconPath.isEmpty() ? il->unknown() : QPixmap( iconPath ) ;
118 #ifndef QT_NO_SPLASHSCREEN
119 class SplashScreen :
public KSplashScreen {
123 : KSplashScreen(
UserIcon_nocached(
"kleopatra_splashscreen" ), Qt::WindowStaysOnTopHint ),
130 void timerEvent( QTimerEvent * ev ) {
131 if ( ev->timerId() == m_timer.timerId() ) {
135 KSplashScreen::timerEvent( ev );
141 class SplashScreen {};
142 #endif // QT_NO_SPLASHSCREEN
145 #ifndef QT_NO_SPLASHSCREEN
146 splash.showMessage( i18n(
"Performing Self-Check...") );
151 #ifndef QT_NO_SPLASHSCREEN
155 QObject::connect( &cmd, SIGNAL(finished()), &loop, SLOT(quit()) );
156 #ifndef QT_NO_SPLASHSCREEN
157 QObject::connect( &cmd, SIGNAL(info(QString)), &splash, SLOT(showMessage(QString)) );
159 QTimer::singleShot( 0, &cmd, SLOT(start()) );
162 #ifndef QT_NO_SPLASHSCREEN
163 splash.showMessage( i18nc(
"did not pass",
"Self-Check Failed") );
167 #ifndef QT_NO_SPLASHSCREEN
168 splash.showMessage( i18n(
"Self-Check Passed") );
178 QObject::connect( cmd, SIGNAL(finished()), &loop, SLOT(quit()) );
179 #ifdef HAVE_USABLE_ASSUAN
180 QObject::connect( cmd, SIGNAL(finished()), server, SLOT(enableCryptoCommands()) );
184 #ifndef QT_NO_SPLASHSCREEN
185 splash->showMessage( i18n(
"Loading certificate cache...") );
191 #ifndef QT_NO_SPLASHSCREEN
192 splash->showMessage( i18n(
"Certificate cache loaded.") );
196 int main(
int argc,
char** argv )
201 const GpgME::Error gpgmeInitError = GpgME::initializeLibrary(0);
204 const unsigned int threads = QThreadPool::globalInstance()->maxThreadCount();
205 QThreadPool::globalInstance()->setMaxThreadCount( qMax( 2U, threads ) );
210 KCmdLineArgs::init(argc, argv, &aboutData);
212 #ifdef KDEPIM_MOBILE_UI
218 kDebug() <<
"Statup timing:" << timer.elapsed() <<
"ms elapsed: Command line args created";
221 #ifdef KDEPIM_MOBILE_UI
222 KDeclarativeApplicationBase::postApplicationSetup();
225 kDebug() <<
"Startup timing:" << timer.elapsed() <<
"ms elapsed: Application created";
227 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
229 if ( gpgmeInitError ) {
230 KMessageBox::sorry( 0, i18nc(
"@info",
231 "<para>The version of the <application>GpgME</application> library you are running against "
232 "is older than the one that the <application>GpgME++</application> library was built against.</para>"
233 "<para><application>Kleopatra</application> will not function in this setting.</para>"
234 "<para>Please ask your administrator for help in resolving this issue.</para>"),
235 i18nc(
"@title",
"GpgME Too Old") );
242 Kleo::ChecksumDefinition::setInstallPath( installPath );
246 #ifdef HAVE_USABLE_ASSUAN
250 kDebug() <<
"Startup timing:" << timer.elapsed() <<
"ms elapsed: UiServer created";
252 QObject::connect( &server, SIGNAL(startKeyManagerRequested()),
253 &app, SLOT(openOrRaiseMainWindow()) );
255 QObject::connect( &server, SIGNAL(startConfigDialogRequested()),
256 &app, SLOT(openOrRaiseConfigDialog()) );
258 #define REGISTER( Command ) server.registerCommandFactory( boost::shared_ptr<Kleo::AssuanCommandFactory>( new Kleo::GenericAssuanCommandFactory<Kleo::Command> ) )
259 REGISTER( CreateChecksumsCommand );
260 REGISTER( DecryptCommand );
261 REGISTER( DecryptFilesCommand );
262 REGISTER( DecryptVerifyFilesCommand );
263 REGISTER( EchoCommand );
264 REGISTER( EncryptCommand );
265 REGISTER( EncryptFilesCommand );
266 REGISTER( EncryptSignFilesCommand );
267 REGISTER( ImportFilesCommand );
268 REGISTER( PrepEncryptCommand );
269 REGISTER( PrepSignCommand );
270 REGISTER( SelectCertificateCommand );
271 REGISTER( SignCommand );
272 REGISTER( SignEncryptFilesCommand );
273 REGISTER( SignFilesCommand );
274 #ifndef QT_NO_DIRMODEL
275 REGISTER( VerifyChecksumsCommand );
276 #endif // QT_NO_DIRMODEL
277 REGISTER( VerifyCommand );
278 REGISTER( VerifyFilesCommand );
282 kDebug() <<
"Startup timing:" << timer.elapsed() <<
"ms elapsed: UiServer started";
285 const bool daemon = args->isSet(
"daemon");
286 if ( !daemon && app.isSessionRestored() ) {
290 #ifndef QT_NO_SPLASHSCREEN
292 if ( !( daemon || app.isSessionRestored() ) )
297 kDebug() <<
"Startup timing:" << timer.elapsed() <<
"ms elapsed: SelfCheck completed";
299 #ifdef HAVE_USABLE_ASSUAN
304 kDebug() <<
"Startup timing:" << timer.elapsed() <<
"ms elapsed: KeyCache loaded";
306 #ifndef QT_NO_SYSTEMTRAYICON
315 kDebug() <<
"Startup timing:" << timer.elapsed() <<
"ms elapsed: new instance created";
316 #ifndef QT_NO_SPLASHSCREEN
318 #endif // QT_NO_SPLASHSCREEN
323 #ifdef HAVE_USABLE_ASSUAN
325 QObject::disconnect( &server, SIGNAL(startKeyManagerRequested()),
326 &app, SLOT(openOrRaiseMainWindow()) );
327 QObject::disconnect( &server, SIGNAL(startConfigDialogRequested()),
328 &app, SLOT(openOrRaiseConfigDialog()) );
331 server.waitForStopped();
332 }
catch (
const std::exception & e ) {
333 QMessageBox::information( 0, i18n(
"GPG UI Server Error"),
334 i18n(
"<qt>The Kleopatra GPG UI Server Module could not be initialized.<br/>"
335 "The error given was: <b>%1</b><br/>"
336 "You can use Kleopatra as a certificate manager, but cryptographic plugins that "
337 "rely on a GPG UI Server being present might not work correctly, or at all.</qt>",
338 Qt::escape( QString::fromUtf8( e.what() ) ) ));
339 #ifndef QT_NO_SYSTEMTRAYICON
static QPixmap UserIcon_nocached(const char *name)
int main(int argc, char **argv)
void setAutoDelete(bool on)
void setAutomaticMode(bool automatic)
void setIgnoreNewInstance(bool on)
static void fillKeyCache(SplashScreen *splash, Kleo::UiServer *server)
static const int SPLASHSCREEN_TIMEOUT
const MainWindow * mainWindow() const
void setSplashScreen(KSplashScreen *splash)
static KCmdLineOptions commandLineOptions()
void startMonitoringSmartCard()
void setFirstNewInstance(bool on)
static bool selfCheck(SplashScreen &splash)
QString gpg4winInstallPath()
static void setInstallPath(const QString &ip)