File indexing completed on 2018-01-16 12:10:21

0001 /*
0002     This file is part of Konsole, an X terminal.
0003 
0004     Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
0005     Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
0006     Copyright 2009 by Thomas Dreibholz <dreibh@iem.uni-due.de>
0007 
0008     This program is free software; you can redistribute it and/or modify
0009     it under the terms of the GNU General Public License as published by
0010     the Free Software Foundation; either version 2 of the License, or
0011     (at your option) any later version.
0012 
0013     This program is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016     GNU General Public License for more details.
0017 
0018     You should have received a copy of the GNU General Public License
0019     along with this program; if not, write to the Free Software
0020     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0021     02110-1301  USA.
0022 */
0023 
0024 #ifndef SESSION_H
0025 #define SESSION_H
0026 
0027 // Qt
0028 #include <QStringList>
0029 #include <QHash>
0030 #include <QUuid>
0031 #include <QSize>
0032 #include <QProcess>
0033 #include <QWidget>
0034 #include <QUrl>
0035 
0036 // Konsole
0037 #include "konsoleprivate_export.h"
0038 #include "config-konsole.h" //krazy:exclude=includes
0039 #include "Shortcut_p.h"
0040 
0041 class QColor;
0042 
0043 class KConfigGroup;
0044 class KProcess;
0045 
0046 namespace Konsole {
0047 class Emulation;
0048 class Pty;
0049 class ProcessInfo;
0050 class TerminalDisplay;
0051 class ZModemDialog;
0052 class HistoryType;
0053 
0054 /**
0055  * Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
0056  * The pseudo-teletype (or PTY) handles I/O between the terminal process and Konsole.
0057  * The terminal emulation ( Emulation and subclasses ) processes the output stream from the
0058  * PTY and produces a character image which is then shown on views connected to the session.
0059  *
0060  * Each Session can be connected to one or more views by using the addView() method.
0061  * The attached views can then display output from the program running in the terminal
0062  * or send input to the program in the terminal in the form of keypresses and mouse
0063  * activity.
0064  */
0065 class KONSOLEPRIVATE_EXPORT Session : public QObject
0066 {
0067     Q_OBJECT
0068     Q_CLASSINFO("D-Bus Interface", "org.kde.konsole.Session")
0069 
0070 public:
0071     Q_PROPERTY(QString name READ nameTitle)
0072     Q_PROPERTY(int processId READ processId)
0073     Q_PROPERTY(QString keyBindings READ keyBindings WRITE setKeyBindings)
0074     Q_PROPERTY(QSize size READ size WRITE setSize)
0075 
0076     /**
0077      * Constructs a new session.
0078      *
0079      * To start the terminal process, call the run() method,
0080      * after specifying the program and arguments
0081      * using setProgram() and setArguments()
0082      *
0083      * If no program or arguments are specified explicitly, the Session
0084      * falls back to using the program specified in the SHELL environment
0085      * variable.
0086      */
0087     explicit Session(QObject *parent = nullptr);
0088     ~Session() Q_DECL_OVERRIDE;
0089 
0090     /**
0091      * Connect to an existing terminal.  When a new Session() is constructed it
0092      * automatically searches for and opens a new teletype.  If you want to
0093      * use an existing teletype (given its file descriptor) call this after
0094      * constructing the session.
0095      *
0096      * Calling openTeletype() while a session is running has no effect.
0097      *
0098      * @param fd The file descriptor of the pseudo-teletype master (See KPtyProcess::KPtyProcess())
0099      */
0100     void openTeletype(int fd);
0101 
0102     /**
0103      * Returns true if the session is currently running.  This will be true
0104      * after run() has been called successfully.
0105      */
0106     bool isRunning() const;
0107 
0108     /**
0109      * Adds a new view for this session.
0110      *
0111      * The viewing widget will display the output from the terminal and
0112      * input from the viewing widget (key presses, mouse activity etc.)
0113      * will be sent to the terminal.
0114      *
0115      * Views can be removed using removeView().  The session is automatically
0116      * closed when the last view is removed.
0117      */
0118     void addView(TerminalDisplay *widget);
0119     /**
0120      * Removes a view from this session.  When the last view is removed,
0121      * the session will be closed automatically.
0122      *
0123      * @p widget will no longer display output from or send input
0124      * to the terminal
0125      */
0126     void removeView(TerminalDisplay *widget);
0127 
0128     /**
0129      * Returns the views connected to this session
0130      */
0131     QList<TerminalDisplay *> views() const;
0132 
0133     /**
0134      * Returns the terminal emulation instance being used to encode / decode
0135      * characters to / from the process.
0136      */
0137     Emulation *emulation() const;
0138 
0139     /** Returns the unique ID for this session. */
0140     int sessionId() const;
0141 
0142     /**
0143      * This enum describes the contexts for which separate
0144      * tab title formats may be specified.
0145      */
0146     enum TabTitleContext {
0147         /** Default tab title format */
0148         LocalTabTitle,
0149         /**
0150          * Tab title format used session currently contains
0151          * a connection to a remote computer (via SSH)
0152          */
0153         RemoteTabTitle
0154     };
0155 
0156     /**
0157      * Returns true if the session currently contains a connection to a
0158      * remote computer.  It currently supports ssh.
0159      */
0160     bool isRemote();
0161 
0162     /**
0163      * Sets the format used by this session for tab titles.
0164      *
0165      * @param context The context whose format should be set.
0166      * @param format The tab title format.  This may be a mixture
0167      * of plain text and dynamic elements denoted by a '%' character
0168      * followed by a letter.  (eg. %d for directory).  The dynamic
0169      * elements available depend on the @p context
0170      */
0171     void setTabTitleFormat(TabTitleContext context, const QString &format);
0172     /** Returns the format used by this session for tab titles. */
0173     QString tabTitleFormat(TabTitleContext context) const;
0174 
0175     /** Returns the arguments passed to the shell process when run() is called. */
0176     QStringList arguments() const;
0177     /** Returns the program name of the shell process started when run() is called. */
0178     QString program() const;
0179 
0180     /**
0181      * Sets the command line arguments which the session's program will be passed when
0182      * run() is called.
0183      */
0184     void setArguments(const QStringList &arguments);
0185     /** Sets the program to be executed when run() is called. */
0186     void setProgram(const QString &program);
0187 
0188     /** Returns the session's current working directory. */
0189     QString initialWorkingDirectory()
0190     {
0191         return _initialWorkingDir;
0192     }
0193 
0194     /**
0195      * Sets the initial working directory for the session when it is run
0196      * This has no effect once the session has been started.
0197      */
0198     void setInitialWorkingDirectory(const QString &dir);
0199 
0200     /**
0201      * Returns the current directory of the foreground process in the session
0202      */
0203     QString currentWorkingDirectory();
0204 
0205     /**
0206      * Sets the type of history store used by this session.
0207      * Lines of output produced by the terminal are added
0208      * to the history store.  The type of history store
0209      * used affects the number of lines which can be
0210      * remembered before they are lost and the storage
0211      * (in memory, on-disk etc.) used.
0212      */
0213     void setHistoryType(const HistoryType &hType);
0214     /**
0215      * Returns the type of history store used by this session.
0216      */
0217     const HistoryType &historyType() const;
0218     /**
0219      * Clears the history store used by this session.
0220      */
0221     void clearHistory();
0222 
0223     /**
0224      * Sets the key bindings used by this session.  The bindings
0225      * specify how input key sequences are translated into
0226      * the character stream which is sent to the terminal.
0227      *
0228      * @param name The name of the key bindings to use.  The
0229      * names of available key bindings can be determined using the
0230      * KeyboardTranslatorManager class.
0231      */
0232     void setKeyBindings(const QString &name);
0233     /** Returns the name of the key bindings used by this session. */
0234     QString keyBindings() const;
0235 
0236     /**
0237      * This enum describes the available title roles.
0238      */
0239     enum TitleRole {
0240         /** The name of the session. */
0241         NameRole,
0242         /** The title of the session which is displayed in tabs etc. */
0243         DisplayedTitleRole
0244     };
0245 
0246     /**
0247      * Return the session title set by the user (ie. the program running
0248      * in the terminal), or an empty string if the user has not set a custom title
0249      */
0250     QString userTitle() const;
0251 
0252     /** Convenience method used to read the name property.  Returns title(Session::NameRole). */
0253     QString nameTitle() const
0254     {
0255         return title(Session::NameRole);
0256     }
0257 
0258     /** Returns a title generated from tab format and process information. */
0259     QString getDynamicTitle();
0260 
0261     /** Sets the name of the icon associated with this session. */
0262     void setIconName(const QString &iconName);
0263     /** Returns the name of the icon associated with this session. */
0264     QString iconName() const;
0265 
0266     /** Return URL for the session. */
0267     QUrl getUrl();
0268 
0269     /** Sets the text of the icon associated with this session. */
0270     void setIconText(const QString &iconText);
0271     /** Returns the text of the icon associated with this session. */
0272     QString iconText() const;
0273 
0274     /** Sets the session's title for the specified @p role to @p title. */
0275     void setTitle(TitleRole role, const QString &newTitle);
0276 
0277     /** Returns the session's title for the specified @p role. */
0278     QString title(TitleRole role) const;
0279 
0280     /**
0281      * Specifies whether a utmp entry should be created for the pty used by this session.
0282      * If true, KPty::login() is called when the session is started.
0283      */
0284     void setAddToUtmp(bool);
0285 
0286     /**
0287      * Specifies whether to close the session automatically when the terminal
0288      * process terminates.
0289      */
0290     void setAutoClose(bool close);
0291 
0292     /** See setAutoClose() */
0293     bool autoClose() const;
0294 
0295     /** Returns true if the user has started a program in the session. */
0296     bool isForegroundProcessActive();
0297 
0298     /** Returns the name of the current foreground process. */
0299     QString foregroundProcessName();
0300 
0301     /** Returns the terminal session's window size in lines and columns. */
0302     QSize size();
0303     /**
0304      * Emits a request to resize the session to accommodate
0305      * the specified window size.
0306      *
0307      * @param size The size in lines and columns to request.
0308      */
0309     void setSize(const QSize &size);
0310 
0311     QSize preferredSize() const;
0312 
0313     void setPreferredSize(const QSize &size);
0314 
0315     /**
0316      * Sets whether the session has a dark background or not.  The session
0317      * uses this information to set the COLORFGBG variable in the process's
0318      * environment, which allows the programs running in the terminal to determine
0319      * whether the background is light or dark and use appropriate colors by default.
0320      *
0321      * This has no effect once the session is running.
0322      */
0323     void setDarkBackground(bool darkBackground);
0324 
0325     /**
0326      * Attempts to get the shell program to redraw the current display area.
0327      * This can be used after clearing the screen, for example, to get the
0328      * shell to redraw the prompt line.
0329      */
0330     void refresh();
0331 
0332     void startZModem(const QString &zmodem, const QString &dir, const QStringList &list);
0333     void cancelZModem();
0334     bool isZModemBusy()
0335     {
0336         return _zmodemBusy;
0337     }
0338 
0339     /**
0340       * Possible values of the @p what parameter for setUserTitle()
0341       * See "Operating System Controls" section on http://rtfm.etla.org/xterm/ctlseq.html
0342       */
0343     enum UserTitleChange {
0344         IconNameAndWindowTitle = 0,
0345         IconName = 1,
0346         WindowTitle = 2,
0347         CurrentDirectory = 7,         // From VTE (supposedly 6 was for dir, 7 for file, but whatever)
0348         TextColor = 10,
0349         BackgroundColor = 11,
0350         SessionName = 30,             // Non-standard
0351         SessionIcon = 32,             // Non-standard
0352         ProfileChange = 50            // this clashes with Xterm's font change command
0353     };
0354 
0355     // Sets the text codec used by this sessions terminal emulation.
0356     void setCodec(QTextCodec *codec);
0357 
0358     // session management
0359     void saveSession(KConfigGroup &group);
0360     void restoreSession(KConfigGroup &group);
0361 
0362     void sendSignal(int signal);
0363 
0364     void reportBackgroundColor(const QColor &c);
0365 
0366 public Q_SLOTS:
0367 
0368     /**
0369      * Starts the terminal session.
0370      *
0371      * This creates the terminal process and connects the teletype to it.
0372      */
0373     void run();
0374 
0375     /**
0376      * Returns the environment of this session as a list of strings like
0377      * VARIABLE=VALUE
0378      */
0379     Q_SCRIPTABLE QStringList environment() const;
0380 
0381     /**
0382      * Sets the environment for this session.
0383      * @p environment should be a list of strings like
0384      * VARIABLE=VALUE
0385      */
0386     Q_SCRIPTABLE void setEnvironment(const QStringList &environment);
0387 
0388     /**
0389      * Adds one entry for the environment of this session
0390      * @p entry should be like VARIABLE=VALUE
0391      */
0392     void addEnvironmentEntry(const QString &entry);
0393 
0394     /**
0395      * Closes the terminal session. It kills the terminal process by calling
0396      * closeInNormalWay() and, optionally, closeInForceWay().
0397      */
0398     //Q_SCRIPTABLE void close(); // This cause the menu issues bko 185466
0399     void close();
0400 
0401     /**
0402      * Kill the terminal process in normal way. This sends a hangup signal
0403      * (SIGHUP) to the terminal process and causes the finished() signal to
0404      * be emitted. If the process does not respond to the SIGHUP signal then
0405      * the terminal connection (the pty) is closed and Konsole waits for the
0406      * process to exit. This method works most of the time, but fails with some
0407      * programs which respond to SIGHUP signal in special way, such as autossh
0408      * and irssi.
0409      */
0410     bool closeInNormalWay();
0411 
0412     /**
0413      * kill terminal process in force way. This send a SIGKILL signal to the
0414      * terminal process. It should be called only after closeInNormalWay() has
0415      * failed. Take it as last resort.
0416      */
0417     bool closeInForceWay();
0418 
0419     /**
0420      * Changes the session title or other customizable aspects of the terminal
0421      * emulation display. For a list of what may be changed see the
0422      * Emulation::titleChanged() signal.
0423      *
0424      * @param what The feature being changed.  Value is one of UserTitleChange
0425      * @param caption The text part of the terminal command
0426      */
0427     void setUserTitle(int what, const QString &caption);
0428 
0429     /**
0430      * Enables monitoring for activity in the session.
0431      * This will cause notifySessionState() to be emitted
0432      * with the NOTIFYACTIVITY state flag when output is
0433      * received from the terminal.
0434      */
0435     Q_SCRIPTABLE void setMonitorActivity(bool);
0436 
0437     /** Returns true if monitoring for activity is enabled. */
0438     Q_SCRIPTABLE bool isMonitorActivity() const;
0439 
0440     /**
0441      * Enables monitoring for silence in the session.
0442      * This will cause notifySessionState() to be emitted
0443      * with the NOTIFYSILENCE state flag when output is not
0444      * received from the terminal for a certain period of
0445      * time, specified with setMonitorSilenceSeconds()
0446      */
0447     Q_SCRIPTABLE void setMonitorSilence(bool);
0448 
0449     /**
0450      * Returns true if monitoring for inactivity (silence)
0451      * in the session is enabled.
0452      */
0453     Q_SCRIPTABLE bool isMonitorSilence() const;
0454 
0455     /** See setMonitorSilence() */
0456     Q_SCRIPTABLE void setMonitorSilenceSeconds(int seconds);
0457 
0458     /**
0459      * Sets whether flow control is enabled for this terminal
0460      * session.
0461      */
0462     Q_SCRIPTABLE void setFlowControlEnabled(bool enabled);
0463 
0464     /** Returns whether flow control is enabled for this terminal session. */
0465     Q_SCRIPTABLE bool flowControlEnabled() const;
0466 
0467     /**
0468      * @param text to send to the current foreground terminal program.
0469      * @param eol send this after @p text
0470      */
0471     void sendTextToTerminal(const QString &text, const QChar &eol = QChar()) const;
0472 
0473 #if defined(REMOVE_SENDTEXT_RUNCOMMAND_DBUS_METHODS)
0474     void sendText(const QString &text) const;
0475 #else
0476     Q_SCRIPTABLE void sendText(const QString &text) const;
0477 #endif
0478 
0479     /**
0480      * Sends @p command to the current foreground terminal program.
0481      */
0482 #if defined(REMOVE_SENDTEXT_RUNCOMMAND_DBUS_METHODS)
0483     void runCommand(const QString &command) const;
0484 #else
0485     Q_SCRIPTABLE void runCommand(const QString &command) const;
0486 #endif
0487 
0488     /**
0489      * Sends a mouse event of type @p eventType emitted by button
0490      * @p buttons on @p column/@p line to the current foreground
0491      * terminal program
0492      */
0493     Q_SCRIPTABLE void sendMouseEvent(int buttons, int column, int line, int eventType);
0494 
0495     /**
0496     * Returns the process id of the terminal process.
0497     * This is the id used by the system API to refer to the process.
0498     */
0499     Q_SCRIPTABLE int processId() const;
0500 
0501     /**
0502      * Returns the process id of the terminal's foreground process.
0503      * This is initially the same as processId() but can change
0504      * as the user starts other programs inside the terminal.
0505      */
0506     Q_SCRIPTABLE int foregroundProcessId();
0507 
0508     /** Sets the text codec used by this sessions terminal emulation.
0509       * Overloaded to accept a QByteArray for convenience since DBus
0510       * does not accept QTextCodec directly.
0511       */
0512     Q_SCRIPTABLE bool setCodec(const QByteArray &name);
0513 
0514     /** Returns the codec used to decode incoming characters in this
0515      * terminal emulation
0516      */
0517     Q_SCRIPTABLE QByteArray codec();
0518 
0519     /** Sets the session's title for the specified @p role to @p title.
0520      *  This is an overloaded member function for setTitle(TitleRole, QString)
0521      *  provided for convenience since enum data types may not be
0522      *  exported directly through DBus
0523      */
0524     Q_SCRIPTABLE void setTitle(int role, const QString &title);
0525 
0526     /** Returns the session's title for the specified @p role.
0527      * This is an overloaded member function for  setTitle(TitleRole)
0528      * provided for convenience since enum data types may not be
0529      * exported directly through DBus
0530      */
0531     Q_SCRIPTABLE QString title(int role) const;
0532 
0533     /** Returns the "friendly" version of the QUuid of this session.
0534     * This is a QUuid with the braces and dashes removed, so it cannot be
0535     * used to construct a new QUuid. The same text appears in the
0536     * SHELL_SESSION_ID environment variable.
0537     */
0538     Q_SCRIPTABLE QString shellSessionId() const;
0539 
0540     /** Sets the session's tab title format for the specified @p context to @p format.
0541      *  This is an overloaded member function for setTabTitleFormat(TabTitleContext, QString)
0542      *  provided for convenience since enum data types may not be
0543      *  exported directly through DBus
0544      */
0545     Q_SCRIPTABLE void setTabTitleFormat(int context, const QString &format);
0546 
0547     /** Returns the session's tab title format for the specified @p context.
0548      * This is an overloaded member function for tabTitleFormat(TitleRole)
0549      * provided for convenience since enum data types may not be
0550      * exported directly through DBus
0551      */
0552     Q_SCRIPTABLE QString tabTitleFormat(int context) const;
0553 
0554     /**
0555      * Sets the history capacity of this session.
0556      *
0557      * @param lines The history capacity in unit of lines. Its value can be:
0558      * <ul>
0559      * <li> positive integer  -  fixed size history</li>
0560      * <li> 0 -  no history</li>
0561      * <li> negative integer -  unlimited history</li>
0562      * </ul>
0563      */
0564     Q_SCRIPTABLE void setHistorySize(int lines);
0565 
0566     /**
0567      * Returns the history capacity of this session.
0568      */
0569     Q_SCRIPTABLE int historySize() const;
0570 
0571 Q_SIGNALS:
0572 
0573     /** Emitted when the terminal process starts. */
0574     void started();
0575 
0576     /**
0577      * Emitted when the terminal process exits.
0578      */
0579     void finished();
0580 
0581     /** Emitted when the session's title has changed. */
0582     void titleChanged();
0583 
0584     /**
0585      * Emitted when the activity state of this session changes.
0586      *
0587      * @param state The new state of the session.  This may be one
0588      * of NOTIFYNORMAL, NOTIFYSILENCE or NOTIFYACTIVITY
0589      */
0590     void stateChanged(int state);
0591 
0592     /**
0593      * Emitted when the current working directory of this session changes.
0594      *
0595      * @param dir The new current working directory of the session.
0596      */
0597     void currentDirectoryChanged(const QString &dir);
0598 
0599     /** Emitted when a bell event occurs in the session. */
0600     void bellRequest(const QString &message);
0601 
0602     /**
0603      * Requests that the color the text for any tabs associated with
0604      * this session should be changed;
0605      *
0606      * TODO: Document what the parameter does
0607      */
0608     void changeTabTextColorRequest(int);
0609 
0610     /**
0611      * Requests that the background color of views on this session
0612      * should be changed.
0613      */
0614     void changeBackgroundColorRequest(const QColor &);
0615     /**
0616      * Requests that the text color of views on this session should
0617      * be changed to @p color.
0618      */
0619     void changeForegroundColorRequest(const QColor &);
0620 
0621     /** TODO: Document me. */
0622     void openUrlRequest(const QString &url);
0623 
0624     /**
0625      * Emitted when the request for data transmission through ZModem
0626      * protocol is detected.
0627      */
0628     void zmodemDetected();
0629 
0630     /**
0631      * Emitted when the terminal process requests a change
0632      * in the size of the terminal window.
0633      *
0634      * @param size The requested window size in terms of lines and columns.
0635      */
0636     void resizeRequest(const QSize &size);
0637 
0638     /**
0639      * Emitted when a profile change command is received from the terminal.
0640      *
0641      * @param text The text of the command.  This is a string of the form
0642      * "PropertyName=Value;PropertyName=Value ..."
0643      */
0644     void profileChangeCommandReceived(const QString &text);
0645 
0646     /**
0647      * Emitted when the flow control state changes.
0648      *
0649      * @param enabled True if flow control is enabled or false otherwise.
0650      */
0651     void flowControlEnabledChanged(bool enabled);
0652 
0653     /**
0654      * Emitted when the active screen is switched, to indicate whether the primary
0655      * screen is in use.
0656      *
0657      * This signal serves as a relayer of Emulation::priamyScreenInUse(bool),
0658      * making it usable for higher level component.
0659      */
0660     void primaryScreenInUse(bool use);
0661 
0662     /**
0663      * Emitted when the text selection is changed.
0664      *
0665      * This signal serves as a relayer of Emulation::selectedText(QString),
0666      * making it usable for higher level component.
0667      */
0668     void selectionChanged(const QString &text);
0669 
0670     /**
0671      * Emitted when background request ("\033]11;?\a") terminal code received.
0672      * Terminal is expected send "\033]11;rgb:RRRR/GGGG/BBBB\a" response.
0673      *
0674      * Originally implemented to support vim's background detection feature
0675      * (without explictly setting 'bg=dark' within local/remote vimrc)
0676      */
0677     void getBackgroundColor();
0678 
0679 private Q_SLOTS:
0680     void done(int, QProcess::ExitStatus);
0681 
0682     void fireZModemDetected();
0683 
0684     void onReceiveBlock(const char *buf, int len);
0685     void silenceTimerDone();
0686     void activityTimerDone();
0687 
0688     void onViewSizeChange(int height, int width);
0689 
0690     void activityStateSet(int);
0691 
0692     //automatically detach views from sessions when view is destroyed
0693     void viewDestroyed(QObject *view);
0694 
0695     void zmodemReadStatus();
0696     void zmodemReadAndSendBlock();
0697     void zmodemReceiveBlock(const char *data, int len);
0698     void zmodemFinished();
0699 
0700     void updateFlowControlState(bool suspended);
0701     void updateWindowSize(int lines, int columns);
0702 
0703     // signal relayer
0704     void onPrimaryScreenInUse(bool use);
0705 
0706     void sessionAttributeRequest(int id);
0707 
0708 private:
0709     Q_DISABLE_COPY(Session)
0710 
0711     // checks that the binary 'program' is available and can be executed
0712     // returns the binary name if available or an empty string otherwise
0713     static QString checkProgram(const QString &program);
0714 
0715     void updateTerminalSize();
0716     WId windowId() const;
0717     bool kill(int signal);
0718     // print a warning message in the terminal.  This is used
0719     // if the program fails to start, or if the shell exits in
0720     // an unsuccessful manner
0721     void terminalWarning(const QString &message);
0722     ProcessInfo *getProcessInfo();
0723     void updateSessionProcessInfo();
0724     bool updateForegroundProcessInfo();
0725     void updateWorkingDirectory();
0726 
0727     QString validDirectory(const QString &dir) const;
0728 
0729     QUuid _uniqueIdentifier;            // SHELL_SESSION_ID
0730 
0731     Pty *_shellProcess;
0732     Emulation *_emulation;
0733 
0734     QList<TerminalDisplay *> _views;
0735 
0736     // monitor activity & silence
0737     bool _monitorActivity;
0738     bool _monitorSilence;
0739     bool _notifiedActivity;
0740     int _silenceSeconds;
0741     QTimer *_silenceTimer;
0742     QTimer *_activityTimer;
0743 
0744     bool _autoClose;
0745     bool _closePerUserRequest;
0746 
0747     QString _nameTitle;
0748     QString _displayTitle;
0749     QString _userTitle;
0750 
0751     QString _localTabTitleFormat;
0752     QString _remoteTabTitleFormat;
0753 
0754     QString _iconName;
0755     QString _iconText;        // not actually used
0756     bool _addToUtmp;
0757     bool _flowControlEnabled;
0758 
0759     QString _program;
0760     QStringList _arguments;
0761 
0762     QStringList _environment;
0763     int _sessionId;
0764 
0765     QString _initialWorkingDir;
0766     QString _currentWorkingDir;
0767     QUrl _reportedWorkingUrl;
0768 
0769     ProcessInfo *_sessionProcessInfo;
0770     ProcessInfo *_foregroundProcessInfo;
0771     int _foregroundPid;
0772 
0773     // ZModem
0774     bool _zmodemBusy;
0775     KProcess *_zmodemProc;
0776     ZModemDialog *_zmodemProgress;
0777 
0778     bool _hasDarkBackground;
0779 
0780     QSize _preferredSize;
0781 
0782     static int lastSessionId;
0783 };
0784 
0785 /**
0786  * Provides a group of sessions which is divided into master and slave sessions.
0787  * Activity in master sessions can be propagated to all sessions within the group.
0788  * The type of activity which is propagated and method of propagation is controlled
0789  * by the masterMode() flags.
0790  */
0791 class SessionGroup : public QObject
0792 {
0793     Q_OBJECT
0794 
0795 public:
0796     /** Constructs an empty session group. */
0797     explicit SessionGroup(QObject *parent);
0798     /** Destroys the session group and removes all connections between master and slave sessions. */
0799     ~SessionGroup() Q_DECL_OVERRIDE;
0800 
0801     /** Adds a session to the group. */
0802     void addSession(Session *session);
0803     /** Removes a session from the group. */
0804     void removeSession(Session *session);
0805 
0806     /** Returns the list of sessions currently in the group. */
0807     QList<Session *> sessions() const;
0808 
0809     /**
0810      * Sets whether a particular session is a master within the group.
0811      * Changes or activity in the group's master sessions may be propagated
0812      * to all the sessions in the group, depending on the current masterMode()
0813      *
0814      * @param session The session whose master status should be changed.
0815      * @param master True to make this session a master or false otherwise
0816      */
0817     void setMasterStatus(Session *session, bool master);
0818     /** Returns the master status of a session.  See setMasterStatus() */
0819     bool masterStatus(Session *session) const;
0820 
0821     /**
0822      * This enum describes the options for propagating certain activity or
0823      * changes in the group's master sessions to all sessions in the group.
0824      */
0825     enum MasterMode {
0826         /**
0827          * Any input key presses in the master sessions are sent to all
0828          * sessions in the group.
0829          */
0830         CopyInputToAll = 1
0831     };
0832 
0833     /**
0834      * Specifies which activity in the group's master sessions is propagated
0835      * to all sessions in the group.
0836      *
0837      * @param mode A bitwise OR of MasterMode flags.
0838      */
0839     void setMasterMode(int mode);
0840     /**
0841      * Returns a bitwise OR of the active MasterMode flags for this group.
0842      * See setMasterMode()
0843      */
0844     int masterMode() const;
0845 
0846 private Q_SLOTS:
0847     void sessionFinished();
0848     void forwardData(const QByteArray &data);
0849 
0850 private:
0851     QList<Session *> masters() const;
0852 
0853     // maps sessions to their master status
0854     QHash<Session *, bool> _sessions;
0855 
0856     int _masterMode;
0857 };
0858 }
0859 
0860 #endif