[Xfce4-commits] <thunar:master> Move GetSupported() into the thumbnailer D-Bus API. Update client code.

Jannis Pohlmann noreply at xfce.org
Thu Oct 8 16:50:02 CEST 2009


Updating branch refs/heads/master
         to 4eef4962d6d56d43b1a27846ffcbd0c8b151c17d (commit)
       from 767a44d17636b11caf73a8c8fecc30270fff59d5 (commit)

commit 4eef4962d6d56d43b1a27846ffcbd0c8b151c17d
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Thu Oct 8 16:44:22 2009 +0200

    Move GetSupported() into the thumbnailer D-Bus API. Update client code.
    
    We now return URI scheme / MIME type pairs from GetSupported(), which
    was moved from the manager interface into the generic thumbnailer
    interface for semantic reasons. We therefor no longer need to generate
    bindings for the manager client as it is from now on only used to
    register specialized thumbnailers at runtime.

 thunar/Makefile.am                         |   12 +---
 thunar/thunar-thumbnailer-dbus.xml         |   11 +++
 thunar/thunar-thumbnailer-manager-dbus.xml |   14 ----
 thunar/thunar-thumbnailer.c                |  100 ++++++++--------------------
 4 files changed, 42 insertions(+), 95 deletions(-)

diff --git a/thunar/Makefile.am b/thunar/Makefile.am
index ee62564..5e0b3d2 100644
--- a/thunar/Makefile.am
+++ b/thunar/Makefile.am
@@ -250,16 +250,14 @@ Thunar_DEPENDENCIES =							\
 if HAVE_DBUS
 thunar_built_sources +=							\
 	thunar-dbus-service-infos.h					\
-	thunar-thumbnailer-proxy.h					\
-	thunar-thumbnailer-manager-proxy.h
+	thunar-thumbnailer-proxy.h
 
 thunar_dbus_sources =							\
 	thunar-dbus-client.c						\
 	thunar-dbus-client.h						\
 	thunar-dbus-service.c						\
 	thunar-dbus-service.h						\
-	thunar-thumbnailer-proxy.h					\
-	thunar-thumbnailer-manager-proxy.h
+	thunar-thumbnailer-proxy.h
 
 Thunar_CFLAGS +=							\
 	-DDBUS_API_SUBJECT_TO_CHANGE					\
@@ -334,12 +332,6 @@ thunar-thumbnailer-proxy.h: $(srcdir)/thunar-thumbnailer-dbus.xml Makefile
 		$(srcdir)/thunar-thumbnailer-dbus.xml > thunar-thumbnailer-proxy.h \
 	&& sed -i -e 's/org_freedesktop_thumbnails_Thumbnailer1/thunar_thumbnailer_proxy/g' \
 		thunar-thumbnailer-proxy.h
-
-thunar-thumbnailer-manager-proxy.h: $(srcdir)/thunar-thumbnailer-manager-dbus.xml Makefile
-	dbus-binding-tool --mode=glib-client \
-		$(srcdir)/thunar-thumbnailer-manager-dbus.xml > thunar-thumbnailer-manager-proxy.h \
-	&& sed -i -e 's/org_freedesktop_thumbnails_Manager1/thunar_thumbnailer_manager_proxy/g' \
-		thunar-thumbnailer-manager-proxy.h
 endif
 
 thunar-throbber-fallback.c: $(srcdir)/thunar-throbber-fallback.png Makefile
diff --git a/thunar/thunar-thumbnailer-dbus.xml b/thunar/thunar-thumbnailer-dbus.xml
index 84ecb65..d6ad2e9 100644
--- a/thunar/thunar-thumbnailer-dbus.xml
+++ b/thunar/thunar-thumbnailer-dbus.xml
@@ -15,6 +15,17 @@
       <arg type="u" name="handle" direction="in" />
     </method>
 
+    <method name="GetSupported">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="as" name="uri_schemes" direction="out" />
+      <arg type="as" name="mime_types" direction="out" />
+    </method>
+
+    <method name="GetSchedulers">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
+      <arg type="as" name="schedulers" direction="out" />
+    </method>
+
     <signal name="Started">
       <arg type="u" name="handle" />
     </signal>
diff --git a/thunar/thunar-thumbnailer-manager-dbus.xml b/thunar/thunar-thumbnailer-manager-dbus.xml
deleted file mode 100644
index e104b4f..0000000
--- a/thunar/thunar-thumbnailer-manager-dbus.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<node name="/org/freedesktop/thumbnails/Manager1">
-  <interface name="org.freedesktop.thumbnails.Manager1">
-    <method name="Register">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <arg type="s" name="uri_scheme" direction="in" />
-      <arg type="s" name="mime_type" direction="in" />
-    </method>
-    <method name="GetSupported">
-      <annotation name="org.freedesktop.DBus.GLib.Async" value="true"/>
-      <arg type="as" name="mime_types" direction="out" />
-    </method>
-  </interface>
-</node>
diff --git a/thunar/thunar-thumbnailer.c b/thunar/thunar-thumbnailer.c
index 6a6314e..97fc86f 100644
--- a/thunar/thunar-thumbnailer.c
+++ b/thunar/thunar-thumbnailer.c
@@ -27,7 +27,6 @@
 #include <dbus/dbus-glib.h>
 
 #include <thunar/thunar-thumbnailer-proxy.h>
-#include <thunar/thunar-thumbnailer-manager-proxy.h>
 #endif
 
 #include <thunar/thunar-marshal.h>
@@ -139,8 +138,6 @@ static void                   thunar_thumbnailer_finalize               (GObject
 #ifdef HAVE_DBUS              
 static void                   thunar_thumbnailer_init_thumbnailer_proxy (ThunarThumbnailer     *thumbnailer,
                                                                          DBusGConnection       *connection);
-static void                   thunar_thumbnailer_init_manager_proxy     (ThunarThumbnailer     *thumbnailer,
-                                                                         DBusGConnection       *connection);
 static gboolean               thunar_thumbnailer_file_is_supported      (ThunarThumbnailer     *thumbnailer,
                                                                          ThunarFile            *file);
 static void                   thunar_thumbnailer_thumbnailer_finished   (DBusGProxy            *proxy,
@@ -184,7 +181,6 @@ struct _ThunarThumbnailer
 
 #ifdef HAVE_DBUS
   /* proxies to communicate with D-Bus services */
-  DBusGProxy *manager_proxy;
   DBusGProxy *thumbnailer_proxy;
 
   /* wait queue used to delay (and thereby group) thumbnail requests */
@@ -205,7 +201,9 @@ struct _ThunarThumbnailer
 
   GMutex     *lock;
 
-  /* cached array of MIME types for which thumbnails can be generated */
+  /* cached arrays of URI schemes and MIME types for which thumbnails 
+   * can be generated */
+  gchar     **supported_schemes;
   gchar     **supported_types;
 
   /* last ThunarThumbnailer request ID */
@@ -246,9 +244,7 @@ struct _ThunarThumbnailerItem
 
 
 #ifdef HAVE_DBUS
-static DBusGProxy *thunar_thumbnailer_manager_proxy;
 static DBusGProxy *thunar_thumbnailer_proxy;
-static DBusGProxy *thunar_manager_proxy;
 #endif
 
 
@@ -275,6 +271,7 @@ thunar_thumbnailer_init (ThunarThumbnailer *thumbnailer)
   DBusGConnection *connection;
 
   thumbnailer->lock = g_mutex_new ();
+  thumbnailer->supported_schemes = NULL;
   thumbnailer->supported_types = NULL;
   thumbnailer->last_request = GUINT_TO_POINTER (0);
   thumbnailer->idles = NULL;
@@ -285,7 +282,6 @@ thunar_thumbnailer_init (ThunarThumbnailer *thumbnailer)
 
   /* initialize the proxies */
   thunar_thumbnailer_init_thumbnailer_proxy (thumbnailer, connection);
-  thunar_thumbnailer_init_manager_proxy (thumbnailer, connection);
 
   /* check if we have a thumbnailer proxy */
   if (thumbnailer->thumbnailer_proxy != NULL)
@@ -340,17 +336,6 @@ thunar_thumbnailer_finalize (GObject *object)
   /* free the idle list */
   g_list_free (thumbnailer->idles);
 
-  if (thumbnailer->manager_proxy != NULL)
-    {
-      /* disconnect from the manager proxy */
-      g_signal_handlers_disconnect_matched (thumbnailer->manager_proxy,
-                                            G_SIGNAL_MATCH_DATA, 0, 0,
-                                            NULL, NULL, thumbnailer);
-  
-      /* release the manager proxy */
-      g_object_unref (thumbnailer->manager_proxy);
-    }
-
   if (thumbnailer->thumbnailer_proxy != NULL)
     {
       /* cancel all pending D-Bus calls */
@@ -382,7 +367,8 @@ thunar_thumbnailer_finalize (GObject *object)
       g_object_unref (thumbnailer->thumbnailer_proxy);
     }
 
-  /* free the cached MIME types array */
+  /* free the cached URI schemes and MIME types array */
+  g_strfreev (thumbnailer->supported_schemes);
   g_strfreev (thumbnailer->supported_types);
 
   /* release the thumbnailer lock */
@@ -470,41 +456,6 @@ thunar_thumbnailer_init_thumbnailer_proxy (ThunarThumbnailer *thumbnailer,
 
 
 
-static void
-thunar_thumbnailer_init_manager_proxy (ThunarThumbnailer *thumbnailer,
-                                       DBusGConnection   *connection)
-{
-  /* we cannot have a proxy without a D-Bus connection */
-  if (connection == NULL)
-    {
-      thumbnailer->manager_proxy = NULL;
-      return;
-    }
-
-  /* create the manager proxy shared by all ThunarThumbnailers on demand */
-  if (thunar_manager_proxy == NULL)
-    {
-      /* create the shared manager proxy */
-      thunar_thumbnailer_manager_proxy = 
-        dbus_g_proxy_new_for_name (connection, 
-                                   "org.freedesktop.thumbnails.Manager1",
-                                   "/org/freedesktop/thumbnails/Manager1",
-                                   "org.freedesktop.thumbnails.Manager1");
-
-      /* make sure to set it to NULL when the last reference is dropped */
-      g_object_add_weak_pointer (G_OBJECT (thunar_thumbnailer_manager_proxy),
-                                 (gpointer) &thunar_thumbnailer_manager_proxy);
-
-      thumbnailer->manager_proxy = thunar_thumbnailer_manager_proxy;
-    }
-  else
-    {
-      thumbnailer->manager_proxy = g_object_ref (thunar_thumbnailer_manager_proxy);
-    }
-}
-
-
-
 static gboolean
 thunar_thumbnailer_file_is_supported (ThunarThumbnailer *thumbnailer,
                                       ThunarFile        *file)
@@ -519,36 +470,43 @@ thunar_thumbnailer_file_is_supported (ThunarThumbnailer *thumbnailer,
   /* acquire the thumbnailer lock */
   g_mutex_lock (thumbnailer->lock);
 
-  /* just assume all types are supported if we don't have a manager */
-  if (thumbnailer->manager_proxy == NULL)
+  /* no types are supported if we don't have a thumbnailer */
+  if (thumbnailer->thumbnailer_proxy == NULL)
     {
       /* release the thumbnailer lock */
       g_mutex_unlock (thumbnailer->lock);
-      return TRUE;
+      return FALSE;
     }
 
   /* request the supported types on demand */
-  if (thumbnailer->supported_types == NULL)
+  if (thumbnailer->supported_schemes == NULL 
+      || thumbnailer->supported_types == NULL)
     {
-      /* request the supported types from the manager D-Bus service. We only do
+      /* request the supported types from the thumbnailer D-Bus service. We only do
        * this once, so using a non-async call should be ok */
-      thunar_thumbnailer_manager_proxy_get_supported (thumbnailer->manager_proxy,
-                                                      &thumbnailer->supported_types, 
-                                                      NULL);
+      thunar_thumbnailer_proxy_get_supported (thumbnailer->thumbnailer_proxy,
+                                              &thumbnailer->supported_schemes,
+                                              &thumbnailer->supported_types, 
+                                              NULL);
     }
 
-  /* check if we have supported types now */
-  if (thumbnailer->supported_types != NULL)
+  /* check if we have supported URI schemes and MIME types now */
+  if (thumbnailer->supported_schemes != NULL
+      && thumbnailer->supported_types != NULL)
     {
       /* determine the content type of the passed file */
       content_type = thunar_file_get_content_type (file);
 
-      /* go through all the types */
-      for (n = 0; !supported && thumbnailer->supported_types[n] != NULL; ++n)
+      /* go through all the URI schemes we support */
+      for (n = 0; !supported && thumbnailer->supported_schemes[n] != NULL; ++n)
         {
-          /* check if the type of the file is a subtype of the supported type */
-          if (g_content_type_is_a (content_type, thumbnailer->supported_types[n]))
-            supported = TRUE;
+          /* check if the file has the current URI scheme */
+          if (thunar_file_has_uri_scheme (file, thumbnailer->supported_schemes[n]))
+            {
+              /* check if the type of the file is a subtype of the supported type */
+              if (g_content_type_is_a (content_type, thumbnailer->supported_types[n]))
+                supported = TRUE;
+            }
         }
     }
 
@@ -784,7 +742,7 @@ thunar_thumbnailer_queue_async (ThunarThumbnailer *thumbnailer,
   /* queue thumbnails for the given URIs asynchronously */
   call = thunar_thumbnailer_proxy_queue_async (thumbnailer->thumbnailer_proxy,
                                                (const gchar **)uris, mime_hints, 
-                                               "foreground", 0, 
+                                               "default", 0, 
                                                thunar_thumbnailer_queue_async_reply,
                                                thumbnailer_call);
 



More information about the Xfce4-commits mailing list