From 32500bca06fed0cd408cc674d143a9872935c40d Mon Sep 17 00:00:00 2001
From: Stephan Arts <stephan@xfce.org>
Date: Fri, 24 Oct 2008 23:06:03 +0000
Subject: [PATCH] Adding the thunar-wallpaper-plugin to the thunar package

(Old svn revision: 28402)
---
 ChangeLog                                     |   6 +
 acinclude.m4                                  |  14 +
 configure.in.in                               |   3 +
 plugins/Makefile.am                           |   5 +
 plugins/thunar-wallpaper/Makefile.am          |  33 +++
 .../thunar-wallpaper-plugin.c                 |  86 ++++++
 plugins/thunar-wallpaper/twp-provider.c       | 252 ++++++++++++++++++
 plugins/thunar-wallpaper/twp-provider.h       |  43 +++
 8 files changed, 442 insertions(+)
 create mode 100644 plugins/thunar-wallpaper/Makefile.am
 create mode 100644 plugins/thunar-wallpaper/thunar-wallpaper-plugin.c
 create mode 100644 plugins/thunar-wallpaper/twp-provider.c
 create mode 100644 plugins/thunar-wallpaper/twp-provider.h

diff --git a/ChangeLog b/ChangeLog
index 5bde458d9..b41b3de12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-10-25  Stephan Arts <stephan@xfce.org>
+
+	* plugins/thunar-wallpaper:
+	  Add thunar-wallpaper-plugin which can be used to set the wallpaper
+	  on xfdesktop >= 4.5.90
+
 2008-08-25	Brian Tarricone <kelnos@xfce.org>
 
 	* thunar/{Makefile.am,thunar-settings,thunar-settings.desktop.in}:
diff --git a/acinclude.m4 b/acinclude.m4
index b6ce99ea8..bd13e0516 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -90,6 +90,20 @@ AM_CONDITIONAL([THUNAR_PLUGIN_UCA], [test x"$ac_bm_thunar_plugin_uca" = x"yes"])
 AC_MSG_RESULT([$ac_bm_thunar_plugin_uca])
 ])
 
+dnl # BM_THUNAR_PLUGIN_WALLPAPER()
+dnl #
+dnl # Check whether the "Wallpaper" plugin
+dnl # should be built and installed.
+dnl #
+AC_DEFUN([BM_THUNAR_PLUGIN_WALLPAPER],
+[
+AC_ARG_ENABLE([wallpaper-plugin], AC_HELP_STRING([--disable-wallpaper-plugin], [Don't build the thunar-wallpaper plugin, see plugins/thunar-wallpaper/README]),
+  [ac_bm_thunar_plugin_wallpaper=$enableval], [ac_bm_thunar_plugin_wallpaper=yes])
+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])
+])
 
 
 dnl # BM_THUNAR_VFS_MONITOR_IMPL()
diff --git a/configure.in.in b/configure.in.in
index d50bbbc19..4f4f71e05 100644
--- a/configure.in.in
+++ b/configure.in.in
@@ -406,6 +406,7 @@ BM_THUNAR_PLUGIN_APR()
 BM_THUNAR_PLUGIN_SBR()
 BM_THUNAR_PLUGIN_TPA()
 BM_THUNAR_PLUGIN_UCA()
+BM_THUNAR_PLUGIN_WALLPAPER()
 
 AC_OUTPUT([
 Makefile
@@ -460,6 +461,7 @@ plugins/thunar-sbr/Makefile
 plugins/thunar-sendto-email/Makefile
 plugins/thunar-tpa/Makefile
 plugins/thunar-uca/Makefile
+plugins/thunar-wallpaper/Makefile
 po/Makefile.in
 po-doc/Makefile
 tdb/Makefile
@@ -507,4 +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
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index f9f06c6a4..53cb3effd 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -16,11 +16,16 @@ if THUNAR_PLUGIN_UCA
 THUNAR_UCA_SUBDIRS = thunar-uca
 endif
 
+if THUNAR_PLUGIN_WALLPAPER
+THUNAR_WALLPAPER_SUBDIRS = thunar-wallpaper
+endif
+
 SUBDIRS =								\
 	$(THUNAR_APR_SUBDIRS)						\
 	$(THUNAR_SBR_SUBDIRS)						\
 	$(THUNAR_TPA_SUBDIRS)						\
 	$(THUNAR_UCA_SUBDIRS)						\
+	$(THUNAR_WALLPAPER_SUBDIRS)					\
 	thunar-sendto-email
 
 # vi:set ts=8 sw=8 noet ai nocindent syntax=automake:
diff --git a/plugins/thunar-wallpaper/Makefile.am b/plugins/thunar-wallpaper/Makefile.am
new file mode 100644
index 000000000..0bb79cb1e
--- /dev/null
+++ b/plugins/thunar-wallpaper/Makefile.am
@@ -0,0 +1,33 @@
+INCLUDES =										\
+	-I$(top_builddir)							\
+	-I$(top_srcdir)								\
+	-DG_LOG_DOMAIN=\"thunar-wallpaper-plugin\"	\
+	-DEXO_API_SUBJECT_TO_CHANGE					\
+	-DLIBEXECDIR=\"$(libexecdir)\"				\
+	-DPACKAGE_LOCALE_DIR=\"$(localedir)\"		\
+	$(PLATFORM_CPPFLAGS)
+
+extensionsdir = $(libdir)/thunarx-1
+extensions_LTLIBRARIES =					\
+	thunar-wallpaper-plugin.la
+
+thunar_wallpaper_plugin_la_SOURCES =		\
+	twp-provider.h							\
+	twp-provider.c							\
+	thunar-wallpaper-plugin.c
+
+thunar_wallpaper_plugin_la_CFLAGS =			\
+	$(PLATFORM_CFLAGS)						\
+	$(THUNARX_CFLAGS)						\
+	$(XFCONF_CFLAGS)						\
+	$(EXO_CFLAGS)							\
+	$(THUNAR_VFS_CFLAGS)
+
+thunar_wallpaper_plugin_la_LDFLAGS =		\
+	-avoid-version							\
+	-export-dynamic							\
+	-module									\
+	$(PLATFORM_LDFLAGS)						\
+	$(THUNARX_LDFLAGS)						\
+	$(XFCONF_LIBS)							\
+	$(THUNAR_VFS_LDFLAGS)
diff --git a/plugins/thunar-wallpaper/thunar-wallpaper-plugin.c b/plugins/thunar-wallpaper/thunar-wallpaper-plugin.c
new file mode 100644
index 000000000..bab5858b5
--- /dev/null
+++ b/plugins/thunar-wallpaper/thunar-wallpaper-plugin.c
@@ -0,0 +1,86 @@
+/*-
+ * Copyright (c) 2008 Stephan Arts <stephan@xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <exo/exo.h>
+
+#include "twp-provider.h"
+
+
+
+static GType type_list[1];
+
+
+
+G_MODULE_EXPORT void
+thunar_extension_initialize (ThunarxProviderPlugin *plugin)
+{
+  const gchar *mismatch;
+
+  /* verify that the thunarx versions are compatible */
+  mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION, THUNARX_MINOR_VERSION, THUNARX_MICRO_VERSION);
+  if (G_UNLIKELY (mismatch != NULL))
+    {
+      g_warning ("Version mismatch: %s", mismatch);
+      return;
+    }
+
+  /* setup i18n support */
+  bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
+#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
+  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);
+
+  /* setup the plugin provider type list */
+  type_list[0] = TWP_TYPE_PROVIDER;
+}
+
+
+
+G_MODULE_EXPORT void
+thunar_extension_shutdown (void)
+{
+#ifdef G_ENABLE_DEBUG
+  g_message ("Shutting down thunar-wallpaper-plugin extension");
+#endif
+}
+
+
+
+G_MODULE_EXPORT void
+thunar_extension_list_types (const GType **types,
+                             gint         *n_types)
+{
+  *types = type_list;
+  *n_types = G_N_ELEMENTS (type_list);
+}
+
+
+
+
diff --git a/plugins/thunar-wallpaper/twp-provider.c b/plugins/thunar-wallpaper/twp-provider.c
new file mode 100644
index 000000000..08672ccbd
--- /dev/null
+++ b/plugins/thunar-wallpaper/twp-provider.c
@@ -0,0 +1,252 @@
+/*-
+ * Copyright (c) 2008 Stephan Arts <stephan@xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * 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.
+ */
+
+#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"
+
+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);
+static GList *twp_provider_get_folder_actions   (ThunarxMenuProvider      *menu_provider,
+                                                 GtkWidget                *window,
+                                                 ThunarxFileInfo          *folder);
+
+static
+twp_action_set_wallpaper (GtkAction *action, gpointer user_data);
+
+
+
+struct _TwpProviderClass
+{
+  GObjectClass __parent__;
+};
+
+struct _TwpProvider
+{
+  GObject         __parent__;
+
+  gchar          *child_watch_path;
+  gint            child_watch_id;
+};
+
+
+
+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));
+
+
+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)
+{
+  iface->get_file_actions = twp_provider_get_file_actions;
+}
+
+
+
+static void
+twp_provider_property_page_provider_init (ThunarxPropertyPageProviderIface *iface)
+{
+}
+
+
+
+static void
+twp_provider_init (TwpProvider *twp_provider)
+{
+    xfconf_init(NULL);
+	//twp_gpg_backend_init();
+}
+
+
+
+static void
+twp_provider_finalize (GObject *object)
+{
+    TwpProvider *twp_provider = TWP_PROVIDER (object);
+    GSource     *source;
+    xfconf_shutdown();
+
+   (*G_OBJECT_CLASS (twp_provider_parent_class)->finalize) (object);
+}
+
+static GList*
+twp_provider_get_file_actions (ThunarxMenuProvider *menu_provider,
+                               GtkWidget           *window,
+                               GList               *files)
+{
+	ThunarVfsPathScheme scheme;
+	ThunarVfsInfo      *info;
+	GtkWidget          *action;
+	GList              *actions = NULL;
+    gint                n_files = 0;
+    gchar               selection_name[100];
+
+    GdkScreen *gdk_screen = gdk_screen_get_default();
+    gint xscreen = gdk_screen_get_number(gdk_screen);
+
+    g_snprintf(selection_name, 100, XFDESKTOP_SELECTION_FMT, xscreen);
+
+    Window root_window = GDK_ROOT_WINDOW();
+    Atom xfce_selection_atom = XInternAtom (gdk_display, selection_name, False);
+    if(!(XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom)))
+    {
+        return NULL;
+    }
+
+    /* we can only set a single wallpaper */
+	if (files->next == NULL)
+	{
+		/* check if the file is a local file */
+		info = thunarx_file_info_get_vfs_info (files->data);
+		scheme = thunar_vfs_path_get_scheme (info->path);
+		thunar_vfs_info_unref (info);
+
+		/* unable to handle non-local files */
+		if (G_UNLIKELY (scheme != THUNAR_VFS_PATH_SCHEME_FILE))
+			return NULL;
+
+		if (!thunarx_file_info_is_directory (files->data))
+		{
+            if (thunarx_file_info_has_mime_type (files->data, "image/jpeg")
+              ||thunarx_file_info_has_mime_type (files->data, "image/png")
+              ||thunarx_file_info_has_mime_type (files->data, "image/svg+xml")
+              ||thunarx_file_info_has_mime_type (files->data, "image/svg+xml-compressed"))
+            {
+                action = g_object_new (GTK_TYPE_ACTION,
+                            "name", "Twp::setwallpaper",
+                            "label", _("Set as Wallpaper"),
+                            NULL);
+                g_signal_connect (action, "activate", G_CALLBACK (twp_action_set_wallpaper), files->data);
+
+                actions = g_list_append (actions, action);
+            }
+		}
+	}
+
+  return actions;
+}
+
+
+static GList*
+twp_Provider_get_pages (ThunarxPropertyPageProvider *page_provider, GList *files)
+{
+  GList *pages = NULL;
+  return pages;
+}
+
+static
+twp_action_set_wallpaper (GtkAction *action, gpointer user_data)
+{
+    ThunarxFileInfo *file_info = user_data;
+    GdkDisplay *display = gdk_display_get_default();
+    gint n_screens = gdk_display_get_n_screens (display);
+    gint screen_nr = 0;
+    gint n_monitors;
+    gint monitor_nr = 0;
+    GdkScreen *screen;
+    gchar *image_path_prop;
+    gchar *image_show_prop;
+    gchar *image_style_prop;
+    gchar *file_uri;
+    gchar *file_name;
+    gchar *hostname = NULL;
+
+    XfconfChannel *xfdesktop_channel = xfconf_channel_new("xfce4-desktop");
+
+    file_uri = thunarx_file_info_get_uri (file_info);
+    file_name = g_filename_from_uri (file_uri, &hostname, NULL);
+    if (hostname == NULL)
+    {
+        if (n_screens > 1)
+        {
+            screen = gdk_display_get_default_screen (display);
+        }
+        else
+        {
+            screen = gdk_display_get_screen (display, 0);
+        }
+
+        n_monitors = gdk_screen_get_n_monitors (screen);
+
+        if (n_monitors > 1)
+        {
+
+        }
+        
+        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);
+        }
+
+        g_free(image_path_prop);
+        g_free(image_show_prop);
+        g_free(image_style_prop);
+
+    }
+    g_free(file_uri);
+    g_free(file_name);
+    g_object_unref(xfdesktop_channel);
+
+    
+}
diff --git a/plugins/thunar-wallpaper/twp-provider.h b/plugins/thunar-wallpaper/twp-provider.h
new file mode 100644
index 000000000..670d63f75
--- /dev/null
+++ b/plugins/thunar-wallpaper/twp-provider.h
@@ -0,0 +1,43 @@
+/*-
+ * Copyright (c) 2008 Stephan Arts <stephan@xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * 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.
+ */
+
+#ifndef __TWP_PROVIDER_H__
+#define __TWP_PROVIDER_H__
+
+#include <thunarx/thunarx.h>
+
+G_BEGIN_DECLS;
+
+typedef struct _TwpProviderClass TwpProviderClass;
+typedef struct _TwpProvider      TwpProvider;
+
+#define TWP_TYPE_PROVIDER             (twp_provider_get_type ())
+#define TWP_PROVIDER(obj)             (G_TYPE_CHECK_INSTANCE_CAST ((obj), TWP_TYPE_PROVIDER, TwpProvider))
+#define TWP_PROVIDER_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST ((klass), TWP_TYPE_PROVIDER, TwpProviderClass))
+#define TWP_IS_PROVIDER(obj)          (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TWP_TYPE_PROVIDER))
+#define TWP_IS_PROVIDER_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE ((klass), TWP_TYPE_PROVIDER))
+#define TWP_PROVIDER_GET_CLASS(obj)   (G_TYPE_INSTANCE_GET_CLASS ((obj), TWP_TYPE_PROVIDER, TwpProviderClass))
+
+GType twp_provider_get_type      (void) G_GNUC_CONST G_GNUC_INTERNAL;
+void  twp_provider_register_type (ThunarxProviderPlugin *plugin) G_GNUC_INTERNAL;
+
+G_END_DECLS;
+
+#endif /* !__TWP_PROVIDER_H__ */
+
-- 
GitLab