summaryrefslogtreecommitdiffstats
path: root/xparts/src
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /xparts/src
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'xparts/src')
-rw-r--r--xparts/src/Makefile.am7
-rw-r--r--xparts/src/gtk/Makefile.am13
-rw-r--r--xparts/src/gtk/configure.in.in1
-rw-r--r--xparts/src/gtk/gtkbrowserextension.c244
-rw-r--r--xparts/src/gtk/gtkbrowserextension.h54
-rw-r--r--xparts/src/gtk/gtkpart.c299
-rw-r--r--xparts/src/gtk/gtkpart.h61
-rw-r--r--xparts/src/interfaces/Makefile.am3
-rw-r--r--xparts/src/interfaces/xbrowserextension.h17
-rw-r--r--xparts/src/interfaces/xbrowsersignals.h15
-rw-r--r--xparts/src/interfaces/xpart.h36
-rw-r--r--xparts/src/interfaces/xparthost.h53
-rw-r--r--xparts/src/interfaces/xpartmanager.h20
-rw-r--r--xparts/src/kde/Makefile.am17
-rw-r--r--xparts/src/kde/kbrowsersignals.cpp31
-rw-r--r--xparts/src/kde/kbrowsersignals.h27
-rw-r--r--xparts/src/kde/xparthost_kpart.cpp150
-rw-r--r--xparts/src/kde/xparthost_kpart.h74
18 files changed, 1122 insertions, 0 deletions
diff --git a/xparts/src/Makefile.am b/xparts/src/Makefile.am
new file mode 100644
index 00000000..243ba3b3
--- /dev/null
+++ b/xparts/src/Makefile.am
@@ -0,0 +1,7 @@
+
+if include_GTK_support
+SUPPORTGTKDIR=gtk
+endif
+
+SUBDIRS = interfaces kde $(SUPPORTGTKDIR)
+
diff --git a/xparts/src/gtk/Makefile.am b/xparts/src/gtk/Makefile.am
new file mode 100644
index 00000000..2e83df3b
--- /dev/null
+++ b/xparts/src/gtk/Makefile.am
@@ -0,0 +1,13 @@
+INCLUDES = $(GLIB_INCLUDES) -I$(prefix)/include -I$(top_srcdir) $(all_includes)
+
+AM_CFLAGS = $(GLIB_CFLAGS) $(GTK_CFLAGS)
+AM_CXXFLAGS = $(GLIB_CFLAGS) $(GTK_CFLAGS)
+
+lib_LTLIBRARIES = libgtkxparts.la
+
+libgtkxparts_la_SOURCES = gtkpart.c gtkbrowserextension.c
+libgtkxparts_la_LIBADD = $(GTK_LIBS) $(GLIB_LIBS) $(top_builddir)/dcopc/libdcopc.la
+libgtkxparts_la_LDFLAGS = -L$(prefix)/lib $(all_libraries) -no-undefined
+
+gtkxpartsinclude_HEADERS = gtkpart.h gtkbrowserextension.h
+gtkxpartsincludedir = $(includedir)/xkparts
diff --git a/xparts/src/gtk/configure.in.in b/xparts/src/gtk/configure.in.in
new file mode 100644
index 00000000..32dfac1e
--- /dev/null
+++ b/xparts/src/gtk/configure.in.in
@@ -0,0 +1 @@
+AM_CONDITIONAL(include_GTK_support, [ test "$GTK_CONFIG" != "no" ])
diff --git a/xparts/src/gtk/gtkbrowserextension.c b/xparts/src/gtk/gtkbrowserextension.c
new file mode 100644
index 00000000..165320a8
--- /dev/null
+++ b/xparts/src/gtk/gtkbrowserextension.c
@@ -0,0 +1,244 @@
+
+#include "gtkbrowserextension.h"
+
+#include <gdk/gdkx.h>
+
+#include <dcopc/util.h>
+#include <dcopc/marshal.h>
+#include <dcopc/dcopc.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+
+typedef struct _GtkXBrowserExtensionPrivate GtkXBrowserExtensionPrivate;
+
+struct _GtkXBrowserExtensionPrivate {
+ gchar *host_app_id;
+ gchar *host_obj_id;
+ DcopClient *client;
+};
+
+#define P ((GtkXBrowserExtensionPrivate *)(part->data))
+#define CLASS(obj) GTK_XBROWSEREXTENSION_CLASS(GTK_OBJECT(obj)->klass)
+
+
+/* class and instance initialization */
+
+static void
+gtk_xbrowserextension_class_init(GtkXBrowserExtensionClass *klass);
+
+static void
+gtk_xbrowserextension_init(GtkXBrowserExtension *part);
+
+static void
+gtk_xbrowserextension_destroy( GtkObject *obj );
+
+
+/* dcop handlers */
+
+gboolean gtk_xbrowserextension_dcop_process( DcopObject *obj, const char *fun, dcop_data *data,
+ char **reply_type, dcop_data **reply_data );
+
+GList *gtk_xbrowserextension_dcop_functions( DcopObject *obj );
+
+GList *gtk_xbrowserextension_dcop_interfaces( DcopObject *obj );
+
+static DcopObjectClass *parent_class = 0;
+
+/* --------------------------- implementations --------------------------------------- */
+
+/* type information */
+GtkType
+gtk_xbrowserextension_get_type(void)
+{
+ static GtkType part_type = 0;
+ if (!part_type)
+ {
+ static const GtkTypeInfo part_info =
+ {
+ "GtkXBrowserExtension",
+ sizeof(GtkXBrowserExtension),
+ sizeof(GtkXBrowserExtensionClass),
+ (GtkClassInitFunc)gtk_xbrowserextension_class_init,
+ (GtkObjectInitFunc)gtk_xbrowserextension_init,
+ 0,
+ 0,
+ 0
+ };
+ part_type = gtk_type_unique(DCOP_TYPE_OBJECT, &part_info);
+ }
+ return part_type;
+}
+
+/* class and instance initialization */
+static void
+gtk_xbrowserextension_class_init(GtkXBrowserExtensionClass *klass)
+{
+ GtkObjectClass *object_class = (GtkObjectClass *)klass;
+ DcopObjectClass *dcop_class = DCOP_OBJECT_CLASS(klass);
+ g_message( "gtk_xbrowserextension_class_init\n" );
+
+ parent_class = (DcopObjectClass *)gtk_type_class(dcop_object_get_type());
+
+ object_class->destroy = gtk_xbrowserextension_destroy;
+
+ dcop_class->process = gtk_xbrowserextension_dcop_process;
+ dcop_class->functions = gtk_xbrowserextension_dcop_functions;
+ dcop_class->interfaces = gtk_xbrowserextension_dcop_interfaces;
+
+ klass->save_state = 0;
+ klass->restore_state = 0;
+
+ g_message( "gtk_xbrowserextension_class_init\n" );
+}
+
+static void
+gtk_xbrowserextension_init(GtkXBrowserExtension *part)
+{
+ GtkXBrowserExtensionPrivate *d;
+ d = g_new( GtkXBrowserExtensionPrivate, 1 );
+ part->data = d;
+
+ dcop_object_set_id( DCOP_OBJECT(part), "XBrowserExtensionClient" );
+
+ d->client = 0;
+ d->host_app_id = 0;
+ d->host_obj_id = 0;
+
+ g_message( "gtk_xbrowserextension_init\n" );
+}
+
+GtkXBrowserExtension *gtk_xbrowserextension_new (void)
+{
+ return (GtkXBrowserExtension *) gtk_type_new(gtk_xbrowserextension_get_type());
+}
+
+
+gboolean gtk_xbrowserextension_dcop_process( DcopObject *obj, const char *fun, dcop_data *data,
+ char **reply_type, dcop_data **reply_data )
+{
+ GtkXBrowserExtension *part = GTK_XBROWSEREXTENSION(obj);
+ GtkXBrowserExtensionPrivate *d = (GtkXBrowserExtensionPrivate *)part->data;
+ GtkXBrowserExtensionClass *klass = GTK_XBROWSEREXTENSION_CLASS(GTK_OBJECT(part)->klass);
+
+ if ( strcmp( fun, "saveState()" ) == 0 )
+ {
+ const char *state = 0;
+ if( klass->save_state) {
+ state = klass->save_state( part );
+
+ dcop_marshal_bytearray( *reply_data, state, strlen( state ) );
+ }
+ return True;
+ }
+ else if ( strcmp( fun, "restoreState(QByteArray)" ) == 0 )
+ {
+ if( klass->restore_state ) {
+ size_t len;
+ char *state;
+ dcop_demarshal_bytearray( data, &state, &len );
+ klass->restore_state( part, state, len );
+ }
+ return True;
+ }
+ else if ( strcmp( fun, "setBrowserSignals(DCOPRef)" ) == 0 )
+ {
+ dcop_demarshal_string( data, &d->host_app_id );
+ dcop_demarshal_string( data, &d->host_obj_id );
+ return True;
+ }
+
+ return parent_class->process( obj, fun, data, reply_type, reply_data );
+}
+
+GList *gtk_xbrowserextension_dcop_functions( DcopObject *obj )
+{
+ GList *res = parent_class->functions( obj );
+ res = g_list_append( res, g_strdup( "saveState()" ) );
+ res = g_list_append( res, g_strdup( "restoreState(QByteArray)" ) );
+ return res;
+}
+
+GList *gtk_xbrowserextension_dcop_interfaces( DcopObject *obj )
+{
+ GList *res = parent_class->interfaces( obj );
+ res = g_list_append( res, g_strdup( "XBrowserExtension" ) );
+ return res;
+}
+
+void gtk_xbrowserextension_destroy( GtkObject *obj )
+{
+ GtkXBrowserExtension *part = GTK_XBROWSEREXTENSION(obj);
+ GtkXBrowserExtensionPrivate *d = (GtkXBrowserExtensionPrivate *) part->data;
+ g_free( d->host_app_id );
+ g_free( d->host_obj_id );
+ g_free( d );
+
+ GTK_OBJECT_CLASS(parent_class)->destroy(obj);
+}
+
+void gtk_xbrowserextension_set_dcop_client( GtkXBrowserExtension *part, DcopClient *client )
+{
+ P->client = client;
+}
+
+
+gboolean gtk_xbrowserextension_register( GtkXBrowserExtension *part, const gchar *host_app_id, const gchar *host_obj_id)
+{
+ dcop_data *reply_data;
+ char *reply_type;
+ dcop_data *data = dcop_data_ref( dcop_data_new() );
+ GtkXBrowserExtensionPrivate *d = (GtkXBrowserExtensionPrivate *)part->data;
+
+ if(!P->client)
+ fprintf(stderr, "register a dcop client first!\n");
+
+ dcop_marshal_string( data, dcop_client_app_id( P->client ) );
+ dcop_marshal_string( data, DCOP_ID(DCOP_OBJECT(part)) );
+
+ if ( !dcop_client_call( P->client, host_app_id, host_obj_id, "registerXBrowserExtension(DCOPRef)", data,
+ &reply_type, &reply_data ) ) {
+ fprintf( stderr, "cannot register with shell %s / %s\n", host_app_id, host_obj_id );
+ gtk_exit( 1 );
+ }
+ g_message( "back from registration call!" );
+
+ /*assert( strcmp( reply_type, "DCOPRef" ) == 0 );*/
+
+#if 0
+ /* this is wrong. but as we have the ref anyway, let's ignore the return value*/
+ dcop_demarshal_string( data, &d->host_app_id );
+ dcop_demarshal_string( data, &d->host_obj_id );
+
+ printf("appid=%s, objid=%s\n", d->host_app_id, d->host_obj_id);
+#endif
+ d->host_obj_id = g_strdup( host_obj_id );
+ d->host_app_id = g_strdup( host_app_id );
+
+ dcop_data_reset( reply_data );
+
+ dcop_data_deref( data );
+ g_message( "returning from gtk_xbrowserextension_register" );
+ return TRUE;
+}
+
+gboolean gtk_browserextension_open_url_request( GtkXBrowserExtension *part, const char *url )
+{
+ dcop_data *reply_data;
+ char *reply_type;
+ dcop_data *data = dcop_data_ref( dcop_data_new() );
+
+ if(!P->client)
+ fprintf(stderr, "register a dcop client first!\n");
+
+ dcop_marshal_string( data, url );
+
+ if ( !dcop_client_call( P->client, P->host_app_id, P->host_obj_id, "openURLRequest(QCString)", data,
+ &reply_type, &reply_data ) ) {
+ g_warning(" openURLRequest failed");
+ return FALSE;
+ }
+ return TRUE;
+}
diff --git a/xparts/src/gtk/gtkbrowserextension.h b/xparts/src/gtk/gtkbrowserextension.h
new file mode 100644
index 00000000..7efbd938
--- /dev/null
+++ b/xparts/src/gtk/gtkbrowserextension.h
@@ -0,0 +1,54 @@
+#ifndef _gtkxbrowserextension_h__
+#define _gtkxbrowserextension_h__
+
+#include <dcopc/dcopobject.h>
+#include <dcopc/dcopc.h>
+#include <dcopc/marshal.h>
+#include <dcopc/util.h>
+
+#include <gtk/gtk.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define GTK_TYPE_XBROWSEREXTENSION (gtk_xbrowserextension_get_type())
+#define GTK_XBROWSEREXTENSION(obj) GTK_CHECK_CAST((obj), GTK_TYPE_XBROWSEREXTENSION, GtkXBrowserExtension)
+#define GTK_XBROWSEREXTENSION_CLASS(klass) GTK_CHECK_CLASS_CAST((klass), GTK_TYPE_XBROWSEREXTENSION, GtkXBrowserExtensionClass)
+#define GTK_IS_XBROWSEREXTENSION(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_XBROWSEREXTENSION)
+#define GTK_IS_XBROWSEREXTENSION_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_XBROWSEREXTENSION)
+
+#define GTK_XBROWSEREXTENSION_WIDGET(part) (gtk_xbrowserextension_get_widget(part))
+#define GTK_XBROWSEREXTENSION_DCOP(part) (gtk_xbrowserextension_get_dcop(part))
+
+typedef struct _GtkXBrowserExtension GtkXBrowserExtension;
+typedef struct _GtkXBrowserExtensionClass GtkXBrowserExtensionClass;
+
+struct _GtkXBrowserExtension
+{
+ DcopObject obj;
+ void *data;
+};
+
+struct _GtkXBrowserExtensionClass
+{
+ DcopObjectClass parent_class;
+
+ const char * ( *save_state)( GtkXBrowserExtension *ext );
+ void (* restore_state) ( GtkXBrowserExtension *ext, const char *state, unsigned int size );
+};
+
+extern GtkType gtk_xbrowserextension_get_type (void);
+extern GtkXBrowserExtension *gtk_xbrowserextension_new (void);
+
+gboolean gtk_browserextension_open_url_request( GtkXBrowserExtension *ext, const char *url );
+
+/* "virtual" functions from DcopObject */
+void gtk_xbrowserextension_set_dcop_client( GtkXBrowserExtension *part, DcopClient *client );
+gboolean gtk_xbrowserextension_register( GtkXBrowserExtension *part, const gchar *host_app_id, const gchar *host_obj_id);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/xparts/src/gtk/gtkpart.c b/xparts/src/gtk/gtkpart.c
new file mode 100644
index 00000000..740910fb
--- /dev/null
+++ b/xparts/src/gtk/gtkpart.c
@@ -0,0 +1,299 @@
+
+#include "gtkpart.h"
+
+#include <gdk/gdkx.h>
+
+#include <dcopc/util.h>
+#include <dcopc/marshal.h>
+#include <dcopc/dcopc.h>
+
+#include <string.h>
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+
+typedef struct _GtkXPartPrivate GtkXPartPrivate;
+
+struct _GtkXPartPrivate {
+ GtkWidget *widget;
+ gchar *host_app_id;
+ gchar *host_obj_id;
+ DcopClient *client;
+};
+
+#define P ((GtkXPartPrivate *)(part->data))
+#define CLASS(obj) GTK_XPART_CLASS(GTK_OBJECT(obj)->klass)
+
+
+/* class and instance initialization */
+
+static void
+gtk_xpart_class_init(GtkXPartClass *klass);
+
+static void
+gtk_xpart_init(GtkXPart *part);
+
+static void
+gtk_xpart_destroy( GtkObject *obj );
+
+/* dcop handlers */
+
+gboolean gtk_xpart_dcop_process( DcopObject *obj, const char *fun, dcop_data *data,
+ char **reply_type, dcop_data **reply_data );
+
+GList *gtk_xpart_dcop_functions( DcopObject *obj );
+
+GList *gtk_xpart_dcop_interfaces( DcopObject *obj );
+
+static DcopObjectClass *parent_class = 0;
+
+/* --------------------------- implementations --------------------------------------- */
+
+/* type information */
+GtkType
+gtk_xpart_get_type(void)
+{
+ static GtkType part_type = 0;
+ if (!part_type)
+ {
+ static const GtkTypeInfo part_info =
+ {
+ "GtkXPart",
+ sizeof(GtkXPart),
+ sizeof(GtkXPartClass),
+ (GtkClassInitFunc)gtk_xpart_class_init,
+ (GtkObjectInitFunc)gtk_xpart_init,
+ 0,
+ 0,
+ 0
+ };
+ part_type = gtk_type_unique(DCOP_TYPE_OBJECT, &part_info);
+ }
+ return part_type;
+}
+
+/* class and instance initialization */
+static void
+gtk_xpart_class_init(GtkXPartClass *klass)
+{
+ GtkObjectClass *object_class = (GtkObjectClass *)klass;
+ DcopObjectClass *dcop_class = DCOP_OBJECT_CLASS(klass);
+
+ parent_class = (DcopObjectClass *)gtk_type_class(dcop_object_get_type());
+
+ object_class->destroy = gtk_xpart_destroy;
+
+ dcop_class->process = gtk_xpart_dcop_process;
+ dcop_class->functions = gtk_xpart_dcop_functions;
+ dcop_class->interfaces = gtk_xpart_dcop_interfaces;
+
+ klass->open_url = 0;
+ klass->close_url = 0;
+ klass->query_extension = 0;
+
+ g_message( "gtk_xpart_class_init\n" );
+}
+
+static void
+gtk_xpart_init(GtkXPart *part)
+{
+ GtkXPartPrivate *d;
+ d = g_new( GtkXPartPrivate, 1 );
+ part->data = d;
+
+ dcop_object_set_id( DCOP_OBJECT(part), "XPartClient" );
+
+ d->widget = 0;
+ d->client = 0;
+ d->host_app_id = 0;
+ d->host_obj_id = 0;
+
+ g_message( "gtk_xpart_init\n" );
+}
+
+GtkXPart *gtk_xpart_new (void)
+{
+ return (GtkXPart *) gtk_type_new(gtk_xpart_get_type());
+}
+
+
+void gtk_xpart_set_widget( GtkXPart *part, GtkWidget *widget )
+{
+ GtkXPartPrivate *d = (GtkXPartPrivate *)part->data;
+ d->widget = widget;
+ gtk_object_ref( GTK_OBJECT( widget ) );
+}
+
+
+
+gboolean gtk_xpart_dcop_process( DcopObject *obj, const char *fun, dcop_data *data,
+ char **reply_type, dcop_data **reply_data )
+{
+ GtkXPart *part = GTK_XPART(obj);
+ GtkXPartPrivate *d = (GtkXPartPrivate *)part->data;
+ GtkXPartClass *klass = GTK_XPART_CLASS(GTK_OBJECT(part)->klass);
+ gboolean b;
+
+ if ( strcmp( fun, "windowId()" ) == 0 )
+ {
+ *reply_type = strdup( "Q_UINT32" );
+ *reply_data = dcop_data_ref( dcop_data_new() );
+
+ fprintf( stderr, "returning window id %ld\n", GDK_WINDOW_XWINDOW( d->widget->window ) );
+ dcop_marshal_uint32( *reply_data, GDK_WINDOW_XWINDOW( d->widget->window ) );
+
+ return True;
+ }
+ else if ( strcmp( fun, "show()" ) == 0 )
+ {
+ fprintf( stderr, "show %p!\n", d->widget );
+ gtk_widget_show_all( d->widget );
+ return True;
+ }
+ else if ( strcmp( fun, "openURL(QCString)" ) == 0 )
+ {
+ char *url;
+ fprintf( stderr, "openURL!\n" );
+ dcop_demarshal_string( data, &url );
+ b = FALSE;
+ if ( klass->open_url )
+ b = klass->open_url( part, url );
+ *reply_type = strdup( "bool" );
+ *reply_data = dcop_data_ref( dcop_data_new() );
+ dcop_marshal_boolean( *reply_data, b );
+ return True;
+ }
+ else if ( strcmp( fun, "closeURL()" ) == 0 )
+ {
+ fprintf( stderr, "closeURL!\n" );
+ b = FALSE;
+ if ( klass->close_url )
+ b = klass->close_url( part );
+ *reply_type = strdup( "bool" );
+ *reply_data = dcop_data_ref( dcop_data_new() );
+ dcop_marshal_boolean( *reply_data, b );
+ return True;
+ }
+ else if ( strcmp( fun, "activateAction(QCString,int)" ) == 0 )
+ {
+ char *name;
+ uint state;
+ dcop_demarshal_string( data, &name );
+ dcop_demarshal_uint32( data, &state );
+ fprintf( stderr, "activateAction %s state=%d\n", name, state );
+ gtk_signal_emit_by_name( GTK_OBJECT(part), name, state);
+ return True;
+ }
+ else if ( strcmp( fun, "queryExtension(QCString)" ) == 0 ) {
+ char *name;
+ char *extension = NULL;
+ dcop_demarshal_string( data, &name );
+ if ( klass->query_extension )
+ extension = klass->query_extension( part, name );
+ *reply_type = strdup( "DCOPRef" );
+ *reply_data = dcop_data_ref( dcop_data_new() );
+ dcop_marshal_string( *reply_data, dcop_client_app_id( P->client ) );
+ dcop_marshal_string( *reply_data, extension );
+ return True;
+ }
+
+ return parent_class->process( obj, fun, data, reply_type, reply_data );
+}
+
+GList *gtk_xpart_dcop_functions( DcopObject *obj )
+{
+ GList *res = parent_class->functions( obj );
+ res = g_list_append( res, g_strdup( "windowId()" ) );
+ res = g_list_append( res, g_strdup( "show()" ) );
+ res = g_list_append( res, g_strdup( "bool openURL(QString url)" ) );
+ res = g_list_append( res, g_strdup( "bool closeURL()" ) );
+ res = g_list_append( res, g_strdup( "queryExtension(QCString)" ) );
+ return res;
+}
+
+GList *gtk_xpart_dcop_interfaces( DcopObject *obj )
+{
+ GList *res = parent_class->interfaces( obj );
+ res = g_list_append( res, g_strdup( "XPart" ) );
+ return res;
+}
+
+void gtk_xpart_destroy( GtkObject *obj )
+{
+ GtkXPart *part = GTK_XPART(obj);
+ GtkXPartPrivate *d = (GtkXPartPrivate *) part->data;
+ g_free( d->host_app_id );
+ g_free( d->host_obj_id );
+
+ gtk_object_destroy( GTK_OBJECT( d->widget ) );
+
+ GTK_OBJECT_CLASS(parent_class)->destroy(obj);
+}
+
+void gtk_xpart_set_dcop_client( GtkXPart *part, DcopClient *client )
+{
+ P->client = client;
+}
+
+
+gboolean gtk_xpart_register( GtkXPart *part, const gchar *host_app_id, const gchar *host_obj_id)
+{
+ dcop_data *reply_data;
+ char *reply_type;
+ dcop_data *data = dcop_data_ref( dcop_data_new() );
+ GtkXPartPrivate *d = (GtkXPartPrivate *)part->data;
+
+ if(!P->client)
+ fprintf(stderr, "register a dcop client first!\n");
+
+ dcop_marshal_string( data, dcop_client_app_id( P->client ) );
+ dcop_marshal_string( data, DCOP_ID(DCOP_OBJECT(part)) );
+
+ if ( !dcop_client_call( P->client, host_app_id, host_obj_id, "registerXPart(DCOPRef)", data,
+ &reply_type, &reply_data ) ) {
+ fprintf( stderr, "cannot register with shell %s / %s\n", host_app_id, host_obj_id );
+ gtk_exit( 1 );
+ }
+ g_message( "back from registration call!" );
+
+ /*assert( strcmp( reply_type, "DCOPRef" ) == 0 );*/
+
+#if 0
+ /* this is wrong. but as we have the ref anyway, let's ignore the return value*/
+ dcop_demarshal_string( data, &d->host_app_id );
+ dcop_demarshal_string( data, &d->host_obj_id );
+
+ printf("appid=%s, objid=%s\n", d->host_app_id, d->host_obj_id);
+#endif
+ d->host_obj_id = g_strdup( host_obj_id );
+ d->host_app_id = g_strdup( host_app_id );
+
+ dcop_data_reset( reply_data );
+
+ dcop_data_deref( data );
+ g_message( "returning from gtk_xpart_register" );
+ return TRUE;
+}
+
+
+gboolean gtk_xpart_initialize_actions( GtkXPart *part, const char * actions )
+{
+ GtkXPartPrivate *d = (GtkXPartPrivate *) part->data;
+ dcop_data *data = 0;
+
+ g_message( "gtk_xpart_initialize_actions\n" );
+
+ if(!P->client)
+ g_message( "register a dcop client first!\n" );
+
+ data = dcop_data_ref( dcop_data_new() );
+ dcop_marshal_string( data, actions );
+
+ if( !dcop_client_send( d->client, d->host_app_id, d->host_obj_id, "createActions(QCString)", data ) ) {
+ fprintf( stderr, "could not create actions\n" );
+ dcop_data_deref( data );
+ return FALSE;
+ }
+ dcop_data_deref( data );
+ return TRUE;
+}
diff --git a/xparts/src/gtk/gtkpart.h b/xparts/src/gtk/gtkpart.h
new file mode 100644
index 00000000..e803f03e
--- /dev/null
+++ b/xparts/src/gtk/gtkpart.h
@@ -0,0 +1,61 @@
+#ifndef _gtkxpart_h__
+#define _gtkxpart_h__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <dcopc/dcopobject.h>
+#include <dcopc/dcopc.h>
+#include <dcopc/marshal.h>
+#include <dcopc/util.h>
+
+#include <gtk/gtk.h>
+
+#include "gtkbrowserextension.h"
+
+#define GTK_TYPE_XPART (gtk_xpart_get_type())
+#define GTK_XPART(obj) GTK_CHECK_CAST((obj), GTK_TYPE_XPART, GtkXPart)
+#define GTK_XPART_CLASS(klass) GTK_CHECK_CLASS_CAST((klass), GTK_TYPE_XPART, GtkXPartClass)
+#define GTK_IS_XPART(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_XPART)
+#define GTK_IS_XPART_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_XPART)
+
+#define GTK_XPART_WIDGET(part) (gtk_xpart_get_widget(part))
+#define GTK_XPART_DCOP(part) (gtk_xpart_get_dcop(part))
+
+typedef struct _GtkXPart GtkXPart;
+typedef struct _GtkXPartClass GtkXPartClass;
+
+struct _GtkXPart
+{
+ DcopObject obj;
+ void *data;
+};
+
+struct _GtkXPartClass
+{
+ DcopObjectClass parent_class;
+
+ gboolean (* open_url) ( GtkXPart *part, const char * url );
+ gboolean (* close_url) ( GtkXPart *part );
+
+ /* virtual function, returns the dcop object id of the extension, or NULL if it
+ doesn't exist */
+ char * (*query_extension) ( GtkXPart *part, const char *name );
+};
+
+extern GtkType gtk_xpart_get_type (void);
+extern GtkXPart *gtk_xpart_new (void);
+
+/* "virtual" functions from DcopObject */
+void gtk_xpart_set_dcop_client( GtkXPart *part, DcopClient *client );
+gboolean gtk_xpart_register( GtkXPart *part, const gchar *host_app_id, const gchar *host_obj_id);
+gboolean gtk_xpart_initialize_actions( GtkXPart *part, const char * actions );
+
+void gtk_xpart_set_widget( GtkXPart *part, GtkWidget *widget );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/xparts/src/interfaces/Makefile.am b/xparts/src/interfaces/Makefile.am
new file mode 100644
index 00000000..0d4b7f97
--- /dev/null
+++ b/xparts/src/interfaces/Makefile.am
@@ -0,0 +1,3 @@
+
+xkpartsinclude_HEADERS = xpart.h xparthost.h
+xkpartsincludedir = $(includedir)/xkparts
diff --git a/xparts/src/interfaces/xbrowserextension.h b/xparts/src/interfaces/xbrowserextension.h
new file mode 100644
index 00000000..57297441
--- /dev/null
+++ b/xparts/src/interfaces/xbrowserextension.h
@@ -0,0 +1,17 @@
+#ifndef __xpart_browser_h__
+#define __xpart_browser_h__
+
+#include <dcopref.h>
+
+class XBrowserExtension : public DCOPObject
+{
+ K_DCOP
+
+k_dcop:
+ virtual void setBrowserSignals( const DCOPRef &ref) = 0;
+
+ virtual QByteArray saveState() = 0;
+ virtual void restoreState( QByteArray state ) = 0;
+};
+
+#endif
diff --git a/xparts/src/interfaces/xbrowsersignals.h b/xparts/src/interfaces/xbrowsersignals.h
new file mode 100644
index 00000000..6d41d28b
--- /dev/null
+++ b/xparts/src/interfaces/xbrowsersignals.h
@@ -0,0 +1,15 @@
+#ifndef __xpart_browsersignals_h__
+#define __xpart_browsersignals_h__
+
+#include <dcopobject.h>
+
+class XBrowserSignals : public DCOPObject
+{
+ K_DCOP
+
+k_dcop:
+ virtual ASYNC openURLRequest( const QCString &url) = 0;
+ virtual ASYNC createNewWindow( const QCString &url ) = 0;
+};
+
+#endif
diff --git a/xparts/src/interfaces/xpart.h b/xparts/src/interfaces/xpart.h
new file mode 100644
index 00000000..7722f5fb
--- /dev/null
+++ b/xparts/src/interfaces/xpart.h
@@ -0,0 +1,36 @@
+#ifndef __xkparts_part_h__
+#define __xkparts_part_h__
+
+#include <dcopobject.h>
+#include <dcopref.h>
+#include <qglobal.h>
+
+class XPart : public DCOPObject
+{
+ K_DCOP
+k_dcop:
+
+ /** The XPartManager uses the windowId() to embed the part. */
+ virtual Q_UINT32 windowId() = 0;
+
+ /** Called when the part should display itself */
+ virtual void show() = 0;
+
+ /** sent by the XPartHost to request url opening */
+ virtual bool openURL( const QCString& url ) = 0;
+
+ /** sent by the XPartHost to close the url */
+ virtual bool closeURL() = 0;
+
+ /** Called when an action (previously registered with
+ * XPartHost::createActions()) has been activated. Name is the name of the
+ * action, state is used with Toggle actions to precise the current state.
+ */
+ virtual ASYNC activateAction( const QString &name, int state ) = 0;
+
+ /** Are extentions available -> browser extension / TextEditor ? */
+ virtual DCOPRef queryExtension( const QCString& extension ) = 0;
+
+};
+
+#endif
diff --git a/xparts/src/interfaces/xparthost.h b/xparts/src/interfaces/xparthost.h
new file mode 100644
index 00000000..3d1d95f4
--- /dev/null
+++ b/xparts/src/interfaces/xparthost.h
@@ -0,0 +1,53 @@
+#ifndef __xkparts_parthost_h__
+#define __xkparts_parthost_h__
+
+#include <dcopobject.h>
+#include <dcopref.h>
+
+class XPartHost : public DCOPObject
+{
+ K_DCOP
+public:
+ XPartHost(QCString name) : DCOPObject(name) {}
+
+k_dcop:
+
+ /** The XPart should register itself to its host when it is created */
+ virtual DCOPRef registerXPart( const DCOPRef &part ) = 0;
+
+ /** Returns the registered part */
+ virtual DCOPRef part() = 0;
+
+ /** The XPart informs its host about its available actions.
+ * the actions are sent to the XPart using XPart::activateAction */
+ virtual ASYNC createActions( const QCString &xmlActions ) = 0;
+
+ /** DCOP signal emitted by the XPart and received here, to be
+ * forwarded to the KPartHost. See KParts documentation for
+ * more details. */
+ virtual ASYNC setWindowCaption( const QString &caption ) = 0;
+
+ /** DCOP signal emitted by the XPart and received here, to be
+ * forwarded to the KPartHost. See KParts documentation for
+ * more details. */
+ virtual ASYNC setStatusBarText( const QString &text ) = 0;
+
+
+ /** DCOP signal emitted by the XPart and received here, to be
+ * forwarded to the KPartHost. See KParts documentation for
+ * more details. */
+ virtual ASYNC started() = 0;
+
+ /** DCOP signal emitted by the XPart and received here, to be
+ * forwarded to the KPartHost. See KParts documentation for
+ * more details. */
+ virtual ASYNC completed() = 0;
+
+ /** DCOP signal emitted by the XPart and received here, to be
+ * forwarded to the KPartHost. See KParts documentation for
+ * more details. */
+ virtual ASYNC canceled( const QString &errMsg ) = 0;
+
+};
+
+#endif
diff --git a/xparts/src/interfaces/xpartmanager.h b/xparts/src/interfaces/xpartmanager.h
new file mode 100644
index 00000000..a172ee3f
--- /dev/null
+++ b/xparts/src/interfaces/xpartmanager.h
@@ -0,0 +1,20 @@
+#ifndef __xkparts_partmanager_h__
+#define __xkparts_partmanager_h__
+
+#include <dcopobject.h>
+#include <qglobal.h>
+
+class XKPartManager : public DCOPObject
+{
+ K_DCOP
+
+k_dcop:
+ /** Query a XPart able to handle a given mimetype */
+ virtual DCOPRef createPart( QString servicetype ) = 0;
+
+ /** Delete a previously created XPart */
+ virtual void deletePart( DCOPRef ref ) = 0;
+};
+
+
+#endif
diff --git a/xparts/src/kde/Makefile.am b/xparts/src/kde/Makefile.am
new file mode 100644
index 00000000..acdfff7f
--- /dev/null
+++ b/xparts/src/kde/Makefile.am
@@ -0,0 +1,17 @@
+
+INCLUDES = -I$(srcdir)/../interfaces $(all_includes)
+
+lib_LTLIBRARIES = libkdexparts.la
+
+libkdexparts_la_SOURCES = xparthost_kpart.cpp xparthost.skel xpart.stub \
+ kbrowsersignals.cpp xbrowsersignals.skel xbrowserextension.stub
+libkdexparts_la_LIBADD = $(LIB_KPARTS)
+libkdexparts_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/kde/kbrowsersignals.cpp b/xparts/src/kde/kbrowsersignals.cpp
new file mode 100644
index 00000000..f96655f0
--- /dev/null
+++ b/xparts/src/kde/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 )
+{
+ qDebug("KBrowserSignals constructor");
+ part = _part;
+ ext = new XBrowserExtension_stub( extension.app(), extension.object() );
+ ext->setBrowserSignals( DCOPRef( this ) );
+}
+
+KBrowserSignals::~KBrowserSignals()
+{
+ delete ext;
+}
+
+void KBrowserSignals::openURLRequest( const QCString &url)
+{
+ KURL u = QString(url);
+ emit KParts::BrowserExtension::openURLRequest(u);
+}
+
+void KBrowserSignals::createNewWindow( const QCString &url )
+{
+}
+
+#include "kbrowsersignals.moc"
+
diff --git a/xparts/src/kde/kbrowsersignals.h b/xparts/src/kde/kbrowsersignals.h
new file mode 100644
index 00000000..dab8f208
--- /dev/null
+++ b/xparts/src/kde/kbrowsersignals.h
@@ -0,0 +1,27 @@
+#ifndef __kbrowsersignals_h__
+#define __kbrowsersignals_h__
+
+#include <xbrowsersignals.h>
+#include <kparts/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 QCString &url);
+ virtual ASYNC createNewWindow( const QCString &url );
+
+protected:
+ XPartHost_KPart *part;
+ XBrowserExtension_stub *ext;
+};
+
+#endif
diff --git a/xparts/src/kde/xparthost_kpart.cpp b/xparts/src/kde/xparthost_kpart.cpp
new file mode 100644
index 00000000..c88e0c99
--- /dev/null
+++ b/xparts/src/kde/xparthost_kpart.cpp
@@ -0,0 +1,150 @@
+#include "xparthost_kpart.h"
+#include "kbrowsersignals.h"
+#include "xpart_stub.h"
+
+#include <dcopclient.h>
+#include <kapplication.h>
+
+#include <assert.h>
+
+#include <qxembed.h>
+
+#include <qdom.h>
+#include <kaction.h>
+
+#include <kdebug.h>
+
+XPartHost_KPart::XPartHost_KPart( QWidget *parentWidget, const char *widgetName,
+ QObject *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() );
+
+ kdDebug() << "embedding window " << m_stub->windowId() << endl;
+ embed->embed( static_cast<WId>( m_stub->windowId() ) );
+
+ m_stub->show();
+ embed->show();
+ DCOPRef ref = m_stub->queryExtension("browserextension");
+ if( !ref.isNull() ) {
+ qDebug(" found browser extension ");
+ be = new KBrowserSignals( this, ref );
+ }
+ return DCOPRef( kapp->dcopClient()->appId(), objId() );
+}
+
+
+void XPartHost_KPart::createActions( const QCString &xmlActions )
+{
+ qDebug("--> createActions");
+ // creates a set of actions and adds them to the actionCollection
+ QDomDocument d;
+ d.setContent( xmlActions );
+
+ QDomElement docElem = d.documentElement();
+
+ kdDebug() << "docElement is " << docElem.tagName() << endl;
+
+ QDomNode n = docElem.firstChild();
+ while( !n.isNull() ) {
+ QDomElement e = n.toElement();
+ if( !e.isNull() ) {
+ if ( e.tagName() == "Action") {
+ QString name = e.attribute("name");
+ QString type = e.attribute("type");
+
+ if(type.isEmpty())
+ new KAction( name, 0, this, SLOT( actionActivated() ), actionCollection(), name.latin1() );
+ else if( type == "toggle" )
+ new KToggleAction( name, 0, this, SLOT( actionActivated() ), actionCollection(), name.latin1() );
+ kdDebug() << "action=" << name << " type=" << type << endl;
+ } else if ( e.tagName() == "XMLFile" ) {
+ QString location = e.attribute("location");
+ setXMLFile(location);
+ }
+ }
+ n = n.nextSibling();
+ }
+ emit actionsInitialized();
+}
+
+
+void XPartHost_KPart::setWindowCaption( const QString &caption )
+{
+ emit KParts::ReadOnlyPart::setWindowCaption( caption );
+}
+
+void XPartHost_KPart::setStatusBarText( const QString &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 QString &errMsg )
+{
+ emit KParts::ReadOnlyPart::canceled( errMsg );
+}
+
+bool XPartHost_KPart::openURL( const KURL &url )
+{
+ qDebug("XPartHost_KPart::openUrl()");
+ return m_stub->openURL( url.url().latin1() );
+}
+
+bool XPartHost_KPart::closeURL()
+{
+ return m_stub->closeURL();
+}
+
+
+void XPartHost_KPart::actionActivated()
+{
+ const QObject *o = sender();
+
+ if( !o->inherits("KAction") ) return;
+
+ const KAction *action = static_cast<const KAction *>(o);
+ QString name = action->text();
+ int state = 0;
+
+ if(action->inherits("KToggleAction")) {
+ const KToggleAction *t = static_cast<const KToggleAction *>(action);
+ state = t->isChecked();
+ }
+
+ m_stub->activateAction(name, state);
+}
+
+#include "xparthost_kpart.moc"
diff --git a/xparts/src/kde/xparthost_kpart.h b/xparts/src/kde/xparthost_kpart.h
new file mode 100644
index 00000000..5a12dec0
--- /dev/null
+++ b/xparts/src/kde/xparthost_kpart.h
@@ -0,0 +1,74 @@
+#ifndef __xparthost_kpart_h__
+#define __xparthost_kpart_h__
+
+#include <xparthost.h>
+
+#include <kparts/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( QWidget *parentWidget, const char *widgetName,
+ QObject *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 QCString &xmlActions );
+ /** Emitted by the XPart, to be transfered to the KPart host */
+ virtual ASYNC setWindowCaption( const QString &caption );
+ /** Emitted by the XPart, to be transfered to the KPart host */
+ virtual ASYNC setStatusBarText( const QString &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 QString &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