File indexing completed on 2018-09-18 18:15:57

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     /**
0176      * Returns true if the tab title has been changed by the user via the
0177      * rename-tab dialog.
0178      */
0179     bool isTabTitleSetByUser() const;
0180 
0181     /** Returns the arguments passed to the shell process when run() is called. */
0182     QStringList arguments() const;
0183     /** Returns the program name of the shell process started when run() is called. */
0184     QString program() const;
0185 
0186     /**
0187      * Sets the command line arguments which the session's program will be passed when
0188      * run() is called.
0189      */
0190     void setArguments(const QStringList &arguments);
0191     /** Sets the program to be executed when run() is called. */
0192     void setProgram(const QString &program);
0193 
0194     /** Returns the session's current working directory. */
0195     QString initialWorkingDirectory()
0196     {
0197         return _initialWorkingDir;
0198     }
0199 
0200     /**
0201      * Sets the initial working directory for the session when it is run
0202      * This has no effect once the session has been started.
0203      */
0204     void setInitialWorkingDirectory(const QString &dir);
0205 
0206     /**
0207      * Returns the current directory of the foreground process in the session
0208      */
0209     QString currentWorkingDirectory();
0210 
0211     /**
0212      * Sets the type of history store used by this session.
0213      * Lines of output produced by the terminal are added
0214      * to the history store.  The type of history store
0215      * used affects the number of lines which can be
0216      * remembered before they are lost and the storage
0217      * (in memory, on-disk etc.) used.
0218      */
0219     void setHistoryType(const HistoryType &hType);
0220     /**
0221      * Returns the type of history store used by this session.
0222      */
0223     const HistoryType &historyType() const;
0224     /**
0225      * Clears the history store used by this session.
0226      */
0227     void clearHistory();
0228 
0229     /**
0230      * Sets the key bindings used by this session.  The bindings
0231      * specify how input key sequences are translated into
0232      * the character stream which is sent to the terminal.
0233      *
0234      * @param name The name of the key bindings to use.  The
0235      * names of available key bindings can be determined using the
0236      * KeyboardTranslatorManager class.
0237      */
0238     void setKeyBindings(const QString &name);
0239     /** Returns the name of the key bindings used by this session. */
0240     QString keyBindings() const;
0241 
0242     /**
0243      * This enum describes the available title roles.
0244      */
0245     enum TitleRole {
0246         /** The name of the session. */
0247         NameRole,
0248         /** The title of the session which is displayed in tabs etc. */
0249         DisplayedTitleRole
0250     };
0251 
0252     /**
0253      * Return the session title set by the user (ie. the program running
0254      * in the terminal), or an empty string if the user has not set a custom title
0255      */
0256     QString userTitle() const;
0257 
0258     /** Convenience method used to read the name property.  Returns title(Session::NameRole). */
0259     QString nameTitle() const
0260     {
0261         return title(Session::NameRole);
0262     }
0263 
0264     /** Returns a title generated from tab format and process information. */
0265     QString getDynamicTitle();
0266 
0267     /** Sets the name of the icon associated with this session. */
0268     void setIconName(const QString &iconName);
0269     /** Returns the name of the icon associated with this session. */
0270     QString iconName() const;
0271 
0272     /** Return URL for the session. */
0273     QUrl getUrl();
0274 
0275     /** Sets the text of the icon associated with this session. */
0276     void setIconText(const QString &iconText);
0277     /** Returns the text of the icon associated with this session. */
0278     QString iconText() const;
0279 
0280     /** Sets the session's title for the specified @p role to @p title. */
0281     void setTitle(TitleRole role, const QString &newTitle);
0282 
0283     /** Returns the session's title for the specified @p role. */
0284     QString title(TitleRole role) const;
0285 
0286     /**
0287      * Specifies whether a utmp entry should be created for the pty used by this session.
0288      * If true, KPty::login() is called when the session is started.
0289      */
0290     void setAddToUtmp(bool);
0291 
0292     /**
0293      * Specifies whether to close the session automatically when the terminal
0294      * process terminates.
0295      */
0296     void setAutoClose(bool close);
0297 
0298     /** See setAutoClose() */
0299     bool autoClose() const;
0300 
0301     /** Returns true if the user has started a program in the session. */
0302     bool isForegroundProcessActive();
0303 
0304     /** Returns the name of the current foreground process. */
0305     QString foregroundProcessName();
0306 
0307     /** Returns the terminal session's window size in lines and columns. */
0308     QSize size();
0309     /**
0310      * Emits a request to resize the session to accommodate
0311      * the specified window size.
0312      *
0313      * @param size The size in lines and columns to request.
0314      */
0315     void setSize(const QSize &size);
0316 
0317     QSize preferredSize() const;
0318 
0319     void setPreferredSize(const QSize &size);
0320 
0321     /**
0322      * Sets whether the session has a dark background or not.  The session
0323      * uses this information to set the COLORFGBG variable in the process's
0324      * environment, which allows the programs running in the terminal to determine
0325      * whether the background is light or dark and use appropriate colors by default.
0326      *
0327      * This has no effect once the session is running.
0328      */
0329     void setDarkBackground(bool darkBackground);
0330 
0331     /**
0332      * Attempts to get the shell program to redraw the current display area.
0333      * This can be used after clearing the screen, for example, to get the
0334      * shell to redraw the prompt line.
0335      */
0336     void refresh();
0337 
0338     void startZModem(const QString &zmodem, const QString &dir, const QStringList &list);
0339     void cancelZModem();
0340     bool isZModemBusy()
0341     {
0342         return _zmodemBusy;
0343     }
0344     void setZModemBusy(bool busy)
0345     {
0346         _zmodemBusy = busy;
0347     }
0348 
0349     /**
0350       * Possible values of the @p what parameter for setSessionAttribute().
0351       * See the "Operating System Commands" section at:
0352       * http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h2-Operating-System-Commands
0353       */
0354     enum SessionAttributes {
0355         IconNameAndWindowTitle = 0,
0356         IconName = 1,
0357         WindowTitle = 2,
0358         CurrentDirectory = 7,         // From VTE (supposedly 6 was for dir, 7 for file, but whatever)
0359         TextColor = 10,
0360         BackgroundColor = 11,
0361         SessionName = 30,             // Non-standard
0362         SessionIcon = 32,             // Non-standard
0363         ProfileChange = 50            // this clashes with Xterm's font change command
0364     };
0365 
0366     // Sets the text codec used by this sessions terminal emulation.
0367     void setCodec(QTextCodec *codec);
0368 
0369     // session management
0370     void saveSession(KConfigGroup &group);
0371     void restoreSession(KConfigGroup &group);
0372 
0373     void sendSignal(int signal);
0374 
0375     void reportBackgroundColor(const QColor &c);
0376 
0377     bool isReadOnly() const;
0378     void setReadOnly(bool readOnly);
0379 
0380     // Returns true if the current screen is the secondary/alternate one
0381     // or false if it's the primary/normal buffer
0382     bool isPrimaryScreen();
0383     void tabTitleSetByUser(bool set);
0384 
0385 public Q_SLOTS:
0386 
0387     /**
0388      * Starts the terminal session.
0389      *
0390      * This creates the terminal process and connects the teletype to it.
0391      */
0392     void run();
0393 
0394     /**
0395      * Returns the environment of this session as a list of strings like
0396      * VARIABLE=VALUE
0397      */
0398     Q_SCRIPTABLE QStringList environment() const;
0399 
0400     /**
0401      * Sets the environment for this session.
0402      * @p environment should be a list of strings like
0403      * VARIABLE=VALUE
0404      */
0405     Q_SCRIPTABLE void setEnvironment(const QStringList &environment);
0406 
0407     /**
0408      * Adds one entry for the environment of this session
0409      * @p entry should be like VARIABLE=VALUE
0410      */
0411     void addEnvironmentEntry(const QString &entry);
0412 
0413     /**
0414      * Closes the terminal session. It kills the terminal process by calling
0415      * closeInNormalWay() and, optionally, closeInForceWay().
0416      */
0417     //Q_SCRIPTABLE void close(); // This cause the menu issues bko 185466
0418     void close();
0419 
0420     /**
0421      * Kill the terminal process in normal way. This sends a hangup signal
0422      * (SIGHUP) to the terminal process and causes the finished() signal to
0423      * be emitted. If the process does not respond to the SIGHUP signal then
0424      * the terminal connection (the pty) is closed and Konsole waits for the
0425      * process to exit. This method works most of the time, but fails with some
0426      * programs which respond to SIGHUP signal in special way, such as autossh
0427      * and irssi.
0428      */
0429     bool closeInNormalWay();
0430 
0431     /**
0432      * kill terminal process in force way. This send a SIGKILL signal to the
0433      * terminal process. It should be called only after closeInNormalWay() has
0434      * failed. Take it as last resort.
0435      */
0436     bool closeInForceWay();
0437 
0438     /**
0439      * Changes one of certain session attributes in the terminal emulation
0440      * display. For a list of what may be changed see the
0441      * Emulation::sessionAttributeChanged() signal.
0442      *
0443      * @param what The session attribute being changed, it is one of the
0444      * SessionAttributes enum
0445      * @param caption The text part of the terminal command
0446      */
0447     void setSessionAttribute(int what, const QString &caption);
0448 
0449     /**
0450      * Enables monitoring for activity in the session.
0451      * This will cause notifySessionState() to be emitted
0452      * with the NOTIFYACTIVITY state flag when output is
0453      * received from the terminal.
0454      */
0455     Q_SCRIPTABLE void setMonitorActivity(bool);
0456 
0457     /** Returns true if monitoring for activity is enabled. */
0458     Q_SCRIPTABLE bool isMonitorActivity() const;
0459 
0460     /**
0461      * Enables monitoring for silence in the session.
0462      * This will cause notifySessionState() to be emitted
0463      * with the NOTIFYSILENCE state flag when output is not
0464      * received from the terminal for a certain period of
0465      * time, specified with setMonitorSilenceSeconds()
0466      */
0467     Q_SCRIPTABLE void setMonitorSilence(bool);
0468 
0469     /**
0470      * Returns true if monitoring for inactivity (silence)
0471      * in the session is enabled.
0472      */
0473     Q_SCRIPTABLE bool isMonitorSilence() const;
0474 
0475     /** See setMonitorSilence() */
0476     Q_SCRIPTABLE void setMonitorSilenceSeconds(int seconds);
0477 
0478     /**
0479      * Sets whether flow control is enabled for this terminal
0480      * session.
0481      */
0482     Q_SCRIPTABLE void setFlowControlEnabled(bool enabled);
0483 
0484     /** Returns whether flow control is enabled for this terminal session. */
0485     Q_SCRIPTABLE bool flowControlEnabled() const;
0486 
0487     /**
0488      * @param text to send to the current foreground terminal program.
0489      * @param eol send this after @p text
0490      */
0491     void sendTextToTerminal(const QString &text, const QChar &eol = QChar()) const;
0492 
0493 #if defined(REMOVE_SENDTEXT_RUNCOMMAND_DBUS_METHODS)
0494     void sendText(const QString &text) const;
0495 #else
0496     Q_SCRIPTABLE void sendText(const QString &text) const;
0497 #endif
0498 
0499     /**
0500      * Sends @p command to the current foreground terminal program.
0501      */
0502 #if defined(REMOVE_SENDTEXT_RUNCOMMAND_DBUS_METHODS)
0503     void runCommand(const QString &command) const;
0504 #else
0505     Q_SCRIPTABLE void runCommand(const QString &command) const;
0506 #endif
0507 
0508     /**
0509      * Sends a mouse event of type @p eventType emitted by button
0510      * @p buttons on @p column/@p line to the current foreground
0511      * terminal program
0512      */
0513     Q_SCRIPTABLE void sendMouseEvent(int buttons, int column, int line, int eventType);
0514 
0515     /**
0516     * Returns the process id of the terminal process.
0517     * This is the id used by the system API to refer to the process.
0518     */
0519     Q_SCRIPTABLE int processId() const;
0520 
0521     /**
0522      * Returns the process id of the terminal's foreground process.
0523      * This is initially the same as processId() but can change
0524      * as the user starts other programs inside the terminal.
0525      */
0526     Q_SCRIPTABLE int foregroundProcessId();
0527 
0528     /** Sets the text codec used by this sessions terminal emulation.
0529       * Overloaded to accept a QByteArray for convenience since DBus
0530       * does not accept QTextCodec directly.
0531       */
0532     Q_SCRIPTABLE bool setCodec(const QByteArray &name);
0533 
0534     /** Returns the codec used to decode incoming characters in this
0535      * terminal emulation
0536      */
0537     Q_SCRIPTABLE QByteArray codec();
0538 
0539     /** Sets the session's title for the specified @p role to @p title.
0540      *  This is an overloaded member function for setTitle(TitleRole, QString)
0541      *  provided for convenience since enum data types may not be
0542      *  exported directly through DBus
0543      */
0544     Q_SCRIPTABLE void setTitle(int role, const QString &title);
0545 
0546     /** Returns the session's title for the specified @p role.
0547      * This is an overloaded member function for  setTitle(TitleRole)
0548      * provided for convenience since enum data types may not be
0549      * exported directly through DBus
0550      */
0551     Q_SCRIPTABLE QString title(int role) const;
0552 
0553     /** Returns the "friendly" version of the QUuid of this session.
0554     * This is a QUuid with the braces and dashes removed, so it cannot be
0555     * used to construct a new QUuid. The same text appears in the
0556     * SHELL_SESSION_ID environment variable.
0557     */
0558     Q_SCRIPTABLE QString shellSessionId() const;
0559 
0560     /** Sets the session's tab title format for the specified @p context to @p format.
0561      *  This is an overloaded member function for setTabTitleFormat(TabTitleContext, QString)
0562      *  provided for convenience since enum data types may not be
0563      *  exported directly through DBus
0564      */
0565     Q_SCRIPTABLE void setTabTitleFormat(int context, const QString &format);
0566 
0567     /** Returns the session's tab title format for the specified @p context.
0568      * This is an overloaded member function for tabTitleFormat(TitleRole)
0569      * provided for convenience since enum data types may not be
0570      * exported directly through DBus
0571      */
0572     Q_SCRIPTABLE QString tabTitleFormat(int context) const;
0573 
0574     /**
0575      * Sets the history capacity of this session.
0576      *
0577      * @param lines The history capacity in unit of lines. Its value can be:
0578      * <ul>
0579      * <li> positive integer  -  fixed size history</li>
0580      * <li> 0 -  no history</li>
0581      * <li> negative integer -  unlimited history</li>
0582      * </ul>
0583      */
0584     Q_SCRIPTABLE void setHistorySize(int lines);
0585 
0586     /**
0587      * Returns the history capacity of this session.
0588      */
0589     Q_SCRIPTABLE int historySize() const;
0590 
0591     /**
0592      * Sets the current session's profile
0593      */
0594     Q_SCRIPTABLE void setProfile(const QString &profile);
0595 
0596 Q_SIGNALS:
0597 
0598     /** Emitted when the terminal process starts. */
0599     void started();
0600 
0601     /**
0602      * Emitted when the terminal process exits.
0603      */
0604     void finished();
0605 
0606     /**
0607      * Emitted when one of certain session attributes has been changed.
0608      * See setSessionAttribute().
0609      */
0610     void sessionAttributeChanged();
0611 
0612     /** Emitted when the session gets locked / unlocked. */
0613     void readOnlyChanged();
0614 
0615     /**
0616      * Emitted when the activity state of this session changes.
0617      *
0618      * @param state The new state of the session.  This may be one
0619      * of NOTIFYNORMAL, NOTIFYSILENCE or NOTIFYACTIVITY
0620      */
0621     void stateChanged(int state);
0622 
0623     /**
0624      * Emitted when the current working directory of this session changes.
0625      *
0626      * @param dir The new current working directory of the session.
0627      */
0628     void currentDirectoryChanged(const QString &dir);
0629 
0630     /** Emitted when a bell event occurs in the session. */
0631     void bellRequest(const QString &message);
0632 
0633     /**
0634      * Requests that the color the text for any tabs associated with
0635      * this session should be changed;
0636      *
0637      * TODO: Document what the parameter does
0638      */
0639     void changeTabTextColorRequest(int);
0640 
0641     /**
0642      * Requests that the background color of views on this session
0643      * should be changed.
0644      */
0645     void changeBackgroundColorRequest(const QColor &);
0646     /**
0647      * Requests that the text color of views on this session should
0648      * be changed to @p color.
0649      */
0650     void changeForegroundColorRequest(const QColor &);
0651 
0652     /** TODO: Document me. */
0653     void openUrlRequest(const QString &url);
0654 
0655     /**
0656      * Emitted when the request for data transmission through ZModem
0657      * protocol is detected.
0658      */
0659     void zmodemDownloadDetected();
0660     void zmodemUploadDetected();
0661 
0662     /**
0663      * Emitted when the terminal process requests a change
0664      * in the size of the terminal window.
0665      *
0666      * @param size The requested window size in terms of lines and columns.
0667      */
0668     void resizeRequest(const QSize &size);
0669 
0670     /**
0671      * Emitted when a profile change command is received from the terminal.
0672      *
0673      * @param text The text of the command.  This is a string of the form
0674      * "PropertyName=Value;PropertyName=Value ..."
0675      */
0676     void profileChangeCommandReceived(const QString &text);
0677 
0678     /**
0679      * Emitted when the flow control state changes.
0680      *
0681      * @param enabled True if flow control is enabled or false otherwise.
0682      */
0683     void flowControlEnabledChanged(bool enabled);
0684 
0685     /**
0686      * Emitted when the active screen is switched, to indicate whether the primary
0687      * screen is in use.
0688      *
0689      * This signal serves as a relayer of Emulation::priamyScreenInUse(bool),
0690      * making it usable for higher level component.
0691      */
0692     void primaryScreenInUse(bool use);
0693 
0694     /**
0695      * Emitted when the text selection is changed.
0696      *
0697      * This signal serves as a relayer of Emulation::selectedText(QString),
0698      * making it usable for higher level component.
0699      */
0700     void selectionChanged(const QString &text);
0701 
0702     /**
0703      * Emitted when background request ("\033]11;?\a") terminal code received.
0704      * Terminal is expected send "\033]11;rgb:RRRR/GGGG/BBBB\a" response.
0705      *
0706      * Originally implemented to support vim's background detection feature
0707      * (without explictly setting 'bg=dark' within local/remote vimrc)
0708      */
0709     void getBackgroundColor();
0710 
0711 private Q_SLOTS:
0712     void done(int, QProcess::ExitStatus);
0713 
0714     void fireZModemDownloadDetected();
0715     void fireZModemUploadDetected();
0716 
0717     void onReceiveBlock(const char *buf, int len);
0718     void silenceTimerDone();
0719     void activityTimerDone();
0720 
0721     void onViewSizeChange(int height, int width);
0722 
0723     void activityStateSet(int);
0724 
0725     //automatically detach views from sessions when view is destroyed
0726     void viewDestroyed(QObject *view);
0727 
0728     void zmodemReadStatus();
0729     void zmodemReadAndSendBlock();
0730     void zmodemReceiveBlock(const char *data, int len);
0731     void zmodemFinished();
0732 
0733     void updateFlowControlState(bool suspended);
0734     void updateWindowSize(int lines, int columns);
0735 
0736     // Relays the signal from Emulation and sets _isPrimaryScreen
0737     void onPrimaryScreenInUse(bool use);
0738 
0739     void sessionAttributeRequest(int id);
0740 
0741 private:
0742     Q_DISABLE_COPY(Session)
0743 
0744     // checks that the binary 'program' is available and can be executed
0745     // returns the binary name if available or an empty string otherwise
0746     static QString checkProgram(const QString &program);
0747 
0748     void updateTerminalSize();
0749     WId windowId() const;
0750     bool kill(int signal);
0751     // print a warning message in the terminal.  This is used
0752     // if the program fails to start, or if the shell exits in
0753     // an unsuccessful manner
0754     void terminalWarning(const QString &message);
0755     ProcessInfo *getProcessInfo();
0756     void updateSessionProcessInfo();
0757     bool updateForegroundProcessInfo();
0758     void updateWorkingDirectory();
0759 
0760     QString validDirectory(const QString &dir) const;
0761 
0762     QUuid _uniqueIdentifier;            // SHELL_SESSION_ID
0763 
0764     Pty *_shellProcess;
0765     Emulation *_emulation;
0766 
0767     QList<TerminalDisplay *> _views;
0768 
0769     // monitor activity & silence
0770     bool _monitorActivity;
0771     bool _monitorSilence;
0772     bool _notifiedActivity;
0773     int _silenceSeconds;
0774     QTimer *_silenceTimer;
0775     QTimer *_activityTimer;
0776 
0777     bool _autoClose;
0778     bool _closePerUserRequest;
0779 
0780     QString _nameTitle;
0781     QString _displayTitle;
0782     QString _userTitle;
0783 
0784     QString _localTabTitleFormat;
0785     QString _remoteTabTitleFormat;
0786 
0787     bool _tabTitleSetByUser;
0788 
0789     QString _iconName;
0790     QString _iconText;        // not actually used
0791     bool _addToUtmp;
0792     bool _flowControlEnabled;
0793 
0794     QString _program;
0795     QStringList _arguments;
0796 
0797     QStringList _environment;
0798     int _sessionId;
0799 
0800     QString _initialWorkingDir;
0801     QString _currentWorkingDir;
0802     QUrl _reportedWorkingUrl;
0803 
0804     ProcessInfo *_sessionProcessInfo;
0805     ProcessInfo *_foregroundProcessInfo;
0806     int _foregroundPid;
0807 
0808     // ZModem
0809     bool _zmodemBusy;
0810     KProcess *_zmodemProc;
0811     ZModemDialog *_zmodemProgress;
0812 
0813     bool _hasDarkBackground;
0814 
0815     QSize _preferredSize;
0816 
0817     bool _readOnly;
0818     static int lastSessionId;
0819 
0820     bool _isPrimaryScreen;
0821 };
0822 
0823 /**
0824  * Provides a group of sessions which is divided into master and slave sessions.
0825  * Activity in master sessions can be propagated to all sessions within the group.
0826  * The type of activity which is propagated and method of propagation is controlled
0827  * by the masterMode() flags.
0828  */
0829 class SessionGroup : public QObject
0830 {
0831     Q_OBJECT
0832 
0833 public:
0834     /** Constructs an empty session group. */
0835     explicit SessionGroup(QObject *parent);
0836     /** Destroys the session group and removes all connections between master and slave sessions. */
0837     ~SessionGroup() Q_DECL_OVERRIDE;
0838 
0839     /** Adds a session to the group. */
0840     void addSession(Session *session);
0841     /** Removes a session from the group. */
0842     void removeSession(Session *session);
0843 
0844     /** Returns the list of sessions currently in the group. */
0845     QList<Session *> sessions() const;
0846 
0847     /**
0848      * Sets whether a particular session is a master within the group.
0849      * Changes or activity in the group's master sessions may be propagated
0850      * to all the sessions in the group, depending on the current masterMode()
0851      *
0852      * @param session The session whose master status should be changed.
0853      * @param master True to make this session a master or false otherwise
0854      */
0855     void setMasterStatus(Session *session, bool master);
0856     /** Returns the master status of a session.  See setMasterStatus() */
0857     bool masterStatus(Session *session) const;
0858 
0859     /**
0860      * This enum describes the options for propagating certain activity or
0861      * changes in the group's master sessions to all sessions in the group.
0862      */
0863     enum MasterMode {
0864         /**
0865          * Any input key presses in the master sessions are sent to all
0866          * sessions in the group.
0867          */
0868         CopyInputToAll = 1
0869     };
0870 
0871     /**
0872      * Specifies which activity in the group's master sessions is propagated
0873      * to all sessions in the group.
0874      *
0875      * @param mode A bitwise OR of MasterMode flags.
0876      */
0877     void setMasterMode(int mode);
0878     /**
0879      * Returns a bitwise OR of the active MasterMode flags for this group.
0880      * See setMasterMode()
0881      */
0882     int masterMode() const;
0883 
0884 private Q_SLOTS:
0885     void sessionFinished();
0886     void forwardData(const QByteArray &data);
0887 
0888 private:
0889     QList<Session *> masters() const;
0890 
0891     // maps sessions to their master status
0892     QHash<Session *, bool> _sessions;
0893 
0894     int _masterMode;
0895 };
0896 }
0897 
0898 #endif