File indexing completed on 2024-05-19 04:38:46
0001 /**************************************************************************** 0002 ** 0003 ** Copyright (C) 2016 The Qt Company Ltd. 0004 ** Contact: https://www.qt.io/licensing/ 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 The Qt Company. For licensing terms 0013 ** and conditions see https://www.qt.io/terms-conditions. For further 0014 ** information use the contact form at https://www.qt.io/contact-us. 0015 ** 0016 ** GNU General Public License Usage 0017 ** Alternatively, this file may be used under the terms of the GNU 0018 ** General Public License version 3 as published by the Free Software 0019 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 0020 ** included in the packaging of this file. Please review the following 0021 ** information to ensure the GNU General Public License requirements will 0022 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 0023 ** 0024 ****************************************************************************/ 0025 0026 #include <QApplication> 0027 0028 QT_FORWARD_DECLARE_CLASS(QSharedMemory) 0029 0030 namespace SharedTools { 0031 0032 class QtLocalPeer; 0033 0034 class QtSingleApplication : public QApplication 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 QtSingleApplication(const QString &id, int &argc, char **argv); 0040 ~QtSingleApplication(); 0041 0042 bool isRunning(qint64 pid = -1); 0043 0044 void setActivationWindow(QWidget* aw, bool activateOnMessage = true); 0045 QWidget* activationWindow() const; 0046 bool event(QEvent *event); 0047 0048 QString applicationId() const; 0049 void setBlock(bool value); 0050 0051 public Q_SLOTS: 0052 bool sendMessage(const QString &message, int timeout = 5000, qint64 pid = -1); 0053 void activateWindow(); 0054 0055 Q_SIGNALS: 0056 void messageReceived(const QString &message, QObject *socket); 0057 void fileOpenRequest(const QString &file); 0058 0059 private: 0060 QString instancesFileName(const QString &appId); 0061 0062 qint64 firstPeer; 0063 QSharedMemory *instances; 0064 QtLocalPeer *pidPeer; 0065 QWidget *actWin; 0066 QString appId; 0067 bool block; 0068 }; 0069 0070 } // namespace SharedTools