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.
8 * @see The GNU Public License (GPL) Version 3
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
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"
33 #include <QFileOpenEvent>
35 namespace SharedTools
{
36 void QtSingleApplication::sysInit(const QString
&appId
)
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
)
51 QtSingleApplication::QtSingleApplication(const QString
&appId
, int &argc
, char * *argv
)
52 : QApplication(argc
, argv
)
58 QtSingleApplication::QtSingleApplication(Display
*dpy
, Qt::HANDLE visual
, Qt::HANDLE colormap
)
59 : QApplication(dpy
, visual
, colormap
)
64 QtSingleApplication::QtSingleApplication(Display
*dpy
, int &argc
, char * *argv
, Qt::HANDLE visual
, Qt::HANDLE cmap
)
65 : QApplication(dpy
, argc
, argv
, visual
, cmap
)
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
)
78 bool QtSingleApplication::event(QEvent
*event
)
80 if (event
->type() == QEvent::FileOpen
) {
81 QFileOpenEvent
*foe
= static_cast<QFileOpenEvent
*>(event
);
82 emit
fileOpenRequest(foe
->file());
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
)
109 if (activateOnMessage
) {
110 connect(peer
, SIGNAL(messageReceived(QString
)), this, SLOT(activateWindow()));
112 disconnect(peer
, SIGNAL(messageReceived(QString
)), this, SLOT(activateWindow()));
117 QWidget
*QtSingleApplication::activationWindow() const
123 void QtSingleApplication::activateWindow()
126 actWin
->setWindowState(actWin
->windowState() & ~Qt::WindowMinimized
);
128 actWin
->activateWindow();
131 } // namespace SharedTools