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 "qof.h"
00040 
00041 
00042 typedef QofSession * (*QofSessionCB) (void);
00043 
00044 
00045 gboolean gnc_reverse_balance(const Account *account);
00046 gboolean gnc_reverse_balance_type(GNCAccountType type);
00047 
00048 
00049 /* Default directories **********************************************/
00050 
00051 gchar *gnc_get_default_directory (const gchar *gconf_section);
00052 void gnc_set_default_directory (const gchar *gconf_section,
00053                                 const gchar *directory);
00054 
00055 /* Engine enhancements & i18n ***************************************/
00056 QofBook * gnc_get_current_book (void);
00057 Account * gnc_get_current_root_account (void);
00058 gnc_commodity_table * gnc_get_current_commodities (void);
00059 
00067 gchar *gnc_get_account_name_for_register(const Account *account);
00068 
00080 Account *gnc_account_lookup_for_register(const Account *base_account, const
00081                                          gchar *name);
00082 
00083 /*
00084  * This is a wrapper routine around an xaccGetBalanceInCurrency
00085  * function that handles additional needs of the gui.
00086  *
00087  * @param fn        The underlying function in Account.c to call to retrieve
00088  *                  a specific balance from the account.
00089  * @param account   The account to retrieve data about.
00090  * @param recurse   Include all sub-accounts of this account.
00091  * @param negative  An indication of whether or not the returned value
00092  *                  is negative.  This can be used by the caller to
00093  *                  easily decode whether or not to color the output.
00094  * @param commodity The commodity in which the account balance should
00095  *                  be returned. If NULL, the value will be returned in
00096  *                  the commodity of the account. This is normally used
00097  *                  to specify a currency, which forces the conversion
00098  *                  of things like stock account values from share
00099  *                  values to an amount the requested currency.
00100  */
00101 gnc_numeric
00102 gnc_ui_account_get_balance_full (xaccGetBalanceInCurrencyFn fn,
00103                                  const Account *account,
00104                                  gboolean recurse,
00105                                  gboolean *negative,
00106                                  const gnc_commodity *commodity);
00107 
00115 gnc_numeric gnc_ui_account_get_balance (const Account *account,
00116                                         gboolean include_children);
00117 
00118 gnc_numeric gnc_ui_account_get_balance_in_currency (const Account *account,
00119                                                     const gnc_commodity *currency,
00120                                                     gboolean recurse);
00128 gnc_numeric gnc_ui_account_get_reconciled_balance(const Account *account,
00129                                                   gboolean include_children);
00130 
00144 gchar *
00145 gnc_ui_account_get_print_balance (xaccGetBalanceInCurrencyFn fn,
00146                                   const Account *account,
00147                                   gboolean recurse,
00148                                   gboolean *negative);
00149 
00164 gchar *
00165 gnc_ui_account_get_print_report_balance (xaccGetBalanceInCurrencyFn fn,
00166                                          const Account *account,
00167                                          gboolean recurse,
00168                                          gboolean *negative);
00169 
00170 char *gnc_ui_account_get_tax_info_string (const Account *account);
00171 
00172 gnc_numeric gnc_ui_account_get_balance_as_of_date (Account *account,
00173                                                    time_t date,
00174                                                    gboolean include_children);
00175 
00176 const char * gnc_get_reconcile_str (char reconciled_flag);
00177 const char * gnc_get_reconcile_valid_flags (void);
00178 const char * gnc_get_reconcile_flag_order (void);
00179 
00180 typedef enum
00181 {
00182   EQUITY_OPENING_BALANCE,
00183   EQUITY_RETAINED_EARNINGS,
00184   NUM_EQUITY_TYPES
00185 } GNCEquityType;
00186 
00187 Account * gnc_find_or_create_equity_account (Account *root,
00188                                              GNCEquityType equity_type,
00189                                              gnc_commodity *currency);
00190 gboolean gnc_account_create_opening_balance (Account *account,
00191                                              gnc_numeric balance,
00192                                              time_t date,
00193                                              QofBook *book);
00194 
00195 char * gnc_account_get_full_name (const Account *account);
00196 
00197 
00198 /* Locale functions *************************************************/
00199 
00200 /* The gnc_localeconv() subroutine returns an lconv structure
00201  * containing locale information. If no locale is set, the structure
00202  * is given default (en_US) values.  */
00203 struct lconv * gnc_localeconv (void);
00204 
00205 /* Returns the default currency of the current locale, or NULL if no
00206  * sensible currency could be identified from the locale. */
00207 gnc_commodity * gnc_locale_default_currency_nodefault (void);
00208 
00209 /* Returns the default currency of the current locale. WATCH OUT: If
00210  * no currency could be identified from the locale, this one returns
00211  * "USD", but this will have nothing to do with the actual locale. */
00212 gnc_commodity * gnc_locale_default_currency (void);
00213 
00214 /* Returns the default ISO currency string of the current locale. */
00215 const char * gnc_locale_default_iso_currency_code (void);
00216 
00217 
00224 gnc_commodity * gnc_default_currency (void);
00225 
00226 
00233 gnc_commodity * gnc_default_report_currency (void);
00234 
00235 
00236 /* Returns the number of decimal place to print in the current locale */
00237 int gnc_locale_decimal_places (void);
00238 
00239 /* Push and pop locales. Currently, this has no effect on gnc_localeconv.
00240  * i.e., after the first call to gnc_localeconv, subsequent calls will
00241  * return the same information. */
00242 void gnc_push_locale (const char *locale);
00243 void gnc_pop_locale (void);
00244 
00245 /* Amount printing and parsing **************************************/
00246 
00247 /*
00248  * The xaccPrintAmount() and xaccSPrintAmount() routines provide
00249  *    i18n'ed convenience routines for printing gnc_numerics.
00250  *    amounts. Both routines take a gnc_numeric argument and
00251  *    a printing information object.
00252  *
00253  * The xaccPrintAmount() routine returns a pointer to a statically
00254  *    allocated buffer, and is therefore not thread-safe.
00255  *
00256  * The xaccSPrintAmount() routine accepts a pointer to the buffer to be
00257  *    printed to.  It returns the length of the printed string.
00258  */
00259 
00260 typedef struct _GNCPrintAmountInfo
00261 {
00262   const gnc_commodity *commodity;  /* may be NULL */
00263 
00264   guint8 max_decimal_places;
00265   guint8 min_decimal_places;
00266 
00267   unsigned int use_separators : 1; /* Print thousands separators */
00268   unsigned int use_symbol : 1;     /* Print currency symbol */
00269   unsigned int use_locale : 1;     /* Use locale for some positioning */
00270   unsigned int monetary : 1;       /* Is a monetary quantity */
00271   unsigned int force_fit : 1;      /* Don't print more than max_dp places */
00272   unsigned int round : 1;          /* Round at max_dp instead of truncating */
00273 } GNCPrintAmountInfo;
00274 
00275 
00276 GNCPrintAmountInfo gnc_default_print_info (gboolean use_symbol);
00277 
00278 GNCPrintAmountInfo gnc_commodity_print_info (const gnc_commodity *commodity,
00279                                              gboolean use_symbol);
00280 
00281 GNCPrintAmountInfo gnc_account_print_info (const Account *account,
00282                                            gboolean use_symbol);
00283 
00284 GNCPrintAmountInfo gnc_split_amount_print_info (Split *split,
00285                                                 gboolean use_symbol);
00286 GNCPrintAmountInfo gnc_split_value_print_info (Split *split,
00287                                                gboolean use_symbol);
00288 
00289 GNCPrintAmountInfo gnc_share_print_info_places (int decplaces);
00290 GNCPrintAmountInfo gnc_default_share_print_info (void);
00291 GNCPrintAmountInfo gnc_default_price_print_info (void);
00292 
00293 GNCPrintAmountInfo gnc_integral_print_info (void);
00294 
00295 /* WARNING: Garbage in, garbage out.  You must check the validity of
00296    the supplied gnc_numeric.  If it's invalid, the returned string
00297    could point to ANYTHING. */
00298 const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
00299 int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
00300 
00301 const gchar *printable_value(gdouble val, gint denom);
00302 gchar *number_to_words(gdouble val, gint64 denom);
00303 gchar *numeric_to_words(gnc_numeric val);
00304 
00305 /* xaccParseAmount parses in_str to obtain a numeric result. The
00306  *   routine will parse as much of in_str as it can to obtain a single
00307  *   number. The number is parsed using the current locale information
00308  *   and the 'monetary' flag. The routine will return TRUE if it
00309  *   successfully parsed a number and FALSE otherwise. If TRUE is
00310  *   returned and result is non-NULL, the value of the parsed number
00311  *   is stored in *result. If FALSE is returned, *result is
00312  *   unchanged. If TRUE is returned and endstr is non-NULL, the
00313  *   location of the first character in in_str not used by the parser
00314  *   will be returned in *endstr. If FALSE is returned and endstr is
00315  *   non-NULL, *endstr will point to in_str. */
00316 gboolean xaccParseAmount (const char * in_str, gboolean monetary,
00317                           gnc_numeric *result, char **endstr);
00318 
00319 /*
00320  * xaccParseAmountExtended is just like xaccParseAmount except the
00321  * caller must provide all the locale-specific information.
00322  *
00323  * Note: if group is NULL, no group-size verification will take place.
00324  * ignore_list is a list of characters that are completely ignored
00325  * while processing the input string.  If ignore_list is NULL, nothing
00326  * is ignored.
00327  */
00328 gboolean
00329 xaccParseAmountExtended (const char * in_str, gboolean monetary,
00330                          gunichar negative_sign, gunichar decimal_point,
00331                          gunichar group_separator, char *group, char *ignore_list,
00332                          gnc_numeric *result, char **endstr);
00333 
00334 /* Initialization ***************************************************/
00335 
00336 void gnc_ui_util_init (void);
00337 
00338 /* Missing functions ************************************************/
00339 
00340 #ifndef HAVE_TOWUPPER
00341 gint32 towupper (gint32 wc);
00342 int iswlower (gint32 wc);
00343 #endif
00344 
00345 #endif
00346 

Generated on Mon Sep 8 05:04:10 2008 for GnuCash by  doxygen 1.5.2