[Kde-bindings] KDE/kdebindings
Arno Rehn
kde at arnorehn.de
Sun Apr 12 17:24:51 UTC 2009
SVN commit 952845 by arnorehn:
* Make it possible to register new metatypes. For the moment this works only
with classes wrapped by SMOKE.
CCMAIL: kde-bindings at kde.org
M +4 -0 csharp/qyoto/ChangeLog
M +1 -1 csharp/qyoto/core/QMetaType.cs
A csharp/qyoto/core/QMetaTypeExtras.cs
M +16 -4 csharp/qyoto/core/QVariantExtras.cs
M +70 -5 csharp/qyoto/src/qyoto.cpp
M +1 -0 kalyptus/kalyptusCxxToKimono.pm
--- trunk/KDE/kdebindings/csharp/qyoto/ChangeLog #952844:952845
@@ -1,3 +1,7 @@
+2009-04-12 Arno Rhen <arno at arnorehn.de>
+ * Make it possible to register new metatypes. For the moment this works only
+ with classes wrapped by SMOKE.
+
2009-03-24 Arno Rehn <arno at arnorehn.de>
* Change Qyoto's license to LGPL2.
--- trunk/KDE/kdebindings/csharp/qyoto/core/QMetaType.cs #952844:952845
@@ -2,7 +2,7 @@
namespace Qyoto {
using System;
[SmokeClass("QMetaType")]
- public class QMetaType : Object, IDisposable {
+ public partial class QMetaType : Object, IDisposable {
protected SmokeInvocation interceptor = null;
private IntPtr smokeObject;
protected QMetaType(Type dummy) {}
--- trunk/KDE/kdebindings/csharp/qyoto/core/QVariantExtras.cs #952844:952845
@@ -73,7 +73,11 @@
} else if (typeof(T).IsEnum) {
return (T) (object) ToInt();
} else {
- string typeName = typeof(T).ToString().Replace("Qyoto.", "");
+ string typeName;
+ if (SmokeMarshallers.IsSmokeClass(typeof(T)))
+ typeName = SmokeMarshallers.SmokeClassName(typeof(T));
+ else
+ typeName = typeof(T).ToString();
if (NameToType(typeName) > TypeOf.LastCoreType) {
IntPtr instancePtr = QVariantValue(typeName, (IntPtr) GCHandle.Alloc(this));
return (T) ((GCHandle) instancePtr).Target;
@@ -139,10 +143,16 @@
} else if (typeof(T).IsEnum) {
return new QVariant((int) value);
} else {
- string typeName = typeof(T).ToString().Replace("Qyoto.", "");
+ string typeName;
+ if (SmokeMarshallers.IsSmokeClass(typeof(T)))
+ typeName = SmokeMarshallers.SmokeClassName(typeof(T));
+ else
+ typeName = typeof(T).ToString();
if (NameToType(typeName) > TypeOf.LastCoreType) {
- IntPtr instancePtr = QVariantFromValue((int) NameToType(typeName), (IntPtr) GCHandle.Alloc(value));
- return (QVariant) ((GCHandle) instancePtr).Target;
+ GCHandle handle = (GCHandle) QVariantFromValue(QMetaType.type(typeName), (IntPtr) GCHandle.Alloc(value));
+ QVariant v = (QVariant) handle.Target;
+ handle.Free();
+ return v;
}
return new QVariant();
@@ -316,3 +326,5 @@
}
}
}
+
+// kate: space-indent on; indent-width 4; replace-tabs on; mixed-indent off;
--- trunk/KDE/kdebindings/csharp/qyoto/src/qyoto.cpp #952844:952845
@@ -345,18 +345,26 @@
printf("ENTER QVariantValue(typeName: %s variant: 0x%8.8x)\n", typeName, variant);
#endif
smokeqyoto_object *o = (smokeqyoto_object*) (*GetSmokeObject)(variant);
- void * value = QMetaType::construct( QMetaType::type(typeName),
- (void *) ((QVariant *)o->ptr)->constData() );
+ (*FreeGCHandle)(variant);
+ QVariant *v = (QVariant*) o->ptr;
+ int type = QMetaType::type(typeName);
+ void *value = 0;
+ if (v->canConvert((QVariant::Type) type)) {
+ v->convert((QVariant::Type) type);
+ value = QMetaType::construct(type, v->constData());
+ } else {
+ value = QMetaType::construct(type, 0);
+ }
+
if (qstrcmp(typeName, "QDBusVariant") == 0) {
Smoke::ModuleIndex id = o->smoke->findClass("QVariant");
smokeqyoto_object * vo = alloc_smokeqyoto_object(true, id.smoke, id.index, value);
- (*FreeGCHandle)(variant);
return (*CreateInstance)("Qyoto.QDBusVariant", vo);
}
+
Smoke::ModuleIndex id = o->smoke->findClass(typeName);
smokeqyoto_object * vo = alloc_smokeqyoto_object(true, id.smoke, id.index, value);
- (*FreeGCHandle)(variant);
- return (*CreateInstance)((QString("Qyoto.") + typeName).toLatin1(), vo);
+ return (*CreateInstance)(qyoto_resolve_classname(vo), vo);
}
Q_DECL_EXPORT void *
@@ -373,6 +381,63 @@
return (*CreateInstance)("Qyoto.QVariant", vo);
}
+Q_DECL_EXPORT void
+DestroyObject(const char *className, void *ptr)
+{
+ if (!ptr) return;
+ QByteArray klassName(className);
+ QByteArray dtor = "~" + klassName;
+ QByteArray sig = dtor + "()";
+ Smoke::ModuleIndex mi = FindMethodId(klassName.data(), dtor.data(), sig.data());
+ if (!mi.smoke) {
+ printf("can't destroy %p, missing method: %s\n", ptr, sig.constData());
+ return;
+ }
+ const Smoke::Method &method = mi.smoke->methods[mi.index];
+ const Smoke::Class &klass = mi.smoke->classes[method.classId];
+ (*klass.classFn)(method.method, ptr, 0);
+}
+
+Q_DECL_EXPORT void*
+CreateObject(char *className, void *other)
+{
+ QByteArray klassName(className);
+ Smoke::ModuleIndex mi;
+ Smoke::StackItem stack[2];
+
+ if (other) {
+ QByteArray ctor = klassName + "#";
+ QByteArray signature = klassName + "(const " + klassName + "&)";
+ mi = FindMethodId(className, ctor.data(), signature.data());
+ if (!mi.smoke) {
+ printf("can't create copy of %p, missing method: %s\n", other, signature.data());
+ return 0;
+ }
+ stack[1].s_voidp = other;
+ } else {
+ QByteArray signature = klassName + "()";
+ mi = FindMethodId(className, klassName.data(), signature.data());
+ if (!mi.smoke) {
+ printf("can't create object, missing method: %s\n", signature.data());
+ return 0;
+ }
+ }
+
+ const Smoke::Method &method = mi.smoke->methods[mi.index];
+ const Smoke::Class &klass = mi.smoke->classes[method.classId];
+ (*klass.classFn)(method.method, 0, stack);
+ // set the binding
+ stack[1].s_voidp = qyoto_modules[mi.smoke].binding;
+ (*klass.classFn)(0, stack[0].s_voidp, stack);
+ return stack[0].s_voidp;
+}
+
+Q_DECL_EXPORT int
+QMetaTypeRegisterType(const char *name, QMetaType::Destructor destructor, QMetaType::Constructor constructor)
+{
+ return QMetaType::registerType(name, destructor, constructor);
+}
+
Q_DECL_EXPORT void *
ModelIndexInternalPointer(void *obj)
{
--- trunk/KDE/kdebindings/kalyptus/kalyptusCxxToKimono.pm #952844:952845
@@ -198,6 +198,7 @@
'QIODevice' => '1',
'QKeySequence' => '1',
'QLineF' => '1',
+ 'QMetaType' => '1',
'QModelIndex' => '1',
'QObject' => '1',
'QPen' => '1',
More information about the Kde-bindings
mailing list