1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "qtsingleapplication.h"
35 #include "qtlocalpeer.h"
37 #include <QtGui/QWidget>
38 #include <QtGui/QFileOpenEvent>
40 namespace SharedTools {
42 void QtSingleApplication::sysInit(const QString &appId)
45 peer = new QtLocalPeer(this, appId);
46 connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
50 QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled)
51 : QApplication(argc, argv, GUIenabled)
57 QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
58 : QApplication(argc, argv)
64 QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type)
65 : QApplication(argc, argv, type)
72 QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE colormap)
73 : QApplication(dpy, visual, colormap)
78 QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
79 : QApplication(dpy, argc, argv, visual, cmap)
84 QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId,
85 int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE colormap)
86 : QApplication(dpy, argc, argv, visual, colormap)
92 bool QtSingleApplication::event(QEvent *event)
94 if (event->type() == QEvent::FileOpen) {
95 QFileOpenEvent *foe = static_cast<QFileOpenEvent*>(event);
96 emit fileOpenRequest(foe->file());
99 return QApplication::event(event);
102 bool QtSingleApplication::isRunning()
104 return peer->isClient();
107 bool QtSingleApplication::sendMessage(const QString &message, int timeout)
109 return peer->sendMessage(message, timeout);
113 QString QtSingleApplication::id() const
115 return peer->applicationId();
119 void QtSingleApplication::setActivationWindow(QWidget *aw, bool activateOnMessage)
122 if (activateOnMessage)
123 connect(peer, SIGNAL(messageReceived(QString)), this, SLOT(activateWindow()));
125 disconnect(peer, SIGNAL(messageReceived(QString)), this, SLOT(activateWindow()));
129 QWidget* QtSingleApplication::activationWindow() const
135 void QtSingleApplication::activateWindow()
138 actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
140 actWin->activateWindow();
144 } // namespace SharedTools