diff options
Diffstat (limited to 'xparts/src/tde')
-rw-r--r-- | xparts/src/tde/Makefile.am | 17 | ||||
-rw-r--r-- | xparts/src/tde/kbrowsersignals.cpp | 31 | ||||
-rw-r--r-- | xparts/src/tde/kbrowsersignals.h | 27 | ||||
-rw-r--r-- | xparts/src/tde/xparthost_kpart.cpp | 150 | ||||
-rw-r--r-- | xparts/src/tde/xparthost_kpart.h | 74 |
5 files changed, 299 insertions, 0 deletions
diff --git a/xparts/src/tde/Makefile.am b/xparts/src/tde/Makefile.am new file mode 100644 index 00000000..0a3d28ad --- /dev/null +++ b/xparts/src/tde/Makefile.am @@ -0,0 +1,17 @@ + +INCLUDES = -I$(srcdir)/../interfaces $(all_includes) + +lib_LTLIBRARIES = libtdexparts.la + +libtdexparts_la_SOURCES = xparthost_kpart.cpp xparthost.skel xpart.stub \ + kbrowsersignals.cpp xbrowsersignals.skel xbrowserextension.stub +libtdexparts_la_LIBADD = $(LIB_TDEPARTS) $(LIB_QT) $(LIB_TDECORE) $(LIB_TDEUI) -lDCOP +libtdexparts_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 1:0 + +xpart_DIR=$(srcdir)/../interfaces +xparthost_DIR=$(srcdir)/../interfaces +xbrowsersignals_DIR=$(srcdir)/../interfaces +xbrowserextension_DIR=$(srcdir)/../interfaces + +METASOURCES = AUTO + diff --git a/xparts/src/tde/kbrowsersignals.cpp b/xparts/src/tde/kbrowsersignals.cpp new file mode 100644 index 00000000..59a688e4 --- /dev/null +++ b/xparts/src/tde/kbrowsersignals.cpp @@ -0,0 +1,31 @@ +#include "kbrowsersignals.h" +#include "xparthost_kpart.h" +#include "xbrowserextension_stub.h" +#include <kurl.h> + +KBrowserSignals::KBrowserSignals( XPartHost_KPart *_part, DCOPRef extension ) + : KParts::BrowserExtension( _part ) +{ + tqDebug("KBrowserSignals constructor"); + part = _part; + ext = new XBrowserExtension_stub( extension.app(), extension.object() ); + ext->setBrowserSignals( DCOPRef( this ) ); +} + +KBrowserSignals::~KBrowserSignals() +{ + delete ext; +} + +void KBrowserSignals::openURLRequest( const TQCString &url) +{ + KURL u = TQString(url); + emit KParts::BrowserExtension::openURLRequest(u); +} + +void KBrowserSignals::createNewWindow( const TQCString &url ) +{ +} + +#include "kbrowsersignals.moc" + diff --git a/xparts/src/tde/kbrowsersignals.h b/xparts/src/tde/kbrowsersignals.h new file mode 100644 index 00000000..baee95aa --- /dev/null +++ b/xparts/src/tde/kbrowsersignals.h @@ -0,0 +1,27 @@ +#ifndef __kbrowsersignals_h__ +#define __kbrowsersignals_h__ + +#include <xbrowsersignals.h> +#include <tdeparts/browserextension.h> +#include <dcopref.h> + +class XBrowserExtension_stub; +class XPartHost_KPart; + +class KBrowserSignals : public KParts::BrowserExtension, virtual public XBrowserSignals +{ + Q_OBJECT +public: + KBrowserSignals( XPartHost_KPart *part, DCOPRef ref ); + virtual ~KBrowserSignals(); + + + virtual ASYNC openURLRequest( const TQCString &url); + virtual ASYNC createNewWindow( const TQCString &url ); + +protected: + XPartHost_KPart *part; + XBrowserExtension_stub *ext; +}; + +#endif diff --git a/xparts/src/tde/xparthost_kpart.cpp b/xparts/src/tde/xparthost_kpart.cpp new file mode 100644 index 00000000..54bcb804 --- /dev/null +++ b/xparts/src/tde/xparthost_kpart.cpp @@ -0,0 +1,150 @@ +#include "xparthost_kpart.h" +#include "kbrowsersignals.h" +#include "xpart_stub.h" + +#include <dcopclient.h> +#include <tdeapplication.h> + +#include <assert.h> + +#include <qxembed.h> + +#include <tqdom.h> +#include <tdeaction.h> + +#include <kdebug.h> + +XPartHost_KPart::XPartHost_KPart( TQWidget *parentWidget, const char *widgetName, + TQObject *parent, const char *name ) + : KParts::ReadOnlyPart( parent, name ), + XPartHost("parthost") +{ + m_stub = 0; + be = 0; + embed = new QXEmbed(parentWidget, widgetName); + setWidget(embed); +} + +XPartHost_KPart::~XPartHost_KPart() +{ + delete m_stub; +} + +DCOPRef XPartHost_KPart::part() +{ + return m_part; +} + +DCOPRef XPartHost_KPart::registerXPart( const DCOPRef &part ) +{ + m_part = part; + + assert( m_stub == 0 ); + + m_stub = new XPart_stub( part.app(), part.object() ); + m_stub->show(); + + kdDebug() << "embedding window " << m_stub->windowId() << endl; + embed->embed( static_cast<WId>( m_stub->windowId() ) ); + + embed->show(); + DCOPRef ref = m_stub->queryExtension("browserextension"); + if( !ref.isNull() ) { + tqDebug(" found browser extension "); + be = new KBrowserSignals( this, ref ); + } + return DCOPRef( kapp->dcopClient()->appId(), objId() ); +} + + +void XPartHost_KPart::createActions( const TQCString &xmlActions ) +{ + tqDebug("--> createActions"); + // creates a set of actions and adds them to the actionCollection + TQDomDocument d; + d.setContent( xmlActions ); + + TQDomElement docElem = d.documentElement(); + + kdDebug() << "docElement is " << docElem.tagName() << endl; + + TQDomNode n = docElem.firstChild(); + while( !n.isNull() ) { + TQDomElement e = n.toElement(); + if( !e.isNull() ) { + if ( e.tagName() == "Action") { + TQString name = e.attribute("name"); + TQString type = e.attribute("type"); + + if(type.isEmpty()) + new TDEAction( name, 0, this, TQT_SLOT( actionActivated() ), actionCollection(), name.latin1() ); + else if( type == "toggle" ) + new TDEToggleAction( name, 0, this, TQT_SLOT( actionActivated() ), actionCollection(), name.latin1() ); + kdDebug() << "action=" << name << " type=" << type << endl; + } else if ( e.tagName() == "XMLFile" ) { + TQString location = e.attribute("location"); + setXMLFile(location); + } + } + n = n.nextSibling(); + } + emit actionsInitialized(); +} + + +void XPartHost_KPart::setWindowCaption( const TQString &caption ) +{ + emit KParts::ReadOnlyPart::setWindowCaption( caption ); +} + +void XPartHost_KPart::setStatusBarText( const TQString &text ) +{ + emit KParts::ReadOnlyPart::setStatusBarText( text ); +} + +void XPartHost_KPart::started() +{ + emit KParts::ReadOnlyPart::started( 0 ); +} + +void XPartHost_KPart::completed() +{ + emit KParts::ReadOnlyPart::completed(); +} + +void XPartHost_KPart::canceled( const TQString &errMsg ) +{ + emit KParts::ReadOnlyPart::canceled( errMsg ); +} + +bool XPartHost_KPart::openURL( const KURL &url ) +{ + tqDebug("XPartHost_KPart::openUrl()"); + return m_stub->openURL( url.url().latin1() ); +} + +bool XPartHost_KPart::closeURL() +{ + return m_stub->closeURL(); +} + + +void XPartHost_KPart::actionActivated() +{ + const TQObject *o = sender(); + + if( !o->inherits("TDEAction") ) return; + + const TDEAction *action = static_cast<const TDEAction *>(o); + TQString name = action->text(); + int state = 0; + + if(action->inherits("TDEToggleAction")) { + const TDEToggleAction *t = static_cast<const TDEToggleAction *>(action); + state = t->isChecked(); + } + + m_stub->activateAction(name, state); +} + +#include "xparthost_kpart.moc" diff --git a/xparts/src/tde/xparthost_kpart.h b/xparts/src/tde/xparthost_kpart.h new file mode 100644 index 00000000..8cc54699 --- /dev/null +++ b/xparts/src/tde/xparthost_kpart.h @@ -0,0 +1,74 @@ +#ifndef __xparthost_kpart_h__ +#define __xparthost_kpart_h__ + +#include <xparthost.h> + +#include <tdeparts/part.h> + +class XPart_stub; +class KBrowserSignals; +class QXEmbed; + + +/** + * This class is the middle class between the host of the KPart (usually a + * KParts::MainWindow) and the XPart. It transfer calls from the XPart to the + * KPartHost host and from the KPartHost to the XPart. + * + * Note : In the XPart white paper, this class is named KXPartHost + */ +class XPartHost_KPart : public KParts::ReadOnlyPart, public XPartHost +{ + Q_OBJECT +public: + XPartHost_KPart( TQWidget *parentWidget, const char *widgetName, + TQObject *parent, const char *name ); + virtual ~XPartHost_KPart(); + + // DCOP stuff + + /** The XPart uses this function to register itself */ + virtual DCOPRef registerXPart( const DCOPRef &part ); + + /** Return the XPart DCOPRef to someone willing to communicate with it */ + virtual DCOPRef part(); + + // KPart signals + + /** Emitted by the XPart, to be transfered to the KPart host */ + virtual ASYNC createActions( const TQCString &xmlActions ); + /** Emitted by the XPart, to be transfered to the KPart host */ + virtual ASYNC setWindowCaption( const TQString &caption ); + /** Emitted by the XPart, to be transfered to the KPart host */ + virtual ASYNC setStatusBarText( const TQString &text ); + + /** Emitted by the XPart, to be transfered to the KPart host */ + virtual ASYNC started(); + /** Emitted by the XPart, to be transfered to the KPart host */ + virtual ASYNC completed(); + /** Emitted by the XPart, to be transfered to the KPart host */ + virtual ASYNC canceled( const TQString &errMsg ); + + // reimplemented from KReadOnlyPart + /** function called by the KPart host to be forwarded to the XPart */ + virtual bool openURL( const KURL &url ); + /** function called by the KPart host to be forwarded to the XPart */ + virtual bool closeURL(); + +protected: + virtual bool openFile() { return false; } + +private slots: + void actionActivated(); + +signals: + void actionsInitialized(); + +private: + DCOPRef m_part; + XPart_stub *m_stub; + KBrowserSignals *be; + QXEmbed *embed; +}; + +#endif |