media-export: Extract some common functionality
authorJens Georg <jensg@openismus.com>
Thu, 13 Dec 2012 11:13:06 +0000 (12:13 +0100)
committerJens Georg <jensg@openismus.com>
Thu, 13 Dec 2012 14:02:08 +0000 (15:02 +0100)
src/plugins/media-export/rygel-media-export-harvester.vala
src/plugins/media-export/rygel-media-export-harvesting-task.vala

index 82624ee..f0a0a0f 100644 (file)
@@ -64,6 +64,22 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
     }
 
     /**
+     * Check if a FileInfo is considered for extraction
+     *
+     * @param info a FileInfo
+     * @return true if file should be extracted, false otherwise
+     */
+    public static bool is_eligible (FileInfo info) {
+        return info.get_content_type ().has_prefix ("image/") ||
+               info.get_content_type ().has_prefix ("video/") ||
+               info.get_content_type ().has_prefix ("audio/") ||
+               info.get_content_type () == "application/ogg" ||
+               info.get_content_type () == "application/xml" ||
+               info.get_content_type () == "text/xml" ||
+               info.get_content_type () == "text/plain";
+    }
+
+    /**
      * Put a file on queue for meta-data extraction
      *
      * @param file the file to investigate
@@ -153,13 +169,7 @@ internal class Rygel.MediaExport.Harvester : GLib.Object {
                                         FileQueryInfoFlags.NONE,
                                         this.cancellable);
             if (info.get_file_type () == FileType.DIRECTORY ||
-                info.get_content_type ().has_prefix ("image/") ||
-                info.get_content_type ().has_prefix ("video/") ||
-                info.get_content_type ().has_prefix ("audio/") ||
-                info.get_content_type () == "application/ogg" ||
-                info.get_content_type () == "application/xml" ||
-                info.get_content_type () == "text/xml" ||
-                info.get_content_type () == "text/plain") {
+                Harvester.is_eligible (info)) {
                 string id;
                 try {
                     MediaContainer parent_container = null;
index 6bc32d5..e487a49 100644 (file)
@@ -194,13 +194,7 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine,
         } else {
             // Check if the file needs to be harvested at all either because
             // it is denied by filter or it hasn't updated
-            if (info.get_content_type ().has_prefix ("image/") ||
-                info.get_content_type ().has_prefix ("video/") ||
-                info.get_content_type ().has_prefix ("audio/") ||
-                info.get_content_type () == "application/ogg" ||
-                info.get_content_type () == "application/xml" ||
-                info.get_content_type () == "text/xml" ||
-                info.get_content_type () == "text/plain") {
+            if (Harvester.is_eligible (info)) {
                 return this.push_if_changed_or_unknown (file, info);
             }