[gcalctool] Remove Icelandic krona (ISK) from currency list, it is no longer provided by the ECB. Also warn if a
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Remove Icelandic krona (ISK) from currency list, it is no longer provided by the ECB. Also warn if a
- Date: Mon, 6 Dec 2010 22:31:31 +0000 (UTC)
commit 5ab55de17647c8950a926f8569e5483eec859048
Author: Robert Ancell <robert ancell canonical com>
Date: Tue Dec 7 09:30:49 2010 +1100
Remove Icelandic krona (ISK) from currency list, it is no longer provided by the ECB.
Also warn if a currency is no longer being downloaded, or doesn't have display information
NEWS | 2 ++
src/currency.c | 39 +++++++++++++++++++++++++++++++++++++++
src/currency.h | 10 ++++++----
src/math-buttons.c | 11 ++++-------
src/math-equation.c | 8 ++++----
5 files changed, 55 insertions(+), 15 deletions(-)
---
diff --git a/NEWS b/NEWS
index 35033fe..a42631b 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
Overview of changes in gcalctool 5.91.4
* Use new Indian Rupee sign â?¹ (Bug #636587, Carlos Cejudo)
+ * Remove Icelandic krona (ISK) from currency list, it is no longer provided
+ by the ECB.
Overview of changes in gcalctool 5.91.3
diff --git a/src/currency.c b/src/currency.c
index 6f5e745..a489510 100644
--- a/src/currency.c
+++ b/src/currency.c
@@ -13,6 +13,7 @@
typedef struct {
char *short_name;
MPNumber value;
+ const CurrencyInfo *info;
} Currency;
static Currency *currencies = NULL;
@@ -118,7 +119,19 @@ set_rate (xmlNodePtr node, Currency *cur)
xmlAttrPtr attribute;
for (attribute = node->properties; attribute; attribute = attribute->next) {
if (strcmp((char *)attribute->name, "currency") == 0) {
+ int i;
+
cur->short_name = (char *)xmlNodeGetContent((xmlNodePtr) attribute);
+ for (i = 0; currency_info[i].short_name; i++)
+ {
+ if (strcmp(cur->short_name, currency_info[i].short_name) == 0)
+ {
+ cur->info = ¤cy_info[i];
+ break;
+ }
+ }
+ if (!cur->info)
+ g_warning("Currency %s is not in the currency table", cur->short_name);
} else if (strcmp ((char *)attribute->name, "rate") == 0) {
char *val = (char *)xmlNodeGetContent ((xmlNodePtr) attribute);
mp_set_from_string(val, 10, &(cur->value));
@@ -183,17 +196,43 @@ currency_load_rates()
MPNumber foo;
mp_set_from_integer(1, &foo);
currencies[len].value = foo;
+ currencies[len].info = currency_get_info("EUR");
xmlXPathFreeObject(xpath_obj);
xmlXPathFreeContext(xpath_ctx);
xmlFreeDoc(document);
xmlCleanupParser();
+ for (i = 0; currency_info[i].short_name; i++)
+ {
+ int j;
+ for (j = 0; j < currency_count; j++)
+ {
+ if (currencies[j].info == ¤cy_info[i])
+ break;
+ }
+ if (j == currency_count)
+ g_warning("Currency %s is not provided by server", currency_info[i].short_name);
+ }
+
g_debug("Rates loaded");
loaded_rates = TRUE;
}
+const CurrencyInfo *
+currency_get_info(const gchar *name)
+{
+ int i = 0;
+ while (currency_info[i].short_name && strcmp(name, currency_info[i].short_name) != 0)
+ i++;
+ if (currency_info[i].short_name)
+ return ¤cy_info[i];
+ else
+ return NULL;
+}
+
+
gboolean
currency_convert(const MPNumber *from_amount,
const char *source_currency, const char *target_currency,
diff --git a/src/currency.h b/src/currency.h
index 5b31a80..e167147 100644
--- a/src/currency.h
+++ b/src/currency.h
@@ -5,17 +5,17 @@
#include "mp.h"
-struct currency_name {
+typedef struct {
char *short_name;
char *symbol;
char *long_name;
-};
+} CurrencyInfo;
/*
* List taken from http://www.ecb.int/press/pr/date/2008/html/pr081205.en.html
* with euro added.
*/
-static const struct currency_name currency_names[] = {
+static const CurrencyInfo currency_info[] = {
{"AUD", "$", N_("Australian dollar")},
{"BGN", "лв", N_("Bulgarian lev")},
{"BRL", "R$", N_("Brazilian real")},
@@ -32,7 +32,7 @@ static const struct currency_name currency_names[] = {
{"HUF", "Ft", N_("Hungarian forint")},
{"IDR", "Rp", N_("Indonesian rupiah")},
{"INR", "â?¹", N_("Indian rupee")},
- {"ISK", "kr", N_("Icelandic krona")},
+// {"ISK", "kr", N_("Icelandic krona")}, // NOTE: Used to be provided by the ECB
{"JPY", "Â¥", N_("Japanese yen")},
{"KRW", "â?©", N_("South Korean won")},
{"LTL", "Lt", N_("Lithuanian litas")},
@@ -56,6 +56,8 @@ static const struct currency_name currency_names[] = {
// FIXME: Should indicate when rates are updated to UI
+const CurrencyInfo *currency_get_info(const gchar *name);
+
/* Converts an amount of money from one currency to another */
gboolean currency_convert(const MPNumber *from_amount,
const char *source_currency, const char *target_currency,
diff --git a/src/math-buttons.c b/src/math-buttons.c
index de3b213..b0214dc 100644
--- a/src/math-buttons.c
+++ b/src/math-buttons.c
@@ -594,15 +594,12 @@ update_currency_label(MathButtons *buttons)
&value)) {
char *input_text, *output_text;
const char *source_symbol, *target_symbol;
- int i;
input_text = mp_serializer_to_string(buttons->priv->currency_serializer, &x);
output_text = mp_serializer_to_string(buttons->priv->currency_serializer, &value);
- for (i = 0; strcmp(math_equation_get_source_currency(buttons->priv->equation), currency_names[i].short_name) != 0; i++);
- source_symbol = currency_names[i].symbol;
- for (i = 0; strcmp(math_equation_get_target_currency(buttons->priv->equation), currency_names[i].short_name) != 0; i++);
- target_symbol = currency_names[i].symbol;
+ source_symbol = currency_get_info(math_equation_get_source_currency(buttons->priv->equation))->symbol;
+ target_symbol = currency_get_info(math_equation_get_target_currency(buttons->priv->equation))->symbol;
/* Translators: first and third %s are currency symbols, second and fourth are amounts in these currencies, you may want to change the order of these, example: $100 = â?¬100 */
label = g_strdup_printf(_("%s%s = %s%s"),
@@ -1151,11 +1148,11 @@ load_mode(MathButtons *buttons, ButtonMode mode)
model = gtk_list_store_new(1, G_TYPE_STRING);
- for (i = 0; currency_names[i].short_name != NULL; i++) {
+ for (i = 0; currency_info[i].short_name != NULL; i++) {
GtkTreeIter iter;
gtk_list_store_append(GTK_LIST_STORE(model), &iter);
- gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, currency_names[i].short_name, -1);
+ gtk_list_store_set(GTK_LIST_STORE(model), &iter, 0, currency_info[i].short_name, -1);
}
gtk_combo_box_set_model(GTK_COMBO_BOX(buttons->priv->source_currency_combo), GTK_TREE_MODEL(model));
diff --git a/src/math-equation.c b/src/math-equation.c
index 3dbab8d..40c4221 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -642,7 +642,7 @@ math_equation_set_source_currency(MathEquation *equation, const gchar *currency)
{
// FIXME: Pick based on locale
if (!currency || currency[0] == '\0')
- currency = currency_names[0].short_name;
+ currency = currency_info[0].short_name;
if (strcmp(equation->priv->source_currency, currency) == 0)
return;
@@ -664,7 +664,7 @@ math_equation_set_target_currency(MathEquation *equation, const gchar *currency)
{
// FIXME: Pick based on locale
if (!currency || currency[0] == '\0')
- currency = currency_names[0].short_name;
+ currency = currency_info[0].short_name;
if (strcmp(equation->priv->target_currency, currency) == 0)
return;
@@ -1849,8 +1849,8 @@ math_equation_init(MathEquation *equation)
equation->priv->word_size = 32;
equation->priv->angle_units = MP_DEGREES;
// FIXME: Pick based on locale
- equation->priv->source_currency = g_strdup(currency_names[0].short_name);
- equation->priv->target_currency = g_strdup(currency_names[0].short_name);
+ equation->priv->source_currency = g_strdup(currency_info[0].short_name);
+ equation->priv->target_currency = g_strdup(currency_info[0].short_name);
equation->priv->source_units = g_strdup("");
equation->priv->target_units = g_strdup("");
equation->priv->serializer = mp_serializer_new(MP_DISPLAY_FORMAT_AUTOMATIC, 10, 9);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]