[Kde-bindings] KDE/kdebindings/ruby/korundum
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Fri May 2 11:35:46 UTC 2008
SVN commit 803238 by rdale:
* Changed the way the Ruby classname is derived from a
X-KDE-PluginKeyword entry in a desktop file. The directory name is now
used to derive a Ruby module name and the Ruby script name used to
derive a class name within that module. So given a path of
'my_app/foo_bar.rb' krubypluginfactory would expect a MyApp::FooBar
class in the Ruby file. Otherwise the Ruby classname would need to
be unique across all plugins loaded by a KDE app, and it is easy
to get clashes such as two 'Clock' classes.
* Special cased KDE::ComponentData so you can pass Ruby Strings to it
as well as Qt::ByteArrays
CCMAIL: kde-bindings at kde.org
M +13 -0 ChangeLog
M +2 -1 src/krubyapplication.cpp
M +36 -15 src/krubypluginfactory.cpp
M +15 -0 src/lib/KDE/korundum4.rb
M +1 -1 tools/rbkconfig_compiler/tests/test_rbkconfig_compiler.rb
--- trunk/KDE/kdebindings/ruby/korundum/ChangeLog #803237:803238
@@ -1,3 +1,16 @@
+2008-05-02 Richard Dale <richard.j.dale at gmail.com>
+
+ * Changed the way the Ruby classname is derived from a
+ X-KDE-PluginKeyword entry in a desktop file. The directory name is now
+ used to derive a Ruby module name and the Ruby script name used to
+ derive a class name within that module. So given a path of
+ 'my_app/foo_bar.rb' krubypluginfactory would expect a MyApp::FooBar
+ class in the Ruby file. Otherwise the Ruby classname would need to
+ be unique across all plugins loaded by a KDE app, and it is easy
+ to get clashes such as two 'Clock' classes.
+ * Special cased KDE::ComponentData so you can pass Ruby Strings to it
+ as well as Qt::ByteArrays
+
2008-04-30 Richard Dale <richard.j.dale at gmail.com>
* Oops, the KConfigSkeleton constructors didn't quite work..
--- trunk/KDE/kdebindings/ruby/korundum/src/krubyapplication.cpp #803237:803238
@@ -21,6 +21,7 @@
#include <QString>
#include <QFileInfo>
+#include <QDir>
#include <KStandardDirs>
#include <KComponentData>
@@ -40,7 +41,7 @@
}
QFileInfo script(argv[1]);
- KComponentData componentData(script.dirPath().toLatin1(), QByteArray(), KComponentData::SkipMainComponentRegistration);
+ KComponentData componentData(script.dir().dirName().toLatin1(), QByteArray(), KComponentData::SkipMainComponentRegistration);
QString path = componentData.dirs()->locate("data", argv[1], componentData);
if (path.isEmpty()) {
--- trunk/KDE/kdebindings/ruby/korundum/src/krubypluginfactory.cpp #803237:803238
@@ -22,6 +22,7 @@
#include <ruby.h>
#include <QString>
+#include <QDir>
#include <QFileInfo>
#include <KStandardDirs>
@@ -82,6 +83,9 @@
protected:
virtual QObject *create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword);
+
+ private:
+ static QByteArray toCamelCase(QByteArray name);
};
K_EXPORT_PLUGIN(KRubyPluginFactory)
@@ -90,6 +94,24 @@
{
}
+QByteArray KRubyPluginFactory::toCamelCase(QByteArray name)
+{
+ // Convert foo_bar_baz to FooBarBaz
+ QByteArray camelCaseName = name.left(1).toUpper();
+ for (int i = 1; i < name.size(); i++) {
+ if (name[i] == '_' || name[i] == '-') {
+ i++;
+ if (i < name.size()) {
+ camelCaseName += name.mid(i, 1).toUpper();
+ }
+ } else {
+ camelCaseName += name[i];
+ }
+ }
+
+ return camelCaseName;
+}
+
QObject *KRubyPluginFactory::create(const char *iface, QWidget *parentWidget, QObject *parent, const QVariantList &args, const QString &keyword)
{
Q_UNUSED(iface);
@@ -122,23 +144,19 @@
return 0;
}
- // Convert foo_bar_baz to FooBarBaz
- const QByteArray baseName = program.baseName().toLatin1();
- QByteArray className = baseName.left(1).toUpper();
- for (int i = 1; i < baseName.size(); i++) {
- if (baseName[i] == '_') {
- i++;
- if (i < baseName.size()) {
- className += baseName.mid(i, 1).toUpper();
- }
- } else {
- className += baseName[i];
- }
- }
+ // A path of my_app/foo_bar.rb is turned into module/class 'MyApp::FooBar'
+ const QByteArray moduleName = KRubyPluginFactory::toCamelCase(QFile::encodeName(program.dir().dirName()));
+ const QByteArray className = KRubyPluginFactory::toCamelCase(program.baseName().toLatin1());
- plugin_class = rb_const_get(rb_cObject, rb_intern(className));
+ VALUE plugin_module = rb_const_get(rb_cObject, rb_intern(moduleName));
+ if (plugin_module == Qnil) {
+ kWarning() << "no " << moduleName << " module found";
+ return 0;
+ }
+
+ plugin_class = rb_const_get(plugin_module, rb_intern(className));
if (plugin_class == Qnil) {
- kWarning() << "no" << className << "class found";
+ kWarning() << "no " << moduleName << "::" << className << " class found";
return 0;
}
@@ -161,6 +179,9 @@
return 0;
}
+ // Set a global variable $my_app_foo_bar to the value of the new instance of MyApp::FooBar
+ rb_gv_set(QByteArray("$") + QFile::encodeName(program.path()) + "_" + program.baseName().toLatin1(), plugin_value);
+
smokeruby_object *o = 0;
Data_Get_Struct(plugin_value, smokeruby_object, o);
QObject * createdInstance = reinterpret_cast<QObject *>(o->ptr);
--- trunk/KDE/kdebindings/ruby/korundum/src/lib/KDE/korundum4.rb #803237:803238
@@ -243,6 +243,21 @@
end
end
+ class ComponentData
+ def initialize(*args)
+ sargs = []
+ for i in 0...args.length do
+ if [0, 1].include?(i) && (args[i].kind_of?(String) || args[i].nil?)
+ sargs << Qt::ByteArray.new(args[i])
+ else
+ sargs << args[i]
+ end
+ end
+
+ super(*sargs)
+ end
+ end
+
class Config
def name(*args)
method_missing(:name, *args)
--- trunk/KDE/kdebindings/ruby/korundum/tools/rbkconfig_compiler/tests/test_rbkconfig_compiler.rb #803237:803238
@@ -10,7 +10,7 @@
class TestRbkconfigCompiler < Test::Unit::TestCase
def setup
- i = KDE::ComponentData.new(Qt::ByteArray.new("test"))
+ i = KDE::ComponentData.new("test")
end
def teardown
More information about the Kde-bindings
mailing list