[Xfce4-commits] <ristretto:master> Add desktop-chooser dialog for first-run.

Stephan Arts noreply at xfce.org
Wed Nov 23 06:52:06 CET 2011


Updating branch refs/heads/master
         to f23eed30888c666b6e221c86efae4b01aacfc8fd (commit)
       from d1008cd61d86985a01f3c13af379fdd8209a6638 (commit)

commit f23eed30888c666b6e221c86efae4b01aacfc8fd
Author: Stephan Arts <stephan at xfce.org>
Date:   Wed Nov 16 06:29:06 2011 +0100

    Add desktop-chooser dialog for first-run.
    
    Implement set-wallpaper for gnome (no idea if this works)

 src/Makefile.am               |    1 +
 src/gnome_wallpaper_manager.c |   94 +++++++++++++++++----------
 src/main_window.c             |  141 ++++++++++++++++++++++++++++++++++++++++-
 src/preferences_dialog.c      |   30 +--------
 src/util.h                    |    6 ++
 5 files changed, 209 insertions(+), 63 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 6e39af4..c5e810e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -11,6 +11,7 @@ ristretto_SOURCES = \
 	wallpaper_manager.c wallpaper_manager.h \
 	monitor_chooser.c monitor_chooser.h \
 	xfce_wallpaper_manager.c xfce_wallpaper_manager.h \
+	gnome_wallpaper_manager.c gnome_wallpaper_manager.h \
 	app_menu_item.c app_menu_item.h \
 	thumbnail_bar.c thumbnail_bar.h \
 	thumbnail.c thumbnail.h \
diff --git a/src/gnome_wallpaper_manager.c b/src/gnome_wallpaper_manager.c
index d1890b6..25c4352 100644
--- a/src/gnome_wallpaper_manager.c
+++ b/src/gnome_wallpaper_manager.c
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) Stephan Arts 2009-2010 <stephan at gnome.org>
+ *  Copyright (c) Stephan Arts 2009-2011 <stephan at gnome.org>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -22,10 +22,16 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include <X11/Xlib.h>
-#include <X11/Xatom.h>
-#include <X11/Xproto.h>
+#include <xfconf/xfconf.h>
+#include <libxfce4util/libxfce4util.h>
 #include <gio/gio.h>
 
+
+#include <libexif/exif-data.h>
+
+#include "util.h"
+#include "file.h"
+
 #include "wallpaper_manager.h"
 #include "gnome_wallpaper_manager.h"
 
@@ -36,6 +42,8 @@ typedef struct {
     gint16 a;
 } RsttoColor;
 
+#define IMAGE_PATH_PROP "/desktop/gnome/background/picture_filename"
+#define IMAGE_SHOW_PROP "/desktop/gnome/background/draw_background"
 
 static void
 rstto_gnome_wallpaper_manager_init (GObject *);
@@ -53,6 +61,9 @@ static RsttoWallpaperManager *gnome_wallpaper_manager_object;
 
 struct _RsttoGnomeWallpaperManagerPriv
 {
+    RsttoFile *file;
+
+    GtkWidget *dialog;
 };
 
 
@@ -62,46 +73,48 @@ enum
 };
 
 static gint 
-rstto_gnome_wallpaper_manager_configure_dialog_run (RsttoWallpaperManager *self, GFile *file)
+rstto_gnome_wallpaper_manager_configure_dialog_run (
+        RsttoWallpaperManager *self,
+        RsttoFile *file)
 {
-    RsttoGnomeWallpaperManager *manager = RSTTO_GNOME_WALLPAPER_MANAGER (self);
+    //RsttoGnomeWallpaperManager *manager = RSTTO_GNOME_WALLPAPER_MANAGER (self);
     gint response = GTK_RESPONSE_OK;
+
+    //response = gtk_dialog_run (GTK_DIALOG(manager->priv->dialog));
+    //gtk_widget_hide (manager->priv->dialog);
     return response;
 }
 
 static gboolean
-rstto_gnome_wallpaper_manager_check_running (RsttoWallpaperManager *self)
+rstto_gnome_wallpaper_manager_check_running (
+        RsttoWallpaperManager *self)
 {
-    GdkScreen *gdk_screen = gdk_screen_get_default();
-    GdkAtom gnome_selection_atom;
-    GdkAtom actual_type;
-    gint actual_format;
-    gint actual_length;
-    guchar *data;
-
-    gnome_selection_atom = gdk_atom_intern("NAUTILUS_DESKTOP_WINDOW_ID", FALSE);
-
-    if (gdk_property_get(gdk_screen_get_root_window(gdk_screen),
-                         gnome_selection_atom,
-                         GDK_NONE,
-                         0,
-                         1,
-                         FALSE,
-                         &actual_type,
-                         &actual_format,
-                         &actual_length,
-                         &data))
-    {
-        return TRUE;
-    }
-
-    return FALSE;
+    return TRUE;
 }
 
 static gboolean
-rstto_gnome_wallpaper_manager_set (RsttoWallpaperManager *self, GFile *file)
+rstto_gnome_wallpaper_manager_set (
+        RsttoWallpaperManager *self,
+        RsttoFile *file)
 {
-    RsttoGnomeWallpaperManager *manager = RSTTO_GNOME_WALLPAPER_MANAGER (self);
+    gchar *command = NULL;
+    gchar *escaped_file_name = g_shell_quote (
+            rstto_file_get_path (file));
+
+    command = g_strdup_printf (
+            "gconftool-2 %s --set %s --type string",
+            IMAGE_PATH_PROP,
+            escaped_file_name);
+
+    g_spawn_command_line_async (command, NULL);
+    g_free (command);
+
+    command = g_strdup_printf (
+            "gconftool-2 %s --set true --type boolean",
+            IMAGE_SHOW_PROP);
+
+    g_spawn_command_line_async (command, NULL);
+    g_free (command);
 
     return FALSE;
 }
@@ -153,9 +166,21 @@ rstto_gnome_wallpaper_manager_get_type (void)
 static void
 rstto_gnome_wallpaper_manager_init (GObject *object)
 {
-    RsttoGnomeWallpaperManager *gnome_wallpaper_manager = RSTTO_GNOME_WALLPAPER_MANAGER (object);
+    RsttoGnomeWallpaperManager *manager = RSTTO_GNOME_WALLPAPER_MANAGER (object);
 
-    gnome_wallpaper_manager->priv = g_new0 (RsttoGnomeWallpaperManagerPriv, 1);
+    manager->priv = g_new0 (RsttoGnomeWallpaperManagerPriv, 1);
+
+    manager->priv->dialog = gtk_dialog_new_with_buttons (
+            _("Set as wallpaper"),
+            NULL,
+            0,
+            GTK_STOCK_CANCEL,
+            GTK_RESPONSE_CANCEL,
+            GTK_STOCK_APPLY,
+            GTK_RESPONSE_APPLY,
+            GTK_STOCK_OK,
+            GTK_RESPONSE_OK,
+            NULL);
 }
 
 
@@ -219,3 +244,4 @@ rstto_gnome_wallpaper_manager_new (void)
 
     return gnome_wallpaper_manager_object;
 }
+
diff --git a/src/main_window.c b/src/main_window.c
index 8541688..94b138a 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -42,7 +42,9 @@
 #include "main_window_ui.h"
 #include "thumbnail_bar.h"
 #include "wallpaper_manager.h"
+
 #include "xfce_wallpaper_manager.h"
+#include "gnome_wallpaper_manager.h"
 
 #include "privacy_dialog.h"
 #include "properties_dialog.h"
@@ -432,7 +434,7 @@ rstto_main_window_init (RsttoMainWindow *window)
 
         if (!g_strcasecmp(desktop_type, "gnome"))
         {
-            //window->priv->wallpaper_manager = rstto_gnome_wallpaper_manager_new();
+            window->priv->wallpaper_manager = rstto_gnome_wallpaper_manager_new();
         }
 
         if (!g_strcasecmp(desktop_type, "none"))
@@ -1750,8 +1752,13 @@ cb_rstto_main_window_navigationtoolbar_position_changed (GtkRadioAction *action,
 static void
 cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *window)
 {
-    RsttoFile *file = NULL;
     gint response = GTK_RESPONSE_APPLY;
+    RsttoFile *file = NULL;
+    gchar *desktop_type = NULL;
+    GtkWidget *dialog = NULL;
+    GtkWidget *content_area = NULL;
+    GtkWidget *behaviour_desktop_lbl;
+    GtkWidget *choose_desktop_combo_box;
 
     if (window->priv->iter)
     {
@@ -1760,8 +1767,129 @@ cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *windo
 
     g_return_if_fail (NULL != file);
 
+    desktop_type = rstto_settings_get_string_property (window->priv->settings_manager, "desktop-type");
+    if (G_UNLIKELY (NULL == desktop_type))
+    {
+        /* No desktop has been selected, first time this feature is
+         * used. -- Ask the user which method he wants ristretto to
+         * apply to set the desktop wallpaper.
+         */
+        dialog = gtk_dialog_new_with_buttons (
+                _("Choose 'set wallpaper' method"),
+                GTK_WINDOW(window),
+                GTK_DIALOG_DESTROY_WITH_PARENT,
+                GTK_STOCK_OK,
+                GTK_RESPONSE_OK,
+                GTK_STOCK_CANCEL,
+                GTK_RESPONSE_CANCEL,
+                NULL);
+
+        /* Populate the dialog */
+        content_area = gtk_dialog_get_content_area (GTK_DIALOG(dialog));
+
+        behaviour_desktop_lbl = gtk_label_new(NULL);
+        gtk_label_set_markup (
+                GTK_LABEL (behaviour_desktop_lbl),
+                _("Configure which system is currently managing your desktop.\n"
+                  "This setting determines the method <i>Ristretto</i> will use\n"
+                  "to configure the desktop wallpaper."));
+        gtk_misc_set_alignment(
+                GTK_MISC(behaviour_desktop_lbl),
+                0,
+                0.5);
+        gtk_box_pack_start (
+                GTK_BOX (content_area),
+                behaviour_desktop_lbl,
+                FALSE,
+                FALSE,
+                0);
+
+        choose_desktop_combo_box =
+                gtk_combo_box_text_new();
+        gtk_box_pack_start (
+                GTK_BOX (content_area),
+                choose_desktop_combo_box,
+                FALSE,
+                FALSE,
+                0);
+        gtk_combo_box_text_insert_text(
+                GTK_COMBO_BOX_TEXT (choose_desktop_combo_box),
+                DESKTOP_TYPE_NONE,
+                _("None"));
+        gtk_combo_box_text_insert_text (
+                GTK_COMBO_BOX_TEXT (choose_desktop_combo_box),
+                DESKTOP_TYPE_XFCE,
+                _("Xfce"));
+        gtk_combo_box_text_insert_text (
+                GTK_COMBO_BOX_TEXT (choose_desktop_combo_box),
+                DESKTOP_TYPE_GNOME,
+                _("GNOME"));
+
+        gtk_combo_box_set_active (
+            GTK_COMBO_BOX (choose_desktop_combo_box),
+            DESKTOP_TYPE_XFCE);
+
+        gtk_widget_show_all (content_area);
+        
+
+
+        /* Show the dialog */
+        response = gtk_dialog_run (GTK_DIALOG(dialog));
+
+        /* If the response was 'OK', the user has made a choice */
+        if ( GTK_RESPONSE_OK == response )
+        {
+            switch (gtk_combo_box_get_active (
+                    GTK_COMBO_BOX (choose_desktop_combo_box)))
+            {
+                case DESKTOP_TYPE_NONE:
+                    rstto_settings_set_string_property (
+                            window->priv->settings_manager,
+                            "desktop-type",
+                            "none");
+                    if (NULL != window->priv->wallpaper_manager)
+                    {
+                        g_object_unref (window->priv->wallpaper_manager);
+                        window->priv->wallpaper_manager = NULL;
+                    }
+                    break;
+                case DESKTOP_TYPE_XFCE:
+                    rstto_settings_set_string_property (
+                            window->priv->settings_manager,
+                            "desktop-type",
+                            "xfce");
+                    if (NULL != window->priv->wallpaper_manager)
+                    {
+                        g_object_unref (window->priv->wallpaper_manager);
+                    }
+                    window->priv->wallpaper_manager = rstto_xfce_wallpaper_manager_new ();
+                    break;
+                case DESKTOP_TYPE_GNOME:
+                    rstto_settings_set_string_property (
+                            window->priv->settings_manager,
+                            "desktop-type",
+                            "gnome");
+                    if (NULL != window->priv->wallpaper_manager)
+                    {
+                        g_object_unref (window->priv->wallpaper_manager);
+                    }
+                    window->priv->wallpaper_manager = rstto_gnome_wallpaper_manager_new ();
+                    break;
+            }
+        
+        }
+
+        /* Clean-up the dialog */
+        gtk_widget_destroy (dialog);
+        dialog = NULL;
+    }
+
     if (window->priv->wallpaper_manager)
     {
+        /* Set the response to GTK_RESPONSE_APPLY,
+         * so we at least do one run.
+         */
+        response = GTK_RESPONSE_APPLY;
         while (GTK_RESPONSE_APPLY == response)
         {
             response = rstto_wallpaper_manager_configure_dialog_run (window->priv->wallpaper_manager, file);
@@ -1774,6 +1902,12 @@ cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *windo
             }
         }
     }
+
+    if (G_LIKELY (NULL != desktop_type))
+    {
+        g_free (desktop_type);
+        desktop_type = NULL;
+    }
 }
 
 static void
@@ -3031,7 +3165,7 @@ cb_rstto_desktop_type_changed (
 
         if (!g_strcasecmp(desktop_type, "gnome"))
         {
-            //window->priv->wallpaper_manager = rstto_gnome_wallpaper_manager_new();
+            window->priv->wallpaper_manager = rstto_gnome_wallpaper_manager_new();
         }
 
         if (!g_strcasecmp(desktop_type, "none"))
@@ -3050,3 +3184,4 @@ cb_rstto_desktop_type_changed (
 
     rstto_main_window_update_buttons (window);
 }
+
diff --git a/src/preferences_dialog.c b/src/preferences_dialog.c
index 5baa879..29781f6 100644
--- a/src/preferences_dialog.c
+++ b/src/preferences_dialog.c
@@ -21,6 +21,7 @@
 #include <libxfce4ui/libxfce4ui.h>
 #include <libxfce4util/libxfce4util.h>
 
+#include "util.h"
 #include "settings.h"
 #include "preferences_dialog.h"
 
@@ -32,12 +33,6 @@
 #define RSTTO_DEFAULT_CACHE_SIZE 256
 #endif
 
-enum {
-    DESKTOP_TYPE_NONE = 0,
-    DESKTOP_TYPE_XFCE,
-    DESKTOP_TYPE_GNOME,
-    DESKTOP_TYPE_OPENBOX
-};
 
 static void
 rstto_preferences_dialog_init(RsttoPreferencesDialog *);
@@ -380,12 +375,10 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
             GTK_COMBO_BOX_TEXT (dialog->priv->behaviour_tab.choose_desktop_combo_box),
             DESKTOP_TYPE_XFCE,
             _("Xfce"));
-    /*
     gtk_combo_box_text_insert_text (
             GTK_COMBO_BOX_TEXT (dialog->priv->behaviour_tab.choose_desktop_combo_box),
             DESKTOP_TYPE_GNOME,
             _("GNOME"));
-    */
 
     if (str_desktop_type != NULL)
     {
@@ -405,18 +398,9 @@ rstto_preferences_dialog_init(RsttoPreferencesDialog *dialog)
             }
             else
             {
-                if (0 == g_strcasecmp (str_desktop_type, "openbox"))
-                {
-                    gtk_combo_box_set_active (
-                        GTK_COMBO_BOX (dialog->priv->behaviour_tab.choose_desktop_combo_box),
-                        DESKTOP_TYPE_OPENBOX);
-                }
-                else
-                {
-                    gtk_combo_box_set_active (
-                        GTK_COMBO_BOX (dialog->priv->behaviour_tab.choose_desktop_combo_box),
-                        DESKTOP_TYPE_NONE);
-                }
+                gtk_combo_box_set_active (
+                    GTK_COMBO_BOX (dialog->priv->behaviour_tab.choose_desktop_combo_box),
+                    DESKTOP_TYPE_NONE);
             }
         }
     }
@@ -611,11 +595,5 @@ cb_choose_desktop_combo_box_changed (
                     "desktop-type",
                     "gnome");
             break;
-        case DESKTOP_TYPE_OPENBOX:
-            rstto_settings_set_string_property (
-                    dialog->priv->settings,
-                    "desktop-type",
-                    "openbox");
-            break;
     }
 }
diff --git a/src/util.h b/src/util.h
index 34020ac..71328b7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -34,6 +34,12 @@ typedef enum
   RSTTO_IMAGE_ORIENT_NOT_DETERMINED,
 } RsttoImageOrientation;
 
+typedef enum {
+    DESKTOP_TYPE_NONE = 0,
+    DESKTOP_TYPE_XFCE,
+    DESKTOP_TYPE_GNOME
+} RsttoDesktopType;
+
 gboolean
 rstto_launch_help (void);
 


More information about the Xfce4-commits mailing list