3 xconsole widget for KDM
5 Copyright (C) 2002-2003 Oswald Buddenhagen <ossi@kde.org>
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.
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.
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 02110-1301, USA.
25 #include "kdmconfig.h"
26 #include "kdm_greet.h"
31 #include <QSocketNotifier>
39 #include <sys/ioctl.h>
42 /* for HP-UX (some versions) the extern C is needed, and for other
43 platforms it doesn't hurt */
50 /* needed at least on AIX */
55 #if defined (_HPUX_SOURCE)
56 #define _TERMIOS_INCLUDED
60 KConsole::KConsole( QWidget
*_parent
)
61 : inherited( _parent
)
67 setLineWrapMode( NoWrap
);
70 append( i18n("*** Cannot connect to console log ***") );
79 KConsole::openConsole()
82 static const char on
= 1;
86 if ((fd
= open( _logSource
, O_RDONLY
| O_NONBLOCK
)) >= 0)
88 logError( "Cannot open log source %s, "
89 "falling back to /dev/console.\n", _logSource
);
100 if (ioctl( pty
->slaveFd(), TIOCCONS
, &on
) < 0) {
101 perror( "ioctl TIOCCONS" );
108 if ((consfd
= open( "/dev/console", O_RDONLY
)) < 0) {
109 perror( "opening /dev/console" );
114 if (ioctl( consfd
, SRIOCSREDIR
, pty
->slaveFd() ) < 0) {
115 perror( "ioctl SRIOCSREDIR" );
123 fd
= pty
->masterFd();
126 notifier
= new QSocketNotifier( fd
, QSocketNotifier::Read
, this );
127 connect( notifier
, SIGNAL(activated( int )), SLOT(slotData()) );
132 KConsole::closeConsole()
150 if ((n
= read( fd
, buffer
, sizeof(buffer
) )) <= 0) {
152 if (n
|| !openConsole())
153 append( i18n("\n*** Lost connection with console log ***") );
155 QString
str( QString::fromLocal8Bit( buffer
, n
).remove( '\r' ) );
157 for (opos
= 0; (pos
= str
.indexOf( '\n', opos
)) >= 0; opos
= pos
+ 1) {
158 if (document()->blockCount() == 100) {
159 QTextCursor
cur( document() );
160 cur
.movePosition( QTextCursor::NextBlock
, QTextCursor::KeepAnchor
);
161 cur
.removeSelectedText();
163 if (!leftover
.isEmpty()) {
164 append( leftover
+ str
.mid( opos
, pos
- opos
) );
167 append( str
.mid( opos
, pos
- opos
) );
169 leftover
+= str
.mid( opos
);
173 #include "kconsole.moc"