1 | /* |
2 | This file is part of Konsole, an X terminal. |
3 | |
4 | Copyright 2007-2008 by Robert Knight <robertknight@gmail.com> |
5 | Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de> |
6 | Copyright 2009 by Thomas Dreibholz <dreibh@iem.uni-due.de> |
7 | |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 2 of the License, or |
11 | (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | 02110-1301 USA. |
22 | */ |
23 | |
24 | #ifndef SESSION_H |
25 | #define SESSION_H |
26 | |
27 | // Qt |
28 | #include <QtCore/QStringList> |
29 | #include <QtCore/QHash> |
30 | //#include <QtCore/QByteRef> |
31 | #include <QtCore/QUuid> |
32 | #include <QtCore/QSize> |
33 | #include <QtCore/QProcess> |
34 | #include <QWidget> |
35 | |
36 | // KDE |
37 | #include <KUrl> |
38 | |
39 | // Konsole |
40 | #include "konsole_export.h" |
41 | |
42 | class QColor; |
43 | |
44 | class KConfigGroup; |
45 | class KProcess; |
46 | |
47 | namespace Konsole |
48 | { |
49 | class Emulation; |
50 | class Pty; |
51 | class ProcessInfo; |
52 | class TerminalDisplay; |
53 | class ZModemDialog; |
54 | class HistoryType; |
55 | |
56 | /** |
57 | * Represents a terminal session consisting of a pseudo-teletype and a terminal emulation. |
58 | * The pseudo-teletype (or PTY) handles I/O between the terminal process and Konsole. |
59 | * The terminal emulation ( Emulation and subclasses ) processes the output stream from the |
60 | * PTY and produces a character image which is then shown on views connected to the session. |
61 | * |
62 | * Each Session can be connected to one or more views by using the addView() method. |
63 | * The attached views can then display output from the program running in the terminal |
64 | * or send input to the program in the terminal in the form of keypresses and mouse |
65 | * activity. |
66 | */ |
67 | class KONSOLEPRIVATE_EXPORT Session : public QObject |
68 | { |
69 | Q_OBJECT |
70 | Q_CLASSINFO("D-Bus Interface" , "org.kde.konsole.Session" ) |
71 | |
72 | public: |
73 | Q_PROPERTY(QString name READ nameTitle) |
74 | Q_PROPERTY(int processId READ processId) |
75 | Q_PROPERTY(QString keyBindings READ keyBindings WRITE setKeyBindings) |
76 | Q_PROPERTY(QSize size READ size WRITE setSize) |
77 | |
78 | /** |
79 | * Constructs a new session. |
80 | * |
81 | * To start the terminal process, call the run() method, |
82 | * after specifying the program and arguments |
83 | * using setProgram() and setArguments() |
84 | * |
85 | * If no program or arguments are specified explicitly, the Session |
86 | * falls back to using the program specified in the SHELL environment |
87 | * variable. |
88 | */ |
89 | explicit Session(QObject* parent = 0); |
90 | ~Session(); |
91 | |
92 | /** |
93 | * Connect to an existing terminal. When a new Session() is constructed it |
94 | * automatically searches for and opens a new teletype. If you want to |
95 | * use an existing teletype (given its file descriptor) call this after |
96 | * constructing the session. |
97 | * |
98 | * Calling openTeletype() while a session is running has no effect. |
99 | * |
100 | * @param masterFd The file descriptor of the pseudo-teletype master (See KPtyProcess::KPtyProcess()) |
101 | */ |
102 | void openTeletype(int masterFd); |
103 | |
104 | /** |
105 | * Returns true if the session is currently running. This will be true |
106 | * after run() has been called successfully. |
107 | */ |
108 | bool isRunning() const; |
109 | |
110 | /** |
111 | * Adds a new view for this session. |
112 | * |
113 | * The viewing widget will display the output from the terminal and |
114 | * input from the viewing widget (key presses, mouse activity etc.) |
115 | * will be sent to the terminal. |
116 | * |
117 | * Views can be removed using removeView(). The session is automatically |
118 | * closed when the last view is removed. |
119 | */ |
120 | void addView(TerminalDisplay* widget); |
121 | /** |
122 | * Removes a view from this session. When the last view is removed, |
123 | * the session will be closed automatically. |
124 | * |
125 | * @p widget will no longer display output from or send input |
126 | * to the terminal |
127 | */ |
128 | void removeView(TerminalDisplay* widget); |
129 | |
130 | /** |
131 | * Returns the views connected to this session |
132 | */ |
133 | QList<TerminalDisplay*> views() const; |
134 | |
135 | /** |
136 | * Returns the terminal emulation instance being used to encode / decode |
137 | * characters to / from the process. |
138 | */ |
139 | Emulation* emulation() const; |
140 | |
141 | /** Returns the unique ID for this session. */ |
142 | int sessionId() const; |
143 | |
144 | /** |
145 | * This enum describes the contexts for which separate |
146 | * tab title formats may be specified. |
147 | */ |
148 | enum TabTitleContext { |
149 | /** Default tab title format */ |
150 | LocalTabTitle, |
151 | /** |
152 | * Tab title format used session currently contains |
153 | * a connection to a remote computer (via SSH) |
154 | */ |
155 | RemoteTabTitle |
156 | }; |
157 | |
158 | /** |
159 | * Returns true if the session currently contains a connection to a |
160 | * remote computer. It currently supports ssh. |
161 | */ |
162 | bool isRemote(); |
163 | |
164 | /** |
165 | * Sets the format used by this session for tab titles. |
166 | * |
167 | * @param context The context whose format should be set. |
168 | * @param format The tab title format. This may be a mixture |
169 | * of plain text and dynamic elements denoted by a '%' character |
170 | * followed by a letter. (eg. %d for directory). The dynamic |
171 | * elements available depend on the @p context |
172 | */ |
173 | void setTabTitleFormat(TabTitleContext context , const QString& format); |
174 | /** Returns the format used by this session for tab titles. */ |
175 | QString tabTitleFormat(TabTitleContext context) const; |
176 | |
177 | /** Returns the arguments passed to the shell process when run() is called. */ |
178 | QStringList arguments() const; |
179 | /** Returns the program name of the shell process started when run() is called. */ |
180 | QString program() const; |
181 | |
182 | /** |
183 | * Sets the command line arguments which the session's program will be passed when |
184 | * run() is called. |
185 | */ |
186 | void setArguments(const QStringList& arguments); |
187 | /** Sets the program to be executed when run() is called. */ |
188 | void setProgram(const QString& program); |
189 | |
190 | /** Returns the session's current working directory. */ |
191 | QString initialWorkingDirectory() { |
192 | return _initialWorkingDir; |
193 | } |
194 | |
195 | /** |
196 | * Sets the initial working directory for the session when it is run |
197 | * This has no effect once the session has been started. |
198 | */ |
199 | void setInitialWorkingDirectory(const QString& dir); |
200 | |
201 | /** |
202 | * Returns the current directory of the foreground process in the session |
203 | */ |
204 | QString currentWorkingDirectory(); |
205 | |
206 | /** |
207 | * Sets the type of history store used by this session. |
208 | * Lines of output produced by the terminal are added |
209 | * to the history store. The type of history store |
210 | * used affects the number of lines which can be |
211 | * remembered before they are lost and the storage |
212 | * (in memory, on-disk etc.) used. |
213 | */ |
214 | void setHistoryType(const HistoryType& type); |
215 | /** |
216 | * Returns the type of history store used by this session. |
217 | */ |
218 | const HistoryType& historyType() const; |
219 | /** |
220 | * Clears the history store used by this session. |
221 | */ |
222 | void clearHistory(); |
223 | |
224 | /** |
225 | * Sets the key bindings used by this session. The bindings |
226 | * specify how input key sequences are translated into |
227 | * the character stream which is sent to the terminal. |
228 | * |
229 | * @param name The name of the key bindings to use. The |
230 | * names of available key bindings can be determined using the |
231 | * KeyboardTranslatorManager class. |
232 | */ |
233 | void setKeyBindings(const QString& name); |
234 | /** Returns the name of the key bindings used by this session. */ |
235 | QString keyBindings() const; |
236 | |
237 | /** |
238 | * This enum describes the available title roles. |
239 | */ |
240 | enum TitleRole { |
241 | /** The name of the session. */ |
242 | NameRole, |
243 | /** The title of the session which is displayed in tabs etc. */ |
244 | DisplayedTitleRole |
245 | }; |
246 | |
247 | /** |
248 | * Return the session title set by the user (ie. the program running |
249 | * in the terminal), or an empty string if the user has not set a custom title |
250 | */ |
251 | QString userTitle() const; |
252 | |
253 | /** Convenience method used to read the name property. Returns title(Session::NameRole). */ |
254 | QString nameTitle() const { |
255 | return title(Session::NameRole); |
256 | } |
257 | /** Returns a title generated from tab format and process information. */ |
258 | QString getDynamicTitle(); |
259 | |
260 | /** Sets the name of the icon associated with this session. */ |
261 | void setIconName(const QString& iconName); |
262 | /** Returns the name of the icon associated with this session. */ |
263 | QString iconName() const; |
264 | |
265 | /** Return URL for the session. */ |
266 | KUrl getUrl(); |
267 | |
268 | /** Sets the text of the icon associated with this session. */ |
269 | void setIconText(const QString& iconText); |
270 | /** Returns the text of the icon associated with this session. */ |
271 | QString iconText() const; |
272 | |
273 | /** Sets the session's title for the specified @p role to @p title. */ |
274 | void setTitle(TitleRole role , const QString& title); |
275 | |
276 | /** Returns the session's title for the specified @p role. */ |
277 | QString title(TitleRole role) const; |
278 | |
279 | /** |
280 | * Specifies whether a utmp entry should be created for the pty used by this session. |
281 | * If true, KPty::login() is called when the session is started. |
282 | */ |
283 | void setAddToUtmp(bool); |
284 | |
285 | /** |
286 | * Specifies whether to close the session automatically when the terminal |
287 | * process terminates. |
288 | */ |
289 | void setAutoClose(bool close); |
290 | |
291 | /** See setAutoClose() */ |
292 | bool autoClose() const; |
293 | |
294 | /** Returns true if the user has started a program in the session. */ |
295 | bool isForegroundProcessActive(); |
296 | |
297 | /** Returns the name of the current foreground process. */ |
298 | QString foregroundProcessName(); |
299 | |
300 | /** Returns the terminal session's window size in lines and columns. */ |
301 | QSize size(); |
302 | /** |
303 | * Emits a request to resize the session to accommodate |
304 | * the specified window size. |
305 | * |
306 | * @param size The size in lines and columns to request. |
307 | */ |
308 | void setSize(const QSize& size); |
309 | |
310 | QSize preferredSize() const; |
311 | |
312 | void setPreferredSize(const QSize & size); |
313 | |
314 | /** |
315 | * Sets whether the session has a dark background or not. The session |
316 | * uses this information to set the COLORFGBG variable in the process's |
317 | * environment, which allows the programs running in the terminal to determine |
318 | * whether the background is light or dark and use appropriate colors by default. |
319 | * |
320 | * This has no effect once the session is running. |
321 | */ |
322 | void setDarkBackground(bool darkBackground); |
323 | |
324 | /** |
325 | * Attempts to get the shell program to redraw the current display area. |
326 | * This can be used after clearing the screen, for example, to get the |
327 | * shell to redraw the prompt line. |
328 | */ |
329 | void refresh(); |
330 | |
331 | void startZModem(const QString& rz, const QString& dir, const QStringList& list); |
332 | void cancelZModem(); |
333 | bool isZModemBusy() { |
334 | return _zmodemBusy; |
335 | } |
336 | |
337 | /** |
338 | * Possible values of the @p what parameter for setUserTitle() |
339 | * See "Operating System Controls" section on http://rtfm.etla.org/xterm/ctlseq.html |
340 | */ |
341 | enum UserTitleChange { |
342 | IconNameAndWindowTitle = 0, |
343 | IconName = 1, |
344 | WindowTitle = 2, |
345 | TextColor = 10, |
346 | BackgroundColor = 11, |
347 | SessionName = 30, // Non-standard |
348 | SessionIcon = 32, // Non-standard |
349 | ProfileChange = 50 // this clashes with Xterm's font change command |
350 | }; |
351 | |
352 | // Sets the text codec used by this sessions terminal emulation. |
353 | void setCodec(QTextCodec* codec); |
354 | |
355 | // session management |
356 | void saveSession(KConfigGroup& group); |
357 | void restoreSession(KConfigGroup& group); |
358 | |
359 | void sendSignal(int signal); |
360 | |
361 | public slots: |
362 | |
363 | /** |
364 | * Starts the terminal session. |
365 | * |
366 | * This creates the terminal process and connects the teletype to it. |
367 | */ |
368 | void run(); |
369 | |
370 | /** |
371 | * Returns the environment of this session as a list of strings like |
372 | * VARIABLE=VALUE |
373 | */ |
374 | Q_SCRIPTABLE QStringList environment() const; |
375 | |
376 | /** |
377 | * Sets the environment for this session. |
378 | * @p environment should be a list of strings like |
379 | * VARIABLE=VALUE |
380 | */ |
381 | Q_SCRIPTABLE void setEnvironment(const QStringList& environment); |
382 | |
383 | /** |
384 | * Adds one entry for the environment of this session |
385 | * @p entry should be like VARIABLE=VALUE |
386 | */ |
387 | void addEnvironmentEntry(const QString& entry); |
388 | |
389 | /** |
390 | * Closes the terminal session. It kills the terminal process by calling |
391 | * closeInNormalWay() and, optionally, closeInForceWay(). |
392 | */ |
393 | //Q_SCRIPTABLE void close(); // This cause the menu issues bko 185466 |
394 | void close(); |
395 | |
396 | /** |
397 | * Kill the terminal process in normal way. This sends a hangup signal |
398 | * (SIGHUP) to the terminal process and causes the finished() signal to |
399 | * be emitted. If the process does not respond to the SIGHUP signal then |
400 | * the terminal connection (the pty) is closed and Konsole waits for the |
401 | * process to exit. This method works most of the time, but fails with some |
402 | * programs which respond to SIGHUP signal in special way, such as autossh |
403 | * and irssi. |
404 | */ |
405 | bool closeInNormalWay(); |
406 | |
407 | /** |
408 | * kill terminal process in force way. This send a SIGKILL signal to the |
409 | * terminal process. It should be called only after closeInNormalWay() has |
410 | * failed. Take it as last resort. |
411 | */ |
412 | bool closeInForceWay(); |
413 | |
414 | /** |
415 | * Changes the session title or other customizable aspects of the terminal |
416 | * emulation display. For a list of what may be changed see the |
417 | * Emulation::titleChanged() signal. |
418 | * |
419 | * @param what The feature being changed. Value is one of UserTitleChange |
420 | * @param caption The text part of the terminal command |
421 | */ |
422 | void setUserTitle(int what , const QString& caption); |
423 | |
424 | /** |
425 | * Enables monitoring for activity in the session. |
426 | * This will cause notifySessionState() to be emitted |
427 | * with the NOTIFYACTIVITY state flag when output is |
428 | * received from the terminal. |
429 | */ |
430 | Q_SCRIPTABLE void setMonitorActivity(bool); |
431 | |
432 | /** Returns true if monitoring for activity is enabled. */ |
433 | Q_SCRIPTABLE bool isMonitorActivity() const; |
434 | |
435 | /** |
436 | * Enables monitoring for silence in the session. |
437 | * This will cause notifySessionState() to be emitted |
438 | * with the NOTIFYSILENCE state flag when output is not |
439 | * received from the terminal for a certain period of |
440 | * time, specified with setMonitorSilenceSeconds() |
441 | */ |
442 | Q_SCRIPTABLE void setMonitorSilence(bool); |
443 | |
444 | /** |
445 | * Returns true if monitoring for inactivity (silence) |
446 | * in the session is enabled. |
447 | */ |
448 | Q_SCRIPTABLE bool isMonitorSilence() const; |
449 | |
450 | /** See setMonitorSilence() */ |
451 | Q_SCRIPTABLE void setMonitorSilenceSeconds(int seconds); |
452 | |
453 | /** |
454 | * Sets whether flow control is enabled for this terminal |
455 | * session. |
456 | */ |
457 | Q_SCRIPTABLE void setFlowControlEnabled(bool enabled); |
458 | |
459 | /** Returns whether flow control is enabled for this terminal session. */ |
460 | Q_SCRIPTABLE bool flowControlEnabled() const; |
461 | |
462 | /** |
463 | * Sends @p text to the current foreground terminal program. |
464 | */ |
465 | Q_SCRIPTABLE void sendText(const QString& text) const; |
466 | |
467 | /** |
468 | * Sends @p command to the current foreground terminal program. |
469 | */ |
470 | Q_SCRIPTABLE void runCommand(const QString& command) const; |
471 | |
472 | /** |
473 | * Sends a mouse event of type @p eventType emitted by button |
474 | * @p buttons on @p column/@p line to the current foreground |
475 | * terminal program |
476 | */ |
477 | Q_SCRIPTABLE void sendMouseEvent(int buttons, int column, int line, int eventType); |
478 | |
479 | /** |
480 | * Returns the process id of the terminal process. |
481 | * This is the id used by the system API to refer to the process. |
482 | */ |
483 | Q_SCRIPTABLE int processId() const; |
484 | |
485 | /** |
486 | * Returns the process id of the terminal's foreground process. |
487 | * This is initially the same as processId() but can change |
488 | * as the user starts other programs inside the terminal. |
489 | */ |
490 | Q_SCRIPTABLE int foregroundProcessId(); |
491 | |
492 | /** Sets the text codec used by this sessions terminal emulation. |
493 | * Overloaded to accept a QByteArray for convenience since DBus |
494 | * does not accept QTextCodec directly. |
495 | */ |
496 | Q_SCRIPTABLE bool setCodec(QByteArray codec); |
497 | |
498 | /** Returns the codec used to decode incoming characters in this |
499 | * terminal emulation |
500 | */ |
501 | Q_SCRIPTABLE QByteArray codec(); |
502 | |
503 | /** Sets the session's title for the specified @p role to @p title. |
504 | * This is an overloaded member function for setTitle(TitleRole, QString) |
505 | * provided for convenience since enum data types may not be |
506 | * exported directly through DBus |
507 | */ |
508 | Q_SCRIPTABLE void setTitle(int role, const QString& title); |
509 | |
510 | /** Returns the session's title for the specified @p role. |
511 | * This is an overloaded member function for setTitle(TitleRole) |
512 | * provided for convenience since enum data types may not be |
513 | * exported directly through DBus |
514 | */ |
515 | Q_SCRIPTABLE QString title(int role) const; |
516 | |
517 | /** Returns the "friendly" version of the QUuid of this session. |
518 | * This is a QUuid with the braces and dashes removed, so it cannot be |
519 | * used to construct a new QUuid. The same text appears in the |
520 | * SHELL_SESSION_ID environment variable. |
521 | */ |
522 | Q_SCRIPTABLE QString shellSessionId() const; |
523 | |
524 | /** Sets the session's tab title format for the specified @p context to @p format. |
525 | * This is an overloaded member function for setTabTitleFormat(TabTitleContext, QString) |
526 | * provided for convenience since enum data types may not be |
527 | * exported directly through DBus |
528 | */ |
529 | Q_SCRIPTABLE void setTabTitleFormat(int context, const QString& format); |
530 | |
531 | /** Returns the session's tab title format for the specified @p context. |
532 | * This is an overloaded member function for tabTitleFormat(TitleRole) |
533 | * provided for convenience since enum data types may not be |
534 | * exported directly through DBus |
535 | */ |
536 | Q_SCRIPTABLE QString tabTitleFormat(int context) const; |
537 | |
538 | /** |
539 | * Sets the history capacity of this session. |
540 | * |
541 | * @param lines The history capacity in unit of lines. Its value can be: |
542 | * <ul> |
543 | * <li> positive integer - fixed size history</li> |
544 | * <li> 0 - no history</li> |
545 | * <li> negative integer - unlimited history</li> |
546 | * </ul> |
547 | */ |
548 | Q_SCRIPTABLE void setHistorySize(int lines); |
549 | |
550 | /** |
551 | * Returns the history capacity of this session. |
552 | */ |
553 | Q_SCRIPTABLE int historySize() const; |
554 | |
555 | signals: |
556 | |
557 | /** Emitted when the terminal process starts. */ |
558 | void started(); |
559 | |
560 | /** |
561 | * Emitted when the terminal process exits. |
562 | */ |
563 | void finished(); |
564 | |
565 | /** Emitted when the session's title has changed. */ |
566 | void titleChanged(); |
567 | |
568 | /** |
569 | * Emitted when the activity state of this session changes. |
570 | * |
571 | * @param state The new state of the session. This may be one |
572 | * of NOTIFYNORMAL, NOTIFYSILENCE or NOTIFYACTIVITY |
573 | */ |
574 | void stateChanged(int state); |
575 | |
576 | /** |
577 | * Emitted when the current working directory of this session changes. |
578 | * |
579 | * @param dir The new current working directory of the session. |
580 | */ |
581 | void currentDirectoryChanged(const QString& dir); |
582 | |
583 | /** Emitted when a bell event occurs in the session. */ |
584 | void bellRequest(const QString& message); |
585 | |
586 | /** |
587 | * Requests that the color the text for any tabs associated with |
588 | * this session should be changed; |
589 | * |
590 | * TODO: Document what the parameter does |
591 | */ |
592 | void changeTabTextColorRequest(int); |
593 | |
594 | /** |
595 | * Requests that the background color of views on this session |
596 | * should be changed. |
597 | */ |
598 | void changeBackgroundColorRequest(const QColor&); |
599 | /** |
600 | * Requests that the text color of views on this session should |
601 | * be changed to @p color. |
602 | */ |
603 | void changeForegroundColorRequest(const QColor&); |
604 | |
605 | /** TODO: Document me. */ |
606 | void openUrlRequest(const QString& url); |
607 | |
608 | /** |
609 | * Emitted when the request for data transmission through ZModem |
610 | * protocol is detected. |
611 | */ |
612 | void zmodemDetected(); |
613 | |
614 | /** |
615 | * Emitted when the terminal process requests a change |
616 | * in the size of the terminal window. |
617 | * |
618 | * @param size The requested window size in terms of lines and columns. |
619 | */ |
620 | void resizeRequest(const QSize& size); |
621 | |
622 | /** |
623 | * Emitted when a profile change command is received from the terminal. |
624 | * |
625 | * @param text The text of the command. This is a string of the form |
626 | * "PropertyName=Value;PropertyName=Value ..." |
627 | */ |
628 | void profileChangeCommandReceived(const QString& text); |
629 | |
630 | /** |
631 | * Emitted when the flow control state changes. |
632 | * |
633 | * @param enabled True if flow control is enabled or false otherwise. |
634 | */ |
635 | void flowControlEnabledChanged(bool enabled); |
636 | |
637 | /** |
638 | * Emitted when the active screen is switched, to indicate whether the primary |
639 | * screen is in use. |
640 | * |
641 | * This signal serves as a relayer of Emulation::priamyScreenInUse(bool), |
642 | * making it usable for higher level component. |
643 | */ |
644 | void primaryScreenInUse(bool use); |
645 | |
646 | /** |
647 | * Emitted when the text selection is changed. |
648 | * |
649 | * This signal serves as a relayer of Emulation::selectedText(QString), |
650 | * making it usable for higher level component. |
651 | */ |
652 | void selectionChanged(const QString& text); |
653 | |
654 | private slots: |
655 | void done(int, QProcess::ExitStatus); |
656 | |
657 | void fireZModemDetected(); |
658 | |
659 | void onReceiveBlock(const char* buffer, int len); |
660 | void silenceTimerDone(); |
661 | void activityTimerDone(); |
662 | |
663 | void onViewSizeChange(int height, int width); |
664 | |
665 | void activityStateSet(int); |
666 | |
667 | //automatically detach views from sessions when view is destroyed |
668 | void viewDestroyed(QObject* view); |
669 | |
670 | void zmodemReadStatus(); |
671 | void zmodemReadAndSendBlock(); |
672 | void zmodemReceiveBlock(const char* data, int len); |
673 | void zmodemFinished(); |
674 | |
675 | void updateFlowControlState(bool suspended); |
676 | void updateWindowSize(int lines, int columns); |
677 | |
678 | // signal relayer |
679 | void onPrimaryScreenInUse(bool use); |
680 | |
681 | private: |
682 | // checks that the binary 'program' is available and can be executed |
683 | // returns the binary name if available or an empty string otherwise |
684 | static QString checkProgram(const QString& program); |
685 | |
686 | void updateTerminalSize(); |
687 | WId windowId() const; |
688 | bool kill(int signal); |
689 | // print a warning message in the terminal. This is used |
690 | // if the program fails to start, or if the shell exits in |
691 | // an unsuccessful manner |
692 | void terminalWarning(const QString& message); |
693 | ProcessInfo* getProcessInfo(); |
694 | void updateSessionProcessInfo(); |
695 | bool updateForegroundProcessInfo(); |
696 | ProcessInfo* updateWorkingDirectory(); |
697 | |
698 | QUuid _uniqueIdentifier; // SHELL_SESSION_ID |
699 | |
700 | Pty* _shellProcess; |
701 | Emulation* _emulation; |
702 | |
703 | QList<TerminalDisplay*> _views; |
704 | |
705 | // monitor activity & silence |
706 | bool _monitorActivity; |
707 | bool _monitorSilence; |
708 | bool _notifiedActivity; |
709 | int _silenceSeconds; |
710 | QTimer* _silenceTimer; |
711 | QTimer* _activityTimer; |
712 | |
713 | bool _autoClose; |
714 | bool _closePerUserRequest; |
715 | |
716 | QString _nameTitle; |
717 | QString _displayTitle; |
718 | QString _userTitle; |
719 | |
720 | QString _localTabTitleFormat; |
721 | QString _remoteTabTitleFormat; |
722 | |
723 | QString _iconName; |
724 | QString _iconText; // not actually used |
725 | bool _addToUtmp; |
726 | bool _flowControlEnabled; |
727 | |
728 | QString _program; |
729 | QStringList _arguments; |
730 | |
731 | QStringList _environment; |
732 | int _sessionId; |
733 | |
734 | QString _initialWorkingDir; |
735 | QString _currentWorkingDir; |
736 | |
737 | ProcessInfo* _sessionProcessInfo; |
738 | ProcessInfo* _foregroundProcessInfo; |
739 | int _foregroundPid; |
740 | |
741 | // ZModem |
742 | bool _zmodemBusy; |
743 | KProcess* _zmodemProc; |
744 | ZModemDialog* _zmodemProgress; |
745 | |
746 | bool _hasDarkBackground; |
747 | |
748 | QSize _preferredSize; |
749 | |
750 | static int lastSessionId; |
751 | }; |
752 | |
753 | /** |
754 | * Provides a group of sessions which is divided into master and slave sessions. |
755 | * Activity in master sessions can be propagated to all sessions within the group. |
756 | * The type of activity which is propagated and method of propagation is controlled |
757 | * by the masterMode() flags. |
758 | */ |
759 | class SessionGroup : public QObject |
760 | { |
761 | Q_OBJECT |
762 | |
763 | public: |
764 | /** Constructs an empty session group. */ |
765 | explicit SessionGroup(QObject* parent); |
766 | /** Destroys the session group and removes all connections between master and slave sessions. */ |
767 | ~SessionGroup(); |
768 | |
769 | /** Adds a session to the group. */ |
770 | void addSession(Session* session); |
771 | /** Removes a session from the group. */ |
772 | void removeSession(Session* session); |
773 | |
774 | /** Returns the list of sessions currently in the group. */ |
775 | QList<Session*> sessions() const; |
776 | |
777 | /** |
778 | * Sets whether a particular session is a master within the group. |
779 | * Changes or activity in the group's master sessions may be propagated |
780 | * to all the sessions in the group, depending on the current masterMode() |
781 | * |
782 | * @param session The session whose master status should be changed. |
783 | * @param master True to make this session a master or false otherwise |
784 | */ |
785 | void setMasterStatus(Session* session , bool master); |
786 | /** Returns the master status of a session. See setMasterStatus() */ |
787 | bool masterStatus(Session* session) const; |
788 | |
789 | /** |
790 | * This enum describes the options for propagating certain activity or |
791 | * changes in the group's master sessions to all sessions in the group. |
792 | */ |
793 | enum MasterMode { |
794 | /** |
795 | * Any input key presses in the master sessions are sent to all |
796 | * sessions in the group. |
797 | */ |
798 | CopyInputToAll = 1 |
799 | }; |
800 | |
801 | /** |
802 | * Specifies which activity in the group's master sessions is propagated |
803 | * to all sessions in the group. |
804 | * |
805 | * @param mode A bitwise OR of MasterMode flags. |
806 | */ |
807 | void setMasterMode(int mode); |
808 | /** |
809 | * Returns a bitwise OR of the active MasterMode flags for this group. |
810 | * See setMasterMode() |
811 | */ |
812 | int masterMode() const; |
813 | |
814 | private slots: |
815 | void sessionFinished(); |
816 | void forwardData(const char* data, int size); |
817 | |
818 | private: |
819 | QList<Session*> masters() const; |
820 | |
821 | // maps sessions to their master status |
822 | QHash<Session*, bool> _sessions; |
823 | |
824 | int _masterMode; |
825 | }; |
826 | } |
827 | |
828 | #endif |
829 | |