[Xfce4-commits] <xfce4-settings:xrandr-display-settings> Add timed user confirmation (Xfce bug #867).

Jérôme Guelfucci noreply at xfce.org
Sun Jun 27 15:52:02 CEST 2010


Updating branch refs/heads/xrandr-display-settings
         to ed1a8ce66a1dd9af39cda99e1cd23dec3a474cad (commit)
       from 2a927783de14ed4715b7611b0dc53d84e33d989f (commit)

commit ed1a8ce66a1dd9af39cda99e1cd23dec3a474cad
Author: Jérôme Guelfucci <jeromeg at xfce.org>
Date:   Sun Jun 27 15:47:53 2010 +0200

    Add timed user confirmation (Xfce bug #867).
    
    Add a dialog to revert the changes. The dialog allows the user to
    validate the current configuration or to restore the previous one. If
    the user does not reply to the dialog within 5 seconds, it restores the
    previous configuration.

 dialogs/display-settings/Makefile.am               |    6 +
 ...play-dialog.glade => confirmation-dialog.glade} |   94 +++-----
 dialogs/display-settings/main.c                    |  244 +++++++++++++++++++-
 po/POTFILES.in                                     |    1 +
 4 files changed, 278 insertions(+), 67 deletions(-)

diff --git a/dialogs/display-settings/Makefile.am b/dialogs/display-settings/Makefile.am
index 987a2e6..c862306 100644
--- a/dialogs/display-settings/Makefile.am
+++ b/dialogs/display-settings/Makefile.am
@@ -18,6 +18,7 @@ xfce4_display_settings_SOURCES = \
 	xfce-randr.h \
 	xfce-randr-legacy.c \
 	xfce-randr-legacy.h \
+	confirmation-dialog_ui.h \
 	display-dialog_ui.h \
 	minimal-display-dialog_ui.h \
 	display-name.c \
@@ -46,9 +47,13 @@ xfce4_display_settings_LDADD = \
 if MAINTAINER_MODE
 
 BUILT_SOURCES = \
+	confirmation-dialog_ui.h
 	display-dialog_ui.h \
 	minimal-display-dialog_ui.h
 
+confirmation-dialog_ui.h: confirmation-dialog.glade
+	exo-csource --static --strip-comments --strip-content --name=confirmation_dialog_ui $< >$@
+
 display-dialog_ui.h: display-dialog.glade
 	exo-csource --static --strip-comments --strip-content --name=display_dialog_ui $< >$@
 
@@ -65,6 +70,7 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 
 EXTRA_DIST = \
 	$(desktop_in_files) \
+	confirmation-dialog.glade \
 	display-dialog.glade \
 	minimal-display-dialog.glade
 
diff --git a/dialogs/display-settings/minimal-display-dialog.glade b/dialogs/display-settings/confirmation-dialog.glade
similarity index 51%
copy from dialogs/display-settings/minimal-display-dialog.glade
copy to dialogs/display-settings/confirmation-dialog.glade
index 218aff8..85b1910 100644
--- a/dialogs/display-settings/minimal-display-dialog.glade
+++ b/dialogs/display-settings/confirmation-dialog.glade
@@ -4,10 +4,10 @@
   <!-- interface-naming-policy project-wide -->
   <object class="GtkDialog" id="dialog1">
     <property name="border_width">5</property>
-    <property name="title" translatable="yes">Display settings</property>
+    <property name="title" translatable="yes">Confirmation</property>
     <property name="resizable">False</property>
     <property name="window_position">center</property>
-    <property name="icon_name">video-display</property>
+    <property name="icon_name">dialog-question</property>
     <property name="type_hint">normal</property>
     <property name="has_separator">False</property>
     <child internal-child="vbox">
@@ -16,28 +16,34 @@
         <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child>
-          <object class="GtkVBox" id="vbox1">
+          <object class="GtkHBox" id="hbox1">
             <property name="visible">True</property>
-            <property name="orientation">vertical</property>
             <child>
-              <object class="GtkLabel" id="label1">
+              <object class="GtkImage" id="image1">
                 <property name="visible">True</property>
-                <property name="label" translatable="yes">Several displays are available. Use:
-</property>
+                <property name="xalign">0.20000000298023224</property>
+                <property name="xpad">10</property>
+                <property name="stock">gtk-dialog-question</property>
+                <property name="icon-size">6</property>
               </object>
               <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="position">0</property>
               </packing>
             </child>
             <child>
-              <object class="GtkHBox" id="hbox1">
+              <object class="GtkVBox" id="vbox1">
                 <property name="visible">True</property>
+                <property name="orientation">vertical</property>
                 <child>
-                  <object class="GtkImage" id="image1">
+                  <object class="GtkLabel" id="label1">
                     <property name="visible">True</property>
-                    <property name="xpad">20</property>
-                    <property name="pixel_size">64</property>
-                    <property name="icon_name">video-display</property>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="ypad">10</property>
+                    <property name="label" translatable="yes"><big><b>Would you like to keep this configuration?</b></big></property>
+                    <property name="use_markup">True</property>
                   </object>
                   <packing>
                     <property name="expand">False</property>
@@ -46,52 +52,17 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkVBox" id="vbox3">
+                  <object class="GtkLabel" id="label2">
                     <property name="visible">True</property>
-                    <property name="orientation">vertical</property>
-                    <property name="spacing">4</property>
-                    <child>
-                      <object class="GtkRadioButton" id="radiobutton1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="active">True</property>
-                        <property name="draw_indicator">True</property>
-                      </object>
-                      <packing>
-                        <property name="position">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkRadioButton" id="radiobutton2">
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="active">True</property>
-                        <property name="draw_indicator">True</property>
-                        <property name="group">radiobutton1</property>
-                      </object>
-                      <packing>
-                        <property name="position">1</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkRadioButton" id="radiobutton3">
-                        <property name="label" translatable="yes">Both displays cloned</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">True</property>
-                        <property name="receives_default">True</property>
-                        <property name="tooltip_text" translatable="yes">Use both displays to show the same contents</property>
-                        <property name="active">True</property>
-                        <property name="draw_indicator">True</property>
-                        <property name="group">radiobutton1</property>
-                      </object>
-                      <packing>
-                        <property name="position">2</property>
-                      </packing>
-                    </child>
+                    <property name="xalign">0</property>
+                    <property name="yalign">0</property>
+                    <property name="ypad">10</property>
+                    <property name="label" translatable="yes">The previous configuration will be restored in 5 seconds if you do not reply to this question.</property>
+                    <property name="wrap">True</property>
                   </object>
                   <packing>
+                    <property name="expand">False</property>
+                    <property name="fill">False</property>
                     <property name="position">1</property>
                   </packing>
                 </child>
@@ -102,7 +73,6 @@
             </child>
           </object>
           <packing>
-            <property name="padding">4</property>
             <property name="position">1</property>
           </packing>
         </child>
@@ -112,11 +82,12 @@
             <property name="layout_style">end</property>
             <child>
               <object class="GtkButton" id="button2">
-                <property name="label">gtk-cancel</property>
+                <property name="label" translatable="yes">Keep this configuration</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
+                <property name="can_default">True</property>
+                <property name="has_default">True</property>
                 <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -126,13 +97,10 @@
             </child>
             <child>
               <object class="GtkButton" id="button1">
-                <property name="label">gtk-ok</property>
+                <property name="label" translatable="yes">Restore the previous configuration</property>
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="can_default">True</property>
-                <property name="has_default">True</property>
                 <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -150,7 +118,7 @@
       </object>
     </child>
     <action-widgets>
-      <action-widget response="0">button2</action-widget>
+      <action-widget response="2">button2</action-widget>
       <action-widget response="1">button1</action-widget>
     </action-widgets>
   </object>
diff --git a/dialogs/display-settings/main.c b/dialogs/display-settings/main.c
index 44bceb7..6612134 100644
--- a/dialogs/display-settings/main.c
+++ b/dialogs/display-settings/main.c
@@ -43,6 +43,7 @@
 #include "xfce-randr.h"
 #include "xfce-randr-legacy.h"
 #include "display-dialog_ui.h"
+#include "confirmation-dialog_ui.h"
 #ifdef HAS_RANDR_ONE_POINT_TWO
 #include "minimal-display-dialog_ui.h"
 #endif
@@ -88,6 +89,15 @@ static const XfceRotation reflection_names[] =
 
 
 
+/* confirmation dialog data */
+typedef struct
+{
+    GtkBuilder *builder;
+    gint count;
+} ConfirmationDialog;
+
+
+
 /* option entries */
 static gboolean opt_version = FALSE;
 #ifdef HAS_RANDR_ONE_POINT_TWO
@@ -135,6 +145,90 @@ display_setting_combo_box_get_value (GtkComboBox *combobox,
     return FALSE;
 }
 
+static gboolean
+display_settings_update_time_label (ConfirmationDialog *confirmation_dialog)
+{
+    GObject *dialog;
+
+    dialog = gtk_builder_get_object (confirmation_dialog->builder, "dialog1");
+    confirmation_dialog->count--;
+
+    if (confirmation_dialog->count <= 0)
+    {
+        gtk_dialog_response (GTK_DIALOG (dialog), 1);
+
+        return FALSE;
+    }
+    else
+    {
+        GObject *label;
+        gchar   *string;
+
+        string = g_strdup_printf (_("The previous configuration will be restored in %i"
+                                    " seconds if you do not reply to this question."),
+                                  confirmation_dialog->count);
+
+        label = gtk_builder_get_object (confirmation_dialog->builder, "label2");
+        gtk_label_set_text (GTK_LABEL (label), string);
+
+        return TRUE;
+    }
+
+    return TRUE;
+}
+
+
+/* Returns true if the configuration is to be kept or false if it is to
+ * be reverted */
+static gboolean
+display_setting_timed_confirmation (GtkBuilder *main_builder)
+{
+    GtkBuilder *builder;
+    GObject    *main_dialog;
+    GError     *error = NULL;
+    gint        response_id;
+    gint        source_id;
+
+    /* Lock the main UI */
+    main_dialog = gtk_builder_get_object (main_builder, "display-dialog");
+    gtk_widget_set_sensitive (GTK_WIDGET (main_dialog), FALSE);
+
+    builder = gtk_builder_new ();
+
+    if (gtk_builder_add_from_string (builder, confirmation_dialog_ui,
+                                     confirmation_dialog_ui_length, &error) != 0)
+    {
+        GObject *dialog;
+        ConfirmationDialog *confirmation_dialog;
+
+        confirmation_dialog = g_new0 (ConfirmationDialog, 1);
+        confirmation_dialog->builder = builder;
+        confirmation_dialog->count = 5;
+
+        dialog = gtk_builder_get_object (builder, "dialog1");
+        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (main_dialog));
+        source_id = g_timeout_add_seconds (1, (GSourceFunc) display_settings_update_time_label,
+                                           confirmation_dialog);
+
+        response_id = gtk_dialog_run (GTK_DIALOG (dialog));
+        g_source_remove (source_id);
+        gtk_widget_destroy (GTK_WIDGET (dialog));
+    }
+    else
+    {
+        response_id = 2;
+        g_error ("Failed to load the UI file: %s.", error->message);
+        g_error_free (error);
+    }
+
+    g_object_unref (G_OBJECT (builder));
+
+    /* Unlock the main UI */
+    gtk_widget_set_sensitive (GTK_WIDGET (main_dialog), TRUE);
+
+    return ((response_id == 2) ? TRUE : FALSE);
+}
+
 
 
 #ifdef HAS_RANDR_ONE_POINT_TWO
@@ -149,12 +243,23 @@ display_setting_reflections_changed (GtkComboBox *combobox,
 
     if (xfce_randr)
     {
+        Rotation old_rotation;
+
+        old_rotation = XFCE_RANDR_ROTATION (xfce_randr);
+
         /* remove existing reflection */
         XFCE_RANDR_ROTATION (xfce_randr) &= ~XFCE_RANDR_REFLECTIONS_MASK;
         /* set the new one */
         XFCE_RANDR_ROTATION (xfce_randr) |= value;
         /* Apply the changes */
         xfce_randr_save (xfce_randr, "Default", display_channel);
+
+        /* Ask user confirmation */
+        if (!display_setting_timed_confirmation (builder))
+        {
+            XFCE_RANDR_ROTATION (xfce_randr) = old_rotation;
+            xfce_randr_save (xfce_randr, "Default", display_channel);
+        }
     }
 }
 
@@ -169,11 +274,19 @@ display_setting_reflections_populate (GtkBuilder *builder)
     guint         n;
     GtkTreeIter   iter;
 
-    /* get the combo box store and clear it */
     combobox = gtk_builder_get_object (builder, "randr-reflection");
+
+    /* Disconnect the "changed" signal to avoid triggering the confirmation
+     * dialog */
+    g_object_disconnect (combobox, "any_signal::changed",
+                         display_setting_reflections_changed,
+                         builder, NULL);
+
+    /* get the combo box store and clear it */
     model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
     gtk_list_store_clear (GTK_LIST_STORE (model));
 
+
     if (xfce_randr)
     {
         /* disable it if no mode is selected */
@@ -203,6 +316,9 @@ display_setting_reflections_populate (GtkBuilder *builder)
             }
         }
     }
+
+    /* Reconnect the signal */
+    g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_reflections_changed), builder);
 }
 #endif
 
@@ -212,29 +328,56 @@ static void
 display_setting_rotations_changed (GtkComboBox *combobox,
                                    GtkBuilder  *builder)
 {
+    Rotation old_rotation;
     gint value;
 
     if (!display_setting_combo_box_get_value (combobox, &value))
         return;
 
+
     /* set new rotation */
 #ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
     {
+        old_rotation = XFCE_RANDR_ROTATION (xfce_randr);
         XFCE_RANDR_ROTATION (xfce_randr) &= ~XFCE_RANDR_ROTATIONS_MASK;
         XFCE_RANDR_ROTATION (xfce_randr) |= value;
     }
     else
+    {
 #endif
+        old_rotation = XFCE_RANDR_LEGACY_ROTATION (xfce_randr_legacy);
         XFCE_RANDR_LEGACY_ROTATION (xfce_randr_legacy) = value;
+#ifdef HAS_RANDR_ONE_POINT_TWO
+    }
+#endif
 
     /* Apply the changes */
-    #ifdef HAS_RANDR_ONE_POINT_TWO
+#ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
         xfce_randr_save (xfce_randr, "Default", display_channel);
     else
-    #endif
+#endif
         xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
+
+    /* Ask user confirmation */
+    if (!display_setting_timed_confirmation (builder))
+    {
+#ifdef HAS_RANDR_ONE_POINT_TWO
+        if (xfce_randr)
+        {
+          XFCE_RANDR_ROTATION (xfce_randr) = old_rotation;
+          xfce_randr_save (xfce_randr, "Default", display_channel);
+        }
+        else
+        {
+#endif
+        XFCE_RANDR_LEGACY_ROTATION (xfce_randr_legacy) = old_rotation;
+        xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
+#ifdef HAS_RANDR_ONE_POINT_TWO
+        }
+#endif
+    }
 }
 
 
@@ -251,6 +394,13 @@ display_setting_rotations_populate (GtkBuilder *builder)
 
     /* get the combo box store and clear it */
     combobox = gtk_builder_get_object (builder, "randr-rotation");
+
+    /* Disconnect the "changed" signal to avoid triggering the confirmation
+     * dialog */
+    g_object_disconnect (combobox, "any_signal::changed",
+                         display_setting_rotations_changed,
+                         builder, NULL);
+
     model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
     gtk_list_store_clear (GTK_LIST_STORE (model));
 
@@ -293,6 +443,9 @@ display_setting_rotations_populate (GtkBuilder *builder)
             }
         }
     }
+
+    /* Reconnect the signal */
+    g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_rotations_changed), builder);
 }
 
 
@@ -301,6 +454,10 @@ static void
 display_setting_refresh_rates_changed (GtkComboBox *combobox,
                                        GtkBuilder  *builder)
 {
+#ifdef HAS_RANDR_ONE_POINT_TWO
+    RRMode old_mode;
+#endif
+    gshort old_rate;
     gint value;
 
     if (!display_setting_combo_box_get_value (combobox, &value))
@@ -309,10 +466,18 @@ display_setting_refresh_rates_changed (GtkComboBox *combobox,
     /* set new mode (1.2) or rate (1.1) */
 #ifdef HAS_RANDR_ONE_POINT_TWO
     if (xfce_randr)
+    {
+        old_mode = XFCE_RANDR_MODE (xfce_randr);
         XFCE_RANDR_MODE (xfce_randr) = value;
+    }
     else
+    {
 #endif
+        old_rate = XFCE_RANDR_LEGACY_RATE (xfce_randr_legacy);
         XFCE_RANDR_LEGACY_RATE (xfce_randr_legacy) = value;
+#ifdef HAS_RANDR_ONE_POINT_TWO
+    }
+#endif
 
     /* Apply the changes */
     #ifdef HAS_RANDR_ONE_POINT_TWO
@@ -321,6 +486,25 @@ display_setting_refresh_rates_changed (GtkComboBox *combobox,
     else
     #endif
         xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
+
+    /* Ask user confirmation */
+    if (!display_setting_timed_confirmation (builder))
+    {
+#ifdef HAS_RANDR_ONE_POINT_TWO
+        if (xfce_randr)
+        {
+            XFCE_RANDR_MODE (xfce_randr) = old_mode;
+            xfce_randr_save (xfce_randr, "Default", display_channel);
+        }
+        else
+        {
+#endif
+        XFCE_RANDR_LEGACY_RATE (xfce_randr_legacy) = old_rate;
+        xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
+#ifdef HAS_RANDR_ONE_POINT_TWO
+        }
+#endif
+    }
 }
 
 
@@ -343,6 +527,13 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
 
     /* get the combo box store and clear it */
     combobox = gtk_builder_get_object (builder, "randr-refresh-rate");
+
+    /* Disconnect the "changed" signal to avoid triggering the confirmation
+     * dialog */
+    g_object_disconnect (combobox, "any_signal::changed",
+                         display_setting_refresh_rates_changed,
+                         builder, NULL);
+
     model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
     gtk_list_store_clear (GTK_LIST_STORE (model));
 
@@ -419,6 +610,9 @@ display_setting_refresh_rates_populate (GtkBuilder *builder)
         if (G_LIKELY (active != -1))
             gtk_combo_box_set_active (GTK_COMBO_BOX (combobox), active);
     }
+
+    /* Reconnect the signal */
+    g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_refresh_rates_changed), builder);
 }
 
 
@@ -427,14 +621,27 @@ static void
 display_setting_resolutions_changed (GtkComboBox *combobox,
                                      GtkBuilder  *builder)
 {
+#ifdef HAS_RANDR_ONE_POINT_TWO
+    RRMode old_mode;
+#endif
+    SizeID old_resolution;
     gint value;
 
     if (!display_setting_combo_box_get_value (combobox, &value))
         return;
 
-    /* set new resolution */
+    /* Set new resolution */
+    if (xfce_randr)
+    {
+        old_mode = XFCE_RANDR_MODE (xfce_randr);
+        XFCE_RANDR_MODE (xfce_randr) = value;
+    }
+
     if (xfce_randr_legacy)
+    {
+        old_resolution = XFCE_RANDR_LEGACY_RESOLUTION (xfce_randr_legacy);
         XFCE_RANDR_LEGACY_RESOLUTION (xfce_randr_legacy) = value;
+    }
 
     /* update refresh rates */
     display_setting_refresh_rates_populate (builder);
@@ -446,6 +653,25 @@ display_setting_resolutions_changed (GtkComboBox *combobox,
     else
     #endif
         xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
+
+    /* Ask user confirmation */
+    if (!display_setting_timed_confirmation (builder))
+    {
+#ifdef HAS_RANDR_ONE_POINT_TWO
+        if (xfce_randr)
+        {
+            XFCE_RANDR_MODE (xfce_randr) = old_mode;
+            xfce_randr_save (xfce_randr, "Default", display_channel);
+        }
+        else
+        {
+#endif
+        XFCE_RANDR_LEGACY_RESOLUTION (xfce_randr_legacy) = old_resolution;
+        xfce_randr_legacy_save (xfce_randr_legacy, "Default", display_channel);
+#ifdef HAS_RANDR_ONE_POINT_TWO
+        }
+#endif
+    }
 }
 
 
@@ -465,6 +691,13 @@ display_setting_resolutions_populate (GtkBuilder *builder)
 
     /* get the combo box store and clear it */
     combobox = gtk_builder_get_object (builder, "randr-resolution");
+
+    /* Disconnect the "changed" signal to avoid triggering the confirmation
+     * dialog */
+    g_object_disconnect (combobox, "any_signal::changed",
+                         display_setting_resolutions_changed,
+                         builder, NULL);
+
     model = gtk_combo_box_get_model (GTK_COMBO_BOX (combobox));
     gtk_list_store_clear (GTK_LIST_STORE (model));
 
@@ -517,6 +750,9 @@ display_setting_resolutions_populate (GtkBuilder *builder)
                 gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
         }
     }
+
+    /* Reconnect the signal */
+    g_signal_connect (G_OBJECT (combobox), "changed", G_CALLBACK (display_setting_resolutions_changed), builder);
 }
 
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ec96522..6ed39c7 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@ dialogs/appearance-settings/appearance-dialog.glade
 dialogs/appearance-settings/main.c
 dialogs/appearance-settings/xfce-ui-settings.desktop.in
 
+dialogs/display-settings/confirmation-dialog.glade
 dialogs/display-settings/display-dialog.glade
 dialogs/display-settings/minimal-display-dialog.glade
 dialogs/display-settings/main.c



More information about the Xfce4-commits mailing list