GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-ui-util.h
Go to the documentation of this file.
1 /********************************************************************\
2  * gnc-ui-util.h -- utility functions for the GnuCash UI *
3  * Copyright (C) 2000 Dave Peticolas <[email protected]> *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA [email protected] *
21 \********************************************************************/
22 
32 #ifndef GNC_UI_UTIL_H
33 #define GNC_UI_UTIL_H
34 
35 #include <glib.h>
36 #include <locale.h>
37 
38 #include "Account.h"
39 #include "gncOwner.h"
40 #include "qof.h"
41 
42 
43 typedef QofSession * (*QofSessionCB) (void);
44 
45 
46 gchar *gnc_normalize_account_separator (const gchar* separator);
47 gboolean gnc_reverse_balance(const Account *account);
48 
49 /* Default directory sections ***************************************/
50 #define GNC_PREFS_GROUP_OPEN_SAVE "dialogs.open-save"
51 #define GNC_PREFS_GROUP_EXPORT "dialogs.export-accounts"
52 #define GNC_PREFS_GROUP_REPORT "dialogs.report"
53 #define GNC_PREF_AUTO_DECIMAL_POINT "auto-decimal-point"
54 #define GNC_PREF_AUTO_DECIMAL_PLACES "auto-decimal-places"
55 
56 /* Default directories **********************************************/
57 
58 gchar *gnc_get_default_directory (const gchar *section);
59 void gnc_set_default_directory (const gchar *section,
60  const gchar *directory);
61 
62 /* Engine enhancements & i18n ***************************************/
63 QofBook * gnc_get_current_book (void);
64 
65 /* If there is no current session, there is no book and we must be dealing
66  * with a new book. When gnucash is started with --nofile, there is
67  * initially no session (and no book), but by the time we check, one
68  * could have been created (for example, if an empty account tree tab is
69  * opened, a session is created which creates a new, but empty, book).
70  * A session is created and a book is loaded from a backend when gnucash is
71  * started with a file, but selecting 'new file' keeps a session open. So we
72  * need to check as well for a book with no accounts (root with no children). */
73 gboolean gnc_is_new_book (void);
74 
75 void gnc_set_current_book_tax_name (const gchar *tax_name);
76 const gchar * gnc_get_current_book_tax_name (void);
77 void gnc_set_current_book_tax_type (const gchar *tax_type);
78 const gchar * gnc_get_current_book_tax_type (void);
82 void gnc_book_option_num_field_source_change_cb (gboolean num_action);
83 Account * gnc_get_current_root_account (void);
84 gnc_commodity_table * gnc_get_current_commodities (void);
85 
93 gchar *gnc_get_account_name_for_register(const Account *account);
94 
106 Account *gnc_account_lookup_for_register(const Account *base_account, const
107  gchar *name);
108 
109 /*
110  * This is a wrapper routine around an xaccGetBalanceInCurrency
111  * function that handles additional needs of the gui.
112  *
113  * @param fn The underlying function in Account.c to call to retrieve
114  * a specific balance from the account.
115  * @param account The account to retrieve data about.
116  * @param recurse Include all sub-accounts of this account.
117  * @param negative An indication of whether or not the returned value
118  * is negative. This can be used by the caller to
119  * easily decode whether or not to color the output.
120  * @param commodity The commodity in which the account balance should
121  * be returned. If NULL, the value will be returned in
122  * the commodity of the account. This is normally used
123  * to specify a currency, which forces the conversion
124  * of things like stock account values from share
125  * values to an amount the requested currency.
126  */
127 char *gnc_ui_account_get_tax_info_string (const Account *account);
128 
129 char *gnc_ui_account_get_tax_info_sub_acct_string (const Account *account);
130 
131 const char * gnc_get_reconcile_str (char reconciled_flag);
132 const char * gnc_get_reconcile_valid_flags (void);
133 const char * gnc_get_reconcile_flag_order (void);
134 
135 typedef enum
136 {
137  EQUITY_OPENING_BALANCE,
138  EQUITY_RETAINED_EARNINGS,
139  NUM_EQUITY_TYPES
140 } GNCEquityType;
141 
142 Account * gnc_find_or_create_equity_account (Account *root,
143  GNCEquityType equity_type,
144  gnc_commodity *currency);
145 gboolean gnc_account_create_opening_balance (Account *account,
146  gnc_numeric balance,
147  time64 date,
148  QofBook *book);
149 
150 /* Locale functions *************************************************/
151 
152 
153 /* Returns the default currency of the current locale, or NULL if no
154  * sensible currency could be identified from the locale. */
155 gnc_commodity * gnc_locale_default_currency_nodefault (void);
156 
157 /* Returns the default currency of the current locale. WATCH OUT: If
158  * no currency could be identified from the locale, this one returns
159  * "USD", but this will have nothing to do with the actual locale. */
160 gnc_commodity * gnc_locale_default_currency (void);
161 
162 /* Returns the default ISO currency string of the current locale. */
163 const char * gnc_locale_default_iso_currency_code (void);
164 
165 
173 
197 gnc_commodity * gnc_account_or_default_currency(const Account* account, gboolean * currency_from_account_found);
198 
206 
207 /* Amount printing and parsing **************************************/
208 
209 /*
210  * The xaccPrintAmount() and xaccSPrintAmount() routines provide
211  * i18n'ed convenience routines for printing gnc_numerics.
212  * amounts. Both routines take a gnc_numeric argument and
213  * a printing information object.
214  *
215  * The xaccPrintAmount() routine returns a pointer to a statically
216  * allocated buffer, and is therefore not thread-safe.
217  *
218  * The xaccSPrintAmount() routine accepts a pointer to the buffer to be
219  * printed to. It returns the length of the printed string.
220  */
221 
222 typedef struct _GNCPrintAmountInfo
223 {
224  const gnc_commodity *commodity; /* may be NULL */
225 
226  guint8 max_decimal_places;
227  guint8 min_decimal_places;
228 
229  unsigned int use_separators : 1; /* Print thousands separators */
230  unsigned int use_symbol : 1; /* Print currency symbol */
231  unsigned int use_locale : 1; /* Use locale for some positioning */
232  unsigned int monetary : 1; /* Is a monetary quantity */
233  unsigned int force_fit : 1; /* Don't print more than max_dp places */
234  unsigned int round : 1; /* Round at max_dp instead of truncating */
236 
237 
238 GNCPrintAmountInfo gnc_default_print_info (gboolean use_symbol);
239 
240 GNCPrintAmountInfo gnc_commodity_print_info (const gnc_commodity *commodity,
241  gboolean use_symbol);
242 
243 GNCPrintAmountInfo gnc_account_print_info (const Account *account,
244  gboolean use_symbol);
245 
246 GNCPrintAmountInfo gnc_split_amount_print_info (Split *split,
247  gboolean use_symbol);
248 
249 GNCPrintAmountInfo gnc_share_print_info_places (int decplaces);
250 GNCPrintAmountInfo gnc_default_share_print_info (void);
251 GNCPrintAmountInfo gnc_default_price_print_info (void);
252 
253 GNCPrintAmountInfo gnc_integral_print_info (void);
254 
255 /* WARNING: Garbage in, garbage out. You must check the validity of
256  the supplied gnc_numeric. If it's invalid, the returned string
257  could point to ANYTHING. */
258 const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info);
259 int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info);
260 
261 const gchar *printable_value(gdouble val, gint denom);
262 gchar *number_to_words(gdouble val, gint64 denom);
263 gchar *numeric_to_words(gnc_numeric val);
264 
265 /* xaccParseAmount parses in_str to obtain a numeric result. The
266  * routine will parse as much of in_str as it can to obtain a single
267  * number. The number is parsed using the current locale information
268  * and the 'monetary' flag. The routine will return TRUE if it
269  * successfully parsed a number and FALSE otherwise. If TRUE is
270  * returned and result is non-NULL, the value of the parsed number
271  * is stored in *result. If FALSE is returned, *result is
272  * unchanged. If TRUE is returned and endstr is non-NULL, the
273  * location of the first character in in_str not used by the parser
274  * will be returned in *endstr. If FALSE is returned and endstr is
275  * non-NULL, *endstr will point to in_str. */
276 gboolean xaccParseAmount (const char * in_str, gboolean monetary,
277  gnc_numeric *result, char **endstr);
278 
279 /*
280  * xaccParseAmountExtended is just like xaccParseAmount except the
281  * caller must provide all the locale-specific information.
282  *
283  * Note: if group is NULL, no group-size verification will take place.
284  * ignore_list is a list of characters that are completely ignored
285  * while processing the input string. If ignore_list is NULL, nothing
286  * is ignored.
287  */
288 gboolean
289 xaccParseAmountExtended (const char * in_str, gboolean monetary,
290  gunichar negative_sign, gunichar decimal_point,
291  gunichar group_separator, char *group, char *ignore_list,
292  gnc_numeric *result, char **endstr);
293 
294 /* Initialization ***************************************************/
295 
296 void gnc_ui_util_init (void);
297 
298 #endif
299 
Business Interface: Object OWNERs.
void gnc_book_option_num_field_source_change_cb(gboolean num_action)
Definition: gnc-ui-util.c:253
gnc_commodity * gnc_default_report_currency(void)
Definition: gnc-ui-util.c:972
gnc_commodity * gnc_default_currency(void)
Definition: gnc-ui-util.c:939
gchar * gnc_get_account_name_for_register(const Account *account)
Definition: gnc-ui-util.c:282
Account handling public routines.
int xaccSPrintAmount(char *buf, gnc_numeric val, GNCPrintAmountInfo info)
Definition: gnc-ui-util.c:1437
gnc_commodity * gnc_account_or_default_currency(const Account *account, gboolean *currency_from_account_found)
Definition: gnc-ui-util.c:944
Definition: SplitP.h:71
gint64 time64
Definition: gnc-date.h:83
Account * gnc_account_lookup_for_register(const Account *base_account, const gchar *name)