media-export: Remove Dynamic container
authorJens Georg <mail@jensge.org>
Fri, 23 Jul 2010 20:25:49 +0000 (23:25 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Sat, 24 Jul 2010 00:28:18 +0000 (03:28 +0300)
src/plugins/media-export/Makefile.am
src/plugins/media-export/rygel-media-export-dynamic-container.vala [deleted file]
src/plugins/media-export/rygel-media-export-harvester.vala
src/plugins/media-export/rygel-media-export-media-cache.vala
src/plugins/media-export/rygel-media-export-root-container.vala

index 47a4f8b..5f06c87 100644 (file)
@@ -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-dynamic-container.vala b/src/plugins/media-export/rygel-media-export-dynamic-container.vala
deleted file mode 100644 (file)
index 70ddb21..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2009 Jens Georg <mail@jensge.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.
- */
-using Gee;
-
-internal class Rygel.MediaExport.DynamicContainer : Rygel.MediaExport.DBContainer {
-    public const string ID = "DynamicContainerId";
-
-    public DynamicContainer (MediaCache media_db, MediaContainer parent) {
-        base (media_db, ID, "Dynamic");
-        this.parent = parent;
-    }
-
-    public Gee.List<string> get_uris () {
-        var result = new ArrayList<string> ();
-
-        try {
-            var children = this.media_db.get_children (this.id, -1, -1);
-            if (children != null) {
-                foreach (var child in children) {
-                    result.add_all (child.uris);
-                }
-            }
-        } catch (Error err) {}
-
-        return result;
-    }
-}
index 4d0376d..c977add 100644 (file)
@@ -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);
         }
 
index fd50eb0..f665aa1 100644 (file)
@@ -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;
+    }
 }
index e3c9a9f..8796643 100644 (file)
@@ -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);