From 87ec0afffc96cc4d10d5407a896d28deebd26f00 Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Thu, 22 Sep 2011 18:51:48 +0200 Subject: [PATCH] core: Check availability of DBus interface Only show debug message if thumbnail DBus service is not available and also not activatable. --- src/rygel/rygel-dbus-thumbnailer.vala | 35 ++++++++++++++++++++++++++++++----- src/rygel/rygel-thumbnailer.vala | 8 +++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/rygel/rygel-dbus-thumbnailer.vala b/src/rygel/rygel-dbus-thumbnailer.vala index 3a48316..ec289d3 100644 --- a/src/rygel/rygel-dbus-thumbnailer.vala +++ b/src/rygel/rygel-dbus-thumbnailer.vala @@ -39,6 +39,8 @@ internal class Rygel.DbusThumbnailer : GLib.Object { private bool is_running = false; private string file_path; + public bool available { get; private set; } + const string THUMBNAILER_IFACE = "org.freedesktop.thumbnails.Thumbnailer1"; const string THUMBNAILER_SERVICE = "/org/freedesktop/thumbnails/Thumbnailer1"; @@ -51,12 +53,35 @@ internal class Rygel.DbusThumbnailer : GLib.Object { public DbusThumbnailer () throws GLib.IOError { - this.tumbler = GLib.Bus.get_proxy_sync (BusType.SESSION, - THUMBNAILER_IFACE, - THUMBNAILER_SERVICE); + this.available = false; + Bus.watch_name (BusType.SESSION, + THUMBNAILER_IFACE, + BusNameWatcherFlags.AUTO_START, + this.on_name_available, + this.on_name_unavailable); + + } + + public void on_name_available (DBusConnection connection, + string name, + string owner) { + try { + this.tumbler = connection.get_proxy_sync (THUMBNAILER_IFACE, + THUMBNAILER_SERVICE); + + tumbler.Finished.connect (on_finished); + tumbler.Error.connect (on_error); + this.available = true; + debug ("DBus thumbnailer service available"); + } catch (Error error) { + this.available = false; + } + } - tumbler.Finished.connect (on_finished); - tumbler.Error.connect (on_error); + public void on_name_unavailable (DBusConnection connection, + string name) { + this.available = false; + debug ("DBus thumbnailer service not available"); } public async void create_thumbnail_task (string file_path, diff --git a/src/rygel/rygel-thumbnailer.vala b/src/rygel/rygel-thumbnailer.vala index 3f3fb5d..40d1e56 100644 --- a/src/rygel/rygel-thumbnailer.vala +++ b/src/rygel/rygel-thumbnailer.vala @@ -77,8 +77,8 @@ internal class Rygel.Thumbnailer : GLib.Object { try { this.thumbler = new DbusThumbnailer (); - } catch (GLib.IOError error) {} - + } catch (GLib.Error error) { + } } public static Thumbnailer? get_default () { @@ -104,7 +104,9 @@ internal class Rygel.Thumbnailer : GLib.Object { 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 ())) { + if (this.thumbler != null && + this.thumbler.available && + !file.query_exists ()) { this.thumbler.create_thumbnail_task (uri, mime_type, "normal"); } -- 2.7.4