[nautilus] preferences-window: Use spin button for thumbnail limit



commit 611f381d561024b0a590237c31fc0612e6698530
Author: vyasgiridhar <vyasgiridhar27 gmail com>
Date:   Sat Feb 25 23:24:35 2017 +0530

    preferences-window: Use spin button for thumbnail limit
    
    File sizes (especially compressed images) are arbitrary values that are
    highly dependant on the camera resolution, and contents of the image.
    Therefore it does not make sense to have this be a drop-down with preset
    hard-coded values: A 21MP camera often produces 12MB images... but the
    only option is 10MB, or 100MB.
    
    This commit changes the combobox in the preferences to a spinbutton and
    changes the signal handler for thumbnail-limit.
    The value is in MB, with a maximum of 4096 and a minimum of 1.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779165

 src/nautilus-file.c                             |   10 +-
 src/nautilus-preferences-window.c               |   95 +++-----
 src/resources/ui/nautilus-preferences-window.ui |  310 ++++++++++-------------
 3 files changed, 180 insertions(+), 235 deletions(-)
---
diff --git a/src/nautilus-file.c b/src/nautilus-file.c
index fa16eb5..e37ba19 100644
--- a/src/nautilus-file.c
+++ b/src/nautilus-file.c
@@ -85,6 +85,8 @@
 #define DEBUG_REF_PRINTF printf
 #endif
 
+#define MEGA_TO_BASE_RATE 1048576
+
 /* Files that start with these characters sort after files that don't. */
 #define SORT_LAST_CHAR1 '.'
 #define SORT_LAST_CHAR2 '#'
@@ -9230,9 +9232,11 @@ nautilus_file_list_cancel_call_when_ready (NautilusFileListHandle *handle)
 static void
 thumbnail_limit_changed_callback (gpointer user_data)
 {
-    g_settings_get (nautilus_preferences,
-                    NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT,
-                    "t", &cached_thumbnail_limit);
+    cached_thumbnail_limit = g_settings_get_uint64 (nautilus_preferences,
+                                                    NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT);
+
+    //Converts the obtained limit in MB to bytes
+    cached_thumbnail_limit *= MEGA_TO_BASE_RATE;;
 
     /* Tell the world that icons might have changed. We could invent a narrower-scope
      * signal to mean only "thumbnails might have changed" if this ends up being slow
diff --git a/src/nautilus-preferences-window.c b/src/nautilus-preferences-window.c
index 0e4a5a4..9116692 100644
--- a/src/nautilus-preferences-window.c
+++ b/src/nautilus-preferences-window.c
@@ -64,7 +64,7 @@
 
 /* int enums */
 #define NAUTILUS_PREFERENCES_DIALOG_THUMBNAIL_LIMIT_WIDGET                     \
-    "preview_image_size_combobox"
+    "preview_image_size_spinbutton"
 
 static const char * const speed_tradeoff_values[] =
 {
@@ -106,12 +106,6 @@ static const char * const count_components[] =
     "count_only_this_computer_radiobutton", "count_all_files_radiobutton", "count_never_radiobutton", NULL
 };
 
-static const guint64 thumbnail_limit_values[] =
-{
-    102400, 512000, 1048576, 3145728, 5242880,
-    10485760, 104857600, 1073741824, 2147483648U, 4294967295U
-};
-
 static const char * const icon_captions_components[] =
 {
     "captions_0_combobox", "captions_1_combobox", "captions_2_combobox", NULL
@@ -360,68 +354,48 @@ nautilus_preferences_window_setup_list_column_page (GtkBuilder *builder)
     gtk_box_pack_start (GTK_BOX (box), chooser, TRUE, TRUE, 0);
 }
 
-static void bind_builder_bool(GtkBuilder *builder,
-                              GSettings  *settings,
-                              const char *widget_name,
-                              const char *prefs)
+static gboolean format_spin_button(GtkSpinButton *spin_button,
+                                   gpointer user_data)
 {
-    g_settings_bind (settings, prefs, gtk_builder_get_object (builder, widget_name),
-                     "active", G_SETTINGS_BIND_DEFAULT);
+    GtkAdjustment *adjustment;
+    int value;
+    gchar *text;
+
+    adjustment = gtk_spin_button_get_adjustment (spin_button);
+    value = (int)gtk_adjustment_get_value (adjustment);
+    text = g_strdup_printf ("%d MB",value);
+    gtk_entry_set_text (GTK_ENTRY (spin_button), text);
+
+    return TRUE;
 }
 
-typedef struct
+static void nautilus_preferences_window_setup_thumbnail_limit_formatting (GtkBuilder *builder)
 {
-    const guint64 *values;
-    int n_values;
-} UIntEnumBinding;
+    GtkSpinButton *spin;
 
-static gboolean uint_enum_get_mapping(GValue   *value,
-                                      GVariant *variant,
-                                      gpointer  user_data)
-{
-    UIntEnumBinding *binding = user_data;
-    guint64 v;
-    int i;
+    spin = GTK_SPIN_BUTTON (gtk_builder_get_object (builder, "preview_image_size_spinbutton"));
 
-    v = g_variant_get_uint64 (variant);
-    for (i = 0; i < binding->n_values; i++)
-    {
-        if (binding->values[i] >= v)
-        {
-            g_value_set_int (value, i);
-            return TRUE;
-        }
-    }
+    g_signal_connect (spin, "output", G_CALLBACK (format_spin_button),
+                      spin);
 
-    return FALSE;
 }
 
-static GVariant *uint_enum_set_mapping(const GValue       *value,
-                                       const GVariantType *expected_type,
-                                       gpointer            user_data)
+static void bind_builder_bool(GtkBuilder *builder,
+                              GSettings  *settings,
+                              const char *widget_name,
+                              const char *prefs)
 {
-    UIntEnumBinding *binding = user_data;
-
-    return g_variant_new_uint64 (binding->values[g_value_get_int (value)]);
+    g_settings_bind (settings, prefs, gtk_builder_get_object (builder, widget_name),
+                     "active", G_SETTINGS_BIND_DEFAULT);
 }
 
-static void bind_builder_uint_enum(GtkBuilder    *builder,
-                                   GSettings     *settings,
-                                   const char    *widget_name,
-                                   const char    *prefs,
-                                   const guint64 *values,
-                                   int            n_values)
-{
-    UIntEnumBinding *binding;
-
-    binding = g_new (UIntEnumBinding, 1);
-    binding->values = values;
-    binding->n_values = n_values;
-
-    g_settings_bind_with_mapping (
-        settings, prefs, gtk_builder_get_object (builder, widget_name), "active",
-        G_SETTINGS_BIND_DEFAULT, uint_enum_get_mapping, uint_enum_set_mapping,
-        binding, g_free);
+static void bind_builder_uint_spin(GtkBuilder *builder,
+                                   GSettings  *settings,
+                                   const char *widget_name,
+                                   const char *prefs)
+{    
+    g_settings_bind (settings, prefs, gtk_builder_get_object (builder, widget_name),
+                     "value", G_SETTINGS_BIND_DEFAULT);
 }
 
 static GVariant *radio_mapping_set(const GValue       *gvalue,
@@ -527,12 +501,11 @@ static void nautilus_preferences_window_setup(GtkBuilder *builder,
                         NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
                         (const char **) speed_tradeoff_values);
 
-    bind_builder_uint_enum (builder, nautilus_preferences,
+    bind_builder_uint_spin (builder, nautilus_preferences,
                             NAUTILUS_PREFERENCES_DIALOG_THUMBNAIL_LIMIT_WIDGET,
-                            NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT,
-                            thumbnail_limit_values,
-                            G_N_ELEMENTS (thumbnail_limit_values));
+                            NAUTILUS_PREFERENCES_FILE_THUMBNAIL_LIMIT);
 
+    nautilus_preferences_window_setup_thumbnail_limit_formatting (builder);
     nautilus_preferences_window_setup_icon_caption_page (builder);
     nautilus_preferences_window_setup_list_column_page (builder);
 
diff --git a/src/resources/ui/nautilus-preferences-window.ui b/src/resources/ui/nautilus-preferences-window.ui
index aeeb1f8..fe89e24 100644
--- a/src/resources/ui/nautilus-preferences-window.ui
+++ b/src/resources/ui/nautilus-preferences-window.ui
@@ -2,168 +2,11 @@
 <!-- Generated with glade 3.20.0 -->
 <interface>
   <requires lib="gtk+" version="3.16"/>
-  <object class="GtkListStore" id="icon_view_zoom_levels">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Always</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Local Files Only</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Never</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="list_view_zoom_levels">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Small</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Standard</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Large</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model1">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Icon View</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">List View</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model10">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Always</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Local Files Only</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Never</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model2">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">By Name</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">By Size</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">By Type</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">By Modification Date</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">By Access Date</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">By Trashed Date</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model3">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Small</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Standard</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Large</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model7">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">Always</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Local Files Only</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">Never</col>
-      </row>
-    </data>
-  </object>
-  <object class="GtkListStore" id="model8">
-    <columns>
-      <!-- column-name gchararray -->
-      <column type="gchararray"/>
-    </columns>
-    <data>
-      <row>
-        <col id="0" translatable="yes">100 KB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">500 KB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">1 MB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">3 MB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">5 MB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">10 MB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">100 MB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">1 GB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">2 GB</col>
-      </row>
-      <row>
-        <col id="0" translatable="yes">4 GB</col>
-      </row>
-    </data>
+  <object class="GtkAdjustment" id="adjustment1">
+    <property name="lower">1</property>
+    <property name="upper">4096</property>
+    <property name="step_increment">1</property>
+    <property name="page_increment">10</property>
   </object>
   <object class="GtkDialog" id="preferences_window">
     <property name="can_focus">False</property>
@@ -1126,16 +969,13 @@
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkComboBox" id="preview_image_size_combobox">
+                          <object class="GtkSpinButton" id="preview_image_size_spinbutton">
                             <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="model">model8</property>
-                            <child>
-                              <object class="GtkCellRendererText" id="renderer8"/>
-                              <attributes>
-                                <attribute name="text">0</attribute>
-                              </attributes>
-                            </child>
+                            <property name="can_focus">True</property>
+                            <property name="width_chars">8</property>
+                            <property name="input_purpose">number</property>
+                            <property name="adjustment">adjustment1</property>
+                            <property name="climb_rate">10</property>
                           </object>
                           <packing>
                             <property name="expand">False</property>
@@ -1271,5 +1111,133 @@
         </child>
       </object>
     </child>
+    <child type="titlebar">
+      <placeholder/>
+    </child>
+  </object>
+  <object class="GtkListStore" id="icon_view_zoom_levels">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Always</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Local Files Only</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Never</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="list_view_zoom_levels">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Small</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Standard</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Large</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="model1">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Icon View</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">List View</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="model10">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Always</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Local Files Only</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Never</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="model2">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">By Name</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">By Size</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">By Type</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">By Modification Date</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">By Access Date</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">By Trashed Date</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="model3">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Small</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Standard</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Large</col>
+      </row>
+    </data>
+  </object>
+  <object class="GtkListStore" id="model7">
+    <columns>
+      <!-- column-name gchararray -->
+      <column type="gchararray"/>
+    </columns>
+    <data>
+      <row>
+        <col id="0" translatable="yes">Always</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Local Files Only</col>
+      </row>
+      <row>
+        <col id="0" translatable="yes">Never</col>
+      </row>
+    </data>
   </object>
 </interface>


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