[Kde-bindings] branches/KDE/4.2/kdebindings/ruby

Richard Dale Richard_Dale at tipitina.demon.co.uk
Wed Feb 25 13:30:35 UTC 2009


SVN commit 931553 by rdale:

* Backport the port of QtRuby to Ruby 1.9.1 to the release branch

CCMAIL: kde-bindings at kde.org


 M  +3 -0      korundum/ChangeLog  
 M  +12 -12    korundum/examples/kludgeror.rb  
 M  +4 -0      korundum/src/CMakeLists.txt  
 M  +3 -3      korundum/src/Korundum.cpp  
 M  +5 -0      korundum/src/krubyapplication.cpp  
 M  +8 -4      korundum/src/krubypluginfactory.cpp  
 M  +1 -1      korundum/src/lib/KDE/korundum4.rb  
 M  +3 -0      plasma/ChangeLog  
 M  +1 -1      plasma/src/plasmahandlers.cpp  
 M  +24 -0     qtruby/ChangeLog  
 M  +4 -0      qtruby/src/CMakeLists.txt  
 M  +46 -10    qtruby/src/handlers.cpp  
 M  +2 -2      qtruby/src/lib/Qt/qtruby4.rb  
 M  +0 -1      qtruby/src/marshall_types.cpp  
 M  +5 -0      qtruby/src/qtruby.cpp  
 M  +0 -48     qtruby/src/smokeruby.h  


--- branches/KDE/4.2/kdebindings/ruby/korundum/ChangeLog #931552:931553
@@ -1,3 +1,6 @@
+2009-02-02  Richard Dale  <richard.j.dale at gmail.com>
+	* Make Korundum build with Ruby 1.9
+
 2009-01-13  Richard Dale  <richard.j.dale at gmail.com>
 	* The enum KDE::File::File was conflicting with the Ruby class 'File' and
 	  not working properly. So special case it and make it a constant. Thanks
--- branches/KDE/4.2/kdebindings/ruby/korundum/examples/kludgeror.rb #931552:931553
@@ -4,20 +4,20 @@
 # -- gg.
 # AK - ported to ruby
 
-require 'Korundum'
+require 'korundum4'
 
-opt =     [ [ "+[url]",      "An URL to open at startup.",         ""            ],
-            [ "z",           "A dummy binary option.",             ""            ],
-            [ "baz <file>",  "A long option with arg.",            ""            ],
-            [ "boz <file>",  "Same as above with default value",   "default.txt" ],
-          ]            
+# Qt::Internal::setDebug Qt::QtDebugChannel::QTDB_ALL
+# Qt.debug_level = Qt::DebugLevel::High
 
-Qt::Internal::setDebug Qt::QtDebugChannel::QTDB_ALL
-Qt.debug_level = Qt::DebugLevel::High
+aboutData = KDE::AboutData.new("kludgeror", "Kludgeror", KDE.ki18n("A basic web browser"), "0.1")
+KDE::CmdLineArgs.init(ARGV, aboutData)
+cmdlineoptions = KDE::CmdLineOptions.new()
+cmdlineoptions.add("+[url]", KDE.ki18n("An URL to open at startup."))
+cmdlineoptions.add("z", KDE.ki18n("A dummy binary option."))
+cmdlineoptions.add("baz <file>", KDE.ki18n("A long option with arg."))
+cmdlineoptions.add("boz <file>", KDE.ki18n("Same as above with default value."), "default.txt")
+KDE::CmdLineArgs.addCmdLineOptions(cmdlineoptions)
 
-about = KDE::AboutData.new("kludgeror", "Kludgeror", "0.1", "A basic web browser")
-KDE::CmdLineArgs::init(ARGV.length + 1, [$0] + ARGV, about)
-KDE::CmdLineArgs::addCmdLineOptions opt
 args = KDE::CmdLineArgs::parsedArgs
 
 a = KDE::Application.new # BUG, application shouldn't be needed at the top, lets fix this...
@@ -63,7 +63,7 @@
 ERASE_B = 323
 BACK_B  = 324
 
-url = (args.count > 1) ? args.url(0) : KDE::URL.new("http://loki:8080/xml/index.xml")
+url = (args.count > 1) ? args.url(0) : KDE::Url.new("http://loki:8080/xml/index.xml")
 
 puts "Dummy z option activated." if args.isSet "z"
 puts "Dummy baz option has value: #{args.getOption "baz"}" if args.isSet "baz"
--- branches/KDE/4.2/kdebindings/ruby/korundum/src/CMakeLists.txt #931552:931553
@@ -5,6 +5,10 @@
     ADD_DEFINITIONS (-DQT_QTDBUS)
 ENDIF(QT_QTDBUS_FOUND)
 
+if(RUBY_VERSION)
+    ADD_DEFINITIONS (-DRUBY_VERSION=0x${RUBY_VERSION_NUMBER})
+ENDIF(RUBY_VERSION)
+
 include_directories( ${CMAKE_SOURCE_DIR}/smoke ${RUBY_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/ruby/qtruby/src ${KDE4_INCLUDE_DIR} ${QT_INCLUDES}  )
 
 set(korundum_LIB_SRCS 
--- branches/KDE/4.2/kdebindings/ruby/korundum/src/Korundum.cpp #931552:931553
@@ -112,7 +112,7 @@
 	}
 	
 	if (TYPE(argv[0]) != T_DATA) {
-		rb_raise(rb_eArgError, "wrong argument type, expected KDE::ConfigSkeletonItem\n", argc);
+		rb_raise(rb_eArgError, "wrong argument type, expected KDE::ConfigSkeletonItem\n");
 	}
 	
 	smokeruby_object *c = value_obj_info(argv[0]);
@@ -254,7 +254,7 @@
 
 	QStringList * reference = new QStringList();
     VALUE list = argv[2];
-	int count = RARRAY(list)->len;
+	int count = RARRAY_LEN(list);
 	for(int i = 0; i < count; i++) {
 		VALUE item = rb_ary_entry(list, i);
 		reference->append(QString::fromLatin1(StringValuePtr(item)));
@@ -269,7 +269,7 @@
 	} else if (argc == 4) {
 		QStringList defaultList;
 		list = argv[3];
-		int count = RARRAY(list)->len;
+		int count = RARRAY_LEN(list);
 		for(int i = 0; i < count; i++) {
 			VALUE item = rb_ary_entry(list, i);
 			defaultList.append(QString::fromLatin1(StringValuePtr(item)));
--- branches/KDE/4.2/kdebindings/ruby/korundum/src/krubyapplication.cpp #931552:931553
@@ -65,7 +65,12 @@
     ruby_init();
     ruby_init_loadpath();
     ruby_incpush(QFile::encodeName(program.path()));
+#if RUBY_VERSION < 0x10900
     ruby_options(argc+1, rubyargs); 
     ruby_script(QFile::encodeName(program.fileName()));
     ruby_run();
+#else
+    ruby_script(QFile::encodeName(program.fileName()));
+    ruby_run_node(ruby_options(argc+1, rubyargs));
+#endif
 }
--- branches/KDE/4.2/kdebindings/ruby/korundum/src/krubypluginfactory.cpp #931552:931553
@@ -54,7 +54,7 @@
 {
     VALUE info = rb_gv_get("$!");
     VALUE bt = rb_funcall(info, rb_intern("backtrace"), 0);
-    VALUE message = RARRAY(bt)->ptr[0];
+    VALUE message = RARRAY_PTR(bt)[0];
 
     QString errormessage = QString("%1: %2 (%3)")
                             .arg( STR2CSTR(message) )
@@ -63,9 +63,9 @@
     fprintf(stderr, "%s\n", errormessage.toLatin1().constData());
 
     QString tracemessage;
-    for(int i = 1; i < RARRAY(bt)->len; ++i) {
-        if( TYPE(RARRAY(bt)->ptr[i]) == T_STRING ) {
-            QString s = QString("%1\n").arg( STR2CSTR(RARRAY(bt)->ptr[i]) );
+    for(int i = 1; i < RARRAY_LEN(bt); ++i) {
+        if( TYPE(RARRAY_PTR(bt)[i]) == T_STRING ) {
+            QString s = QString("%1\n").arg( STR2CSTR(RARRAY_PTR(bt)[i]) );
             Q_ASSERT( ! s.isNull() );
             tracemessage += s;
             fprintf(stderr, "\t%s", s.toLatin1().constData());
@@ -135,7 +135,11 @@
     RUBY_INIT_STACK
 #endif
 
+#if RUBY_VERSION < 0x10900
     bool firstTime = (rb_load_path == 0);
+#else
+    bool firstTime = true;
+#endif
 
     ruby_init();
     ruby_script(QFile::encodeName(program.fileName()));
--- branches/KDE/4.2/kdebindings/ruby/korundum/src/lib/KDE/korundum4.rb #931552:931553
@@ -324,7 +324,7 @@
 	end
 
 	class File < Qt::Base
-		File = 1
+		File = Qt::Enum.new(1, "KFile::Mode")
 	end
 
 	class FileItem < Qt::Base
--- branches/KDE/4.2/kdebindings/ruby/plasma/ChangeLog #931552:931553
@@ -1,3 +1,6 @@
+2009-02-02  Richard Dale  <richard.j.dale at gmail.com>
+	* Make the plasma extension build with Ruby 1.9
+
 2008-10-30  Richard Dale  <richard.j.dale at gmail.com>
 * Separated the script engine plugins from the plasma ruby extension and moved
   the script engine code to kdebase with the other script engines
--- branches/KDE/4.2/kdebindings/ruby/plasma/src/plasmahandlers.cpp #931552:931553
@@ -81,7 +81,7 @@
 		// 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(temp)->len; i++) {
+		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);
 			
--- branches/KDE/4.2/kdebindings/ruby/qtruby/ChangeLog #931552:931553
@@ -1,3 +1,27 @@
+2009-02-07  Richard Dale  <richard.j.dale at gmail.com>
+	* Add a Qt::dynamic_cast method as a synonym with a less clunky name for 
+	  Qt::Internal.cast_object_to
+
+2009-02-04  Richard Dale  <richard.j.dale at gmail.com>
+	* In Ruby 1.9.1 the arity of a block with no arguments is 0, whereas in 
+	  Ruby 1.8.x it is -1. This meant that blocks passed to QtRuby 
+	  constructors with no args weren't working with Ruby 1.9.1
+
+2009-02-02  Richard Dale  <richard.j.dale at gmail.com>
+	* Set up a RUBY_VERSION macro to use to test for whether QtRuby is being 
+	  built for Ruby 1.9 or not. Add patches from Mr Napalm for building with
+	  Ruby 1.9, for the new 'per string' encoding. Also add conditional code
+	  for whether to use the new rb_frame_callee() function or the old
+	  rb_frame_last_func() one.
+
+2009-02-01  Richard Dale  <richard.j.dale at gmail.com>
+	* The construct_copy() function was using the full classname of the class
+	  to construct which meant that it didn't work with classnames containing
+	  '::' scope operators. So strip out the scope part of the classname to
+	  create the consructor name.
+	* Make Qt::Internal#try_initialize catch a ':newqt' symbol rather than a 
+	  string.
+
 2009-01-14  Richard Dale  <richard.j.dale at gmail.com>
 	* For the enum values whose names clashed with Ruby classes, make them
 	  Qt::Enums instead of just Fixnums
--- branches/KDE/4.2/kdebindings/ruby/qtruby/src/CMakeLists.txt #931552:931553
@@ -9,6 +9,10 @@
     ADD_DEFINITIONS (-DQT_QWT)
 ENDIF(QWT_FOUND)
 
+if(RUBY_VERSION)
+    ADD_DEFINITIONS (-DRUBY_VERSION=0x${RUBY_VERSION_NUMBER})
+ENDIF(RUBY_VERSION)
+
 include_directories( ${CMAKE_SOURCE_DIR}/smoke ${RUBY_INCLUDE_PATH} )
 INCLUDE_DIRECTORIES (${QT_INCLUDES})
 
--- branches/KDE/4.2/kdebindings/ruby/qtruby/src/handlers.cpp #931552:931553
@@ -699,11 +699,16 @@
 {
     const char *className = o->smoke->className(o->classId);
     int classNameLen = strlen(className);
-    char *ccSig = new char[classNameLen + 2];       // copy constructor signature
-    strcpy(ccSig, className);
-    strcat(ccSig, "#");
+
+    // copy constructor signature
+    QByteArray ccSig(className);
+    int pos = ccSig.lastIndexOf("::");
+    if (pos != -1) {
+        ccSig = ccSig.mid(pos + strlen("::"));
+    }
+    ccSig.append("#");
+
     Smoke::ModuleIndex ccId = o->smoke->findMethodName(className, ccSig);
-    delete[] ccSig;
 
     char *ccArg = new char[classNameLen + 8];
     sprintf(ccArg, "const %s&", className);
@@ -886,9 +891,11 @@
 	}
 }
 
-static const char * KCODE = 0;
 static QTextCodec *codec = 0;
 
+#if RUBY_VERSION < 0x10900
+static const char * KCODE = 0;
+
 static void 
 init_codec() {
 	VALUE temp = rb_gv_get("$KCODE");
@@ -918,11 +925,6 @@
 	return new QString(QString::fromLocal8Bit(StringValuePtr(rstring), RSTRING_LEN(rstring)));
 }
 
-QByteArray*
-qbytearrayFromRString(VALUE rstring) {
-  return new QByteArray(StringValuePtr(rstring), RSTRING_LEN(rstring));
-}
-
 VALUE 
 rstringFromQString(QString * s) {
 	if (KCODE == 0) {
@@ -941,6 +943,40 @@
 		return rb_str_new2(s->toLocal8Bit());
 }
 
+#else
+
+QString* 
+qstringFromRString(VALUE rstring) {
+	VALUE encoding = rb_funcall(rstring, rb_intern("encoding"), 0);
+	encoding = rb_funcall(encoding, rb_intern("to_s"), 0);
+	const char * enc_s = RSTRING_PTR(encoding);
+
+	if (qstrcmp(enc_s, "UTF8") == 0) {
+		return new QString(QString::fromUtf8(StringValuePtr(rstring), RSTRING_LEN(rstring)));
+	} else if (qstrcmp(enc_s, "EUC-JP") == 0) {
+		codec = QTextCodec::codecForName("eucJP");
+		return new QString(codec->toUnicode(StringValuePtr(rstring)));
+	} else if (qstrcmp(enc_s, "Shift-JIS") == 0) {
+		codec = QTextCodec::codecForName("Shift-JIS");
+		return new QString(codec->toUnicode(StringValuePtr(rstring)));
+	} else if(qstrcmp(enc_s, "ISO-8859-1") == 0 || qstrcmp(enc_s, "US-ASCII") == 0) {
+		return new QString(QString::fromLatin1(StringValuePtr(rstring)));
+	}
+
+	return new QString(QString::fromLocal8Bit(StringValuePtr(rstring), RSTRING_LEN(rstring)));
+}
+
+VALUE 
+rstringFromQString(QString * s) {
+	return rb_str_new2(s->toUtf8());
+}
+#endif
+
+QByteArray*
+qbytearrayFromRString(VALUE rstring) {
+  return new QByteArray(StringValuePtr(rstring), RSTRING_LEN(rstring));
+}
+
 VALUE
 rstringFromQByteArray(QByteArray * s) {
   return rb_str_new(s->data(), s->size());
--- branches/KDE/4.2/kdebindings/ruby/qtruby/src/lib/Qt/qtruby4.rb #931552:931553
@@ -2525,7 +2525,7 @@
 		# wrapped in a new ruby variable of type T_DATA
 		def Internal.try_initialize(instance, *args)
 			initializer = instance.method(:initialize)
-			catch "newqt" do
+			catch :newqt do
 				initializer.call(*args)
 			end
 		end
@@ -2535,7 +2535,7 @@
 		# if no args were passed to the block. Or otherwise,
 		# run the block in the context of the arg.
 		def Internal.run_initializer_block(instance, block)
-			if block.arity == -1
+			if block.arity == -1 || block.arity == 0
 				instance.instance_eval(&block)
 			elsif block.arity == 1
 				block.call(instance)
--- branches/KDE/4.2/kdebindings/ruby/qtruby/src/marshall_types.cpp #931552:931553
@@ -17,7 +17,6 @@
  ***************************************************************************/
 
 #include "marshall_types.h"
-#include <rubysig.h>
 #include <smoke/qt_smoke.h>
 #include <QtDBus>
 
--- branches/KDE/4.2/kdebindings/ruby/qtruby/src/qtruby.cpp #931552:931553
@@ -1365,7 +1365,11 @@
 		return Qfalse;
 	}
 
+#if RUBY_VERSION >= 0x10900
+	QLatin1String signalname(rb_id2name(rb_frame_callee()));
+#else
 	QLatin1String signalname(rb_id2name(rb_frame_last_func()));
+#endif
 	VALUE metaObject_value = rb_funcall(qt_internal_module, rb_intern("getMetaObject"), 2, Qnil, self);
 
 	smokeruby_object *ometa = value_obj_info(metaObject_value);
@@ -2341,6 +2345,7 @@
     rb_define_module_function(qt_internal_module, "create_qt_class", (VALUE (*) (...)) create_qt_class, 2);
     rb_define_module_function(qt_internal_module, "create_qobject_class", (VALUE (*) (...)) create_qobject_class, 2);
     rb_define_module_function(qt_internal_module, "cast_object_to", (VALUE (*) (...)) cast_object_to, 2);
+    rb_define_module_function(qt_module, "dynamic_cast", (VALUE (*) (...)) cast_object_to, 2);
     rb_define_module_function(qt_internal_module, "kross2smoke", (VALUE (*) (...)) kross2smoke, 2);
     rb_define_module_function(qt_internal_module, "set_qtruby_embedded", (VALUE (*) (...)) set_qtruby_embedded_wrapped, 1);
     
--- branches/KDE/4.2/kdebindings/ruby/qtruby/src/smokeruby.h #931552:931553
@@ -86,54 +86,6 @@
 
 };
 
-class SmokeClass {
-    Smoke::Class *_c;
-    Smoke *_smoke;
-    Smoke::Index _id;
-public:
-    SmokeClass(const SmokeType &t) {
-	_smoke = t.smoke();
-	_id = t.classId();
-	_c = _smoke->classes + _id;
-    }
-    SmokeClass(Smoke *smoke, Smoke::Index id) : _smoke(smoke), _id(id) {
-	_c = _smoke->classes + _id;
-    }
-
-    Smoke *smoke() const { return _smoke; }
-    const Smoke::Class &c() const { return *_c; }
-    Smoke::Index classId() const { return _id; }
-    const char *className() const { return _c->className; }
-    Smoke::ClassFn classFn() const { return _c->classFn; }
-    Smoke::EnumFn enumFn() const { return _c->enumFn; }
-    bool operator ==(const SmokeClass &b) const {
-	const SmokeClass &a = *this;
-	if(a.className() == b.className()) return true;
-	if(a.className() && b.className() && qstrcmp(a.className(), b.className()) == 0)
-	    return true;
-	return false;
-    }
-    bool operator !=(const SmokeClass &b) const {
-	const SmokeClass &a = *this;
-	return !(a == b);
-    }
-    bool isa(const SmokeClass &sc) const {
-	// This is a sick function, if I do say so myself
-	if(*this == sc) return true;
-	Smoke::Index *parents = _smoke->inheritanceList + _c->parents;
-	for(int i = 0; parents[i]; i++) {
-	    if(SmokeClass(_smoke, parents[i]).isa(sc)) return true;
-	}
-	return false;
-    }
-
-    unsigned short flags() const { return _c->flags; }
-    bool hasConstructor() const { return flags() & Smoke::cf_constructor; }
-    bool hasCopy() const { return flags() & Smoke::cf_deepcopy; }
-    bool hasVirtual() const { return flags() & Smoke::cf_virtual; }
-    bool hasFire() const { return !(flags() & Smoke::cf_undefined); }
-};
-
 /*
  * Simply using typeids isn't enough for signals/slots. It will be possible
  * to declare signals and slots which use arguments which can't all be



More information about the Kde-bindings mailing list