[Kde-bindings] playground/bindings/kimono
Richard Dale
Richard_Dale at tipitina.demon.co.uk
Sat Feb 10 13:39:26 UTC 2007
SVN commit 632282 by rdale:
* The csrcc tool nearly works, but Qt.Q_INIT_RESOURCE() can't find the
class where the resource is.
CCMAIL: kde-bindings at kde.org
M +2 -0 ChangeLog
M +0 -3 Qyoto.cs
M +4 -2 SmokeInvocation.cs
M +1 -1 core/Qt.cs
M +27 -1 core/QtExtras.cs
M +2 -1 examples/graphicsview/collidingmice/main.cs
M +0 -1 examples/qdbus/listnames/listnames.cs
M +4 -5 examples/qdbus/pingpong/ping.cs
M +5 -6 examples/qdbus/pingpong/pong.cs
M +8 -7 examples/tutorial/t1/t1.cs
M +2 -2 examples/tutorial/t14/main.cs
M +0 -2 gui/QApplication.cs
M +1 -0 qdbus/QDBusArgument.cs
M +14 -7 qyoto.cpp
M +19 -14 tools/csrcc/rcc.cpp
--- trunk/playground/bindings/kimono/ChangeLog #632281:632282
@@ -1,6 +1,8 @@
2007-02-10 Richard Dale <rdale at foton.es>
* Improved debug messages in SmokeInvocation.cs
+ * The csrcc tool nearly works, but Qt.Q_INIT_RESOURCE() can't find the
+ class where the resource is.
2007-02-09 Arno Rehn <arno at arnorehn.de>
--- trunk/playground/bindings/kimono/Qyoto.cs #632281:632282
@@ -48,9 +48,6 @@
public class Qyoto : System.Object
{
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
- public static extern void DeleteQApp();
-
- [DllImport("libqyoto", CharSet=CharSet.Ansi)]
public static extern void Init_qyoto();
[DllImport("libqyoto", CharSet=CharSet.Ansi)]
--- trunk/playground/bindings/kimono/SmokeInvocation.cs #632281:632282
@@ -152,7 +152,9 @@
object instance = ((GCHandle) instanceHandle).Target;
MethodInfo method = (MethodInfo) ((GCHandle) methodHandle).Target;
#if DEBUG
- if ((Debug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0) {
+ if ( (Debug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0
+ && (Debug.DebugChannel() & QtDebugChannel.QTDB_VIRTUAL) != 0 )
+ {
Console.WriteLine( "ENTER InvokeMethod() {0}.{1}",
instance,
method.Name );
@@ -497,7 +499,7 @@
#if DEBUG
if ((Debug.DebugChannel() & QtDebugChannel.QTDB_TRANSPARENT_PROXY) != 0) {
- Console.WriteLine( "ENTER SmokeInvocation.Invoke() MethodName: {0}.{1} Type: {2} ArgCount: {3}",
+ Console.WriteLine( "ENTER SignalInvocation.Invoke() MethodName: {0}.{1} Type: {2} ArgCount: {3}",
_className,
callMessage.MethodName,
callMessage.TypeName,
--- trunk/playground/bindings/kimono/core/Qt.cs #632281:632282
@@ -1349,7 +1349,7 @@
}
[SmokeMethod("~Qt", "()", "")]
private void DisposeQt() {
- ProxyQt().DisposeQt();
+// ProxyQt().DisposeQt();
}
public static void QDBusReplyFill(QDBusMessage reply, QDBusError error, QVariant data) {
StaticQt().QDBusReplyFill(reply,error,data);
--- trunk/playground/bindings/kimono/core/QtExtras.cs #632281:632282
@@ -3,6 +3,7 @@
using System;
using System.Collections;
using System.Text;
+ using System.Reflection;
public partial class Qt : MarshalByRefObject {
public static QApplication qApp = null;
@@ -14,7 +15,32 @@
public static string SLOT(string slot) {
return "1" + slot;
}
-
+
+ public static void Q_INIT_RESOURCE(string name) {
+ string className = "QInitResources_" + name + "__dest_class__";
+ // This unfortunately doesn't work because it only looks in the
+ // current assembly. Is it possible to force a search of all
+ // assemblies?
+ Type klass = Type.GetType(className);
+ if (klass == null) {
+ Console.Error.WriteLine("Q_INIT_RESOURCE: resource '{0}' is missing", name);
+ return;
+ }
+ MethodInfo initResource = klass.GetMethod("QInitResources_" + name);
+ initResource.Invoke(null, null);
+ }
+
+ public static void Q_CLEANUP_RESOURCE(string name) {
+ string className = "QInitResources_" + name + "__dest_class__";
+ Type klass = Type.GetType(className);
+ if (klass == null) {
+ Console.Error.WriteLine("Q_CLEANUP_RESOURCE: resource '{0}' is missing", name);
+ return;
+ }
+ MethodInfo cleanupResource = klass.GetMethod("QCleanupResources_" + name);
+ cleanupResource.Invoke(null, null);
+ }
+
// These should really use generic types like the C++ originals, but
// it doesn't seem to work with C#
public static int QMin(int a, int b) { if (a < b) return a; return b; }
--- trunk/playground/bindings/kimono/examples/graphicsview/collidingmice/main.cs #632281:632282
@@ -23,10 +23,11 @@
using Qyoto;
using System;
-public class MouseMain {
+public class MouseMain : Qt{
private static int MouseCount = 7;
public static int Main(string[] args) {
+ Q_INIT_RESOURCE("mice");
new QApplication(args);
QGraphicsScene scene = new QGraphicsScene();
--- trunk/playground/bindings/kimono/examples/qdbus/listnames/listnames.cs #632281:632282
@@ -72,7 +72,6 @@
Method2();
Method3();
- Qyoto.Qyoto.DeleteQApp();
return 0;
}
}
--- trunk/playground/bindings/kimono/examples/qdbus/pingpong/ping.cs #632281:632282
@@ -29,7 +29,7 @@
static private string SERVICE_NAME = "com.trolltech.QtDBus.PingExample";
public static int Main(string[] args) {
- new QCoreApplication(args);
+ QCoreApplication app = new QCoreApplication(args);
if (!QDBusConnection.SessionBus().IsConnected()) {
Console.WriteLine("Cannot connect to the D-BUS session bus.\n" +
@@ -40,20 +40,19 @@
QDBusInterface iface = new QDBusInterface(SERVICE_NAME, "/", "", QDBusConnection.SessionBus());
if (iface.IsValid()) {
- QDBusReply<string> reply = new QDBusReply<string>(iface.Call("ping", new QVariant(args.Length > 0 ? args[0] : "")));
+ QDBusMessage message = iface.Call("ping", new QVariant(args.Length > 0 ? args[0] : ""));
+ QDBusReply<string> reply = new QDBusReply<string>(message);
if (reply.IsValid()) {
Console.WriteLine("Reply was: {0}", reply.Value());
- Qyoto.Qyoto.DeleteQApp();
+ Debug.SetDebug(QtDebugChannel.QTDB_ALL);
return 0;
}
Console.WriteLine("Call failed: {0}\n", reply.Error().Message());
- Qyoto.Qyoto.DeleteQApp();
return 1;
}
Console.WriteLine(QDBusConnection.SessionBus().LastError().Message());
- Qyoto.Qyoto.DeleteQApp();
return 1;
}
}
--- trunk/playground/bindings/kimono/examples/qdbus/pingpong/pong.cs #632281:632282
@@ -27,23 +27,22 @@
using System;
using System.Collections.Generic;
-class Pong : QObject
-{
+class Pong : QObject {
static private string SERVICE_NAME = "com.trolltech.QtDBus.PingExample";
[Q_SLOT]
public string ping(string arg)
{
-// This call crashes mono for some reason, so comment it out for now..
-// QMetaObject.InvokeMethod(QCoreApplication.Instance(), "quit");
+ QMetaObject.InvokeMethod(QCoreApplication.Instance(), "quit");
+ Debug.SetDebug(QtDebugChannel.QTDB_ALL);
return "ping(\"" + arg + "\") got called";
}
public static int Main(string[] args) {
- new QCoreApplication(args);
+ QCoreApplication app = new QCoreApplication(args);
if (!QDBusConnection.SessionBus().IsConnected()) {
- Console.WriteLine("Cannot connect to the D-BUS session bus.\n" +
+ Console.Write("Cannot connect to the D-BUS session bus.\n" +
"To start it, run:\n" +
"\teval `dbus-launch --auto-syntax`\n");
return 1;
--- trunk/playground/bindings/kimono/examples/tutorial/t1/t1.cs #632281:632282
@@ -3,11 +3,12 @@
public class T1
{
- public static int Main(String[] args) {
- new QApplication(args);
- QPushButton hello = new QPushButton("Hello world!", null);
- hello.Resize(100, 30);
- hello.Show();
- return QApplication.Exec();
- }
+ public static int Main(String[] args) {
+ QApplication app = new QApplication(args);
+ QPushButton hello = new QPushButton("Hello world!");
+ QLabel label = new QLabel(hello);
+ hello.Resize(100, 30);
+ hello.Show();
+ return QApplication.Exec();
+ }
}
--- trunk/playground/bindings/kimono/examples/tutorial/t14/main.cs #632281:632282
@@ -22,7 +22,7 @@
using Qyoto;
using System;
-class T13 {
+class T14 {
public static void Main(string[] args) {
new QApplication(args);
GameBoard board = new GameBoard();
@@ -30,4 +30,4 @@
board.Show();
QApplication.Exec();
}
-}
\ No newline at end of file
+}
--- trunk/playground/bindings/kimono/gui/QApplication.cs #632281:632282
@@ -514,8 +514,6 @@
return StaticQApplication().KeyboardInputDirection();
}
public static new int Exec() {
- /*int ret = StaticQApplication().Exec();
- Qyoto.DeleteQApp();*/
return StaticQApplication().Exec();
}
public static void SetQuitOnLastWindowClosed(bool quit) {
--- trunk/playground/bindings/kimono/qdbus/QDBusArgument.cs #632281:632282
@@ -196,6 +196,7 @@
public bool AtEnd() {
return ProxyQDBusArgument().AtEnd();
}
+ // QDBusArgument* QDBusArgument(QDBusArgumentPrivate* arg1); >>>> NOT CONVERTED
~QDBusArgument() {
DisposeQDBusArgument();
}
--- trunk/playground/bindings/kimono/qyoto.cpp #632281:632282
@@ -80,6 +80,8 @@
// Maps from a classname in the form Qt::Widget to an int id
QHash<int,char *> classname;
+extern bool qRegisterResourceData(int, const unsigned char *, const unsigned char *, const unsigned char *);
+extern bool qUnregisterResourceData(int, const unsigned char *, const unsigned char *, const unsigned char *);
extern "C" {
extern void * set_obj_info(const char * className, smokeqyoto_object * o);
@@ -1153,6 +1155,17 @@
return set_obj_info("Qyoto.QVariant", vo);
}
+
+bool QyotoRegisterResourceData(int flag, const unsigned char * s, const unsigned char *n, const unsigned char *d)
+{
+ qRegisterResourceData(flag, s, n, d);
+}
+
+bool QyotoUnregisterResourceData(int flag, const unsigned char * s, const unsigned char *n, const unsigned char *d)
+{
+ qUnregisterResourceData(flag, s, n, d);
+}
+
void
InstallFreeGCHandle(FromIntPtr callback)
{
@@ -1364,7 +1377,7 @@
QMetaObject* parent_meta_object(void* obj) {
#ifdef DEBUG
-printf("In make_metaObject()\n");
+printf("ENTER make_metaObject()\n");
#endif
smokeqyoto_object* o = value_obj_info(obj);
Smoke::Index nameId = o->smoke->idMethodName("metaObject");
@@ -1555,16 +1568,10 @@
for (int i = 1; i <= qt_Smoke->numClasses; i++) {
className = classPrefix + qt_Smoke->classes[i].className;
-// printf("classname: %s id: %d\n", className.latin1(), i);
classStringName = className.toLatin1();
classname.insert(i, strdup(classStringName.constData()));
}
}
-void
-DeleteQApp() {
- delete qApp;
}
-}
-
--- trunk/playground/bindings/kimono/tools/csrcc/rcc.cpp #632281:632282
@@ -474,11 +474,11 @@
initName.replace(QRegExp("[^a-zA-Z0-9_]"), "_");
}
- fprintf(out, "public class QCleanupResources%s__dest_class__ {\n\n", initName.toLatin1().constData());
+ fprintf(out, "public class QInitResources%s__dest_class__ {\n\n", initName.toLatin1().constData());
fprintf(out, "[DllImport(\"libqyoto\", CharSet=CharSet.Ansi)]\n");
- fprintf(out, "public static extern void qRegisterResourceData(int flag, byte[] resource_struct, byte[] resource_name, byte[] resource_data);\n\n");
+ fprintf(out, "public static unsafe extern void QyotoRegisterResourceData(int flag, byte * resource_struct, byte * resource_name, byte * resource_data);\n\n");
fprintf(out, "[DllImport(\"libqyoto\", CharSet=CharSet.Ansi)]\n");
- fprintf(out, "public static extern void qUnregisterResourceData(int flag, byte[] resource_struct, byte[] resource_name, byte[] resource_data);\n\n");
+ fprintf(out, "public static unsafe extern void QyotoUnregisterResourceData(int flag, byte * resource_struct, byte * resource_name, byte * resource_data);\n\n");
} else if(mFormat == Binary) {
fprintf(out,"qres");
qt_rcc_write_number(out, 0, 4, mFormat);
@@ -627,26 +627,31 @@
}
//init
- fprintf(out, "static int QInitResources%s()\n{\n", initName.toLatin1().constData());
- fprintf(out, " qRegisterResourceData(0x01, qt_resource_struct, "
- "qt_resource_name, qt_resource_data);\n");
+ fprintf(out, "public static int QInitResources%s()\n{\n", initName.toLatin1().constData());
+ fprintf(out, " unsafe {\n");
+ fprintf(out, " fixed (byte *s = qt_resource_struct, n = qt_resource_name, d = qt_resource_data)\n");
+
+ // Make the call here, passing in the array.
+ fprintf(out, " QyotoRegisterResourceData(0x01, s, n, d);\n");
+ fprintf(out, " }\n");
fprintf(out, " return 1;\n");
fprintf(out, "}\n\n");
-// fprintf(out, "Q_CONSTRUCTOR_FUNCTION(qInitResources%s)\n",
-// initName.toLatin1().constData());
- fprintf(out, "static QCleanupResources%s__dest_class__() {\n", initName.toLatin1().constData());
+
+ fprintf(out, "static QInitResources%s__dest_class__() {\n", initName.toLatin1().constData());
fprintf(out, " QInitResources%s();\n", initName.toLatin1().constData());
fprintf(out, "}\n\n");
//cleanup
- fprintf(out, "static int QCleanupResources%s()\n{\n", initName.toLatin1().constData());
- fprintf(out, " qUnregisterResourceData(0x01, qt_resource_struct, "
- "qt_resource_name, qt_resource_data);\n");
+ fprintf(out, "public static int QCleanupResources%s()\n{\n", initName.toLatin1().constData());
+ fprintf(out, " unsafe {\n");
+ fprintf(out, " fixed (byte *s = qt_resource_struct, n = qt_resource_name, d = qt_resource_data)\n");
+
+ // Make the call here, passing in the array.
+ fprintf(out, " QyotoUnregisterResourceData(0x01, s, n, d);\n");
+ fprintf(out, " }\n");
fprintf(out, " return 1;\n");
fprintf(out, "}\n\n");
fprintf(out, "}\n");
-// fprintf(out, "Q_DESTRUCTOR_FUNCTION(qCleanupResources%s)\n",
-// initName.toLatin1().constData());
} else if(mFormat == Binary) {
const long old_pos = ftell(out);
fseek(out, 4, SEEK_SET);
More information about the Kde-bindings
mailing list