gnucash master: Multiple changes pushed

Geert Janssens gjanssens at code.gnucash.org
Tue Nov 3 11:16:06 EST 2015


Updated	 via  https://github.com/Gnucash/gnucash/commit/d0fee729 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1ef201c7 (commit)
	from  https://github.com/Gnucash/gnucash/commit/ad2c36e5 (commit)



commit d0fee72900860869b7f14d2d55305fd67944efba
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Sat Oct 17 12:03:05 2015 +0100

    Bug 706021 New CSV Import Account Mappings.
    
    This patch allows the saving of account name mappings
    so these can be reused in later imports.

diff --git a/src/import-export/csv-imp/Makefile.am b/src/import-export/csv-imp/Makefile.am
index dcfe311..d2359f3 100644
--- a/src/import-export/csv-imp/Makefile.am
+++ b/src/import-export/csv-imp/Makefile.am
@@ -10,6 +10,7 @@ libgncmod_csv_import_la_SOURCES = \
   gnc-plugin-csv-import.c \
   csv-account-import.c \
   csv-fixed-trans-import.c \
+  gnc-csv-account-map.c \
   gnc-csv-model.c \
   gnc-csv-gnumeric-popup.c \
   gnc-csv-trans-settings.c
@@ -21,6 +22,7 @@ noinst_HEADERS = \
   gnc-plugin-csv-import.h \
   csv-account-import.h \
   csv-fixed-trans-import.h \
+  gnc-csv-account-map.h \
   gnc-csv-model.h \
   gnc-csv-gnumeric-popup.h \
   gnc-csv-trans-settings.h
diff --git a/src/import-export/csv-imp/gnc-csv-account-map.c b/src/import-export/csv-imp/gnc-csv-account-map.c
new file mode 100644
index 0000000..e53fffe
--- /dev/null
+++ b/src/import-export/csv-imp/gnc-csv-account-map.c
@@ -0,0 +1,167 @@
+/*******************************************************************\
+ * gnc-csv-account-map.c -- Load and Update Mappings                *
+ *                                                                  *
+ * Copyright (C) 2015 Robert Fewell                                 *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+/** @file gnc-csv-account-map.c
+    @brief Save and Load Mappings
+    @author Copyright (c) 2015 Robert Fewell
+*/
+#include "config.h"
+
+#include <gtk/gtk.h>
+#include <glib/gi18n.h>
+
+#include "qof.h"
+#include "gnc-ui-util.h"
+#include "gnc-csv-account-map.h"
+
+#define CSV_CATEGORY         "csv-account-map"
+
+#define IMPORT_STRING        "String"
+#define IMPORT_FULL_PATH     "FullPath"
+#define IMPORT_ACCOUNT       "Account"
+
+/* This static indicates the debugging module that this .o belongs to.  */
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+/**************************************************
+ * account_imap_destroy
+ *
+ * Destroy an import map. But all stored entries will
+ * still continue to exist in the underlying kvp frame
+ * of the account.
+ **************************************************/
+static void
+account_imap_destroy (GncImportMatchMap *imap)
+{
+    if (!imap) return;
+    g_free (imap);
+}
+
+/**************************************************
+ * gnc_csv_account_map_search
+ *
+ * search the existing mappings for the account
+ * linked to the import string.
+ **************************************************/
+Account * gnc_csv_account_map_search (gchar *map_string)
+{
+    Account *root, *account = NULL;
+    GList   *accts, *ptr;
+
+    /* Get list of Accounts */
+    root = gnc_book_get_root_account (gnc_get_current_book());
+    accts = gnc_account_get_descendants_sorted (root);
+
+    /* Go through list of accounts */
+    for (ptr = accts; ptr; ptr = g_list_next (ptr))
+    {
+        GncImportMatchMap *tmp_imap;
+
+        tmp_imap = gnc_account_imap_create_imap (ptr->data);
+
+        if (gnc_account_imap_find_account (tmp_imap, CSV_CATEGORY, map_string) != NULL)
+        {
+            account = ptr->data;
+            account_imap_destroy (tmp_imap);
+            break;
+        }
+        account_imap_destroy (tmp_imap);
+    }
+    g_list_free (accts);
+
+    return account;
+}
+
+
+/**************************************************
+ * gnc_csv_account_map_load_mappings
+ *
+ * load the existing mappings
+ **************************************************/
+void
+gnc_csv_account_map_load_mappings (GtkTreeModel *mappings_store)
+{
+    GtkTreeIter iter;
+    gboolean    valid;
+
+    // Set iter to first entry of store
+    valid = gtk_tree_model_get_iter_first (mappings_store, &iter);
+
+    // Walk through the store trying to match to a map
+    while (valid)
+    {
+        Account *account = NULL;
+        gchar   *map_string;
+        gchar   *fullpath;
+
+        // Walk through the list, reading each row
+        gtk_tree_model_get (GTK_TREE_MODEL(mappings_store), &iter, MAPPING_STRING, &map_string, MAPPING_ACCOUNT, &account, -1);
+
+        if (account == NULL) // if account is NULL, store has not been updated
+        {
+            account = gnc_csv_account_map_search (map_string); //search the account list for the map_string
+
+            if (account == NULL) // account still NULL, we have no map
+            {
+                g_free (map_string);
+                valid = gtk_tree_model_iter_next (mappings_store, &iter);
+                continue;
+            }
+        }
+        fullpath = gnc_account_get_full_name (account);
+        gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_FULLPATH, fullpath, -1);
+        gtk_list_store_set (GTK_LIST_STORE(mappings_store), &iter, MAPPING_ACCOUNT, account, -1);
+        g_free (fullpath);
+
+        g_free (map_string);
+        valid = gtk_tree_model_iter_next (mappings_store, &iter);
+    }
+}
+
+
+/**************************************************
+ * gnc_csv_account_map_change_mappings
+ *
+ * change the existing mappings
+ **************************************************/
+void
+gnc_csv_account_map_change_mappings (Account *old_account, Account *new_account, gchar *map_string)
+{
+    GncImportMatchMap *tmp_imap;
+
+    if (strlen (map_string) == 0)
+        return;
+
+    if (old_account != NULL)
+    {
+        tmp_imap = gnc_account_imap_create_imap (old_account);
+        gnc_account_imap_delete_account (tmp_imap, CSV_CATEGORY, map_string);
+        account_imap_destroy (tmp_imap);
+    }
+
+    if (new_account != NULL)
+    {
+        tmp_imap = gnc_account_imap_create_imap (new_account);
+	gnc_account_imap_add_account (tmp_imap, CSV_CATEGORY, map_string, new_account);
+        account_imap_destroy (tmp_imap);
+    }
+}
diff --git a/src/import-export/csv-imp/gnc-csv-account-map.h b/src/import-export/csv-imp/gnc-csv-account-map.h
new file mode 100644
index 0000000..217b07b
--- /dev/null
+++ b/src/import-export/csv-imp/gnc-csv-account-map.h
@@ -0,0 +1,51 @@
+/*******************************************************************\
+ * gnc-csv-account-map.h   -- Load and Update Mappings              *
+ *                                                                  *
+ * Copyright (C) 2015 Robert Fewell                                 *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, contact:                        *
+ *                                                                  *
+ * Free Software Foundation           Voice:  +1-617-542-5942       *
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org                   *
+\********************************************************************/
+/** @file gnc-csv-account-map.h
+    @brief Save and Load Mappings
+    @author Copyright (c) 2015 Robert Fewell
+*/
+#ifndef GNC_CSV_ACCOUNT_MAP_H
+#define GNC_CSV_ACCOUNT_MAP_H
+
+#include "Account.h"
+
+/** Enumeration for the mappings liststore */
+enum GncImportColumn {MAPPING_STRING, MAPPING_FULLPATH, MAPPING_ACCOUNT};
+
+/** Load the import mappings.
+ *
+ */
+void gnc_csv_account_map_load_mappings (GtkTreeModel *mappings_store);
+
+/** Update the import mappings.
+ *
+ */
+void gnc_csv_account_map_change_mappings (Account *old_account, Account *new_account, gchar *map_string);
+
+/** Returns a pointer to the account that matches the import string.
+ *
+ * @return A pointer to an account.
+ */
+Account * gnc_csv_account_map_search (gchar *map_string);
+
+#endif

commit 1ef201c7d1544c12bf15b3dbd45a108dc1edfb72
Author: Robert Fewell <14uBobIT at gmail.com>
Date:   Fri Oct 16 20:13:30 2015 +0100

    Bug 706021 Rename and Move Imap functions.
    
    This patch renames the Imap functions in Account.c and
    adds them to the .h file to make accessible. Also added
    a delete function to the non Baysian functions along with
    a test.

diff --git a/src/engine/Account.c b/src/engine/Account.c
index f0f774d..70b2952 100644
--- a/src/engine/Account.c
+++ b/src/engine/Account.c
@@ -5028,26 +5028,12 @@ xaccAccountForEachTransaction(const Account *acc, TransactionCallback proc,
  * matching data. See src/import-export/import-backend.c for explanations.
  */
 
-typedef struct _GncImportMatchMap
-{
-    Account *   acc;
-    QofBook *   book;
-} GncImportMatchMap;
-
 #define IMAP_FRAME              "import-map"
 #define IMAP_FRAME_BAYES        "import-map-bayes"
-GncImportMatchMap * gnc_account_create_imap (Account *acc);
-Account* gnc_imap_find_account(GncImportMatchMap *imap, const char* category,
-                               const char *key);
-void gnc_imap_add_account (GncImportMatchMap *imap, const char *category,
-                           const char *key, Account *acc);
-Account* gnc_imap_find_account_bayes (GncImportMatchMap *imap, GList* tokens);
-void gnc_imap_add_account_bayes (GncImportMatchMap *imap, GList* tokens,
-                                 Account *acc);
 
 /* Obtain an ImportMatchMap object from an Account or a Book */
 GncImportMatchMap *
-gnc_account_create_imap (Account *acc)
+gnc_account_imap_create_imap (Account *acc)
 {
     GncImportMatchMap *imap;
 
@@ -5066,9 +5052,9 @@ gnc_account_create_imap (Account *acc)
 
 /* Look up an Account in the map */
 Account*
-gnc_imap_find_account (GncImportMatchMap *imap,
-                       const char *category,
-                       const char *key)
+gnc_account_imap_find_account (GncImportMatchMap *imap,
+                               const char *category,
+                               const char *key)
 {
     GValue v = G_VALUE_INIT;
     GncGUID * guid = NULL;
@@ -5088,10 +5074,10 @@ gnc_imap_find_account (GncImportMatchMap *imap,
 
 /* Store an Account in the map */
 void
-gnc_imap_add_account (GncImportMatchMap *imap,
-                      const char *category,
-                      const char *key,
-                      Account *acc)
+gnc_account_imap_add_account (GncImportMatchMap *imap,
+                              const char *category,
+                              const char *key,
+                              Account *acc)
 {
     GValue v = G_VALUE_INIT;
     char *kvp_path;
@@ -5111,6 +5097,39 @@ gnc_imap_add_account (GncImportMatchMap *imap,
     xaccAccountCommitEdit (imap->acc);
 }
 
+/* Remove a reference to an Account in the map */
+void
+gnc_account_imap_delete_account (GncImportMatchMap *imap,
+                                 const char *category,
+                                 const char *key)
+{
+    char *kvp_path;
+
+    if (!imap || !key) return;
+    if (!category)
+        kvp_path = g_strdup_printf (IMAP_FRAME "/%s", key);
+    else
+        kvp_path = g_strdup_printf (IMAP_FRAME "/%s/%s", category, key);
+
+    xaccAccountBeginEdit (imap->acc);
+
+    if (qof_instance_has_slot (QOF_INSTANCE (imap->acc), kvp_path))
+    {
+        qof_instance_slot_delete (QOF_INSTANCE (imap->acc), kvp_path);
+        g_free (kvp_path);
+
+        if (category)
+        {
+            kvp_path = g_strdup_printf (IMAP_FRAME "/%s", category);
+            qof_instance_slot_delete_if_empty (QOF_INSTANCE (imap->acc), kvp_path);
+            g_free (kvp_path);
+        }
+        qof_instance_slot_delete_if_empty (QOF_INSTANCE (imap->acc), IMAP_FRAME);
+    }
+    qof_instance_set_dirty (QOF_INSTANCE (imap->acc));
+    xaccAccountCommitEdit (imap->acc);
+}
+
 /*--------------------------------------------------------------------------
  Below here is the bayes transaction to account matching system
 --------------------------------------------------------------------------*/
@@ -5237,7 +5256,7 @@ highestProbability(gpointer key, gpointer value, gpointer data)
 
 /** Look up an Account in the map */
 Account*
-gnc_imap_find_account_bayes (GncImportMatchMap *imap, GList *tokens)
+gnc_account_imap_find_account_bayes (GncImportMatchMap *imap, GList *tokens)
 {
     struct token_accounts_info tokenInfo; /**< holds the accounts and total
                                            * token count for a single token */
@@ -5395,9 +5414,9 @@ gnc_imap_find_account_bayes (GncImportMatchMap *imap, GList *tokens)
 
 /** Updates the imap for a given account using a list of tokens */
 void
-gnc_imap_add_account_bayes(GncImportMatchMap *imap,
-                           GList *tokens,
-                           Account *acc)
+gnc_account_imap_add_account_bayes (GncImportMatchMap *imap,
+                                    GList *tokens,
+                                    Account *acc)
 {
     GList *current_token;
     gint64 token_count;
diff --git a/src/engine/Account.h b/src/engine/Account.h
index a136d86..6208f0c 100644
--- a/src/engine/Account.h
+++ b/src/engine/Account.h
@@ -65,6 +65,12 @@ typedef struct
     QofInstanceClass parent_class;
 } AccountClass;
 
+typedef struct
+{
+    Account *acc;
+    QofBook *book;
+} GncImportMatchMap;
+
 /* --- type macros --- */
 #define GNC_TYPE_ACCOUNT            (gnc_account_get_type ())
 #define GNC_ACCOUNT(o)              \
@@ -1372,6 +1378,34 @@ int gnc_account_tree_staged_transaction_traversal(const Account *account,
 int xaccAccountTreeForEachTransaction(Account *acc,
                                       TransactionCallback proc, void *data);
 
+/** Obtain an ImportMatchMap object from an Account or a Book
+ */
+GncImportMatchMap *gnc_account_imap_create_imap (Account *acc);
+
+/* Look up an Account in the map non Baysian
+ */
+Account* gnc_account_imap_find_account (GncImportMatchMap *imap, const char* category,
+                                        const char *key);
+
+/* Store an Account in the map non Baysian
+ */
+void gnc_account_imap_add_account (GncImportMatchMap *imap, const char *category,
+                                   const char *key, Account *acc);
+
+/* Remove a reference to an Account in the map non Baysian
+ */
+void gnc_account_imap_delete_account (GncImportMatchMap *imap, const char *category,
+                                      const char *key);
+
+/** Look up an Account in the map using Baysian
+ */
+Account* gnc_account_imap_find_account_bayes (GncImportMatchMap *imap, GList* tokens);
+
+/** Updates the imap for a given account using a list of tokens
+ */
+void gnc_account_imap_add_account_bayes (GncImportMatchMap *imap, GList* tokens,
+                                         Account *acc);
+
 /** @} */
 
 
diff --git a/src/engine/test/gtest-import-map.cpp b/src/engine/test/gtest-import-map.cpp
index e24a64f..8b0891e 100644
--- a/src/engine/test/gtest-import-map.cpp
+++ b/src/engine/test/gtest-import-map.cpp
@@ -1,5 +1,5 @@
 /********************************************************************
- * test-import-map.cpp: Test import match maps.                     *
+ * gtest-import-map.cpp: Test import match maps.                    *
  * Copyright 2015 John Ralls <jralls at ceridwen.us>		    *
  *                                                                  *
  * This program is free software; you can redistribute it and/or    *
@@ -26,25 +26,6 @@ extern "C"
 #include "../Account.h"
 #include <qof.h>
 #include <qofinstance-p.h>
-
-struct GncImportMatchMap
-{
-    Account *acc;
-    QofBook *book;
-};
-
-extern GncImportMatchMap * gnc_account_create_imap (Account *acc);
-extern Account* gnc_imap_find_account(GncImportMatchMap *imap,
-				      const char* category,
-				      const char *key);
-extern void gnc_imap_add_account (GncImportMatchMap *imap,
-				  const char *category,
-				  const char *key, Account *acc);
-extern Account* gnc_imap_find_account_bayes (GncImportMatchMap *imap,
-					     GList* tokens);
-extern void gnc_imap_add_account_bayes (GncImportMatchMap *imap,
-					GList* tokens,
-					Account *acc);
 }
 
 #include <kvp_frame.hpp>
@@ -73,7 +54,7 @@ protected:
 };
 
 TEST_F(ImapTest, CreateImap) {
-    GncImportMatchMap *imap = gnc_account_create_imap (t_bank_account);
+    GncImportMatchMap *imap = gnc_account_imap_create_imap (t_bank_account);
     EXPECT_NE(nullptr, imap);
     EXPECT_EQ(t_bank_account, imap->acc);
     EXPECT_EQ(gnc_account_get_book(t_bank_account), imap->book);
@@ -89,7 +70,7 @@ class ImapPlainTest : public ImapTest
 protected:
     void SetUp() {
         ImapTest::SetUp();
-        t_imap = gnc_account_create_imap (t_bank_account);
+        t_imap = gnc_account_imap_create_imap (t_bank_account);
     }
 
     void TearDown() {
@@ -110,13 +91,13 @@ TEST_F(ImapPlainTest, FindAccount)
     root->set_path({IMAP_FRAME, "pepper"}, acc1_val);
     root->set_path({IMAP_FRAME, "salt"}, acc2_val);
 
-    EXPECT_EQ(t_expense_account1, gnc_imap_find_account(t_imap, "foo", "bar"));
+    EXPECT_EQ(t_expense_account1, gnc_account_imap_find_account(t_imap, "foo", "bar"));
     EXPECT_EQ(t_expense_account2,
-              gnc_imap_find_account(t_imap, "baz", "waldo"));
+              gnc_account_imap_find_account(t_imap, "baz", "waldo"));
     EXPECT_EQ(t_expense_account1,
-              gnc_imap_find_account(t_imap, NULL, "pepper"));
-    EXPECT_EQ(t_expense_account2, gnc_imap_find_account(t_imap, NULL, "salt"));
-    EXPECT_EQ(nullptr, gnc_imap_find_account(t_imap, "salt", NULL));
+              gnc_account_imap_find_account(t_imap, NULL, "pepper"));
+    EXPECT_EQ(t_expense_account2, gnc_account_imap_find_account(t_imap, NULL, "salt"));
+    EXPECT_EQ(nullptr, gnc_account_imap_find_account(t_imap, "salt", NULL));
 }
 
 TEST_F(ImapPlainTest, AddAccount)
@@ -124,16 +105,16 @@ TEST_F(ImapPlainTest, AddAccount)
 // prevent the embedded beginedit/commitedit from doing anything
     qof_instance_increase_editlevel(QOF_INSTANCE(t_bank_account));
     qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
-    gnc_imap_add_account(t_imap, "foo", "bar", t_expense_account1);
-    gnc_imap_add_account(t_imap, "baz", "waldo", t_expense_account2);
-    gnc_imap_add_account(t_imap, NULL, "pepper", t_expense_account1);
-    gnc_imap_add_account(t_imap, NULL, "salt", t_expense_account2);
+    gnc_account_imap_add_account(t_imap, "foo", "bar", t_expense_account1);
+    gnc_account_imap_add_account(t_imap, "baz", "waldo", t_expense_account2);
+    gnc_account_imap_add_account(t_imap, NULL, "pepper", t_expense_account1);
+    gnc_account_imap_add_account(t_imap, NULL, "salt", t_expense_account2);
     EXPECT_EQ(1, qof_instance_get_editlevel(QOF_INSTANCE(t_bank_account)));
     EXPECT_TRUE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
     qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
-    gnc_imap_add_account(t_imap, NULL, NULL, t_expense_account2);
+    gnc_account_imap_add_account(t_imap, NULL, NULL, t_expense_account2);
     EXPECT_FALSE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
-    gnc_imap_add_account(t_imap, "pork", "sausage", NULL);
+    gnc_account_imap_add_account(t_imap, "pork", "sausage", NULL);
     EXPECT_FALSE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
     qof_instance_reset_editlevel(QOF_INSTANCE(t_bank_account));
 
@@ -152,6 +133,45 @@ TEST_F(ImapPlainTest, AddAccount)
     EXPECT_EQ(nullptr, value);
 }
 
+TEST_F(ImapPlainTest, DeleteAccount)
+{
+    Path path1 {IMAP_FRAME, "foo", "waldo"};
+    Path path2 {IMAP_FRAME, "foo"};
+    Path path3 {IMAP_FRAME};
+
+// prevent the embedded beginedit/commitedit from doing anything
+    qof_instance_increase_editlevel(QOF_INSTANCE(t_bank_account));
+    qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
+    gnc_account_imap_add_account(t_imap, "foo", "bar", t_expense_account1);
+    gnc_account_imap_add_account(t_imap, "foo", "waldo", t_expense_account2);
+    gnc_account_imap_add_account(t_imap, NULL, "pepper", t_expense_account1);
+    EXPECT_EQ(1, qof_instance_get_editlevel(QOF_INSTANCE(t_bank_account)));
+    EXPECT_TRUE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
+    qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
+
+    gnc_account_imap_delete_account(t_imap, NULL, NULL);
+    EXPECT_FALSE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
+
+    gnc_account_imap_delete_account(t_imap, "foo", "waldo");
+    EXPECT_TRUE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
+    qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
+    EXPECT_EQ(t_expense_account1, gnc_account_imap_find_account(t_imap, "foo", "bar"));
+    EXPECT_EQ(nullptr, gnc_account_imap_find_account(t_imap, "foo", "waldo"));
+    auto root = qof_instance_get_slots(QOF_INSTANCE(t_bank_account));
+    EXPECT_EQ(nullptr, root->get_slot(path1));
+
+    gnc_account_imap_delete_account(t_imap, "foo", "bar");
+    EXPECT_TRUE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
+    qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
+    EXPECT_EQ(nullptr, root->get_slot(path2));
+
+    gnc_account_imap_delete_account(t_imap, NULL, "pepper");
+    EXPECT_TRUE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
+    qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
+    EXPECT_EQ(nullptr, root->get_slot(path3));
+    qof_instance_reset_editlevel(QOF_INSTANCE(t_bank_account));
+}
+
 static const char* foo = "foo";
 static const char* bar = "bar";
 static const char* baz = "baz";
@@ -212,15 +232,15 @@ TEST_F(ImapBayesTest, FindAccountBayes)
     root->set_path({IMAP_FRAME_BAYES, pepper, acct1_name}, value);
     root->set_path({IMAP_FRAME_BAYES, salt, acct2_name}, value);
 
-    auto account = gnc_imap_find_account_bayes(t_imap, t_list1);
+    auto account = gnc_account_imap_find_account_bayes(t_imap, t_list1);
     EXPECT_EQ(t_expense_account1, account);
-    account = gnc_imap_find_account_bayes(t_imap, t_list2);
+    account = gnc_account_imap_find_account_bayes(t_imap, t_list2);
     EXPECT_EQ(t_expense_account2, account);
-    account = gnc_imap_find_account_bayes(t_imap, t_list3);
+    account = gnc_account_imap_find_account_bayes(t_imap, t_list3);
     EXPECT_EQ(t_expense_account1, account);
-    account = gnc_imap_find_account_bayes(t_imap, t_list4);
+    account = gnc_account_imap_find_account_bayes(t_imap, t_list4);
     EXPECT_EQ(t_expense_account2, account);
-    account = gnc_imap_find_account_bayes(t_imap, t_list5);
+    account = gnc_account_imap_find_account_bayes(t_imap, t_list5);
     EXPECT_EQ(nullptr, account);
 }
 
@@ -229,14 +249,14 @@ TEST_F(ImapBayesTest, AddAccountBayes)
     // prevent the embedded beginedit/commitedit from doing anything
     qof_instance_increase_editlevel(QOF_INSTANCE(t_bank_account));
     qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
-    gnc_imap_add_account_bayes(t_imap, t_list1, t_expense_account1);
-    gnc_imap_add_account_bayes(t_imap, t_list2, t_expense_account2);
-    gnc_imap_add_account_bayes(t_imap, t_list3, t_expense_account1);
-    gnc_imap_add_account_bayes(t_imap, t_list4, t_expense_account2);
+    gnc_account_imap_add_account_bayes(t_imap, t_list1, t_expense_account1);
+    gnc_account_imap_add_account_bayes(t_imap, t_list2, t_expense_account2);
+    gnc_account_imap_add_account_bayes(t_imap, t_list3, t_expense_account1);
+    gnc_account_imap_add_account_bayes(t_imap, t_list4, t_expense_account2);
     EXPECT_EQ(1, qof_instance_get_editlevel(QOF_INSTANCE(t_bank_account)));
     EXPECT_TRUE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
     qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
-    gnc_imap_add_account_bayes(t_imap, t_list5, NULL);
+    gnc_account_imap_add_account_bayes(t_imap, t_list5, NULL);
     EXPECT_FALSE(qof_instance_get_dirty_flag(QOF_INSTANCE(t_bank_account)));
     qof_instance_reset_editlevel(QOF_INSTANCE(t_bank_account));
 
@@ -262,7 +282,7 @@ TEST_F(ImapBayesTest, AddAccountBayes)
     EXPECT_EQ(nullptr, value);
 
     qof_instance_increase_editlevel(QOF_INSTANCE(t_bank_account));
-    gnc_imap_add_account_bayes(t_imap, t_list2, t_expense_account2);
+    gnc_account_imap_add_account_bayes(t_imap, t_list2, t_expense_account2);
     qof_instance_mark_clean(QOF_INSTANCE(t_bank_account));
     qof_instance_reset_editlevel(QOF_INSTANCE(t_bank_account));
     value = root->get_slot({IMAP_FRAME_BAYES, baz, acct2_name});
diff --git a/src/import-export/import-backend.c b/src/import-export/import-backend.c
index fdd219d..827421a 100644
--- a/src/import-export/import-backend.c
+++ b/src/import-export/import-backend.c
@@ -44,37 +44,6 @@
 #include "gnc-prefs.h"
 #include "gnc-ui-util.h"
 
-/* Private interface to Account GncImportMatchMap functions */
-
-/** @{
-Obtain an ImportMatchMap object from an Account */
-extern GncImportMatchMap * gnc_account_create_imap (Account *acc);
-/*@}*/
-
-/* Look up an Account in the map */
-extern Account* gnc_imap_find_account(GncImportMatchMap *imap,
-				      const char* category,
-				      const char *key);
-
-/* Store an Account in the map. This mapping is immediatly stored in
-  the underlying kvp frame, regardless of whether the MatchMap is
-  destroyed later or not. */
-extern void gnc_imap_add_account (GncImportMatchMap *imap,
-				  const char *category,
-				  const char *key, Account *acc);
-
-/* Look up an Account in the map from a GList* of pointers to strings(tokens)
-  from the current transaction */
-extern Account* gnc_imap_find_account_bayes (GncImportMatchMap *imap,
-					     GList* tokens);
-
-/* Store an Account in the map. This mapping is immediatly stored in
-  the underlying kvp frame, regardless of whether the MatchMap is
-  destroyed later or not. */
-extern void gnc_imap_add_account_bayes (GncImportMatchMap *imap,
-					GList* tokens,
-					Account *acc);
-
 #define GNCIMPORT_DESC    "desc"
 #define GNCIMPORT_MEMO    "memo"
 #define GNCIMPORT_PAYEE    "payee"
@@ -514,7 +483,7 @@ matchmap_find_destination (GncImportMatchMap *matchmap, GNCImportTransInfo *info
 
     g_assert (info);
     tmp_map = ((matchmap != NULL) ? matchmap :
-               gnc_account_create_imap
+               gnc_account_imap_create_imap
                (xaccSplitGetAccount
                 (gnc_import_TransInfo_get_fsplit (info))));
 
@@ -525,13 +494,13 @@ matchmap_find_destination (GncImportMatchMap *matchmap, GNCImportTransInfo *info
         tokens = TransactionGetTokens(info);
 
         /* try to find the destination account for this transaction from its tokens */
-        result = gnc_imap_find_account_bayes(tmp_map, tokens);
+        result = gnc_account_imap_find_account_bayes(tmp_map, tokens);
 
     }
     else
     {
         /* old system of transaction to account matching */
-        result = gnc_imap_find_account
+        result = gnc_account_imap_find_account
                  (tmp_map, GNCIMPORT_DESC,
                   xaccTransGetDescription (gnc_import_TransInfo_get_trans (info)));
     }
@@ -542,7 +511,7 @@ matchmap_find_destination (GncImportMatchMap *matchmap, GNCImportTransInfo *info
      * transaction is stored there.
 
        if (result == NULL)
-       result = gnc_imap_find_account
+       result = gnc_account_imap_find_account
        (tmp_map, GNCIMPORT_MEMO,
        xaccSplitGetMemo (gnc_import_TransInfo_get_fsplit (info)));
     */
@@ -584,7 +553,7 @@ matchmap_store_destination (GncImportMatchMap *matchmap,
 
     tmp_matchmap = ((matchmap != NULL) ?
                     matchmap :
-                    gnc_account_create_imap
+                    gnc_account_imap_create_imap
                     (xaccSplitGetAccount
                      (gnc_import_TransInfo_get_fsplit (trans_info))));
 
@@ -596,7 +565,7 @@ matchmap_store_destination (GncImportMatchMap *matchmap,
         tokens = TransactionGetTokens(trans_info);
 
         /* add the tokens to the imap with the given destination account */
-        gnc_imap_add_account_bayes(tmp_matchmap, tokens, dest);
+        gnc_account_imap_add_account_bayes(tmp_matchmap, tokens, dest);
 
     }
     else
@@ -605,14 +574,14 @@ matchmap_store_destination (GncImportMatchMap *matchmap,
         descr = xaccTransGetDescription
                 (gnc_import_TransInfo_get_trans (trans_info));
         if (descr && (strlen (descr) > 0))
-            gnc_imap_add_account (tmp_matchmap,
+            gnc_account_imap_add_account (tmp_matchmap,
                                   GNCIMPORT_DESC,
                                   descr,
                                   dest);
         memo = xaccSplitGetMemo
                (gnc_import_TransInfo_get_fsplit (trans_info));
         if (memo && (strlen (memo) > 0))
-            gnc_imap_add_account (tmp_matchmap,
+            gnc_account_imap_add_account (tmp_matchmap,
                                   GNCIMPORT_MEMO,
                                   memo,
                                   dest);
diff --git a/src/import-export/import-backend.h b/src/import-export/import-backend.h
index 99e6421..43fea10 100644
--- a/src/import-export/import-backend.h
+++ b/src/import-export/import-backend.h
@@ -33,7 +33,6 @@
 
 typedef struct _transactioninfo GNCImportTransInfo;
 typedef struct _matchinfo GNCImportMatchInfo;
-typedef struct _GncImportMatchMap GncImportMatchMap;
 
 typedef enum _action
 {



Summary of changes:
 src/engine/Account.c                               |  71 +++++----
 src/engine/Account.h                               |  34 +++++
 src/engine/test/gtest-import-map.cpp               | 108 +++++++------
 src/import-export/csv-imp/Makefile.am              |   2 +
 src/import-export/csv-imp/gnc-csv-account-map.c    | 167 +++++++++++++++++++++
 .../csv-imp/gnc-csv-account-map.h}                 |  38 +++--
 src/import-export/import-backend.c                 |  47 +-----
 src/import-export/import-backend.h                 |   1 -
 8 files changed, 347 insertions(+), 121 deletions(-)
 create mode 100644 src/import-export/csv-imp/gnc-csv-account-map.c
 copy src/{gnome/dialog-lot-viewer.h => import-export/csv-imp/gnc-csv-account-map.h} (62%)



More information about the gnucash-changes mailing list