/********************************************************************\ * gnc_is_trans_scm * * returns true if the scm object is a scheme transaction * * * * Args: scm - a scheme object * * Returns: true if scm is a scheme transaction * \********************************************************************/ gboolean gnc_is_trans_scm(SCM scm) { initialize_scm_functions(); return scm_is_true(scm_call_1(predicates.is_trans_scm, scm)); }
/********************************************************************\ * gnc_get_credit_string * * return a credit string for a given account type * * * * Args: account_type - type of account to get credit string for * * Return: g_malloc'd credit string or NULL * \********************************************************************/ char * gnc_get_credit_string(GNCAccountType account_type) { const gchar *string; SCM result; SCM arg; initialize_scm_functions(); if (gnc_gconf_get_bool(GCONF_GENERAL, KEY_ACCOUNTING_LABELS, NULL)) return g_strdup(_("Credit")); if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES)) account_type = ACCT_TYPE_NONE; arg = scm_long2num(account_type); result = scm_call_1(getters.credit_string, arg); if (!scm_is_string(result)) return NULL; string = scm_to_locale_string(result); if (string) return g_strdup(string); return NULL; }
/********************************************************************\ * gnc_trans_scm_append_split_scm * * append the scheme split onto the scheme transaction * * * * Args: trans_scm - the scheme transaction * * split_scm - the scheme split to append * * Returns: Nothing * \********************************************************************/ void gnc_trans_scm_append_split_scm(SCM trans_scm, SCM split_scm) { initialize_scm_functions(); if (!gnc_is_trans_scm(trans_scm)) return; if (!gnc_is_split_scm(split_scm)) return; scm_call_2(setters.trans_scm_append_split_scm, trans_scm, split_scm); }
/********************************************************************\ * gnc_split_scm_set_value * * set the value of a scheme split * * * * Args: split_scm - the scheme split * * value - the value to set * * Returns: Nothing * \********************************************************************/ void gnc_split_scm_set_value(SCM split_scm, gnc_numeric value) { SCM arg; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return; arg = gnc_numeric_to_scm(value); scm_call_2(setters.split_scm_value, split_scm, arg); }
/********************************************************************\ * gnc_split_scm_set_amount * * set the amount of a scheme split * * * * Args: split_scm - the scheme split * * amount - the amount to set * * Returns: Nothing * \********************************************************************/ void gnc_split_scm_set_amount(SCM split_scm, gnc_numeric amount) { SCM arg; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return; arg = gnc_numeric_to_scm(amount); scm_call_2(setters.split_scm_amount, split_scm, arg); }
/********************************************************************\ * gnc_trans_scm_get_split_scm * * get the indexth scheme split of a scheme transaction. * * * * Args: trans_scm - the scheme transaction * * index - the index of the split to get * * Returns: scheme split to get, or SCM_UNDEFINED if none * \********************************************************************/ SCM gnc_trans_scm_get_split_scm(SCM trans_scm, int index) { SCM arg; initialize_scm_functions(); if (!gnc_is_trans_scm(trans_scm)) return SCM_UNDEFINED; arg = scm_from_int (index); return scm_call_2(getters.trans_scm_split_scm, trans_scm, arg); }
/********************************************************************\ * gnc_split_scm_set_reconcile_state * * set the reconcile state of a scheme split. * * * * Args: split_scm - the scheme split * * reconcile_state - the reconcile state to set * * Returns: Nothing * \********************************************************************/ void gnc_split_scm_set_reconcile_state(SCM split_scm, char reconcile_state) { SCM arg; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return; arg = SCM_MAKE_CHAR(reconcile_state); scm_call_2(setters.split_scm_reconcile_state, split_scm, arg); }
/********************************************************************\ * gnc_trans_scm_set_description * * set the description of a scheme transaction. * * * * Args: trans_scm - the scheme transaction * * description - the description to set * * Returns: Nothing * \********************************************************************/ void gnc_trans_scm_set_description(SCM trans_scm, const char *description) { SCM arg; initialize_scm_functions(); if (!gnc_is_trans_scm(trans_scm)) return; if (description == NULL) return; arg = scm_from_utf8_string(description); scm_call_2(setters.trans_scm_description, trans_scm, arg); }
/********************************************************************\ * gnc_trans_scm_set_date * * set the date of a scheme transaction. * * * * Args: trans_scm - the scheme transaction * * ts - the time to set * * Returns: Nothing * \********************************************************************/ void gnc_trans_scm_set_date(SCM trans_scm, Timespec *ts) { SCM arg; initialize_scm_functions(); if (!gnc_is_trans_scm(trans_scm)) return; if (ts == NULL) return; arg = gnc_timespec2timepair(*ts); scm_call_2(setters.trans_scm_date, trans_scm, arg); }
/**********************************************************************\ * gnc_split_scm_get_action * * return the newly allocated action of a scheme split, or NULL. * * * * Args: split_scm - the scheme split * * Returns: newly allocated action string, must be freed with g_free * \**********************************************************************/ char * gnc_split_scm_get_action(SCM split_scm) { SCM result; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return NULL; result = scm_call_1(getters.split_scm_action, split_scm); if (!scm_is_string(result)) return NULL; return gnc_scm_to_utf8_string(result); }
/********************************************************************\ * gnc_split_scm_get_memo * * return the newly allocated memo of a scheme split, or NULL. * * * * Args: split_scm - the scheme split * * Returns: newly allocated memo string * \********************************************************************/ char * gnc_split_scm_get_memo(SCM split_scm) { SCM result; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return NULL; result = scm_call_1(getters.split_scm_memo, split_scm); if (!scm_is_string(result)) return NULL; return g_strdup(scm_to_locale_string(result)); }
/********************************************************************\ * gnc_split_scm_set_action * * set the action of a scheme representation of a split. * * * * Args: split_scm - the scheme split * * action - the action to set * * Returns: Nothing * \********************************************************************/ void gnc_split_scm_set_action(SCM split_scm, const char *action) { SCM arg; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return; if (action == NULL) return; arg = scm_from_utf8_string(action); scm_call_2(setters.split_scm_action, split_scm, arg); }
/********************************************************************\ * gnc_split_scm_set_memo * * set the memo of a scheme representation of a split. * * * * Args: split_scm - the scheme split * * memo - the memo to set * * Returns: Nothing * \********************************************************************/ void gnc_split_scm_set_memo(SCM split_scm, const char *memo) { SCM arg; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return; if (memo == NULL) return; arg = scm_from_utf8_string(memo); scm_call_2(setters.split_scm_memo, split_scm, arg); }
/********************************************************************\ * gnc_trans_scm_set_notes * * set the notes of a scheme transaction. * * * * Args: trans_scm - the scheme transaction * * notes - the notes to set * * Returns: Nothing * \********************************************************************/ void gnc_trans_scm_set_notes(SCM trans_scm, const char *notes) { SCM arg; initialize_scm_functions(); if (!gnc_is_trans_scm(trans_scm)) return; if (notes == NULL) return; arg = scm_from_utf8_string(notes); scm_call_2(setters.trans_scm_notes, trans_scm, arg); }
/********************************************************************\ * gnc_split_scm_get_value * * return the value of a scheme split * * * * Args: split_scm - the scheme split * * Returns: value of scheme split * \********************************************************************/ gnc_numeric gnc_split_scm_get_value(SCM split_scm) { SCM result; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return gnc_numeric_zero (); result = scm_call_1(getters.split_scm_value, split_scm); if (!gnc_numeric_p(result)) return gnc_numeric_zero (); return gnc_scm_to_numeric(result); }
/********************************************************************\ * gnc_trans_scm_set_num * * set the num of a scheme transaction. * * * * Args: trans_scm - the scheme transaction * * num - the num to set * * Returns: Nothing * \********************************************************************/ void gnc_trans_scm_set_num(SCM trans_scm, const char *num) { SCM arg; initialize_scm_functions(); if (!gnc_is_trans_scm(trans_scm)) return; if (num == NULL) return; arg = scm_makfrom0str(num); scm_call_2(setters.trans_scm_num, trans_scm, arg); }
/********************************************************************\ * gnc_trans_scm_get_num_splits * * get the number of scheme splits in a scheme transaction. * * * * Args: trans_scm - the scheme transaction * * Returns: number of scheme splits in the transaction * \********************************************************************/ int gnc_trans_scm_get_num_splits(SCM trans_scm) { SCM result; initialize_scm_functions(); if (!gnc_is_trans_scm(trans_scm)) return 0; result = scm_call_1(getters.trans_scm_split_scms, trans_scm); if (!scm_is_list(result)) return 0; return scm_to_int(scm_length(result)); }
/********************************************************************\ * gnc_trans_scm_get_other_split_scm * * get the other scheme split of a scheme transaction. * * * * Args: trans_scm - the scheme transaction * * split_scm - the split not to get * * Returns: other scheme split, or SCM_UNDEFINED if none * \********************************************************************/ SCM gnc_trans_scm_get_other_split_scm(SCM trans_scm, SCM split_scm) { SCM result; initialize_scm_functions(); if (!gnc_is_trans_scm(trans_scm)) return SCM_UNDEFINED; if (!gnc_is_split_scm(split_scm)) return SCM_UNDEFINED; result = scm_call_2(getters.trans_scm_other_split_scm, trans_scm, split_scm); if (!gnc_is_split_scm(result)) return SCM_UNDEFINED; return result; }
/********************************************************************\ * gnc_split_scm_set_account * * set the account of a scheme representation of a split. * * * * Args: split_scm - the scheme split * * account - the account to set * * Returns: Nothing * \********************************************************************/ void gnc_split_scm_set_account(SCM split_scm, Account *account) { gchar guid_string[GUID_ENCODING_LENGTH+1]; SCM arg; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return; if (account == NULL) return; guid_to_string_buff(xaccAccountGetGUID(account), guid_string); if (strlen(guid_string) == 0) return; arg = scm_from_utf8_string(guid_string); scm_call_2(setters.split_scm_account_guid, split_scm, arg); }
/********************************************************************\ * gnc_split_scm_set_account * * set the account of a scheme representation of a split. * * * * Args: split_scm - the scheme split * * account - the account to set * * Returns: Nothing * \********************************************************************/ void gnc_split_scm_set_account(SCM split_scm, Account *account) { const char *guid_string; SCM arg; initialize_scm_functions(); if (!gnc_is_split_scm(split_scm)) return; if (account == NULL) return; guid_string = guid_to_string(xaccAccountGetGUID(account)); if (guid_string == NULL) return; arg = scm_makfrom0str(guid_string); scm_call_2(setters.split_scm_account_guid, split_scm, arg); }
/************************************************************************\ * gnc_get_credit_string * * return a credit string for a given account type * * * * Args: account_type - type of account to get credit string for * * Return: g_malloc'd credit string or NULL, must be freed with g_free * \************************************************************************/ char * gnc_get_credit_string(GNCAccountType account_type) { SCM result; SCM arg; initialize_scm_functions(); if (gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNTING_LABELS)) return g_strdup(_("Credit")); if ((account_type < ACCT_TYPE_NONE) || (account_type >= NUM_ACCOUNT_TYPES)) account_type = ACCT_TYPE_NONE; arg = scm_from_long (account_type); result = scm_call_1(getters.credit_string, arg); if (!scm_is_string(result)) return NULL; return gnc_scm_to_utf8_string(result); }