GnuCash 2.4.99
gnc-ui-util.h
Go to the documentation of this file.
00001 /********************************************************************\
00002  * gnc-ui-util.h -- utility functions for the GnuCash UI            *
00003  * Copyright (C) 2000 Dave Peticolas <dave@krondo.com>              *
00004  *                                                                  *
00005  * This program is free software; you can redistribute it and/or    *
00006  * modify it under the terms of the GNU General Public License as   *
00007  * published by the Free Software Foundation; either version 2 of   *
00008  * the License, or (at your option) any later version.              *
00009  *                                                                  *
00010  * This program is distributed in the hope that it will be useful,  *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00013  * GNU General Public License for more details.                     *
00014  *                                                                  *
00015  * You should have received a copy of the GNU General Public License*
00016  * along with this program; if not, contact:                        *
00017  *                                                                  *
00018  * Free Software Foundation           Voice:  +1-617-542-5942       *
00019  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00020  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00021 \********************************************************************/
00022 
00032 #ifndef GNC_UI_UTIL_H
00033 #define GNC_UI_UTIL_H
00034 
00035 #include <glib.h>
00036 #include <locale.h>
00037 
00038 #include "Account.h"
00039 #include "gncOwner.h"
00040 #include "qof.h"
00041 
00042 
00043 typedef QofSession * (*QofSessionCB) (void);
00044 
00045 
00046 gboolean gnc_reverse_balance(const Account *account);
00047 
00048 /* Default directory sections ***************************************/
00049 #define GCONF_DIR_OPEN_SAVE "dialogs/open_save"
00050 #define GCONF_DIR_EXPORT "dialogs/export_accounts"
00051 #define GCONF_DIR_REPORT "dialogs/report"
00052 
00053 /* Default directories **********************************************/
00054 
00055 gchar *gnc_get_default_directory (const gchar *gconf_section);
00056 void gnc_set_default_directory (const gchar *gconf_section,
00057                                 const gchar *directory);
00058 
00059 /* Engine enhancements & i18n ***************************************/
00060 QofBook * gnc_get_current_book (void);
00061 void gnc_set_current_book_tax_name (const gchar *tax_name);
00062 const gchar * gnc_get_current_book_tax_name (void);
00063 void gnc_set_current_book_tax_type (const gchar *tax_type);
00064 const gchar * gnc_get_current_book_tax_type (void);
00065 Account * gnc_get_current_root_account (void);
00066 gnc_commodity_table * gnc_get_current_commodities (void);
00067 
00075 gchar *gnc_get_account_name_for_register(const Account *account);
00076 
00088 Account *gnc_account_lookup_for_register(const Account *base_account, const
00089         gchar *name);
00090 
00091 /*
00092  * This is a wrapper routine around an xaccGetBalanceInCurrency
00093  * function that handles additional needs of the gui.
00094  *
00095  * @param fn        The underlying function in Account.c to call to retrieve
00096  *                  a specific balance from the account.
00097  * @param account   The account to retrieve data about.
00098  * @param recurse   Include all sub-accounts of this account.
00099  * @param negative  An indication of whether or not the returned value
00100  *                  is negative.  This can be used by the caller to
00101  *                  easily decode whether or not to color the output.
00102  * @param commodity The commodity in which the account balance should
00103  *                  be returned. If NULL, the value will be returned in
00104  *                  the commodity of the account. This is normally used
00105  *                  to specify a currency, which forces the conversion
00106  *                  of things like stock account values from share
00107  *                  values to an amount the requested currency.
00108  */
00109 char *gnc_ui_account_get_tax_info_string (const Account *account);
00110 
00111 char *gnc_ui_account_get_tax_info_sub_acct_string (const Account *account);
00112 
00113 const char * gnc_get_reconcile_str (char reconciled_flag);
00114 const char * gnc_get_reconcile_valid_flags (void);
00115 const char * gnc_get_reconcile_flag_order (void);
00116 
00117 typedef enum
00118 {
00119     EQUITY_OPENING_BALANCE,
00120     EQUITY_RETAINED_EARNINGS,
00121     NUM_EQUITY_TYPES
00122 } GNCEquityType;
00123 
00124 Account * gnc_find_or_create_equity_account (Account *root,
00125         GNCEquityType equity_type,
00126         gnc_commodity *currency);
00127 gboolean gnc_account_create_opening_balance (Account *account,
00128         gnc_numeric balance,
00129         time_t date,
00130         QofBook *book);
00131 
00132 /* Locale functions *************************************************/
00133 
00134 
00135 /* Returns the default currency of the current locale, or NULL if no
00136  * sensible currency could be identified from the locale. */
00137 gnc_commodity * gnc_locale_default_currency_nodefault (void);
00138 
00139 /* Returns the default currency of the current locale. WATCH OUT: If
00140  * no currency could be identified from the locale, this one returns
00141  * "USD", but this will have nothing to do with the actual locale. */
00142 gnc_commodity * gnc_locale_default_currency (void);
00143 
00144 /* Returns the default ISO currency string of the current locale. */
00145 const char * gnc_locale_default_iso_currency_code (void);
00146 
00147 
00154 gnc_commodity * gnc_default_currency (void);
00155 
00156 
00163 gnc_commodity * gnc_default_report_currency (void);
00164 
00165 /* Amount printing and parsing **************************************/
00166 
00167 /*
00168  * The xaccPrintAmount() and xaccSPrintAmount() routines provide
00169  *    i18n'ed convenience routines for printing gnc_numerics.
00170  *    amounts. Both routines take a gnc_numeric argument and
00171  *    a printing information object.
00172  *
00173  * The xaccPrintAmount() routine returns a pointer to a statically
00174  *    allocated buffer, and is therefore not thread-safe.
00175  *
00176  * The xaccSPrintAmount() routine accepts a pointer to the buffer to be
00177  *    printed to.  It returns the length of the printed string.
00178  */
00179 
00180 typedef struct _GNCPrintAmountInfo
00181 {
00182     const gnc_commodity *commodity;  /* may be NULL */
00183 
00184     guint8 max_decimal_places;
00185     guint8 min_decimal_places;
00186 
00187     unsigned int use_separators : 1; /* Print thousands separators */
00188     unsigned int use_symbol : 1;     /* Print currency symbol */
00189     unsigned int use_locale : 1;     /* Use locale for some positioning */
00190     unsigned int monetary : 1;       /* Is a monetary quantity */
00191     unsigned int force_fit : 1;      /* Don't print more than max_dp places */
00192     unsigned int round : 1;          /* Round at max_dp instead of truncating */
00193 } GNCPrintAmountInfo;
00194 
00195 
00196 GNCPrintAmountInfo gnc_default_print_info (gboolean use_symbol);
00197 
00198 GNCPrintAmountInfo gnc_commodity_print_info (const gnc_commodity *commodity,
00199         gboolean use_symbol);
00200 
00201 GNCPrintAmountInfo gnc_account_print_info (const Account *account,
00202         gboolean use_symbol);
00203 
00204 GNCPrintAmountInfo gnc_split_amount_print_info (Split *split,
00205         gboolean use_symbol);
00206 
00207 GNCPrintAmountInfo gnc_share_print_info_places (int decplaces);
00208 GNCPrintAmountInfo gnc_default_share_print_info (void);
00209 GNCPrintAmountInfo gnc_default_price_print_info (void);
00210 
00211 GNCPrintAmountInfo gnc_integral_print_info (void);
00212 
00213 /* WARNING: Garbage in, garbage out.  You must check the validity of
00214    the supplied gnc_numeric.  If it's invalid, the returned string
00215    could point to ANYTHING. */
00216 const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
00217 int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
00218 
00219 const gchar *printable_value(gdouble val, gint denom);
00220 gchar *number_to_words(gdouble val, gint64 denom);
00221 gchar *numeric_to_words(gnc_numeric val);
00222 
00223 /* xaccParseAmount parses in_str to obtain a numeric result. The
00224  *   routine will parse as much of in_str as it can to obtain a single
00225  *   number. The number is parsed using the current locale information
00226  *   and the 'monetary' flag. The routine will return TRUE if it
00227  *   successfully parsed a number and FALSE otherwise. If TRUE is
00228  *   returned and result is non-NULL, the value of the parsed number
00229  *   is stored in *result. If FALSE is returned, *result is
00230  *   unchanged. If TRUE is returned and endstr is non-NULL, the
00231  *   location of the first character in in_str not used by the parser
00232  *   will be returned in *endstr. If FALSE is returned and endstr is
00233  *   non-NULL, *endstr will point to in_str. */
00234 gboolean xaccParseAmount (const char * in_str, gboolean monetary,
00235                           gnc_numeric *result, char **endstr);
00236 
00237 /*
00238  * xaccParseAmountExtended is just like xaccParseAmount except the
00239  * caller must provide all the locale-specific information.
00240  *
00241  * Note: if group is NULL, no group-size verification will take place.
00242  * ignore_list is a list of characters that are completely ignored
00243  * while processing the input string.  If ignore_list is NULL, nothing
00244  * is ignored.
00245  */
00246 gboolean
00247 xaccParseAmountExtended (const char * in_str, gboolean monetary,
00248                          gunichar negative_sign, gunichar decimal_point,
00249                          gunichar group_separator, char *group, char *ignore_list,
00250                          gnc_numeric *result, char **endstr);
00251 
00252 /* Initialization ***************************************************/
00253 
00254 void gnc_ui_util_init (void);
00255 
00256 #endif
00257 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines