Move commodity tables into GNCBooks instead of global data.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5460 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2001-10-03 10:07:45 +00:00
parent 249e3b56fe
commit e23fcf4fc5
84 changed files with 1429 additions and 674 deletions

View File

@ -269,8 +269,6 @@ gnc_file_new (void)
gnc_session_destroy (session);
current_session = NULL;
gnc_commodity_table_remove_non_iso (gnc_engine_commodities ());
/* start a new book */
gnc_get_current_session_internal ();
@ -357,8 +355,6 @@ gnc_post_file_open (const char * filename)
gnc_session_destroy (current_session);
current_session = NULL;
gnc_commodity_table_remove_non_iso (gnc_engine_commodities ());
/* load the accounts from the users datafile */
/* but first, check to make sure we've got a session going. */
new_session = gnc_session_new ();

View File

@ -28,9 +28,11 @@
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "gnc-euro.h"
#include "gnc-ui-util.h"
/* local structs */
typedef struct _gnc_euro_rate_struct {
typedef struct
{
const char *currency;
double rate;
} gnc_euro_rate_struct;
@ -38,7 +40,7 @@ typedef struct _gnc_euro_rate_struct {
/* This array MUST be sorted ! */
/* The rates are per EURO */
static gnc_euro_rate_struct _gnc_euro_rate_[] =
static gnc_euro_rate_struct gnc_euro_rates[] =
{
{ "ATS", 13.7603 }, /* austrian schilling */
{ "BEF", 40.3399 }, /* belgian franc */
@ -69,7 +71,7 @@ static gnc_euro_rate_struct _gnc_euro_rate_[] =
};
static int
_gnc_euro_rate_compare_(const void * key, const void * value)
gnc_euro_rate_compare (const void * key, const void * value)
{
const gnc_commodity * curr = key;
const gnc_euro_rate_struct * euro = value;
@ -78,15 +80,41 @@ _gnc_euro_rate_compare_(const void * key, const void * value)
return -1;
return strcasecmp(gnc_commodity_get_mnemonic(curr), euro->currency);
}
static int
gnc_euro_rate_compare_code (const void * key, const void * value)
{
const char *code = key;
const gnc_euro_rate_struct * euro = value;
if (!key || !value)
return -1;
return strcasecmp (code, euro->currency);
}
/* ------------------------------------------------------ */
gboolean
gnc_is_euro_currency_code (const char *code)
{
gnc_euro_rate_struct *result;
if (!code) return FALSE;
result = bsearch (code,
gnc_euro_rates,
sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
sizeof(gnc_euro_rate_struct),
gnc_euro_rate_compare_code);
return result != NULL;
}
gboolean
gnc_is_euro_currency(const gnc_commodity * currency)
{
gnc_euro_rate_struct *result;
const char *namespace;
@ -101,10 +129,10 @@ gnc_is_euro_currency(const gnc_commodity * currency)
return FALSE;
result = bsearch(currency,
_gnc_euro_rate_,
sizeof(_gnc_euro_rate_) / sizeof(gnc_euro_rate_struct),
gnc_euro_rates,
sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
sizeof(gnc_euro_rate_struct),
_gnc_euro_rate_compare_);
gnc_euro_rate_compare);
if (result == NULL)
return FALSE;
@ -115,8 +143,8 @@ gnc_is_euro_currency(const gnc_commodity * currency)
/* ------------------------------------------------------ */
gnc_numeric
gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value) {
gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value)
{
gnc_euro_rate_struct *result;
const char *namespace;
@ -131,10 +159,10 @@ gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value) {
return gnc_numeric_zero ();
result = bsearch(currency,
_gnc_euro_rate_,
sizeof(_gnc_euro_rate_) / sizeof(gnc_euro_rate_struct),
gnc_euro_rates,
sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
sizeof(gnc_euro_rate_struct),
_gnc_euro_rate_compare_);
gnc_euro_rate_compare);
if (result == NULL)
return gnc_numeric_zero ();
@ -152,8 +180,8 @@ gnc_convert_to_euro(const gnc_commodity * currency, gnc_numeric value) {
/* ------------------------------------------------------ */
gnc_numeric
gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value) {
gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value)
{
gnc_euro_rate_struct * result;
const char *namespace;
@ -168,10 +196,10 @@ gnc_convert_from_euro(const gnc_commodity * currency, gnc_numeric value) {
return gnc_numeric_zero ();
result = bsearch(currency,
_gnc_euro_rate_,
sizeof(_gnc_euro_rate_) / sizeof(gnc_euro_rate_struct),
gnc_euro_rates,
sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
sizeof(gnc_euro_rate_struct),
_gnc_euro_rate_compare_);
gnc_euro_rate_compare);
if (result == NULL)
return gnc_numeric_zero ();
@ -205,10 +233,10 @@ gnc_euro_currency_get_rate (const gnc_commodity *currency)
return gnc_numeric_zero ();
result = bsearch(currency,
_gnc_euro_rate_,
sizeof(_gnc_euro_rate_) / sizeof(gnc_euro_rate_struct),
gnc_euro_rates,
sizeof(gnc_euro_rates) / sizeof(gnc_euro_rate_struct),
sizeof(gnc_euro_rate_struct),
_gnc_euro_rate_compare_);
gnc_euro_rate_compare);
if (result == NULL)
return gnc_numeric_zero ();
@ -222,7 +250,9 @@ gnc_euro_currency_get_rate (const gnc_commodity *currency)
gnc_commodity *
gnc_get_euro (void)
{
return gnc_commodity_table_lookup (gnc_engine_commodities (),
GNC_COMMODITY_NS_ISO,
"EUR");
gnc_commodity_table *table;
table = gnc_book_get_commodity_table (gnc_get_current_book ());
return gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_ISO, "EUR");
}

View File

@ -28,6 +28,7 @@
#include "gnc-numeric.h"
gboolean gnc_is_euro_currency (const gnc_commodity * currency);
gboolean gnc_is_euro_currency_code (const char *code);
gnc_numeric gnc_convert_to_euro (const gnc_commodity * currency,
gnc_numeric value);
gnc_numeric gnc_convert_from_euro (const gnc_commodity * currency,

View File

@ -224,6 +224,12 @@ gnc_get_current_group (void)
return gnc_book_get_group (gnc_get_current_book ());
}
gnc_commodity_table *
gnc_get_current_commodities (void)
{
return gnc_book_get_commodity_table (gnc_get_current_book ());
}
const char *
gnc_ui_account_get_field_name (AccountFieldCode field)
{
@ -340,7 +346,7 @@ gnc_ui_convert_balance_to_currency(gnc_numeric balance, gnc_commodity *balance_c
static gnc_numeric
gnc_account_get_reconciled_balance_in_currency (Account *account,
gnc_commodity *currency)
gnc_commodity *currency)
{
GNCBook *book;
GNCPriceDB *pdb;
@ -354,9 +360,10 @@ gnc_account_get_reconciled_balance_in_currency (Account *account,
return gnc_numeric_zero ();
balance = xaccAccountGetReconciledBalance (account);
balance_currency = DxaccAccountGetCurrency (account);
balance_currency = xaccAccountGetCommodity (account);
return gnc_ui_convert_balance_to_currency (balance, balance_currency, currency);
return gnc_ui_convert_balance_to_currency (balance, balance_currency,
currency);
}
typedef struct
@ -523,7 +530,7 @@ gnc_ui_account_get_reconciled_balance (Account *account,
if (account == NULL)
return gnc_numeric_zero ();
currency = DxaccAccountGetCurrency (account);
currency = xaccAccountGetCommodity (account);
balance = gnc_account_get_reconciled_balance_in_currency (account, currency);
@ -556,7 +563,7 @@ gnc_ui_account_get_balance_as_of_date (Account *account, time_t date,
if (account == NULL)
return gnc_numeric_zero ();
currency = DxaccAccountGetCurrency (account);
currency = xaccAccountGetCommodity (account);
balance = xaccAccountGetBalanceAsOfDate (account, date);
if (include_children)
@ -567,14 +574,14 @@ gnc_ui_account_get_balance_as_of_date (Account *account, time_t date,
children_group = xaccAccountGetChildren (account);
children = xaccGroupGetSubAccounts (children_group);
for( node = children; node; node = node->next )
for (node = children; node; node = node->next)
{
Account *child;
gnc_commodity *child_currency;
gnc_numeric child_balance;
child = (Account *)node->data;
child_currency = DxaccAccountGetCurrency (child);
child = node->data;
child_currency = xaccAccountGetCommodity (child);
child_balance = xaccAccountGetBalanceAsOfDate (child, date);
child_balance = gnc_ui_convert_balance_to_currency
(child_balance, child_currency, currency);
@ -1003,41 +1010,44 @@ gnc_localeconv (void)
return &lc;
}
const char *
gnc_locale_default_iso_currency_code (void)
{
static char *code = NULL;
struct lconv *lc;
if (code)
return code;
lc = gnc_localeconv ();
code = g_strdup (lc->int_curr_symbol);
/* The int_curr_symbol includes a space at the end! Note: you
* can't just change "USD " to "USD" in gnc_localeconv, because
* that is only used if int_curr_symbol was not defined in the
* current locale. If it was, it will have the space! */
g_strstrip (code);
return code;
}
gnc_commodity *
gnc_locale_default_currency (void)
{
static gnc_commodity * currency;
struct lconv * lc;
static gboolean got_it = FALSE;
gnc_commodity * currency;
gnc_commodity_table *table;
const char *code;
if (!got_it)
{
char *symbol;
table = gnc_get_current_commodities ();
code = gnc_locale_default_iso_currency_code ();
lc = gnc_localeconv();
currency = gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_ISO, code);
symbol = g_strdup (lc->int_curr_symbol);
if (currency)
return currency;
/* The int_curr_symbol includes a space at the end! Note: you
* can't just change "USD " to "USD" in gnc_localeconv, because
* that is only used if int_curr_symbol was not defined in the
* current locale. If it was, it will have the space! */
g_strstrip (symbol);
currency = gnc_commodity_table_lookup (gnc_engine_commodities(),
GNC_COMMODITY_NS_ISO,
symbol);
if (!currency)
currency = gnc_commodity_table_lookup (gnc_engine_commodities(),
GNC_COMMODITY_NS_ISO,
"USD");
g_free (symbol);
got_it = TRUE;
}
return currency;
return gnc_commodity_table_lookup (table, GNC_COMMODITY_NS_ISO, "USD");
}
@ -1100,17 +1110,17 @@ gnc_default_print_info (gboolean use_symbol)
{
static GNCPrintAmountInfo info;
static gboolean got_it = FALSE;
struct lconv *lc;
/* These must be updated each time. */
info.use_symbol = use_symbol ? 1 : 0;
info.commodity = gnc_default_currency ();
if (got_it)
return info;
lc = gnc_localeconv ();
info.commodity = gnc_default_currency ();
info.max_decimal_places = lc->frac_digits;
info.min_decimal_places = lc->frac_digits;

View File

@ -49,6 +49,7 @@ void gnc_set_current_session_handler (GNCSessionCB cb);
GNCSession * gnc_get_current_session (void);
GNCBook * gnc_get_current_book (void);
AccountGroup * gnc_get_current_group (void);
gnc_commodity_table * gnc_get_current_commodities (void);
typedef enum
{
@ -136,6 +137,9 @@ struct lconv * gnc_localeconv (void);
/* Returns the default currency of the current locale. */
gnc_commodity * gnc_locale_default_currency (void);
/* Returns the default ISO currency string of the current locale. */
const char * gnc_locale_default_iso_currency_code (void);
/* Returns the number of decimal place to print in the current locale */
int gnc_locale_decimal_places (void);

View File

@ -86,6 +86,22 @@
"GNCOptionChangeCallback" "const GNCOptionChangeCallback")
(gw:wrap-function
mod
'gnc:get-current-group
'<gnc:AccountGroup*>
"gnc_get_current_group"
'()
"Get the current top-level group.")
(gw:wrap-function
mod
'gnc:get-current-book
'<gnc:Book*>
"gnc_get_current_book"
'()
"Get the current top-level book.")
(gw:wrap-function
mod
'gnc:exp-parser-init
@ -205,6 +221,14 @@ determines formatting details.")
'()
"Return the default currency for the current locale.")
(gw:wrap-function
mod
'gnc:locale-default-iso-currency-code
'(<gw:m-chars-callee-owned> gw:const)
"gnc_locale_default_iso_currency_code"
'()
"Return the default iso currency code for the current locale.")
(gw:wrap-function
mod
'gnc:suspend-gui-refresh
@ -301,6 +325,14 @@ determines formatting details.")
'((<gnc:commodity*> currency))
"Check if a given currency is a EURO currency")
(gw:wrap-function
mod
'gnc:is-euro-currency-code
'<gw:bool>
"gnc_is_euro_currency_code"
'((<gw:m-chars-caller-owned> gw:const))
"Check if a given currency is a EURO currency")
(gw:wrap-function
mod
'gnc:convert-to-euro

View File

@ -255,7 +255,8 @@
(define (scm->currency currency)
(if (string? currency)
(gnc:commodity-table-lookup
(gnc:engine-commodities) GNC_COMMODITY_NS_ISO currency)
(gnc:book-get-commodity-table (gnc:get-current-book))
GNC_COMMODITY_NS_ISO currency)
currency))
(let* ((value (currency->scm default-value))
@ -279,13 +280,18 @@
default-value)
(define (commodity->scm commodity)
(list 'commodity-scm
(gnc:commodity-get-namespace commodity)
(gnc:commodity-get-mnemonic commodity)))
(if (string? commodity)
(list 'commodity-scm
GNC_COMMODITY_NS_ISO
commodity)
(list 'commodity-scm
(gnc:commodity-get-namespace commodity)
(gnc:commodity-get-mnemonic commodity))))
(define (scm->commodity scm)
(gnc:commodity-table-lookup
(gnc:engine-commodities) (cadr scm) (caddr scm)))
(gnc:book-get-commodity-table (gnc:get-current-book))
(cadr scm) (caddr scm)))
(let* ((value (commodity->scm default-value))
(value->string (lambda ()

View File

@ -158,7 +158,7 @@
(gnc:make-currency-option
(N_ "International") (N_ "Default Currency")
"b" (N_ "Default currency for new accounts")
(gnc:locale-default-currency)))
(gnc:locale-default-iso-currency-code)))
(gnc:register-configuration-option
(gnc:make-simple-boolean-option
@ -169,7 +169,7 @@
(gnc:make-simple-boolean-option
(N_ "International") (N_ "Enable EURO support")
"d" (N_ "Enables support for the European Union EURO currency")
(gnc:is-euro-currency (gnc:default-currency))))
(gnc:is-euro-currency-code (gnc:locale-default-iso-currency-code))))
;;; Register options

View File

@ -14,7 +14,7 @@ libgncmod_backend_file_la_SOURCES = \
gnc-backend-file.c \
gnc-commodity-xml-v2.c \
gnc-freqspec-xml-v2.c \
gnc-pricedb-xml-v1.c \
gnc-pricedb-xml-v2.c \
gnc-schedxaction-xml-v2.c \
gnc-transaction-xml-v2.c \
io-example-account.c \

View File

@ -39,6 +39,7 @@
#include "gnc-xml.h"
#include "io-gncxml-gen.h"
#include "io-gncxml-v2.h"
#include "sixtp-dom-parsers.h"
#include "AccountP.h"
@ -71,10 +72,11 @@ gnc_account_dom_tree_create(Account *act)
ret = xmlNewNode(NULL, gnc_account_string);
xmlSetProp(ret, "version", account_version_string);
xmlAddChild(ret, text_to_dom_tree(act_name_string, xaccAccountGetName(act)));
xmlAddChild(ret, text_to_dom_tree(act_name_string,
xaccAccountGetName(act)));
xmlAddChild(ret, guid_to_dom_tree(act_id_string, xaccAccountGetGUID(act)));
xmlAddChild(ret, text_to_dom_tree(
act_type_string,
xaccAccountTypeEnumAsString(xaccAccountGetType(act))));
@ -121,6 +123,12 @@ gnc_account_dom_tree_create(Account *act)
/***********************************************************************/
struct account_pdata
{
Account *account;
GNCSession *session;
};
static gboolean
set_string(xmlNodePtr node, Account* act,
void (*func)(Account *act, const gchar *txt))
@ -136,18 +144,21 @@ set_string(xmlNodePtr node, Account* act,
}
static gboolean
account_name_handler (xmlNodePtr node, gpointer act)
account_name_handler (xmlNodePtr node, gpointer act_pdata)
{
return set_string(node, (Account*)act, xaccAccountSetName);
struct account_pdata *pdata = act_pdata;
return set_string(node, pdata->account, xaccAccountSetName);
}
static gboolean
account_id_handler (xmlNodePtr node, gpointer act)
account_id_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
GUID *guid;
guid = dom_tree_to_guid(node);
xaccAccountSetGUID((Account*)act, guid);
xaccAccountSetGUID(pdata->account, guid);
g_free(guid);
@ -155,8 +166,9 @@ account_id_handler (xmlNodePtr node, gpointer act)
}
static gboolean
account_type_handler (xmlNodePtr node, gpointer act)
account_type_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
int type;
char *string;
@ -164,87 +176,101 @@ account_type_handler (xmlNodePtr node, gpointer act)
xaccAccountStringToType(string, &type);
xmlFree (string);
xaccAccountSetType((Account*)act, type);
xaccAccountSetType(pdata->account, type);
return TRUE;
}
static gboolean
account_commodity_handler (xmlNodePtr node, gpointer act)
account_commodity_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gnc_commodity *ref;
ref = dom_tree_to_commodity_ref_no_engine(node);
xaccAccountSetCommodity((Account*)act, ref);
xaccAccountSetCommodity(pdata->account, ref);
return TRUE;
}
static gboolean
account_commodity_scu_handler (xmlNodePtr node, gpointer act)
account_commodity_scu_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gint64 val;
dom_tree_to_integer(node, &val);
xaccAccountSetCommoditySCU((Account*)act, val);
xaccAccountSetCommoditySCU(pdata->account, val);
return TRUE;
}
static gboolean
account_currency_handler (xmlNodePtr node, gpointer act)
account_currency_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gnc_commodity *ref;
ref = dom_tree_to_commodity_ref_no_engine(node);
DxaccAccountSetCurrency((Account*)act, ref);
DxaccAccountSetCurrency(pdata->account, ref, pdata->session);
return TRUE;
}
static gboolean
account_currency_scu_handler (xmlNodePtr node, gpointer act)
account_currency_scu_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gint64 val;
dom_tree_to_integer(node, &val);
DxaccAccountSetCurrencySCU((Account*)act, val);
DxaccAccountSetCurrencySCU(pdata->account, val);
return TRUE;
}
static gboolean
account_security_handler (xmlNodePtr node, gpointer act)
account_security_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gnc_commodity *ref;
ref = dom_tree_to_commodity_ref_no_engine(node);
DxaccAccountSetSecurity((Account*)act, ref);
DxaccAccountSetSecurity(pdata->account, ref, pdata->session);
return TRUE;
}
static gboolean
account_security_scu_handler (xmlNodePtr node, gpointer act)
account_security_scu_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gint64 val;
dom_tree_to_integer(node, &val);
xaccAccountSetCommoditySCU((Account*)act, val);
xaccAccountSetCommoditySCU(pdata->account, val);
return TRUE;
}
static gboolean
account_slots_handler (xmlNodePtr node, gpointer act)
account_slots_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
gboolean success;
success = dom_tree_to_kvp_frame_given (node, xaccAccountGetSlots (act));
success = dom_tree_to_kvp_frame_given
(node, xaccAccountGetSlots (pdata->account));
g_return_val_if_fail(success, FALSE);
return TRUE;
}
static gboolean
account_parent_handler (xmlNodePtr node, gpointer act)
account_parent_handler (xmlNodePtr node, gpointer act_pdata)
{
struct account_pdata *pdata = act_pdata;
Account *parent;
GUID *gid;
@ -258,7 +284,7 @@ account_parent_handler (xmlNodePtr node, gpointer act)
g_return_val_if_fail(parent, FALSE);
}
xaccAccountInsertSubAccount(parent, (Account*)act);
xaccAccountInsertSubAccount(parent, pdata->account);
g_free (gid);
@ -266,15 +292,19 @@ account_parent_handler (xmlNodePtr node, gpointer act)
}
static gboolean
account_code_handler(xmlNodePtr node, gpointer act)
account_code_handler(xmlNodePtr node, gpointer act_pdata)
{
return set_string(node, (Account*)act, xaccAccountSetCode);
struct account_pdata *pdata = act_pdata;
return set_string(node, pdata->account, xaccAccountSetCode);
}
static gboolean
account_description_handler(xmlNodePtr node, gpointer act)
account_description_handler(xmlNodePtr node, gpointer act_pdata)
{
return set_string(node, (Account*)act, xaccAccountSetDescription);
struct account_pdata *pdata = act_pdata;
return set_string(node, pdata->account, xaccAccountSetDescription);
}
static struct dom_tree_handler account_handlers_v2[] = {
@ -305,7 +335,8 @@ gnc_account_end_handler(gpointer data_for_children,
xmlNodePtr achild;
xmlNodePtr tree = (xmlNodePtr)data_for_children;
gxpf_data *gdata = (gxpf_data*)global_data;
GNCSession *session = gdata->sessiondata;
successful = TRUE;
if(parent_data)
@ -319,13 +350,13 @@ gnc_account_end_handler(gpointer data_for_children,
{
return TRUE;
}
g_return_val_if_fail(tree, FALSE);
acc = dom_tree_to_account(tree);
acc = dom_tree_to_account(tree, session);
if(acc != NULL)
{
gdata->cb(tag, gdata->data, acc);
gdata->cb(tag, gdata->parsedata, acc);
/*
* Now return the account to the "edit" state. At the end of reading
* all the transactions, we will Commit. This replaces #splits
@ -333,28 +364,35 @@ gnc_account_end_handler(gpointer data_for_children,
*/
xaccAccountBeginEdit(acc);
}
xmlFreeNode(tree);
return acc != NULL;
}
Account*
dom_tree_to_account( xmlNodePtr node )
dom_tree_to_account (xmlNodePtr node, GNCSession * session)
{
struct account_pdata act_pdata;
Account *accToRet;
gboolean successful;
accToRet = xaccMallocAccount();
xaccAccountBeginEdit(accToRet);
successful = dom_tree_generic_parse( node, account_handlers_v2, accToRet );
xaccAccountCommitEdit( accToRet );
if ( !successful ) {
xaccFreeAccount( accToRet );
act_pdata.account = accToRet;
act_pdata.session = session;
successful = dom_tree_generic_parse (node, account_handlers_v2,
&act_pdata);
xaccAccountCommitEdit (accToRet);
if (!successful)
{
xaccAccountDestroy (accToRet);
accToRet = NULL;
}
return accToRet;
}

View File

@ -193,7 +193,7 @@ gnc_commodity_end_handler(gpointer data_for_children,
return FALSE;
}
gdata->cb(tag, gdata->data, com);
gdata->cb(tag, gdata->parsedata, com);
xmlFreeNode(tree);

View File

@ -87,7 +87,7 @@ static short module = MOD_ENGINE;
*/
static gboolean
price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node)
price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node, GNCSession *session)
{
if(!p || !sub_node) return FALSE;
@ -98,11 +98,11 @@ price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node)
gnc_price_set_guid(p, c);
g_free(c);
} else if(safe_strcmp("price:commodity", sub_node->name) == 0) {
gnc_commodity *c = dom_tree_to_commodity_ref(sub_node);
gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, session);
if(!c) return FALSE;
gnc_price_set_commodity(p, c);
} else if(safe_strcmp("price:currency", sub_node->name) == 0) {
gnc_commodity *c = dom_tree_to_commodity_ref(sub_node);
gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, session);
if(!c) return FALSE;
gnc_price_set_currency(p, c);
} else if(safe_strcmp("price:time", sub_node->name) == 0) {
@ -143,6 +143,8 @@ price_parse_xml_end_handler(gpointer data_for_children,
xmlNodePtr price_xml = (xmlNodePtr) data_for_children;
xmlNodePtr child;
GNCPrice *p = NULL;
gxpf_data *gdata = global_data;
GNCSession *session = gdata->sessiondata;
/* we haven't been handed the *top* level node yet... */
if(parent_data) return TRUE;
@ -153,7 +155,7 @@ price_parse_xml_end_handler(gpointer data_for_children,
if(price_xml->next) { ok = FALSE; goto cleanup_and_exit; }
if(price_xml->prev) { ok = FALSE; goto cleanup_and_exit; }
if(!price_xml->xmlChildrenNode) { ok = FALSE; goto cleanup_and_exit; }
p = gnc_price_create();
if(!p) { ok = FALSE; goto cleanup_and_exit; }
@ -162,7 +164,7 @@ price_parse_xml_end_handler(gpointer data_for_children,
case XML_COMMENT_NODE:
break;
case XML_ELEMENT_NODE:
if(!price_parse_xml_sub_node(p, child)) {
if(!price_parse_xml_sub_node(p, child, session)) {
ok = FALSE;
goto cleanup_and_exit;
}
@ -296,15 +298,13 @@ pricedb_v2_end_handler(
return TRUE;
}
gdata->cb(tag, gdata->data, db);
gdata->cb(tag, gdata->parsedata, db);
*result = NULL;
return TRUE;
}
sixtp* gnc_pricedb_parser_new(void);
sixtp*
static sixtp*
gnc_pricedb_parser_new(void)
{
sixtp *top_level;
@ -319,17 +319,18 @@ gnc_pricedb_parser_new(void)
SIXTP_RESULT_FAIL_ID, pricedb_cleanup_result_handler,
SIXTP_CLEANUP_RESULT_ID, pricedb_cleanup_result_handler,
SIXTP_NO_MORE_HANDLERS);
if(!top_level) return NULL;
price_parser = gnc_price_parser_new();
if(!price_parser) {
sixtp_destroy(top_level);
return NULL;
}
sixtp_add_sub_parser(top_level, "price", price_parser);
return top_level;
}

View File

@ -439,7 +439,7 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
successful = dom_tree_generic_parse( tree, sx_dom_handlers, sx );
if ( successful ) {
gdata->cb( tag, gdata->data, sx );
gdata->cb( tag, gdata->parsedata, sx );
} else {
xmlElemDump( stdout, NULL, tree );
xaccSchedXactionFree( sx );
@ -451,13 +451,17 @@ gnc_schedXaction_end_handler(gpointer data_for_children,
AccountGroup *ag = NULL;
char *id = NULL;
Account *acct = NULL;
sixtp_gdv2 *sixdata = gdata->parsedata;
GNCBook *book;
book = gnc_session_get_book (sixdata->session);
/* We're dealing with a pre-200107<near-end-of-month> rgmerk
change re: storing template accounts. */
/* Fix: get account with name of our GUID from the template
accounts group. Make that our template_acct pointer. */
id = guid_to_string( xaccSchedXactionGetGUID( sx ) );
ag = gnc_book_get_template_group( ((sixtp_gdv2*)gdata->data)->book );
ag = gnc_book_get_template_group(book);
if ( ag == NULL )
{
PERR( "Error getting template account group from being-parsed Book." );
@ -502,7 +506,7 @@ tt_act_handler( xmlNodePtr node, gpointer data )
Account *acc;
gnc_commodity *com;
acc = dom_tree_to_account( node );
acc = dom_tree_to_account(node, txd->session);
if ( acc == NULL ) {
return FALSE;
@ -556,17 +560,24 @@ struct dom_tree_handler tt_dom_handlers[] = {
static gboolean
gnc_template_transaction_end_handler(gpointer data_for_children,
GSList* data_from_children, GSList* sibling_data,
gpointer parent_data, gpointer global_data,
gpointer *result, const gchar *tag)
GSList* data_from_children,
GSList* sibling_data,
gpointer parent_data,
gpointer global_data,
gpointer *result,
const gchar *tag)
{
gboolean successful = FALSE;
xmlNodePtr achild;
xmlNodePtr tree = (xmlNodePtr)data_for_children;
gxpf_data *gdata = (gxpf_data*)global_data;
GList *n;
gnc_template_xaction_data *txd =
g_new0( gnc_template_xaction_data, 1 );
gboolean successful = FALSE;
xmlNodePtr achild;
xmlNodePtr tree = data_for_children;
gxpf_data *gdata = global_data;
GNCSession *session = gdata->sessiondata;
GList *n;
gnc_template_xaction_data *txd;
txd = g_new0 (gnc_template_xaction_data, 1);
txd->session = session;
/* the DOM tree will have an account tree [the template group
and account] and a list of transactions [which will be
@ -589,7 +600,7 @@ gnc_template_transaction_end_handler(gpointer data_for_children,
successful = dom_tree_generic_parse( tree, tt_dom_handlers, txd );
if ( successful ) {
gdata->cb( tag, gdata->data, txd );
gdata->cb( tag, gdata->parsedata, txd );
} else {
xmlElemDump( stdout, NULL, tree );
}

View File

@ -502,7 +502,7 @@ gnc_transaction_end_handler(gpointer data_for_children,
trn = dom_tree_to_transaction(tree);
if(trn != NULL)
{
gdata->cb(tag, gdata->data, trn);
gdata->cb(tag, gdata->parsedata, trn);
successful = TRUE;
}

View File

@ -53,26 +53,6 @@
#define GNC_ACCOUNT_LONG "gnc-act:long-description"
#define GNC_ACCOUNT_TITLE "gnc-act:title"
GncExampleAccount*
gnc_create_example_account(AccountGroup *grp,
const char *title,
const char *filename,
const char *short_descrip,
const char *long_descrip)
{
GncExampleAccount *ret;
ret = g_new0(GncExampleAccount, 1);
ret->title = g_strdup(title);
ret->filename = g_strdup(filename);
ret->group = grp;
ret->short_description = g_strdup(short_descrip);
ret->long_description = g_strdup(long_descrip);
return ret;
}
void
gnc_destroy_example_account(GncExampleAccount *gea)
{
@ -107,6 +87,48 @@ gnc_destroy_example_account(GncExampleAccount *gea)
g_free(gea);
}
static void
clear_up_account_commodity_session(
GNCSession *session, Account *act,
gnc_commodity * (*getter) (Account *account, GNCSession *session),
void (*setter) (Account *account, gnc_commodity *comm,
GNCSession *session))
{
gnc_commodity_table *tbl;
gnc_commodity *gcom;
gnc_commodity *com;
tbl = gnc_book_get_commodity_table (gnc_session_get_book (session));
com = getter (act, session);
if(!com)
{
return;
}
g_return_if_fail (tbl != NULL);
gcom = gnc_commodity_table_lookup(tbl,
gnc_commodity_get_namespace(com),
gnc_commodity_get_mnemonic(com));
if(gcom == com)
{
return;
}
else if(!gcom)
{
g_warning("unable to find global commodity for %s adding new",
gnc_commodity_get_unique_name(com));
gnc_commodity_table_insert(tbl, com);
}
else
{
gnc_commodity_destroy(com);
setter(act, gcom, session);
}
}
static void
clear_up_account_commodity(
gnc_commodity_table *tbl, Account *act,
@ -120,8 +142,11 @@ clear_up_account_commodity(
{
return;
}
gcom = gnc_commodity_table_lookup(tbl, gnc_commodity_get_namespace(com),
g_return_if_fail (tbl != NULL);
gcom = gnc_commodity_table_lookup(tbl,
gnc_commodity_get_namespace(com),
gnc_commodity_get_mnemonic(com));
if(gcom == com)
@ -144,16 +169,24 @@ clear_up_account_commodity(
static void
add_account_local(GncExampleAccount *gea, Account *act)
{
clear_up_account_commodity(gnc_engine_commodities(), act,
DxaccAccountGetCurrency, DxaccAccountSetCurrency);
clear_up_account_commodity(gnc_engine_commodities(), act,
DxaccAccountGetSecurity, DxaccAccountSetSecurity);
clear_up_account_commodity(gnc_engine_commodities(), act,
xaccAccountGetCommodity, xaccAccountSetCommodity);
gnc_commodity_table *table;
xaccAccountScrubCommodity (act);
table = gnc_book_get_commodity_table (gnc_session_get_book (gea->session));
if(!xaccAccountGetParent(act))
clear_up_account_commodity_session(gea->session, act,
DxaccAccountGetCurrency,
DxaccAccountSetCurrency);
clear_up_account_commodity_session(gea->session, act,
DxaccAccountGetSecurity,
DxaccAccountSetSecurity);
clear_up_account_commodity(table, act,
xaccAccountGetCommodity,
xaccAccountSetCommodity);
xaccAccountScrubCommodity (act, gea->session);
if (!xaccAccountGetParent(act))
{
xaccGroupInsertAccount(gea->group, act);
}
@ -205,7 +238,7 @@ gnc_short_descrip_end_handler(gpointer data_for_children,
gpointer *result, const gchar *tag)
{
GncExampleAccount *gea =
(GncExampleAccount*)((gxpf_data*)global_data)->data;
(GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
gea->short_description = grab_clean_string((xmlNodePtr)data_for_children);
@ -225,7 +258,7 @@ gnc_long_descrip_end_handler(gpointer data_for_children,
gpointer *result, const gchar *tag)
{
GncExampleAccount *gea =
(GncExampleAccount*)((gxpf_data*)global_data)->data;
(GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
gea->long_description = grab_clean_string((xmlNodePtr)data_for_children);
@ -245,7 +278,7 @@ gnc_title_end_handler(gpointer data_for_children,
gpointer *result, const gchar *tag)
{
GncExampleAccount *gea =
(GncExampleAccount*)((gxpf_data*)global_data)->data;
(GncExampleAccount*)((gxpf_data*)global_data)->parsedata;
gea->title = grab_clean_string((xmlNodePtr)data_for_children);
@ -260,17 +293,20 @@ gnc_titse_sixtp_parser_create(void)
GncExampleAccount*
gnc_read_example_account(const gchar *filename)
gnc_read_example_account(GNCSession *session, const gchar *filename)
{
GncExampleAccount *gea;
sixtp *top_parser;
sixtp *main_parser;
g_return_val_if_fail (session != NULL, NULL);
gea = g_new0(GncExampleAccount, 1);
gea->session = session;
gea->filename = g_strdup(filename);
gea->group = xaccMallocAccountGroup();
top_parser = sixtp_new();
main_parser = sixtp_new();
@ -293,7 +329,8 @@ gnc_read_example_account(const gchar *filename)
return FALSE;
}
if(!gnc_xml_parse_file(top_parser, filename, generic_callback, gea))
if(!gnc_xml_parse_file(top_parser, filename,
generic_callback, gea, session))
{
sixtp_destroy(top_parser);
xaccLogEnable ();
@ -380,7 +417,7 @@ is_directory(const gchar *filename)
}
GSList*
gnc_load_example_account_list(const char *dirname)
gnc_load_example_account_list(GNCSession *session, const char *dirname)
{
GSList *ret;
DIR *dir;
@ -403,7 +440,7 @@ gnc_load_example_account_list(const char *dirname)
if(!is_directory(filename))
{
gea = gnc_read_example_account(filename);
gea = gnc_read_example_account(session, filename);
if(gea == NULL)
{

View File

@ -28,33 +28,32 @@
#include <glib.h>
#include "sixtp.h"
#include "Group.h"
#include "gnc-session.h"
struct GncExampleAccount_struct
{
gchar *title;
gchar *filename;
GNCSession *session;
AccountGroup *group;
gchar *short_description;
gchar *long_description;
};
typedef struct GncExampleAccount_struct GncExampleAccount;
GncExampleAccount* gnc_create_example_account(
AccountGroup *grp, const char *title, const char *filename,
const char *short_descrip, const char *long_descrip);
void gnc_destroy_example_account(GncExampleAccount *gea);
gboolean gnc_write_example_account(GncExampleAccount *gea,
const gchar *filename);
GncExampleAccount *gnc_read_example_account(const gchar *filename);
GncExampleAccount *gnc_read_example_account(GNCSession *session,
const gchar *filename);
gboolean gnc_is_xml_data_file_v2(const gchar *filename);
void gnc_free_example_account_list(GSList *list);
GSList* gnc_load_example_account_list(const char *dirname);
GSList* gnc_load_example_account_list(GNCSession *session,
const char *dirname);
gboolean gnc_is_example_account_xml(const gchar *name);

View File

@ -197,7 +197,8 @@ mark_potential_quote(Split *s, double price, double quantity)
}
static gboolean
cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices)
cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices,
GNCSession *session)
{
GSList *item = potential_quotes;
@ -220,8 +221,10 @@ cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices)
Timespec time = xaccTransRetDatePostedTS(txn);
gnc_price_begin_edit(price);
gnc_price_set_commodity(price, DxaccAccountGetSecurity(split_acct));
gnc_price_set_currency(price, DxaccAccountGetCurrency(split_acct));
gnc_price_set_commodity(price,
DxaccAccountGetSecurity(split_acct, session));
gnc_price_set_currency(price,
DxaccAccountGetCurrency(split_acct, session));
gnc_price_set_time(price, time);
gnc_price_set_source(price, "old-file-import");
gnc_price_set_type(price, "unknown");
@ -249,8 +252,9 @@ cvt_potential_prices_to_pricedb_and_cleanup(GNCPriceDB **prices)
/** PROTOTYPES ******************************************************/
static Account *locateAccount (int acc_id);
static AccountGroup *readGroup( int fd, Account *, int token );
static Account *readAccount( int fd, AccountGroup *, int token );
static AccountGroup *readGroup( GNCSession *, int fd, Account *, int token );
static Account *readAccount( GNCSession *session, int fd,
AccountGroup *, int token );
static gboolean readAccInfo( int fd, Account *, int token );
static Transaction *readTransaction( int fd, Account *, int token );
static Split *readSplit( int fd, int token );
@ -367,11 +371,17 @@ xaccFlipLongLong (gint64 val)
********************************************************************/
static gnc_commodity *
gnc_commodity_import_legacy(const char * currency_name) {
gnc_commodity_import_legacy(GNCSession *session, const char * currency_name)
{
gnc_commodity_table *table;
gnc_commodity * old = NULL;
table = gnc_book_get_commodity_table (gnc_session_get_book (session));
g_return_val_if_fail (table != NULL, NULL);
if(currency_name && (currency_name[0] != 0) ) {
old = gnc_commodity_table_lookup(gnc_engine_commodities(),
old = gnc_commodity_table_lookup(table,
GNC_COMMODITY_NS_LEGACY,
currency_name);
@ -379,7 +389,7 @@ gnc_commodity_import_legacy(const char * currency_name) {
old = gnc_commodity_new(currency_name,
GNC_COMMODITY_NS_LEGACY, currency_name,
0, 100000);
old = gnc_commodity_table_insert(gnc_engine_commodities(), old);
old = gnc_commodity_table_insert(table, old);
}
return old;
}
@ -401,12 +411,15 @@ gnc_commodity_import_legacy(const char * currency_name) {
* Return: the struct with the program data in it *
\********************************************************************/
static gboolean
gnc_load_financials_from_fd(GNCBook *book, int fd)
gnc_load_financials_from_fd(GNCSession *session, int fd)
{
int err=0;
int token=0;
int num_unclaimed;
AccountGroup *grp = 0x0;
GNCBook *book;
book = gnc_session_get_book (session);
maingrp = 0x0;
error_code = ERR_BACKEND_NO_ERR;
@ -463,7 +476,7 @@ gnc_load_financials_from_fd(GNCBook *book, int fd)
/* disable logging during load; otherwise its just a mess */
xaccLogDisable();
holder = xaccMallocAccountGroup();
grp = readGroup (fd, NULL, token);
grp = readGroup (session, fd, NULL, token);
/* the number of unclaimed accounts should be zero if the
* read succeeded. But just in case of a very unlikely
@ -493,7 +506,8 @@ gnc_load_financials_from_fd(GNCBook *book, int fd)
{
GNCPriceDB *tmpdb;
if(cvt_potential_prices_to_pricedb_and_cleanup(&tmpdb)) {
if(cvt_potential_prices_to_pricedb_and_cleanup(&tmpdb, session))
{
GNCPriceDB *db = gnc_book_get_pricedb(book);
gnc_book_set_pricedb(book, tmpdb);
if(db) gnc_pricedb_destroy(db);
@ -546,7 +560,7 @@ gnc_session_load_from_binfile(GNCSession *session)
return;
}
if (!gnc_load_financials_from_fd(gnc_session_get_book (session), fd))
if (!gnc_load_financials_from_fd(session, fd))
return;
close(fd);
@ -560,7 +574,7 @@ gnc_session_load_from_binfile(GNCSession *session)
* Return: the struct with the program data in it *
\********************************************************************/
static AccountGroup *
readGroup (int fd, Account *aparent, int token)
readGroup (GNCSession *session, int fd, Account *aparent, int token)
{
int numAcc;
int err=0;
@ -587,7 +601,7 @@ readGroup (int fd, Account *aparent, int token)
/* read in the accounts */
for( i=0; i<numAcc; i++ )
{
Account * acc = readAccount( fd, grp, token );
Account * acc = readAccount( session, fd, grp, token );
if( NULL == acc ) {
PERR("Short group read: \n"
"\texpected %d, got %d accounts\n",numAcc,i);
@ -608,13 +622,14 @@ readGroup (int fd, Account *aparent, int token)
* readAccount *
* reads in the data for an account from the datafile *
* *
* Args: fd - the filedescriptor of the data file *
* Args: session - the session *
* fd - the filedescriptor of the data file *
* acc - the account structure to be filled in *
* token - the datafile version *
* Return: error value, 0 if OK, else -1 *
\********************************************************************/
static Account *
readAccount( int fd, AccountGroup *grp, int token )
readAccount( GNCSession *session, int fd, AccountGroup *grp, int token )
{
int err=0;
int i;
@ -625,7 +640,7 @@ readAccount( int fd, AccountGroup *grp, int token )
char * tmp;
ENTER (" ");
/* version 1 does not store the account number */
if (1 < token) {
err = read( fd, &accID, sizeof(int) );
@ -705,8 +720,8 @@ readAccount( int fd, AccountGroup *grp, int token )
if( NULL == tmp ) return NULL;
PINFO ("currency is %s", tmp);
currency = gnc_commodity_import_legacy(tmp);
DxaccAccountSetCurrency (acc, currency);
currency = gnc_commodity_import_legacy(session, tmp);
DxaccAccountSetCurrency (acc, currency, session);
if(tmp) free (tmp);
@ -730,15 +745,15 @@ readAccount( int fd, AccountGroup *grp, int token )
}
PINFO ("security is %s", tmp);
security = gnc_commodity_import_legacy(tmp);
DxaccAccountSetSecurity (acc, security);
security = gnc_commodity_import_legacy(session, tmp);
DxaccAccountSetSecurity (acc, security, session);
if(tmp) free (tmp);
}
else {
/* set the default currency when importing old files */
currency = gnc_commodity_import_legacy(DEFAULT_CURRENCY);
DxaccAccountSetCurrency (acc, currency);
currency = gnc_commodity_import_legacy(session, DEFAULT_CURRENCY);
DxaccAccountSetCurrency (acc, currency, session);
}
/* aux account info first appears in version ten files */
@ -782,7 +797,7 @@ readAccount( int fd, AccountGroup *grp, int token )
}
XACC_FLIP_INT (numGrps);
if (numGrps) {
readGroup (fd, acc, token);
readGroup (session, fd, acc, token);
}
}

View File

@ -28,14 +28,16 @@
gboolean
gnc_xml_parse_file(sixtp *top_parser, const char *filename,
gxpf_callback callback, gpointer data)
gxpf_callback callback, gpointer parsedata,
gpointer sessiondata)
{
gpointer parse_result = NULL;
gxpf_data gpdata;
gpdata.cb = callback;
gpdata.data = data;
gpdata.parsedata = parsedata;
gpdata.sessiondata = sessiondata;
return sixtp_parse_file(top_parser, filename,
NULL, &gpdata, &parse_result);
}

View File

@ -28,19 +28,21 @@
#include <glib.h>
#include "sixtp.h"
typedef gboolean (*gxpf_callback)(const char *tag, gpointer globaldata,
typedef gboolean (*gxpf_callback)(const char *tag, gpointer parsedata,
gpointer data);
struct gxpf_data_struct
{
gxpf_callback cb;
gpointer data;
gpointer parsedata;
gpointer sessiondata;
};
typedef struct gxpf_data_struct gxpf_data;
gboolean
gnc_xml_parse_file(sixtp *top_parser, const char *filename,
gxpf_callback callback, gpointer data);
gxpf_callback callback, gpointer parsedata,
gpointer sessiondata);
#endif /* IO_GNCXML_GEN_H */

View File

@ -46,33 +46,34 @@
#include "io-gncxml.h"
#include "sixtp.h"
#include "sixtp-dom-parsers.h"
#include "sixtp-stack.h"
#include "sixtp-parsers.h"
#include "sixtp-utils.h"
/* from Transaction-xml-parser-v1.c */
sixtp* gnc_transaction_parser_new(void);
static sixtp* gnc_transaction_parser_new(void);
/* from Account-xml-parser-v1.c */
sixtp* gnc_account_parser_new(void);
static sixtp* gnc_account_parser_new(void);
/* from Ledger-xml-parser-v1.c */
sixtp* ledger_data_parser_new(void);
static sixtp* ledger_data_parser_new(void);
/* from Commodity-xml-parser-v1.c */
sixtp* commodity_restore_parser_new(void);
static sixtp* commodity_restore_parser_new(void);
/* from Commodity-xml-parser-v1.c */
sixtp* generic_gnc_commodity_lookup_parser_new(void);
static sixtp* generic_gnc_commodity_lookup_parser_new(void);
/* from Query-xml-parser-v1.c */
sixtp* query_server_parser_new (void);
static sixtp* query_server_parser_new (void);
/* from sixtp-kvp-parser.c */
sixtp* kvp_frame_parser_new(void);
static sixtp* kvp_frame_parser_new(void);
/* from gnc-pricedb-xml-v1.c */
sixtp* gnc_pricedb_parser_new(void);
static sixtp* gnc_pricedb_parser_new(void);
typedef enum {
@ -89,6 +90,9 @@ typedef struct {
after we see the file version. */
sixtp *gnc_parser;
/* The session */
GNCSession *session;
/* The account group */
AccountGroup *account_group;
@ -97,10 +101,11 @@ typedef struct {
/* The query */
Query *query;
GNCParseErr error;
} GNCParseStatus;
/* result for a characters handler is shared across all character
handlers for a given node. result for start/end pair is shared as
well.
@ -352,6 +357,8 @@ gnc_session_load_from_xml_file(GNCSession *session)
const gchar *filename;
GNCBook *book;
global_parse_status.session = session;
book = gnc_session_get_book (session);
g_return_val_if_fail(session, FALSE);
@ -401,7 +408,7 @@ gnc_session_load_from_xml_file(GNCSession *session)
}
/* Fix account and transaction commodities */
xaccGroupScrubCommodities (gnc_book_get_group(book));
xaccGroupScrubCommodities (gnc_book_get_group(book), session);
/* Fix split amount/value */
xaccGroupScrubSplits (gnc_book_get_group(book));
@ -1059,7 +1066,7 @@ kvp_frame_result_cleanup(sixtp_child_result *cr)
if(f) kvp_frame_delete(f);
}
sixtp*
static sixtp*
kvp_frame_parser_new(void)
{
sixtp *top_level;
@ -1209,7 +1216,7 @@ ledger_data_result_cleanup(sixtp_child_result *cr)
}
sixtp*
static sixtp*
ledger_data_parser_new(void)
{
sixtp *top_level;
@ -1373,7 +1380,10 @@ account_restore_after_child_handler(gpointer data_for_children,
sixtp_child_result *child_result)
{
Account *a = (Account *) data_for_children;
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
g_return_val_if_fail(a, FALSE);
if(!child_result) return(TRUE);
if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(TRUE);
if(strcmp(child_result->tag, "slots") == 0) {
@ -1386,15 +1396,15 @@ account_restore_after_child_handler(gpointer data_for_children,
else if(strcmp(child_result->tag, "currency") == 0) {
gnc_commodity *com = (gnc_commodity *) child_result->data;
g_return_val_if_fail(com, FALSE);
if(DxaccAccountGetCurrency(a)) return FALSE;
DxaccAccountSetCurrency(a, com);
if(DxaccAccountGetCurrency(a, pstatus->session)) return FALSE;
DxaccAccountSetCurrency(a, com, pstatus->session);
/* let the normal child_result handler clean up com */
}
else if(strcmp(child_result->tag, "security") == 0) {
gnc_commodity *com = (gnc_commodity *) child_result->data;
g_return_val_if_fail(com, FALSE);
if(DxaccAccountGetSecurity(a)) return FALSE;
DxaccAccountSetSecurity(a, com);
if(DxaccAccountGetSecurity(a, pstatus->session)) return FALSE;
DxaccAccountSetSecurity(a, com, pstatus->session);
/* let the normal child_result handler clean up com */
}
@ -1725,7 +1735,7 @@ parent_lookup_parser_new(void)
SIXTP_NO_MORE_HANDLERS);
}
sixtp *
static sixtp *
gnc_account_parser_new(void)
{
sixtp *restore_pr;
@ -1848,7 +1858,8 @@ commodity_restore_start_handler(GSList* sibling_data, gpointer parent_data,
gpointer *data_for_children, gpointer *result,
const gchar *tag, gchar **attrs)
{
CommodityParseInfo *cpi = (CommodityParseInfo *) g_new0(CommodityParseInfo, 1);
CommodityParseInfo *cpi =
(CommodityParseInfo *) g_new0(CommodityParseInfo, 1);
g_return_val_if_fail(cpi, FALSE);
@ -1910,6 +1921,7 @@ commodity_restore_end_handler(gpointer data_for_children,
gpointer *result, const gchar *tag)
{
CommodityParseInfo *cpi = (CommodityParseInfo *) data_for_children;
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
gboolean ok = FALSE;
gnc_commodity *comm = NULL;
@ -1928,9 +1940,15 @@ commodity_restore_end_handler(gpointer data_for_children,
cpi->id,
cpi->xcode,
cpi->fraction);
if(comm) {
gnc_commodity_table *ctab = gnc_engine_commodities();
if(ctab) {
if(comm)
{
gnc_commodity_table *ctab;
ctab = gnc_book_get_commodity_table
(gnc_session_get_book (pstatus->session));
if(ctab)
{
gnc_commodity_table_insert(ctab, comm);
ok = TRUE;
}
@ -1949,7 +1967,7 @@ commodity_restore_end_handler(gpointer data_for_children,
}
sixtp *
static sixtp *
commodity_restore_parser_new(void)
{
sixtp *top_level;
@ -2083,15 +2101,20 @@ generic_gnc_commodity_lookup_end_handler(gpointer data_for_children,
{
CommodityLookupParseInfo *cpi =
(CommodityLookupParseInfo *) data_for_children;
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
gboolean ok = FALSE;
g_return_val_if_fail(cpi, FALSE);
if(cpi->namespace && cpi->id) {
gnc_commodity *com =
gnc_commodity_table_lookup(gnc_engine_commodities(),
cpi->namespace,
cpi->id);
gnc_commodity_table *table;
gnc_commodity *com;
table = gnc_book_get_commodity_table
(gnc_session_get_book (pstatus->session));
com = gnc_commodity_table_lookup(table, cpi->namespace, cpi->id);
if(com) {
*result = com;
ok = TRUE;
@ -2101,11 +2124,12 @@ generic_gnc_commodity_lookup_end_handler(gpointer data_for_children,
g_free(cpi->namespace);
g_free(cpi->id);
g_free(cpi);
return(ok);
}
sixtp *
static sixtp *
generic_gnc_commodity_lookup_parser_new(void)
{
sixtp *top_level;
@ -2573,7 +2597,7 @@ qrestore_datepred_parser_new(void)
0);
}
sixtp*
static sixtp*
query_server_parser_new (void)
{
sixtp *top_level;
@ -3425,7 +3449,7 @@ gnc_txn_restore_split_parser_new(void)
/***************************************************************************/
sixtp *
static sixtp *
gnc_transaction_parser_new(void)
{
sixtp *top_level;
@ -3479,4 +3503,272 @@ gnc_transaction_parser_new(void)
return(top_level);
}
/****************************************************************************/
/****************************************************************************/
/* Read and Write the pricedb as XML -- something like this:
<pricedb>
price-1
price-2
...
</pricedb>
where each price should look roughly like this:
<price>
<price:id>
00000000111111112222222233333333
</price:id>
<price:commodity>
<cmdty:space>NASDAQ</cmdty:space>
<cmdty:id>RHAT</cmdty:id>
</price:commodity>
<price:currency>
<cmdty:space>ISO?</cmdty:space>
<cmdty:id>USD</cmdty:id>
</price:currency>
<price:time><ts:date>Mon ...</ts:date><ts:ns>12</ts:ns></price:time>
<price:source>Finance::Quote</price:source>
<price:type>bid</price:type>
<price:value>11011/100</price:value>
</price>
*/
/***********************************************************************/
/* READING */
/***********************************************************************/
/****************************************************************************/
/* <price>
restores a price. Does so via a walk of the XML tree in memory.
Returns a GNCPrice * in result.
Right now, a price is legitimate even if all of it's fields are not
set. We may need to change that later, but at the moment.
*/
static gboolean
price_parse_xml_sub_node(GNCPrice *p, xmlNodePtr sub_node, GNCSession *session)
{
if(!p || !sub_node) return FALSE;
gnc_price_begin_edit (p);
if(safe_strcmp("price:id", sub_node->name) == 0) {
GUID *c = dom_tree_to_guid(sub_node);
if(!c) return FALSE;
gnc_price_set_guid(p, c);
g_free(c);
} else if(safe_strcmp("price:commodity", sub_node->name) == 0) {
gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, session);
if(!c) return FALSE;
gnc_price_set_commodity(p, c);
} else if(safe_strcmp("price:currency", sub_node->name) == 0) {
gnc_commodity *c = dom_tree_to_commodity_ref(sub_node, session);
if(!c) return FALSE;
gnc_price_set_currency(p, c);
} else if(safe_strcmp("price:time", sub_node->name) == 0) {
Timespec *t = dom_tree_to_timespec(sub_node);
if(!t) return FALSE;
gnc_price_set_time(p, *t);
g_free(t);
} else if(safe_strcmp("price:source", sub_node->name) == 0) {
char *text = dom_tree_to_text(sub_node);
if(!text) return FALSE;
gnc_price_set_source(p, text);
g_free(text);
} else if(safe_strcmp("price:type", sub_node->name) == 0) {
char *text = dom_tree_to_text(sub_node);
if(!text) return FALSE;
gnc_price_set_type(p, text);
g_free(text);
} else if(safe_strcmp("price:value", sub_node->name) == 0) {
gnc_numeric *value = dom_tree_to_gnc_numeric(sub_node);
if(!value) return FALSE;
gnc_price_set_value(p, *value);
g_free(value);
}
gnc_price_commit_edit (p);
return TRUE;
}
static gboolean
price_parse_xml_end_handler(gpointer data_for_children,
GSList* data_from_children,
GSList* sibling_data,
gpointer parent_data,
gpointer global_data,
gpointer *result,
const gchar *tag)
{
gboolean ok = TRUE;
xmlNodePtr price_xml = (xmlNodePtr) data_for_children;
xmlNodePtr child;
GNCPrice *p = NULL;
GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
/* we haven't been handed the *top* level node yet... */
if(parent_data) return TRUE;
*result = NULL;
if(!price_xml) return FALSE;
if(price_xml->next) { ok = FALSE; goto cleanup_and_exit; }
if(price_xml->prev) { ok = FALSE; goto cleanup_and_exit; }
if(!price_xml->xmlChildrenNode) { ok = FALSE; goto cleanup_and_exit; }
p = gnc_price_create();
if(!p) { ok = FALSE; goto cleanup_and_exit; }
for(child = price_xml->xmlChildrenNode; child; child = child->next) {
switch(child->type) {
case XML_COMMENT_NODE:
break;
case XML_ELEMENT_NODE:
if(!price_parse_xml_sub_node(p, child, pstatus->session)) {
ok = FALSE;
goto cleanup_and_exit;
}
break;
default:
PERR("Unknown node type (%d) while parsing gnc-price xml.", child->type);
child = NULL;
ok = FALSE;
goto cleanup_and_exit;
break;
}
}
cleanup_and_exit:
if(ok) {
*result = p;
} else {
*result = NULL;
gnc_price_unref(p);
}
xmlFreeNode(price_xml);
return ok;
}
static void
cleanup_gnc_price(sixtp_child_result *result)
{
if(result->data) gnc_price_unref((GNCPrice *) result->data);
}
static sixtp *
gnc_price_parser_new (void)
{
return sixtp_dom_parser_new(price_parse_xml_end_handler,
cleanup_gnc_price,
cleanup_gnc_price);
}
/****************************************************************************/
/* <pricedb> (lineage <ledger-data>)
restores a pricedb. We allocate the new db in the start block, the
children add to it, and it gets returned in result. Note that the
cleanup handler will destroy the pricedb, so the parent needs to
stop that if desired.
result: GNCPriceDB*
start: create new GNCPriceDB*, and leave in *data_for_children.
cleanup-result: destroy GNCPriceDB*
result-fail: destroy GNCPriceDB*
*/
static gboolean
pricedb_start_handler(GSList* sibling_data,
gpointer parent_data,
gpointer global_data,
gpointer *data_for_children,
gpointer *result,
const gchar *tag,
gchar **attrs)
{
GNCPriceDB *db = gnc_pricedb_create();
g_return_val_if_fail(db, FALSE);
*result = db;
return(TRUE);
}
static gboolean
pricedb_after_child_handler(gpointer data_for_children,
GSList* data_from_children,
GSList* sibling_data,
gpointer parent_data,
gpointer global_data,
gpointer *result,
const gchar *tag,
const gchar *child_tag,
sixtp_child_result *child_result)
{
GNCPriceDB *db = (GNCPriceDB *) *result;
g_return_val_if_fail(db, FALSE);
/* right now children have to produce results :> */
if(!child_result) return(FALSE);
if(child_result->type != SIXTP_CHILD_RESULT_NODE) return(FALSE);
if(strcmp(child_result->tag, "price") == 0) {
GNCPrice *p = (GNCPrice *) child_result->data;
g_return_val_if_fail(p, FALSE);
gnc_pricedb_add_price(db, p);
return TRUE;
} else {
return FALSE;
}
return FALSE;
}
static void
pricedb_cleanup_result_handler(sixtp_child_result *result)
{
if(result->data) {
GNCPriceDB *db = (GNCPriceDB *) result->data;
if(db) gnc_pricedb_destroy(db);
result->data = NULL;
}
}
static sixtp*
gnc_pricedb_parser_new(void)
{
sixtp *top_level;
sixtp *price_parser;
top_level =
sixtp_set_any(sixtp_new(), TRUE,
SIXTP_START_HANDLER_ID, pricedb_start_handler,
SIXTP_AFTER_CHILD_HANDLER_ID, pricedb_after_child_handler,
SIXTP_CHARACTERS_HANDLER_ID,
allow_and_ignore_only_whitespace,
SIXTP_RESULT_FAIL_ID, pricedb_cleanup_result_handler,
SIXTP_CLEANUP_RESULT_ID, pricedb_cleanup_result_handler,
SIXTP_NO_MORE_HANDLERS);
if(!top_level) return NULL;
price_parser = gnc_price_parser_new();
if(!price_parser) {
sixtp_destroy(top_level);
return NULL;
}
sixtp_add_sub_parser(top_level, "price", price_parser);
return top_level;
}
/* ======================= END OF FILE ============================== */

View File

@ -57,6 +57,56 @@ run_callback(sixtp_gdv2 *data, const char *type)
}
}
static void
clear_up_account_commodity_session(
GNCSession *session, Account *act,
gnc_commodity * (*getter) (Account *account, GNCSession *session),
void (*setter) (Account *account, gnc_commodity *comm,
GNCSession *session),
int (*scu_getter) (Account *account),
void (*scu_setter) (Account *account, int scu))
{
gnc_commodity_table *tbl;
gnc_commodity *gcom;
gnc_commodity *com;
int old_scu;
tbl = gnc_book_get_commodity_table (gnc_session_get_book (session));
com = getter (act, session);
if (scu_getter)
old_scu = scu_getter(act);
else
old_scu = 0;
if(!com)
{
return;
}
gcom = gnc_commodity_table_lookup(tbl, gnc_commodity_get_namespace(com),
gnc_commodity_get_mnemonic(com));
if (gcom == com)
{
return;
}
else if(!gcom)
{
g_warning("unable to find global commodity for %s adding new",
gnc_commodity_get_unique_name(com));
gnc_commodity_table_insert(tbl, com);
}
else
{
gnc_commodity_destroy(com);
setter(act, gcom, session);
if (old_scu != 0 && scu_setter)
scu_setter(act, old_scu);
}
}
static void
clear_up_account_commodity(
gnc_commodity_table *tbl, Account *act,
@ -140,55 +190,74 @@ clear_up_transaction_commodity(
static gboolean
add_account_local(sixtp_gdv2 *data, Account *act)
{
clear_up_account_commodity(gnc_book_get_commodity_table(data->book), act,
DxaccAccountGetCurrency,
DxaccAccountSetCurrency,
DxaccAccountGetCurrencySCU,
DxaccAccountSetCurrencySCU);
GNCBook *book;
gnc_commodity_table *table;
clear_up_account_commodity(gnc_book_get_commodity_table(data->book), act,
DxaccAccountGetSecurity,
DxaccAccountSetSecurity,
NULL, NULL);
book = gnc_session_get_book (data->session);
table = gnc_book_get_commodity_table (book);
clear_up_account_commodity(gnc_book_get_commodity_table(data->book), act,
clear_up_account_commodity_session(data->session, act,
DxaccAccountGetCurrency,
DxaccAccountSetCurrency,
DxaccAccountGetCurrencySCU,
DxaccAccountSetCurrencySCU);
clear_up_account_commodity_session(data->session, act,
DxaccAccountGetSecurity,
DxaccAccountSetSecurity,
NULL, NULL);
clear_up_account_commodity(table, act,
xaccAccountGetCommodity,
xaccAccountSetCommodity,
xaccAccountGetCommoditySCU,
xaccAccountSetCommoditySCU);
xaccAccountScrubCommodity (act);
xaccAccountScrubCommodity (act, data->session);
if(!xaccAccountGetParent(act))
{
xaccGroupInsertAccount(gnc_book_get_group(data->book), act);
xaccGroupInsertAccount(gnc_book_get_group(book), act);
}
data->counter.accounts_loaded++;
run_callback(data, "account");
return FALSE;
}
static gboolean
add_commodity_local(sixtp_gdv2 *data, gnc_commodity *com)
{
gnc_commodity_table_insert(gnc_book_get_commodity_table(data->book), com);
GNCBook *book;
gnc_commodity_table *table;
book = gnc_session_get_book (data->session);
table = gnc_book_get_commodity_table (book);
gnc_commodity_table_insert(table, com);
data->counter.commodities_loaded++;
run_callback(data, "commodities");
return TRUE;
}
static gboolean
add_transaction_local(sixtp_gdv2 *data, Transaction *trn)
{
int i;
GNCBook *book;
gnc_commodity_table *table;
Split *spl;
int i;
clear_up_transaction_commodity(gnc_book_get_commodity_table(data->book),
trn, xaccTransGetCurrency,
book = gnc_session_get_book (data->session);
table = gnc_book_get_commodity_table (book);
clear_up_transaction_commodity(table, trn,
xaccTransGetCurrency,
xaccTransSetCurrency);
xaccTransScrubCurrency (trn);
xaccTransScrubCurrency (trn, data->session);
for(i = 0, spl = xaccTransGetSplit(trn, i);
spl;
@ -206,9 +275,15 @@ static gboolean
add_schedXaction_local(sixtp_gdv2 *data, SchedXaction *sx)
{
GList *list;
list = gnc_book_get_schedxactions( data->book );
list = g_list_append( list, sx );
gnc_book_set_schedxactions( data->book, list );
GNCBook *book;
book = gnc_session_get_book (data->session);
list = gnc_book_get_schedxactions (book);
list = g_list_append(list, sx);
gnc_book_set_schedxactions(book, list);
return TRUE;
}
@ -219,6 +294,9 @@ add_template_transaction_local( sixtp_gdv2 *data,
GList *n;
Account *tmpAcct;
AccountGroup *acctGroup = NULL;
GNCBook *book;
book = gnc_session_get_book (data->session);
/* expect a struct of: */
/* . template accounts. */
@ -227,7 +305,7 @@ add_template_transaction_local( sixtp_gdv2 *data,
if ( xaccAccountGetParent( (Account*)n->data ) == NULL ) {
/* remove the gnc_book_init-created account of the same name */
acctGroup =
gnc_book_get_template_group( data->book );
gnc_book_get_template_group(book);
tmpAcct =
xaccGetAccountFromName( acctGroup,
xaccAccountGetName( (Account*)n->data ) );
@ -253,13 +331,17 @@ add_template_transaction_local( sixtp_gdv2 *data,
static gboolean
add_pricedb_local(sixtp_gdv2 *data, GNCPriceDB *db)
{
if(gnc_book_get_pricedb(data->book))
GNCBook *book;
book = gnc_session_get_book (data->session);
if (gnc_book_get_pricedb(book))
{
gnc_pricedb_destroy(gnc_book_get_pricedb(data->book));
gnc_pricedb_destroy(gnc_book_get_pricedb(book));
}
/* gnc_pricedb_print_contents(db, stdout); */
gnc_book_set_pricedb(data->book, db);
gnc_book_set_pricedb(book, db);
return TRUE;
}
@ -275,7 +357,7 @@ gnc_counter_end_handler(gpointer data_for_children,
char *type;
xmlNodePtr tree = (xmlNodePtr)data_for_children;
gxpf_data *gdata = (gxpf_data*)global_data;
sixtp_gdv2 *sixdata = (sixtp_gdv2*)gdata->data;
sixtp_gdv2 *sixdata = (sixtp_gdv2*)gdata->parsedata;
if(parent_data)
{
@ -406,7 +488,7 @@ gnc_session_load_from_xml_file_v2(
book = gnc_session_get_book (session);
gd->book = book;
gd->session = session;
gd->counter.accounts_loaded = 0;
gd->counter.accounts_total = 0;
gd->counter.commodities_loaded = 0;
@ -418,12 +500,6 @@ gnc_session_load_from_xml_file_v2(
gd->counter.schedXactions_loaded = 0;
gd->counter.schedXactions_total = 0;
{
AccountGroup *g = gnc_book_get_group(book);
gnc_book_set_group(book, xaccMallocAccountGroup());
if(g) xaccFreeAccountGroup(g);
}
gd->countCallback = countcallback;
top_parser = sixtp_new();
@ -455,7 +531,7 @@ gnc_session_load_from_xml_file_v2(
xaccLogDisable ();
if(!gnc_xml_parse_file(top_parser, gnc_session_get_file_path(session),
generic_callback, gd))
generic_callback, gd, session))
{
sixtp_destroy(top_parser);
xaccLogEnable ();
@ -477,7 +553,7 @@ gnc_session_load_from_xml_file_v2(
gnc_pricedb_mark_clean (gnc_book_get_pricedb (book));
/* Fix account and transaction commodities */
xaccGroupScrubCommodities (gnc_book_get_group(book));
xaccGroupScrubCommodities (gnc_book_get_group(book), session);
/* Fix split amount/value */
xaccGroupScrubSplits (gnc_book_get_group(book));
@ -748,4 +824,3 @@ gnc_is_xml_data_file_v2(const gchar *name)
{
return gnc_is_our_xml_file(name, GNC_V2_STRING);
}

View File

@ -58,12 +58,12 @@ typedef struct
int schedXactions_loaded;
} load_counter;
struct sixtp_global_data_v2_struct
typedef struct
{
GNCBook *book;
GNCSession *session;
load_counter counter;
void (*countCallback)(const char *type, load_counter counter);
};
} sixtp_gdv2;
/**
* Struct used to pass the account group/accounts and trasnactions in
@ -75,10 +75,9 @@ typedef struct
{
GList *accts;
GList *transactions;
GNCSession *session;
} gnc_template_xaction_data;
typedef struct sixtp_global_data_v2_struct sixtp_gdv2;
/* read in an account group from a file */
gboolean gnc_session_load_from_xml_file_v2(
GNCSession *session,

View File

@ -700,25 +700,27 @@ dom_tree_to_commodity_ref_no_engine(xmlNodePtr node)
}
gnc_commodity*
dom_tree_to_commodity_ref(xmlNodePtr node)
dom_tree_to_commodity_ref(xmlNodePtr node, GNCSession *session)
{
gnc_commodity *daref;
gnc_commodity *ret;
gnc_commodity_table *table;
daref = dom_tree_to_commodity_ref_no_engine(node);
ret = associate_commodity_ref_with_engine_commodity(daref);
table = gnc_book_get_commodity_table (gnc_session_get_book (session));
g_return_val_if_fail (table != NULL, NULL);
ret = gnc_commodity_table_lookup (table,
gnc_commodity_get_namespace(daref),
gnc_commodity_get_mnemonic(daref));
gnc_commodity_destroy(daref);
return ret;
}
g_return_val_if_fail (ret != NULL, NULL);
gnc_commodity *
associate_commodity_ref_with_engine_commodity(gnc_commodity *com)
{
return gnc_commodity_table_lookup(gnc_engine_commodities(),
gnc_commodity_get_namespace(com),
gnc_commodity_get_mnemonic(com));
return ret;
}
/***********************************************************************/
@ -749,9 +751,9 @@ dom_tree_handlers_all_gotten_p(struct dom_tree_handler *handlers)
return ret;
}
static gboolean
gnc_xml_set_data(const gchar* tag, xmlNodePtr node, gboolean *item,
gnc_xml_set_data(const gchar* tag, xmlNodePtr node, gpointer item,
struct dom_tree_handler *handlers)
{
for(;handlers->tag != NULL; handlers++)
@ -763,7 +765,7 @@ gnc_xml_set_data(const gchar* tag, xmlNodePtr node, gboolean *item,
break;
}
}
if(!handlers->tag)
{
PERR("Unhandled tag: %s\n",
@ -780,7 +782,7 @@ dom_tree_generic_parse(xmlNodePtr node, struct dom_tree_handler *handlers,
{
xmlNodePtr achild;
gboolean successful = TRUE;
dom_tree_handlers_reset(handlers);
for(achild = node->xmlChildrenNode; achild; achild = achild->next)

View File

@ -21,8 +21,8 @@
* *
********************************************************************/
#ifndef _SIXTP_DOM_PARSERS_H_
#define _SIXTP_DOM_PARSERS_H_
#ifndef SIXTP_DOM_PARSERS_H
#define SIXTP_DOM_PARSERS_H
#include "config.h"
@ -30,22 +30,17 @@
#include "gnc-xml-helper.h"
#include "gnc-commodity.h"
#include "kvp_frame.h"
#include "date.h"
#include "gnc-numeric.h"
#include "gnc-commodity.h"
#include "gnc-session.h"
#include "GNCId.h"
#include "FreqSpec.h"
#include "Account.h"
#include "Transaction.h"
GUID* dom_tree_to_guid(xmlNodePtr node);
gnc_commodity* dom_tree_to_commodity_ref(xmlNodePtr node);
gnc_commodity* associate_commodity_ref_with_engine_commodity(
gnc_commodity *com);
gnc_commodity* dom_tree_to_commodity_ref(xmlNodePtr node, GNCSession *session);
gnc_commodity *dom_tree_to_commodity_ref_no_engine(xmlNodePtr node);
FreqSpec* dom_tree_to_freqSpec( xmlNodePtr node );
@ -71,15 +66,14 @@ kvp_value* dom_tree_to_frame_kvp_value(xmlNodePtr node);
gboolean dom_tree_to_integer(xmlNodePtr node, gint64 *daint);
// jsled-added...
Account* dom_tree_to_account( xmlNodePtr node );
Transaction* dom_tree_to_transaction( xmlNodePtr node );
Account* dom_tree_to_account(xmlNodePtr node, GNCSession *session);
Transaction* dom_tree_to_transaction(xmlNodePtr node);
struct dom_tree_handler
{
const char *tag;
gboolean (*handler) (xmlNodePtr, gpointer);
gboolean (*handler) (xmlNodePtr, gpointer data);
int required;
int gotten;
@ -90,5 +84,4 @@ gboolean dom_tree_generic_parse(xmlNodePtr node,
gpointer data);
#endif /* _SIXTP_DOM_PARSERS_H_ */

View File

@ -46,6 +46,9 @@ LDADD = -L${top_srcdir}/src/gnc-module -L${top_srcdir}/src/gnc-module/.libs \
${top_srcdir}/src/test-core/libgncmod-test.la \
${top_srcdir}/src/gnc-module/libgncmodule.la \
${top_srcdir}/src/engine/libgncmod-engine.la \
${top_srcdir}/src/engine/libgw-engine.la \
${top_srcdir}/src/engine/libgw-glib.la \
${top_srcdir}/src/engine/libgw-kvp.la \
${top_srcdir}/src/engine/test-core/libgncmod-test-engine.la \
../libgncmod-backend-file.la \
./libgnc-test-file-stuff.la \

View File

@ -303,7 +303,8 @@ grab_file_doc(const char *filename)
static void
test_load_file(const char *filename, gxpf_callback cb,
sixtp *parser, const char *parser_tag)
sixtp *parser, const char *parser_tag,
GNCSession *session)
{
xmlNodePtr node;
sixtp *main_parser;
@ -320,7 +321,7 @@ test_load_file(const char *filename, gxpf_callback cb,
top_parser = sixtp_new();
main_parser = sixtp_new();
if(!sixtp_add_some_sub_parsers(
top_parser, TRUE,
"gnc-v2", main_parser,
@ -337,7 +338,7 @@ test_load_file(const char *filename, gxpf_callback cb,
return;
}
if(!gnc_xml_parse_file(top_parser, filename, cb, (gpointer)(node->childs)))
if(!gnc_xml_parse_file(top_parser, filename, cb, node->childs, session))
{
failure_args("failure to parse file", __FILE__, __LINE__,
"%s", filename);
@ -348,7 +349,8 @@ test_load_file(const char *filename, gxpf_callback cb,
void
test_files_in_dir(int argc, char **argv, gxpf_callback cb,
sixtp *parser, const char *parser_tag)
sixtp *parser, const char *parser_tag,
GNCSession *session)
{
int count;
@ -364,7 +366,7 @@ test_files_in_dir(int argc, char **argv, gxpf_callback cb,
{
if(!S_ISDIR(file_info.st_mode))
{
test_load_file(to_open, cb, parser, parser_tag);
test_load_file(to_open, cb, parser, parser_tag, session);
}
}
}

View File

@ -11,6 +11,7 @@
#include "date.h"
#include "gnc-commodity.h"
#include "gnc-session.h"
#include "gnc-xml-helper.h"
#include "guid.h"
#include "io-gncxml-gen.h"
@ -40,6 +41,7 @@ gboolean equals_node_val_vs_int(xmlNodePtr node, gint64 val);
void
test_files_in_dir(int argc, char **argv, gxpf_callback cb,
sixtp *parser, const char *parser_tag);
sixtp *parser, const char *parser_tag,
GNCSession *session);
#endif

View File

@ -21,11 +21,11 @@
static const gchar *da_ending = ".gnucash-xea";
static void
test_load_file(const char *filename)
test_load_file(GNCSession *session, const char *filename)
{
GncExampleAccount *gea;
gea = gnc_read_example_account(filename);
gea = gnc_read_example_account(session, filename);
if(gea != NULL)
{
@ -39,17 +39,19 @@ test_load_file(const char *filename)
}
}
int
main(int argc, char **argv)
static void
guile_main(int argc, char **argv)
{
const char *location = "../../../../accounts/C";
GSList *list = NULL;
DIR *ea_dir;
GSList *list;
GNCSession *session;
gnc_module_system_init();
gnc_module_load("gnucash/engine", 0);
session = gnc_session_new ();
list = NULL;
gnc_engine_init(argc, argv);
if((ea_dir = opendir(location)) == NULL)
{
failure("unable to open ea directory");
@ -73,7 +75,7 @@ main(int argc, char **argv)
{
if(!S_ISDIR(file_info.st_mode))
{
test_load_file(to_open);
test_load_file(session, to_open);
}
}
g_free(to_open);
@ -83,7 +85,7 @@ main(int argc, char **argv)
closedir(ea_dir);
{
list = gnc_load_example_account_list(location);
list = gnc_load_example_account_list(session, location);
do_test(list != NULL, "gnc_load_example_account_list");
@ -94,3 +96,10 @@ main(int argc, char **argv)
print_test_results();
exit(get_rv());
}
int
main(int argc, char ** argv)
{
gh_enter (argc, argv, guile_main);
return 0;
}

View File

@ -50,9 +50,9 @@ test_load_file(const char *filename)
session = gnc_session_new();
remove_locks(filename);
gnc_session_begin(session, filename, FALSE, FALSE);
gnc_session_load_from_xml_file_v2(session, NULL);
book = gnc_session_get_book (session);
@ -73,7 +73,7 @@ guile_main(int argc, char **argv)
{
const char *location = "test-files/xml2";
DIR *xml2_dir;
gnc_module_system_init();
gnc_module_load("gnucash/engine", 0);
@ -117,7 +117,11 @@ guile_main(int argc, char **argv)
}
int
main(int argc, char ** argv) {
main(int argc, char ** argv)
{
/* getchar (); */
gh_enter(argc, argv, guile_main);
return 0;
}

View File

@ -23,6 +23,8 @@
#include "Scrub.h"
#include "gnc-book.h"
static GNCSession *session;
static gchar*
node_and_account_equal(xmlNodePtr node, Account *act)
{
@ -91,7 +93,7 @@ node_and_account_equal(xmlNodePtr node, Account *act)
else if(safe_strcmp(mark->name, "act:currency") == 0)
{
if(!equals_node_val_vs_commodity(
mark, DxaccAccountGetCurrency(act)))
mark, DxaccAccountGetCurrency(act, session)))
{
return g_strdup("currencies differ");
}
@ -114,7 +116,7 @@ node_and_account_equal(xmlNodePtr node, Account *act)
else if(safe_strcmp(mark->name, "act:security") == 0)
{
if(!equals_node_val_vs_commodity(
mark, DxaccAccountGetSecurity(act)))
mark, DxaccAccountGetSecurity(act, session)))
{
return g_strdup("securities differ");
}
@ -187,7 +189,7 @@ static gboolean
test_add_account(const char *tag, gpointer globaldata, gpointer data)
{
act_data *gdata = (act_data*)globaldata;
do_test_args(xaccAccountEqual((Account*)data, (Account*)(gdata->act),
TRUE),
"gnc_account_sixtp_parser_create",
@ -243,11 +245,11 @@ test_account(int i, Account *test_act)
data.act = test_act;
data.value = i;
parser = gnc_account_sixtp_parser_create();
if(!gnc_xml_parse_file(parser, filename1, test_add_account,
(gpointer)&data))
&data, session))
{
failure_args("gnc_xml_parse_file returned FALSE",
__FILE__, __LINE__, "%d", i);
@ -267,14 +269,15 @@ static void
test_generation(void)
{
int i;
for(i = 0; i < 20; i++)
{
Account *ran_act;
ran_act = get_random_account();
ran_act = get_random_account(session);
test_account(i, ran_act);
delete_random_account(ran_act);
}
@ -282,7 +285,7 @@ test_generation(void)
/* empty some things. */
Account *act;
act = get_random_account();
act = get_random_account(session);
xaccAccountSetCode(act, "");
xaccAccountSetDescription(act, "");
@ -311,37 +314,42 @@ test_generation(void)
}
GNCBook *bk;
static GNCBook *bk;
static gboolean
test_real_account(const char *tag, gpointer global_data, gpointer data)
{
char *msg;
Account *act = (Account*)data;
if(!xaccAccountGetParent(act))
{
xaccGroupInsertAccount(gnc_book_get_group(bk), act);
}
msg = node_and_account_equal((xmlNodePtr)global_data, act);
do_test_args(msg == NULL, "test_real_account",
__FILE__, __LINE__, msg);
g_free(msg);
return TRUE;
}
int
main(int argc, char **argv)
static void
guile_main(int argc, char **argv)
{
gnc_engine_init(argc, argv);
xaccGUIDInit();
gnc_module_system_init();
gnc_module_load("gnucash/engine", 0);
session = gnc_session_new ();
if(argc > 1)
{
bk = gnc_book_new();
bk = gnc_session_get_book (session);
test_files_in_dir(argc, argv, test_real_account,
gnc_account_sixtp_parser_create(),
"gnc:account");
"gnc:account", session);
}
else
{
@ -351,3 +359,10 @@ main(int argc, char **argv)
print_test_results();
exit(get_rv());
}
int
main(int argc, char ** argv)
{
gh_enter (argc, argv, guile_main);
return 0;
}

View File

@ -22,12 +22,13 @@
#include "Account.h"
static GNCSession *session;
static gchar*
node_and_commodity_equal(xmlNodePtr node, const gnc_commodity *com)
{
xmlNodePtr mark;
if(!check_dom_tree_version(node, "2.0.0"))
{
return "version wrong. Not 2.0.0 or not there";
@ -142,7 +143,7 @@ test_generation(void)
int fd;
gchar *compare_msg;
ran_com = get_random_commodity();
ran_com = get_random_commodity(session);
test_node = gnc_commodity_dom_tree_create(ran_com);
if(!test_node)
@ -186,7 +187,7 @@ test_generation(void)
parser = gnc_commodity_sixtp_parser_create();
if(!gnc_xml_parse_file(parser, filename1, test_add_commodity,
(gpointer)&data))
(gpointer)&data, session))
{
failure_args("gnc_xml_parse_file returned FALSE",
__FILE__, __LINE__, "%d", i);
@ -214,20 +215,32 @@ test_real_commodity(const char *tag, gpointer globaldata, gpointer data)
return TRUE;
}
int
main(int argc, char **argv)
static void
guile_main(int argc, char **argv)
{
gnc_engine_init (argc, argv);
gnc_module_system_init();
gnc_module_load("gnucash/engine", 0);
session = gnc_session_new ();
if(argc > 1)
{
test_files_in_dir(argc, argv, test_real_commodity,
gnc_commodity_sixtp_parser_create(),
"gnc:commodity");
"gnc:commodity", session);
}
else
{
test_generation();
}
print_test_results();
exit(get_rv());
}
int
main(int argc, char ** argv)
{
gh_enter (argc, argv, guile_main);
return 0;
}

View File

@ -21,6 +21,7 @@
#include "GNCIdP.h"
#include "gnc-book.h"
static GNCSession *session;
struct pricedb_data_struct
{
@ -88,7 +89,7 @@ test_db (int i, GNCPriceDB *db)
__FILE__, __LINE__, "%d", i);
}
else if (!gnc_xml_parse_file (parser, filename1, test_add_pricedb,
(gpointer)&data))
(gpointer)&data, session))
{
failure_args ("gnc_xml_parse_file returned FALSE",
__FILE__, __LINE__, "%d", i);
@ -109,7 +110,7 @@ test_generation (void)
{
GNCPriceDB *db;
db = get_random_pricedb ();
db = get_random_pricedb (session);
if (gnc_pricedb_get_num_prices (db))
test_db (i, db);
@ -118,13 +119,23 @@ test_generation (void)
}
}
int
main (int argc, char **argv)
static void
guile_main(int argc, char **argv)
{
gnc_engine_init (argc, argv);
gnc_module_system_init();
gnc_module_load("gnucash/engine", 0);
session = gnc_session_new ();
test_generation ();
print_test_results ();
exit (get_rv ());
}
int
main(int argc, char ** argv)
{
gh_enter (argc, argv, guile_main);
return 0;
}

View File

@ -27,6 +27,7 @@
#include "Transaction.h"
#include "GNCIdP.h"
static GNCSession *session;
static xmlNodePtr
find_appropriate_node(xmlNodePtr node, Split *spl)
@ -319,7 +320,7 @@ test_transaction(void)
FILE *cmp_file;
int fd;
ran_trn = get_random_transaction();
ran_trn = get_random_transaction(session);
com = xaccTransGetCurrency (ran_trn);
@ -369,7 +370,7 @@ test_transaction(void)
parser = gnc_transaction_sixtp_parser_create();
if(!gnc_xml_parse_file(parser, filename1, test_add_transaction,
(gpointer)&data))
(gpointer)&data, session))
{
failure_args("gnc_xml_parse_file returned FALSE",
__FILE__, __LINE__, "%d", i);
@ -399,23 +400,34 @@ test_real_transaction(const char *tag, gpointer global_data, gpointer data)
return TRUE;
}
int
main(int argc, char **argv)
static void
guile_main(int argc, char **argv)
{
gnc_engine_init (argc, argv);
gnc_module_system_init();
gnc_module_load("gnucash/engine", 0);
xaccLogDisable();
session = gnc_session_new ();
if(argc > 1)
{
test_files_in_dir(argc, argv, test_real_transaction,
gnc_transaction_sixtp_parser_create(),
"gnc:transaction");
"gnc:transaction", session);
}
else
{
test_transaction();
}
print_test_results();
exit(get_rv());
}
int
main(int argc, char ** argv)
{
gh_enter (argc, argv, guile_main);
return 0;
}

View File

@ -149,12 +149,14 @@ pgendGetTopGroup (PGBackend *be)
*/
gnc_commodity *
gnc_string_to_commodity (const char *str)
gnc_string_to_commodity (const char *str, GNCSession *session)
{
gnc_commodity_table *comtab = gnc_engine_commodities();
gnc_commodity_table *comtab;
gnc_commodity *com;
char *space, *name;
comtab = gnc_book_get_commodity_table (gnc_session_get_book (session));
space = g_strdup(str);
name = strchr (space, ':');
*name = 0;
@ -338,7 +340,7 @@ query_cb (PGBackend *be, PGresult *result, int j, gpointer data)
xaccTransSetDateEnteredTS (trans, &ts);
xaccTransSetVersion (trans, atoi(DB_GET_VAL("version",j)));
currency = gnc_string_to_commodity (DB_GET_VAL("currency",j));
currency = gnc_string_to_commodity (DB_GET_VAL("currency",j), be->session);
xaccTransSetCurrency (trans, currency);
trans->marker = 1;

View File

@ -264,7 +264,8 @@ get_account_cb (PGBackend *be, PGresult *result, int j, gpointer data)
xaccAccountSetCode(acc, DB_GET_VAL("accountCode",j));
xaccAccountSetType(acc, xaccAccountStringToEnum(DB_GET_VAL("type",j)));
xaccAccountSetCommodity(acc,
gnc_string_to_commodity (DB_GET_VAL("commodity",j)));
gnc_string_to_commodity (DB_GET_VAL("commodity",j),
be->session));
xaccAccountSetVersion(acc, atoi(DB_GET_VAL("version",j)));
acc->idata = atoi(DB_GET_VAL("iguid",j));

View File

@ -85,9 +85,9 @@ pgendGetAllCommodities (PGBackend *be)
ENTER ("be=%p, conn=%p", be, be->connection);
comtab = gnc_engine_commodities();
comtab = gnc_book_get_commodity_table (gnc_session_get_book (be->session));
if (!comtab) {
PERR ("can't get global commodity table");
PERR ("can't get commodity table");
return;
}
@ -177,7 +177,9 @@ commodity_mark_cb (gnc_commodity *cm, gpointer user_data)
void
pgendStorePriceDBNoLock (PGBackend *be, GNCPriceDB *prdb)
{
gnc_commodity_table *comtab = gnc_engine_commodities();
gnc_commodity_table *comtab;
comtab = gnc_book_get_commodity_table (gnc_session_get_book (be->session));
/* clear the marks on commodities -- we use this to mark
* the thing as 'already stored', avoiding redundant stores */
@ -262,10 +264,10 @@ get_price_cb (PGBackend *be, PGresult *result, int j, gpointer data)
}
gnc_price_set_version (pr, sql_vers);
modity = gnc_string_to_commodity (DB_GET_VAL("commodity",j));
modity = gnc_string_to_commodity (DB_GET_VAL("commodity",j), be->session);
gnc_price_set_commodity (pr, modity);
modity = gnc_string_to_commodity (DB_GET_VAL("currency",j));
modity = gnc_string_to_commodity (DB_GET_VAL("currency",j), be->session);
gnc_price_set_currency (pr, modity);
ts = gnc_iso8601_to_timespec_local (DB_GET_VAL("time",j));

View File

@ -63,10 +63,10 @@ gpointer pgendGetResults (PGBackend *be,
gpointer (*handler) (PGBackend *, PGresult *, int, gpointer),
gpointer data);
/* The gnc_string_to_commodity() routine finds the commodity by parsing a string
* of the form NAMESPACE::MNEMONIC
/* The gnc_string_to_commodity() routine finds the commodity by
* parsing a string of the form NAMESPACE::MNEMONIC
*/
gnc_commodity * gnc_string_to_commodity (const char *str);
gnc_commodity * gnc_string_to_commodity (const char *str, GNCSession *session);
/* hack alert -- calling PQFinish() is quite harsh, since all
* subsequent sql queries will fail. On the other hand, killing

View File

@ -16,6 +16,10 @@ LDADD = -L${top_srcdir}/src/gnc-module -L${top_srcdir}/src/gnc-module/.libs \
${top_srcdir}/src/test-core/libgncmod-test.la \
${top_srcdir}/src/gnc-module/libgncmodule.la \
${top_srcdir}/src/engine/libgncmod-engine.la \
${top_srcdir}/src/engine/libgncmod-engine.la \
${top_srcdir}/src/engine/libgw-engine.la \
${top_srcdir}/src/engine/libgw-glib.la \
${top_srcdir}/src/engine/libgw-kvp.la \
${top_srcdir}/src/engine/test-core/libgncmod-test-engine.la \
${top_srcdir}/src/backend/postgres/libgncmod-backend-postgres.la \
-lltdl

View File

@ -12,10 +12,6 @@ EXIT_VALUE=0
if test $EXIT_VALUE != 0; then exit $EXIT_VALUE; fi
diff -u test-file-1 test-file-2 || EXIT_VALUE=1
if test $EXIT_VALUE != 0; then exit $EXIT_VALUE; fi
#./db-control.sh destroy
exit $EXIT_VALUE

View File

@ -22,9 +22,10 @@ run_test (void)
GNCBackendError io_err;
char *filename;
book = get_random_book ();
session = gnc_session_new ();
book = get_random_book (session);
gnc_session_set_book (session, book);
filename = g_strdup ("postgres://localhost:7777/gnc_test?mode=single-file");

View File

@ -630,7 +630,8 @@ pgendCopyTransactionToEngine (PGBackend *be, const GUID *trans_guid)
ts = gnc_iso8601_to_timespec_local (DB_GET_VAL("date_entered",j));
xaccTransSetDateEnteredTS (trans, &ts);
xaccTransSetVersion (trans, atoi(DB_GET_VAL("version",j)));
currency = gnc_string_to_commodity (DB_GET_VAL("currency",j));
currency = gnc_string_to_commodity (DB_GET_VAL("currency",j),
be->session);
xaccTransSetCurrency (trans, currency);
trans->idata = atoi(DB_GET_VAL("iguid",j));
}

View File

@ -101,11 +101,13 @@ get_mass_trans_cb (PGBackend *be, PGresult *result, int j, gpointer data)
xaccTransSetVersion (trans, atoi(DB_GET_VAL("version",j)));
trans->idata = atoi (DB_GET_VAL("iguid",j));
currency = gnc_string_to_commodity (DB_GET_VAL("currency",j));
currency = gnc_string_to_commodity (DB_GET_VAL("currency",j),
be->session);
trans_frac = gnc_commodity_get_fraction (currency);
xaccTransSetCurrency
(trans, gnc_string_to_commodity (DB_GET_VAL("currency",j)));
xaccTransSetCurrency (trans,
gnc_string_to_commodity (DB_GET_VAL("currency",j),
be->session));
/* set timestamp as 'recent' for this data */
trans->version_check = be->version_check;

View File

@ -28,16 +28,13 @@
#include <glib.h>
#include <string.h>
#include "Account.h"
#include "AccountP.h"
#include "BackendP.h"
#include "GNCIdP.h"
#include "Group.h"
#include "GroupP.h"
#include "Transaction.h"
#include "TransactionP.h"
#include "date.h"
#include "gnc-commodity.h"
#include "gnc-book.h"
#include "gnc-engine.h"
#include "gnc-engine-util.h"
#include "gnc-event-p.h"
@ -1089,12 +1086,16 @@ xaccAccountGetCommoditySCU (Account * acc) {
/* below follow the old, deprecated currency/security routines. */
void
DxaccAccountSetCurrency (Account * acc, gnc_commodity * currency) {
DxaccAccountSetCurrency (Account * acc, gnc_commodity * currency,
GNCSession *session)
{
const char *string;
gnc_commodity *commodity;
if ((!acc) || (!currency)) return;
g_return_if_fail (session);
xaccAccountBeginEdit(acc);
string = gnc_commodity_get_unique_name (currency);
kvp_frame_set_slot_nc(acc->kvp_data, "old-currency",
@ -1103,18 +1104,26 @@ DxaccAccountSetCurrency (Account * acc, gnc_commodity * currency) {
acc->core_dirty = TRUE;
xaccAccountCommitEdit(acc);
commodity = DxaccAccountGetCurrency (acc);
commodity = DxaccAccountGetCurrency (acc, session);
if (!commodity)
gnc_commodity_table_insert (gnc_engine_commodities (), currency);
{
GNCBook * book = gnc_session_get_book (session);
gnc_commodity_table_insert (gnc_book_get_commodity_table (book), currency);
}
}
void
DxaccAccountSetSecurity (Account *acc, gnc_commodity * security) {
DxaccAccountSetSecurity (Account *acc, gnc_commodity * security,
GNCSession *session)
{
const char *string;
gnc_commodity *commodity;
if ((!acc) || (!security)) return;
g_return_if_fail (session);
xaccAccountBeginEdit(acc);
string = gnc_commodity_get_unique_name (security);
kvp_frame_set_slot_nc(acc->kvp_data, "old-security",
@ -1123,9 +1132,13 @@ DxaccAccountSetSecurity (Account *acc, gnc_commodity * security) {
acc->core_dirty = TRUE;
xaccAccountCommitEdit(acc);
commodity = DxaccAccountGetSecurity (acc);
commodity = DxaccAccountGetSecurity (acc, session);
if (!commodity)
gnc_commodity_table_insert (gnc_engine_commodities (), security);
{
GNCBook * book = gnc_session_get_book (session);
gnc_commodity_table_insert (gnc_book_get_commodity_table (book), security);
}
}
void
@ -1289,20 +1302,28 @@ xaccAccountGetNotes (Account *acc)
}
gnc_commodity *
DxaccAccountGetCurrency (Account *acc)
DxaccAccountGetCurrency (Account *acc, GNCSession *session)
{
kvp_value *v;
const char *s;
GNCBook *book;
gnc_commodity_table *table;
if (!acc) return NULL;
g_return_val_if_fail (session, NULL);
v = kvp_frame_get_slot(acc->kvp_data, "old-currency");
if (!v) return NULL;
s = kvp_value_get_string (v);
if (!s) return NULL;
return gnc_commodity_table_lookup_unique (gnc_engine_commodities (), s);
book = gnc_session_get_book (session);
table = gnc_book_get_commodity_table (book);
return gnc_commodity_table_lookup_unique (table, s);
}
gnc_commodity *
@ -1314,20 +1335,28 @@ xaccAccountGetCommodity (Account *acc)
}
gnc_commodity *
DxaccAccountGetSecurity (Account *acc)
DxaccAccountGetSecurity (Account *acc, GNCSession *session)
{
kvp_value *v;
const char *s;
GNCBook *book;
gnc_commodity_table *table;
if (!acc) return NULL;
g_return_val_if_fail (session, NULL);
v = kvp_frame_get_slot(acc->kvp_data, "old-security");
if (!v) return NULL;
s = kvp_value_get_string (v);
if (!s) return NULL;
return gnc_commodity_table_lookup_unique (gnc_engine_commodities (), s);
book = gnc_session_get_book (session);
table = gnc_book_get_commodity_table (book);
return gnc_commodity_table_lookup_unique (table, s);
}
gnc_numeric

View File

@ -27,6 +27,7 @@
#include "GNCId.h"
#include "Transaction.h"
#include "gnc-engine.h"
#include "kvp_frame.h"
@ -215,10 +216,14 @@ void xaccAccountSetCommoditySCU (Account *account, int frac);
* the 'commodity'. Use xaccAccountGetCommodity() to fetch it.
*/
/* these two funcs take control of their gnc_commodity args. Don't free */
void DxaccAccountSetCurrency (Account *account, gnc_commodity *currency);
void DxaccAccountSetSecurity (Account *account, gnc_commodity *security);
gnc_commodity * DxaccAccountGetCurrency (Account *account);
gnc_commodity * DxaccAccountGetSecurity (Account *account);
void DxaccAccountSetCurrency (Account *account, gnc_commodity *currency,
GNCSession *session);
void DxaccAccountSetSecurity (Account *account, gnc_commodity *security,
GNCSession *session);
gnc_commodity * DxaccAccountGetCurrency (Account *account,
GNCSession *session);
gnc_commodity * DxaccAccountGetSecurity (Account *account,
GNCSession *session);
void DxaccAccountSetCurrencySCU (Account *account, int frac);
int DxaccAccountGetCurrencySCU (Account *account);

View File

@ -199,6 +199,18 @@ xaccGroupSetBook (AccountGroup *group, GNCBook *book)
}
}
GNCBook *
xaccAccountGetBook (Account *account)
{
AccountGroup *group;
if (!account) return NULL;
group = xaccAccountGetParent (account);
return xaccGroupGetBook (group);
}
/********************************************************************\
\********************************************************************/

View File

@ -388,16 +388,18 @@ xaccTransScrubImbalance (Transaction *trans, AccountGroup *root,
/* ================================================================ */
void
xaccTransScrubCurrency (Transaction *trans)
xaccTransScrubCurrency (Transaction *trans, GNCSession *session)
{
gnc_commodity *currency;
if (!trans) return;
g_return_if_fail (session);
currency = xaccTransGetCurrency (trans);
if (currency) return;
currency = xaccTransFindOldCommonCurrency (trans);
currency = xaccTransFindOldCommonCurrency (trans, session);
if (currency)
{
xaccTransBeginEdit (trans);
@ -413,23 +415,25 @@ xaccTransScrubCurrency (Transaction *trans)
/* ================================================================ */
void
xaccAccountScrubCommodity (Account *account)
xaccAccountScrubCommodity (Account *account, GNCSession *session)
{
gnc_commodity *commodity;
if (!account) return;
g_return_if_fail (session);
commodity = xaccAccountGetCommodity (account);
if (commodity) return;
commodity = DxaccAccountGetSecurity (account);
commodity = DxaccAccountGetSecurity (account, session);
if (commodity)
{
xaccAccountSetCommodity (account, commodity);
return;
}
commodity = DxaccAccountGetCurrency (account);
commodity = DxaccAccountGetCurrency (account, session);
if (commodity)
{
xaccAccountSetCommodity (account, commodity);
@ -442,30 +446,39 @@ xaccAccountScrubCommodity (Account *account)
/* ================================================================ */
static gboolean
scrub_trans_currency_helper (Transaction *t, void *unused)
scrub_trans_currency_helper (Transaction *t, gpointer data)
{
xaccTransScrubCurrency (t);
GNCSession *session = data;
xaccTransScrubCurrency (t, session);
return TRUE;
}
static gpointer
scrub_account_commodity_helper (Account *account, gpointer unused)
scrub_account_commodity_helper (Account *account, gpointer data)
{
xaccAccountScrubCommodity (account);
GNCSession *session = data;
xaccAccountScrubCommodity (account, session);
xaccAccountDeleteOldData (account);
return NULL;
}
void
xaccGroupScrubCommodities (AccountGroup *group)
xaccGroupScrubCommodities (AccountGroup *group, GNCSession *session)
{
if (!group) return;
g_return_if_fail (session != NULL);
xaccAccountGroupBeginEdit (group);
xaccGroupForEachTransaction (group, scrub_trans_currency_helper, NULL);
xaccGroupForEachTransaction (group, scrub_trans_currency_helper, session);
xaccGroupForEachAccount (group, scrub_account_commodity_helper, NULL, TRUE);
xaccGroupForEachAccount (group, scrub_account_commodity_helper,
session, TRUE);
xaccAccountGroupCommitEdit (group);
}

View File

@ -86,14 +86,14 @@ void xaccGroupScrubImbalance (AccountGroup *grp);
/* The xaccTransScrubCurrency method fixes transactions without a
* common_currency by using the old account currency and security
* fields of the parent accounts of the transaction's splits. */
void xaccTransScrubCurrency (Transaction *trans);
void xaccTransScrubCurrency (Transaction *trans, GNCSession *session);
/* The xaccAccountScrubCommodity method fixed accounts without
* a commodity by using the old account currency and security. */
void xaccAccountScrubCommodity (Account *account);
void xaccAccountScrubCommodity (Account *account, GNCSession *session);
/* The xaccGroupScrubCommodities will scrub the currency/commodity
* of all accounts & transactions in the group. */
void xaccGroupScrubCommodities (AccountGroup *group);
void xaccGroupScrubCommodities (AccountGroup *group, GNCSession *session);
#endif /* XACC_SCRUB_H */

View File

@ -1095,12 +1095,15 @@ xaccTransGetImbalance (Transaction * trans)
static gnc_commodity *
FindCommonExclSCurrency (GList *splits,
gnc_commodity * ra, gnc_commodity * rb,
Split *excl_split)
Split *excl_split,
GNCSession *session)
{
GList *node;
if (!splits) return NULL;
g_return_val_if_fail (session, NULL);
for (node = splits; node; node = node->next)
{
Split *s = node->data;
@ -1115,12 +1118,12 @@ FindCommonExclSCurrency (GList *splits,
* Well, that's ok, we'll just go with the flow.
*/
if (force_double_entry)
assert (xaccSplitGetAccount(s));
g_return_val_if_fail (xaccSplitGetAccount(s), NULL);
else if (xaccSplitGetAccount(s) == NULL)
continue;
sa = DxaccAccountGetCurrency (xaccSplitGetAccount(s));
sb = DxaccAccountGetSecurity (xaccSplitGetAccount(s));
sa = DxaccAccountGetCurrency (xaccSplitGetAccount(s), session);
sb = DxaccAccountGetSecurity (xaccSplitGetAccount(s), session);
if (ra && rb) {
int aa = !gnc_commodity_equiv(ra,sa);
@ -1158,13 +1161,14 @@ FindCommonExclSCurrency (GList *splits,
* common currency.
*/
static gnc_commodity *
FindCommonCurrency (GList *splits, gnc_commodity * ra, gnc_commodity * rb)
FindCommonCurrency (GList *splits, gnc_commodity * ra, gnc_commodity * rb,
GNCSession *session)
{
return FindCommonExclSCurrency(splits, ra, rb, NULL);
return FindCommonExclSCurrency(splits, ra, rb, NULL, session);
}
gnc_commodity *
xaccTransFindOldCommonCurrency (Transaction *trans)
xaccTransFindOldCommonCurrency (Transaction *trans, GNCSession *session)
{
gnc_commodity *ra, *rb, *retval;
Split *split;
@ -1173,14 +1177,16 @@ xaccTransFindOldCommonCurrency (Transaction *trans)
if (trans->splits == NULL) return NULL;
g_return_val_if_fail (session, NULL);
split = trans->splits->data;
if (xaccSplitGetAccount(split) == NULL) return NULL;
ra = DxaccAccountGetCurrency (xaccSplitGetAccount(split));
rb = DxaccAccountGetSecurity (xaccSplitGetAccount(split));
ra = DxaccAccountGetCurrency (xaccSplitGetAccount(split), session);
rb = DxaccAccountGetSecurity (xaccSplitGetAccount(split), session);
retval = FindCommonCurrency (trans->splits, ra, rb);
retval = FindCommonCurrency (trans->splits, ra, rb, session);
/* compare this value to what we think should be the 'right' value */
if (!trans->common_currency)

View File

@ -28,7 +28,7 @@
#include <time.h>
#include "gnc-commodity.h"
#include "gnc-numeric.h"
#include "gnc-engine.h"
#include "kvp_frame.h"
#include "GNCId.h"
#include "date.h"

View File

@ -231,6 +231,7 @@ gint32 xaccTransGetVersion (Transaction*);
* indicating a currency denomination that all of the splits in this
* transaction have in common, using the old currency/security fields
* of the split accounts. */
gnc_commodity * xaccTransFindOldCommonCurrency (Transaction *trans);
gnc_commodity * xaccTransFindOldCommonCurrency (Transaction *trans,
GNCSession *session);
#endif /* XACC_TRANSACTION_P_H */

View File

@ -21,13 +21,12 @@
;; in the engine
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (gnc:setup-default-namespaces)
(let ((table (gnc:engine-commodities)))
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_AMEX)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_NYSE)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_NASDAQ)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_EUREX)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_MUTUAL)))
(define (gnc:setup-default-namespaces table)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_AMEX)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_NYSE)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_NASDAQ)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_EUREX)
(gnc:commodity-table-add-namespace table GNC_COMMODITY_NS_MUTUAL))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -35,9 +34,8 @@
;; load the default table of ISO-4217 currency information.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (gnc:load-iso-4217-currencies)
(let ((table (gnc:engine-commodities))
(curr-path (%search-load-path gnc:*iso-4217-currency-file*)))
(define (gnc:load-iso-4217-currencies table)
(let ((curr-path (%search-load-path gnc:*iso-4217-currency-file*)))
(if curr-path
(with-input-from-file curr-path
(lambda ()
@ -70,3 +68,7 @@
(gnc:commodity-table-insert table comm)))))
(loop (read)))))))
(display "Unable to load iso-4217 currency definitions\n"))))
(define (gnc:engine-commodity-table-construct table)
(gnc:load-iso-4217-currencies table)
(gnc:setup-default-namespaces table))

View File

@ -38,6 +38,34 @@
#include <g-wrap-runtime-guile.h>
gnc_commodity_table *
gnc_engine_commodity_table_new (void)
{
static SCM commodity_table_type = SCM_UNDEFINED;
gnc_commodity_table *commodity_table;
SCM ct_scm;
SCM func;
commodity_table = gnc_commodity_table_new ();
if (commodity_table_type == SCM_UNDEFINED)
{
commodity_table_type = gh_eval_str("<gnc:commodity-table*>");
/* don't really need this - types are bound globally anyway. */
if (commodity_table_type != SCM_UNDEFINED)
scm_protect_object (commodity_table_type);
}
ct_scm = gw_wcp_assimilate_ptr ((void *) commodity_table,
commodity_table_type);
func = gh_eval_str ("gnc:engine-commodity-table-construct");
gh_call1 (func, ct_scm);
return commodity_table;
}
Timespec
gnc_transaction_get_date_posted(Transaction *t) {
Timespec result;

View File

@ -34,6 +34,8 @@
#include <guile/gh.h>
#include <glib.h>
gnc_commodity_table * gnc_engine_commodity_table_new (void);
Timespec gnc_transaction_get_date_posted(Transaction *t);
Timespec gnc_transaction_get_date_entered(Transaction *t);

View File

@ -5,7 +5,3 @@
;;; Bill Gribble <grib@billgribble.com> 4 Aug 2000
;;; $Id$
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; initialize commodity tables in the engine
(gnc:load-iso-4217-currencies)
(gnc:setup-default-namespaces)

View File

@ -40,9 +40,7 @@
(export GNC_COMMODITY_NS_EUREX)
(export GNC_COMMODITY_NS_MUTUAL)
(export gnc:setup-default-namespaces)
(export gnc:load-iso-4217-currencies)
(export gnc:engine-commodity-table-construct)
(export gnc:url->loaded-session)
(export gnc:transaction-map-splits)

View File

@ -41,12 +41,13 @@ struct gnc_book_struct
{
AccountGroup *topgroup;
GNCPriceDB *pricedb;
GList *sched_xactions;
AccountGroup *template_group;
gboolean sx_notsaved; /* true if sched_xactions is changed */
gnc_commodity_table *commodity_table;
/* should be set true if sched_xactions is changed */
gboolean sx_notsaved;
Backend *backend;
};

View File

@ -48,6 +48,7 @@
#include "GroupP.h"
#include "SchedXaction.h"
#include "TransLog.h"
#include "engine-helpers.h"
#include "gnc-engine-util.h"
#include "gnc-pricedb-p.h"
#include "DateUtils.h"
@ -61,8 +62,6 @@ static short module = MOD_IO;
/* ---------------------------------------------------------------------- */
const char *TEMPLATE_ACCOUNT_NAME = "__account for template transactions__";
static void
gnc_book_init (GNCBook *book)
{
@ -77,6 +76,8 @@ gnc_book_init (GNCBook *book)
book->sx_notsaved = FALSE;
book->template_group = xaccMallocAccountGroup();
book->commodity_table = gnc_engine_commodity_table_new ();
xaccGroupSetBook (book->topgroup, book);
xaccGroupSetBook (book->template_group, book);
}
@ -91,10 +92,11 @@ gnc_book_new (void)
/* ---------------------------------------------------------------------- */
gnc_commodity_table*
gnc_commodity_table *
gnc_book_get_commodity_table(GNCBook *book)
{
return gnc_engine_commodities();
if (!book) return NULL;
return book->commodity_table;
}
AccountGroup *
@ -287,6 +289,9 @@ gnc_book_destroy (GNCBook *book)
gnc_pricedb_destroy (book->pricedb);
book->pricedb = NULL;
gnc_commodity_table_destroy (book->commodity_table);
book->commodity_table = NULL;
/* FIXME: destroy SX data members here, too */
xaccLogEnable();

View File

@ -56,14 +56,10 @@ void gnc_book_set_group(GNCBook *book, AccountGroup *group);
GNCPriceDB *gnc_book_get_pricedb (GNCBook *book);
GNCBook * xaccGroupGetBook (AccountGroup *group);
GNCBook * xaccAccountGetBook (Account *account);
guint gnc_book_count_transactions(GNCBook *book);
/*
* gnc_book_get_commodity_table returns the commodity table associated with
* the BOOK. At the moment this just returns the global commodity table,
* but if we get everything using this we can make it a non-global table :)
*/
gnc_commodity_table* gnc_book_get_commodity_table(GNCBook *book);
/**

View File

@ -110,15 +110,30 @@ gnc_commodity_new(const char * fullname,
********************************************************************/
void
gnc_commodity_destroy(gnc_commodity * cm) {
gnc_commodity_destroy(gnc_commodity * cm)
{
if(!cm) return;
g_free(cm->fullname);
cm->fullname = NULL;
g_free(cm->printname);
cm->printname = NULL;
g_free(cm->namespace);
cm->namespace = NULL;
g_free(cm->exchange_code);
cm->exchange_code = NULL;
g_free(cm->mnemonic);
cm->mnemonic = NULL;
g_free(cm->unique_name);
cm->unique_name = NULL;
cm->mark = 0;
g_free(cm);
}

View File

@ -30,7 +30,6 @@
#include "gnc-engine.h"
static GList * engine_init_hooks = NULL;
static gnc_commodity_table * known_commodities = NULL;
static int engine_is_initialized = 0;
GCache * gnc_string_cache = NULL;
@ -73,15 +72,13 @@ gnc_engine_init(int argc, char ** argv)
xaccGUIDInit ();
/* initialize the commodity table (it starts empty) */
known_commodities = gnc_commodity_table_new();
/* call any engine hooks */
for(cur = engine_init_hooks; cur; cur = cur->next) {
for (cur = engine_init_hooks; cur; cur = cur->next)
{
hook = (gnc_engine_init_hook_t)cur->data;
if(hook) {
if (hook)
(*hook)(argc, argv);
}
}
}
@ -110,9 +107,6 @@ gnc_engine_shutdown (void)
gnc_string_cache = NULL;
xaccGUIDShutdown ();
gnc_commodity_table_destroy (known_commodities);
known_commodities = NULL;
}
/********************************************************************
@ -124,15 +118,3 @@ void
gnc_engine_add_init_hook(gnc_engine_init_hook_t h) {
engine_init_hooks = g_list_append(engine_init_hooks, (gpointer)h);
}
/********************************************************************
* gnc_engine_commodities()
* get the global gnc_engine commodity table
********************************************************************/
gnc_commodity_table *
gnc_engine_commodities(void) {
assert(engine_is_initialized);
return known_commodities;
}

View File

@ -26,8 +26,12 @@
#include "gnc-commodity.h"
/** TYPES **********************************************************/
typedef struct gnc_session_struct GNCSession;
typedef void (* gnc_engine_init_hook_t)(int, char **);
/** PROTOTYPES ******************************************************/
/* GnuCash version number infomation. */
@ -46,9 +50,6 @@ void gnc_engine_shutdown (void);
* it will be called during the evaluation of gnc_engine_init */
void gnc_engine_add_init_hook(gnc_engine_init_hook_t hook);
/* this is a global table of known commodity types. */
gnc_commodity_table * gnc_engine_commodities(void);
/* Many strings used throughout the engine are likely to be duplicated.
* So we provide a reference counted cache system for the strings, which
* shares strings whenever possible.
@ -71,4 +72,3 @@ gnc_commodity_table * gnc_engine_commodities(void);
GCache* gnc_engine_get_string_cache(void);
#endif

View File

@ -53,11 +53,7 @@
#define GNC_SESSION_H
#include "gnc-book.h"
/** TYPES **********************************************************/
typedef struct gnc_session_struct GNCSession;
#include "gnc-engine.h"
/** PROTOTYPES ******************************************************/

View File

@ -45,12 +45,6 @@ gnc_module_init(int refcount)
gh_eval_str("(use-modules (gnucash engine))");
gh_eval_str("(use-modules (g-wrapped gw-engine))");
if(refcount == 0)
{
/* and set up the gnc-commodity stuff */
gh_eval_str("(gnc:load-iso-4217-currencies)");
gh_eval_str("(gnc:setup-default-namespaces)");
}
return TRUE;
}

View File

@ -2114,6 +2114,14 @@ of having a parent transaction with which one is working...")
'((<gnc:commodity*> comm1) (<gnc:commodity*> comm2))
"Return true if the two commodities are equivalent.")
(gw:wrap-function
mod
'gnc:commodity-table-new
'<gnc:commodity-table*>
"gnc_commodity_table_new"
'()
"Return a new commodity table.");
(gw:wrap-function
mod
'gnc:commodity-table-lookup
@ -2187,18 +2195,8 @@ of having a parent transaction with which one is working...")
((<gw:m-chars-caller-owned> gw:const) namespace))
"Return a list of all the namespaces in the table.")
(gw:wrap-function
mod
'gnc:engine-commodities
'<gnc:commodity-table*>
"gnc_engine_commodities"
'()
"Get the engine's list of known commodity types.")
;;=========
(gw:wrap-function
mod
'gnc:engine-shutdown

View File

@ -16,7 +16,6 @@
#include "test-engine-stuff.h"
#include "test-stuff.h"
static gboolean add_comms_to_engine = TRUE;
static gboolean glist_strings_only = FALSE;
static GHashTable *exclude_kvp_types = NULL;
@ -83,12 +82,6 @@ glist_type_excluded (kvp_value_t kvp_type)
return FALSE;
}
void
add_random_commodities_to_engine (gboolean add)
{
add_comms_to_engine = add;
}
void
random_glist_strings_only (gboolean strings_only)
{
@ -131,7 +124,7 @@ get_random_commodity_namespace(void)
}
GNCPrice *
get_random_price(void)
get_random_price(GNCSession *session)
{
GNCPrice *p;
Timespec *ts;
@ -140,12 +133,10 @@ get_random_price(void)
p = gnc_price_create ();
c = get_random_commodity ();
c = gnc_commodity_table_insert (gnc_engine_commodities (), c);
c = get_random_commodity (session);
gnc_price_set_commodity (p, c);
c = get_random_commodity ();
c = gnc_commodity_table_insert (gnc_engine_commodities (), c);
c = get_random_commodity (session);
gnc_price_set_currency (p, c);
ts = get_random_timespec ();
@ -166,7 +157,7 @@ get_random_price(void)
}
void
make_random_pricedb (GNCPriceDB *db)
make_random_pricedb (GNCSession *session, GNCPriceDB *db)
{
int num_prices;
@ -176,7 +167,7 @@ make_random_pricedb (GNCPriceDB *db)
{
GNCPrice *p;
p = get_random_price ();
p = get_random_price (session);
gnc_pricedb_add_price (db, p);
@ -185,12 +176,12 @@ make_random_pricedb (GNCPriceDB *db)
}
GNCPriceDB *
get_random_pricedb(void)
get_random_pricedb(GNCSession *session)
{
GNCPriceDB *db;
db = gnc_pricedb_create ();
make_random_pricedb (db);
make_random_pricedb (session, db);
return db;
}
@ -411,7 +402,7 @@ set_account_random_string(Account* act,
}
static void
account_add_subaccounts (Account *account, int depth)
account_add_subaccounts (GNCSession *session, Account *account, int depth)
{
int num_accounts;
@ -422,16 +413,16 @@ account_add_subaccounts (Account *account, int depth)
while (num_accounts-- > 0)
{
Account *sub = get_random_account ();
Account *sub = get_random_account (session);
xaccAccountInsertSubAccount (account, sub);
account_add_subaccounts (sub, depth - 1);
account_add_subaccounts (session, sub, depth - 1);
}
}
static AccountGroup *
get_random_group_depth(int depth)
get_random_group_depth(GNCSession *session, int depth)
{
AccountGroup *group;
int num_accounts;
@ -445,32 +436,32 @@ get_random_group_depth(int depth)
while (num_accounts-- > 0)
{
Account *account = get_random_account ();
Account *account = get_random_account (session);
xaccGroupInsertAccount (group, account);
account_add_subaccounts (account, depth - 1);
account_add_subaccounts (session, account, depth - 1);
}
return group;
}
AccountGroup *
get_random_group(void)
get_random_group (GNCSession *session)
{
int depth;
depth = get_random_int_in_range (1, max_group_depth);
return get_random_group_depth (depth);
return get_random_group_depth (session, depth);
}
Account*
get_random_account(void)
get_random_account(GNCSession *session)
{
Account *ret;
int tmp_int;
ret = xaccMallocAccount();
xaccAccountBeginEdit(ret);
@ -483,11 +474,12 @@ get_random_account(void)
set_account_random_string(ret, xaccAccountSetCode);
set_account_random_string(ret, xaccAccountSetDescription);
xaccAccountSetCommodity(ret, get_random_commodity());
xaccAccountSetCommodity(ret, get_random_commodity(session));
xaccAccountSetSlots_nc(ret, get_random_kvp_frame());
xaccAccountCommitEdit(ret);
return ret;
}
@ -506,7 +498,7 @@ set_split_random_string(Split *spl,
static char possible_chars[] = { 'c', 'y', 'f', 'n' };
Split*
get_random_split(gnc_numeric num)
get_random_split(GNCSession *session, gnc_numeric num)
{
Split *ret;
gnc_numeric oneVal;
@ -533,7 +525,7 @@ get_random_split(gnc_numeric num)
xaccSplitSetAccountGUID(ret, *ranguid);
g_free(ranguid);
}
return ret;
}
@ -550,11 +542,12 @@ set_tran_random_string(Transaction* trn,
}
static void
add_random_splits(Transaction *trn)
add_random_splits(GNCSession *session, Transaction *trn)
{
gnc_numeric num = get_random_gnc_numeric();
xaccTransAppendSplit(trn, get_random_split(num));
xaccTransAppendSplit(trn, get_random_split(gnc_numeric_neg(num)));
xaccTransAppendSplit(trn, get_random_split(session, num));
xaccTransAppendSplit(trn, get_random_split(session, gnc_numeric_neg(num)));
}
static void
@ -570,7 +563,7 @@ trn_add_ran_timespec(Transaction *trn, void (*func)(Transaction*,
Transaction*
get_random_transaction(void)
get_random_transaction(GNCSession *session)
{
Transaction* ret;
@ -578,7 +571,7 @@ get_random_transaction(void)
xaccTransBeginEdit(ret);
xaccTransSetCurrency(ret, get_random_commodity ());
xaccTransSetCurrency(ret, get_random_commodity (session));
set_tran_random_string(ret, xaccTransSetNum);
@ -589,7 +582,7 @@ get_random_transaction(void)
xaccTransSetSlots_nc(ret, get_random_kvp_frame());
add_random_splits(ret);
add_random_splits(session, ret);
xaccTransCommitEdit(ret);
@ -597,7 +590,7 @@ get_random_transaction(void)
}
gnc_commodity*
get_random_commodity (void)
get_random_commodity (GNCSession *session)
{
gnc_commodity *ret;
gchar *name;
@ -605,13 +598,16 @@ get_random_commodity (void)
gchar *mn;
gchar *xcode;
int ran_int;
gnc_commodity_table *table;
mn = get_random_string();
space = get_random_commodity_namespace();
if (add_comms_to_engine)
table = gnc_book_get_commodity_table (gnc_session_get_book (session));
if (table)
{
ret = gnc_commodity_table_lookup (gnc_engine_commodities (), space, mn);
ret = gnc_commodity_table_lookup (table, space, mn);
if (ret)
{
@ -630,8 +626,8 @@ get_random_commodity (void)
g_free(name);
g_free(xcode);
if (add_comms_to_engine)
ret = gnc_commodity_table_insert (gnc_engine_commodities (), ret);
if (table)
ret = gnc_commodity_table_insert (table, ret);
return ret;
}
@ -824,13 +820,13 @@ get_random_query(void)
}
GNCBook *
get_random_book (void)
get_random_book (GNCSession *session)
{
GNCBook *book;
book = gnc_book_new ();
gnc_book_set_group (book, get_random_group ());
gnc_book_set_group (book, get_random_group (session));
/* make_random_pricedb (gnc_book_get_pricedb (book)); */

View File

@ -9,7 +9,7 @@
#include <glib.h>
#include <stdlib.h>
#include "gnc-book.h"
#include "gnc-session.h"
#include "Query.h"
#include "date.h"
#include "gnc-pricedb.h"
@ -37,21 +37,18 @@ void set_max_kvp_frame_elements (gint max_kvp_frame_elements);
void set_max_group_depth (gint max_group_depth);
void set_max_group_accounts (gint max_group_accounts);
GNCPrice * get_random_price(void);
void make_random_pricedb (GNCPriceDB *pdb);
GNCPriceDB * get_random_pricedb(void);
AccountGroup * get_random_group(void);
Account* get_random_account(void);
Split* get_random_split(gnc_numeric num);
Transaction* get_random_transaction(void);
gnc_commodity* get_random_commodity(void);
GNCPrice * get_random_price(GNCSession *session);
void make_random_pricedb (GNCSession *session, GNCPriceDB *pdb);
GNCPriceDB * get_random_pricedb(GNCSession *session);
AccountGroup * get_random_group(GNCSession * session);
Account* get_random_account(GNCSession * session);
Split* get_random_split(GNCSession *session, gnc_numeric num);
Transaction* get_random_transaction(GNCSession *session);
gnc_commodity* get_random_commodity(GNCSession *session);
const char *get_random_commodity_namespace(void);
Query* get_random_query(void);
GNCBook * get_random_book (void);
void add_random_commodities_to_engine (gboolean add);
GNCBook * get_random_book (GNCSession *session);
#endif

View File

@ -1,9 +1,11 @@
#include <glib.h>
#include <guile/gh.h>
#include "gnc-engine-util.h"
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "gnc-module.h"
#include "test-engine-stuff.h"
#include "test-stuff.h"
@ -20,7 +22,7 @@ test_commodity(void)
success("commodity new and destroy");
}
{
char *fullname;
const char *namespace;
@ -103,15 +105,17 @@ test_commodity(void)
int j;
gnc_commodity_table *tbl;
gnc_commodity *coms[20];
GNCSession *session;
tbl = gnc_commodity_table_new();
session = gnc_session_new ();
tbl = gnc_commodity_table_new ();
do_test(gnc_commodity_table_get_size(tbl) == 0,
"test size for 0 table");
"test size for 0 table");
for(i = 0; i < 20; i++)
{
coms[i] = get_random_commodity();
coms[i] = get_random_commodity(session);
do_test(
gnc_commodity_table_insert(tbl, coms[i]) != NULL,
@ -119,8 +123,10 @@ test_commodity(void)
do_test_args(
gnc_commodity_table_get_size(tbl) == i + 1,
"test next size table", __FILE__, __LINE__, "should be %d and is %d", i + 1, gnc_commodity_table_get_size(tbl));
"test next size table", __FILE__, __LINE__,
"should be %d and is %d", i + 1,
gnc_commodity_table_get_size(tbl));
for(j = 0; j <= i; j++)
{
gnc_commodity *testcom;
@ -144,12 +150,18 @@ test_commodity(void)
}
int
main(int argc, char **argv)
static void
main_helper (int argc, char **argv)
{
gnc_engine_init (argc, argv);
add_random_commodities_to_engine (FALSE);
test_commodity();
print_test_results();
exit(get_rv());
gnc_module_load("gnucash/engine", 0);
test_commodity();
print_test_results();
exit(get_rv());
}
int
main (int argc, char **argv)
{
gh_enter (argc, argv, main_helper);
return 0;
}

View File

@ -1,9 +1,11 @@
#include <glib.h>
#include <guile/gh.h>
#include "GNCIdP.h"
#include "gnc-book.h"
#include "gnc-engine.h"
#include "gnc-module.h"
#include "test-engine-stuff.h"
#include "test-stuff.h"
@ -37,13 +39,16 @@ group_has_book (AccountGroup *group, GNCBook *book)
static void
run_test (void)
{
GNCSession *session;
AccountGroup *group1;
AccountGroup *group2;
Account *account1;
Account *account2;
GNCBook *book;
group1 = get_random_group ();
session = gnc_session_new ();
group1 = get_random_group (session);
if(!group1)
{
failure("group1 not created");
@ -70,7 +75,7 @@ run_test (void)
exit(get_rv());
}
group2 = get_random_group ();
group2 = get_random_group (session);
if(!group2)
{
failure("group2 not created");
@ -91,7 +96,7 @@ run_test (void)
exit(get_rv());
}
account1 = get_random_account ();
account1 = get_random_account (session);
if(!account1)
{
failure("account1 not created");
@ -105,7 +110,7 @@ run_test (void)
exit(get_rv());
}
account2 = get_random_account ();
account2 = get_random_account (session);
if(!account2)
{
failure("account2 not created");
@ -133,12 +138,12 @@ run_test (void)
}
}
int
main (int argc, char **argv)
static void
main_helper (int argc, char **argv)
{
int i;
gnc_engine_init (argc, argv);
gnc_module_load("gnucash/engine", 0);
for (i = 0; i < 10; i++)
run_test ();
@ -147,3 +152,10 @@ main (int argc, char **argv)
print_test_results();
exit(get_rv());
}
int
main (int argc, char **argv)
{
gh_enter (argc, argv, main_helper);
return 0;
}

View File

@ -58,7 +58,6 @@ run_tests (void)
static void
main_helper (int argc, char **argv)
{
gnc_module_load("gnucash/engine", 0);
run_tests ();

View File

@ -1,10 +1,13 @@
#include <glib.h>
#include <guile/gh.h>
#include "GNCIdP.h"
#include "Account.h"
#include "gnc-engine.h"
#include "gnc-module.h"
#include "gnc-session.h"
#include "test-engine-stuff.h"
#include "test-stuff.h"
#include "Transaction.h"
@ -25,36 +28,37 @@ is_null_guid(const GUID *id)
return TRUE;
}
int
main(int argc, char **argv)
static void
run_test (void)
{
Account *act1;
Account *act2;
Split *spl;
gnc_numeric num;
GNCSession *session;
gnc_engine_init (argc, argv);
session = gnc_session_new ();
act1 = get_random_account();
act1 = get_random_account(session);
if(!act1)
{
failure("act1 not created");
return(get_rv());
return;
}
act2 = get_random_account();
act2 = get_random_account(session);
if(!act2)
{
failure("act2 not created");
return(get_rv());
return;
}
num = get_random_gnc_numeric();
spl = get_random_split(num);
spl = get_random_split(session, num);
if(!spl)
{
failure("spl not created");
return(get_rv());
return;
}
xaccSplitSetAccount(spl, act1);
@ -62,14 +66,14 @@ main(int argc, char **argv)
if(act1 != xaccSplitGetAccount(spl))
{
failure("xaccSplitSetAccount is broken");
return(get_rv());
return;
}
if(!guid_equal(xaccAccountGetGUID(act1), xaccSplitGetAccountGUID(spl)))
{
failure("xaccSplitGetAccountGUID "
"after xaccSplitSetAccount failed");
return(get_rv());
failure("xaccSplitGetAccountGUID "
"after xaccSplitSetAccount failed");
return;
}
xaccSplitSetAccountGUID(spl, *xaccAccountGetGUID(act2));
@ -77,7 +81,7 @@ main(int argc, char **argv)
if(act2 != xaccSplitGetAccount(spl))
{
failure("xaccSplitSetAccountGUID is broken");
return(get_rv());
return;
}
xaccSplitSetAccount(spl, NULL);
@ -86,18 +90,33 @@ main(int argc, char **argv)
{
failure_args("xaccSplitSetAccount(NULL)",
__FILE__, __LINE__, "account not NULL");
return(get_rv());
return;
}
if(!is_null_guid(xaccSplitGetAccountGUID(spl)))
{
failure_args("xaccSplitSetAccount(NULL)",
__FILE__, __LINE__, "account guid not NULL");
return(get_rv());
return;
}
success("split account crap seems to work");
print_test_results();
return(get_rv());
}
static void
main_helper (int argc, char **argv)
{
gnc_module_load("gnucash/engine", 0);
run_test ();
success("split account crap seems to work");
print_test_results();
exit(get_rv());
}
int
main (int argc, char **argv)
{
gh_enter (argc, argv, main_helper);
return 0;
}

View File

@ -30,6 +30,7 @@
#include "dialog-utils.h"
#include "gnc-engine-util.h"
#include "gnc-gui-query.h"
#include "gnc-ui-util.h"
#include "gnc-ui.h"
#include "messages.h"
#include "window-help.h"
@ -196,14 +197,17 @@ g_strcmp(gconstpointer a, gconstpointer b) {
void
gnc_ui_update_commodity_picker(GtkWidget * combobox,
const char * namespace,
const char * init_string) {
GList * commodities =
gnc_commodity_table_get_commodities(gnc_engine_commodities(),
namespace);
const char * init_string)
{
GList * commodities;
GList * iterator = NULL;
GList * commodity_items = NULL;
gnc_commodity_table *table;
const char * current;
table = gnc_book_get_commodity_table (gnc_get_current_book ());
commodities = gnc_commodity_table_get_commodities(table, namespace);
for(iterator = commodities; iterator; iterator = iterator->next) {
commodity_items =
g_list_append(commodity_items,
@ -249,9 +253,9 @@ gnc_ui_select_commodity_destroy(SelectCommodityWindow * w) {
static void
gnc_ui_select_commodity_ok_cb(GtkButton * button,
gpointer user_data) {
gpointer user_data)
{
SelectCommodityWindow * w = user_data;
const char * namespace;
char * fullname;
gnc_commodity * retval = NULL;
@ -259,7 +263,7 @@ gnc_ui_select_commodity_ok_cb(GtkButton * button,
namespace = gnc_ui_namespace_picker_ns (w->namespace_combo);
fullname = gtk_entry_get_text(GTK_ENTRY(w->commodity_entry));
retval = gnc_commodity_table_find_full(gnc_engine_commodities(),
retval = gnc_commodity_table_find_full(gnc_get_current_commodities(),
namespace,
fullname);
if(retval) {
@ -347,7 +351,8 @@ gnc_ui_update_namespace_picker(GtkWidget * combobox,
/* fetch a list of the namespaces */
if (!include_all)
namespaces = gnc_commodity_table_get_namespaces(gnc_engine_commodities());
namespaces =
gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
else
{
namespaces = NULL;
@ -629,7 +634,7 @@ gnc_ui_commodity_ok_cb(GtkButton * button,
if(fullname && fullname[0] &&
namespace && namespace[0] &&
mnemonic && mnemonic[0]) {
c = gnc_commodity_table_lookup (gnc_engine_commodities(),
c = gnc_commodity_table_lookup (gnc_get_current_commodities(),
namespace, mnemonic);
if ((!w->edit_commodity && c) ||
@ -645,7 +650,7 @@ gnc_ui_commodity_ok_cb(GtkButton * button,
else {
c = w->edit_commodity;
gnc_commodity_table_remove (gnc_engine_commodities(), c);
gnc_commodity_table_remove (gnc_get_current_commodities(), c);
gnc_commodity_set_fullname (c, fullname);
gnc_commodity_set_mnemonic (c, mnemonic);
@ -655,7 +660,7 @@ gnc_ui_commodity_ok_cb(GtkButton * button,
}
/* remember the commodity */
c = gnc_commodity_table_insert(gnc_engine_commodities(), c);
c = gnc_commodity_table_insert(gnc_get_current_commodities(), c);
/* if there's a callback (generally to fill in some fields with
* info about the commodity) call it */

View File

@ -40,6 +40,7 @@
#include "gnc-currency-edit.h"
#include "gnc-commodity.h"
#include "gnc-engine.h"
#include "gnc-ui-util.h"
#include "messages.h"
@ -145,7 +146,7 @@ fill_currencies(GNCCurrencyEdit *gce)
GList *node;
currencies = gnc_commodity_table_get_commodities
(gnc_engine_commodities (), GNC_COMMODITY_NS_ISO);
(gnc_get_current_commodities (), GNC_COMMODITY_NS_ISO);
currencies = g_list_sort(currencies, currency_compare);
@ -212,7 +213,7 @@ gnc_currency_edit_get_currency (GNCCurrencyEdit *gce)
mnemonic = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(gce)->entry));
return gnc_commodity_table_lookup (gnc_engine_commodities (),
return gnc_commodity_table_lookup (gnc_get_current_commodities (),
GNC_COMMODITY_NS_ISO,
mnemonic);
}

View File

@ -110,7 +110,7 @@ gnc_load_namespace (gpointer data, gpointer user_data)
safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) == 0)
return;
ct = gnc_engine_commodities ();
ct = gnc_get_current_commodities ();
commodities = gnc_commodity_table_get_commodities (ct, namespace);
@ -163,7 +163,7 @@ gnc_commodities_load_commodities (CommoditiesDialog *cd)
int new_row;
guint size;
ct = gnc_engine_commodities ();
ct = gnc_get_current_commodities ();
namespaces = gnc_commodity_table_get_namespaces (ct);
namespaces = g_list_sort (namespaces, namespace_compare);
@ -271,7 +271,7 @@ remove_clicked (GtkWidget *widget, gpointer data)
if (do_delete)
{
gnc_commodity_table *ct = gnc_engine_commodities ();
gnc_commodity_table *ct = gnc_get_current_commodities ();
gnc_commodity_table_remove (ct, cd->commodity);
gnc_commodity_destroy (cd->commodity);

View File

@ -351,7 +351,8 @@ on_choose_account_types_prepare (GnomeDruidPage *gnomedruidpage,
gchar *locale_dir = gnc_get_ea_locale_dir (GNC_ACCOUNTS_DIR);
gnc_suspend_gui_refresh ();
list = gnc_load_example_account_list (locale_dir);
list = gnc_load_example_account_list (gnc_get_current_session (),
locale_dir);
gnc_resume_gui_refresh ();
clist = get_account_types_clist ();

View File

@ -212,7 +212,7 @@ gnc_main_window_can_cancel_save (GNCMDIInfo *wind)
static gboolean
gnc_main_window_can_restore_cb (const char * filename)
{
return !gnc_commodity_table_has_namespace (gnc_engine_commodities (),
return !gnc_commodity_table_has_namespace (gnc_get_current_commodities (),
GNC_COMMODITY_NS_LEGACY);
}

View File

@ -91,10 +91,11 @@ static void gnc_ui_commodity_druid_finish_cb(GnomeDruidPage * page,
void
gnc_import_legacy_commodities(const char * filename) {
gnc_import_legacy_commodities(const char * filename)
{
CommodityDruid * d;
if (!gnc_commodity_table_has_namespace (gnc_engine_commodities (),
if (!gnc_commodity_table_has_namespace (gnc_get_current_commodities (),
GNC_COMMODITY_NS_LEGACY))
return;
@ -166,7 +167,7 @@ gnc_ui_commodity_druid_create(const char * filename) {
d->new_map = g_hash_table_new(g_str_hash, g_str_equal);
d->old_map = g_hash_table_new(g_str_hash, g_str_equal);
orphans =
gnc_commodity_table_get_commodities(gnc_engine_commodities(),
gnc_commodity_table_get_commodities(gnc_get_current_commodities(),
GNC_COMMODITY_NS_LEGACY);
/* make a new list with the (saved) old mnemonic and the
@ -176,7 +177,7 @@ gnc_ui_commodity_druid_create(const char * filename) {
/* if the mnemonic is an ISO-4217 currency, use that as
* the default */
found = gnc_commodity_table_lookup(gnc_engine_commodities(),
found = gnc_commodity_table_lookup(gnc_get_current_commodities(),
GNC_COMMODITY_NS_ISO,
gnc_commodity_get_mnemonic(lost));
@ -346,7 +347,7 @@ gnc_ui_commodity_druid_destroy(CommodityDruid * cd) {
CommodityDruidPage * cdp;
/* remove the old commodities no matter how we exit */
gnc_commodity_table_delete_namespace(gnc_engine_commodities(),
gnc_commodity_table_delete_namespace(gnc_get_current_commodities(),
GNC_COMMODITY_NS_LEGACY);
for(p=cd->pages; p; p=p->next) {
@ -415,7 +416,7 @@ gnc_ui_commodity_druid_comm_check_cb(GnomeDruidPage * page, gpointer druid,
}
if (safe_strcmp (new_type, GNC_COMMODITY_NS_ISO) == 0 &&
!gnc_commodity_table_lookup (gnc_engine_commodities (),
!gnc_commodity_table_lookup (gnc_get_current_commodities (),
new_type, new_mnemonic))
{
gnc_warning_dialog_parented(cd->window,
@ -451,7 +452,7 @@ finish_helper(gpointer key, gpointer value, gpointer data) {
/* key is the old mnemonic, value is a pointer to the gnc_commodity
* structure. */
comm = gnc_commodity_table_insert(gnc_engine_commodities(), comm);
comm = gnc_commodity_table_insert(gnc_get_current_commodities(), comm);
/* s/old commodity/new commodity/g in the pricedb */
gnc_pricedb_substitute_commodity(gnc_book_get_pricedb(book),
@ -461,19 +462,26 @@ finish_helper(gpointer key, gpointer value, gpointer data) {
/* now replace all the accounts using old_comm with new_comm */
accts = xaccGroupGetSubAccounts(gnc_get_current_group ());
for(node = accts; node; node = node->next) {
for(node = accts; node; node = node->next)
{
Account *account = node->data;
GNCSession *session;
session = gnc_get_current_session ();
xaccAccountBeginEdit(account);
if(gnc_commodity_equiv(DxaccAccountGetCurrency(account), old_comm)) {
DxaccAccountSetCurrency(account, comm);
}
if(gnc_commodity_equiv(DxaccAccountGetSecurity(account), old_comm)) {
DxaccAccountSetSecurity(account, comm);
}
if(gnc_commodity_equiv(xaccAccountGetCommodity(account), old_comm)) {
if (gnc_commodity_equiv (DxaccAccountGetCurrency(account, session),
old_comm))
DxaccAccountSetCurrency (account, comm, session);
if (gnc_commodity_equiv (DxaccAccountGetSecurity(account, session),
old_comm))
DxaccAccountSetSecurity(account, comm, session);
if (gnc_commodity_equiv (xaccAccountGetCommodity(account), old_comm))
xaccAccountSetCommodity(account, comm);
}
xaccAccountCommitEdit(account);
}
@ -491,7 +499,8 @@ gnc_ui_commodity_druid_finish_cb(GnomeDruidPage * page, gpointer druid,
g_hash_table_foreach(cd->new_map, &finish_helper, (gpointer)cd);
/* Fix account and transaction commodities */
xaccGroupScrubCommodities (gnc_get_current_group ());
xaccGroupScrubCommodities (gnc_get_current_group (),
gnc_get_current_session ());
/* Fix split amount/value */
xaccGroupScrubSplits (gnc_get_current_group ());

View File

@ -1071,10 +1071,10 @@ gnc_ui_qif_import_convert(QIFImportWindow * wind) {
gnc_commodity_set_fullname(page->commodity, fullname);
gnc_commodity_set_mnemonic(page->commodity, mnemonic);
page->commodity = gnc_commodity_table_insert(gnc_engine_commodities(),
page->commodity = gnc_commodity_table_insert(gnc_get_current_commodities(),
page->commodity);
}
/* call a scheme function to do the work. The return value is an
* account group containing all the new accounts and transactions */
retval = gh_apply(qif_to_gnc,
@ -1311,7 +1311,7 @@ gnc_ui_qif_import_comm_check_cb(GnomeDruidPage * page,
}
if (safe_strcmp (namespace, GNC_COMMODITY_NS_ISO) == 0 &&
!gnc_commodity_table_lookup (gnc_engine_commodities (),
!gnc_commodity_table_lookup (gnc_get_current_commodities (),
namespace, mnemonic))
{
gnc_warning_dialog_parented(wind->window,

View File

@ -157,8 +157,9 @@
(namespace (cadr entry))
(mnemonic (caddr entry)))
(hash-set! table name
(gnc:commodity-table-lookup (gnc:engine-commodities)
namespace mnemonic)))))
(gnc:commodity-table-lookup
(gnc:book-get-commodity-table (gnc:get-current-book))
namespace mnemonic)))))
commlist)
table))

View File

@ -182,7 +182,7 @@
(separator (string-ref (gnc:account-separator-char) 0))
(default-currency
(gnc:commodity-table-find-full
(gnc:engine-commodities)
(gnc:book-get-commodity-table (gnc:get-current-book))
GNC_COMMODITY_NS_ISO default-currency-name))
(sorted-accounts-list '())
(markable-xtns '())

View File

@ -14,7 +14,10 @@
(gnc:module-load "gnucash/qif-io/core" 0)
(let ((qiffile (qif-io:make-empty-file))
(acct-table (qif-io:make-empty-acct-table)))
(acct-table (qif-io:make-empty-acct-table))
(com-table (gnc:commodity-table-new)))
(gnc:engine-commodity-table-construct com-table)
;; read the file and look at data formats. we need to do this
;; immediately when loading a file.
@ -36,9 +39,8 @@
(if (qif-io:file-xtns-need-acct? qiffile)
(qif-io:file-set-default-src-acct! qiffile filename))
(let ((commodity
(gnc:commodity-table-lookup
(gnc:engine-commodities) "ISO4217" "USD")))
(let ((commodity (gnc:commodity-table-lookup com-table "ISO4217" "USD")))
;; import the bank transactions
(for-each
(lambda (xtn)
@ -50,7 +52,7 @@
(lambda (xtn)
(qif-io:invst-xtn-import xtn qiffile acct-table commodity))
(qif-io:file-invst-xtns qiffile))
;; build a gnucash account group
(let ((group (qif-io:acct-table-make-gnc-group
acct-table qiffile commodity)))
@ -108,6 +110,3 @@
(if all-pass
(exit 0)
(exit -1))))

View File

@ -428,8 +428,9 @@ gnc_ledger_display_template_gl (char *id)
q = xaccMallocQuery ();
ag = gnc_book_get_template_group
(xaccGroupGetBook (gnc_get_current_group ()));
book = gnc_get_current_book ();
ag = gnc_book_get_template_group (book);
acct = xaccGetAccountFromName (ag, id);
if (!acct)
{
@ -438,7 +439,6 @@ gnc_ledger_display_template_gl (char *id)
}
xaccQueryAddSingleAccountMatch (q, acct, QUERY_AND);
book = xaccGroupGetBook (gnc_get_current_group ());
xaccQuerySetGroup (q, gnc_book_get_template_group(book));
ld = gnc_ledger_display_internal (NULL, q, LD_GL,

View File

@ -197,7 +197,7 @@
pagename name-report-currency
sort-tag
(N_ "Select the currency to display the values of this report in.")
(gnc:default-currency))))
(gnc:locale-default-iso-currency-code))))
;; These are common options for the selection of the report's
;; currency/commodity.

View File

@ -75,7 +75,7 @@
pagename-price optname-price-commodity
"e"
(N_ "Calculate the price of this commodity.")
(gnc:default-currency)))
(gnc:locale-default-iso-currency-code)))
(add-option
(gnc:make-multichoice-option

View File

@ -36,7 +36,7 @@
(newline)
(display (_ "Report bugs and other problems to gnucash-devel@gnucash.org."))
(newline)
(display (sprintf #f (_ "The last stable version was %s.") "GnuCash 1.6.2"))
(display (sprintf #f (_ "The last stable version was %s.") "GnuCash 1.6.4"))
(newline)
(display (sprintf #f (_ "The next stable version will be %s.")
"GnuCash 1.8.0"))