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",
"DWS, DE"),
"dwsfunds" },
205 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Financial Times Funds service, GB"),
"ftfunds" },
206 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Finanzpartner, DE"),
"finanzpartner" },
207 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"FondsWeb, DE"),
"fondsweb" },
208 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"GoldMoney precious metals"),
"goldmoney" },
209 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Google Web, US Stocks"),
"googleweb" },
210 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"IEX (Investors Exchange), US"),
"iexcloud" },
211 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Market Watch"),
"marketwatch" },
212 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, AU"),
"morningstarau" },
213 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, CH"),
"morningstarch" },
214 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, GB"),
"morningstaruk" },
215 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Morningstar, JP"),
"morningstarjp" },
216 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Motley Fool"),
"fool" },
217 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"New Zealand stock eXchange, NZ"),
"nzx" },
218 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"NSE (National Stock Exchange), IN"),
"nseindia" },
219 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"OnVista, DE"),
"onvista"},
220 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Paris Stock Exchange/Boursorama, FR"),
"bourso" },
221 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"S-Investor, DE"),
"sinvestor"},
222 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Sharenet, ZA"),
"za" },
223 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"SIX Swiss Exchange shares, CH"),
"six" },
224 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Skandinaviska Enskilda Banken, SE"),
"seb_funds" },
225 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"StockData"),
"stockdata" },
226 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Stooq, PL"),
"stooq" },
227 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"T. Rowe Price, US"),
"troweprice" },
228 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Tesouro Direto bonds, BR"),
"tesouro_direto" },
229 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"TIAA-CREF, US"),
"tiaacref" },
230 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Toronto Stock eXchange, CA"),
"tsx" },
231 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Tradegate, DE"),
"tradegate" },
232 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Treasury Direct bonds, US"),
"treasurydirect" },
233 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Twelve Data"),
"twelvedata" },
234 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Union Investment, DE"),
"unionfunds" },
235 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"US Govt. Thrift Savings Plan"),
"tsp" },
236 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"XETRA, DE"),
"xetra" },
237 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Yahoo as JSON"),
"yahoo_json" },
238 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"Yahoo Web"),
"yahooweb" },
239 {
false,
SOURCE_SINGLE, NC_(
"FQ Source",
"YH Finance (FinanceAPI)"),
"financeapi" },
242 static QuoteSourceList multiple_quote_sources =
244 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Australia (ASX)"),
"australia" },
245 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Australia Funds (MorningstarAU)"),
"aufunds" },
246 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Canada (Alphavantage, TMX)"),
"canada" },
247 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Dutch (AEX)"),
"dutch" },
248 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Europe (ASEGR, Bourso, …)"),
"europe" },
249 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"France (Bourso)"),
"france" },
250 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Greece (ASEGR)"),
"greece" },
251 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"India (BSEIndia, NSEIndia)"),
"india"},
252 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"India Mutual (AMFI)"),
"indiamutual" },
253 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Nasdaq (Alphavantage, FinanceAPI, …)"),
"nasdaq" },
254 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"NYSE (Alphavantage, FinanceAPI, …)"),
"nyse" },
255 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Poland (Stooq)"),
"poland" },
256 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"Romania (BVB)"),
"romania" },
257 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"South Africa (Sharenet)"),
"za" },
258 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"U.K. Funds (FTfunds, MorningstarUK)"),
"ukfunds" },
259 {
false,
SOURCE_MULTI, NC_(
"FQ Source",
"USA (Alphavantage, FinanceAPI, …)"),
"usa" },
262 static QuoteSourceList new_quote_sources;
265 static const std::vector<std::pair<QuoteSourceType,QuoteSourceList&>> quote_sources_map =
282 return (!fq_version.empty());
295 return fq_version.c_str();
298 static QuoteSourceList&
301 auto quote_sources_it = std::find_if (quote_sources_map.begin(), quote_sources_map.end(),
302 [type] (
const auto& qs) {
return type == qs.first; });
304 if (quote_sources_it != quote_sources_map.end())
305 return quote_sources_it->second;
307 PWARN (
"Invalid Quote Source %d, returning new_quote_sources", type);
308 return new_quote_sources;
318 auto source{get_quote_source_from_type(type)};
319 return std::distance(source.begin(), source.end());
335 DEBUG(
"Creating new source %s", (!source_name ?
"(null)" : source_name));
341 return &new_quote_sources.emplace_back (supported,
SOURCE_UNKNOWN, source_name, source_name);
352 ENTER(
"type/index is %d/%d", type, index);
353 auto& sources = get_quote_source_from_type (type);
354 if ((
size_t) index < sources.size())
356 auto it = std::next(sources.begin(), index);
357 LEAVE(
"found %s", it->get_user_name());
371 for (
const auto& [_, sources] : quote_sources_map)
373 auto source_it = std::find_if (sources.begin(), sources.end(),
374 [name] (
const auto& qs)
375 {
return (g_strcmp0(name, qs.get_internal_name()) == 0); });
376 if (source_it != sources.end())
377 return &(*source_it);
380 DEBUG(
"gnc_quote_source_lookup_by_internal: Unknown source %s", name);
399 LEAVE(
"type is %d", source->get_type());
400 return source->get_type();
408 PWARN (
"bad source");
412 auto& sources = get_quote_source_from_type (source->get_type());
413 auto is_source = [&source](
const auto& findif_source)
414 {
return &findif_source == source; };
416 auto iter = std::find_if (sources.begin(), sources.end(), is_source);
417 if (iter != sources.end())
418 return std::distance (sources.begin(), iter);
420 PWARN (
"couldn't locate source");
434 LEAVE(
"%s supported", source && source->get_supported() ?
"" :
"not ");
435 return source->get_supported();
447 LEAVE(
"user name %s", source->get_user_name());
448 return source->get_user_name();
460 LEAVE(
"internal name %s", source->get_internal_name());
461 return source->get_internal_name();
473 const std::vector<std::string>& sources_list)
477 if (sources_list.empty())
481 fq_version = version_string;
485 for (
const auto& source_name_str : sources_list)
487 auto source_name = source_name_str.c_str();
492 DEBUG(
"Found source %s: %s", source_name, source->get_user_name());
493 source->set_supported (
true);
507 gnc_commodity_begin_edit (gnc_commodity *cm)
514 PERR (
"Failed to commit: %d", errcode);
515 gnc_engine_signal_commit_error( errcode );
523 commodity_free( GNC_COMMODITY(inst) );
527 gnc_commodity_commit_edit (gnc_commodity *cm)
538 mark_commodity_dirty (gnc_commodity *cm)
540 qof_instance_set_dirty(&cm->inst);
547 g_free(priv->printname);
548 priv->printname = g_strdup_printf(
"%s (%s)",
549 priv->mnemonic ? priv->mnemonic :
"",
550 priv->fullname ? priv->fullname :
"");
556 gnc_commodity_namespace *ns;
558 g_free(priv->unique_name);
559 ns = priv->name_space;
560 priv->unique_name = g_strdup_printf(
"%s::%s",
562 priv->mnemonic ? priv->mnemonic :
"");
566 G_DEFINE_TYPE_WITH_PRIVATE(gnc_commodity, gnc_commodity, QOF_TYPE_INSTANCE)
569 gnc_commodity_init(gnc_commodity* com)
573 priv = GET_PRIVATE(com);
575 priv->name_space =
nullptr;
576 priv->fullname = CACHE_INSERT(
"");
577 priv->mnemonic = CACHE_INSERT(
"");
578 priv->cusip = CACHE_INSERT(
"");
579 priv->fraction = 10000;
580 priv->quote_flag = 0;
581 priv->quote_source =
nullptr;
582 priv->quote_tz = CACHE_INSERT(
"");
584 reset_printname(priv);
585 reset_unique_name(priv);
589 gnc_commodity_dispose(GObject *comp)
591 G_OBJECT_CLASS(gnc_commodity_parent_class)->dispose(comp);
595 gnc_commodity_finalize(GObject* comp)
597 G_OBJECT_CLASS(gnc_commodity_parent_class)->finalize(comp);
606 gnc_commodity_get_property (GObject *
object,
611 gnc_commodity *commodity;
614 g_return_if_fail(GNC_IS_COMMODITY(
object));
616 commodity = GNC_COMMODITY(
object);
617 priv = GET_PRIVATE(commodity);
621 g_value_take_object(value, priv->name_space);
624 g_value_set_string(value, priv->fullname);
627 g_value_set_string(value, priv->mnemonic);
630 g_value_set_string(value, priv->printname);
633 g_value_set_string(value, priv->cusip);
636 g_value_set_int(value, priv->fraction);
638 case PROP_UNIQUE_NAME:
639 g_value_set_string(value, priv->unique_name);
641 case PROP_QUOTE_FLAG:
642 g_value_set_boolean(value, priv->quote_flag);
644 case PROP_QUOTE_SOURCE:
645 g_value_set_pointer(value, priv->quote_source);
648 g_value_set_string(value, priv->quote_tz);
651 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
657 gnc_commodity_set_property (GObject *
object,
662 gnc_commodity *commodity;
664 g_return_if_fail(GNC_IS_COMMODITY(
object));
666 commodity = GNC_COMMODITY(
object);
667 g_assert (qof_instance_get_editlevel(commodity));
686 case PROP_QUOTE_FLAG:
689 case PROP_QUOTE_SOURCE:
696 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
703 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
705 gobject_class->dispose = gnc_commodity_dispose;
706 gobject_class->finalize = gnc_commodity_finalize;
707 gobject_class->set_property = gnc_commodity_set_property;
708 gobject_class->get_property = gnc_commodity_get_property;
710 g_object_class_install_property(gobject_class,
712 g_param_spec_object (
"namespace",
714 "The namespace field denotes the " 715 "namespace for this commodity, either " 716 "a currency or symbol from a quote source.",
717 GNC_TYPE_COMMODITY_NAMESPACE,
719 g_object_class_install_property(gobject_class,
721 g_param_spec_string (
"fullname",
722 "Full Commodity Name",
723 "The fullname is the official full name of" 727 g_object_class_install_property(gobject_class,
729 g_param_spec_string (
"mnemonic",
730 "Commodity Mnemonic",
731 "The mnemonic is the official abbreviated" 732 "designation for the currency.",
735 g_object_class_install_property(gobject_class,
737 g_param_spec_string (
"printname",
738 "Commodity Print Name",
739 "Printable form of the commodity name.",
742 g_object_class_install_property(gobject_class,
744 g_param_spec_string (
"cusip",
745 "Commodity CUSIP Code",
749 g_object_class_install_property(gobject_class,
751 g_param_spec_int (
"fraction",
753 "The fraction is the number of sub-units that " 754 "the basic commodity can be divided into.",
759 g_object_class_install_property(gobject_class,
761 g_param_spec_string (
"unique-name",
762 "Commodity Unique Name",
763 "Unique form of the commodity name which combines " 764 "the namespace name and the commodity name.",
767 g_object_class_install_property(gobject_class,
769 g_param_spec_boolean (
"quote_flag",
771 "TRUE if prices are to be downloaded for this " 772 "commodity from a quote source.",
775 g_object_class_install_property(gobject_class,
777 g_param_spec_pointer(
"quote-source",
779 "The quote source from which prices are downloaded.",
781 g_object_class_install_property(gobject_class,
783 g_param_spec_string (
"quote-tz",
784 "Commodity Quote Timezone",
792 const char * name_space,
const char * mnemonic,
793 const char * cusip,
int fraction)
795 auto retval = GNC_COMMODITY(g_object_new(GNC_TYPE_COMMODITY,
nullptr));
798 gnc_commodity_begin_edit(retval);
800 if ( name_space !=
nullptr )
803 if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
804 g_strcmp0 (mnemonic,
"template") != 0)
806 PWARN(
"Converting commodity %s from namespace template to " 807 "namespace User", mnemonic);
821 mark_commodity_dirty (retval);
822 gnc_commodity_commit_edit(retval);
835 commodity_free(gnc_commodity * cm)
838 gnc_commodity_table *
table;
846 priv = GET_PRIVATE(cm);
851 CACHE_REMOVE (priv->fullname);
852 CACHE_REMOVE (priv->cusip);
853 CACHE_REMOVE (priv->mnemonic);
854 CACHE_REMOVE (priv->quote_tz);
855 priv->name_space =
nullptr;
858 priv->quote_source =
nullptr;
861 g_free(priv->printname);
862 priv->printname =
nullptr;
864 g_free(priv->unique_name);
865 priv->unique_name =
nullptr;
867 #ifdef ACCOUNTS_CLEANED_UP 872 if (priv->usage_count != 0)
874 PWARN(
"Destroying commodity (%p) with non-zero usage_count (%d).", cm,
886 gnc_commodity_begin_edit(cm);
887 qof_instance_set_destroying(cm, TRUE);
888 gnc_commodity_commit_edit(cm);
899 dest_priv->name_space = src_priv->name_space;
905 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
914 auto dest = GNC_COMMODITY (g_object_new(GNC_TYPE_COMMODITY,
nullptr));
916 src_priv = GET_PRIVATE(src);
917 dest_priv = GET_PRIVATE(dest);
919 dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
920 dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
921 dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
922 dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
924 dest_priv->name_space = src_priv->name_space;
926 dest_priv->fraction = src_priv->fraction;
927 dest_priv->quote_flag = src_priv->quote_flag;
931 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
933 reset_printname(dest_priv);
934 reset_unique_name(dest_priv);
946 if (!cm)
return nullptr;
947 return GET_PRIVATE(cm)->mnemonic;
957 if (!cm)
return nullptr;
958 return GET_PRIVATE(cm)->printname;
969 if (!cm)
return nullptr;
973 gnc_commodity_namespace *
976 if (!cm)
return nullptr;
977 return GET_PRIVATE(cm)->name_space;
987 if (!cm)
return nullptr;
988 return GET_PRIVATE(cm)->fullname;
999 if (!cm)
return nullptr;
1000 return GET_PRIVATE(cm)->unique_name;
1011 if (!cm)
return nullptr;
1012 return GET_PRIVATE(cm)->cusip;
1023 return GET_PRIVATE(cm)->fraction;
1031 gnc_commodity_get_auto_quote_control_flag(
const gnc_commodity *cm)
1033 GValue v = G_VALUE_INIT;
1034 gboolean retval = TRUE;
1036 if (!cm)
return FALSE;
1038 if (G_VALUE_HOLDS_STRING (&v) &&
1039 strcmp(g_value_get_string (&v),
"false") == 0)
1052 if (!cm)
return FALSE;
1053 return (GET_PRIVATE(cm)->quote_flag);
1065 if (!cm)
return nullptr;
1066 priv = GET_PRIVATE(cm);
1068 return ¤cy_quote_sources.front();
1069 return priv->quote_source;
1073 gnc_commodity_get_default_quote_source(
const gnc_commodity *cm)
1076 return ¤cy_quote_sources.front();
1088 if (!cm)
return nullptr;
1089 return GET_PRIVATE(cm)->quote_tz;
1098 g_return_val_if_fail (GNC_IS_COMMODITY (cm),
nullptr);
1100 GValue v = G_VALUE_INIT;
1102 const char *rv = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) :
nullptr;
1113 if (!cm)
return nullptr;
1114 return GET_PRIVATE(cm)->default_symbol;
1123 const char *nice_symbol;
1125 if (!cm)
return nullptr;
1128 if (nice_symbol && *nice_symbol)
1131 lc = gnc_localeconv();
1132 nice_symbol = lc->currency_symbol;
1137 if (nice_symbol && *nice_symbol)
1153 priv = GET_PRIVATE(cm);
1154 if (priv->mnemonic == mnemonic)
return;
1156 gnc_commodity_begin_edit(cm);
1157 CACHE_REMOVE (priv->mnemonic);
1158 priv->mnemonic = CACHE_INSERT(mnemonic);
1160 mark_commodity_dirty (cm);
1161 reset_printname(priv);
1162 reset_unique_name(priv);
1163 gnc_commodity_commit_edit(cm);
1174 gnc_commodity_table *
table;
1175 gnc_commodity_namespace *nsp;
1179 priv = GET_PRIVATE(cm);
1183 if (priv->name_space == nsp)
1186 gnc_commodity_begin_edit(cm);
1187 priv->name_space = nsp;
1190 mark_commodity_dirty(cm);
1191 reset_printname(priv);
1192 reset_unique_name(priv);
1193 gnc_commodity_commit_edit(cm);
1206 priv = GET_PRIVATE(cm);
1207 if (priv->fullname == fullname)
return;
1209 CACHE_REMOVE (priv->fullname);
1210 priv->fullname = CACHE_INSERT (fullname);
1212 gnc_commodity_begin_edit(cm);
1213 mark_commodity_dirty(cm);
1214 reset_printname(priv);
1215 gnc_commodity_commit_edit(cm);
1230 priv = GET_PRIVATE(cm);
1231 if (priv->cusip == cusip)
return;
1233 gnc_commodity_begin_edit(cm);
1234 CACHE_REMOVE (priv->cusip);
1235 priv->cusip = CACHE_INSERT (cusip);
1236 mark_commodity_dirty(cm);
1237 gnc_commodity_commit_edit(cm);
1248 gnc_commodity_begin_edit(cm);
1249 GET_PRIVATE(cm)->fraction = fraction;
1250 mark_commodity_dirty(cm);
1251 gnc_commodity_commit_edit(cm);
1259 gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
1260 const gboolean flag)
1262 GValue v = G_VALUE_INIT;
1263 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1270 gnc_commodity_begin_edit(cm);
1275 g_value_init (&v, G_TYPE_STRING);
1276 g_value_set_string (&v,
"false");
1280 mark_commodity_dirty(cm);
1281 gnc_commodity_commit_edit(cm);
1294 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1302 priv = GET_PRIVATE(cm);
1303 gnc_commodity_begin_edit(cm);
1314 gnc_commodity_set_auto_quote_control_flag(cm,
1315 (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1317 gnc_commodity_commit_edit(cm);
1328 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1331 gnc_commodity_begin_edit(cm);
1332 GET_PRIVATE(cm)->quote_flag = flag;
1333 mark_commodity_dirty(cm);
1334 gnc_commodity_commit_edit(cm);
1345 ENTER (
"(cm=%p, src=%p(%s))", cm, src, src ? src->get_internal_name() :
"unknown");
1348 gnc_commodity_begin_edit(cm);
1349 GET_PRIVATE(cm)->quote_source = src;
1350 mark_commodity_dirty(cm);
1351 gnc_commodity_commit_edit(cm);
1366 ENTER (
"(cm=%p, tz=%s)", cm, tz ? tz :
"(null)");
1368 priv = GET_PRIVATE(cm);
1370 if (tz == priv->quote_tz)
1372 LEAVE(
"Already correct TZ");
1376 gnc_commodity_begin_edit(cm);
1377 CACHE_REMOVE (priv->quote_tz);
1378 priv->quote_tz = CACHE_INSERT (tz);
1379 mark_commodity_dirty(cm);
1380 gnc_commodity_commit_edit(cm);
1395 ENTER (
"(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol :
"(null)");
1397 lc = gnc_localeconv();
1398 if (!user_symbol || !*user_symbol)
1399 user_symbol =
nullptr;
1401 !g_strcmp0(lc->currency_symbol, user_symbol))
1404 user_symbol =
nullptr;
1406 user_symbol =
nullptr;
1408 gnc_commodity_begin_edit (cm);
1412 GValue v = G_VALUE_INIT;
1413 g_value_init (&v, G_TYPE_STRING);
1414 g_value_set_static_string (&v, user_symbol);
1423 mark_commodity_dirty(cm);
1424 gnc_commodity_commit_edit(cm);
1435 gnc_commodity_set_default_symbol(gnc_commodity * cm,
1436 const char * default_symbol)
1438 GET_PRIVATE(cm)->default_symbol = default_symbol;
1450 ENTER(
"(cm=%p)", cm);
1458 priv = GET_PRIVATE(cm);
1460 if ((priv->usage_count == 0) && !priv->quote_flag
1461 && gnc_commodity_get_auto_quote_control_flag(cm)
1466 gnc_commodity_begin_edit(cm);
1469 gnc_commodity_get_default_quote_source(cm));
1470 gnc_commodity_commit_edit(cm);
1472 priv->usage_count++;
1473 LEAVE(
"(usage_count=%d)", priv->usage_count);
1485 ENTER(
"(cm=%p)", cm);
1493 priv = GET_PRIVATE(cm);
1495 if (priv->usage_count == 0)
1497 PWARN(
"usage_count already zero");
1502 priv->usage_count--;
1503 if ((priv->usage_count == 0) && priv->quote_flag
1504 && gnc_commodity_get_auto_quote_control_flag(cm)
1511 LEAVE(
"(usage_count=%d)", priv->usage_count);
1529 if (a == b)
return TRUE;
1530 if (!a || !b)
return FALSE;
1532 priv_a = GET_PRIVATE(a);
1533 priv_b = GET_PRIVATE(b);
1534 if (priv_a->name_space != priv_b->name_space)
return FALSE;
1535 if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
return FALSE;
1550 if (a == b)
return 0;
1551 if (a && !b)
return 1;
1552 if (b && !a)
return -1;
1579 if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
1580 return GNC_COMMODITY_NS_ISO_GUI;
1590 return g_list_copy (name_space->cm_list);
1596 return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1597 (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1600 static const gchar *
1601 gnc_commodity_table_map_namespace(
const char * name_space)
1603 if (g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0)
1604 return GNC_COMMODITY_NS_CURRENCY;
1613 gnc_commodity_table *
1616 gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1617 retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1618 retval->ns_list =
nullptr;
1626 gnc_commodity_table *
1629 if (!book)
return nullptr;
1630 return static_cast<gnc_commodity_table*
>(
qof_book_get_data (book, GNC_COMMODITY_TABLE));
1636 gnc_commodity *twin;
1638 gnc_commodity_table * comtbl;
1640 if (!from)
return nullptr;
1642 if (!comtbl)
return nullptr;
1645 twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1660 count_coms(gpointer key, gpointer value, gpointer user_data)
1662 GHashTable *tbl = ((gnc_commodity_namespace*)value)->cm_table;
1663 guint *count = (guint*)user_data;
1665 if (g_strcmp0((
char*)key, GNC_COMMODITY_NS_CURRENCY) == 0)
1673 *count += g_hash_table_size(tbl);
1680 g_return_val_if_fail(tbl, 0);
1681 g_return_val_if_fail(tbl->ns_table, 0);
1683 g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1694 gnc_commodity_table_lookup(
const gnc_commodity_table *
table,
1695 const char * name_space,
const char * mnemonic)
1697 gnc_commodity_namespace * nsp =
nullptr;
1699 if (!
table || !name_space || !mnemonic)
return nullptr;
1711 auto it = gnc_new_iso_codes.find (mnemonic);
1712 if (it != gnc_new_iso_codes.end())
1713 mnemonic = it->second.c_str();
1715 return GNC_COMMODITY(g_hash_table_lookup(nsp->cm_table, (gpointer)mnemonic));
1729 gnc_commodity_table_lookup_unique(
const gnc_commodity_table *
table,
1730 const char * unique_name)
1734 gnc_commodity *commodity;
1736 if (!
table || !unique_name)
return nullptr;
1738 name_space = g_strdup (unique_name);
1739 mnemonic = strstr (name_space,
"::");
1742 g_free (name_space);
1749 commodity = gnc_commodity_table_lookup (
table, name_space, mnemonic);
1751 g_free (name_space);
1762 gnc_commodity_table_find_full(
const gnc_commodity_table *
table,
1763 const char * name_space,
1764 const char * fullname)
1766 gnc_commodity * retval =
nullptr;
1770 if (!fullname || (fullname[0] ==
'\0'))
1775 for (iterator = all; iterator; iterator = iterator->next)
1777 auto commodity = GNC_COMMODITY (iterator->data);
1778 if (!strcmp(fullname,
1799 gnc_commodity * comm)
1801 gnc_commodity_namespace * nsp =
nullptr;
1803 const char *ns_name;
1807 if (!
table)
return nullptr;
1808 if (!comm)
return nullptr;
1810 priv = GET_PRIVATE(comm);
1812 ENTER (
"(table=%p, comm=%p) %s %s",
table, comm,
1813 (priv->mnemonic ==
nullptr ?
"(null)" : priv->mnemonic),
1814 (priv->fullname ==
nullptr ?
"(null)" : priv->fullname));
1816 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1822 LEAVE(
"already in table");
1828 if (priv->name_space->iso4217)
1830 auto it = gnc_new_iso_codes.find (priv->mnemonic);
1831 if (it != gnc_new_iso_codes.end())
1836 LEAVE(
"found at %p", c);
1841 if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
1842 g_strcmp0 (priv->mnemonic,
"template") != 0)
1844 PWARN(
"Converting commodity %s from namespace template to " 1845 "namespace User", priv->mnemonic);
1848 mark_commodity_dirty (comm);
1854 PINFO (
"insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1855 nsp->cm_table, nsp->name);
1856 g_hash_table_insert(nsp->cm_table,
1857 (gpointer)CACHE_INSERT(priv->mnemonic),
1859 nsp->cm_list = g_list_append(nsp->cm_list, comm);
1873 gnc_commodity * comm)
1875 gnc_commodity_namespace * nsp;
1878 const char *ns_name;
1883 priv = GET_PRIVATE(comm);
1885 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1886 if (c != comm)
return;
1893 nsp->cm_list = g_list_remove(nsp->cm_list, comm);
1894 g_hash_table_remove (nsp->cm_table, priv->mnemonic);
1905 const char * name_space)
1907 gnc_commodity_namespace * nsp =
nullptr;
1909 if (!
table || !name_space)
1926 hash_keys_helper(gpointer key, gpointer value, gpointer data)
1928 auto l = (GList**)data;
1929 *l = g_list_prepend(*l, key);
1933 g_hash_table_keys(GHashTable *
table)
1935 GList * l =
nullptr;
1936 g_hash_table_foreach(
table, &hash_keys_helper, (gpointer) &l);
1941 hash_values_helper(gpointer key, gpointer value, gpointer data)
1943 auto l = (GList**)data;
1944 *l = g_list_prepend(*l, value);
1948 g_hash_table_values(GHashTable *
table)
1950 GList * l =
nullptr;
1951 g_hash_table_foreach(
table, &hash_values_helper, (gpointer) &l);
1966 return g_hash_table_keys(
table->ns_table);
1975 return g_list_copy (
table->ns_list);
1989 if (!cm)
return FALSE;
1991 priv = GET_PRIVATE(cm);
1992 if ( !priv->name_space)
return FALSE;
1993 return priv->name_space->iso4217;
1999 const char *ns_name;
2000 if (!cm)
return FALSE;
2004 !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
2012 static CommodityList*
2013 commodity_table_get_all_noncurrency_commodities(
const gnc_commodity_table*
table)
2016 CommodityList *retval =
nullptr;
2017 for (node = nslist; node; node=g_list_next(node))
2019 gnc_commodity_namespace *ns =
nullptr;
2020 if (g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_CURRENCY) == 0
2021 || g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_TEMPLATE) == 0)
2026 retval = g_list_concat(g_hash_table_values(ns->cm_table), retval);
2028 g_list_free(nslist);
2034 const char * name_space)
2036 gnc_commodity_namespace * ns =
nullptr;
2040 if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONISO_GUI) == 0)
2041 return commodity_table_get_all_noncurrency_commodities(
table);
2046 return g_hash_table_values(ns->cm_table);
2055 get_quotables_helper1(gpointer key, gpointer value, gpointer data)
2057 auto comm = GNC_COMMODITY(value);
2059 auto l =
static_cast<GList**
>(data);
2061 if (!priv->quote_flag || !priv->quote_source || !priv->quote_source->get_supported())
2063 *l = g_list_prepend(*l, value);
2067 get_quotables_helper2 (gnc_commodity *comm, gpointer data)
2069 auto l =
static_cast<GList**
>(data);
2072 if (!priv->quote_flag || priv->quote_source || !priv->quote_source->get_supported())
2074 *l = g_list_prepend(*l, comm);
2081 gnc_commodity_namespace * ns =
nullptr;
2082 const char *name_space;
2083 GList * nslist, * tmp;
2084 GList * l =
nullptr;
2086 const char *expression = gnc_prefs_get_namespace_regexp();
2088 ENTER(
"table=%p, expression=%s",
table, expression);
2092 if (expression && *expression)
2094 if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2096 LEAVE(
"Cannot compile regex");
2101 for (tmp = nslist; tmp; tmp = tmp->next)
2103 name_space =
static_cast<const char*
>(tmp->data);
2104 if (regexec(&pattern, name_space, 0,
nullptr, 0) == 0)
2106 DEBUG(
"Running list of %s commodities", name_space);
2110 g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2114 g_list_free(nslist);
2122 LEAVE(
"list head %p", l);
2132 QOF_GOBJECT_IMPL(gnc_commodity_namespace, gnc_commodity_namespace, QOF_TYPE_INSTANCE)
2135 gnc_commodity_namespace_init(gnc_commodity_namespace* ns)
2140 gnc_commodity_namespace_dispose_real (GObject *nsp)
2145 gnc_commodity_namespace_finalize_real(GObject* nsp)
2149 gnc_commodity_namespace *
2151 const char * name_space,
2154 gnc_commodity_namespace * ns =
nullptr;
2156 if (!
table)
return nullptr;
2158 name_space = gnc_commodity_table_map_namespace(name_space);
2162 ns =
static_cast<gnc_commodity_namespace*
>(g_object_new(GNC_TYPE_COMMODITY_NAMESPACE,
nullptr));
2163 ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2164 ns->name = CACHE_INSERT(static_cast<const char*>(name_space));
2169 g_hash_table_insert(
table->ns_table,
2170 (gpointer) ns->name,
2172 table->ns_list = g_list_append(
table->ns_list, ns);
2179 gnc_commodity_namespace *
2181 const char * name_space)
2183 if (!
table || !name_space)
2186 name_space = gnc_commodity_table_map_namespace(name_space);
2187 return static_cast<gnc_commodity_namespace*
>(g_hash_table_lookup(
table->ns_table, (gpointer)name_space));
2192 gnc_commodity_find_commodity_by_guid(
const GncGUID *guid, QofBook *book)
2195 if (!guid || !book)
return nullptr;
2206 ns_helper(gpointer key, gpointer value, gpointer user_data)
2208 auto c = GNC_COMMODITY(value);
2210 CACHE_REMOVE(static_cast<char*>(key));
2216 const char * name_space)
2218 gnc_commodity_namespace * ns;
2227 g_hash_table_remove(
table->ns_table, name_space);
2228 table->ns_list = g_list_remove(
table->ns_list, ns);
2230 g_list_free(ns->cm_list);
2231 ns->cm_list =
nullptr;
2233 g_hash_table_foreach_remove(ns->cm_table, ns_helper,
nullptr);
2234 g_hash_table_destroy(ns->cm_table);
2235 CACHE_REMOVE(ns->name);
2251 gboolean (*func)(gnc_commodity *, gpointer);
2256 iter_commodity (gpointer key, gpointer value, gpointer user_data)
2259 gnc_commodity *cm = (gnc_commodity *) value;
2263 iter_data->ok = (iter_data->func)(cm, iter_data->user_data);
2268 iter_namespace (gpointer key, gpointer value, gpointer user_data)
2270 GHashTable *namespace_hash = ((gnc_commodity_namespace *) value)->cm_table;
2271 g_hash_table_foreach (namespace_hash, iter_commodity, user_data);
2276 gboolean (*f)(gnc_commodity *, gpointer),
2281 if (!tbl || !f)
return FALSE;
2283 iter_data.ok = TRUE;
2285 iter_data.user_data = user_data;
2287 g_hash_table_foreach(tbl->ns_table, iter_namespace, (gpointer)&iter_data);
2289 return iter_data.ok;
2298 gnc_commodity_table_destroy(gnc_commodity_table * t)
2300 gnc_commodity_namespace * ns;
2304 ENTER (
"table=%p", t);
2306 for (item = t->ns_list; item; item = next)
2308 next = g_list_next(item);
2309 ns =
static_cast<gnc_commodity_namespace*
>(item->data);
2313 g_list_free(t->ns_list);
2314 t->ns_list =
nullptr;
2315 g_hash_table_destroy(t->ns_table);
2316 t->ns_table =
nullptr;
2317 LEAVE (
"table=%p", t);
2327 #define CUR_I18N(String) dgettext ("iso_4217", String) 2337 c =
gnc_commodity_new(book,
"template", GNC_COMMODITY_NS_TEMPLATE,
"template",
"template", 1);
2340 #include "iso-4217-currencies.c" 2365 static QofObject commodity_object_def =
2368 DI(.e_type = ) GNC_ID_COMMODITY,
2369 DI(.type_label = ) "Commodity",
2370 DI(.create = )
nullptr,
2371 DI(.book_begin = )
nullptr,
2372 DI(.book_end = )
nullptr,
2375 DI(.foreach = ) qof_collection_foreach,
2379 static QofObject namespace_object_def =
2382 DI(.e_type = ) GNC_ID_COMMODITY_NAMESPACE,
2383 DI(.type_label = ) "Namespace",
2384 DI(.create = )
nullptr,
2385 DI(.book_begin = )
nullptr,
2386 DI(.book_end = )
nullptr,
2387 DI(.is_dirty = )
nullptr,
2388 DI(.mark_clean = )
nullptr,
2389 DI(.foreach = )
nullptr,
2390 DI(.printable = )
nullptr,
2394 commodity_table_book_begin (QofBook *book)
2396 gnc_commodity_table *ct;
2397 ENTER (
"book=%p", book);
2407 PWARN(
"unable to initialize book's commodity_table");
2410 LEAVE (
"book=%p", book);
2414 commodity_table_book_end (QofBook *book)
2416 gnc_commodity_table *ct;
2420 gnc_commodity_table_destroy (ct);
2423 static QofObject commodity_table_object_def =
2426 DI(.e_type = ) GNC_ID_COMMODITY_TABLE,
2427 DI(.type_label = ) "CommodityTable",
2428 DI(.create = )
nullptr,
2429 DI(.book_begin = ) commodity_table_book_begin,
2430 DI(.book_end = ) commodity_table_book_end,
2433 DI(.foreach = )
nullptr,
2434 DI(.printable = )
nullptr,
2435 DI(.version_cmp = )
nullptr,
2456 MonetaryList *l = list, *tmp;
2457 for (tmp = list; tmp; tmp = tmp->next)
2459 auto list_mon =
static_cast<gnc_monetary*
>(tmp->data);
2471 auto new_mon =
static_cast<gnc_monetary*
>(g_new0(gnc_monetary, 1));
2473 l = g_list_prepend(l, new_mon);
2484 MonetaryList *node, *next;
2485 for (node = list; node; node = next)
2487 auto mon =
static_cast<gnc_monetary*
>(node->data);
2492 list = g_list_delete_link(list, node);
2503 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...