[gcalctool] Migrate from gconf to gsettings



commit 1b12555a1cbbf0e5d89da8d9a40f38bf7e9bcd8c
Author: Robert Ancell <robert ancell gmail com>
Date:   Thu Jun 24 12:27:56 2010 +1000

    Migrate from gconf to gsettings

 .gitignore                              |    2 +-
 NEWS                                    |    2 +
 configure.ac                            |    8 +-
 data/Makefile.am                        |   11 +-
 data/org.gnome.gcalctool.gschema.xml.in |   94 ++++++++-------
 src/gcalctool.c                         |  186 +++++--------------------------
 6 files changed, 90 insertions(+), 213 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 50d7d05..4f78e70 100644
--- a/.gitignore
+++ b/.gitignore
@@ -19,7 +19,7 @@ Makefile.in.in
 stamp-h1
 xmldocs.make
 data/gcalctool.desktop
-data/gcalctool.schemas
+data/org.gnome.gcalctool.gschema.xml
 help/[^C]*/*.page
 help/[^C]*/legal.xml
 help/*/*.gmo
diff --git a/NEWS b/NEWS
index e220cde..432e56d 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@
 Overview of changes in gcalctool 5.31.4
 
     * Show currency conversion below display
+
+    * Use gsettings instead of gconf
  
 Overview of changes in gcalctool 5.31.3
 
diff --git a/configure.ac b/configure.ac
index c2a8d3f..560655c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -12,8 +12,7 @@ AC_PROG_CC
 AM_PROG_CC_STDC
 AC_HEADER_STDC
 
-AM_GCONF_SOURCE_2
-
+GLIB_GSETTINGS
 GNOME_COMPILE_WARNINGS(yes)
 
 dnl ###########################################################################
@@ -21,12 +20,11 @@ dnl Dependencies
 dnl ###########################################################################
 
 GTK_REQUIRED=2.18
-GCONF_REQUIRED=1.1.9
+GIO_REQUIRED=2.25.10
 
 PKG_CHECK_MODULES(GCALCTOOL, [
     gtk+-2.0 >= $GTK_REQUIRED
-    gconf-2.0 >= $GCONF_REQUIRED
-    gio-2.0
+    gio-2.0 >= $GIO_REQUIRED
     libxml-2.0
     gmodule-export-2.0
 ])
diff --git a/data/Makefile.am b/data/Makefile.am
index d06c5da..67a6949 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -6,10 +6,9 @@ ui_DATA = \
 	buttons-financial.ui \
 	buttons-programming.ui
 
-schemadir   = @GCONF_SCHEMA_FILE_DIR@
-schema_in_files = gcalctool.schemas.in
-schema_DATA = $(schema_in_files:.schemas.in=.schemas)
- INTLTOOL_SCHEMAS_RULE@
+gsettings_SCHEMAS = org.gnome.gcalctool.gschema.xml
+ INTLTOOL_XML_NOMERGE_RULE@
+ GSETTINGS_RULES@
 
 Utilitiesdir = $(datadir)/applications
 Utilities_in_files = gcalctool.desktop.in
@@ -18,9 +17,9 @@ Utilities_DATA = $(Utilities_in_files:.desktop.in=.desktop)
 
 man1_MANS = gcalctool.1
 
-EXTRA_DIST = $(ui_DATA) $(schema_in_files) gcalctool.desktop.in $(man1_MANS)
+EXTRA_DIST = $(ui_DATA) org.gnome.gcalctool.gschema.xml gcalctool.desktop.in $(man1_MANS)
 
 DISTCLEANFILES = \
 	Makefile.in \
 	gcalctool.desktop \
-	$(schema_DATA)
+	$(gsettings_SCHEMAS)
diff --git a/data/org.gnome.gcalctool.gschema.xml.in b/data/org.gnome.gcalctool.gschema.xml.in
index 96f21fe..eff5b95 100644
--- a/data/org.gnome.gcalctool.gschema.xml.in
+++ b/data/org.gnome.gcalctool.gschema.xml.in
@@ -1,69 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <schemalist>
-  <schema id="org.gnome.gcalctool" path="/apps/gcalctool/">
-    <key name="accuracy" type="i">
+  <enum id="org.gnome.gcalctool.NumberFormat">
+    <value value="0" nick="fixed"/>
+    <value value="1" nick="scientific"/>
+    <value value="2" nick="engineering"/>
+  </enum>
+  <enum id="org.gnome.gcalctool.ButtonMode">
+    <value value="0" nick="basic"/>
+    <value value="1" nick="advanced"/>
+    <value value="2" nick="financial"/>
+    <value value="3" nick="programming"/>
+  </enum>
+  <enum id="org.gnome.gcalctool.AngleUnit">
+    <value value="0" nick="radians"/>
+    <value value="1" nick="degrees"/>
+    <value value="2" nick="gradians"/>
+  </enum>
+
+  <schema path="/apps/gcalctool/" id="org.gnome.gcalctool" gettext-domain="gcalctool">
+    <key type="i" name="accuracy">
       <default>9</default>
+      <range min="0" max="9"/>
       <_summary>Accuracy value</_summary>
-      <_description>The number of digits displayed after the numeric point. This value must be in the range 0 to 9.</_description>
+      <_description>The number of digits displayed after the numeric point</_description>
     </key>
-    <key name="base" type="i">
+    <key type="i" name="word-size">
+      <default>64</default>
+      <range min="8" max="64"/>
+      <_summary>Word size</_summary>
+      <_description>The size of the words used in bitwise operations</_description>
+    </key>
+    <key type="i" name="base">
       <default>10</default>
+      <range min="2" max="16"/>
       <_summary>Numeric Base</_summary>
-      <_description>The numeric base (used in programming mode)</_description>
-    </key>
-    <key name="display" type="s">
-      <default>'FIX'</default>
-      <_summary>Display Mode</_summary>
-      <_description>The display format used in advanced mode.  One of: "ENG" (engineering),  "FIX" (fixed-point) and "SCI" (scientific)</_description>
-    </key>
-    <key name="mode" type="s">
-      <default>'BASIC'</default>
-      <_summary>Mode</_summary>
-      <_description>The initial calculator mode. Valid values are "BASIC",  "FINANCIAL",  "LOGICAL",  "SCIENTIFIC" and  "PROGRAMMING"</_description>
-    </key>
-    <key name="showzeroes" type="b">
-      <default>false</default>
-      <_summary>Show Trailing Zeroes</_summary>
-      <_description>Indicates whether any trailing zeroes after the  numeric point should be shown in the display value.</_description>
+      <_description>The numeric base</_description>
     </key>
-    <key name="showthousands" type="b">
+    <key type="b" name="show-thousands">
       <default>false</default>
       <_summary>Show Thousands Separators</_summary>
       <_description>Indicates whether thousands separators are shown in large numbers.</_description>
     </key>
-    <key name="showregisters" type="b">
+    <key type="b" name="show-zeroes">
       <default>false</default>
-      <_summary>Show Registers</_summary>
-      <_description>Indicates whether the memory register window is  initially displayed.</_description>
+      <_summary>Show Trailing Zeroes</_summary>
+      <_description>Indicates whether any trailing zeroes after the  numeric point should be shown in the display value.</_description>
     </key>
-    <key name="trigtype" type="s">
-      <default>'DEG'</default>
-      <_summary>Trigonometric type</_summary>
-      <_description>The initial trigonometric type. Valid values are "DEG" (degrees), "GRAD" (gradians) and  "RAD" (radians).</_description>
+    <key name="number-format" enum="org.gnome.gcalctool.NumberFormat">
+      <default>'fixed'</default>
+      <_summary>Number format</_summary>
+      <_description>The format to display numbers in</_description>
     </key>
-    <key name="wordlen" type="i">
-      <default>64</default>
-      <_summary>Word size</_summary>
-      <_description>The size of the words used in bitwise operations. Valid values are 16,  32 and 64.</_description>
+    <key name="angle-units" enum="org.gnome.gcalctool.AngleUnit">
+      <default>'degrees'</default>
+      <_summary>Angle units</_summary>
+      <_description>The angle units to use</_description>
+    </key>
+    <key name="button-mode" enum="org.gnome.gcalctool.ButtonMode">
+      <default>'basic'</default>
+      <_summary>Button mode</_summary>
+      <_description>The button mode</_description>
     </key>
-    <key name="source_currency" type="s">
+    <key type="s" name="source-currency">
       <default>''</default>
       <_summary>Source currency</_summary>
       <_description>Currency of the current calculation</_description>
     </key>
-    <key name="target_currency" type="s">
+    <key type="s" name="target-currency">
       <default>''</default>
       <_summary>Target currency</_summary>
       <_description>Currency to convert the current calculation into</_description>
     </key>
-    <key name="xposition" type="i">
-      <default>-1</default>
-      <_summary>The initial x-coordinate for the window</_summary>
-      <_description>The number of pixels to place the window from the left of the screen.</_description>
-    </key>
-    <key name="yposition" type="i">
-      <default>-1</default>
-      <_summary>The initial y-coordinate for the window</_summary>
-      <_description>The number of pixels to place the window from the top of the screen.</_description>
-    </key>
   </schema>
 </schemalist>
diff --git a/src/gcalctool.c b/src/gcalctool.c
index 00b5e52..8eeb285 100644
--- a/src/gcalctool.c
+++ b/src/gcalctool.c
@@ -20,14 +20,13 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <gconf/gconf-client.h>
 
 #include "currency.h"
 #include "unittest.h"
 #include "math-window.h"
 #include "mp-equation.h"
 
-static GConfClient *client = NULL;
+static GSettings *settings = NULL;
 
 static MathWindow *window;
 
@@ -175,104 +174,6 @@ get_options(int argc, char *argv[])
 }
 
 
-// FIXME: Use a proper GEnum for these
-static const gchar *
-number_format_to_string(DisplayFormat format)
-{
-    switch(format)
-    {
-    default:
-    case FIX:
-        return "FIX";
-    case SCI:
-        return "SCI";
-    case ENG:      
-        return "ENG";
-    }
-}
-
-
-static DisplayFormat
-string_to_number_format(const gchar *name)
-{
-    if (name == NULL)
-        return FIX;
-
-    if (strcmp(name, "SCI") == 0)
-        return SCI;
-    else if (strcmp(name, "ENG") == 0)
-        return ENG;
-    else
-        return FIX;
-}
-
-
-static const gchar *
-angle_unit_to_string(MPAngleUnit unit)
-{
-    switch(unit)
-    {
-    default:
-    case MP_DEGREES:
-        return "degrees";
-    case MP_RADIANS:
-        return "radians";
-    case MP_GRADIANS:
-        return "gradians";
-    }
-}
-
-
-static MPAngleUnit
-string_to_angle_unit(const gchar *name)
-{
-    if (name == NULL)
-        return MP_DEGREES;
-
-    if (strcmp(name, "radians") == 0)
-        return MP_RADIANS;
-    else if (strcmp(name, "gradians") == 0)
-        return MP_GRADIANS;
-    else
-        return MP_DEGREES;
-}
-
-
-static const gchar *
-button_mode_to_string(ButtonMode mode)
-{
-    switch(mode)
-    {
-    default:
-    case BASIC:
-        return "BASIC";
-    case ADVANCED:
-        return "ADVANCED";
-    case FINANCIAL:
-        return "FINANCIAL";
-    case PROGRAMMING:
-        return "PROGRAMMING";
-    }
-}
-
-
-static ButtonMode
-string_to_button_mode(const gchar *name)
-{
-    if (name == NULL)
-         return BASIC;
-
-    if (strcmp(name, "ADVANCED") == 0)
-        return ADVANCED;
-    else if (strcmp(name, "FINANCIAL") == 0)
-        return FINANCIAL;
-    else if (strcmp(name, "PROGRAMMING") == 0)
-        return PROGRAMMING;
-    else
-        return BASIC;
-}
-
-
 static void
 quit_cb(MathWindow *window)
 {
@@ -282,55 +183,31 @@ quit_cb(MathWindow *window)
     equation = math_window_get_equation(window);
     buttons = math_window_get_buttons(window);
 
-    gconf_client_set_int(client, "/apps/gcalctool/accuracy", math_equation_get_accuracy(equation), NULL);
-    gconf_client_set_int(client, "/apps/gcalctool/wordlen", math_equation_get_word_size(equation), NULL);
-    gconf_client_set_bool(client, "/apps/gcalctool/showthousands", math_equation_get_show_thousands_separators(equation), NULL);
-    gconf_client_set_bool(client, "/apps/gcalctool/showzeroes", math_equation_get_show_trailing_zeroes(equation), NULL);
-    gconf_client_set_string(client, "/apps/gcalctool/result_format", number_format_to_string(math_equation_get_number_format(equation)), NULL);
-    gconf_client_set_string(client, "/apps/gcalctool/angle_units", angle_unit_to_string(math_equation_get_angle_units(equation)), NULL);
-    gconf_client_set_string(client, "/apps/gcalctool/button_layout", button_mode_to_string(math_buttons_get_mode(buttons)), NULL);
-    gconf_client_set_int(client, "/apps/gcalctool/base", math_buttons_get_programming_base(buttons), NULL);
-    gconf_client_set_string(client, "/apps/gcalctool/source_currency", math_equation_get_source_currency(equation), NULL);
-    gconf_client_set_string(client, "/apps/gcalctool/target_currency", math_equation_get_target_currency(equation), NULL);
+    g_settings_set_int(settings, "accuracy", math_equation_get_accuracy(equation));
+    g_settings_set_int(settings, "word-size", math_equation_get_word_size(equation));
+    g_settings_set_int(settings, "base", math_buttons_get_programming_base(buttons));
+    g_settings_set_boolean(settings, "show-thousands", math_equation_get_show_thousands_separators(equation));
+    g_settings_set_boolean(settings, "show-zeroes", math_equation_get_show_trailing_zeroes(equation));
+    g_settings_set_enum(settings, "number-format", math_equation_get_number_format(equation));
+    g_settings_set_enum(settings, "angle-units", math_equation_get_angle_units(equation));
+    g_settings_set_enum(settings, "button-mode", math_buttons_get_mode(buttons));
+    g_settings_set_string(settings, "source-currency", math_equation_get_source_currency(equation));
+    g_settings_set_string(settings, "target-currency", math_equation_get_target_currency(equation));
 
     currency_free_resources();
     gtk_main_quit();
 }
 
 
-static void
-get_int(const char *name, gint *value)
-{
-    GConfValue *v;
-
-    v = gconf_client_get(client, name, NULL);
-    if (!v)
-        return;
-    *value = gconf_value_get_int(v);
-    gconf_value_free(v);
-}
-
-
-static void
-get_bool(const char *name, gboolean *value)
-{
-    GConfValue *v;
-
-    v = gconf_client_get(client, name, NULL);
-    if (!v)
-        return;
-    *value = gconf_value_get_bool(v);
-    gconf_value_free(v);
-}
-
-
 int
 main(int argc, char **argv)
 {
     MathEquation *equation;
     int accuracy = 9, word_size = 64, base = 10;
     gboolean show_tsep = FALSE, show_zeroes = FALSE;
-    gchar *number_format, *angle_units, *button_mode;
+    DisplayFormat number_format;
+    MPAngleUnit angle_units;
+    ButtonMode button_mode;
     gchar *source_currency, *target_currency;
 
     g_type_init();
@@ -344,31 +221,27 @@ main(int argc, char **argv)
 
     get_options(argc, argv);
 
-    client = gconf_client_get_default();
-    gconf_client_add_dir(client, "/apps/gcalctool", GCONF_CLIENT_PRELOAD_NONE, NULL);  
-  
-    equation = math_equation_new();
-    get_int("/apps/gcalctool/accuracy", &accuracy);
-    get_int("/apps/gcalctool/wordlen", &word_size);
-    get_bool("/apps/gcalctool/showthousands", &show_tsep);
-    get_bool("/apps/gcalctool/showzeroes", &show_zeroes);
-    get_int("/apps/gcalctool/base", &base);
-    number_format = gconf_client_get_string(client, "/apps/gcalctool/result_format", NULL);
-    angle_units = gconf_client_get_string(client, "/apps/gcalctool/angle_units", NULL);
-    button_mode = gconf_client_get_string(client, "/apps/gcalctool/button_layout", NULL);
-    source_currency = gconf_client_get_string(client, "/apps/gcalctool/source_currency", NULL);
-    target_currency = gconf_client_get_string(client, "/apps/gcalctool/target_currency", NULL);
+    settings = g_settings_new ("org.gnome.gcalctool");
+    accuracy = g_settings_get_int(settings, "accuracy");
+    word_size = g_settings_get_int(settings, "word-size");
+    base = g_settings_get_int(settings, "base");
+    show_tsep = g_settings_get_boolean(settings, "show-thousands");
+    show_zeroes = g_settings_get_boolean(settings, "show-zeroes");
+    number_format = g_settings_get_enum(settings, "number-format");
+    angle_units = g_settings_get_enum(settings, "angle-units");
+    button_mode = g_settings_get_enum(settings, "button-mode");
+    source_currency = g_settings_get_string(settings, "source-currency");
+    target_currency = g_settings_get_string(settings, "target-currency");
 
+    equation = math_equation_new();
     math_equation_set_accuracy(equation, accuracy);
     math_equation_set_word_size(equation, word_size);
     math_equation_set_show_thousands_separators(equation, show_tsep);
     math_equation_set_show_trailing_zeroes(equation, show_zeroes);
-    math_equation_set_number_format(equation, string_to_number_format(number_format));
-    math_equation_set_angle_units(equation, string_to_angle_unit(angle_units));
+    math_equation_set_number_format(equation, number_format);
+    math_equation_set_angle_units(equation, angle_units);
     math_equation_set_source_currency(equation, source_currency);
     math_equation_set_target_currency(equation, target_currency);
-    g_free(number_format);
-    g_free(angle_units);
     g_free(source_currency);
     g_free(target_currency);
 
@@ -377,8 +250,7 @@ main(int argc, char **argv)
     window = math_window_new(equation);
     g_signal_connect(G_OBJECT(window), "quit", G_CALLBACK(quit_cb), NULL);
     math_buttons_set_programming_base(math_window_get_buttons(window), base);
-    math_buttons_set_mode(math_window_get_buttons(window), string_to_button_mode(button_mode)); // FIXME: We load the basic buttons even if we immediately switch to the next type
-    g_free(button_mode);
+    math_buttons_set_mode(math_window_get_buttons(window), button_mode); // FIXME: We load the basic buttons even if we immediately switch to the next type
 
     gtk_widget_show(GTK_WIDGET(window));
     gtk_main();



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