MauiKit Terminal

Session.cpp
1/*
2 This file is part of Konsole
3
4 SPDX-FileCopyrightText: 2006-2007 Robert Knight <robertknight@gmail.com>
5 SPDX-FileCopyrightText: 1997, 1998 Lars Doelle <lars.doelle@on-line.de>
6
7 Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
8
9 SPDX-License-Identifier: GPL-2.0-or-later
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
20*/
21
22// Own
23#include "Session.h"
24
25// Standard
26#include <csignal>
27#include <cstdlib>
28
29// Qt
30#include <QApplication>
31#include <QDir>
32#include <QFile>
33#include <QRegExp>
34#include <QRegularExpression>
35#include <QStringList>
36#include <QtDebug>
37
38#include "Pty.h"
39// #include "kptyprocess.h"
40#include "ShellCommand.h"
41#include "TerminalDisplay.h"
42#include "Vt102Emulation.h"
43#include "kptydevice.h"
44
45// QMLTermWidget
46#include <QQuickWindow>
47
48using namespace Konsole;
49
50int Session::lastSessionId = 0;
51
52Session::Session(QObject *parent)
53 : QObject(parent)
54 , _shellProcess(nullptr)
55 , _emulation(nullptr)
56 , _monitorActivity(false)
57 , _monitorSilence(false)
58 , _notifiedActivity(false)
59 , _autoClose(true)
60 , _wantedClose(false)
61 , _silenceSeconds(10)
62 , _isTitleChanged(false)
63 , _addToUtmp(false) // disabled by default because of a bug encountered on certain systems
64 // which caused Konsole to hang when closing a tab and then opening a new
65 // one. A 'QProcess destroyed while still running' warning was being
66 // printed to the terminal. Likely a problem in KPty::logout()
67 // or KPty::login() which uses a QProcess to start /usr/bin/utempter
68 , _flowControl(true)
69 , _fullScripting(false)
70 , _sessionId(0)
71 , _hasDarkBackground(false)
72 , _foregroundPid(0)
73{
74 _sessionId = ++lastSessionId;
75
76 // create teletype for I/O with shell process
77 _shellProcess = std::make_unique<Pty>();
78 ptySlaveFd = _shellProcess->pty()->slaveFd();
79
80 // create emulation backend
81 _emulation = std::make_unique<Vt102Emulation>();
82
83 connect(_emulation.get(), &Emulation::titleChanged, this, &Session::setUserTitle);
84 connect(_emulation.get(), &Emulation::stateSet, this, &Session::activityStateSet);
87
88 connect(_emulation.get(), &Emulation::imageResizeRequest, this, &Session::onEmulationSizeChange);
89 connect(_emulation.get(), &Emulation::imageSizeChanged, this, &Session::onViewSizeChange);
91
92 // connect teletype to emulation backend
93 _shellProcess->setUtf8Mode(_emulation->utf8());
94
95 connect(_shellProcess.get(), &Pty::receivedData, this, &Session::onReceiveBlock);
96 connect(_emulation.get(), &Emulation::sendData, _shellProcess.get(), &Pty::sendData);
97 connect(_emulation.get(), &Emulation::useUtf8Request, _shellProcess.get(), &Pty::setUtf8Mode);
98
99 connect(_shellProcess.get(), qOverload<int, QProcess::ExitStatus>(&QProcess::finished), this, &Session::done);
100 // not in kprocess anymore connect( _shellProcess,SIGNAL(done(int)), this, SLOT(done(int)) );
101
102 // setup timer for monitoring session activity
103 _monitorTimer = new QTimer(this);
104 _monitorTimer->setSingleShot(true);
105 connect(_monitorTimer, &QTimer::timeout, this, &Session::monitorTimerDone);
106}
107
108WId Session::windowId() const
109{
110 // On Qt5, requesting window IDs breaks QQuickWidget and the likes,
111 // for example, see the following bug reports:
112 // https://bugreports.qt.io/browse/QTBUG-40765
113 // https://codereview.qt-project.org/#/c/94880/
114 return 0;
115}
116
117void Session::setDarkBackground(bool darkBackground)
118{
119 _hasDarkBackground = darkBackground;
120}
122{
123 return _hasDarkBackground;
124}
126{
127 return _shellProcess->state() == QProcess::Running;
128}
129
130void Session::setCodec(QTextCodec *codec) const
131{
132 emulation()->setCodec(codec);
133}
134
135void Session::setProgram(const QString &program)
136{
137 _program = ShellCommand::expand(program);
138}
140{
141 _initialWorkingDir = ShellCommand::expand(dir);
142}
143void Session::setArguments(const QStringList &arguments)
144{
145 _arguments = ShellCommand::expand(arguments);
146}
147
149{
150 return _view;
151}
152
154{
155 Q_ASSERT(!_view);
156 _view = widget;
157
158 if (_emulation != nullptr) {
159 // connect emulation - view signals and slots
162 connect(widget, &TerminalDisplay::sendStringToEmu, _emulation.get(), [this](auto string) {
163 _emulation->sendString(string);
164 });
165
166 // allow emulation to notify view when the foreground process
167 // indicates whether or not it is interested in mouse signals
169
170 widget->setUsesMouse(_emulation->programUsesMouse());
171
172 connect(_emulation.get(), &Emulation::programBracketedPasteModeChanged, widget, &TerminalDisplay::setBracketedPasteMode);
173
174 widget->setBracketedPasteMode(_emulation->programBracketedPasteMode());
175
176 widget->setScreenWindow(_emulation->createWindow());
177 }
178
179 // connect view signals and slots
180 QObject::connect(widget, &TerminalDisplay::changedContentSizeSignal, this, &Session::onViewSizeChange);
181
182 QObject::connect(widget, &QObject::destroyed, this, &Session::viewDestroyed);
183 // slot for close
184 // QObject::connect(this, SIGNAL(finished()), widget, SLOT(close()));
185}
186
187void Session::viewDestroyed(QObject *view)
188{
190 Q_UNUSED(display)
191
192 Q_ASSERT(_view);
193
194 view = nullptr;
195}
196
198{
199 _view = nullptr;
200
201 disconnect(widget, nullptr, this, nullptr);
202
203 if (_emulation != nullptr) {
204 // disconnect
205 // - key presses signals from widget
206 // - mouse activity signals from widget
207 // - string sending signals from widget
208 //
209 // ... and any other signals connected in addView()
210 disconnect(widget, nullptr, _emulation.get(), nullptr);
211
212 // disconnect state change signals emitted by emulation
213 disconnect(_emulation.get(), nullptr, widget, nullptr);
214 }
215
216 // close the session automatically when the last view is removed
217 close();
218}
219
221{
222 // Upon a KPty error, there is no description on what that error was...
223 // Check to see if the given program is executable.
224
225 /* ok iam not exactly sure where _program comes from - however it was set to /bin/bash on my system
226 * Thats bad for BSD as its /usr/local/bin/bash there - its also bad for arch as its /usr/bin/bash there too!
227 * So i added a check to see if /bin/bash exists - if no then we use $SHELL - if that does not exist either, we fall back to /bin/sh
228 * As far as i know /bin/sh exists on every unix system.. You could also just put some ifdef __FREEBSD__ here but i think these 2 filechecks are worth
229 * their computing time on any system - especially with the problem on arch linux beeing there too.
230 */
232 // if 'exec' is not specified, fall back to default shell. if that
233 // is not set then fall back to /bin/sh
234
235 // here we expect full path. If there is no fullpath let's expect it's
236 // a custom shell (eg. python, etc.) available in the PATH.
237 if (exec.startsWith(QLatin1Char('/')) || exec.isEmpty()) {
238 const QString defaultShell{QLatin1String("/bin/sh")};
239
240 QFile excheck(exec);
241 if (exec.isEmpty() || !excheck.exists()) {
242 exec = QString::fromLocal8Bit(qgetenv("SHELL"));
243 }
244 excheck.setFileName(exec);
245
246 if (exec.isEmpty() || !excheck.exists()) {
247 qWarning() << "Neither default shell nor $SHELL is set to a correct path. Fallback to" << defaultShell;
248 exec = defaultShell;
249 }
250 }
251
253 if (!_initialWorkingDir.isEmpty()) {
254 _shellProcess->setWorkingDirectory(_initialWorkingDir);
255 } else {
256 _shellProcess->setWorkingDirectory(cwd);
257 }
258
259 _shellProcess->setFlowControlEnabled(_flowControl);
260 _shellProcess->setEraseChar(_emulation->eraseChar());
261
262 // this is not strictly accurate use of the COLORFGBG variable. This does not
263 // tell the terminal exactly which colors are being used, but instead approximates
264 // the color scheme as "black on white" or "white on black" depending on whether
265 // the background color is deemed dark or not
266 QString backgroundColorHint = _hasDarkBackground ? QLatin1String("COLORFGBG=15;0") : QLatin1String("COLORFGBG=0;15");
267
268 /* if we do all the checking if this shell exists then we use it ;)
269 * Dont know about the arguments though.. maybe youll need some more checking im not sure
270 * However this works on Arch and FreeBSD now.
271 */
272 int result = _shellProcess->start(exec, _arguments, _environment << backgroundColorHint);
273
274 if (result < 0) {
275 qDebug() << "CRASHED! result: " << result;
276 return;
277 }
278
279 _shellProcess->setWriteable(false); // We are reachable via kwrited.
280 Q_EMIT started();
281}
282
284{
285 _shellProcess->setFlowControlEnabled(_flowControl);
286 _shellProcess->setEraseChar(_emulation->eraseChar());
287 _shellProcess->setWriteable(false);
288
289 // disconnet send data from emulator to internal terminal process
290 disconnect(_emulation.get(), &Emulation::sendData, _shellProcess.get(), &Pty::sendData);
291
292 Q_EMIT started();
293}
294
295void Session::setUserTitle(int what, const QString &caption)
296{
297 // set to true if anything is actually changed (eg. old _nameTitle != new _nameTitle )
298 bool modified = false;
299
300 // (btw: what=0 changes _userTitle and icon, what=1 only icon, what=2 only _nameTitle
301 if ((what == 0) || (what == 2)) {
302 _isTitleChanged = true;
303 if (_userTitle != caption) {
304 _userTitle = caption;
305 modified = true;
306 }
307 }
308
309 if ((what == 0) || (what == 1)) {
310 _isTitleChanged = true;
311 if (_iconText != caption) {
312 _iconText = caption;
313 modified = true;
314 }
315 }
316
317 if (what == 11) {
318 QString colorString = caption.section(QLatin1Char(';'), 0, 0);
319 // qDebug() << __FILE__ << __LINE__ << ": setting background colour to " << colorString;
320 QColor backColor = QColor(colorString);
321 if (backColor.isValid()) { // change color via \033]11;Color\007
322 if (backColor != _modifiedBackground) {
323 _modifiedBackground = backColor;
324
325 // bail out here until the code to connect the terminal display
326 // to the changeBackgroundColor() signal has been written
327 // and tested - just so we don't forget to do this.
328 Q_ASSERT(0);
329
331 }
332 }
333 }
334
335 if (what == 30) {
336 _isTitleChanged = true;
337 if (_nameTitle != caption) {
338 setTitle(Session::NameRole, caption);
339 return;
340 }
341 }
342
343 if (what == 31) {
344 QString cwd = caption;
347 }
348
349 // change icon via \033]32;Icon\007
350 if (what == 32) {
351 _isTitleChanged = true;
352 if (_iconName != caption) {
353 _iconName = caption;
354
355 modified = true;
356 }
357 }
358
359 if (what == 50) {
361 return;
362 }
363
364 if (modified) {
366 }
367}
368
370{
371 return _userTitle;
372}
373
375{
376 if (context == LocalTabTitle) {
377 _localTabTitleFormat = format;
378 } else if (context == RemoteTabTitle) {
379 _remoteTabTitleFormat = format;
380 }
381}
383{
384 if (context == LocalTabTitle) {
385 return _localTabTitleFormat;
386 } else if (context == RemoteTabTitle) {
387 return _remoteTabTitleFormat;
388 }
389
390 return QString();
391}
392
393void Session::monitorTimerDone()
394{
395 // FIXME: The idea here is that the notification popup will appear to tell the user than output from
396 // the terminal has stopped and the popup will disappear when the user activates the session.
397 //
398 // This breaks with the addition of multiple views of a session. The popup should disappear
399 // when any of the views of the session becomes active
400
401 // FIXME: Make message text for this notification and the activity notification more descriptive.
402 if (_monitorSilence) {
403 Q_EMIT silence();
404 Q_EMIT stateChanged(NOTIFYSILENCE);
405 } else {
406 Q_EMIT stateChanged(NOTIFYNORMAL);
407 }
408
409 _notifiedActivity = false;
410}
411
412void Session::activityStateSet(int state)
413{
414 if (state == NOTIFYBELL) {
415 Q_EMIT bellRequest(tr("Bell in session '%1'").arg(_nameTitle));
416 } else if (state == NOTIFYACTIVITY) {
417 if (_monitorSilence) {
418 _monitorTimer->start(_silenceSeconds * 1000);
419 }
420
421 if (_monitorActivity) {
422 // FIXME: See comments in Session::monitorTimerDone()
423 if (!_notifiedActivity) {
424 _notifiedActivity = true;
425 Q_EMIT activity();
426 }
427 }
428 }
429
430 if (state == NOTIFYACTIVITY && !_monitorActivity) {
431 state = NOTIFYNORMAL;
432 }
433 if (state == NOTIFYSILENCE && !_monitorSilence) {
434 state = NOTIFYNORMAL;
435 }
436
437 Q_EMIT stateChanged(state);
438}
439
440void Session::onViewSizeChange(int /*height*/, int /*width*/)
441{
442 updateTerminalSize();
443}
444void Session::onEmulationSizeChange(QSize size)
445{
446 setSize(size);
447}
448
449void Session::updateTerminalSize()
450{
451 // backend emulation must have a _terminal of at least 1 column x 1 line in size
452 _emulation->setImageSize(_view->lines(), _view->columns());
453 _shellProcess->setWindowSize(_view->columns(), _view->lines(), _view->width(), _view->height());
454}
455
457{
458 // attempt to get the shell process to redraw the display
459 //
460 // this requires the program running in the shell
461 // to cooperate by sending an update in response to
462 // a window size change
463 //
464 // the window size is changed twice, first made slightly larger and then
465 // resized back to its normal size so that there is actually a change
466 // in the window size (some shells do nothing if the
467 // new and old sizes are the same)
468 //
469 // if there is a more 'correct' way to do this, please
470 // send an email with method or patches to konsole-devel@kde.org
471
472 const QSize existingSize = _shellProcess->windowSize();
473 const QSize existingPixelSize = _shellProcess->pixelSize();
474 _shellProcess->setWindowSize(existingSize.height(), existingSize.width() + 1, existingPixelSize.height(), existingPixelSize.width());
475 _shellProcess->setWindowSize(existingSize.height(), existingSize.width(), existingPixelSize.height(), existingPixelSize.width());
476}
477
478bool Session::sendSignal(int signal)
479{
480 int result = ::kill(static_cast<pid_t>(_shellProcess->processId()), signal);
481
482 if (result == 0) {
483 _shellProcess->waitForFinished();
484 return true;
485 } else
486 return false;
487}
488
490{
491 _autoClose = true;
492 _wantedClose = true;
493 if (_shellProcess->state() != QProcess::Running || !sendSignal(SIGHUP)) {
494 // Forced close.
496 }
497}
498
499void Session::sendText(const QString &text) const
500{
501 _emulation->sendText(text);
502}
503
504void Session::sendKeyEvent(QKeyEvent *e) const
505{
506 _emulation->sendKeyEvent(e, false);
507}
508
509Session::~Session() = default;
510
512{
513 _profileKey = key;
515}
516
518{
519 return _profileKey;
520}
521
522void Session::done(int exitStatus)
523{
524 if (!_autoClose) {
525 _userTitle = QString::fromLatin1("This session is done. Finished");
527 return;
528 }
529
530 // message is not being used. But in the original kpty.cpp file
531 // (https://cgit.kde.org/kpty.git/) it's part of a notification.
532 // So, we make it translatable, hoping that in the future it will
533 // be used in some kind of notification.
534 QString message;
535 if (!_wantedClose || exitStatus != 0) {
536 if (_shellProcess->exitStatus() == QProcess::NormalExit) {
537 message = tr("Session '%1' exited with status %2.").arg(_nameTitle).arg(exitStatus);
538 } else {
539 message = tr("Session '%1' crashed.").arg(_nameTitle);
540 }
541 }
542
543 if (!_wantedClose && _shellProcess->exitStatus() != QProcess::NormalExit)
544 message = tr("Session '%1' exited unexpectedly.").arg(_nameTitle);
545 else
547}
548
550{
551 return _emulation.get();
552}
553
554QString Session::keyBindings() const
555{
556 return _emulation->keyBindings();
557}
558
560{
561 return _environment;
562}
563
564void Session::setEnvironment(const QStringList &environment)
565{
566 _environment = environment;
567}
568
570{
571 return _sessionId;
572}
573
575{
576 _emulation->setKeyBindings(id);
577}
578
579void Session::setTitle(TitleRole role, const QString &newTitle)
580{
581 if (title(role) != newTitle) {
582 if (role == NameRole) {
583 _nameTitle = newTitle;
584 } else if (role == DisplayedTitleRole) {
585 _displayTitle = newTitle;
586 }
587
589 }
590}
591
593{
594 if (role == NameRole) {
595 return _nameTitle;
596 } else if (role == DisplayedTitleRole) {
597 return _displayTitle;
598 } else {
599 return QString();
600 }
601}
602
603void Session::setIconName(const QString &iconName)
604{
605 if (iconName != _iconName) {
606 _iconName = iconName;
608 }
609}
610
611void Session::setIconText(const QString &iconText)
612{
613 _iconText = iconText;
614 // kDebug(1211)<<"Session setIconText " << _iconText;
615}
616
618{
619 return _iconName;
620}
621
623{
624 return _iconText;
625}
626
628{
629 return _isTitleChanged;
630}
631
632void Session::setHistoryType(const HistoryType &hType)
633{
634 _emulation->setHistory(hType);
635}
636
637const HistoryType &Session::historyType() const
638{
639 return _emulation->history();
640}
641
643{
644 _emulation->clearHistory();
645}
646
648{
649 return _arguments;
650}
651
653{
654 return _program;
655}
656
657// unused currently
659{
660 return _monitorActivity;
661}
662// unused currently
664{
665 return _monitorSilence;
666}
667
669{
670 _monitorActivity = _monitor;
671 _notifiedActivity = false;
672
673 activityStateSet(NOTIFYNORMAL);
674}
675
676void Session::setMonitorSilence(bool _monitor)
677{
678 if (_monitorSilence == _monitor) {
679 return;
680 }
681
682 _monitorSilence = _monitor;
683 if (_monitorSilence) {
684 _monitorTimer->start(_silenceSeconds * 1000);
685 } else {
686 _monitorTimer->stop();
687 }
688
689 activityStateSet(NOTIFYNORMAL);
690}
691
693{
694 _silenceSeconds = seconds;
695 if (_monitorSilence) {
696 _monitorTimer->start(_silenceSeconds * 1000);
697 }
698}
699
701{
702 _addToUtmp = set;
703}
704
706{
707 if (_flowControl == enabled) {
708 return;
709 }
710
711 _flowControl = enabled;
712
713 if (_shellProcess) {
714 _shellProcess->setFlowControlEnabled(_flowControl);
715 }
716
718}
720{
721 return _flowControl;
722}
723
724void Session::onReceiveBlock(const char *buf, int len)
725{
726 _emulation->receiveData(buf, len);
728}
729
730QSize Session::size()
731{
732 return _emulation->imageSize();
733}
734
735void Session::setSize(const QSize &size)
736{
737 if ((size.width() <= 1) || (size.height() <= 1)) {
738 return;
739 }
740
741 Q_EMIT resizeRequest(size);
742}
744{
745 return _shellProcess->foregroundProcessGroup();
746}
747
749{
750 QString name;
751
752 if (updateForegroundProcessInfo()) {
753 bool ok = false;
754 name = _foregroundProcessInfo->name(&ok);
755 if (!ok)
756 name.clear();
757 }
758
759 return name;
760}
761
763{
764 QString path;
765 if (updateForegroundProcessInfo()) {
766 bool ok = false;
767 path = _foregroundProcessInfo->currentDir(&ok);
768 if (!ok)
769 path.clear();
770 }
771 return path;
772}
773
774bool Session::updateForegroundProcessInfo()
775{
776 Q_ASSERT(_shellProcess);
777
778 const int foregroundPid = _shellProcess->foregroundProcessGroup();
779 if (foregroundPid != _foregroundPid) {
780 _foregroundProcessInfo.reset();
781 _foregroundProcessInfo = ProcessInfo::newInstance(foregroundPid);
782 _foregroundPid = foregroundPid;
783 }
784
785 if (_foregroundProcessInfo) {
786 _foregroundProcessInfo->update();
787 return _foregroundProcessInfo->isValid();
788 } else {
789 return false;
790 }
791}
792
793int Session::processId() const
794{
795 return static_cast<int>(_shellProcess->processId());
796}
798{
799 return ptySlaveFd;
800}
801
803 : _masterMode(0)
804{
805}
807{
808 // disconnect all
809 connectAll(false);
810}
812{
813 return _masterMode;
814}
816{
817 return _sessions.keys();
818}
820{
821 return _sessions[session];
822}
823
825{
826 _sessions.insert(session, false);
827
828 const auto masterSessions = masters();
829 for (const auto master : masterSessions) {
830 connectPair(master, session);
831 }
832}
833
835{
836 setMasterStatus(session, false);
837
838 const auto masterSessions = masters();
839 for (const auto master : masterSessions) {
840 disconnectPair(master, session);
841 }
842
843 _sessions.remove(session);
844}
845
847{
848 _masterMode = mode;
849
850 connectAll(false);
851 connectAll(true);
852}
853
854QList<Session *> SessionGroup::masters() const
855{
856 return _sessions.keys(true);
857}
858
859void SessionGroup::connectAll(bool connect)
860{
861 const auto masterSessions = masters();
862 for (const auto master : masterSessions) {
863 const auto other = _sessions.keys();
864
865 for (const auto other : other) {
866 if (other != master) {
867 if (connect) {
868 connectPair(master, other);
869 } else {
870 disconnectPair(master, other);
871 }
872 }
873 }
874 }
875}
876
877void SessionGroup::setMasterStatus(Session *session, bool master)
878{
879 bool wasMaster = _sessions[session];
880 _sessions[session] = master;
881
882 if (wasMaster == master) {
883 return;
884 }
885
886 const auto otherSessions = _sessions.keys();
887 for (const auto other : otherSessions) {
888 if (other != session) {
889 if (master) {
890 connectPair(session, other);
891 } else {
892 disconnectPair(session, other);
893 }
894 }
895 }
896}
897
898void SessionGroup::connectPair(Session *master, Session *other) const
899{
900 // qDebug() << k_funcinfo;
901
902 if (_masterMode & CopyInputToAll) {
903 qDebug() << "Connection session " << master->nameTitle() << "to" << other->nameTitle();
904
906 }
907}
908void SessionGroup::disconnectPair(Session *master, Session *other) const
909{
910 // qDebug() << k_funcinfo;
911
912 if (_masterMode & CopyInputToAll) {
913 qDebug() << "Disconnecting session " << master->nameTitle() << "from" << other->nameTitle();
914
915 disconnect(master->emulation(), &Emulation::sendData, other->emulation(), &Emulation::sendString);
916 }
917}
918
919// #include "moc_Session.cpp"
Base class for terminal emulation back-ends.
Definition Emulation.h:120
virtual void sendMouseEvent(int buttons, int column, int line, int eventType)
Converts information about a mouse event into an xterm-compatible escape sequence and emits the chara...
void imageSizeChanged(int lineCount, int columnCount)
Emitted when the program running in the terminal changes the screen size.
void programUsesMouseChanged(bool usesMouse)
This is emitted when the program running in the shell indicates whether or not it is interested in mo...
void imageResizeRequest(const QSize &sizz)
Emitted after receiving the escape sequence which asks to change the terminal emulator's size.
void profileChangeCommandReceived(const QString &text)
Emitted when the terminal program requests to change various properties of the terminal display.
void changeTabTextColorRequest(int color)
Requests that the color of the text used to represent the tabs associated with this emulation be chan...
void stateSet(int state)
Emitted when the activity state of the emulation is set.
void titleChanged(int title, const QString &newTitle)
Emitted when the program running in the terminal wishes to update the session's title.
virtual void sendKeyEvent(QKeyEvent *, bool fromPaste)
Interprets a key press event and emits the sendData() signal with the resulting character stream.
void cursorChanged(KeyboardCursorShape cursorShape, bool blinkingCursorEnabled)
Emitted when the cursor shape or its blinking state is changed via DECSCUSR sequences.
void sendData(const char *data, int len)
Emitted when a buffer of data is ready to send to the standard input of the terminal.
void useUtf8Request(bool)
Requests that the pty used by the terminal process be set to UTF 8 mode.
void setCodec(const QTextCodec *)
Sets the codec used to decode incoming characters.
virtual void sendString(const char *string, int length=-1)=0
Sends a string of characters to the foreground terminal process.
static std::unique_ptr< ProcessInfo > newInstance(int pid, bool readEnvironment=false)
Constructs a new instance of a suitable ProcessInfo sub-class for the current platform which provides...
void receivedData(const char *buffer, int length)
Emitted when a new block of data is received from the teletype.
void sendData(const QByteArray &data)
Sends data to the process currently controlling the teletype ( whose id is returned by foregroundProc...
Definition Pty.cpp:78
void setUtf8Mode(bool on)
Put the pty into UTF-8 mode on systems which support it.
Definition Pty.cpp:162
SessionGroup()
Constructs an empty session group.
Definition Session.cpp:802
void setMasterStatus(Session *session, bool master)
Sets whether a particular session is a master within the group.
Definition Session.cpp:877
QList< Session * > sessions() const
Returns the list of sessions currently in the group.
Definition Session.cpp:815
@ CopyInputToAll
Any input key presses in the master sessions are sent to all sessions in the group.
Definition Session.h:632
~SessionGroup() override
Destroys the session group and removes all connections between master and slave sessions.
Definition Session.cpp:806
void removeSession(Session *session)
Removes a session from the group.
Definition Session.cpp:834
void addSession(Session *session)
Adds a session to the group.
Definition Session.cpp:824
void setMasterMode(int mode)
Specifies which activity in the group's master sessions is propagated to all sessions in the group.
Definition Session.cpp:846
bool masterStatus(Session *session) const
Returns the master status of a session.
Definition Session.cpp:819
int masterMode() const
Returns a bitwise OR of the active MasterMode flags for this group.
Definition Session.cpp:811
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition Session.h:54
QString tabTitleFormat(TabTitleContext context) const
Returns the format used by this session for tab titles.
Definition Session.cpp:382
void started()
Emitted when the terminal process starts.
QString title(TitleRole role) const
Returns the session's title for the specified role.
Definition Session.cpp:592
void receivedData(const QString &text)
Emitted when output is received from the terminal process.
bool isRunning() const
Returns true if the session is currently running.
Definition Session.cpp:125
void setIconName(const QString &iconName)
Sets the name of the icon associated with this session.
Definition Session.cpp:603
void close()
Closes the terminal session.
Definition Session.cpp:489
int sessionId() const
Returns the unique ID for this session.
Definition Session.cpp:569
bool flowControlEnabled() const
Returns whether flow control is enabled for this terminal session.
Definition Session.cpp:719
TabTitleContext
This enum describes the contexts for which separate tab title formats may be specified.
Definition Session.h:153
@ LocalTabTitle
Default tab title format.
Definition Session.h:155
@ RemoteTabTitle
Tab title format used session currently contains a connection to a remote computer (via SSH)
Definition Session.h:160
void setMonitorSilenceSeconds(int seconds)
See setMonitorSilence()
Definition Session.cpp:692
void run()
Starts the terminal session.
Definition Session.cpp:220
void setProgram(const QString &program)
Sets the program to be executed when run() is called.
Definition Session.cpp:135
QString userTitle() const
Return the session title set by the user (ie.
Definition Session.cpp:369
QString foregroundProcessName()
Returns the name of the terminal's foreground process.
Definition Session.cpp:748
QString profileKey() const
Returns the profile key associated with this session.
Definition Session.cpp:517
bool isMonitorSilence() const
Returns true if monitoring for inactivity (silence) in the session is enabled.
Definition Session.cpp:663
void finished()
Emitted when the terminal process exits.
void setCodec(QTextCodec *codec) const
Sets the text codec used by this session's terminal emulation.
Definition Session.cpp:130
void setHistoryType(const HistoryType &type)
Sets the type of history store used by this session.
Definition Session.cpp:632
QString iconName() const
Returns the name of the icon associated with this session.
Definition Session.cpp:617
void setDarkBackground(bool darkBackground)
Sets whether the session has a dark background or not.
Definition Session.cpp:117
void setIconText(const QString &iconText)
Sets the text of the icon associated with this session.
Definition Session.cpp:611
void setArguments(const QStringList &arguments)
Sets the command line arguments which the session's program will be passed when run() is called.
Definition Session.cpp:143
Emulation * emulation() const
Returns the terminal emulation instance being used to encode / decode characters to / from the proces...
Definition Session.cpp:549
void flowControlEnabledChanged(bool enabled)
Emitted when the flow control state changes.
void profileChanged(const QString &profile)
Emitted when the session's profile has changed.
void clearHistory()
Clears the history store used by this session.
Definition Session.cpp:642
QStringList environment() const
Returns the environment of this session as a list of strings like VARIABLE=VALUE.
Definition Session.cpp:559
void setTabTitleFormat(TabTitleContext context, const QString &format)
Sets the format used by this session for tab titles.
Definition Session.cpp:374
void titleChanged()
Emitted when the session's title has changed.
void openUrlRequest(const QString &url)
TODO: Document me.
void removeView(TerminalDisplay *widget)
Removes a view from this session.
Definition Session.cpp:197
const HistoryType & historyType() const
Returns the type of history store used by this session.
Definition Session.cpp:637
QString currentDir()
Returns the current working directory of the process.
Definition Session.cpp:762
bool sendSignal(int signal)
Sends the specified signal to the terminal process.
Definition Session.cpp:478
void setMonitorSilence(bool)
Enables monitoring for silence in the session.
Definition Session.cpp:676
void changeTabTextColorRequest(int)
Requests that the color the text for any tabs associated with this session should be changed;.
void stateChanged(int state)
Emitted when the activity state of this session changes.
void runEmptyPTY()
Starts the terminal session for "as is" PTY (without the direction a data to internal terminal proces...
Definition Session.cpp:283
int getPtySlaveFd() const
Returns a pty slave file descriptor.
Definition Session.cpp:797
void setProfileKey(const QString &profileKey)
Sets the profile associated with this session.
Definition Session.cpp:511
void setFlowControlEnabled(bool enabled)
Sets whether flow control is enabled for this terminal session.
Definition Session.cpp:705
void changeBackgroundColorRequest(const QColor &)
Requests that the background color of views on this session should be changed.
void setTitle(TitleRole role, const QString &title)
Sets the session's title for the specified role to title.
Definition Session.cpp:579
void setAddToUtmp(bool)
Specifies whether a utmp entry should be created for the pty used by this session.
Definition Session.cpp:700
void setInitialWorkingDirectory(const QString &dir)
Sets the initial working directory for the session when it is run This has no effect once the session...
Definition Session.cpp:139
bool hasDarkBackground() const
Returns true if the session has a dark background.
Definition Session.cpp:121
void cursorChanged(Emulation::KeyboardCursorShape cursorShape, bool blinkingCursorEnabled)
Broker for Emulation::cursorChanged() signal.
bool isMonitorActivity() const
Returns true if monitoring for activity is enabled.
Definition Session.cpp:658
void setView(TerminalDisplay *widget)
Adds a new view for this session.
Definition Session.cpp:153
QString nameTitle() const
Convenience method used to read the name property.
Definition Session.h:272
void setUserTitle(int, const QString &caption)
Changes the session title or other customizable aspects of the terminal emulation display.
Definition Session.cpp:295
void setEnvironment(const QStringList &environment)
Sets the environment for this session.
Definition Session.cpp:564
TerminalDisplay * view() const
Returns the view connected to this session.
Definition Session.cpp:148
void resizeRequest(const QSize &size)
TODO: Document me.
void refresh()
Attempts to get the shell program to redraw the current display area.
Definition Session.cpp:456
QString program() const
Returns the program name of the shell process started when run() is called.
Definition Session.cpp:652
QStringList arguments() const
Returns the arguments passed to the shell process when run() is called.
Definition Session.cpp:647
TitleRole
This enum describes the available title roles.
Definition Session.h:260
@ NameRole
The name of the session.
Definition Session.h:262
@ DisplayedTitleRole
The title of the session which is displayed in tabs etc.
Definition Session.h:264
void bellRequest(const QString &message)
Emitted when a bell event occurs in the session.
void setKeyBindings(const QString &id)
Sets the key bindings used by this session.
Definition Session.cpp:574
void profileChangeCommandReceived(const QString &text)
Emitted when a profile change command is received from the terminal.
void sendText(const QString &text) const
Sends text to the current foreground terminal program.
Definition Session.cpp:499
void setMonitorActivity(bool)
Enables monitoring for activity in the session.
Definition Session.cpp:668
QString iconText() const
Returns the text of the icon associated with this session.
Definition Session.cpp:622
bool isTitleChanged() const
Flag if the title/icon was changed by user/shell.
Definition Session.cpp:627
int foregroundProcessId() const
Returns the process id of the terminal's foreground process.
Definition Session.cpp:743
void setSize(const QSize &size)
Emits a request to resize the session to accommodate the specified window size.
Definition Session.cpp:735
static QString expand(const QString &text)
Expands environment variables in text .
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
void setUsesMouse(bool usesMouse)
Sets whether the program whoose output is being displayed in the view is interested in mouse events.
void keyPressedSignal(QKeyEvent *e, bool fromPaste)
Emitted when the user presses a key whilst the terminal widget has focus.
void mouseSignal(int button, int column, int line, int eventType)
A mouse event occurred.
void setScreenWindow(ScreenWindow *window)
Sets the terminal screen section which is displayed in this widget.
bool isValid() const const
QString currentPath()
QString homePath()
QByteArray encodeName(const QString &fileName)
bool exists(const QString &fileName)
void setFileName(const QString &name)
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
bool disconnect(const QMetaObject::Connection &connection)
QString tr(const char *sourceText, const char *disambiguation, int n)
void finished(int exitCode, QProcess::ExitStatus exitStatus)
int height() const const
int width() const const
QString arg(Args &&... args) const const
void clear()
QString fromLatin1(QByteArrayView str)
QString fromLocal8Bit(QByteArrayView str)
bool isEmpty() const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
QString section(QChar sep, qsizetype start, qsizetype end, SectionFlags flags) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
void setSingleShot(bool singleShot)
void start()
void stop()
void timeout()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.