dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
coreplugin.cpp
Go to the documentation of this file.
1 
15 /*
16  * This program is free software; you can redistribute it and/or modify
17  * it under the terms of the GNU General Public License as published by
18  * the Free Software Foundation; either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
23  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24  * for more details.
25  *
26  * You should have received a copy of the GNU General Public License along
27  * with this program; if not, see <http://www.gnu.org/licenses/>
28  */
29 #include "coreplugin.h"
30 #include "coreimpl.h"
31 #include "mainwindow.h"
32 #include <runguard/runguard.h>
33 #include <QtPlugin>
35 #include <QtCore/QtPlugin>
36 #include <QTimer>
37 
38 using namespace Core::Internal;
39 
40 CorePlugin::CorePlugin()
41  : m_mainWindow(new MainWindow)
42  , m_secondaryAttempts(0)
43  , m_secondaryTimer(new QTimer)
44 {
45  connect(m_mainWindow, SIGNAL(splashMessages(QString)), this, SIGNAL(splashMessages(QString)));
46  connect(m_mainWindow, SIGNAL(hideSplash()), this, SIGNAL(hideSplash()));
47  connect(m_mainWindow, SIGNAL(showSplash()), this, SIGNAL(showSplash()));
48 }
49 
50 CorePlugin::~CorePlugin()
51 {
52  m_secondaryTimer->stop();
53  delete m_secondaryTimer;
54  delete m_mainWindow;
55 }
56 
57 bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
58 {
59  if (arguments.contains("crashme")) {
60  if ((arguments.length() > 1) && (arguments.at(arguments.indexOf("crashme") + 1) == "yes")) {
61  QString *s = nullptr;
62  s->append("crash");
63  }
64  }
65  const bool success = m_mainWindow->init(errorMessage);
66  if (success) {
67  // nothing right now
68  }
69  return success;
70 }
71 
72 void CorePlugin::extensionsInitialized()
73 {
74  m_mainWindow->extensionsInitialized();
75 
76  // check if another app instance has attempted to start periodically
77  // and show our instance if so
78  m_secondaryTimer->setInterval(1000);
79  connect(m_secondaryTimer, &QTimer::timeout, this, [this]() {
80  // relying on main() to have already created the instance
81  // (with appropriate key)
82  quint64 attempts = RunGuard::instance("").secondaryAttempts();
83  if (attempts != m_secondaryAttempts && m_mainWindow)
84  m_mainWindow->activateWindow();
85  m_secondaryAttempts = attempts;
86  });
87  m_secondaryTimer->start();
88 }
89 
90 void CorePlugin::remoteArgument(const QString &arg)
91 {
92  // An empty argument is sent to trigger activation
93  // of the window via QtSingleApplication. It should be
94  // the last of a sequence.
95  if (arg.isEmpty()) {
96  m_mainWindow->activateWindow();
97  }
98 }
99 
100 void CorePlugin::shutdown()
101 {
102  m_mainWindow->shutdown();
103 }
quint64 secondaryAttempts()
Number of secondary instances attempted to start.
Definition: runguard.cpp:110
static RunGuard & instance(const QString &key)
Get instance of this singleton.
Definition: runguard.cpp:70
bool init(QString *errorMessage)
Definition: mainwindow.cpp:297
void remoteArgument(const QString &=QString())
Definition: coreplugin.cpp:90