* src/import-export/gnc-import-match-map.[ch]

Implement a generic Account Mapper for the import routines.
	  Still needs a GUI.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7475 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2002-11-12 22:07:40 +00:00
parent da778e274e
commit a0ec45ad40
4 changed files with 184 additions and 0 deletions
+6
View File
@@ -1,3 +1,9 @@
2002-11-12 Derek Atkins <derek@ihtfp.com>
* src/import-export/gnc-import-match-map.[ch]
Implement a generic Account Mapper for the import routines.
Still needs a GUI.
2002-11-12 David Hampton <hampton@employees.org>
* src/register/ledger-core/split-register-control.c
+5
View File
@@ -7,8 +7,13 @@ libgncmod_generic_import_la_SOURCES = \
Commodity-matcher.c \
Transaction-matcher.c \
Utilities.c \
gnc-import-match-map.c \
gncmod-generic-import.c
gncincludedir = ${GNC_INCLUDE_DIR}
gncinclude_HEADERS = \
gnc-import-match-map.h
noinst_HEADERS = \
gnc-generic-import.h
+124
View File
@@ -0,0 +1,124 @@
/*
* gnc-import-match-map.c:
* an import mapper service that stores Account Maps for the
* generic importer. This allows importers to map various
* "strings" to Gnucash accounts in a generic manner.
*
* Created by: Derek Atkins <derek@ihtfp.com>
*
*/
#include "gnc-import-match-map.h"
#include "kvp_frame.h"
struct _GncImportMatchMap {
kvp_frame * frame;
Account * acc;
GNCBook * book;
};
#define IMAP_FRAME "import-map"
static GncImportMatchMap *
gnc_imap_create_from_frame (kvp_frame *frame, Account *acc, GNCBook *book)
{
GncImportMatchMap *imap;
g_return_val_if_fail (frame != NULL, NULL);
g_return_val_if_fail ((acc && !book) || (!acc && book), NULL);
imap = g_new0(GncImportMatchMap, 1);
imap->frame = frame;
/* Cache the book for easy lookups; store the account/book for
* marking dirtiness
*/
if (acc)
book = xaccAccountGetBook (acc);
imap->acc = acc;
imap->book = book;
return imap;
}
/* Obtain an ImportMatchMap object from an Account or a Book */
GncImportMatchMap * gnc_imap_create_from_account (Account *acc)
{
kvp_frame * frame;
if (!acc) return NULL;
frame = xaccAccountGetSlots (acc);
g_return_val_if_fail (frame != NULL, NULL);
return gnc_imap_create_from_frame (frame, acc, NULL);
}
GncImportMatchMap * gnc_imap_create_from_book (GNCBook *book)
{
kvp_frame * frame;
if (!book) return NULL;
frame = gnc_book_get_slots (book);
g_return_val_if_fail (frame != NULL, NULL);
return gnc_imap_create_from_frame (frame, NULL, book);
}
/* Destroy an import map */
void gnc_imap_destroy (GncImportMatchMap *imap)
{
if (!imap) return;
g_free (imap);
}
/* Clear an import map -- this removes ALL entries in the map */
void gnc_imap_clear (GncImportMatchMap *imap)
{
if (!imap) return;
/* Clear the IMAP_FRAME kvp */
kvp_frame_set_slot_path (imap->frame, NULL, IMAP_FRAME);
/* XXX: mark the account (or book) as dirty! */
}
/* Look up an Account in the map */
Account * gnc_imap_find_account (GncImportMatchMap *imap, const char *category,
const char *key)
{
kvp_value *value;
GUID * guid;
if (!imap || !key) return NULL;
if (!category) {
category = key;
key = NULL;
}
value = kvp_frame_get_slot_path (imap->frame, IMAP_FRAME, category, key, NULL);
if (!value) return NULL;
guid = kvp_value_get_guid (value);
return xaccAccountLookup (guid, imap->book);
}
/* Store an Account in the map */
void gnc_imap_add_account (GncImportMatchMap *imap, const char *category,
const char *key, Account *acc)
{
kvp_value *value;
if (!imap || !key || !acc) return;
if (!category) {
category = key;
key = NULL;
}
value = kvp_value_new_guid (xaccAccountGetGUID (acc));
g_return_if_fail (value != NULL);
kvp_frame_set_slot_path (imap->frame, value, IMAP_FRAME, category, key, NULL);
kvp_value_delete (value);
/* XXX Mark the account (or book) as dirty! */
}
+49
View File
@@ -0,0 +1,49 @@
/*
* gnc-import-match-map.h:
* an import mapper service that stores Account Maps for the
* generic importer. This allows importers to map various
* "strings" to Gnucash accounts in a generic manner.
*
* Created by: Derek Atkins <derek@ihtfp.com>
*
*/
#ifndef GNC_IMPORT_MATCH_MAP_H
#define GNC_IMPORT_MATCH_MAP_H
typedef struct _GncImportMatchMap GncImportMatchMap;
#include "Account.h"
#include "gnc-book.h"
/* Obtain an ImportMatchMap object from an Account or a Book */
GncImportMatchMap * gnc_imap_create_from_account (Account *acc);
GncImportMatchMap * gnc_imap_create_from_book (GNCBook *book);
/* Destroy an import map */
void gnc_imap_destroy (GncImportMatchMap *imap);
/* Clear an import map -- this removes ALL entries in the map */
void gnc_imap_clear (GncImportMatchMap *imap);
/* Look up an Account in the map */
Account * gnc_imap_find_account (GncImportMatchMap *imap, const char *category,
const char *key);
/* Store an Account in the map */
void gnc_imap_add_account (GncImportMatchMap *imap, const char *category,
const char *key, Account *acc);
/* some well-known categories
*
* NOTE: You DO NOT have to use these values in your importer -- these
* are just "well known" values, not "mandatory" values. You are free
* to use these if they apply, map your own fields to these labels, or
* create your own category strings.
*/
#define GNCIMPORT_DESC "desc"
#define GNCIMPORT_MEMO "memo"
#define GNCIMPORT_PAYEE "payee"
#endif /* GNC_IMPORT_MATCH_MAP_H */