Skip to content

Commit 72869a3

Browse files
[gnc-commodity.cpp] use qof_instance kvp API for const char*
1 parent e7f05b9 commit 72869a3

File tree

1 file changed

+8
-36
lines changed

1 file changed

+8
-36
lines changed

libgnucash/engine/gnc-commodity.cpp

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,16 +1016,9 @@ gnc_commodity_get_fraction(const gnc_commodity * cm)
10161016
gboolean
10171017
gnc_commodity_get_auto_quote_control_flag(const gnc_commodity *cm)
10181018
{
1019-
GValue v = G_VALUE_INIT;
1020-
gboolean retval = TRUE;
1021-
10221019
if (!cm) return FALSE;
1023-
qof_instance_get_kvp (QOF_INSTANCE (cm), &v, 1, "auto_quote_control");
1024-
if (G_VALUE_HOLDS_STRING (&v) &&
1025-
strcmp(g_value_get_string (&v), "false") == 0)
1026-
retval = FALSE;
1027-
g_value_unset (&v);
1028-
return retval;
1020+
auto str{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE (cm), {"auto_quote_control"})};
1021+
return !str || g_strcmp0 (*str, "false");
10291022
}
10301023

10311024
/********************************************************************
@@ -1083,11 +1076,8 @@ gnc_commodity_get_user_symbol(const gnc_commodity *cm)
10831076
{
10841077
g_return_val_if_fail (GNC_IS_COMMODITY (cm), nullptr);
10851078

1086-
GValue v = G_VALUE_INIT;
1087-
qof_instance_get_kvp (QOF_INSTANCE(cm), &v, 1, "user_symbol");
1088-
const char *rv = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : nullptr;
1089-
g_value_unset (&v);
1090-
return rv;
1079+
auto sym{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(cm), {"user_symbol"})};
1080+
return sym ? *sym : nullptr;
10911081
}
10921082

10931083
/********************************************************************
@@ -1245,7 +1235,6 @@ void
12451235
gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
12461236
const gboolean flag)
12471237
{
1248-
GValue v = G_VALUE_INIT;
12491238
ENTER ("(cm=%p, flag=%d)", cm, flag);
12501239

12511240
if (!cm)
@@ -1254,15 +1243,8 @@ gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
12541243
return;
12551244
}
12561245
gnc_commodity_begin_edit(cm);
1257-
if (flag)
1258-
qof_instance_set_kvp (QOF_INSTANCE (cm), nullptr, 1, "auto_quote_control");
1259-
else
1260-
{
1261-
g_value_init (&v, G_TYPE_STRING);
1262-
g_value_set_string (&v, "false");
1263-
qof_instance_set_kvp (QOF_INSTANCE (cm), &v, 1, "auto_quote_control");
1264-
}
1265-
g_value_unset (&v);
1246+
auto val = flag ? std::nullopt : std::make_optional<const char*>(g_strdup("false"));
1247+
qof_instance_set_path_kvp<const char*> (QOF_INSTANCE (cm), val, {"auto_quote_control"});
12661248
mark_commodity_dirty(cm);
12671249
gnc_commodity_commit_edit(cm);
12681250
LEAVE("");
@@ -1393,18 +1375,8 @@ gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
13931375

13941376
gnc_commodity_begin_edit (cm);
13951377

1396-
if (user_symbol)
1397-
{
1398-
GValue v = G_VALUE_INIT;
1399-
g_value_init (&v, G_TYPE_STRING);
1400-
g_value_set_static_string (&v, user_symbol);
1401-
qof_instance_set_kvp (QOF_INSTANCE(cm), &v, 1, "user_symbol");
1402-
g_value_unset (&v);
1403-
}
1404-
else
1405-
{
1406-
qof_instance_set_kvp (QOF_INSTANCE(cm), nullptr, 1, "user_symbol");
1407-
}
1378+
auto val = user_symbol ? std::make_optional<const char*>(g_strdup(user_symbol)) : std::nullopt;
1379+
qof_instance_set_path_kvp<const char*> (QOF_INSTANCE(cm), val, {"user_symbol"});
14081380

14091381
mark_commodity_dirty(cm);
14101382
gnc_commodity_commit_edit(cm);

0 commit comments

Comments
 (0)