core: Clean-up MediaQueryAction and its subclasses
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Fri, 23 Jul 2010 16:53:32 +0000 (19:53 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Fri, 23 Jul 2010 16:53:32 +0000 (19:53 +0300)
Cleaner way to handle error messages and ObjectID argument name in
MediaQueryAction and its implementations.

src/rygel/rygel-browse.vala
src/rygel/rygel-media-query-action.vala
src/rygel/rygel-search.vala

index b89b428..46dfef7 100644 (file)
@@ -37,10 +37,13 @@ internal class Rygel.Browse: Rygel.MediaQueryAction {
 
     public Browse (ContentDirectory    content_dir,
                    owned ServiceAction action) {
-        base (content_dir,
-              action,
-              "ObjectID",
-              _("Failed to browse '%s': %s\n"));
+        base (content_dir, action);
+
+        if (this.xbox_hacks != null) {
+            this.object_id_arg = "ContainerID";
+        } else {
+            this.object_id_arg = "ObjectID";
+        }
     }
 
     protected override void parse_args () throws Error {
@@ -113,5 +116,13 @@ internal class Rygel.Browse: Rygel.MediaQueryAction {
 
         return children;
     }
+
+    protected override void handle_error (Error error) {
+        warning (_("Failed to browse '%s': %s\n"),
+                 this.object_id,
+                 error.message);
+
+        base.handle_error (error);
+    }
 }
 
index a5e51af..600544e 100644 (file)
@@ -47,20 +47,15 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
     protected ServiceAction action;
     protected Rygel.DIDLLiteWriter didl_writer;
     protected XBoxHacks xbox_hacks;
+    protected string object_id_arg;
 
-    private string object_id_arg;
-    private string error_message;
 
     protected MediaQueryAction (ContentDirectory    content_dir,
-                                owned ServiceAction action,
-                                string              object_id_arg,
-                                string              error_message) {
+                                owned ServiceAction action) {
         this.root_container = content_dir.root_container;
         this.system_update_id = content_dir.system_update_id;
         this.cancellable = content_dir.cancellable;
         this.action = (owned) action;
-        this.object_id_arg = object_id_arg;
-        this.error_message = error_message;
 
         this.didl_writer = new Rygel.DIDLLiteWriter (content_dir.http_server);
 
@@ -116,13 +111,6 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
                              out this.sort_criteria);
 
         if (this.object_id == null) {
-            /* Stupid Xbox */
-            this.action.get ("ContainerID",
-                                 typeof (string),
-                                 out this.object_id);
-        }
-
-        if (this.object_id == null) {
             // Sorry we can't do anything without ObjectID
             throw new ContentDirectoryError.NO_SUCH_OBJECT (
                                         _("No such object"));
@@ -183,9 +171,7 @@ internal abstract class Rygel.MediaQueryAction : GLib.Object, StateMachine {
         this.completed ();
     }
 
-    private void handle_error (Error error) {
-        warning (this.error_message, this.object_id, error.message);
-
+    protected virtual void handle_error (Error error) {
         if (error is ContentDirectoryError) {
             this.action.return_error (error.code, error.message);
         } else {
index e05b780..8ec2fe8 100644 (file)
@@ -34,10 +34,9 @@ internal class Rygel.Search:  Rygel.MediaQueryAction {
 
     public Search (ContentDirectory    content_dir,
                    owned ServiceAction action) {
-        base (content_dir,
-              action,
-              "ContainerID",
-              _("Failed to search in '%s': %s"));
+        base (content_dir, action);
+
+        this.object_id_arg = "ContainerID";
     }
 
     protected override void parse_args () throws Error {
@@ -79,5 +78,13 @@ internal class Rygel.Search:  Rygel.MediaQueryAction {
 
         return results;
     }
+
+    protected override void handle_error (Error error) {
+        warning (_("Failed to search in '%s': %s"),
+                 this.object_id,
+                 error.message);
+
+        base.handle_error (error);
+    }
 }