media-export: Implement MediaContainer.add_item()
authorJens Georg <mail@jensge.org>
Mon, 8 Feb 2010 10:10:52 +0000 (11:10 +0100)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Sat, 13 Feb 2010 16:24:46 +0000 (18:24 +0200)
MediaExport now has it's own implementation of MediaContainer that is
specifically meant for adding a complete add_item() implementation to
MediaDBContainer.

src/plugins/media-export/Makefile.am
src/plugins/media-export/rygel-media-export-object-factory.vala
src/plugins/media-export/rygel-media-export-writable-container.vala [new file with mode: 0644]

index aec8ee7..e19f78b 100644 (file)
@@ -22,6 +22,7 @@ librygel_media_export_la_SOURCES = rygel-media-export-plugin.vala \
                                   rygel-media-export-recursive-file-monitor.vala \
                                   rygel-media-export-harvester.vala \
                                   rygel-media-export-item.vala \
+                                  rygel-media-export-writable-container.vala \
                                   rygel-media-export-object-factory.vala
 
 librygel_media_export_la_VALAFLAGS = --vapidir=$(top_srcdir)/src/rygel \
index 9fd3d02..4ccaf70 100644 (file)
  */
 
 internal class Rygel.MediaExportObjectFactory : MediaDBObjectFactory {
+    public override MediaContainer get_container (MediaDB media_db,
+                                                  string  id,
+                                                  string  title,
+                                                  uint    child_count) {
+        return new MediaExportWritableContainer (media_db, id, title);
+    }
 }
diff --git a/src/plugins/media-export/rygel-media-export-writable-container.vala b/src/plugins/media-export/rygel-media-export-writable-container.vala
new file mode 100644 (file)
index 0000000..8d62603
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 Jens Georg <mail@jensge.org>.
+ * Copyright (C) 2010 Nokia Corporation.
+ *
+ * Author: Jens Georg <mail@jensge.org>
+ *         Zeeshan Ali (Khattak) <zeeshan.ali@nokia.com>
+ *                               <zeeshanak@gnome.org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+internal class Rygel.MediaExportWritableContainer : MediaDBContainer {
+    public MediaExportWritableContainer (MediaDB media_db,
+                                         string  id,
+                                         string  title) {
+        base (media_db, id, title);
+    }
+
+    public override async void add_item (MediaItem    item,
+                                         Cancellable? cancellable)
+                                         throws Error {
+        yield base.add_item (item, cancellable);
+
+        item.parent = this;
+        item.id = Checksum.compute_for_string (ChecksumType.MD5, item.uris[0]);
+        this.media_db.save_item (item);
+    }
+}