2
This file is part of Konsole, an X terminal.
3
Copyright (C) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
5
Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27
#include <sys/types.h>
37
//#include <KStandardDirs>
42
using namespace Konsole;
46
emit done( exitStatus() );
49
void Pty::setWindowSize( int lines, int cols )
51
_windowColumns = cols;
54
if ( pty()->masterFd() >= 0 )
55
pty()->setWinSize( lines, cols );
57
QSize Pty::windowSize() const
59
return QSize( _windowColumns, _windowLines );
62
void Pty::setXonXoff( bool enable )
66
if ( pty()->masterFd() >= 0 )
68
struct ::termios ttmode;
69
pty()->tcGetAttr( &ttmode );
71
ttmode.c_iflag &= ~( IXOFF | IXON );
73
ttmode.c_iflag |= ( IXOFF | IXON );
74
if ( !pty()->tcSetAttr( &ttmode ) )
75
qWarning( "Unable to set terminal attributes." );
79
void Pty::setUtf8Mode( bool enable )
81
#ifdef IUTF8 // XXX not a reasonable place to check it.
84
if ( pty()->masterFd() >= 0 )
86
struct ::termios ttmode;
87
pty()->tcGetAttr( &ttmode );
89
ttmode.c_iflag &= ~IUTF8;
91
ttmode.c_iflag |= IUTF8;
92
if ( !pty()->tcSetAttr( &ttmode ) )
93
qWarning( "Unable to set terminal attributes." );
98
void Pty::setErase( char erase )
102
if ( pty()->masterFd() >= 0 )
104
struct ::termios ttmode;
106
pty()->tcGetAttr( &ttmode );
108
ttmode.c_cc[VERASE] = erase;
110
if ( !pty()->tcSetAttr( &ttmode ) )
111
qWarning( "Unable to set terminal attributes." );
115
char Pty::erase() const
117
if ( pty()->masterFd() >= 0 )
119
qDebug() << "Getting erase char";
120
struct ::termios ttyAttributes;
121
pty()->tcGetAttr( &ttyAttributes );
122
return ttyAttributes.c_cc[VERASE];
128
void Pty::addEnvironmentVariables( const QStringList& environment )
130
QListIterator<QString> iter( environment );
131
while ( iter.hasNext() )
133
QString pair = iter.next();
135
// split on the first '=' character
136
int pos = pair.indexOf( '=' );
140
QString variable = pair.left( pos );
141
QString value = pair.mid( pos + 1 );
143
//kDebug() << "Setting environment pair" << variable <<
144
// " set to " << value;
146
setEnvironment( variable, value );
151
int Pty::start( const QString& program,
152
const QStringList& programArguments,
153
const QStringList& environment,
156
// const QString& dbusService,
157
// const QString& dbusSession)
162
setBinaryExecutable( program.toLatin1() );
164
addEnvironmentVariables( environment );
166
QStringListIterator it( programArguments );
167
while ( it.hasNext() )
168
arguments.append( it.next().toUtf8() );
170
// if ( !dbusService.isEmpty() )
171
// setEnvironment("KONSOLE_DBUS_SERVICE",dbusService);
172
// if ( !dbusSession.isEmpty() )
173
// setEnvironment("KONSOLE_DBUS_SESSION", dbusSession);
175
setEnvironment( "WINDOWID", QString::number( winid ) );
177
// unless the LANGUAGE environment variable has been set explicitly
178
// set it to a null string
179
// this fixes the problem where KCatalog sets the LANGUAGE environment
180
// variable during the application's startup to something which
181
// differs from LANG,LC_* etc. and causes programs run from
182
// the terminal to display mesages in the wrong language
184
// this can happen if LANG contains a language which KDE
185
// does not have a translation for
188
if ( !environment.contains( "LANGUAGE" ) )
189
setEnvironment( "LANGUAGE", QString() );
191
setUsePty( All, addToUtmp );
195
struct ::termios ttmode;
196
pty()->tcGetAttr( &ttmode );
198
ttmode.c_iflag &= ~( IXOFF | IXON );
200
ttmode.c_iflag |= ( IXOFF | IXON );
201
#ifdef IUTF8 // XXX not a reasonable place to check it.
203
ttmode.c_iflag &= ~IUTF8;
205
ttmode.c_iflag |= IUTF8;
208
if ( _eraseChar != 0 )
209
ttmode.c_cc[VERASE] = _eraseChar;
211
if ( !pty()->tcSetAttr( &ttmode ) )
212
qWarning( "Unable to set terminal attributes." );
214
pty()->setWinSize( _windowLines, _windowColumns );
216
if ( K3Process::start( NotifyOnExit, ( Communication )( Stdin | Stdout ) ) == false )
219
resume(); // Start...
224
void Pty::setWriteable( bool writeable )
227
stat( pty()->ttyName(), &sbuf );
229
chmod( pty()->ttyName(), sbuf.st_mode | S_IWGRP );
231
chmod( pty()->ttyName(), sbuf.st_mode & ~( S_IWGRP | S_IWOTH ) );
235
: _bufferFull( false ),
242
connect( this, SIGNAL( receivedStdout( K3Process *, char *, int ) ),
243
this, SLOT( dataReceived( K3Process *, char *, int ) ) );
244
connect( this, SIGNAL( processExited( K3Process * ) ),
245
this, SLOT( donePty() ) );
246
connect( this, SIGNAL( wroteStdin( K3Process * ) ),
247
this, SLOT( writeReady() ) );
250
setUsePty( All, false ); // utmp will be overridden later
258
void Pty::writeReady()
260
_pendingSendJobs.erase( _pendingSendJobs.begin() );
265
void Pty::doSendJobs()
267
if ( _pendingSendJobs.isEmpty() )
273
SendJob& job = _pendingSendJobs.first();
276
if ( !writeStdin( job.data(), job.length() ) )
278
qWarning( "Pty::doSendJobs - Could not send input data to terminal process." );
284
void Pty::appendSendJob( const char* s, int len )
286
_pendingSendJobs.append( SendJob( s, len ) );
289
void Pty::sendData( const char* s, int len )
291
appendSendJob( s, len );
296
void Pty::dataReceived( K3Process *, char *buf, int len )
298
emit receivedData( buf, len );
301
void Pty::lockPty( bool lock )
309
int Pty::foregroundProcessGroup() const
311
int pid = tcgetpgrp( pty()->masterFd() );
321
//#include "moc_Pty.cpp"