Changeset View
Changeset View
Standalone View
Standalone View
addons/externaltools/katetoolrunner.cpp
- This file was added.
1 | /* This file is part of the KDE project | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright 2019 Dominik Haumann <dhaumann@kde.org> | ||||
4 | * | ||||
5 | * This library is free software; you can redistribute it and/or | ||||
6 | * modify it under the terms of the GNU Library General Public | ||||
7 | * License as published by the Free Software Foundation; either | ||||
8 | * version 2 of the License, or (at your option) any later version. | ||||
9 | * | ||||
10 | * This library is distributed in the hope that it will be useful, | ||||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
13 | * Library General Public License for more details. | ||||
14 | * | ||||
15 | * You should have received a copy of the GNU Library General Public License | ||||
16 | * along with this library; see the file COPYING.LIB. If not, write to | ||||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
18 | * Boston, MA 02110-1301, USA. | ||||
19 | */ | ||||
20 | | ||||
21 | #include "katetoolrunner.h" | ||||
22 | | ||||
23 | #include "kateexternaltool.h" | ||||
24 | | ||||
25 | #include <KShell> | ||||
26 | | ||||
27 | KateToolRunner::KateToolRunner(KateExternalTool * tool) | ||||
28 | : m_tool(tool) | ||||
29 | , m_process(new QProcess()) | ||||
30 | { | ||||
31 | } | ||||
32 | | ||||
33 | KateToolRunner::~KateToolRunner() | ||||
34 | { | ||||
35 | delete m_tool; | ||||
36 | m_tool = nullptr; | ||||
37 | | ||||
38 | delete m_process; | ||||
39 | m_process = nullptr; | ||||
40 | } | ||||
41 | | ||||
42 | void KateToolRunner::run() | ||||
43 | { | ||||
44 | if (m_tool->includeStderr) { | ||||
45 | m_process->setProcessChannelMode(QProcess::MergedChannels); | ||||
46 | } | ||||
47 | | ||||
48 | if (!m_tool->workingDir.isEmpty()) { | ||||
49 | m_process->setWorkingDirectory(m_tool->workingDir); | ||||
50 | } | ||||
51 | | ||||
52 | QObject::connect(m_process, &QProcess::readyRead, this, &KateToolRunner::slotReadyRead); | ||||
53 | QObject::connect(m_process, static_cast<void(QProcess::*)(int,QProcess::ExitStatus)>(&QProcess::finished), this, &KateToolRunner::toolFinished); | ||||
54 | | ||||
55 | const QStringList args = KShell::splitArgs(m_tool->arguments); | ||||
56 | m_process->start(m_tool->executable, args); | ||||
57 | } | ||||
58 | | ||||
59 | void KateToolRunner::waitForFinished() | ||||
60 | { | ||||
61 | m_process->waitForFinished(); | ||||
62 | } | ||||
63 | | ||||
64 | | ||||
65 | QString KateToolRunner::outputData() const | ||||
66 | { | ||||
67 | return QString::fromLocal8Bit(m_output); | ||||
68 | } | ||||
69 | | ||||
70 | void KateToolRunner::slotReadyRead() | ||||
71 | { | ||||
72 | m_output += m_process->readAll(); | ||||
73 | } | ||||
74 | | ||||
75 | void KateToolRunner::toolFinished(int exitCode, QProcess::ExitStatus exitStatus) | ||||
76 | { | ||||
77 | if (exitCode != 0) { | ||||
78 | // FIXME: somehow tell user | ||||
79 | return; | ||||
80 | } | ||||
81 | | ||||
82 | if (exitStatus != QProcess::NormalExit) { | ||||
83 | // FIXME: somehow tell user | ||||
84 | return; | ||||
85 | } | ||||
86 | | ||||
87 | // FIXME: process m_output depending on the tool's outputMode | ||||
88 | } | ||||
89 | | ||||
90 | // kate: space-indent on; indent-width 4; replace-tabs on; |