• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
Session.h
Go to the documentation of this file.
1 /*
2  This file is part of Konsole, an X terminal.
3 
4  Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
5  Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
6  Copyright 2009 by Thomas Dreibholz <dreibh@iem.uni-due.de>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301 USA.
22 */
23 
24 #ifndef SESSION_H
25 #define SESSION_H
26 
27 // Qt
28 #include <QtCore/QStringList>
29 #include <QtCore/QHash>
30 //#include <QtCore/QByteRef>
31 #include <QtCore/QUuid>
32 #include <QtCore/QSize>
33 #include <QtCore/QProcess>
34 #include <QWidget>
35 
36 // KDE
37 #include <KUrl>
38 
39 // Konsole
40 #include "konsole_export.h"
41 
42 class QColor;
43 
44 class KConfigGroup;
45 class KProcess;
46 
47 namespace Konsole
48 {
49 class Emulation;
50 class Pty;
51 class ProcessInfo;
52 class TerminalDisplay;
53 class ZModemDialog;
54 class HistoryType;
55 
59 enum Modifier {
60 #ifdef Q_OS_MAC
61  ACCEL = Qt::META
62 #else
63  ACCEL = Qt::CTRL
64 #endif
65 };
66 
78 class KONSOLEPRIVATE_EXPORT Session : public QObject
79 {
80  Q_OBJECT
81  Q_CLASSINFO("D-Bus Interface", "org.kde.konsole.Session")
82 
83 public:
84  Q_PROPERTY(QString name READ nameTitle)
85  Q_PROPERTY(int processId READ processId)
86  Q_PROPERTY(QString keyBindings READ keyBindings WRITE setKeyBindings)
87  Q_PROPERTY(QSize size READ size WRITE setSize)
88 
100  explicit Session(QObject* parent = 0);
101  ~Session();
102 
113  void openTeletype(int masterFd);
114 
119  bool isRunning() const;
120 
131  void addView(TerminalDisplay* widget);
139  void removeView(TerminalDisplay* widget);
140 
144  QList<TerminalDisplay*> views() const;
145 
150  Emulation* emulation() const;
151 
153  int sessionId() const;
154 
159  enum TabTitleContext {
161  LocalTabTitle,
166  RemoteTabTitle
167  };
168 
173  bool isRemote();
174 
184  void setTabTitleFormat(TabTitleContext context , const QString& format);
186  QString tabTitleFormat(TabTitleContext context) const;
187 
189  QStringList arguments() const;
191  QString program() const;
192 
197  void setArguments(const QStringList& arguments);
199  void setProgram(const QString& program);
200 
202  QString initialWorkingDirectory() {
203  return _initialWorkingDir;
204  }
205 
210  void setInitialWorkingDirectory(const QString& dir);
211 
215  QString currentWorkingDirectory();
216 
225  void setHistoryType(const HistoryType& type);
229  const HistoryType& historyType() const;
233  void clearHistory();
234 
244  void setKeyBindings(const QString& name);
246  QString keyBindings() const;
247 
251  enum TitleRole {
253  NameRole,
255  DisplayedTitleRole
256  };
257 
262  QString userTitle() const;
263 
265  QString nameTitle() const {
266  return title(Session::NameRole);
267  }
269  QString getDynamicTitle();
270 
272  void setIconName(const QString& iconName);
274  QString iconName() const;
275 
277  KUrl getUrl();
278 
280  void setIconText(const QString& iconText);
282  QString iconText() const;
283 
285  void setTitle(TitleRole role , const QString& title);
286 
288  QString title(TitleRole role) const;
289 
294  void setAddToUtmp(bool);
295 
300  void setAutoClose(bool close);
301 
303  bool autoClose() const;
304 
306  bool isForegroundProcessActive();
307 
309  QString foregroundProcessName();
310 
312  QSize size();
319  void setSize(const QSize& size);
320 
321  QSize preferredSize() const;
322 
323  void setPreferredSize(const QSize & size);
324 
333  void setDarkBackground(bool darkBackground);
334 
340  void refresh();
341 
342  void startZModem(const QString& rz, const QString& dir, const QStringList& list);
343  void cancelZModem();
344  bool isZModemBusy() {
345  return _zmodemBusy;
346  }
347 
352  enum UserTitleChange {
353  IconNameAndWindowTitle = 0,
354  IconName = 1,
355  WindowTitle = 2,
356  TextColor = 10,
357  BackgroundColor = 11,
358  SessionName = 30, // Non-standard
359  SessionIcon = 32, // Non-standard
360  ProfileChange = 50 // this clashes with Xterm's font change command
361  };
362 
363  // Sets the text codec used by this sessions terminal emulation.
364  void setCodec(QTextCodec* codec);
365 
366  // session management
367  void saveSession(KConfigGroup& group);
368  void restoreSession(KConfigGroup& group);
369 
370  void sendSignal(int signal);
371 
372 public slots:
373 
379  void run();
380 
385  Q_SCRIPTABLE QStringList environment() const;
386 
392  Q_SCRIPTABLE void setEnvironment(const QStringList& environment);
393 
398  void addEnvironmentEntry(const QString& entry);
399 
404  //Q_SCRIPTABLE void close(); // This cause the menu issues bko 185466
405  void close();
406 
416  bool closeInNormalWay();
417 
423  bool closeInForceWay();
424 
433  void setUserTitle(int what , const QString& caption);
434 
441  Q_SCRIPTABLE void setMonitorActivity(bool);
442 
444  Q_SCRIPTABLE bool isMonitorActivity() const;
445 
453  Q_SCRIPTABLE void setMonitorSilence(bool);
454 
459  Q_SCRIPTABLE bool isMonitorSilence() const;
460 
462  Q_SCRIPTABLE void setMonitorSilenceSeconds(int seconds);
463 
468  Q_SCRIPTABLE void setFlowControlEnabled(bool enabled);
469 
471  Q_SCRIPTABLE bool flowControlEnabled() const;
472 
476  Q_SCRIPTABLE void sendText(const QString& text) const;
477 
481  Q_SCRIPTABLE void runCommand(const QString& command) const;
482 
488  Q_SCRIPTABLE void sendMouseEvent(int buttons, int column, int line, int eventType);
489 
494  Q_SCRIPTABLE int processId() const;
495 
501  Q_SCRIPTABLE int foregroundProcessId();
502 
507  Q_SCRIPTABLE bool setCodec(QByteArray codec);
508 
512  Q_SCRIPTABLE QByteArray codec();
513 
519  Q_SCRIPTABLE void setTitle(int role, const QString& title);
520 
526  Q_SCRIPTABLE QString title(int role) const;
527 
533  Q_SCRIPTABLE QString shellSessionId() const;
534 
540  Q_SCRIPTABLE void setTabTitleFormat(int context, const QString& format);
541 
547  Q_SCRIPTABLE QString tabTitleFormat(int context) const;
548 
559  Q_SCRIPTABLE void setHistorySize(int lines);
560 
564  Q_SCRIPTABLE int historySize() const;
565 
566 signals:
567 
569  void started();
570 
574  void finished();
575 
577  void titleChanged();
578 
585  void stateChanged(int state);
586 
592  void currentDirectoryChanged(const QString& dir);
593 
595  void bellRequest(const QString& message);
596 
603  void changeTabTextColorRequest(int);
604 
609  void changeBackgroundColorRequest(const QColor&);
614  void changeForegroundColorRequest(const QColor&);
615 
617  void openUrlRequest(const QString& url);
618 
623  void zmodemDetected();
624 
631  void resizeRequest(const QSize& size);
632 
639  void profileChangeCommandReceived(const QString& text);
640 
646  void flowControlEnabledChanged(bool enabled);
647 
655  void primaryScreenInUse(bool use);
656 
663  void selectionChanged(const QString& text);
664 
665 private slots:
666  void done(int, QProcess::ExitStatus);
667 
668  void fireZModemDetected();
669 
670  void onReceiveBlock(const char* buffer, int len);
671  void silenceTimerDone();
672  void activityTimerDone();
673 
674  void onViewSizeChange(int height, int width);
675 
676  void activityStateSet(int);
677 
678  //automatically detach views from sessions when view is destroyed
679  void viewDestroyed(QObject* view);
680 
681  void zmodemReadStatus();
682  void zmodemReadAndSendBlock();
683  void zmodemReceiveBlock(const char* data, int len);
684  void zmodemFinished();
685 
686  void updateFlowControlState(bool suspended);
687  void updateWindowSize(int lines, int columns);
688 
689  // signal relayer
690  void onPrimaryScreenInUse(bool use);
691 
692 private:
693  // checks that the binary 'program' is available and can be executed
694  // returns the binary name if available or an empty string otherwise
695  static QString checkProgram(const QString& program);
696 
697  void updateTerminalSize();
698  WId windowId() const;
699  bool kill(int signal);
700  // print a warning message in the terminal. This is used
701  // if the program fails to start, or if the shell exits in
702  // an unsuccessful manner
703  void terminalWarning(const QString& message);
704  ProcessInfo* getProcessInfo();
705  void updateSessionProcessInfo();
706  bool updateForegroundProcessInfo();
707  ProcessInfo* updateWorkingDirectory();
708 
709  QUuid _uniqueIdentifier; // SHELL_SESSION_ID
710 
711  Pty* _shellProcess;
712  Emulation* _emulation;
713 
714  QList<TerminalDisplay*> _views;
715 
716  // monitor activity & silence
717  bool _monitorActivity;
718  bool _monitorSilence;
719  bool _notifiedActivity;
720  int _silenceSeconds;
721  QTimer* _silenceTimer;
722  QTimer* _activityTimer;
723 
724  bool _autoClose;
725  bool _closePerUserRequest;
726 
727  QString _nameTitle;
728  QString _displayTitle;
729  QString _userTitle;
730 
731  QString _localTabTitleFormat;
732  QString _remoteTabTitleFormat;
733 
734  QString _iconName;
735  QString _iconText; // not actually used
736  bool _addToUtmp;
737  bool _flowControlEnabled;
738 
739  QString _program;
740  QStringList _arguments;
741 
742  QStringList _environment;
743  int _sessionId;
744 
745  QString _initialWorkingDir;
746  QString _currentWorkingDir;
747 
748  ProcessInfo* _sessionProcessInfo;
749  ProcessInfo* _foregroundProcessInfo;
750  int _foregroundPid;
751 
752  // ZModem
753  bool _zmodemBusy;
754  KProcess* _zmodemProc;
755  ZModemDialog* _zmodemProgress;
756 
757  bool _hasDarkBackground;
758 
759  QSize _preferredSize;
760 
761  static int lastSessionId;
762 };
763 
770 class SessionGroup : public QObject
771 {
772  Q_OBJECT
773 
774 public:
776  explicit SessionGroup(QObject* parent);
778  ~SessionGroup();
779 
781  void addSession(Session* session);
783  void removeSession(Session* session);
784 
786  QList<Session*> sessions() const;
787 
796  void setMasterStatus(Session* session , bool master);
798  bool masterStatus(Session* session) const;
799 
804  enum MasterMode {
809  CopyInputToAll = 1
810  };
811 
818  void setMasterMode(int mode);
823  int masterMode() const;
824 
825 private slots:
826  void sessionFinished();
827  void forwardData(const char* data, int size);
828 
829 private:
830  QList<Session*> masters() const;
831 
832  // maps sessions to their master status
833  QHash<Session*, bool> _sessions;
834 
835  int _masterMode;
836 };
837 }
838 
839 #endif
restoreSession
void restoreSession(Application &app)
Definition: main.cpp:285
Konsole::Session
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition: Session.h:78
QByteArray
Konsole::ZModemDialog
Definition: ZModemDialog.h:29
Konsole::SessionGroup::sessions
QList< Session * > sessions() const
Returns the list of sessions currently in the group.
Definition: Session.cpp:1461
QUuid
Konsole::Session::isZModemBusy
bool isZModemBusy()
Definition: Session.h:344
Konsole::SessionGroup::masterStatus
bool masterStatus(Session *session) const
Returns the master status of a session.
Definition: Session.cpp:1465
Konsole::Session::TitleRole
TitleRole
This enum describes the available title roles.
Definition: Session.h:251
konsole_export.h
Konsole::Pty
The Pty class is used to start the terminal process, send data to it, receive data from it and manipu...
Definition: Pty.h:52
Konsole::SessionGroup::masterMode
int masterMode() const
Returns a bitwise OR of the active MasterMode flags for this group.
Definition: Session.cpp:1457
Konsole::Session::UserTitleChange
UserTitleChange
Possible values of the what parameter for setUserTitle() See "Operating System Controls" section on h...
Definition: Session.h:352
QTimer
Konsole::SessionGroup
Provides a group of sessions which is divided into master and slave sessions.
Definition: Session.h:770
QHash
Konsole::Modifier
Modifier
Platform-specific main shortcut "opcode":
Definition: Session.h:59
QObject
Konsole::ProcessInfo
Takes a snapshot of the state of a process and provides access to information such as the process nam...
Definition: ProcessInfo.h:74
Konsole::SessionGroup::setMasterStatus
void setMasterStatus(Session *session, bool master)
Sets whether a particular session is a master within the group.
Definition: Session.cpp:1495
Konsole::Emulation
Base class for terminal emulation back-ends.
Definition: Emulation.h:117
Konsole::ACCEL
Definition: Session.h:63
Konsole::SessionGroup::MasterMode
MasterMode
This enum describes the options for propagating certain activity or changes in the group's master ses...
Definition: Session.h:804
QString
QList
QColor
QTextCodec
Konsole::Session::nameTitle
QString nameTitle() const
Convenience method used to read the name property.
Definition: Session.h:265
QStringList
Konsole::SessionGroup::setMasterMode
void setMasterMode(int mode)
Specifies which activity in the group's master sessions is propagated to all sessions in the group...
Definition: Session.cpp:1487
Konsole::SessionGroup::removeSession
void removeSession(Session *session)
Removes a session from the group.
Definition: Session.cpp:1475
QSize
Konsole::SessionGroup::SessionGroup
SessionGroup(QObject *parent)
Constructs an empty session group.
Definition: Session.cpp:1450
Konsole::SessionGroup::~SessionGroup
~SessionGroup()
Destroys the session group and removes all connections between master and slave sessions.
Definition: Session.cpp:1454
Konsole::HistoryType
Definition: History.h:319
Konsole::Session::NameRole
The name of the session.
Definition: Session.h:253
Konsole::Session::LocalTabTitle
Default tab title format.
Definition: Session.h:161
Konsole::SessionGroup::addSession
void addSession(Session *session)
Adds a session to the group.
Definition: Session.cpp:1470
KONSOLEPRIVATE_EXPORT
#define KONSOLEPRIVATE_EXPORT
Definition: konsole_export.h:33
Konsole::Session::initialWorkingDirectory
QString initialWorkingDirectory()
Returns the session's current working directory.
Definition: Session.h:202
Konsole::SessionGroup::CopyInputToAll
Any input key presses in the master sessions are sent to all sessions in the group.
Definition: Session.h:809
Konsole::Session::TabTitleContext
TabTitleContext
This enum describes the contexts for which separate tab title formats may be specified.
Definition: Session.h:159
QObject::parent
QObject * parent() const
Konsole::TerminalDisplay
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
Definition: TerminalDisplay.h:63
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal