[Kde-bindings] KDE/kdebindings/csharp/plasma

Arno Rehn kde at arnorehn.de
Thu Jul 3 16:34:47 UTC 2008


SVN commit 827703 by arnorehn:

* Camelize the folder and file names to get a proper type name
* Instantiate the class from the resulting type name.
* Basic example works now.

CCMAIL: kde-bindings at kde.org



 M  +1 -1      plasma-scriptengine-mono-applet.desktop  
 M  +33 -5     src/PlasmaScriptengineKimono_Applet.cs  


--- trunk/KDE/kdebindings/csharp/plasma/plasma-scriptengine-mono-applet.desktop #827702:827703
@@ -7,5 +7,5 @@
 X-KDE-PluginKeyword=PlasmaScriptengineKimono/Applet.dll
 X-EngineName=kimono-applet-script
 X-Plasma-API=mono-script
-X-Plasma-PackageFormat=Monoid
+# X-Plasma-PackageFormat=Monoid
 X-Plasma-ComponentTypes=Applet
--- trunk/KDE/kdebindings/csharp/plasma/src/PlasmaScriptengineKimono_Applet.cs #827702:827703
@@ -1,21 +1,49 @@
 namespace PlasmaScriptengineKimono {
-	using Plasma;
+
 	using System;
-	using Kimono;
-	using Qyoto;
+	using System.Text;
+	using System.Reflection;
 	using System.Collections.Generic;
 
+	using Qyoto;
+	using Kimono;
+	using Plasma;
+
 	public class Applet : Plasma.AppletScript {
 		private PlasmaScripting.Applet applet;
+		private Assembly appletAssembly;
+		private Type appletType;
 
 		public Applet(QObject parent, List<QVariant> args) : base(parent) {
 		}
 
+		private string Camelize(string str) {
+			StringBuilder ret = new StringBuilder(str.Substring(0, 1).ToUpper());
+			for (int i = 1; i < str.Length; i++) {
+				if (str[i] == '_' || str[i] == '-') {
+					i++;
+					if (i < str.Length)
+						ret.Append(str.Substring(i, 1).ToUpper());
+				} else {
+					ret.Append(str[i]);
+				}
+			}
+			return ret.ToString();
+		}
+
 		public virtual bool Init() {
 			Applet().Resize(200, 200);
 			QFileInfo program = new QFileInfo(MainScript());
-			Console.WriteLine("going to load {0}", MainScript());
-			return false;
+			
+			appletAssembly = Assembly.LoadFile(program.AbsoluteFilePath());
+			
+			string typeName = Camelize(Package().Metadata().PluginName()) + ".";  // namespace
+			typeName += Camelize(program.CompleteBaseName());
+			appletType = appletAssembly.GetType(typeName);
+			
+			applet = (PlasmaScripting.Applet) Activator.CreateInstance(appletType, new object[] { this });
+			applet.Init();
+			return true;
 		}
 
 		public virtual void PaintInterface(QPainter painter, QStyleOptionGraphicsItem option, QRect contentsRect) {



More information about the Kde-bindings mailing list