File indexing completed on 2024-06-23 05:14:17
0001 #pragma once 0002 /* 0003 kuniqueservice.h 0004 0005 This file is part of Kleopatra, the KDE keymanager 0006 SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik 0007 SPDX-FileContributor: Intevation GmbH 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 #include <QObject> 0012 #include <QString> 0013 #include <QStringList> 0014 0015 /** 0016 * This class can be used to create a unique service and redirect calls 0017 * to this service similarly to KDBusService(KDBusService::Unique). 0018 * @code 0019 * YourApplication app(argc, argv); 0020 * 0021 * KUniqueService service; 0022 * QObject::connect(&service, &KUniqueService::activateRequested, 0023 * &app, &YourApplication::slotActivateRequested); 0024 * QObject::connect(&app, &YourApplication::setExitValue, 0025 * &service, [&service](int i) { 0026 * service.setExitValue(i); 0027 * }); 0028 * @endcode 0029 * This will redirect calls to running instances over the 0030 * the slotActivateRequested. When you set the exit 0031 * value the calling process will afterwards exit with the 0032 * code provided. 0033 * If you do not set the exit value the application will not 0034 * be terminated. 0035 * @author Andre Heinecke (aheinecke@intevation.org) 0036 */ 0037 class KUniqueService : public QObject 0038 { 0039 Q_OBJECT 0040 public: 0041 /** 0042 * Default constructor 0043 */ 0044 KUniqueService(); 0045 ~KUniqueService() override; 0046 0047 public Q_SLOTS: 0048 /** 0049 * Set the exit @p code the second app should use to terminate. 0050 * If unset it exits with 0. 0051 * @param code The exit code. 0052 */ 0053 void setExitValue(int code); 0054 0055 Q_SIGNALS: 0056 void activateRequested(const QStringList &arguments, const QString &workingDirectory); 0057 0058 private: 0059 void emitActivateRequested(const QStringList &arguments, const QString &workingDirectory) 0060 { 0061 Q_EMIT activateRequested(arguments, workingDirectory); 0062 } 0063 class KUniqueServicePrivate; 0064 Q_DECLARE_PRIVATE(KUniqueService) 0065 KUniqueServicePrivate *d_ptr; 0066 };