29 #include <glib/gi18n.h> 36 #include <qofinstance-p.h> 40 #include "gnc-locale-utils.h" 46 #include <unordered_map> 48 static 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;
107 static void commodity_free(gnc_commodity * cm);
108 static void gnc_commodity_set_default_symbol(gnc_commodity *,
const char *);
116 GHashTable * cm_table;
122 QofInstanceClass parent_class;
127 GHashTable * ns_table;
131 static const std::unordered_map<std::string,std::string> gnc_new_iso_codes =
147 static 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:
""} { };
170 using QuoteSourceList = std::list<gnc_quote_source>;
180 static QuoteSourceList currency_quote_sources =
189 static QuoteSourceList single_quote_sources =
191 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Alphavantage"),
"alphavantage" },
192 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Amsterdam Euronext eXchange, NL"),
"aex" },
193 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Association of Mutual Funds in India"),
"amfiindia" },
194 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Athens Exchange Group, GR"),
"asegr" },
195 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Australian Stock Exchange, AU"),
"asx" },
196 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Bloomberg"),
"bloomberg" },
197 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Italian Stock Exchange, IT"),
"borsa_italiana" },
198 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"BSE India, IN"),
"bseindia" },
199 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Bucharest Stock Exchange, RO"),
"bvb" },
200 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Colombo Stock Exchange, LK"),
"cse" },
201 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"comdirect, DE"),
"comdirect" },
202 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Consors Bank, DE"),
"consorsbank" },
203 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Deka Investments, DE"),
"deka" },
204 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Financial Times Funds service, GB"),
"ftfunds" },
205 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Finanzpartner, DE"),
"finanzpartner" },
206 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"FondsWeb, DE"),
"fondsweb" },
207 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"GoldMoney precious metals"),
"goldmoney" },
208 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Google Web, US Stocks"),
"googleweb" },
209 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Market Watch"),
"marketwatch" },
210 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, CH"),
"morningstarch" },
211 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, GB"),
"morningstaruk" },
212 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, JP"),
"morningstarjp" },
213 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Motley Fool"),
"fool" },
214 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"New Zealand stock eXchange, NZ"),
"nzx" },
215 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"NSE (National Stock Exchange), IN"),
"nseindia" },
216 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"OnVista, DE"),
"onvista"},
217 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Paris Stock Exchange/Boursorama, FR"),
"bourso" },
218 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"S-Investor, DE"),
"sinvestor"},
219 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Sharenet, ZA"),
"za" },
220 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"SIX Swiss Exchange shares, CH"),
"six" },
221 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"StockData"),
"stockdata" },
222 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Stooq, PL"),
"stooq" },
223 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"T. Rowe Price, US"),
"troweprice" },
224 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Tesouro Direto bonds, BR"),
"tesouro_direto" },
225 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"TIAA-CREF, US"),
"tiaacref" },
226 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Toronto Stock eXchange, CA"),
"tsx" },
227 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Tradegate, DE"),
"tradegate" },
228 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Treasury Direct bonds, US"),
"treasurydirect" },
229 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Twelve Data"),
"twelvedata" },
230 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Union Investment, DE"),
"unionfunds" },
231 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"US Govt. Thrift Savings Plan"),
"tsp" },
232 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"XETRA, DE"),
"xetra" },
233 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Yahoo as JSON"),
"yahoo_json" },
234 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Yahoo Web"),
"yahooweb" },
235 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"YH Finance (FinanceAPI)"),
"financeapi" },
239 static QuoteSourceList multiple_quote_sources =
241 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Canada (Alphavantage, TMX)"),
"canada" },
242 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Europe (ASEGR, Bourso, …)"),
"europe" },
243 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"India (BSEIndia, NSEIndia)"),
"india"},
244 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Nasdaq (Alphavantage, FinanceAPI, …)"),
"nasdaq" },
245 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"NYSE (Alphavantage, FinanceAPI, …)"),
"nyse" },
246 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"U.K. Funds (FTfunds, MorningstarUK)"),
"ukfunds" },
247 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"USA (Alphavantage, FinanceAPI, …)"),
"usa" },
250 static QuoteSourceList new_quote_sources;
253 static const std::vector<std::pair<QuoteSourceType,QuoteSourceList&>> quote_sources_map =
270 return (!fq_version.empty());
283 return fq_version.c_str();
286 static QuoteSourceList&
289 auto quote_sources_it = std::find_if (quote_sources_map.begin(), quote_sources_map.end(),
290 [type] (
const auto& qs) {
return type == qs.first; });
292 if (quote_sources_it != quote_sources_map.end())
293 return quote_sources_it->second;
295 PWARN (
"Invalid Quote Source %d, returning new_quote_sources", type);
296 return new_quote_sources;
306 auto source{get_quote_source_from_type(type)};
307 return std::distance(source.begin(), source.end());
323 DEBUG(
"Creating new source %s", (!source_name ?
"(null)" : source_name));
329 return &new_quote_sources.emplace_back (supported,
SOURCE_UNKNOWN, source_name, source_name);
340 ENTER(
"type/index is %d/%d", type, index);
341 auto& sources = get_quote_source_from_type (type);
342 if ((
size_t) index < sources.size())
344 auto it = std::next(sources.begin(), index);
345 LEAVE(
"found %s", it->get_user_name());
359 for (
const auto& [_, sources] : quote_sources_map)
361 auto source_it = std::find_if (sources.begin(), sources.end(),
362 [name] (
const auto& qs)
363 {
return (g_strcmp0(name, qs.get_internal_name()) == 0); });
364 if (source_it != sources.end())
365 return &(*source_it);
368 DEBUG(
"gnc_quote_source_lookup_by_internal: Unknown source %s", name);
387 LEAVE(
"type is %d", source->get_type());
388 return source->get_type();
396 PWARN (
"bad source");
400 auto& sources = get_quote_source_from_type (source->get_type());
401 auto is_source = [&source](
const auto& findif_source)
402 {
return &findif_source == source; };
404 auto iter = std::find_if (sources.begin(), sources.end(), is_source);
405 if (iter != sources.end())
406 return std::distance (sources.begin(), iter);
408 PWARN (
"couldn't locate source");
422 LEAVE(
"%s supported", source && source->get_supported() ?
"" :
"not ");
423 return source->get_supported();
435 LEAVE(
"user name %s", source->get_user_name());
436 return source->get_user_name();
448 LEAVE(
"internal name %s", source->get_internal_name());
449 return source->get_internal_name();
461 const std::vector<std::string>& sources_list)
465 if (sources_list.empty())
469 fq_version = version_string;
473 for (
const auto& source_name_str : sources_list)
475 auto source_name = source_name_str.c_str();
480 DEBUG(
"Found source %s: %s", source_name, source->get_user_name());
481 source->set_supported (
true);
495 gnc_commodity_begin_edit (gnc_commodity *cm)
502 PERR (
"Failed to commit: %d", errcode);
503 gnc_engine_signal_commit_error( errcode );
511 commodity_free( GNC_COMMODITY(inst) );
515 gnc_commodity_commit_edit (gnc_commodity *cm)
526 mark_commodity_dirty (gnc_commodity *cm)
528 qof_instance_set_dirty(&cm->inst);
535 g_free(priv->printname);
536 priv->printname = g_strdup_printf(
"%s (%s)",
537 priv->mnemonic ? priv->mnemonic :
"",
538 priv->fullname ? priv->fullname :
"");
544 gnc_commodity_namespace *ns;
546 g_free(priv->unique_name);
547 ns = priv->name_space;
548 priv->unique_name = g_strdup_printf(
"%s::%s",
550 priv->mnemonic ? priv->mnemonic :
"");
554 G_DEFINE_TYPE_WITH_PRIVATE(gnc_commodity, gnc_commodity, QOF_TYPE_INSTANCE)
557 gnc_commodity_init(gnc_commodity* com)
561 priv = GET_PRIVATE(com);
563 priv->name_space =
nullptr;
564 priv->fullname = CACHE_INSERT(
"");
565 priv->mnemonic = CACHE_INSERT(
"");
566 priv->cusip = CACHE_INSERT(
"");
567 priv->fraction = 10000;
568 priv->quote_flag = 0;
569 priv->quote_source =
nullptr;
570 priv->quote_tz = CACHE_INSERT(
"");
572 reset_printname(priv);
573 reset_unique_name(priv);
577 gnc_commodity_dispose(GObject *comp)
579 G_OBJECT_CLASS(gnc_commodity_parent_class)->dispose(comp);
583 gnc_commodity_finalize(GObject* comp)
585 G_OBJECT_CLASS(gnc_commodity_parent_class)->finalize(comp);
594 gnc_commodity_get_property (GObject *
object,
599 gnc_commodity *commodity;
602 g_return_if_fail(GNC_IS_COMMODITY(
object));
604 commodity = GNC_COMMODITY(
object);
605 priv = GET_PRIVATE(commodity);
609 g_value_take_object(value, priv->name_space);
612 g_value_set_string(value, priv->fullname);
615 g_value_set_string(value, priv->mnemonic);
618 g_value_set_string(value, priv->printname);
621 g_value_set_string(value, priv->cusip);
624 g_value_set_int(value, priv->fraction);
626 case PROP_UNIQUE_NAME:
627 g_value_set_string(value, priv->unique_name);
629 case PROP_QUOTE_FLAG:
630 g_value_set_boolean(value, priv->quote_flag);
632 case PROP_QUOTE_SOURCE:
633 g_value_set_pointer(value, priv->quote_source);
636 g_value_set_string(value, priv->quote_tz);
639 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
645 gnc_commodity_set_property (GObject *
object,
650 gnc_commodity *commodity;
652 g_return_if_fail(GNC_IS_COMMODITY(
object));
654 commodity = GNC_COMMODITY(
object);
655 g_assert (qof_instance_get_editlevel(commodity));
674 case PROP_QUOTE_FLAG:
677 case PROP_QUOTE_SOURCE:
684 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
691 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
693 gobject_class->dispose = gnc_commodity_dispose;
694 gobject_class->finalize = gnc_commodity_finalize;
695 gobject_class->set_property = gnc_commodity_set_property;
696 gobject_class->get_property = gnc_commodity_get_property;
698 g_object_class_install_property(gobject_class,
700 g_param_spec_object (
"namespace",
702 "The namespace field denotes the " 703 "namespace for this commodity, either " 704 "a currency or symbol from a quote source.",
705 GNC_TYPE_COMMODITY_NAMESPACE,
707 g_object_class_install_property(gobject_class,
709 g_param_spec_string (
"fullname",
710 "Full Commodity Name",
711 "The fullname is the official full name of" 715 g_object_class_install_property(gobject_class,
717 g_param_spec_string (
"mnemonic",
718 "Commodity Mnemonic",
719 "The mnemonic is the official abbreviated" 720 "designation for the currency.",
723 g_object_class_install_property(gobject_class,
725 g_param_spec_string (
"printname",
726 "Commodity Print Name",
727 "Printable form of the commodity name.",
730 g_object_class_install_property(gobject_class,
732 g_param_spec_string (
"cusip",
733 "Commodity CUSIP Code",
737 g_object_class_install_property(gobject_class,
739 g_param_spec_int (
"fraction",
741 "The fraction is the number of sub-units that " 742 "the basic commodity can be divided into.",
747 g_object_class_install_property(gobject_class,
749 g_param_spec_string (
"unique-name",
750 "Commodity Unique Name",
751 "Unique form of the commodity name which combines " 752 "the namespace name and the commodity name.",
755 g_object_class_install_property(gobject_class,
757 g_param_spec_boolean (
"quote_flag",
759 "TRUE if prices are to be downloaded for this " 760 "commodity from a quote source.",
763 g_object_class_install_property(gobject_class,
765 g_param_spec_pointer(
"quote-source",
767 "The quote source from which prices are downloaded.",
769 g_object_class_install_property(gobject_class,
771 g_param_spec_string (
"quote-tz",
772 "Commodity Quote Timezone",
780 const char * name_space,
const char * mnemonic,
781 const char * cusip,
int fraction)
783 auto retval = GNC_COMMODITY(g_object_new(GNC_TYPE_COMMODITY,
nullptr));
786 gnc_commodity_begin_edit(retval);
788 if ( name_space !=
nullptr )
791 if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
792 g_strcmp0 (mnemonic,
"template") != 0)
794 PWARN(
"Converting commodity %s from namespace template to " 795 "namespace User", mnemonic);
809 mark_commodity_dirty (retval);
810 gnc_commodity_commit_edit(retval);
823 commodity_free(gnc_commodity * cm)
826 gnc_commodity_table *
table;
834 priv = GET_PRIVATE(cm);
839 CACHE_REMOVE (priv->fullname);
840 CACHE_REMOVE (priv->cusip);
841 CACHE_REMOVE (priv->mnemonic);
842 CACHE_REMOVE (priv->quote_tz);
843 priv->name_space =
nullptr;
846 priv->quote_source =
nullptr;
849 g_free(priv->printname);
850 priv->printname =
nullptr;
852 g_free(priv->unique_name);
853 priv->unique_name =
nullptr;
855 #ifdef ACCOUNTS_CLEANED_UP 860 if (priv->usage_count != 0)
862 PWARN(
"Destroying commodity (%p) with non-zero usage_count (%d).", cm,
874 gnc_commodity_begin_edit(cm);
875 qof_instance_set_destroying(cm, TRUE);
876 gnc_commodity_commit_edit(cm);
887 dest_priv->name_space = src_priv->name_space;
893 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
902 auto dest = GNC_COMMODITY (g_object_new(GNC_TYPE_COMMODITY,
nullptr));
904 src_priv = GET_PRIVATE(src);
905 dest_priv = GET_PRIVATE(dest);
907 dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
908 dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
909 dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
910 dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
912 dest_priv->name_space = src_priv->name_space;
914 dest_priv->fraction = src_priv->fraction;
915 dest_priv->quote_flag = src_priv->quote_flag;
919 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
921 reset_printname(dest_priv);
922 reset_unique_name(dest_priv);
934 if (!cm)
return nullptr;
935 return GET_PRIVATE(cm)->mnemonic;
945 if (!cm)
return nullptr;
946 return GET_PRIVATE(cm)->printname;
957 if (!cm)
return nullptr;
961 gnc_commodity_namespace *
964 if (!cm)
return nullptr;
965 return GET_PRIVATE(cm)->name_space;
975 if (!cm)
return nullptr;
976 return GET_PRIVATE(cm)->fullname;
987 if (!cm)
return nullptr;
988 return GET_PRIVATE(cm)->unique_name;
999 if (!cm)
return nullptr;
1000 return GET_PRIVATE(cm)->cusip;
1011 return GET_PRIVATE(cm)->fraction;
1019 gnc_commodity_get_auto_quote_control_flag(
const gnc_commodity *cm)
1021 GValue v = G_VALUE_INIT;
1022 gboolean retval = TRUE;
1024 if (!cm)
return FALSE;
1026 if (G_VALUE_HOLDS_STRING (&v) &&
1027 strcmp(g_value_get_string (&v),
"false") == 0)
1040 if (!cm)
return FALSE;
1041 return (GET_PRIVATE(cm)->quote_flag);
1053 if (!cm)
return nullptr;
1054 priv = GET_PRIVATE(cm);
1056 return ¤cy_quote_sources.front();
1057 return priv->quote_source;
1061 gnc_commodity_get_default_quote_source(
const gnc_commodity *cm)
1064 return ¤cy_quote_sources.front();
1076 if (!cm)
return nullptr;
1077 return GET_PRIVATE(cm)->quote_tz;
1086 g_return_val_if_fail (GNC_IS_COMMODITY (cm),
nullptr);
1088 GValue v = G_VALUE_INIT;
1090 const char *rv = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) :
nullptr;
1101 if (!cm)
return nullptr;
1102 return GET_PRIVATE(cm)->default_symbol;
1111 const char *nice_symbol;
1113 if (!cm)
return nullptr;
1116 if (nice_symbol && *nice_symbol)
1119 lc = gnc_localeconv();
1120 nice_symbol = lc->currency_symbol;
1125 if (nice_symbol && *nice_symbol)
1141 priv = GET_PRIVATE(cm);
1142 if (priv->mnemonic == mnemonic)
return;
1144 gnc_commodity_begin_edit(cm);
1145 CACHE_REMOVE (priv->mnemonic);
1146 priv->mnemonic = CACHE_INSERT(mnemonic);
1148 mark_commodity_dirty (cm);
1149 reset_printname(priv);
1150 reset_unique_name(priv);
1151 gnc_commodity_commit_edit(cm);
1162 gnc_commodity_table *
table;
1163 gnc_commodity_namespace *nsp;
1167 priv = GET_PRIVATE(cm);
1171 if (priv->name_space == nsp)
1174 gnc_commodity_begin_edit(cm);
1175 priv->name_space = nsp;
1178 mark_commodity_dirty(cm);
1179 reset_printname(priv);
1180 reset_unique_name(priv);
1181 gnc_commodity_commit_edit(cm);
1194 priv = GET_PRIVATE(cm);
1195 if (priv->fullname == fullname)
return;
1197 CACHE_REMOVE (priv->fullname);
1198 priv->fullname = CACHE_INSERT (fullname);
1200 gnc_commodity_begin_edit(cm);
1201 mark_commodity_dirty(cm);
1202 reset_printname(priv);
1203 gnc_commodity_commit_edit(cm);
1218 priv = GET_PRIVATE(cm);
1219 if (priv->cusip == cusip)
return;
1221 gnc_commodity_begin_edit(cm);
1222 CACHE_REMOVE (priv->cusip);
1223 priv->cusip = CACHE_INSERT (cusip);
1224 mark_commodity_dirty(cm);
1225 gnc_commodity_commit_edit(cm);
1236 gnc_commodity_begin_edit(cm);
1237 GET_PRIVATE(cm)->fraction = fraction;
1238 mark_commodity_dirty(cm);
1239 gnc_commodity_commit_edit(cm);
1247 gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
1248 const gboolean flag)
1250 GValue v = G_VALUE_INIT;
1251 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1258 gnc_commodity_begin_edit(cm);
1263 g_value_init (&v, G_TYPE_STRING);
1264 g_value_set_string (&v,
"false");
1268 mark_commodity_dirty(cm);
1269 gnc_commodity_commit_edit(cm);
1282 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1290 priv = GET_PRIVATE(cm);
1291 gnc_commodity_begin_edit(cm);
1302 gnc_commodity_set_auto_quote_control_flag(cm,
1303 (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1305 gnc_commodity_commit_edit(cm);
1316 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1319 gnc_commodity_begin_edit(cm);
1320 GET_PRIVATE(cm)->quote_flag = flag;
1321 mark_commodity_dirty(cm);
1322 gnc_commodity_commit_edit(cm);
1333 ENTER (
"(cm=%p, src=%p(%s))", cm, src, src ? src->get_internal_name() :
"unknown");
1336 gnc_commodity_begin_edit(cm);
1337 GET_PRIVATE(cm)->quote_source = src;
1338 mark_commodity_dirty(cm);
1339 gnc_commodity_commit_edit(cm);
1354 ENTER (
"(cm=%p, tz=%s)", cm, tz ? tz :
"(null)");
1356 priv = GET_PRIVATE(cm);
1358 if (tz == priv->quote_tz)
1360 LEAVE(
"Already correct TZ");
1364 gnc_commodity_begin_edit(cm);
1365 CACHE_REMOVE (priv->quote_tz);
1366 priv->quote_tz = CACHE_INSERT (tz);
1367 mark_commodity_dirty(cm);
1368 gnc_commodity_commit_edit(cm);
1383 ENTER (
"(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol :
"(null)");
1385 lc = gnc_localeconv();
1386 if (!user_symbol || !*user_symbol)
1387 user_symbol =
nullptr;
1389 !g_strcmp0(lc->currency_symbol, user_symbol))
1392 user_symbol =
nullptr;
1394 user_symbol =
nullptr;
1396 gnc_commodity_begin_edit (cm);
1400 GValue v = G_VALUE_INIT;
1401 g_value_init (&v, G_TYPE_STRING);
1402 g_value_set_static_string (&v, user_symbol);
1411 mark_commodity_dirty(cm);
1412 gnc_commodity_commit_edit(cm);
1423 gnc_commodity_set_default_symbol(gnc_commodity * cm,
1424 const char * default_symbol)
1426 GET_PRIVATE(cm)->default_symbol = default_symbol;
1438 ENTER(
"(cm=%p)", cm);
1446 priv = GET_PRIVATE(cm);
1448 if ((priv->usage_count == 0) && !priv->quote_flag
1449 && gnc_commodity_get_auto_quote_control_flag(cm)
1454 gnc_commodity_begin_edit(cm);
1457 gnc_commodity_get_default_quote_source(cm));
1458 gnc_commodity_commit_edit(cm);
1460 priv->usage_count++;
1461 LEAVE(
"(usage_count=%d)", priv->usage_count);
1473 ENTER(
"(cm=%p)", cm);
1481 priv = GET_PRIVATE(cm);
1483 if (priv->usage_count == 0)
1485 PWARN(
"usage_count already zero");
1490 priv->usage_count--;
1491 if ((priv->usage_count == 0) && priv->quote_flag
1492 && gnc_commodity_get_auto_quote_control_flag(cm)
1499 LEAVE(
"(usage_count=%d)", priv->usage_count);
1517 if (a == b)
return TRUE;
1518 if (!a || !b)
return FALSE;
1520 priv_a = GET_PRIVATE(a);
1521 priv_b = GET_PRIVATE(b);
1522 if (priv_a->name_space != priv_b->name_space)
return FALSE;
1523 if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
return FALSE;
1538 if (a == b)
return 0;
1539 if (a && !b)
return 1;
1540 if (b && !a)
return -1;
1567 if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
1568 return GNC_COMMODITY_NS_ISO_GUI;
1578 return g_list_copy (name_space->cm_list);
1584 return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1585 (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1588 static const gchar *
1589 gnc_commodity_table_map_namespace(
const char * name_space)
1591 if (g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0)
1592 return GNC_COMMODITY_NS_CURRENCY;
1601 gnc_commodity_table *
1604 gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1605 retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1606 retval->ns_list =
nullptr;
1614 gnc_commodity_table *
1617 if (!book)
return nullptr;
1618 return static_cast<gnc_commodity_table*
>(
qof_book_get_data (book, GNC_COMMODITY_TABLE));
1624 gnc_commodity *twin;
1626 gnc_commodity_table * comtbl;
1628 if (!from)
return nullptr;
1630 if (!comtbl)
return nullptr;
1633 twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1648 count_coms(gpointer key, gpointer value, gpointer user_data)
1650 GHashTable *tbl = ((gnc_commodity_namespace*)value)->cm_table;
1651 guint *count = (guint*)user_data;
1653 if (g_strcmp0((
char*)key, GNC_COMMODITY_NS_CURRENCY) == 0)
1661 *count += g_hash_table_size(tbl);
1668 g_return_val_if_fail(tbl, 0);
1669 g_return_val_if_fail(tbl->ns_table, 0);
1671 g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1682 gnc_commodity_table_lookup(
const gnc_commodity_table *
table,
1683 const char * name_space,
const char * mnemonic)
1685 gnc_commodity_namespace * nsp =
nullptr;
1687 if (!
table || !name_space || !mnemonic)
return nullptr;
1699 auto it = gnc_new_iso_codes.find (mnemonic);
1700 if (it != gnc_new_iso_codes.end())
1701 mnemonic = it->second.c_str();
1703 return GNC_COMMODITY(g_hash_table_lookup(nsp->cm_table, (gpointer)mnemonic));
1717 gnc_commodity_table_lookup_unique(
const gnc_commodity_table *
table,
1718 const char * unique_name)
1722 gnc_commodity *commodity;
1724 if (!
table || !unique_name)
return nullptr;
1726 name_space = g_strdup (unique_name);
1727 mnemonic = strstr (name_space,
"::");
1730 g_free (name_space);
1737 commodity = gnc_commodity_table_lookup (
table, name_space, mnemonic);
1739 g_free (name_space);
1750 gnc_commodity_table_find_full(
const gnc_commodity_table *
table,
1751 const char * name_space,
1752 const char * fullname)
1754 gnc_commodity * retval =
nullptr;
1758 if (!fullname || (fullname[0] ==
'\0'))
1763 for (iterator = all; iterator; iterator = iterator->next)
1765 auto commodity = GNC_COMMODITY (iterator->data);
1766 if (!strcmp(fullname,
1787 gnc_commodity * comm)
1789 gnc_commodity_namespace * nsp =
nullptr;
1791 const char *ns_name;
1795 if (!
table)
return nullptr;
1796 if (!comm)
return nullptr;
1798 priv = GET_PRIVATE(comm);
1800 ENTER (
"(table=%p, comm=%p) %s %s",
table, comm,
1801 (priv->mnemonic ==
nullptr ?
"(null)" : priv->mnemonic),
1802 (priv->fullname ==
nullptr ?
"(null)" : priv->fullname));
1804 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1810 LEAVE(
"already in table");
1816 if (priv->name_space->iso4217)
1818 auto it = gnc_new_iso_codes.find (priv->mnemonic);
1819 if (it != gnc_new_iso_codes.end())
1824 LEAVE(
"found at %p", c);
1829 if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
1830 g_strcmp0 (priv->mnemonic,
"template") != 0)
1832 PWARN(
"Converting commodity %s from namespace template to " 1833 "namespace User", priv->mnemonic);
1836 mark_commodity_dirty (comm);
1842 PINFO (
"insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1843 nsp->cm_table, nsp->name);
1844 g_hash_table_insert(nsp->cm_table,
1845 (gpointer)CACHE_INSERT(priv->mnemonic),
1847 nsp->cm_list = g_list_append(nsp->cm_list, comm);
1861 gnc_commodity * comm)
1863 gnc_commodity_namespace * nsp;
1866 const char *ns_name;
1871 priv = GET_PRIVATE(comm);
1873 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1874 if (c != comm)
return;
1881 nsp->cm_list = g_list_remove(nsp->cm_list, comm);
1882 g_hash_table_remove (nsp->cm_table, priv->mnemonic);
1893 const char * name_space)
1895 gnc_commodity_namespace * nsp =
nullptr;
1897 if (!
table || !name_space)
1914 hash_keys_helper(gpointer key, gpointer value, gpointer data)
1916 auto l = (GList**)data;
1917 *l = g_list_prepend(*l, key);
1921 g_hash_table_keys(GHashTable *
table)
1923 GList * l =
nullptr;
1924 g_hash_table_foreach(
table, &hash_keys_helper, (gpointer) &l);
1929 hash_values_helper(gpointer key, gpointer value, gpointer data)
1931 auto l = (GList**)data;
1932 *l = g_list_prepend(*l, value);
1936 g_hash_table_values(GHashTable *
table)
1938 GList * l =
nullptr;
1939 g_hash_table_foreach(
table, &hash_values_helper, (gpointer) &l);
1954 return g_hash_table_keys(
table->ns_table);
1963 return g_list_copy (
table->ns_list);
1977 if (!cm)
return FALSE;
1979 priv = GET_PRIVATE(cm);
1980 if ( !priv->name_space)
return FALSE;
1981 return priv->name_space->iso4217;
1987 const char *ns_name;
1988 if (!cm)
return FALSE;
1992 !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
2000 static CommodityList*
2001 commodity_table_get_all_noncurrency_commodities(
const gnc_commodity_table*
table)
2004 CommodityList *retval =
nullptr;
2005 for (node = nslist; node; node=g_list_next(node))
2007 gnc_commodity_namespace *ns =
nullptr;
2008 if (g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_CURRENCY) == 0
2009 || g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_TEMPLATE) == 0)
2014 retval = g_list_concat(g_hash_table_values(ns->cm_table), retval);
2016 g_list_free(nslist);
2022 const char * name_space)
2024 gnc_commodity_namespace * ns =
nullptr;
2028 if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONISO_GUI) == 0)
2029 return commodity_table_get_all_noncurrency_commodities(
table);
2034 return g_hash_table_values(ns->cm_table);
2043 get_quotables_helper1(gpointer key, gpointer value, gpointer data)
2045 auto comm = GNC_COMMODITY(value);
2047 auto l =
static_cast<GList**
>(data);
2049 if (!priv->quote_flag || !priv->quote_source || !priv->quote_source->get_supported())
2051 *l = g_list_prepend(*l, value);
2055 get_quotables_helper2 (gnc_commodity *comm, gpointer data)
2057 auto l =
static_cast<GList**
>(data);
2060 if (!priv->quote_flag || priv->quote_source || !priv->quote_source->get_supported())
2062 *l = g_list_prepend(*l, comm);
2069 gnc_commodity_namespace * ns =
nullptr;
2070 const char *name_space;
2071 GList * nslist, * tmp;
2072 GList * l =
nullptr;
2074 const char *expression = gnc_prefs_get_namespace_regexp();
2076 ENTER(
"table=%p, expression=%s",
table, expression);
2080 if (expression && *expression)
2082 if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2084 LEAVE(
"Cannot compile regex");
2089 for (tmp = nslist; tmp; tmp = tmp->next)
2091 name_space =
static_cast<const char*
>(tmp->data);
2092 if (regexec(&pattern, name_space, 0,
nullptr, 0) == 0)
2094 DEBUG(
"Running list of %s commodities", name_space);
2098 g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2102 g_list_free(nslist);
2110 LEAVE(
"list head %p", l);
2120 QOF_GOBJECT_IMPL(gnc_commodity_namespace, gnc_commodity_namespace, QOF_TYPE_INSTANCE)
2123 gnc_commodity_namespace_init(gnc_commodity_namespace* ns)
2128 gnc_commodity_namespace_dispose_real (GObject *nsp)
2133 gnc_commodity_namespace_finalize_real(GObject* nsp)
2137 gnc_commodity_namespace *
2139 const char * name_space,
2142 gnc_commodity_namespace * ns =
nullptr;
2144 if (!
table)
return nullptr;
2146 name_space = gnc_commodity_table_map_namespace(name_space);
2150 ns =
static_cast<gnc_commodity_namespace*
>(g_object_new(GNC_TYPE_COMMODITY_NAMESPACE,
nullptr));
2151 ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2152 ns->name = CACHE_INSERT(static_cast<const char*>(name_space));
2157 g_hash_table_insert(
table->ns_table,
2158 (gpointer) ns->name,
2160 table->ns_list = g_list_append(
table->ns_list, ns);
2167 gnc_commodity_namespace *
2169 const char * name_space)
2171 if (!
table || !name_space)
2174 name_space = gnc_commodity_table_map_namespace(name_space);
2175 return static_cast<gnc_commodity_namespace*
>(g_hash_table_lookup(
table->ns_table, (gpointer)name_space));
2180 gnc_commodity_find_commodity_by_guid(
const GncGUID *guid, QofBook *book)
2183 if (!guid || !book)
return nullptr;
2194 ns_helper(gpointer key, gpointer value, gpointer user_data)
2196 auto c = GNC_COMMODITY(value);
2198 CACHE_REMOVE(static_cast<char*>(key));
2204 const char * name_space)
2206 gnc_commodity_namespace * ns;
2215 g_hash_table_remove(
table->ns_table, name_space);
2216 table->ns_list = g_list_remove(
table->ns_list, ns);
2218 g_list_free(ns->cm_list);
2219 ns->cm_list =
nullptr;
2221 g_hash_table_foreach_remove(ns->cm_table, ns_helper,
nullptr);
2222 g_hash_table_destroy(ns->cm_table);
2223 CACHE_REMOVE(ns->name);
2239 gboolean (*func)(gnc_commodity *, gpointer);
2244 iter_commodity (gpointer key, gpointer value, gpointer user_data)
2247 gnc_commodity *cm = (gnc_commodity *) value;
2251 iter_data->ok = (iter_data->func)(cm, iter_data->user_data);
2256 iter_namespace (gpointer key, gpointer value, gpointer user_data)
2258 GHashTable *namespace_hash = ((gnc_commodity_namespace *) value)->cm_table;
2259 g_hash_table_foreach (namespace_hash, iter_commodity, user_data);
2264 gboolean (*f)(gnc_commodity *, gpointer),
2269 if (!tbl || !f)
return FALSE;
2271 iter_data.ok = TRUE;
2273 iter_data.user_data = user_data;
2275 g_hash_table_foreach(tbl->ns_table, iter_namespace, (gpointer)&iter_data);
2277 return iter_data.ok;
2286 gnc_commodity_table_destroy(gnc_commodity_table * t)
2288 gnc_commodity_namespace * ns;
2292 ENTER (
"table=%p", t);
2294 for (item = t->ns_list; item; item = next)
2296 next = g_list_next(item);
2297 ns =
static_cast<gnc_commodity_namespace*
>(item->data);
2301 g_list_free(t->ns_list);
2302 t->ns_list =
nullptr;
2303 g_hash_table_destroy(t->ns_table);
2304 t->ns_table =
nullptr;
2305 LEAVE (
"table=%p", t);
2315 #define CUR_I18N(String) dgettext ("iso_4217", String) 2325 c =
gnc_commodity_new(book,
"template", GNC_COMMODITY_NS_TEMPLATE,
"template",
"template", 1);
2328 #include "iso-4217-currencies.c" 2353 static QofObject commodity_object_def =
2356 DI(.e_type = ) GNC_ID_COMMODITY,
2357 DI(.type_label = ) "Commodity",
2358 DI(.create = )
nullptr,
2359 DI(.book_begin = )
nullptr,
2360 DI(.book_end = )
nullptr,
2363 DI(.foreach = ) qof_collection_foreach,
2367 static QofObject namespace_object_def =
2370 DI(.e_type = ) GNC_ID_COMMODITY_NAMESPACE,
2371 DI(.type_label = ) "Namespace",
2372 DI(.create = )
nullptr,
2373 DI(.book_begin = )
nullptr,
2374 DI(.book_end = )
nullptr,
2375 DI(.is_dirty = )
nullptr,
2376 DI(.mark_clean = )
nullptr,
2377 DI(.foreach = )
nullptr,
2378 DI(.printable = )
nullptr,
2382 commodity_table_book_begin (QofBook *book)
2384 gnc_commodity_table *ct;
2385 ENTER (
"book=%p", book);
2395 PWARN(
"unable to initialize book's commodity_table");
2398 LEAVE (
"book=%p", book);
2402 commodity_table_book_end (QofBook *book)
2404 gnc_commodity_table *ct;
2408 gnc_commodity_table_destroy (ct);
2411 static QofObject commodity_table_object_def =
2414 DI(.e_type = ) GNC_ID_COMMODITY_TABLE,
2415 DI(.type_label = ) "CommodityTable",
2416 DI(.create = )
nullptr,
2417 DI(.book_begin = ) commodity_table_book_begin,
2418 DI(.book_end = ) commodity_table_book_end,
2421 DI(.foreach = )
nullptr,
2422 DI(.printable = )
nullptr,
2423 DI(.version_cmp = )
nullptr,
2444 MonetaryList *l = list, *tmp;
2445 for (tmp = list; tmp; tmp = tmp->next)
2447 auto list_mon =
static_cast<gnc_monetary*
>(tmp->data);
2459 auto new_mon =
static_cast<gnc_monetary*
>(g_new0(gnc_monetary, 1));
2461 l = g_list_prepend(l, new_mon);
2472 MonetaryList *node, *next;
2473 for (node = list; node; node = next)
2475 auto mon =
static_cast<gnc_monetary*
>(node->data);
2480 list = g_list_delete_link(list, node);
2491 for (tmp = list; tmp; tmp = tmp->next)
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_cusip(const gnc_commodity *cm)
Retrieve the 'exchange code' for the specified commodity.
gboolean gnc_commodity_table_foreach_commodity(const gnc_commodity_table *table, gboolean(*f)(gnc_commodity *cm, gpointer user_data), gpointer user_data)
Call a function once for each commodity in the commodity table.
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
A gnc_commodity_table is a database of commodity info.
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...
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
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_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...
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
#define GNC_COMMODITY_MAX_FRACTION
Max fraction is 10^9 because 10^10 would require changing it to an int64_t.
This quote source pulls from a single specific web site.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gboolean qof_collection_is_dirty(const QofCollection *col)
Return value of 'dirty' flag on collection.
gnc_quote_source * gnc_quote_source_add_new(const char *source_name, gboolean supported)
Create a new quote source.
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...
QofInstance * qof_collection_lookup_entity(const QofCollection *col, const GncGUID *guid)
Find the entity going only from its guid.
#define PINFO(format, args...)
Print an informational note.
gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm)
Retrieve the automatic price quote flag for the specified commodity.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
const char * gnc_commodity_get_user_symbol(const gnc_commodity *cm)
Retrieve the user-defined symbol for the specified commodity.
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
Set the automatic price quote timezone 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...
Commodity handling public routines (C++ api)
const char * gnc_commodity_get_quote_tz(const gnc_commodity *cm)
Retrieve the automatic price quote timezone for the specified commodity.
#define DEBUG(format, args...)
Print a debugging message.
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
Set the fraction for the specified commodity.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
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...
globally unique ID User API
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Return a+b.
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...
The special currency quote source.
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...
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
Object instance holds common fields that most gnucash objects use.
gnc_commodity * gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
allocate and copy
This is a locally installed quote source that gnucash knows nothing about.
const char * gnc_commodity_get_namespace(const gnc_commodity *cm)
Retrieve the namespace for the specified commodity.
Use any denominator which gives an exactly correct ratio of numerator to denominator.
A gnc_commodity_namespace is an collection of commodities.
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity.
#define QOF_OBJECT_VERSION
Defines the version of the core object object registration interface.
QuoteSourceType
The quote source type enum account types are used to determine how the transaction data in the accoun...
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...
gboolean qof_commit_edit(QofInstance *inst)
commit_edit helpers
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
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.
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.
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 qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.
void gnc_commodity_set_user_symbol(gnc_commodity *cm, const char *user_symbol)
Set a user-defined symbol for the specified commodity.
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure.
#define PWARN(format, args...)
Log a warning.
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
MonetaryList * gnc_monetary_list_delete_zeros(MonetaryList *list)
Delete all entries in the list that have zero value.
gboolean qof_begin_edit(QofInstance *inst)
begin_edit
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
gint gnc_quote_source_num_entries(QuoteSourceType type)
Return the number of entries for a given type of quote source.
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
Return a list of all namespaces in the commodity table.
gboolean gnc_commodity_table_register(void)
You should probably not be using gnc_commodity_table_register() It is an internal routine for registe...
void gnc_commodity_increment_usage_count(gnc_commodity *cm)
Increment a commodity's internal counter that tracks how many accounts are using that commodity...
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
Set the 'exchange code' for the specified commodity.
void gnc_monetary_list_free(MonetaryList *list)
Free a MonetaryList and all the monetaries it points to.
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.
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.
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.
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.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
#define GNC_COMMODITY_NS_LEGACY
The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the excha...
void qof_book_set_data(QofBook *book, const gchar *key, gpointer data)
The qof_book_set_data() allows arbitrary pointers to structs to be stored in QofBook.
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
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 qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
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.
const char * gnc_quote_source_fq_version(void)
This function returns the version of the Finance::Quote module installed on a user's computer...
Generic api to store and retrieve preferences.
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.
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...
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name 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.
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
Set the full name for the specified commodity.
This quote source may pull from multiple web sites.
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
Retrieve the automatic price quote source 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_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
Set the mnemonic for the specified commodity.
const char * gnc_commodity_get_default_symbol(const gnc_commodity *cm)
Retrieve the default symbol for the specified commodity.
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
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.
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...
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_commodity_namespace * gnc_commodity_get_namespace_ds(const gnc_commodity *cm)
Retrieve the namespace data structure for the specified commodity.
#define LEAVE(format, args...)
Print a function exit debugging message.
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the 'unique' name for the specified commodity.
MonetaryList * gnc_monetary_list_add_monetary(MonetaryList *list, gnc_monetary add_mon)
Add a gnc_monetary to the list.
void gnc_commodity_table_remove(gnc_commodity_table *table, gnc_commodity *comm)
Remove a commodity from the commodity table.
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
Set the namespace for the specified commodity.
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
guint gnc_commodity_table_get_size(const gnc_commodity_table *tbl)
Returns the number of commodities in the commodity table.
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.
gboolean qof_object_register(const QofObject *object)
Register new types of object objects.
An article that is bought and sold.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
#define GNC_DENOM_AUTO
Values that can be passed as the 'denom' argument.
The type used to store guids in C.
void gnc_commodity_copy(gnc_commodity *dest, const gnc_commodity *src)
Copy src into dest.
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
Retrieves arbitrary pointers to structs stored by qof_book_set_data.
GList * gnc_commodity_table_get_namespaces_list(const gnc_commodity_table *table)
Return a list of all namespace data structures in the commodity table.
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...
Commodity handling public routines.
void gnc_commodity_destroy(gnc_commodity *cm)
Destroy a commodity.
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_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.
gboolean gnc_quote_source_fq_installed(void)
This function indicates whether or not the Finance::Quote module is installed on a user's computer...