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

Konsole

  • sources
  • kde-4.12
  • 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 
67 class KONSOLEPRIVATE_EXPORT Session : public QObject
68 {
69  Q_OBJECT
70  Q_CLASSINFO("D-Bus Interface", "org.kde.konsole.Session")
71 
72 public:
73  Q_PROPERTY(QString name READ nameTitle)
74  Q_PROPERTY(int processId READ processId)
75  Q_PROPERTY(QString keyBindings READ keyBindings WRITE setKeyBindings)
76  Q_PROPERTY(QSize size READ size WRITE setSize)
77 
89  explicit Session(QObject* parent = 0);
90  ~Session();
91 
102  void openTeletype(int masterFd);
103 
108  bool isRunning() const;
109 
120  void addView(TerminalDisplay* widget);
128  void removeView(TerminalDisplay* widget);
129 
133  QList<TerminalDisplay*> views() const;
134 
139  Emulation* emulation() const;
140 
142  int sessionId() const;
143 
148  enum TabTitleContext {
150  LocalTabTitle,
155  RemoteTabTitle
156  };
157 
162  bool isRemote();
163 
173  void setTabTitleFormat(TabTitleContext context , const QString& format);
175  QString tabTitleFormat(TabTitleContext context) const;
176 
178  QStringList arguments() const;
180  QString program() const;
181 
186  void setArguments(const QStringList& arguments);
188  void setProgram(const QString& program);
189 
191  QString initialWorkingDirectory() {
192  return _initialWorkingDir;
193  }
194 
199  void setInitialWorkingDirectory(const QString& dir);
200 
204  QString currentWorkingDirectory();
205 
214  void setHistoryType(const HistoryType& type);
218  const HistoryType& historyType() const;
222  void clearHistory();
223 
233  void setKeyBindings(const QString& name);
235  QString keyBindings() const;
236 
240  enum TitleRole {
242  NameRole,
244  DisplayedTitleRole
245  };
246 
251  QString userTitle() const;
252 
254  QString nameTitle() const {
255  return title(Session::NameRole);
256  }
258  QString getDynamicTitle();
259 
261  void setIconName(const QString& iconName);
263  QString iconName() const;
264 
266  KUrl getUrl();
267 
269  void setIconText(const QString& iconText);
271  QString iconText() const;
272 
274  void setTitle(TitleRole role , const QString& title);
275 
277  QString title(TitleRole role) const;
278 
283  void setAddToUtmp(bool);
284 
289  void setAutoClose(bool close);
290 
292  bool autoClose() const;
293 
295  bool isForegroundProcessActive();
296 
298  QString foregroundProcessName();
299 
301  QSize size();
308  void setSize(const QSize& size);
309 
310  QSize preferredSize() const;
311 
312  void setPreferredSize(const QSize & size);
313 
322  void setDarkBackground(bool darkBackground);
323 
329  void refresh();
330 
331  void startZModem(const QString& rz, const QString& dir, const QStringList& list);
332  void cancelZModem();
333  bool isZModemBusy() {
334  return _zmodemBusy;
335  }
336 
341  enum UserTitleChange {
342  IconNameAndWindowTitle = 0,
343  IconName = 1,
344  WindowTitle = 2,
345  TextColor = 10,
346  BackgroundColor = 11,
347  SessionName = 30, // Non-standard
348  SessionIcon = 32, // Non-standard
349  ProfileChange = 50 // this clashes with Xterm's font change command
350  };
351 
352  // Sets the text codec used by this sessions terminal emulation.
353  void setCodec(QTextCodec* codec);
354 
355  // session management
356  void saveSession(KConfigGroup& group);
357  void restoreSession(KConfigGroup& group);
358 
359  void sendSignal(int signal);
360 
361 public slots:
362 
368  void run();
369 
374  Q_SCRIPTABLE QStringList environment() const;
375 
381  Q_SCRIPTABLE void setEnvironment(const QStringList& environment);
382 
387  void addEnvironmentEntry(const QString& entry);
388 
393  //Q_SCRIPTABLE void close(); // This cause the menu issues bko 185466
394  void close();
395 
405  bool closeInNormalWay();
406 
412  bool closeInForceWay();
413 
422  void setUserTitle(int what , const QString& caption);
423 
430  Q_SCRIPTABLE void setMonitorActivity(bool);
431 
433  Q_SCRIPTABLE bool isMonitorActivity() const;
434 
442  Q_SCRIPTABLE void setMonitorSilence(bool);
443 
448  Q_SCRIPTABLE bool isMonitorSilence() const;
449 
451  Q_SCRIPTABLE void setMonitorSilenceSeconds(int seconds);
452 
457  Q_SCRIPTABLE void setFlowControlEnabled(bool enabled);
458 
460  Q_SCRIPTABLE bool flowControlEnabled() const;
461 
465  Q_SCRIPTABLE void sendText(const QString& text) const;
466 
470  Q_SCRIPTABLE void runCommand(const QString& command) const;
471 
477  Q_SCRIPTABLE void sendMouseEvent(int buttons, int column, int line, int eventType);
478 
483  Q_SCRIPTABLE int processId() const;
484 
490  Q_SCRIPTABLE int foregroundProcessId();
491 
496  Q_SCRIPTABLE bool setCodec(QByteArray codec);
497 
501  Q_SCRIPTABLE QByteArray codec();
502 
508  Q_SCRIPTABLE void setTitle(int role, const QString& title);
509 
515  Q_SCRIPTABLE QString title(int role) const;
516 
522  Q_SCRIPTABLE QString shellSessionId() const;
523 
529  Q_SCRIPTABLE void setTabTitleFormat(int context, const QString& format);
530 
536  Q_SCRIPTABLE QString tabTitleFormat(int context) const;
537 
548  Q_SCRIPTABLE void setHistorySize(int lines);
549 
553  Q_SCRIPTABLE int historySize() const;
554 
555 signals:
556 
558  void started();
559 
563  void finished();
564 
566  void titleChanged();
567 
574  void stateChanged(int state);
575 
581  void currentDirectoryChanged(const QString& dir);
582 
584  void bellRequest(const QString& message);
585 
592  void changeTabTextColorRequest(int);
593 
598  void changeBackgroundColorRequest(const QColor&);
603  void changeForegroundColorRequest(const QColor&);
604 
606  void openUrlRequest(const QString& url);
607 
612  void zmodemDetected();
613 
620  void resizeRequest(const QSize& size);
621 
628  void profileChangeCommandReceived(const QString& text);
629 
635  void flowControlEnabledChanged(bool enabled);
636 
644  void primaryScreenInUse(bool use);
645 
652  void selectionChanged(const QString& text);
653 
654 private slots:
655  void done(int, QProcess::ExitStatus);
656 
657  void fireZModemDetected();
658 
659  void onReceiveBlock(const char* buffer, int len);
660  void silenceTimerDone();
661  void activityTimerDone();
662 
663  void onViewSizeChange(int height, int width);
664 
665  void activityStateSet(int);
666 
667  //automatically detach views from sessions when view is destroyed
668  void viewDestroyed(QObject* view);
669 
670  void zmodemReadStatus();
671  void zmodemReadAndSendBlock();
672  void zmodemReceiveBlock(const char* data, int len);
673  void zmodemFinished();
674 
675  void updateFlowControlState(bool suspended);
676  void updateWindowSize(int lines, int columns);
677 
678  // signal relayer
679  void onPrimaryScreenInUse(bool use);
680 
681 private:
682  // checks that the binary 'program' is available and can be executed
683  // returns the binary name if available or an empty string otherwise
684  static QString checkProgram(const QString& program);
685 
686  void updateTerminalSize();
687  WId windowId() const;
688  bool kill(int signal);
689  // print a warning message in the terminal. This is used
690  // if the program fails to start, or if the shell exits in
691  // an unsuccessful manner
692  void terminalWarning(const QString& message);
693  ProcessInfo* getProcessInfo();
694  void updateSessionProcessInfo();
695  bool updateForegroundProcessInfo();
696  ProcessInfo* updateWorkingDirectory();
697 
698  QUuid _uniqueIdentifier; // SHELL_SESSION_ID
699 
700  Pty* _shellProcess;
701  Emulation* _emulation;
702 
703  QList<TerminalDisplay*> _views;
704 
705  // monitor activity & silence
706  bool _monitorActivity;
707  bool _monitorSilence;
708  bool _notifiedActivity;
709  int _silenceSeconds;
710  QTimer* _silenceTimer;
711  QTimer* _activityTimer;
712 
713  bool _autoClose;
714  bool _closePerUserRequest;
715 
716  QString _nameTitle;
717  QString _displayTitle;
718  QString _userTitle;
719 
720  QString _localTabTitleFormat;
721  QString _remoteTabTitleFormat;
722 
723  QString _iconName;
724  QString _iconText; // not actually used
725  bool _addToUtmp;
726  bool _flowControlEnabled;
727 
728  QString _program;
729  QStringList _arguments;
730 
731  QStringList _environment;
732  int _sessionId;
733 
734  QString _initialWorkingDir;
735  QString _currentWorkingDir;
736 
737  ProcessInfo* _sessionProcessInfo;
738  ProcessInfo* _foregroundProcessInfo;
739  int _foregroundPid;
740 
741  // ZModem
742  bool _zmodemBusy;
743  KProcess* _zmodemProc;
744  ZModemDialog* _zmodemProgress;
745 
746  bool _hasDarkBackground;
747 
748  QSize _preferredSize;
749 
750  static int lastSessionId;
751 };
752 
759 class SessionGroup : public QObject
760 {
761  Q_OBJECT
762 
763 public:
765  explicit SessionGroup(QObject* parent);
767  ~SessionGroup();
768 
770  void addSession(Session* session);
772  void removeSession(Session* session);
773 
775  QList<Session*> sessions() const;
776 
785  void setMasterStatus(Session* session , bool master);
787  bool masterStatus(Session* session) const;
788 
793  enum MasterMode {
798  CopyInputToAll = 1
799  };
800 
807  void setMasterMode(int mode);
812  int masterMode() const;
813 
814 private slots:
815  void sessionFinished();
816  void forwardData(const char* data, int size);
817 
818 private:
819  QList<Session*> masters() const;
820 
821  // maps sessions to their master status
822  QHash<Session*, bool> _sessions;
823 
824  int _masterMode;
825 };
826 }
827 
828 #endif
restoreSession
void restoreSession(Application &app)
Definition: main.cpp:276
Konsole::Session
Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
Definition: Session.h:67
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:1454
Konsole::Session::isZModemBusy
bool isZModemBusy()
Definition: Session.h:333
Konsole::SessionGroup::masterStatus
bool masterStatus(Session *session) const
Returns the master status of a session.
Definition: Session.cpp:1458
Konsole::Session::TitleRole
TitleRole
This enum describes the available title roles.
Definition: Session.h:240
konsole_export.h
QObject
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:1450
Konsole::Session::UserTitleChange
UserTitleChange
Possible values of the what parameter for setUserTitle() See "Operating System Controls" section on h...
Definition: Session.h:341
Konsole::SessionGroup
Provides a group of sessions which is divided into master and slave sessions.
Definition: Session.h:759
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:1488
Konsole::Emulation
Base class for terminal emulation back-ends.
Definition: Emulation.h:117
Konsole::SessionGroup::MasterMode
MasterMode
This enum describes the options for propagating certain activity or changes in the group's master ses...
Definition: Session.h:793
Konsole::Session::nameTitle
QString nameTitle() const
Convenience method used to read the name property.
Definition: Session.h:254
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:1480
Konsole::SessionGroup::removeSession
void removeSession(Session *session)
Removes a session from the group.
Definition: Session.cpp:1468
Konsole::SessionGroup::SessionGroup
SessionGroup(QObject *parent)
Constructs an empty session group.
Definition: Session.cpp:1443
Konsole::SessionGroup::~SessionGroup
~SessionGroup()
Destroys the session group and removes all connections between master and slave sessions.
Definition: Session.cpp:1447
Konsole::HistoryType
Definition: History.h:319
Konsole::Session::NameRole
The name of the session.
Definition: Session.h:242
Konsole::Session::LocalTabTitle
Default tab title format.
Definition: Session.h:150
Konsole::SessionGroup::addSession
void addSession(Session *session)
Adds a session to the group.
Definition: Session.cpp:1463
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:191
Konsole::SessionGroup::CopyInputToAll
Any input key presses in the master sessions are sent to all sessions in the group.
Definition: Session.h:798
Konsole::Session::TabTitleContext
TabTitleContext
This enum describes the contexts for which separate tab title formats may be specified.
Definition: Session.h:148
Konsole::TerminalDisplay
A widget which displays output from a terminal emulation and sends input keypresses and mouse activit...
Definition: TerminalDisplay.h:63
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:31:24 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
  • Applications
  •   Libraries
  •     libkonq
  • 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