forked from qt-creator/qt-creator
146 lines
3.8 KiB
C++
146 lines
3.8 KiB
C++
/***************************************************************************
|
|
**
|
|
** This file is part of Qt Creator
|
|
**
|
|
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
**
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
**
|
|
**
|
|
** Non-Open Source Usage
|
|
**
|
|
** Licensees may use this file in accordance with the Qt Beta Version
|
|
** License Agreement, Agreement version 2.2 provided with the Software or,
|
|
** alternatively, in accordance with the terms contained in a written
|
|
** agreement between you and Nokia.
|
|
**
|
|
** GNU General Public License Usage
|
|
**
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
** Public License versions 2.0 or 3.0 as published by the Free Software
|
|
** Foundation and appearing in the file LICENSE.GPL included in the packaging
|
|
** of this file. Please review the following information to ensure GNU
|
|
** General Public Licensing requirements will be met:
|
|
**
|
|
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
**
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
|
** rights. These rights are described in the Nokia Qt GPL Exception
|
|
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
|
|
**
|
|
***************************************************************************/
|
|
|
|
#include "qtsingleapplication.h"
|
|
#include "qtlocalpeer.h"
|
|
|
|
#include <QtGui/QWidget>
|
|
#include <QtGui/QFileOpenEvent>
|
|
|
|
namespace SharedTools {
|
|
|
|
void QtSingleApplication::sysInit(const QString &appId)
|
|
{
|
|
actWin = 0;
|
|
peer = new QtLocalPeer(this, appId);
|
|
connect(peer, SIGNAL(messageReceived(const QString&)), SIGNAL(messageReceived(const QString&)));
|
|
}
|
|
|
|
|
|
QtSingleApplication::QtSingleApplication(int &argc, char **argv, bool GUIenabled)
|
|
: QApplication(argc, argv, GUIenabled)
|
|
{
|
|
sysInit();
|
|
}
|
|
|
|
|
|
QtSingleApplication::QtSingleApplication(const QString &appId, int &argc, char **argv)
|
|
: QApplication(argc, argv)
|
|
{
|
|
sysInit(appId);
|
|
}
|
|
|
|
|
|
QtSingleApplication::QtSingleApplication(int &argc, char **argv, Type type)
|
|
: QApplication(argc, argv, type)
|
|
{
|
|
sysInit();
|
|
}
|
|
|
|
|
|
#if defined(Q_WS_X11)
|
|
QtSingleApplication::QtSingleApplication(Display* dpy, Qt::HANDLE visual, Qt::HANDLE colormap)
|
|
: QApplication(dpy, visual, colormap)
|
|
{
|
|
sysInit();
|
|
}
|
|
|
|
QtSingleApplication::QtSingleApplication(Display *dpy, int &argc, char **argv, Qt::HANDLE visual, Qt::HANDLE cmap)
|
|
: QApplication(dpy, argc, argv, visual, cmap)
|
|
{
|
|
sysInit();
|
|
}
|
|
|
|
QtSingleApplication::QtSingleApplication(Display* dpy, const QString &appId,
|
|
int argc, char **argv, Qt::HANDLE visual, Qt::HANDLE colormap)
|
|
: QApplication(dpy, argc, argv, visual, colormap)
|
|
{
|
|
sysInit(appId);
|
|
}
|
|
#endif
|
|
|
|
bool QtSingleApplication::event(QEvent *event)
|
|
{
|
|
if (event->type() == QEvent::FileOpen) {
|
|
QFileOpenEvent *foe = static_cast<QFileOpenEvent*>(event);
|
|
emit fileOpenRequest(foe->file());
|
|
return true;
|
|
}
|
|
return QApplication::event(event);
|
|
}
|
|
|
|
bool QtSingleApplication::isRunning()
|
|
{
|
|
return peer->isClient();
|
|
}
|
|
|
|
|
|
bool QtSingleApplication::sendMessage(const QString &message, int timeout)
|
|
{
|
|
return peer->sendMessage(message, timeout);
|
|
}
|
|
|
|
|
|
QString QtSingleApplication::id() const
|
|
{
|
|
return peer->applicationId();
|
|
}
|
|
|
|
|
|
void QtSingleApplication::setActivationWindow(QWidget *aw, bool activateOnMessage)
|
|
{
|
|
actWin = aw;
|
|
if (activateOnMessage)
|
|
connect(peer, SIGNAL(messageReceived(QString)), this, SLOT(activateWindow()));
|
|
else
|
|
disconnect(peer, SIGNAL(messageReceived(QString)), this, SLOT(activateWindow()));
|
|
}
|
|
|
|
|
|
QWidget* QtSingleApplication::activationWindow() const
|
|
{
|
|
return actWin;
|
|
}
|
|
|
|
|
|
void QtSingleApplication::activateWindow()
|
|
{
|
|
if (actWin) {
|
|
actWin->setWindowState(actWin->windowState() & ~Qt::WindowMinimized);
|
|
actWin->raise();
|
|
actWin->activateWindow();
|
|
}
|
|
}
|
|
|
|
} // namespace SharedTools
|