gnucash maint: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Mon Feb 28 16:55:36 EST 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/831b25f8 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/065cf236 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/8ccfc2b0 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/0576626c (commit)
	from  https://github.com/Gnucash/gnucash/commit/c3883e70 (commit)



commit 831b25f8f8a218e5e9b75bcc6c0161e8ba1bd6b1
Merge: c3883e703 065cf236c
Author: John Ralls <jralls at ceridwen.us>
Date:   Mon Feb 28 13:51:45 2022 -0800

    Merge Chris Lam's 'maint-progress1' into maint.


commit 065cf236cb8159acfd4567b3e7486a71f9bf2f84
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Fri Oct 15 08:20:01 2021 +0800

    Don't iterate index on xaccTransGetSplit (trans, index)
    
    Iterate on xaccTransGetSplitList directly.

diff --git a/gnucash/gnome-utils/gnc-tree-view-split-reg.c b/gnucash/gnome-utils/gnc-tree-view-split-reg.c
index 35c9ea256..74738392e 100644
--- a/gnucash/gnome-utils/gnc-tree-view-split-reg.c
+++ b/gnucash/gnome-utils/gnc-tree-view-split-reg.c
@@ -1164,8 +1164,6 @@ static Split *
 gtv_sr_get_this_split (GncTreeViewSplitReg *view, Transaction *trans)
 {
     GncTreeModelSplitReg *model;
-    int i;
-    Split *split = NULL;
     Account *anchor;
 
     model = gnc_tree_view_split_reg_get_model_from_view (view);
@@ -1178,7 +1176,9 @@ gtv_sr_get_this_split (GncTreeViewSplitReg *view, Transaction *trans)
             return gnc_tree_model_split_get_blank_split (model);
     }
 
-    for (i = 0; (split = xaccTransGetSplit (trans, i)); i++) {
+    for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
+    {
+        Split *split = n->data;
         if (anchor == xaccSplitGetAccount (split))
             return split;
     }
@@ -1210,8 +1210,7 @@ gtv_sr_get_split_pair (GncTreeViewSplitReg *view, Transaction *trans, Split **os
     }
     else
     {
-        int i;
-        Split *s, *first_split;
+        Split *first_split;
 
         first_split = xaccTransGetSplit (trans, 0);
 
@@ -1219,8 +1218,9 @@ gtv_sr_get_split_pair (GncTreeViewSplitReg *view, Transaction *trans, Split **os
             return FALSE;
         else // two split trans
         {
-            for (i = 0; (s = xaccTransGetSplit (trans, i)); i++)
+            for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
             {
+                Split *s = n->data;
                 if (anchor == xaccSplitGetAccount (s))
                 {
                     *split = s;
@@ -1241,13 +1241,12 @@ gtv_sr_get_split_pair (GncTreeViewSplitReg *view, Transaction *trans, Split **os
 static gboolean
 gtv_sr_get_imbalance (Transaction *trans)
 {
-    int i;
-    Split *split = NULL;
     const gchar *acc_name;
     const gchar *prefix = _("Imbalance");
 
-    for (i = 0; (split = xaccTransGetSplit (trans, i)); i++)
+    for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
     {
+        Split *split = n->data;
         if (xaccSplitGetAccount (split) != NULL)
         {
             acc_name = xaccAccountGetName (xaccSplitGetAccount (split));
diff --git a/gnucash/register/ledger-core/split-register-control.c b/gnucash/register/ledger-core/split-register-control.c
index 6ef114984..09b0c89b0 100644
--- a/gnucash/register/ledger-core/split-register-control.c
+++ b/gnucash/register/ledger-core/split-register-control.c
@@ -641,12 +641,9 @@ static Split *
 gnc_find_split_in_trans_by_memo (Transaction *trans, const char *memo,
                                  gboolean unit_price)
 {
-    int i = 0;
-    Split *split;
-
-    while ((split = xaccTransGetSplit(trans, i)) != NULL)
+    for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
     {
-        i++;
+        Split *split = n->data;
         if (unit_price)
         {
             gnc_numeric price = xaccSplitGetSharePrice (split);
@@ -899,21 +896,19 @@ gnc_split_register_auto_completion (SplitRegister *reg,
                 gnc_split_register_get_default_account (reg);
             gnc_commodity *trans_cmdty = xaccTransGetCurrency(trans);
             gnc_commodity *acct_cmdty = xaccAccountGetCommodity(default_account);
-            Split *s;
-            int i = 0;
             if (gnc_commodity_is_currency(acct_cmdty) &&
                 !gnc_commodity_equal(trans_cmdty, acct_cmdty))
                 xaccTransSetCurrency(trans, acct_cmdty);
 
-            while ((s = xaccTransGetSplit(trans, i)) != NULL)
+            for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
             {
+                Split *s = n->data;
                 if (default_account == xaccSplitGetAccount(s))
                 {
                     blank_split = s;
                     info->blank_split_guid = *xaccSplitGetGUID(blank_split);
                     break;
                 }
-                i++;
             }
         }
 
diff --git a/gnucash/register/ledger-core/split-register-load.c b/gnucash/register/ledger-core/split-register-load.c
index 13ae25d2c..f11339393 100644
--- a/gnucash/register/ledger-core/split-register-load.c
+++ b/gnucash/register/ledger-core/split-register-load.c
@@ -238,9 +238,6 @@ _find_split_with_parent_txn (gconstpointer a, gconstpointer b)
 static void add_quickfill_completions (TableLayout* layout, Transaction* trans,
                                        Split* split, gboolean has_last_num)
 {
-    Split* s;
-    int i = 0;
-
     gnc_quickfill_cell_add_completion (
         (QuickFillCell*) gnc_table_layout_get_cell (layout, DESC_CELL),
         xaccTransGetDescription (trans));
@@ -254,12 +251,12 @@ static void add_quickfill_completions (TableLayout* layout, Transaction* trans,
             (NumCell*) gnc_table_layout_get_cell (layout, NUM_CELL),
             gnc_get_num_action (trans, split));
 
-    while ((s = xaccTransGetSplit (trans, i)) != NULL)
+    for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
     {
+        Split *s = n->data;
         gnc_quickfill_cell_add_completion (
             (QuickFillCell*) gnc_table_layout_get_cell (layout, MEMO_CELL),
             xaccSplitGetMemo (s));
-        i++;
     }
 }
 
diff --git a/gnucash/register/ledger-core/split-register.c b/gnucash/register/ledger-core/split-register.c
index 0c31a81a8..88824e42b 100644
--- a/gnucash/register/ledger-core/split-register.c
+++ b/gnucash/register/ledger-core/split-register.c
@@ -1114,14 +1114,13 @@ gnc_split_register_change_blank_split_ref (SplitRegister* reg, Split* split)
                                                   gnc_get_current_book ());
     Split* pref_split = NULL; // has the same account as incoming split
     Split* other_split = NULL; // other split
-    Split* s;
     Account* blank_split_account = xaccSplitGetAccount (current_blank_split);
     Transaction* trans = xaccSplitGetParent (split);
-    int i = 0;
 
     // loop through splitlist looking for splits other than the blank_split
-    while ((s = xaccTransGetSplit (trans, i)) != NULL)
+    for (GList *n = xaccTransGetSplitList (trans); n; n = n->next)
     {
+        Split *s = n->data;
         if (s != current_blank_split)
         {
             if (blank_split_account == xaccSplitGetAccount (s))
@@ -1129,7 +1128,6 @@ gnc_split_register_change_blank_split_ref (SplitRegister* reg, Split* split)
             else
                 other_split = s; // any other split
         }
-        i++;
     }
     // now change the saved blank split reference
     if (pref_split != NULL)

commit 8ccfc2b0e7708ae28f92a90c55b6805531d9e502
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Oct 13 21:00:18 2021 +0800

    Use g_object_set instead of g_object_set_property
    
    Don't need to allocate a GValue

diff --git a/gnucash/gnome-utils/gnc-plugin.c b/gnucash/gnome-utils/gnc-plugin.c
index 6173cbf16..217256515 100644
--- a/gnucash/gnome-utils/gnc-plugin.c
+++ b/gnucash/gnome-utils/gnc-plugin.c
@@ -283,18 +283,14 @@ gnc_plugin_update_actions (GtkActionGroup *action_group,
                            gboolean value)
 {
     GtkAction    *action;
-    GValue        gvalue = { 0 };
     gint          i;
 
-    g_value_init (&gvalue, G_TYPE_BOOLEAN);
-    g_value_set_boolean (&gvalue, value);
-
     for (i = 0; action_names[i]; i++)
     {
         action = gtk_action_group_get_action (action_group, action_names[i]);
         if (action)
         {
-            g_object_set_property (G_OBJECT(action), property_name, &gvalue);
+            g_object_set (G_OBJECT(action), property_name, value, NULL);
         }
         else
         {
@@ -303,7 +299,6 @@ gnc_plugin_update_actions (GtkActionGroup *action_group,
                       g_list_length(gtk_action_group_list_actions(action_group)));
         }
     }
-    g_value_unset (&gvalue);
 }
 
 
diff --git a/gnucash/gnome/gnc-plugin-page-owner-tree.c b/gnucash/gnome/gnc-plugin-page-owner-tree.c
index c6c578278..9c1563617 100644
--- a/gnucash/gnome/gnc-plugin-page-owner-tree.c
+++ b/gnucash/gnome/gnc-plugin-page-owner-tree.c
@@ -338,7 +338,6 @@ gnc_plugin_page_owner_tree_new (GncOwnerType owner_type)
 
     GtkActionGroup *action_group;
     GtkAction    *action;
-    GValue        gvalue = { 0 };
     gint          i;
 
     g_return_val_if_fail( (owner_type != GNC_OWNER_UNDEFINED)
@@ -365,15 +364,14 @@ gnc_plugin_page_owner_tree_new (GncOwnerType owner_type)
 
     /* Hide menu and toolbar items that are not relevant for the active owner list */
     action_group = gnc_plugin_page_get_action_group(GNC_PLUGIN_PAGE(plugin_page));
-    g_value_init (&gvalue, G_TYPE_BOOLEAN);
     for (i = 0; action_owners[i].action_name; i++)
     {
         action = gtk_action_group_get_action (action_group, action_owners[i].action_name);
-        g_value_set_boolean (&gvalue, (priv->owner_type == action_owners[i].owner_type) );
-        g_object_set_property (G_OBJECT(action), "visible", &gvalue);
+        g_object_set (G_OBJECT(action),
+                      "visible", (priv->owner_type == action_owners[i].owner_type),
+                      NULL);
     }
 
-    g_value_unset (&gvalue);
     LEAVE("new %s tree page %p", gncOwnerTypeToQofIdType(owner_type), plugin_page);
     return GNC_PLUGIN_PAGE(plugin_page);
 }

commit 0576626c9abfacf450bbbaa75c72dd073fdc526e
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Wed Oct 13 20:51:09 2021 +0800

    Use gtk_tree_model_get instead of gtk_tree_model_get_value
    
    This saves allocating and freeing a GValue.

diff --git a/gnucash/gnome-utils/gnc-currency-edit.c b/gnucash/gnome-utils/gnc-currency-edit.c
index 15aea6064..9261cca5a 100644
--- a/gnucash/gnome-utils/gnc-currency-edit.c
+++ b/gnucash/gnome-utils/gnc-currency-edit.c
@@ -402,11 +402,9 @@ gnc_commodity *
 gnc_currency_edit_get_currency (GNCCurrencyEdit *gce)
 {
     gnc_commodity *commodity;
-    const char *fullname;
     char *mnemonic, *name;
     GtkTreeModel *model;
     GtkTreeIter iter;
-    GValue value = { 0 };
 
     g_return_val_if_fail(gce != NULL, NULL);
     g_return_val_if_fail(GNC_IS_CURRENCY_EDIT(gce), NULL);
@@ -414,10 +412,7 @@ gnc_currency_edit_get_currency (GNCCurrencyEdit *gce)
     if (gtk_combo_box_get_active_iter(GTK_COMBO_BOX(gce), &iter))
     {
         model = gtk_combo_box_get_model(GTK_COMBO_BOX(gce));
-        gtk_tree_model_get_value(model, &iter, 0, &value);
-        fullname = g_value_get_string(&value);
-        mnemonic = g_strdup(fullname);
-        g_value_unset(&value);
+        gtk_tree_model_get (model, &iter, 0, &mnemonic, -1);
 
         name = strchr(mnemonic, ' ');
         if (name != NULL)
diff --git a/gnucash/gnome-utils/gnc-tree-model-budget.c b/gnucash/gnome-utils/gnc-tree-model-budget.c
index 2cddd653f..14be5f612 100644
--- a/gnucash/gnome-utils/gnc-tree-model-budget.c
+++ b/gnucash/gnome-utils/gnc-tree-model-budget.c
@@ -108,13 +108,9 @@ GncBudget *
 gnc_tree_model_budget_get_budget(GtkTreeModel *tm, GtkTreeIter *iter)
 {
     GncBudget *bgt;
-    GValue gv = { 0 };
     GncGUID *guid;
 
-    gtk_tree_model_get_value(tm, iter, BUDGET_GUID_COLUMN, &gv);
-    guid = (GncGUID *) g_value_get_pointer(&gv);
-    g_value_unset(&gv);
-
+    gtk_tree_model_get (tm, iter, BUDGET_GUID_COLUMN, &guid, -1);
     bgt = gnc_budget_lookup(guid, gnc_get_current_book());
     return bgt;
 }
@@ -123,7 +119,6 @@ gboolean
 gnc_tree_model_budget_get_iter_for_budget(GtkTreeModel *tm, GtkTreeIter *iter,
         GncBudget *bgt)
 {
-    GValue gv = { 0 };
     const GncGUID *guid1;
     GncGUID *guid2;
 
@@ -134,9 +129,7 @@ gnc_tree_model_budget_get_iter_for_budget(GtkTreeModel *tm, GtkTreeIter *iter,
         return FALSE;
     while (gtk_list_store_iter_is_valid(GTK_LIST_STORE(tm), iter))
     {
-        gtk_tree_model_get_value(tm, iter, BUDGET_GUID_COLUMN, &gv);
-        guid2 = (GncGUID *) g_value_get_pointer(&gv);
-        g_value_unset(&gv);
+        gtk_tree_model_get (tm, iter, BUDGET_GUID_COLUMN, &guid2, -1);
 
         if (guid_equal(guid1, guid2))
             return TRUE;
diff --git a/gnucash/gnome/business-gnome-utils.c b/gnucash/gnome/business-gnome-utils.c
index 4ece5af03..41c42fc52 100644
--- a/gnucash/gnome/business-gnome-utils.c
+++ b/gnucash/gnome/business-gnome-utils.c
@@ -579,7 +579,6 @@ gnc_simple_combo_get_value (GtkComboBox *cbox)
 {
     GtkTreeIter iter;
     GtkTreeModel *model;
-    GValue value = { 0 };
     gpointer retval;
 
     if (!cbox) return NULL;
@@ -587,9 +586,7 @@ gnc_simple_combo_get_value (GtkComboBox *cbox)
     model = gtk_combo_box_get_model (cbox);
     if (!gtk_combo_box_get_active_iter (cbox, &iter))
         return NULL;
-    gtk_tree_model_get_value (model, &iter, 1, &value);
-    retval = g_value_get_pointer (&value);
-    g_value_unset (&value);
+    gtk_tree_model_get (model, &iter, 1, &retval, -1);
     return retval;
 }
 
@@ -610,28 +607,25 @@ gnc_simple_combo_set_value (GtkComboBox *cbox, gpointer data)
 
     while (valid_iter)
     {
-        GValue value = { 0 };
+        gpointer ptr;
 
-        gtk_tree_model_get_value (model, &iter, 1, &value);
+        gtk_tree_model_get (model, &iter, 1, &ptr, -1);
         if (lsd && lsd->is_equal)    // A specific comparator function was set
         {
-            if ((lsd->is_equal)(g_value_get_pointer(&value), data))
+            if ((lsd->is_equal)(ptr, data))
             {
                 gtk_combo_box_set_active_iter (cbox, &iter);
-                g_value_unset (&value);
                 return;
             }
         }
         else    // No specific comparator function set, use generic pointer comparison instead
         {
-            if (g_value_get_pointer(&value) == data)
+            if (ptr == data)
             {
                 gtk_combo_box_set_active_iter (cbox, &iter);
-                g_value_unset (&value);
                 return;
             }
         }
-        g_value_unset (&value);
         valid_iter = gtk_tree_model_iter_next (model, &iter);
     }
 }
diff --git a/gnucash/gnome/dialog-lot-viewer.c b/gnucash/gnome/dialog-lot-viewer.c
index 7bd5ebcd0..929bdf36d 100644
--- a/gnucash/gnome/dialog-lot-viewer.c
+++ b/gnucash/gnome/dialog-lot-viewer.c
@@ -810,16 +810,13 @@ static void print_date (GtkTreeViewColumn *tree_column,
                         GtkTreeIter *iter,
                         gpointer data)
 {
-    GValue value = { 0 };
     time64 doc_date_time;
     gchar *doc_date_str = g_strdup (_("Open"));
     gint col = GPOINTER_TO_INT(data);
 
     g_return_if_fail (cell && iter && tree_model);
 
-    gtk_tree_model_get_value (tree_model, iter, col, &value);
-    doc_date_time = (time64) g_value_get_int64 (&value);
-    g_value_unset (&value);
+    gtk_tree_model_get (tree_model, iter, col, &doc_date_time, -1);
 
     if (doc_date_time != G_MAXINT64) /* assumes INT64_MAX represents an invalid date/time */
     {
diff --git a/gnucash/gnome/dialog-payment.c b/gnucash/gnome/dialog-payment.c
index 20bb58c50..fabbdedda 100644
--- a/gnucash/gnome/dialog-payment.c
+++ b/gnucash/gnome/dialog-payment.c
@@ -338,14 +338,11 @@ calculate_selected_total_helper (GtkTreeModel *model,
 {
     gnc_numeric *subtotal = (gnc_numeric*) data;
     gnc_numeric cur_val;
-    GValue value = { 0 };
     GNCLot *lot;
     Account *acct;
     gnc_commodity *currency;
 
-    gtk_tree_model_get_value (model, iter, 5, &value);
-    lot = (GNCLot *) g_value_get_pointer (&value);
-    g_value_unset (&value);
+    gtk_tree_model_get (model, iter, 5, &lot, -1);
 
     /* Find the amount's currency to determine the required precision */
     acct = gnc_lot_get_account (lot);
@@ -412,13 +409,10 @@ gnc_payment_dialog_highlight_documents (PaymentWindow *pw)
     {
         do
         {
-            GValue value = { 0 };
             GNCLot *lot;
             GList *li_node;
 
-            gtk_tree_model_get_value (model, &iter, 5, &value);
-            lot = (GNCLot *) g_value_get_pointer (&value);
-            g_value_unset (&value);
+            gtk_tree_model_get (model, &iter, 5, &lot, -1);
 
             if (!lot)
                 continue; /* Lot has been deleted behind our back... */
@@ -948,11 +942,8 @@ get_selected_lots (GtkTreeModel *model,
 {
     GList **return_list = data;
     GNCLot *lot;
-    GValue value = { 0 };
 
-    gtk_tree_model_get_value (model, iter, 5, &value);
-    lot = (GNCLot *) g_value_get_pointer (&value);
-    g_value_unset (&value);
+    gtk_tree_model_get (model, iter, 5, &lot, -1);
 
     if (lot)
         *return_list = g_list_insert_sorted (*return_list, lot, (GCompareFunc)gncOwnerLotsSortFunc);
@@ -1185,16 +1176,13 @@ static void print_date (G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
                         GtkTreeIter *iter,
                         G_GNUC_UNUSED gpointer data)
 {
-    GValue value = { 0 };
     time64 doc_date_time;
     gchar *doc_date_str;
 
     g_return_if_fail (cell && iter && tree_model);
 
 
-    gtk_tree_model_get_value (tree_model, iter, 0, &value);
-    doc_date_time = (time64) g_value_get_int64 (&value);
-    g_value_unset (&value);
+    gtk_tree_model_get (tree_model, iter, 0, &doc_date_time, -1);
     doc_date_str = qof_print_date (doc_date_time);
     g_object_set (G_OBJECT (cell), "text", doc_date_str, NULL);
     g_free (doc_date_str);



Summary of changes:
 gnucash/gnome-utils/gnc-currency-edit.c              |  7 +------
 gnucash/gnome-utils/gnc-plugin.c                     |  7 +------
 gnucash/gnome-utils/gnc-tree-model-budget.c          | 11 ++---------
 gnucash/gnome-utils/gnc-tree-view-split-reg.c        | 17 ++++++++---------
 gnucash/gnome/business-gnome-utils.c                 | 16 +++++-----------
 gnucash/gnome/dialog-lot-viewer.c                    |  5 +----
 gnucash/gnome/dialog-payment.c                       | 20 ++++----------------
 gnucash/gnome/gnc-plugin-page-owner-tree.c           |  8 +++-----
 .../register/ledger-core/split-register-control.c    | 13 ++++---------
 gnucash/register/ledger-core/split-register-load.c   |  7 ++-----
 gnucash/register/ledger-core/split-register.c        |  6 ++----
 11 files changed, 33 insertions(+), 84 deletions(-)



More information about the gnucash-changes mailing list