gnucash maint: Multiple changes pushed

Robert Fewell bobit at code.gnucash.org
Thu Jan 9 10:01:08 EST 2020


Updated	 via  https://github.com/Gnucash/gnucash/commit/c8eb3b37 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/5bfef54d (commit)
	 via  https://github.com/Gnucash/gnucash/commit/936e2bf3 (commit)
	from  https://github.com/Gnucash/gnucash/commit/3c6ad3ae (commit)



commit c8eb3b37380b9196718d29be759cfbda7e708b48
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Jan 9 14:59:53 2020 +0000

    Bug 797550 - Crash when changing register tab position
    
    Check for a valid GNC_MAIN_WINDOW being passed to
    gnc_main_window_update_tab_position before trying to update tabs

diff --git a/gnucash/gnome-utils/gnc-main-window.c b/gnucash/gnome-utils/gnc-main-window.c
index 3d85d7f1a..1372142d6 100644
--- a/gnucash/gnome-utils/gnc-main-window.c
+++ b/gnucash/gnome-utils/gnc-main-window.c
@@ -3285,6 +3285,8 @@ gnc_main_window_update_tab_position (gpointer prefs, gchar *pref, gpointer user_
     GtkPositionType position = GTK_POS_TOP;
     GncMainWindowPrivate *priv;
 
+    g_return_if_fail (GNC_IS_MAIN_WINDOW(user_data));
+
     window = GNC_MAIN_WINDOW(user_data);
 
     ENTER ("window %p", window);

commit 5bfef54d6d8ed99aa7ce6d13823f691b25f78dd6
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Jan 9 14:49:25 2020 +0000

    Change some spacing in source files account-quickfill.*

diff --git a/gnucash/gnome-utils/account-quickfill.c b/gnucash/gnome-utils/account-quickfill.c
index 9036c6b2e..b6ddccb81 100644
--- a/gnucash/gnome-utils/account-quickfill.c
+++ b/gnucash/gnome-utils/account-quickfill.c
@@ -31,8 +31,8 @@
 static QofLogModule log_module = GNC_MOD_REGISTER;
 
 static void shared_quickfill_pref_changed (gpointer prefs, gchar *pref, gpointer qfb);
-static void listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
-                                        gpointer user_data, gpointer event_data);
+static void listen_for_account_events (QofInstance *entity, QofEventId event_type,
+                                       gpointer user_data, gpointer event_data);
 
 /* Column indices for the list store */
 #define ACCOUNT_NAME        0
@@ -74,7 +74,7 @@ shared_quickfill_destroy (QofBook *book, gpointer key, gpointer user_data)
                                  shared_quickfill_pref_changed,
                                  qfb);
     gnc_quickfill_destroy (qfb->qf);
-    g_object_unref(qfb->list_store);
+    g_object_unref (qfb->list_store);
     qof_event_unregister_handler (qfb->listener);
     g_free (qfb);
 }
@@ -97,18 +97,17 @@ shared_quickfill_find_accounts (GtkTreeModel *model,
     GtkTreeRowReference* ref;
     GList *tmp;
 
-    gtk_tree_model_get(model, iter, ACCOUNT_POINTER, &account, -1);
-    for (tmp = data->accounts; tmp; tmp = g_list_next(tmp))
+    gtk_tree_model_get (model, iter, ACCOUNT_POINTER, &account, -1);
+    for (tmp = data->accounts; tmp; tmp = g_list_next (tmp))
     {
         if (tmp->data == account)
         {
-            ref = gtk_tree_row_reference_new(model, path);
-            data->refs = g_list_append(data->refs, ref);
-            data->accounts = g_list_remove_link(data->accounts, tmp);
+            ref = gtk_tree_row_reference_new (model, path);
+            data->refs = g_list_append (data->refs, ref);
+            data->accounts = g_list_remove_link (data->accounts, tmp);
             return (data->accounts == NULL);
         }
     }
-
     return FALSE;
 }
 
@@ -124,11 +123,13 @@ load_shared_qf_cb (Account *account, gpointer data)
     if (qfb->dont_add_cb)
     {
         gboolean skip = (qfb->dont_add_cb) (account, qfb->dont_add_data);
-        if (skip) return;
+        if (skip)
+            return;
     }
 
     name = gnc_get_account_name_for_register (account);
-    if (NULL == name) return;
+    if (NULL == name)
+        return;
     gnc_quickfill_insert (qfb->qf, name, QUICKFILL_ALPHA);
     if (qfb->load_list_store)
     {
@@ -138,7 +139,7 @@ load_shared_qf_cb (Account *account, gpointer data)
                             ACCOUNT_POINTER, account,
                             -1);
     }
-    g_free(name);
+    g_free (name);
 }
 
 
@@ -148,10 +149,10 @@ shared_quickfill_pref_changed (gpointer prefs, gchar *pref, gpointer user_data)
     QFB *qfb = user_data;
 
     /* Reload the quickfill */
-    gnc_quickfill_purge(qfb->qf);
-    gtk_list_store_clear(qfb->list_store);
+    gnc_quickfill_purge (qfb->qf);
+    gtk_list_store_clear (qfb->list_store);
     qfb->load_list_store = TRUE;
-    gnc_account_foreach_descendant(qfb->root, load_shared_qf_cb, qfb);
+    gnc_account_foreach_descendant (qfb->root, load_shared_qf_cb, qfb);
     qfb->load_list_store = FALSE;
 }
 
@@ -165,7 +166,7 @@ build_shared_quickfill (QofBook *book, Account *root, const char * key,
 {
     QFB *qfb;
 
-    qfb = g_new0(QFB, 1);
+    qfb = g_new0 (QFB, 1);
     qfb->qf = gnc_quickfill_new ();
     qfb->book = book;
     qfb->root = root;
@@ -173,8 +174,8 @@ build_shared_quickfill (QofBook *book, Account *root, const char * key,
     qfb->dont_add_cb = cb;
     qfb->dont_add_data = data;
     qfb->load_list_store = TRUE;
-    qfb->list_store =
-        gtk_list_store_new (NUM_ACCOUNT_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER);
+    qfb->list_store = gtk_list_store_new (NUM_ACCOUNT_COLUMNS,
+                                          G_TYPE_STRING, G_TYPE_POINTER);
 
     gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL,
                            GNC_PREF_ACCOUNT_SEPARATOR,
@@ -186,11 +187,10 @@ build_shared_quickfill (QofBook *book, Account *root, const char * key,
                            shared_quickfill_pref_changed,
                            qfb);
 
-    gnc_account_foreach_descendant(root, load_shared_qf_cb, qfb);
+    gnc_account_foreach_descendant (root, load_shared_qf_cb, qfb);
     qfb->load_list_store = FALSE;
 
-    qfb->listener =
-        qof_event_register_handler (listen_for_account_events, qfb);
+    qfb->listener = qof_event_register_handler (listen_for_account_events, qfb);
 
     qof_book_set_data_fin (book, key, qfb, shared_quickfill_destroy);
 
@@ -198,8 +198,7 @@ build_shared_quickfill (QofBook *book, Account *root, const char * key,
 }
 
 QuickFill *
-gnc_get_shared_account_name_quickfill (Account *root,
-                                       const char * key,
+gnc_get_shared_account_name_quickfill (Account *root, const char * key,
                                        AccountBoolCB cb, gpointer cb_data)
 {
     QFB *qfb;
@@ -208,15 +207,15 @@ gnc_get_shared_account_name_quickfill (Account *root,
     book = gnc_account_get_book (root);
     qfb = qof_book_get_data (book, key);
 
-    if (qfb) return qfb->qf;
+    if (qfb)
+        return qfb->qf;
 
     qfb = build_shared_quickfill (book, root, key, cb, cb_data);
     return qfb->qf;
 }
 
 GtkListStore *
-gnc_get_shared_account_name_list_store (Account *root,
-                                        const char * key,
+gnc_get_shared_account_name_list_store (Account *root, const char * key,
                                         AccountBoolCB cb, gpointer cb_data)
 {
     QFB *qfb;
@@ -225,7 +224,8 @@ gnc_get_shared_account_name_list_store (Account *root,
     book = gnc_account_get_book (root);
     qfb = qof_book_get_data (book, key);
 
-    if (qfb) return qfb->list_store;
+    if (qfb)
+        return qfb->list_store;
 
     qfb = build_shared_quickfill (book, root, key, cb, cb_data);
     return qfb->list_store;
@@ -236,8 +236,8 @@ gnc_get_shared_account_name_list_store (Account *root,
  * for account modification events, and add new accounts.
  */
 static void
-listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
-                            gpointer user_data, gpointer event_data)
+listen_for_account_events (QofInstance *entity, QofEventId event_type,
+                           gpointer user_data, gpointer event_data)
 {
     QFB *qfb = user_data;
     QuickFill *qf = qfb->qf;
@@ -253,9 +253,9 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
     if (0 == (event_type & (QOF_EVENT_MODIFY | QOF_EVENT_ADD | QOF_EVENT_REMOVE)))
         return;
 
-    if (!GNC_IS_ACCOUNT (entity))
+    if (!GNC_IS_ACCOUNT(entity))
         return;
-    account = GNC_ACCOUNT (entity);
+    account = GNC_ACCOUNT(entity);
 
     ENTER("entity %p, event type %x, user data %p, ecent data %p",
           entity, event_type, user_data, event_data);
@@ -266,7 +266,7 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
         return;
     }
 
-    name = gnc_get_account_name_for_register(account);
+    name = gnc_get_account_name_for_register (account);
     if (NULL == name)
     {
         LEAVE("account has no name");
@@ -280,33 +280,33 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
 
         /* Find the account (and all its descendants) in the model.  The
          * full name of all these accounts has changed. */
-        data.accounts = gnc_account_get_descendants(account);
-        data.accounts = g_list_prepend(data.accounts, account);
-        gtk_tree_model_foreach(GTK_TREE_MODEL(qfb->list_store),
-                               shared_quickfill_find_accounts, &data);
+        data.accounts = gnc_account_get_descendants (account);
+        data.accounts = g_list_prepend (data.accounts, account);
+        gtk_tree_model_foreach (GTK_TREE_MODEL(qfb->list_store),
+                                shared_quickfill_find_accounts, &data);
 
         /* Update the existing items in the list store.  Its possible
          * that the change has caused an existing item to now become
          * hidden, in which case it needs to be removed from the list
          * store.  Otherwise its a simple update of the name string. */
-        for (tmp = data.refs; tmp; tmp = g_list_next(tmp))
+        for (tmp = data.refs; tmp; tmp = g_list_next (tmp))
         {
             gchar *old_name, *new_name;
-            path = gtk_tree_row_reference_get_path(tmp->data);
-            gtk_tree_row_reference_free(tmp->data);
-            if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(qfb->list_store),
-                                         &iter, path))
+            path = gtk_tree_row_reference_get_path (tmp->data);
+            gtk_tree_row_reference_free (tmp->data);
+            if (!gtk_tree_model_get_iter (GTK_TREE_MODEL(qfb->list_store),
+                                          &iter, path))
             {
-                gtk_tree_path_free(path);
+                gtk_tree_path_free (path);
                 continue;
             }
-            gtk_tree_path_free(path);
-            gtk_tree_model_get(GTK_TREE_MODEL(qfb->list_store), &iter,
-                               ACCOUNT_POINTER, &account,
-                               ACCOUNT_NAME, &old_name,
-                               -1);
+            gtk_tree_path_free (path);
+            gtk_tree_model_get (GTK_TREE_MODEL(qfb->list_store), &iter,
+                                ACCOUNT_POINTER, &account,
+                                ACCOUNT_NAME, &old_name,
+                                -1);
 
-            new_name = gnc_get_account_name_for_register(account);
+            new_name = gnc_get_account_name_for_register (account);
 
             /* check if the name has changed */
             match = gnc_quickfill_get_string_match (qf, old_name);
@@ -314,17 +314,17 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
                 gnc_quickfill_remove (qf, old_name, QUICKFILL_ALPHA);
 
             if (qfb->dont_add_cb &&
-                    qfb->dont_add_cb(account, qfb->dont_add_data))
+                    qfb->dont_add_cb (account, qfb->dont_add_data))
             {
                 gnc_quickfill_remove (qf, new_name, QUICKFILL_ALPHA);
-                gtk_list_store_remove(qfb->list_store, &iter);
+                gtk_list_store_remove (qfb->list_store, &iter);
             }
             else
             {
                 gnc_quickfill_insert (qf, new_name, QUICKFILL_ALPHA);
-                gtk_list_store_set(qfb->list_store, &iter,
-                                   ACCOUNT_NAME, new_name,
-                                   -1);
+                gtk_list_store_set (qfb->list_store, &iter,
+                                    ACCOUNT_NAME, new_name,
+                                    -1);
             }
             g_free (old_name);
             g_free (new_name);
@@ -333,12 +333,12 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
         /* Any accounts that weren't found in the tree are accounts that
          * were hidden but have now become visible. Add them to the list
          * store. */
-        for (tmp = data.accounts; tmp; tmp = g_list_next(tmp))
+        for (tmp = data.accounts; tmp; tmp = g_list_next (tmp))
         {
             account = tmp->data;
             if (qfb->dont_add_cb)
             {
-                if (qfb->dont_add_cb(account, qfb->dont_add_data))
+                if (qfb->dont_add_cb (account, qfb->dont_add_data))
                 {
                     continue;
                 }
@@ -356,24 +356,24 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
         DEBUG("remove %s", name);
 
         /* Remove from qf */
-        gnc_quickfill_remove(qfb->qf, name, QUICKFILL_ALPHA);
+        gnc_quickfill_remove (qfb->qf, name, QUICKFILL_ALPHA);
 
         /* Does the account exist in the model? */
-        data.accounts = g_list_append(NULL, account);
-        gtk_tree_model_foreach(GTK_TREE_MODEL(qfb->list_store),
-                               shared_quickfill_find_accounts, &data);
+        data.accounts = g_list_append (NULL, account);
+        gtk_tree_model_foreach (GTK_TREE_MODEL(qfb->list_store),
+                                shared_quickfill_find_accounts, &data);
 
         /* Remove from list store */
-        for (tmp = data.refs; tmp; tmp = g_list_next(tmp))
+        for (tmp = data.refs; tmp; tmp = g_list_next (tmp))
         {
             path = gtk_tree_row_reference_get_path (tmp->data);
             gtk_tree_row_reference_free (tmp->data);
-            if (gtk_tree_model_get_iter(GTK_TREE_MODEL(qfb->list_store),
-                                        &iter, path))
+            if (gtk_tree_model_get_iter (GTK_TREE_MODEL(qfb->list_store),
+                                         &iter, path))
             {
-                gtk_list_store_remove(qfb->list_store, &iter);
+                gtk_list_store_remove (qfb->list_store, &iter);
             }
-            gtk_tree_path_free(path);
+            gtk_tree_path_free (path);
         }
         break;
 
@@ -381,14 +381,14 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
         DEBUG("add %s", name);
 
         if (qfb->dont_add_cb &&
-                qfb->dont_add_cb(account, qfb->dont_add_data))
+                qfb->dont_add_cb (account, qfb->dont_add_data))
             break;
 
         match = gnc_quickfill_get_string_match (qf, name);
         if (match)
         {
             match_str = gnc_quickfill_string (match);
-            if (match_str && (g_strcmp0(match_str, name) != 0))
+            if (match_str && (g_strcmp0 (match_str, name) != 0))
             {
                 PINFO ("got match for %s", name);
                 break;
@@ -410,10 +410,10 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
     }
 
     if (data.accounts)
-        g_list_free(data.accounts);
+        g_list_free (data.accounts);
     if (data.refs)
-        g_list_free(data.refs);
-    g_free(name);
+        g_list_free (data.refs);
+    g_free (name);
     LEAVE(" ");
 }
 
diff --git a/gnucash/gnome-utils/account-quickfill.h b/gnucash/gnome-utils/account-quickfill.h
index 0a0ef8003..a9a280acd 100644
--- a/gnucash/gnome-utils/account-quickfill.h
+++ b/gnucash/gnome-utils/account-quickfill.h
@@ -68,13 +68,11 @@ typedef gboolean (*AccountBoolCB) (Account *, gpointer);
  *  it).  This code does not currently listen to account-destroy
  *  events.
  */
-QuickFill * gnc_get_shared_account_name_quickfill (Account *root,
-        const char * key,
-        AccountBoolCB skip_cb,
-        gpointer cb_data);
+QuickFill *
+gnc_get_shared_account_name_quickfill (Account *root, const char * key,
+                                       AccountBoolCB skip_cb, gpointer cb_data);
 GtkListStore *
-gnc_get_shared_account_name_list_store (Account *root,
-                                        const char * key,
+gnc_get_shared_account_name_list_store (Account *root, const char * key,
                                         AccountBoolCB cb, gpointer cb_data);
 
 #endif

commit 936e2bf3713c481250e123a4f1724b821337739e
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Thu Jan 9 14:47:43 2020 +0000

    Bug 797546 - Autocomplete not updated when account names changed
    
    If an account name is changed, the autocomplete list store was updated
    but the hash table was not so this change checks for the name change
    and updates the hash table. Also fixed was changing the account from /
    to a placeholder account which will show or hide the account.

diff --git a/gnucash/gnome-utils/account-quickfill.c b/gnucash/gnome-utils/account-quickfill.c
index 729ce39cc..9036c6b2e 100644
--- a/gnucash/gnome-utils/account-quickfill.c
+++ b/gnucash/gnome-utils/account-quickfill.c
@@ -291,6 +291,7 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
          * store.  Otherwise its a simple update of the name string. */
         for (tmp = data.refs; tmp; tmp = g_list_next(tmp))
         {
+            gchar *old_name, *new_name;
             path = gtk_tree_row_reference_get_path(tmp->data);
             gtk_tree_row_reference_free(tmp->data);
             if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(qfb->list_store),
@@ -302,20 +303,31 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
             gtk_tree_path_free(path);
             gtk_tree_model_get(GTK_TREE_MODEL(qfb->list_store), &iter,
                                ACCOUNT_POINTER, &account,
+                               ACCOUNT_NAME, &old_name,
                                -1);
+
+            new_name = gnc_get_account_name_for_register(account);
+
+            /* check if the name has changed */
+            match = gnc_quickfill_get_string_match (qf, old_name);
+            if (match && (g_strcmp0 (old_name, new_name) != 0))
+                gnc_quickfill_remove (qf, old_name, QUICKFILL_ALPHA);
+
             if (qfb->dont_add_cb &&
                     qfb->dont_add_cb(account, qfb->dont_add_data))
             {
+                gnc_quickfill_remove (qf, new_name, QUICKFILL_ALPHA);
                 gtk_list_store_remove(qfb->list_store, &iter);
             }
             else
             {
-                gchar *aname = gnc_get_account_name_for_register(account);
+                gnc_quickfill_insert (qf, new_name, QUICKFILL_ALPHA);
                 gtk_list_store_set(qfb->list_store, &iter,
-                                   ACCOUNT_NAME, aname,
+                                   ACCOUNT_NAME, new_name,
                                    -1);
-                g_free(aname);
             }
+            g_free (old_name);
+            g_free (new_name);
         }
 
         /* Any accounts that weren't found in the tree are accounts that
@@ -331,6 +343,7 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
                     continue;
                 }
             }
+            gnc_quickfill_insert (qf, name, QUICKFILL_ALPHA);
             gtk_list_store_append (qfb->list_store, &iter);
             gtk_list_store_set (qfb->list_store, &iter,
                                 ACCOUNT_NAME, name,
@@ -366,6 +379,7 @@ listen_for_account_events  (QofInstance *entity,  QofEventId event_type,
 
     case QOF_EVENT_ADD:
         DEBUG("add %s", name);
+
         if (qfb->dont_add_cb &&
                 qfb->dont_add_cb(account, qfb->dont_add_data))
             break;



Summary of changes:
 gnucash/gnome-utils/account-quickfill.c | 152 +++++++++++++++++---------------
 gnucash/gnome-utils/account-quickfill.h |  10 +--
 gnucash/gnome-utils/gnc-main-window.c   |   2 +
 3 files changed, 89 insertions(+), 75 deletions(-)



More information about the gnucash-changes mailing list