From 3bedfaacab8c062d292fd6448086e6f48a0b5a00 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Wed, 21 Jun 2017 08:56:51 +0300 Subject: [PATCH] Port to GDBus With xfconf 4.13.1, ristretto was failing to compile due to DBUS_GLIB_CFLAGS + LIBS not being in the src/Makefile.am file. Instead of adding that simple fix, this patch goes one step further and just ports it to GDBus. --- .gitignore | 1 + configure.ac.in | 1 - src/Makefile.am | 15 ++++- src/main_window.c | 49 +++++++------- src/thumbnailer.c | 149 ++++++++++++++++++------------------------- src/tumbler-service-dbus.xml | 55 ++++++++++++++++ 6 files changed, 157 insertions(+), 113 deletions(-) create mode 100644 src/tumbler-service-dbus.xml diff --git a/.gitignore b/.gitignore index 4be0c37..a58b67f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ Makefile.in src/.deps src/ristretto src/marshal.[ch] +src/tumbler.[ch] src/main_window_ui.h src/stamp-marshal.h autom4te.cache diff --git a/configure.ac.in b/configure.ac.in index 8de673c..7c6acf3 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -58,7 +58,6 @@ XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.24.0]) XDT_CHECK_PACKAGE([GOBJECT], [gobject-2.0], [2.24.0]) XDT_CHECK_PACKAGE([GIO], [gio-2.0], [2.18.0]) XDT_CHECK_PACKAGE([GIO_UNIX], [gio-unix-2.0], [2.18.0]) -XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.34]) XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.10.0]) XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.10.0]) diff --git a/src/Makefile.am b/src/Makefile.am index 36a31dc..e6d41e0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,7 @@ ristretto_SOURCES = \ gnome_wallpaper_manager.c gnome_wallpaper_manager.h \ app_menu_item.c app_menu_item.h \ thumbnailer.c thumbnailer.h \ + tumbler.c tumbler.h \ marshal.c marshal.h \ file.c file.h \ privacy_dialog.h privacy_dialog.c \ @@ -65,7 +66,9 @@ if MAINTAINER_MODE ristretto_built_sources = \ marshal.h \ - marshal.c + marshal.c \ + tumbler.c \ + tumbler.h BUILT_SOURCES = \ $(ristretto_built_sources) \ @@ -102,10 +105,18 @@ marshal.c: marshal.list Makefile && rm -f xgen-tmc \ ) +tumbler.c tumbler.h : $(srcdir)/tumbler-service-dbus.xml Makefile.am + gdbus-codegen \ + --c-namespace=Tumbler \ + --interface-prefix=org.freedesktop.thumbnails. \ + --generate-c-code=tumbler \ + $(srcdir)/tumbler-service-dbus.xml + DISTCLEANFILES += \ stamp-marshal.h endif EXTRA_DIST = \ - main_window_ui.xml + main_window_ui.xml \ + tumbler-service-dbus.xml diff --git a/src/main_window.c b/src/main_window.c index a960ac2..78c0be2 100644 --- a/src/main_window.c +++ b/src/main_window.c @@ -28,8 +28,6 @@ #include #include -#include - #include #include "settings.h" @@ -78,8 +76,7 @@ struct _RsttoMainWindowPriv RsttoMimeDB *db; - DBusGConnection *connection; - DBusGProxy *filemanager_proxy; + GDBusProxy *filemanager_proxy; guint show_fs_toolbar_timeout_id; gint window_save_geometry_timer_id; @@ -808,16 +805,15 @@ rstto_main_window_init (RsttoMainWindow *window) /* D-Bus stuff */ - window->priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - if (window->priv->connection) - { - window->priv->filemanager_proxy = - dbus_g_proxy_new_for_name( - window->priv->connection, - "org.xfce.FileManager", - "/org/xfce/FileManager", - "org.xfce.FileManager"); - } + window->priv->filemanager_proxy = + g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.xfce.FileManager", + "/org/xfce/FileManager", + "org.xfce.FileManager", + NULL, + NULL); desktop_type = rstto_settings_get_string_property (window->priv->settings_manager, "desktop-type"); if (desktop_type) @@ -1242,6 +1238,8 @@ rstto_main_window_dispose(GObject *object) window->priv->action_group = NULL; } + g_clear_object (&window->priv->filemanager_proxy); + g_free (window->priv); window->priv = NULL; } @@ -3390,6 +3388,8 @@ cb_rstto_main_window_properties (GtkWidget *widget, RsttoMainWindow *window) */ if ( TRUE == use_thunar_properties ) { + GVariant *unused = NULL; + /* Get the file-uri */ uri = rstto_file_get_uri(file); @@ -3397,14 +3397,17 @@ cb_rstto_main_window_properties (GtkWidget *widget, RsttoMainWindow *window) * interface. If it fails, fall back to the * internal properties-dialog. */ - if(dbus_g_proxy_call(window->priv->filemanager_proxy, - "DisplayFileProperties", - &error, - G_TYPE_STRING, uri, - G_TYPE_STRING, gdk_display_get_name(display), - G_TYPE_STRING, "", - G_TYPE_INVALID, - G_TYPE_INVALID) == FALSE) + unused = g_dbus_proxy_call_sync (window->priv->filemanager_proxy, + "DisplayFileProperties", + g_variant_new ("(sss)", + uri, + gdk_display_get_name(display), + ""), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + if (error != NULL) { g_warning("DBUS CALL FAILED: '%s'", error->message); @@ -3417,6 +3420,8 @@ cb_rstto_main_window_properties (GtkWidget *widget, RsttoMainWindow *window) /* Cleanup the file-properties dialog */ gtk_widget_destroy(dialog); + } else { + g_variant_unref (unused); } } else diff --git a/src/thumbnailer.c b/src/thumbnailer.c index 22e669a..ba7be67 100644 --- a/src/thumbnailer.c +++ b/src/thumbnailer.c @@ -23,7 +23,6 @@ #include #include -#include #include @@ -34,6 +33,7 @@ #include "settings.h" #include "thumbnailer.h" #include "marshal.h" +#include "tumbler.h" static void rstto_thumbnailer_init (GObject *); @@ -60,14 +60,14 @@ rstto_thumbnailer_get_property ( static void cb_rstto_thumbnailer_request_finished ( - DBusGProxy *proxy, - gint handle, + TumblerThumbnailer1 *proxy, + guint arg_handle, gpointer data); static void cb_rstto_thumbnailer_thumbnail_ready ( - DBusGProxy *proxy, - gint handle, - const gchar **uri, + TumblerThumbnailer1 *proxy, + guint handle, + const gchar *const *uri, gpointer data); static gboolean @@ -122,18 +122,18 @@ rstto_thumbnailer_get_type (void) struct _RsttoThumbnailerPriv { - DBusGConnection *connection; - DBusGProxy *proxy; - RsttoSettings *settings; + GDBusConnection *connection; + TumblerThumbnailer1 *proxy; + RsttoSettings *settings; - GSList *queue; + GSList *queue; - GSList *in_process_queue; - gint handle; + GSList *in_process_queue; + gint handle; - gboolean show_missing_thumbnailer_error; + gboolean show_missing_thumbnailer_error; - gint request_timer_id; + gint request_timer_id; }; static void @@ -142,7 +142,7 @@ rstto_thumbnailer_init (GObject *object) RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (object); thumbnailer->priv = g_new0 (RsttoThumbnailerPriv, 1); - thumbnailer->priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + thumbnailer->priv->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); thumbnailer->priv->settings = rstto_settings_new(); thumbnailer->priv->show_missing_thumbnailer_error = @@ -153,43 +153,22 @@ rstto_thumbnailer_init (GObject *object) if (thumbnailer->priv->connection) { - thumbnailer->priv->proxy = dbus_g_proxy_new_for_name ( + thumbnailer->priv->proxy = tumbler_thumbnailer1_proxy_new_sync ( thumbnailer->priv->connection, + G_DBUS_PROXY_FLAGS_NONE, "org.freedesktop.thumbnails.Thumbnailer1", "/org/freedesktop/thumbnails/Thumbnailer1", - "org.freedesktop.thumbnails.Thumbnailer1"); - - dbus_g_object_register_marshaller ( - (GClosureMarshal) _rstto_marshal_VOID__UINT_BOXED, - G_TYPE_NONE, - G_TYPE_UINT, - G_TYPE_STRV, - G_TYPE_INVALID); - - dbus_g_proxy_add_signal ( - thumbnailer->priv->proxy, - "Finished", - G_TYPE_UINT, - G_TYPE_INVALID); - dbus_g_proxy_add_signal ( - thumbnailer->priv->proxy, - "Ready", - G_TYPE_UINT, - G_TYPE_STRV, - G_TYPE_INVALID); - - dbus_g_proxy_connect_signal ( - thumbnailer->priv->proxy, - "Finished", - G_CALLBACK (cb_rstto_thumbnailer_request_finished), - thumbnailer, - NULL); - dbus_g_proxy_connect_signal ( - thumbnailer->priv->proxy, - "Ready", - G_CALLBACK(cb_rstto_thumbnailer_thumbnail_ready), - thumbnailer, + NULL, NULL); + + g_signal_connect(thumbnailer->priv->proxy, + "finished", + G_CALLBACK (cb_rstto_thumbnailer_request_finished), + thumbnailer); + g_signal_connect(thumbnailer->priv->proxy, + "ready", + G_CALLBACK(cb_rstto_thumbnailer_thumbnail_ready), + thumbnailer); } } @@ -234,20 +213,11 @@ rstto_thumbnailer_dispose (GObject *object) if (thumbnailer->priv) { - if (thumbnailer->priv->settings) - { - g_object_unref (thumbnailer->priv->settings); - thumbnailer->priv->settings = NULL; - } + g_clear_object (&thumbnailer->priv->settings); + g_clear_object (&thumbnailer->priv->proxy); + g_clear_object (&thumbnailer->priv->connection); - if (thumbnailer->priv->proxy) - { - g_object_unref (thumbnailer->priv->proxy); - thumbnailer->priv->proxy = NULL; - } - - g_free (thumbnailer->priv); - thumbnailer->priv = NULL; + g_clear_pointer (&thumbnailer->priv, g_free); } } @@ -327,12 +297,14 @@ rstto_thumbnailer_queue_file ( g_source_remove (thumbnailer->priv->request_timer_id); if (thumbnailer->priv->handle) { - if(dbus_g_proxy_call(thumbnailer->priv->proxy, - "Dequeue", - NULL, - G_TYPE_UINT, thumbnailer->priv->handle, - G_TYPE_INVALID) == FALSE) + if(tumbler_thumbnailer1_call_dequeue_sync( + thumbnailer->priv->proxy, + thumbnailer->priv->handle, + NULL, + NULL) == FALSE) { + /* If this fails it usually means there's a thumbnail already + * being processed, no big deal */ } thumbnailer->priv->handle = 0; } @@ -370,12 +342,14 @@ rstto_thumbnailer_dequeue_file ( if (thumbnailer->priv->handle) { - if(dbus_g_proxy_call(thumbnailer->priv->proxy, - "Dequeue", + if(tumbler_thumbnailer1_call_dequeue_sync( + thumbnailer->priv->proxy, + thumbnailer->priv->handle, NULL, - G_TYPE_UINT, thumbnailer->priv->handle, - G_TYPE_INVALID) == FALSE) + NULL) == FALSE) { + /* If this fails it usually means there's a thumbnail already + * being processed, no big deal */ } thumbnailer->priv->handle = 0; g_slist_foreach (thumbnailer->priv->in_process_queue, (GFunc)g_object_unref, NULL); @@ -437,23 +411,22 @@ rstto_thumbnailer_queue_request_timer ( i++; } - if(dbus_g_proxy_call(thumbnailer->priv->proxy, - "Queue", - &error, - G_TYPE_STRV, uris, - G_TYPE_STRV, mimetypes, - G_TYPE_STRING, "normal", - G_TYPE_STRING, "default", - G_TYPE_UINT, 0, - G_TYPE_INVALID, - G_TYPE_UINT, &thumbnailer->priv->handle, - G_TYPE_INVALID) == FALSE) + if(tumbler_thumbnailer1_call_queue_sync( + thumbnailer->priv->proxy, + (const gchar * const*)uris, + (const gchar * const*)mimetypes, + "normal", + "default", + 0, + &thumbnailer->priv->handle, + NULL, + &error) == FALSE) { if (NULL != error) { g_warning("DBUS-call failed:%s", error->message); - if ((error->domain == DBUS_GERROR) && - (error->code == DBUS_GERROR_SERVICE_UNKNOWN) && + if ((error->domain == G_DBUS_ERROR) && + (error->code == G_DBUS_ERROR_SERVICE_UNKNOWN) && thumbnailer->priv->show_missing_thumbnailer_error == TRUE) { GDK_THREADS_ENTER(); @@ -508,8 +481,8 @@ rstto_thumbnailer_queue_request_timer ( static void cb_rstto_thumbnailer_request_finished ( - DBusGProxy *proxy, - gint handle, + TumblerThumbnailer1 *proxy, + guint arg_handle, gpointer data) { RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (data); @@ -526,9 +499,9 @@ cb_rstto_thumbnailer_request_finished ( static void cb_rstto_thumbnailer_thumbnail_ready ( - DBusGProxy *proxy, - gint handle, - const gchar **uri, + TumblerThumbnailer1 *proxy, + guint handle, + const gchar *const *uri, gpointer data) { RsttoThumbnailer *thumbnailer = RSTTO_THUMBNAILER (data); diff --git a/src/tumbler-service-dbus.xml b/src/tumbler-service-dbus.xml new file mode 100644 index 0000000..9076691 --- /dev/null +++ b/src/tumbler-service-dbus.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.11.0