File indexing completed on 2024-05-12 05:20:01
0001 /* 0002 kleopatraapplication.h 0003 0004 This file is part of Kleopatra, the KDE keymanager 0005 SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB 0006 0007 SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik 0008 SPDX-FileContributor: Intevation GmbH 0009 0010 SPDX-License-Identifier: GPL-2.0-or-later 0011 */ 0012 0013 #pragma once 0014 0015 #include <QApplication> 0016 #include <QCommandLineParser> 0017 #include <QElapsedTimer> 0018 0019 #include <utils/pimpl_ptr.h> 0020 0021 #include <gpgme++/global.h> 0022 0023 extern QElapsedTimer startupTimer; 0024 #define STARTUP_TIMING qCDebug(KLEOPATRA_LOG) << "Startup timing:" << startupTimer.elapsed() << "ms:" 0025 #define STARTUP_TRACE qCDebug(KLEOPATRA_LOG) << "Startup timing:" << startupTimer.elapsed() << "ms:" << SRCNAME << __func__ << __LINE__; 0026 0027 class MainWindow; 0028 class SysTrayIcon; 0029 class QSettings; 0030 0031 class KleopatraApplication : public QApplication 0032 { 0033 Q_OBJECT 0034 public: 0035 /** Create a new Application object. You have to 0036 * make sure to call init afterwards to get a valid object. 0037 * This is to delay initialisation after the UniqueService 0038 * call is done and our init / call might be forwarded to 0039 * another instance. */ 0040 KleopatraApplication(int &argc, char *argv[]); 0041 ~KleopatraApplication() override; 0042 0043 /** Initialize the application. Without calling init any 0044 * other call to KleopatraApplication will result in undefined behavior 0045 * and likely crash. */ 0046 void init(); 0047 0048 static KleopatraApplication *instance() 0049 { 0050 return qobject_cast<KleopatraApplication *>(qApp); 0051 } 0052 0053 /** Starts a new instance or a command from the command line. 0054 * 0055 * Handles the parser options and starts the according commands. 0056 * If ignoreNewInstance is set this function does nothing. 0057 * The parser should have been initialized with kleopatra_options and 0058 * already processed. 0059 * If kleopatra is not session restored 0060 * 0061 * @param parser: The command line parser to use. 0062 * @param workingDirectory: Optional working directory for file arguments. 0063 * 0064 * @returns an empty QString on success. A localized error message otherwise. 0065 * */ 0066 QString newInstance(const QCommandLineParser &parser, const QString &workingDirectory = QString()); 0067 0068 void setMainWindow(MainWindow *mw); 0069 0070 const MainWindow *mainWindow() const; 0071 MainWindow *mainWindow(); 0072 0073 const SysTrayIcon *sysTrayIcon() const; 0074 SysTrayIcon *sysTrayIcon(); 0075 0076 void setIgnoreNewInstance(bool on); 0077 bool ignoreNewInstance() const; 0078 void toggleMainWindowVisibility(); 0079 void restoreMainWindow(); 0080 void openConfigDialogWithForeignParent(WId parentWId); 0081 0082 /* Add optional signed settings for specialized distributions */ 0083 void setDistributionSettings(const std::shared_ptr<QSettings> &settings); 0084 std::shared_ptr<QSettings> distributionSettings() const; 0085 0086 public Q_SLOTS: 0087 void openOrRaiseMainWindow(); 0088 void openOrRaiseConfigDialog(); 0089 void openOrRaiseGroupsConfigDialog(QWidget *parent); 0090 #ifndef QT_NO_SYSTEMTRAYICON 0091 void startMonitoringSmartCard(); 0092 void importCertificatesFromFile(const QStringList &files, GpgME::Protocol proto); 0093 #endif 0094 void encryptFiles(const QStringList &files, GpgME::Protocol proto); 0095 void signFiles(const QStringList &files, GpgME::Protocol proto); 0096 void signEncryptFiles(const QStringList &files, GpgME::Protocol proto); 0097 void decryptFiles(const QStringList &files, GpgME::Protocol proto); 0098 void verifyFiles(const QStringList &files, GpgME::Protocol proto); 0099 void decryptVerifyFiles(const QStringList &files, GpgME::Protocol proto); 0100 void checksumFiles(const QStringList &files, GpgME::Protocol /* unused */); 0101 void slotActivateRequested(const QStringList &arguments, const QString &workingDirectory); 0102 0103 void handleFiles(const QStringList &files, WId parentId = 0); 0104 0105 Q_SIGNALS: 0106 /* Emitted from slotActivateRequested to enable setting the 0107 * correct exitValue */ 0108 void setExitValue(int value); 0109 0110 void configurationChanged(); 0111 0112 private Q_SLOTS: 0113 // used as URL handler for URLs with schemes that shall be blocked 0114 void blockUrl(const QUrl &url); 0115 void startGpgAgent(); 0116 0117 private: 0118 class Private; 0119 kdtools::pimpl_ptr<Private> d; 0120 };