gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Mon Dec 7 14:55:18 EST 2015


Updated	 via  https://github.com/Gnucash/gnucash/commit/2a0bb45f (commit)
	 via  https://github.com/Gnucash/gnucash/commit/7788b710 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/16288403 (commit)
	from  https://github.com/Gnucash/gnucash/commit/3a9825f8 (commit)



commit 2a0bb45f935a4e64eb6f9ee97858e0c5181e3e1f
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Mon Dec 7 20:54:44 2015 +0100

    Slight logic cleanup in previous commit
    
    GNC_RESPONSE_NEW case falls through to GTK_RESPONSE_OK so avoid doing thing twice

diff --git a/src/import-export/import-account-matcher.c b/src/import-export/import-account-matcher.c
index 8844f90..fe17bd9 100644
--- a/src/import-export/import-account-matcher.c
+++ b/src/import-export/import-account-matcher.c
@@ -344,18 +344,16 @@ Account * gnc_import_select_account(GtkWidget *parent,
             {
             case GNC_RESPONSE_NEW:
                 gnc_import_add_account(NULL, picker);
-                retval = gnc_tree_view_account_get_selected_account(picker->account_tree);
+                response = GTK_RESPONSE_OK;
+                /* no break */
 
+            case GTK_RESPONSE_OK:
+                retval = gnc_tree_view_account_get_selected_account(picker->account_tree);
                 if (retval == NULL)
                 {
                     response = GNC_RESPONSE_NEW;
                     break;
                 }
-                response = GTK_RESPONSE_OK;
-                ok_pressed_retval = TRUE;
-
-            case GTK_RESPONSE_OK:
-                retval = gnc_tree_view_account_get_selected_account(picker->account_tree);
                 if (retval)
                     retval_name = xaccAccountGetName(retval);
                 if (!retval_name)

commit 7788b71041a451f2e50e0fb54f1c1fdd3b78741c
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Dec 6 11:50:34 2015 +0000

    Bug 706021 Test match text for valid account path
    
    Test the match text for a valid account path and use that or create
    an alternative so there is only one call to the new account dialog.

diff --git a/src/import-export/csv-imp/assistant-csv-trans-import.c b/src/import-export/csv-imp/assistant-csv-trans-import.c
index d65677b..1e44ddb 100644
--- a/src/import-export/csv-imp/assistant-csv-trans-import.c
+++ b/src/import-export/csv-imp/assistant-csv-trans-import.c
@@ -2299,6 +2299,90 @@ import_account_check_all (GtkTreeModel *model)
 }
 
 
+/*****************************************************************
+ * Parse the text spliting into a path and the last_part based on
+ * account separator. If the path is valid, add the last_part and
+ * return this. If the path is invalid, use the new separator path
+ * with the last_part and return that so there is only one new
+ * account dialog.
+ *****************************************************************/
+static gchar *
+import_account_text_parse (gchar *text)
+{
+    QofBook     *book;
+    const gchar *sep;
+    const gchar *newsep;
+    gchar      **names;
+    gchar      **ptr = NULL;
+    gint         i, count = 0;
+    gchar       *ret_string, *last_part = NULL;;
+
+    // Get the book
+    book = gnc_get_current_book ();
+    sep = gnc_get_account_separator_string ();
+
+    // Setup an alternative separator
+    if (g_strcmp0 (sep,":") == 0)
+        newsep = "-";
+    else
+        newsep = ":";
+
+    // Split the incoming string by current separator
+    names = g_strsplit (text, sep, -1);
+
+    /* find the last_part and count parts */
+    for (ptr = names; *ptr; ptr++)
+    {
+        if (g_strcmp0 (*ptr,"") != 0) //separator is last in string
+        {
+            g_free (last_part);
+            last_part = g_strdup (*ptr);
+            count = count + 1;
+        }
+    }
+
+    // If count is 1 we have no path
+    if (count == 1)
+        ret_string = g_strdup (last_part);
+    else
+    {
+        Account   *account;
+        gchar     *sep_path, *newsep_path;
+
+        // Start to create two paths based on current and possibly new separator
+        sep_path = g_strdup (names[0]);
+        newsep_path = g_strdup (names[0]);
+
+        // Join the parts together apart from last_part which could be account name
+        for (i = 1; i < count - 1; i++)
+        {
+            gchar *temp_sep_path, *temp_newsep_path;
+
+            temp_sep_path = g_strdup (sep_path);
+            temp_newsep_path = g_strdup (newsep_path);
+            g_free (sep_path);
+            g_free (newsep_path);
+            sep_path = g_strconcat (temp_sep_path, sep, names[i], NULL);
+            newsep_path = g_strconcat (temp_newsep_path, newsep, names[i], NULL);
+            g_free (temp_sep_path);
+            g_free (temp_newsep_path);
+        }
+        account = gnc_account_lookup_by_full_name (gnc_book_get_root_account (book), sep_path);
+
+        if (account == NULL) // path not found
+            ret_string = g_strconcat (newsep_path, newsep, last_part, NULL);
+        else
+            ret_string = g_strconcat (sep_path, sep, last_part, NULL);
+
+        g_free (sep_path);
+        g_free (newsep_path);
+    }
+    g_free (last_part);
+    g_strfreev (names);
+    return ret_string;
+}
+
+
 static void
 import_account_select_cb (GtkWidget *widget, gpointer user_data)
 {
@@ -2315,7 +2399,7 @@ import_account_select_cb (GtkWidget *widget, gpointer user_data)
     {
         Account *gnc_acc = NULL, *account = NULL;
         gchar *text = NULL;
-        gchar *fullpath = NULL;
+        gchar *parsed_text = NULL;
 
         // Get the the String
         gtk_tree_model_get (model, &iter, MAPPING_STRING, &text, -1);
@@ -2323,18 +2407,26 @@ import_account_select_cb (GtkWidget *widget, gpointer user_data)
         // Get the pointer to the Account
         gtk_tree_model_get (model, &iter, MAPPING_ACCOUNT, &account, -1);
 
-        gnc_acc = gnc_import_select_account (NULL, NULL, 1, text, NULL, ACCT_TYPE_NONE, account, NULL);
+        parsed_text = import_account_text_parse (text);
 
-        gtk_list_store_set (GTK_LIST_STORE(model), &iter, MAPPING_ACCOUNT, gnc_acc, -1);
+        gnc_acc = gnc_import_select_account (NULL, NULL, 1, parsed_text, NULL, ACCT_TYPE_NONE, account, NULL);
 
-        fullpath = gnc_account_get_full_name (gnc_acc);
-        gtk_list_store_set (GTK_LIST_STORE(model), &iter, MAPPING_FULLPATH, fullpath, -1);
+        if (gnc_acc != NULL) // We may of canceled
+        {
+            gchar *fullpath = NULL;
 
-        // Update the account kvp mappings
-        gnc_csv_account_map_change_mappings (account, gnc_acc, text);
+            gtk_list_store_set (GTK_LIST_STORE(model), &iter, MAPPING_ACCOUNT, gnc_acc, -1);
 
+            fullpath = gnc_account_get_full_name (gnc_acc);
+            gtk_list_store_set (GTK_LIST_STORE(model), &iter, MAPPING_FULLPATH, fullpath, -1);
+
+            // Update the account kvp mappings
+            gnc_csv_account_map_change_mappings (account, gnc_acc, text);
+
+            g_free (fullpath);
+        }
         g_free (text);
-        g_free (fullpath);
+        g_free (parsed_text);
     }
     if (import_account_check_all (model))
         gtk_assistant_set_page_complete (GTK_ASSISTANT(info->window), info->account_match_page, TRUE);
@@ -2371,7 +2463,7 @@ import_account_button_cb (GtkWidget *widget, GdkEventButton *event, gpointer use
             {
                 Account *gnc_acc = NULL, *account = NULL;
                 gchar *text = NULL;
-                gchar *fullpath = NULL;
+                gchar *parsed_text = NULL;
 
                 // Get the the String
                 gtk_tree_model_get (model, &iter, MAPPING_STRING, &text, -1);
@@ -2379,18 +2471,26 @@ import_account_button_cb (GtkWidget *widget, GdkEventButton *event, gpointer use
                 // Get the pointer to the Account
                 gtk_tree_model_get (model, &iter, MAPPING_ACCOUNT, &account, -1);
 
-                gnc_acc = gnc_import_select_account (NULL, NULL, 1, text, NULL, ACCT_TYPE_NONE, account, NULL);
+                parsed_text = import_account_text_parse (text);
 
-                gtk_list_store_set (GTK_LIST_STORE(model), &iter, MAPPING_ACCOUNT, gnc_acc, -1);
+                gnc_acc = gnc_import_select_account (NULL, NULL, 1, parsed_text, NULL, ACCT_TYPE_NONE, account, NULL);
 
-                fullpath = gnc_account_get_full_name (gnc_acc);
-                gtk_list_store_set (GTK_LIST_STORE(model), &iter, MAPPING_FULLPATH, fullpath, -1);
+                if (gnc_acc != NULL) // We may of canceled
+                {
+                    gchar *fullpath = NULL;
 
-                // Update the account kvp mappings
-                gnc_csv_account_map_change_mappings (account, gnc_acc, text);
+                    gtk_list_store_set (GTK_LIST_STORE(model), &iter, MAPPING_ACCOUNT, gnc_acc, -1);
 
+                    fullpath = gnc_account_get_full_name (gnc_acc);
+                    gtk_list_store_set (GTK_LIST_STORE(model), &iter, MAPPING_FULLPATH, fullpath, -1);
+
+                    // Update the account kvp mappings
+                    gnc_csv_account_map_change_mappings (account, gnc_acc, text);
+
+                    g_free (fullpath);
+                }
                 g_free (text);
-                g_free (fullpath);
+                g_free (parsed_text);
             }
             gtk_tree_path_free (path);
         }

commit 1628840314ab7b8bae04f18e5229a7574b1451d2
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sun Dec 6 11:44:20 2015 +0000

    Bug 706021 Change Account Matcher New Account Button
    
    This change allows the account matcher dialog to be closed
    automatically after a new account is created.

diff --git a/src/import-export/import-account-matcher.c b/src/import-export/import-account-matcher.c
index b12a4f4..8844f90 100644
--- a/src/import-export/import-account-matcher.c
+++ b/src/import-export/import-account-matcher.c
@@ -342,6 +342,18 @@ Account * gnc_import_select_account(GtkWidget *parent,
             response = gtk_dialog_run(GTK_DIALOG(picker->dialog));
             switch (response)
             {
+            case GNC_RESPONSE_NEW:
+                gnc_import_add_account(NULL, picker);
+                retval = gnc_tree_view_account_get_selected_account(picker->account_tree);
+
+                if (retval == NULL)
+                {
+                    response = GNC_RESPONSE_NEW;
+                    break;
+                }
+                response = GTK_RESPONSE_OK;
+                ok_pressed_retval = TRUE;
+
             case GTK_RESPONSE_OK:
                 retval = gnc_tree_view_account_get_selected_account(picker->account_tree);
                 if (retval)
@@ -368,10 +380,7 @@ Account * gnc_import_select_account(GtkWidget *parent,
                 }
                 ok_pressed_retval = TRUE;
                 break;
-            case GNC_RESPONSE_NEW:
-                gnc_import_add_account(NULL, picker);
-                ok_pressed_retval = TRUE;
-                break;
+
             default:
                 ok_pressed_retval = FALSE;
                 break;



Summary of changes:
 .../csv-imp/assistant-csv-trans-import.c           | 132 ++++++++++++++++++---
 src/import-export/import-account-matcher.c         |  15 ++-
 2 files changed, 127 insertions(+), 20 deletions(-)



More information about the gnucash-changes mailing list