LP-106 Setup Wizard refresh : Add dual servo setup (dual aileron or
[librepilot.git] / ground / gcs / src / shared / qtsingleapplication / qtsingleapplication.cpp
blob8545260668cde4bd432943d9b0be1232273bf5cc
1 /**
2 ******************************************************************************
4 * @file qtsingleapplication.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * Parts by Nokia Corporation (qt-info@nokia.com) Copyright (C) 2009.
7 * @brief
8 * @see The GNU Public License (GPL) Version 3
9 * @defgroup
10 * @{
12 *****************************************************************************/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "qtsingleapplication.h"
30 #include "qtlocalpeer.h"
32 #include <QWidget>
33 #include <QFileOpenEvent>
35 namespace SharedTools {
36 void QtSingleApplication::sysInit(const QString &appId)
38 actWin = 0;
39 peer = new QtLocalPeer(this, appId);
40 connect(peer, SIGNAL(messageReceived(const QString &)), SIGNAL(messageReceived(const QString &)));
44 QtSingleApplication::QtSingleApplication(int &argc, char * *argv, bool GUIenabled)
45 : QApplication(argc, argv, GUIenabled)
47 sysInit();
51 QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char * *argv)
52 : QApplication(argc, argv)
54 sysInit(appId);
57 #if defined(Q_WS_X11)
58 QtSingleApplication::QtSingleApplication(Display *dpy, Qt::HANDLE visual, Qt::HANDLE colormap)
59 : QApplication(dpy, visual, colormap)
61 sysInit();
64 QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char * *argv, Qt::HANDLE visual, Qt::HANDLE cmap)
65 : QApplication(dpy, argc, argv, visual, cmap)
67 sysInit();
70 QtSingleApplication::QtSingleApplication(Display *dpy, const QString &appId,
71 int argc, char * *argv, Qt::HANDLE visual, Qt::HANDLE colormap)
72 : QApplication(dpy, argc, argv, visual, colormap)
74 sysInit(appId);
76 #endif
78 bool QtSingleApplication::event(QEvent *event)
80 if (event->type() == QEvent::FileOpen) {
81 QFileOpenEvent *foe = static_cast<QFileOpenEvent *>(event);
82 emit fileOpenRequest(foe->file());
83 return true;
85 return QApplication::event(event);
88 bool QtSingleApplication::isRunning()
90 return peer->isClient();
94 bool QtSingleApplication::sendMessage(const QString &message, int timeout)
96 return peer->sendMessage(message, timeout);
100 QString QtSingleApplication::id() const
102 return peer->applicationId();
106 void QtSingleApplication::setActivationWindow(QWidget *aw, bool activateOnMessage)
108 actWin = aw;
109 if (activateOnMessage) {
110 connect(peer, SIGNAL(messageReceived(QString)), this, SLOT(activateWindow()));
111 } else {
112 disconnect(peer, SIGNAL(messageReceived(QString)), this, SLOT(activateWindow()));
117 QWidget *QtSingleApplication::activationWindow() const
119 return actWin;
123 void QtSingleApplication::activateWindow()
125 if (actWin) {
126 actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
127 actWin->raise();
128 actWin->activateWindow();
131 } // namespace SharedTools