1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "ioutputparser.h" |
6 | |
7 | IOutputParser::~IOutputParser() |
8 | { |
9 | delete outParser; |
10 | } |
11 | |
12 | void IOutputParser::appendOutputParser(IOutputParser *parser) |
13 | { |
14 | if (!parser) |
15 | return; |
16 | if (outParser) { |
17 | outParser->appendOutputParser(parser); |
18 | return; |
19 | } |
20 | |
21 | outParser = parser; |
22 | connect(parser, &IOutputParser::addOutput, |
23 | this, &IOutputParser::outputAdded, Qt::DirectConnection); |
24 | connect(parser, &IOutputParser::addTask, |
25 | this, &IOutputParser::taskAdded, Qt::DirectConnection); |
26 | } |
27 | |
28 | IOutputParser *IOutputParser::takeOutputParserChain() |
29 | { |
30 | IOutputParser *parser = outParser; |
31 | disconnect(parser, &IOutputParser::addOutput, this, &IOutputParser::outputAdded); |
32 | disconnect(parser, &IOutputParser::addTask, this, &IOutputParser::taskAdded); |
33 | outParser = nullptr; |
34 | return parser; |
35 | } |
36 | |
37 | IOutputParser *IOutputParser::childParser() const |
38 | { |
39 | return outParser; |
40 | } |
41 | |
42 | void IOutputParser::setChildParser(IOutputParser *parser) |
43 | { |
44 | if (outParser != parser) |
45 | delete outParser; |
46 | outParser = parser; |
47 | if (parser) { |
48 | connect(parser, &IOutputParser::addOutput, |
49 | this, &IOutputParser::outputAdded, Qt::DirectConnection); |
50 | connect(parser, &IOutputParser::addTask, |
51 | this, &IOutputParser::taskAdded, Qt::DirectConnection); |
52 | } |
53 | } |
54 | |
55 | void IOutputParser::stdOutput(const QString &line, OutputPane::OutputFormat format) |
56 | { |
57 | if (outParser) |
58 | outParser->stdOutput(line, format); |
59 | } |
60 | |
61 | void IOutputParser::stdError(const QString &line) |
62 | { |
63 | if (outParser) |
64 | outParser->stdError(line); |
65 | } |
66 | |
67 | void IOutputParser::outputAdded(const QString &string, OutputPane::OutputFormat format) |
68 | { |
69 | emit addOutput(string, format); |
70 | } |
71 | |
72 | void IOutputParser::taskAdded(const Task &task, int linkedOutputLines, int skipLines) |
73 | { |
74 | emit addTask(task, linkedOutputLines, skipLines); |
75 | } |
76 | |
77 | void IOutputParser::doFlush() |
78 | { } |
79 | |
80 | bool IOutputParser::hasFatalErrors() const |
81 | { |
82 | return outParser && outParser->hasFatalErrors(); |
83 | } |
84 | |
85 | void IOutputParser::setWorkingDirectory(const QString &workingDirectory) |
86 | { |
87 | if (outParser) |
88 | outParser->setWorkingDirectory(workingDirectory); |
89 | } |
90 | |
91 | void IOutputParser::flush() |
92 | { |
93 | doFlush(); |
94 | if (outParser) |
95 | outParser->flush(); |
96 | } |
97 | |
98 | QString IOutputParser::rightTrimmed(const QString &in) |
99 | { |
100 | int pos = in.length(); |
101 | for (; pos > 0; --pos) { |
102 | if (!in.at(pos - 1).isSpace()) |
103 | break; |
104 | } |
105 | return in.mid(0, pos); |
106 | } |
107 | |