[gnome-calculator/currency-display-format: 1/3] Draft of change to currency converter
- From: A.M. Rowsell <amrowsell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calculator/currency-display-format: 1/3] Draft of change to currency converter
- Date: Wed, 4 Nov 2020 01:22:43 +0000 (UTC)
commit 55b775ecee2d0326a96d7860f867b999a5effab0
Author: A.M. Rowsell <amrowsell frozenelectronics ca>
Date: Tue Nov 3 18:00:18 2020 -0500
Draft of change to currency converter
This addresses the concerns brought up in #150 -- adding an option
to the preferences menu that changes the way currency names are
displayed in the converter. Options are the name (current default),
the currency code (like USD), or both (United States Dollar USD).
Still needs some polishing but this may work.
data/org.gnome.calculator.gschema.xml | 5 +++++
src/math-converter.vala | 26 ++++++++++++++++++++++++--
src/math-preferences.vala | 9 +++++++++
src/ui/math-preferences.ui | 32 ++++++++++++++++++++++++++++++--
4 files changed, 68 insertions(+), 4 deletions(-)
---
diff --git a/data/org.gnome.calculator.gschema.xml b/data/org.gnome.calculator.gschema.xml
index a3af435f..f5b2573b 100644
--- a/data/org.gnome.calculator.gschema.xml
+++ b/data/org.gnome.calculator.gschema.xml
@@ -62,6 +62,11 @@
<summary>Currency update interval</summary>
<description>How often the currency exchange rates should be updated</description>
</key>
+ <key name="currency-display-format" type="i">
+ <default>0</default>
+ <summary>Currency name display format</summary>
+ <description>How currency names are displayed; either the code, the name, or both.</description>
+ </key>
<key name="button-mode" enum="org.gnome.calculator.ButtonMode">
<default>'basic'</default>
<summary>Button mode</summary>
diff --git a/src/math-converter.vala b/src/math-converter.vala
index bc03b4de..09e69415 100644
--- a/src/math-converter.vala
+++ b/src/math-converter.vala
@@ -15,6 +15,8 @@ public class MathConverter : Gtk.Grid
private string category;
+ private Settings settings;
+
[GtkChild]
private Gtk.CellRendererText from_renderer;
@@ -35,6 +37,7 @@ public class MathConverter : Gtk.Grid
construct
{
+ settings = new Settings ("org.gnome.calculator");
from_combo.set_cell_data_func (from_renderer, from_cell_data_func);
CurrencyManager.get_default ().updated.connect (() => { update_result_label (); });
@@ -120,7 +123,6 @@ public class MathConverter : Gtk.Grid
private void update_from_model ()
{
var from_model = new Gtk.TreeStore (3, typeof (string), typeof (UnitCategory), typeof (Unit));
-
if (category == null)
{
var categories = UnitManager.get_default ().get_categories ();
@@ -134,7 +136,27 @@ public class MathConverter : Gtk.Grid
{
Gtk.TreeIter iter;
from_model.append (out iter, parent);
- from_model.set (iter, 0, unit.display_name, 1, category, 2, unit, -1);
+ if (category.name == "currency")
+ {
+ var CurrencyFormat = settings.get_int ("currency-display-format");
+ if (CurrencyFormat == 0) /* Currency names */
+ {
+ from_model.set (iter, 0, unit.display_name, 1, category, 2, unit, -1);
+ }
+ else if (CurrencyFormat == 1) /* Currency code */
+ {
+ from_model.set (iter, 0, unit.name, 1, category, 2, unit, -1);
+ }
+ else if (CurrencyFormat == 2) /* Both */
+ {
+ string DisplayName = unit.display_name + unit.name;
+ from_model.set (iter, 0, DisplayName, 1, category, 2, unit, -1);
+ }
+ }
+ else
+ {
+ from_model.set (iter, 0, unit.display_name, 1, category, 2, unit, -1);
+ }
}
}
}
diff --git a/src/math-preferences.vala b/src/math-preferences.vala
index 8c64a48a..285207af 100644
--- a/src/math-preferences.vala
+++ b/src/math-preferences.vala
@@ -16,6 +16,8 @@ public class MathPreferencesDialog : Gtk.Dialog
private Gtk.ComboBoxText combo_angle_units;
[GtkChild]
private Gtk.ComboBoxText combo_refresh_interval;
+ [GtkChild]
+ private Gtk.ComboBoxText combo_currency_display_format;
[GtkChild]
private Gtk.ComboBoxText combo_word_size;
[GtkChild]
@@ -42,6 +44,7 @@ public class MathPreferencesDialog : Gtk.Dialog
combo_angle_units.changed.connect (combo_angle_units_changed_cb);
combo_word_size.changed.connect (combo_word_size_changed_cb);
combo_refresh_interval.changed.connect (combo_refresh_interval_changed_cb);
+ combo_currency_display_format.changed.connect (combo_currency_display_format_changed_cb);
spinbutton_decimals.set_value (equation.accuracy);
equation.notify["accuracy"].connect ((pspec) => { spinbutton_decimals.set_value (equation.accuracy);
});
@@ -84,6 +87,12 @@ public class MathPreferencesDialog : Gtk.Dialog
CurrencyManager.get_default ().refresh_interval = value;
}
+ private void combo_currency_display_format_changed_cb (Gtk.ComboBox combo)
+ {
+ string active_id = combo.get_active_id ();
+ int value = int.parse (active_id);
+ settings.set_int ("currency-display-format", value);
+ }
protected override void response (int id)
{
hide ();
diff --git a/src/ui/math-preferences.ui b/src/ui/math-preferences.ui
index 0eb3ec2e..4910e380 100644
--- a/src/ui/math-preferences.ui
+++ b/src/ui/math-preferences.ui
@@ -215,8 +215,36 @@
</items>
</object>
<packing>
- <property name="left_attach">1</property>
- <property name="top_attach">5</property>
+ <property name="left-attach">1</property>
+ <property name="top-attach">5</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_currency_display_format">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Currenc_y format</property>
+ <property name="use-underline">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">6</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBoxText" id="combo_currency_display_format">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <items>
+ <item id="0" translatable="yes">Currency name</item>
+ <item id="1" translatable="yes">Currency code</item>
+ <item id="2" translatable="yes">Both</item>
+ </items>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">6</property>
</packing>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]