| 1 | // For license of this file, see <project-root-folder>/LICENSE.md. |
| 2 | |
| 3 | #ifndef SINGLEAPPLICATION_H |
| 4 | #define SINGLEAPPLICATION_H |
| 5 | |
| 6 | #include <QApplication> |
| 7 | |
| 8 | class QLocalServer; |
| 9 | |
| 10 | class SingleApplication : public QApplication { |
| 11 | Q_OBJECT |
| 12 | |
| 13 | public: |
| 14 | explicit SingleApplication(const QString& id, int& argc, char** argv); |
| 15 | virtual ~SingleApplication(); |
| 16 | |
| 17 | void finish(); |
| 18 | |
| 19 | bool isOtherInstanceRunning(const QString& message = {}); |
| 20 | bool sendMessage(const QString& message); |
| 21 | |
| 22 | signals: |
| 23 | void messageReceived(const QString& message); |
| 24 | |
| 25 | private slots: |
| 26 | void processMessageFromOtherInstance(); |
| 27 | |
| 28 | private: |
| 29 | QString m_id; |
| 30 | QLocalServer* m_server; |
| 31 | }; |
| 32 | |
| 33 | #endif // SINGLEAPPLICATION_H |