MauiKit Terminal

ksession.h
1/*
2 * This file is part of Konsole QML plugin,
3 * which is a terminal emulator from KDE.
4 *
5 * Copyright 2013 by Dmitry Zagnoyko <hiroshidi@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA.
21 */
22
23#pragma once
24
25#include <QObject>
26
27#include "Session.h"
28
29using namespace Konsole;
30
31/**
32 * @brief The KSession class
33 * Creates and controls the terminal session. This class is exposed to the QML engine as `Session`.
34 *
35 * @note This class is not part of any public API and it is only part of the Terminal QML control implementation
36 */
37class KSession : public QObject
38{
40
41 /**
42 * Allows to select the preferred key binding, by default there is one pre-defined.
43 */
45
46 /**
47 * Set the initial working directory from a local path
48 */
50
51 /**
52 * The session title
53 */
54 Q_PROPERTY(QString title READ getTitle WRITE setTitle NOTIFY titleChanged)
55
56 /**
57 * Allows to change the default shell program, by default bash is used
58 */
60
61 /**
62 * Allows to set the arguments to the default shell program
63 */
65
66 /**
67 * The commands history
68 */
69 Q_PROPERTY(QString history READ getHistory)
70
71 /**
72 * Whether the session has an active process running
73 */
75
76 /**
77 * The name of the current process running
78 */
80
81 /**
82 * The current directory of the session
83 */
85
86 /**
87 * Allows to set the amount of lines to store in the history
88 */
90
91 /**
92 * Whether to monitor when the session has gone silent
93 */
95
96public:
97 KSession(QObject *parent = nullptr);
98 ~KSession();
99
100public:
101 /**
102 * @brief addView
103 * @param display
104 */
105 void addView(TerminalDisplay *display);
106
107 /**
108 * @brief removeView
109 * @param display
110 */
111 void removeView(TerminalDisplay *display);
112
113 int getRandomSeed();
114 QString getKeyBindings();
115
116 /**
117 * @brief Set the custom enviroment variables
118 * @param environment
119 */
120 void setEnvironment(const QStringList & environment);
121
122 /**
123 * @brief Initial working directory
124 * @param dir
125 */
126 void setInitialWorkingDirectory(const QString & dir);
127 QString getInitialWorkingDirectory();
128
129 /**
130 * @brief Text codec, default is UTF-8
131 * @param codec
132 */
133 void setTextCodec(QTextCodec * codec);
134
135 /**
136 * @brief History size for scrolling
137 * @param lines
138 */
139 void setHistorySize(int lines); //infinite if lines < 0
140 int historySize() const;
141
142 QString getHistory() const;
143
144 /**
145 * @brief Sets whether flow control is enabled
146 * @param enabled
147 */
148 void setFlowControlEnabled(bool enabled);
149
150 /**
151 * @brief Returns whether flow control is enabled
152 * @return
153 */
154 bool flowControlEnabled(void);
155
156 /**
157 * Sets whether the flow control warning box should be shown
158 * when the flow control stop key (Ctrl+S) is pressed.
159 */
160 //void setFlowControlWarningEnabled(bool enabled);
161
162 /**
163 * @brief Get all available keyboard bindings
164 * @return
165 */
167
168 /**
169 * @brief Return current key bindings
170 * @return
171 */
173
174 QString getTitle();
175
176 /**
177 * @brief Returns \c true if the session has an active subprocess running in it
178 * spawned from the initial shell.
179 */
180 bool hasActiveProcess() const;
181
182 /**
183 * @brief Returns the name of the terminal's foreground process.
184 */
186
187 /**
188 * @brief Returns the current working directory of the process.
189 */
191
192 /**
193 * @brief setMonitorSilence
194 * @param value
195 */
196 void setMonitorSilence(bool value);
197
198 /**
199 * @brief monitorSilence
200 * @return
201 */
202 bool monitorSilence() const;
203
205 /**
206 * @brief started
207 */
208 void started();
209
210 /**
211 * @brief finished
212 */
213 void finished();
214
215 /**
216 * @brief copyAvailable
217 */
218 void copyAvailable(bool);
219
220 /**
221 * @brief termGetFocus
222 */
224
225 /**
226 * @brief termLostFocus
227 */
229
230 /**
231 * @brief termKeyPressed
232 */
234
235 /**
236 * @brief changedKeyBindings
237 * @param kb
238 */
240
241 /**
242 * @brief titleChanged
243 */
245
246 /**
247 * @brief historySizeChanged
248 */
250
251 /**
252 * @brief initialWorkingDirectoryChanged
253 */
255
256 /**
257 * @brief matchFound
258 * @param startColumn
259 * @param startLine
260 * @param endColumn
261 * @param endLine
262 */
263 void matchFound(int startColumn, int startLine, int endColumn, int endLine);
264
265 /**
266 * @brief noMatchFound
267 */
269
270 /**
271 * @brief hasActiveProcessChanged
272 */
274
275 /**
276 * @brief foregroundProcessNameChanged
277 */
279
280 /**
281 * @brief processHasSilent
282 * @param value
283 */
284 void processHasSilent(bool value);
285
286 /**
287 * @brief bellRequest
288 * @param message
289 */
290 void bellRequest(QString message);
291
292 /**
293 * @brief monitorSilenceChanged
294 */
296
297 /**
298 * @brief currentDirChanged
299 */
301
302 /**
303 * @brief shellProgramChanged
304 */
306
307 /**
308 * @brief argsChanged
309 */
311
312public Q_SLOTS:
313 /**
314 * @brief Set named key binding for the session
315 */
316 void setKeyBindings(const QString & kb);
317
318 /**
319 * @brief setTitle
320 * @param name
321 */
322 void setTitle(QString name);
323
324 /**
325 * @brief startShellProgram
326 */
327 void startShellProgram();
328
329 /**
330 * @brief sendSignal
331 * @param signal
332 * @return
333 */
334 bool sendSignal(int signal);
335
336 /**
337 * @brief Shell program, default is `/bin/bash`
338 * @param progname
339 */
340 void setShellProgram(const QString & progname);
341
342 /**
343 * @brief shellProgram
344 * @return
345 */
346 QString shellProgram() const;
347
348 /**
349 * @brief Shell program args, default is none
350 * @param args
351 */
352 void setArgs(const QStringList &args);
353
354 /**
355 * @brief args
356 * @return
357 */
358 QStringList args() const;
359
360 /**
361 * @brief getShellPID
362 * @return
363 */
364 int getShellPID();
365
366 /**
367 * @brief changeDir
368 * @param dir
369 */
370 void changeDir(const QString & dir);
371
372 /**
373 * @brief Send some text to terminal
374 * @param text
375 */
376 void sendText(QString text);
377
378 /**
379 * @brief Emulate a key press
380 * @param rep
381 * @param key
382 * @param mod
383 */
384 void sendKey(int rep, int key, int mod) const;
385
386 /**
387 * @brief clearScreen
388 */
389 void clearScreen();
390
391 /**
392 * @brief Search history
393 * @param regexp
394 * @param startLine
395 * @param startColumn
396 * @param forwards
397 */
398 void search(const QString &regexp, int startLine = 0, int startColumn = 0, bool forwards = true );
399
400 void selectionChanged(bool textSelected);
401
402protected Q_SLOTS:
403 void sessionFinished();
404
405private Q_SLOTS:
406 std::unique_ptr<Session> createSession(QString name);
407
408private:
409 QString _initialWorkingDirectory;
410 std::unique_ptr<Session> m_session;
411 QString m_processName;
412};
The KSession class Creates and controls the terminal session.
Definition ksession.h:38
void hasActiveProcessChanged()
hasActiveProcessChanged
QString history
The commands history.
Definition ksession.h:69
void clearScreen()
clearScreen
Definition ksession.cpp:354
QString kbScheme
Allows to select the preferred key binding, by default there is one pre-defined.
Definition ksession.h:44
void titleChanged()
titleChanged
void removeView(TerminalDisplay *display)
removeView
Definition ksession.cpp:180
void termLostFocus()
termLostFocus
void startShellProgram()
startShellProgram
Definition ksession.cpp:195
void addView(TerminalDisplay *display)
addView
Definition ksession.cpp:175
void search(const QString &regexp, int startLine=0, int startColumn=0, bool forwards=true)
Search history.
Definition ksession.cpp:359
bool sendSignal(int signal)
sendSignal
Definition ksession.cpp:205
void noMatchFound()
noMatchFound
void initialWorkingDirectoryChanged()
initialWorkingDirectoryChanged
QString keyBindings()
Return current key bindings.
Definition ksession.cpp:393
QString currentDir
The current directory of the session.
Definition ksession.h:84
QString initialWorkingDirectory
Set the initial working directory from a local path.
Definition ksession.h:49
void setTitle(QString name)
setTitle
Definition ksession.cpp:121
void changedKeyBindings(QString kb)
changedKeyBindings
QString foregroundProcessName
The name of the current process running.
Definition ksession.h:79
void setInitialWorkingDirectory(const QString &dir)
Initial working directory.
Definition ksession.cpp:266
void changeDir(const QString &dir)
changeDir
Definition ksession.cpp:220
void setArgs(const QStringList &args)
Shell program args, default is none.
Definition ksession.cpp:282
void setShellProgram(const QString &progname)
Shell program, default is /bin/bash
Definition ksession.cpp:252
void monitorSilenceChanged()
monitorSilenceChanged
void bellRequest(QString message)
bellRequest
void sendKey(int rep, int key, int mod) const
Emulate a key press.
Definition ksession.cpp:337
bool hasActiveProcess
Whether the session has an active process running.
Definition ksession.h:74
int historySize
Allows to set the amount of lines to store in the history.
Definition ksession.h:89
void setEnvironment(const QStringList &environment)
Set the custom enviroment variables.
Definition ksession.cpp:247
QString title
The session title.
Definition ksession.h:54
void matchFound(int startColumn, int startLine, int endColumn, int endLine)
matchFound
void shellProgramChanged()
shellProgramChanged
void setKeyBindings(const QString &kb)
Set named key binding for the session.
Definition ksession.cpp:377
QStringList args() const
args
Definition ksession.cpp:427
int getShellPID()
getShellPID
Definition ksession.cpp:215
void currentDirChanged()
currentDirChanged
void termGetFocus()
termGetFocus
QStringList shellProgramArgs
Allows to set the arguments to the default shell program.
Definition ksession.h:64
void setHistorySize(int lines)
History size for scrolling.
Definition ksession.cpp:296
void setMonitorSilence(bool value)
setMonitorSilence
Definition ksession.cpp:107
void finished()
finished
void setFlowControlEnabled(bool enabled)
Sets whether flow control is enabled.
Definition ksession.cpp:367
void processHasSilent(bool value)
processHasSilent
void termKeyPressed(QKeyEvent *, bool)
termKeyPressed
void started()
started
void foregroundProcessNameChanged()
foregroundProcessNameChanged
bool flowControlEnabled(void)
Returns whether flow control is enabled.
Definition ksession.cpp:372
static QStringList availableKeyBindings()
Sets whether the flow control warning box should be shown when the flow control stop key (Ctrl+S) is ...
Definition ksession.cpp:388
void argsChanged()
argsChanged
void setTextCodec(QTextCodec *codec)
Text codec, default is UTF-8.
Definition ksession.cpp:291
void historySizeChanged()
historySizeChanged
void copyAvailable(bool)
copyAvailable
void sendText(QString text)
Send some text to terminal.
Definition ksession.cpp:332
QString shellProgram
Allows to change the default shell program, by default bash is used.
Definition ksession.h:59
bool monitorSilence
Whether to monitor when the session has gone silent.
Definition ksession.h:94
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition Session.h:54
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
Q_OBJECTQ_OBJECT
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
Q_SLOTSQ_SLOTS
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Aug 30 2024 11:51:42 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.