1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of Qt Creator.
7**
8** Commercial License Usage
9** Licensees holding valid commercial Qt licenses may use this file in
10** accordance with the commercial license agreement provided with the
11** Software or, alternatively, in accordance with the terms contained in
12** a written agreement between you and Digia. For licensing terms and
13** conditions see http://qt.digia.com/licensing. For further information
14** use the contact form at http://qt.digia.com/contact-us.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Digia gives you certain additional
25** rights. These rights are described in the Digia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28****************************************************************************/
29
30#ifndef QTSINGLEAPPLICATION_H
31#define QTSINGLEAPPLICATION_H
32
33#include <QApplication>
34
35QT_FORWARD_DECLARE_CLASS(QSharedMemory)
36
37namespace SharedTools {
38
39class QtLocalPeer;
40
41class QtSingleApplication : public QApplication
42{
43 Q_OBJECT
44
45public:
46 QtSingleApplication(const QString &id, int &argc, char **argv);
47 ~QtSingleApplication();
48
49 bool isRunning(qint64 pid = -1);
50
51 void setActivationWindow(QWidget* aw, bool activateOnMessage = true);
52 QWidget* activationWindow() const;
53 bool event(QEvent *event) Q_DECL_OVERRIDE;
54
55 QString applicationId() const;
56 void setBlock(bool value);
57
58public Q_SLOTS:
59 bool sendMessage(const QString &message, int timeout = 5000, qint64 pid = -1);
60 void activateWindow();
61
62Q_SIGNALS:
63 void messageReceived(const QString &message, QObject *socket);
64 void fileOpenRequest(const QString &file);
65
66private:
67 QString instancesFileName(const QString &appId);
68
69 qint64 firstPeer;
70 QSharedMemory *instances;
71 QtLocalPeer *pidPeer;
72 QWidget *actWin;
73 QString appId;
74 bool block;
75};
76
77} // namespace SharedTools
78
79#endif // QTSINGLEAPPLICATION_H
80