From 636f509299122d02087c6fd62e1e4a46dbd22026 Mon Sep 17 00:00:00 2001 From: Darrell Anderson Date: Wed, 8 Jan 2014 20:06:00 +0100 Subject: Rename many classes to avoid conflicts with KDE --- korundum/README | 4 +- korundum/bin/Makefile.am | 8 +- korundum/rubylib/korundum/Makefile.am | 2 +- korundum/rubylib/korundum/kdehandlers.cpp | 1438 ------------------------- korundum/rubylib/korundum/lib/KDE/Korundum.rb | 1 - korundum/rubylib/korundum/lib/KDE/Makefile.am | 5 - korundum/rubylib/korundum/lib/KDE/korundum.rb | 1391 ------------------------ korundum/rubylib/korundum/lib/Makefile.am | 2 +- korundum/rubylib/korundum/lib/TDE/Korundum.rb | 1 + korundum/rubylib/korundum/lib/TDE/Makefile.am | 5 + korundum/rubylib/korundum/lib/TDE/korundum.rb | 1391 ++++++++++++++++++++++++ korundum/rubylib/korundum/tdehandlers.cpp | 1438 +++++++++++++++++++++++++ 12 files changed, 2843 insertions(+), 2843 deletions(-) delete mode 100644 korundum/rubylib/korundum/kdehandlers.cpp delete mode 100644 korundum/rubylib/korundum/lib/KDE/Korundum.rb delete mode 100644 korundum/rubylib/korundum/lib/KDE/Makefile.am delete mode 100644 korundum/rubylib/korundum/lib/KDE/korundum.rb create mode 100644 korundum/rubylib/korundum/lib/TDE/Korundum.rb create mode 100644 korundum/rubylib/korundum/lib/TDE/Makefile.am create mode 100644 korundum/rubylib/korundum/lib/TDE/korundum.rb create mode 100644 korundum/rubylib/korundum/tdehandlers.cpp (limited to 'korundum') diff --git a/korundum/README b/korundum/README index 51641222..2ddb3911 100644 --- a/korundum/README +++ b/korundum/README @@ -8,10 +8,10 @@ KDE Specific Infomation: The other KDE classes are in the KParts::, TDEIO:: or DOM:: namespaces, with the same names as their C++ counterparts. - - Use the 'rbkdeapi' script to introspect the Korundum api from the command + - Use the 'rbtdeapi' script to introspect the Korundum api from the command line. For example: - $ rbkdeapi KDE::Action + $ rbtdeapi KDE::Action Will list all the methods in the KDE::Action class. There are currently (as at KDE 3.3 beta 2) 977 classes/30841 methods in the Smoke library diff --git a/korundum/bin/Makefile.am b/korundum/bin/Makefile.am index ef682c09..92beb014 100644 --- a/korundum/bin/Makefile.am +++ b/korundum/bin/Makefile.am @@ -7,7 +7,7 @@ krubyinit_SOURCES = krubyinit.cpp krubyinit_LDADD = $(LIB_KDE) $(RUBY_LIBRUBYARG) $(top_builddir)/smoke/tde/libsmoketde.la $(top_builddir)/qtruby/rubylib/qtruby/libqtrubyinternal.la install-exec-local: - @-rm -f $(DESTDIR)$(bindir)/rbkdeapi - @$(LN_S) rbqtapi $(DESTDIR)$(bindir)/rbkdeapi - @-rm -f $(DESTDIR)$(bindir)/rbkdesh - @$(LN_S) rbqtsh $(DESTDIR)$(bindir)/rbkdesh + @-rm -f $(DESTDIR)$(bindir)/rbtdeapi + @$(LN_S) rbqtapi $(DESTDIR)$(bindir)/rbtdeapi + @-rm -f $(DESTDIR)$(bindir)/rbtdesh + @$(LN_S) rbqtsh $(DESTDIR)$(bindir)/rbtdesh diff --git a/korundum/rubylib/korundum/Makefile.am b/korundum/rubylib/korundum/Makefile.am index 85797c62..70a05dd5 100644 --- a/korundum/rubylib/korundum/Makefile.am +++ b/korundum/rubylib/korundum/Makefile.am @@ -4,7 +4,7 @@ rubylibdir = $(RUBY_ARCHDIR) rubylib_LTLIBRARIES = korundum.la korundum_la_LDFLAGS = -module $(all_libraries) -version-info 0:0:0 korundum_la_METASOURCES = AUTO -korundum_la_SOURCES = Korundum.cpp kdehandlers.cpp +korundum_la_SOURCES = Korundum.cpp tdehandlers.cpp korundum_la_LIBADD = $(LIB_KDE) $(top_builddir)/smoke/tde/libsmoketde.la $(top_builddir)/qtruby/rubylib/qtruby/libqtrubyinternal.la SUBDIRS = lib diff --git a/korundum/rubylib/korundum/kdehandlers.cpp b/korundum/rubylib/korundum/kdehandlers.cpp deleted file mode 100644 index 12af6baf..00000000 --- a/korundum/rubylib/korundum/kdehandlers.cpp +++ /dev/null @@ -1,1438 +0,0 @@ -/*************************************************************************** - kdehandlers.cpp - KDE specific marshallers - ------------------- - begin : Sun Sep 28 2003 - copyright : (C) 2003 by Richard Dale - email : Richard_Dale@tipitina.demon.co.uk - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 option) any later version. * - * * - ***************************************************************************/ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#if TDE_VERSION >= 0x030200 -#include -#include -#include -#endif -#include -#include -#include -#include -#include - -#define HAVE_STRLCAT_PROTO 1 -#define HAVE_STRLCPY_PROTO 1 -#include "config.h" - -#ifndef HAVE_RUBY_1_9 -#define RARRAY_LEN(x) (RARRAY(x)->len) -#define RSTRING_LEN(x) (RSTRING(x)->len) -#define rb_str_catf_1 rb_str_catf -#endif - -extern "C" { -extern VALUE set_obj_info(const char * className, smokeruby_object * o); -}; - -extern bool isDerivedFromByName(Smoke *smoke, const char *className, const char *baseClassName); - -extern "C" { -/* - * Given an approximate classname and a kde instance, try to improve the resolution of the name - * by using the various KDE rtti mechanisms - */ -const char * -kde_resolve_classname(Smoke * smoke, int classId, void * ptr) -{ - if (isDerivedFromByName(smoke, smoke->classes[classId].className, "KArchiveEntry")) { - KArchiveEntry * entry = (KArchiveEntry *) smoke->cast(ptr, classId, smoke->idClass("KArchiveEntry")); - if (entry->isDirectory()) { - return "KDE::ArchiveDirectory"; - } else { - return "KDE::ArchiveFile"; - } - } else if (strcmp(smoke->classes[classId].className, "DOM::Node") == 0) { - DOM::Node * node = (DOM::Node *) smoke->cast(ptr, classId, smoke->idClass("DOM::Node")); - switch (node->nodeType()) { - case DOM::Node::ELEMENT_NODE: - if (((DOM::Element*)node)->isHTMLElement()) { - return "DOM::HTMLElement"; - } else { - return "DOM::Element"; - } - case DOM::Node::ATTRIBUTE_NODE: - return "DOM::Attr"; - case DOM::Node::TEXT_NODE: - return "DOM::Text"; - case DOM::Node::CDATA_SECTION_NODE: - return "DOM::CDATASection"; - case DOM::Node::ENTITY_REFERENCE_NODE: - return "DOM::EntityReference"; - case DOM::Node::ENTITY_NODE: - return "DOM::Entity"; - case DOM::Node::PROCESSING_INSTRUCTION_NODE: - return "DOM::ProcessingInstruction"; - case DOM::Node::COMMENT_NODE: - return "DOM::Comment"; - case DOM::Node::DOCUMENT_NODE: - return "DOM::Document"; - case DOM::Node::DOCUMENT_TYPE_NODE: - return "DOM::DocumentType"; - case DOM::Node::DOCUMENT_FRAGMENT_NODE: - return "DOM::DocumentFragment"; - case DOM::Node::NOTATION_NODE: - return "DOM::Notation"; - } - } - - return smoke->binding->className(classId); -} - -}; - -void marshall_TQCStringList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE list = *(m->var()); - if (TYPE(list) != T_ARRAY) { - m->item().s_voidp = 0; - break; - } - - int count = RARRAY_LEN(list); - QCStringList *stringlist = new QCStringList; - - for(long i = 0; i < count; i++) { - VALUE item = rb_ary_entry(list, i); - if(TYPE(item) != T_STRING) { - stringlist->append(TQCString()); - continue; - } - stringlist->append(TQCString(StringValuePtr(item), RSTRING_LEN(item) + 1)); - } - - m->item().s_voidp = stringlist; - m->next(); - - if(m->cleanup()) { - rb_ary_clear(list); - for(QCStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) - rb_ary_push(list, rb_str_new2(static_cast(*it))); - delete stringlist; - } - break; - } - case Marshall::ToVALUE: - { - QCStringList *stringlist = static_cast(m->item().s_voidp); - if(!stringlist) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - for(QCStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) { - VALUE rv = rb_str_new2(static_cast((*it))); - rb_ary_push(av, rv); - } - - if(m->cleanup()) - delete stringlist; - - *(m->var()) = av; - } - break; - default: - m->unsupported(); - break; - } -} - -#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 -# define BREAKPOINT { __asm__ __volatile__ ("int $03"); } -#else -# define BREAKPOINT { fprintf(stderr, "hit ctrl-c\n"); int b = 0; while (b == 0) { ; } } -#endif - -void marshall_TDECmdLineOptions(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE optionslist = *(m->var()); - if (optionslist == Qnil - || TYPE(optionslist) != T_ARRAY - || RARRAY_LEN(optionslist) == 0 ) - { - m->item().s_voidp = 0; - break; - } - - // Allocate 'length + 1' entries, to include an all NULLs last entry - TDECmdLineOptions *cmdLineOptions = (TDECmdLineOptions *) calloc( RARRAY_LEN(optionslist) + 1, - sizeof(struct TDECmdLineOptions) ); - - VALUE options; - long i; - for(i = 0; i < RARRAY_LEN(optionslist); i++) { - options = rb_ary_entry(optionslist, i); - VALUE temp = rb_ary_entry(options, 0); - cmdLineOptions[i].name = StringValuePtr(temp); - temp = rb_ary_entry(options, 1); - cmdLineOptions[i].description = StringValuePtr(temp); - temp = rb_ary_entry(options, 2); - cmdLineOptions[i].def = StringValuePtr(temp); - } - cmdLineOptions[i].name = 0; - cmdLineOptions[i].description = 0; - cmdLineOptions[i].def = 0; - - - m->item().s_voidp = cmdLineOptions; - m->next(); - /* - if(m->cleanup()) { - rb_ary_clear(optionslist); - for(i = 0; cmdLineOptions[i].name; i++) - options = rb_ary_new(); - rb_ary_push(options, rb_str_new2(cmdLineOptions[i].name)); - rb_ary_push(options, rb_str_new2(cmdLineOptions[i].description)); - rb_ary_push(options, rb_str_new2(cmdLineOptions[i].def)); - rb_ary_push(optionslist, options); - } - */ - } - break; - case Marshall::ToVALUE: - { - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_WIdList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE list = *(m->var()); - if (TYPE(list) != T_ARRAY) { - m->item().s_voidp = 0; - break; - } - int count = RARRAY_LEN(list); - TQValueList *valuelist = new TQValueList; - long i; - for(i = 0; i < count; i++) { - VALUE item = rb_ary_entry(list, i); - if(TYPE(item) != T_FIXNUM && TYPE(item) != T_BIGNUM) { - valuelist->append(0); - continue; - } - valuelist->append(NUM2LONG(item)); - } - - m->item().s_voidp = valuelist; - m->next(); - - if (!m->type().isConst()) { - rb_ary_clear(list); - for(TQValueListIterator it = valuelist->begin(); - it != valuelist->end(); - ++it) - rb_ary_push(list, LONG2NUM((int)*it)); - } - - if (m->cleanup()) { - delete valuelist; - } - } - break; - case Marshall::ToVALUE: - { - TQValueList *valuelist = (TQValueList*)m->item().s_voidp; - if(!valuelist) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - for(TQValueListIterator it = valuelist->begin(); - it != valuelist->end(); - ++it) - rb_ary_push(av, LONG2NUM(*it)); - - *(m->var()) = av; - - if(m->cleanup()) - delete valuelist; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KMimeTypeList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - KMimeType::List *offerList = (KMimeType::List*)m->item().s_voidp; - if(!offerList) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - for(KMimeType::List::Iterator it = offerList->begin(); - it != offerList->end(); - ++it) { - KMimeType * item = new KMimeType (*(KMimeType*)((KMimeType::Ptr)(*it)).data()); - - VALUE obj = getPointerObject(item); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KMimeType"); - o->ptr = item; - o->allocated = true; - obj = set_obj_info("KDE::MimeType", o); - } - rb_ary_push(av, obj); - } - - *(m->var()) = av; - - if(m->cleanup()) - delete offerList; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KMimeTypePtr(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - KMimeType::Ptr ptr(*(KMimeType::Ptr*)m->item().s_voidp); - if(ptr == 0) { - *(m->var()) = Qnil; - break; - } - KMimeType * mimeType = new KMimeType(*(KMimeType*)ptr); - - VALUE obj = getPointerObject(mimeType); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KMimeType"); - o->ptr = mimeType; - o->allocated = true; - obj = set_obj_info("KDE::MimeType", o); - } - - *(m->var()) = obj; - - if(m->cleanup()) - ; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KServicePtr(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - TDESharedPtr *ptr = new TDESharedPtr(*(TDESharedPtr*)m->item().s_voidp); - if(ptr == 0) { - *(m->var()) = Qnil; - break; - } - KService * service = ptr->data(); - - VALUE obj = getPointerObject(service); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KService"); - o->ptr = service; - o->allocated = true; - obj = set_obj_info("KDE::Service", o); - } - - *(m->var()) = obj; - - if(m->cleanup()) - ; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KServiceList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - KService::List *offerList = (KService::List*)m->item().s_voidp; - if(!offerList) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - for(KService::List::Iterator it = offerList->begin(); - it != offerList->end(); - ++it) { - TDESharedPtr *ptr = new TDESharedPtr(*it); - KService * currentOffer = ptr->data(); - - VALUE obj = getPointerObject(currentOffer); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KService"); - o->ptr = currentOffer; - o->allocated = false; - obj = set_obj_info("KDE::Service", o); - } - rb_ary_push(av, obj); - } - - *(m->var()) = av; - - if(m->cleanup()) - delete offerList; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KServiceGroupPtr(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - KServiceGroup::Ptr ptr(*(KServiceGroup::Ptr*)m->item().s_voidp); - if(ptr == 0) { - *(m->var()) = Qnil; - break; - } - KServiceGroup * serviceGroup = new KServiceGroup(*(KServiceGroup*)ptr); - - VALUE obj = getPointerObject(serviceGroup); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KServiceGroup"); - o->ptr = serviceGroup; - o->allocated = true; - obj = set_obj_info("KDE::ServiceGroup", o); - } - - *(m->var()) = obj; - - if(m->cleanup()) - ; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KServiceTypeList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - KServiceType::List *offerList = (KServiceType::List*)m->item().s_voidp; - if(!offerList) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - for(KServiceType::List::Iterator it = offerList->begin(); - it != offerList->end(); - ++it) { - KServiceType * currentOffer = new KServiceType(*((KServiceType*)*it)); - - VALUE obj = getPointerObject(currentOffer); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KServiceType"); - o->ptr = currentOffer; - o->allocated = true; - obj = set_obj_info("KDE::ServiceType", o); - } - rb_ary_push(av, obj); - } - - *(m->var()) = av; - - if(m->cleanup()) - delete offerList; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KServiceGroupList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - KServiceGroup::List *offerList = (KServiceGroup::List*)m->item().s_voidp; - if(!offerList) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - for(KServiceGroup::List::ConstIterator it = offerList->begin(); - it != offerList->end(); - ++it) { - KSycocaEntry *p = (*it); - VALUE obj = Qnil; - if (p->isType(KST_KService)) { - KService *s = static_cast(p); - obj = getPointerObject(s); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KService"); - o->ptr = s; - o->allocated = true; - obj = set_obj_info("KDE::Service", o); - } - } else if (p->isType(KST_KServiceGroup)) { - KServiceGroup *g = static_cast(p); - obj = getPointerObject(g); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KServiceGroup"); - o->ptr = g; - o->allocated = true; - obj = set_obj_info("KDE::ServiceGroup", o); - } - } - - rb_ary_push(av, obj); - } - - *(m->var()) = av; - - if(m->cleanup()) - delete offerList; - } - break; - default: - m->unsupported(); - break; - } -} - -#if TDE_VERSION >= 0x030200 -void marshall_KMountPointList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - KMountPoint::List *list = (KMountPoint::List*)m->item().s_voidp; - if(!list) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - for(KMountPoint::List::Iterator it = list->begin(); - it != list->end(); - ++it) { - KMountPoint * item = new KMountPoint(*((KMountPoint*)*it)); - - VALUE obj = getPointerObject(item); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KMountPoint"); - o->ptr = item; - o->allocated = true; - obj = set_obj_info("KDE::MountPoint", o); - } - rb_ary_push(av, obj); - } - - *(m->var()) = av; - - if(m->cleanup()) - delete list; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KPluginInfoList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - KPluginInfo::List *valuelist = (KPluginInfo::List*)m->item().s_voidp; - if(!valuelist) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - int ix = m->smoke()->idClass("KPluginInfo"); - const char * className = m->smoke()->binding->className(ix); - - for(KPluginInfo::List::Iterator it = valuelist->begin(); - it != valuelist->end(); - ++it) { - void *p = (*it); - - if(m->item().s_voidp == 0) { - *(m->var()) = Qnil; - break; - } - - VALUE obj = getPointerObject(p); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = o->smoke->idClass("KPluginInfo"); - o->ptr = p; - o->allocated = false; - obj = set_obj_info(className, o); - } - rb_ary_push(av, obj); - } - - if(m->cleanup()) - delete valuelist; - else - *(m->var()) = av; - } - break; - default: - m->unsupported(); - break; - } -} -#endif - -void marshall_TDEActionPtrList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - TDEActionPtrList *valuelist = (TDEActionPtrList*)m->item().s_voidp; - if (!valuelist) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - int ix = m->smoke()->idClass("TDEAction"); - const char * className = m->smoke()->binding->className(ix); - - for ( TDEActionPtrList::Iterator it = valuelist->begin(); - it != valuelist->end(); - ++it ) - { - void *p = (*it); - - if (m->item().s_voidp == 0) { - *(m->var()) = Qnil; - break; - } - - VALUE obj = getPointerObject(p); - if (obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = o->smoke->idClass("TDEAction"); - o->ptr = p; - o->allocated = false; - obj = set_obj_info(className, o); - } - rb_ary_push(av, obj); - } - - if (m->cleanup()) - delete valuelist; - else - *(m->var()) = av; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_TDETraderOfferList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - } - break; - case Marshall::ToVALUE: - { - TDETrader::OfferList *offerList = (TDETrader::OfferList*)m->item().s_voidp; - if(!offerList) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - for(TDETrader::OfferList::Iterator it = offerList->begin(); - it != offerList->end(); - ++it) { - TDESharedPtr *ptr = new TDESharedPtr(*it); - KService * currentOffer = ptr->data(); - - VALUE obj = getPointerObject(currentOffer); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = m->smoke()->idClass("KService"); - o->ptr = currentOffer; - o->allocated = false; - obj = set_obj_info("KDE::Service", o); - } - rb_ary_push(av, obj); - } - - *(m->var()) = av; - - if(m->cleanup()) - delete offerList; - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_KURLList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE list = *(m->var()); - if (TYPE(list) != T_ARRAY) { - m->item().s_voidp = 0; - break; - } - int count = RARRAY_LEN(list); - KURL::List *kurllist = new KURL::List; - long i; - for(i = 0; i < count; i++) { - VALUE item = rb_ary_entry(list, i); - // TODO do type checking! - smokeruby_object *o = value_obj_info(item); - if(!o || !o->ptr) - continue; - void *ptr = o->ptr; - ptr = o->smoke->cast( - ptr, // pointer - o->classId, // from - o->smoke->idClass("KURL") // to - ); - kurllist->append((KURL&)*(KURL*)ptr); - } - - m->item().s_voidp = kurllist; - m->next(); - - rb_ary_clear(list); - int ix = m->smoke()->idClass("KURL"); - const char * className = m->smoke()->binding->className(ix); - for ( KURL::List::Iterator it = kurllist->begin(); - it != kurllist->end(); - ++it ) - { - void *p = new KURL(*it); - VALUE obj = getPointerObject(p); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = ix; - o->ptr = p; - o->allocated = true; - obj = set_obj_info(className, o); - } - rb_ary_push(list, obj); - } - - if(m->cleanup()) { - delete kurllist; - } - } - break; - case Marshall::ToVALUE: - { - KURL::List *kurllist = (KURL::List*)m->item().s_voidp; - if(!kurllist) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - int ix = m->smoke()->idClass("KURL"); - const char * className = m->smoke()->binding->className(ix); - - for(KURL::List::Iterator it = kurllist->begin(); - it != kurllist->end(); - ++it) { - void *p = new KURL(*it); - - VALUE obj = getPointerObject(p); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = ix; - o->ptr = p; - o->allocated = true; - obj = set_obj_info(className, o); - } - rb_ary_push(av, obj); - } - - *(m->var()) = av; - - if(m->cleanup()) { - delete kurllist; - } - } - break; - default: - m->unsupported(); - break; - } -} - -void marshall_UDSEntryList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE list = *(m->var()); - if (TYPE(list) != T_ARRAY) { - m->item().s_voidp = 0; - break; - } - - TDEIO::UDSEntryList *cpplist = new TDEIO::UDSEntryList; - - for(long i = 0; i < RARRAY_LEN(list); i++) { - VALUE item = rb_ary_entry(list, i); - TDEIO::UDSEntry *cppsublist = new TDEIO::UDSEntry; - - for (int j = 0; j < RARRAY_LEN(item); j++) { - VALUE subitem = rb_ary_entry(item, j); - smokeruby_object *o = value_obj_info(subitem); - if(!o || !o->ptr) - continue; - void *ptr = o->ptr; - ptr = o->smoke->cast(ptr, o->classId, o->smoke->idClass("TDEIO::UDSAtom")); - cppsublist->append(*(TDEIO::UDSAtom*)ptr); - } - - cpplist->append(*cppsublist); - } - - m->item().s_voidp = cpplist; - m->next(); - } - break; - case Marshall::ToVALUE: - { - TDEIO::UDSEntryList *valuelist = (TDEIO::UDSEntryList*)m->item().s_voidp; - if (!valuelist) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - int ix = m->smoke()->idClass("TDEIO::UDSAtom"); - - for ( TDEIO::UDSEntryList::Iterator it = valuelist->begin(); - it != valuelist->end(); - ++it ) - { - TDEIO::UDSEntry * udsentry = &(*it); - VALUE subav = rb_ary_new(); - - for ( TDEIO::UDSEntry::Iterator it = udsentry->begin(); - it != udsentry->end(); - ++it ) - { - void * p = &(*it); - VALUE obj = getPointerObject(p); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = ix; - o->ptr = p; - o->allocated = false; - obj = set_obj_info("TDEIO::UDSAtom", o); - } - - rb_ary_push(subav, obj); - } - - rb_ary_push(av, subav); - } - - *(m->var()) = av; - } - break; - default: - m->unsupported(); - break; - } -} - - -// Some time saving magic from Alex Kellett here.. -template -void marshall_ItemList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE list = *(m->var()); - if (TYPE(list) != T_ARRAY) { - m->item().s_voidp = 0; - break; - } - int count = RARRAY_LEN(list); - ItemList *cpplist = new ItemList; - long i; - for(i = 0; i < count; i++) { - VALUE item = rb_ary_entry(list, i); - // TODO do type checking! - smokeruby_object *o = value_obj_info(item); - if(!o || !o->ptr) - continue; - void *ptr = o->ptr; - ptr = o->smoke->cast( - ptr, // pointer - o->classId, // from - o->smoke->idClass(ItemSTR) // to - ); - cpplist->append((Item*)ptr); - } - - m->item().s_voidp = cpplist; - m->next(); - - if(m->cleanup()) { - rb_ary_clear(list); - for( Item * it = cpplist->first(); - it != 0; - it = cpplist->next()) { - VALUE obj = getPointerObject((void*)it); - rb_ary_push(list, obj); - } - delete cpplist; - } - } - break; - case Marshall::ToVALUE: - { - ItemList *valuelist = (ItemList*)m->item().s_voidp; - if(!valuelist) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - int ix = m->smoke()->idClass(ItemSTR); - const char * className = m->smoke()->binding->className(ix); - - for(Item * it = valuelist->first(); - it != 0; - it = valuelist->next()) { - void *p = it; - - if(m->item().s_voidp == 0) { - *(m->var()) = Qnil; - break; - } - - VALUE obj = getPointerObject(p); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = o->smoke->idClass(ItemSTR); - o->ptr = p; - o->allocated = false; - obj = set_obj_info(className, o); - } - rb_ary_push(av, obj); - } - - if(m->cleanup()) - delete valuelist; - else - *(m->var()) = av; - } - break; - default: - m->unsupported(); - break; - } -} - -#define DEF_LIST_MARSHALLER(ListIdent,ItemList,Item) namespace { char ListIdent##STR[] = #Item; }; \ - Marshall::HandlerFn marshall_##ListIdent = marshall_ItemList; - -DEF_LIST_MARSHALLER( KFileItemList, TQPtrList, KFileItem ) -DEF_LIST_MARSHALLER( TDEMainWindowList, TQPtrList, TDEMainWindow ) -DEF_LIST_MARSHALLER( TDEActionList, TQPtrList, TDEAction ) -DEF_LIST_MARSHALLER( DCOPObjectList, TQPtrList, DCOPObject ) -DEF_LIST_MARSHALLER( KDockWidgetList, TQPtrList, KDockWidget ) -DEF_LIST_MARSHALLER( KFileTreeBranch, TQPtrList, KFileTreeBranch ) -DEF_LIST_MARSHALLER( KFileTreeViewItem, TQPtrList, KFileTreeViewItem ) -DEF_LIST_MARSHALLER( KPartList, TQPtrList, KParts::Part ) -DEF_LIST_MARSHALLER( KPartPluginList, TQPtrList, KParts::Plugin ) -DEF_LIST_MARSHALLER( KPartReadOnlyPartList, TQPtrList, KParts::ReadOnlyPart ) -DEF_LIST_MARSHALLER( KServiceTypeProfileList, TQPtrList, KServiceTypeProfile ) - -template -void marshall_ValueItemList(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE list = *(m->var()); - if (TYPE(list) != T_ARRAY) { - m->item().s_voidp = 0; - break; - } - int count = RARRAY_LEN(list); - ItemList *cpplist = new ItemList; - long i; - for(i = 0; i < count; i++) { - VALUE item = rb_ary_entry(list, i); - // TODO do type checking! - smokeruby_object *o = value_obj_info(item); - if(!o || !o->ptr) - continue; - void *ptr = o->ptr; - ptr = o->smoke->cast( - ptr, // pointer - o->classId, // from - o->smoke->idClass(ItemSTR) // to - ); - cpplist->append(*(Item*)ptr); - } - - m->item().s_voidp = cpplist; - m->next(); - - if(m->cleanup()) { - rb_ary_clear(list); - for(ItemListIterator it = cpplist->begin(); - it != cpplist->end(); - ++it) { - VALUE obj = getPointerObject((void*)&(*it)); - rb_ary_push(list, obj); - } - delete cpplist; - } - } - break; - case Marshall::ToVALUE: - { - ItemList *valuelist = (ItemList*)m->item().s_voidp; - if(!valuelist) { - *(m->var()) = Qnil; - break; - } - - VALUE av = rb_ary_new(); - - int ix = m->smoke()->idClass(ItemSTR); - const char * className = m->smoke()->binding->className(ix); - - for(ItemListIterator it = valuelist->begin(); - it != valuelist->end(); - ++it) { - void *p = &(*it); - - if(m->item().s_voidp == 0) { - *(m->var()) = Qnil; - break; - } - - VALUE obj = getPointerObject(p); - if(obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->smoke = m->smoke(); - o->classId = o->smoke->idClass(ItemSTR); - o->ptr = p; - o->allocated = false; - obj = set_obj_info(className, o); - } - rb_ary_push(av, obj); - } - - if(m->cleanup()) - delete valuelist; - else - *(m->var()) = av; - } - break; - default: - m->unsupported(); - break; - } -} - -#define DEF_VALUELIST_MARSHALLER(ListIdent,ItemList,Item,Itr) namespace { char ListIdent##STR[] = #Item; }; \ - Marshall::HandlerFn marshall_##ListIdent = marshall_ValueItemList; - -#if TDE_VERSION >= 0x030200 -DEF_VALUELIST_MARSHALLER( ChoicesList, TQValueList, TDEConfigSkeleton::ItemEnum::Choice, TQValueList::Iterator ) -#endif -DEF_VALUELIST_MARSHALLER( TDEAboutPersonList, TQValueList, TDEAboutPerson, TQValueList::Iterator ) -DEF_VALUELIST_MARSHALLER( TDEAboutTranslatorList, TQValueList, TDEAboutTranslator, TQValueList::Iterator ) -DEF_VALUELIST_MARSHALLER( KIOCopyInfoList, TQValueList, TDEIO::CopyInfo, TQValueList::Iterator ) -DEF_VALUELIST_MARSHALLER( KServiceOfferList, TQValueList, KServiceOffer, TQValueList::Iterator ) -DEF_VALUELIST_MARSHALLER( UDSEntry, TQValueList, TDEIO::UDSAtom, TQValueList::Iterator ) - -template -void marshall_Map(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE hash = *(m->var()); - if (TYPE(hash) != T_HASH) { - m->item().s_voidp = 0; - break; - } - - TQMap * map = new TQMap; - - // Convert the ruby hash to an array of key/value arrays - VALUE temp = rb_funcall(hash, rb_intern("to_a"), 0); - - for (long i = 0; i < RARRAY_LEN(temp); i++) { - VALUE key = rb_ary_entry(rb_ary_entry(temp, i), 0); - VALUE value = rb_ary_entry(rb_ary_entry(temp, i), 1); - - smokeruby_object *o = value_obj_info(key); - if( !o || !o->ptr) - continue; - void * key_ptr = o->ptr; - key_ptr = o->smoke->cast(key_ptr, o->classId, o->smoke->idClass(KeySTR)); - - o = value_obj_info(value); - if( !o || !o->ptr) - continue; - void * val_ptr = o->ptr; - val_ptr = o->smoke->cast(val_ptr, o->classId, o->smoke->idClass(ValueSTR)); - - (*map)[(Key)*(Key*)key_ptr] = (Value)*(Value*)val_ptr; - } - - m->item().s_voidp = map; - m->next(); - - if(m->cleanup()) - delete map; - } - break; - case Marshall::ToVALUE: - { - TQMap *map = (TQMap*)m->item().s_voidp; - if(!map) { - *(m->var()) = Qnil; - break; - } - - VALUE hv = rb_hash_new(); - - int key_ix = m->smoke()->idClass(KeySTR); - const char * key_className = m->smoke()->binding->className(key_ix); - - int val_ix = m->smoke()->idClass(ValueSTR); - const char * val_className = m->smoke()->binding->className(val_ix); - - ItemMapIterator it; - for (it = map->begin(); it != map->end(); ++it) { - void *key_p = new Key(it.key()); - VALUE key_obj = getPointerObject(key_p); - smokeruby_object * o; - - if (key_obj == Qnil) { - o = ALLOC(smokeruby_object); - o->classId = m->smoke()->idClass(KeySTR); - o->smoke = m->smoke(); - o->ptr = key_p; - o->allocated = true; - key_obj = set_obj_info(key_className, o); - } - - void *val_p = new Value(it.data()); - VALUE value_obj = getPointerObject(val_p); - - if (value_obj == Qnil) { - o = ALLOC(smokeruby_object); - o->classId = m->smoke()->idClass(ValueSTR); - o->smoke = m->smoke(); - o->ptr = val_p; - o->allocated = true; - value_obj = set_obj_info(val_className, o); - } - - rb_hash_aset(hv, key_obj, value_obj); - } - - *(m->var()) = hv; - m->next(); - - if(m->cleanup()) - delete map; - } - break; - default: - m->unsupported(); - break; - } -} - -#define DEF_MAP_MARSHALLER(MapIdent,Key,Value) namespace { char KeyIdent##STR[] = #Key; char ValueIdent##STR[] = #Value; }; \ - Marshall::HandlerFn marshall_##MapIdent = marshall_Map::Iterator,KeyIdent##STR, ValueIdent##STR>; - -DEF_MAP_MARSHALLER( TQMapKEntryKeyKEntry, KEntryKey, KEntry ) - -void marshall_TQMapTQCStringDCOPRef(Marshall *m) { - switch(m->action()) { - case Marshall::FromVALUE: - { - VALUE hash = *(m->var()); - if (TYPE(hash) != T_HASH) { - m->item().s_voidp = 0; - break; - } - - TQMap * map = new TQMap; - - // Convert the ruby hash to an array of key/value arrays - VALUE temp = rb_funcall(hash, rb_intern("to_a"), 0); - - for (long i = 0; i < RARRAY_LEN(temp); i++) { - VALUE key = rb_ary_entry(rb_ary_entry(temp, i), 0); - VALUE value = rb_ary_entry(rb_ary_entry(temp, i), 1); - - smokeruby_object *o = value_obj_info(value); - if( !o || !o->ptr) - continue; - void * ptr = o->ptr; - ptr = o->smoke->cast(ptr, o->classId, o->smoke->idClass("DCOPRef")); - - (*map)[TQCString(StringValuePtr(key))] = (DCOPRef)*(DCOPRef*)ptr; - } - - m->item().s_voidp = map; - m->next(); - - if(m->cleanup()) - delete map; - } - break; - case Marshall::ToVALUE: - { - TQMap *map = (TQMap*)m->item().s_voidp; - if(!map) { - *(m->var()) = Qnil; - break; - } - - VALUE hv = rb_hash_new(); - - TQMap::Iterator it; - for (it = map->begin(); it != map->end(); ++it) { - void *p = new DCOPRef(it.data()); - VALUE obj = getPointerObject(p); - - if (obj == Qnil) { - smokeruby_object * o = ALLOC(smokeruby_object); - o->classId = m->smoke()->idClass("DCOPRef"); - o->smoke = m->smoke(); - o->ptr = p; - o->allocated = true; - obj = set_obj_info("KDE::DCOPRef", o); - } - - rb_hash_aset(hv, rb_str_new2((const char *) it.key()), obj); - } - - *(m->var()) = hv; - m->next(); - - if(m->cleanup()) - delete map; - } - break; - default: - m->unsupported(); - break; - } -} - -TypeHandler KDE_handlers[] = { - { "QCStringList", marshall_TQCStringList }, - { "TDECmdLineOptions*", marshall_TDECmdLineOptions }, - { "TDEActionPtrList", marshall_TDEActionList }, - { "TQPtrList", marshall_TDEActionList }, - { "TQPtrList&", marshall_TDEActionList }, - { "KMimeType::List", marshall_KMimeTypeList }, - { "KMimeType::Ptr", marshall_KMimeTypePtr }, - { "KService::Ptr", marshall_KServicePtr }, - { "KService::List", marshall_KServiceList }, - { "KServiceGroup::List", marshall_KServiceGroupList }, - { "KServiceGroup::Ptr", marshall_KServiceGroupPtr }, -#if TDE_VERSION >= 0x030200 - { "KMountPoint::List", marshall_KMountPointList }, - { "KPluginInfo::List", marshall_KPluginInfoList }, - { "TQValueList", marshall_ChoicesList }, - { "TQValueList&", marshall_ChoicesList }, -#endif - { "KServiceType::List", marshall_KServiceTypeList }, - { "TDETrader::OfferList", marshall_TDETraderOfferList }, - { "KURL::List", marshall_KURLList }, - { "KURL::List&", marshall_KURLList }, - { "KFileItemList", marshall_KFileItemList }, - { "KFileItemList*", marshall_KFileItemList }, - { "TQPtrList*", marshall_TDEMainWindowList }, - { "TQPtrList", marshall_DCOPObjectList }, - { "TQPtrList&", marshall_KDockWidgetList }, - { "TQPtrList*", marshall_KDockWidgetList }, - { "KFileTreeBranchList&", marshall_KFileTreeBranch }, - { "KFileTreeViewItemList&", marshall_KFileTreeViewItem }, - { "TQPtrList*", marshall_KPartList }, - { "TQPtrList", marshall_KPartPluginList }, - { "TQPtrList", marshall_KPartReadOnlyPartList }, - { "TQPtrList&", marshall_KServiceTypeProfileList }, - { "TQValueList", marshall_TDEActionPtrList }, - { "TDEActionPtrList", marshall_TDEActionPtrList }, - { "TQValueList", marshall_TDEAboutPersonList }, - { "TQValueList", marshall_TDEAboutTranslatorList }, - { "TQValueList&", marshall_KIOCopyInfoList }, - { "TDEIO::UDSEntry&", marshall_UDSEntry }, - { "TDEIO::UDSEntryList&", marshall_UDSEntryList }, - { "KServiceTypeProfile::OfferList", marshall_KServiceOfferList }, - { "KEntryMap", marshall_TQMapKEntryKeyKEntry }, - { "KEntryMap&", marshall_TQMapKEntryKeyKEntry }, - { "KEntryMap*", marshall_TQMapKEntryKeyKEntry }, - { "TQMap", marshall_TQMapTQCStringDCOPRef }, - { "TQValueList&", marshall_WIdList }, - { "TQValueList", marshall_WIdList }, - { 0, 0 } -}; diff --git a/korundum/rubylib/korundum/lib/KDE/Korundum.rb b/korundum/rubylib/korundum/lib/KDE/Korundum.rb deleted file mode 100644 index 101d3e30..00000000 --- a/korundum/rubylib/korundum/lib/KDE/Korundum.rb +++ /dev/null @@ -1 +0,0 @@ -require 'korundum' diff --git a/korundum/rubylib/korundum/lib/KDE/Makefile.am b/korundum/rubylib/korundum/lib/KDE/Makefile.am deleted file mode 100644 index e69bcb05..00000000 --- a/korundum/rubylib/korundum/lib/KDE/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -kderubylibdir = $(RUBY_RUBYLIBDIR)/KDE -kderubylib_DATA = korundum.rb - -rubylibdir = $(RUBY_RUBYLIBDIR) -rubylib_DATA = Korundum.rb diff --git a/korundum/rubylib/korundum/lib/KDE/korundum.rb b/korundum/rubylib/korundum/lib/KDE/korundum.rb deleted file mode 100644 index 87e3be87..00000000 --- a/korundum/rubylib/korundum/lib/KDE/korundum.rb +++ /dev/null @@ -1,1391 +0,0 @@ -=begin -/*************************************************************************** - Korundum.rb - KDE specific ruby runtime, dcop etc. - ------------------- - begin : Sun Sep 28 2003 - copyright : (C) 2003-2006 by Richard Dale - email : Richard_Dale@tipitina.demon.co.uk - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 option) any later version. * - * * - ***************************************************************************/ -=end - -module KDE - DCOPMeta = {} - - # An entry for each dcop signal or slot - # Example - # int foobar(TQString,bool) - # :name is 'foobar' - # :full_name is 'foobar(TQString,bool)' - # :arg_types is 'TQString,bool' - # :reply_type is 'int' - DCOPMember = Struct.new :name, :full_name, :arg_types, :reply_type - - # If the class with the 'k_dcop' slots declaration is not a subclass of DCOPObject, - # then 'dcop_object' holds a instance of DCOPObject for the class to use as a - # proxy. For subclasses of DCOPObject, 'dcop_object' will always be nil - class DCOPMetaInfo - attr_accessor :dcop_object, :changed - attr_reader :k_dcop_signals, :k_dcop - - def initialize(aClass) - DCOPMeta[aClass.name] = self - @dcop_object = nil - @k_dcop_signals = {} - @k_dcop = {} - @changed = false - end - - def add_signals(signal_list) - signal_list.each do |signal| - signal = DCOPClient.normalizeFunctionSignature(signal) - if signal =~ /^([\w,<>:]*)\s+([^\s]*)\((.*)\)/ - args = DCOPClient.normalizeFunctionSignature($3) - @k_dcop_signals[$2] = DCOPMember.new($2, $2 + "(" + args + ")", args, $1) - else - tqWarning( "Invalid DCOP signal format: '#{signal}'" ) - end - end - end - - def add_slots(slot_list) - slot_list.each do |slot| - if slot =~ /^([\w,<>:]*)\s+([^\s]*)\((.*)\)/ - args = DCOPClient.normalizeFunctionSignature($3) - @k_dcop[$2] = DCOPMember.new($2, $1 + ' ' + $2 + "(" + args + ")", args, $1) - else - tqWarning( "Invalid DCOP slot format: '#{slot}'" ) - end - end - end - end # DCOPMetaInfo - - def KDE.hasDCOPSignals(aClass) - classname = aClass.name if aClass.is_a? Module - meta = DCOPMeta[classname] - return !meta.nil? && meta.k_dcop_signals.length > 0 - end - - def KDE.hasDCOPSlots(aClass) - classname = aClass.name if aClass.is_a? Module - meta = DCOPMeta[classname] - return !meta.nil? && meta.k_dcop.length > 0 - end - - def KDE.getDCOPSignalNames(aClass) - classname = aClass.name if aClass.is_a? Module - signals = DCOPMeta[classname].k_dcop_signals - return signals.keys - end - - module Internal - def Internal.fullSignalName(instance, signalName) - classname = instance.class.name if instance.class.is_a? Module - signals = DCOPMeta[classname].k_dcop_signals - return signals[signalName].full_name - end - end - - class KDE::DCOPObject - def initialize(*k) - super - end - - def process(fun, data, replyType, replyData) - if fun == 'functions()' or fun == 'interfaces()' - return super - end - - slots = DCOPMeta[@client.class.name].k_dcop - dcop_slot = slots[fun.sub(/\(.*/, '')] - if dcop_slot.nil? - # Can't find an entry for the slot being called? This shouldn't happen.. - return false - end - - replyType << dcop_slot.reply_type - KDE::dcop_process( @client, - dcop_slot.name, - TQt::Internal::getMocArguments(fun), - data, - replyType, - (replyType == 'void' or replyType == 'ASYNC') ? nil : TQt::Internal::getMocArguments(replyType), - replyData ) - end - - def interfaces() - ifaces = super() - return ifaces << @client.class.name - end - - def functions() - funcs = super() - return funcs + @functions - end - - def functions=(funcs) - @functions = funcs - end - - # If a ruby class has 'k_dcop' slots declarations, but isn't a - # subclass of DCOPObject, then keep an instance of it - def client=(obj) - @client = obj - end - - def inspect - str = super - if @functions != nil - str.sub(/>$/, " objId=%s, functions=Array (%d element(s))>" % [objId.inspect, functions.length]) - end - end - - def pretty_print(pp) - str = to_s - if @functions != nil - pp.text str.sub(/>$/, "\n objId=%s,\n functions=Array (%d element(s))>" % [objId.inspect, functions.length]) - end - end - end - - # If a class contains a k_dcop slots list declaration, then create a DCOPObject - # associated with it - def KDE.createDCOPObject(instance) - meta = DCOPMeta[instance.class.name] - return nil if meta.nil? - - if meta.dcop_object.nil? or meta.changed - funcs = [] - meta.k_dcop.each_value do |value| - sig = value.reply_type + ' ' + value.name + '(' + value.arg_types + ')' - funcs << sig - end - meta.changed = false - if instance.kind_of? DCOPObject - instance.functions = funcs - instance.client = instance - return nil - else - if meta.dcop_object.nil? - # Only ever allocate a single instance of a DCOPObject if the - # class isn't a subclass of DCOPObject - meta.dcop_object = DCOPObject.new(instance.class.name) - meta.dcop_object.client = instance - end - meta.dcop_object.functions = funcs - end - end - - return meta.dcop_object - end - - class DCOPRef < TQt::Base - def method_missing(*k) - # Enables DCOPRef calls to be made like this: - # - # dcopRef = DCOPRef.new("dcopslot", "MyWidget") - # result = dcopRef.getPoint("Hello from dcopcall") - begin - # First look for a method in the Smoke runtime. - # If not found, then throw an exception and try dcop. - super(*k) - rescue - dcopArgs = k[1, k.length-1] - dcopArgs << NoEventLoop << -1 - method = k[0].id2name - # Make 'parrot.age = 7' a synonym for 'parrot.setAge(7)' - method = 'set' + method[0,1].upcase + method[1,method.length].sub("=", "") if method =~ /.*[^-+%\/|]=$/ - - # If the method name contains underscores, convert to camel case - while method =~ /([^_]*)_(.)(.*)/ - method = $1 + $2.upcase + $3 - end - - # Get the functions() for this dcop ref and - # cache method_name => full_type_signature in a hash - if @functions.nil? - @functions = {} - funcs = call("functions()") - if funcs.nil? - return nil - end - funcs.each do |func| - if func =~ /^([\w,<>:]*)\s+(.*)(\(.*\))/ - return_type = $1 - name = $2 - args = $3 - if args =~ / / - # Remove any arg names - args.gsub!(/ \w*/, "") - end - - # Make thing? a synonym for isThing() or hasThing() - if name =~ /^(is|has)(.)(.*)/ - predicate = $2.downcase + $3 + '?' - if @functions[predicate].nil? - @functions[predicate] = return_type + " " + name + args - end - end - - if @functions[name].nil? - @functions[name] = return_type + " " + name + args - else - # If a function name is overloaded, just keep a single name entry in - # the hash, not all the full type signatures. Then leave dcopTypeNames() - # to try and resolve the ambiguous call from the ruby arg types passed. - @functions.delete(name) - @functions[name] = name - end - end - end - end - - method = @functions[method] - if method.nil? - tqWarning( "DCOPRef: call #{k[0].id2name}() not found" ) - return - end - - return callExt(method, *dcopArgs) - end - end - - def dcopTypeNames(*k) - typeNames = "(" - k.each do |arg| - if arg.kind_of? Integer - typeNames << "int," - elsif arg.kind_of? Float - typeNames << "double," - elsif arg.kind_of? Array - typeNames << "TQStringList," - elsif arg.kind_of? String - typeNames << "TQString," - elsif arg.kind_of? TQt::Base - typeNames << arg.class.name + "," - elsif arg.instance_of? FalseClass or arg.instance_of? TrueClass - typeNames << "bool," - end - end - typeNames.sub!(/,$/, '') - typeNames.gsub!(/TQt::/, 'Q') - typeNames.gsub!(/KDE::/, 'K') - typeNames << ")" - return typeNames - end - - def call(fun, *k) - k << NoEventLoop << -1 - callExt(fun, *k) - end - - def callExt(fun, *k) - if isNull - tqWarning( "DCOPRef: call #{fun} on null reference error" ) - return - end - sig = fun - if fun.index('(') == nil - sig << dcopTypeNames(*k[0, k.length - 2]) - end - dc = dcopClient() - if !dc || !dc.isAttached - tqWarning( "DCOPRef::call(): no DCOP client or client not attached error" ) - return - end - if sig =~ /([^\s]*)(\(.*\))/ - full_name = $1+$2 - else - tqWarning( "DCOPRef: call #{fun} invalid format, expecting '()'" ) - return - end - return KDE::dcop_call( self, - full_name, - TQt::Internal::getMocArguments(full_name), - *k ) - end - - def send(fun, *k) - if isNull - tqWarning( "DCOPRef: send #{fun} on null reference error" ) - end - sig = fun - if fun.index('(') == nil - sig << dcopTypeNames(*k) - end - dc = dcopClient() - if !dc || !dc.isAttached - tqWarning( "DCOPRef::send(): no DCOP client or client not attached error" ) - return - end - if !sig =~ /^([^\s]*)(\(.*\))/ - tqWarning( "DCOPRef: send #{sig} invalid format, expecting '()'" ) - return - end - return KDE::dcop_send( self, - fun, - TQt::Internal::getMocArguments(sig), - *k ) - end - - def methods - if @functions.nil? - functions() - end - - result = super + @functions.keys.map {|k| k.sub(/^(set)([A-Z])(.*)/) { $2.downcase + $3 + '=' } } - return result.uniq - end - - def inspect - str = super - str.sub(/>$/, " app=%s, obj=%s>" % [app.inspect, obj.inspect]) - end - - def pretty_print(pp) - str = to_s - pp.text str.sub(/>$/, "\n app=%s,\n obj=%s>" % [app.inspect, obj.inspect]) - end - - def type(*args) - method_missing(:type, *args) - end - end - - def CmdLineArgs::init(*k) - if k.length > 0 - if k[0].kind_of? Array - # If init() is passed an array as the first argument, assume it's ARGV. - # Then convert to a pair of args 'ARGV.length+1, [$0]+ARGV' - array = k.shift - super(*([array.length+1] + [[$0] + array] + k)) - elsif k[0].kind_of? KDE::AboutData - super(1, [$0], k[0]) - end - else - super - end - end - - # A sane alternative to the strange looking C++ template version, - # this takes a variable number of ruby args as classes to restore - def MainWindow::kRestoreMainWindows(*k) - n = 1 - while MainWindow.canBeRestored(n) - className = MainWindow.classNameOfToplevel(n) - k.each do |klass| - if klass.name == className - klass.new.restore(n) - end - end - n += 1 - end - end - - class AboutData - def inspect - str = super - str.sub!(/>$/, " appName=%s, copyrightStatement=%s, programName=%s, version=%s, shortDescription=%s, homepage=%s, bugAddress=%s>" % - [appName.inspect, copyrightStatement.inspect, programName.inspect, version.inspect, - shortDescription.inspect, homepage.inspect, bugAddress.inspect] ) - length = authors.length - if length > 0 - str.sub!(/>$/, ", authors=Array (%d element(s))>" % length) - end - length = credits.length - if length > 0 - str.sub!(/>$/, ", credits=Array (%d element(s))>" % length) - end - length = translators.length - if length > 0 - str.sub!(/>$/, ", translators=Array (%d element(s))>" % length) - end - return str - end - - def pretty_print(pp) - str = to_s - str.sub!(/>$/, "\n appName=%s,\n copyrightStatement=%s,\n programName=%s,\n version=%s,\n shortDescription=%s,\n homepage=%s,\n bugAddress=%s>" % - [appName.inspect, copyrightStatement.inspect, programName.inspect, version.inspect, - shortDescription.inspect, homepage.inspect, bugAddress.inspect] ) - length = authors.length - if length > 0 - str.sub!(/>$/, ",\n authors=Array (%d element(s))>" % length) - end - length = credits.length - if length > 0 - str.sub!(/>$/, ",\n credits=Array (%d element(s))>" % length) - end - length = translators.length - if length > 0 - str.sub!(/>$/, ",\n translators=Array (%d element(s))>" % length) - end - pp.text str - end - end - - class AboutPerson - def inspect - str = super - str.sub(/>$/, " emailAddress=%s, name=%s, task=%s, webAddress=%s>" % - [emailAddress.inspect, name.inspect, task.inspect, webAddress.inspect] ) - end - - def pretty_print(pp) - str = to_s - pp.text str.sub(/>$/, "\n emailAddress=%s,\n name=%s,\n task=%s,\n webAddress=%s>" % - [emailAddress.inspect, name.inspect, task.inspect, webAddress.inspect] ) - end - - def name(*args) - method_missing(:name, *args) - end - end - - class AboutTranslator - def inspect - str = super - str.sub(/>$/, " emailAddress=%s, name=%s>" % - [emailAddress.inspect, name.inspect] ) - end - - def pretty_print(pp) - str = to_s - pp.text str.sub(/>$/, "\n emailAddress=%s,\n name=%s>" % - [emailAddress.inspect, name.inspect] ) - end - - def name(*args) - method_missing(:name, *args) - end - end - - class AccelShortcutList - def name(*args) - method_missing(:name, *args) - end - end - - class ActionPtrShortcutList - def name(*args) - method_missing(:name, *args) - end - end - - class ActionShortcutList - def name(*args) - method_missing(:name, *args) - end - end - - class Application - def initialize(*k) - super - $kapp = self - end - - # Delete the underlying C++ instance after exec returns - # Otherwise, rb_gc_call_finalizer_at_exit() can delete - # stuff that KDE::Application still needs for its cleanup. - def exec - method_missing(:exec) - self.dispose - TQt::Internal.application_terminated = true - end - end - - class Archive - def open(*args) - method_missing(:open, *args) - end - end - - class ArchiveEntry - def name(*args) - method_missing(:name, *args) - end - end - - class BookmarkDrag - def format(*args) - method_missing(:format, *args) - end - end - - class CModule - def load(*args) - method_missing(:load, *args) - end - end - - class Catalogue - def name(*args) - method_missing(:name, *args) - end - end - - class ColorDrag - def format(*args) - method_missing(:format, *args) - end - end - - class CustomMenuEditor - def load(*args) - method_missing(:load, *args) - end - end - - class FileItem - def name(*args) - method_missing(:name, *args) - end - end - - class FileMetaInfoGroup - def name(*args) - method_missing(:name, *args) - end - end - - class FileMetaInfoItem - def type(*args) - method_missing(:type, *args) - end - end - - class FileTreeBranch - def name(*args) - method_missing(:name, *args) - end - end - - class FilterDev - def open(*args) - method_missing(:open, *args) - end - end - - class HTMLView - def print(*args) - method_missing(:print, *args) - end - end - - class Icon - def type(*args) - method_missing(:type, *args) - end - end - - class ImageEffect - def hash(*args) - method_missing(:hash, *args) - end - end - - class ImageIO - def type(*args) - method_missing(:type, *args) - end - end - - class ListView - include Enumerable - - def each - it = TQt::ListViewItemIterator.new(self) - while it.current - yield it.current - it += 1 - end - end - - def sort(*args) - method_missing(:sort, *args) - end - end - - class ListViewItem - include Enumerable - - def each - it = TQt::ListViewItemIterator.new(self) - while it.current - yield it.current - it += 1 - end - end - - def sort(*args) - method_missing(:sort, *args) - end - - def inspect - str = super - str.sub!(/>$/, "") - for i in 0..(listView.columns - 1) - str << " text%d=%s," % [i, self.text(i)] - end - str.sub!(/,?$/, ">") - end - - def pretty_print(pp) - str = to_s - str.sub!(/>$/, "") - for i in 0..(listView.columns - 1) - str << " text%d=%s," % [i, self.text(i)] - end - str.sub!(/,?$/, ">") - pp.text str - end - end - - class MainWindowInterface - def raise(*args) - method_missing(:raise, *args) - end - end - - class MdiChildView - def raise(*args) - method_missing(:raise, *args) - end - end - - class MimeType - def load(*args) - method_missing(:load, *args) - end - end - - class MultiTabBarButton - def id(*args) - method_missing(:id, *args) - end - end - - class MultipleDrag - def format(*args) - method_missing(:format, *args) - end - end - - class NamedCommand - def name(*args) - method_missing(:name, *args) - end - end - - class NewStuff - def type(*args) - method_missing(:type, *args) - end - end - - class OCRDialog - def id(*args) - method_missing(:id, *args) - end - end - - class Palette - def name(*args) - method_missing(:name, *args) - end - end - - class PanelApplet - def type(*args) - method_missing(:type, *args) - end - end - - class PanelExtension - def type(*args) - method_missing(:type, *args) - end - end - - class Pixmap - def load(*args) - method_missing(:load, *args) - end - end - - class PixmapEffect - def hash(*args) - method_missing(:hash, *args) - end - end - - class PluginInfo - def load(*args) - method_missing(:load, *args) - end - - def name(*args) - method_missing(:name, *args) - end - end - - class PluginSelector - def load(*args) - method_missing(:load, *args) - end - end - - class PopupFrame - def exec(*args) - method_missing(:exec, *args) - end - end - - class PrintAction - def print(*args) - method_missing(:print, *args) - end - end - - class Printer - def abort(*args) - method_missing(:abort, *args) - end - end - - class Progress - def format(*args) - method_missing(:format, *args) - end - end - - class ProtocolInfo - def exec(*args) - method_missing(:exec, *args) - end - - def load(*args) - method_missing(:load, *args) - end - - def name(*args) - method_missing(:name, *args) - end - end - - class Pty - def open(*args) - method_missing(:open, *args) - end - end - - class Run - def abort(*args) - method_missing(:abort, *args) - end - end - - class SSLCertDlgRet - def send(*args) - method_missing(:send, *args) - end - end - - class SSLPKCS12 - def name(*args) - method_missing(:name, *args) - end - end - - class SSLPKCS7 - def name(*args) - method_missing(:name, *args) - end - end - - class SSLSettings - def load(*args) - method_missing(:load, *args) - end - end - - class SaveFile - def abort(*args) - method_missing(:abort, *args) - end - - def name(*args) - method_missing(:name, *args) - end - end - - class ScanDialog - def id(*args) - method_missing(:id, *args) - end - end - - class Service - def inspect - str = super - str.sub(/>$/, " library=%s, type=%s, name=%s>" % [library.inspect, type.inspect, name.inspect]) - end - - def pretty_print(pp) - str = to_s - pp.text str.sub(/>$/, "\n library=%s,\n type=%s,\n name=%s>" % [library.inspect, type.inspect, name.inspect]) - end - - def exec(*args) - method_missing(:exec, *args) - end - - def load(*args) - method_missing(:load, *args) - end - - def name(*args) - method_missing(:name, *args) - end - - def type(*args) - method_missing(:type, *args) - end - end - - class ServiceGroup - def load(*args) - method_missing(:load, *args) - end - - def name(*args) - method_missing(:name, *args) - end - end - - class ServiceSeparator - def load(*args) - method_missing(:load, *args) - end - - def name(*args) - method_missing(:name, *args) - end - end - - class ServiceType - def load(*args) - method_missing(:load, *args) - end - - def name(*args) - method_missing(:name, *args) - end - end - - class Socks - def select(*args) - method_missing(:select, *args) - end - - def send(*args) - method_missing(:send, *args) - end - end - - class StdAccel - def name(*args) - method_missing(:name, *args) - end - - def open(*args) - method_missing(:open, *args) - end - - def print(*args) - method_missing(:print, *args) - end - end - - class StdAccel::ShortcutList - def name(*args) - method_missing(:name, *args) - end - end - - class StdAction - def name(*args) - method_missing(:name, *args) - end - - def open(*args) - method_missing(:open, *args) - end - - def print(*args) - method_missing(:print, *args) - end - end - - class StdGuiItem - def open(*args) - method_missing(:open, *args) - end - - def print(*args) - method_missing(:print, *args) - end - - def test(*args) - method_missing(:test, *args) - end - end - - class TempDir - def name(*args) - method_missing(:name, *args) - end - end - - class TempFile - def name(*args) - method_missing(:name, *args) - end - end - - class ToolBarButton - def id(*args) - method_missing(:id, *args) - end - end - - class UniqueApplication - def initialize(*k) - super - $kapp = self - end - - # Delete the underlying C++ instance after exec returns - # Otherwise, rb_gc_call_finalizer_at_exit() can delete - # stuff that KDE::Application still needs for its cleanup. - def exec - method_missing(:exec) - self.dispose - TQt::Internal.application_terminated = true - end - end - - class URIFilterPlugin - def name(*args) - method_missing(:name, *args) - end - end - - class URL - def inspect - str = super - str.sub(/>$/, " url=%s, protocol=%s, host=%s, port=%d>" % [url.inspect, protocol.inspect, host.inspect, port]) - end - - def pretty_print(pp) - str = to_s - pp.text str.sub(/>$/, "\n url=%s,\n protocol=%s,\n host=%s,\n port=%d>" % [url.inspect, protocol.inspect, host.inspect, port]) - end - - def split(*args) - method_missing(:split, *args) - end - end - - class URLDrag - def format(*args) - method_missing(:format, *args) - end - end - - class VMAllocator - def allocate(*args) - method_missing(:allocate, *args) - end - end - - class WindowInfo - def display(*args) - method_missing(:display, *args) - end - end - -end - -module DOM - class Attr - def name(*args) - method_missing(:name, *args) - end - end - - class DOMString - def split(*args) - method_missing(:split, *args) - end - end - - class DocumentType - def name(*args) - method_missing(:name, *args) - end - end - - class Event - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLAnchorElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLAnchorElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLAppletElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLButtonElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLButtonElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLElement - def id(*args) - method_missing(:id, *args) - end - end - - class HTMLFormElement - def method(*args) - method_missing(:method, *args) - end - end - - class HTMLFormElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLFrameElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLIFrameElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLImageElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLInputElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLInputElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLLIElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLLinkElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLMapElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLMetaElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLOListElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLObjectElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLObjectElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLParamElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLParamElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLScriptElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLSelectElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLSelectElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLStyleElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLTextAreaElement - def name(*args) - method_missing(:name, *args) - end - end - - class HTMLTextAreaElement - def type(*args) - method_missing(:type, *args) - end - end - - class HTMLUListElement - def type(*args) - method_missing(:type, *args) - end - end - - class StyleSheet - def type(*args) - method_missing(:type, *args) - end - end - - class CSSRule - def type(*args) - method_missing(:type, *args) - end - end - - class Document - def abort(*args) - method_missing(:abort, *args) - end - end - - class Document - def load(*args) - method_missing(:load, *args) - end - end - - class HTMLDocument - def open(*args) - method_missing(:open, *args) - end - end - - class HTMLInputElement - def select(*args) - method_missing(:select, *args) - end - end - - class HTMLTextAreaElement - def select(*args) - method_missing(:select, *args) - end - end -end # DOM - -module TDEIO - class Connection - def send(*args) - method_missing(:send, *args) - end - end - - class NetRC::AutoLogin - def type(*args) - method_missing(:type, *args) - end - end - - class Slave - def send(*args) - method_missing(:send, *args) - end - end - - class SlaveBase - def exit(*args) - method_missing(:exit, *args) - end - end -end # TDEIO - -module KNS - class Engine - def type(*args) - method_missing(:type, *args) - end - end - - class Entry - def name(*args) - method_missing(:name, *args) - end - - def type(*args) - method_missing(:type, *args) - end - end - - class Provider - def name(*args) - method_missing(:name, *args) - end - end - - class ProviderLoader - def load(*args) - method_missing(:load, *args) - end - end -end # KNS - -module KParts - class Event - def test(*args) - method_missing(:test, *args) - end - end - - class GUIActivateEvent - def test(*args) - method_missing(:test, *args) - end - end - - class OpenURLEvent - def test(*args) - method_missing(:test, *args) - end - end - - class PartActivateEvent - def test(*args) - method_missing(:test, *args) - end - end - - class PartSelectEvent - def test(*args) - method_missing(:test, *args) - end - end -end # KParts - -module Win - class Win::WindowInfo - def name(*args) - method_missing(:name, *args) - end - end -end - -class Object - def RESTORE(klass) - n = 1 - while MainWindow.canBeRestored(n) - klass.new.restore(n) - n += 1 - end - end - - def I18N_NOOP(x) x end - def I18N_NOOP2(comment, x) x end -end - -class TQt::Base - def self.k_dcop_signals(*signal_list) - meta = KDE::DCOPMeta[self.name] || KDE::DCOPMetaInfo.new(self) - meta.add_signals(signal_list) - meta.changed = true - end - - def self.k_dcop(*slot_list) - meta = KDE::DCOPMeta[self.name] || KDE::DCOPMetaInfo.new(self) - meta.add_slots(slot_list) - meta.changed = true - end -end diff --git a/korundum/rubylib/korundum/lib/Makefile.am b/korundum/rubylib/korundum/lib/Makefile.am index fba7d258..c951a717 100644 --- a/korundum/rubylib/korundum/lib/Makefile.am +++ b/korundum/rubylib/korundum/lib/Makefile.am @@ -1 +1 @@ -SUBDIRS = KDE +SUBDIRS = TDE diff --git a/korundum/rubylib/korundum/lib/TDE/Korundum.rb b/korundum/rubylib/korundum/lib/TDE/Korundum.rb new file mode 100644 index 00000000..101d3e30 --- /dev/null +++ b/korundum/rubylib/korundum/lib/TDE/Korundum.rb @@ -0,0 +1 @@ +require 'korundum' diff --git a/korundum/rubylib/korundum/lib/TDE/Makefile.am b/korundum/rubylib/korundum/lib/TDE/Makefile.am new file mode 100644 index 00000000..c01c10df --- /dev/null +++ b/korundum/rubylib/korundum/lib/TDE/Makefile.am @@ -0,0 +1,5 @@ +kderubylibdir = $(RUBY_RUBYLIBDIR)/TDE +kderubylib_DATA = korundum.rb + +rubylibdir = $(RUBY_RUBYLIBDIR) +rubylib_DATA = Korundum.rb diff --git a/korundum/rubylib/korundum/lib/TDE/korundum.rb b/korundum/rubylib/korundum/lib/TDE/korundum.rb new file mode 100644 index 00000000..043aa643 --- /dev/null +++ b/korundum/rubylib/korundum/lib/TDE/korundum.rb @@ -0,0 +1,1391 @@ +=begin +/*************************************************************************** + Korundum.rb - TDE specific ruby runtime, dcop etc. + ------------------- + begin : Sun Sep 28 2003 + copyright : (C) 2003-2006 by Richard Dale + email : Richard_Dale@tipitina.demon.co.uk + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 option) any later version. * + * * + ***************************************************************************/ +=end + +module KDE + DCOPMeta = {} + + # An entry for each dcop signal or slot + # Example + # int foobar(TQString,bool) + # :name is 'foobar' + # :full_name is 'foobar(TQString,bool)' + # :arg_types is 'TQString,bool' + # :reply_type is 'int' + DCOPMember = Struct.new :name, :full_name, :arg_types, :reply_type + + # If the class with the 'k_dcop' slots declaration is not a subclass of DCOPObject, + # then 'dcop_object' holds a instance of DCOPObject for the class to use as a + # proxy. For subclasses of DCOPObject, 'dcop_object' will always be nil + class DCOPMetaInfo + attr_accessor :dcop_object, :changed + attr_reader :k_dcop_signals, :k_dcop + + def initialize(aClass) + DCOPMeta[aClass.name] = self + @dcop_object = nil + @k_dcop_signals = {} + @k_dcop = {} + @changed = false + end + + def add_signals(signal_list) + signal_list.each do |signal| + signal = DCOPClient.normalizeFunctionSignature(signal) + if signal =~ /^([\w,<>:]*)\s+([^\s]*)\((.*)\)/ + args = DCOPClient.normalizeFunctionSignature($3) + @k_dcop_signals[$2] = DCOPMember.new($2, $2 + "(" + args + ")", args, $1) + else + tqWarning( "Invalid DCOP signal format: '#{signal}'" ) + end + end + end + + def add_slots(slot_list) + slot_list.each do |slot| + if slot =~ /^([\w,<>:]*)\s+([^\s]*)\((.*)\)/ + args = DCOPClient.normalizeFunctionSignature($3) + @k_dcop[$2] = DCOPMember.new($2, $1 + ' ' + $2 + "(" + args + ")", args, $1) + else + tqWarning( "Invalid DCOP slot format: '#{slot}'" ) + end + end + end + end # DCOPMetaInfo + + def KDE.hasDCOPSignals(aClass) + classname = aClass.name if aClass.is_a? Module + meta = DCOPMeta[classname] + return !meta.nil? && meta.k_dcop_signals.length > 0 + end + + def KDE.hasDCOPSlots(aClass) + classname = aClass.name if aClass.is_a? Module + meta = DCOPMeta[classname] + return !meta.nil? && meta.k_dcop.length > 0 + end + + def KDE.getDCOPSignalNames(aClass) + classname = aClass.name if aClass.is_a? Module + signals = DCOPMeta[classname].k_dcop_signals + return signals.keys + end + + module Internal + def Internal.fullSignalName(instance, signalName) + classname = instance.class.name if instance.class.is_a? Module + signals = DCOPMeta[classname].k_dcop_signals + return signals[signalName].full_name + end + end + + class KDE::DCOPObject + def initialize(*k) + super + end + + def process(fun, data, replyType, replyData) + if fun == 'functions()' or fun == 'interfaces()' + return super + end + + slots = DCOPMeta[@client.class.name].k_dcop + dcop_slot = slots[fun.sub(/\(.*/, '')] + if dcop_slot.nil? + # Can't find an entry for the slot being called? This shouldn't happen.. + return false + end + + replyType << dcop_slot.reply_type + KDE::dcop_process( @client, + dcop_slot.name, + TQt::Internal::getMocArguments(fun), + data, + replyType, + (replyType == 'void' or replyType == 'ASYNC') ? nil : TQt::Internal::getMocArguments(replyType), + replyData ) + end + + def interfaces() + ifaces = super() + return ifaces << @client.class.name + end + + def functions() + funcs = super() + return funcs + @functions + end + + def functions=(funcs) + @functions = funcs + end + + # If a ruby class has 'k_dcop' slots declarations, but isn't a + # subclass of DCOPObject, then keep an instance of it + def client=(obj) + @client = obj + end + + def inspect + str = super + if @functions != nil + str.sub(/>$/, " objId=%s, functions=Array (%d element(s))>" % [objId.inspect, functions.length]) + end + end + + def pretty_print(pp) + str = to_s + if @functions != nil + pp.text str.sub(/>$/, "\n objId=%s,\n functions=Array (%d element(s))>" % [objId.inspect, functions.length]) + end + end + end + + # If a class contains a k_dcop slots list declaration, then create a DCOPObject + # associated with it + def KDE.createDCOPObject(instance) + meta = DCOPMeta[instance.class.name] + return nil if meta.nil? + + if meta.dcop_object.nil? or meta.changed + funcs = [] + meta.k_dcop.each_value do |value| + sig = value.reply_type + ' ' + value.name + '(' + value.arg_types + ')' + funcs << sig + end + meta.changed = false + if instance.kind_of? DCOPObject + instance.functions = funcs + instance.client = instance + return nil + else + if meta.dcop_object.nil? + # Only ever allocate a single instance of a DCOPObject if the + # class isn't a subclass of DCOPObject + meta.dcop_object = DCOPObject.new(instance.class.name) + meta.dcop_object.client = instance + end + meta.dcop_object.functions = funcs + end + end + + return meta.dcop_object + end + + class DCOPRef < TQt::Base + def method_missing(*k) + # Enables DCOPRef calls to be made like this: + # + # dcopRef = DCOPRef.new("dcopslot", "MyWidget") + # result = dcopRef.getPoint("Hello from dcopcall") + begin + # First look for a method in the Smoke runtime. + # If not found, then throw an exception and try dcop. + super(*k) + rescue + dcopArgs = k[1, k.length-1] + dcopArgs << NoEventLoop << -1 + method = k[0].id2name + # Make 'parrot.age = 7' a synonym for 'parrot.setAge(7)' + method = 'set' + method[0,1].upcase + method[1,method.length].sub("=", "") if method =~ /.*[^-+%\/|]=$/ + + # If the method name contains underscores, convert to camel case + while method =~ /([^_]*)_(.)(.*)/ + method = $1 + $2.upcase + $3 + end + + # Get the functions() for this dcop ref and + # cache method_name => full_type_signature in a hash + if @functions.nil? + @functions = {} + funcs = call("functions()") + if funcs.nil? + return nil + end + funcs.each do |func| + if func =~ /^([\w,<>:]*)\s+(.*)(\(.*\))/ + return_type = $1 + name = $2 + args = $3 + if args =~ / / + # Remove any arg names + args.gsub!(/ \w*/, "") + end + + # Make thing? a synonym for isThing() or hasThing() + if name =~ /^(is|has)(.)(.*)/ + predicate = $2.downcase + $3 + '?' + if @functions[predicate].nil? + @functions[predicate] = return_type + " " + name + args + end + end + + if @functions[name].nil? + @functions[name] = return_type + " " + name + args + else + # If a function name is overloaded, just keep a single name entry in + # the hash, not all the full type signatures. Then leave dcopTypeNames() + # to try and resolve the ambiguous call from the ruby arg types passed. + @functions.delete(name) + @functions[name] = name + end + end + end + end + + method = @functions[method] + if method.nil? + tqWarning( "DCOPRef: call #{k[0].id2name}() not found" ) + return + end + + return callExt(method, *dcopArgs) + end + end + + def dcopTypeNames(*k) + typeNames = "(" + k.each do |arg| + if arg.kind_of? Integer + typeNames << "int," + elsif arg.kind_of? Float + typeNames << "double," + elsif arg.kind_of? Array + typeNames << "TQStringList," + elsif arg.kind_of? String + typeNames << "TQString," + elsif arg.kind_of? TQt::Base + typeNames << arg.class.name + "," + elsif arg.instance_of? FalseClass or arg.instance_of? TrueClass + typeNames << "bool," + end + end + typeNames.sub!(/,$/, '') + typeNames.gsub!(/TQt::/, 'Q') + typeNames.gsub!(/KDE::/, 'K') + typeNames << ")" + return typeNames + end + + def call(fun, *k) + k << NoEventLoop << -1 + callExt(fun, *k) + end + + def callExt(fun, *k) + if isNull + tqWarning( "DCOPRef: call #{fun} on null reference error" ) + return + end + sig = fun + if fun.index('(') == nil + sig << dcopTypeNames(*k[0, k.length - 2]) + end + dc = dcopClient() + if !dc || !dc.isAttached + tqWarning( "DCOPRef::call(): no DCOP client or client not attached error" ) + return + end + if sig =~ /([^\s]*)(\(.*\))/ + full_name = $1+$2 + else + tqWarning( "DCOPRef: call #{fun} invalid format, expecting '()'" ) + return + end + return KDE::dcop_call( self, + full_name, + TQt::Internal::getMocArguments(full_name), + *k ) + end + + def send(fun, *k) + if isNull + tqWarning( "DCOPRef: send #{fun} on null reference error" ) + end + sig = fun + if fun.index('(') == nil + sig << dcopTypeNames(*k) + end + dc = dcopClient() + if !dc || !dc.isAttached + tqWarning( "DCOPRef::send(): no DCOP client or client not attached error" ) + return + end + if !sig =~ /^([^\s]*)(\(.*\))/ + tqWarning( "DCOPRef: send #{sig} invalid format, expecting '()'" ) + return + end + return KDE::dcop_send( self, + fun, + TQt::Internal::getMocArguments(sig), + *k ) + end + + def methods + if @functions.nil? + functions() + end + + result = super + @functions.keys.map {|k| k.sub(/^(set)([A-Z])(.*)/) { $2.downcase + $3 + '=' } } + return result.uniq + end + + def inspect + str = super + str.sub(/>$/, " app=%s, obj=%s>" % [app.inspect, obj.inspect]) + end + + def pretty_print(pp) + str = to_s + pp.text str.sub(/>$/, "\n app=%s,\n obj=%s>" % [app.inspect, obj.inspect]) + end + + def type(*args) + method_missing(:type, *args) + end + end + + def CmdLineArgs::init(*k) + if k.length > 0 + if k[0].kind_of? Array + # If init() is passed an array as the first argument, assume it's ARGV. + # Then convert to a pair of args 'ARGV.length+1, [$0]+ARGV' + array = k.shift + super(*([array.length+1] + [[$0] + array] + k)) + elsif k[0].kind_of? KDE::AboutData + super(1, [$0], k[0]) + end + else + super + end + end + + # A sane alternative to the strange looking C++ template version, + # this takes a variable number of ruby args as classes to restore + def MainWindow::kRestoreMainWindows(*k) + n = 1 + while MainWindow.canBeRestored(n) + className = MainWindow.classNameOfToplevel(n) + k.each do |klass| + if klass.name == className + klass.new.restore(n) + end + end + n += 1 + end + end + + class AboutData + def inspect + str = super + str.sub!(/>$/, " appName=%s, copyrightStatement=%s, programName=%s, version=%s, shortDescription=%s, homepage=%s, bugAddress=%s>" % + [appName.inspect, copyrightStatement.inspect, programName.inspect, version.inspect, + shortDescription.inspect, homepage.inspect, bugAddress.inspect] ) + length = authors.length + if length > 0 + str.sub!(/>$/, ", authors=Array (%d element(s))>" % length) + end + length = credits.length + if length > 0 + str.sub!(/>$/, ", credits=Array (%d element(s))>" % length) + end + length = translators.length + if length > 0 + str.sub!(/>$/, ", translators=Array (%d element(s))>" % length) + end + return str + end + + def pretty_print(pp) + str = to_s + str.sub!(/>$/, "\n appName=%s,\n copyrightStatement=%s,\n programName=%s,\n version=%s,\n shortDescription=%s,\n homepage=%s,\n bugAddress=%s>" % + [appName.inspect, copyrightStatement.inspect, programName.inspect, version.inspect, + shortDescription.inspect, homepage.inspect, bugAddress.inspect] ) + length = authors.length + if length > 0 + str.sub!(/>$/, ",\n authors=Array (%d element(s))>" % length) + end + length = credits.length + if length > 0 + str.sub!(/>$/, ",\n credits=Array (%d element(s))>" % length) + end + length = translators.length + if length > 0 + str.sub!(/>$/, ",\n translators=Array (%d element(s))>" % length) + end + pp.text str + end + end + + class AboutPerson + def inspect + str = super + str.sub(/>$/, " emailAddress=%s, name=%s, task=%s, webAddress=%s>" % + [emailAddress.inspect, name.inspect, task.inspect, webAddress.inspect] ) + end + + def pretty_print(pp) + str = to_s + pp.text str.sub(/>$/, "\n emailAddress=%s,\n name=%s,\n task=%s,\n webAddress=%s>" % + [emailAddress.inspect, name.inspect, task.inspect, webAddress.inspect] ) + end + + def name(*args) + method_missing(:name, *args) + end + end + + class AboutTranslator + def inspect + str = super + str.sub(/>$/, " emailAddress=%s, name=%s>" % + [emailAddress.inspect, name.inspect] ) + end + + def pretty_print(pp) + str = to_s + pp.text str.sub(/>$/, "\n emailAddress=%s,\n name=%s>" % + [emailAddress.inspect, name.inspect] ) + end + + def name(*args) + method_missing(:name, *args) + end + end + + class AccelShortcutList + def name(*args) + method_missing(:name, *args) + end + end + + class ActionPtrShortcutList + def name(*args) + method_missing(:name, *args) + end + end + + class ActionShortcutList + def name(*args) + method_missing(:name, *args) + end + end + + class Application + def initialize(*k) + super + $kapp = self + end + + # Delete the underlying C++ instance after exec returns + # Otherwise, rb_gc_call_finalizer_at_exit() can delete + # stuff that KDE::Application still needs for its cleanup. + def exec + method_missing(:exec) + self.dispose + TQt::Internal.application_terminated = true + end + end + + class Archive + def open(*args) + method_missing(:open, *args) + end + end + + class ArchiveEntry + def name(*args) + method_missing(:name, *args) + end + end + + class BookmarkDrag + def format(*args) + method_missing(:format, *args) + end + end + + class CModule + def load(*args) + method_missing(:load, *args) + end + end + + class Catalogue + def name(*args) + method_missing(:name, *args) + end + end + + class ColorDrag + def format(*args) + method_missing(:format, *args) + end + end + + class CustomMenuEditor + def load(*args) + method_missing(:load, *args) + end + end + + class FileItem + def name(*args) + method_missing(:name, *args) + end + end + + class FileMetaInfoGroup + def name(*args) + method_missing(:name, *args) + end + end + + class FileMetaInfoItem + def type(*args) + method_missing(:type, *args) + end + end + + class FileTreeBranch + def name(*args) + method_missing(:name, *args) + end + end + + class FilterDev + def open(*args) + method_missing(:open, *args) + end + end + + class HTMLView + def print(*args) + method_missing(:print, *args) + end + end + + class Icon + def type(*args) + method_missing(:type, *args) + end + end + + class ImageEffect + def hash(*args) + method_missing(:hash, *args) + end + end + + class ImageIO + def type(*args) + method_missing(:type, *args) + end + end + + class ListView + include Enumerable + + def each + it = TQt::ListViewItemIterator.new(self) + while it.current + yield it.current + it += 1 + end + end + + def sort(*args) + method_missing(:sort, *args) + end + end + + class ListViewItem + include Enumerable + + def each + it = TQt::ListViewItemIterator.new(self) + while it.current + yield it.current + it += 1 + end + end + + def sort(*args) + method_missing(:sort, *args) + end + + def inspect + str = super + str.sub!(/>$/, "") + for i in 0..(listView.columns - 1) + str << " text%d=%s," % [i, self.text(i)] + end + str.sub!(/,?$/, ">") + end + + def pretty_print(pp) + str = to_s + str.sub!(/>$/, "") + for i in 0..(listView.columns - 1) + str << " text%d=%s," % [i, self.text(i)] + end + str.sub!(/,?$/, ">") + pp.text str + end + end + + class MainWindowInterface + def raise(*args) + method_missing(:raise, *args) + end + end + + class MdiChildView + def raise(*args) + method_missing(:raise, *args) + end + end + + class MimeType + def load(*args) + method_missing(:load, *args) + end + end + + class MultiTabBarButton + def id(*args) + method_missing(:id, *args) + end + end + + class MultipleDrag + def format(*args) + method_missing(:format, *args) + end + end + + class NamedCommand + def name(*args) + method_missing(:name, *args) + end + end + + class NewStuff + def type(*args) + method_missing(:type, *args) + end + end + + class OCRDialog + def id(*args) + method_missing(:id, *args) + end + end + + class Palette + def name(*args) + method_missing(:name, *args) + end + end + + class PanelApplet + def type(*args) + method_missing(:type, *args) + end + end + + class PanelExtension + def type(*args) + method_missing(:type, *args) + end + end + + class Pixmap + def load(*args) + method_missing(:load, *args) + end + end + + class PixmapEffect + def hash(*args) + method_missing(:hash, *args) + end + end + + class PluginInfo + def load(*args) + method_missing(:load, *args) + end + + def name(*args) + method_missing(:name, *args) + end + end + + class PluginSelector + def load(*args) + method_missing(:load, *args) + end + end + + class PopupFrame + def exec(*args) + method_missing(:exec, *args) + end + end + + class PrintAction + def print(*args) + method_missing(:print, *args) + end + end + + class Printer + def abort(*args) + method_missing(:abort, *args) + end + end + + class Progress + def format(*args) + method_missing(:format, *args) + end + end + + class ProtocolInfo + def exec(*args) + method_missing(:exec, *args) + end + + def load(*args) + method_missing(:load, *args) + end + + def name(*args) + method_missing(:name, *args) + end + end + + class Pty + def open(*args) + method_missing(:open, *args) + end + end + + class Run + def abort(*args) + method_missing(:abort, *args) + end + end + + class SSLCertDlgRet + def send(*args) + method_missing(:send, *args) + end + end + + class SSLPKCS12 + def name(*args) + method_missing(:name, *args) + end + end + + class SSLPKCS7 + def name(*args) + method_missing(:name, *args) + end + end + + class SSLSettings + def load(*args) + method_missing(:load, *args) + end + end + + class SaveFile + def abort(*args) + method_missing(:abort, *args) + end + + def name(*args) + method_missing(:name, *args) + end + end + + class ScanDialog + def id(*args) + method_missing(:id, *args) + end + end + + class Service + def inspect + str = super + str.sub(/>$/, " library=%s, type=%s, name=%s>" % [library.inspect, type.inspect, name.inspect]) + end + + def pretty_print(pp) + str = to_s + pp.text str.sub(/>$/, "\n library=%s,\n type=%s,\n name=%s>" % [library.inspect, type.inspect, name.inspect]) + end + + def exec(*args) + method_missing(:exec, *args) + end + + def load(*args) + method_missing(:load, *args) + end + + def name(*args) + method_missing(:name, *args) + end + + def type(*args) + method_missing(:type, *args) + end + end + + class ServiceGroup + def load(*args) + method_missing(:load, *args) + end + + def name(*args) + method_missing(:name, *args) + end + end + + class ServiceSeparator + def load(*args) + method_missing(:load, *args) + end + + def name(*args) + method_missing(:name, *args) + end + end + + class ServiceType + def load(*args) + method_missing(:load, *args) + end + + def name(*args) + method_missing(:name, *args) + end + end + + class Socks + def select(*args) + method_missing(:select, *args) + end + + def send(*args) + method_missing(:send, *args) + end + end + + class StdAccel + def name(*args) + method_missing(:name, *args) + end + + def open(*args) + method_missing(:open, *args) + end + + def print(*args) + method_missing(:print, *args) + end + end + + class StdAccel::ShortcutList + def name(*args) + method_missing(:name, *args) + end + end + + class StdAction + def name(*args) + method_missing(:name, *args) + end + + def open(*args) + method_missing(:open, *args) + end + + def print(*args) + method_missing(:print, *args) + end + end + + class StdGuiItem + def open(*args) + method_missing(:open, *args) + end + + def print(*args) + method_missing(:print, *args) + end + + def test(*args) + method_missing(:test, *args) + end + end + + class TempDir + def name(*args) + method_missing(:name, *args) + end + end + + class TempFile + def name(*args) + method_missing(:name, *args) + end + end + + class ToolBarButton + def id(*args) + method_missing(:id, *args) + end + end + + class UniqueApplication + def initialize(*k) + super + $kapp = self + end + + # Delete the underlying C++ instance after exec returns + # Otherwise, rb_gc_call_finalizer_at_exit() can delete + # stuff that KDE::Application still needs for its cleanup. + def exec + method_missing(:exec) + self.dispose + TQt::Internal.application_terminated = true + end + end + + class URIFilterPlugin + def name(*args) + method_missing(:name, *args) + end + end + + class URL + def inspect + str = super + str.sub(/>$/, " url=%s, protocol=%s, host=%s, port=%d>" % [url.inspect, protocol.inspect, host.inspect, port]) + end + + def pretty_print(pp) + str = to_s + pp.text str.sub(/>$/, "\n url=%s,\n protocol=%s,\n host=%s,\n port=%d>" % [url.inspect, protocol.inspect, host.inspect, port]) + end + + def split(*args) + method_missing(:split, *args) + end + end + + class URLDrag + def format(*args) + method_missing(:format, *args) + end + end + + class VMAllocator + def allocate(*args) + method_missing(:allocate, *args) + end + end + + class WindowInfo + def display(*args) + method_missing(:display, *args) + end + end + +end + +module DOM + class Attr + def name(*args) + method_missing(:name, *args) + end + end + + class DOMString + def split(*args) + method_missing(:split, *args) + end + end + + class DocumentType + def name(*args) + method_missing(:name, *args) + end + end + + class Event + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLAnchorElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLAnchorElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLAppletElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLButtonElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLButtonElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLElement + def id(*args) + method_missing(:id, *args) + end + end + + class HTMLFormElement + def method(*args) + method_missing(:method, *args) + end + end + + class HTMLFormElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLFrameElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLIFrameElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLImageElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLInputElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLInputElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLLIElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLLinkElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLMapElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLMetaElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLOListElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLObjectElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLObjectElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLParamElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLParamElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLScriptElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLSelectElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLSelectElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLStyleElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLTextAreaElement + def name(*args) + method_missing(:name, *args) + end + end + + class HTMLTextAreaElement + def type(*args) + method_missing(:type, *args) + end + end + + class HTMLUListElement + def type(*args) + method_missing(:type, *args) + end + end + + class StyleSheet + def type(*args) + method_missing(:type, *args) + end + end + + class CSSRule + def type(*args) + method_missing(:type, *args) + end + end + + class Document + def abort(*args) + method_missing(:abort, *args) + end + end + + class Document + def load(*args) + method_missing(:load, *args) + end + end + + class HTMLDocument + def open(*args) + method_missing(:open, *args) + end + end + + class HTMLInputElement + def select(*args) + method_missing(:select, *args) + end + end + + class HTMLTextAreaElement + def select(*args) + method_missing(:select, *args) + end + end +end # DOM + +module TDEIO + class Connection + def send(*args) + method_missing(:send, *args) + end + end + + class NetRC::AutoLogin + def type(*args) + method_missing(:type, *args) + end + end + + class Slave + def send(*args) + method_missing(:send, *args) + end + end + + class SlaveBase + def exit(*args) + method_missing(:exit, *args) + end + end +end # TDEIO + +module KNS + class Engine + def type(*args) + method_missing(:type, *args) + end + end + + class Entry + def name(*args) + method_missing(:name, *args) + end + + def type(*args) + method_missing(:type, *args) + end + end + + class Provider + def name(*args) + method_missing(:name, *args) + end + end + + class ProviderLoader + def load(*args) + method_missing(:load, *args) + end + end +end # KNS + +module KParts + class Event + def test(*args) + method_missing(:test, *args) + end + end + + class GUIActivateEvent + def test(*args) + method_missing(:test, *args) + end + end + + class OpenURLEvent + def test(*args) + method_missing(:test, *args) + end + end + + class PartActivateEvent + def test(*args) + method_missing(:test, *args) + end + end + + class PartSelectEvent + def test(*args) + method_missing(:test, *args) + end + end +end # KParts + +module Win + class Win::WindowInfo + def name(*args) + method_missing(:name, *args) + end + end +end + +class Object + def RESTORE(klass) + n = 1 + while MainWindow.canBeRestored(n) + klass.new.restore(n) + n += 1 + end + end + + def I18N_NOOP(x) x end + def I18N_NOOP2(comment, x) x end +end + +class TQt::Base + def self.k_dcop_signals(*signal_list) + meta = KDE::DCOPMeta[self.name] || KDE::DCOPMetaInfo.new(self) + meta.add_signals(signal_list) + meta.changed = true + end + + def self.k_dcop(*slot_list) + meta = KDE::DCOPMeta[self.name] || KDE::DCOPMetaInfo.new(self) + meta.add_slots(slot_list) + meta.changed = true + end +end diff --git a/korundum/rubylib/korundum/tdehandlers.cpp b/korundum/rubylib/korundum/tdehandlers.cpp new file mode 100644 index 00000000..f4707824 --- /dev/null +++ b/korundum/rubylib/korundum/tdehandlers.cpp @@ -0,0 +1,1438 @@ +/*************************************************************************** + kdehandlers.cpp - KDE specific marshallers + ------------------- + begin : Sun Sep 28 2003 + copyright : (C) 2003 by Richard Dale + email : Richard_Dale@tipitina.demon.co.uk + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 option) any later version. * + * * + ***************************************************************************/ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if TDE_VERSION >= 0x030200 +#include +#include +#include +#endif +#include +#include +#include +#include +#include + +#define HAVE_STRLCAT_PROTO 1 +#define HAVE_STRLCPY_PROTO 1 +#include "config.h" + +#ifndef HAVE_RUBY_1_9 +#define RARRAY_LEN(x) (RARRAY(x)->len) +#define RSTRING_LEN(x) (RSTRING(x)->len) +#define rb_str_catf_1 rb_str_catf +#endif + +extern "C" { +extern VALUE set_obj_info(const char * className, smokeruby_object * o); +}; + +extern bool isDerivedFromByName(Smoke *smoke, const char *className, const char *baseClassName); + +extern "C" { +/* + * Given an approximate classname and a kde instance, try to improve the resolution of the name + * by using the various KDE rtti mechanisms + */ +const char * +kde_resolve_classname(Smoke * smoke, int classId, void * ptr) +{ + if (isDerivedFromByName(smoke, smoke->classes[classId].className, "KArchiveEntry")) { + KArchiveEntry * entry = (KArchiveEntry *) smoke->cast(ptr, classId, smoke->idClass("KArchiveEntry")); + if (entry->isDirectory()) { + return "KDE::ArchiveDirectory"; + } else { + return "KDE::ArchiveFile"; + } + } else if (strcmp(smoke->classes[classId].className, "DOM::Node") == 0) { + DOM::Node * node = (DOM::Node *) smoke->cast(ptr, classId, smoke->idClass("DOM::Node")); + switch (node->nodeType()) { + case DOM::Node::ELEMENT_NODE: + if (((DOM::Element*)node)->isHTMLElement()) { + return "DOM::HTMLElement"; + } else { + return "DOM::Element"; + } + case DOM::Node::ATTRIBUTE_NODE: + return "DOM::Attr"; + case DOM::Node::TEXT_NODE: + return "DOM::Text"; + case DOM::Node::CDATA_SECTION_NODE: + return "DOM::CDATASection"; + case DOM::Node::ENTITY_REFERENCE_NODE: + return "DOM::EntityReference"; + case DOM::Node::ENTITY_NODE: + return "DOM::Entity"; + case DOM::Node::PROCESSING_INSTRUCTION_NODE: + return "DOM::ProcessingInstruction"; + case DOM::Node::COMMENT_NODE: + return "DOM::Comment"; + case DOM::Node::DOCUMENT_NODE: + return "DOM::Document"; + case DOM::Node::DOCUMENT_TYPE_NODE: + return "DOM::DocumentType"; + case DOM::Node::DOCUMENT_FRAGMENT_NODE: + return "DOM::DocumentFragment"; + case DOM::Node::NOTATION_NODE: + return "DOM::Notation"; + } + } + + return smoke->binding->className(classId); +} + +}; + +void marshall_TQCStringList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE list = *(m->var()); + if (TYPE(list) != T_ARRAY) { + m->item().s_voidp = 0; + break; + } + + int count = RARRAY_LEN(list); + QCStringList *stringlist = new QCStringList; + + for(long i = 0; i < count; i++) { + VALUE item = rb_ary_entry(list, i); + if(TYPE(item) != T_STRING) { + stringlist->append(TQCString()); + continue; + } + stringlist->append(TQCString(StringValuePtr(item), RSTRING_LEN(item) + 1)); + } + + m->item().s_voidp = stringlist; + m->next(); + + if(m->cleanup()) { + rb_ary_clear(list); + for(QCStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) + rb_ary_push(list, rb_str_new2(static_cast(*it))); + delete stringlist; + } + break; + } + case Marshall::ToVALUE: + { + QCStringList *stringlist = static_cast(m->item().s_voidp); + if(!stringlist) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + for(QCStringList::Iterator it = stringlist->begin(); it != stringlist->end(); ++it) { + VALUE rv = rb_str_new2(static_cast((*it))); + rb_ary_push(av, rv); + } + + if(m->cleanup()) + delete stringlist; + + *(m->var()) = av; + } + break; + default: + m->unsupported(); + break; + } +} + +#if defined (__i386__) && defined (__GNUC__) && __GNUC__ >= 2 +# define BREAKPOINT { __asm__ __volatile__ ("int $03"); } +#else +# define BREAKPOINT { fprintf(stderr, "hit ctrl-c\n"); int b = 0; while (b == 0) { ; } } +#endif + +void marshall_TDECmdLineOptions(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE optionslist = *(m->var()); + if (optionslist == Qnil + || TYPE(optionslist) != T_ARRAY + || RARRAY_LEN(optionslist) == 0 ) + { + m->item().s_voidp = 0; + break; + } + + // Allocate 'length + 1' entries, to include an all NULLs last entry + TDECmdLineOptions *cmdLineOptions = (TDECmdLineOptions *) calloc( RARRAY_LEN(optionslist) + 1, + sizeof(struct TDECmdLineOptions) ); + + VALUE options; + long i; + for(i = 0; i < RARRAY_LEN(optionslist); i++) { + options = rb_ary_entry(optionslist, i); + VALUE temp = rb_ary_entry(options, 0); + cmdLineOptions[i].name = StringValuePtr(temp); + temp = rb_ary_entry(options, 1); + cmdLineOptions[i].description = StringValuePtr(temp); + temp = rb_ary_entry(options, 2); + cmdLineOptions[i].def = StringValuePtr(temp); + } + cmdLineOptions[i].name = 0; + cmdLineOptions[i].description = 0; + cmdLineOptions[i].def = 0; + + + m->item().s_voidp = cmdLineOptions; + m->next(); + /* + if(m->cleanup()) { + rb_ary_clear(optionslist); + for(i = 0; cmdLineOptions[i].name; i++) + options = rb_ary_new(); + rb_ary_push(options, rb_str_new2(cmdLineOptions[i].name)); + rb_ary_push(options, rb_str_new2(cmdLineOptions[i].description)); + rb_ary_push(options, rb_str_new2(cmdLineOptions[i].def)); + rb_ary_push(optionslist, options); + } + */ + } + break; + case Marshall::ToVALUE: + { + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_WIdList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE list = *(m->var()); + if (TYPE(list) != T_ARRAY) { + m->item().s_voidp = 0; + break; + } + int count = RARRAY_LEN(list); + TQValueList *valuelist = new TQValueList; + long i; + for(i = 0; i < count; i++) { + VALUE item = rb_ary_entry(list, i); + if(TYPE(item) != T_FIXNUM && TYPE(item) != T_BIGNUM) { + valuelist->append(0); + continue; + } + valuelist->append(NUM2LONG(item)); + } + + m->item().s_voidp = valuelist; + m->next(); + + if (!m->type().isConst()) { + rb_ary_clear(list); + for(TQValueListIterator it = valuelist->begin(); + it != valuelist->end(); + ++it) + rb_ary_push(list, LONG2NUM((int)*it)); + } + + if (m->cleanup()) { + delete valuelist; + } + } + break; + case Marshall::ToVALUE: + { + TQValueList *valuelist = (TQValueList*)m->item().s_voidp; + if(!valuelist) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + for(TQValueListIterator it = valuelist->begin(); + it != valuelist->end(); + ++it) + rb_ary_push(av, LONG2NUM(*it)); + + *(m->var()) = av; + + if(m->cleanup()) + delete valuelist; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KMimeTypeList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + KMimeType::List *offerList = (KMimeType::List*)m->item().s_voidp; + if(!offerList) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + for(KMimeType::List::Iterator it = offerList->begin(); + it != offerList->end(); + ++it) { + KMimeType * item = new KMimeType (*(KMimeType*)((KMimeType::Ptr)(*it)).data()); + + VALUE obj = getPointerObject(item); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KMimeType"); + o->ptr = item; + o->allocated = true; + obj = set_obj_info("KDE::MimeType", o); + } + rb_ary_push(av, obj); + } + + *(m->var()) = av; + + if(m->cleanup()) + delete offerList; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KMimeTypePtr(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + KMimeType::Ptr ptr(*(KMimeType::Ptr*)m->item().s_voidp); + if(ptr == 0) { + *(m->var()) = Qnil; + break; + } + KMimeType * mimeType = new KMimeType(*(KMimeType*)ptr); + + VALUE obj = getPointerObject(mimeType); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KMimeType"); + o->ptr = mimeType; + o->allocated = true; + obj = set_obj_info("KDE::MimeType", o); + } + + *(m->var()) = obj; + + if(m->cleanup()) + ; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KServicePtr(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + TDESharedPtr *ptr = new TDESharedPtr(*(TDESharedPtr*)m->item().s_voidp); + if(ptr == 0) { + *(m->var()) = Qnil; + break; + } + KService * service = ptr->data(); + + VALUE obj = getPointerObject(service); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KService"); + o->ptr = service; + o->allocated = true; + obj = set_obj_info("KDE::Service", o); + } + + *(m->var()) = obj; + + if(m->cleanup()) + ; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KServiceList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + KService::List *offerList = (KService::List*)m->item().s_voidp; + if(!offerList) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + for(KService::List::Iterator it = offerList->begin(); + it != offerList->end(); + ++it) { + TDESharedPtr *ptr = new TDESharedPtr(*it); + KService * currentOffer = ptr->data(); + + VALUE obj = getPointerObject(currentOffer); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KService"); + o->ptr = currentOffer; + o->allocated = false; + obj = set_obj_info("KDE::Service", o); + } + rb_ary_push(av, obj); + } + + *(m->var()) = av; + + if(m->cleanup()) + delete offerList; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KServiceGroupPtr(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + KServiceGroup::Ptr ptr(*(KServiceGroup::Ptr*)m->item().s_voidp); + if(ptr == 0) { + *(m->var()) = Qnil; + break; + } + KServiceGroup * serviceGroup = new KServiceGroup(*(KServiceGroup*)ptr); + + VALUE obj = getPointerObject(serviceGroup); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KServiceGroup"); + o->ptr = serviceGroup; + o->allocated = true; + obj = set_obj_info("KDE::ServiceGroup", o); + } + + *(m->var()) = obj; + + if(m->cleanup()) + ; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KServiceTypeList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + KServiceType::List *offerList = (KServiceType::List*)m->item().s_voidp; + if(!offerList) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + for(KServiceType::List::Iterator it = offerList->begin(); + it != offerList->end(); + ++it) { + KServiceType * currentOffer = new KServiceType(*((KServiceType*)*it)); + + VALUE obj = getPointerObject(currentOffer); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KServiceType"); + o->ptr = currentOffer; + o->allocated = true; + obj = set_obj_info("KDE::ServiceType", o); + } + rb_ary_push(av, obj); + } + + *(m->var()) = av; + + if(m->cleanup()) + delete offerList; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KServiceGroupList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + KServiceGroup::List *offerList = (KServiceGroup::List*)m->item().s_voidp; + if(!offerList) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + for(KServiceGroup::List::ConstIterator it = offerList->begin(); + it != offerList->end(); + ++it) { + KSycocaEntry *p = (*it); + VALUE obj = Qnil; + if (p->isType(KST_KService)) { + KService *s = static_cast(p); + obj = getPointerObject(s); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KService"); + o->ptr = s; + o->allocated = true; + obj = set_obj_info("KDE::Service", o); + } + } else if (p->isType(KST_KServiceGroup)) { + KServiceGroup *g = static_cast(p); + obj = getPointerObject(g); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KServiceGroup"); + o->ptr = g; + o->allocated = true; + obj = set_obj_info("KDE::ServiceGroup", o); + } + } + + rb_ary_push(av, obj); + } + + *(m->var()) = av; + + if(m->cleanup()) + delete offerList; + } + break; + default: + m->unsupported(); + break; + } +} + +#if TDE_VERSION >= 0x030200 +void marshall_KMountPointList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + KMountPoint::List *list = (KMountPoint::List*)m->item().s_voidp; + if(!list) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + for(KMountPoint::List::Iterator it = list->begin(); + it != list->end(); + ++it) { + KMountPoint * item = new KMountPoint(*((KMountPoint*)*it)); + + VALUE obj = getPointerObject(item); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KMountPoint"); + o->ptr = item; + o->allocated = true; + obj = set_obj_info("KDE::MountPoint", o); + } + rb_ary_push(av, obj); + } + + *(m->var()) = av; + + if(m->cleanup()) + delete list; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KPluginInfoList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + KPluginInfo::List *valuelist = (KPluginInfo::List*)m->item().s_voidp; + if(!valuelist) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + int ix = m->smoke()->idClass("KPluginInfo"); + const char * className = m->smoke()->binding->className(ix); + + for(KPluginInfo::List::Iterator it = valuelist->begin(); + it != valuelist->end(); + ++it) { + void *p = (*it); + + if(m->item().s_voidp == 0) { + *(m->var()) = Qnil; + break; + } + + VALUE obj = getPointerObject(p); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = o->smoke->idClass("KPluginInfo"); + o->ptr = p; + o->allocated = false; + obj = set_obj_info(className, o); + } + rb_ary_push(av, obj); + } + + if(m->cleanup()) + delete valuelist; + else + *(m->var()) = av; + } + break; + default: + m->unsupported(); + break; + } +} +#endif + +void marshall_TDEActionPtrList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + TDEActionPtrList *valuelist = (TDEActionPtrList*)m->item().s_voidp; + if (!valuelist) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + int ix = m->smoke()->idClass("TDEAction"); + const char * className = m->smoke()->binding->className(ix); + + for ( TDEActionPtrList::Iterator it = valuelist->begin(); + it != valuelist->end(); + ++it ) + { + void *p = (*it); + + if (m->item().s_voidp == 0) { + *(m->var()) = Qnil; + break; + } + + VALUE obj = getPointerObject(p); + if (obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = o->smoke->idClass("TDEAction"); + o->ptr = p; + o->allocated = false; + obj = set_obj_info(className, o); + } + rb_ary_push(av, obj); + } + + if (m->cleanup()) + delete valuelist; + else + *(m->var()) = av; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_TDETraderOfferList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + } + break; + case Marshall::ToVALUE: + { + TDETrader::OfferList *offerList = (TDETrader::OfferList*)m->item().s_voidp; + if(!offerList) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + for(TDETrader::OfferList::Iterator it = offerList->begin(); + it != offerList->end(); + ++it) { + TDESharedPtr *ptr = new TDESharedPtr(*it); + KService * currentOffer = ptr->data(); + + VALUE obj = getPointerObject(currentOffer); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = m->smoke()->idClass("KService"); + o->ptr = currentOffer; + o->allocated = false; + obj = set_obj_info("KDE::Service", o); + } + rb_ary_push(av, obj); + } + + *(m->var()) = av; + + if(m->cleanup()) + delete offerList; + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_KURLList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE list = *(m->var()); + if (TYPE(list) != T_ARRAY) { + m->item().s_voidp = 0; + break; + } + int count = RARRAY_LEN(list); + KURL::List *kurllist = new KURL::List; + long i; + for(i = 0; i < count; i++) { + VALUE item = rb_ary_entry(list, i); + // TODO do type checking! + smokeruby_object *o = value_obj_info(item); + if(!o || !o->ptr) + continue; + void *ptr = o->ptr; + ptr = o->smoke->cast( + ptr, // pointer + o->classId, // from + o->smoke->idClass("KURL") // to + ); + kurllist->append((KURL&)*(KURL*)ptr); + } + + m->item().s_voidp = kurllist; + m->next(); + + rb_ary_clear(list); + int ix = m->smoke()->idClass("KURL"); + const char * className = m->smoke()->binding->className(ix); + for ( KURL::List::Iterator it = kurllist->begin(); + it != kurllist->end(); + ++it ) + { + void *p = new KURL(*it); + VALUE obj = getPointerObject(p); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = ix; + o->ptr = p; + o->allocated = true; + obj = set_obj_info(className, o); + } + rb_ary_push(list, obj); + } + + if(m->cleanup()) { + delete kurllist; + } + } + break; + case Marshall::ToVALUE: + { + KURL::List *kurllist = (KURL::List*)m->item().s_voidp; + if(!kurllist) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + int ix = m->smoke()->idClass("KURL"); + const char * className = m->smoke()->binding->className(ix); + + for(KURL::List::Iterator it = kurllist->begin(); + it != kurllist->end(); + ++it) { + void *p = new KURL(*it); + + VALUE obj = getPointerObject(p); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = ix; + o->ptr = p; + o->allocated = true; + obj = set_obj_info(className, o); + } + rb_ary_push(av, obj); + } + + *(m->var()) = av; + + if(m->cleanup()) { + delete kurllist; + } + } + break; + default: + m->unsupported(); + break; + } +} + +void marshall_UDSEntryList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE list = *(m->var()); + if (TYPE(list) != T_ARRAY) { + m->item().s_voidp = 0; + break; + } + + TDEIO::UDSEntryList *cpplist = new TDEIO::UDSEntryList; + + for(long i = 0; i < RARRAY_LEN(list); i++) { + VALUE item = rb_ary_entry(list, i); + TDEIO::UDSEntry *cppsublist = new TDEIO::UDSEntry; + + for (int j = 0; j < RARRAY_LEN(item); j++) { + VALUE subitem = rb_ary_entry(item, j); + smokeruby_object *o = value_obj_info(subitem); + if(!o || !o->ptr) + continue; + void *ptr = o->ptr; + ptr = o->smoke->cast(ptr, o->classId, o->smoke->idClass("TDEIO::UDSAtom")); + cppsublist->append(*(TDEIO::UDSAtom*)ptr); + } + + cpplist->append(*cppsublist); + } + + m->item().s_voidp = cpplist; + m->next(); + } + break; + case Marshall::ToVALUE: + { + TDEIO::UDSEntryList *valuelist = (TDEIO::UDSEntryList*)m->item().s_voidp; + if (!valuelist) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + int ix = m->smoke()->idClass("TDEIO::UDSAtom"); + + for ( TDEIO::UDSEntryList::Iterator it = valuelist->begin(); + it != valuelist->end(); + ++it ) + { + TDEIO::UDSEntry * udsentry = &(*it); + VALUE subav = rb_ary_new(); + + for ( TDEIO::UDSEntry::Iterator it = udsentry->begin(); + it != udsentry->end(); + ++it ) + { + void * p = &(*it); + VALUE obj = getPointerObject(p); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = ix; + o->ptr = p; + o->allocated = false; + obj = set_obj_info("TDEIO::UDSAtom", o); + } + + rb_ary_push(subav, obj); + } + + rb_ary_push(av, subav); + } + + *(m->var()) = av; + } + break; + default: + m->unsupported(); + break; + } +} + + +// Some time saving magic from Alex Kellett here.. +template +void marshall_ItemList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE list = *(m->var()); + if (TYPE(list) != T_ARRAY) { + m->item().s_voidp = 0; + break; + } + int count = RARRAY_LEN(list); + ItemList *cpplist = new ItemList; + long i; + for(i = 0; i < count; i++) { + VALUE item = rb_ary_entry(list, i); + // TODO do type checking! + smokeruby_object *o = value_obj_info(item); + if(!o || !o->ptr) + continue; + void *ptr = o->ptr; + ptr = o->smoke->cast( + ptr, // pointer + o->classId, // from + o->smoke->idClass(ItemSTR) // to + ); + cpplist->append((Item*)ptr); + } + + m->item().s_voidp = cpplist; + m->next(); + + if(m->cleanup()) { + rb_ary_clear(list); + for( Item * it = cpplist->first(); + it != 0; + it = cpplist->next()) { + VALUE obj = getPointerObject((void*)it); + rb_ary_push(list, obj); + } + delete cpplist; + } + } + break; + case Marshall::ToVALUE: + { + ItemList *valuelist = (ItemList*)m->item().s_voidp; + if(!valuelist) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + int ix = m->smoke()->idClass(ItemSTR); + const char * className = m->smoke()->binding->className(ix); + + for(Item * it = valuelist->first(); + it != 0; + it = valuelist->next()) { + void *p = it; + + if(m->item().s_voidp == 0) { + *(m->var()) = Qnil; + break; + } + + VALUE obj = getPointerObject(p); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = o->smoke->idClass(ItemSTR); + o->ptr = p; + o->allocated = false; + obj = set_obj_info(className, o); + } + rb_ary_push(av, obj); + } + + if(m->cleanup()) + delete valuelist; + else + *(m->var()) = av; + } + break; + default: + m->unsupported(); + break; + } +} + +#define DEF_LIST_MARSHALLER(ListIdent,ItemList,Item) namespace { char ListIdent##STR[] = #Item; }; \ + Marshall::HandlerFn marshall_##ListIdent = marshall_ItemList; + +DEF_LIST_MARSHALLER( KFileItemList, TQPtrList, KFileItem ) +DEF_LIST_MARSHALLER( TDEMainWindowList, TQPtrList, TDEMainWindow ) +DEF_LIST_MARSHALLER( TDEActionList, TQPtrList, TDEAction ) +DEF_LIST_MARSHALLER( DCOPObjectList, TQPtrList, DCOPObject ) +DEF_LIST_MARSHALLER( KDockWidgetList, TQPtrList, KDockWidget ) +DEF_LIST_MARSHALLER( KFileTreeBranch, TQPtrList, KFileTreeBranch ) +DEF_LIST_MARSHALLER( KFileTreeViewItem, TQPtrList, KFileTreeViewItem ) +DEF_LIST_MARSHALLER( KPartList, TQPtrList, KParts::Part ) +DEF_LIST_MARSHALLER( KPartPluginList, TQPtrList, KParts::Plugin ) +DEF_LIST_MARSHALLER( KPartReadOnlyPartList, TQPtrList, KParts::ReadOnlyPart ) +DEF_LIST_MARSHALLER( KServiceTypeProfileList, TQPtrList, KServiceTypeProfile ) + +template +void marshall_ValueItemList(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE list = *(m->var()); + if (TYPE(list) != T_ARRAY) { + m->item().s_voidp = 0; + break; + } + int count = RARRAY_LEN(list); + ItemList *cpplist = new ItemList; + long i; + for(i = 0; i < count; i++) { + VALUE item = rb_ary_entry(list, i); + // TODO do type checking! + smokeruby_object *o = value_obj_info(item); + if(!o || !o->ptr) + continue; + void *ptr = o->ptr; + ptr = o->smoke->cast( + ptr, // pointer + o->classId, // from + o->smoke->idClass(ItemSTR) // to + ); + cpplist->append(*(Item*)ptr); + } + + m->item().s_voidp = cpplist; + m->next(); + + if(m->cleanup()) { + rb_ary_clear(list); + for(ItemListIterator it = cpplist->begin(); + it != cpplist->end(); + ++it) { + VALUE obj = getPointerObject((void*)&(*it)); + rb_ary_push(list, obj); + } + delete cpplist; + } + } + break; + case Marshall::ToVALUE: + { + ItemList *valuelist = (ItemList*)m->item().s_voidp; + if(!valuelist) { + *(m->var()) = Qnil; + break; + } + + VALUE av = rb_ary_new(); + + int ix = m->smoke()->idClass(ItemSTR); + const char * className = m->smoke()->binding->className(ix); + + for(ItemListIterator it = valuelist->begin(); + it != valuelist->end(); + ++it) { + void *p = &(*it); + + if(m->item().s_voidp == 0) { + *(m->var()) = Qnil; + break; + } + + VALUE obj = getPointerObject(p); + if(obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->smoke = m->smoke(); + o->classId = o->smoke->idClass(ItemSTR); + o->ptr = p; + o->allocated = false; + obj = set_obj_info(className, o); + } + rb_ary_push(av, obj); + } + + if(m->cleanup()) + delete valuelist; + else + *(m->var()) = av; + } + break; + default: + m->unsupported(); + break; + } +} + +#define DEF_VALUELIST_MARSHALLER(ListIdent,ItemList,Item,Itr) namespace { char ListIdent##STR[] = #Item; }; \ + Marshall::HandlerFn marshall_##ListIdent = marshall_ValueItemList; + +#if TDE_VERSION >= 0x030200 +DEF_VALUELIST_MARSHALLER( ChoicesList, TQValueList, TDEConfigSkeleton::ItemEnum::Choice, TQValueList::Iterator ) +#endif +DEF_VALUELIST_MARSHALLER( TDEAboutPersonList, TQValueList, TDEAboutPerson, TQValueList::Iterator ) +DEF_VALUELIST_MARSHALLER( TDEAboutTranslatorList, TQValueList, TDEAboutTranslator, TQValueList::Iterator ) +DEF_VALUELIST_MARSHALLER( KIOCopyInfoList, TQValueList, TDEIO::CopyInfo, TQValueList::Iterator ) +DEF_VALUELIST_MARSHALLER( KServiceOfferList, TQValueList, KServiceOffer, TQValueList::Iterator ) +DEF_VALUELIST_MARSHALLER( UDSEntry, TQValueList, TDEIO::UDSAtom, TQValueList::Iterator ) + +template +void marshall_Map(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE hash = *(m->var()); + if (TYPE(hash) != T_HASH) { + m->item().s_voidp = 0; + break; + } + + TQMap * map = new TQMap; + + // Convert the ruby hash to an array of key/value arrays + VALUE temp = rb_funcall(hash, rb_intern("to_a"), 0); + + for (long i = 0; i < RARRAY_LEN(temp); i++) { + VALUE key = rb_ary_entry(rb_ary_entry(temp, i), 0); + VALUE value = rb_ary_entry(rb_ary_entry(temp, i), 1); + + smokeruby_object *o = value_obj_info(key); + if( !o || !o->ptr) + continue; + void * key_ptr = o->ptr; + key_ptr = o->smoke->cast(key_ptr, o->classId, o->smoke->idClass(KeySTR)); + + o = value_obj_info(value); + if( !o || !o->ptr) + continue; + void * val_ptr = o->ptr; + val_ptr = o->smoke->cast(val_ptr, o->classId, o->smoke->idClass(ValueSTR)); + + (*map)[(Key)*(Key*)key_ptr] = (Value)*(Value*)val_ptr; + } + + m->item().s_voidp = map; + m->next(); + + if(m->cleanup()) + delete map; + } + break; + case Marshall::ToVALUE: + { + TQMap *map = (TQMap*)m->item().s_voidp; + if(!map) { + *(m->var()) = Qnil; + break; + } + + VALUE hv = rb_hash_new(); + + int key_ix = m->smoke()->idClass(KeySTR); + const char * key_className = m->smoke()->binding->className(key_ix); + + int val_ix = m->smoke()->idClass(ValueSTR); + const char * val_className = m->smoke()->binding->className(val_ix); + + ItemMapIterator it; + for (it = map->begin(); it != map->end(); ++it) { + void *key_p = new Key(it.key()); + VALUE key_obj = getPointerObject(key_p); + smokeruby_object * o; + + if (key_obj == Qnil) { + o = ALLOC(smokeruby_object); + o->classId = m->smoke()->idClass(KeySTR); + o->smoke = m->smoke(); + o->ptr = key_p; + o->allocated = true; + key_obj = set_obj_info(key_className, o); + } + + void *val_p = new Value(it.data()); + VALUE value_obj = getPointerObject(val_p); + + if (value_obj == Qnil) { + o = ALLOC(smokeruby_object); + o->classId = m->smoke()->idClass(ValueSTR); + o->smoke = m->smoke(); + o->ptr = val_p; + o->allocated = true; + value_obj = set_obj_info(val_className, o); + } + + rb_hash_aset(hv, key_obj, value_obj); + } + + *(m->var()) = hv; + m->next(); + + if(m->cleanup()) + delete map; + } + break; + default: + m->unsupported(); + break; + } +} + +#define DEF_MAP_MARSHALLER(MapIdent,Key,Value) namespace { char KeyIdent##STR[] = #Key; char ValueIdent##STR[] = #Value; }; \ + Marshall::HandlerFn marshall_##MapIdent = marshall_Map::Iterator,KeyIdent##STR, ValueIdent##STR>; + +DEF_MAP_MARSHALLER( TQMapKEntryKeyKEntry, KEntryKey, KEntry ) + +void marshall_TQMapTQCStringDCOPRef(Marshall *m) { + switch(m->action()) { + case Marshall::FromVALUE: + { + VALUE hash = *(m->var()); + if (TYPE(hash) != T_HASH) { + m->item().s_voidp = 0; + break; + } + + TQMap * map = new TQMap; + + // Convert the ruby hash to an array of key/value arrays + VALUE temp = rb_funcall(hash, rb_intern("to_a"), 0); + + for (long i = 0; i < RARRAY_LEN(temp); i++) { + VALUE key = rb_ary_entry(rb_ary_entry(temp, i), 0); + VALUE value = rb_ary_entry(rb_ary_entry(temp, i), 1); + + smokeruby_object *o = value_obj_info(value); + if( !o || !o->ptr) + continue; + void * ptr = o->ptr; + ptr = o->smoke->cast(ptr, o->classId, o->smoke->idClass("DCOPRef")); + + (*map)[TQCString(StringValuePtr(key))] = (DCOPRef)*(DCOPRef*)ptr; + } + + m->item().s_voidp = map; + m->next(); + + if(m->cleanup()) + delete map; + } + break; + case Marshall::ToVALUE: + { + TQMap *map = (TQMap*)m->item().s_voidp; + if(!map) { + *(m->var()) = Qnil; + break; + } + + VALUE hv = rb_hash_new(); + + TQMap::Iterator it; + for (it = map->begin(); it != map->end(); ++it) { + void *p = new DCOPRef(it.data()); + VALUE obj = getPointerObject(p); + + if (obj == Qnil) { + smokeruby_object * o = ALLOC(smokeruby_object); + o->classId = m->smoke()->idClass("DCOPRef"); + o->smoke = m->smoke(); + o->ptr = p; + o->allocated = true; + obj = set_obj_info("KDE::DCOPRef", o); + } + + rb_hash_aset(hv, rb_str_new2((const char *) it.key()), obj); + } + + *(m->var()) = hv; + m->next(); + + if(m->cleanup()) + delete map; + } + break; + default: + m->unsupported(); + break; + } +} + +TypeHandler KDE_handlers[] = { + { "QCStringList", marshall_TQCStringList }, + { "TDECmdLineOptions*", marshall_TDECmdLineOptions }, + { "TDEActionPtrList", marshall_TDEActionList }, + { "TQPtrList", marshall_TDEActionList }, + { "TQPtrList&", marshall_TDEActionList }, + { "KMimeType::List", marshall_KMimeTypeList }, + { "KMimeType::Ptr", marshall_KMimeTypePtr }, + { "KService::Ptr", marshall_KServicePtr }, + { "KService::List", marshall_KServiceList }, + { "KServiceGroup::List", marshall_KServiceGroupList }, + { "KServiceGroup::Ptr", marshall_KServiceGroupPtr }, +#if TDE_VERSION >= 0x030200 + { "KMountPoint::List", marshall_KMountPointList }, + { "KPluginInfo::List", marshall_KPluginInfoList }, + { "TQValueList", marshall_ChoicesList }, + { "TQValueList&", marshall_ChoicesList }, +#endif + { "KServiceType::List", marshall_KServiceTypeList }, + { "TDETrader::OfferList", marshall_TDETraderOfferList }, + { "KURL::List", marshall_KURLList }, + { "KURL::List&", marshall_KURLList }, + { "KFileItemList", marshall_KFileItemList }, + { "KFileItemList*", marshall_KFileItemList }, + { "TQPtrList*", marshall_TDEMainWindowList }, + { "TQPtrList", marshall_DCOPObjectList }, + { "TQPtrList&", marshall_KDockWidgetList }, + { "TQPtrList*", marshall_KDockWidgetList }, + { "KFileTreeBranchList&", marshall_KFileTreeBranch }, + { "KFileTreeViewItemList&", marshall_KFileTreeViewItem }, + { "TQPtrList*", marshall_KPartList }, + { "TQPtrList", marshall_KPartPluginList }, + { "TQPtrList", marshall_KPartReadOnlyPartList }, + { "TQPtrList&", marshall_KServiceTypeProfileList }, + { "TQValueList", marshall_TDEActionPtrList }, + { "TDEActionPtrList", marshall_TDEActionPtrList }, + { "TQValueList", marshall_TDEAboutPersonList }, + { "TQValueList", marshall_TDEAboutTranslatorList }, + { "TQValueList&", marshall_KIOCopyInfoList }, + { "TDEIO::UDSEntry&", marshall_UDSEntry }, + { "TDEIO::UDSEntryList&", marshall_UDSEntryList }, + { "KServiceTypeProfile::OfferList", marshall_KServiceOfferList }, + { "KEntryMap", marshall_TQMapKEntryKeyKEntry }, + { "KEntryMap&", marshall_TQMapKEntryKeyKEntry }, + { "KEntryMap*", marshall_TQMapKEntryKeyKEntry }, + { "TQMap", marshall_TQMapTQCStringDCOPRef }, + { "TQValueList&", marshall_WIdList }, + { "TQValueList", marshall_WIdList }, + { 0, 0 } +}; -- cgit v1.2.1