Utility functions for the GnuCash GUI
[GUI]


Files

file  gnc-ui-util.h
 utility functions for the GnuCash UI

Data Structures

struct  _GNCPrintAmountInfo

Typedefs

typedef QofSession *(* QofSessionCB )(void)
typedef _GNCPrintAmountInfo GNCPrintAmountInfo

Enumerations

enum  GNCEquityType { EQUITY_OPENING_BALANCE, EQUITY_RETAINED_EARNINGS, NUM_EQUITY_TYPES }

Functions

char gnc_get_account_separator (void)
gboolean gnc_reverse_balance (Account *account)
gboolean gnc_reverse_balance_type (GNCAccountType type)
void gnc_init_default_directory (char **dirname)
void gnc_extract_directory (char **dirname, const char *filename)
QofBookgnc_get_current_book (void)
AccountGroupgnc_get_current_group (void)
gnc_commodity_tablegnc_get_current_commodities (void)
gnc_numeric gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn, Account *account, gboolean recurse, gboolean *negative, gnc_commodity *commodity)
gnc_numeric gnc_ui_account_get_balance (Account *account, gboolean include_children)
gnc_numeric gnc_ui_account_get_balance_in_currency (Account *account, gnc_commodity *currency, gboolean recurse)
gnc_numeric gnc_ui_account_get_reconciled_balance (Account *account, gboolean include_children)
gchar * gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn, Account *account, gboolean recurse, gboolean *negative)
gchar * gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn, Account *account, gboolean recurse, gboolean *negative)
char * gnc_ui_account_get_tax_info_string (Account *account)
gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account, time_t date, gboolean include_children)
const char * gnc_get_reconcile_str (char reconciled_flag)
const char * gnc_get_reconcile_valid_flags (void)
const char * gnc_get_reconcile_flag_order (void)
Accountgnc_find_or_create_equity_account (AccountGroup *group, GNCEquityType equity_type, gnc_commodity *currency, QofBook *book)
gboolean gnc_account_create_opening_balance (Account *account, gnc_numeric balance, time_t date, QofBook *book)
char * gnc_account_get_full_name (Account *account)
lconv * gnc_localeconv (void)
gnc_commoditygnc_locale_default_currency_nodefault (void)
gnc_commoditygnc_locale_default_currency (void)
const char * gnc_locale_default_iso_currency_code (void)
int gnc_locale_decimal_places (void)
void gnc_push_locale (const char *locale)
void gnc_pop_locale (void)
GNCPrintAmountInfo gnc_default_print_info (gboolean use_symbol)
GNCPrintAmountInfo gnc_commodity_print_info (const gnc_commodity *commodity, gboolean use_symbol)
GNCPrintAmountInfo gnc_account_print_info (Account *account, gboolean use_symbol)
GNCPrintAmountInfo gnc_split_amount_print_info (Split *split, gboolean use_symbol)
GNCPrintAmountInfo gnc_split_value_print_info (Split *split, gboolean use_symbol)
GNCPrintAmountInfo gnc_share_print_info_places (int decplaces)
GNCPrintAmountInfo gnc_default_share_print_info (void)
GNCPrintAmountInfo gnc_default_price_print_info (void)
GNCPrintAmountInfo gnc_integral_print_info (void)
const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info)
int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info)
gboolean xaccParseAmount (const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr)
gboolean xaccParseAmountExtended (const char *in_str, gboolean monetary, char negative_sign, char decimal_point, char group_separator, char *group, char *ignore_list, gnc_numeric *result, char **endstr)
void gnc_ui_util_init (void)
gint32 towupper (gint32 wc)
int iswlower (gint32 wc)


Function Documentation

gnc_numeric gnc_ui_account_get_balance Account account,
gboolean  include_children
 

This routine retrives the total balance in an account, possibly including all sub-accounts under the specified account.

Parameters:
account The account to retrieve data about.
include_children Include all sub-accounts of this account.

Definition at line 257 of file gnc-ui-util.c.

00258 {
00259   return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
00260                                           account, recurse, NULL, NULL);
00261 }

gchar* gnc_ui_account_get_print_balance xaccGetBalanceInCurrencyFn  fn,
Account account,
gboolean  recurse,
gboolean *  negative
 

Wrapper around gnc_ui_account_get_balance_full that converts the resulting number to a character string. The number is formatted according to the specification of the account currency. The caller is responsible for g_free'ing the returned memory.

Parameters:
fn The underlying function in Account.c to call to retrieve a specific balance from the account.
account The account to retrieve data about.
recurse Include all sub-accounts of this account.
negative An indication of whether or not the returned value is negative. This can be used by the caller to easily decode whether or not to color the output.

Definition at line 304 of file gnc-ui-util.c.

00308 {
00309   GNCPrintAmountInfo print_info;
00310   gnc_numeric balance;
00311 
00312   balance = gnc_ui_account_get_balance_full(fn, account, recurse,
00313                                             negative, NULL);
00314   print_info = gnc_account_print_info(account, TRUE);
00315   return g_strdup(xaccPrintAmount(balance, print_info));
00316 }

gchar* gnc_ui_account_get_print_report_balance xaccGetBalanceInCurrencyFn  fn,
Account account,
gboolean  recurse,
gboolean *  negative
 

Wrapper around gnc_ui_account_get_balance_full that converts the resulting number to a character string. The number is formatted according to the specification of the default reporting currency.

Parameters:
fn The underlying function in Account.c to call to retrieve a specific balance from the account.
account The account to retrieve data about.
recurse Include all sub-accounts of this account.
negative An indication of whether or not the returned value is negative. This can be used by the caller to easily decode whether or not to color the output.

Definition at line 334 of file gnc-ui-util.c.

00338 {
00339   GNCPrintAmountInfo print_info;
00340   gnc_numeric balance;
00341   gnc_commodity *report_commodity;
00342 
00343   report_commodity = gnc_default_report_currency();
00344   balance = gnc_ui_account_get_balance_full(fn, account, recurse,
00345                                             negative, report_commodity);
00346   print_info = gnc_commodity_print_info(report_commodity, TRUE);
00347   return g_strdup(xaccPrintAmount(balance, print_info));
00348 }

gnc_numeric gnc_ui_account_get_reconciled_balance Account account,
gboolean  include_children
 

This routine retrives the reconciled balance in an account, possibly including all sub-accounts under the specified account.

Parameters:
account The account to retrieve data about.
include_children Include all sub-accounts of this account.

Definition at line 281 of file gnc-ui-util.c.

00283 {
00284   return gnc_ui_account_get_balance_full (xaccAccountGetReconciledBalanceInCurrency,
00285                                           account, recurse, NULL, NULL);
00286 }

int xaccSPrintAmount char *  bufp,
gnc_numeric  val,
GNCPrintAmountInfo  info
 

Parameters:
bufp Should be at least 64 chars.

Definition at line 1294 of file gnc-ui-util.c.

01295 {
01296    struct lconv *lc;
01297 
01298    char *orig_bufp = bufp;
01299    const char *currency_symbol;
01300    const char *sign;
01301 
01302    char cs_precedes;
01303    char sep_by_space;
01304    char sign_posn;
01305 
01306    gboolean print_sign = TRUE;
01307    gboolean is_shares = FALSE;
01308 
01309    if (!bufp)
01310      return 0;
01311 
01312    lc = gnc_localeconv();
01313 
01314    if (info.use_symbol)
01315    {
01316      /* There was a bug here: don't use gnc_locale_default_currency */
01317      if (gnc_commodity_equiv (info.commodity, 
01318                               gnc_locale_default_currency_nodefault ()))
01319      {
01320        currency_symbol = lc->currency_symbol;
01321      }
01322      else
01323      {
01324        if (info.commodity && !gnc_commodity_is_iso (info.commodity))
01325          is_shares = TRUE;
01326 
01327        currency_symbol = gnc_commodity_get_mnemonic (info.commodity);
01328        info.use_locale = 0;
01329      }
01330 
01331      if (currency_symbol == NULL)
01332        currency_symbol = "";
01333    }
01334    else
01335      currency_symbol = NULL;
01336 
01337    if (!info.use_locale)
01338    {
01339      cs_precedes = is_shares ? 0 : 1;
01340      sep_by_space = 1;
01341    }
01342    else
01343    {
01344      if (gnc_numeric_negative_p (val))
01345      {
01346        cs_precedes  = lc->n_cs_precedes;
01347        sep_by_space = lc->n_sep_by_space;
01348      }
01349      else
01350      {
01351        cs_precedes  = lc->p_cs_precedes;
01352        sep_by_space = lc->p_sep_by_space;
01353      }
01354    }
01355 
01356    if (gnc_numeric_negative_p (val))
01357    {
01358      sign = lc->negative_sign;
01359      sign_posn = lc->n_sign_posn;
01360    }
01361    else
01362    {
01363      sign = lc->positive_sign;
01364      sign_posn = lc->p_sign_posn;
01365    }
01366 
01367    if (gnc_numeric_zero_p (val) || (sign == NULL) || (sign[0] == 0))
01368      print_sign = FALSE;
01369 
01370    /* See if we print sign now */
01371    if (print_sign && (sign_posn == 1))
01372      bufp = gnc_stpcpy(bufp, sign);
01373 
01374    /* Now see if we print currency */
01375    if (cs_precedes)
01376    {
01377      /* See if we print sign now */
01378      if (print_sign && (sign_posn == 3))
01379        bufp = gnc_stpcpy(bufp, sign);
01380 
01381      if (info.use_symbol)
01382      {
01383        bufp = gnc_stpcpy(bufp, currency_symbol);
01384        if (sep_by_space)
01385          bufp = gnc_stpcpy(bufp, " ");
01386      }
01387 
01388      /* See if we print sign now */
01389      if (print_sign && (sign_posn == 4))
01390        bufp = gnc_stpcpy(bufp, sign);
01391    }
01392 
01393    /* Now see if we print parentheses */
01394    if (print_sign && (sign_posn == 0))
01395      bufp = gnc_stpcpy(bufp, "(");
01396 
01397    /* Now print the value */
01398    bufp += PrintAmountInternal(bufp, val, &info);
01399 
01400    /* Now see if we print parentheses */
01401    if (print_sign && (sign_posn == 0))
01402      bufp = gnc_stpcpy(bufp, ")");
01403 
01404    /* Now see if we print currency */
01405    if (!cs_precedes)
01406    {
01407      /* See if we print sign now */
01408      if (print_sign && (sign_posn == 3))
01409        bufp = gnc_stpcpy(bufp, sign);
01410 
01411      if (info.use_symbol)
01412      {
01413        if (sep_by_space)
01414          bufp = gnc_stpcpy(bufp, " ");
01415        bufp = gnc_stpcpy(bufp, currency_symbol);
01416      }
01417 
01418      /* See if we print sign now */
01419      if (print_sign && (sign_posn == 4))
01420        bufp = gnc_stpcpy(bufp, sign);
01421    }
01422 
01423    /* See if we print sign now */
01424    if (print_sign && (sign_posn == 2))
01425      bufp = gnc_stpcpy(bufp, sign);
01426 
01427    /* return length of printed string */
01428    return (bufp - orig_bufp);
01429 }


Generated on Sun Sep 4 18:09:06 2005 for GnuCash by  doxygen 1.4.3-20050530