[account.cpp] new static: get/set_kvp_string_path

exactly the same as set_kvp_string_tag but will accept the full kvp
path.
This commit is contained in:
Christopher Lam 2021-09-14 07:23:22 +08:00
parent 1d8983191d
commit 374443747d

View File

@ -2486,7 +2486,8 @@ stripdup_or_null (const char *value)
// note the *value argument is expected to be either a strstripped // note the *value argument is expected to be either a strstripped
// char* or nullptr, as returned by stripdup_or_null above. // char* or nullptr, as returned by stripdup_or_null above.
static void static void
set_kvp_string_tag (Account *acc, const char *tag, const char *value) set_kvp_string_path (Account *acc, std::vector<std::string> const & path,
const char *value)
{ {
g_return_if_fail(GNC_IS_ACCOUNT(acc)); g_return_if_fail(GNC_IS_ACCOUNT(acc));
@ -2496,28 +2497,40 @@ set_kvp_string_tag (Account *acc, const char *tag, const char *value)
GValue v = G_VALUE_INIT; GValue v = G_VALUE_INIT;
g_value_init (&v, G_TYPE_STRING); g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, value); g_value_set_string (&v, value);
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {tag}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path);
g_value_unset (&v); g_value_unset (&v);
} }
else else
{ {
qof_instance_set_path_kvp (QOF_INSTANCE (acc), NULL, {tag}); qof_instance_set_path_kvp (QOF_INSTANCE (acc), NULL, path);
} }
mark_account (acc); mark_account (acc);
xaccAccountCommitEdit(acc); xaccAccountCommitEdit(acc);
} }
static void
set_kvp_string_tag (Account *acc, const char *tag, const char *value)
{
set_kvp_string_path (acc, {tag}, value);
}
static char* static char*
get_kvp_string_tag (const Account *acc, const char *tag) get_kvp_string_path (const Account *acc, std::vector<std::string> const & path)
{ {
GValue v = G_VALUE_INIT; GValue v = G_VALUE_INIT;
if (acc == NULL || tag == NULL) return NULL; if (acc == NULL) return NULL; // how to check path is valid??
qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, {tag}); qof_instance_get_path_kvp (QOF_INSTANCE (acc), &v, path);
auto retval = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL; auto retval = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL;
g_value_unset (&v); g_value_unset (&v);
return retval; return retval;
} }
static char*
get_kvp_string_tag (const Account *acc, const char *tag)
{
return get_kvp_string_path (acc, {tag});
}
void void
xaccAccountSetColor (Account *acc, const char *str) xaccAccountSetColor (Account *acc, const char *str)
{ {