[Kde-bindings] branches/work/kdebindings-smoke2
Arno Rehn
kde at arnorehn.de
Thu Jan 31 19:57:22 UTC 2008
SVN commit 769190 by arnorehn:
* Simplified the definition of nested classes.
* Added possibility to create a callback for class definition.
CCMAIL: kde-bindings at kde.org
M +2 -0 ChangeLog
M +36 -1 ruby/korundum/korundum.cpp
M +1 -1 ruby/qsci/qscintilla.cpp
M +0 -1 ruby/qtruby/src/Qt.cpp
M +2 -2 ruby/qtruby/src/lib/Qt/qtruby4.rb
M +18 -10 ruby/qtruby/src/qtruby.cpp
M +2 -1 ruby/qtruby/src/qtruby.h
--- branches/work/kdebindings-smoke2/ChangeLog #769189:769190
@@ -8,6 +8,8 @@
* Fixed bug preventing KDE and QScintilla Ruby bindings being loaded at the same
time.
* Added convenience rb file to QScintilla (you can do "require 'QScintilla'" now)
+ * Simplified the definition of nested classes.
+ * Added possibility to create a callback for class definition.
2008-01-29 Arno Rehn <arno at arnorehn.de>
--- branches/work/kdebindings-smoke2/ruby/korundum/korundum.cpp #769189:769190
@@ -5,6 +5,7 @@
#include <QtDebug>
#include <klocalizedstring.h>
+#include <kconfigskeleton.h>
#include <smoke.h>
@@ -62,6 +63,40 @@
return set_obj_info("KDE::LocalizedString", result);
}
+static VALUE
+config_additem(int argc, VALUE * argv, VALUE self)
+{
+ smokeruby_object *o = value_obj_info(self);
+ KConfigSkeleton * config = (KConfigSkeleton *) o->ptr;
+
+ if (argc < 1 || argc > 2) {
+ rb_raise(rb_eArgError, "wrong number of arguments(%d for 2)\n", argc);
+ }
+
+ if (TYPE(argv[0]) != T_DATA) {
+ rb_raise(rb_eArgError, "wrong argument type, expected KDE::ConfigSkeletonItem\n", argc);
+ }
+
+ smokeruby_object *c = value_obj_info(argv[0]);
+ KConfigSkeletonItem * item = (KConfigSkeletonItem *) c->ptr;
+
+ if (argc == 1) {
+ config->addItem(item);
+ } else {
+ config->addItem(item, QString(StringValuePtr(argv[1])));
+ }
+
+ return self;
+}
+
+static void classCreated(const char* package, VALUE /*module*/, VALUE klass)
+{
+ QString packageName(package);
+ if (packageName == "KDE::ConfigSkeleton") {
+ rb_define_method(klass, "addItem", (VALUE (*) (...)) config_additem, -1);
+ }
+}
+
extern TypeHandler KDE_handlers[];
extern "C" {
@@ -79,7 +114,7 @@
smokeList << kde_Smoke;
- QtRubyModule module = { "KDE", resolve_classname_kde };
+ QtRubyModule module = { "KDE", resolve_classname_kde, classCreated };
modules[kde_Smoke] = module;
install_handlers(KDE_handlers);
--- branches/work/kdebindings-smoke2/ruby/qsci/qscintilla.cpp #769189:769190
@@ -41,7 +41,7 @@
smokeList << qsci_Smoke;
- QtRubyModule module = { "Qsci", resolve_classname_qsci };
+ QtRubyModule module = { "Qsci", resolve_classname_qsci, 0 };
modules[qsci_Smoke] = module;
qscintilla_module = rb_define_module("Qsci");
--- branches/work/kdebindings-smoke2/ruby/qtruby/src/Qt.cpp #769189:769190
@@ -83,7 +83,6 @@
VALUE qmetaobject_class = Qnil;
VALUE qtablemodel_class = Qnil;
VALUE qt_base_class = Qnil;
-VALUE qtextlayout_class = Qnil;
VALUE qvariant_class = Qnil;
VALUE moduleindex_class = Qnil;
--- branches/work/kdebindings-smoke2/ruby/qtruby/src/lib/Qt/qtruby4.rb #769189:769190
@@ -2442,7 +2442,7 @@
end
def Internal.getAllParents(class_id, res)
- getIsa(class_id).each do |s|
+ getIsa(class_id.index).each do |s|
c = idClass(s)
res << c.index
getAllParents(c, res)
@@ -2793,7 +2793,7 @@
Qt::Internal::getAllParents(classid, ids)
end
ids << classid
- ids.each { |c| Qt::Internal::findAllMethodNames(meths, c, flags) }
+ ids.each { |c| Qt::Internal::findAllMethodNames(meths, c.index, flags) }
return meths.uniq
end
end
--- branches/work/kdebindings-smoke2/ruby/qtruby/src/qtruby.cpp #769189:769190
@@ -2280,11 +2280,13 @@
// any ideas why?
VALUE value_moduleName = rb_funcall(module_value, rb_intern("name"), 0);
const char *moduleName = strdup(StringValuePtr(value_moduleName));
- VALUE klass;
+ VALUE klass = module_value;
QString packageName(package);
- klass = rb_define_class_under(module_value, package + strlen(moduleName) + 2, qt_base_class);
+ foreach(QString s, packageName.mid(strlen(moduleName) + 2).split("::")) {
+ klass = rb_define_class_under(klass, (const char*) s.toLatin1(), qt_base_class);
+ }
if (packageName == "Qt::Application" || packageName == "Qt::CoreApplication" ) {
rb_define_singleton_method(klass, "new", (VALUE (*) (...)) new_qapplication, -1);
@@ -2328,6 +2330,11 @@
rb_define_method(klass, "connect", (VALUE (*) (...)) qobject_connect, -1);
rb_define_singleton_method(klass, "connect", (VALUE (*) (...)) qobject_connect, -1);
+ foreach(QtRubyModule m, modules.values()) {
+ if (m.class_created)
+ m.class_created(package, module_value, klass);
+ }
+
free((void *) package);
return klass;
}
@@ -2341,19 +2348,15 @@
// any ideas why?
VALUE value_moduleName = rb_funcall(module_value, rb_intern("name"), 0);
const char *moduleName = strdup(StringValuePtr(value_moduleName));
- VALUE klass;
+ VALUE klass = module_value;
QString packageName(package);
- if (packageName.startsWith("Qt::TextLayout::")) {
- klass = rb_define_class_under(qtextlayout_class, package+strlen("Qt::TextLayout::"), qt_base_class);
- } else {
- klass = rb_define_class_under(module_value, package+strlen(moduleName) + 2, qt_base_class);
+ foreach(QString s, packageName.mid(strlen(moduleName) + 2).split("::")) {
+ klass = rb_define_class_under(klass, (const char*) s.toLatin1(), qt_base_class);
}
if (packageName == "Qt::MetaObject") {
qmetaobject_class = klass;
- } else if (packageName == "Qt::TextLayout") {
- qtextlayout_class = klass;
} else if (packageName == "Qt::Variant") {
qvariant_class = klass;
rb_define_singleton_method(qvariant_class, "fromValue", (VALUE (*) (...)) qvariant_from_value, -1);
@@ -2385,6 +2388,11 @@
#endif
}
+ foreach(QtRubyModule m, modules.values()) {
+ if (m.class_created)
+ m.class_created(package, module_value, klass);
+ }
+
free((void *) package);
return klass;
}
@@ -2423,7 +2431,7 @@
smokeList << qt_Smoke;
qt_Smoke->binding = new QtRubySmokeBinding(qt_Smoke);
- QtRubyModule module = { "QtRuby", resolve_classname_qt };
+ QtRubyModule module = { "QtRuby", resolve_classname_qt, 0 };
modules[qt_Smoke] = module;
install_handlers(Qt_handlers);
--- branches/work/kdebindings-smoke2/ruby/qtruby/src/qtruby.h #769189:769190
@@ -53,10 +53,12 @@
extern Q_DECL_EXPORT int object_count;
typedef const char* (*ResolveClassNameFn)(Smoke* smoke, int classId, void * ptr);
+typedef void (*ClassCreatedFn)(const char* package, VALUE module, VALUE klass);
struct QtRubyModule {
const char *name;
ResolveClassNameFn resolve_classname;
+ ClassCreatedFn class_created;
};
// keep this enum in sync with lib/Qt/debug.pm
@@ -79,7 +81,6 @@
extern Q_DECL_EXPORT VALUE qmetaobject_class;
extern Q_DECL_EXPORT VALUE qtablemodel_class;
extern Q_DECL_EXPORT VALUE qt_base_class;
-extern Q_DECL_EXPORT VALUE qtextlayout_class;
extern Q_DECL_EXPORT VALUE qvariant_class;
extern Q_DECL_EXPORT VALUE moduleindex_class;
More information about the Kde-bindings
mailing list