[Kde-bindings] KDE/kdebindings

Richard Dale Richard_Dale at tipitina.demon.co.uk
Sat Apr 5 10:31:01 UTC 2008


SVN commit 793805 by rdale:

* Added some type() methods for Plasma classes so that they are called, rather
  than the Ruby Object#type method.
* Added a marshaller for the ugly Plasma::PackageStructure::Ptr type
* Added rb_protect() wrappers around virtual method callbacks and
  slot invocations. When there is a Ruby exception, the app no
  longer terminates which is useful for Plasma applets.

CCMAIL: kde-bindings at kde.org


 M  +5 -0      ruby/plasma/ChangeLog  
 M  +1 -0      ruby/plasma/src/CMakeLists.txt  
 M  +78 -1     ruby/plasma/src/kdehandlers.cpp  
 A             ruby/plasma/src/lib (directory)  
 A             ruby/plasma/src/lib/CMakeLists.txt  
 A             ruby/plasma/src/lib/KDE (directory)  
 A             ruby/plasma/src/lib/KDE/CMakeLists.txt  
 A             ruby/plasma/src/lib/KDE/plasma.rb  
 M  +1 -21     ruby/plasma/src/plasma.cpp  
 M  +6 -0      ruby/qtruby/ChangeLog  
 M  +47 -5     ruby/qtruby/src/marshall_types.cpp  
 M  +17 -0     smoke/plasma/CMakeLists.txt  
 M  +1 -0      smoke/plasma/header_list  


--- trunk/KDE/kdebindings/ruby/plasma/ChangeLog #793804:793805
@@ -0,0 +1,5 @@
+2008-04-05  Richard Dale  <richard.j.dale at gmail.com>
+
+	* Added some type() methods for Plasma classes so that they are called, rather
+	  than the Ruby Object#type method.
+	* Added a marshaller for the ugly Plasma::PackageStructure::Ptr type
\ No newline at end of file
--- trunk/KDE/kdebindings/ruby/plasma/src/CMakeLists.txt #793804:793805
@@ -1,3 +1,4 @@
+add_subdirectory( lib )
 
 include_directories( ${CMAKE_SOURCE_DIR}/smoke ${RUBY_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/ruby/qtruby/src ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
 
--- trunk/KDE/kdebindings/ruby/plasma/src/kdehandlers.cpp #793804:793805
@@ -26,7 +26,6 @@
 #include <kmainwindow.h>
 #include <kfile.h>
 #include <kfileitem.h>
-#include <kfileview.h>
 #include <kurl.h>
 #include <kaction.h>
 #include <kfiletreebranch.h>
@@ -47,6 +46,7 @@
 #include <kuser.h>
 #include <ktoolbar.h>
 #include <kio/copyjob.h>
+#include <plasma/packagestructure.h>
 
 extern "C" {
 extern VALUE set_obj_info(const char * className, smokeruby_object * o);
@@ -235,6 +235,80 @@
 	}
 }
 
+void marshall_KSharedConfigPtr(Marshall *m) {
+	switch(m->action()) {
+	case Marshall::FromVALUE: 
+		{
+		}
+		break;
+	case Marshall::ToVALUE: 
+		{
+		KSharedPtr<KSharedConfig> *ptr = new KSharedPtr<KSharedConfig>(*(KSharedPtr<KSharedConfig>*)m->item().s_voidp);
+	    if(ptr == 0) {
+		*(m->var()) = Qnil;
+		break;
+	    }
+	    KConfig * config = ptr->data();
+	    
+		VALUE obj = getPointerObject(config);
+		if(obj == Qnil) {
+		    smokeruby_object  * o = ALLOC(smokeruby_object);
+		    o->smoke = m->smoke();
+		    o->classId = m->smoke()->idClass("KConfig");
+		    o->ptr = config;
+		    o->allocated = true;
+		    obj = set_obj_info("KDE::Config", o);
+		}
+
+	    *(m->var()) = obj;		
+	    
+		if(m->cleanup())
+		;
+		}
+		break;
+	default:
+		m->unsupported();
+		break;
+	}
+}
+
+void marshall_PackageStructurePtr(Marshall *m) {
+	switch(m->action()) {
+	case Marshall::FromVALUE: 
+		{
+		}
+		break;
+	case Marshall::ToVALUE: 
+		{
+		KSharedPtr<Plasma::PackageStructure> *ptr = new KSharedPtr<Plasma::PackageStructure>(*(KSharedPtr<Plasma::PackageStructure>*)m->item().s_voidp);
+	    if(ptr == 0) {
+		*(m->var()) = Qnil;
+		break;
+	    }
+	    Plasma::PackageStructure * package = ptr->data();
+	    
+		VALUE obj = getPointerObject(package);
+		if(obj == Qnil) {
+		    smokeruby_object  * o = ALLOC(smokeruby_object);
+		    o->smoke = m->smoke();
+		    o->classId = m->smoke()->idClass("Plasma::PackageStructure");
+		    o->ptr = package;
+		    o->allocated = true;
+		    obj = set_obj_info("Plasma::PackageStructure", o);
+		}
+
+	    *(m->var()) = obj;		
+	    
+		if(m->cleanup())
+		;
+		}
+		break;
+	default:
+		m->unsupported();
+		break;
+	}
+}
+
 void marshall_KServiceList(Marshall *m) {
 	switch(m->action()) {
 	case Marshall::FromVALUE: 
@@ -681,6 +755,9 @@
 */
 
 TypeHandler KDE_handlers[] = {
+    { "Plasma::PackageStructure::Ptr", marshall_PackageStructurePtr },
+    { "KSharedConfig::Ptr", marshall_KSharedConfigPtr },
+    { "KSharedConfigPtr", marshall_KSharedConfigPtr },
     { "KService::Ptr", marshall_KServicePtr },
     { "KService::List", marshall_KServiceList },
 
--- trunk/KDE/kdebindings/ruby/plasma/src/plasma.cpp #793804:793805
@@ -74,26 +74,6 @@
 	return instance;
 }
 
-KPluginFactory *
-rb_plasma_applet_factory(const char * factory)
-{
-printf("ENTER rb_plasma_applet_factory %s\n", factory);
-	VALUE factory_klass = rb_funcall(rb_cObject, rb_intern("const_get"), 1, rb_intern(factory));
-	if (factory_klass == Qnil) {
-printf("rb_plasma_applet_factory factory class nil\n");
-		return 0;
-	}
-
-	VALUE factory_value = rb_funcall(factory_klass, rb_intern("new"), 0);
-	if (factory_value == Qnil) {
-printf("rb_plasma_applet_factory factory value nil\n");
-		return 0;
-	}
-
-    smokeruby_object * o = value_obj_info(factory_value);
-	return (KPluginFactory *) o->ptr;
-}
-
 void
 Init_plasma_applet()
 {
@@ -115,7 +95,7 @@
 	
     kde_internal_module = rb_define_module_under(kde_module, "Internal");
 
-//	rb_require("KDE/plasma.rb");
+	rb_require("KDE/plasma.rb");
 }
 
 }
--- trunk/KDE/kdebindings/ruby/qtruby/ChangeLog #793804:793805
@@ -1,3 +1,9 @@
+2008-04-05  Richard Dale  <richard.j.dale at gmail.com>
+
+	* Added rb_protect() wrappers around virtual method callbacks and
+	  slot invocations. When there is a Ruby exception, the app no
+	  longer terminates which is useful for Plasma applets.
+
 2008-04-04  Richard Dale  <richard.j.dale at gmail.com>
 
 	* Ensure the class and module names in rbuic4 generated code
--- trunk/KDE/kdebindings/ruby/qtruby/src/marshall_types.cpp #793804:793805
@@ -17,7 +17,18 @@
  ***************************************************************************/
 
 #include "marshall_types.h"
+#include <rubysig.h>
 
+static VALUE funcall2_protect_id = Qnil;
+static int funcall2_protect_argc = 0;
+static VALUE * funcall2_protect_args = 0;
+
+static VALUE
+funcall2_protect(VALUE obj)
+{
+	return rb_funcall2(obj, funcall2_protect_id, funcall2_protect_argc, funcall2_protect_args);
+}
+
 void
 smokeStackToQtStack(Smoke::Stack stack, void ** o, int items, MocArgument* args)
 {
@@ -409,10 +420,25 @@
 	if (_called) return;
 	_called = true;
 
-	VALUE _retval = rb_funcall2(_obj, rb_intern(_smoke->methodNames[method().name]),
-		method().numArgs,	_sp );
+	funcall2_protect_id = rb_intern(_smoke->methodNames[method().name]);
+	funcall2_protect_argc = method().numArgs;
+	funcall2_protect_args = _sp;
+	int state = 0;
 
-	VirtualMethodReturnValue r(_smoke, _method, _stack, _retval);
+	// Sebastian Sauer suggested setting rb_thread_critical to fix the plasma
+	// problems with applets occasionally throwing exceptions. It doesn't seem
+	// to make any difference though, and so comment the code out for now.
+	//int critical_save = rb_thread_critical;
+	//rb_thread_critical = Qtrue;
+
+	VALUE _retval = rb_protect(funcall2_protect, _obj, &state);
+	if (state != 0) {
+		rb_backtrace();
+	} else {
+		VirtualMethodReturnValue r(_smoke, _method, _stack, _retval);
+	}
+
+	//rb_thread_critical = critical_save;
 }
 
 bool 
@@ -630,10 +656,26 @@
 {
 	if (_called) return;
 	_called = true;
-	VALUE result = rb_funcall2(_obj, _slotname, _items - 1, _sp);
-	if (_args[0].argType != xmoc_void) {
+
+	funcall2_protect_id = _slotname;
+	funcall2_protect_argc = _items - 1;
+	funcall2_protect_args = _sp;
+	int state = 0;
+
+	// Sebastian Sauer suggested setting rb_thread_critical to fix the plasma
+	// problems with applets occasionally throwing exceptions. It doesn't seem
+	// to make any difference though, and so comment the code out for now.
+	//int critical_save = rb_thread_critical;
+	//rb_thread_critical = Qtrue;
+
+	VALUE result = rb_protect(funcall2_protect, _obj, &state);
+	if (state != 0) {
+		rb_backtrace();
+	} else if (_args[0].argType != xmoc_void) {
 		SlotReturnValue r(_o, &result, _args);
 	}
+
+	//rb_thread_critical = critical_save;
 }
 
 void 
--- trunk/KDE/kdebindings/smoke/plasma/CMakeLists.txt #793804:793805
@@ -84,6 +84,22 @@
 # Needed to make QSqlRelationalDelegate compile
 ADD_DEFINITIONS (-DQT_GUI_LIB)
 
+INCLUDE(${QT_USE_FILE})
+# At this point, QT_LIBRARIES will contain a list of the found Qt Libs
+# and QT_INCLUDES contains the directories of the found includes
+
+FOREACH(filename ${QT_INCLUDES})
+    set(all_includes "-I${filename} ${all_includes}")
+ENDFOREACH(filename)
+
+FOREACH(incname ${QT_INCLUDES})
+    SET(qt_incs "'${incname}', ${qt_incs}")
+ENDFOREACH(incname)
+
+FOREACH(libname ${QT_LIBRARIES})
+    set(all_libs "${libname} ${all_libs}")
+ENDFOREACH(libname)
+
 kde4_add_library(smokeplasma SHARED ${smokeplasma_LIB_SRCS})
 
 target_link_libraries(smokeplasma 
@@ -93,6 +109,7 @@
     ${QT_QTXML_LIBRARY} 
     ${QT_QTSVG_LIBRARY} 
     ${QT_QTUITOOLS_LIBRARY} 
+    ${QT_QTWEBKIT_LIBRARY} 
     ${QT_QT3SUPPORT_LIBRARY} 
     ${KDE4_KDECORE_LIBS} 
     ${KDE4_KDEUI_LIBS}
--- trunk/KDE/kdebindings/smoke/plasma/header_list #793804:793805
@@ -228,6 +228,7 @@
 qstylefactory.h
 qstyle.h
 qstylepainter.h
+qstyleoption.h
 qstyleplugin.h
 qsyntaxhighlighter.h
 qsystemtrayicon.h



More information about the Kde-bindings mailing list