Blame SOURCES/0002-currency-provider-Don-t-ever-download-rates-if-refre.patch

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