[Kde-bindings] branches/work/kdebindings-smoke2

Arno Rehn kde at arnorehn.de
Wed Apr 23 18:05:39 UTC 2008


SVN commit 800231 by arnorehn:

* Fixed enum-checking for types.
* Fixed resolving classnames.
* Backported changes from trunk.
* The Soprano dbpedia example works now with modular smoke.

CCMAIL: kde-bindings at kde.org



 M  +7 -0      ChangeLog  
 M  +68 -7     ruby/korundum/korundum4.rb  
 M  +1 -0      ruby/plasma/plasma.rb  
 M  +1 -0      ruby/qsci/qscintilla.rb  
 M  +5 -2      ruby/qtruby/src/Qt.cpp  
 M  +15 -7     ruby/qtruby/src/qtruby.cpp  
 M  +12 -1     ruby/qtruby/src/qtruby.h  


--- branches/work/kdebindings-smoke2/ChangeLog #800230:800231
@@ -1,3 +1,10 @@
+2008-04-23  Arno Rehn  <arno at arnorehn.de>
+
+	* Fixed enum-checking for types.
+	* Fixed resolving classnames.
+	* Backported changes from trunk.
+	* The Soprano dbpedia example works now with modular smoke.
+
 2008-04-21  Arno Rehn  <arno at arnorehn.de>
 
 	* Backported changes from trunk.
--- branches/work/kdebindings-smoke2/ruby/korundum/korundum4.rb #800230:800231
@@ -146,6 +146,8 @@
 	end
 
 	class CmdLineArgs < Qt::Base
+		include Enumerable
+
 		def CmdLineArgs.init(*k)
 			if k.length > 0
 				if k[0].kind_of? Array
@@ -161,6 +163,38 @@
 			end
 		end
 
+		def each
+			i = 0
+			while i < count do
+				yield arg(i)
+				i += 1
+			end
+		end
+
+		def length
+			count
+		end
+
+		def size
+			count
+		end
+
+		# Allows args["formfactor"] as an alternative to args.getOption("formfactor"),
+		# and args[1] as an alternative to args.arg(1)
+		def [](arg)
+			if arg.kind_of?(String)
+				getOption(arg)
+			elsif arg.kind_of?(Integer)
+				arg(arg)
+			else
+				nil
+			end
+		end
+
+		def set?(arg)
+			isSet(arg)
+		end
+
 		def isSet(arg)
 			super(arg.kind_of?(String) ? Qt::ByteArray.new(arg) : arg)
 		end
@@ -168,6 +202,10 @@
 		def getOption(arg)
 			super(arg.kind_of?(String) ? Qt::ByteArray.new(arg) : arg)
 		end
+
+		def getOptionList(arg)
+			super(arg.kind_of?(String) ? Qt::ByteArray.new(arg) : arg)
+		end
 	end
 
 	class CmdLineOptions < Qt::Base
@@ -239,20 +277,42 @@
 	end
 
 	class MainWindow < Qt::Base
-		# A sane alternative to the strange looking C++ template version,
-		# this takes a variable number of ruby args as classes to restore
-		def self.kRestoreMainWindows(*k)
+		# A sane alternative to the strange looking C++ template version.
+		# There is no need to pass a list of classes, as the Ruby classes
+		# of the main windows to be restored are derived from 
+		# KDE::MainWindow#classNameOfToplevel
+		# Takes an optional block, so a newly created window can be passed
+		# into the block. For example:
+		#
+		# KDE::MainWindow.kRestoreMainWindows {|window| window.caption = "foobar"}
+		#
+		def self.kRestoreMainWindows(&block)
 			n = 1
 			while MainWindow.canBeRestored(n)
 				className = MainWindow.classNameOfToplevel(n)
-				k.each do |klass|
-					if klass.name == className
-						klass.new.restore(n)
-					end
+				if className =~ /(.*)::(.*)/
+					namespace = Object.const_get($1)
+					klass = namespace.const_get($2)
+				else
+					klass = Object.const_get(className)
 				end
+				obj = klass.new.restore(n)
+				if block_given?
+					yield obj
+				end
 				n += 1
 			end
 		end
+
+		# Yield the numbers of the windows that can be restored
+		# in turn
+		def self.each_restore
+			n = 1
+			while MainWindow.canBeRestored(n)
+				yield n
+				n += 1
+			end
+		end
 	end
 
 	class PageWidgetItem < Qt::Base
@@ -351,6 +411,7 @@
 			getClassList.each do |c|
 				classname = Qt::Internal::normalize_classname(c)
 				id = Qt::Internal::findClass(c);
+				Qt::Internal::insert_pclassid(classname, id)
 				Qt::Internal::cpp_names[classname] = c
 				if classname =~ /^KParts/
 					m = KParts
--- branches/work/kdebindings-smoke2/ruby/plasma/plasma.rb #800230:800231
@@ -15,6 +15,7 @@
 			getClassList.each do |c|
 				classname = Qt::Internal::normalize_classname(c)
 				id = Qt::Internal::findClass(c);
+				Qt::Internal::insert_pclassid(classname, id)
 				Qt::Internal::cpp_names[classname] = c
 				klass = Qt::Internal::isQObject(c) ? Qt::Internal::create_qobject_class(classname, Plasma) \
 				                                   : Qt::Internal::create_qt_class(classname, Plasma)
--- branches/work/kdebindings-smoke2/ruby/qsci/qscintilla.rb #800230:800231
@@ -14,6 +14,7 @@
             getClassList.each do |c|
                 classname = Qt::Internal::normalize_classname(c)
                 id = Qt::Internal::findClass(c);
+                Qt::Internal::insert_pclassid(classname, id)
                 Qt::Internal::cpp_names[classname] = c
                 klass = Qt::Internal::isQObject(c) ? Qt::Internal::create_qobject_class(classname, Qsci) \
                                                     : Qt::Internal::create_qt_class(classname, Qsci)
--- branches/work/kdebindings-smoke2/ruby/qtruby/src/Qt.cpp #800230:800231
@@ -111,7 +111,7 @@
 // FIXME:
 // find some way to use a Smoke::ModuleIndex here instead of an int
 // Maps from an int id to classname in the form Qt::Widget
-QHash<int, QByteArray*> classname;
+QHash<Smoke::ModuleIndex, QByteArray*> classname;
 
 #define logger logger_backend
 
@@ -273,7 +273,10 @@
 
 char*
 QtRubySmokeBinding::className(Smoke::Index classId) {
-	return (char *) (const char *) *(classname.value(classId));
+	Smoke::ModuleIndex mi = { smoke, classId };
+	if (smoke->classes[classId].external) // the class is in this module, but marked as external.
+		mi = smoke->findClass(smoke->className(classId));
+	return (char *) (const char *) *(classname.value(mi));
 }
 
 /*
--- branches/work/kdebindings-smoke2/ruby/qtruby/src/qtruby.cpp #800230:800231
@@ -1388,13 +1388,21 @@
 isEnum(VALUE /*self*/, VALUE enumName_value)
 {
     char *enumName = StringValuePtr(enumName_value);
-    Smoke::Index typeId = qt_Smoke->idType(enumName);
+    Smoke::Index typeId = 0;
+    Smoke* s = 0;
+    for (int i = 0; i < smokeList.count(); i++) {
+         typeId = smokeList[i]->idType(enumName);
+         if (typeId > 0) {
+             s = smokeList[i];
+             break;
+         }
+    }
 	return	typeId > 0 
-			&& (	(qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_enum
-					|| (qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_ulong
-					|| (qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_long
-					|| (qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_uint
-					|| (qt_Smoke->types[typeId].flags & Smoke::tf_elem) == Smoke::t_int ) ? Qtrue : Qfalse;
+			&& (	(s->types[typeId].flags & Smoke::tf_elem) == Smoke::t_enum
+					|| (s->types[typeId].flags & Smoke::tf_elem) == Smoke::t_ulong
+					|| (s->types[typeId].flags & Smoke::tf_elem) == Smoke::t_long
+					|| (s->types[typeId].flags & Smoke::tf_elem) == Smoke::t_uint
+					|| (s->types[typeId].flags & Smoke::tf_elem) == Smoke::t_int ) ? Qtrue : Qfalse;
 }
 
 static VALUE
@@ -1405,7 +1413,7 @@
     int smokeidx = NUM2INT(rb_funcall(mi_value, rb_intern("smoke"), 0));
     Smoke::ModuleIndex mi = { smokeList[smokeidx], ix };
     classcache.insert(QByteArray(p), new Smoke::ModuleIndex(mi));
-    classname.insert(ix, new QByteArray(p));
+    classname.insert(mi, new QByteArray(p));
     return self;
 }
 
--- branches/work/kdebindings-smoke2/ruby/qtruby/src/qtruby.h #800230:800231
@@ -28,6 +28,17 @@
 #endif
 #define QTRUBY_VERSION "1.4.10"
 
+inline bool operator==(const Smoke::ModuleIndex& a, const Smoke::ModuleIndex& b) {
+	if (a.index == b.index && a.smoke == b.smoke)
+		return true;
+	else
+		return false;
+}
+
+inline uint qHash(const Smoke::ModuleIndex& mi) {
+	return qHash(mi.index) ^ qHash(mi.smoke);
+}
+
 struct MocArgument;
 
 class Q_DECL_EXPORT QtRubySmokeBinding : public SmokeBinding {
@@ -99,7 +110,7 @@
 extern Q_DECL_EXPORT QHash<QByteArray, Smoke::ModuleIndex *> methcache;
 extern Q_DECL_EXPORT QHash<QByteArray, Smoke::ModuleIndex *> classcache;
 // Maps from an int id to classname in the form Qt::Widget
-extern Q_DECL_EXPORT QHash<int, QByteArray*> classname;
+extern Q_DECL_EXPORT QHash<Smoke::ModuleIndex, QByteArray*> classname;
 
 extern Q_DECL_EXPORT void install_handlers(TypeHandler *);
 



More information about the Kde-bindings mailing list