1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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 <tqtimer.h>
#include <tqframe.h>
#include <kdebug.h>
#include <tdeparts/part.h>
#include <klibloader.h>
#include <kde_terminal_interface.h>
#include <kprocess.h>
#include "tdevshellwidget.h"
TDevShellWidget::TDevShellWidget(TQWidget *parent, const char *name)
: TQVBox(parent, name), m_doAutoActivate( false ), m_isRunning( false )
{
}
TDevShellWidget::~TDevShellWidget()
{
}
void TDevShellWidget::setShell( const TQString & shell, const TQStrList & arguments )
{
m_shellName = shell;
m_shellArguments = arguments;
}
void TDevShellWidget::activate( )
{
KLibFactory *factory = KLibLoader::self()->factory("libkonsolepart");
if ( !factory ) return;
m_konsolePart = (KParts::ReadOnlyPart *) factory->create( TQT_TQOBJECT(this), "libkonsolepart", "KParts::ReadOnlyPart" );
if ( !m_konsolePart ) return;
connect( m_konsolePart, TQT_SIGNAL( processExited(TDEProcess *) ), this, TQT_SLOT( processExited(TDEProcess *) ) );
connect( m_konsolePart, TQT_SIGNAL( receivedData( const TQString& ) ), this, TQT_SIGNAL( receivedData( const TQString& ) ) );
connect( m_konsolePart, TQT_SIGNAL(destroyed()), this, TQT_SLOT(partDestroyed()) );
m_konsolePart->widget()->setFocusPolicy( TQ_WheelFocus );
setFocusProxy( m_konsolePart->widget() );
m_konsolePart->widget()->setFocus();
if ( m_konsolePart->widget()->inherits(TQFRAME_OBJECT_NAME_STRING) )
((TQFrame*)m_konsolePart->widget())->setFrameStyle( TQFrame::Panel | TQFrame::Sunken );
m_konsolePart->widget()->show();
TerminalInterface* ti = static_cast<TerminalInterface*>( m_konsolePart->tqt_cast( "TerminalInterface" ) );
if( !ti ) return;
if ( !m_shellName.isEmpty() )
ti->startProgram( m_shellName, m_shellArguments );
m_isRunning = true;
}
void TDevShellWidget::partDestroyed( )
{
if ( m_doAutoActivate )
{
activate();
}
}
void TDevShellWidget::processExited( TDEProcess * 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 TDevShellWidget::sendInput( const TQString & text )
{
if ( !m_konsolePart ) return;
TerminalInterface* ti = static_cast<TerminalInterface*>( m_konsolePart->tqt_cast( "TerminalInterface" ) );
if( !ti ) return;
ti->sendInput( text );
}
bool TDevShellWidget::isRunning( )
{
return m_isRunning;
}
void TDevShellWidget::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 )
TQTimer::singleShot( 3000, this, TQT_SLOT(setAutoReactivateOnCloseDelayed()) );
else
m_doAutoActivate = false;
}
void TDevShellWidget::setAutoReactivateOnCloseDelayed( )
{
m_doAutoActivate = true;
}
#include "tdevshellwidget.moc"
// kate: space-indent off; indent-width 4; tab-width 4; show-tabs off;
|