29 #include <glib/gi18n.h> 36 #include <qofinstance-p.h> 39 #include "gnc-locale-utils.h" 42 static QofLogModule log_module = GNC_MOD_COMMODITY;
71 gnc_commodity_namespace *name_space;
82 gnc_quote_source *quote_source;
90 const char *default_symbol;
96 #define GET_PRIVATE(o) \ 97 ((gnc_commodityPrivate*)g_type_instance_get_private((GTypeInstance*)o, GNC_TYPE_COMMODITY)) 101 QofInstanceClass parent_class;
104 static void commodity_free(gnc_commodity * cm);
105 static void gnc_commodity_set_default_symbol(gnc_commodity *,
const char *);
113 GHashTable * cm_table;
119 QofInstanceClass parent_class;
124 GHashTable * ns_table;
130 const char *old_code;
131 const char *new_code;
132 } gnc_new_iso_codes[] =
147 #define GNC_NEW_ISO_CODES \ 148 (sizeof(gnc_new_iso_codes) / sizeof(struct gnc_new_iso_code)) 150 static char *fq_version = NULL;
158 char *old_internal_name;
170 static gnc_quote_source currency_quote_source =
171 { TRUE, 0, 0,
"Currency",
"CURRENCY",
"currency" };
177 static gnc_quote_source single_quote_sources[] =
179 { FALSE, 0, 0,
"Alphavantage, US",
"ALPHAVANTAGE",
"alphavantage" },
180 { FALSE, 0, 0,
"Amsterdam Euronext eXchange, NL",
"AEX",
"aex" },
181 { FALSE, 0, 0,
"American International Assurance, HK",
"AIAHK",
"aiahk" },
182 { FALSE, 0, 0,
"Association of Mutual Funds in India",
"AMFIINDIA",
"amfiindia" },
183 { FALSE, 0, 0,
"Athens Stock Exchange, GR",
"ASEGR",
"asegr" },
184 { FALSE, 0, 0,
"Australian Stock Exchange, AU",
"ASX",
"asx" },
185 { FALSE, 0, 0,
"BAMOSZ funds, HU",
"BAMOSZ",
"bamosz" },
186 { FALSE, 0, 0,
"BMO NesbittBurns, CA",
"BMONESBITTBURNS",
"bmonesbittburns" },
187 { FALSE, 0, 0,
"Bucharest Stock Exchange, RO",
"BSERO",
"bsero" },
188 { FALSE, 0, 0,
"Budapest Stock Exchange (BET), ex-BUX, HU",
"BSE",
"bse" },
189 { FALSE, 0, 0,
"Canada Mutual",
"CANADAMUTUAL",
"canadamutual" },
190 { FALSE, 0, 0,
"Citywire Funds, GB",
"citywire",
"citywire" },
191 { FALSE, 0, 0,
"Colombo Stock Exchange, LK",
"CSE",
"cse" },
192 { FALSE, 0, 0,
"Cominvest, ex-Adig, DE",
"COMINVEST",
"cominvest" },
193 { FALSE, 0, 0,
"Deka Investments, DE",
"DEKA",
"deka" },
194 { FALSE, 0, 0,
"Dutch",
"DUTCH",
"dutch" },
195 { FALSE, 0, 0,
"DWS, DE",
"DWS",
"dwsfunds" },
196 { FALSE, 0, 0,
"Equinox Unit Trusts, ZA",
"ZA_unittrusts",
"za_unittrusts" },
197 { FALSE, 0, 0,
"Fidelity Direct",
"FIDELITY_DIRECT",
"fidelity_direct" },
198 { FALSE, 0, 0,
"Fidelity Fixed",
"FIDELITY_DIRECT",
"fidelityfixed" },
199 { FALSE, 0, 0,
"Finance Canada",
"FINANCECANADA",
"financecanada" },
200 { FALSE, 0, 0,
"Financial Times Funds service, GB",
"FTFUNDS",
"ftfunds" },
201 { FALSE, 0, 0,
"Finanzpartner, DE",
"FINANZPARTNER",
"finanzpartner" },
202 { FALSE, 0, 0,
"First Trust Portfolios, US",
"FTPORTFOLIOS",
"ftportfolios" },
203 { FALSE, 0, 0,
"Fund Library, CA",
"FUNDLIBRARY",
"fundlibrary" },
204 { FALSE, 0, 0,
"GoldMoney spot rates, JE",
"GOLDMONEY",
"goldmoney" },
205 { FALSE, 0, 0,
"Greece",
"GREECE",
"greece" },
206 { FALSE, 0, 0,
"Helsinki stock eXchange, FI",
"HEX",
"hex" },
207 { FALSE, 0, 0,
"Hungary",
"HU",
"hu" },
208 { FALSE, 0, 0,
"India Mutual",
"INDIAMUTUAL",
"indiamutual" },
209 { FALSE, 0, 0,
"Man Investments, AU",
"maninv",
"maninv" },
210 { FALSE, 0, 0,
"Morningstar, GB",
"MSTARUK",
"mstaruk" },
211 { FALSE, 0, 0,
"Morningstar, JP",
"MORNINGSTARJP",
"morningstarjp" },
212 { FALSE, 0, 0,
"Morningstar, SE",
"MORNINGSTAR",
"morningstar" },
213 { FALSE, 0, 0,
"Motley Fool, US",
"FOOL",
"fool" },
214 { FALSE, 0, 0,
"New Zealand stock eXchange, NZ",
"NZX",
"nzx" },
215 { FALSE, 0, 0,
"Paris Stock Exchange/Boursorama, FR",
"BOURSO",
"bourso" },
216 { FALSE, 0, 0,
"Paris Stock Exchange/LeRevenu, FR",
"LEREVENU",
"lerevenu" },
217 { FALSE, 0, 0,
"Platinum Asset Management, AU",
"PLATINUM",
"platinum" },
218 { FALSE, 0, 0,
"Romania",
"romania",
"romania" },
219 { FALSE, 0, 0,
"SIX Swiss Exchange funds, CH",
"SIXFUNDS",
"sixfunds" },
220 { FALSE, 0, 0,
"SIX Swiss Exchange shares, CH",
"SIXSHARES",
"sixshares" },
221 { FALSE, 0, 0,
"Skandinaviska Enskilda Banken, SE",
"SEB_FUNDS",
"seb_funds" },
222 { FALSE, 0, 0,
"Sharenet, ZA",
"ZA",
"za" },
223 { FALSE, 0, 0,
"StockHouse Canada",
"STOCKHOUSE_FUND",
"stockhousecanada_fund" },
224 { FALSE, 0, 0,
"TD Waterhouse Funds, CA",
"TDWATERHOUSE",
"tdwaterhouse" },
225 { FALSE, 0, 0,
"TD Efunds, CA",
"TDEFUNDS",
"tdefunds" },
226 { FALSE, 0, 0,
"TIAA-CREF, US",
"TIAACREF",
"tiaacref" },
227 { FALSE, 0, 0,
"Toronto Stock eXchange, CA",
"TSX",
"tsx" },
228 { FALSE, 0, 0,
"T. Rowe Price",
"TRPRICE",
"troweprice" },
229 { FALSE, 0, 0,
"T. Rowe Price, US",
"TRPRICE_DIRECT",
"troweprice_direct" },
230 { FALSE, 0, 0,
"Trustnet via tnetuk.pm, GB",
"TNETUK",
"tnetuk" },
231 { FALSE, 0, 0,
"Trustnet via trustnet.pm, GB",
"TRUSTNET",
"trustnet" },
232 { FALSE, 0, 0,
"U.K. Unit Trusts",
"UKUNITTRUSTS",
"uk_unit_trusts" },
233 { FALSE, 0, 0,
"Union Investment, DE",
"UNIONFUNDS",
"unionfunds" },
234 { FALSE, 0, 0,
"US Treasury Bonds",
"usfedbonds",
"usfedbonds" },
235 { FALSE, 0, 0,
"US Govt. Thrift Savings Plan",
"TSP",
"tsp" },
236 { FALSE, 0, 0,
"Vanguard",
"VANGUARD",
"vanguard" },
237 { FALSE, 0, 0,
"VWD, DE (unmaintained)",
"VWD",
"vwd" },
238 { FALSE, 0, 0,
"Yahoo as JSON",
"YAHOO_JSON",
"yahoo_json" },
239 { FALSE, 0, 0,
"Yahoo as YQL",
"YAHOO_YQL",
"yahoo_yql" },
242 static gnc_quote_source multiple_quote_sources[] =
244 { FALSE, 0, 0,
"Australia (ASX, ...)",
"AUSTRALIA",
"australia" },
245 { FALSE, 0, 0,
"Canada (Alphavantage, TSX, ...)",
"CANADA",
"canada" },
246 { FALSE, 0, 0,
"Canada Mutual (Fund Library, StockHouse, ...)",
"CANADAMUTUAL",
"canadamutual" },
247 { FALSE, 0, 0,
"Dutch (AEX, ...)",
"DUTCH",
"dutch" },
248 { FALSE, 0, 0,
"Europe (asegr,.bsero, hex ...)",
"EUROPE",
"europe" },
249 { FALSE, 0, 0,
"Greece (ASE, ...)",
"GREECE",
"greece" },
250 { FALSE, 0, 0,
"Hungary (Bamosz, BET, ...)",
"HU",
"hu" },
251 { FALSE, 0, 0,
"India Mutual (AMFI, ...)",
"INDIAMUTUAL",
"indiamutual" },
252 { FALSE, 0, 0,
"Fidelity (Fidelity, ...)",
"FIDELITY",
"fidelity" },
253 { FALSE, 0, 0,
"Finland (HEX, ...)",
"FINLAND",
"finland" },
254 { FALSE, 0, 0,
"First Trust (First Trust, ...)",
"FTPORTFOLIOS",
"ftportfolios" },
255 { FALSE, 0, 0,
"France (bourso, ĺerevenu, ...)",
"FRANCE",
"france" },
256 { FALSE, 0, 0,
"Nasdaq (alphavantage, fool, ...)",
"NASDAQ",
"nasdaq" },
257 { FALSE, 0, 0,
"New Zealand (NZX, ...)",
"NZ",
"nz" },
258 { FALSE, 0, 0,
"NYSE (alphavantage, fool, ...)",
"NYSE",
"nyse" },
259 { FALSE, 0, 0,
"South Africa (Sharenet, ...)",
"ZA",
"za" },
260 { FALSE, 0, 0,
"Romania (BSE-RO, ...)",
"romania",
"romania" },
261 { FALSE, 0, 0,
"T. Rowe Price",
"TRPRICE",
"troweprice" },
262 { FALSE, 0, 0,
"U.K. Funds (citywire, FTfunds, MStar, tnetuk, ...)",
"ukfunds",
"ukfunds" },
263 { FALSE, 0, 0,
"U.K. Unit Trusts (trustnet, ...)",
"UKUNITTRUSTS",
"uk_unit_trusts" },
264 { FALSE, 0, 0,
"USA (Alphavantage, Fool, ...)",
"USA",
"usa" },
267 static const int num_single_quote_sources =
268 sizeof(single_quote_sources) /
sizeof(gnc_quote_source);
269 static const int num_multiple_quote_sources =
270 sizeof(multiple_quote_sources) /
sizeof(gnc_quote_source);
271 static GList *new_quote_sources = NULL;
283 return (fq_version != NULL);
310 return num_single_quote_sources;
313 return num_multiple_quote_sources;
315 return g_list_length(new_quote_sources);
324 gnc_quote_source_init_tables (
void)
328 for (i = 0; i < num_single_quote_sources; i++)
331 single_quote_sources[i].index = i;
334 for (i = 0; i < num_multiple_quote_sources; i++)
337 multiple_quote_sources[i].index = i;
341 currency_quote_source.index = 0;
356 gnc_quote_source *new_source;
358 DEBUG(
"Creating new source %s", (source_name == NULL ?
"(null)" : source_name));
359 new_source = malloc(
sizeof(gnc_quote_source));
360 new_source->supported = supported;
362 new_source->index = g_list_length(new_quote_sources);
366 new_source->user_name = g_strdup(source_name);
371 new_source->old_internal_name = g_strdup(source_name);
372 new_source->internal_name = g_strdup(source_name);
373 new_quote_sources = g_list_append(new_quote_sources, new_source);
385 gnc_quote_source *source;
388 ENTER(
"type/index is %d/%d", type, index);
392 LEAVE(
"found %s", currency_quote_source.user_name);
393 return ¤cy_quote_source;
397 if (index < num_single_quote_sources)
399 LEAVE(
"found %s", single_quote_sources[index].user_name);
400 return &single_quote_sources[index];
405 if (index < num_multiple_quote_sources)
407 LEAVE(
"found %s", multiple_quote_sources[index].user_name);
408 return &multiple_quote_sources[index];
414 node = g_list_nth(new_quote_sources, index);
418 LEAVE(
"found %s", source->user_name);
431 gnc_quote_source *source;
435 if ((name == NULL) || (g_strcmp0(name,
"") == 0))
440 if (g_strcmp0(name, currency_quote_source.internal_name) == 0)
441 return ¤cy_quote_source;
442 if (g_strcmp0(name, currency_quote_source.old_internal_name) == 0)
443 return ¤cy_quote_source;
445 for (i = 0; i < num_single_quote_sources; i++)
447 if (g_strcmp0(name, single_quote_sources[i].internal_name) == 0)
448 return &single_quote_sources[i];
449 if (g_strcmp0(name, single_quote_sources[i].old_internal_name) == 0)
450 return &single_quote_sources[i];
453 for (i = 0; i < num_multiple_quote_sources; i++)
455 if (g_strcmp0(name, multiple_quote_sources[i].internal_name) == 0)
456 return &multiple_quote_sources[i];
457 if (g_strcmp0(name, multiple_quote_sources[i].old_internal_name) == 0)
458 return &multiple_quote_sources[i];
461 for (i = 0, node = new_quote_sources; node; node = node->next, i++)
464 if (g_strcmp0(name, source->internal_name) == 0)
466 if (g_strcmp0(name, source->old_internal_name) == 0)
470 DEBUG(
"gnc_quote_source_lookup_by_internal: Unknown source %s", name);
489 LEAVE(
"type is %d", source->type);
503 LEAVE(
"index is %d", source->index);
504 return source->index;
517 LEAVE(
"%ssupported", source && source->supported ?
"" :
"not ");
518 return source->supported;
530 LEAVE(
"user name %s", source->user_name);
531 return source->user_name;
543 LEAVE(
"internal name %s", source->internal_name);
544 return source->internal_name;
556 const GList *sources_list)
558 gnc_quote_source *source;
574 fq_version = g_strdup (version_string);
576 for (node = sources_list; node; node = node->next)
578 source_name = node->data;
583 DEBUG(
"Found source %s: %s", source_name, source->user_name);
584 source->supported = TRUE;
598 gnc_commodity_begin_edit (gnc_commodity *cm)
605 PERR (
"Failed to commit: %d", errcode);
606 gnc_engine_signal_commit_error( errcode );
614 commodity_free( GNC_COMMODITY(inst) );
618 gnc_commodity_commit_edit (gnc_commodity *cm)
629 mark_commodity_dirty (gnc_commodity *cm)
631 qof_instance_set_dirty(&cm->inst);
638 g_free(priv->printname);
639 priv->printname = g_strdup_printf(
"%s (%s)",
640 priv->mnemonic ? priv->mnemonic :
"",
641 priv->fullname ? priv->fullname :
"");
647 gnc_commodity_namespace *ns;
649 g_free(priv->unique_name);
650 ns = priv->name_space;
651 priv->unique_name = g_strdup_printf(
"%s::%s",
653 priv->mnemonic ? priv->mnemonic :
"");
657 G_DEFINE_TYPE_WITH_PRIVATE(gnc_commodity, gnc_commodity, QOF_TYPE_INSTANCE);
660 gnc_commodity_init(gnc_commodity* com)
664 priv = GET_PRIVATE(com);
666 priv->name_space = NULL;
667 priv->fullname = CACHE_INSERT(
"");
668 priv->mnemonic = CACHE_INSERT(
"");
669 priv->cusip = CACHE_INSERT(
"");
670 priv->fraction = 10000;
671 priv->quote_flag = 0;
672 priv->quote_source = NULL;
673 priv->quote_tz = CACHE_INSERT(
"");
674 priv->user_symbol = (
char*) is_unset;
676 reset_printname(priv);
677 reset_unique_name(priv);
681 gnc_commodity_dispose(GObject *comp)
683 G_OBJECT_CLASS(gnc_commodity_parent_class)->dispose(comp);
687 gnc_commodity_finalize(GObject* comp)
689 G_OBJECT_CLASS(gnc_commodity_parent_class)->finalize(comp);
698 gnc_commodity_get_property (GObject *
object,
703 gnc_commodity *commodity;
706 g_return_if_fail(GNC_IS_COMMODITY(
object));
708 commodity = GNC_COMMODITY(
object);
709 priv = GET_PRIVATE(commodity);
713 g_value_take_object(value, priv->name_space);
716 g_value_set_string(value, priv->fullname);
719 g_value_set_string(value, priv->mnemonic);
722 g_value_set_string(value, priv->printname);
725 g_value_set_string(value, priv->cusip);
728 g_value_set_int(value, priv->fraction);
730 case PROP_UNIQUE_NAME:
731 g_value_set_string(value, priv->unique_name);
733 case PROP_QUOTE_FLAG:
734 g_value_set_boolean(value, priv->quote_flag);
736 case PROP_QUOTE_SOURCE:
737 g_value_set_pointer(value, priv->quote_source);
740 g_value_set_string(value, priv->quote_tz);
743 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
749 gnc_commodity_set_property (GObject *
object,
754 gnc_commodity *commodity;
756 g_return_if_fail(GNC_IS_COMMODITY(
object));
758 commodity = GNC_COMMODITY(
object);
759 g_assert (qof_instance_get_editlevel(commodity));
778 case PROP_QUOTE_FLAG:
781 case PROP_QUOTE_SOURCE:
788 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
795 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
797 gobject_class->dispose = gnc_commodity_dispose;
798 gobject_class->finalize = gnc_commodity_finalize;
799 gobject_class->set_property = gnc_commodity_set_property;
800 gobject_class->get_property = gnc_commodity_get_property;
802 g_object_class_install_property(gobject_class,
804 g_param_spec_object (
"namespace",
806 "The namespace field denotes the " 807 "namespace for this commodity, either " 808 "a currency or symbol from a quote source.",
809 GNC_TYPE_COMMODITY_NAMESPACE,
811 g_object_class_install_property(gobject_class,
813 g_param_spec_string (
"fullname",
814 "Full Commodity Name",
815 "The fullname is the official full name of" 819 g_object_class_install_property(gobject_class,
821 g_param_spec_string (
"mnemonic",
822 "Commodity Mnemonic",
823 "The mnemonic is the official abbreviated" 824 "designation for the currency.",
827 g_object_class_install_property(gobject_class,
829 g_param_spec_string (
"printname",
830 "Commodity Print Name",
831 "Printable form of the commodity name.",
834 g_object_class_install_property(gobject_class,
836 g_param_spec_string (
"cusip",
837 "Commodity CUSIP Code",
841 g_object_class_install_property(gobject_class,
843 g_param_spec_int (
"fraction",
845 "The fraction is the number of sub-units that " 846 "the basic commodity can be divided into.",
851 g_object_class_install_property(gobject_class,
853 g_param_spec_string (
"unique-name",
854 "Commodity Unique Name",
855 "Unique form of the commodity name which combines " 856 "the namespace name and the commodity name.",
859 g_object_class_install_property(gobject_class,
861 g_param_spec_boolean (
"quote_flag",
863 "TRUE if prices are to be downloaded for this " 864 "commodity from a quote source.",
867 g_object_class_install_property(gobject_class,
869 g_param_spec_pointer(
"quote-source",
871 "The quote source from which prices are downloaded.",
873 g_object_class_install_property(gobject_class,
875 g_param_spec_string (
"quote-tz",
876 "Commodity Quote Timezone",
884 const char * name_space,
const char * mnemonic,
885 const char * cusip,
int fraction)
887 gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
890 gnc_commodity_begin_edit(retval);
892 if ( name_space != NULL )
895 if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
896 g_strcmp0 (mnemonic,
"template") != 0)
898 PWARN(
"Converting commodity %s from namespace template to " 899 "namespace User", mnemonic);
913 mark_commodity_dirty (retval);
914 gnc_commodity_commit_edit(retval);
927 commodity_free(gnc_commodity * cm)
930 gnc_commodity_table *
table;
938 priv = GET_PRIVATE(cm);
943 CACHE_REMOVE (priv->fullname);
944 CACHE_REMOVE (priv->cusip);
945 CACHE_REMOVE (priv->mnemonic);
946 CACHE_REMOVE (priv->quote_tz);
947 priv->name_space = NULL;
950 priv->quote_source = NULL;
953 g_free(priv->printname);
954 priv->printname = NULL;
956 g_free(priv->unique_name);
957 priv->unique_name = NULL;
959 if (priv->user_symbol != is_unset)
960 g_free (priv->user_symbol);
961 priv->user_symbol = NULL;
963 #ifdef ACCOUNTS_CLEANED_UP 968 if (priv->usage_count != 0)
970 PWARN(
"Destroying commodity (%p) with non-zero usage_count (%d).", cm,
982 gnc_commodity_begin_edit(cm);
983 qof_instance_set_destroying(cm, TRUE);
984 gnc_commodity_commit_edit(cm);
995 dest_priv->name_space = src_priv->name_space;
1001 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
1010 gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
1012 src_priv = GET_PRIVATE(src);
1013 dest_priv = GET_PRIVATE(dest);
1015 dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
1016 dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
1017 dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
1018 dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
1020 dest_priv->name_space = src_priv->name_space;
1022 dest_priv->fraction = src_priv->fraction;
1023 dest_priv->quote_flag = src_priv->quote_flag;
1027 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
1029 reset_printname(dest_priv);
1030 reset_unique_name(dest_priv);
1042 if (!cm)
return NULL;
1043 return GET_PRIVATE(cm)->mnemonic;
1053 if (!cm)
return NULL;
1054 return GET_PRIVATE(cm)->printname;
1065 if (!cm)
return NULL;
1069 gnc_commodity_namespace *
1072 if (!cm)
return NULL;
1073 return GET_PRIVATE(cm)->name_space;
1083 if (!cm)
return NULL;
1084 return GET_PRIVATE(cm)->fullname;
1095 if (!cm)
return NULL;
1096 return GET_PRIVATE(cm)->unique_name;
1107 if (!cm)
return NULL;
1108 return GET_PRIVATE(cm)->cusip;
1119 return GET_PRIVATE(cm)->fraction;
1127 gnc_commodity_get_auto_quote_control_flag(
const gnc_commodity *cm)
1129 GValue v = G_VALUE_INIT;
1130 gboolean retval = TRUE;
1132 if (!cm)
return FALSE;
1134 if (G_VALUE_HOLDS_STRING (&v) &&
1135 strcmp(g_value_get_string (&v),
"false") == 0)
1148 if (!cm)
return FALSE;
1149 return (GET_PRIVATE(cm)->quote_flag);
1161 if (!cm)
return NULL;
1162 priv = GET_PRIVATE(cm);
1164 return ¤cy_quote_source;
1165 return priv->quote_source;
1169 gnc_commodity_get_default_quote_source(
const gnc_commodity *cm)
1172 return ¤cy_quote_source;
1184 if (!cm)
return NULL;
1185 return GET_PRIVATE(cm)->quote_tz;
1195 g_return_val_if_fail (GNC_IS_COMMODITY (cm), NULL);
1196 priv = GET_PRIVATE(cm);
1197 if (priv->user_symbol == is_unset)
1199 GValue v = G_VALUE_INIT;
1201 priv->user_symbol = G_VALUE_HOLDS_STRING (&v) ? g_value_dup_string (&v) : NULL;
1204 return priv->user_symbol;
1213 if (!cm)
return NULL;
1214 return GET_PRIVATE(cm)->default_symbol;
1223 const char *nice_symbol;
1225 if (!cm)
return NULL;
1228 if (nice_symbol && *nice_symbol)
1231 lc = gnc_localeconv();
1232 nice_symbol = lc->currency_symbol;
1237 if (nice_symbol && *nice_symbol)
1253 priv = GET_PRIVATE(cm);
1254 if (priv->mnemonic == mnemonic)
return;
1256 gnc_commodity_begin_edit(cm);
1257 CACHE_REMOVE (priv->mnemonic);
1258 priv->mnemonic = CACHE_INSERT(mnemonic);
1260 mark_commodity_dirty (cm);
1261 reset_printname(priv);
1262 reset_unique_name(priv);
1263 gnc_commodity_commit_edit(cm);
1274 gnc_commodity_table *
table;
1275 gnc_commodity_namespace *nsp;
1279 priv = GET_PRIVATE(cm);
1283 if (priv->name_space == nsp)
1286 gnc_commodity_begin_edit(cm);
1287 priv->name_space = nsp;
1290 mark_commodity_dirty(cm);
1291 reset_printname(priv);
1292 reset_unique_name(priv);
1293 gnc_commodity_commit_edit(cm);
1306 priv = GET_PRIVATE(cm);
1307 if (priv->fullname == fullname)
return;
1309 CACHE_REMOVE (priv->fullname);
1310 priv->fullname = CACHE_INSERT (fullname);
1312 gnc_commodity_begin_edit(cm);
1313 mark_commodity_dirty(cm);
1314 reset_printname(priv);
1315 gnc_commodity_commit_edit(cm);
1330 priv = GET_PRIVATE(cm);
1331 if (priv->cusip == cusip)
return;
1333 gnc_commodity_begin_edit(cm);
1334 CACHE_REMOVE (priv->cusip);
1335 priv->cusip = CACHE_INSERT (cusip);
1336 mark_commodity_dirty(cm);
1337 gnc_commodity_commit_edit(cm);
1348 gnc_commodity_begin_edit(cm);
1349 GET_PRIVATE(cm)->fraction = fraction;
1350 mark_commodity_dirty(cm);
1351 gnc_commodity_commit_edit(cm);
1359 gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
1360 const gboolean flag)
1362 GValue v = G_VALUE_INIT;
1363 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1370 gnc_commodity_begin_edit(cm);
1375 g_value_init (&v, G_TYPE_STRING);
1376 g_value_set_string (&v,
"false");
1380 mark_commodity_dirty(cm);
1381 gnc_commodity_commit_edit(cm);
1394 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1402 priv = GET_PRIVATE(cm);
1403 gnc_commodity_begin_edit(cm);
1414 gnc_commodity_set_auto_quote_control_flag(cm,
1415 (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1417 gnc_commodity_commit_edit(cm);
1428 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1431 gnc_commodity_begin_edit(cm);
1432 GET_PRIVATE(cm)->quote_flag = flag;
1433 mark_commodity_dirty(cm);
1434 gnc_commodity_commit_edit(cm);
1445 ENTER (
"(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name :
"unknown");
1448 gnc_commodity_begin_edit(cm);
1449 GET_PRIVATE(cm)->quote_source = src;
1450 mark_commodity_dirty(cm);
1451 gnc_commodity_commit_edit(cm);
1466 ENTER (
"(cm=%p, tz=%s)", cm, tz ? tz :
"(null)");
1468 priv = GET_PRIVATE(cm);
1470 if (tz == priv->quote_tz)
1472 LEAVE(
"Already correct TZ");
1476 gnc_commodity_begin_edit(cm);
1477 CACHE_REMOVE (priv->quote_tz);
1478 priv->quote_tz = CACHE_INSERT (tz);
1479 mark_commodity_dirty(cm);
1480 gnc_commodity_commit_edit(cm);
1495 priv = GET_PRIVATE(cm);
1497 ENTER (
"(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol :
"(null)");
1499 lc = gnc_localeconv();
1500 if (!user_symbol || !*user_symbol)
1503 !g_strcmp0(lc->currency_symbol, user_symbol))
1510 if (priv->user_symbol != is_unset)
1512 if (!g_strcmp0 (user_symbol, priv->user_symbol))
1514 LEAVE (
"gnc_commodity_set_user_symbol: no change");
1517 g_free (priv->user_symbol);
1520 gnc_commodity_begin_edit (cm);
1524 GValue v = G_VALUE_INIT;
1525 g_value_init (&v, G_TYPE_STRING);
1526 g_value_set_string (&v, user_symbol);
1528 priv->user_symbol = g_strdup (user_symbol);
1534 priv->user_symbol = NULL;
1537 mark_commodity_dirty(cm);
1538 gnc_commodity_commit_edit(cm);
1549 gnc_commodity_set_default_symbol(gnc_commodity * cm,
1550 const char * default_symbol)
1552 GET_PRIVATE(cm)->default_symbol = default_symbol;
1564 ENTER(
"(cm=%p)", cm);
1572 priv = GET_PRIVATE(cm);
1574 if ((priv->usage_count == 0) && !priv->quote_flag
1575 && gnc_commodity_get_auto_quote_control_flag(cm)
1580 gnc_commodity_begin_edit(cm);
1583 gnc_commodity_get_default_quote_source(cm));
1584 gnc_commodity_commit_edit(cm);
1586 priv->usage_count++;
1587 LEAVE(
"(usage_count=%d)", priv->usage_count);
1599 ENTER(
"(cm=%p)", cm);
1607 priv = GET_PRIVATE(cm);
1609 if (priv->usage_count == 0)
1611 PWARN(
"usage_count already zero");
1616 priv->usage_count--;
1617 if ((priv->usage_count == 0) && priv->quote_flag
1618 && gnc_commodity_get_auto_quote_control_flag(cm)
1625 LEAVE(
"(usage_count=%d)", priv->usage_count);
1643 if (a == b)
return TRUE;
1644 if (!a || !b)
return FALSE;
1646 priv_a = GET_PRIVATE(a);
1647 priv_b = GET_PRIVATE(b);
1648 if (priv_a->name_space != priv_b->name_space)
return FALSE;
1649 if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
return FALSE;
1660 if (a == b)
return TRUE;
1664 DEBUG (
"one is NULL");
1668 priv_a = GET_PRIVATE(a);
1669 priv_b = GET_PRIVATE(b);
1672 if ((same_book && priv_a->name_space != priv_b->name_space)
1676 DEBUG (
"namespaces differ: %p(%s) vs %p(%s)",
1682 if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
1684 DEBUG (
"mnemonics differ: %s vs %s", priv_a->mnemonic, priv_b->mnemonic);
1688 if (g_strcmp0(priv_a->fullname, priv_b->fullname) != 0)
1690 DEBUG (
"fullnames differ: %s vs %s", priv_a->fullname, priv_b->fullname);
1694 if (g_strcmp0(priv_a->cusip, priv_b->cusip) != 0)
1696 DEBUG (
"cusips differ: %s vs %s", priv_a->cusip, priv_b->cusip);
1700 if (priv_a->fraction != priv_b->fraction)
1702 DEBUG (
"fractions differ: %d vs %d", priv_a->fraction, priv_b->fraction);
1742 if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
1743 return GNC_COMMODITY_NS_ISO_GUI;
1753 return name_space->cm_list;
1759 return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1760 (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1763 static const gchar *
1764 gnc_commodity_table_map_namespace(
const char * name_space)
1766 if (g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0)
1767 return GNC_COMMODITY_NS_CURRENCY;
1776 gnc_commodity_table *
1779 gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1780 retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1781 retval->ns_list = NULL;
1789 gnc_commodity_table *
1792 if (!book)
return NULL;
1799 gnc_commodity *twin;
1801 gnc_commodity_table * comtbl;
1803 if (!from)
return NULL;
1805 if (!comtbl)
return NULL;
1808 twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1823 count_coms(gpointer key, gpointer value, gpointer user_data)
1825 GHashTable *tbl = ((gnc_commodity_namespace*)value)->cm_table;
1826 guint *count = (guint*)user_data;
1828 if (g_strcmp0((
char*)key, GNC_COMMODITY_NS_CURRENCY) == 0)
1836 *count += g_hash_table_size(tbl);
1843 g_return_val_if_fail(tbl, 0);
1844 g_return_val_if_fail(tbl->ns_table, 0);
1846 g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1857 gnc_commodity_table_lookup(
const gnc_commodity_table *
table,
1858 const char * name_space,
const char * mnemonic)
1860 gnc_commodity_namespace * nsp = NULL;
1863 if (!
table || !name_space || !mnemonic)
return NULL;
1875 for (i = 0; i < GNC_NEW_ISO_CODES; i++)
1877 if (strcmp(mnemonic, gnc_new_iso_codes[i].old_code) == 0)
1879 mnemonic = gnc_new_iso_codes[i].new_code;
1884 return g_hash_table_lookup(nsp->cm_table, (gpointer)mnemonic);
1898 gnc_commodity_table_lookup_unique(
const gnc_commodity_table *
table,
1899 const char * unique_name)
1903 gnc_commodity *commodity;
1905 if (!
table || !unique_name)
return NULL;
1907 name_space = g_strdup (unique_name);
1908 mnemonic = strstr (name_space,
"::");
1911 g_free (name_space);
1918 commodity = gnc_commodity_table_lookup (
table, name_space, mnemonic);
1920 g_free (name_space);
1931 gnc_commodity_table_find_full(
const gnc_commodity_table *
table,
1932 const char * name_space,
1933 const char * fullname)
1935 gnc_commodity * retval = NULL;
1939 if (!fullname || (fullname[0] ==
'\0'))
1944 for (iterator = all; iterator; iterator = iterator->next)
1946 if (!strcmp(fullname,
1949 retval = iterator->data;
1967 gnc_commodity * comm)
1969 gnc_commodity_namespace * nsp = NULL;
1971 const char *ns_name;
1975 if (!
table)
return NULL;
1976 if (!comm)
return NULL;
1978 priv = GET_PRIVATE(comm);
1980 ENTER (
"(table=%p, comm=%p) %s %s",
table, comm,
1981 (priv->mnemonic == NULL ?
"(null)" : priv->mnemonic),
1982 (priv->fullname == NULL ?
"(null)" : priv->fullname));
1984 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1990 LEAVE(
"already in table");
1996 if (priv->name_space->iso4217)
1999 for (i = 0; i < GNC_NEW_ISO_CODES; i++)
2002 || !strcmp(priv->mnemonic, gnc_new_iso_codes[i].old_code))
2011 LEAVE(
"found at %p", c);
2016 if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
2017 g_strcmp0 (priv->mnemonic,
"template") != 0)
2019 PWARN(
"Converting commodity %s from namespace template to " 2020 "namespace User", priv->mnemonic);
2023 mark_commodity_dirty (comm);
2029 PINFO (
"insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
2030 nsp->cm_table, nsp->name);
2031 g_hash_table_insert(nsp->cm_table,
2032 (gpointer)CACHE_INSERT(priv->mnemonic),
2034 nsp->cm_list = g_list_append(nsp->cm_list, comm);
2048 gnc_commodity * comm)
2050 gnc_commodity_namespace * nsp;
2053 const char *ns_name;
2058 priv = GET_PRIVATE(comm);
2060 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
2061 if (c != comm)
return;
2068 nsp->cm_list = g_list_remove(nsp->cm_list, comm);
2069 g_hash_table_remove (nsp->cm_table, priv->mnemonic);
2080 const char * name_space)
2082 gnc_commodity_namespace * nsp = NULL;
2084 if (!
table || !name_space)
2101 hash_keys_helper(gpointer key, gpointer value, gpointer data)
2104 *l = g_list_prepend(*l, key);
2108 g_hash_table_keys(GHashTable *
table)
2111 g_hash_table_foreach(
table, &hash_keys_helper, (gpointer) &l);
2116 hash_values_helper(gpointer key, gpointer value, gpointer data)
2119 *l = g_list_prepend(*l, value);
2123 g_hash_table_values(GHashTable *
table)
2126 g_hash_table_foreach(
table, &hash_values_helper, (gpointer) &l);
2141 return g_hash_table_keys(
table->ns_table);
2150 return table->ns_list;
2164 if (!cm)
return FALSE;
2166 priv = GET_PRIVATE(cm);
2167 if ( !priv->name_space)
return FALSE;
2168 return priv->name_space->iso4217;
2174 const char *ns_name;
2175 if (!cm)
return FALSE;
2179 !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
2187 static CommodityList*
2188 commodity_table_get_all_noncurrency_commodities(
const gnc_commodity_table*
table)
2191 CommodityList *retval = NULL;
2192 for (node = nslist; node; node=g_list_next(node))
2194 gnc_commodity_namespace *ns = NULL;
2195 if (g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_CURRENCY) == 0
2196 || g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_TEMPLATE) == 0)
2201 retval = g_list_concat(g_hash_table_values(ns->cm_table), retval);
2203 g_list_free(nslist);
2209 const char * name_space)
2211 gnc_commodity_namespace * ns = NULL;
2215 if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONISO_GUI) == 0)
2216 return commodity_table_get_all_noncurrency_commodities(
table);
2221 return g_hash_table_values(ns->cm_table);
2230 get_quotables_helper1(gpointer key, gpointer value, gpointer data)
2232 gnc_commodity *comm = value;
2236 if (!priv->quote_flag ||
2237 !priv->quote_source || !priv->quote_source->supported)
2239 *l = g_list_prepend(*l, value);
2243 get_quotables_helper2 (gnc_commodity *comm, gpointer data)
2248 if (!priv->quote_flag ||
2249 !priv->quote_source || !priv->quote_source->supported)
2251 *l = g_list_prepend(*l, comm);
2258 gnc_commodity_namespace * ns = NULL;
2259 const char *name_space;
2260 GList * nslist, * tmp;
2263 const char *expression = gnc_prefs_get_namespace_regexp();
2265 ENTER(
"table=%p, expression=%s",
table, expression);
2269 if (expression && *expression)
2271 if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2273 LEAVE(
"Cannot compile regex");
2278 for (tmp = nslist; tmp; tmp = tmp->next)
2280 name_space = tmp->data;
2281 if (regexec(&pattern, name_space, 0, NULL, 0) == 0)
2283 DEBUG(
"Running list of %s commodities", name_space);
2287 g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2291 g_list_free(nslist);
2299 LEAVE(
"list head %p", l);
2309 QOF_GOBJECT_IMPL(gnc_commodity_namespace, gnc_commodity_namespace, QOF_TYPE_INSTANCE);
2312 gnc_commodity_namespace_init(gnc_commodity_namespace* ns)
2317 gnc_commodity_namespace_dispose_real (GObject *nsp)
2322 gnc_commodity_namespace_finalize_real(GObject* nsp)
2326 gnc_commodity_namespace *
2328 const char * name_space,
2331 gnc_commodity_namespace * ns = NULL;
2333 if (!
table)
return NULL;
2335 name_space = gnc_commodity_table_map_namespace(name_space);
2339 ns = g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, NULL);
2340 ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2341 ns->name = CACHE_INSERT((gpointer)name_space);
2346 g_hash_table_insert(
table->ns_table,
2347 (gpointer) ns->name,
2349 table->ns_list = g_list_append(
table->ns_list, ns);
2356 gnc_commodity_namespace *
2358 const char * name_space)
2360 if (!
table || !name_space)
2363 name_space = gnc_commodity_table_map_namespace(name_space);
2364 return g_hash_table_lookup(
table->ns_table, (gpointer)name_space);
2369 gnc_commodity_find_commodity_by_guid(
const GncGUID *guid, QofBook *book)
2372 if (!guid || !book)
return NULL;
2383 ns_helper(gpointer key, gpointer value, gpointer user_data)
2385 gnc_commodity * c = value;
2393 const char * name_space)
2395 gnc_commodity_namespace * ns;
2404 g_hash_table_remove(
table->ns_table, name_space);
2405 table->ns_list = g_list_remove(
table->ns_list, ns);
2407 g_list_free(ns->cm_list);
2410 g_hash_table_foreach_remove(ns->cm_table, ns_helper, NULL);
2411 g_hash_table_destroy(ns->cm_table);
2412 CACHE_REMOVE(ns->name);
2428 gboolean (*func)(gnc_commodity *, gpointer);
2433 iter_commodity (gpointer key, gpointer value, gpointer user_data)
2436 gnc_commodity *cm = (gnc_commodity *) value;
2440 iter_data->ok = (iter_data->func)(cm, iter_data->user_data);
2445 iter_namespace (gpointer key, gpointer value, gpointer user_data)
2447 GHashTable *namespace_hash = ((gnc_commodity_namespace *) value)->cm_table;
2448 g_hash_table_foreach (namespace_hash, iter_commodity, user_data);
2453 gboolean (*f)(gnc_commodity *, gpointer),
2458 if (!tbl || !f)
return FALSE;
2460 iter_data.ok = TRUE;
2462 iter_data.user_data = user_data;
2464 g_hash_table_foreach(tbl->ns_table, iter_namespace, (gpointer)&iter_data);
2466 return iter_data.ok;
2475 gnc_commodity_table_destroy(gnc_commodity_table * t)
2477 gnc_commodity_namespace * ns;
2481 ENTER (
"table=%p", t);
2483 for (item = t->ns_list; item; item = next)
2485 next = g_list_next(item);
2490 g_list_free(t->ns_list);
2492 g_hash_table_destroy(t->ns_table);
2494 LEAVE (
"table=%p", t);
2504 #define CUR_I18N(String) dgettext ("iso_4217", String) 2514 c =
gnc_commodity_new(book,
"template", GNC_COMMODITY_NS_TEMPLATE,
"template",
"template", 1);
2517 #include "iso-4217-currencies.c" 2542 static QofObject commodity_object_def =
2545 DI(.e_type = ) GNC_ID_COMMODITY,
2546 DI(.type_label = ) "Commodity",
2547 DI(.create = ) NULL,
2548 DI(.book_begin = ) NULL,
2549 DI(.book_end = ) NULL,
2556 static QofObject namespace_object_def =
2559 DI(.e_type = ) GNC_ID_COMMODITY_NAMESPACE,
2560 DI(.type_label = ) "Namespace",
2561 DI(.create = ) NULL,
2562 DI(.book_begin = ) NULL,
2563 DI(.book_end = ) NULL,
2564 DI(.is_dirty = ) NULL,
2565 DI(.mark_clean = ) NULL,
2566 DI(.foreach = ) NULL,
2567 DI(.printable = ) NULL,
2571 commodity_table_book_begin (QofBook *book)
2573 gnc_commodity_table *ct;
2574 ENTER (
"book=%p", book);
2584 PWARN(
"unable to initialize book's commodity_table");
2587 LEAVE (
"book=%p", book);
2591 commodity_table_book_end (QofBook *book)
2593 gnc_commodity_table *ct;
2597 gnc_commodity_table_destroy (ct);
2600 static QofObject commodity_table_object_def =
2603 DI(.e_type = ) GNC_ID_COMMODITY_TABLE,
2604 DI(.type_label = ) "CommodityTable",
2605 DI(.create = ) NULL,
2606 DI(.book_begin = ) commodity_table_book_begin,
2607 DI(.book_end = ) commodity_table_book_end,
2610 DI(.foreach = ) NULL,
2611 DI(.printable = ) NULL,
2612 DI(.version_cmp = ) NULL,
2618 gnc_quote_source_init_tables();
2635 MonetaryList *l = list, *tmp;
2636 for (tmp = list; tmp; tmp = tmp->next)
2638 gnc_monetary *list_mon = tmp->data;
2650 gnc_monetary *new_mon = g_new0(gnc_monetary, 1);
2652 l = g_list_prepend(l, new_mon);
2663 MonetaryList *node, *next;
2664 for (node = list; node; node = next)
2666 gnc_monetary *mon = node->data;
2671 list = g_list_delete_link(list, node);
2682 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...
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...
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.
Use any denominator which gives an exactly correct ratio of numerator to denominator.
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.
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.
void qof_collection_foreach(const QofCollection *col, QofInstanceForeachCB cb_func, gpointer user_data)
Call the callback for each entity in the collection.
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.
void gnc_quote_source_set_fq_installed(const char *version_string, const GList *sources_list)
Update gnucash internal tables based on what Finance::Quote sources are installed.
#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
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.
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...