File indexing completed on 2024-12-22 04:12:50
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). 0004 ** Contact: http://www.qt-project.org/legal 0005 ** 0006 ** This file is part of Qt Creator. 0007 ** 0008 ** Commercial License Usage 0009 ** Licensees holding valid commercial Qt licenses may use this file in 0010 ** accordance with the commercial license agreement provided with the 0011 ** Software or, alternatively, in accordance with the terms contained in 0012 ** a written agreement between you and Digia. For licensing terms and 0013 ** conditions see https://www.qt.io/licensing. For further information 0014 ** use the contact form at https://www.qt.io/contact-us. 0015 ** 0016 ** GNU Lesser General Public License Usage 0017 ** Alternatively, this file may be used under the terms of the GNU Lesser 0018 ** General Public License version 2.1 or version 3 as published by the Free 0019 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 0020 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 0021 ** following information to ensure the GNU Lesser General Public License 0022 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 0023 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 0024 ** 0025 ** In addition, as a special exception, Digia gives you certain additional 0026 ** rights. These rights are described in the Digia Qt LGPL Exception 0027 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 0028 ** 0029 ****************************************************************************/ 0030 0031 #ifndef QTSINGLEAPPLICATION 0032 #define QTSINGLEAPPLICATION 0033 0034 0035 #include <QApplication> 0036 0037 QT_FORWARD_DECLARE_CLASS(QSharedMemory) 0038 0039 class QtLocalPeer; 0040 0041 #include <kritaui_export.h> 0042 0043 class KRITAUI_EXPORT QtSingleApplication : public QApplication 0044 { 0045 Q_OBJECT 0046 0047 public: 0048 QtSingleApplication(const QString &id, int &argc, char **argv); 0049 ~QtSingleApplication() override; 0050 0051 bool isRunning(qint64 pid = -1); 0052 0053 void setActivationWindow(QWidget* aw, bool activateOnMessage = true); 0054 QWidget* activationWindow() const; 0055 bool event(QEvent *event) override; 0056 0057 QString applicationId() const; 0058 void setBlock(bool value); 0059 0060 public Q_SLOTS: 0061 bool sendMessage(const QByteArray &message, int timeout = 5000, qint64 pid = -1); 0062 void activateWindow(); 0063 0064 Q_SIGNALS: 0065 void messageReceived(const QByteArray &message, QObject *socket); 0066 void fileOpenRequest(const QString &file); 0067 0068 private: 0069 QString instancesFileName(const QString &appId); 0070 0071 qint64 firstPeer; 0072 QSharedMemory *instances; 0073 QtLocalPeer *pidPeer; 0074 QWidget *actWin; 0075 QString appId; 0076 bool block; 0077 }; 0078 0079 #endif