[Xfce4-commits] <tumbler:master> Moved GetSupported and GetSchedulers to the service

Jannis Pohlmann noreply at xfce.org
Thu Oct 8 15:10:01 CEST 2009


Updating branch refs/heads/master
         to 5bee7fc98468c3788ea3a60f26452a494dade6e1 (commit)
       from 4f6085ac25592e18ab082b2707d2bffcf2301047 (commit)

commit 5bee7fc98468c3788ea3a60f26452a494dade6e1
Author: Philip Van Hoof <philip at codeminded.be>
Date:   Wed Oct 7 11:55:56 2009 +0200

    Moved GetSupported and GetSchedulers to the service
    
    GetSupported now returns URI scheme and MIME type pairs. GetSchedulers returns
    a list of available schedulers plus "default".
    
    Signed-off-by: Jannis Pohlmann <jannis at xfce.org>

 tumblerd/tumbler-manager-dbus.xml |    4 -
 tumblerd/tumbler-manager.c        |   67 -------------------
 tumblerd/tumbler-service-dbus.xml |   11 +++
 tumblerd/tumbler-service.c        |  127 +++++++++++++++++++++++++++++++++++++
 tumblerd/tumbler-service.h        |   30 +++++----
 5 files changed, 155 insertions(+), 84 deletions(-)

diff --git a/tumblerd/tumbler-manager-dbus.xml b/tumblerd/tumbler-manager-dbus.xml
index e104b4f..f56d422 100644
--- a/tumblerd/tumbler-manager-dbus.xml
+++ b/tumblerd/tumbler-manager-dbus.xml
@@ -6,9 +6,5 @@
       <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/tumblerd/tumbler-manager.c b/tumblerd/tumbler-manager.c
index 14502ef..b5c3e1b 100644
--- a/tumblerd/tumbler-manager.c
+++ b/tumblerd/tumbler-manager.c
@@ -285,70 +285,3 @@ tumbler_manager_register (TumblerManager        *manager,
   dbus_g_method_return (context);
 }
 
-
-
-void
-tumbler_manager_get_supported (TumblerManager        *manager, 
-                               DBusGMethodInvocation *context)
-{
-  GHashTable *types;
-  GList      *thumbnailers;
-  GList      *keys;
-  GList      *lp;
-  GStrv       supported_types;
-  GStrv       mime_types;
-  gint        n;
-
-  dbus_async_return_if_fail (TUMBLER_IS_MANAGER (manager), context);
-
-  /* create a hash table to collect unique MIME types */
-  types = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
-  g_mutex_lock (manager->mutex);
-
-  /* get a list of all active thumbnailers */
-  thumbnailers = tumbler_registry_get_thumbnailers (manager->registry);
-
-  /* iterate over all of them */
-  for (lp = thumbnailers; lp != NULL; lp = lp->next)
-    {
-      /* determine the MIME types supported by the current thumbnailer */
-      mime_types = tumbler_thumbnailer_get_mime_types (lp->data);
-
-      /* insert all MIME types into the hash table */
-      for (n = 0; mime_types != NULL && mime_types[n] != NULL; ++n)
-        g_hash_table_replace (types, g_strdup (mime_types[n]), NULL);
-
-      /* free MIME types array */
-      g_strfreev (mime_types);
-    }
-
-  /* relase the thumbnailer list */
-  g_list_free (thumbnailers);
-  
-  g_mutex_unlock (manager->mutex);
-
-  /* determine all suported MIME types */
-  keys = g_hash_table_get_keys (types);
-
-  /* allocate a string array for them */
-  supported_types = g_new0 (gchar *, g_list_length (keys) + 1);
-
-  /* insert all MIME types into the array */
-  for (lp = keys, n = 0; lp != NULL; lp = lp->next, ++n)
-    supported_types[n] = g_strdup (lp->data);
-
-  /* NULL-terminate the array */
-  supported_types[n] = NULL;
-
-  /* release the list of supported MIME types */
-  g_list_free (keys);
-
-  /* destroy the hash table we used */
-  g_hash_table_unref (types);
-
-  dbus_g_method_return (context, supported_types);
-
-  /* free the supported types */
-  g_strfreev (supported_types);
-}
diff --git a/tumblerd/tumbler-service-dbus.xml b/tumblerd/tumbler-service-dbus.xml
index 0026e6c..59891ac 100644
--- a/tumblerd/tumbler-service-dbus.xml
+++ b/tumblerd/tumbler-service-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/tumblerd/tumbler-service.c b/tumblerd/tumbler-service.c
index a38b727..eda23c4 100644
--- a/tumblerd/tumbler-service.c
+++ b/tumblerd/tumbler-service.c
@@ -531,3 +531,130 @@ tumbler_service_unqueue (TumblerService        *service,
 
   dbus_g_method_return (context);
 }
+
+
+void
+tumbler_service_get_supported (TumblerService        *service,
+                               DBusGMethodInvocation *context)
+{
+  GHashTable    *types;
+  GHashTableIter iter;
+  gpointer       key;
+  gpointer       value;
+  GList         *thumbnailers;
+  GList         *lp;
+  GStrv          supported_types;
+  GStrv          supported_schemes;
+  GStrv          mime_types;
+  GStrv          uri_schemes;
+  gint           n, u;
+
+  dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context);
+
+  /* create a hash table to collect unique MIME types */
+  types = g_hash_table_new_full (g_str_hash, g_str_equal, 
+                                 (GDestroyNotify) g_free, 
+                                 (GDestroyNotify) g_strfreev);
+
+  g_mutex_lock (service->mutex);
+
+  /* get a list of all active thumbnailers */
+  thumbnailers = tumbler_registry_get_thumbnailers (service->registry);
+
+  /* iterate over all of them */
+  for (lp = thumbnailers; lp != NULL; lp = lp->next)
+    {
+      /* determine the MIME types & URI schemes supported by the current thumbnailer */
+      mime_types = tumbler_thumbnailer_get_mime_types (lp->data);
+      uri_schemes = tumbler_thumbnailer_get_uri_schemes (lp->data);
+
+      /* insert all MIME types & URI schemes into the hash table */
+      for (n = 0; mime_types != NULL && mime_types[n] != NULL; ++n) 
+        {
+         for (u = 0; uri_schemes != NULL && uri_schemes[u] != NULL; ++u)
+           {
+             GStrv registry = g_new0 (gchar *, 3);
+
+             registry[0] = g_strdup (uri_schemes[u]);
+             registry[1] = g_strdup (mime_types[n]);
+
+             g_hash_table_replace (types, 
+                                   g_strdup_printf ("%s-%s", uri_schemes[u],
+                                                    mime_types[n]),
+                                   registry);
+           }
+        }
+
+      /* free MIME types & URI schemes array */
+      g_strfreev (mime_types);
+      g_strfreev (uri_schemes);
+    }
+
+  /* relase the thumbnailer list */
+  g_list_free (thumbnailers);
+  
+  g_mutex_unlock (service->mutex);
+
+  /* allocate a string array for them */
+  u =  g_hash_table_size (types) + 1;
+  supported_types = g_new0 (gchar *, u);
+  supported_schemes = g_new0 (gchar *, u);
+
+  /* insert all MIME types & URI schemes into arrays */
+
+  n = 0;
+  g_hash_table_iter_init (&iter, types);
+  while (g_hash_table_iter_next (&iter, &key, &value)) 
+    {
+      GStrv registry = value;
+
+      supported_schemes[n] = g_strdup (registry[0]);
+      supported_types[n] = g_strdup (registry[1]);
+
+      ++n;
+    }
+
+
+  /* NULL-terminate the arrays */
+  supported_types[n] = NULL;
+  supported_schemes[n] = NULL;
+
+  /* destroy the hash table we used */
+  g_hash_table_unref (types);
+
+  dbus_g_method_return (context, supported_schemes, supported_types);
+
+  /* free the supported types & schemes */
+  g_strfreev (supported_types);
+  g_strfreev (supported_schemes);
+}
+
+
+void
+tumbler_service_get_schedulers (TumblerService        *service,
+                                DBusGMethodInvocation *context)
+{
+  GStrv supported_schedulers;
+  GList *iter;
+  guint n = 0;
+
+  dbus_async_return_if_fail (TUMBLER_IS_SERVICE (service), context);
+
+  g_mutex_lock (service->mutex);
+
+  supported_schedulers = g_new0 (gchar *, g_list_length (service->schedulers) + 2);
+  supported_schedulers[n++] = g_strdup ("default");
+
+  for (iter = service->schedulers; iter != NULL; iter = iter->next)
+    {
+      supported_schedulers[n++] = tumbler_scheduler_get_name (TUMBLER_SCHEDULER (iter->data));
+    }
+
+  g_mutex_unlock (service->mutex);
+
+  supported_schedulers[n] = NULL;
+
+  dbus_g_method_return (context, supported_schedulers);
+
+  g_strfreev (supported_schedulers);
+}
diff --git a/tumblerd/tumbler-service.h b/tumblerd/tumbler-service.h
index 3d45d89..dc35ef1 100644
--- a/tumblerd/tumbler-service.h
+++ b/tumblerd/tumbler-service.h
@@ -39,19 +39,23 @@ typedef struct _TumblerService      TumblerService;
 
 GType           tumbler_service_get_type (void) G_GNUC_CONST;
 
-TumblerService *tumbler_service_new      (DBusGConnection       *connection,
-                                          TumblerRegistry       *registry) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
-gboolean        tumbler_service_start    (TumblerService        *service,
-                                          GError               **error);
-void            tumbler_service_queue    (TumblerService        *service,
-                                          const GStrv            uris,
-                                          const GStrv            mime_hints,
-                                          const gchar           *s_scheduler,
-                                          guint                  handle_to_unqueue,
-                                          DBusGMethodInvocation *context);
-void            tumbler_service_unqueue (TumblerService         *service,
-                                         guint                   handle,
-                                         DBusGMethodInvocation  *context);
+TumblerService *tumbler_service_new            (DBusGConnection       *connection,
+                                                TumblerRegistry       *registry) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+gboolean        tumbler_service_start          (TumblerService        *service,
+                                                GError               **error);
+void            tumbler_service_queue          (TumblerService        *service,
+                                                const GStrv            uris,
+                                                const GStrv            mime_hints,
+                                                const gchar           *s_scheduler,
+                                                guint                  handle_to_unqueue,
+                                                DBusGMethodInvocation *context);
+void            tumbler_service_unqueue        (TumblerService         *service,
+                                                guint                   handle,
+                                                DBusGMethodInvocation  *context);
+void            tumbler_service_get_schedulers (TumblerService        *service,
+                                                DBusGMethodInvocation *context);
+void            tumbler_service_get_supported  (TumblerService        *service,
+                                                DBusGMethodInvocation *context);
 
 G_END_DECLS;
 



More information about the Xfce4-commits mailing list