[shotwell] printing: Use inch/cm depending on locale settings



commit eaf7e88240369f87defe0f7f8ba9fe9f468a256e
Author: Jens Georg <mail jensge org>
Date:   Mon Mar 13 19:33:07 2017 +0100

    printing: Use inch/cm depending on locale settings
    
    Signed-off-by: Jens Georg <mail jensge org>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779844

 misc/org.yorba.shotwell.gschema.xml     |    2 +-
 src/Printing.vala                       |    3 ++
 src/Resources.vala                      |   39 +++++++++++++++++++++++++++++++
 src/config/ConfigurationInterfaces.vala |   11 ++++++++-
 4 files changed, 53 insertions(+), 2 deletions(-)
---
diff --git a/misc/org.yorba.shotwell.gschema.xml b/misc/org.yorba.shotwell.gschema.xml
index 5991c91..afd2f02 100644
--- a/misc/org.yorba.shotwell.gschema.xml
+++ b/misc/org.yorba.shotwell.gschema.xml
@@ -668,7 +668,7 @@
     </key>
 
     <key name="size-selection" type="i">
-        <default>3</default>
+        <default>-1</default>
         <summary>size selection</summary>
         <description>The index of the current print size in a pre-defined list of standard 
sizes</description>
     </key>
diff --git a/src/Printing.vala b/src/Printing.vala
index 1c00246..988a456 100644
--- a/src/Printing.vala
+++ b/src/Printing.vala
@@ -318,6 +318,8 @@ public class CustomPrintTab : Gtk.Box {
             standard_sizes_combo.append_text(size.name);
         }
 
+        standard_sizes_combo.set_active(9 * Resources.get_default_measurement_unit());
+
         custom_width_entry.insert_text.connect(on_entry_insert_text);
         custom_width_entry.focus_out_event.connect(on_width_entry_focus_out);
 
@@ -325,6 +327,7 @@ public class CustomPrintTab : Gtk.Box {
         custom_height_entry.focus_out_event.connect(on_height_entry_focus_out);
 
         units_combo.changed.connect(on_units_combo_changed);
+        units_combo.set_active(Resources.get_default_measurement_unit());
 
         ppi_entry.insert_text.connect(on_ppi_entry_insert_text);
         ppi_entry.focus_out_event.connect(on_ppi_entry_focus_out);
diff --git a/src/Resources.vala b/src/Resources.vala
index 046f193..13a2b6e 100644
--- a/src/Resources.vala
+++ b/src/Resources.vala
@@ -765,6 +765,45 @@ along with Shotwell; if not, write to the Free Software Foundation, Inc.,
         if (old_language != null) {
             Environment.set_variable("LANGUAGE", old_language, true);
         }
+
+    }
+
+    [CCode (cname = "int", cprefix = "LC_", cheader_filename = "locale.h", has_type_id = false)]
+    private enum Lc {
+        MEASUREMENT
+    }
+
+    public enum UnitSystem {
+        IMPERIAL,
+        METRIC,
+        UNKNOWN
+    }
+
+    private string lc_measurement = null;
+    private UnitSystem unit_system = UnitSystem.UNKNOWN;
+    private const string IMPERIAL_COUNTRIES[] = {"unm_US", "es_US", "en_US", "yi_US" };
+
+    public UnitSystem get_default_measurement_unit() {
+        if (unit_system != UnitSystem.UNKNOWN) {
+            return unit_system;
+        }
+
+        lc_measurement = Intl.setlocale((LocaleCategory) Lc.MEASUREMENT, null);
+        if (lc_measurement == null) {
+            lc_measurement = Intl.get_language_names()[0];
+        }
+
+        var index = lc_measurement.last_index_of_char('.');
+        if (index > 0) {
+            lc_measurement = lc_measurement.substring(0, index);
+        }
+
+        unit_system = UnitSystem.METRIC;
+        if (lc_measurement in IMPERIAL_COUNTRIES) {
+            unit_system = UnitSystem.IMPERIAL;
+        }
+
+        return unit_system;
     }
     
     /**
diff --git a/src/config/ConfigurationInterfaces.vala b/src/config/ConfigurationInterfaces.vala
index 29a3604..a9636ef 100644
--- a/src/config/ConfigurationInterfaces.vala
+++ b/src/config/ConfigurationInterfaces.vala
@@ -1515,7 +1515,16 @@ public abstract class ConfigurationFacade : Object {
     //
     public virtual int get_printing_size_selection() {
         try {
-            return get_engine().get_int_property(ConfigurableProperty.PRINTING_SIZE_SELECTION) - 1;
+            var val = get_engine().get_int_property(ConfigurableProperty.PRINTING_SIZE_SELECTION) - 1;
+            if (val == -2) {
+                if (Resources.get_default_measurement_unit() == Resources.UnitSystem.IMPERIAL) {
+                    val = 2;
+                } else {
+                    val = 10;
+                }
+            }
+
+            return val;
         } catch (ConfigurationError err) {
             on_configuration_error(err);
 


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