[seed] examples: Some cleanup to the DBus examples, shorten the code of the NetworkManager one a good bit



commit 5836610f6409e7560f65106b6f73c7e642558144
Author: Robert Carr <racarr svn gnome org>
Date:   Wed May 13 02:18:54 2009 -0400

    examples: Some cleanup to the DBus examples, shorten the code of the NetworkManager one a good bit
---
 examples/dbus/dbus-banshee.js        |   23 +++++++++++------------
 examples/dbus/dbus-consolekit.js     |   11 ++++++-----
 examples/dbus/dbus-networkmanager.js |   29 ++++++++++++-----------------
 3 files changed, 29 insertions(+), 34 deletions(-)

diff --git a/examples/dbus/dbus-banshee.js b/examples/dbus/dbus-banshee.js
index 77b0146..8edc7d0 100755
--- a/examples/dbus/dbus-banshee.js
+++ b/examples/dbus/dbus-banshee.js
@@ -8,10 +8,11 @@ function PlayerEngine() {
 
 PlayerEngine.prototype = {
     _init: function() {
-	DBus.session.proxifyObject (this, 'org.bansheeproject.Banshee','/org/bansheeproject/Banshee/PlayerEngine');
+	DBus.session.proxifyObject (this, 
+				    x'org.bansheeproject.Banshee',
+				    '/org/bansheeproject/Banshee/PlayerEngine');
     }
 };
-
 var PlayerEngineIface = {
     name: 'org.bansheeproject.Banshee.PlayerEngine',
     methods: [
@@ -37,20 +38,18 @@ var PlayerEngineIface = {
 	{ name: 'Length', signature: 'u', access: 'read' }
     ]
 };
-
-
 DBus.proxifyPrototype (PlayerEngine.prototype, PlayerEngineIface);
 
-proxy = new PlayerEngine();
-proxy.OpenRemote(Seed.argv[2]);
-proxy.PlayRemote(function(){
-    Seed.print("proxy.PlayRemote returned");
+engine = new PlayerEngine();
+engine.OpenRemote(Seed.argv[2]);
+engine.PlayRemote(function(){
+    Seed.print("engine.PlayRemote returned");
 });
 
-proxy.connect("StateChanged", 
-	      function(emitter, state){
-		  Seed.print("Banshee state changed: " + state);
-	      });
+engine.connect("StateChanged", 
+	       function(emitter, state){
+		   Seed.print("Banshee state changed: " + state);
+	       });
 
 mainloop = GLib.main_loop_new();
 GLib.main_loop_run(mainloop);
diff --git a/examples/dbus/dbus-consolekit.js b/examples/dbus/dbus-consolekit.js
index 2b08606..87345a4 100755
--- a/examples/dbus/dbus-consolekit.js
+++ b/examples/dbus/dbus-consolekit.js
@@ -5,20 +5,22 @@ GLib = imports.gi.GLib;
 function ConsoleKitManager() {
     this._init();
 }
-
 ConsoleKitManager.prototype = {
     _init: function() {
-	DBus.system.proxifyObject (this, 'org.freedesktop.ConsoleKit','/org/freedesktop/ConsoleKit/Manager');
+	DBus.system.proxifyObject (this, 
+				   'org.freedesktop.ConsoleKit',
+				   '/org/freedesktop/ConsoleKit/Manager');
     }
 };
 
 function ConsoleKitSession(path) {
     this._init(path);
 }
-
 ConsoleKitSession.prototype = {
     _init: function(path) {
-	DBus.system.proxifyObject (this, 'org.freedesktop.ConsoleKit', path);
+	DBus.system.proxifyObject (this, 
+				   'org.freedesktop.ConsoleKit',
+				   path);
     }
 };
 
@@ -28,7 +30,6 @@ var ManagerIface = {
 	{ name: 'GetCurrentSession', inSignature: '', outSignature: 'o' },
     ]
 };
-
 var SessionIFace = {
     name: 'org.freedesktop.ConsoleKit.Session',
     methods: [
diff --git a/examples/dbus/dbus-networkmanager.js b/examples/dbus/dbus-networkmanager.js
index 6b5efad..d69c061 100755
--- a/examples/dbus/dbus-networkmanager.js
+++ b/examples/dbus/dbus-networkmanager.js
@@ -65,34 +65,29 @@ function print_access_point (path){
     });
 }
 
-function handle_points (result){
-    for (var i=0; i<result.length; i++){
-	print_access_point(result[i]);
-    }
-}
 
 function print_wireless(path){
     wireless = new NetworkManagerWirelessDevice(path);
-    wireless.GetAccessPointsRemote (handle_points);
-}
-
-function handle_type (path){
-    return function(result){
-	if (result == 2)
-	    print_wireless(path);
-    }
+    wireless.GetAccessPointsRemote (function (result){
+	for (var i=0; i<result.length; i++){
+	    print_access_point(result[i]);
+	}
+    });
 }
-
 nm.GetDevicesRemote(
-    function (result, exception){
+    function (result){
 	for (var i = 0; i<result.length; i++){
 	    var dev = new NetworkManagerDevice(result[i]);
 	    var type = 
-		dev.GetRemote("DeviceType", handle_type (result[i]));
+		dev.GetRemote("DeviceType", function(path){
+		    return function(result){
+			if (result == 2)
+			    print_wireless (path);
+		    }
+		}(result[i]));
 	    }
     });
 
 var mainloop = GLib.main_loop_new();
 GLib.main_loop_run(mainloop);
 
-



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]