forked from lxqt/liblxqt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lxqtsingleapplication.h
158 lines (142 loc) · 4.63 KB
/
lxqtsingleapplication.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* LXQt - a lightweight, Qt based, desktop toolset
* https://lxqt.org
*
* Copyright: 2014 LXQt team
* Authors:
* Luís Pereira <[email protected]>
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#ifndef LXQTSINGLEAPPLICATION_H
#define LXQTSINGLEAPPLICATION_H
#include "lxqtapplication.h"
class QWidget;
namespace LXQt {
/*! \class SingleApplication
* \brief The SingleApplication class provides an single instance Application.
*
* This class allows the user to create applications where only one instance
* is allowed to be running at an given time. If the user tries to launch
* another instance, the already running instance will be activated instead.
*
* The user has to set the activation window with setActivationWindow. If it
* doesn't the second instance will quietly exit without activating the first
* instance window. In any case only one instance is allowed.
*
* These classes depend on D-Bus and KF5::WindowSystem
*
* \code
*
* // Original code
* int main(int argc, char **argv)
* {
* LXQt::Application app(argc, argv);
*
* MainWidget w;
* w.show();
*
* return app.exec();
* }
*
* // Using the library
* int main(int argc, char **argv)
* {
* LXQt::SingleApplication app(argc, argv);
*
* MainWidget w;
* app.setActivationWindow(&w);
* w.show();
*
* return app.exec();
* }
* \endcode
* \sa SingleApplication
*/
class LXQT_API SingleApplication : public Application {
Q_OBJECT
public:
/*!
* \brief Options to control the D-Bus failure related application behaviour
*
* By default (ExitOnDBusFailure) if an instance can't connect to the D-Bus
* session bus, that instance calls ::exit(1). Not even the first instance
* will run. Connecting to the D-Bus session bus is an condition to
* guarantee that only one instance will run.
*
* If an user wants to allow an application to run without D-Bus, it must
* use the NoExitOnDBusFailure option.
*
* ExitOnDBusFailure is the default.
*/
enum StartOptions {
/** Exit if the connection to the D-Bus session bus fails.
* It's the default
*/
ExitOnDBusFailure,
/** Don't exit if the connection to the D-Bus session bus fails.*/
NoExitOnDBusFailure
};
Q_ENUM(StartOptions)
/*!
* \brief Construct a LXQt SingleApplication object.
* \param argc standard argc as in QApplication
* \param argv standard argv as in QApplication
* \param options Control the on D-Bus failure application behaviour
*
* \sa StartOptions.
*/
SingleApplication(int &argc, char **argv, StartOptions options = ExitOnDBusFailure);
~SingleApplication() override;
/*!
* \brief Sets the activation window.
* \param w activation window.
*
* Sets the activation window of this application to w. The activation
* window is the widget that will be activated by \a activateWindow().
*
* \sa activationWindow() \sa activateWindow();
*/
void setActivationWindow(QWidget *w);
/*!
* \brief Gets the current activation window.
* \return The current activation window.
*
* \sa setActivationWindow();
*/
QWidget *activationWindow() const;
public Q_SLOTS:
/*!
* \brief Activates this application activation window.
*
* Changes to the desktop where this applications is. It then de-minimizes,
* raises and activates the application's activation window.
* If no activation window has been set, this function does nothing.
*
* \sa setActivationWindow();
*/
void activateWindow();
private:
QWidget *mActivationWindow;
};
#if defined(lxqtSingleApp)
#undef lxqtSingleApp
#endif
#define lxqtSingleApp (static_cast<LXQt::SingleApplication *>(qApp))
} // namespace LXQt
#endif // LXQTSINGLEAPPLICATION_H