r23249 - gnucash/trunk/src - Gnc-Prefs: migrate GncCurrencyEdit widgets (and associated preferences)

Geert Janssens gjanssens at code.gnucash.org
Mon Oct 7 10:18:11 EDT 2013


Author: gjanssens
Date: 2013-10-07 10:18:06 -0400 (Mon, 07 Oct 2013)
New Revision: 23249
Trac: http://svn.gnucash.org/trac/changeset/23249

Modified:
   gnucash/trunk/src/gnome-utils/dialog-preferences.c
   gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade
   gnucash/trunk/src/gnome/gschemas/org.gnucash.gschema.xml.in
Log:
Gnc-Prefs: migrate GncCurrencyEdit widgets (and associated preferences)

All GncCurrencyEdits now use the new preferences backend
so drop the GncCurrencyEdit-Gconf wiring as well.

Modified: gnucash/trunk/src/gnome/gschemas/org.gnucash.gschema.xml.in
===================================================================
--- gnucash/trunk/src/gnome/gschemas/org.gnucash.gschema.xml.in	2013-10-07 14:16:59 UTC (rev 23248)
+++ gnucash/trunk/src/gnome/gschemas/org.gnucash.gschema.xml.in	2013-10-07 14:18:06 UTC (rev 23249)
@@ -115,7 +115,7 @@
       <description>This setting controls the source of the default currency for new accounts.  If set to "locale" then GnuCash will retrieve the default currency from the user's locale setting.  If set to "other", GnuCash will use the setting specified by the currency_other key.</description>
     </key>
     <key name="currency_other" type="s">
-      <default>''</default>
+      <default>'USD'</default>
       <summary>Default currency for new accounts</summary>
       <description>This setting specifies the default currency used for new accounts if the currency_choice setting is set to "other". This field must contain the three letter ISO 4217 code for a currency (e.g. USD, GBP, RUB).</description>
     </key>
@@ -313,7 +313,7 @@
       <description>This setting controls the source of the default currency for new accounts.  If set to "locale" then GnuCash will retrieve the default currency from the user's locale setting.  If set to "other", GnuCash will use the setting specified by the currency_other key.</description>
     </key>
     <key name="currency_other" type="s">
-      <default>''</default>
+      <default>'USD'</default>
       <summary>Default currency for new reports</summary>
       <description>This setting controls the default currency used for reports. If set to "locale" then GnuCash will retrieve the default currency from the user's locale setting.  If set to "other", GnuCash will use the setting specified by the currency_other key.</description>
     </key>

Modified: gnucash/trunk/src/gnome-utils/dialog-preferences.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-preferences.c	2013-10-07 14:16:59 UTC (rev 23248)
+++ gnucash/trunk/src/gnome-utils/dialog-preferences.c	2013-10-07 14:18:06 UTC (rev 23249)
@@ -679,118 +679,6 @@
 /* FIXME to remove when gconf conversion of preferences is complete */
 /****************************************************************************/
 
-/** The user changed a currency_edit.  Update gconf.  Currency_edit
- *  choices are stored as an int.
- *
- *  @internal
- *
- *  @param gce A pointer to the currency_edit that was changed.
- *
- *  @param user_data Unused.
- */
-static void
-gnc_prefs_currency_edit_user_cb_gconf (GNCCurrencyEdit *gce,
-                                 gpointer user_data)
-{
-    const gchar *name, *mnemonic;
-    gnc_commodity *currency;
-
-    g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
-    name  = g_object_get_data(G_OBJECT(gce), "name");
-    currency = gnc_currency_edit_get_currency(gce);
-    mnemonic = gnc_commodity_get_mnemonic(currency);
-
-    DEBUG("Currency edit %s set to %s", name, mnemonic);
-    gnc_gconf_set_string(name, NULL, mnemonic, NULL);
-}
-
-
-/** A currency_edit choice was updated in gconf.  Update the user
- *  visible dialog.
- *
- *  @internal
- *
- *  @param gce A pointer to the currency_edit that changed.
- *
- *  @param value The new value of the currency_edit.
- */
-static void
-gnc_prefs_currency_edit_gconf_cb_gconf (GNCCurrencyEdit *gce,
-                                  GConfEntry *entry)
-{
-    const gchar *mnemonic;
-    gnc_commodity *currency;
-
-    g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
-    ENTER("gce %p, entry %p", gce, entry);
-
-    mnemonic = gconf_value_get_string(entry->value);
-    DEBUG("gce %p, mnemonic %s", gce, mnemonic);
-    currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
-                                          GNC_COMMODITY_NS_CURRENCY, mnemonic);
-
-    /* If there isn't any such commodity, get the default */
-    if (!currency)
-    {
-        currency = gnc_locale_default_currency();
-        DEBUG("gce %p, default currency mnemonic %s",
-              gce, gnc_commodity_get_mnemonic(currency));
-    }
-
-    g_signal_handlers_block_by_func(G_OBJECT(gce),
-                                    G_CALLBACK(gnc_prefs_currency_edit_user_cb_gconf), NULL);
-    gnc_currency_edit_set_currency(GNC_CURRENCY_EDIT(gce), currency);
-    g_signal_handlers_unblock_by_func(G_OBJECT(gce),
-                                      G_CALLBACK(gnc_prefs_currency_edit_user_cb_gconf), NULL);
-    LEAVE(" ");
-}
-
-
-/** Connect a currency_edit widget to the user callback function.  Set
- *  the starting state of the gce from its value in gconf.
- *
- *  @internal
- *
- *  @param gce A pointer to the currency_edit that should be connected.
- */
-static void
-gnc_prefs_connect_currency_edit_gconf (GNCCurrencyEdit *gce, const gchar *boxname )
-{
-    gnc_commodity *currency;
-    const gchar *name;
-    gchar *mnemonic;
-
-    g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
-
-    /* Lookup commodity based upon gconf setting */
-    name = boxname + PREFIX_LEN;
-
-    g_object_set_data(G_OBJECT(gce), "name", g_strdup(name) );
-
-    mnemonic = gnc_gconf_get_string(name, NULL, NULL);
-    currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
-                                          GNC_COMMODITY_NS_CURRENCY, mnemonic);
-    if (mnemonic)
-        g_free(mnemonic);
-
-    /* If there isn't any such commodity, get the default */
-    if (!currency)
-        currency = gnc_locale_default_currency();
-
-    gnc_currency_edit_set_currency(GNC_CURRENCY_EDIT(gce), currency);
-    DEBUG(" Currency edit %s set to %s", name,
-          gnc_commodity_get_mnemonic(currency));
-
-    g_signal_connect(G_OBJECT(gce), "changed",
-                     G_CALLBACK(gnc_prefs_currency_edit_user_cb_gconf), NULL);
-
-    gtk_widget_show_all(GTK_WIDGET(gce));
-}
-
-/****************************************************************************/
-
-/****************************************************************************/
-
 /** The user changed a GncPeriodSelect widget.  Update gconf.
  *  GncPeriodSelect choices are stored as an int.
  *
@@ -1109,6 +997,33 @@
 
 /****************************************************************************/
 
+/** Connect a GncCurrencyEdit widget to its stored value in the preferences database.
+ *
+ *  @internal
+ *
+ *  @param gce A pointer to the currency_edit that should be connected.
+ */
+static void
+gnc_prefs_connect_currency_edit (GNCCurrencyEdit *gce, const gchar *boxname )
+{
+    gnc_commodity *currency;
+    gchar *group, *pref;
+    gchar *mnemonic;
+
+    g_return_if_fail(GNC_IS_CURRENCY_EDIT(gce));
+
+    gnc_prefs_split_widget_name (boxname, &group, &pref);
+
+    gnc_prefs_bind (group, pref, G_OBJECT (gce), "mnemonic");
+
+    g_free (group);
+    g_free (pref);
+
+    gtk_widget_show_all(GTK_WIDGET(gce));
+}
+
+/****************************************************************************/
+
 /** Connect a GtkEntry widget to its stored value in the preferences database.
  *
  *  @internal
@@ -1212,13 +1127,8 @@
         DEBUG("  %s - hbox", name);
         DEBUG("Hbox widget type is %s and name is %s", gtk_widget_get_name(GTK_WIDGET(widget_child)), name);
 
-        if (GNC_IS_CURRENCY_EDIT(widget_child))
+        if (GNC_IS_PERIOD_SELECT(widget_child))
         {
-            DEBUG("  %s - currency_edit", name);
-            gnc_prefs_connect_currency_edit_gconf(GNC_CURRENCY_EDIT(widget_child), name );
-        }
-        else if (GNC_IS_PERIOD_SELECT(widget_child))
-        {
             DEBUG("  %s - period_Select", name);
             gnc_prefs_connect_period_select_gconf(GNC_PERIOD_SELECT(widget_child), name );
         }
@@ -1285,6 +1195,22 @@
         DEBUG("  %s - entry", name);
         gnc_prefs_connect_entry(GTK_ENTRY(widget));
     }
+    else if (GTK_IS_HBOX(widget))
+    {
+        /* Test custom widgets are all children of a hbox */
+        GtkWidget *widget_child;
+        GList* child = gtk_container_get_children(GTK_CONTAINER(widget));
+        widget_child = child->data;
+        g_list_free(child);
+        DEBUG("  %s - hbox", name);
+        DEBUG("Hbox widget type is %s and name is %s", gtk_widget_get_name(GTK_WIDGET(widget_child)), name);
+
+        if (GNC_IS_CURRENCY_EDIT(widget_child))
+        {
+            DEBUG("  %s - currency_edit", name);
+            gnc_prefs_connect_currency_edit(GNC_CURRENCY_EDIT(widget_child), name );
+        }
+    }
     else
     {
         DEBUG("  %s - unsupported %s", name,
@@ -1356,7 +1282,7 @@
     g_object_set_data_full(G_OBJECT(dialog), PREFS_WIDGET_HASH,
                            prefs_table, (GDestroyNotify)g_hash_table_destroy);
 
-    box = GTK_WIDGET(gtk_builder_get_object (builder, "gconf/window/pages/account_tree/summary/start_period"));
+    box = GTK_WIDGET(gtk_builder_get_object (builder, "pref/window.pages.account_tree.summary/start_period"));
     period = gnc_period_select_new(TRUE);
     gtk_widget_show (period);
     gtk_box_pack_start (GTK_BOX (box), period, TRUE, TRUE, 0);
@@ -1366,7 +1292,7 @@
     gtk_widget_show (date);
     gtk_box_pack_start (GTK_BOX (box), date, TRUE, TRUE, 0);
 
-    box = GTK_WIDGET(gtk_builder_get_object (builder, "gconf/window/pages/account_tree/summary/end_period"));
+    box = GTK_WIDGET(gtk_builder_get_object (builder, "pref/window.pages.account_tree.summary/end_period"));
     period = gnc_period_select_new(FALSE);
     gtk_widget_show (period);
     gtk_box_pack_start (GTK_BOX (box), period, TRUE, TRUE, 0);
@@ -1376,13 +1302,13 @@
     gtk_widget_show (date);
     gtk_box_pack_start (GTK_BOX (box), date, TRUE, TRUE, 0);
 
-    box = GTK_WIDGET(gtk_builder_get_object (builder, "gconf/general/currency_other"));
+    box = GTK_WIDGET(gtk_builder_get_object (builder, "pref/general/currency_other"));
     currency = gnc_currency_edit_new();
     gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(currency), gnc_default_currency());
     gtk_widget_show (currency);
     gtk_box_pack_start(GTK_BOX (box), currency, TRUE, TRUE, 0);
 
-    box = GTK_WIDGET(gtk_builder_get_object (builder, "gconf/general/report/currency_other"));
+    box = GTK_WIDGET(gtk_builder_get_object (builder, "pref/general.report/currency_other"));
     currency = gnc_currency_edit_new();
     gnc_currency_edit_set_currency (GNC_CURRENCY_EDIT(currency), gnc_default_currency());
     gtk_widget_show (currency);
@@ -1548,13 +1474,8 @@
             DEBUG("  %s - hbox", name);
             DEBUG("Hbox gconf name is %s and widget get name is %s", name, gtk_widget_get_name(GTK_WIDGET(widget_child)));
 
-            if (GNC_IS_CURRENCY_EDIT(widget_child))
+            if (GNC_IS_PERIOD_SELECT(widget_child))
             {
-                DEBUG("widget %p - currency_edit", widget_child);
-                gnc_prefs_currency_edit_gconf_cb_gconf(GNC_CURRENCY_EDIT(widget_child), entry);
-            }
-            else if (GNC_IS_PERIOD_SELECT(widget_child))
-            {
                 DEBUG("widget %p - period_select", widget_child);
                 gnc_prefs_period_select_gconf_cb_gconf(GNC_PERIOD_SELECT(widget_child),
                                                  gconf_value_get_int(entry->value));

Modified: gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade
===================================================================
--- gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade	2013-10-07 14:16:59 UTC (rev 23248)
+++ gnucash/trunk/src/gnome-utils/gtkbuilder/dialog-preferences.glade	2013-10-07 14:18:06 UTC (rev 23249)
@@ -828,7 +828,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkHBox" id="gconf/general/currency_other">
+                  <object class="GtkHBox" id="pref/general/currency_other">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <child>
@@ -3070,7 +3070,7 @@
                   </packing>
                 </child>
                 <child>
-                  <object class="GtkHBox" id="gconf/general/report/currency_other">
+                  <object class="GtkHBox" id="pref/general.report/currency_other">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <child>



More information about the gnucash-changes mailing list