Git Repositories

- Applied patch from Mike Massonnet to use xfconf-query instead of
authorStephan Arts <stephan@xfce.org>
Mon, 3 Nov 2008 22:01:58 +0000 (22:01 +0000)
committerStephan Arts <stephan@xfce.org>
Mon, 3 Nov 2008 22:01:58 +0000 (22:01 +0000)
  xfconf for setting the xfce desktop.
- Added support for gconftool to set the gnome desktop (detecting
  nautilus is still flawed)

(Old svn revision: 28600)

acinclude.m4
configure.in.in
plugins/thunar-wallpaper/Makefile.am
plugins/thunar-wallpaper/README
plugins/thunar-wallpaper/thunar-wallpaper-plugin.c
plugins/thunar-wallpaper/twp-provider.c
plugins/thunar-wallpaper/twp-provider.h

index bd13e05..49afe08 100644 (file)
@@ -102,7 +102,15 @@ AC_ARG_ENABLE([wallpaper-plugin], AC_HELP_STRING([--disable-wallpaper-plugin], [
 AC_MSG_CHECKING([whether to build the thunar-wallpaper plugin])
 AM_CONDITIONAL([THUNAR_PLUGIN_WALLPAPER], [test x"$ac_bm_thunar_plugin_wallpaper" = x"yes"])
 AC_MSG_RESULT([$ac_bm_thunar_plugin_wallpaper])
-XDT_CHECK_OPTIONAL_PACKAGE([XFCONF], [libxfconf-0], [4.5.91], [xfconf], [Xfconf support])
+if test x"$ac_bm_thunar_plugin_wallpaper" = x"yes"; then
+       AC_CHECK_PROG([xfconf_query_found], [xfconf-query], [yes], [no])
+       if test x"$xfconf_query_found" = x"no"; then
+               echo "***"
+               echo "*** xfconf-query was not found on your system."
+               echo "*** The wallpaper won't work without it installed."
+               echo "***"
+       fi
+fi
 ])
 
 
index 4f4f71e..b90fab1 100644 (file)
@@ -509,5 +509,5 @@ echo "* Advanced Properties:       $ac_bm_thunar_plugin_apr"
 echo "* Simple Builting Renamers:  $ac_bm_thunar_plugin_sbr"
 echo "* Trash Panel Applet:        $ac_bm_thunar_plugin_tpa"
 echo "* User Customizable Actions: $ac_bm_thunar_plugin_uca"
-echo "* Wallpaper support: $ac_bm_thunar_plugin_wallpaper"
+echo "* Wallpaper support:         $ac_bm_thunar_plugin_wallpaper"
 echo
index 0bb79cb..573a8fd 100644 (file)
@@ -19,7 +19,6 @@ thunar_wallpaper_plugin_la_SOURCES =          \
 thunar_wallpaper_plugin_la_CFLAGS =                    \
        $(PLATFORM_CFLAGS)                                              \
        $(THUNARX_CFLAGS)                                               \
-       $(XFCONF_CFLAGS)                                                \
        $(EXO_CFLAGS)                                                   \
        $(THUNAR_VFS_CFLAGS)
 
@@ -29,5 +28,4 @@ thunar_wallpaper_plugin_la_LDFLAGS =          \
        -module                                                                 \
        $(PLATFORM_LDFLAGS)                                             \
        $(THUNARX_LDFLAGS)                                              \
-       $(XFCONF_LIBS)                                                  \
        $(THUNAR_VFS_LDFLAGS)
index c84677a..fb880f1 100644 (file)
@@ -1,8 +1,7 @@
 Thunar Wallpaper Plugin (thunar-wallpaper)
 ===========================================
 
-The Thunar Wallpaper plugin is an extension to Thunar. It pulls the xfconf 
-dependency required to set the correct settings on the Xfce4 desktop.
+The Thunar Wallpaper plugin is an extension to Thunar. It depends on the
+xfconf-query command line to set the correct settings on the Xfce4 desktop.
 
-To disable this plugin (and the xfconf dependency that comes with it), pass 
---disable-wallpaper-plugin to ./configure.
+To disable this plugin, pass --disable-wallpaper-plugin to ./configure.
index 440dd17..7d6ef37 100644 (file)
@@ -1,5 +1,6 @@
-/*-
+/*
  * Copyright (c) 2008 Stephan Arts <stephan@xfce.org>
+ * Copyright (c) 2008 Mike Massonnet <mmassonnet@xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -13,8 +14,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301  USA
  */
 
 #ifdef HAVE_CONFIG_H
@@ -50,16 +51,9 @@ thunar_extension_initialize (ThunarxProviderPlugin *plugin)
   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 #endif
 
-//#ifdef G_ENABLE_DEBUG
-  g_message ("Initializing thunar-wallpaper-plugin extension");
-//#endif
-
   /* register the types provided by this plugin */
   twp_provider_register_type (plugin);
 
-  thunarx_provider_plugin_set_resident (plugin, TRUE);
-  xfconf_init(NULL);
-
   /* setup the plugin provider type list */
   type_list[0] = TWP_TYPE_PROVIDER;
 }
@@ -69,10 +63,6 @@ thunar_extension_initialize (ThunarxProviderPlugin *plugin)
 G_MODULE_EXPORT void
 thunar_extension_shutdown (void)
 {
-#ifdef G_ENABLE_DEBUG
-  g_message ("Shutting down thunar-wallpaper-plugin extension");
-#endif
-  xfconf_shutdown();
 }
 
 
@@ -85,6 +75,3 @@ thunar_extension_list_types (const GType **types,
   *n_types = G_N_ELEMENTS (type_list);
 }
 
-
-
-
index 5ddc69d..868d8f1 100644 (file)
@@ -1,5 +1,6 @@
-/*-
+/*
  * Copyright (c) 2008 Stephan Arts <stephan@xfce.org>
+ * Copyright (c) 2008 Mike Massonnet <mmassonnet@xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301  USA
  */
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
-#include <xfconf/xfconf.h>
 #include <thunar-vfs/thunar-vfs.h>
 #include <gdk/gdkx.h>
 #include <X11/Xlib.h>
 
 #include "twp-provider.h"
 
+
 #define XFDESKTOP_SELECTION_FMT "XFDESKTOP_SELECTION_%d"
+#define NAUTILUS_SELECTION_FMT  "NAUTILUS_DESKTOP_WINDOW_ID"
+
+static gboolean _has_xfconf_query = FALSE;
+static gboolean _has_gconftool = FALSE;
 
 
 typedef enum {
     DESKTOP_TYPE_NONE,
-    DESKTOP_TYPE_XFCE
+    DESKTOP_TYPE_XFCE,
+    DESKTOP_TYPE_NAUTILUS
 } DesktopType;
 
 static DesktopType desktop_type;
 
+static void   twp_menu_provider_init            (ThunarxMenuProviderIface *iface);
 static void   twp_provider_class_init           (TwpProviderClass         *klass);
-static void   twp_provider_menu_provider_init   (ThunarxMenuProviderIface *iface);
-static void   twp_provider_property_page_provider_init (ThunarxPropertyPageProviderIface *iface);
 static void   twp_provider_init                 (TwpProvider              *twp_provider);
 static void   twp_provider_finalize             (GObject                  *object);
 static GList *twp_provider_get_file_actions     (ThunarxMenuProvider      *menu_provider,
                                                  GtkWidget                *window,
                                                  GList                    *files);
-#if 0
-static GList *twp_provider_get_folder_actions   (ThunarxMenuProvider      *menu_provider,
-                                                 GtkWidget                *window,
-                                                 ThunarxFileInfo          *folder);
-#endif
 
-static void
-twp_action_set_wallpaper (GtkAction *action, gpointer user_data);
+static void   twp_action_set_wallpaper          (GtkAction                *action,
+                                                 gpointer                  user_data);
+
+static gboolean check_cli_tools ();
+
 
 
 struct _TwpProviderClass
@@ -83,24 +78,10 @@ THUNARX_DEFINE_TYPE_WITH_CODE (TwpProvider,
                                twp_provider,
                                G_TYPE_OBJECT,
                                THUNARX_IMPLEMENT_INTERFACE (THUNARX_TYPE_MENU_PROVIDER,
-                                                            twp_provider_menu_provider_init)
-                               THUNARX_IMPLEMENT_INTERFACE (THUNARX_TYPE_PROPERTY_PAGE_PROVIDER,
-                                                            twp_provider_property_page_provider_init));
-
+                                                            twp_menu_provider_init));
 
 static void
-twp_provider_class_init (TwpProviderClass *klass)
-{
-  GObjectClass *gobject_class;
-
-  gobject_class = G_OBJECT_CLASS (klass);
-  gobject_class->finalize = twp_provider_finalize;
-}
-
-
-
-static void
-twp_provider_menu_provider_init (ThunarxMenuProviderIface *iface)
+twp_menu_provider_init (ThunarxMenuProviderIface *iface)
 {
   iface->get_file_actions = twp_provider_get_file_actions;
 }
@@ -108,36 +89,39 @@ twp_provider_menu_provider_init (ThunarxMenuProviderIface *iface)
 
 
 static void
-twp_provider_property_page_provider_init (ThunarxPropertyPageProviderIface *iface)
+twp_provider_class_init (TwpProviderClass *klass)
 {
-}
-
+  GObjectClass *gobject_class;
 
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->finalize = twp_provider_finalize;
+}
 
 static void
 twp_provider_init (TwpProvider *twp_provider)
 {
-       //twp_gpg_backend_init();
+    check_cli_tools();
 }
 
-
-
 static void
 twp_provider_finalize (GObject *object)
 {
-
-   (*G_OBJECT_CLASS (twp_provider_parent_class)->finalize) (object);
+  G_OBJECT_CLASS (twp_provider_parent_class)->finalize (object);
 }
 
+
+
 static GList*
 twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
                                GtkWidget           *window,
                                GList               *files)
 {
     Atom xfce_selection_atom;
+    Atom nautilus_selection_atom;
+
        ThunarVfsPathScheme scheme;
        ThunarVfsInfo      *info;
-       GtkWidget          *action;
+       GtkWidget          *action = NULL;
        GList              *actions = NULL;
     gchar               selection_name[100];
 
@@ -167,7 +151,8 @@ twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
             {
                 action = g_object_new (GTK_TYPE_ACTION,
                             "name", "Twp::setwallpaper",
-                            "label", _("Set as Wallpaper"),
+                            "icon-name", "background",
+                            "label", _("Set as wallpaper"),
                             NULL);
                 g_signal_connect (action, "activate", G_CALLBACK (twp_action_set_wallpaper), files->data);
 
@@ -181,27 +166,29 @@ twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
 
     if((XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom)))
     {
-        desktop_type = DESKTOP_TYPE_XFCE;
+        if (_has_xfconf_query)
+            desktop_type = DESKTOP_TYPE_XFCE;
+    }
+    else
+    {
+        /* FIXME: This is wrong, nautilus WINDOW_ID is not a selection */
+        g_snprintf(selection_name, 100, NAUTILUS_SELECTION_FMT);
+        nautilus_selection_atom = XInternAtom (gdk_display, selection_name, False);
+        if((XGetSelectionOwner(GDK_DISPLAY(), nautilus_selection_atom)))
+        {
+            if (_has_gconftool)
+                desktop_type = DESKTOP_TYPE_NAUTILUS;
+        }
     }
 
-    if (desktop_type == DESKTOP_TYPE_NONE)
+    if ((desktop_type == DESKTOP_TYPE_NONE) && (action != NULL))
     {
-        gtk_widget_set_sensitive (action, FALSE);
+        //gtk_widget_set_sensitive (action, FALSE);
     }
 
   return actions;
 }
 
-
-#if 0
-static GList*
-twp_Provider_get_pages (ThunarxPropertyPageProvider *page_provider, GList *files)
-{
-  GList *pages = NULL;
-  return pages;
-}
-#endif
-
 static void
 twp_action_set_wallpaper (GtkAction *action, gpointer user_data)
 {
@@ -216,9 +203,9 @@ twp_action_set_wallpaper (GtkAction *action, gpointer user_data)
     gchar *image_show_prop;
     gchar *image_style_prop;
     gchar *file_uri;
-    gchar *file_name;
+    gchar *file_name = NULL;
     gchar *hostname = NULL;
-    XfconfChannel *xfdesktop_channel;
+    gchar *command;
 
     if (desktop_type != DESKTOP_TYPE_NONE)
     {
@@ -227,8 +214,8 @@ twp_action_set_wallpaper (GtkAction *action, gpointer user_data)
         if (hostname != NULL)
         {
             g_free (hostname);
-            g_free(file_uri);
-            g_free(file_name);
+            g_free (file_uri);
+            g_free (file_name);
             return;
         }
         if (n_screens > 1)
@@ -246,28 +233,48 @@ twp_action_set_wallpaper (GtkAction *action, gpointer user_data)
 
         }
         g_free(file_uri);
-        g_free(file_name);
-
     }
 
     switch (desktop_type)
     {
         case DESKTOP_TYPE_XFCE:
-            xfdesktop_channel = xfconf_channel_new("xfce4-desktop");
+            g_debug ("set on xfce");
             image_path_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-path", screen_nr, monitor_nr);
             image_show_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-show", screen_nr, monitor_nr);
             image_style_prop = g_strdup_printf("/backdrop/screen%d/monitor%d/image-style", screen_nr, monitor_nr);
 
-            if(xfconf_channel_set_string(xfdesktop_channel, image_path_prop, file_name) == TRUE)
-            {
-                xfconf_channel_set_bool(xfdesktop_channel, image_show_prop, TRUE);
-                xfconf_channel_set_int(xfdesktop_channel, image_style_prop, 4);
-            }
+            command = g_strdup_printf ("xfconf-query -c xfce4-desktop -p %s --create -t string -s %s", image_path_prop, file_name);
+            g_spawn_command_line_async (command, NULL);
+            g_free (command);
+
+            command = g_strdup_printf ("xfconf-query -c xfce4-desktop -p %s --create -t bool -s true", image_show_prop);
+            g_spawn_command_line_async (command, NULL);
+            g_free (command);
+
+            command = g_strdup_printf ("xfconf-query -c xfce4-desktop -p %s --create -t int -s 4", image_style_prop);
+            g_spawn_command_line_async (command, NULL);
+            g_free (command);
 
             g_free(image_path_prop);
             g_free(image_show_prop);
             g_free(image_style_prop);
-            g_object_unref(xfdesktop_channel);
+            break;
+        case DESKTOP_TYPE_NAUTILUS:
+            g_debug ("set on gnome");
+            image_path_prop = g_strdup_printf("/desktop/gnome/background/picture_filename");
+            image_show_prop = g_strdup_printf("/desktop/gnome/background/draw_background");
+
+            command = g_strdup_printf ("gconftool %s --set %s--type string", image_path_prop, file_name);
+            g_spawn_command_line_async (command, NULL);
+            g_free (command);
+
+
+            command = g_strdup_printf ("gconftool %s --set true --type boolean", image_show_prop);
+            g_spawn_command_line_async (command, NULL);
+            g_free (command);
+
+            g_free(image_path_prop);
+            g_free(image_show_prop);
             break;
 
         default:
@@ -275,5 +282,28 @@ twp_action_set_wallpaper (GtkAction *action, gpointer user_data)
             break;
     }
 
+    g_free(file_name);
+}
+
 
+static gboolean
+check_cli_tools ()
+{
+  gchar *program;
+
+  program = g_find_program_in_path ("xfconf-query");
+  if (G_LIKELY (program != NULL))
+  {
+    _has_xfconf_query = TRUE;
+    g_free (program);
+  }
+
+  program = g_find_program_in_path ("gconftool");
+  if (G_LIKELY (program != NULL))
+  {
+    _has_gconftool = TRUE;
+    g_free (program);
+  }
+
+  return TRUE;
 }
index 670d63f..e3be28a 100644 (file)
@@ -1,5 +1,6 @@
-/*-
+/*
  * Copyright (c) 2008 Stephan Arts <stephan@xfce.org>
+ * Copyright (c) 2008 Mike Massonnet <mmassonnet@xfce.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -13,8 +14,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301  USA
  */
 
 #ifndef __TWP_PROVIDER_H__