[cheese] Refactor GtkScale code in CheesePreferences



commit a9ee541607d3c2edb5cd1f4e232fcf8a61505ac3
Author: David King <amigadave amigadave com>
Date:   Mon Nov 11 18:08:38 2013 +0000

    Refactor GtkScale code in CheesePreferences
    
    Move mark definitions into GtkBuilder. Convert GtkHScale to GtkScale
    with a horizontal orientation. Use g_settings_bind() to link GSettings
    values to UI elements, and remove unnecessary signal handlers.

 data/cheese-prefs.ui        |   27 +++++++++++----
 src/cheese-preferences.vala |   77 ++++++++++--------------------------------
 2 files changed, 39 insertions(+), 65 deletions(-)
---
diff --git a/data/cheese-prefs.ui b/data/cheese-prefs.ui
index 0f62c03..5c0e537 100644
--- a/data/cheese-prefs.ui
+++ b/data/cheese-prefs.ui
@@ -217,12 +217,16 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkHScale" id="brightness_scale">
+                  <object class="GtkScale" id="brightness_scale">
+                    <property name="orientation">horizontal</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="hexpand">True</property>
                     <property name="adjustment">brightness_adjustment</property>
                     <property name="draw_value">False</property>
+                    <marks>
+                      <mark value="0" position="bottom" />
+                    </marks>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -232,12 +236,16 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkHScale" id="contrast_scale">
+                  <object class="GtkScale" id="contrast_scale">
+                    <property name="orientation">horizontal</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="hexpand">True</property>
                     <property name="adjustment">contrast_adjustment</property>
                     <property name="draw_value">False</property>
+                    <marks>
+                      <mark value="1" position="bottom" />
+                    </marks>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -247,12 +255,16 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkHScale" id="saturation_scale">
+                  <object class="GtkScale" id="saturation_scale">
+                    <property name="orientation">horizontal</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="hexpand">True</property>
                     <property name="adjustment">saturation_adjustment</property>
                     <property name="draw_value">False</property>
+                    <marks>
+                      <mark value="1" position="bottom" />
+                    </marks>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -262,12 +274,16 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkHScale" id="hue_scale">
+                  <object class="GtkScale" id="hue_scale">
+                    <property name="orientation">horizontal</property>
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="hexpand">True</property>
                     <property name="adjustment">hue_adjustment</property>
                     <property name="draw_value">False</property>
+                    <marks>
+                      <mark value="0" position="bottom" />
+                    </marks>
                   </object>
                   <packing>
                     <property name="left_attach">1</property>
@@ -365,7 +381,6 @@
                         <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
-                        <signal name="toggled" handler="cheese_preferences_dialog_on_countdown_toggle" 
swapped="no"/>
                       </object>
                       <packing>
                         <property name="left_attach">0</property>
@@ -385,7 +400,6 @@
                         <property name="use_underline">True</property>
                         <property name="xalign">0</property>
                         <property name="draw_indicator">True</property>
-                        <signal name="toggled" handler="cheese_preferences_dialog_on_flash_toggle" 
swapped="no"/>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
@@ -463,7 +477,6 @@
                         <property name="invisible_char">●</property>
                         <property name="invisible_char_set">True</property>
                         <property name="adjustment">burst_count_adjustment</property>
-                        <signal name="value-changed" 
handler="cheese_preferences_dialog_on_burst_repeat_change" swapped="no"/>
                       </object>
                       <packing>
                         <property name="left_attach">1</property>
diff --git a/src/cheese-preferences.vala b/src/cheese-preferences.vala
index f04660a..8174491 100644
--- a/src/cheese-preferences.vala
+++ b/src/cheese-preferences.vala
@@ -76,18 +76,11 @@ public class Cheese.PreferencesDialog : GLib.Object
     this.hue_adjustment = builder.get_object ("hue_adjustment") as Gtk.Adjustment;
     this.saturation_adjustment = builder.get_object ("saturation_adjustment") as Gtk.Adjustment;
 
-    /* Here instead of in cheese-prefs.ui because of https://bugzilla.gnome.org/show_bug.cgi?id=624443 */
-
     this.brightness_scale = builder.get_object ("brightness_scale") as Gtk.Scale;
     this.contrast_scale = builder.get_object ("contrast_scale") as Gtk.Scale;
     this.hue_scale = builder.get_object ("hue_scale") as Gtk.Scale;
     this.saturation_scale = builder.get_object ("saturation_scale") as Gtk.Scale;
 
-    this.brightness_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
-    this.contrast_scale.add_mark (1, Gtk.PositionType.BOTTOM, null);
-    this.hue_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
-    this.saturation_scale.add_mark (1, Gtk.PositionType.BOTTOM, null);
-
     this.photo_resolution_combo = builder.get_object ("photo_resolution_combo_box") as Gtk.ComboBox;
     this.video_resolution_combo = builder.get_object ("video_resolution_combo_box") as Gtk.ComboBox;
     this.source_combo = builder.get_object ("camera_combo_box") as Gtk.ComboBox;
@@ -192,22 +185,25 @@ public class Cheese.PreferencesDialog : GLib.Object
     }
   }
 
-  /**
-   * Take the user preferences from GSettings.
-   */
-  private void initialize_values_from_settings ()
-  {
-    brightness_adjustment.value = settings.get_double ("brightness");
-    contrast_adjustment.value   = settings.get_double ("contrast");
-    hue_adjustment.value        = settings.get_double ("hue");
-    saturation_adjustment.value = settings.get_double ("saturation");
-
-    burst_repeat_spin.value = settings.get_int ("burst-repeat");
-    burst_delay_spin.value  = settings.get_int ("burst-delay") / 1000;
-
-    countdown_check.active = settings.get_boolean ("countdown");
-    flash_check.active = settings.get_boolean ("flash");
-  }
+    /**
+     * Take the user preferences from GSettings.
+     */
+    private void initialize_values_from_settings ()
+    {
+      brightness_adjustment.value = settings.get_double ("brightness");
+      contrast_adjustment.value   = settings.get_double ("contrast");
+      hue_adjustment.value        = settings.get_double ("hue");
+      saturation_adjustment.value = settings.get_double ("saturation");
+
+        settings.bind ("burst-repeat", burst_repeat_spin, "value",
+                       SettingsBindFlags.DEFAULT);
+      burst_delay_spin.value  = settings.get_int ("burst-delay") / 1000;
+
+        settings.bind ("countdown", countdown_check, "active",
+                       SettingsBindFlags.DEFAULT);
+        settings.bind ("flash", flash_check, "active",
+                       SettingsBindFlags.DEFAULT);
+    }
 
   /**
    * Update the active device to the active iter of the device combo box.
@@ -319,41 +315,6 @@ public class Cheese.PreferencesDialog : GLib.Object
   }
 
   /**
-   * Toggle the countdown GSetting when toggling the check button.
-   *
-   * @param checkbutton the countdown check button
-   */
-  [CCode (instance_pos = -1)]
-  public void on_countdown_toggle (Gtk.CheckButton checkbutton)
-  {
-    settings.set_boolean ("countdown", checkbutton.active);
-  }
-
-  /**
-   * Toggle the flash GSetting when toggling the check button.
-   *
-   * @param checkbutton the flash check button
-   */
-  [CCode (instance_pos = -1)]
-  public void on_flash_toggle (Gtk.CheckButton checkbutton)
-  {
-    settings.set_boolean ("flash", checkbutton.active);
-  }
-
-  /**
-   * Change the burst-repeat GSetting when changing the spin button.
-   *
-   * The burst repeat is the total number of photos to take in a single burst.
-   *
-   * @param spinbutton the burst-repeat spin button
-   */
-  [CCode (instance_pos = -1)]
-  public void on_burst_repeat_change (Gtk.SpinButton spinbutton)
-  {
-    settings.set_int ("burst-repeat", (int) spinbutton.value);
-  }
-
-  /**
    * Change the burst-delay GSetting when changing the spin button.
    *
    * The burst delay is the time, in milliseconds, between individual photos in


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]