Changeset View
Changeset View
Standalone View
Standalone View
plugins/execute/nativeappjob.cpp
Show All 13 Lines | 1 | /* This file is part of KDevelop | |||
---|---|---|---|---|---|
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "nativeappjob.h" | 20 | #include "nativeappjob.h" | ||
21 | 21 | | |||
22 | #include <QAbstractButton> | ||||
22 | #include <QFileInfo> | 23 | #include <QFileInfo> | ||
23 | #include <QMessageBox> | 24 | #include <QMessageBox> | ||
25 | #include <QPointer> | ||||
24 | 26 | | |||
25 | #include <KConfigGroup> | 27 | #include <KConfigGroup> | ||
26 | #include <KLocalizedString> | 28 | #include <KLocalizedString> | ||
27 | #include <KShell> | 29 | #include <KShell> | ||
28 | #include <KSharedConfig> | 30 | #include <KSharedConfig> | ||
29 | 31 | | |||
30 | #include <interfaces/ilaunchconfiguration.h> | 32 | #include <interfaces/ilaunchconfiguration.h> | ||
31 | #include <interfaces/iruncontroller.h> | 33 | #include <interfaces/iruncontroller.h> | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 128 | if (!job) { | |||
127 | const QList<NativeAppJob*> jobs = j->findChildren<NativeAppJob*>(); | 129 | const QList<NativeAppJob*> jobs = j->findChildren<NativeAppJob*>(); | ||
128 | if (!jobs.isEmpty()) | 130 | if (!jobs.isEmpty()) | ||
129 | job = jobs.first(); | 131 | job = jobs.first(); | ||
130 | } | 132 | } | ||
131 | return job; | 133 | return job; | ||
132 | } | 134 | } | ||
133 | 135 | | |||
134 | void NativeAppJob::start() | 136 | void NativeAppJob::start() | ||
135 | { | 137 | { | ||
136 | // we kill any execution of the configuration | 138 | QVector<QPointer<NativeAppJob> > currentJobs; | ||
mwolff: use QSet, or unordered_set - the order isn't needed and the hash-based containers are faster | |||||
I'd prefer QSet and then you could use the more expressive !contains here instead of !count mwolff: I'd prefer QSet and then you could use the more expressive `!contains` here instead of `!count` | |||||
please put the QMessageBox::question call into a separate line, and break it up. Save the return value in a temp var and switch over it then Also reword the message to '%1' is already being executed.. Then set proper texts on the button such that it's clear what they do: Yes -> Kill I'd also say that the default action should be cancel here, or maybe "start another", but not a destructive kill mwolff: please put the `QMessageBox::question` call into a separate line, and break it up. Save the… | |||||
137 | auto currentJobs = ICore::self()->runController()->currentJobs(); | 139 | // collect running instances of the same type | ||
138 | for (auto it = currentJobs.begin(); it != currentJobs.end();) { | 140 | for (auto j : ICore::self()->runController()->currentJobs()) { | ||
why this line? you do this, to check whether the job is still alive? If so, store it in a QPointer and check its validity mwolff: why this line? you do this, to check whether the job is still alive? If so, store it in a… | |||||
139 | NativeAppJob* job = findNativeJob(*it); | 141 | NativeAppJob* njob = findNativeJob(j); | ||
140 | if (job && job != this && job->m_name == m_name) { | 142 | if (njob && njob != this && njob->m_name == m_name) | ||
141 | QMessageBox::StandardButton button = QMessageBox::question(nullptr, i18n("Job already running"), i18n("'%1' is already being executed. Should we kill the previous instance?", m_name)); | 143 | currentJobs << njob; | ||
142 | if (button != QMessageBox::No && ICore::self()->runController()->currentJobs().contains(*it)) { | 144 | } | ||
143 | (*it)->kill(); | 145 | | ||
144 | } | 146 | if (!currentJobs.isEmpty()) { | ||
145 | currentJobs = ICore::self()->runController()->currentJobs(); | 147 | QMessageBox msgBox(QMessageBox::Question, | ||
146 | it = currentJobs.begin(); | 148 | i18n("Job already running"), | ||
147 | } else { | 149 | i18n("'%1' is already being executed.", m_name), | ||
148 | ++it; | 150 | QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel); | ||
151 | msgBox.button(QMessageBox::No)->setText(i18n("Kill All Instances")); | ||||
152 | msgBox.button(QMessageBox::Yes)->setText(i18n("Start Another")); | ||||
153 | msgBox.setDefaultButton(QMessageBox::Cancel); | ||||
154 | | ||||
155 | switch (msgBox.exec()) { | ||||
156 | case QMessageBox::Yes: // simply start another job | ||||
157 | break; | ||||
158 | case QMessageBox::No: // kill the running instance | ||||
159 | for (auto & job : currentJobs) { | ||||
160 | if (job) | ||||
161 | job->kill(); | ||||
162 | } | ||||
163 | break; | ||||
164 | default: // cancel starting a new job | ||||
165 | kill(); | ||||
166 | return; | ||||
mwolff: use a QVector please | |||||
149 | } | 167 | } | ||
150 | } | 168 | } | ||
151 | 169 | | |||
152 | OutputExecuteJob::start(); | 170 | OutputExecuteJob::start(); | ||
153 | } | 171 | } |
use QSet, or unordered_set - the order isn't needed and the hash-based containers are faster