mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge Chris Lam's 'maint-static-string' into master.
This commit is contained in:
commit
4fab9f8284
@ -292,8 +292,6 @@ mark_account (Account *acc)
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
static constexpr const char* is_unset {"unset"};
|
||||
|
||||
/* GObject Initialization */
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(Account, gnc_account, QOF_TYPE_INSTANCE)
|
||||
|
||||
@ -331,22 +329,6 @@ gnc_account_init(Account* acc)
|
||||
priv->starting_reconciled_balance = gnc_numeric_zero();
|
||||
priv->balance_dirty = FALSE;
|
||||
|
||||
priv->higher_balance_limit = gnc_numeric_create (1,0);
|
||||
priv->higher_balance_cached = false;
|
||||
priv->lower_balance_limit = gnc_numeric_create (1,0);
|
||||
priv->lower_balance_cached = false;
|
||||
priv->include_sub_account_balances = TriState::Unset;
|
||||
|
||||
priv->last_num = (char*) is_unset;
|
||||
priv->tax_us_code = (char*) is_unset;
|
||||
priv->tax_us_pns = (char*) is_unset;
|
||||
priv->color = (char*) is_unset;
|
||||
priv->sort_order = (char*) is_unset;
|
||||
priv->notes = (char*) is_unset;
|
||||
priv->filter = (char*) is_unset;
|
||||
priv->equity_type = TriState::Unset;
|
||||
priv->sort_reversed = TriState::Unset;
|
||||
|
||||
priv->splits = NULL;
|
||||
priv->sort_dirty = FALSE;
|
||||
}
|
||||
@ -1404,21 +1386,6 @@ xaccFreeAccount (Account *acc)
|
||||
qof_string_cache_remove(priv->description);
|
||||
priv->accountName = priv->accountCode = priv->description = nullptr;
|
||||
|
||||
if (priv->last_num != is_unset)
|
||||
g_free (priv->last_num);
|
||||
if (priv->tax_us_code != is_unset)
|
||||
g_free (priv->tax_us_code);
|
||||
if (priv->tax_us_pns != is_unset)
|
||||
g_free (priv->tax_us_pns);
|
||||
if (priv->color != is_unset)
|
||||
g_free (priv->color);
|
||||
if (priv->sort_order != is_unset)
|
||||
g_free (priv->sort_order);
|
||||
if (priv->notes != is_unset)
|
||||
g_free (priv->notes);
|
||||
if (priv->filter != is_unset)
|
||||
g_free (priv->filter);
|
||||
|
||||
/* zero out values, just in case stray
|
||||
* pointers are pointing here. */
|
||||
|
||||
@ -2507,21 +2474,6 @@ xaccAccountSetDescription (Account *acc, const char *str)
|
||||
xaccAccountCommitEdit(acc);
|
||||
}
|
||||
|
||||
static char*
|
||||
stripdup_or_null (const char *value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
auto temp = g_strstrip (g_strdup (value));
|
||||
if (*temp)
|
||||
return temp;
|
||||
g_free (temp);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// note the *value argument is expected to be either a strstripped
|
||||
// char* or nullptr, as returned by stripdup_or_null above.
|
||||
static void
|
||||
set_kvp_string_path (Account *acc, std::vector<std::string> const & path,
|
||||
const char *value)
|
||||
@ -2529,11 +2481,11 @@ set_kvp_string_path (Account *acc, std::vector<std::string> const & path,
|
||||
g_return_if_fail(GNC_IS_ACCOUNT(acc));
|
||||
|
||||
xaccAccountBeginEdit(acc);
|
||||
if (value)
|
||||
if (value && *value)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
g_value_set_string (&v, value);
|
||||
g_value_set_static_string (&v, value);
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path);
|
||||
g_value_unset (&v);
|
||||
}
|
||||
@ -2551,58 +2503,43 @@ set_kvp_string_tag (Account *acc, const char *tag, const char *value)
|
||||
set_kvp_string_path (acc, {tag}, value);
|
||||
}
|
||||
|
||||
static char*
|
||||
get_kvp_string_path (const Account *acc, std::vector<std::string> const & path)
|
||||
static const char*
|
||||
get_kvp_string_path (const Account *acc, std::vector<std::string> const & path,
|
||||
GValue *v)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
*v = G_VALUE_INIT;
|
||||
if (acc == NULL) return NULL; // how to check path is valid??
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, path);
|
||||
auto retval = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
return retval;
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE (acc), v, path);
|
||||
return G_VALUE_HOLDS_STRING (v) ? g_value_get_string (v) : NULL;
|
||||
}
|
||||
|
||||
static char*
|
||||
get_kvp_string_tag (const Account *acc, const char *tag)
|
||||
static const char*
|
||||
get_kvp_string_tag (const Account *acc, const char *tag, GValue *v)
|
||||
{
|
||||
return get_kvp_string_path (acc, {tag});
|
||||
return get_kvp_string_path (acc, {tag}, v);
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetColor (Account *acc, const char *str)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->color != is_unset)
|
||||
g_free (priv->color);
|
||||
priv->color = stripdup_or_null (str);
|
||||
set_kvp_string_tag (acc, "color", priv->color);
|
||||
set_kvp_string_tag (acc, "color", str);
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetFilter (Account *acc, const char *str)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->filter != is_unset)
|
||||
g_free (priv->filter);
|
||||
priv->filter = stripdup_or_null (str);
|
||||
set_kvp_string_tag (acc, "filter", priv->filter);
|
||||
set_kvp_string_tag (acc, "filter", str);
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetSortOrder (Account *acc, const char *str)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->sort_order != is_unset)
|
||||
g_free (priv->sort_order);
|
||||
priv->sort_order = stripdup_or_null (str);
|
||||
set_kvp_string_tag (acc, "sort-order", priv->sort_order);
|
||||
set_kvp_string_tag (acc, "sort-order", str);
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetSortReversed (Account *acc, gboolean sortreversed)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
priv->sort_reversed = sortreversed ? TriState::True : TriState::False;
|
||||
set_kvp_string_tag (acc, "sort-reversed", sortreversed ? "true" : NULL);
|
||||
}
|
||||
|
||||
@ -2627,11 +2564,7 @@ qofAccountSetParent (Account *acc, QofInstance *parent)
|
||||
void
|
||||
xaccAccountSetNotes (Account *acc, const char *str)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->notes != is_unset)
|
||||
g_free (priv->notes);
|
||||
priv->notes = stripdup_or_null (str);
|
||||
set_kvp_string_tag (acc, "notes", priv->notes);
|
||||
set_kvp_string_tag (acc, "notes", str);
|
||||
}
|
||||
|
||||
void
|
||||
@ -2754,7 +2687,7 @@ DxaccAccountSetCurrency (Account * acc, gnc_commodity * currency)
|
||||
|
||||
if ((!acc) || (!currency)) return;
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
g_value_set_string (&v, s);
|
||||
g_value_set_static_string (&v, s);
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"old-currency"});
|
||||
mark_account (acc);
|
||||
xaccAccountCommitEdit(acc);
|
||||
@ -3375,57 +3308,51 @@ xaccAccountGetDescription (const Account *acc)
|
||||
const char *
|
||||
xaccAccountGetColor (const Account *acc)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->color == is_unset)
|
||||
priv->color = get_kvp_string_tag (acc, "color");
|
||||
return priv->color;
|
||||
auto rv = get_kvp_string_tag (acc, "color", &v);
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
const char *
|
||||
xaccAccountGetFilter (const Account *acc)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->filter == is_unset)
|
||||
priv->filter = get_kvp_string_tag (acc, "filter");
|
||||
return priv->filter;
|
||||
auto rv = get_kvp_string_tag (acc, "filter", &v);
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
const char *
|
||||
xaccAccountGetSortOrder (const Account *acc)
|
||||
{
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), 0);
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->sort_order == is_unset)
|
||||
priv->sort_order = get_kvp_string_tag (acc, "sort-order");
|
||||
return priv->sort_order;
|
||||
GValue v = G_VALUE_INIT;
|
||||
auto rv = get_kvp_string_tag (acc, "sort-order", &v);
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
gboolean
|
||||
xaccAccountGetSortReversed (const Account *acc)
|
||||
{
|
||||
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->sort_reversed == TriState::Unset)
|
||||
{
|
||||
auto sort_reversed = get_kvp_string_tag (acc, "sort-reversed");
|
||||
priv->sort_reversed = g_strcmp0 (sort_reversed, "true") ?
|
||||
TriState::False : TriState::True;
|
||||
g_free (sort_reversed);
|
||||
}
|
||||
return (priv->sort_reversed == TriState::True);
|
||||
GValue v = G_VALUE_INIT;
|
||||
auto rv = !g_strcmp0 (get_kvp_string_tag (acc, "sort-reversed", &v), "true");
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
const char *
|
||||
xaccAccountGetNotes (const Account *acc)
|
||||
{
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), NULL);
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->notes == is_unset)
|
||||
priv->notes = get_kvp_string_tag (acc, "notes");
|
||||
return priv->notes;
|
||||
GValue v = G_VALUE_INIT;
|
||||
auto rv = get_kvp_string_tag (acc, "notes", &v);
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
gnc_commodity *
|
||||
@ -4142,39 +4069,31 @@ xaccAccountSetTaxRelated (Account *acc, gboolean tax_related)
|
||||
const char *
|
||||
xaccAccountGetTaxUSCode (const Account *acc)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->tax_us_code == is_unset)
|
||||
priv->tax_us_code = get_kvp_string_path (acc, {"tax-US", "code"});
|
||||
return priv->tax_us_code;
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, {"tax-US", "code"});
|
||||
return G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetTaxUSCode (Account *acc, const char *code)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->tax_us_code != is_unset)
|
||||
g_free (priv->tax_us_code);
|
||||
priv->tax_us_code = g_strdup (code);
|
||||
set_kvp_string_path (acc, {"tax-US", "code"}, priv->tax_us_code);
|
||||
set_kvp_string_path (acc, {"tax-US", "code"}, code);
|
||||
}
|
||||
|
||||
const char *
|
||||
xaccAccountGetTaxUSPayerNameSource (const Account *acc)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->tax_us_pns == is_unset)
|
||||
priv->tax_us_pns = get_kvp_string_path (acc, {"tax-US", "payer-name-source"});
|
||||
return priv->tax_us_pns;
|
||||
}
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, {"tax-US", "payer-name-source"});
|
||||
return G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
|
||||
}
|
||||
|
||||
void
|
||||
xaccAccountSetTaxUSPayerNameSource (Account *acc, const char *source)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->tax_us_pns != is_unset)
|
||||
g_free (priv->tax_us_pns);
|
||||
priv->tax_us_pns = g_strdup (source);
|
||||
set_kvp_string_path (acc, {"tax-US", "payer-name-source"}, priv->tax_us_pns);
|
||||
set_kvp_string_path (acc, {"tax-US", "payer-name-source"}, source);
|
||||
}
|
||||
|
||||
gint64
|
||||
@ -4272,15 +4191,12 @@ xaccAccountGetIsOpeningBalance (const Account *acc)
|
||||
{
|
||||
if (GET_PRIVATE(acc)->type != ACCT_TYPE_EQUITY)
|
||||
return false;
|
||||
auto priv = GET_PRIVATE(acc);
|
||||
if (priv->equity_type == TriState::Unset)
|
||||
{
|
||||
auto equity_type = get_kvp_string_tag (acc, "equity-type");
|
||||
priv->equity_type = g_strcmp0 (equity_type, "opening-balance") ?
|
||||
TriState::False : TriState::True;
|
||||
g_free (equity_type);
|
||||
}
|
||||
return (priv->equity_type == TriState::True);
|
||||
|
||||
GValue v = G_VALUE_INIT;
|
||||
auto rv = !g_strcmp0 (get_kvp_string_tag (acc, "equity-type", &v),
|
||||
"opening-balance");
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
@ -4288,8 +4204,6 @@ xaccAccountSetIsOpeningBalance (Account *acc, gboolean val)
|
||||
{
|
||||
if (GET_PRIVATE(acc)->type != ACCT_TYPE_EQUITY)
|
||||
return;
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
priv->equity_type = val ? TriState::True : TriState::False;
|
||||
set_kvp_string_tag(acc, "equity-type", val ? "opening-balance" : nullptr);
|
||||
}
|
||||
|
||||
@ -4917,10 +4831,10 @@ xaccAccountClearReconcilePostpone (Account *acc)
|
||||
const char *
|
||||
xaccAccountGetLastNum (const Account *acc)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->last_num == is_unset)
|
||||
priv->last_num = get_kvp_string_tag (acc, "last-num");
|
||||
return priv->last_num;
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(acc), FALSE);
|
||||
qof_instance_get_path_kvp (QOF_INSTANCE(acc), &v, {"last-num"});
|
||||
return G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
@ -4929,11 +4843,15 @@ xaccAccountGetLastNum (const Account *acc)
|
||||
void
|
||||
xaccAccountSetLastNum (Account *acc, const char *num)
|
||||
{
|
||||
auto priv = GET_PRIVATE (acc);
|
||||
if (priv->last_num != is_unset)
|
||||
g_free (priv->last_num);
|
||||
priv->last_num = g_strdup (num);
|
||||
set_kvp_string_tag (acc, "last-num", priv->last_num);
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_return_if_fail(GNC_IS_ACCOUNT(acc));
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
|
||||
g_value_set_static_string (&v, num);
|
||||
xaccAccountBeginEdit (acc);
|
||||
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"last-num"});
|
||||
mark_account (acc);
|
||||
xaccAccountCommitEdit (acc);
|
||||
}
|
||||
|
||||
|
||||
@ -5288,8 +5206,11 @@ dxaccAccountGetPriceSrc(const Account *acc)
|
||||
if (!xaccAccountIsPriced(acc)) return NULL;
|
||||
|
||||
g_free (source);
|
||||
source = get_kvp_string_tag (acc, "old-price-source");
|
||||
return source;
|
||||
|
||||
GValue v = G_VALUE_INIT;
|
||||
auto rv = get_kvp_string_tag (acc, "old-price-source", &v);
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
@ -5309,12 +5230,12 @@ dxaccAccountSetQuoteTZ(Account *acc, const char *tz)
|
||||
const char*
|
||||
dxaccAccountGetQuoteTZ(const Account *acc)
|
||||
{
|
||||
static char *quote_tz = nullptr;
|
||||
if (!acc) return NULL;
|
||||
if (!xaccAccountIsPriced(acc)) return NULL;
|
||||
g_free (quote_tz);
|
||||
quote_tz = get_kvp_string_tag (acc, "old-quote-tz");
|
||||
return quote_tz;
|
||||
GValue v = G_VALUE_INIT;
|
||||
auto rv = get_kvp_string_tag (acc, "old-quote-tz", &v);
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
@ -6273,10 +6194,12 @@ gnc_account_imap_get_info (Account *acc, const char *category)
|
||||
gchar *
|
||||
gnc_account_get_map_entry (Account *acc, const char *head, const char *category)
|
||||
{
|
||||
if (category)
|
||||
return get_kvp_string_path (acc, {head, category});
|
||||
else
|
||||
return get_kvp_string_path (acc, {head});
|
||||
GValue v = G_VALUE_INIT;
|
||||
auto rv = g_strdup (category ?
|
||||
get_kvp_string_path (acc, {head, category}, &v) :
|
||||
get_kvp_string_path (acc, {head}, &v));
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
@ -97,7 +97,6 @@ enum
|
||||
|
||||
};
|
||||
|
||||
static const char * is_unset = "unset";
|
||||
static const char * split_type_normal = "normal";
|
||||
static const char * split_type_stock_split = "stock-split";
|
||||
|
||||
@ -120,7 +119,6 @@ gnc_split_init(Split* split)
|
||||
split->value = gnc_numeric_zero();
|
||||
|
||||
split->date_reconciled = 0;
|
||||
split->split_type = is_unset;
|
||||
|
||||
split->balance = gnc_numeric_zero();
|
||||
split->cleared_balance = gnc_numeric_zero();
|
||||
@ -719,7 +717,6 @@ xaccFreeSplit (Split *split)
|
||||
split->lot = NULL;
|
||||
split->acc = NULL;
|
||||
split->orig_acc = NULL;
|
||||
split->split_type = NULL;
|
||||
|
||||
split->date_reconciled = 0;
|
||||
G_OBJECT_CLASS (QOF_INSTANCE_GET_CLASS (&split->inst))->dispose(G_OBJECT (split));
|
||||
@ -1967,25 +1964,23 @@ const char *
|
||||
xaccSplitGetType(const Split *s)
|
||||
{
|
||||
if (!s) return NULL;
|
||||
if (s->split_type == is_unset)
|
||||
|
||||
GValue v = G_VALUE_INIT;
|
||||
const char* type;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (s), &v, 1, "split-type");
|
||||
type = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
|
||||
const char *rv;
|
||||
if (!type || !g_strcmp0 (type, split_type_normal))
|
||||
rv = split_type_normal;
|
||||
else if (!g_strcmp0 (type, split_type_stock_split))
|
||||
rv = split_type_stock_split;
|
||||
else
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
Split *split = (Split*) s;
|
||||
const char* type;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (s), &v, 1, "split-type");
|
||||
type = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
|
||||
if (!type || !g_strcmp0 (type, split_type_normal))
|
||||
split->split_type = (char*) split_type_normal;
|
||||
else if (!g_strcmp0 (type, split_type_stock_split))
|
||||
split->split_type = (char*) split_type_stock_split;
|
||||
else
|
||||
{
|
||||
PERR ("unexpected split-type %s, reset to normal.", type);
|
||||
split->split_type = split_type_normal;
|
||||
}
|
||||
g_value_unset (&v);
|
||||
PERR ("unexpected split-type %s, reset to normal.", type);
|
||||
rv = split_type_normal;
|
||||
}
|
||||
return s->split_type;
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* reconfigure a split to be a stock split - after this, you shouldn't
|
||||
@ -1999,7 +1994,6 @@ xaccSplitMakeStockSplit(Split *s)
|
||||
s->value = gnc_numeric_zero();
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
g_value_set_static_string (&v, split_type_stock_split);
|
||||
s->split_type = split_type_stock_split;
|
||||
qof_instance_set_kvp (QOF_INSTANCE (s), &v, 1, "split-type");
|
||||
SET_GAINS_VDIRTY(s);
|
||||
mark_split(s);
|
||||
|
@ -92,9 +92,6 @@ typedef struct gnc_commodityPrivate
|
||||
const char *default_symbol;
|
||||
} gnc_commodityPrivate;
|
||||
|
||||
static const char*
|
||||
is_unset = "unset";
|
||||
|
||||
#define GET_PRIVATE(o) \
|
||||
((gnc_commodityPrivate*)gnc_commodity_get_instance_private((gnc_commodity*)o))
|
||||
|
||||
@ -673,7 +670,6 @@ gnc_commodity_init(gnc_commodity* com)
|
||||
priv->quote_flag = 0;
|
||||
priv->quote_source = NULL;
|
||||
priv->quote_tz = CACHE_INSERT("");
|
||||
priv->user_symbol = (char*) is_unset;
|
||||
|
||||
reset_printname(priv);
|
||||
reset_unique_name(priv);
|
||||
@ -958,10 +954,6 @@ commodity_free(gnc_commodity * cm)
|
||||
g_free(priv->unique_name);
|
||||
priv->unique_name = NULL;
|
||||
|
||||
if (priv->user_symbol != is_unset)
|
||||
g_free (priv->user_symbol);
|
||||
priv->user_symbol = NULL;
|
||||
|
||||
#ifdef ACCOUNTS_CLEANED_UP
|
||||
/* Account objects are not actually cleaned up when a book is closed (in fact
|
||||
* a memory leak), but commodities are, so in currently this warning gets hit
|
||||
@ -1193,17 +1185,13 @@ gnc_commodity_get_quote_tz(const gnc_commodity *cm)
|
||||
const char*
|
||||
gnc_commodity_get_user_symbol(const gnc_commodity *cm)
|
||||
{
|
||||
gnc_commodityPrivate* priv;
|
||||
g_return_val_if_fail (GNC_IS_COMMODITY (cm), NULL);
|
||||
priv = GET_PRIVATE(cm);
|
||||
if (priv->user_symbol == is_unset)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
qof_instance_get_kvp (QOF_INSTANCE(cm), &v, 1, "user_symbol");
|
||||
priv->user_symbol = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
}
|
||||
return priv->user_symbol;
|
||||
|
||||
GValue v = G_VALUE_INIT;
|
||||
qof_instance_get_kvp (QOF_INSTANCE(cm), &v, 1, "user_symbol");
|
||||
const char *rv = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
@ -1491,10 +1479,8 @@ void
|
||||
gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
|
||||
{
|
||||
struct lconv *lc;
|
||||
gnc_commodityPrivate* priv;
|
||||
|
||||
if (!cm) return;
|
||||
priv = GET_PRIVATE(cm);
|
||||
|
||||
ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
|
||||
|
||||
@ -1509,31 +1495,19 @@ gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
|
||||
else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
|
||||
user_symbol = NULL;
|
||||
|
||||
if (priv->user_symbol != is_unset)
|
||||
{
|
||||
if (!g_strcmp0 (user_symbol, priv->user_symbol))
|
||||
{
|
||||
LEAVE ("gnc_commodity_set_user_symbol: no change");
|
||||
return;
|
||||
}
|
||||
g_free (priv->user_symbol);
|
||||
}
|
||||
|
||||
gnc_commodity_begin_edit (cm);
|
||||
|
||||
if (user_symbol)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
g_value_set_string (&v, user_symbol);
|
||||
g_value_set_static_string (&v, user_symbol);
|
||||
qof_instance_set_kvp (QOF_INSTANCE(cm), &v, 1, "user_symbol");
|
||||
priv->user_symbol = g_strdup (user_symbol);
|
||||
g_value_unset (&v);
|
||||
}
|
||||
else
|
||||
{
|
||||
qof_instance_set_kvp (QOF_INSTANCE(cm), NULL, 1, "user_symbol");
|
||||
priv->user_symbol = NULL;
|
||||
}
|
||||
|
||||
mark_commodity_dirty(cm);
|
||||
|
@ -106,9 +106,6 @@ typedef struct GNCLotPrivate
|
||||
|
||||
/* ============================================================= */
|
||||
|
||||
static char*
|
||||
is_unset = "unset";
|
||||
|
||||
/* GObject Initialization */
|
||||
G_DEFINE_TYPE_WITH_PRIVATE(GNCLot, gnc_lot, QOF_TYPE_INSTANCE)
|
||||
|
||||
@ -122,8 +119,6 @@ gnc_lot_init(GNCLot* lot)
|
||||
priv->splits = NULL;
|
||||
priv->cached_invoice = NULL;
|
||||
priv->is_closed = LOT_CLOSED_UNKNOWN;
|
||||
priv->title = is_unset;
|
||||
priv->notes = is_unset;
|
||||
priv->marker = 0;
|
||||
}
|
||||
|
||||
@ -301,14 +296,6 @@ gnc_lot_free(GNCLot* lot)
|
||||
if (priv->account && !qof_instance_get_destroying(priv->account))
|
||||
xaccAccountRemoveLot (priv->account, lot);
|
||||
|
||||
if (priv->notes != is_unset)
|
||||
g_free (priv->notes);
|
||||
|
||||
if (priv->title != is_unset)
|
||||
g_free (priv->title);
|
||||
|
||||
priv->notes = NULL;
|
||||
priv->title = NULL;
|
||||
priv->account = NULL;
|
||||
priv->is_closed = TRUE;
|
||||
/* qof_instance_release (&lot->inst); */
|
||||
@ -457,50 +444,37 @@ gint gnc_lot_count_splits (const GNCLot *lot)
|
||||
const char *
|
||||
gnc_lot_get_title (const GNCLot *lot)
|
||||
{
|
||||
GNCLotPrivate* priv;
|
||||
if (!lot) return NULL;
|
||||
priv = GET_PRIVATE (lot);
|
||||
if (priv->title == is_unset)
|
||||
{
|
||||
GNCLotPrivate* priv = GET_PRIVATE (lot);
|
||||
GValue v = G_VALUE_INIT;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (lot), &v, 1, "title");
|
||||
priv->title = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
}
|
||||
return priv->title;
|
||||
|
||||
GValue v = G_VALUE_INIT;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (lot), &v, 1, "title");
|
||||
const char *rv = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
const char *
|
||||
gnc_lot_get_notes (const GNCLot *lot)
|
||||
{
|
||||
GNCLotPrivate* priv;
|
||||
if (!lot) return NULL;
|
||||
priv = GET_PRIVATE (lot);
|
||||
if (priv->notes == is_unset)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (lot), &v, 1, "notes");
|
||||
priv->notes = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
}
|
||||
return priv->notes;
|
||||
|
||||
GValue v = G_VALUE_INIT;
|
||||
qof_instance_get_kvp (QOF_INSTANCE (lot), &v, 1, "notes");
|
||||
const char *rv = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_lot_set_title (GNCLot *lot, const char *str)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
GNCLotPrivate* priv;
|
||||
if (!lot) return;
|
||||
priv = GET_PRIVATE (lot);
|
||||
if (priv->title != is_unset)
|
||||
g_free (priv->title);
|
||||
|
||||
qof_begin_edit(QOF_INSTANCE(lot));
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
g_value_set_string (&v, str);
|
||||
priv->title = g_strdup (str);
|
||||
g_value_set_static_string (&v, str);
|
||||
qof_instance_set_kvp (QOF_INSTANCE (lot), &v, 1, "title");
|
||||
qof_instance_set_dirty(QOF_INSTANCE(lot));
|
||||
gnc_lot_commit_edit(lot);
|
||||
@ -511,15 +485,11 @@ void
|
||||
gnc_lot_set_notes (GNCLot *lot, const char *str)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
GNCLotPrivate* priv;
|
||||
if (!lot) return;
|
||||
priv = GET_PRIVATE (lot);
|
||||
if (priv->notes != is_unset)
|
||||
g_free (priv->notes);
|
||||
|
||||
qof_begin_edit(QOF_INSTANCE(lot));
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
g_value_set_string (&v, str);
|
||||
priv->notes = g_strdup (str);
|
||||
g_value_set_static_string (&v, str);
|
||||
qof_instance_set_kvp (QOF_INSTANCE (lot), &v, 1, "notes");
|
||||
qof_instance_set_dirty(QOF_INSTANCE(lot));
|
||||
gnc_lot_commit_edit(lot);
|
||||
|
@ -66,8 +66,6 @@ struct _gncInvoice
|
||||
time64 date_opened;
|
||||
time64 date_posted;
|
||||
|
||||
char *doclink;
|
||||
|
||||
gnc_numeric to_charge_amount;
|
||||
|
||||
gnc_commodity *currency;
|
||||
@ -285,9 +283,6 @@ impl_get_typed_referring_object_list (const QofInstance* inst, const QofInstance
|
||||
return qof_instance_get_referring_object_list_from_collection (qof_instance_get_collection (inst), ref);
|
||||
}
|
||||
|
||||
static const char*
|
||||
is_unset = "unset";
|
||||
|
||||
static void
|
||||
gnc_invoice_class_init (GncInvoiceClass *klass)
|
||||
{
|
||||
@ -333,7 +328,6 @@ GncInvoice *gncInvoiceCreate (QofBook *book)
|
||||
invoice->active = TRUE;
|
||||
|
||||
invoice->to_charge_amount = gnc_numeric_zero ();
|
||||
invoice->doclink = (char*) is_unset;
|
||||
|
||||
qof_event_gen (&invoice->inst, QOF_EVENT_CREATE, NULL);
|
||||
|
||||
@ -379,10 +373,7 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *from)
|
||||
// Oops. Do not forget to copy the pointer to the correct currency here.
|
||||
invoice->currency = from->currency;
|
||||
|
||||
if (from->doclink == is_unset)
|
||||
invoice->doclink = (char*)is_unset;
|
||||
else
|
||||
gncInvoiceSetDocLink (invoice, from->doclink);
|
||||
gncInvoiceSetDocLink (invoice, gncInvoiceGetDocLink (from));
|
||||
|
||||
// Copy all invoice->entries
|
||||
for (node = from->entries; node; node = node->next)
|
||||
@ -444,9 +435,6 @@ static void gncInvoiceFree (GncInvoice *invoice)
|
||||
gncBillTermDecRef (invoice->terms);
|
||||
}
|
||||
|
||||
if (invoice->doclink != is_unset)
|
||||
g_free (invoice->doclink);
|
||||
|
||||
/* qof_instance_release (&invoice->inst); */
|
||||
g_object_unref (invoice);
|
||||
}
|
||||
@ -558,28 +546,18 @@ void gncInvoiceSetDocLink (GncInvoice *invoice, const char *doclink)
|
||||
{
|
||||
if (!invoice || !doclink) return;
|
||||
|
||||
if (invoice->doclink != is_unset)
|
||||
{
|
||||
if (!g_strcmp0 (doclink, invoice->doclink))
|
||||
return;
|
||||
|
||||
g_free (invoice->doclink);
|
||||
}
|
||||
|
||||
gncInvoiceBeginEdit (invoice);
|
||||
|
||||
if (doclink[0] == '\0')
|
||||
{
|
||||
invoice->doclink = NULL;
|
||||
qof_instance_set_kvp (QOF_INSTANCE (invoice), NULL, 1, GNC_INVOICE_DOCLINK);
|
||||
}
|
||||
else
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
g_value_init (&v, G_TYPE_STRING);
|
||||
g_value_set_string (&v, doclink);
|
||||
g_value_set_static_string (&v, doclink);
|
||||
qof_instance_set_kvp (QOF_INSTANCE (invoice), &v, 1, GNC_INVOICE_DOCLINK);
|
||||
invoice->doclink = g_strdup (doclink);
|
||||
g_value_unset (&v);
|
||||
}
|
||||
qof_instance_set_dirty (QOF_INSTANCE(invoice));
|
||||
@ -898,15 +876,13 @@ const char * gncInvoiceGetNotes (const GncInvoice *invoice)
|
||||
const char * gncInvoiceGetDocLink (const GncInvoice *invoice)
|
||||
{
|
||||
if (!invoice) return NULL;
|
||||
if (invoice->doclink == is_unset)
|
||||
{
|
||||
GValue v = G_VALUE_INIT;
|
||||
GncInvoice *inv = (GncInvoice*) invoice;
|
||||
qof_instance_get_kvp (QOF_INSTANCE(invoice), &v, 1, GNC_INVOICE_DOCLINK);
|
||||
inv->doclink = G_VALUE_HOLDS_STRING(&v) ? g_value_dup_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
}
|
||||
return invoice->doclink;
|
||||
|
||||
GValue v = G_VALUE_INIT;
|
||||
qof_instance_get_kvp (QOF_INSTANCE(invoice), &v, 1, GNC_INVOICE_DOCLINK);
|
||||
const char *rv = G_VALUE_HOLDS_STRING(&v) ? g_value_get_string (&v) : NULL;
|
||||
g_value_unset (&v);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
GncOwnerType gncInvoiceGetOwnerType (const GncInvoice *invoice)
|
||||
|
@ -1065,15 +1065,7 @@ qof_instance_set_kvp (QofInstance * inst, GValue const * value, unsigned count,
|
||||
|
||||
void qof_instance_get_path_kvp (QofInstance * inst, GValue * value, std::vector<std::string> const & path)
|
||||
{
|
||||
auto temp = gvalue_from_kvp_value (inst->kvp_data->get_slot (path));
|
||||
if (G_IS_VALUE (temp))
|
||||
{
|
||||
if (G_IS_VALUE (value))
|
||||
g_value_unset (value);
|
||||
g_value_init (value, G_VALUE_TYPE (temp));
|
||||
g_value_copy (temp, value);
|
||||
gnc_gvalue_free (temp);
|
||||
}
|
||||
gvalue_from_kvp_value (inst->kvp_data->get_slot (path), value);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -19,6 +19,7 @@
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
********************************************************************/
|
||||
#include <cstddef>
|
||||
#include <glib.h>
|
||||
|
||||
#include <config.h>
|
||||
@ -1153,7 +1154,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, "red");
|
||||
|
||||
xaccAccountSetTaxUSCode (account, "");
|
||||
g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, "");
|
||||
g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, nullptr);
|
||||
|
||||
xaccAccountSetTaxUSCode (account, " ");
|
||||
g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, " ");
|
||||
@ -1171,7 +1172,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, "red");
|
||||
|
||||
xaccAccountSetTaxUSPayerNameSource (account, "");
|
||||
g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, "");
|
||||
g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, nullptr);
|
||||
|
||||
xaccAccountSetTaxUSPayerNameSource (account, " ");
|
||||
g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, " ");
|
||||
@ -1192,7 +1193,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (xaccAccountGetFilter (account), ==, "unset");
|
||||
|
||||
xaccAccountSetFilter (account, " unset ");
|
||||
g_assert_cmpstr (xaccAccountGetFilter (account), ==, "unset");
|
||||
g_assert_cmpstr (xaccAccountGetFilter (account), ==, " unset ");
|
||||
|
||||
xaccAccountSetFilter (account, "");
|
||||
g_assert_cmpstr (xaccAccountGetFilter (account), ==, nullptr);
|
||||
@ -1210,7 +1211,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, "unset");
|
||||
|
||||
xaccAccountSetSortOrder (account, " unset ");
|
||||
g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, "unset");
|
||||
g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, " unset ");
|
||||
|
||||
xaccAccountSetSortOrder (account, "");
|
||||
g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, nullptr);
|
||||
@ -1228,7 +1229,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (xaccAccountGetNotes (account), ==, "unset");
|
||||
|
||||
xaccAccountSetNotes (account, " unset ");
|
||||
g_assert_cmpstr (xaccAccountGetNotes (account), ==, "unset");
|
||||
g_assert_cmpstr (xaccAccountGetNotes (account), ==, " unset ");
|
||||
|
||||
xaccAccountSetNotes (account, "");
|
||||
g_assert_cmpstr (xaccAccountGetNotes (account), ==, nullptr);
|
||||
@ -1301,7 +1302,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, "boo");
|
||||
|
||||
dxaccAccountSetPriceSrc (account, "");
|
||||
g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, "");
|
||||
g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, nullptr);
|
||||
|
||||
dxaccAccountSetPriceSrc (account, nullptr);
|
||||
g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, nullptr);
|
||||
@ -1313,7 +1314,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
|
||||
g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, "boo");
|
||||
|
||||
dxaccAccountSetQuoteTZ (account, "");
|
||||
g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, "");
|
||||
g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, nullptr);
|
||||
|
||||
dxaccAccountSetQuoteTZ (account, nullptr);
|
||||
g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, nullptr);
|
||||
|
Loading…
Reference in New Issue
Block a user