00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
#include "kateconsole.h"
00022
#include "kateconsole.moc"
00023
00024
#include "katemainwindow.h"
00025
00026
#include <kate/view.h>
00027
#include <kate/document.h>
00028
00029
#include <kde_terminal_interface.h>
00030
00031
#include <kurl.h>
00032
#include <klibloader.h>
00033
#include <klocale.h>
00034
#include <kapplication.h>
00035
#include <kdebug.h>
00036
00037
#include <qlayout.h>
00038
00039 KateConsole::KateConsole (QWidget* parent,
const char* name,
Kate::ViewManager *kvm) : QWidget (parent, name),part(0)
00040 {
00041
00042 lo =
new QVBoxLayout(
this);
00043 m_kvm=kvm;
00044 }
00045
00046 KateConsole::~KateConsole ()
00047 {
00048 }
00049
00050
00051
void KateConsole::loadConsoleIfNeeded()
00052 {
00053 kdDebug(13001)<<
"================================ loadConsoleIfNeeded()"<<endl;
00054
if (part!=0)
return;
00055
if (!kapp->loopLevel()) {
00056 connect(kapp,SIGNAL(onEventLoopEnter()),
this,SLOT(loadConsoleIfNeeded()));
00057
return;
00058 }
00059
00060
if (!topLevelWidget() || !parentWidget())
return;
00061
if (!topLevelWidget() || !isVisibleTo(topLevelWidget()))
return;
00062
00063 kdDebug(13001)<<
"CREATING A CONSOLE PART"<<endl;
00064
00065 KLibFactory *factory = 0;
00066 factory = KLibLoader::self()->factory(
"libkonsolepart");
00067 part = 0L;
00068
if (factory)
00069 {
00070 part = static_cast<KParts::ReadOnlyPart *>(factory->create(
this,
"libkonsolepart",
00071
"KParts::ReadOnlyPart"));
00072
if (part)
00073 {
00074 KGlobal::locale()->insertCatalogue(
"konsole");
00075 part->widget()->show();
00076 lo->addWidget(part->widget());
00077 connect ( part, SIGNAL(destroyed()),
this, SLOT(slotDestroyed()) );
00078
if (m_kvm->activeView())
00079
if (m_kvm->activeView()->getDoc()->url().isValid())
00080 cd(KURL( m_kvm->activeView()->getDoc()->url().path() ));
00081 }
00082 }
00083 }
00084
00085
void KateConsole::showEvent(QShowEvent *)
00086 {
00087
if (!part)
00088 loadConsoleIfNeeded();
00089 }
00090
00091
void KateConsole::cd (KURL url)
00092 {
00093
if (!part)
00094
return;
00095
00096 part->openURL (url);
00097 }
00098
00099
void KateConsole::sendInput(
const QString& text )
00100 {
00101
if (!part)
00102
return;
00103
00104 TerminalInterface *t = static_cast<TerminalInterface*>( part->qt_cast(
"TerminalInterface" ) );
00105
00106
if (!t)
00107
return;
00108
00109 t->sendInput (text);
00110 }
00111
00112
void KateConsole::slotDestroyed ()
00113 {
00114 part=0;
00115
00116
00117
if (parentWidget())
00118 parentWidget()->hide ();
00119 }