kateconsole.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
00003    Copyright (C) 2002 Joseph Wenninger <jowenn@kde.org>
00004    Copyright (C) 2002 Anders Lund <anders.lund@lund.tdcadsl.dk>
00005 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kateconsole.h"
00022 #include "kateconsole.moc"
00023 
00024 #include "katemain.h"
00025 #include "katemdi.h"
00026 #include "katemainwindow.h"
00027 #include "kateviewmanager.h"
00028 
00029 #include <kate/view.h>
00030 #include <kate/document.h>
00031 
00032 #include <kde_terminal_interface.h>
00033 
00034 #include <kparts/part.h>
00035 
00036 #include <kurl.h>
00037 #include <klibloader.h>
00038 #include <klocale.h>
00039 #include <kdebug.h>
00040 #include <kmessagebox.h>
00041 
00042 KateConsole::KateConsole (KateMainWindow *mw, KateMDI::ToolView* parent)
00043  : QVBox (parent)
00044  , m_part (0)
00045  , m_mw (mw)
00046  , m_toolView (parent)
00047 {
00048 }
00049 
00050 KateConsole::~KateConsole ()
00051 {
00052   disconnect ( m_part, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
00053 }
00054 
00055 void KateConsole::loadConsoleIfNeeded()
00056 {
00057   if (m_part) return;
00058 
00059   if (!topLevelWidget() || !parentWidget()) return;
00060   if (!topLevelWidget() || !isVisibleTo(topLevelWidget())) return;
00061 
00062   KLibFactory *factory = KLibLoader::self()->factory("libkonsolepart");
00063 
00064   if (!factory) return;
00065 
00066   m_part = static_cast<KParts::ReadOnlyPart *>(factory->create(this,"libkonsolepart", "KParts::ReadOnlyPart"));
00067 
00068   if (!m_part) return;
00069 
00070   KGlobal::locale()->insertCatalogue("konsole");
00071 
00072   m_part->widget()->show();
00073 
00074   connect ( m_part, SIGNAL(destroyed()), this, SLOT(slotDestroyed()) );
00075 
00076   if (m_mw->viewManager()->activeView())
00077     if (m_mw->viewManager()->activeView()->getDoc()->url().isValid())
00078       cd(KURL( m_mw->viewManager()->activeView()->getDoc()->url().path() ));
00079 }
00080 
00081 void KateConsole::slotDestroyed ()
00082 {
00083   m_part = 0;
00084 
00085   // hide the dockwidget
00086   if (parentWidget())
00087   {
00088     m_mw->hideToolView (m_toolView);
00089     m_mw->centralWidget()->setFocus ();
00090   }
00091 }
00092 
00093 void KateConsole::showEvent(QShowEvent *)
00094 {
00095   if (m_part) return;
00096 
00097   loadConsoleIfNeeded();
00098 }
00099 
00100 void KateConsole::cd (const KURL &url)
00101 {
00102   loadConsoleIfNeeded();
00103 
00104   if (!m_part) return;
00105 
00106   m_part->openURL (url);
00107 }
00108 
00109 void KateConsole::sendInput( const QString& text )
00110 {
00111   loadConsoleIfNeeded();
00112 
00113   if (!m_part) return;
00114 
00115   TerminalInterface *t = static_cast<TerminalInterface*>( m_part->qt_cast( "TerminalInterface" ) );
00116 
00117   if (!t) return;
00118 
00119   t->sendInput (text);
00120 }
00121 
00122 void KateConsole::slotPipeToConsole ()
00123 {
00124   if (KMessageBox::warningContinueCancel
00125       (m_mw
00126        , i18n ("Do you really want to pipe the text to the console? This will execute any contained commands with your user rights.")
00127        , i18n ("Pipe to Console?")
00128        , i18n("Pipe to Console"), "Pipe To Console Warning") != KMessageBox::Continue)
00129     return;
00130 
00131   Kate::View *v = m_mw->viewManager()->activeView();
00132 
00133   if (!v)
00134     return;
00135 
00136   if (v->getDoc()->hasSelection ())
00137     sendInput (v->getDoc()->selection());
00138   else
00139     sendInput (v->getDoc()->text());
00140 }
KDE Home | KDE Accessibility Home | Description of Access Keys