[Xfce4-commits] <xfce4-settings:master> Add theme installation basics with dnd.

Nick Schermer noreply at xfce.org
Sat Oct 22 19:28:02 CEST 2011


Updating branch refs/heads/master
         to 2eb6b06c424d3a97f03c872e1ac447462b20c697 (commit)
       from ab9bd9a2757a81675632b8837eaee1928960a39b (commit)

commit 2eb6b06c424d3a97f03c872e1ac447462b20c697
Author: Nick Schermer <nick at xfce.org>
Date:   Sat Oct 22 19:24:54 2011 +0200

    Add theme installation basics with dnd.
    
    Script does nothing yet, but this implements the
    basics in the appearance dialog.

 configure.ac.in                                    |   12 +++-
 dialogs/appearance-settings/Makefile.am            |    5 +
 .../appearance-settings/appearance-install-theme   |    3 +
 dialogs/appearance-settings/main.c                 |   79 ++++++++++++++++++++
 4 files changed, 98 insertions(+), 1 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index 3d33a53..80b1a45 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -63,7 +63,7 @@ AC_PROG_LIBTOOL()
 dnl **********************************
 dnl *** Check for standard headers ***
 dnl **********************************
-AC_CHECK_HEADERS([errno.h memory.h math.h stdlib.h string.h unistd.h signal.h time.h sys/types.h])
+AC_CHECK_HEADERS([errno.h memory.h math.h stdlib.h string.h unistd.h signal.h time.h sys/types.h sys/wait.h])
 AC_CHECK_FUNCS([daemon setsid])
 
 dnl ******************************
@@ -182,6 +182,16 @@ if test x"$enable_sound_settings" = x"yes"; then
 fi
 AC_SUBST(ENABLE_SOUND_SETTINGS)
 
+dnl ******************************
+dnl *** Set helper path prefix ***
+dnl ******************************
+AC_ARG_WITH([helper-path-prefix],
+            [AC_HELP_STRING([--with-helper-path-prefix=PATH],
+                            [Path prefix under which helper executables will be installed (default: $libdir)])],
+            [HELPER_PATH_PREFIX="$withval"],
+            [HELPER_PATH_PREFIX="$libdir"])
+AC_SUBST([HELPER_PATH_PREFIX])
+
 dnl ***********************************
 dnl *** Check for debugging support ***
 dnl ***********************************
diff --git a/dialogs/appearance-settings/Makefile.am b/dialogs/appearance-settings/Makefile.am
index 66a946a..9839581 100644
--- a/dialogs/appearance-settings/Makefile.am
+++ b/dialogs/appearance-settings/Makefile.am
@@ -5,6 +5,7 @@ INCLUDES = \
 	-DDATADIR=\"$(datadir)\" \
 	-DSRCDIR=\"$(top_srcdir)\" \
 	-DLOCALEDIR=\"$(localedir)\" \
+	-DHELPERDIR=\"$(HELPER_PATH_PREFIX)/xfce4/settings\" \
 	-DG_LOG_DOMAIN=\"xfce4-appearance-settings\" \
 	$(PLATFORM_CPPFLAGS)
 
@@ -31,6 +32,9 @@ xfce4_appearance_settings_LDADD = \
 	$(LIBXFCE4UI_LIBS) \
 	$(XFCONF_LIBS)
 
+xfce4_appearance_scriptsdir = $(HELPER_PATH_PREFIX)/xfce4/settings
+xfce4_appearance_scripts_SCRIPTS = appearance-install-theme
+
 if MAINTAINER_MODE
 
 BUILT_SOURCES = \
@@ -49,6 +53,7 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 
 EXTRA_DIST = \
 	$(desktop_in_files) \
+	appearance-install-theme \
 	appearance-dialog.glade
 
 DISTCLEANFILES = \
diff --git a/dialogs/appearance-settings/appearance-install-theme b/dialogs/appearance-settings/appearance-install-theme
new file mode 100644
index 0000000..c52d3c2
--- /dev/null
+++ b/dialogs/appearance-settings/appearance-install-theme
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+exit 0
diff --git a/dialogs/appearance-settings/main.c b/dialogs/appearance-settings/main.c
index 76b0ee0..e324660 100644
--- a/dialogs/appearance-settings/main.c
+++ b/dialogs/appearance-settings/main.c
@@ -27,6 +27,9 @@
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
 
 #include <glib.h>
 #include <gtk/gtk.h>
@@ -78,6 +81,11 @@ static const gchar* xft_rgba_array[] =
     "none", "rgb", "bgr", "vrgb", "vbgr"
 };
 
+static const GtkTargetEntry theme_drop_targets[] =
+{
+  { "text/uri-list", 0, 0 }
+};
+
 /* Option entries */
 static GdkNativeWindow opt_socket_id = 0;
 static gboolean opt_version = FALSE;
@@ -669,6 +677,67 @@ appearance_settings_dialog_channel_property_changed (XfconfChannel *channel,
 }
 
 static void
+cb_theme_uri_dropped (GtkWidget        *widget,
+                      GdkDragContext   *drag_context,
+                      gint              x,
+                      gint              y,
+                      GtkSelectionData *data,
+                      guint             info,
+                      guint             timestamp)
+{
+    gchar     **uris;
+    gchar      *argv[3];
+    guint       i;
+    GError     *error = NULL;
+    gint        status;
+    GtkWidget  *toplevel;
+    gchar      *filename;
+
+    uris = gtk_selection_data_get_uris (data);
+    if (uris != NULL)
+    {
+        argv[0] = HELPERDIR G_DIR_SEPARATOR_S "appearance-install-theme";
+        argv[2] = NULL;
+
+        toplevel = gtk_widget_get_toplevel (widget);
+
+        for (i = 0; uris[i] != NULL; i++)
+        {
+            filename = g_filename_from_uri (uris[i], NULL, NULL);
+            if (filename == NULL)
+                continue;
+
+            argv[1] = filename;
+
+            if (g_spawn_sync (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, &status, &error)
+                && status > 0)
+            {
+                switch (WEXITSTATUS (status))
+                {
+                    case 1:
+
+                        break;
+
+                    default:
+                        g_set_error_literal (&error, 0, 0, _("An unknown error occured"));
+                        break;
+                }
+            }
+
+            if (error != NULL)
+            {
+                xfce_dialog_show_error (GTK_WINDOW (toplevel), error, _("Failed to install theme"));
+                g_clear_error (&error);
+            }
+
+            g_free (filename);
+        }
+
+        g_strfreev (uris);
+    }
+}
+
+static void
 appearance_settings_dialog_configure_widgets (GtkBuilder *builder)
 {
     GObject          *object, *object2;
@@ -696,6 +765,11 @@ appearance_settings_dialog_configure_widgets (GtkBuilder *builder)
     gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
     g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (cb_icon_theme_tree_selection_changed), NULL);
 
+    gtk_drag_dest_set (GTK_WIDGET (object), GTK_DEST_DEFAULT_ALL,
+                       theme_drop_targets, G_N_ELEMENTS (theme_drop_targets),
+                       GDK_ACTION_COPY);
+    g_signal_connect (G_OBJECT (object), "drag-data-received", G_CALLBACK (cb_theme_uri_dropped), NULL);
+
     /* Gtk (UI) themes */
     object = gtk_builder_get_object (builder, "gtk_theme_treeview");
 
@@ -715,6 +789,11 @@ appearance_settings_dialog_configure_widgets (GtkBuilder *builder)
     gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
     g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (cb_ui_theme_tree_selection_changed), NULL);
 
+    gtk_drag_dest_set (GTK_WIDGET (object), GTK_DEST_DEFAULT_ALL,
+                       theme_drop_targets, G_N_ELEMENTS (theme_drop_targets),
+                       GDK_ACTION_COPY);
+    g_signal_connect (G_OBJECT (object), "drag-data-received", G_CALLBACK (cb_theme_uri_dropped), NULL);
+
     /* Subpixel (rgba) hinting Combo */
     object = gtk_builder_get_object (builder, "xft_rgba_store");
 


More information about the Xfce4-commits mailing list