[rygel/wip/create-reference: 3/10] wip: Implement playlistContainer in media-export



commit f157f79a402080489069bd52299b37a7e8e63112
Author: Jens Georg <jensg openismus com>
Date:   Thu Feb 28 15:00:43 2013 +0100

    wip: Implement playlistContainer in media-export

 src/librygel-server/rygel-media-object.vala        |    2 +-
 src/plugins/media-export/Makefile.am               |    1 +
 .../rygel-media-export-object-factory.vala         |    4 +
 ...rygel-media-export-playlist-root-container.vala |   64 ++++++++++++++++++++
 .../rygel-media-export-writable-db-container.vala  |   24 +++++---
 5 files changed, 85 insertions(+), 10 deletions(-)
---
diff --git a/src/librygel-server/rygel-media-object.vala b/src/librygel-server/rygel-media-object.vala
index 6b3953a..7f488f8 100644
--- a/src/librygel-server/rygel-media-object.vala
+++ b/src/librygel-server/rygel-media-object.vala
@@ -266,7 +266,7 @@ public abstract class Rygel.MediaObject : GLib.Object {
     private async bool check_writable (File file, Cancellable? cancellable)
                                        throws Error {
         if (!file.is_native ()) {
-            return false;
+            return true;
         }
 
         try {
diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am
index 5921883..9ea1696 100644
--- a/src/plugins/media-export/Makefile.am
+++ b/src/plugins/media-export/Makefile.am
@@ -28,6 +28,7 @@ librygel_media_export_la_SOURCES = \
        rygel-media-export-jpeg-writer.vala \
        rygel-media-export-object-factory.vala \
        rygel-media-export-writable-db-container.vala \
+       rygel-media-export-playlist-root-container.vala \
        rygel-media-export-music-item.vala \
        rygel-media-export-video-item.vala \
        rygel-media-export-photo-item.vala \
diff --git a/src/plugins/media-export/rygel-media-export-object-factory.vala 
b/src/plugins/media-export/rygel-media-export-object-factory.vala
index 1b62107..fb9cbf9 100644
--- a/src/plugins/media-export/rygel-media-export-object-factory.vala
+++ b/src/plugins/media-export/rygel-media-export-object-factory.vala
@@ -50,6 +50,10 @@ internal class Rygel.MediaExport.ObjectFactory : Object {
             return factory.create_from_hashed_id (id, title);
         }
 
+        if (id.has_prefix ("virtual-parent:" + Rygel.PlaylistItem.UPNP_CLASS)) {
+            return new PlaylistRootContainer (id, title);
+        }
+
         // Return a suitable container for the top-level virtual folders.
         // This corresponds to the short-lived NullContainers that
         // we used to save these in the database.
diff --git a/src/plugins/media-export/rygel-media-export-playlist-root-container.vala 
b/src/plugins/media-export/rygel-media-export-playlist-root-container.vala
new file mode 100644
index 0000000..ef0cb39
--- /dev/null
+++ b/src/plugins/media-export/rygel-media-export-playlist-root-container.vala
@@ -0,0 +1,64 @@
+using Gee;
+
+internal class Rygel.MediaExport.PlaylistRootContainer : Rygel.WritableContainer,
+                                                         DBContainer {
+    public ArrayList<string> create_classes { get; set; }
+
+    public PlaylistRootContainer (string id, string title) {
+        Object (id : id,
+                title : title,
+                parent : null,
+                child_count : 0);
+    }
+
+    public override void constructed () {
+        base.constructed ();
+
+        // We don't support adding real folders here, just playlist container
+        this.create_classes = new ArrayList<string> ();
+        this.create_classes.add (Rygel.MediaContainer.PLAYLIST);
+
+        this.uris.add ("rygel://playlist-root");
+
+        debug ("=> Updated create_classes");
+    }
+
+    public async void add_item (Rygel.MediaItem item,
+                                         Cancellable?    cancellable)
+                                         throws Error {
+        // FIXME: Add translation
+        throw new WriteableContainerError.NOT_IMPLEMENTED
+                                        ("Can't create items here");
+    }
+
+    public async void remove_item (string id,
+                                            Cancellable?    cancellable)
+                                            throws Error {
+        // FIXME: Add translation
+        throw new WriteableContainerError.NOT_IMPLEMENTED
+                                        ("Can't create items here");
+    }
+
+    public async void add_container (Rygel.MediaContainer container,
+                                              Cancellable?         cancellable)
+                                              throws Error {
+        if (container.upnp_class != Rygel.MediaContainer.PLAYLIST) {
+            warning ("===========> Foo! %s %s", container.upnp_class,
+                     Rygel.MediaContainer.PLAYLIST);
+            throw new WriteableContainerError.NOT_IMPLEMENTED
+                                        ("upnp:class not supported");
+        }
+
+        // FIXME: Do something here :)
+        assert_not_reached ();
+    }
+
+    public async void remove_container (string id,
+                                                 Cancellable?    cancellable)
+                                                 throws Error {
+        // FIXME: Add translation
+        throw new WriteableContainerError.NOT_IMPLEMENTED
+                                        ("Can't create items here");
+    }
+
+ }
diff --git a/src/plugins/media-export/rygel-media-export-writable-db-container.vala 
b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
index 023d3be..0938cc5 100644
--- a/src/plugins/media-export/rygel-media-export-writable-db-container.vala
+++ b/src/plugins/media-export/rygel-media-export-writable-db-container.vala
@@ -56,8 +56,13 @@ internal class Rygel.MediaExport.WritableDbContainer : TrackableDbContainer,
         this.create_classes.add (Rygel.MediaContainer.STORAGE_FOLDER);
     }
 
-    public async void add_item (Rygel.MediaItem item, Cancellable? cancellable)
-                                throws Error {
+    public virtual async void add_item (Rygel.MediaItem item,
+                                        Cancellable? cancellable)
+                                        throws Error {
+        if (item.id == null && item.ref_id != null) {
+            warning ("=> CreateReference not supported");
+            throw new WriteableContainerError.NOT_IMPLEMENTED ("Not supported");
+        }
         item.parent = this;
         var file = File.new_for_uri (item.uris[0]);
         // TODO: Mark as place-holder. Make this proper some time.
@@ -69,9 +74,9 @@ internal class Rygel.MediaExport.WritableDbContainer : TrackableDbContainer,
         this.media_db.make_object_guarded (item);
     }
 
-    public async void add_container (MediaContainer container,
-                                     Cancellable?   cancellable)
-                                     throws Error {
+    public virtual async void add_container (MediaContainer container,
+                                             Cancellable?   cancellable)
+                                             throws Error {
         container.parent = this;
         switch (container.upnp_class) {
         case MediaContainer.STORAGE_FOLDER:
@@ -91,15 +96,16 @@ internal class Rygel.MediaExport.WritableDbContainer : TrackableDbContainer,
         this.media_db.make_object_guarded (container);
     }
 
-    public async void remove_item (string id, Cancellable? cancellable)
-                                   throws Error {
+    public virtual async void remove_item (string id, Cancellable? cancellable)
+                                           throws Error {
         var object = this.media_db.get_object (id);
 
         yield this.remove_child_tracked (object);
     }
 
-    public async void remove_container (string id, Cancellable? cancellable)
-                                        throws Error {
+    public virtual async void remove_container (string id,
+                                                Cancellable? cancellable)
+                                                throws Error {
         throw new WritableContainerError.NOT_IMPLEMENTED ("Not supported");
     }
 


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