Falkon Develop
Cross-platform Qt-based web browser
qtsingleapplication.cpp
Go to the documentation of this file.
1/****************************************************************************
2**
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the Qt Solutions component.
7**
8** $QT_BEGIN_LICENSE:BSD$
9** You may use this file under the terms of the BSD license as follows:
10**
11** "Redistribution and use in source and binary forms, with or without
12** modification, are permitted provided that the following conditions are
13** met:
14** * Redistributions of source code must retain the above copyright
15** notice, this list of conditions and the following disclaimer.
16** * Redistributions in binary form must reproduce the above copyright
17** notice, this list of conditions and the following disclaimer in
18** the documentation and/or other materials provided with the
19** distribution.
20** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21** of its contributors may be used to endorse or promote products derived
22** from this software without specific prior written permission.
23**
24**
25** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41
42#include "qtsingleapplication.h"
43#include "qtlocalpeer.h"
44#include <QWidget>
45
46
136void QtSingleApplication::sysInit(const QString &appId)
137{
138 actWin = nullptr;
139 peer = new QtLocalPeer(this, appId);
141}
142
143
154QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled)
155 : QApplication(argc, argv, GUIenabled)
156{
157 sysInit();
158}
159
160
167QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
168 : QApplication(argc, argv)
169{
170 sysInit(appId);
171}
172
173#if QT_VERSION < 0x050000
174
180QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type)
181 : QApplication(argc, argv, type)
182{
183}
184
185
186# if defined(Q_WS_X11)
193QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE cmap)
194 : QApplication(dpy, visual, cmap)
195{
196 sysInit();
197}
198
206QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
207 : QApplication(dpy, argc, argv, visual, cmap)
208{
209 sysInit();
210}
211
219QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId, int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
220 : QApplication(dpy, argc, argv, visual, cmap)
221{
222 sysInit(appId);
223}
224# endif // Q_WS_X11
225#endif // QT_VERSION < 0x050000
226
227
240{
241 return peer->isClient();
242}
243
244void QtSingleApplication::setAppId(const QString &id)
245{
246 sysInit(id);
247}
248
249
263bool QtSingleApplication::sendMessage(const QString &message, int timeout)
264{
265 return peer->sendMessage(message, timeout);
266}
267
268
274{
275 return peer->applicationId();
276}
277
278
291void QtSingleApplication::setActivationWindow(QWidget* aw, bool activateOnMessage)
292{
293 actWin = aw;
294 if (activateOnMessage)
296 else
298}
299
300
308{
309 return actWin;
310}
311
313{
314 peer->removeLockedFile();
315}
316
317
333{
334 if (actWin) {
335 actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
336 actWin->raise();
337 actWin->activateWindow();
338 }
339}
340
341
void messageReceived(const QString &message)
bool isClient()
QString applicationId() const
Definition: qtlocalpeer.h:58
bool sendMessage(const QString &message, int timeout)
void removeLockedFile()
bool sendMessage(const QString &message, int timeout=5000)
void setAppId(const QString &id)
void messageReceived(const QString &message)
QWidget * activationWindow() const
void setActivationWindow(QWidget *aw, bool activateOnMessage=true)
QtSingleApplication(int &argc, char **argv, bool GUIenabled=true)