|
|
351863 |
From bddcd343ec6a4aad86a7add9cd5abf77338ffb76 Mon Sep 17 00:00:00 2001
|
|
|
351863 |
From: Ray Strode <rstrode@redhat.com>
|
|
|
351863 |
Date: Thu, 13 May 2021 10:44:33 -0400
|
|
|
351863 |
Subject: [PATCH 2/5] currency-provider: Don't ever download rates if refresh
|
|
|
351863 |
interval is 0
|
|
|
351863 |
|
|
|
351863 |
If an admin has set the currency refresh interval to 0 they probably
|
|
|
351863 |
don't ever want the data refreshed from the network.
|
|
|
351863 |
|
|
|
351863 |
This commit treats a refresh interval of 0 specially to mean
|
|
|
351863 |
"don't go on the network at all"
|
|
|
351863 |
---
|
|
|
351863 |
data/org.gnome.calculator.gschema.xml | 2 +-
|
|
|
351863 |
lib/currency.vala | 6 ++++++
|
|
|
351863 |
2 files changed, 7 insertions(+), 1 deletion(-)
|
|
|
351863 |
|
|
|
351863 |
diff --git a/data/org.gnome.calculator.gschema.xml b/data/org.gnome.calculator.gschema.xml
|
|
|
351863 |
index a3af435f..fbde9b53 100644
|
|
|
351863 |
--- a/data/org.gnome.calculator.gschema.xml
|
|
|
351863 |
+++ b/data/org.gnome.calculator.gschema.xml
|
|
|
351863 |
@@ -33,61 +33,61 @@
|
|
|
351863 |
</key>
|
|
|
351863 |
<key type="i" name="base">
|
|
|
351863 |
<default>10</default>
|
|
|
351863 |
<range min="2" max="16"/>
|
|
|
351863 |
<summary>Numeric Base</summary>
|
|
|
351863 |
<description>The numeric base</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key type="b" name="show-thousands">
|
|
|
351863 |
<default>false</default>
|
|
|
351863 |
<summary>Show Thousands Separators</summary>
|
|
|
351863 |
<description>Indicates whether thousands separators are shown in large numbers.</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key type="b" name="show-zeroes">
|
|
|
351863 |
<default>false</default>
|
|
|
351863 |
<summary>Show Trailing Zeroes</summary>
|
|
|
351863 |
<description>Indicates whether any trailing zeroes after the numeric point should be shown in the display value.</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key name="number-format" enum="org.gnome.calculator.NumberFormat">
|
|
|
351863 |
<default>'automatic'</default>
|
|
|
351863 |
<summary>Number format</summary>
|
|
|
351863 |
<description>The format to display numbers in</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key name="angle-units" enum="org.gnome.calculator.AngleUnit">
|
|
|
351863 |
<default>'degrees'</default>
|
|
|
351863 |
<summary>Angle units</summary>
|
|
|
351863 |
<description>The angle units to use</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key name="refresh-interval" type="i">
|
|
|
351863 |
<default>604800</default>
|
|
|
351863 |
<summary>Currency update interval</summary>
|
|
|
351863 |
- <description>How often the currency exchange rates should be updated</description>
|
|
|
351863 |
+ <description>How often the currency exchange rates should be updated. A value of 0 means the currency exchange rates won't be fetched from the network at all.</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key name="button-mode" enum="org.gnome.calculator.ButtonMode">
|
|
|
351863 |
<default>'basic'</default>
|
|
|
351863 |
<summary>Button mode</summary>
|
|
|
351863 |
<description>The button mode</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key type="s" name="source-currency">
|
|
|
351863 |
<default>''</default>
|
|
|
351863 |
<summary>Source currency</summary>
|
|
|
351863 |
<description>Currency of the current calculation</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key type="s" name="target-currency">
|
|
|
351863 |
<default>''</default>
|
|
|
351863 |
<summary>Target currency</summary>
|
|
|
351863 |
<description>Currency to convert the current calculation into</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key type="s" name="source-units">
|
|
|
351863 |
<default>'degree'</default>
|
|
|
351863 |
<summary>Source units</summary>
|
|
|
351863 |
<description>Units of the current calculation</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key type="s" name="target-units">
|
|
|
351863 |
<default>'radian'</default>
|
|
|
351863 |
<summary>Target units</summary>
|
|
|
351863 |
<description>Units to convert the current calculation into</description>
|
|
|
351863 |
</key>
|
|
|
351863 |
<key type="i" name="precision">
|
|
|
351863 |
<default>2000</default>
|
|
|
351863 |
<summary>Internal precision</summary>
|
|
|
351863 |
<description>The internal precision used with the MPFR library</description>
|
|
|
351863 |
diff --git a/lib/currency.vala b/lib/currency.vala
|
|
|
351863 |
index c098cc52..2adb11e4 100644
|
|
|
351863 |
--- a/lib/currency.vala
|
|
|
351863 |
+++ b/lib/currency.vala
|
|
|
351863 |
@@ -354,83 +354,89 @@ public class CurrencyManager : Object
|
|
|
351863 |
{
|
|
|
351863 |
warning ("Couldn't create XPath context");
|
|
|
351863 |
return;
|
|
|
351863 |
}
|
|
|
351863 |
|
|
|
351863 |
xpath_ctx.register_ns ("xref", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref");
|
|
|
351863 |
var xpath_obj = xpath_ctx.eval_expression ("//xref:Cube[@currency][@rate]");
|
|
|
351863 |
if (xpath_obj == null)
|
|
|
351863 |
{
|
|
|
351863 |
warning ("Couldn't create XPath object");
|
|
|
351863 |
return;
|
|
|
351863 |
}
|
|
|
351863 |
var len = (xpath_obj->nodesetval != null) ? xpath_obj->nodesetval->length () : 0;
|
|
|
351863 |
for (var i = 0; i < len; i++)
|
|
|
351863 |
{
|
|
|
351863 |
var node = xpath_obj->nodesetval->item (i);
|
|
|
351863 |
|
|
|
351863 |
if (node->type == Xml.ElementType.ELEMENT_NODE)
|
|
|
351863 |
set_ecb_rate (node, eur_rate);
|
|
|
351863 |
|
|
|
351863 |
/* Avoid accessing removed elements */
|
|
|
351863 |
if (node->type != Xml.ElementType.NAMESPACE_DECL)
|
|
|
351863 |
node = null;
|
|
|
351863 |
}
|
|
|
351863 |
|
|
|
351863 |
Xml.Parser.cleanup ();
|
|
|
351863 |
}
|
|
|
351863 |
|
|
|
351863 |
private void download_rates ()
|
|
|
351863 |
{
|
|
|
351863 |
+ if (refresh_interval == 0)
|
|
|
351863 |
+ return;
|
|
|
351863 |
+
|
|
|
351863 |
/* Update rates if necessary */
|
|
|
351863 |
var path = get_imf_rate_filepath ();
|
|
|
351863 |
if (!downloading_imf_rates && file_needs_update (path, refresh_interval))
|
|
|
351863 |
{
|
|
|
351863 |
downloading_imf_rates = true;
|
|
|
351863 |
debug ("Downloading rates from the IMF...");
|
|
|
351863 |
download_file.begin ("https://www.imf.org/external/np/fin/data/rms_five.aspx?tsvflag=Y", path, "IMF");
|
|
|
351863 |
}
|
|
|
351863 |
path = get_ecb_rate_filepath ();
|
|
|
351863 |
if (!downloading_ecb_rates && file_needs_update (path, refresh_interval))
|
|
|
351863 |
{
|
|
|
351863 |
downloading_ecb_rates = true;
|
|
|
351863 |
debug ("Downloading rates from the ECB...");
|
|
|
351863 |
download_file.begin ("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml", path, "ECB");
|
|
|
351863 |
}
|
|
|
351863 |
}
|
|
|
351863 |
|
|
|
351863 |
private bool load_rates ()
|
|
|
351863 |
{
|
|
|
351863 |
/* Already loaded */
|
|
|
351863 |
if (loaded_rates)
|
|
|
351863 |
return true;
|
|
|
351863 |
|
|
|
351863 |
+ if (refresh_interval == 0)
|
|
|
351863 |
+ return false;
|
|
|
351863 |
+
|
|
|
351863 |
/* In process */
|
|
|
351863 |
if (downloading_imf_rates || downloading_ecb_rates)
|
|
|
351863 |
return false;
|
|
|
351863 |
|
|
|
351863 |
/* Use the IMF provided values and top up with currencies tracked by the ECB and not the IMF */
|
|
|
351863 |
load_imf_rates ();
|
|
|
351863 |
load_ecb_rates ();
|
|
|
351863 |
|
|
|
351863 |
/* Check if we couldn't find out a currency */
|
|
|
351863 |
foreach (var c in currencies)
|
|
|
351863 |
if (c.get_value () == null || c.get_value ().is_zero ())
|
|
|
351863 |
warning ("Currency %s is not provided by IMF or ECB", c.name);
|
|
|
351863 |
|
|
|
351863 |
debug ("Rates loaded");
|
|
|
351863 |
loaded_rates = true;
|
|
|
351863 |
|
|
|
351863 |
updated ();
|
|
|
351863 |
|
|
|
351863 |
return true;
|
|
|
351863 |
}
|
|
|
351863 |
|
|
|
351863 |
public Number? get_value (string currency)
|
|
|
351863 |
{
|
|
|
351863 |
/* Make sure that the rates we're returning are up to date. (Just in case the application is running from a long long time) */
|
|
|
351863 |
download_rates ();
|
|
|
351863 |
|
|
|
351863 |
if (!load_rates ())
|
|
|
351863 |
return null;
|
|
|
351863 |
|
|
|
351863 |
var c = get_currency (currency);
|
|
|
351863 |
--
|
|
|
351863 |
2.31.1
|
|
|
351863 |
|