Session.h 26.1 KB
Newer Older
1
2
/*
    This file is part of Konsole, an X terminal.
3

4
5
    Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
    Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
6
    Copyright 2009 by Thomas Dreibholz <dreibh@iem.uni-due.de>
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301  USA.
*/
23
24
25
26

#ifndef SESSION_H
#define SESSION_H

27
// Qt
Dirk Mueller's avatar
Dirk Mueller committed
28
#include <QtCore/QStringList>
29
#include <QtCore/QHash>
Dirk Mueller's avatar
Dirk Mueller committed
30
#include <QtCore/QByteRef>
31
#include <QtCore/QUuid>
32
33
34
35
#include <QtCore/QSize>
#include <QtCore/QProcess>
#include <QtGui/QColor>
#include <QtGui/QWidget>
36

37
// KDE
38
#include <KUrl>
39

40
// Konsole
41
#include "konsole_export.h"
42

43
44
class KConfigGroup;
class KProcess;
Robert Knight's avatar
   
Robert Knight committed
45

46
47
48
namespace Konsole
{

49
50
class Emulation;
class Pty;
Robert Knight's avatar
   
Robert Knight committed
51
class ProcessInfo;
52
53
class TerminalDisplay;
class ZModemDialog;
54
class HistoryType;
Waldo Bastian's avatar
Waldo Bastian committed
55

Robert Knight's avatar
   
Robert Knight committed
56
/**
57
58
 * Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
 * The pseudo-teletype (or PTY) handles I/O between the terminal process and Konsole.
59
60
 * The terminal emulation ( Emulation and subclasses ) processes the output stream from the
 * PTY and produces a character image which is then shown on views connected to the session.
Robert Knight's avatar
   
Robert Knight committed
61
 *
62
 * Each Session can be connected to one or more views by using the addView() method.
Robert Knight's avatar
   
Robert Knight committed
63
64
65
66
 * The attached views can then display output from the program running in the terminal
 * or send input to the program in the terminal in the form of keypresses and mouse
 * activity.
 */
67
class KONSOLEPRIVATE_EXPORT Session : public QObject
68
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
69
70
    Q_OBJECT
    Q_CLASSINFO("D-Bus Interface", "org.kde.konsole.Session")
71
72

public:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
    Q_PROPERTY(QString name READ nameTitle)
    Q_PROPERTY(int processId READ processId)
    Q_PROPERTY(QString keyBindings READ keyBindings WRITE setKeyBindings)
    Q_PROPERTY(QSize size READ size WRITE setSize)

    /**
     * Constructs a new session.
     *
     * To start the terminal process, call the run() method,
     * after specifying the program and arguments
     * using setProgram() and setArguments()
     *
     * If no program or arguments are specified explicitly, the Session
     * falls back to using the program specified in the SHELL environment
     * variable.
     */
    explicit Session(QObject* parent = 0);
    ~Session();

    /**
     * Connect to an existing terminal.  When a new Session() is constructed it
     * automatically searches for and opens a new teletype.  If you want to
     * use an existing teletype (given its file descriptor) call this after
     * constructing the session.
     *
     * Calling openTeletype() while a session is running has no effect.
     *
     * @param masterFd The file descriptor of the pseudo-teletype master (See KPtyProcess::KPtyProcess())
     */
    void openTeletype(int masterFd);

    /**
     * Returns true if the session is currently running.  This will be true
     * after run() has been called successfully.
     */
    bool isRunning() const;

    /**
     * Adds a new view for this session.
     *
     * The viewing widget will display the output from the terminal and
     * input from the viewing widget (key presses, mouse activity etc.)
     * will be sent to the terminal.
     *
     * Views can be removed using removeView().  The session is automatically
     * closed when the last view is removed.
     */
    void addView(TerminalDisplay* widget);
    /**
     * Removes a view from this session.  When the last view is removed,
     * the session will be closed automatically.
     *
     * @p widget will no longer display output from or send input
     * to the terminal
     */
    void removeView(TerminalDisplay* widget);

    /**
     * Returns the views connected to this session
     */
    QList<TerminalDisplay*> views() const;

    /**
     * Returns the terminal emulation instance being used to encode / decode
     * characters to / from the process.
     */
    Emulation*  emulation() const;

    /** Returns the unique ID for this session. */
    int sessionId() const;

    /**
     * This enum describes the contexts for which separate
     * tab title formats may be specified.
     */
    enum TabTitleContext {
        /** Default tab title format */
        LocalTabTitle,
        /**
         * Tab title format used session currently contains
         * a connection to a remote computer (via SSH)
         */
        RemoteTabTitle
    };

    /**
     * Returns true if the session currently contains a connection to a
     * remote computer.  It currently supports ssh.
     */
    bool isRemote();

    /**
     * Sets the format used by this session for tab titles.
     *
     * @param context The context whose format should be set.
     * @param format The tab title format.  This may be a mixture
     * of plain text and dynamic elements denoted by a '%' character
     * followed by a letter.  (eg. %d for directory).  The dynamic
     * elements available depend on the @p context
     */
    void setTabTitleFormat(TabTitleContext context , const QString& format);
    /** Returns the format used by this session for tab titles. */
    QString tabTitleFormat(TabTitleContext context) const;


    /** Returns the arguments passed to the shell process when run() is called. */
    QStringList arguments() const;
    /** Returns the program name of the shell process started when run() is called. */
    QString program() const;

    /**
     * Sets the command line arguments which the session's program will be passed when
     * run() is called.
     */
    void setArguments(const QStringList& arguments);
    /** Sets the program to be executed when run() is called. */
    void setProgram(const QString& program);

    /** Returns the session's current working directory. */
    QString initialWorkingDirectory() {
        return _initialWorkingDir;
    }

    /**
     * Sets the initial working directory for the session when it is run
     * This has no effect once the session has been started.
     */
    void setInitialWorkingDirectory(const QString& dir);

    /**
     * Returns the current directory of the foreground process in the session
     */
    QString currentWorkingDirectory();

    /**
     * Sets the type of history store used by this session.
     * Lines of output produced by the terminal are added
     * to the history store.  The type of history store
     * used affects the number of lines which can be
     * remembered before they are lost and the storage
     * (in memory, on-disk etc.) used.
     */
    void setHistoryType(const HistoryType& type);
    /**
     * Returns the type of history store used by this session.
     */
    const HistoryType& historyType() const;
    /**
     * Clears the history store used by this session.
     */
    void clearHistory();

    /**
     * Sets the key bindings used by this session.  The bindings
     * specify how input key sequences are translated into
     * the character stream which is sent to the terminal.
     *
     * @param id The name of the key bindings to use.  The
     * names of available key bindings can be determined using the
     * KeyboardTranslatorManager class.
     */
    void setKeyBindings(const QString& id);
    /** Returns the name of the key bindings used by this session. */
    QString keyBindings() const;

    /**
     * This enum describes the available title roles.
     */
    enum TitleRole {
        /** The name of the session. */
        NameRole,
        /** The title of the session which is displayed in tabs etc. */
        DisplayedTitleRole
    };

    /**
     * Return the session title set by the user (ie. the program running
     * in the terminal), or an empty string if the user has not set a custom title
     */
    QString userTitle() const;

    /** Convenience method used to read the name property.  Returns title(Session::NameRole). */
    QString nameTitle() const {
        return title(Session::NameRole);
    }
    /** Returns a title generated from tab format and process information. */
    QString getDynamicTitle();

    /** Sets the name of the icon associated with this session. */
    void setIconName(const QString& iconName);
    /** Returns the name of the icon associated with this session. */
    QString iconName() const;

    /** Return URL for the session. */
    KUrl getUrl();

    /** Sets the text of the icon associated with this session. */
    void setIconText(const QString& iconText);
    /** Returns the text of the icon associated with this session. */
    QString iconText() const;

    /** Sets the session's title for the specified @p role to @p title. */
    void setTitle(TitleRole role , const QString& title);

    /** Returns the session's title for the specified @p role. */
    QString title(TitleRole role) const;

    /**
     * Specifies whether a utmp entry should be created for the pty used by this session.
     * If true, KPty::login() is called when the session is started.
     */
    void setAddToUtmp(bool);

    /**
     * Specifies whether to close the session automatically when the terminal
     * process terminates.
     */
    void setAutoClose(bool b) {
        _autoClose = b;
    }

    /** Returns true if the user has started a program in the session. */
    bool isForegroundProcessActive();

    /** Returns the name of the current foreground process. */
    QString foregroundProcessName();

    /** Returns the terminal session's window size in lines and columns. */
    QSize size();
    /**
     * Emits a request to resize the session to accommodate
     * the specified window size.
     *
     * @param size The size in lines and columns to request.
     */
    void setSize(const QSize& size);

    /**
     * Sets whether the session has a dark background or not.  The session
     * uses this information to set the COLORFGBG variable in the process's
     * environment, which allows the programs running in the terminal to determine
     * whether the background is light or dark and use appropriate colors by default.
     *
     * This has no effect once the session is running.
     */
    void setDarkBackground(bool darkBackground);
    /**
     * Returns true if the session has a dark background.
     * See setDarkBackground()
     */
    bool hasDarkBackground() const;

    /**
     * Attempts to get the shell program to redraw the current display area.
     * This can be used after clearing the screen, for example, to get the
     * shell to redraw the prompt line.
     */
    void refresh();

    void startZModem(const QString& rz, const QString& dir, const QStringList& list);
    void cancelZModem();
    bool isZModemBusy() {
        return _zmodemBusy;
    }

    /**
      * Possible values of the @p what parameter for setUserTitle()
      * See "Operating System Controls" section on http://rtfm.etla.org/xterm/ctlseq.html
      */
    enum UserTitleChange {
        IconNameAndWindowTitle     = 0,
        IconName                 = 1,
        WindowTitle                = 2,
        TextColor                = 10,
        BackgroundColor            = 11,
        SessionName                = 30,
        ProfileChange            = 50     // this clashes with Xterm's font change command
    };

    // Sets the text codec used by this sessions terminal emulation.
    void setCodec(QTextCodec* codec);

    // session management
    void saveSession(KConfigGroup& group);
    void restoreSession(KConfigGroup& group);
Robert Knight's avatar
   
Robert Knight committed
358

359
public slots:
360

Kurt Hindenburg's avatar
Kurt Hindenburg committed
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
    /**
     * Starts the terminal session.
     *
     * This creates the terminal process and connects the teletype to it.
     */
    void run();

    /**
     * Returns the environment of this session as a list of strings like
     * VARIABLE=VALUE
     */
    Q_SCRIPTABLE QStringList environment() const;

    /**
     * Sets the environment for this session.
     * @p environment should be a list of strings like
     * VARIABLE=VALUE
     */
    Q_SCRIPTABLE void setEnvironment(const QStringList& environment);

381
382
    void addEnvironmentEntry(const QString& entry);

Kurt Hindenburg's avatar
Kurt Hindenburg committed
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
    /**
     * Closes the terminal session. It kills the terminal process by calling
     * closeInNormalWay() and, optionally, closeInForceWay().
     */
    //Q_SCRIPTABLE void close(); // This cause the menu issues bko 185466
    void close();

    /**
     * Kill the terminal process in normal way. This sends a hangup signal
     * (SIGHUP) to the terminal process and causes the finished() signal to
     * be emitted. If the process does not respond to the SIGHUP signal then
     * the terminal connection (the pty) is closed and Konsole waits for the
     * process to exit. This method works most of the time, but fails with some
     * programs which respond to SIGHUP signal in special way, such as autossh
     * and irssi.
     */
    bool closeInNormalWay();

    /**
     * kill terminal process in force way. This send a SIGKILL signal to the
     * terminal process. It should be called only after closeInNormalWay() has
     * failed. Take it as last resort.
     */
    bool closeInForceWay();

    /**
     * Changes the session title or other customizable aspects of the terminal
     * emulation display. For a list of what may be changed see the
     * Emulation::titleChanged() signal.
     *
     * @param what The feature being changed.  Value is one of UserTitleChange
     * @param caption The text part of the terminal command
     */
    void setUserTitle(int what , const QString& caption);

    /**
     * Enables monitoring for activity in the session.
     * This will cause notifySessionState() to be emitted
     * with the NOTIFYACTIVITY state flag when output is
     * received from the terminal.
     */
    Q_SCRIPTABLE void setMonitorActivity(bool);

    /** Returns true if monitoring for activity is enabled. */
    Q_SCRIPTABLE bool isMonitorActivity() const;

    /**
     * Enables monitoring for silence in the session.
     * This will cause notifySessionState() to be emitted
     * with the NOTIFYSILENCE state flag when output is not
     * received from the terminal for a certain period of
     * time, specified with setMonitorSilenceSeconds()
     */
    Q_SCRIPTABLE void setMonitorSilence(bool);

    /**
     * Returns true if monitoring for inactivity (silence)
     * in the session is enabled.
     */
    Q_SCRIPTABLE bool isMonitorSilence() const;

    /** See setMonitorSilence() */
    Q_SCRIPTABLE void setMonitorSilenceSeconds(int seconds);

    /**
     * Sets whether flow control is enabled for this terminal
     * session.
     */
    Q_SCRIPTABLE void setFlowControlEnabled(bool enabled);

    /** Returns whether flow control is enabled for this terminal session. */
    Q_SCRIPTABLE bool flowControlEnabled() const;

    /**
     * Sends @p text to the current foreground terminal program.
     */
    Q_SCRIPTABLE void sendText(const QString& text) const;

    /**
     * Sends a mouse event of type @p eventType emitted by button
     * @p buttons on @p column/@p line to the current foreground
     * terminal program
     */
    Q_SCRIPTABLE void sendMouseEvent(int buttons, int column, int line, int eventType);

    /**
    * Returns the process id of the terminal process.
    * This is the id used by the system API to refer to the process.
471
    */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
    Q_SCRIPTABLE int processId() const;

    /**
     * Returns the process id of the terminal's foreground process.
     * This is initially the same as processId() but can change
     * as the user starts other programs inside the terminal.
     */
    Q_SCRIPTABLE int foregroundProcessId();

    /** Sets the text codec used by this sessions terminal emulation.
      * Overloaded to accept a QByteArray for convenience since DBus
      * does not accept QTextCodec directky.
      */
    Q_SCRIPTABLE bool setCodec(QByteArray codec);

    /** Returns the codec used to decode incoming characters in this
     * terminal emulation
     */
    Q_SCRIPTABLE QByteArray codec();

    /** Sets the session's title for the specified @p role to @p title.
     *  This is an overloaded member function for setTitle(TitleRole, QString)
     *  provided for convenience since enum data types may not be
     *  exported directly through DBus
     */
    Q_SCRIPTABLE void setTitle(int role, const QString& title);

    /** Returns the session's title for the specified @p role.
     * This is an overloaded member function for  setTitle(TitleRole)
     * provided for convenience since enum data types may not be
     * exported directly through DBus
     */
    Q_SCRIPTABLE QString title(int role) const;

    /** Returns the "friendly" version of the QUuid of this session.
    * This is a QUuid with the braces and dashes removed, so it cannot be
    * used to construct a new QUuid. The same text appears in the
    * SHELL_SESSION_ID environment variable.
510
    */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
    Q_SCRIPTABLE QString shellSessionId() const;

    /** Sets the session's tab title format for the specified @p context to @p format.
     *  This is an overloaded member function for setTabTitleFormat(TabTitleContext, QString)
     *  provided for convenience since enum data types may not be
     *  exported directly through DBus
     */
    Q_SCRIPTABLE void setTabTitleFormat(int context, const QString& format);

    /** Returns the session's tab title format for the specified @p context.
     * This is an overloaded member function for tabTitleFormat(TitleRole)
     * provided for convenience since enum data types may not be
     * exported directly through DBus
     */
    Q_SCRIPTABLE QString tabTitleFormat(int context) const;
526

527
528
529
    /**
     * Sets the history capacity of this session.
     *
Kurt Hindenburg's avatar
Kurt Hindenburg committed
530
     * @param lines The history capacity in unit of lines. Its value can be:
531
532
533
534
535
536
537
538
539
540
541
542
543
     * <ul>
     * <li> positive integer  -  fixed size history</li>
     * <li> 0 -  no history</li>
     * <li> negative integer -  unlimited history</li>
     * </ul>
     */
    Q_SCRIPTABLE void setHistorySize(int lines) ;

    /**
     * Returns the history capacity of this session.
     */
    Q_SCRIPTABLE int historySize() const;

544
signals:
545

Kurt Hindenburg's avatar
Kurt Hindenburg committed
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
    /** Emitted when the terminal process starts. */
    void started();

    /**
     * Emitted when the terminal process exits.
     */
    void finished();

    /**
     * Emitted when output is received from the terminal process.
     */
    void receivedData(const QString& text);

    /** Emitted when the session's title has changed. */
    void titleChanged();

    /**
     * Emitted when the activity state of this session changes.
     *
     * @param state The new state of the session.  This may be one
     * of NOTIFYNORMAL, NOTIFYSILENCE or NOTIFYACTIVITY
     */
    void stateChanged(int state);

    /** Emitted when a bell event occurs in the session. */
    void bellRequest(const QString& message);

    /**
     * Requests that the color the text for any tabs associated with
     * this session should be changed;
     *
     * TODO: Document what the parameter does
     */
    void changeTabTextColorRequest(int);

    /**
     * Requests that the background color of views on this session
     * should be changed.
     */
    void changeBackgroundColorRequest(const QColor&);
    /**
     * Requests that the text color of views on this session should
     * be changed to @p color.
     */
    void changeForegroundColorRequest(const QColor&);

    /** TODO: Document me. */
    void openUrlRequest(const QString& url);

    /**
     * Emitted when the request for data transmission through ZModem
     * protocol is detected.
     */
    void zmodemDetected();

    /**
     * Emitted when the terminal process requests a change
     * in the size of the terminal window.
     *
     * @param size The requested window size in terms of lines and columns.
     */
    void resizeRequest(const QSize& size);

    /**
     * Emitted when a profile change command is received from the terminal.
     *
     * @param text The text of the command.  This is a string of the form
     * "PropertyName=Value;PropertyName=Value ..."
     */
    void profileChangeCommandReceived(const QString& text);

    /**
     * Emitted when the flow control state changes.
     *
     * @param enabled True if flow control is enabled or false otherwise.
     */
    void flowControlEnabledChanged(bool enabled);

    /**
     * Emitted when the active screen is swiched, to indicate whether the primary
     * screen is in use.
     *
     * This signal serves as a relayer of Emulation::priamyScreenInUse(bool),
     * making it usable for higher level component.
     */
    void primaryScreenInUse(bool use);

    /**
     * Emitted when the text selection is changed.
     *
     * This signal serves as a relayer of Emulation::selectedText(QString),
     * making it usable for higher level component.
     */
    void selectedText(const QString & text);
640
641


642
private slots:
Kurt Hindenburg's avatar
Kurt Hindenburg committed
643
    void done(int, QProcess::ExitStatus);
644

Kurt Hindenburg's avatar
Kurt Hindenburg committed
645
    void fireZModemDetected();
646

Kurt Hindenburg's avatar
Kurt Hindenburg committed
647
648
649
    void onReceiveBlock(const char* buffer, int len);
    void silenceTimerDone();
    void activityTimerDone();
650

Kurt Hindenburg's avatar
Kurt Hindenburg committed
651
    void onViewSizeChange(int height, int width);
652

Kurt Hindenburg's avatar
Kurt Hindenburg committed
653
    void activityStateSet(int);
654

Kurt Hindenburg's avatar
Kurt Hindenburg committed
655
656
    //automatically detach views from sessions when view is destroyed
    void viewDestroyed(QObject* view);
657

Kurt Hindenburg's avatar
Kurt Hindenburg committed
658
659
660
661
    void zmodemReadStatus();
    void zmodemReadAndSendBlock();
    void zmodemRcvBlock(const char* data, int len);
    void zmodemFinished();
662

Kurt Hindenburg's avatar
Kurt Hindenburg committed
663
664
    void updateFlowControlState(bool suspended);
    void updateWindowSize(int lines, int columns);
665

Kurt Hindenburg's avatar
Kurt Hindenburg committed
666
667
    // signal relayer
    void onPrimaryScreenInUse(bool use);
668

Kurt Hindenburg's avatar
Kurt Hindenburg committed
669
670
    // signal relayer
    void onSelectedText(const QString & text);
671

672
673
private:

Kurt Hindenburg's avatar
Kurt Hindenburg committed
674
675
676
677
678
679
680
681
682
683
684
685
686
687
    void updateTerminalSize();
    WId windowId() const;
    bool kill(int signal);
    // print a warning message in the terminal.  This is used
    // if the program fails to start, or if the shell exits in
    // an unsuccessful manner
    void terminalWarning(const QString& message);
    // checks that the binary 'program' is available and can be executed
    // returns the binary name if available or an empty string otherwise
    QString checkProgram(const QString& program) const;
    ProcessInfo* getProcessInfo();
    void updateSessionProcessInfo();
    bool updateForegroundProcessInfo();
    ProcessInfo* updateWorkingDirectory();
688

Kurt Hindenburg's avatar
Kurt Hindenburg committed
689
    QUuid            _uniqueIdentifier; // SHELL_SESSION_ID
690

Kurt Hindenburg's avatar
Kurt Hindenburg committed
691
692
    Pty*          _shellProcess;
    Emulation*    _emulation;
693

Kurt Hindenburg's avatar
Kurt Hindenburg committed
694
    QList<TerminalDisplay*> _views;
695

Kurt Hindenburg's avatar
Kurt Hindenburg committed
696
697
698
699
700
701
702
    // monitor activity & silence
    bool           _monitorActivity;
    bool           _monitorSilence;
    bool           _notifiedActivity;
    int            _silenceSeconds;
    QTimer*        _silenceTimer;
    QTimer*        _activityTimer;
703

Kurt Hindenburg's avatar
Kurt Hindenburg committed
704
705
706
    bool           _masterMode;
    bool           _autoClose;
    bool           _closePerUserRequest;
707

Laurent Montel's avatar
Laurent Montel committed
708

Kurt Hindenburg's avatar
Kurt Hindenburg committed
709
710
711
    QString        _nameTitle;
    QString        _displayTitle;
    QString        _userTitle;
712

Kurt Hindenburg's avatar
Kurt Hindenburg committed
713
714
    QString        _localTabTitleFormat;
    QString        _remoteTabTitleFormat;
715

Kurt Hindenburg's avatar
Kurt Hindenburg committed
716
717
718
719
    QString        _iconName;
    QString        _iconText; // as set by: echo -en '\033]1;IconText\007
    bool           _addToUtmp;
    bool           _flowControl;
720

Kurt Hindenburg's avatar
Kurt Hindenburg committed
721
722
    QString        _program;
    QStringList    _arguments;
723

Kurt Hindenburg's avatar
Kurt Hindenburg committed
724
725
    QStringList    _environment;
    int            _sessionId;
726

Kurt Hindenburg's avatar
Kurt Hindenburg committed
727
728
    QString        _initialWorkingDir;
    QString        _currentWorkingDir;
Robert Knight's avatar
   
Robert Knight committed
729

Kurt Hindenburg's avatar
Kurt Hindenburg committed
730
731
732
    ProcessInfo*   _sessionProcessInfo;
    ProcessInfo*   _foregroundProcessInfo;
    int            _foregroundPid;
Laurent Montel's avatar
Laurent Montel committed
733

Kurt Hindenburg's avatar
Kurt Hindenburg committed
734
735
736
737
    // ZModem
    bool           _zmodemBusy;
    KProcess*      _zmodemProc;
    ZModemDialog*  _zmodemProgress;
738

Kurt Hindenburg's avatar
Kurt Hindenburg committed
739
    // Color/Font Changes by ESC Sequences
740

Kurt Hindenburg's avatar
Kurt Hindenburg committed
741
    QColor         _modifiedBackground; // as set by: echo -en '\033]11;Color\007
742

Kurt Hindenburg's avatar
Kurt Hindenburg committed
743
    bool _hasDarkBackground;
744

Kurt Hindenburg's avatar
Kurt Hindenburg committed
745
    static int lastSessionId;
746

747
748
};

749
750
751
752
/**
 * Provides a group of sessions which is divided into master and slave sessions.
 * Activity in master sessions can be propagated to all sessions within the group.
 * The type of activity which is propagated and method of propagation is controlled
753
 * by the masterMode() flags.
754
755
756
 */
class SessionGroup : public QObject
{
Kurt Hindenburg's avatar
Kurt Hindenburg committed
757
    Q_OBJECT
758
759
760

public:
    /** Constructs an empty session group. */
761
    SessionGroup(QObject* parent);
762
763
764
765
    /** Destroys the session group and removes all connections between master and slave sessions. */
    ~SessionGroup();

    /** Adds a session to the group. */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
766
    void addSession(Session* session);
767
    /** Removes a session from the group. */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
768
    void removeSession(Session* session);
769
770
771
772
773
774
775
776
777

    /** Returns the list of sessions currently in the group. */
    QList<Session*> sessions() const;

    /**
     * Sets whether a particular session is a master within the group.
     * Changes or activity in the group's master sessions may be propagated
     * to all the sessions in the group, depending on the current masterMode()
     *
Jekyll Wu's avatar
Jekyll Wu committed
778
     * @param session The session whose master status should be changed.
779
780
     * @param master True to make this session a master or false otherwise
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
781
    void setMasterStatus(Session* session , bool master);
782
    /** Returns the master status of a session.  See setMasterStatus() */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
783
    bool masterStatus(Session* session) const;
784

785
786
    /**
     * This enum describes the options for propagating certain activity or
787
788
     * changes in the group's master sessions to all sessions in the group.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
789
    enum MasterMode {
790
791
        /**
         * Any input key presses in the master sessions are sent to all
792
793
794
795
796
         * sessions in the group.
         */
        CopyInputToAll = 1
    };

797
    /**
798
799
800
801
802
     * Specifies which activity in the group's master sessions is propagated
     * to all sessions in the group.
     *
     * @param mode A bitwise OR of MasterMode flags.
     */
Kurt Hindenburg's avatar
Kurt Hindenburg committed
803
    void setMasterMode(int mode);
804
    /**
805
     * Returns a bitwise OR of the active MasterMode flags for this group.
806
807
808
809
     * See setMasterMode()
     */
    int masterMode() const;

810
private slots:
811
    void sessionFinished();
812
    void forwardData(const char* data, int size);
813

814
815
816
817
private:
    QList<Session*> masters() const;

    // maps sessions to their master status
Kurt Hindenburg's avatar
Kurt Hindenburg committed
818
    QHash<Session*, bool> _sessions;
819
820
821
822

    int _masterMode;
};

Stephan Binner's avatar
Stephan Binner committed
823
}
824

825
#endif