GnuCash fec5643+
Loading...
Searching...
No Matches
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"
 
#define WLINK   'w'
 
#define FLINK   'f'
 

Typedefs

typedef QofSession *(* QofSessionCB) (void)
 

Enumerations

enum  GNCEquityType { EQUITY_OPENING_BALANCE , EQUITY_RETAINED_EARNINGS , NUM_EQUITY_TYPES }
 

Functions

char * gnc_normalize_account_separator (const char *separator)
 
gboolean gnc_reverse_balance (const Account *account)
 
void gnc_set_use_equity_type_opening_balance_account (QofBook *book)
 
gboolean gnc_using_equity_type_opening_balance_account (QofBook *book)
 
char * gnc_get_default_directory (const char *section)
 
void gnc_set_default_directory (const char *section, const char *directory)
 
QofBook * gnc_get_current_book (void)
 
gboolean gnc_is_new_book (void)
 
void gnc_set_current_book_tax_name_type (gboolean name_changed, const char *tax_name, gboolean type_changed, const char *tax_type)
 
const char * gnc_get_current_book_tax_name (void)
 
const char * gnc_get_current_book_tax_type (void)
 
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.
 
Account * gnc_get_current_root_account (void)
 
gnc_commodity_table * gnc_get_current_commodities (void)
 
char * 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.
 
Account * gnc_account_lookup_for_register (const Account *base_account, const char *name)
 Retrieve the account matching the given name starting from the descendants of base_account.
 
char * gnc_get_account_name_for_split_register (const Account *account, gboolean show_leaf_accounts)
 Get either the full name of the account or the simple name, depending on the show_leaf_accounts.
 
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)
 
const char * gnc_get_doclink_valid_flags (void)
 Get a string containing documentation link valid flags.
 
const char * gnc_get_doclink_flag_order (void)
 Get a string containing document link flag order.
 
const char * gnc_get_doclink_str (char link_flag)
 Get a string representing the document link type.
 
Account * gnc_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_commodity * gnc_locale_default_currency_nodefault (void)
 Returns the default currency of the current locale, or NULL if no sensible currency could be identified from the locale.
 
gnc_commodity * gnc_locale_default_currency (void)
 Returns the default currency of the current locale.
 
gnc_commodity * gnc_default_currency (void)
 Return the default currency set by the user.
 
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.
 
gnc_commodity * gnc_default_report_currency (void)
 Return the default currency for use in reports, as set by the user.
 
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_price_print_info (const gnc_commodity *curr, gboolean use_symbol)
 
GNCPrintAmountInfo gnc_share_print_info_places (int decplaces)
 
GNCPrintAmountInfo gnc_default_share_print_info (void)
 
GNCPrintAmountInfo gnc_default_price_print_info (const gnc_commodity *curr)
 
GNCPrintAmountInfo gnc_integral_print_info (void)
 
const char * xaccPrintAmount (gnc_numeric val, GNCPrintAmountInfo info)
 Make a string representation of a gnc_numeric.
 
int xaccSPrintAmount (char *buf, gnc_numeric val, GNCPrintAmountInfo info)
 Make a string representation of a gnc_numeric.
 
const char * printable_value (gdouble val, gint denom)
 
char * numeric_to_words (gnc_numeric val)
 
gboolean xaccParseAmount (const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr)
 Parses in_str to obtain a numeric result.
 
gboolean xaccParseAmountExtended (const char *in_str, gboolean monetary, gunichar negative_sign, gunichar decimal_point, gunichar group_separator, const char *ignore_list, gnc_numeric *result, char **endstr)
 Converts a string to a gnc_numeric.
 
gboolean xaccParseAmountImport (const char *in_str, gboolean monetary, gnc_numeric *result, char **endstr, gboolean skip)
 Similar to xaccParseAmount, but with two differences.
 
gboolean xaccParseAmountExtImport (const char *in_str, gboolean monetary, gunichar negative_sign, gunichar decimal_point, gunichar group_separator, const char *ignore_list, gnc_numeric *result, char **endstr)
 Similar to xaccParseAmountExtended, but will not automatically set a decimal point, regardless of what the user has set for this option.
 
const char * gnc_print_amount_with_bidi_ltr_isolate (gnc_numeric val, GNCPrintAmountInfo info)
 Make a string representation of a gnc_numeric.
 
char * gnc_wrap_text_with_bidi_ltr_isolate (const char *text)
 This function helps with GTK's use of 'Unicode Bidirectional Text Algorithm'.
 
void gnc_ui_util_init (void)
 
void gnc_ui_util_remove_registered_prefs (void)
 
char * gnc_filter_text_for_bidi_marks (const char *incoming_text)
 Returns the incoming text with Unicode bidi control characters removed.
 
char * gnc_filter_text_for_control_chars (const char *incoming_text)
 Returns the incoming text removed of control characters.
 
void gnc_filter_text_set_cursor_position (const char *incoming_text, const char *symbol, int *zcursor_position)
 Updates cursor_position after removal of currency symbols.
 
char * gnc_filter_text_for_currency_symbol (const char *incoming_text, const char *symbol)
 Returns the incoming text removed of a currency symbol.
 
char * gnc_filter_text_for_currency_commodity (const gnc_commodity *comm, const char *incoming_text, const char **symbol)
 Returns the incoming text removed of currency symbol.
 
gchar * gnc_list_formatter (GList *strings)
 This function takes a GList of char*, and uses locale-sensitive list formatter.
 

Detailed Description

Macro Definition Documentation

◆ FLINK

#define FLINK   'f'

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

◆ GNC_PREF_AUTO_DECIMAL_PLACES

#define GNC_PREF_AUTO_DECIMAL_PLACES   "auto-decimal-places"

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

◆ GNC_PREF_AUTO_DECIMAL_POINT

#define GNC_PREF_AUTO_DECIMAL_POINT   "auto-decimal-point"

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

◆ GNC_PREFS_GROUP_EXPORT

#define GNC_PREFS_GROUP_EXPORT   "dialogs.export-accounts"

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

◆ GNC_PREFS_GROUP_OPEN_SAVE

#define GNC_PREFS_GROUP_OPEN_SAVE   "dialogs.open-save"

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

◆ GNC_PREFS_GROUP_REPORT

#define GNC_PREFS_GROUP_REPORT   "dialogs.report"

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

◆ WLINK

#define WLINK   'w'

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

Typedef Documentation

◆ QofSessionCB

typedef QofSession *(* QofSessionCB) (void)

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

Enumeration Type Documentation

◆ GNCEquityType

enum GNCEquityType

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

178{
179 EQUITY_OPENING_BALANCE,
180 EQUITY_RETAINED_EARNINGS,
181 NUM_EQUITY_TYPES
182} GNCEquityType;

Function Documentation

◆ gnc_account_create_opening_balance()

gboolean gnc_account_create_opening_balance ( Account *  account,
gnc_numeric  balance,
time64  date,
QofBook *  book 
)

Definition at line 668 of file gnc-ui-util.cpp.

672{
673 if (gnc_numeric_zero_p (balance))
674 return TRUE;
675
676 g_return_val_if_fail (account != nullptr, FALSE);
677 auto commodity = xaccAccountGetCommodity (account);
678 g_return_val_if_fail (gnc_commodity_is_currency (commodity), FALSE);
679
680 auto equity_account =
681 gnc_find_or_create_equity_account (gnc_account_get_root(account),
682 EQUITY_OPENING_BALANCE,
683 commodity);
684 if (!equity_account)
685 return FALSE;
686
687 xaccAccountBeginEdit (account);
688 xaccAccountBeginEdit (equity_account);
689
690 auto trans = xaccMallocTransaction (book);
691
692 xaccTransBeginEdit (trans);
693
694 xaccTransSetCurrency (trans, gnc_account_or_default_currency (account, nullptr));
696 xaccTransSetDescription (trans, _("Opening Balance"));
697
698 auto split = xaccMallocSplit (book);
699
700 xaccTransAppendSplit (trans, split);
701 xaccAccountInsertSplit (account, split);
702
703 xaccSplitSetAmount (split, balance);
704 xaccSplitSetValue (split, balance);
705
706 balance = gnc_numeric_neg (balance);
707
708 split = xaccMallocSplit (book);
709
710 xaccTransAppendSplit (trans, split);
711 xaccAccountInsertSplit (equity_account, split);
712
713 xaccSplitSetAmount (split, balance);
714 xaccSplitSetValue (split, balance);
715
716 xaccTransCommitEdit (trans);
717 xaccAccountCommitEdit (equity_account);
718 xaccAccountCommitEdit (account);
719
720 return TRUE;
721}
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition Account.cpp:1504
Account * gnc_account_get_root(Account *acc)
This routine returns the root account of the account tree that the specified account belongs to.
Definition Account.cpp:2930
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition Account.cpp:1463
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity
Definition Account.cpp:3396
gboolean gnc_commodity_is_currency(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency or a legacy currency.
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
#define xaccTransAppendSplit(t, s)
Add a split to the transaction.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
Transaction * xaccMallocTransaction(QofBook *book)
The xaccMallocTransaction() will malloc memory and initialize it.
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
This function sets the posted date of the transaction, specified by a time64 (see ctime(3)).
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
#define xaccAccountInsertSplit(acc, s)
The xaccAccountInsertSplit() method will insert the indicated split into the indicated account.
Definition Account.h:1069
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
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.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value.
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
Split * xaccMallocSplit(QofBook *book)
Constructor.
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...

◆ gnc_account_lookup_for_register()

Account * gnc_account_lookup_for_register ( const Account *  base_account,
const char *  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.

Definition at line 450 of file gnc-ui-util.cpp.

451{
452 auto show_leaf_accounts =
453 gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER,
454 GNC_PREF_SHOW_LEAF_ACCT_NAMES);
455
456 if (show_leaf_accounts)
457 return gnc_account_lookup_by_name (base_account, name);
458 else
459 return gnc_account_lookup_by_full_name (base_account, name);
460}
Account * gnc_account_lookup_by_name(const Account *parent, const char *name)
The gnc_account_lookup_by_name() subroutine fetches the account by name from the descendants of the s...
Definition Account.cpp:3081
Account * gnc_account_lookup_by_full_name(const Account *any_acc, const gchar *name)
The gnc_account_lookup_full_name() subroutine works like gnc_account_lookup_by_name,...
Definition Account.cpp:3151
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.

◆ gnc_account_or_default_currency()

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 790 of file gnc-ui-util.cpp.

792{
793 gnc_commodity *currency;
794 if (!account)
795 {
796 if (currency_from_account_found)
797 *currency_from_account_found = FALSE;
798 return gnc_default_currency();
799 }
800
801 currency = gnc_account_get_currency_or_parent(account);
802 if (currency)
803 {
804 if (currency_from_account_found)
805 *currency_from_account_found = TRUE;
806 }
807 else
808 {
809 if (currency_from_account_found)
810 *currency_from_account_found = FALSE;
811 currency = gnc_default_currency();
812 }
813 return currency;
814}
gnc_commodity * gnc_account_get_currency_or_parent(const Account *account)
Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
Definition Account.cpp:3403
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.

◆ gnc_account_print_info()

GNCPrintAmountInfo gnc_account_print_info ( const Account *  account,
gboolean  use_symbol 
)

Definition at line 957 of file gnc-ui-util.cpp.

958{
959 return gnc_account_print_info_helper(account, use_symbol,
962}
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
Definition Account.cpp:2733

◆ gnc_book_option_num_field_source_change_cb()

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 4709 of file gnc-main-window.cpp.

4710{
4711 gnc_suspend_gui_refresh ();
4712 if (num_action)
4713 {
4714 /* Set a feature flag in the book for use of the split action field as number.
4715 * This will prevent older GnuCash versions that don't support this feature
4716 * from opening this file. */
4717 gnc_features_set_used (gnc_get_current_book(),
4718 GNC_FEATURE_NUM_FIELD_SOURCE);
4719 }
4720 gnc_book_option_num_field_source_change (num_action);
4721 gnc_resume_gui_refresh ();
4722}
void gnc_features_set_used(QofBook *book, const gchar *feature)
Indicate that the current book uses the given feature.

◆ gnc_commodity_print_info()

GNCPrintAmountInfo gnc_commodity_print_info ( const gnc_commodity *  commodity,
gboolean  use_symbol 
)

Definition at line 887 of file gnc-ui-util.cpp.

889{
891
892 if (commodity == nullptr)
893 return gnc_default_print_info (use_symbol);
894
895 info.commodity = commodity;
896
897 auto is_iso = gnc_commodity_is_iso (commodity);
898
899 if (is_decimal_fraction (gnc_commodity_get_fraction (commodity),
900 &info.max_decimal_places))
901 {
902 if (is_iso)
903 info.min_decimal_places = info.max_decimal_places;
904 else
905 info.min_decimal_places = 0;
906 }
907 else
908 info.max_decimal_places = info.min_decimal_places = 0;
909
910 info.use_separators = 1;
911 info.use_symbol = use_symbol ? 1 : 0;
912 info.use_locale = is_iso ? 1 : 0;
913 info.monetary = 1;
914 info.force_fit = 0;
915 info.round = 0;
916
917 return info;
918}
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.

◆ gnc_default_currency()

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 783 of file gnc-ui-util.cpp.

784{
785 return gnc_default_currency_common (user_default_currency,
786 GNC_PREFS_GROUP_GENERAL);
787}

◆ gnc_default_price_print_info()

GNCPrintAmountInfo gnc_default_price_print_info ( const gnc_commodity *  curr)

Definition at line 1061 of file gnc-ui-util.cpp.

1062{
1063 return gnc_price_print_info (curr, FALSE);
1064}

◆ gnc_default_print_info()

GNCPrintAmountInfo gnc_default_print_info ( gboolean  use_symbol)

Definition at line 835 of file gnc-ui-util.cpp.

836{
837 static GNCPrintAmountInfo info;
838 static bool got_it = false;
839
840 /* These must be updated each time. */
841 info.use_symbol = use_symbol ? 1 : 0;
842 info.commodity = gnc_default_currency ();
843
844 if (got_it)
845 return info;
846
847 auto lc = gnc_localeconv ();
848
849 info.max_decimal_places = lc->frac_digits;
850 info.min_decimal_places = lc->frac_digits;
851
852 info.use_separators = 1;
853 info.use_locale = 1;
854 info.monetary = 1;
855 info.force_fit = 0;
856 info.round = 0;
857
858 got_it = TRUE;
859
860 return info;
861}

◆ gnc_default_report_currency()

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 819 of file gnc-ui-util.cpp.

820{
821 return gnc_default_currency_common (user_report_currency,
822 GNC_PREFS_GROUP_GENERAL_REPORT);
823}

◆ gnc_default_share_print_info()

GNCPrintAmountInfo gnc_default_share_print_info ( void  )

Definition at line 998 of file gnc-ui-util.cpp.

999{
1000 static GNCPrintAmountInfo info;
1001 static bool got_it = false;
1002
1003 if (!got_it)
1004 {
1005 info = gnc_default_print_info_helper (5);
1006 info.monetary = 0;
1007 got_it = TRUE;
1008 }
1009
1010 return info;
1011}

◆ gnc_filter_text_for_bidi_marks()

char * gnc_filter_text_for_bidi_marks ( const char *  incoming_text)

Returns the incoming text with Unicode bidi control characters removed.

Strips directional marks (U+200E, U+200F), embedding/override codes (U+202A–U+202E), isolate codes (U+2066–U+2069) and the Arabic letter mark (U+061C) that GnuCash inserts for RTL display, so that values copied to the clipboard are clean plain text.

Parameters
incoming_textThe text to filter (may be NULL)
Returns
A newly-allocated string with bidi marks removed, or NULL when incoming_text is NULL. Must be freed by the caller.

Definition at line 2137 of file gnc-ui-util.cpp.

2138{
2139 if (!text)
2140 return nullptr;
2141
2142 int32_t len = static_cast<int32_t> (strlen (text));
2143 std::string result;
2144 result.reserve (len);
2145
2146 const char* p = text;
2147 int32_t i = 0;
2148
2149 while (i < len)
2150 {
2151 UChar32 c;
2152 int32_t start = i;
2153 U8_NEXT (p, i, len, c);
2154
2155 if (c >= 0 && !u_hasBinaryProperty (c, UCHAR_BIDI_CONTROL))
2156 result.append (p + start, i - start);
2157 }
2158
2159 return g_strdup (result.c_str ());
2160}

◆ gnc_filter_text_for_control_chars()

char * gnc_filter_text_for_control_chars ( const char *  incoming_text)

Returns the incoming text removed of control characters.

Parameters
incoming_textThe text to filter
Returns
The incoming text filtered of control characters to be freed by the caller.

Definition at line 2169 of file gnc-ui-util.cpp.

2170{
2171 bool cntrl = false;
2172 bool text_found = false;
2173
2174 if (!text)
2175 return nullptr;
2176
2177 if (!g_utf8_validate (text, -1, nullptr))
2178 return nullptr;
2179
2180 auto filtered = g_string_sized_new (strlen (text) + 1);
2181
2182 auto ch = text;
2183
2184 while (*ch)
2185 {
2186 auto uc = g_utf8_get_char (ch);
2187
2188 // check for starting with control characters
2189 if (unichar_is_cntrl (uc) && !text_found)
2190 {
2191 ch = g_utf8_next_char (ch);
2192 continue;
2193 }
2194 // check for alpha, num and punctuation
2195 if (!unichar_is_cntrl (uc))
2196 {
2197 filtered = g_string_append_unichar (filtered, uc);
2198 text_found = true;
2199 }
2200 // check for control characters after text
2201 if (unichar_is_cntrl (uc))
2202 cntrl = true;
2203
2204 ch = g_utf8_next_char (ch);
2205
2206 if (cntrl) // if control characters in text replace with space
2207 {
2208 auto uc2 = g_utf8_get_char (ch);
2209
2210 if (!unichar_is_cntrl (uc2))
2211 filtered = g_string_append_unichar (filtered, ' ');
2212 }
2213 cntrl = false;
2214 }
2215 return g_string_free (filtered, FALSE);
2216}

◆ gnc_filter_text_for_currency_commodity()

char * gnc_filter_text_for_currency_commodity ( const gnc_commodity *  comm,
const char *  incoming_text,
const char **  symbol 
)

Returns the incoming text removed of currency symbol.

Parameters
commcommodity of entry if known
incoming_textThe text to filter
symbolreturn the symbol used
Returns
The incoming text with symbol removed to be freed by the caller

Definition at line 2271 of file gnc-ui-util.cpp.

2274{
2275 if (!incoming_text)
2276 {
2277 *symbol = nullptr;
2278 return nullptr;
2279 }
2280
2281 if (!gnc_commodity_is_currency (comm))
2282 {
2283 *symbol = nullptr;
2284 return g_strdup (incoming_text);
2285 }
2286
2287 if (comm)
2288 *symbol = gnc_commodity_get_nice_symbol (comm);
2289 else
2291
2292 return gnc_filter_text_for_currency_symbol (incoming_text, *symbol);
2293}
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
Retrieve a symbol for the specified commodity, suitable for display to the user.
char * gnc_filter_text_for_currency_symbol(const char *incoming_text, const char *symbol)
Returns the incoming text removed of a currency symbol.

◆ gnc_filter_text_for_currency_symbol()

char * gnc_filter_text_for_currency_symbol ( const char *  incoming_text,
const char *  symbol 
)

Returns the incoming text removed of a currency symbol.

Parameters
incoming_textThe text to filter
symbolto remove
cursor_positionthe position of cursor in the incoming text
Returns
The incoming text with symbol removed to be freed by the caller

Definition at line 2250 of file gnc-ui-util.cpp.

2252{
2253 if (!incoming_text)
2254 return nullptr;
2255
2256 if (!symbol)
2257 return g_strdup (incoming_text);
2258
2259 if (g_strrstr (incoming_text, symbol) == nullptr)
2260 return g_strdup (incoming_text);
2261
2262 auto split = g_strsplit (incoming_text, symbol, -1);
2263
2264 auto ret_text = g_strjoinv (nullptr, split);
2265
2266 g_strfreev (split);
2267 return ret_text;
2268}

◆ gnc_filter_text_set_cursor_position()

void gnc_filter_text_set_cursor_position ( const char *  incoming_text,
const char *  symbol,
int *  zcursor_position 
)

Updates cursor_position after removal of currency symbols.

Parameters
incoming_textThe text to filter
symbolto remove
cursor_positionthe position of cursor in the incoming text
Returns
nothing

◆ gnc_find_or_create_equity_account()

Account * gnc_find_or_create_equity_account ( Account *  root,
GNCEquityType  equity_type,
gnc_commodity *  currency 
)

Definition at line 565 of file gnc-ui-util.cpp.

568{
569 g_return_val_if_fail (equity_type >= 0, nullptr);
570 g_return_val_if_fail (equity_type < NUM_EQUITY_TYPES, nullptr);
571 g_return_val_if_fail (currency != nullptr, nullptr);
572 g_return_val_if_fail (root != nullptr, nullptr);
573 g_return_val_if_fail (gnc_commodity_is_currency(currency), nullptr);
574
575 auto use_eq_op_feature = equity_type == EQUITY_OPENING_BALANCE && gnc_using_equity_type_opening_balance_account (gnc_get_current_book ());
576
577 if (use_eq_op_feature)
578 {
579 auto account = gnc_account_lookup_by_opening_balance (root, currency);
580 if (account)
581 return account;
582 }
583
584 auto base_name = equity_base_name (equity_type);
585
586 auto account = gnc_account_lookup_by_name(root, base_name);
587 if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
588 account = nullptr;
589
590 if (!account)
591 {
592 base_name = base_name && *base_name ? _(base_name) : "";
593
594 account = gnc_account_lookup_by_name(root, base_name);
595 if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
596 account = nullptr;
597 }
598
599 auto base_name_exists = (account != nullptr);
600
601 if (account &&
602 gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
603 {
604 if (use_eq_op_feature)
605 xaccAccountSetIsOpeningBalance (account, TRUE);
606 return account;
607 }
608
609 auto name = g_strconcat (base_name, " - ",
610 gnc_commodity_get_mnemonic (currency), nullptr);
611 account = gnc_account_lookup_by_name(root, name);
612 if (account && xaccAccountGetType (account) != ACCT_TYPE_EQUITY)
613 account = nullptr;
614
615 auto name_exists = (account != nullptr);
616
617 if (account &&
618 gnc_commodity_equiv (currency, xaccAccountGetCommodity (account)))
619 {
620 if (use_eq_op_feature)
621 xaccAccountSetIsOpeningBalance (account, TRUE);
622 return account;
623 }
624
625 /* Couldn't find one, so create it */
626 if (name_exists && base_name_exists)
627 {
628 PWARN ("equity account with unexpected currency");
629 g_free (name);
630 return nullptr;
631 }
632
633 if (!base_name_exists &&
635 {
636 g_free (name);
637 name = g_strdup (base_name);
638 }
639
640 auto parent = gnc_account_lookup_by_name(root, _("Equity"));
641 if (!parent || xaccAccountGetType (parent) != ACCT_TYPE_EQUITY)
642 parent = root;
643 g_assert(parent);
644
645 account = xaccMallocAccount (gnc_account_get_book(root));
646
647 xaccAccountBeginEdit (account);
648
649 xaccAccountSetName (account, name);
650 xaccAccountSetType (account, ACCT_TYPE_EQUITY);
651 xaccAccountSetCommodity (account, currency);
652
653 if (use_eq_op_feature)
654 xaccAccountSetIsOpeningBalance (account, TRUE);
655
656 xaccAccountBeginEdit (parent);
657 gnc_account_append_child (parent, account);
658 xaccAccountCommitEdit (parent);
659
660 xaccAccountCommitEdit (account);
661
662 g_free (name);
663
664 return account;
665}
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship,...
Definition Account.cpp:2824
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
Definition Account.cpp:3255
void xaccAccountSetName(Account *acc, const char *str)
Set the account's name.
Definition Account.cpp:2446
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Set the account's type.
Definition Account.cpp:2425
Account * xaccMallocAccount(QofBook *book)
Constructor.
Definition Account.cpp:1258
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Set the account's commodity.
Definition Account.cpp:2666
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
void xaccAccountSetIsOpeningBalance(Account *acc, gboolean val)
Set the "opening-balance" flag for an account.
Definition Account.cpp:4141
Account * gnc_account_lookup_by_opening_balance(Account *account, gnc_commodity *commodity)
Find the opening balance account for the currency.
Definition Account.cpp:3109
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250

◆ gnc_get_account_name_for_register()

char * 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 440 of file gnc-ui-util.cpp.

441{
442 auto show_leaf_accounts =
443 gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL_REGISTER,
444 GNC_PREF_SHOW_LEAF_ACCT_NAMES);
445
446 return gnc_get_account_name_for_split_register(account, show_leaf_accounts);
447}
char * gnc_get_account_name_for_split_register(const Account *account, gboolean show_leaf_accounts)
Get either the full name of the account or the simple name, depending on the show_leaf_accounts.

◆ gnc_get_account_name_for_split_register()

char * gnc_get_account_name_for_split_register ( const Account *  account,
gboolean  show_leaf_accounts 
)

Get either the full name of the account or the simple name, depending on the show_leaf_accounts.

Parameters
accountThe account to retrieve the name for.
show_leaf_accountsWhether the full name will be returned.
Returns
A newly allocated string.

Definition at line 430 of file gnc-ui-util.cpp.

432{
433 if (show_leaf_accounts)
434 return g_strdup (xaccAccountGetName (account));
435 else
436 return gnc_account_get_full_name (account);
437}
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Definition Account.cpp:3277
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
Definition Account.cpp:3293

◆ gnc_get_current_book()

QofBook * gnc_get_current_book ( void  )

Definition at line 209 of file gnc-ui-util.cpp.

210{
211 return qof_session_get_book (gnc_get_current_session ());
212}
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.

◆ gnc_get_current_book_tax_name()

const char * gnc_get_current_book_tax_name ( void  )

Definition at line 329 of file gnc-ui-util.cpp.

330{
331 auto book = gnc_get_current_book();
332 auto tax_name = qof_book_get_string_option(book, OPTION_TAXUS_NAME);
333 if (tax_name)
334 {
335 return tax_name;
336 }
337 else
338 {
339 const char* old_option_taxus_name =
340 qof_book_get_string_option(book, OLD_OPTION_TAXUS_NAME);
341 if (old_option_taxus_name)
342 {
343 char* taxus_name = g_strdup(old_option_taxus_name);
344 const char* old_option_taxus_type =
345 qof_book_get_string_option(book, OLD_OPTION_TAXUS_TYPE);
346 if (old_option_taxus_type)
347 { /* switch both name and type and remove unused frames */
348 char* taxus_type = g_strdup(old_option_taxus_type);
349 qof_book_set_string_option(book, OPTION_TAXUS_NAME, taxus_name);
350 qof_book_set_string_option(book, OLD_OPTION_TAXUS_NAME, nullptr);
351 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, taxus_type);
352 qof_book_set_string_option(book, OLD_OPTION_TAXUS_TYPE, nullptr);
353 qof_book_option_frame_delete(book, "book/tax_US");
354 qof_book_option_frame_delete(book, "book");
355 g_free (taxus_type);
356 }
357 else
358 { /* switch just name and remove unused frames */
359 qof_book_set_string_option(book, OPTION_TAXUS_NAME, taxus_name);
360 qof_book_set_string_option(book, OLD_OPTION_TAXUS_NAME, nullptr);
361 qof_book_option_frame_delete(book, "book/tax_US");
362 qof_book_option_frame_delete(book, "book");
363 }
364 g_free (taxus_name);
365 return qof_book_get_string_option(book, OPTION_TAXUS_NAME);
366 }
367 return nullptr;
368 }
369}

◆ gnc_get_current_book_tax_type()

const char * gnc_get_current_book_tax_type ( void  )

Definition at line 372 of file gnc-ui-util.cpp.

373{
374 auto book = gnc_get_current_book();
375 auto tax_type =
376 qof_book_get_string_option(book, OPTION_TAXUS_TYPE);
377 if (tax_type)
378 {
379 return tax_type;
380 }
381 else
382 {
383 auto old_option_taxus_type =
384 qof_book_get_string_option(book, OLD_OPTION_TAXUS_TYPE);
385 if (old_option_taxus_type)
386 {
387 auto taxus_type = g_strdup(old_option_taxus_type);
388 auto old_option_taxus_name =
389 qof_book_get_string_option(book, OLD_OPTION_TAXUS_NAME);
390 if (old_option_taxus_name)
391 { /* switch both name and type and remove unused frames */
392 auto taxus_name = g_strdup(old_option_taxus_name);
393 qof_book_set_string_option(book, OPTION_TAXUS_NAME, taxus_name);
394 qof_book_set_string_option(book, OLD_OPTION_TAXUS_NAME, nullptr);
395 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, taxus_type);
396 qof_book_set_string_option(book, OLD_OPTION_TAXUS_TYPE, nullptr);
397 qof_book_option_frame_delete(book, "book/tax_US");
398 qof_book_option_frame_delete(book, "book");
399 g_free (taxus_name);
400 }
401 else
402 { /* switch just type and remove unused frames */
403 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, taxus_type);
404 qof_book_set_string_option(book, OLD_OPTION_TAXUS_TYPE, nullptr);
405 qof_book_option_frame_delete(book, "book/tax_US");
406 qof_book_option_frame_delete(book, "book");
407 }
408 g_free (taxus_type);
409 return qof_book_get_string_option(book, OPTION_TAXUS_TYPE);
410 }
411 return nullptr;
412 }
413}

◆ gnc_get_current_commodities()

gnc_commodity_table * gnc_get_current_commodities ( void  )

Definition at line 422 of file gnc-ui-util.cpp.

423{
424 if (gnc_current_session_exist())
425 return gnc_commodity_table_get_table (gnc_get_current_book ());
426 return nullptr;
427}
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.

◆ gnc_get_current_root_account()

Account * gnc_get_current_root_account ( void  )

Definition at line 416 of file gnc-ui-util.cpp.

417{
418 return gnc_book_get_root_account (gnc_get_current_book ());
419}

◆ gnc_get_default_directory()

char * gnc_get_default_directory ( const char *  section)

Definition at line 187 of file gnc-ui-util.cpp.

188{
189 auto dir = gnc_prefs_get_string (section, GNC_PREF_LAST_PATH);
190 if (!(dir && *dir))
191 {
192 g_free (dir); // if it's ""
193#ifdef G_OS_WIN32
194 dir = g_strdup (g_get_user_data_dir ()); /* equivalent of "My Documents" */
195#else
196 dir = g_strdup (g_get_home_dir ());
197#endif
198 }
199 return dir;
200}
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
Get a string value from the preferences backend.

◆ gnc_get_doclink_flag_order()

const char * gnc_get_doclink_flag_order ( void  )

Get a string containing document link flag order.

Returns
a string containing the document link flag change order

Definition at line 542 of file gnc-ui-util.cpp.

543{
544 static const char flags[] = { FLINK, WLINK, ' ', 0 };
545 return flags;
546}

◆ gnc_get_doclink_str()

const char * gnc_get_doclink_str ( char  link_flag)

Get a string representing the document link type.

Parameters
link_flagThe flag to convert into a string
Returns
the i18n'd doclink string

Definition at line 518 of file gnc-ui-util.cpp.

519{
520 switch (link_flag)
521 {
522 case WLINK:
523 return C_("Document Link flag for 'web'", "w");
524 case FLINK:
525 return C_("Document Link flag for 'file'", "f");
526 case ' ':
527 return " ";
528 default:
529 PERR("Bad link flag");
530 return nullptr;
531 }
532}
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244

◆ gnc_get_doclink_valid_flags()

const char * gnc_get_doclink_valid_flags ( void  )

Get a string containing documentation link valid flags.

Returns
a string containing the list of valid link_flags

Definition at line 535 of file gnc-ui-util.cpp.

536{
537 static const char flags[] = { FLINK, WLINK, ' ', 0 };
538 return flags;
539}

◆ gnc_get_reconcile_flag_order()

const char * gnc_get_reconcile_flag_order ( void  )

Definition at line 511 of file gnc-ui-util.cpp.

512{
513 static const char flags[] = { NREC, CREC, 0 };
514 return flags;
515}
#define NREC
not reconciled or cleared
Definition Split.h:76
#define CREC
The Split has been cleared
Definition Split.h:73

◆ gnc_get_reconcile_str()

const char * gnc_get_reconcile_str ( char  reconciled_flag)

Definition at line 470 of file gnc-ui-util.cpp.

471{
472 switch (reconciled_flag)
473 {
474 case NREC:
475 return C_("Reconciled flag 'not cleared'", "n");
476 case CREC:
477 return C_("Reconciled flag 'cleared'", "c");
478 case YREC:
479 return C_("Reconciled flag 'reconciled'", "y");
480 case FREC:
481 return C_("Reconciled flag 'frozen'", "f");
482 case VREC:
483 return C_("Reconciled flag 'void'", "v");
484 default:
485 PERR("Bad reconciled flag\n");
486 return nullptr;
487 }
488}
#define VREC
split is void
Definition Split.h:77
#define FREC
frozen into accounting period
Definition Split.h:75
#define YREC
The Split has been reconciled.
Definition Split.h:74

◆ gnc_get_reconcile_valid_flags()

const char * gnc_get_reconcile_valid_flags ( void  )

Definition at line 497 of file gnc-ui-util.cpp.

498{
499 static const char flags[] = { NREC, CREC, YREC, FREC, VREC, 0 };
500 return flags;
501}

◆ gnc_integral_print_info()

GNCPrintAmountInfo gnc_integral_print_info ( void  )

Definition at line 1068 of file gnc-ui-util.cpp.

1069{
1070 static GNCPrintAmountInfo info;
1071 static bool got_it = false;
1072
1073 if (!got_it)
1074 {
1075 info = gnc_default_print_info_helper (0);
1076 got_it = TRUE;
1077 }
1078
1079 return info;
1080}

◆ gnc_is_new_book()

gboolean gnc_is_new_book ( void  )

Definition at line 223 of file gnc-ui-util.cpp.

224{
225 return (!gnc_current_session_exist() ||
226 gnc_account_n_children (gnc_book_get_root_account (gnc_get_current_book ())) == 0);
227}
gint gnc_account_n_children(const Account *account)
Return the number of children of the specified account.
Definition Account.cpp:2964

◆ gnc_list_formatter()

gchar * gnc_list_formatter ( GList *  strings)

This function takes a GList of char*, and uses locale-sensitive list formatter.

Parameters
stringsThe GList* of char*.
Returns
a newly allocated char*

Definition at line 2296 of file gnc-ui-util.cpp.

2297{
2298 g_return_val_if_fail (strings, nullptr);
2299
2300 UErrorCode status = U_ZERO_ERROR;
2301 auto formatter = icu::ListFormatter::createInstance(status);
2302 std::vector<UniStr> strvec;
2303 UniStr result;
2304 std::string retval;
2305
2306 for (auto n = strings; n; n = g_list_next (n))
2307 {
2308 auto utf8_str{static_cast<const char*>(n->data)};
2309 strvec.push_back (UniStr::fromUTF8(utf8_str));
2310 }
2311
2312 formatter->format (strvec.data(), strvec.size(), result, status);
2313
2314 if (U_FAILURE(status))
2315 PERR ("Unicode error");
2316 else
2317 result.toUTF8String(retval);
2318
2319 delete formatter;
2320 return g_strdup (retval.c_str());
2321}

◆ gnc_locale_default_currency()

gnc_commodity * gnc_locale_default_currency ( void  )

Returns the default currency of the current locale.

WATCH OUT: If no currency could be identified from the locale, this one returns "USD", but this will have nothing to do with the actual locale.

Definition at line 738 of file gnc-ui-util.cpp.

739{
740 auto currency = gnc_locale_default_currency_nodefault ();
741
742 return (currency ? currency :
743 gnc_commodity_table_lookup (gnc_get_current_commodities (),
744 GNC_COMMODITY_NS_CURRENCY, "USD"));
745}
gnc_commodity * gnc_locale_default_currency_nodefault(void)
Returns the default currency of the current locale, or NULL if no sensible currency could be identifi...

◆ gnc_locale_default_currency_nodefault()

gnc_commodity * gnc_locale_default_currency_nodefault ( void  )

Returns the default currency of the current locale, or NULL if no sensible currency could be identified from the locale.

Definition at line 725 of file gnc-ui-util.cpp.

726{
727 auto table = gnc_get_current_commodities ();
728 auto code = gnc_locale_default_iso_currency_code ();
729
730 auto currency = gnc_commodity_table_lookup (table,
731 GNC_COMMODITY_NS_CURRENCY,
732 code);
733
734 return (currency ? currency : nullptr);
735}

◆ gnc_price_print_info()

GNCPrintAmountInfo gnc_price_print_info ( const gnc_commodity *  curr,
gboolean  use_symbol 
)

Definition at line 1027 of file gnc-ui-util.cpp.

1028{
1029 GNCPrintAmountInfo info;
1030 auto force = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL,
1031 GNC_PREF_PRICES_FORCE_DECIMAL);
1032 info.commodity = curr;
1033
1034 if (info.commodity)
1035 {
1036 int frac = gnc_commodity_get_fraction (curr);
1037 guint8 decplaces = 0;
1038 while (frac != 1 && (frac % 10) == 0 && (frac /= 10)) ++decplaces;
1039 if (force)
1040 decplaces += 2;
1041 info.max_decimal_places = decplaces;
1042 info.min_decimal_places = decplaces;
1043 }
1044 else
1045 {
1046 info.max_decimal_places = 6;
1047 info.min_decimal_places = 0;
1048 }
1049
1050 info.use_separators = 1;
1051 info.use_symbol = use_symbol ? 1 : 0;
1052 info.use_locale = 1;
1053 info.monetary = 1;
1054
1055 info.force_fit = force;
1056 info.round = force;
1057 return info;
1058}

◆ gnc_print_amount_with_bidi_ltr_isolate()

const char * gnc_print_amount_with_bidi_ltr_isolate ( gnc_numeric  val,
GNCPrintAmountInfo  info 
)

Make a string representation of a gnc_numeric.

Warning, the gnc_numeric is not checked for validity and the returned char* may point to random garbage.

This is the same as xaccPrintAmount but wraps the output with BiDi left to right isolate if a symbol is displayed.

Definition at line 1448 of file gnc-ui-util.cpp.

1449{
1450 /* hack alert -- this is not thread safe ... */
1451 static char buf[BUFLEN];
1452 static const char ltr_isolate[] = { '\xe2', '\x81', '\xa6' };
1453 static const char ltr_pop_isolate[] = { '\xe2', '\x81', '\xa9' };
1454 auto offset = info.use_symbol ? 3 : 0;
1455
1456 if (!gnc_commodity_is_currency (info.commodity))
1457 offset = 0;
1458
1459 memset (buf, 0, BUFLEN);
1460 if (!xaccSPrintAmount (buf + offset, val, info))
1461 {
1462 buf[0] = '\0';
1463 return buf;
1464 };
1465
1466 if (offset == 0)
1467 return buf;
1468
1469 memcpy (buf, ltr_isolate, 3);
1470
1471 if (buf[BUFLEN - 4] == '\0')
1472 {
1473 auto length = strlen (buf);
1474 memcpy (buf + length, ltr_pop_isolate, 3);
1475 }
1476 else
1477 {
1478 buf[BUFLEN - 1] = '\0';
1479 memcpy (buf + BUFLEN - 4, ltr_pop_isolate, 3);
1480
1481 PWARN("buffer length %d exceeded, string truncated was %s", BUFLEN, buf);
1482 }
1483 /* its OK to return buf, since we declared it static
1484 and is immediately g_strdup'd */
1485 return buf;
1486}
int xaccSPrintAmount(char *bufp, gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.

◆ gnc_reverse_balance()

gboolean gnc_reverse_balance ( const Account *  account)

Definition at line 161 of file gnc-ui-util.cpp.

162{
163 if (account == nullptr)
164 return FALSE;
165
166 auto type = xaccAccountGetType (account);
167 if ((type < 0) || (type >= NUM_ACCOUNT_TYPES))
168 return FALSE;
169
170 if (!reverse_balance_inited)
171 gnc_reverse_balance_init ();
172
173 return reverse_type[type];
174}
@ NUM_ACCOUNT_TYPES
stop here; the following types just aren't ready for prime time
Definition Account.h:161

◆ gnc_set_current_book_tax_name_type()

void gnc_set_current_book_tax_name_type ( gboolean  name_changed,
const char *  tax_name,
gboolean  type_changed,
const char *  tax_type 
)

Definition at line 235 of file gnc-ui-util.cpp.

237{
238 if (name_changed)
239 {
240 if (type_changed)
241 {
242 auto book = gnc_get_current_book();
243 if ((g_strcmp0 (tax_name, "") == 0) ||
244 (tax_name == nullptr))
245 { /* change to no name */
246 if ((g_strcmp0 (tax_type, "Other") == 0) ||
247 (g_strcmp0 (tax_type, "") == 0) ||
248 (tax_type == nullptr))
249 { /* need to delete both name and type and the "tax_US" frame */
250 qof_book_set_string_option(book, OPTION_TAXUS_NAME, nullptr);
251 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, nullptr);
252 qof_book_option_frame_delete(book, "tax_US");
253 }
254 else
255 { /* delete the name & change the type; keep the "tax_US" frame */
256 qof_book_set_string_option(book, OPTION_TAXUS_NAME, nullptr);
257 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, tax_type);
258 }
259 }
260 else /* new name */
261 {
262 if ((g_strcmp0 (tax_type, "Other") == 0) ||
263 (g_strcmp0 (tax_type, "") == 0) ||
264 (tax_type == nullptr))
265 { /* delete the type & change the name; keep the "tax_US" frame */
266 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, nullptr);
267 qof_book_set_string_option(book, OPTION_TAXUS_NAME, tax_name);
268 }
269 else /* and new type */
270 { /* change the name & change the type */
271 qof_book_set_string_option(book, OPTION_TAXUS_NAME, tax_name);
272 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, tax_type);
273 }
274 }
275 }
276 else /* no type change but name changed */
277 {
278 auto book = gnc_get_current_book();
279 if ((g_strcmp0 (tax_name, "") == 0) ||
280 (tax_name == nullptr))
281 { /* change to no name */
282 if ((g_strcmp0 (tax_type, "Other") == 0) ||
283 (g_strcmp0 (tax_type, "") == 0) ||
284 (tax_type == nullptr))
285 { /* delete the name; there is no type; deleted the "tax_US" frame */
286 qof_book_set_string_option(book, OPTION_TAXUS_NAME, nullptr);
287 qof_book_option_frame_delete(book, "tax_US");
288 }
289 else
290 { /* need to delete the name and keep "tax_US" frame */
291 qof_book_set_string_option(book, OPTION_TAXUS_NAME, nullptr);
292 }
293 }
294 else
295 { /* change the name & keep "tax_US" frame */
296 qof_book_set_string_option(book, OPTION_TAXUS_NAME, tax_name);
297 }
298 }
299 }
300 else /* no name change */
301 {
302 if (type_changed)
303 {
304 auto book = gnc_get_current_book();
305 if ((g_strcmp0 (tax_type, "Other") == 0) ||
306 (g_strcmp0 (tax_type, "") == 0) ||
307 (tax_type == nullptr))
308 {
309 if ((g_strcmp0 (tax_name, "") == 0) ||
310 (tax_name == nullptr))
311 {/* delete the type; there is no name; delete the "tax_US" frame */
312 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, nullptr);
313 qof_book_option_frame_delete(book, "tax_US");
314 }
315 else
316 { /* need to delete the type and keep "tax_US" frame */
317 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, nullptr);
318 }
319 }
320 else
321 { /* change the type & keep "tax_US" frame */
322 qof_book_set_string_option(book, OPTION_TAXUS_TYPE, tax_type);
323 }
324 } /*else no name and no type change - do nothing */
325 }
326}

◆ gnc_set_default_directory()

void gnc_set_default_directory ( const char *  section,
const char *  directory 
)

Definition at line 203 of file gnc-ui-util.cpp.

204{
205 gnc_prefs_set_string(section, GNC_PREF_LAST_PATH, directory);
206}
gboolean gnc_prefs_set_string(const gchar *group, const gchar *pref_name, const gchar *value)
Store a string into the preferences backend.

◆ gnc_set_use_equity_type_opening_balance_account()

void gnc_set_use_equity_type_opening_balance_account ( QofBook *  book)

Definition at line 181 of file gnc-ui-util.cpp.

182{
183 gnc_features_set_used (book, GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE);
184}

◆ gnc_share_print_info_places()

GNCPrintAmountInfo gnc_share_print_info_places ( int  decplaces)

Definition at line 1014 of file gnc-ui-util.cpp.

1015{
1016 GNCPrintAmountInfo info;
1017
1018 info = gnc_default_share_print_info ();
1019 info.max_decimal_places = decplaces;
1020 info.min_decimal_places = decplaces;
1021 info.force_fit = 1;
1022 info.round = 1;
1023 return info;
1024}

◆ gnc_split_amount_print_info()

GNCPrintAmountInfo gnc_split_amount_print_info ( Split *  split,
gboolean  use_symbol 
)

Definition at line 965 of file gnc-ui-util.cpp.

966{
967 if (!split)
968 {
969 GNCPrintAmountInfo info = gnc_default_share_print_info ();
970 info.use_symbol = use_symbol;
971 return info;
972 }
973
974 return gnc_account_print_info (xaccSplitGetAccount (split), use_symbol);
975}
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().

◆ gnc_ui_util_init()

void gnc_ui_util_init ( void  )

Definition at line 2062 of file gnc-ui-util.cpp.

2063{
2064 gnc_configure_account_separator ();
2065 gnc_auto_decimal_init();
2066
2067 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_ACCOUNT_SEPARATOR,
2068 (void*)gnc_configure_account_separator, nullptr);
2069 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_NONE,
2070 (void*)gnc_configure_reverse_balance, nullptr);
2071 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_CREDIT,
2072 (void*)gnc_configure_reverse_balance, nullptr);
2073 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_REVERSED_ACCTS_INC_EXP,
2074 (void*)gnc_configure_reverse_balance, nullptr);
2075 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_CURRENCY_CHOICE_LOCALE,
2076 (void*)gnc_currency_changed_cb, nullptr);
2077 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_CURRENCY_CHOICE_OTHER,
2078 (void*)gnc_currency_changed_cb, nullptr);
2079 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_CURRENCY_OTHER,
2080 (void*)gnc_currency_changed_cb, nullptr);
2081 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL_REPORT, GNC_PREF_CURRENCY_CHOICE_LOCALE,
2082 (void*)gnc_currency_changed_cb, nullptr);
2083 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL_REPORT, GNC_PREF_CURRENCY_CHOICE_OTHER,
2084 (void*)gnc_currency_changed_cb, nullptr);
2085 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL_REPORT, GNC_PREF_CURRENCY_OTHER,
2086 (void*)gnc_currency_changed_cb, nullptr);
2087 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTO_DECIMAL_POINT,
2088 (void*)gnc_set_auto_decimal_enabled, nullptr);
2089 gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_AUTO_DECIMAL_PLACES,
2090 (void*)gnc_set_auto_decimal_places, nullptr);
2091
2092}
gulong gnc_prefs_register_cb(const char *group, const gchar *pref_name, gpointer func, gpointer user_data)
Register a callback that gets triggered when the given preference changes.

◆ gnc_ui_util_remove_registered_prefs()

void gnc_ui_util_remove_registered_prefs ( void  )

Definition at line 2095 of file gnc-ui-util.cpp.

2096{
2097 // remove the registered pref call backs above
2098 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2099 GNC_PREF_ACCOUNT_SEPARATOR,
2100 (void*)gnc_configure_account_separator, nullptr);
2101 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2102 GNC_PREF_REVERSED_ACCTS_NONE,
2103 (void*)gnc_configure_reverse_balance, nullptr);
2104 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2105 GNC_PREF_REVERSED_ACCTS_CREDIT,
2106 (void*)gnc_configure_reverse_balance, nullptr);
2107 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2108 GNC_PREF_REVERSED_ACCTS_INC_EXP,
2109 (void*)gnc_configure_reverse_balance, nullptr);
2110 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2111 GNC_PREF_CURRENCY_CHOICE_LOCALE,
2112 (void*)gnc_currency_changed_cb, nullptr);
2113 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2114 GNC_PREF_CURRENCY_CHOICE_OTHER,
2115 (void*)gnc_currency_changed_cb, nullptr);
2116 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2117 GNC_PREF_CURRENCY_OTHER,
2118 (void*)gnc_currency_changed_cb, nullptr);
2119 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REPORT,
2120 GNC_PREF_CURRENCY_CHOICE_LOCALE,
2121 (void*)gnc_currency_changed_cb, nullptr);
2122 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REPORT,
2123 GNC_PREF_CURRENCY_CHOICE_OTHER,
2124 (void*)gnc_currency_changed_cb, nullptr);
2125 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL_REPORT,
2126 GNC_PREF_CURRENCY_OTHER,
2127 (void*)gnc_currency_changed_cb, nullptr);
2128 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2129 GNC_PREF_AUTO_DECIMAL_POINT,
2130 (void*)gnc_set_auto_decimal_enabled, nullptr);
2131 gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL,
2132 GNC_PREF_AUTO_DECIMAL_PLACES,
2133 (void*)gnc_set_auto_decimal_places, nullptr);
2134}
void gnc_prefs_remove_cb_by_func(const gchar *group, const gchar *pref_name, gpointer func, gpointer user_data)
Remove a function that was registered for a callback when the given preference changed.

◆ gnc_using_equity_type_opening_balance_account()

gboolean gnc_using_equity_type_opening_balance_account ( QofBook *  book)

Definition at line 176 of file gnc-ui-util.cpp.

177{
178 return gnc_features_check_used (book, GNC_FEATURE_EQUITY_TYPE_OPENING_BALANCE);
179}

◆ gnc_wrap_text_with_bidi_ltr_isolate()

char * gnc_wrap_text_with_bidi_ltr_isolate ( const char *  text)

This function helps with GTK's use of 'Unicode Bidirectional Text Algorithm'.

To keep the format of the text, this function wraps the text with a BiDi isolate charatcter and a BiDi closing character.

This helps with monetary values in RTL languages that display the currency symbol.

Definition at line 1489 of file gnc-ui-util.cpp.

1490{
1491 static const char* ltr = "\u2066"; // ltr isolate
1492 static const char* pop = "\u2069"; // pop directional formatting
1493
1494 if (!text)
1495 return nullptr;
1496
1497 return g_strconcat (ltr, text, pop, nullptr);
1498}

◆ numeric_to_words()

char * numeric_to_words ( gnc_numeric  val)

Definition at line 1563 of file gnc-ui-util.cpp.

1564{
1565 if (val.denom < 0) // reciprocal denominator means num * -denom
1566 val = gnc_numeric_convert (val, 1, GNC_HOW_RND_NEVER);
1567 if (gnc_numeric_check (val))
1568 return g_strdup ("");
1569
1570 std::string out;
1571 out.reserve (300);
1572 auto append_word = [&out](auto word){ if (!out.empty()) out += ' '; out += word; };
1573 auto append_below_1000 = [&](uint64_t n)
1574 {
1575 if (n >= 100)
1576 {
1577 append_word (small_numbers[n / 100]);
1578 append_word (big_numbers[0]);
1579 n %= 100;
1580 }
1581 if (n > 20)
1582 {
1583 append_word (medium_numbers[n / 10]);
1584 n %= 10;
1585 }
1586 if (n > 0)
1587 append_word (small_numbers[n]);
1588 };
1589
1590 auto absnum = val.num < 0 ? 0 - static_cast<uint64_t> (val.num)
1591 : static_cast<uint64_t> (val.num);
1592 auto denom = static_cast<uint64_t> (val.denom);
1593 auto whole = absnum / denom;
1594 if (whole == 0)
1595 out = "zero";
1596 else
1597 {
1598 std::vector<unsigned> groups;
1599 for (; whole; whole /= 1000)
1600 groups.push_back (whole % 1000);
1601
1602 for (int i = groups.size() - 1; i >= 0; --i)
1603 {
1604 if (groups[i] == 0)
1605 continue;
1606 append_below_1000 (groups[i]);
1607 if (i > 0)
1608 append_word (big_numbers[i]);
1609 }
1610 }
1611
1612 if (denom != 1)
1613 {
1614 out += " and ";
1615 auto rem = absnum % denom;
1616 for (auto d = denom, r = rem ? rem : 1; d % 10 == 0; d /= 10, r /= 10)
1617 if (r == 0)
1618 out += '0';
1619 out += std::to_string (rem);
1620 out += '/';
1621 out += std::to_string (denom);
1622 }
1623 return g_strndup (out.c_str(), out.size());
1624}

◆ xaccParseAmount()

gboolean xaccParseAmount ( const char *  in_str,
gboolean  monetary,
gnc_numeric *  result,
char **  endstr 
)

Parses in_str to obtain a numeric result.

The routine will parse as much of in_str as it can to obtain a single number. The number is parsed using the current locale information and the 'monetary' flag. The routine will return TRUE if it successfully parsed a number and FALSE otherwise. If TRUE is returned and result is non-NULL, the value of the parsed number is stored in *result. If FALSE is returned, *result is unchanged. If TRUE is returned and endstr is non-NULL, the location of the first character in in_str not used by the parser will be returned in *endstr. If FALSE is returned and endstr is non-NULL, *endstr will point to in_str.

Definition at line 1994 of file gnc-ui-util.cpp.

1996{
1997 return xaccParseAmountBasicInternal (in_str, monetary, auto_decimal_enabled,
1998 result, endstr, FALSE);
1999}

◆ xaccParseAmountExtended()

gboolean xaccParseAmountExtended ( const char *  in_str,
gboolean  monetary,
gunichar  negative_sign,
gunichar  decimal_point,
gunichar  group_separator,
const char *  ignore_list,
gnc_numeric *  result,
char **  endstr 
)

Converts a string to a gnc_numeric.

The caller must provide all the locale-specific information.

ignore_list is a list of characters that are completely ignored while processing the input string. If ignore_list is NULL, nothing is ignored.

Definition at line 2012 of file gnc-ui-util.cpp.

2016{
2017 return xaccParseAmountInternal (in_str, monetary, negative_sign,
2018 decimal_point, group_separator,
2019 ignore_list, auto_decimal_enabled,
2020 result, endstr);
2021}

◆ xaccParseAmountExtImport()

gboolean xaccParseAmountExtImport ( const char *  in_str,
gboolean  monetary,
gunichar  negative_sign,
gunichar  decimal_point,
gunichar  group_separator,
const char *  ignore_list,
gnc_numeric *  result,
char **  endstr 
)

Similar to xaccParseAmountExtended, but will not automatically set a decimal point, regardless of what the user has set for this option.

Primarily meant for cases where numbers are coming into gnucash that are not typed in by the user (like via csv import).

Definition at line 2024 of file gnc-ui-util.cpp.

2028{
2029 return xaccParseAmountInternal (in_str, monetary, negative_sign,
2030 decimal_point, group_separator,
2031 ignore_list, FALSE,
2032 result, endstr);
2033}

◆ xaccParseAmountImport()

gboolean xaccParseAmountImport ( const char *  in_str,
gboolean  monetary,
gnc_numeric *  result,
char **  endstr,
gboolean  skip 
)

Similar to xaccParseAmount, but with two differences.

  • it exposes a flag to indicate whether the locale's positive sign (or in absence the '+') character is ignored. Setting skip to TRUE will cause the function to ignore any positive sign. Setting it to FALSE, and positive signs will be treated as unrecognized characters. xaccParseAmount will run as if skip is FALSE for compatibility reasons (gnc-expression-parser depends on this behaviour).
  • The other important difference with xaccParseAmount is that this function will never apply automatic decimal point logc, whereas xaccParseAmount will follow the automatic decimal point preference as set by the user.

Definition at line 2002 of file gnc-ui-util.cpp.

2005{
2006 return xaccParseAmountBasicInternal (in_str, monetary, FALSE,
2007 result, endstr, skip);
2008}

◆ xaccPrintAmount()

const char * xaccPrintAmount ( gnc_numeric  val,
GNCPrintAmountInfo  info 
)

Make a string representation of a gnc_numeric.

Warning, the gnc_numeric is not checked for validity and the returned char* may point to random garbage.

Definition at line 1435 of file gnc-ui-util.cpp.

1436{
1437 /* hack alert -- this is not thread safe ... */
1438 static char buf[BUFLEN];
1439
1440 if (!xaccSPrintAmount (buf, val, info))
1441 buf[0] = '\0';
1442
1443 /* its OK to return buf, since we declared it static */
1444 return buf;
1445}

◆ xaccSPrintAmount()

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

Make a string representation of a gnc_numeric.

Warning, the gnc_numeric is not checked for validity and the contents of the buffer will be unchanged. It is up to the calling function to ensure that buf is large enough for the results.

Parameters
bufpShould be at least 64 chars.

Definition at line 1308 of file gnc-ui-util.cpp.

1309{
1310 auto orig_bufp = bufp;
1311 auto currency_symbol = "";
1312 const char* sign;
1313
1314 char cs_precedes;
1315 char sep_by_space;
1316 char sign_posn;
1317
1318 bool print_sign = true;
1319 bool print_absolute = false;
1320
1321 if (!bufp)
1322 return 0;
1323
1324 auto lc = gnc_localeconv();
1325 if (info.use_locale)
1326 if (gnc_numeric_negative_p (val))
1327 {
1328 cs_precedes = lc->n_cs_precedes;
1329 sep_by_space = lc->n_sep_by_space;
1330 }
1331 else
1332 {
1333 cs_precedes = lc->p_cs_precedes;
1334 sep_by_space = lc->p_sep_by_space;
1335 }
1336 else
1337 {
1338 cs_precedes = TRUE;
1339 sep_by_space = TRUE;
1340 }
1341
1342 if (info.commodity && info.use_symbol)
1343 {
1344 currency_symbol = gnc_commodity_get_nice_symbol (info.commodity);
1345 if (!gnc_commodity_is_iso (info.commodity))
1346 {
1347 cs_precedes = FALSE;
1348 sep_by_space = TRUE;
1349 }
1350 }
1351
1352 if (gnc_numeric_negative_p (val))
1353 {
1354 sign = lc->negative_sign;
1355 sign_posn = lc->n_sign_posn;
1356 }
1357 else
1358 {
1359 sign = lc->positive_sign;
1360 sign_posn = lc->p_sign_posn;
1361 }
1362
1363 if (gnc_numeric_zero_p (val) || (sign == nullptr) || (sign[0] == 0))
1364 print_sign = FALSE;
1365
1366 /* See if we print sign now */
1367 if (print_sign && (sign_posn == 1))
1368 bufp = g_stpcpy(bufp, sign);
1369
1370 /* Now see if we print currency */
1371 if (cs_precedes)
1372 {
1373 /* See if we print sign now */
1374 if (print_sign && (sign_posn == 3))
1375 bufp = g_stpcpy(bufp, sign);
1376
1377 if (info.use_symbol)
1378 {
1379 bufp = g_stpcpy(bufp, currency_symbol);
1380 if (sep_by_space)
1381 bufp = g_stpcpy(bufp, " ");
1382 }
1383
1384 /* See if we print sign now */
1385 if (print_sign && (sign_posn == 4))
1386 bufp = g_stpcpy(bufp, sign);
1387 }
1388
1389 /* Now see if we print parentheses */
1390 if (print_sign && (sign_posn == 0))
1391 {
1392 bufp = g_stpcpy(bufp, "(");
1393 print_absolute = TRUE;
1394 }
1395
1396 /* Now print the value */
1397 bufp += PrintAmountInternal(bufp,
1398 print_absolute ? gnc_numeric_abs(val) : val,
1399 &info);
1400
1401 /* Now see if we print parentheses */
1402 if (print_sign && (sign_posn == 0))
1403 bufp = g_stpcpy(bufp, ")");
1404
1405 /* Now see if we print currency */
1406 if (!cs_precedes)
1407 {
1408 /* See if we print sign now */
1409 if (print_sign && (sign_posn == 3))
1410 bufp = g_stpcpy(bufp, sign);
1411
1412 if (info.use_symbol)
1413 {
1414 if (sep_by_space)
1415 bufp = g_stpcpy(bufp, " ");
1416 bufp = g_stpcpy(bufp, currency_symbol);
1417 }
1418
1419 /* See if we print sign now */
1420 if (print_sign && (sign_posn == 4))
1421 bufp = g_stpcpy(bufp, sign);
1422 }
1423
1424 /* See if we print sign now */
1425 if (print_sign && (sign_posn == 2))
1426 bufp = g_stpcpy(bufp, sign);
1427
1428 /* return length of printed string */
1429 return (bufp - orig_bufp);
1430}
gnc_numeric gnc_numeric_abs(gnc_numeric a)
Returns a newly created gnc_numeric that is the absolute value of the given gnc_numeric value.
gboolean gnc_numeric_negative_p(gnc_numeric a)
Returns 1 if a < 0, otherwise returns 0.