GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Data Structures | Macros | Typedefs | Enumerations | Functions
Utility functions for the GnuCash GUI

Files

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

Data Structures

struct  _GNCPrintAmountInfo
 

Macros

#define GNC_PREFS_GROUP_OPEN_SAVE   "dialogs.open-save"
 
#define GNC_PREFS_GROUP_EXPORT   "dialogs.export-accounts"
 
#define GNC_PREFS_GROUP_REPORT   "dialogs.report"
 
#define GNC_PREF_AUTO_DECIMAL_POINT   "auto-decimal-point"
 
#define GNC_PREF_AUTO_DECIMAL_PLACES   "auto-decimal-places"
 

Typedefs

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

Enumerations

enum  GNCEquityType { EQUITY_OPENING_BALANCE, EQUITY_RETAINED_EARNINGS, NUM_EQUITY_TYPES }
 

Functions

gchar * gnc_normalize_account_separator (const gchar *separator)
 
gboolean gnc_reverse_balance (const Account *account)
 
gchar * gnc_get_default_directory (const gchar *section)
 
void gnc_set_default_directory (const gchar *section, const gchar *directory)
 
QofBookgnc_get_current_book (void)
 
gboolean gnc_is_new_book (void)
 
void gnc_set_current_book_tax_name (const gchar *tax_name)
 
const gchar * gnc_get_current_book_tax_name (void)
 
void gnc_set_current_book_tax_type (const gchar *tax_type)
 
const gchar * gnc_get_current_book_tax_type (void)
 
void gnc_book_option_num_field_source_change_cb (gboolean num_action)
 
Accountgnc_get_current_root_account (void)
 
gnc_commodity_tablegnc_get_current_commodities (void)
 
gchar * gnc_get_account_name_for_register (const Account *account)
 
Accountgnc_account_lookup_for_register (const Account *base_account, const gchar *name)
 
char * gnc_ui_account_get_tax_info_string (const Account *account)
 
char * gnc_ui_account_get_tax_info_sub_acct_string (const Account *account)
 
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, time64 date, QofBook *book)
 
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_account_or_default_currency (const Account *account, gboolean *currency_from_account_found)
 
gnc_commoditygnc_default_report_currency (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_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)
 

Detailed Description

Function Documentation

Account* gnc_account_lookup_for_register ( const Account base_account,
const gchar *  name 
)

Retrieve the account matching the given name starting from the descendants of base_account. name is either considered to be the name of the leaf in the account tree or to be the full account path, depending on the configuration parameter general.register/show_leaf_account_names.

Parameters
base_accountThe account to start the search at.
nameThe name to search for.
Returns
A pointer to the account, or NULL if the account was not found.
gnc_commodity* gnc_account_or_default_currency ( const Account account,
gboolean *  currency_from_account_found 
)

Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency. The gnc_commodity is taken either from the current account, or from the next parent account that has a gnc_commodity that is a currency, or from gnc_default_currency().

If the given account or any of its parent account have a commodity that is a currency, it is returned and the gboolean currency_from_account_found is set to TRUE (if non-NULL). If neither this account nor any of its parent accounts have such a commodity, gnc_default_currency() is returned and the gboolean currency_from_account_found is set to FALSE (if non-NULL). This can be used to show an appropriate warning message.

If account is NULL, gnc_default_currency() is returned and currency_from_account_found is set to FALSE.

Parameters
accountThe account where the currency should be looked up. May be NULL.
currency_from_account_foundA gboolean pointer that takes the output argument of whether the returned currency was found in the account. May be NULL.
Returns
A currency pointer (and never NULL).

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

945 {
946  gnc_commodity *currency;
947  if (!account)
948  {
949  if (currency_from_account_found)
950  *currency_from_account_found = FALSE;
951  return gnc_default_currency();
952  }
953 
954  currency = gnc_account_get_currency_or_parent(account);
955  if (currency)
956  {
957  if (currency_from_account_found)
958  *currency_from_account_found = TRUE;
959  }
960  else
961  {
962  if (currency_from_account_found)
963  *currency_from_account_found = FALSE;
964  currency = gnc_default_currency();
965  }
966  return currency;
967 }
gnc_commodity * gnc_default_currency(void)
Definition: gnc-ui-util.c:939
gnc_commodity * gnc_account_get_currency_or_parent(const Account *account)
Definition: Account.c:3155
void gnc_book_option_num_field_source_change_cb ( gboolean  num_action)

Calls gnc_book_option_num_field_source_change to initiate registered callbacks when num_field_source book option changes so that registers/reports can update themselves; sets feature flag

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

254 {
255  gnc_suspend_gui_refresh ();
256  if (num_action)
257  {
258  /* Set a feature flag in the book for use of the split action field as number.
259  * This will prevent older GnuCash versions that don't support this feature
260  * from opening this file. */
261  gnc_features_set_used (gnc_get_current_book(),
262  GNC_FEATURE_NUM_FIELD_SOURCE);
263  }
264  gnc_book_option_num_field_source_change (num_action);
265  gnc_resume_gui_refresh ();
266  gnc_gui_refresh_all ();
267 }
void gnc_features_set_used(QofBook *book, const gchar *feature)
Definition: gnc-features.c:131
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 939 of file gnc-ui-util.c.

940 {
941  return gnc_default_currency_common (user_default_currency, GNC_PREFS_GROUP_GENERAL);
942 }
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 972 of file gnc-ui-util.c.

973 {
974  return gnc_default_currency_common (user_report_currency, GNC_PREFS_GROUP_GENERAL_REPORT);
975 }
gchar* gnc_get_account_name_for_register ( const Account account)

Get either the full name of the account or the simple name, depending on the configuration parameter general/register/show_leaf_account_names.

Parameters
accountThe account to retrieve the name for.
Returns
A newly allocated string.

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

283 {
284  gboolean show_leaf_accounts;
285  show_leaf_accounts = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER,
286  GNC_PREF_SHOW_LEAF_ACCT_NAMES);
287 
288  if (show_leaf_accounts)
289  return g_strdup (xaccAccountGetName (account));
290  else
291  return gnc_account_get_full_name (account);
292 }
gchar * gnc_account_get_full_name(const Account *account)
Definition: Account.c:3038
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:196
const char * xaccAccountGetName(const Account *acc)
Definition: Account.c:3031
int xaccSPrintAmount ( char *  bufp,
gnc_numeric  val,
GNCPrintAmountInfo  info 
)
Parameters
bufpShould be at least 64 chars.

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

1438 {
1439  struct lconv *lc;
1440 
1441  char *orig_bufp = bufp;
1442  const char *currency_symbol;
1443  const char *sign;
1444 
1445  char cs_precedes;
1446  char sep_by_space;
1447  char sign_posn;
1448 
1449  gboolean print_sign = TRUE;
1450  gboolean is_shares = FALSE;
1451  gboolean print_absolute = FALSE;
1452 
1453  if (!bufp)
1454  return 0;
1455 
1456  lc = gnc_localeconv();
1457  if (info.use_locale)
1458  if (gnc_numeric_negative_p (val))
1459  {
1460  cs_precedes = lc->n_cs_precedes;
1461  sep_by_space = lc->n_sep_by_space;
1462  }
1463  else
1464  {
1465  cs_precedes = lc->p_cs_precedes;
1466  sep_by_space = lc->p_sep_by_space;
1467  }
1468  else
1469  {
1470  cs_precedes = TRUE;
1471  sep_by_space = TRUE;
1472  }
1473 
1474  if (info.commodity && info.use_symbol)
1475  {
1476  if (gnc_commodity_is_iso (info.commodity))
1477  currency_symbol = gnc_commodity_get_nice_symbol (info.commodity);
1478  else
1479  {
1480  currency_symbol = gnc_commodity_get_mnemonic (info.commodity);
1481  cs_precedes = FALSE;
1482  sep_by_space = TRUE;
1483  }
1484  }
1485  else /* !info.use_symbol || !info.commodity */
1486  currency_symbol = "";
1487 
1488  if (gnc_numeric_negative_p (val))
1489  {
1490  sign = lc->negative_sign;
1491  sign_posn = lc->n_sign_posn;
1492  }
1493  else
1494  {
1495  sign = lc->positive_sign;
1496  sign_posn = lc->p_sign_posn;
1497  }
1498 
1499  if (gnc_numeric_zero_p (val) || (sign == NULL) || (sign[0] == 0))
1500  print_sign = FALSE;
1501 
1502  /* See if we print sign now */
1503  if (print_sign && (sign_posn == 1))
1504  bufp = g_stpcpy(bufp, sign);
1505 
1506  /* Now see if we print currency */
1507  if (cs_precedes)
1508  {
1509  /* See if we print sign now */
1510  if (print_sign && (sign_posn == 3))
1511  bufp = g_stpcpy(bufp, sign);
1512 
1513  if (info.use_symbol)
1514  {
1515  bufp = g_stpcpy(bufp, currency_symbol);
1516  if (sep_by_space)
1517  bufp = g_stpcpy(bufp, " ");
1518  }
1519 
1520  /* See if we print sign now */
1521  if (print_sign && (sign_posn == 4))
1522  bufp = g_stpcpy(bufp, sign);
1523  }
1524 
1525  /* Now see if we print parentheses */
1526  if (print_sign && (sign_posn == 0))
1527  {
1528  bufp = g_stpcpy(bufp, "(");
1529  print_absolute = TRUE;
1530  }
1531 
1532  /* Now print the value */
1533  bufp += PrintAmountInternal(bufp,
1534  print_absolute ? gnc_numeric_abs(val) : val,
1535  &info);
1536 
1537  /* Now see if we print parentheses */
1538  if (print_sign && (sign_posn == 0))
1539  bufp = g_stpcpy(bufp, ")");
1540 
1541  /* Now see if we print currency */
1542  if (!cs_precedes)
1543  {
1544  /* See if we print sign now */
1545  if (print_sign && (sign_posn == 3))
1546  bufp = g_stpcpy(bufp, sign);
1547 
1548  if (info.use_symbol)
1549  {
1550  if (sep_by_space)
1551  bufp = g_stpcpy(bufp, " ");
1552  bufp = g_stpcpy(bufp, currency_symbol);
1553  }
1554 
1555  /* See if we print sign now */
1556  if (print_sign && (sign_posn == 4))
1557  bufp = g_stpcpy(bufp, sign);
1558  }
1559 
1560  /* See if we print sign now */
1561  if (print_sign && (sign_posn == 2))
1562  bufp = g_stpcpy(bufp, sign);
1563 
1564  /* return length of printed string */
1565  return (bufp - orig_bufp);
1566 }
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
gboolean gnc_numeric_zero_p(gnc_numeric a)
gboolean gnc_numeric_negative_p(gnc_numeric a)
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
gnc_numeric gnc_numeric_abs(gnc_numeric a)
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)