summaryrefslogtreecommitdiffstats
path: root/lib/util/kdevshellwidget.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
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /lib/util/kdevshellwidget.cpp
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.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/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/util/kdevshellwidget.cpp')
-rw-r--r--lib/util/kdevshellwidget.cpp125
1 files changed, 125 insertions, 0 deletions
diff --git a/lib/util/kdevshellwidget.cpp b/lib/util/kdevshellwidget.cpp
new file mode 100644
index 00000000..f9a61fea
--- /dev/null
+++ b/lib/util/kdevshellwidget.cpp
@@ -0,0 +1,125 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Jens Dagerbo *
+ * jens.dagerbo@swipnet.se *
+ * *
+ * 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. *
+ * *
+ ***************************************************************************/
+
+#include <qtimer.h>
+#include <qframe.h>
+
+#include <kdebug.h>
+#include <kparts/part.h>
+#include <klibloader.h>
+#include <kde_terminal_interface.h>
+#include <kprocess.h>
+
+#include "kdevshellwidget.h"
+
+KDevShellWidget::KDevShellWidget(QWidget *parent, const char *name)
+ : QVBox(parent, name), m_doAutoActivate( false ), m_isRunning( false )
+{
+}
+
+
+KDevShellWidget::~KDevShellWidget()
+{
+}
+
+void KDevShellWidget::setShell( const QString & shell, const QStrList & arguments )
+{
+ m_shellName = shell;
+ m_shellArguments = arguments;
+}
+
+void KDevShellWidget::activate( )
+{
+ KLibFactory *factory = KLibLoader::self()->factory("libkonsolepart");
+ if ( !factory ) return;
+
+ m_konsolePart = (KParts::ReadOnlyPart *) factory->create( this, "libkonsolepart", "KParts::ReadOnlyPart" );
+ if ( !m_konsolePart ) return;
+
+ connect( m_konsolePart, SIGNAL( processExited(KProcess *) ), this, SLOT( processExited(KProcess *) ) );
+ connect( m_konsolePart, SIGNAL( receivedData( const QString& ) ), this, SIGNAL( receivedData( const QString& ) ) );
+ connect( m_konsolePart, SIGNAL(destroyed()), this, SLOT(partDestroyed()) );
+
+ m_konsolePart->widget()->setFocusPolicy( QWidget::WheelFocus );
+ setFocusProxy( m_konsolePart->widget() );
+ m_konsolePart->widget()->setFocus();
+
+ if ( m_konsolePart->widget()->inherits("QFrame") )
+ ((QFrame*)m_konsolePart->widget())->setFrameStyle( QFrame::Panel | QFrame::Sunken );
+
+ m_konsolePart->widget()->show();
+
+ TerminalInterface* ti = static_cast<TerminalInterface*>( m_konsolePart->qt_cast( "TerminalInterface" ) );
+ if( !ti ) return;
+
+ if ( !m_shellName.isEmpty() )
+ ti->startProgram( m_shellName, m_shellArguments );
+
+ m_isRunning = true;
+
+}
+
+void KDevShellWidget::partDestroyed( )
+{
+ if ( m_doAutoActivate )
+ {
+ activate();
+ }
+}
+
+void KDevShellWidget::processExited( KProcess * proc )
+{
+ m_isRunning = false;
+
+ if ( !proc ) return;
+
+ kdDebug(9000) << proc->args() << endl;
+
+ if ( proc->normalExit() )
+ emit shellExited( proc->exitStatus() );
+ else if ( proc->signalled() )
+ emit shellSignalled( proc->exitSignal() );
+}
+
+void KDevShellWidget::sendInput( const QString & text )
+{
+ if ( !m_konsolePart ) return;
+ TerminalInterface* ti = static_cast<TerminalInterface*>( m_konsolePart->qt_cast( "TerminalInterface" ) );
+ if( !ti ) return;
+
+ ti->sendInput( text );
+}
+
+bool KDevShellWidget::isRunning( )
+{
+ return m_isRunning;
+}
+
+void KDevShellWidget::setAutoReactivateOnClose( bool doAutoActivate )
+{
+ // to auto reactivate can be dangerous, do it like this to avoid
+ // reactivating with a non-working setting (the partDestroyed()
+ // slot will have ran before m_doAutoActivate is set)
+ if ( doAutoActivate )
+ QTimer::singleShot( 3000, this, SLOT(setAutoReactivateOnCloseDelayed()) );
+ else
+ m_doAutoActivate = false;
+}
+
+void KDevShellWidget::setAutoReactivateOnCloseDelayed( )
+{
+ m_doAutoActivate = true;
+}
+
+
+#include "kdevshellwidget.moc"
+
+// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;