gnucash master: Get the Aqbanking transfer action to work again: Revert part of 7faed6540162ccd1fe.

Christian Stimming cstim at code.gnucash.org
Sun Aug 31 16:51:33 EDT 2014


Updated	 via  https://github.com/Gnucash/gnucash/commit/85c74fbe (commit)
	from  https://github.com/Gnucash/gnucash/commit/1ee4210b (commit)



commit 85c74fbeaa982cba431c8c05f744524ee7fae666
Author: Christian Stimming <christian at cstimming.de>
Date:   Sun Aug 31 22:48:56 2014 +0200

    Get the Aqbanking transfer action to work again: Revert part of 7faed6540162ccd1fe.
    
    As discussed in
    https://lists.gnucash.org/pipermail/gnucash-devel/2014-July/037868.html
    as an exception the direct access to the kvp is enabled again in
    import-export/aqb/gnc-ab-kvp.c because the way aqbanking transfer templates
    are stored cannot be mapped directly on the properties mechanism.
    With this implementation, at least the read access to the templates
    works again, which means the aqbanking transfers can be used again (they
    crashed immediately up until now).
    
    However, writing a changed template to the kvp seems to not work - the
    changed values seem not to be saved. This would be a bug, but not as severe
    as the previous one. The unittest verifies both reading and writing,
    though, and there also writing works fine. Well, this can be worked
    on later.

diff --git a/src/import-export/aqb/gnc-ab-kvp.c b/src/import-export/aqb/gnc-ab-kvp.c
index b99390b..940bad8 100644
--- a/src/import-export/aqb/gnc-ab-kvp.c
+++ b/src/import-export/aqb/gnc-ab-kvp.c
@@ -35,8 +35,6 @@
 /* This static indicates the debugging module that this .o belongs to.  */
 G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
 
-static kvp_frame *gnc_ab_get_book_kvp(QofBook *b, gboolean create);
-
 const gchar *
 gnc_ab_get_account_accountid(const Account *a)
 {
@@ -117,20 +115,43 @@ gnc_ab_set_account_trans_retrieval(Account *a, Timespec time)
     xaccAccountCommitEdit(a);
 }
 
+
+#define AB_KEY "hbci"
+#define AB_TEMPLATES "template-list"
+static kvp_frame *gnc_ab_get_book_kvp(QofBook *b, gboolean create);
+
+
+/* EFFECTIVE FRIEND FUNCTION */
+extern KvpFrame *qof_instance_get_slots (const QofInstance *);
+/* EFFECTIVE FRIEND FUNCTION */
+extern void qof_instance_set_dirty_flag (gconstpointer inst, gboolean flag);
+
 GList *
 gnc_ab_get_book_template_list(QofBook *b)
 {
-    GList *template_list = NULL;
-    qof_instance_get (QOF_INSTANCE (b),
-		      "ab-templates", &template_list,
-		      NULL);
-    return template_list;
+    kvp_frame *frame = gnc_ab_get_book_kvp(b, FALSE);
+    kvp_value *value = kvp_frame_get_slot(frame, AB_TEMPLATES);
+    return kvp_value_get_glist(value);
 }
 
 void
 gnc_ab_set_book_template_list(QofBook *b, GList *template_list)
 {
-    qof_instance_set (QOF_INSTANCE (b),
-		      "ab-templates", &template_list,
-		      NULL);
+    kvp_frame *frame = gnc_ab_get_book_kvp(b, TRUE);
+    kvp_value *value = kvp_value_new_glist_nc(template_list);
+    kvp_frame_set_slot_nc(frame, AB_TEMPLATES, value);
+    qof_instance_set_dirty_flag(QOF_INSTANCE(b), TRUE);
+}
+
+static kvp_frame *
+gnc_ab_get_book_kvp(QofBook *b, gboolean create)
+{
+    kvp_frame *toplevel = qof_instance_get_slots(QOF_INSTANCE(b));
+    kvp_frame *result = kvp_frame_get_frame(toplevel, AB_KEY);
+    if (!result && create)
+    {
+        result = kvp_frame_new();
+        kvp_frame_add_frame_nc(toplevel, AB_KEY, result);
+    }
+    return result;
 }
diff --git a/src/import-export/aqb/test/test-kvp.c b/src/import-export/aqb/test/test-kvp.c
index 5a54484..d6a3236 100644
--- a/src/import-export/aqb/test/test-kvp.c
+++ b/src/import-export/aqb/test/test-kvp.c
@@ -25,6 +25,7 @@
 
 // for the gnc_ab_get_book_template_list() et al. functions
 #include "import-export/aqb/gnc-ab-kvp.h"
+#include "import-export/aqb/gnc-ab-trans-templ.h"
 #include "engine/gnc-hooks.h"
 
 static char* get_filepath(const char* filename)
@@ -91,7 +92,7 @@ test_qofsession_aqb_kvp( void )
         //qof_session_destroy(new_session); // tries to delete the LCK file but it wasn't created in the first place
     }
 
-    if (0)
+    if (1)
     {
         // A file with no content except for the book_template_list kvp
         // slot
@@ -113,8 +114,46 @@ test_qofsession_aqb_kvp( void )
         g_assert(io_err == 0);
 
         {
-            GList *mylist = gnc_ab_get_book_template_list(qof_session_get_book(new_session));
-            g_assert(mylist != 0); // do we have the slot?!
+            GList *templ_list;
+            GncABTransTempl *templ;
+            QofBook *book = qof_session_get_book(new_session);
+            const char* ORIGINAL_NAME = "Some Name";
+            const char* CHANGED_NAME = "Some Changed Name";
+
+            GList *kvp_list = gnc_ab_get_book_template_list(book);
+            g_assert(kvp_list != 0); // do we have the slot?!
+            g_assert_cmpint(g_list_length(kvp_list), ==, 1);
+
+            templ_list = gnc_ab_trans_templ_list_new_from_kvp_list(kvp_list);
+            g_assert_cmpint(g_list_length(templ_list), ==, 1);
+
+            templ = templ_list->data;
+            g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, ORIGINAL_NAME); // ok, name from file is here
+
+            // Now we change the name into something else and verify it can be saved
+            gnc_ab_trans_templ_set_name(templ, CHANGED_NAME);
+            {
+                GList *kvp_list_new = gnc_ab_trans_templ_list_to_kvp_list(templ_list);
+                gnc_ab_trans_templ_list_free(templ_list);
+                g_assert(!qof_instance_get_dirty(QOF_INSTANCE(book))); // not yet dirty
+
+                // Here we save the changed kvp
+                gnc_ab_set_book_template_list(book, kvp_list_new);
+                g_assert(qof_instance_get_dirty(QOF_INSTANCE(book))); // yup, now dirty
+            }
+
+            {
+                GList *mylist = gnc_ab_get_book_template_list(book);
+                g_assert(mylist != 0);
+                g_assert_cmpint(g_list_length(mylist), ==, 1);
+
+                templ_list = gnc_ab_trans_templ_list_new_from_kvp_list(mylist);
+                g_assert_cmpint(g_list_length(templ_list), ==, 1);
+
+                templ = templ_list->data;
+                g_assert_cmpstr(gnc_ab_trans_templ_get_name(templ), ==, CHANGED_NAME); // ok, the change has been saved!
+                gnc_ab_trans_templ_list_free(templ_list);
+            }
         }
 
         g_free(newfile);
diff --git a/src/libqof/qof/qofinstance.cpp b/src/libqof/qof/qofinstance.cpp
index a814579..1af2c0a 100644
--- a/src/libqof/qof/qofinstance.cpp
+++ b/src/libqof/qof/qofinstance.cpp
@@ -574,6 +574,7 @@ qof_instance_books_equal (gconstpointer ptr1, gconstpointer ptr2)
     return (priv1->book == priv2->book);
 }
 
+/* Watch out: This function is still used (as a "friend") in src/import-export/aqb/gnc-ab-kvp.c */
 KvpFrame*
 qof_instance_get_slots (const QofInstance *inst)
 {
@@ -669,6 +670,7 @@ qof_instance_get_dirty_flag (gconstpointer ptr)
     return GET_PRIVATE(ptr)->dirty;
 }
 
+/* Watch out: This function is still used (as a "friend") in src/import-export/aqb/gnc-ab-kvp.c */
 void
 qof_instance_set_dirty_flag (gconstpointer inst, gboolean flag)
 {



Summary of changes:
 src/import-export/aqb/gnc-ab-kvp.c    | 41 +++++++++++++++++++++++--------
 src/import-export/aqb/test/test-kvp.c | 45 ++++++++++++++++++++++++++++++++---
 src/libqof/qof/qofinstance.cpp        |  2 ++
 3 files changed, 75 insertions(+), 13 deletions(-)



More information about the gnucash-changes mailing list