[rygel] core: Request thumbnails via DBus



commit c51b185f89a3ced334efddc384f39f4cd0771b22
Author: Lukasz Pawlik <lucas pawlik gmail com>
Date:   Tue Aug 30 12:33:07 2011 +0200

    core: Request thumbnails via DBus
    
    This patch add functionality to generate thumbnails for visual media
    items. Service tumblerd will be used to create thumbnail. Communication
    with tumblerd is done via D-Bus.
    
    Previously thumbnails were only read from ~/.thumbnails directory. If
    thumbnail was not present int that directory rygel could not provide it.
    This patch adds functionality to send request to create thumbnail for
    visualitem. Patch was added to satisfy 7.3.60.3 DLNA requirement.
    
    Slightly modified by Jens Georg <mail jensge org>

 src/rygel/Makefile.am                 |    1 +
 src/rygel/rygel-dbus-thumbnailer.vala |   98 +++++++++++++++++++++++++++++++++
 src/rygel/rygel-image-item.vala       |    2 +-
 src/rygel/rygel-thumbnailer.vala      |   14 ++++-
 src/rygel/rygel-video-item.vala       |    2 +-
 src/rygel/rygel-visual-item.vala      |    4 +-
 6 files changed, 116 insertions(+), 5 deletions(-)
---
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index b3d3d83..aec85e1 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -76,6 +76,7 @@ VAPI_SOURCE_FILES = \
 	rygel-photo-item.vala \
 	rygel-thumbnail.vala \
 	rygel-thumbnailer.vala \
+	rygel-dbus-thumbnailer.vala \
 	rygel-media-art-store.vala \
 	rygel-subtitle.vala \
 	rygel-subtitle-manager.vala \
diff --git a/src/rygel/rygel-dbus-thumbnailer.vala b/src/rygel/rygel-dbus-thumbnailer.vala
new file mode 100644
index 0000000..3a48316
--- /dev/null
+++ b/src/rygel/rygel-dbus-thumbnailer.vala
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2011 Nokia Corporation.
+ *
+ * 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.
+ */
+
+[DBus (name = "org.freedesktop.thumbnails.Thumbnailer1")]
+interface Tumbler : GLib.Object {
+        public abstract async uint Queue (string[] uris,
+                                          string[] mime_types,
+                                          string flavor,
+                                          string sheduler,
+                                          uint handle) throws GLib.IOError;
+
+        public signal void Finished (uint handle);
+        public signal void Error (uint handle,
+                                  string[] failed_uris,
+                                  int error_code,
+                                  string message);
+}
+
+
+internal class Rygel.DbusThumbnailer : GLib.Object {
+    private Tumbler tumbler;
+    private bool is_running  = false;
+    private string file_path;
+
+    const string THUMBNAILER_IFACE = "org.freedesktop.thumbnails.Thumbnailer1";
+    const string THUMBNAILER_SERVICE =
+                                    "/org/freedesktop/thumbnails/Thumbnailer1";
+
+    public signal void generated (string file_path);
+    public signal void error (string file_path,
+                              int error_code,
+                              string message);
+
+
+
+    public DbusThumbnailer () throws GLib.IOError {
+        this.tumbler = GLib.Bus.get_proxy_sync (BusType.SESSION,
+                                                THUMBNAILER_IFACE,
+                                                THUMBNAILER_SERVICE);
+
+        tumbler.Finished.connect (on_finished);
+        tumbler.Error.connect (on_error);
+    }
+
+    public async void create_thumbnail_task (string file_path,
+                                             string mime,
+                                             string flavor) {
+        string uris[1];
+        string mimes[1];
+
+        if (in_progress ()) {
+            return;
+        }
+
+        this.is_running = true;
+        this.file_path = file_path;
+
+        uris[0] = file_path;
+        mimes[0] = mime;
+
+        try {
+            yield this.tumbler.Queue (uris, mimes, flavor, "default", 0);
+        } catch (GLib.IOError e) {}
+    }
+
+    public bool in_progress () {
+        return this.is_running;
+    }
+
+    private void on_finished (uint handle) {
+        generated (this.file_path);
+        this.is_running = false;
+    }
+
+    private void on_error (uint handle,
+                           string[] failed_uris,
+                           int error_code,
+                           string message) {
+        error (this.file_path, error_code, message);
+    }
+}
diff --git a/src/rygel/rygel-image-item.vala b/src/rygel/rygel-image-item.vala
index 3bdf9b6..c1972ff 100644
--- a/src/rygel/rygel-image-item.vala
+++ b/src/rygel/rygel-image-item.vala
@@ -55,7 +55,7 @@ public class Rygel.ImageItem : MediaItem, VisualItem {
     public override void add_uri (string uri) {
         base.add_uri (uri);
 
-        this.add_thumbnail_for_uri (uri);
+        this.add_thumbnail_for_uri (uri, this.mime_type);
     }
 
     internal override void add_resources (DIDLLiteItem didl_item,
diff --git a/src/rygel/rygel-thumbnailer.vala b/src/rygel/rygel-thumbnailer.vala
index dc909c0..3f3fb5d 100644
--- a/src/rygel/rygel-thumbnailer.vala
+++ b/src/rygel/rygel-thumbnailer.vala
@@ -39,6 +39,8 @@ internal class Rygel.Thumbnailer : GLib.Object {
     private Thumbnail template;
     private string extension;
 
+    private DbusThumbnailer thumbler = null;
+
     private Thumbnailer () throws ThumbnailerError {
         var dir = Path.build_filename (Environment.get_home_dir (),
                                        ".thumbnails",
@@ -72,6 +74,11 @@ internal class Rygel.Thumbnailer : GLib.Object {
         }
 
         this.directory = dir;
+
+        try {
+            this.thumbler = new DbusThumbnailer ();
+       } catch (GLib.IOError error) {}
+
     }
 
     public static Thumbnailer? get_default () {
@@ -88,7 +95,7 @@ internal class Rygel.Thumbnailer : GLib.Object {
         return thumbnailer;
     }
 
-    public Thumbnail get_thumbnail (string uri) throws Error {
+    public Thumbnail get_thumbnail (string uri, string mime_type) throws Error {
         Thumbnail thumbnail = null;
 
         var path = Checksum.compute_for_string (ChecksumType.MD5, uri) +
@@ -96,6 +103,11 @@ internal class Rygel.Thumbnailer : GLib.Object {
         var full_path = Path.build_filename (this.directory, path);
         var file = File.new_for_path (full_path);
 
+        // send a request to create thumbnail if it does not exist
+        if ((this.thumbler != null) && (!file.query_exists ())) {
+            this.thumbler.create_thumbnail_task (uri, mime_type, "normal");
+        }
+
         var info = file.query_info (FILE_ATTRIBUTE_ACCESS_CAN_READ + "," +
                                     FILE_ATTRIBUTE_STANDARD_SIZE,
                                     FileQueryInfoFlags.NONE,
diff --git a/src/rygel/rygel-video-item.vala b/src/rygel/rygel-video-item.vala
index 0a27b1d..36dbd04 100644
--- a/src/rygel/rygel-video-item.vala
+++ b/src/rygel/rygel-video-item.vala
@@ -60,7 +60,7 @@ public class Rygel.VideoItem : AudioItem, VisualItem {
     public override void add_uri (string uri) {
         base.add_uri (uri);
 
-        this.add_thumbnail_for_uri (uri);
+        this.add_thumbnail_for_uri (uri, this.mime_type);
 
         var subtitle_manager = SubtitleManager.get_default ();
 
diff --git a/src/rygel/rygel-visual-item.vala b/src/rygel/rygel-visual-item.vala
index e57132f..0352f65 100644
--- a/src/rygel/rygel-visual-item.vala
+++ b/src/rygel/rygel-visual-item.vala
@@ -38,13 +38,13 @@ public interface Rygel.VisualItem : MediaItem {
 
     public abstract ArrayList<Thumbnail> thumbnails { get; protected set; }
 
-    internal void add_thumbnail_for_uri (string uri) {
+    internal void add_thumbnail_for_uri (string uri, string mime_type) {
         // Lets see if we can provide the thumbnails
         var thumbnailer = Thumbnailer.get_default ();
 
         if (thumbnailer != null) {
             try {
-                var thumb = thumbnailer.get_thumbnail (uri);
+                var thumb = thumbnailer.get_thumbnail (uri, this.mime_type);
                 this.thumbnails.add (thumb);
             } catch (Error err) {}
         }



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