GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libgui
qterminal
libqterminal
unix
TerminalModel.h
Go to the documentation of this file.
1
/*
2
This file is part of Konsole, an X terminal.
3
4
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
5
Copyright (C) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
6
7
Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
8
Copyright (C) 2012-2013 Jacob Dawid <jacob.dawid@googlemail.com>
9
10
This program is free software; you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation; either version 2 of the License, or
13
(at your option) any later version.
14
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
19
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
02110-1301 USA.
24
*/
25
26
#ifndef TERMINALMODEL_H
27
#define TERMINALMODEL_H
28
29
// Qt
30
#include <QtCore/QStringList>
31
#include <QtCore>
32
#include <QWidget>
33
34
#include "
unix/SelfListener.h
"
35
36
// Konsole
37
#include "
unix/History.h
"
38
#include "
unix/kpty.h
"
39
40
class
KProcess;
41
42
class
Emulation
;
43
class
PseudoTerminal;
44
class
TerminalView
;
45
46
/**
47
* Represents a terminal session consisting of a pseudo-teletype and a terminal emulation.
48
* The pseudo-teletype (or PTY) handles I/O between the terminal process and Konsole.
49
* The terminal emulation ( Emulation and subclasses ) processes the output stream from the
50
* PTY and produces a character image which is then shown on views connected to the session.
51
*
52
* Each Session can be connected to one or more views by using the addView() method.
53
* The attached views can then display output from the program running in the terminal
54
* or send input to the program in the terminal in the form of keypresses and mouse
55
* activity.
56
*/
57
class
TerminalModel
:
public
QObject
{
58
Q_OBJECT
59
60
public
:
61
Q_PROPERTY(QString
keyBindings
READ
keyBindings
WRITE
setKeyBindings
)
62
Q_PROPERTY(QSize
size
READ
size
WRITE
setSize
)
63
64
/**
65
* Constructs a new session.
66
*
67
* To start the terminal process, call the run() method,
68
* after specifying the program and arguments
69
* using setProgram() and setArguments()
70
*
71
* If no program or arguments are specified explicitly, the Session
72
* falls back to using the program specified in the SHELL environment
73
* variable.
74
*/
75
TerminalModel
(
KPty
*kpty);
76
~
TerminalModel
();
77
78
79
/**
80
* Sets the profile associated with this session.
81
*
82
* @param profileKey A key which can be used to obtain the current
83
* profile settings from the SessionManager
84
*/
85
void
setProfileKey
(const QString&
profileKey
);
86
/**
87
* Returns the profile key associated with this session.
88
* This can be passed to the SessionManager to obtain the current
89
* profile settings.
90
*/
91
QString profileKey() const;
92
93
/**
94
* Adds a new view for this session.
95
*
96
* The viewing widget will display the output from the terminal and
97
* input from the viewing widget (key presses, mouse activity etc.)
98
* will be sent to the terminal.
99
*
100
* Views can be removed using removeView(). The session is automatically
101
* closed when the last view is removed.
102
*/
103
void
addView
(
TerminalView
* widget);
104
/**
105
* Removes a view from this session. When the last view is removed,
106
* the session will be closed automatically.
107
*
108
* @p widget will no longer display output from or send input
109
* to the terminal
110
*/
111
void
removeView
(
TerminalView
* widget);
112
113
/**
114
* Returns the views connected to this session
115
*/
116
QList
<
TerminalView
*>
views
() const;
117
118
/**
119
* Returns the terminal emulation instance being used to encode / decode
120
* characters to / from the process.
121
*/
122
Emulation
*
emulation
() const;
123
124
125
126
/**
127
* Sets the type of history store used by this session.
128
* Lines of output produced by the terminal are added
129
* to the history store. The type of history store
130
* used affects the number of lines which can be
131
* remembered before they are lost and the storage
132
* (in memory, on-disk etc.) used.
133
*/
134
void
setHistoryType
(const
HistoryType
&
type
);
135
/**
136
* Returns the type of history store used by this session.
137
*/
138
const
HistoryType
&
historyType
() const;
139
/**
140
* Clears the history store used by this session.
141
*/
142
void
clearHistory
();
143
144
/**
145
* Enables monitoring for activity in the session.
146
* This will cause notifySessionState() to be emitted
147
* with the NOTIFYACTIVITY state flag when output is
148
* received from the terminal.
149
*/
150
void
setMonitorActivity
(
bool
);
151
/** Returns true if monitoring for activity is enabled. */
152
bool
isMonitorActivity
() const;
153
154
/**
155
* Enables monitoring for silence in the session.
156
* This will cause notifySessionState() to be emitted
157
* with the NOTIFYSILENCE state flag when output is not
158
* received from the terminal for a certain period of
159
* time, specified with setMonitorSilenceSeconds()
160
*/
161
void
setMonitorSilence
(
bool
);
162
/**
163
* Returns true if monitoring for inactivity (silence)
164
* in the session is enabled.
165
*/
166
bool
isMonitorSilence
() const;
167
/** See setMonitorSilence() */
168
void
setMonitorSilenceSeconds
(
int
seconds);
169
170
/**
171
* Sets the key bindings used by this session. The bindings
172
* specify how input key sequences are translated into
173
* the character stream which is sent to the terminal.
174
*
175
* @param id The name of the key bindings to use. The
176
* names of available key bindings can be determined using the
177
* KeyboardTranslatorManager class.
178
*/
179
void
setKeyBindings(const QString&
id
);
180
/** Returns the name of the key bindings used by this session. */
181
QString
keyBindings
() const;
182
183
184
/** Specifies whether a utmp entry should be created for the pty used by this session. */
185
void
setAddToUtmp
(
bool
);
186
187
/**
188
* Specifies whether to close the session automatically when the terminal
189
* process terminates.
190
*/
191
void
setAutoClose
(
bool
b) {
_autoClose
= b; }
192
193
/**
194
* Sends @p text to the current foreground terminal program.
195
*/
196
void
sendText
(
const
QString&
text
)
const
;
197
198
199
/** Returns the terminal session's window size in lines and columns. */
200
QSize
size
();
201
/**
202
* Emits a request to resize the session to accommodate
203
* the specified window size.
204
*
205
* @param size The size in lines and columns to request.
206
*/
207
void
setSize
(
const
QSize&
size
);
208
209
/** Sets the text codec used by this session's terminal emulation. */
210
void
setCodec
(QTextCodec* codec);
211
212
/**
213
* Sets whether the session has a dark background or not. The session
214
* uses this information to set the COLORFGBG variable in the process's
215
* environment, which allows the programs running in the terminal to determine
216
* whether the background is light or dark and use appropriate colors by default.
217
*
218
* This has no effect once the session is running.
219
*/
220
void
setDarkBackground
(
bool
darkBackground);
221
/**
222
* Returns true if the session has a dark background.
223
* See setDarkBackground()
224
*/
225
bool
hasDarkBackground
()
const
;
226
227
/**
228
* Attempts to get the shell program to redraw the current display area.
229
* This can be used after clearing the screen, for example, to get the
230
* shell to redraw the prompt line.
231
*/
232
void
refresh
();
233
234
public
slots:
235
236
/**
237
* Starts the terminal session.
238
*
239
* This creates the terminal process and connects the teletype to it.
240
*/
241
void
run
();
242
243
/**
244
* Closes the terminal session. This sends a hangup signal
245
* (SIGHUP) to the terminal process and causes the done(Session*)
246
* signal to be emitted.
247
*/
248
void
close
();
249
250
signals:
251
252
/** Emitted when the terminal process starts. */
253
void
started
();
254
255
/**
256
* Emitted when the terminal process exits.
257
*/
258
void
finished
();
259
260
/**
261
* Emitted when output is received from the terminal process.
262
*/
263
void
receivedData
(
const
QString&
text
);
264
265
/** Emitted when the session's title has changed. */
266
void
titleChanged
();
267
268
/** Emitted when the session's profile has changed. */
269
void
profileChanged
(
const
QString& profile);
270
271
/**
272
* Emitted when the activity state of this session changes.
273
*
274
* @param state The new state of the session. This may be one
275
* of NOTIFYNORMAL, NOTIFYSILENCE or NOTIFYACTIVITY
276
*/
277
void
stateChanged
(
int
state
);
278
279
/** Emitted when a bell event occurs in the session. */
280
void
bellRequest
(
const
QString&
message
);
281
282
/**
283
* Requests that the color the text for any tabs associated with
284
* this session should be changed;
285
*
286
* TODO: Document what the parameter does
287
*/
288
void
changeTabTextColorRequest
(
int
);
289
290
/**
291
* Requests that the background color of views on this session
292
* should be changed.
293
*/
294
void
changeBackgroundColorRequest
(
const
QColor&);
295
296
/** TODO: Document me. */
297
void
openUrlRequest
(
const
QString& url);
298
299
/**
300
* Emitted when the terminal process requests a change
301
* in the size of the terminal window.
302
*
303
* @param size The requested window size in terms of lines and columns.
304
*/
305
void
resizeRequest
(
const
QSize&
size
);
306
307
/**
308
* Emitted when a profile change command is received from the terminal.
309
*
310
* @param text The text of the command. This is a string of the form
311
* "PropertyName=Value;PropertyName=Value ..."
312
*/
313
void
profileChangeCommandReceived
(
const
QString&
text
);
314
315
private
slots:
316
void
done
(
int
);
317
318
void
onReceiveBlock
(
const
char
* buffer,
int
len );
319
void
monitorTimerDone
();
320
321
void
onViewSizeChange
(
int
height,
int
width);
322
void
onEmulationSizeChange
(
int
lines ,
int
columns);
323
324
void
activityStateSet
(
int
);
325
326
//automatically detach views from sessions when view is destroyed
327
void
viewDestroyed
(
QObject
* view);
328
329
void
sendData
(
const
char
* buf,
int
len);
330
331
private
:
332
333
void
updateTerminalSize
();
334
WId
windowId
()
const
;
335
336
int
_uniqueIdentifier
;
337
338
PseudoTerminal*
_shellProcess
;
339
Emulation
*
_emulation
;
340
341
QList<TerminalView*>
_views
;
342
343
bool
_monitorActivity
;
344
bool
_monitorSilence
;
345
bool
_notifiedActivity
;
346
bool
_masterMode
;
347
bool
_autoClose
;
348
bool
_wantedClose
;
349
QTimer*
_monitorTimer
;
350
351
int
_silenceSeconds
;
352
353
bool
_addToUtmp
;
354
bool
_fullScripting
;
355
356
int
_masterFd
;
357
int
_slaveFd
;
358
359
SelfListener
*
_selfListener
;
360
KPty
*
_kpty
;
361
362
363
QColor
_modifiedBackground
;
// as set by: echo -en '\033]11;Color\007
364
365
QString
_profileKey
;
366
367
bool
_hasDarkBackground
;
368
};
369
370
371
#endif // TERMINALMODEL_H
Generated on Mon Dec 30 2013 03:04:20 for GNU Octave by
1.8.1.2