Changeset View
Changeset View
Standalone View
Standalone View
plugins/execute/nativeappjob.cpp
Show All 17 Lines | |||||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "nativeappjob.h" | 20 | #include "nativeappjob.h" | ||
21 | 21 | | |||
22 | #include <QDebug> | 22 | #include <QDebug> | ||
23 | #include <QFileInfo> | 23 | #include <QFileInfo> | ||
24 | #include <QMessageBox> | 24 | #include <QMessageBox> | ||
25 | 25 | | |||
26 | #include <KConfigGroup> | ||||
26 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
27 | #include <KShell> | 28 | #include <KShell> | ||
28 | #include <KSharedConfig> | 29 | #include <KSharedConfig> | ||
29 | 30 | | |||
30 | #include <interfaces/ilaunchconfiguration.h> | 31 | #include <interfaces/ilaunchconfiguration.h> | ||
31 | #include <interfaces/iruncontroller.h> | 32 | #include <interfaces/iruncontroller.h> | ||
32 | #include <outputview/outputmodel.h> | 33 | #include <outputview/outputmodel.h> | ||
33 | #include <util/environmentgrouplist.h> | 34 | #include <util/environmentgrouplist.h> | ||
34 | 35 | | |||
35 | #include <interfaces/icore.h> | 36 | #include <interfaces/icore.h> | ||
36 | #include <interfaces/iplugincontroller.h> | 37 | #include <interfaces/iplugincontroller.h> | ||
37 | #include <project/projectmodel.h> | 38 | #include <project/projectmodel.h> | ||
38 | 39 | | |||
39 | #include "iexecuteplugin.h" | 40 | #include "executeplugin.h" | ||
40 | #include "debug.h" | 41 | #include "debug.h" | ||
41 | 42 | | |||
42 | using namespace KDevelop; | 43 | using namespace KDevelop; | ||
43 | 44 | | |||
44 | NativeAppJob::NativeAppJob(QObject* parent, KDevelop::ILaunchConfiguration* cfg) | 45 | NativeAppJob::NativeAppJob(QObject* parent, KDevelop::ILaunchConfiguration* cfg) | ||
45 | : KDevelop::OutputExecuteJob( parent ) | 46 | : KDevelop::OutputExecuteJob( parent ) | ||
46 | , m_cfgname(cfg->name()) | 47 | , m_name(cfg->name()) | ||
47 | { | 48 | { | ||
49 | { | ||||
50 | auto cfgGroup = cfg->config(); | ||||
51 | if (cfgGroup.readEntry(ExecutePlugin::isExecutableEntry, false)) { | ||||
52 | m_name = cfgGroup.readEntry(ExecutePlugin::executableEntry, cfg->name()).section('/', -1); | ||||
apol: Either do `splitRef` or `section`. | |||||
53 | } | ||||
54 | } | ||||
48 | setCapabilities(Killable); | 55 | setCapabilities(Killable); | ||
49 | 56 | | |||
50 | IExecutePlugin* iface = KDevelop::ICore::self()->pluginController()->pluginForExtension(QStringLiteral("org.kdevelop.IExecutePlugin"), QStringLiteral("kdevexecute"))->extension<IExecutePlugin>(); | 57 | IExecutePlugin* iface = KDevelop::ICore::self()->pluginController()->pluginForExtension(QStringLiteral("org.kdevelop.IExecutePlugin"), QStringLiteral("kdevexecute"))->extension<IExecutePlugin>(); | ||
51 | Q_ASSERT(iface); | 58 | Q_ASSERT(iface); | ||
52 | 59 | | |||
53 | KDevelop::EnvironmentGroupList l(KSharedConfig::openConfig()); | 60 | KDevelop::EnvironmentGroupList l(KSharedConfig::openConfig()); | ||
54 | QString envgrp = iface->environmentGroup(cfg); | 61 | QString envgrp = iface->environmentGroup(cfg); | ||
55 | 62 | | |||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 110 | if (iface->useTerminal(cfg)) { | |||
107 | QStringList args = KShell::splitArgs(terminalCommand); | 114 | QStringList args = KShell::splitArgs(terminalCommand); | ||
108 | args.append( arguments ); | 115 | args.append( arguments ); | ||
109 | *this << args; | 116 | *this << args; | ||
110 | } else { | 117 | } else { | ||
111 | *this << executable.toLocalFile(); | 118 | *this << executable.toLocalFile(); | ||
112 | *this << arguments; | 119 | *this << arguments; | ||
113 | } | 120 | } | ||
114 | 121 | | |||
115 | setJobName(cfg->name()); | 122 | setJobName(m_name); | ||
116 | } | 123 | } | ||
117 | 124 | | |||
118 | NativeAppJob* findNativeJob(KJob* j) | 125 | NativeAppJob* findNativeJob(KJob* j) | ||
119 | { | 126 | { | ||
120 | NativeAppJob* job = qobject_cast<NativeAppJob*>(j); | 127 | NativeAppJob* job = qobject_cast<NativeAppJob*>(j); | ||
121 | if (!job) { | 128 | if (!job) { | ||
122 | const QList<NativeAppJob*> jobs = j->findChildren<NativeAppJob*>(); | 129 | const QList<NativeAppJob*> jobs = j->findChildren<NativeAppJob*>(); | ||
123 | if (!jobs.isEmpty()) | 130 | if (!jobs.isEmpty()) | ||
124 | job = jobs.first(); | 131 | job = jobs.first(); | ||
125 | } | 132 | } | ||
126 | return job; | 133 | return job; | ||
127 | } | 134 | } | ||
128 | 135 | | |||
129 | void NativeAppJob::start() | 136 | void NativeAppJob::start() | ||
130 | { | 137 | { | ||
131 | // we kill any execution of the configuration | 138 | // we kill any execution of the configuration | ||
132 | foreach(KJob* j, ICore::self()->runController()->currentJobs()) { | 139 | auto currentJobs = ICore::self()->runController()->currentJobs(); | ||
133 | NativeAppJob* job = findNativeJob(j); | 140 | for (auto it = currentJobs.begin(); it != currentJobs.end();) { | ||
134 | if (job && job != this && job->m_cfgname == m_cfgname) { | 141 | NativeAppJob* job = findNativeJob(*it); | ||
135 | QMessageBox::StandardButton button = QMessageBox::question(nullptr, i18n("Job already running"), i18n("'%1' is already being executed. Should we kill the previous instance?", m_cfgname)); | 142 | if (job && job != this && job->m_name == m_name) { | ||
136 | if (button != QMessageBox::No && ICore::self()->runController()->currentJobs().contains(j)) | 143 | QMessageBox::StandardButton button = QMessageBox::question(nullptr, i18n("Job already running"), i18n("'%1' is already being executed. Should we kill the previous instance?", m_name)); | ||
137 | j->kill(); | 144 | if (button != QMessageBox::No && ICore::self()->runController()->currentJobs().contains(*it)) { | ||
145 | (*it)->kill(); | ||||
146 | } | ||||
147 | currentJobs = ICore::self()->runController()->currentJobs(); | ||||
148 | it = currentJobs.begin(); | ||||
149 | } else { | ||||
150 | ++it; | ||||
138 | } | 151 | } | ||
139 | } | 152 | } | ||
140 | 153 | | |||
141 | OutputExecuteJob::start(); | 154 | OutputExecuteJob::start(); | ||
142 | } | 155 | } |
Either do splitRef or section.