29#include <glib/gi18n.h>
36#include <qofinstance-p.h>
40#include "gnc-locale-utils.h"
46#include <unordered_map>
48static QofLogModule log_module = GNC_MOD_COMMODITY;
77 gnc_commodity_namespace *name_space;
88 gnc_quote_source *quote_source;
96 const char *default_symbol;
99#define GET_PRIVATE(o) \
100 ((gnc_commodityPrivate*)gnc_commodity_get_instance_private((gnc_commodity*)o))
104 QofInstanceClass parent_class;
107static void commodity_free(gnc_commodity * cm);
108static void gnc_commodity_set_default_symbol(gnc_commodity *,
const char *);
116 GHashTable * cm_table;
122 QofInstanceClass parent_class;
127 GHashTable * ns_table;
131static const std::unordered_map<std::string,std::string> gnc_new_iso_codes =
147static std::string fq_version;
152 gboolean m_supported;
154 std::string m_user_name;
155 std::string m_internal_name;
157 bool get_supported ()
const {
return m_supported; }
158 void set_supported (
bool supported) { m_supported = supported; }
160 const char* get_user_name ()
const {
return m_user_name.c_str(); }
161 const char* get_internal_name ()
const {
return m_internal_name.c_str(); }
163 const char* username,
const char* int_name)
164 : m_supported{supported}
166 , m_user_name{username ? username :
""}
167 , m_internal_name{int_name ? int_name:
""} { };
170using QuoteSourceList = std::list<gnc_quote_source>;
180static QuoteSourceList currency_quote_sources =
189static QuoteSourceList single_quote_sources =
191 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Alphavantage"),
"alphavantage" },
192 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Association of Mutual Funds in India"),
"amfiindia" },
193 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Athens Exchange Group, GR"),
"asegr" },
194 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Australian Stock Exchange, AU"),
"asx" },
195 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Italian Stock Exchange, IT"),
"borsa_italiana" },
196 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"BSE India, IN"),
"bseindia" },
197 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Bucharest Stock Exchange, RO"),
"bvb" },
198 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Colombo Stock Exchange, LK"),
"cse" },
199 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"comdirect, DE"),
"comdirect" },
200 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Consors Bank, DE"),
"consorsbank" },
201 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Deka Investments, DE"),
"deka" },
202 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Financial Times Funds service, GB"),
"ftfunds" },
203 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Finanzpartner, DE"),
"finanzpartner" },
204 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Finnhub, US"),
"finnhub" },
205 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"FondsWeb, DE"),
"fondsweb" },
206 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"GoldMoney precious metals"),
"goldmoney" },
207 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Google Web, US Stocks"),
"googleweb" },
208 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Market Watch"),
"marketwatch" },
209 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, CH"),
"morningstarch" },
210 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, GB"),
"morningstaruk" },
211 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, JP"),
"morningstarjp" },
212 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Motley Fool"),
"fool" },
213 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"New Zealand stock eXchange, NZ"),
"nzx" },
214 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"NSE (National Stock Exchange), IN"),
"nseindia" },
215 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"OnVista, DE"),
"onvista"},
216 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Paris Stock Exchange/Boursorama, FR"),
"bourso" },
217 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"S-Investor, DE"),
"sinvestor"},
218 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Sharenet, ZA"),
"za" },
219 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"SIX Swiss Exchange shares, CH"),
"six" },
220 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"StockData"),
"stockdata" },
221 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Stooq, PL"),
"stooq" },
222 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Swiss Fund Data AG, CH"),
"swissfunddata" },
223 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Tesouro Direto bonds, BR"),
"tesouro_direto" },
224 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Toronto Stock eXchange, CA"),
"tsx" },
225 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Tradegate, DE"),
"tradegate" },
226 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Treasury Direct bonds, US"),
"treasurydirect" },
227 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Twelve Data"),
"twelvedata" },
228 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Union Investment, DE"),
"unionfunds" },
229 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"US Savings Bonds, US"),
"usbonds" },
230 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"US Govt. Thrift Savings Plan"),
"tsp" },
231 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"XETRA, DE"),
"xetra" },
232 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Yahoo as JSON"),
"yahoo_json" },
233 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Yahoo Web"),
"yahooweb" },
234 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"YH Finance (FinanceAPI)"),
"financeapi" },
238static QuoteSourceList multiple_quote_sources =
240 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Canada (Alphavantage, TMX)"),
"canada" },
241 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Europe (ASEGR, Bourso, …)"),
"europe" },
242 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"India (BSEIndia, NSEIndia)"),
"india"},
243 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Nasdaq (Alphavantage, FinanceAPI, …)"),
"nasdaq" },
244 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"NYSE (Alphavantage, FinanceAPI, …)"),
"nyse" },
245 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"U.K. Funds (FTfunds, MorningstarUK)"),
"ukfunds" },
246 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"USA (Alphavantage, FinanceAPI, …)"),
"usa" },
249static QuoteSourceList new_quote_sources;
252static const std::vector<std::pair<QuoteSourceType,QuoteSourceList&>> quote_sources_map =
269 return (!fq_version.empty());
282 return fq_version.c_str();
285static QuoteSourceList&
288 auto quote_sources_it = std::find_if (quote_sources_map.begin(), quote_sources_map.end(),
289 [type] (
const auto& qs) { return type == qs.first; });
291 if (quote_sources_it != quote_sources_map.end())
292 return quote_sources_it->second;
294 PWARN (
"Invalid Quote Source %d, returning new_quote_sources", type);
295 return new_quote_sources;
305 return get_quote_source_from_type(type).size();
321 DEBUG(
"Creating new source %s", (!source_name ?
"(null)" : source_name));
327 return &new_quote_sources.emplace_back (supported,
SOURCE_UNKNOWN, source_name, source_name);
338 ENTER(
"type/index is %d/%d", type, index);
339 auto& sources = get_quote_source_from_type (type);
340 if ((
size_t) index < sources.size())
342 auto it = std::next(sources.begin(), index);
343 LEAVE(
"found %s", it->get_user_name());
357 for (
const auto& [_, sources] : quote_sources_map)
359 auto source_it = std::find_if (sources.begin(), sources.end(),
360 [name] (
const auto& qs)
361 { return (g_strcmp0(name, qs.get_internal_name()) == 0); });
362 if (source_it != sources.end())
363 return &(*source_it);
366 DEBUG(
"gnc_quote_source_lookup_by_internal: Unknown source %s", name);
385 LEAVE(
"type is %d", source->get_type());
386 return source->get_type();
394 PWARN (
"bad source");
398 auto& sources = get_quote_source_from_type (source->get_type());
399 auto is_source = [&source](
const auto& findif_source)
400 {
return &findif_source == source; };
402 auto iter = std::find_if (sources.begin(), sources.end(), is_source);
403 if (iter != sources.end())
404 return std::distance (sources.begin(), iter);
406 PWARN (
"couldn't locate source");
420 LEAVE(
"%s supported", source && source->get_supported() ?
"" :
"not ");
421 return source->get_supported();
433 LEAVE(
"user name %s", source->get_user_name());
434 return source->get_user_name();
446 LEAVE(
"internal name %s", source->get_internal_name());
447 return source->get_internal_name();
459 const std::vector<std::string>& sources_list)
463 if (sources_list.empty())
467 fq_version = version_string;
471 for (
const auto& source_name_str : sources_list)
473 auto source_name = source_name_str.c_str();
478 DEBUG(
"Found source %s: %s", source_name, source->get_user_name());
479 source->set_supported (
true);
493gnc_commodity_begin_edit (gnc_commodity *cm)
500 PERR (
"Failed to commit: %d", errcode);
501 gnc_engine_signal_commit_error( errcode );
509 commodity_free( GNC_COMMODITY(inst) );
513gnc_commodity_commit_edit (gnc_commodity *cm)
524mark_commodity_dirty (gnc_commodity *cm)
526 qof_instance_set_dirty(&cm->inst);
533 g_free(priv->printname);
534 priv->printname = g_strdup_printf(
"%s (%s)",
535 priv->mnemonic ? priv->mnemonic :
"",
536 priv->fullname ? priv->fullname :
"");
542 gnc_commodity_namespace *ns;
544 g_free(priv->unique_name);
545 ns = priv->name_space;
546 priv->unique_name = g_strdup_printf(
"%s::%s",
548 priv->mnemonic ? priv->mnemonic :
"");
552G_DEFINE_TYPE_WITH_PRIVATE(gnc_commodity, gnc_commodity, QOF_TYPE_INSTANCE)
555gnc_commodity_init(gnc_commodity* com)
559 priv = GET_PRIVATE(com);
561 priv->name_space =
nullptr;
562 priv->fullname = CACHE_INSERT(
"");
563 priv->mnemonic = CACHE_INSERT(
"");
564 priv->cusip = CACHE_INSERT(
"");
565 priv->fraction = 10000;
566 priv->quote_flag = 0;
567 priv->quote_source =
nullptr;
568 priv->quote_tz = CACHE_INSERT(
"");
570 reset_printname(priv);
571 reset_unique_name(priv);
575gnc_commodity_dispose(GObject *comp)
577 G_OBJECT_CLASS(gnc_commodity_parent_class)->dispose(comp);
581gnc_commodity_finalize(GObject* comp)
583 G_OBJECT_CLASS(gnc_commodity_parent_class)->finalize(comp);
592gnc_commodity_get_property (GObject *
object,
597 gnc_commodity *commodity;
600 g_return_if_fail(GNC_IS_COMMODITY(
object));
602 commodity = GNC_COMMODITY(
object);
603 priv = GET_PRIVATE(commodity);
607 g_value_take_object(value, priv->name_space);
610 g_value_set_string(value, priv->fullname);
613 g_value_set_string(value, priv->mnemonic);
616 g_value_set_string(value, priv->printname);
619 g_value_set_string(value, priv->cusip);
622 g_value_set_int(value, priv->fraction);
624 case PROP_UNIQUE_NAME:
625 g_value_set_string(value, priv->unique_name);
627 case PROP_QUOTE_FLAG:
628 g_value_set_boolean(value, priv->quote_flag);
630 case PROP_QUOTE_SOURCE:
631 g_value_set_pointer(value, priv->quote_source);
634 g_value_set_string(value, priv->quote_tz);
637 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
643gnc_commodity_set_property (GObject *
object,
648 gnc_commodity *commodity;
650 g_return_if_fail(GNC_IS_COMMODITY(
object));
652 commodity = GNC_COMMODITY(
object);
653 g_assert (qof_instance_get_editlevel(commodity));
672 case PROP_QUOTE_FLAG:
675 case PROP_QUOTE_SOURCE:
682 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
689 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
691 gobject_class->dispose = gnc_commodity_dispose;
692 gobject_class->finalize = gnc_commodity_finalize;
693 gobject_class->set_property = gnc_commodity_set_property;
694 gobject_class->get_property = gnc_commodity_get_property;
696 g_object_class_install_property(gobject_class,
698 g_param_spec_object (
"namespace",
700 "The namespace field denotes the "
701 "namespace for this commodity, either "
702 "a currency or symbol from a quote source.",
703 GNC_TYPE_COMMODITY_NAMESPACE,
705 g_object_class_install_property(gobject_class,
707 g_param_spec_string (
"fullname",
708 "Full Commodity Name",
709 "The fullname is the official full name of"
713 g_object_class_install_property(gobject_class,
715 g_param_spec_string (
"mnemonic",
716 "Commodity Mnemonic",
717 "The mnemonic is the official abbreviated"
718 "designation for the currency.",
721 g_object_class_install_property(gobject_class,
723 g_param_spec_string (
"printname",
724 "Commodity Print Name",
725 "Printable form of the commodity name.",
728 g_object_class_install_property(gobject_class,
730 g_param_spec_string (
"cusip",
731 "Commodity CUSIP Code",
735 g_object_class_install_property(gobject_class,
737 g_param_spec_int (
"fraction",
739 "The fraction is the number of sub-units that "
740 "the basic commodity can be divided into.",
745 g_object_class_install_property(gobject_class,
747 g_param_spec_string (
"unique-name",
748 "Commodity Unique Name",
749 "Unique form of the commodity name which combines "
750 "the namespace name and the commodity name.",
753 g_object_class_install_property(gobject_class,
755 g_param_spec_boolean (
"quote_flag",
757 "TRUE if prices are to be downloaded for this "
758 "commodity from a quote source.",
761 g_object_class_install_property(gobject_class,
763 g_param_spec_pointer(
"quote-source",
765 "The quote source from which prices are downloaded.",
767 g_object_class_install_property(gobject_class,
769 g_param_spec_string (
"quote-tz",
770 "Commodity Quote Timezone",
778 const char * name_space,
const char * mnemonic,
779 const char * cusip,
int fraction)
781 auto retval = GNC_COMMODITY(g_object_new(GNC_TYPE_COMMODITY,
nullptr));
784 gnc_commodity_begin_edit(retval);
786 if ( name_space !=
nullptr )
789 if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
790 g_strcmp0 (mnemonic,
"template") != 0)
792 PWARN(
"Converting commodity %s from namespace template to "
793 "namespace User", mnemonic);
807 mark_commodity_dirty (retval);
808 gnc_commodity_commit_edit(retval);
821commodity_free(gnc_commodity * cm)
824 gnc_commodity_table *
table;
832 priv = GET_PRIVATE(cm);
837 CACHE_REMOVE (priv->fullname);
838 CACHE_REMOVE (priv->cusip);
839 CACHE_REMOVE (priv->mnemonic);
840 CACHE_REMOVE (priv->quote_tz);
841 priv->name_space =
nullptr;
844 priv->quote_source =
nullptr;
847 g_free(priv->printname);
848 priv->printname =
nullptr;
850 g_free(priv->unique_name);
851 priv->unique_name =
nullptr;
853#ifdef ACCOUNTS_CLEANED_UP
858 if (priv->usage_count != 0)
860 PWARN(
"Destroying commodity (%p) with non-zero usage_count (%d).", cm,
872 gnc_commodity_begin_edit(cm);
873 qof_instance_set_destroying(cm, TRUE);
874 gnc_commodity_commit_edit(cm);
885 dest_priv->name_space = src_priv->name_space;
891 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
900 auto dest = GNC_COMMODITY (g_object_new(GNC_TYPE_COMMODITY,
nullptr));
902 src_priv = GET_PRIVATE(src);
903 dest_priv = GET_PRIVATE(dest);
905 dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
906 dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
907 dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
908 dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
910 dest_priv->name_space = src_priv->name_space;
912 dest_priv->fraction = src_priv->fraction;
913 dest_priv->quote_flag = src_priv->quote_flag;
917 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
919 reset_printname(dest_priv);
920 reset_unique_name(dest_priv);
932 if (!cm)
return nullptr;
933 return GET_PRIVATE(cm)->mnemonic;
943 if (!cm)
return nullptr;
944 return GET_PRIVATE(cm)->printname;
955 if (!cm)
return nullptr;
959gnc_commodity_namespace *
962 if (!cm)
return nullptr;
963 return GET_PRIVATE(cm)->name_space;
973 if (!cm)
return nullptr;
974 return GET_PRIVATE(cm)->fullname;
985 if (!cm)
return nullptr;
986 return GET_PRIVATE(cm)->unique_name;
997 if (!cm)
return nullptr;
998 return GET_PRIVATE(cm)->cusip;
1009 return GET_PRIVATE(cm)->fraction;
1017gnc_commodity_get_auto_quote_control_flag(
const gnc_commodity *cm)
1019 if (!cm)
return FALSE;
1020 auto str{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE (cm), {
"auto_quote_control"})};
1021 return !str || g_strcmp0 (*str,
"false");
1031 if (!cm)
return FALSE;
1032 return (GET_PRIVATE(cm)->quote_flag);
1044 if (!cm)
return nullptr;
1045 priv = GET_PRIVATE(cm);
1047 return ¤cy_quote_sources.front();
1048 return priv->quote_source;
1052gnc_commodity_get_default_quote_source(
const gnc_commodity *cm)
1055 return ¤cy_quote_sources.front();
1067 if (!cm)
return nullptr;
1068 return GET_PRIVATE(cm)->quote_tz;
1077 g_return_val_if_fail (GNC_IS_COMMODITY (cm),
nullptr);
1079 auto sym{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(cm), {
"user_symbol"})};
1080 return sym ? *sym :
nullptr;
1089 if (!cm)
return nullptr;
1090 return GET_PRIVATE(cm)->default_symbol;
1099 const char *nice_symbol;
1101 if (!cm)
return nullptr;
1104 if (nice_symbol && *nice_symbol)
1107 lc = gnc_localeconv();
1108 nice_symbol = lc->currency_symbol;
1113 if (nice_symbol && *nice_symbol)
1129 priv = GET_PRIVATE(cm);
1130 if (priv->mnemonic == mnemonic)
return;
1132 gnc_commodity_begin_edit(cm);
1133 CACHE_REMOVE (priv->mnemonic);
1134 priv->mnemonic = CACHE_INSERT(mnemonic);
1136 mark_commodity_dirty (cm);
1137 reset_printname(priv);
1138 reset_unique_name(priv);
1139 gnc_commodity_commit_edit(cm);
1150 gnc_commodity_table *
table;
1151 gnc_commodity_namespace *nsp;
1155 priv = GET_PRIVATE(cm);
1159 if (priv->name_space == nsp)
1162 gnc_commodity_begin_edit(cm);
1163 priv->name_space = nsp;
1166 mark_commodity_dirty(cm);
1167 reset_printname(priv);
1168 reset_unique_name(priv);
1169 gnc_commodity_commit_edit(cm);
1182 priv = GET_PRIVATE(cm);
1183 if (priv->fullname == fullname)
return;
1185 CACHE_REMOVE (priv->fullname);
1186 priv->fullname = CACHE_INSERT (fullname);
1188 gnc_commodity_begin_edit(cm);
1189 mark_commodity_dirty(cm);
1190 reset_printname(priv);
1191 gnc_commodity_commit_edit(cm);
1206 priv = GET_PRIVATE(cm);
1207 if (priv->cusip == cusip)
return;
1209 gnc_commodity_begin_edit(cm);
1210 CACHE_REMOVE (priv->cusip);
1211 priv->cusip = CACHE_INSERT (cusip);
1212 mark_commodity_dirty(cm);
1213 gnc_commodity_commit_edit(cm);
1224 gnc_commodity_begin_edit(cm);
1225 GET_PRIVATE(cm)->fraction = fraction;
1226 mark_commodity_dirty(cm);
1227 gnc_commodity_commit_edit(cm);
1235gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
1236 const gboolean flag)
1238 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1245 gnc_commodity_begin_edit(cm);
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"});
1248 mark_commodity_dirty(cm);
1249 gnc_commodity_commit_edit(cm);
1262 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1270 priv = GET_PRIVATE(cm);
1271 gnc_commodity_begin_edit(cm);
1282 gnc_commodity_set_auto_quote_control_flag(cm,
1283 (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1285 gnc_commodity_commit_edit(cm);
1296 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1299 gnc_commodity_begin_edit(cm);
1300 GET_PRIVATE(cm)->quote_flag = flag;
1301 mark_commodity_dirty(cm);
1302 gnc_commodity_commit_edit(cm);
1313 ENTER (
"(cm=%p, src=%p(%s))", cm, src, src ? src->get_internal_name() :
"unknown");
1316 gnc_commodity_begin_edit(cm);
1317 GET_PRIVATE(cm)->quote_source = src;
1318 mark_commodity_dirty(cm);
1319 gnc_commodity_commit_edit(cm);
1334 ENTER (
"(cm=%p, tz=%s)", cm, tz ? tz :
"(null)");
1336 priv = GET_PRIVATE(cm);
1338 if (tz == priv->quote_tz)
1340 LEAVE(
"Already correct TZ");
1344 gnc_commodity_begin_edit(cm);
1345 CACHE_REMOVE (priv->quote_tz);
1346 priv->quote_tz = CACHE_INSERT (tz);
1347 mark_commodity_dirty(cm);
1348 gnc_commodity_commit_edit(cm);
1363 ENTER (
"(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol :
"(null)");
1365 lc = gnc_localeconv();
1366 if (!user_symbol || !*user_symbol)
1367 user_symbol =
nullptr;
1369 !g_strcmp0(lc->currency_symbol, user_symbol))
1372 user_symbol =
nullptr;
1374 user_symbol =
nullptr;
1376 gnc_commodity_begin_edit (cm);
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"});
1381 mark_commodity_dirty(cm);
1382 gnc_commodity_commit_edit(cm);
1393gnc_commodity_set_default_symbol(gnc_commodity * cm,
1394 const char * default_symbol)
1396 GET_PRIVATE(cm)->default_symbol = default_symbol;
1408 ENTER(
"(cm=%p)", cm);
1416 priv = GET_PRIVATE(cm);
1418 if ((priv->usage_count == 0) && !priv->quote_flag
1419 && gnc_commodity_get_auto_quote_control_flag(cm)
1424 gnc_commodity_begin_edit(cm);
1427 gnc_commodity_get_default_quote_source(cm));
1428 gnc_commodity_commit_edit(cm);
1430 priv->usage_count++;
1431 LEAVE(
"(usage_count=%d)", priv->usage_count);
1443 ENTER(
"(cm=%p)", cm);
1451 priv = GET_PRIVATE(cm);
1453 if (priv->usage_count == 0)
1455 PWARN(
"usage_count already zero");
1460 priv->usage_count--;
1461 if ((priv->usage_count == 0) && priv->quote_flag
1462 && gnc_commodity_get_auto_quote_control_flag(cm)
1469 LEAVE(
"(usage_count=%d)", priv->usage_count);
1487 if (a == b)
return TRUE;
1488 if (!a || !b)
return FALSE;
1490 priv_a = GET_PRIVATE(a);
1491 priv_b = GET_PRIVATE(b);
1492 if (priv_a->name_space != priv_b->name_space)
return FALSE;
1493 if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
return FALSE;
1506 if (a == b)
return 0;
1507 if (a && !b)
return 1;
1508 if (b && !a)
return -1;
1537 if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
1538 return GNC_COMMODITY_NS_ISO_GUI;
1548 return g_list_copy (name_space->cm_list);
1554 return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1555 (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1559gnc_commodity_table_map_namespace(
const char * name_space)
1561 if (g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0)
1562 return GNC_COMMODITY_NS_CURRENCY;
1571gnc_commodity_table *
1574 gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1575 retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1576 retval->ns_list =
nullptr;
1584gnc_commodity_table *
1587 if (!book)
return nullptr;
1588 return static_cast<gnc_commodity_table*
>(qof_book_get_data (book, GNC_COMMODITY_TABLE));
1594 gnc_commodity *twin;
1596 gnc_commodity_table * comtbl;
1598 if (!from)
return nullptr;
1600 if (!comtbl)
return nullptr;
1603 twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1618count_coms(gpointer key, gpointer value, gpointer user_data)
1620 GHashTable *tbl = ((gnc_commodity_namespace*)value)->cm_table;
1621 guint *count = (guint*)user_data;
1623 if (g_strcmp0((
char*)key, GNC_COMMODITY_NS_CURRENCY) == 0)
1631 *count += g_hash_table_size(tbl);
1638 g_return_val_if_fail(tbl, 0);
1639 g_return_val_if_fail(tbl->ns_table, 0);
1641 g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1652gnc_commodity_table_lookup(
const gnc_commodity_table *
table,
1653 const char * name_space,
const char * mnemonic)
1655 gnc_commodity_namespace * nsp =
nullptr;
1657 if (!
table || !name_space || !mnemonic)
return nullptr;
1669 auto it = gnc_new_iso_codes.find (mnemonic);
1670 if (it != gnc_new_iso_codes.end())
1671 mnemonic = it->second.c_str();
1673 return GNC_COMMODITY(g_hash_table_lookup(nsp->cm_table, (gpointer)mnemonic));
1687gnc_commodity_table_lookup_unique(
const gnc_commodity_table *
table,
1688 const char * unique_name)
1692 gnc_commodity *commodity;
1694 if (!
table || !unique_name)
return nullptr;
1696 name_space = g_strdup (unique_name);
1697 mnemonic = strstr (name_space,
"::");
1700 g_free (name_space);
1707 commodity = gnc_commodity_table_lookup (
table, name_space, mnemonic);
1709 g_free (name_space);
1720gnc_commodity_table_find_full(
const gnc_commodity_table *
table,
1721 const char * name_space,
1722 const char * fullname)
1724 gnc_commodity * retval =
nullptr;
1728 if (!fullname || (fullname[0] ==
'\0'))
1733 for (iterator = all; iterator; iterator = iterator->next)
1735 auto commodity = GNC_COMMODITY (iterator->data);
1736 if (!strcmp(fullname,
1757 gnc_commodity * comm)
1759 gnc_commodity_namespace * nsp =
nullptr;
1761 const char *ns_name;
1765 if (!
table)
return nullptr;
1766 if (!comm)
return nullptr;
1768 priv = GET_PRIVATE(comm);
1770 ENTER (
"(table=%p, comm=%p) %s %s",
table, comm,
1771 (priv->mnemonic ==
nullptr ?
"(null)" : priv->mnemonic),
1772 (priv->fullname ==
nullptr ?
"(null)" : priv->fullname));
1774 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1780 LEAVE(
"already in table");
1786 if (priv->name_space->iso4217)
1788 auto it = gnc_new_iso_codes.find (priv->mnemonic);
1789 if (it != gnc_new_iso_codes.end())
1794 LEAVE(
"found at %p", c);
1799 if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
1800 g_strcmp0 (priv->mnemonic,
"template") != 0)
1802 PWARN(
"Converting commodity %s from namespace template to "
1803 "namespace User", priv->mnemonic);
1806 mark_commodity_dirty (comm);
1812 PINFO (
"insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1813 nsp->cm_table, nsp->name);
1814 g_hash_table_insert(nsp->cm_table,
1815 (gpointer)CACHE_INSERT(priv->mnemonic),
1817 nsp->cm_list = g_list_append(nsp->cm_list, comm);
1831 gnc_commodity * comm)
1833 gnc_commodity_namespace * nsp;
1836 const char *ns_name;
1841 priv = GET_PRIVATE(comm);
1843 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1844 if (c != comm)
return;
1851 nsp->cm_list = g_list_remove(nsp->cm_list, comm);
1852 g_hash_table_remove (nsp->cm_table, priv->mnemonic);
1863 const char * name_space)
1865 gnc_commodity_namespace * nsp =
nullptr;
1867 if (!
table || !name_space)
1884hash_keys_helper(gpointer key, gpointer value, gpointer data)
1886 auto l = (GList**)data;
1887 *l = g_list_prepend(*l, key);
1891g_hash_table_keys(GHashTable *
table)
1893 GList * l =
nullptr;
1894 g_hash_table_foreach(
table, &hash_keys_helper, (gpointer) &l);
1899hash_values_helper(gpointer key, gpointer value, gpointer data)
1901 auto l = (GList**)data;
1902 *l = g_list_prepend(*l, value);
1906g_hash_table_values(GHashTable *
table)
1908 GList * l =
nullptr;
1909 g_hash_table_foreach(
table, &hash_values_helper, (gpointer) &l);
1924 return g_hash_table_keys(
table->ns_table);
1933 return g_list_copy (
table->ns_list);
1947 if (!cm)
return FALSE;
1949 priv = GET_PRIVATE(cm);
1950 if ( !priv->name_space)
return FALSE;
1951 return priv->name_space->iso4217;
1957 const char *ns_name;
1958 if (!cm)
return FALSE;
1962 !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
1970static CommodityList*
1971commodity_table_get_all_noncurrency_commodities(
const gnc_commodity_table*
table)
1974 CommodityList *retval =
nullptr;
1975 for (node = nslist; node; node=g_list_next(node))
1977 gnc_commodity_namespace *ns =
nullptr;
1978 if (g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_CURRENCY) == 0
1979 || g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_TEMPLATE) == 0)
1984 retval = g_list_concat(g_hash_table_values(ns->cm_table), retval);
1986 g_list_free(nslist);
1992 const char * name_space)
1994 gnc_commodity_namespace * ns =
nullptr;
1998 if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONISO_GUI) == 0)
1999 return commodity_table_get_all_noncurrency_commodities(
table);
2004 return g_hash_table_values(ns->cm_table);
2013get_quotables_helper1(gpointer key, gpointer value, gpointer data)
2015 auto comm = GNC_COMMODITY(value);
2017 auto l =
static_cast<GList**
>(data);
2019 if (!priv->quote_flag || !priv->quote_source || !priv->quote_source->get_supported())
2021 *l = g_list_prepend(*l, value);
2025get_quotables_helper2 (gnc_commodity *comm, gpointer data)
2027 auto l =
static_cast<GList**
>(data);
2030 if (!priv->quote_flag || priv->quote_source || !priv->quote_source->get_supported())
2032 *l = g_list_prepend(*l, comm);
2039 gnc_commodity_namespace * ns =
nullptr;
2040 const char *name_space;
2041 GList * nslist, * tmp;
2042 GList * l =
nullptr;
2044 const char *expression = gnc_prefs_get_namespace_regexp();
2046 ENTER(
"table=%p, expression=%s",
table, expression);
2050 if (expression && *expression)
2052 if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2054 LEAVE(
"Cannot compile regex");
2059 for (tmp = nslist; tmp; tmp = tmp->next)
2061 name_space =
static_cast<const char*
>(tmp->data);
2062 if (regexec(&pattern, name_space, 0,
nullptr, 0) == 0)
2064 DEBUG(
"Running list of %s commodities", name_space);
2068 g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2072 g_list_free(nslist);
2077 gnc_commodity_table_foreach_commodity(
table, get_quotables_helper2,
2080 LEAVE(
"list head %p", l);
2090QOF_GOBJECT_IMPL(gnc_commodity_namespace, gnc_commodity_namespace, QOF_TYPE_INSTANCE)
2093gnc_commodity_namespace_init(gnc_commodity_namespace* ns)
2098gnc_commodity_namespace_dispose_real (GObject *nsp)
2103gnc_commodity_namespace_finalize_real(GObject* nsp)
2107gnc_commodity_namespace *
2109 const char * name_space,
2112 gnc_commodity_namespace * ns =
nullptr;
2114 if (!
table)
return nullptr;
2116 name_space = gnc_commodity_table_map_namespace(name_space);
2120 ns =
static_cast<gnc_commodity_namespace*
>(g_object_new(GNC_TYPE_COMMODITY_NAMESPACE,
nullptr));
2121 ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2122 ns->name = CACHE_INSERT(
static_cast<const char*
>(name_space));
2127 g_hash_table_insert(
table->ns_table,
2128 (gpointer) ns->name,
2130 table->ns_list = g_list_append(
table->ns_list, ns);
2138 const char * namespace_name,
2139 const char * new_namespace_name)
2141 if (!
table || !namespace_name || !new_namespace_name ||
2142 (g_strcmp0 (namespace_name, new_namespace_name) == 0) ||
2143 (g_strcmp0 (new_namespace_name, GNC_COMMODITY_NS_ISO_GUI) == 0) ||
2144 (g_strcmp0 (new_namespace_name, _(GNC_COMMODITY_NS_ISO_GUI)) == 0) ||
2152 ns->name = CACHE_INSERT(
static_cast<const char*
>(new_namespace_name));
2154 g_hash_table_insert (
table->ns_table,
2155 (gpointer) ns->name,
2158 g_hash_table_remove (
table->ns_table,
2159 (gpointer) namespace_name);
2161 CACHE_REMOVE(namespace_name);
2163 qof_instance_set_dirty (&ns->inst);
2168gnc_commodity_namespace *
2170 const char * name_space)
2172 if (!
table || !name_space)
2175 name_space = gnc_commodity_table_map_namespace(name_space);
2176 return static_cast<gnc_commodity_namespace*
>(g_hash_table_lookup(
table->ns_table, (gpointer)name_space));
2181gnc_commodity_find_commodity_by_guid(
const GncGUID *guid,
QofBook *book)
2184 if (!guid || !book)
return nullptr;
2195ns_helper(gpointer key, gpointer value, gpointer user_data)
2197 auto c = GNC_COMMODITY(value);
2199 CACHE_REMOVE(
static_cast<char*
>(key));
2205 const char * name_space)
2207 gnc_commodity_namespace * ns;
2216 g_hash_table_remove(
table->ns_table, name_space);
2217 table->ns_list = g_list_remove(
table->ns_list, ns);
2219 g_list_free(ns->cm_list);
2220 ns->cm_list =
nullptr;
2222 g_hash_table_foreach_remove(ns->cm_table, ns_helper,
nullptr);
2223 g_hash_table_destroy(ns->cm_table);
2224 CACHE_REMOVE(ns->name);
2240 gboolean (*func)(gnc_commodity *, gpointer);
2245iter_commodity (gpointer key, gpointer value, gpointer user_data)
2248 gnc_commodity *cm = (gnc_commodity *) value;
2252 iter_data->ok = (iter_data->func)(cm, iter_data->user_data);
2257iter_namespace (gpointer key, gpointer value, gpointer user_data)
2259 GHashTable *namespace_hash = ((gnc_commodity_namespace *) value)->cm_table;
2260 g_hash_table_foreach (namespace_hash, iter_commodity, user_data);
2264gnc_commodity_table_foreach_commodity (
const gnc_commodity_table * tbl,
2265 gboolean (*f)(gnc_commodity *, gpointer),
2270 if (!tbl || !f)
return FALSE;
2272 iter_data.ok = TRUE;
2274 iter_data.user_data = user_data;
2276 g_hash_table_foreach(tbl->ns_table, iter_namespace, (gpointer)&iter_data);
2278 return iter_data.ok;
2287gnc_commodity_table_destroy(gnc_commodity_table * t)
2289 gnc_commodity_namespace * ns;
2293 ENTER (
"table=%p", t);
2295 for (item = t->ns_list; item; item = next)
2297 next = g_list_next(item);
2298 ns =
static_cast<gnc_commodity_namespace*
>(item->data);
2302 g_list_free(t->ns_list);
2303 t->ns_list =
nullptr;
2304 g_hash_table_destroy(t->ns_table);
2305 t->ns_table =
nullptr;
2306 LEAVE (
"table=%p", t);
2316#define CUR_I18N(String) dgettext ("iso_4217", String)
2326 c =
gnc_commodity_new(book,
"template", GNC_COMMODITY_NS_TEMPLATE,
"template",
"template", 1);
2329#include "iso-4217-currencies.c"
2354static QofObject commodity_object_def =
2357 DI(.e_type = ) GNC_ID_COMMODITY,
2358 DI(.type_label = ) "Commodity",
2359 DI(.create = )
nullptr,
2360 DI(.book_begin = )
nullptr,
2361 DI(.book_end = )
nullptr,
2364 DI(.foreach = ) qof_collection_foreach,
2368static QofObject namespace_object_def =
2371 DI(.e_type = ) GNC_ID_COMMODITY_NAMESPACE,
2372 DI(.type_label = ) "Namespace",
2373 DI(.create = )
nullptr,
2374 DI(.book_begin = )
nullptr,
2375 DI(.book_end = )
nullptr,
2376 DI(.is_dirty = )
nullptr,
2377 DI(.mark_clean = )
nullptr,
2378 DI(.foreach = )
nullptr,
2379 DI(.printable = )
nullptr,
2383commodity_table_book_begin (
QofBook *book)
2385 gnc_commodity_table *ct;
2386 ENTER (
"book=%p", book);
2392 qof_book_set_data (book, GNC_COMMODITY_TABLE, ct);
2396 PWARN(
"unable to initialize book's commodity_table");
2399 LEAVE (
"book=%p", book);
2403commodity_table_book_end (
QofBook *book)
2405 gnc_commodity_table *ct;
2408 qof_book_set_data (book, GNC_COMMODITY_TABLE,
nullptr);
2409 gnc_commodity_table_destroy (ct);
2412static QofObject commodity_table_object_def =
2415 DI(.e_type = ) GNC_ID_COMMODITY_TABLE,
2416 DI(.type_label = ) "CommodityTable",
2417 DI(.create = )
nullptr,
2418 DI(.book_begin = ) commodity_table_book_begin,
2419 DI(.book_end = ) commodity_table_book_end,
2422 DI(.foreach = )
nullptr,
2423 DI(.printable = )
nullptr,
2424 DI(.version_cmp = )
nullptr,
2445 MonetaryList *l = list, *tmp;
2446 for (tmp = list; tmp; tmp = tmp->next)
2448 auto list_mon =
static_cast<gnc_monetary*
>(tmp->data);
2460 auto new_mon =
static_cast<gnc_monetary*
>(g_new0(gnc_monetary, 1));
2462 l = g_list_prepend(l, new_mon);
2473 MonetaryList *node, *next;
2474 for (node = list; node; node = next)
2476 auto mon =
static_cast<gnc_monetary*
>(node->data);
2481 list = g_list_delete_link(list, node);
2492 for (tmp = list; tmp; tmp = tmp->next)
Commodity handling public routines.
Commodity handling public routines (C++ api)
Generic api to store and retrieve preferences.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
int gnc_commodity_table_has_namespace(const gnc_commodity_table *table, const char *name_space)
Test to see if the indicated namespace exits in the commodity table.
const char * gnc_quote_source_fq_version(void)
This function returns the version of the Finance::Quote module installed on a user's computer.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
CommodityList * gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table *table)
This function returns a list of commodities for which price quotes should be retrieved.
const char * gnc_quote_source_get_user_name(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the user friendly name of this quote source.
guint gnc_commodity_table_get_size(const gnc_commodity_table *tbl)
Returns the number of commodities in the commodity table.
#define GNC_COMMODITY_MAX_FRACTION
Max fraction is 10^9 because 10^10 would require changing it to an int64_t.
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
Set the 'exchange code' for the specified commodity.
int gnc_commodity_compare(const gnc_commodity *a, const gnc_commodity *b)
This routine returns 0 if the two commodities are equal, 1 otherwise.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
gboolean gnc_quote_source_get_supported(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the flag that indicates whether this particular quote...
const char * gnc_commodity_get_user_symbol(const gnc_commodity *cm)
Retrieve the user-defined symbol for the specified commodity.
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
This function finds a commodity namespace in the set of existing commodity namespaces.
void gnc_quote_source_set_fq_installed(const char *version_string, const std::vector< std::string > &sources_list)
Update gnucash internal tables based on what Finance::Quote sources are installed.
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
Remove a commodity from the commodity table.
gboolean gnc_quote_source_fq_installed(void)
This function indicates whether or not the Finance::Quote module is installed on a user's computer.
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
Set the namespace for the specified commodity.
gint gnc_quote_source_get_index(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the index of this particular quote source within its ...
gnc_quote_source * gnc_quote_source_add_new(const char *source_name, gboolean supported)
Create a new quote source.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
const char * gnc_quote_source_get_internal_name(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the internal name of this quote source.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
gnc_commodity_namespace * gnc_commodity_table_add_namespace(gnc_commodity_table *table, const char *name_space, QofBook *book)
This function adds a new string to the list of commodity namespaces.
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
Create a new commodity.
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
Set the full name for the specified commodity.
GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace *name_space)
Return a list of all commodity data structures in the specified namespace.
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity.
MonetaryList * gnc_monetary_list_add_monetary(MonetaryList *list, gnc_monetary add_mon)
Add a gnc_monetary to the list.
gnc_commodity * gnc_commodity_obtain_twin(const gnc_commodity *from, QofBook *book)
Given the commodity 'findlike', this routine will find and return the equivalent commodity (commodity...
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.
gboolean gnc_commodity_table_add_default_data(gnc_commodity_table *table, QofBook *book)
Add all the standard namespaces and currencies to the commodity table.
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
Retrieve the automatic price quote timezone for the specified commodity.
const char * gnc_commodity_get_default_symbol(const gnc_commodity *cm)
Retrieve the default symbol for the specified commodity.
const char * gnc_commodity_get_nice_symbol(const gnc_commodity *cm)
Retrieve a symbol for the specified commodity, suitable for display to the user.
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
int gnc_commodity_compare_void(const void *a, const void *b)
A wrapper around gnc_commodity_compare() which offers the function declaration that is needed for g_l...
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
Set the fraction for the specified commodity.
gboolean gnc_commodity_table_register(void)
You should probably not be using gnc_commodity_table_register() It is an internal routine for registe...
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
Retrieve the automatic price quote source for the specified commodity.
bool gnc_commodity_table_rename_namespace(const gnc_commodity_table *table, const char *namespace_name, const char *new_namespace_name)
This function renames a namespace.
const char * gnc_commodity_get_cusip(const gnc_commodity *cm)
Retrieve the 'exchange code' for the specified commodity.
gnc_quote_source * gnc_quote_source_lookup_by_ti(QuoteSourceType type, gint index)
Given the type/index of a quote source, find the data structure identified by this pair.
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
Given the internal (gnucash or F::Q) name of a quote source, find the data structure identified by th...
void gnc_commodity_table_delete_namespace(gnc_commodity_table *table, const char *name_space)
This function deletes a string from the list of commodity namespaces.
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
Increment a commodity's internal counter that tracks how many accounts are using that commodity.
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
Add a new commodity to the commodity table.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
Return a list of all namespaces in the commodity table.
QuoteSourceType
The quote source type enum account types are used to determine how the transaction data in the accoun...
MonetaryList * gnc_monetary_list_delete_zeros(MonetaryList *list)
Delete all entries in the list that have zero value.
GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table *table)
Return a list of all namespace data structures in the commodity table.
void gnc_commodity_set_user_symbol(gnc_commodity *cm, const char *user_symbol)
Set a user-defined symbol for the specified commodity.
void gnc_commodity_decrement_usage_count(gnc_commodity *cm)
Decrement a commodity's internal counter that tracks how many accounts are using that commodity.
gnc_commodity * gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
allocate and copy
void gnc_commodity_user_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity, based on user input.
void gnc_monetary_list_free(MonetaryList *list)
Free a MonetaryList and all the monetaries it points to.
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.
gnc_commodity_namespace * gnc_commodity_get_namespace_ds(const gnc_commodity *cm)
Retrieve the namespace data structure for the specified commodity.
gnc_commodity_table * gnc_commodity_table_new(void)
You probably shouldn't be using gnc_commodity_table_new() directly, it's for internal use only.
void gnc_commodity_destroy(gnc_commodity *cm)
Destroy a commodity.
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure.
#define GNC_COMMODITY_NS_LEGACY
The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the excha...
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
Retrieve the automatic price quote flag for the specified commodity.
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
Set the mnemonic for the specified commodity.
const char * gnc_commodity_namespace_get_gui_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure in a form suitable to present to the user.
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
Set the automatic price quote timezone for the specified commodity.
QuoteSourceType gnc_quote_source_get_type(const gnc_quote_source *source)
Given a gnc_quote_source data structure, return the type of this particular quote source.
CommodityList * gnc_commodity_table_get_commodities(const gnc_commodity_table *table, const char *name_space)
Return a list of all commodities in the commodity table that are in the given namespace.
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the 'unique' name for the specified commodity.
void gnc_commodity_copy(gnc_commodity *dest, const gnc_commodity *src)
Copy src into dest.
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.
gint gnc_quote_source_num_entries(QuoteSourceType type)
Return the number of entries for a given type of quote source.
@ SOURCE_MULTI
This quote source may pull from multiple web sites.
@ SOURCE_SINGLE
This quote source pulls from a single specific web site.
@ SOURCE_CURRENCY
The special currency quote source.
@ SOURCE_UNKNOWN
This is a locally installed quote source that gnucash knows nothing about.
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
#define PINFO(format, args...)
Print an informational note.
#define DEBUG(format, args...)
Print a debugging message.
#define LEAVE(format, args...)
Print a function exit debugging message.
#define PERR(format, args...)
Log a serious error.
#define PWARN(format, args...)
Log a warning.
#define ENTER(format, args...)
Print a function entry debugging message.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
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_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
@ GNC_HOW_DENOM_EXACT
Use any denominator which gives an exactly correct ratio of numerator to denominator.
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
gboolean qof_commit_edit_part2(QofInstance *inst, void(*on_error)(QofInstance *, QofBackendError), void(*on_done)(QofInstance *), void(*on_free)(QofInstance *))
part2 – deal with the backend
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
globally unique ID User API
Object instance holds common fields that most gnucash objects use.
The type used to store guids in C.
A gnc_commodity_namespace is an collection of commodities.
An article that is bought and sold.
A gnc_commodity_table is a database of commodity info.