[gcalctool] Make UnitManager only a singleton



commit 2fd0060b19c6a9abfb602d79df86867082f95d70
Author: Robert Ancell <robert ancell canonical com>
Date:   Thu Jan 27 12:05:46 2011 +1000

    Make UnitManager only a singleton

 src/gcalctool.c      |    1 +
 src/math-converter.c |    8 ++++----
 src/math-converter.h |    2 ++
 src/math-equation.c  |   13 ++-----------
 src/math-equation.h  |    4 +---
 src/unit-manager.c   |    9 +--------
 src/unit-manager.h   |    2 --
 7 files changed, 11 insertions(+), 28 deletions(-)
---
diff --git a/src/gcalctool.c b/src/gcalctool.c
index 8bf030a..1861256 100644
--- a/src/gcalctool.c
+++ b/src/gcalctool.c
@@ -26,6 +26,7 @@
 #include "unittest.h"
 #include "math-window.h"
 #include "mp-equation.h"
+#include "unit-manager.h"
 
 static GSettings *settings = NULL;
 
diff --git a/src/math-converter.c b/src/math-converter.c
index c5021f0..4d5f660 100644
--- a/src/math-converter.c
+++ b/src/math-converter.c
@@ -120,7 +120,7 @@ update_from_model(MathConverter *converter)
     if (converter->priv->category == NULL) {
         const GList *categories, *iter;
 
-        categories = unit_manager_get_categories(math_equation_get_unit_manager(converter->priv->equation));
+        categories = unit_manager_get_categories(unit_manager_get_default());
         for (iter = categories; iter; iter = iter->next) {
             UnitCategory *category = iter->data;
             GtkTreeIter parent;
@@ -142,7 +142,7 @@ update_from_model(MathConverter *converter)
         UnitCategory *category;
         const GList *unit_iter;
 
-        category = unit_manager_get_category(math_equation_get_unit_manager(converter->priv->equation), converter->priv->category);
+        category = unit_manager_get_category(unit_manager_get_default(), converter->priv->category);
         for (unit_iter = unit_category_get_units(category); unit_iter; unit_iter = unit_iter->next) {
             Unit *unit = unit_iter->data;
             GtkTreeIter iter;
@@ -227,8 +227,8 @@ math_converter_set_conversion(MathConverter *converter, /*const gchar *category,
     Unit *ua;
     Unit *ub;
 
-    ua = unit_manager_get_unit(math_equation_get_unit_manager(converter->priv->equation), unit_a);
-    ub = unit_manager_get_unit(math_equation_get_unit_manager(converter->priv->equation), unit_b);
+    ua = unit_manager_get_unit(unit_manager_get_default(), unit_a);
+    ub = unit_manager_get_unit(unit_manager_get_default(), unit_b);
     if (!ua || !ub)
         return;
 
diff --git a/src/math-converter.h b/src/math-converter.h
index 1e17350..e2fc04d 100644
--- a/src/math-converter.h
+++ b/src/math-converter.h
@@ -21,7 +21,9 @@
 
 #include <glib-object.h>
 #include <gtk/gtk.h>
+
 #include "math-equation.h"
+#include "unit.h"
 
 G_BEGIN_DECLS
 
diff --git a/src/math-equation.c b/src/math-equation.c
index 082a3c1..13e0f72 100644
--- a/src/math-equation.c
+++ b/src/math-equation.c
@@ -32,6 +32,7 @@
 #include "mp-equation.h"
 #include "mp-serializer.h"
 #include "math-enums.h"
+#include "unit-manager.h"
 
 
 enum {
@@ -99,7 +100,6 @@ struct MathEquationPrivate
     gboolean in_solve;
 
     MathVariables *variables;
-    UnitManager *unit_manager;
     MpSerializer *serializer;
 
     GAsyncQueue *queue;
@@ -128,13 +128,6 @@ math_equation_get_variables(MathEquation *equation)
 }
 
 
-UnitManager *
-math_equation_get_unit_manager(MathEquation *equation)
-{
-    return equation->priv->unit_manager;
-}
-
-
 static void
 get_ans_offsets(MathEquation *equation, gint *start, gint *end)
 {
@@ -1079,8 +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)
 {
-    MathEquation *equation = data;
-    return unit_manager_convert(equation->priv->unit_manager, x, x_units, z_units, z);
+    return unit_manager_convert(unit_manager_get_default(), x, x_units, z_units, z);
 }
 
 
@@ -1845,7 +1837,6 @@ math_equation_init(MathEquation *equation)
     g_strfreev(digits);
 
     equation->priv->variables = math_variables_new();
-    equation->priv->unit_manager = unit_manager_get_default();
 
     equation->priv->state.status = g_strdup("");
     equation->priv->word_size = 32;
diff --git a/src/math-equation.h b/src/math-equation.h
index 819b157..2486099 100644
--- a/src/math-equation.h
+++ b/src/math-equation.h
@@ -22,9 +22,9 @@
 
 #include <glib-object.h>
 #include <gtk/gtk.h>
+
 #include "mp.h"
 #include "math-variables.h"
-#include "unit-manager.h"
 #include "mp-serializer.h"
 
 G_BEGIN_DECLS
@@ -57,8 +57,6 @@ MathEquation *math_equation_new(void);
 
 MathVariables *math_equation_get_variables(MathEquation *equation);
 
-UnitManager *math_equation_get_unit_manager(MathEquation *equation);
-
 gunichar math_equation_get_digit_text(MathEquation *equation, guint digit);
 
 void math_equation_set_status(MathEquation *equation, const gchar *status);
diff --git a/src/unit-manager.c b/src/unit-manager.c
index 4d5e032..273f0cf 100644
--- a/src/unit-manager.c
+++ b/src/unit-manager.c
@@ -15,13 +15,6 @@ G_DEFINE_TYPE (UnitManager, unit_manager, G_TYPE_OBJECT);
 static UnitManager *default_unit_manager = NULL;
 
 
-UnitManager *
-unit_manager_new(void)
-{
-    return g_object_new(unit_manager_get_type(), NULL);
-}
-
-
 static MPNumber *
 get_value(const gchar *value, MPNumber *t)
 {
@@ -40,7 +33,7 @@ unit_manager_get_default(void)
     if (default_unit_manager)
         return default_unit_manager;
 
-    default_unit_manager = unit_manager_new();
+    default_unit_manager = g_object_new(unit_manager_get_type(), NULL);
 
     /* FIXME: Approximations of 1/(units in a circle), therefore, 360 deg != 400 grads */
     category = unit_manager_add_category(default_unit_manager, "angle", _("Angle"));
diff --git a/src/unit-manager.h b/src/unit-manager.h
index 02b983d..1e9aec5 100644
--- a/src/unit-manager.h
+++ b/src/unit-manager.h
@@ -24,8 +24,6 @@ typedef struct
 
 GType unit_manager_get_type(void);
 
-UnitManager *unit_manager_new(void);
-
 UnitManager *unit_manager_get_default(void);
 
 UnitCategory *unit_manager_add_category(UnitManager *manager, const gchar *name, const gchar *display_name);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]