summaryrefslogtreecommitdiffstats
path: root/kdm/kfrontend/kconsole.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kdm/kfrontend/kconsole.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdm/kfrontend/kconsole.cpp')
-rw-r--r--kdm/kfrontend/kconsole.cpp183
1 files changed, 183 insertions, 0 deletions
diff --git a/kdm/kfrontend/kconsole.cpp b/kdm/kfrontend/kconsole.cpp
new file mode 100644
index 000000000..b101712da
--- /dev/null
+++ b/kdm/kfrontend/kconsole.cpp
@@ -0,0 +1,183 @@
+/*
+
+xconsole widget for KDM
+
+Copyright (C) 2002-2003 Oswald Buddenhagen <ossi@kde.org>
+
+
+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.
+
+*/
+
+#include <config.h>
+
+#ifdef WITH_KDM_XCONSOLE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/ioctl.h>
+
+#ifdef HAVE_TERMIOS_H
+/* for HP-UX (some versions) the extern C is needed, and for other
+ platforms it doesn't hurt */
+extern "C" {
+#include <termios.h>
+}
+#endif
+#if !defined(__osf__)
+#ifdef HAVE_TERMIO_H
+/* needed at least on AIX */
+#include <termio.h>
+#endif
+#endif
+
+#if defined (_HPUX_SOURCE)
+#define _TERMIOS_INCLUDED
+#include <bsdtty.h>
+#endif
+
+
+#include "kconsole.h"
+#include "kdmconfig.h"
+#include "kdm_greet.h"
+
+#include <klocale.h>
+#include <kpty.h>
+
+#include <qsocketnotifier.h>
+
+KConsole::KConsole( QWidget *_parent )
+ : inherited( _parent )
+ , pty( 0 )
+ , notifier( 0 )
+ , fd( -1 )
+{
+ setReadOnly( true );
+ setWordWrap( NoWrap );
+ setTextFormat( PlainText );
+
+ if (!OpenConsole())
+ append( i18n("Cannot open console") );
+}
+
+KConsole::~KConsole()
+{
+ CloseConsole();
+}
+
+int
+KConsole::OpenConsole()
+{
+#ifdef TIOCCONS
+ static const char on = 1;
+#endif
+
+ if (*_logSource) {
+ if ((fd = open( _logSource, O_RDONLY | O_NONBLOCK )) >= 0)
+ goto gotcon;
+ LogError( "Cannot open log source %s, "
+ "falling back to /dev/console.\n", _logSource );
+ }
+
+ pty = new KPty;
+ if (!pty->open()) {
+ delete pty;
+ pty = 0;
+ return 0;
+ }
+
+#ifdef TIOCCONS
+ if (ioctl( pty->slaveFd(), TIOCCONS, &on ) < 0) {
+ perror( "ioctl TIOCCONS" );
+ delete pty;
+ pty = 0;
+ return 0;
+ }
+#else
+ int consfd;
+ if ((consfd = open( "/dev/console", O_RDONLY )) < 0) {
+ perror( "opening /dev/console" );
+ delete pty;
+ pty = 0;
+ return 0;
+ }
+ if (ioctl( consfd, SRIOCSREDIR, slave_fd ) < 0) {
+ perror( "ioctl SRIOCSREDIR" );
+ ::close( consfd );
+ delete pty;
+ pty = 0;
+ return 0;
+ }
+ ::close( consfd );
+#endif
+ fd = pty->masterFd();
+
+ gotcon:
+ notifier = new QSocketNotifier( fd, QSocketNotifier::Read, this );
+ connect( notifier, SIGNAL(activated( int )), SLOT(slotData()) );
+ return 1;
+}
+
+void
+KConsole::CloseConsole()
+{
+ delete notifier;
+ notifier = 0;
+ if (pty) {
+ delete pty;
+ pty = 0;
+ } else
+ ::close( fd );
+ fd = -1;
+}
+
+void
+KConsole::slotData()
+{
+ int n;
+ char buffer[1024];
+
+ if ((n = read( fd, buffer, sizeof(buffer) )) <= 0) {
+ CloseConsole();
+ if (!n)
+ if (!OpenConsole())
+ append( i18n("\n*** Cannot open console log source ***") );
+ } else {
+ bool as = !verticalScrollBar()->isVisible() ||
+ (verticalScrollBar()->value() ==
+ verticalScrollBar()->maxValue());
+ QString str( QString::fromLocal8Bit( buffer, n ).remove( '\r' ) );
+ int pos, opos;
+ for (opos = 0; (pos = str.find( '\n', opos )) >= 0; opos = pos + 1) {
+ if (paragraphs() == 100)
+ removeParagraph( 0 );
+ if (!leftover.isEmpty()) {
+ append( leftover + str.mid( opos, pos - opos ) );
+ leftover = QString::null;
+ } else
+ append( str.mid( opos, pos - opos ) );
+ }
+ leftover += str.mid( opos );
+ if (as)
+ scrollToBottom();
+ }
+}
+
+#include "kconsole.moc"
+
+#endif