[rygel] tracker: Move add_item() to CategoryAllContainer



commit ea1d96d073726c7732e73d5bf6fa936f7ced73bf
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Fri Feb 19 17:03:05 2010 +0200

    tracker: Move add_item() to CategoryAllContainer
    
    Move add_item implementation to CategoryAllContainer. The item was being
    added to these containers in the end anyway so why not be honest and add
    the item in the container for which the client sends the item addition
    request.

 .../rygel-tracker-category-all-container.vala      |   21 ++++++++++++++
 .../tracker/rygel-tracker-category-container.vala  |   21 --------------
 .../tracker/rygel-tracker-item-creation.vala       |   29 +++++++++----------
 3 files changed, 35 insertions(+), 36 deletions(-)
---
diff --git a/src/plugins/tracker/rygel-tracker-category-all-container.vala b/src/plugins/tracker/rygel-tracker-category-all-container.vala
index b2aaf70..02406f2 100644
--- a/src/plugins/tracker/rygel-tracker-category-all-container.vala
+++ b/src/plugins/tracker/rygel-tracker-category-all-container.vala
@@ -30,6 +30,27 @@ using Gee;
 public class Rygel.TrackerCategoryAllContainer : Rygel.TrackerSearchContainer {
     public TrackerCategoryAllContainer (TrackerCategoryContainer parent) {
         base ("All" + parent.id, parent, "All", parent.item_factory);
+
+        try {
+            var uri = Filename.to_uri (item_factory.upload_dir, null);
+            this.uris.add (uri);
+        } catch (ConvertError error) {
+            warning ("Failed to contstruct URI for directory '%s': %s",
+                     item_factory.upload_dir,
+                     error.message);
+        }
+    }
+
+    public async override void add_item (MediaItem    item,
+                                         Cancellable? cancellable)
+                                         throws Error {
+        assert (this.uris.size > 0);
+
+        var creation = new TrackerItemCreation (item, this, cancellable);
+        yield creation.run ();
+        if (creation.error != null) {
+            throw creation.error;
+        }
     }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-category-container.vala b/src/plugins/tracker/rygel-tracker-category-container.vala
index 1105022..30920ac 100644
--- a/src/plugins/tracker/rygel-tracker-category-container.vala
+++ b/src/plugins/tracker/rygel-tracker-category-container.vala
@@ -38,27 +38,6 @@ public class Rygel.TrackerCategoryContainer : Rygel.SimpleContainer {
         this.item_factory = item_factory;
 
         this.add_child (new TrackerCategoryAllContainer (this));
-
-        try {
-            var uri = Filename.to_uri (item_factory.upload_dir, null);
-            this.uris.add (uri);
-        } catch (ConvertError error) {
-            warning ("Failed to contstruct URI for directory '%s': %s",
-                     item_factory.upload_dir,
-                     error.message);
-        }
-    }
-
-    public async override void add_item (MediaItem    item,
-                                         Cancellable? cancellable)
-                                         throws Error {
-        assert (this.uris.size > 0);
-
-        var creation = new TrackerItemCreation (item, this, cancellable);
-        yield creation.run ();
-        if (creation.error != null) {
-            throw creation.error;
-        }
     }
 }
 
diff --git a/src/plugins/tracker/rygel-tracker-item-creation.vala b/src/plugins/tracker/rygel-tracker-item-creation.vala
index e928d01..39b3a54 100644
--- a/src/plugins/tracker/rygel-tracker-item-creation.vala
+++ b/src/plugins/tracker/rygel-tracker-item-creation.vala
@@ -37,16 +37,16 @@ public class Rygel.TrackerItemCreation : GLib.Object, Rygel.StateMachine {
     public Error error { get; set; }
 
     private MediaItem item;
-    private TrackerCategoryContainer category_container;
+    private TrackerCategoryAllContainer container;
     private TrackerResourcesIface resources;
     private TrackerMinerIface miner;
 
-    public TrackerItemCreation (MediaItem                item,
-                                TrackerCategoryContainer category_container,
-                                Cancellable?             cancellable)
+    public TrackerItemCreation (MediaItem                   item,
+                                TrackerCategoryAllContainer container,
+                                Cancellable?                cancellable)
                                 throws Error {
         this.item = item;
-        this.category_container = category_container;
+        this.container = container;
         this.cancellable = cancellable;
         this.create_proxies ();
     }
@@ -65,18 +65,18 @@ public class Rygel.TrackerItemCreation : GLib.Object, Rygel.StateMachine {
 
             var new_item = yield this.get_new_item ();
             this.item.id = new_item.id;
-            this.item.parent = new_item.parent;
+            this.item.parent = container;
         } catch (GLib.Error error) {
             this.error = error;
         }
     }
 
     private async File prepare_file () throws Error {
-        var dir = yield this.category_container.get_writable (cancellable);
+        var dir = yield this.container.get_writable (cancellable);
         if (dir == null) {
             throw new ContentDirectoryError.RESTRICTED_PARENT (
                     "Object creation in %s no allowed",
-                    this.category_container.id);
+                    this.container.id);
         }
 
         var file = dir.get_child_for_display_name (this.item.title);
@@ -87,7 +87,7 @@ public class Rygel.TrackerItemCreation : GLib.Object, Rygel.StateMachine {
     }
 
     private async void create_entry_in_store () throws Error {
-        var category = this.category_container.item_factory.category;
+        var category = this.container.item_factory.category;
         var query = new TrackerInsertionQuery (this.item, category);
 
         yield query.execute (this.resources);
@@ -99,12 +99,11 @@ public class Rygel.TrackerItemCreation : GLib.Object, Rygel.StateMachine {
         expression.operand1 = "res";
         expression.operand2 = this.item.uris[0];
         uint total_matches;
-        var search_results = yield this.category_container.search (
-                                        expression,
-                                        0,
-                                        1,
-                                        out total_matches,
-                                        this.cancellable);
+        var search_results = yield this.container.search (expression,
+                                                          0,
+                                                          1,
+                                                          out total_matches,
+                                                          this.cancellable);
 
         return search_results[0] as MediaItem;
     }



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