29 #include <KServiceTypeTrader>
30 #include <KParts/ReadOnlyPart>
31 #include <kde_terminal_interface.h>
34 #include <QtGui/QLayout>
35 #include <QtGui/QFrame>
36 #include <QtCore/QDir>
46 mTerminalInterface( 0 )
48 QVBoxLayout* layout =
new QVBoxLayout(
this );
49 layout->setMargin( 0 );
51 connect( mTool, SIGNAL(currentUrlChanged(KUrl)), SLOT(onCurrentUrlChanged(KUrl)) );
52 QMetaObject::invokeMethod(
this,
"createTerminalPart", Qt::QueuedConnection );
55 void TerminalView::createTerminalPart()
58 KServiceTypeTrader::createInstanceFromQuery<KParts::ReadOnlyPart>(
59 QString::fromLatin1(
"TerminalEmulator"),
this, this );
63 connect( mTerminalPart, SIGNAL(destroyed(
QObject*)), SLOT(onTerminalPartDestroyed()) );
65 QWidget* terminalWidget = mTerminalPart->widget();
66 terminalWidget->setFocusPolicy( Qt::WheelFocus );
67 terminalWidget->setFocus();
68 setFocusProxy( terminalWidget );
70 QFrame* frame = qobject_cast<QFrame*>( terminalWidget );
72 frame->setFrameStyle( QFrame::Panel | QFrame::Sunken );
74 QVBoxLayout* layout =
static_cast<QVBoxLayout*
>( this->layout() );
75 layout->addWidget( terminalWidget );
76 terminalWidget->show();
78 mTerminalInterface = qobject_cast<TerminalInterface*>( mTerminalPart );
80 if( currentUrl.isEmpty() )
81 currentUrl = QDir::homePath();
82 onCurrentUrlChanged( currentUrl );
86 void TerminalView::onCurrentUrlChanged(
const KUrl& currentUrl )
88 if( mTerminalInterface && currentUrl.isLocalFile() )
89 mTerminalInterface->showShellInDir( currentUrl.path() );
93 void TerminalView::onTerminalPartDestroyed()
96 mTerminalInterface = 0;
TerminalView(TerminalTool *tool, QWidget *parent=0)