1 /* This file is part of the KDE project
2 
3    SPDX-FileCopyrightText: 2008 David Faure <faure@kde.org>
4 
5    SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 */
7 #pragma once
8 
9 #include "kontactinterface_export.h"
10 
11 #include <QApplication>
12 #include <memory>
13 
14 class KAboutData;
15 class QCommandLineParser;
16 
17 namespace KontactInterface
18 {
19 /**
20  * KDEPIM applications which can be integrated into kontact should use
21  * PimUniqueApplication instead of QApplication + Dbus unique.
22  * This makes command-line handling work, i.e. you can launch "korganizer"
23  * and if kontact is already running, it will load the korganizer part and
24  * switch to it.
25  */
26 class KONTACTINTERFACE_EXPORT PimUniqueApplication : public QApplication
27 {
28     Q_OBJECT
29     Q_CLASSINFO("D-Bus Interface", "org.kde.PIMUniqueApplication")
30 
31 public:
32     explicit PimUniqueApplication(int &argc, char **argv[]);
33     ~PimUniqueApplication() override;
34 
35     void setAboutData(KAboutData &aboutData);
36 
37     /**
38      * Register this process as a unique application, if not already running.
39      * Typically called in main().
40      * @param arguments should start with the appname, as QCoreApplication::arguments() does.
41      */
42     static bool start(const QStringList &arguments);
43 
44     /**
45      * Ensure that another PIM application is running.
46      */
47     static bool activateApplication(const QString &application, const QStringList &additionalArguments = {});
48 
49     Q_REQUIRED_RESULT QCommandLineParser *cmdArgs() const;
50 
51 public Q_SLOTS:
52     Q_SCRIPTABLE int newInstance();
53     Q_SCRIPTABLE virtual int newInstance(const QByteArray &startupId, const QStringList &arguments, const QString &workingDirectory);
54 
55 protected:
56     virtual int activate(const QStringList &arguments, const QString &workingDirectory);
57 
58 private:
59     //@cond PRIVATE
60     class PimUniqueApplicationPrivate;
61     std::unique_ptr<PimUniqueApplicationPrivate> const d;
62     //@endcond
63 };
64 
65 }
66 
67