File: TerminalSession.h

package info (click to toggle)
qmlkonsole 25.12.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,680 kB
  • sloc: cpp: 12,794; xml: 345; makefile: 3; sh: 1
file content (178 lines) | stat: -rw-r--r-- 4,923 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
    This file is part of Konsole QML plugin,
    which is a terminal emulator from KDE.

    SPDX-FileCopyrightText: 2013 Dmitry Zagnoyko <hiroshidi@gmail.com>

    SPDX-License-Identifier: GPL-2.0-or-later

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/

#ifndef KSESSION_H
#define KSESSION_H

#include <QObject>

// Konsole
#include "Session.h"

using namespace Konsole;

class TerminalSession : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QString kbScheme READ getKeyBindings WRITE setKeyBindings NOTIFY changedKeyBindings)
    Q_PROPERTY(QString initialWorkingDirectory READ getInitialWorkingDirectory WRITE setInitialWorkingDirectory NOTIFY initialWorkingDirectoryChanged)
    Q_PROPERTY(QString title READ getTitle WRITE setTitle NOTIFY titleChanged)
    Q_PROPERTY(QString shellProgram READ shellProgram WRITE setShellProgram NOTIFY shellProgramChanged)
    Q_PROPERTY(QStringList shellProgramArgs READ args WRITE setArgs NOTIFY argsChanged)
    Q_PROPERTY(QString history READ getHistory)
    Q_PROPERTY(bool hasActiveProcess READ hasActiveProcess)
    Q_PROPERTY(QString foregroundProcessName READ foregroundProcessName)
    Q_PROPERTY(QString currentDir READ currentDir)

public:
    TerminalSession(QObject *parent = nullptr);
    ~TerminalSession() override;

public:
    // bool setup();
    void addView(TerminalDisplay *display);
    void removeView(TerminalDisplay *display);

    int getRandomSeed();
    QString getKeyBindings();

    // look-n-feel, if you don`t like defaults

    // environment
    void setEnvironment(const QStringList &environment);

    // Initial working directory
    void setInitialWorkingDirectory(const QString &dir);
    QString getInitialWorkingDirectory();

    // Text codec, default is UTF-8
    void setTextCodec(QTextCodec *codec);

    // History size for scrolling
    void setHistorySize(int lines); // infinite if lines < 0
    int historySize() const;

    QString getHistory() const;

    // Sets whether flow control is enabled
    void setFlowControlEnabled(bool enabled);

    // Returns whether flow control is enabled
    bool flowControlEnabled(void);

    /**
     * Sets whether the flow control warning box should be shown
     * when the flow control stop key (Ctrl+S) is pressed.
     */
    // void setFlowControlWarningEnabled(bool enabled);

    /*! Get all available keyboard bindings
     */
    static QStringList availableKeyBindings();

    //! Return current key bindings
    QString keyBindings();

    QString getTitle();

    /**
     * Returns \c true if the session has an active subprocess running in it
     * spawned from the initial shell.
     */
    bool hasActiveProcess() const;

    /**
     * Returns the name of the terminal's foreground process.
     */
    QString foregroundProcessName();

    /**
     * Returns the current working directory of the process.
     */
    QString currentDir();

Q_SIGNALS:
    void started();
    void finished();
    void copyAvailable(bool);

    void termGetFocus();
    void termLostFocus();

    void termKeyPressed(QKeyEvent *, bool);

    void changedKeyBindings(QString kb);

    void titleChanged();

    void historySizeChanged();

    void initialWorkingDirectoryChanged();

    void matchFound(int startColumn, int startLine, int endColumn, int endLine);
    void noMatchFound();

    void shellProgramChanged();
    void argsChanged();

public Q_SLOTS:
    /*! Set named key binding for given widget
     */
    void setKeyBindings(const QString &kb);
    void setTitle(QString name);

    void startShellProgram();

    bool sendSignal(int signal);

    //  Shell program, default is /bin/bash
    QString shellProgram() const;
    void setShellProgram(const QString &progname);

    // Shell program args, default is none
    QStringList args() const;
    void setArgs(const QStringList &args);

    int getShellPID();
    void changeDir(const QString &dir);

    // Send some text to terminal
    void sendText(QString text);
    // Send some text to terminal
    void sendKey(int rep, int key, int mod) const;

    void clearScreen();

    // Search history
    void search(const QString &regexp, int startLine = 0, int startColumn = 0, bool forwards = true);

    void selectionChanged(bool textSelected);

protected Q_SLOTS:
    void sessionFinished();

private Q_SLOTS:
    std::unique_ptr<Session> createSession(QString name);

private:
    QString _initialWorkingDirectory;
    std::unique_ptr<Session> m_session;
};

#endif // KSESSION_H