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

gboolean gnc_reverse_balance (const Account *account)
gboolean gnc_reverse_balance_type (GNCAccountType type)
gchar * gnc_get_default_directory (const gchar *gconf_section)
void gnc_set_default_directory (const gchar *gconf_section, const gchar *directory)
QofBookgnc_get_current_book (void)
Accountgnc_get_current_root_account (void)
gnc_commodity_tablegnc_get_current_commodities (void)
gnc_numeric gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn, const Account *account, gboolean recurse, gboolean *negative, const gnc_commodity *commodity)
gnc_numeric gnc_ui_account_get_balance (const Account *account, gboolean include_children)
gnc_numeric gnc_ui_account_get_balance_in_currency (const Account *account, const gnc_commodity *currency, gboolean recurse)
gnc_numeric gnc_ui_account_get_reconciled_balance (const Account *account, gboolean include_children)
gchar * gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn, const Account *account, gboolean recurse, gboolean *negative)
gchar * gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn, const Account *account, gboolean recurse, gboolean *negative)
char * gnc_ui_account_get_tax_info_string (const 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 (Account *root, GNCEquityType equity_type, gnc_commodity *currency)
gboolean gnc_account_create_opening_balance (Account *account, gnc_numeric balance, time_t date, QofBook *book)
char * gnc_account_get_full_name (const 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)
gnc_commoditygnc_default_currency (void)
gnc_commoditygnc_default_report_currency (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 (const 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)
const gchar * printable_value (gdouble val, gint denom)
gchar * number_to_words (gdouble val, gint64 denom)
gchar * numeric_to_words (gnc_numeric val)
gboolean xaccParseAmount (const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr)
gboolean xaccParseAmountExtended (const char *in_str, gboolean monetary, gunichar negative_sign, gunichar decimal_point, gunichar 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)


Enumeration Type Documentation

enum GNCEquityType

Enumerator:
EQUITY_OPENING_BALANCE 
EQUITY_RETAINED_EARNINGS 
NUM_EQUITY_TYPES 

Definition at line 157 of file gnc-ui-util.h.


Function Documentation

gnc_commodity* gnc_default_currency ( void   ) 

Return the default currency set by the user. If the user's preference is invalid, then this routine will return the default currency for the user's locale.

Returns:
A pointer to a currency.

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

00865 {
00866   gnc_commodity *currency = NULL;
00867   gchar *choice, *mnemonic;
00868 
00869   if (user_default_currency)
00870     return gnc_commodity_table_lookup(gnc_get_current_commodities(),
00871                                       GNC_COMMODITY_NS_CURRENCY,
00872                                       user_default_currency);
00873 
00874   choice = gnc_gconf_get_string(GCONF_GENERAL, KEY_CURRENCY_CHOICE, NULL);
00875   if (choice && strcmp(choice, "other") == 0) {
00876     mnemonic = gnc_gconf_get_string(GCONF_GENERAL, KEY_CURRENCY_OTHER, NULL);
00877     currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
00878                                           GNC_COMMODITY_NS_CURRENCY, mnemonic);
00879     DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
00880     g_free(mnemonic);
00881   }
00882   g_free(choice);
00883 
00884   if (!currency)
00885     currency = gnc_locale_default_currency ();
00886   if (currency) {
00887     mnemonic = user_default_currency;
00888     user_default_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
00889     g_free(mnemonic);
00890   }
00891   return currency;
00892 }

gnc_commodity* gnc_default_report_currency ( void   ) 

Return the default currency for use in reports, as set by the user. If the user's preference is invalid, then this routine will return the default currency for the user's locale.

Returns:
A pointer to a currency.

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

00896 {
00897   gnc_commodity *currency = NULL;
00898   gchar *choice, *mnemonic;
00899 
00900   if (user_report_currency)
00901     return gnc_commodity_table_lookup(gnc_get_current_commodities(),
00902                                       GNC_COMMODITY_NS_CURRENCY,
00903                                       user_report_currency);
00904   choice = gnc_gconf_get_string(GCONF_GENERAL_REPORT,
00905                                 KEY_CURRENCY_CHOICE, NULL);
00906   if (choice && strcmp(choice, "other") == 0) {
00907     mnemonic = gnc_gconf_get_string(GCONF_GENERAL_REPORT,
00908                                     KEY_CURRENCY_OTHER, NULL);
00909     currency = gnc_commodity_table_lookup(gnc_get_current_commodities(),
00910                                           GNC_COMMODITY_NS_CURRENCY, mnemonic);
00911     DEBUG("mnemonic %s, result %p", mnemonic ? mnemonic : "(null)", currency);
00912     g_free(mnemonic);
00913   }
00914   g_free(choice);
00915 
00916   if (!currency)
00917     currency = gnc_locale_default_currency (); 
00918   if (currency) {
00919     mnemonic = user_report_currency;
00920     user_report_currency = g_strdup(gnc_commodity_get_mnemonic(currency));
00921     g_free(mnemonic);
00922   }
00923   return currency;
00924 }

gnc_numeric gnc_ui_account_get_balance ( const 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 260 of file gnc-ui-util.c.

00261 {
00262   return gnc_ui_account_get_balance_full (xaccAccountGetBalanceInCurrency,
00263                                           account, recurse, NULL, NULL);
00264 }

gchar* gnc_ui_account_get_print_balance ( xaccGetBalanceInCurrencyFn  fn,
const 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 308 of file gnc-ui-util.c.

00312 {
00313   GNCPrintAmountInfo print_info;
00314   gnc_numeric balance;
00315 
00316   balance = gnc_ui_account_get_balance_full(fn, account, recurse,
00317                                             negative, NULL);
00318   print_info = gnc_account_print_info(account, TRUE);
00319   return g_strdup(xaccPrintAmount(balance, print_info));
00320 }

gchar* gnc_ui_account_get_print_report_balance ( xaccGetBalanceInCurrencyFn  fn,
const 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 338 of file gnc-ui-util.c.

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

gnc_numeric gnc_ui_account_get_reconciled_balance ( const 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 285 of file gnc-ui-util.c.

00287 {
00288   return gnc_ui_account_get_balance_full (xaccAccountGetReconciledBalanceInCurrency,
00289                                           account, recurse, NULL, NULL);
00290 }

int xaccSPrintAmount ( char *  bufp,
gnc_numeric  val,
GNCPrintAmountInfo  info 
)

Parameters:
bufp Should be at least 64 chars.

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

01437 {
01438    struct lconv *lc;
01439 
01440    char *orig_bufp = bufp;
01441    const char *currency_symbol;
01442    const char *sign;
01443 
01444    char cs_precedes;
01445    char sep_by_space;
01446    char sign_posn;
01447 
01448    gboolean print_sign = TRUE;
01449    gboolean is_shares = FALSE;
01450 
01451    if (!bufp)
01452      return 0;
01453 
01454    lc = gnc_localeconv();
01455 
01456    if (info.use_symbol)
01457    {
01458      /* There was a bug here: don't use gnc_locale_default_currency */
01459      if (gnc_commodity_equiv (info.commodity, 
01460                               gnc_locale_default_currency_nodefault ()))
01461      {
01462        currency_symbol = lc->currency_symbol;
01463      }
01464      else
01465      {
01466        if (info.commodity && !gnc_commodity_is_iso (info.commodity))
01467          is_shares = TRUE;
01468 
01469        currency_symbol = gnc_commodity_get_mnemonic (info.commodity);
01470        info.use_locale = 0;
01471      }
01472 
01473      if (currency_symbol == NULL)
01474        currency_symbol = "";
01475    }
01476    else
01477      currency_symbol = NULL;
01478 
01479    if (!info.use_locale)
01480    {
01481      cs_precedes = is_shares ? 0 : 1;
01482      sep_by_space = 1;
01483    }
01484    else
01485    {
01486      if (gnc_numeric_negative_p (val))
01487      {
01488        cs_precedes  = lc->n_cs_precedes;
01489        sep_by_space = lc->n_sep_by_space;
01490      }
01491      else
01492      {
01493        cs_precedes  = lc->p_cs_precedes;
01494        sep_by_space = lc->p_sep_by_space;
01495      }
01496    }
01497 
01498    if (gnc_numeric_negative_p (val))
01499    {
01500      sign = lc->negative_sign;
01501      sign_posn = lc->n_sign_posn;
01502    }
01503    else
01504    {
01505      sign = lc->positive_sign;
01506      sign_posn = lc->p_sign_posn;
01507    }
01508 
01509    if (gnc_numeric_zero_p (val) || (sign == NULL) || (sign[0] == 0))
01510      print_sign = FALSE;
01511 
01512    /* See if we print sign now */
01513    if (print_sign && (sign_posn == 1))
01514      bufp = g_stpcpy(bufp, sign);
01515 
01516    /* Now see if we print currency */
01517    if (cs_precedes)
01518    {
01519      /* See if we print sign now */
01520      if (print_sign && (sign_posn == 3))
01521        bufp = g_stpcpy(bufp, sign);
01522 
01523      if (info.use_symbol)
01524      {
01525        bufp = g_stpcpy(bufp, currency_symbol);
01526        if (sep_by_space)
01527          bufp = g_stpcpy(bufp, " ");
01528      }
01529 
01530      /* See if we print sign now */
01531      if (print_sign && (sign_posn == 4))
01532        bufp = g_stpcpy(bufp, sign);
01533    }
01534 
01535    /* Now see if we print parentheses */
01536    if (print_sign && (sign_posn == 0))
01537      bufp = g_stpcpy(bufp, "(");
01538 
01539    /* Now print the value */
01540    bufp += PrintAmountInternal(bufp, val, &info);
01541 
01542    /* Now see if we print parentheses */
01543    if (print_sign && (sign_posn == 0))
01544      bufp = g_stpcpy(bufp, ")");
01545 
01546    /* Now see if we print currency */
01547    if (!cs_precedes)
01548    {
01549      /* See if we print sign now */
01550      if (print_sign && (sign_posn == 3))
01551        bufp = g_stpcpy(bufp, sign);
01552 
01553      if (info.use_symbol)
01554      {
01555        if (sep_by_space)
01556          bufp = g_stpcpy(bufp, " ");
01557        bufp = g_stpcpy(bufp, currency_symbol);
01558      }
01559 
01560      /* See if we print sign now */
01561      if (print_sign && (sign_posn == 4))
01562        bufp = g_stpcpy(bufp, sign);
01563    }
01564 
01565    /* See if we print sign now */
01566    if (print_sign && (sign_posn == 2))
01567      bufp = g_stpcpy(bufp, sign);
01568 
01569    /* return length of printed string */
01570    return (bufp - orig_bufp);
01571 }


Generated on Thu Jul 3 05:07:14 2008 for GnuCash by  doxygen 1.5.2