[Xfce4-commits] <ristretto:master> Add an apply button to the xfce-wallpaper-manager dialog.

Stephan Arts noreply at xfce.org
Fri Sep 16 11:00:01 CEST 2011


Updating branch refs/heads/master
         to 3fdd43048ac3fb58c744ff6196ea2004b0275426 (commit)
       from 2923174c4b9c1417c96d35039c0d02634faa6ffb (commit)

commit 3fdd43048ac3fb58c744ff6196ea2004b0275426
Author: Stephan Arts <stephan at xfce.org>
Date:   Fri Sep 16 10:57:22 2011 +0200

    Add an apply button to the xfce-wallpaper-manager dialog.

 src/main_window.c            |   13 +-
 src/monitor_chooser.c        |    8 +-
 src/xfce_wallpaper_manager.c |  422 ++++++++++++++++++++++--------------------
 3 files changed, 232 insertions(+), 211 deletions(-)

diff --git a/src/main_window.c b/src/main_window.c
index 62b237b..cb9a302 100644
--- a/src/main_window.c
+++ b/src/main_window.c
@@ -1337,6 +1337,8 @@ static void
 cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *window)
 {
     GFile *file = NULL;
+    gint response = GTK_RESPONSE_APPLY;
+
     if (window->priv->iter)
     {
         file = rstto_image_list_iter_get_file (window->priv->iter);
@@ -1346,9 +1348,16 @@ cb_rstto_main_window_set_as_wallpaper (GtkWidget *widget, RsttoMainWindow *windo
 
     if (window->priv->wallpaper_manager)
     {
-        if (rstto_wallpaper_manager_configure_dialog_run (window->priv->wallpaper_manager, file) == GTK_RESPONSE_OK)
+        while (GTK_RESPONSE_APPLY == response)
         {
-            rstto_wallpaper_manager_set (window->priv->wallpaper_manager, file);
+            response = rstto_wallpaper_manager_configure_dialog_run (window->priv->wallpaper_manager, file);
+            switch (response)
+            {
+                case GTK_RESPONSE_OK:
+                case GTK_RESPONSE_APPLY:
+                    rstto_wallpaper_manager_set (window->priv->wallpaper_manager, file);
+                    break;
+            }
         }
     }
 }
diff --git a/src/monitor_chooser.c b/src/monitor_chooser.c
index 2e57447..adda9f3 100644
--- a/src/monitor_chooser.c
+++ b/src/monitor_chooser.c
@@ -555,12 +555,12 @@ rstto_monitor_chooser_set_pixbuf (
         {
             g_object_unref (monitor->pixbuf);
         }
-        if (pixbuf)
-        {
-            g_object_ref (pixbuf);
-        }
         monitor->pixbuf = pixbuf;
     }
+    if (GTK_WIDGET_REALIZED (GTK_WIDGET(chooser)))
+    {
+        rstto_monitor_chooser_paint (GTK_WIDGET(chooser));
+    }
 }
 
 static void
diff --git a/src/xfce_wallpaper_manager.c b/src/xfce_wallpaper_manager.c
index 82668c8..a02615d 100644
--- a/src/xfce_wallpaper_manager.c
+++ b/src/xfce_wallpaper_manager.c
@@ -78,6 +78,10 @@ struct _RsttoXfceWallpaperManagerPriv
 
     GtkWidget *monitor_chooser;
     GtkWidget *style_combo;
+    GtkObject *saturation_adjustment;
+    GtkObject *brightness_adjustment;
+
+    GtkWidget *dialog;
 };
 
 
@@ -92,34 +96,235 @@ rstto_xfce_wallpaper_manager_configure_dialog_run (
         GFile *file)
 {
     RsttoXfceWallpaperManager *manager = RSTTO_XFCE_WALLPAPER_MANAGER (self);
-    gint response = GTK_RESPONSE_OK;
+    gint response = 0;
+    manager->priv->file = file;
+
+    rstto_monitor_chooser_set_pixbuf (
+            RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser),
+            0,
+            gdk_pixbuf_new_from_file_at_size(
+                    g_file_get_path(file),
+                    500,
+                    500,
+                    NULL),
+            NULL);
+
+    response = gtk_dialog_run (GTK_DIALOG (manager->priv->dialog));
+    gtk_widget_hide (manager->priv->dialog);
+    if ((response == GTK_RESPONSE_OK) || (response == GTK_RESPONSE_APPLY))
+    {
+        manager->priv->style = gtk_combo_box_get_active (
+                GTK_COMBO_BOX (manager->priv->style_combo));
+        manager->priv->saturation = gtk_adjustment_get_value (
+                GTK_ADJUSTMENT (manager->priv->saturation_adjustment));
+        manager->priv->brightness = (gint)gtk_adjustment_get_value (
+                GTK_ADJUSTMENT (manager->priv->brightness_adjustment));
+        manager->priv->monitor = rstto_monitor_chooser_get_selected (
+                RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser));
+    }
+    return response;
+}
+
+static gboolean
+rstto_xfce_wallpaper_manager_check_running (RsttoWallpaperManager *self)
+{
+    gchar selection_name[100];
+    Atom xfce_selection_atom;
+    GdkScreen *gdk_screen = gdk_screen_get_default();
+    gint xscreen = gdk_screen_get_number(gdk_screen);
+
+    g_snprintf(selection_name, 100, XFDESKTOP_SELECTION_FMT, xscreen);
+
+    xfce_selection_atom = XInternAtom (gdk_display, selection_name, False);
+    if((XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom)))
+    {
+        return TRUE;
+    }
+    return FALSE;
+}
+
+static gboolean
+rstto_xfce_wallpaper_manager_set (RsttoWallpaperManager *self, GFile *file)
+{
+    RsttoXfceWallpaperManager *manager = RSTTO_XFCE_WALLPAPER_MANAGER (self);
+
+    gchar *uri = g_file_get_path (file);
+
+    gchar *image_path_prop = g_strdup_printf (
+            "/backdrop/screen%d/monitor%d/image-path",
+            manager->priv->screen,
+            manager->priv->monitor);
+    gchar *image_show_prop = g_strdup_printf (
+            "/backdrop/screen%d/monitor%d/image-show",
+            manager->priv->screen,
+            manager->priv->monitor);
+    gchar *image_style_prop = g_strdup_printf (
+            "/backdrop/screen%d/monitor%d/image-style",
+            manager->priv->screen,
+            manager->priv->monitor);
+    gchar *brightness_prop = g_strdup_printf (
+            "/backdrop/screen%d/monitor%d/brightness",
+            manager->priv->screen,
+            manager->priv->monitor);
+    gchar *saturation_prop = g_strdup_printf (
+            "/backdrop/screen%d/monitor%d/saturation",
+            manager->priv->screen,
+            manager->priv->monitor);
+
+    gchar *color1_prop = g_strdup_printf (
+            "/backdrop/screen%d/monitor%d/color1",
+            manager->priv->screen,
+            manager->priv->monitor);
+    gchar *color2_prop = g_strdup_printf (
+            "/backdrop/screen%d/monitor%d/color2",
+            manager->priv->screen,
+            manager->priv->monitor);
+
+    xfconf_channel_set_string (
+            manager->priv->channel,
+            image_path_prop,
+            uri);
+    xfconf_channel_set_bool (
+            manager->priv->channel,
+            image_show_prop,
+            TRUE);
+    xfconf_channel_set_int (
+            manager->priv->channel,
+            image_style_prop,
+            manager->priv->style);
+
+    xfconf_channel_set_int (
+            manager->priv->channel,
+            brightness_prop,
+            manager->priv->brightness);
+    xfconf_channel_set_double (
+            manager->priv->channel,
+            saturation_prop,
+            manager->priv->saturation);
+
+    xfconf_channel_set_struct (
+            manager->priv->channel,
+            color1_prop,
+            manager->priv->color1,
+            XFCONF_TYPE_INT16, XFCONF_TYPE_INT16,
+            XFCONF_TYPE_INT16, XFCONF_TYPE_INT16,
+            G_TYPE_INVALID);
+    xfconf_channel_set_struct (
+            manager->priv->channel,
+            color2_prop,
+            manager->priv->color2,
+            XFCONF_TYPE_INT16, XFCONF_TYPE_INT16,
+            XFCONF_TYPE_INT16, XFCONF_TYPE_INT16,
+            G_TYPE_INVALID);
+
+    g_free (image_path_prop);
+    g_free (image_show_prop);
+    g_free (image_style_prop);
+    g_free (brightness_prop);
+    g_free (saturation_prop);
+    g_free (color1_prop);
+    g_free (color2_prop);
+
+    return FALSE;
+}
+
+static void
+rstto_xfce_wallpaper_manager_iface_init (RsttoWallpaperManagerIface *iface)
+{
+    iface->configure_dialog_run = rstto_xfce_wallpaper_manager_configure_dialog_run;
+    iface->check_running = rstto_xfce_wallpaper_manager_check_running;
+    iface->set = rstto_xfce_wallpaper_manager_set;
+}
+
+GType
+rstto_xfce_wallpaper_manager_get_type (void)
+{
+    static GType rstto_xfce_wallpaper_manager_type = 0;
+
+    if (!rstto_xfce_wallpaper_manager_type)
+    {
+        static const GTypeInfo rstto_xfce_wallpaper_manager_info = 
+        {
+            sizeof (RsttoXfceWallpaperManagerClass),
+            (GBaseInitFunc) NULL,
+            (GBaseFinalizeFunc) NULL,
+            (GClassInitFunc) rstto_xfce_wallpaper_manager_class_init,
+            (GClassFinalizeFunc) NULL,
+            NULL,
+            sizeof (RsttoXfceWallpaperManager),
+            0,
+            (GInstanceInitFunc) rstto_xfce_wallpaper_manager_init,
+            NULL
+        };
+
+        static const GInterfaceInfo wallpaper_manager_iface_info = 
+        {
+            (GInterfaceInitFunc) rstto_xfce_wallpaper_manager_iface_init,
+            NULL,
+            NULL
+        };
+
+        rstto_xfce_wallpaper_manager_type = g_type_register_static (
+                G_TYPE_OBJECT,
+                "RsttoXfceWallpaperManager",
+                &rstto_xfce_wallpaper_manager_info,
+                0);
+
+        g_type_add_interface_static (
+                rstto_xfce_wallpaper_manager_type,
+                RSTTO_WALLPAPER_MANAGER_TYPE,
+                &wallpaper_manager_iface_info);
+
+    }
+    return rstto_xfce_wallpaper_manager_type;
+}
+
+
+static void
+rstto_xfce_wallpaper_manager_init (GObject *object)
+{
+    RsttoXfceWallpaperManager *manager = RSTTO_XFCE_WALLPAPER_MANAGER (object);
+
+    manager->priv = g_new0 (RsttoXfceWallpaperManagerPriv, 1);
+    manager->priv->channel = xfconf_channel_new ("xfce4-desktop");
+    manager->priv->color1 = g_new0 (RsttoColor, 1);
+    manager->priv->color1->a = 0xffff;
+    manager->priv->color2 = g_new0 (RsttoColor, 1);
+    manager->priv->color2->a = 0xffff;
+    manager->priv->style = 4;
+    manager->priv->brightness = 0;
+    manager->priv->saturation = 1.0;
+
     gint i;
     gchar *str = NULL;
     GdkScreen *screen = gdk_screen_get_default ();
     gint n_monitors = gdk_screen_get_n_monitors (screen);
     GdkRectangle monitor_geometry;
-    GtkWidget *dialog = gtk_dialog_new_with_buttons (
+    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);
-    GtkWidget *vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+    GtkWidget *vbox = gtk_dialog_get_content_area (
+            GTK_DIALOG (manager->priv->dialog));
     GtkWidget *style_label = gtk_label_new( _("Style:"));
     GtkWidget *monitor_label = gtk_label_new( _("Monitor:"));
     GtkWidget *brightness_label = gtk_label_new( _("Brightness:"));
     GtkWidget *saturation_label = gtk_label_new( _("Saturation:"));
-    GtkObject *brightness_adjustment = gtk_adjustment_new (
+    manager->priv->brightness_adjustment = gtk_adjustment_new (
             0.0,
             -128.0,
             127.0,
             1.0,
             10.0,
             0.0);
-    GtkObject *saturation_adjustment = gtk_adjustment_new (
+    manager->priv->saturation_adjustment = gtk_adjustment_new (
             1.0,
             -10.0,
             10.0,
@@ -127,9 +332,9 @@ rstto_xfce_wallpaper_manager_configure_dialog_run (
             0.5,
             0.0);
     GtkWidget *brightness_slider = gtk_hscale_new (
-            GTK_ADJUSTMENT (brightness_adjustment));
+            GTK_ADJUSTMENT (manager->priv->brightness_adjustment));
     GtkWidget *saturation_slider = gtk_hscale_new (
-            GTK_ADJUSTMENT (saturation_adjustment));
+            GTK_ADJUSTMENT (manager->priv->saturation_adjustment));
     GdkPixbuf *image_pixbuf = gtk_icon_theme_load_icon (
             gtk_icon_theme_get_default(),
             "image-missing",
@@ -140,7 +345,6 @@ rstto_xfce_wallpaper_manager_configure_dialog_run (
 
     manager->priv->monitor_chooser = rstto_monitor_chooser_new ();
     manager->priv->style_combo = gtk_combo_box_text_new();
-    manager->priv->file = file;
 
     gtk_table_set_row_spacing (GTK_TABLE(image_prop_table), 1, 4);
 
@@ -155,15 +359,10 @@ rstto_xfce_wallpaper_manager_configure_dialog_run (
                 monitor_geometry.width,
                 monitor_geometry.height);
     }
-    rstto_monitor_chooser_set_pixbuf (
-            RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser),
-            0,
-            gdk_pixbuf_new_from_file_at_size(
-                    g_file_get_path(file),
-                    500,
-                    500,
-                    NULL),
-            NULL);
+        rstto_monitor_chooser_add (
+                RSTTO_MONITOR_CHOOSER (manager->priv->monitor_chooser),
+                monitor_geometry.width,
+                monitor_geometry.height);
     rstto_monitor_chooser_set_style (
             RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser),
             0,
@@ -288,7 +487,7 @@ rstto_xfce_wallpaper_manager_configure_dialog_run (
 
     manager->priv->screen = gdk_screen_get_number (screen);
 
-    gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+    gtk_window_set_resizable (GTK_WINDOW (manager->priv->dialog), FALSE);
 
     g_signal_connect (
             G_OBJECT(manager->priv->monitor_chooser),
@@ -302,193 +501,6 @@ rstto_xfce_wallpaper_manager_configure_dialog_run (
             manager);
 
     gtk_widget_show_all (vbox);
-    response = gtk_dialog_run (GTK_DIALOG (dialog));
-    gtk_widget_hide (dialog);
-    if (response == GTK_RESPONSE_OK)
-    {
-        manager->priv->style = gtk_combo_box_get_active (
-                GTK_COMBO_BOX (manager->priv->style_combo));
-        manager->priv->saturation = gtk_adjustment_get_value (
-                GTK_ADJUSTMENT (saturation_adjustment));
-        manager->priv->brightness = (gint)gtk_adjustment_get_value (
-                GTK_ADJUSTMENT (brightness_adjustment));
-        manager->priv->monitor = rstto_monitor_chooser_get_selected (
-                RSTTO_MONITOR_CHOOSER(manager->priv->monitor_chooser));
-    }
-
-    gtk_widget_destroy (dialog);
-    return response;
-}
-
-static gboolean
-rstto_xfce_wallpaper_manager_check_running (RsttoWallpaperManager *self)
-{
-    gchar selection_name[100];
-    Atom xfce_selection_atom;
-    GdkScreen *gdk_screen = gdk_screen_get_default();
-    gint xscreen = gdk_screen_get_number(gdk_screen);
-
-    g_snprintf(selection_name, 100, XFDESKTOP_SELECTION_FMT, xscreen);
-
-    xfce_selection_atom = XInternAtom (gdk_display, selection_name, False);
-    if((XGetSelectionOwner(GDK_DISPLAY(), xfce_selection_atom)))
-    {
-        return TRUE;
-    }
-    return FALSE;
-}
-
-static gboolean
-rstto_xfce_wallpaper_manager_set (RsttoWallpaperManager *self, GFile *file)
-{
-    RsttoXfceWallpaperManager *manager = RSTTO_XFCE_WALLPAPER_MANAGER (self);
-
-    gchar *uri = g_file_get_path (file);
-
-    gchar *image_path_prop = g_strdup_printf (
-            "/backdrop/screen%d/monitor%d/image-path",
-            manager->priv->screen,
-            manager->priv->monitor);
-    gchar *image_show_prop = g_strdup_printf (
-            "/backdrop/screen%d/monitor%d/image-show",
-            manager->priv->screen,
-            manager->priv->monitor);
-    gchar *image_style_prop = g_strdup_printf (
-            "/backdrop/screen%d/monitor%d/image-style",
-            manager->priv->screen,
-            manager->priv->monitor);
-    gchar *brightness_prop = g_strdup_printf (
-            "/backdrop/screen%d/monitor%d/brightness",
-            manager->priv->screen,
-            manager->priv->monitor);
-    gchar *saturation_prop = g_strdup_printf (
-            "/backdrop/screen%d/monitor%d/saturation",
-            manager->priv->screen,
-            manager->priv->monitor);
-
-    gchar *color1_prop = g_strdup_printf (
-            "/backdrop/screen%d/monitor%d/color1",
-            manager->priv->screen,
-            manager->priv->monitor);
-    gchar *color2_prop = g_strdup_printf (
-            "/backdrop/screen%d/monitor%d/color2",
-            manager->priv->screen,
-            manager->priv->monitor);
-
-    xfconf_channel_set_string (
-            manager->priv->channel,
-            image_path_prop,
-            uri);
-    xfconf_channel_set_bool (
-            manager->priv->channel,
-            image_show_prop,
-            TRUE);
-    xfconf_channel_set_int (
-            manager->priv->channel,
-            image_style_prop,
-            manager->priv->style);
-
-    xfconf_channel_set_int (
-            manager->priv->channel,
-            brightness_prop,
-            manager->priv->brightness);
-    xfconf_channel_set_double (
-            manager->priv->channel,
-            saturation_prop,
-            manager->priv->saturation);
-
-    xfconf_channel_set_struct (
-            manager->priv->channel,
-            color1_prop,
-            manager->priv->color1,
-            XFCONF_TYPE_INT16, XFCONF_TYPE_INT16,
-            XFCONF_TYPE_INT16, XFCONF_TYPE_INT16,
-            G_TYPE_INVALID);
-    xfconf_channel_set_struct (
-            manager->priv->channel,
-            color2_prop,
-            manager->priv->color2,
-            XFCONF_TYPE_INT16, XFCONF_TYPE_INT16,
-            XFCONF_TYPE_INT16, XFCONF_TYPE_INT16,
-            G_TYPE_INVALID);
-
-    g_free (image_path_prop);
-    g_free (image_show_prop);
-    g_free (image_style_prop);
-    g_free (brightness_prop);
-    g_free (saturation_prop);
-    g_free (color1_prop);
-    g_free (color2_prop);
-
-    return FALSE;
-}
-
-static void
-rstto_xfce_wallpaper_manager_iface_init (RsttoWallpaperManagerIface *iface)
-{
-    iface->configure_dialog_run = rstto_xfce_wallpaper_manager_configure_dialog_run;
-    iface->check_running = rstto_xfce_wallpaper_manager_check_running;
-    iface->set = rstto_xfce_wallpaper_manager_set;
-}
-
-GType
-rstto_xfce_wallpaper_manager_get_type (void)
-{
-    static GType rstto_xfce_wallpaper_manager_type = 0;
-
-    if (!rstto_xfce_wallpaper_manager_type)
-    {
-        static const GTypeInfo rstto_xfce_wallpaper_manager_info = 
-        {
-            sizeof (RsttoXfceWallpaperManagerClass),
-            (GBaseInitFunc) NULL,
-            (GBaseFinalizeFunc) NULL,
-            (GClassInitFunc) rstto_xfce_wallpaper_manager_class_init,
-            (GClassFinalizeFunc) NULL,
-            NULL,
-            sizeof (RsttoXfceWallpaperManager),
-            0,
-            (GInstanceInitFunc) rstto_xfce_wallpaper_manager_init,
-            NULL
-        };
-
-        static const GInterfaceInfo wallpaper_manager_iface_info = 
-        {
-            (GInterfaceInitFunc) rstto_xfce_wallpaper_manager_iface_init,
-            NULL,
-            NULL
-        };
-
-        rstto_xfce_wallpaper_manager_type = g_type_register_static (
-                G_TYPE_OBJECT,
-                "RsttoXfceWallpaperManager",
-                &rstto_xfce_wallpaper_manager_info,
-                0);
-
-        g_type_add_interface_static (
-                rstto_xfce_wallpaper_manager_type,
-                RSTTO_WALLPAPER_MANAGER_TYPE,
-                &wallpaper_manager_iface_info);
-
-    }
-    return rstto_xfce_wallpaper_manager_type;
-}
-
-
-static void
-rstto_xfce_wallpaper_manager_init (GObject *object)
-{
-    RsttoXfceWallpaperManager *xfce_wallpaper_manager = RSTTO_XFCE_WALLPAPER_MANAGER (object);
-
-    xfce_wallpaper_manager->priv = g_new0 (RsttoXfceWallpaperManagerPriv, 1);
-    xfce_wallpaper_manager->priv->channel = xfconf_channel_new ("xfce4-desktop");
-    xfce_wallpaper_manager->priv->color1 = g_new0 (RsttoColor, 1);
-    xfce_wallpaper_manager->priv->color1->a = 0xffff;
-    xfce_wallpaper_manager->priv->color2 = g_new0 (RsttoColor, 1);
-    xfce_wallpaper_manager->priv->color2->a = 0xffff;
-    xfce_wallpaper_manager->priv->style = 4;
-    xfce_wallpaper_manager->priv->brightness = 0;
-    xfce_wallpaper_manager->priv->saturation = 1.0;
 }
 
 


More information about the Xfce4-commits mailing list