[gcalctool] Do conversions by unit name, not by unit symbols. This meant that translated symbols would never wo
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Do conversions by unit name, not by unit symbols. This meant that translated symbols would never wo
- Date: Thu, 17 Feb 2011 03:05:20 +0000 (UTC)
commit 67e4540f8a3131984ee4fe41b2393c1480f9ea33
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Feb 17 14:05:11 2011 +1100
Do conversions by unit name, not by unit symbols. This meant that translated symbols would never work
NEWS | 1 +
src/gcalctool.c | 2 +-
src/math-converter.c | 6 +++---
src/math-equation.c | 2 +-
src/unit-category.c | 32 +++++++++++++-------------------
src/unit-category.h | 6 ++++--
src/unit-manager.c | 29 +++++++++++++++++++++++++----
src/unit-manager.h | 6 ++++--
src/unittest.c | 2 +-
9 files changed, 53 insertions(+), 33 deletions(-)
---
diff --git a/NEWS b/NEWS
index 5d5fe8b..d4f1524 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
Overview of changes in gcalctool 5.91.7
* Fix grammar mistakes
+ * Fix translated conversions (Bug #641166)
Overview of changes in gcalctool 5.91.6
diff --git a/src/gcalctool.c b/src/gcalctool.c
index 1861256..5aa1a0a 100644
--- a/src/gcalctool.c
+++ b/src/gcalctool.c
@@ -43,7 +43,7 @@ version(const gchar *progname)
static int
do_convert(const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z, void *data)
{
- return unit_manager_convert(unit_manager_get_default(), x, x_units, z_units, z);
+ return unit_manager_convert_by_symbol(unit_manager_get_default(), x, x_units, z_units, z);
}
diff --git a/src/math-converter.c b/src/math-converter.c
index 0e49a63..1377431 100644
--- a/src/math-converter.c
+++ b/src/math-converter.c
@@ -77,7 +77,7 @@ update_result_label(MathConverter *converter)
gtk_combo_box_get_active_iter(GTK_COMBO_BOX(converter->priv->to_combo), &to_iter)) {
gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(converter->priv->from_combo)), &from_iter, 1, &category, 2, &source_unit, -1);
gtk_tree_model_get(gtk_combo_box_get_model(GTK_COMBO_BOX(converter->priv->to_combo)), &to_iter, 2, &target_unit, -1);
- if (!unit_category_convert(category, &x, unit_get_name(source_unit), unit_get_name(target_unit), &z))
+ if (!unit_category_convert(category, &x, source_unit, target_unit, &z))
enabled = FALSE;
}
else
@@ -228,8 +228,8 @@ math_converter_set_conversion(MathConverter *converter, /*const gchar *category,
Unit *ua;
Unit *ub;
- ua = unit_manager_get_unit(unit_manager_get_default(), unit_a);
- ub = unit_manager_get_unit(unit_manager_get_default(), unit_b);
+ ua = unit_manager_get_unit_by_name(unit_manager_get_default(), unit_a);
+ ub = unit_manager_get_unit_by_name(unit_manager_get_default(), unit_b);
if (!ua || !ub)
return;
diff --git a/src/math-equation.c b/src/math-equation.c
index 13e0f72..23afcf4 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -1072,7 +1072,7 @@ set_variable(const char *name, const MPNumber *x, void *data)
static int
convert(const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z, void *data)
{
- return unit_manager_convert(unit_manager_get_default(), x, x_units, z_units, z);
+ return unit_manager_convert_by_symbol(unit_manager_get_default(), x, x_units, z_units, z);
}
diff --git a/src/unit-category.c b/src/unit-category.c
index 94f33ef..5028c75 100644
--- a/src/unit-category.c
+++ b/src/unit-category.c
@@ -44,7 +44,7 @@ unit_category_add_unit(UnitCategory *category, Unit *unit)
Unit *
-unit_category_get_unit(UnitCategory *category, const gchar *name)
+unit_category_get_unit_by_name(UnitCategory *category, const gchar *name)
{
GList *iter;
@@ -59,15 +59,8 @@ unit_category_get_unit(UnitCategory *category, const gchar *name)
}
-const GList *
-unit_category_get_units(UnitCategory *category)
-{
- return category->priv->units;
-}
-
-
-static Unit *
-get_unit(UnitCategory *category, const gchar *symbol)
+Unit *
+unit_category_get_unit_by_symbol(UnitCategory *category, const gchar *symbol)
{
GList *iter;
@@ -81,20 +74,21 @@ get_unit(UnitCategory *category, const gchar *symbol)
}
+const GList *
+unit_category_get_units(UnitCategory *category)
+{
+ return category->priv->units;
+}
+
+
gboolean
-unit_category_convert(UnitCategory *category, const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z)
+unit_category_convert(UnitCategory *category, const MPNumber *x, Unit *x_units, Unit *z_units, MPNumber *z)
{
- Unit *unit_x, *unit_z;
MPNumber t;
- unit_x = get_unit(category, x_units);
- unit_z = get_unit(category, z_units);
- if (!unit_x || !unit_z)
- return FALSE;
-
- if (!unit_convert_from(unit_x, x, &t))
+ if (!unit_convert_from(x_units, x, &t))
return FALSE;
- if (!unit_convert_to(unit_z, &t, z))
+ if (!unit_convert_to(z_units, &t, z))
return FALSE;
return TRUE;
diff --git a/src/unit-category.h b/src/unit-category.h
index 03349c2..a97d4ef 100644
--- a/src/unit-category.h
+++ b/src/unit-category.h
@@ -30,13 +30,15 @@ const gchar *unit_category_get_name(UnitCategory *category);
const gchar *unit_category_get_display_name(UnitCategory *category);
-Unit *unit_category_get_unit(UnitCategory *category, const gchar *name);
+Unit *unit_category_get_unit_by_name(UnitCategory *category, const gchar *name);
+
+Unit *unit_category_get_unit_by_symbol(UnitCategory *category, const gchar *symbol);
void unit_category_add_unit(UnitCategory *category, Unit *unit);
const GList *unit_category_get_units(UnitCategory *category);
-gboolean unit_category_convert(UnitCategory *category, const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z);
+gboolean unit_category_convert(UnitCategory *category, const MPNumber *x, Unit *x_units, Unit *z_units, MPNumber *z);
G_END_DECLS
diff --git a/src/unit-manager.c b/src/unit-manager.c
index a28a039..aa8c760 100644
--- a/src/unit-manager.c
+++ b/src/unit-manager.c
@@ -170,14 +170,31 @@ unit_manager_get_category(UnitManager *manager, const gchar *category)
Unit *
-unit_manager_get_unit(UnitManager *manager, const gchar *unit)
+unit_manager_get_unit_by_name(UnitManager *manager, const gchar *name)
{
GList *iter;
Unit *u;
for (iter = manager->priv->categories; iter; iter = iter->next) {
UnitCategory *c = iter->data;
- u = unit_category_get_unit (c, unit);
+ u = unit_category_get_unit_by_name(c, name);
+ if (u)
+ return u;
+ }
+
+ return NULL;
+}
+
+
+Unit *
+unit_manager_get_unit_by_symbol(UnitManager *manager, const gchar *symbol)
+{
+ GList *iter;
+ Unit *u;
+
+ for (iter = manager->priv->categories; iter; iter = iter->next) {
+ UnitCategory *c = iter->data;
+ u = unit_category_get_unit_by_symbol(c, symbol);
if (u)
return u;
}
@@ -187,13 +204,17 @@ unit_manager_get_unit(UnitManager *manager, const gchar *unit)
gboolean
-unit_manager_convert(UnitManager *manager, const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z)
+unit_manager_convert_by_symbol(UnitManager *manager, const MPNumber *x, const char *x_symbol, const char *z_symbol, MPNumber *z)
{
GList *iter;
for (iter = manager->priv->categories; iter; iter = iter->next) {
UnitCategory *c = iter->data;
- if (unit_category_convert(c, x, x_units, z_units, z))
+ Unit *x_units, *z_units;
+
+ x_units = unit_category_get_unit_by_symbol(c, x_symbol);
+ z_units = unit_category_get_unit_by_symbol(c, z_symbol);
+ if (x_units && z_units && unit_category_convert(c, x, x_units, z_units, z))
return TRUE;
}
diff --git a/src/unit-manager.h b/src/unit-manager.h
index 1e9aec5..dbb2f80 100644
--- a/src/unit-manager.h
+++ b/src/unit-manager.h
@@ -32,9 +32,11 @@ const GList *unit_manager_get_categories(UnitManager *manager);
UnitCategory *unit_manager_get_category(UnitManager *manager, const gchar *category);
-Unit *unit_manager_get_unit(UnitManager *manager, const gchar *unit);
+Unit *unit_manager_get_unit_by_name(UnitManager *manager, const gchar *name);
-gboolean unit_manager_convert(UnitManager *manager, const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z);
+Unit *unit_manager_get_unit_by_symbol(UnitManager *manager, const gchar *symbol);
+
+gboolean unit_manager_convert_by_symbol(UnitManager *manager, const MPNumber *x, const char *x_symbol, const char *z_symbol, MPNumber *z);
G_END_DECLS
diff --git a/src/unittest.c b/src/unittest.c
index 17103ec..68e35c6 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -120,7 +120,7 @@ test(char *expression, char *expected, int expected_error)
static int
do_convert(const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z, void *data)
{
- return unit_manager_convert(unit_manager_get_default(), x, x_units, z_units, z);
+ return unit_manager_convert_by_symbol(unit_manager_get_default(), x, x_units, z_units, z);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]