File: processlinemaker.h

package info (click to toggle)
kdevelop 4%3A24.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 71,888 kB
  • sloc: cpp: 290,869; python: 3,626; javascript: 3,518; sh: 1,316; ansic: 703; xml: 401; php: 95; lisp: 66; makefile: 31; sed: 12
file content (106 lines) | stat: -rw-r--r-- 2,994 bytes parent folder | download | duplicates (2)
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
/*
    SPDX-FileCopyrightText: 2002 John Firebaugh <jfirebaugh@kde.org>
    SPDX-FileCopyrightText: 2007 Andreas Pakulat <apaku@gmx.de>
    SPDX-FileCopyrightText: 2007 Oswald Buddenhagen <ossi@kde.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#ifndef _PROCESSLINEMAKER_H_
#define _PROCESSLINEMAKER_H_

#include "utilexport.h"

#include <QObject>
#include <QStringList>

/**
@file processlinemaker.h
Utility objects for process output views.
*/

class QProcess;

/**
Convenience class to catch output of QProcess.
*/

namespace KDevelop {
class ProcessLineMakerPrivate;

class KDEVPLATFORMUTIL_EXPORT ProcessLineMaker : public QObject
{
    Q_OBJECT

public:
    explicit ProcessLineMaker(QObject* parent = nullptr);
    explicit ProcessLineMaker(QProcess* process, QObject* parent = nullptr);

    ~ProcessLineMaker() override;

    /**
     * clears out the internal buffers, this drops any data without
     * emitting the related signal
     */
    void discardBuffers();

    /**
     * Flush the data from the buffers and then clear them.
     * This should be called once when the process has
     * exited to make sure all data that was received from the
     * process is properly converted and emitted.
     *
     * Note: Connecting this class to the process finished signal
     * is not going to work, as the user of this class will do
     * that itself too and possibly delete the process, making
     * it impossible to fetch the last output.
     */
    void flushBuffers();

public Q_SLOTS:
    /**
     * This should be used (instead of hand-crafted code) when
     * you need to do custom things with the process output
     * before feeding it to the linemaker and have it convert
     * it to QString lines.
     * @param buffer the output from the process
     */
    void slotReceivedStdout(const QByteArray& buffer);

    /**
     * This should be used (instead of hand-crafted code) when
     * you need to do custom things with the process error output
     * before feeding it to the linemaker and have it convert
     * it to QString lines.
     * @param buffer the output from the process
     */
    void slotReceivedStderr(const QByteArray& buffer);

Q_SIGNALS:
    /**
     * Emitted whenever the process prints something
     * to its standard output. The output is converted
     * to a QString using fromLocal8Bit() and will
     * be split on '\n'.
     * @param lines the lines that the process printed
     */
    void receivedStdoutLines(const QStringList& lines);

    /**
     * Emitted whenever the process prints something
     * to its error output. The output is converted
     * to a QString using fromLocal8Bit() and will
     * be split on '\n'.
     * @param lines the lines that the process printed
     */
    void receivedStderrLines(const QStringList& lines);

private:
    const QScopedPointer<class ProcessLineMakerPrivate> d_ptr;
    Q_DECLARE_PRIVATE(ProcessLineMaker)
    friend class ProcessLineMakerPrivate;
};

}

#endif