1 /* 2 kleopatraapplication.h 3 4 This file is part of Kleopatra, the KDE keymanager 5 SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB 6 7 SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik 8 SPDX-FileContributor: Intevation GmbH 9 10 SPDX-License-Identifier: GPL-2.0-or-later 11 */ 12 13 #pragma once 14 15 #include <QApplication> 16 #include <QCommandLineParser> 17 18 #include <utils/pimpl_ptr.h> 19 20 #include <gpgme++/global.h> 21 22 class MainWindow; 23 class SysTrayIcon; 24 25 class KleopatraApplication : public QApplication 26 { 27 Q_OBJECT 28 public: 29 /** Create a new Application object. You have to 30 * make sure to call init afterwards to get a valid object. 31 * This is to delay initialisation after the UniqueService 32 * call is done and our init / call might be forwarded to 33 * another instance. */ 34 KleopatraApplication(int &argc, char *argv[]); 35 ~KleopatraApplication() override; 36 37 /** Initialize the application. Without calling init any 38 * other call to KleopatraApplication will result in undefined behavior 39 * and likely crash. */ 40 void init(); 41 instance()42 static KleopatraApplication *instance() 43 { 44 return qobject_cast<KleopatraApplication *>(qApp); 45 } 46 47 /** Starts a new instance or a command from the command line. 48 * 49 * Handles the parser options and starts the according commands. 50 * If ignoreNewInstance is set this function does nothing. 51 * The parser should have been initialized with kleopatra_options and 52 * already processed. 53 * If kleopatra is not session restored 54 * 55 * @param parser: The command line parser to use. 56 * @param workingDirectory: Optional working directory for file arguments. 57 * 58 * @returns an empty QString on success. A localized error message otherwise. 59 * */ 60 QString newInstance(const QCommandLineParser &parser, 61 const QString &workingDirectory = QString()); 62 63 void setMainWindow(MainWindow *mw); 64 65 const MainWindow *mainWindow() const; 66 MainWindow *mainWindow(); 67 68 const SysTrayIcon *sysTrayIcon() const; 69 SysTrayIcon *sysTrayIcon(); 70 71 void setIgnoreNewInstance(bool on); 72 bool ignoreNewInstance() const; 73 void toggleMainWindowVisibility(); 74 void restoreMainWindow(); 75 void openConfigDialogWithForeignParent(WId parentWId); 76 77 public Q_SLOTS: 78 void openOrRaiseMainWindow(); 79 void openOrRaiseConfigDialog(); 80 #ifndef QT_NO_SYSTEMTRAYICON 81 void startMonitoringSmartCard(); 82 void importCertificatesFromFile(const QStringList &files, GpgME::Protocol proto); 83 #endif 84 void encryptFiles(const QStringList &files, GpgME::Protocol proto); 85 void signFiles(const QStringList &files, GpgME::Protocol proto); 86 void signEncryptFiles(const QStringList &files, GpgME::Protocol proto); 87 void decryptFiles(const QStringList &files, GpgME::Protocol proto); 88 void verifyFiles(const QStringList &files, GpgME::Protocol proto); 89 void decryptVerifyFiles(const QStringList &files, GpgME::Protocol proto); 90 void checksumFiles(const QStringList &files, GpgME::Protocol /* unused */); 91 void slotActivateRequested(const QStringList &arguments, const QString &workingDirectory); 92 93 Q_SIGNALS: 94 /* Emitted from slotActivateRequested to enable setting the 95 * correct exitValue */ 96 void setExitValue(int value); 97 98 void configurationChanged(); 99 100 private: 101 class Private; 102 kdtools::pimpl_ptr<Private> d; 103 }; 104 105