-
Notifications
You must be signed in to change notification settings - Fork 5
/
qtcdeveloperplugin.cpp
executable file
·177 lines (138 loc) · 6.51 KB
/
qtcdeveloperplugin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* Copyright 2016-2020 Pascal COMBES <[email protected]>
*
* This file is part of QtcDevPlugin.
*
* QtcDevPlugin is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QtcDevPlugin is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QtcDevPlugin. If not, see <http://www.gnu.org/licenses/>
*/
#include "qtcdeveloperplugin.h"
#include "qtcdevpluginconstants.h"
#include "qtcrunconfigurationfactory.h"
#include "qtcrunconfiguration.h"
#ifdef BUILD_TESTS
# include "Test/qtcrunconfigurationfactorytest.h"
# include "Test/qtcrunconfigurationtest.h"
# include "Test/qtcpluginrunnertest.h"
#endif
#include <projectexplorer/projectexplorer.h>
#include <projectexplorer/runcontrol.h>
#include <coreplugin/icore.h>
#include <extensionsystem/pluginmanager.h>
#include <QtCore>
using namespace QtcDevPlugin::Internal;
QtcDeveloperPlugin::QtcDeveloperPlugin()
{
// Create your members
}
QtcDeveloperPlugin::~QtcDeveloperPlugin()
{
// Unregister objects from the plugin manager's object pool
// Delete members
qDeleteAll(mRunConfigurationFactories);
}
bool QtcDeveloperPlugin::initialize(const QStringList &arguments, QString *errorString)
{
// Register objects in the plugin manager's object pool
// Load settings
// Add actions to menus
// Connect to other plugins' signals
// In the initialize function, a plugin can be sure that the plugins it
// depends on have initialized their members.
Q_UNUSED(arguments)
Q_UNUSED(errorString)
// Locate QM file for the current language and use it
QString qmFile = Core::ICore::userInterfaceLanguage();
if (qmFile.isEmpty())
qmFile = QLatin1String("en");
else
qmFile = qmFile.left(2);
qmFile = QString(QLatin1String("qtcdevplugin_%1.qm")).arg(qmFile);
QTranslator *translator = new QTranslator(this);
if (translator->load(qmFile, Core::ICore::resourcePath() + QDir::separator() + QLatin1String("translations")) ||
translator->load(qmFile, Core::ICore::userResourcePath() + QDir::separator() + QLatin1String("translations"))) {
if (!qApp->installTranslator(translator))
qWarning() << qPrintable(QString(QLatin1String("Failed to install translator (%1)")).arg(qmFile));
} else {
qWarning() << qPrintable(QString(QLatin1String("Translator file \"%1\" not found")).arg(qmFile));
}
mRunConfigurationFactories << new QtcRunConfigurationFactory();
mRunConfigurationFactories << new QtcTestRunConfigurationFactory();
connect(ProjectExplorer::ProjectExplorerPlugin::instance(), SIGNAL(aboutToExecuteRunControl(ProjectExplorer::RunControl*, Utils::Id)),
this, SLOT(handleRunControlStarted(ProjectExplorer::RunControl*)), Qt::DirectConnection);
return true;
}
void QtcDeveloperPlugin::extensionsInitialized()
{
// Retrieve objects from the plugin manager's object pool
// In the extensionsInitialized function, a plugin can be sure that all
// plugins that depend on it are completely initialized.
}
ExtensionSystem::IPlugin::ShutdownFlag QtcDeveloperPlugin::aboutToShutdown()
{
// Save settings
// Disconnect from signals that are not needed during shutdown
// Hide UI (if you add UI that is not in the main window directly)
return SynchronousShutdown;
}
void QtcDeveloperPlugin::handleRunControlStarted(ProjectExplorer::RunControl* runControl)
{
qDebug() << "Starting" << runControl->runConfiguration()->id();
if ((runControl->runConfiguration()->id() != Utils::Id(Constants::QtcRunConfigurationId)) &&
(runControl->runConfiguration()->id() != Utils::Id(Constants::QtcTestRunConfigurationId)))
return;
connect(runControl, SIGNAL(stopped()), this, SLOT(handleRunControlStopped()));
Utils::FilePath targetFilePath(static_cast<QtcRunConfiguration*>(runControl->runConfiguration())->targetFilePath());
movePluginFile(targetFilePath, QString(), QLatin1String(".del"));
foreach (Utils::FilePath pluginFilePath, pluginPaths(targetFilePath.fileName()))
movePluginFile(pluginFilePath, QString(), QLatin1String(".del"));
}
void QtcDeveloperPlugin::handleRunControlStopped()
{
ProjectExplorer::RunControl* runControl = qobject_cast<ProjectExplorer::RunControl*>(sender());
QTC_ASSERT(runControl != nullptr, return);
qDebug() << "End of" << runControl->runConfiguration()->id();
if ((runControl->runConfiguration()->id() != Utils::Id(Constants::QtcRunConfigurationId)) &&
(runControl->runConfiguration()->id() != Utils::Id(Constants::QtcTestRunConfigurationId)))
return;
Utils::FilePath targetFilePath(static_cast<QtcRunConfiguration*>(runControl->runConfiguration())->targetFilePath());
movePluginFile(targetFilePath, QLatin1String(".del"), QString());
foreach (Utils::FilePath pluginFilePath, pluginPaths(targetFilePath.fileName()))
movePluginFile(pluginFilePath, QLatin1String(".del"), QString());
}
QLinkedList<Utils::FilePath> QtcDeveloperPlugin::pluginPaths(const QString& fileName)
{
QLinkedList<Utils::FilePath> ans;
foreach (QString pluginPath, ExtensionSystem::PluginManager::pluginPaths())
ans << Utils::FilePath::fromString(pluginPath).pathAppended(fileName);
return ans;
}
void QtcDeveloperPlugin::movePluginFile(const Utils::FilePath& targetPath, const QString& oldSuffix, const QString& newSuffix)
{
Utils::FilePath oldTargetPath = Utils::FilePath(targetPath).stringAppended(oldSuffix);
Utils::FilePath newTargetPath = Utils::FilePath(targetPath).stringAppended(newSuffix);
qDebug() << oldTargetPath << oldTargetPath.toFileInfo().exists() << newTargetPath << newTargetPath.toFileInfo().exists();
if (oldTargetPath.toFileInfo().exists()) {
QTC_CHECK(QFile::rename(oldTargetPath.toString(), newTargetPath.toString()));
}
QTC_CHECK(!oldTargetPath.toFileInfo().exists());
}
#ifdef BUILD_TESTS
QVector<QObject *> QtcDeveloperPlugin::createTestObjects(void) const
{
QVector<QObject *> testObjects;
testObjects << new Test::QtcRunConfigurationFactoryTest;
testObjects << new Test::QtcRunConfigurationTest;
testObjects << new Test::QtcPluginRunnerTest;
return testObjects;
}
#endif