[rygel] media-export: Remove Dynamic container



commit d50aae9d05ee2f58d8b1b3fcf8f6a8cb88be8e83
Author: Jens Georg <mail jensge org>
Date:   Fri Jul 23 23:25:49 2010 +0300

    media-export: Remove Dynamic container

 src/plugins/media-export/Makefile.am               |    1 -
 .../rygel-media-export-dynamic-container.vala      |   44 --------------------
 .../media-export/rygel-media-export-harvester.vala |   11 ++++-
 .../rygel-media-export-media-cache.vala            |   19 ++++++++
 .../rygel-media-export-root-container.vala         |   34 +++++++--------
 5 files changed, 44 insertions(+), 65 deletions(-)
---
diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am
index 47a4f8b..5f06c87 100644
--- a/src/plugins/media-export/Makefile.am
+++ b/src/plugins/media-export/Makefile.am
@@ -27,7 +27,6 @@ librygel_media_export_la_SOURCES = rygel-media-export-plugin.vala \
 				   rygel-media-export-metadata-extractor.vala \
 				   rygel-media-export-null-container.vala \
 				   rygel-media-export-dummy-container.vala \
-				   rygel-media-export-dynamic-container.vala \
 				   rygel-media-export-root-container.vala \
 				   rygel-media-export-query-container.vala \
 				   rygel-media-export-dbus-service.vala \
diff --git a/src/plugins/media-export/rygel-media-export-harvester.vala b/src/plugins/media-export/rygel-media-export-harvester.vala
index 4d0376d..c977add 100644
--- a/src/plugins/media-export/rygel-media-export-harvester.vala
+++ b/src/plugins/media-export/rygel-media-export-harvester.vala
@@ -31,6 +31,7 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
     private RecursiveFileMonitor monitor;
     private Regex file_filter;
     public Cancellable cancellable;
+    private string flag;
     private const string HARVESTER_ATTRIBUTES =
                                         FILE_ATTRIBUTE_STANDARD_NAME + "," +
                                         FILE_ATTRIBUTE_STANDARD_TYPE + "," +
@@ -41,7 +42,8 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
     public Harvester (MediaContainer       parent,
                       MediaCache           media_db,
                       MetadataExtractor    extractor,
-                      RecursiveFileMonitor monitor) {
+                      RecursiveFileMonitor monitor,
+                      string?              flag = null) {
         this.parent = parent;
         this.extractor = extractor;
         this.media_db = media_db;
@@ -52,6 +54,7 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
         this.origin = null;
         this.monitor = monitor;
         this.cancellable = new Cancellable ();
+        this.flag = flag;
         var config = MetaConfig.get_default ();
 
         try {
@@ -214,6 +217,12 @@ public class Rygel.MediaExport.Harvester : GLib.Object {
             enumerate_directory (directory);
         } else {
             // nothing to do
+            if (this.flag != null) {
+                try {
+                    this.media_db.flag_object (Item.get_id (this.origin),
+                                               this.flag);
+                } catch (Error error) {};
+            }
             harvested (this.origin);
         }
 
diff --git a/src/plugins/media-export/rygel-media-export-media-cache.vala b/src/plugins/media-export/rygel-media-export-media-cache.vala
index fd50eb0..f665aa1 100644
--- a/src/plugins/media-export/rygel-media-export-media-cache.vala
+++ b/src/plugins/media-export/rygel-media-export-media-cache.vala
@@ -914,4 +914,23 @@ public class Rygel.MediaExport.MediaCache : Object {
                                                     offset,
                                                     max_count);
     }
+
+    public void flag_object (string id, string flag) throws Error {
+        GLib.Value[] args = { flag, id };
+        this.db.exec ("UPDATE Object SET flags = ? WHERE upnp_id = ?", args);
+    }
+
+    public Gee.List<string> get_flagged_uris (string flag) throws Error {
+        var uris = new ArrayList<string> ();
+        GLib.Value[] args = { flag };
+        this.db.exec ("SELECT uri FROM object WHERE flags = ?",
+                      args,
+                      (statement) => {
+                          uris.add (statement.column_text (0));
+
+                          return true;
+                      });
+
+        return uris;
+    }
 }
diff --git a/src/plugins/media-export/rygel-media-export-root-container.vala b/src/plugins/media-export/rygel-media-export-root-container.vala
index e3c9a9f..8796643 100644
--- a/src/plugins/media-export/rygel-media-export-root-container.vala
+++ b/src/plugins/media-export/rygel-media-export-root-container.vala
@@ -29,7 +29,6 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
     private HashMap<File, Harvester> harvester;
     private RecursiveFileMonitor monitor;
     private DBusService service;
-    private DynamicContainer dynamic_elements;
     private Gee.List<Harvester> harvester_trash;
 
     private static MediaContainer instance = null;
@@ -45,10 +44,9 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
             uris = new ArrayList<string> ();
         }
 
-        var dbus_uris = this.dynamic_elements.get_uris ();
-        if (dbus_uris != null) {
-            uris.add_all (dbus_uris);
-        }
+        try {
+            uris.add_all (this.media_db.get_flagged_uris ("DBUS"));
+        } catch (Error error) {}
 
         return uris;
     }
@@ -68,7 +66,7 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
 
     public void add_uri (string uri) {
         var file = File.new_for_commandline_arg (uri);
-        this.harvest (file, this.dynamic_elements);
+        this.harvest (file, this, "DBUS");
     }
 
     public void remove_uri (string uri) {
@@ -235,9 +233,13 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
 
 
     public string[] get_dynamic_uris () {
-        var dynamic_uris = this.dynamic_elements.get_uris ();
+        try {
+            var uris = this.media_db.get_flagged_uris ("DBUS");
+
+            return uris.to_array ();
+        } catch (Error error) { }
 
-        return dynamic_uris.to_array ();
+        return new string[0];
     }
 
 
@@ -264,17 +266,12 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
             warning (_("Failed to create MediaExport DBus service: %s"),
                      err.message);
         }
-        this.dynamic_elements = new DynamicContainer (db, this);
 
         try {
             int64 timestamp;
             if (!this.media_db.exists ("0", out timestamp)) {
                 media_db.save_container (this);
             }
-
-            if (!this.media_db.exists ("DynamicContainerId", out timestamp)) {
-                media_db.save_container (this.dynamic_elements);
-            }
         } catch (Error error) { } // do nothing
 
         ArrayList<string> ids;
@@ -327,10 +324,6 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
         }
 
         foreach (var id in ids) {
-            if (id == DynamicContainer.ID) {
-                continue;
-            }
-
             debug (_("ID %s no longer in config, deleting..."), id);
             try {
                 this.media_db.remove_by_id (id);
@@ -354,7 +347,9 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
         this.harvester_trash.remove (harvester);
     }
 
-    private void harvest (File file, MediaContainer parent = this) {
+    private void harvest (File           file,
+                          MediaContainer parent = this,
+                          string?        flag   = null) {
         if (this.extractor == null) {
             warning (_("No Metadata extractor available. Will not crawl"));
 
@@ -373,7 +368,8 @@ public class Rygel.MediaExport.RootContainer : Rygel.MediaExport.DBContainer {
         var harvester = new Harvester (parent,
                                        this.media_db,
                                        this.extractor,
-                                       this.monitor);
+                                       this.monitor,
+                                       flag);
         harvester.harvested.connect (this.on_file_harvested);
         this.harvester[file] = harvester;
         harvester.harvest (file);



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