diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 02:13:59 +0000 |
commit | a6d58bb6052ac8cb01805a48c4ad2f129126116f (patch) | |
tree | dd867a099fcbb263a8009a9fb22695b87855dad6 /src/modules/term | |
download | kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.tar.gz kvirc-a6d58bb6052ac8cb01805a48c4ad2f129126116f.zip |
Added KDE3 version of kvirc
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1095341 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/modules/term')
-rw-r--r-- | src/modules/term/Makefile.am | 21 | ||||
-rw-r--r-- | src/modules/term/libkviterm.cpp | 167 | ||||
-rw-r--r-- | src/modules/term/termwidget.cpp | 179 | ||||
-rw-r--r-- | src/modules/term/termwidget.h | 72 | ||||
-rw-r--r-- | src/modules/term/termwindow.cpp | 84 | ||||
-rw-r--r-- | src/modules/term/termwindow.h | 54 |
6 files changed, 577 insertions, 0 deletions
diff --git a/src/modules/term/Makefile.am b/src/modules/term/Makefile.am new file mode 100644 index 00000000..1567e615 --- /dev/null +++ b/src/modules/term/Makefile.am @@ -0,0 +1,21 @@ +############################################################################### +# KVirc IRC client Makefile - 10.03.2000 Szymon Stefanek <stefanek@tin.it> +############################################################################### + +AM_CPPFLAGS = -I$(SS_TOPSRCDIR)/src/kvilib/include/ -I$(SS_TOPSRCDIR)/src/kvirc/include/ \ +$(SS_INCDIRS) $(SS_CPPFLAGS) -DGLOBAL_KVIRC_DIR=\"$(globalkvircdir)\" + +pluglib_LTLIBRARIES = libkviterm.la + +libkviterm_la_LDFLAGS = -module -avoid-version $(SS_LDFLAGS) $(SS_LIBDIRS) + +libkviterm_la_SOURCES = libkviterm.cpp termwidget.cpp termwindow.cpp +libkviterm_la_LIBADD = $(SS_LIBLINK) ../../kvilib/build/libkvilib.la + +noinst_HEADERS= termwidget.h termwindow.h + +%.moc: %.h + $(SS_QT_MOC) $< -o $@ + +termwidget.cpp: termwidget.moc +termwindow.cpp: termwindow.moc diff --git a/src/modules/term/libkviterm.cpp b/src/modules/term/libkviterm.cpp new file mode 100644 index 00000000..742aaa62 --- /dev/null +++ b/src/modules/term/libkviterm.cpp @@ -0,0 +1,167 @@ +// +// File : libkviterm.cpp +// Creation date : Wed Aug 30 2000 15:29:02 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) +// +// 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 opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#include "kvi_settings.h" + +#include "kvi_module.h" + +#include "kvi_window.h" + +#include "kvi_frame.h" + +#include <qsplitter.h> +#include "kvi_pointerlist.h" + +#ifdef COMPILE_KDE_SUPPORT + + #include "termwidget.h" + #include "termwindow.h" + + #include "ktrader.h" + +// #include "kparts/part.h" +// #include "kparts/factory.h" +// #include "klibloader.h" + +#endif + +KviModule * g_pTermModule = 0; + +#ifdef COMPILE_KDE_SUPPORT + KviPointerList<KviTermWidget> * g_pTermWidgetList = 0; + KviPointerList<KviTermWindow> * g_pTermWindowList = 0; + KviStr g_szKonsoleLibraryName = ""; +#endif + +/* + @doc: term.open + @type: + command + @title: + term.open + @short: + Shows a terminal emulator + @syntax: + term.open [-m] + @switches: + !sw: -m | --mdi + creates terminal as a MDI window + @description: + Opens a new terminal window (If the service is available). + if the -m switch is present, the created terminal as a MDI window, + otherwise it is a static window.[br] + This command is exported by the "term" module.[br] + Note: At the time that this module was written, the + KDE terminal emulator module was quite unstable; no extensive + testings have been made on this. +*/ + +static bool term_kvs_cmd_open(KviKvsModuleCommandCall * c) +{ +#ifdef COMPILE_KDE_SUPPORT + if(g_szKonsoleLibraryName.hasData()) + { + c->module()->lock(); // multiple locks are allowed + if(c->hasSwitch('m',"mdi")) + { + KviTermWindow *w = new KviTermWindow(c->window()->frame(),"Terminal emulator"); + c->window()->frame()->addWindow(w); + } else { + KviTermWidget *w = new KviTermWidget(c->window()->frame()->splitter(), + c->window()->frame(),true); + w->show(); + } + } else { + c->warning("No terminal emulation service available"); + } +#else + c->warning("Terminal emulation service not supported (non-KDE compilation)"); +#endif + return true; +} + +static bool term_module_init(KviModule * m) +{ + g_pTermModule = m; + +#ifdef COMPILE_KDE_SUPPORT + g_pTermWidgetList = new KviPointerList<KviTermWidget>; + g_pTermWidgetList->setAutoDelete(false); + g_pTermWindowList = new KviPointerList<KviTermWindow>; + g_pTermWindowList->setAutoDelete(false); + +// KTrader::OfferList offers = KTrader::self()->query("Browser/View","KonsolePart"); +// KTrader::OfferList offers = KTrader::self()->query("Browser/View",""); +// if(offers.count() > 0) +// { +// KTrader::OfferList::Iterator it = offers.begin(); +// while(it != offers.end()) +// { +// KviStr tmp = (*it)->name(); +// KviStr tmp2 = (*it)->type(); +// KviStr tmp3 = (*it)->library(); +// debug("Got Service name:%s type:%s library:%s",tmp.ptr(),tmp2.ptr(),tmp3.ptr()); +// ++it; +// } +// } +// KService::Ptr service = *offers.begin(); + KService::Ptr pKonsoleService = KService::serviceByName("Terminal Emulator"); + if(!pKonsoleService)pKonsoleService = KService::serviceByName("KonsolePart"); + if(!pKonsoleService)pKonsoleService = KService::serviceByName("Terminal *"); + if(pKonsoleService) + { + g_szKonsoleLibraryName = pKonsoleService->library(); +// debug("KONSOLE LIB %s",g_szKonsoleLibraryName.ptr()); + } +// delete pKonsoleService; +#endif + +// m->registerCommand("open",term_module_cmd_open); +#ifdef COMPILE_NEW_KVS + KVSM_REGISTER_SIMPLE_COMMAND(m,"open",term_kvs_cmd_open); +#endif + return true; +} + +static bool term_module_cleanup(KviModule *m) +{ +#ifdef COMPILE_KDE_SUPPORT + while(g_pTermWidgetList->first())delete g_pTermWidgetList->first(); + delete g_pTermWidgetList; + g_pTermWidgetList = 0; + while(g_pTermWindowList->first())g_pTermWindowList->first()->close(); + delete g_pTermWindowList; + g_pTermWindowList = 0; +#endif + return true; +} + +KVIRC_MODULE( + "Term", // module name + "1.0.0", // module version + "Copyright (C) 2000 Szymon Stefanek (pragma at kvirc dot net)", // author & (C) + "Terminal emulator extension based on the KonsolePart KDE class", + term_module_init, + 0, + 0, + term_module_cleanup +) diff --git a/src/modules/term/termwidget.cpp b/src/modules/term/termwidget.cpp new file mode 100644 index 00000000..45bf63a0 --- /dev/null +++ b/src/modules/term/termwidget.cpp @@ -0,0 +1,179 @@ +// +// File : termwidget.cpp +// Creation date : Thu Aug 10 2000 17:42:12 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2000-2005 Szymon Stefanek (pragma at kvirc dot net) +// +// 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 opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#include "termwidget.h" +#include "termwindow.h" + +#include "kvi_module.h" +#include "kvi_frame.h" +#include "kvi_iconmanager.h" +#include "kvi_locale.h" + +#include <qlabel.h> +#include "kvi_pointerlist.h" +#include <qtooltip.h> +#include <qtimer.h> + +#ifdef COMPILE_KDE_SUPPORT + +#include "klibloader.h" +#include "kparts/part.h" +#include "kparts/factory.h" + +extern KviModule * g_pTermModule; +extern KviPointerList<KviTermWidget> * g_pTermWidgetList; +extern KviPointerList<KviTermWindow> * g_pTermWindowList; +extern KviStr g_szKonsoleLibraryName; + +KviTermWidget::KviTermWidget(QWidget * par,KviFrame * lpFrm,bool bIsStandalone) +: QFrame(par,"term_widget") +{ + if(bIsStandalone)g_pTermWidgetList->append(this); + m_bIsStandalone = bIsStandalone; + + m_pKonsolePart = 0; + m_pKonsoleWidget = 0; + + if(bIsStandalone) + { + m_pHBox = new KviTalHBox(this); + m_pTitleLabel = new QLabel(__tr2qs("Terminal emulator"),m_pHBox); + m_pTitleLabel->setFrameStyle(QFrame::Raised | QFrame::WinPanel); + m_pCloseButton = new QPushButton("",m_pHBox); + m_pCloseButton->setPixmap(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_CLOSE))); + QToolTip::add(m_pCloseButton,__tr2qs("Close this window")); + m_pHBox->setStretchFactor(m_pTitleLabel,2); + connect(m_pCloseButton,SIGNAL(clicked()),this,SLOT(closeClicked())); + } else { + m_pHBox = 0; + m_pTitleLabel = 0; + m_pCloseButton = 0; + } + + setFrameStyle(QFrame::Sunken | QFrame::Panel); + + KParts::Factory * pKonsoleFactory = static_cast<KParts::Factory *>( + KLibLoader::self()->factory(g_szKonsoleLibraryName.ptr())); + + if(pKonsoleFactory) + { +// debug("FACTORY %d",pKonsoleFactory); + m_pKonsolePart = static_cast<KParts::Part *>(pKonsoleFactory->createPart( + this,"terminal emulator",this,"the konsole part")); + + if(m_pKonsolePart) + { +// debug("PART %d",m_pKonsolePart); + m_pKonsoleWidget = m_pKonsolePart->widget(); + connect(m_pKonsoleWidget,SIGNAL(destroyed()),this,SLOT(konsoleDestroyed())); +// debug("Widget %d",m_pKonsoleWidget); + } else { + m_pKonsoleWidget = new QLabel(this, + __tr2qs("Can't create the terminal emulation part")); + } + + } else { + m_pKonsoleWidget = new QLabel(this, + __tr2qs("Can't retrieve the terminal emulation factory")); + } +} + +KviTermWidget::~KviTermWidget() +{ + if(m_pKonsoleWidget) + disconnect(m_pKonsoleWidget,SIGNAL(destroyed()),this,SLOT(konsoleDestroyed())); + + if(m_bIsStandalone)g_pTermWidgetList->removeRef(this); + if(g_pTermWindowList->isEmpty() && g_pTermWidgetList->isEmpty())g_pTermModule->unlock(); + +// debug("DELETING KONSOLE WIDGET"); +// if(m_pKonsoleWidget)delete m_pKonsoleWidget; <--// Qt will delete it +// debug("DELETING KONSOLE PART"); +// if(m_pKonsolePart)delete m_pKonsolePart; <--// the part will delete self when the widget will die +// debug("KONSOLE PART DELETED"); +} + +void KviTermWidget::resizeEvent(QResizeEvent *e) +{ + int hght = 0; + if(m_bIsStandalone) + { + hght = m_pCloseButton->sizeHint().height(); + m_pHBox->setGeometry(1,1,width() - 2,hght + 1); + + } + if(m_pKonsoleWidget)m_pKonsoleWidget->setGeometry(1,hght + 1,width() - 2,height() - (hght + 2)); +} + +void KviTermWidget::closeClicked() +{ + // this is called only in standalone mode + delete this; +} + +void KviTermWidget::konsoleDestroyed() +{ + m_pKonsoleWidget = 0; + m_pKonsolePart = 0; + hide(); + QTimer::singleShot(0,this,SLOT(autoClose())); +} + +void KviTermWidget::autoClose() +{ + if(m_bIsStandalone)delete this; + else ((KviWindow *)parent())->close(); +} + +void KviTermWidget::changeTitle(int i,const QString& str) +{ + if(m_bIsStandalone)m_pTitleLabel->setText(str); +} + +void KviTermWidget::notifySize(int,int) +{ +} + +void KviTermWidget::changeColumns(int) +{ +} + +QSize KviTermWidget::sizeHint() const +{ + int hght = 0; + int wdth = 0; + if(m_pKonsoleWidget) + { + hght += m_pKonsoleWidget->sizeHint().height(); + wdth = m_pKonsoleWidget->sizeHint().width(); + } + if(m_pCloseButton) + { + hght += m_pCloseButton->sizeHint().height(); + } + + return QSize(wdth + 2,hght + 2); +} + +#include "termwidget.moc" + +#endif //COMPILE_KDE_SUPPORT diff --git a/src/modules/term/termwidget.h b/src/modules/term/termwidget.h new file mode 100644 index 00000000..88e9d9a7 --- /dev/null +++ b/src/modules/term/termwidget.h @@ -0,0 +1,72 @@ +#ifndef _HELPWIDGET_H_ +#define _HELPWIDGET_H_ +// +// File : termwidget.h +// Creation date : Wed Aug 30 2000 15:34:20 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) +// +// 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 opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#include "kvi_settings.h" + +#ifdef COMPILE_KDE_SUPPORT + +#include <qframe.h> +#include <qlabel.h> +#include <qpushbutton.h> +#include "kvi_tal_hbox.h" + +#include "kparts/part.h" + + +class KviFrame; + +class KviTermWidget : public QFrame +{ + Q_OBJECT + Q_PROPERTY( int KviProperty_ChildFocusOwner READ dummy ) +public: + KviTermWidget(QWidget * par,KviFrame * lpFrm,bool bIsStandalone = false); + ~KviTermWidget(); +private: + KviTalHBox * m_pHBox; + QLabel * m_pTitleLabel; + QPushButton * m_pCloseButton; + KParts::Part * m_pKonsolePart; + bool m_bIsStandalone; + QWidget * m_pKonsoleWidget; +protected: + virtual void resizeEvent(QResizeEvent *e); +protected slots: + void closeClicked(); + void changeTitle(int i,const QString& str); + void notifySize(int,int); + void changeColumns(int); +public: + QWidget * konsoleWidget(){ return m_pKonsoleWidget ? m_pKonsoleWidget : this; }; + virtual QSize sizeHint() const; + int dummy() const { return 0; }; +protected slots: + void konsoleDestroyed(); + void autoClose(); +}; + +#endif + + +#endif //_HELPWIDGET_H_ diff --git a/src/modules/term/termwindow.cpp b/src/modules/term/termwindow.cpp new file mode 100644 index 00000000..39b6cc1a --- /dev/null +++ b/src/modules/term/termwindow.cpp @@ -0,0 +1,84 @@ +// +// File : termwindow.cpp +// Creation date : Thu Aug 31 2000 15:02:22 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) +// +// 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 opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +#include "termwindow.h" +#include "termwidget.h" + +#ifdef COMPILE_KDE_SUPPORT + + +#include "kvi_iconmanager.h" +#include "kvi_options.h" +#include "kvi_locale.h" +#include "kvi_module.h" + +extern KviModule * g_pTermModule; +extern KviPointerList<KviTermWindow> * g_pTermWindowList; +extern KviPointerList<KviTermWidget> * g_pTermWidgetList; + +KviTermWindow::KviTermWindow(KviFrame * lpFrm,const char * name) +: KviWindow(KVI_WINDOW_TYPE_TERM,lpFrm,name) +{ + g_pTermWindowList->append(this); + m_pTermWidget = 0; + m_pTermWidget = new KviTermWidget(this,lpFrm); + // Ensure proper focusing +// setFocusHandler(m_pTermWidget->konsoleWidget(),this); +} + +KviTermWindow::~KviTermWindow() +{ + g_pTermWindowList->removeRef(this); + if(g_pTermWindowList->isEmpty() && g_pTermWidgetList->isEmpty())g_pTermModule->unlock(); +} + +QPixmap * KviTermWindow::myIconPtr() +{ + return g_pIconManager->getSmallIcon(KVI_SMALLICON_RAW); +} + +void KviTermWindow::resizeEvent(QResizeEvent *e) +{ + if(m_pTermWidget)m_pTermWidget->setGeometry(0,0,width(),height()); +} + +QSize KviTermWindow::sizeHint() const +{ + return m_pTermWidget ? m_pTermWidget->sizeHint() : KviWindow::sizeHint(); +} + +void KviTermWindow::fillCaptionBuffers() +{ + m_szPlainTextCaption.sprintf(__tr("Terminal")); + + m_szHtmlActiveCaption.sprintf( + __tr("<nobr><font color=\"%s\"><b>Terminal</b></font></nobr>"), + KVI_OPTION_COLOR(KviOption_colorCaptionTextActive).name().ascii(), + KVI_OPTION_COLOR(KviOption_colorCaptionTextActive2).name().ascii()); + m_szHtmlInactiveCaption.sprintf( + __tr("<nobr><font color=\"%s\"><b>Terminal</b></font></nobr>"), + KVI_OPTION_COLOR(KviOption_colorCaptionTextInactive).name().ascii(), + KVI_OPTION_COLOR(KviOption_colorCaptionTextInactive2).name().ascii()); +} + +#include "termwindow.moc" + +#endif diff --git a/src/modules/term/termwindow.h b/src/modules/term/termwindow.h new file mode 100644 index 00000000..e3a9d556 --- /dev/null +++ b/src/modules/term/termwindow.h @@ -0,0 +1,54 @@ +#ifndef _TERMWINDOW_H_ +#define _TERMWINDOW_H_ +// +// File : termwindow.h +// Creation date : Thu Aug 31 2000 15:00:00 by Szymon Stefanek +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 1999-2000 Szymon Stefanek (pragma at kvirc dot net) +// +// 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 opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// + +#include "kvi_settings.h" + +#ifdef COMPILE_KDE_SUPPORT + + +#include "kvi_window.h" +#include "kvi_string.h" + +class KviTermWidget; + +class KviTermWindow : public KviWindow +{ + Q_OBJECT +public: + KviTermWindow(KviFrame * lpFrm,const char * name); + ~KviTermWindow(); +protected: + KviTermWidget * m_pTermWidget; +protected: + virtual QPixmap * myIconPtr(); + virtual void fillCaptionBuffers(); + virtual void resizeEvent(QResizeEvent *e); +public: + virtual QSize sizeHint() const; +}; + + +#endif + +#endif //_KVI_HELPWINDOW_H_ |