29 #include <glib/gi18n.h> 36 #include <qofinstance-p.h> 39 #include "gnc-locale-utils.h" 44 static QofLogModule log_module = GNC_MOD_COMMODITY;
73 gnc_commodity_namespace *name_space;
84 gnc_quote_source *quote_source;
92 const char *default_symbol;
95 #define GET_PRIVATE(o) \ 96 ((gnc_commodityPrivate*)gnc_commodity_get_instance_private((gnc_commodity*)o)) 100 QofInstanceClass parent_class;
103 static void commodity_free(gnc_commodity * cm);
104 static void gnc_commodity_set_default_symbol(gnc_commodity *,
const char *);
112 GHashTable * cm_table;
118 QofInstanceClass parent_class;
123 GHashTable * ns_table;
129 const char *old_code;
130 const char *new_code;
131 } gnc_new_iso_codes[] =
146 #define GNC_NEW_ISO_CODES \ 147 (sizeof(gnc_new_iso_codes) / sizeof(struct gnc_new_iso_code)) 149 static char *fq_version = NULL;
168 static gnc_quote_source currency_quote_source =
169 { TRUE, 0, 0,
"Currency",
"currency" };
175 static gnc_quote_source single_quote_sources[] =
177 { FALSE, 0, 0,
"Alphavantage, US",
"alphavantage" },
178 { FALSE, 0, 0,
"Amsterdam Euronext eXchange, NL",
"aex" },
179 { FALSE, 0, 0,
"American International Assurance, HK",
"aiahk" },
180 { FALSE, 0, 0,
"Association of Mutual Funds in India",
"amfiindia" },
181 { FALSE, 0, 0,
"Athens Stock Exchange, GR",
"asegr" },
182 { FALSE, 0, 0,
"Australian Stock Exchange, AU",
"asx" },
183 { FALSE, 0, 0,
"BAMOSZ funds, HU",
"bamosz" },
184 { FALSE, 0, 0,
"BMO NesbittBurns, CA",
"bmonesbittburns" },
185 { FALSE, 0, 0,
"Bucharest Stock Exchange, RO",
"bsero" },
186 { FALSE, 0, 0,
"Budapest Stock Exchange (BET), ex-BUX, HU",
"bse" },
187 { FALSE, 0, 0,
"Canada Mutual",
"canadamutual" },
188 { FALSE, 0, 0,
"Citywire Funds, GB",
"citywire" },
189 { FALSE, 0, 0,
"Colombo Stock Exchange, LK",
"cse" },
190 { FALSE, 0, 0,
"Cominvest, ex-Adig, DE",
"cominvest" },
191 { FALSE, 0, 0,
"Deka Investments, DE",
"deka" },
192 { FALSE, 0, 0,
"Dutch",
"dutch" },
193 { FALSE, 0, 0,
"DWS, DE",
"dwsfunds" },
194 { FALSE, 0, 0,
"Equinox Unit Trusts, ZA",
"za_unittrusts" },
195 { FALSE, 0, 0,
"Fidelity Direct",
"fidelity_direct" },
196 { FALSE, 0, 0,
"Fidelity Fixed",
"fidelityfixed" },
197 { FALSE, 0, 0,
"Finance Canada",
"financecanada" },
198 { FALSE, 0, 0,
"Financial Times Funds service, GB",
"ftfunds" },
199 { FALSE, 0, 0,
"Finanzpartner, DE",
"finanzpartner" },
200 { FALSE, 0, 0,
"First Trust Portfolios, US",
"ftportfolios" },
201 { FALSE, 0, 0,
"Fund Library, CA",
"fundlibrary" },
202 { FALSE, 0, 0,
"GoldMoney spot rates, JE",
"goldmoney" },
203 { FALSE, 0, 0,
"Greece",
"greece" },
204 { FALSE, 0, 0,
"Helsinki stock eXchange, FI",
"hex" },
205 { FALSE, 0, 0,
"Hungary",
"hu" },
206 { FALSE, 0, 0,
"India Mutual",
"indiamutual" },
207 { FALSE, 0, 0,
"Man Investments, AU",
"maninv" },
208 { FALSE, 0, 0,
"Morningstar, GB",
"mstaruk" },
209 { FALSE, 0, 0,
"Morningstar, JP",
"morningstarjp" },
210 { FALSE, 0, 0,
"Morningstar, SE",
"morningstar" },
211 { FALSE, 0, 0,
"Motley Fool, US",
"fool" },
212 { FALSE, 0, 0,
"New Zealand stock eXchange, NZ",
"nzx" },
213 { FALSE, 0, 0,
"Paris Stock Exchange/Boursorama, FR",
"bourso" },
214 { FALSE, 0, 0,
"Paris Stock Exchange/LeRevenu, FR",
"lerevenu" },
215 { FALSE, 0, 0,
"Platinum Asset Management, AU",
"platinum" },
216 { FALSE, 0, 0,
"Romania",
"romania" },
217 { FALSE, 0, 0,
"SIX Swiss Exchange funds, CH",
"sixfunds" },
218 { FALSE, 0, 0,
"SIX Swiss Exchange shares, CH",
"sixshares" },
219 { FALSE, 0, 0,
"Skandinaviska Enskilda Banken, SE",
"seb_funds" },
220 { FALSE, 0, 0,
"Sharenet, ZA",
"za" },
221 { FALSE, 0, 0,
"StockHouse Canada",
"stockhousecanada_fund" },
222 { FALSE, 0, 0,
"TD Waterhouse Funds, CA",
"tdwaterhouse" },
223 { FALSE, 0, 0,
"TD Efunds, CA",
"tdefunds" },
224 { FALSE, 0, 0,
"TIAA-CREF, US",
"tiaacref" },
225 { FALSE, 0, 0,
"Toronto Stock eXchange, CA",
"tsx" },
226 { FALSE, 0, 0,
"T. Rowe Price",
"troweprice" },
227 { FALSE, 0, 0,
"T. Rowe Price, US",
"troweprice_direct" },
228 { FALSE, 0, 0,
"Trustnet via tnetuk.pm, GB",
"tnetuk" },
229 { FALSE, 0, 0,
"Trustnet via trustnet.pm, GB",
"trustnet" },
230 { FALSE, 0, 0,
"U.K. Unit Trusts",
"uk_unit_trusts" },
231 { FALSE, 0, 0,
"Union Investment, DE",
"unionfunds" },
232 { FALSE, 0, 0,
"US Treasury Bonds",
"usfedbonds" },
233 { FALSE, 0, 0,
"US Govt. Thrift Savings Plan",
"tsp" },
234 { FALSE, 0, 0,
"Vanguard",
"vanguard" },
235 { FALSE, 0, 0,
"VWD, DE (unmaintained)",
"vwd" },
236 { FALSE, 0, 0,
"Yahoo as JSON",
"yahoo_json" },
237 { FALSE, 0, 0,
"Yahoo as YQL",
"yahoo_yql" },
240 static gnc_quote_source multiple_quote_sources[] =
242 { FALSE, 0, 0,
"Australia (ASX, ...)",
"australia" },
243 { FALSE, 0, 0,
"Canada (Alphavantage, TSX, ...)",
"canada" },
244 { FALSE, 0, 0,
"Canada Mutual (Fund Library, StockHouse, ...)",
"canadamutual" },
245 { FALSE, 0, 0,
"Dutch (AEX, ...)",
"dutch" },
246 { FALSE, 0, 0,
"Europe (asegr,.bsero, hex ...)",
"europe" },
247 { FALSE, 0, 0,
"Greece (ASE, ...)",
"greece" },
248 { FALSE, 0, 0,
"Hungary (Bamosz, BET, ...)",
"hu" },
249 { FALSE, 0, 0,
"India Mutual (AMFI, ...)",
"indiamutual" },
250 { FALSE, 0, 0,
"Fidelity (Fidelity, ...)",
"fidelity" },
251 { FALSE, 0, 0,
"Finland (HEX, ...)",
"finland" },
252 { FALSE, 0, 0,
"First Trust (First Trust, ...)",
"ftportfolios" },
253 { FALSE, 0, 0,
"France (bourso, ĺerevenu, ...)",
"france" },
254 { FALSE, 0, 0,
"Nasdaq (alphavantage, fool, ...)",
"nasdaq" },
255 { FALSE, 0, 0,
"New Zealand (NZX, ...)",
"nz" },
256 { FALSE, 0, 0,
"NYSE (alphavantage, fool, ...)",
"nyse" },
257 { FALSE, 0, 0,
"South Africa (Sharenet, ...)",
"za" },
258 { FALSE, 0, 0,
"Romania (BSE-RO, ...)",
"romania" },
259 { FALSE, 0, 0,
"T. Rowe Price",
"troweprice" },
260 { FALSE, 0, 0,
"U.K. Funds (citywire, FTfunds, MStar, tnetuk, ...)",
"ukfunds" },
261 { FALSE, 0, 0,
"U.K. Unit Trusts (trustnet, ...)",
"uk_unit_trusts" },
262 { FALSE, 0, 0,
"USA (Alphavantage, Fool, ...)",
"usa" },
265 static const int num_single_quote_sources =
266 sizeof(single_quote_sources) /
sizeof(gnc_quote_source);
267 static const int num_multiple_quote_sources =
268 sizeof(multiple_quote_sources) /
sizeof(gnc_quote_source);
269 static GList *new_quote_sources = NULL;
281 return (fq_version != NULL);
308 return num_single_quote_sources;
311 return num_multiple_quote_sources;
313 return g_list_length(new_quote_sources);
322 gnc_quote_source_init_tables (
void)
326 for (i = 0; i < num_single_quote_sources; i++)
329 single_quote_sources[i].index = i;
332 for (i = 0; i < num_multiple_quote_sources; i++)
335 multiple_quote_sources[i].index = i;
339 currency_quote_source.index = 0;
354 gnc_quote_source *new_source;
356 DEBUG(
"Creating new source %s", (source_name == NULL ?
"(null)" : source_name));
357 new_source = malloc(
sizeof(gnc_quote_source));
358 new_source->supported = supported;
360 new_source->index = g_list_length(new_quote_sources);
364 new_source->user_name = g_strdup(source_name);
369 new_source->internal_name = g_strdup(source_name);
370 new_quote_sources = g_list_append(new_quote_sources, new_source);
382 gnc_quote_source *source;
385 ENTER(
"type/index is %d/%d", type, index);
389 LEAVE(
"found %s", currency_quote_source.user_name);
390 return ¤cy_quote_source;
394 if (index < num_single_quote_sources)
396 LEAVE(
"found %s", single_quote_sources[index].user_name);
397 return &single_quote_sources[index];
402 if (index < num_multiple_quote_sources)
404 LEAVE(
"found %s", multiple_quote_sources[index].user_name);
405 return &multiple_quote_sources[index];
411 node = g_list_nth(new_quote_sources, index);
415 LEAVE(
"found %s", source->user_name);
428 gnc_quote_source *source;
432 if ((name == NULL) || (g_strcmp0(name,
"") == 0))
437 if (g_strcmp0(name, currency_quote_source.internal_name) == 0)
438 return ¤cy_quote_source;
440 for (i = 0; i < num_single_quote_sources; i++)
442 if (g_strcmp0(name, single_quote_sources[i].internal_name) == 0)
443 return &single_quote_sources[i];
446 for (i = 0; i < num_multiple_quote_sources; i++)
448 if (g_strcmp0(name, multiple_quote_sources[i].internal_name) == 0)
449 return &multiple_quote_sources[i];
452 for (i = 0, node = new_quote_sources; node; node = node->next, i++)
455 if (g_strcmp0(name, source->internal_name) == 0)
459 DEBUG(
"gnc_quote_source_lookup_by_internal: Unknown source %s", name);
478 LEAVE(
"type is %d", source->type);
492 LEAVE(
"index is %d", source->index);
493 return source->index;
506 LEAVE(
"%ssupported", source && source->supported ?
"" :
"not ");
507 return source->supported;
519 LEAVE(
"user name %s", source->user_name);
520 return source->user_name;
532 LEAVE(
"internal name %s", source->internal_name);
533 return source->internal_name;
545 const GList *sources_list)
547 gnc_quote_source *source;
563 fq_version = g_strdup (version_string);
565 for (node = sources_list; node; node = node->next)
567 source_name = node->data;
572 DEBUG(
"Found source %s: %s", source_name, source->user_name);
573 source->supported = TRUE;
587 gnc_commodity_begin_edit (gnc_commodity *cm)
594 PERR (
"Failed to commit: %d", errcode);
595 gnc_engine_signal_commit_error( errcode );
603 commodity_free( GNC_COMMODITY(inst) );
607 gnc_commodity_commit_edit (gnc_commodity *cm)
618 mark_commodity_dirty (gnc_commodity *cm)
620 qof_instance_set_dirty(&cm->inst);
627 g_free(priv->printname);
628 priv->printname = g_strdup_printf(
"%s (%s)",
629 priv->mnemonic ? priv->mnemonic :
"",
630 priv->fullname ? priv->fullname :
"");
636 gnc_commodity_namespace *ns;
638 g_free(priv->unique_name);
639 ns = priv->name_space;
640 priv->unique_name = g_strdup_printf(
"%s::%s",
642 priv->mnemonic ? priv->mnemonic :
"");
646 G_DEFINE_TYPE_WITH_PRIVATE(gnc_commodity, gnc_commodity, QOF_TYPE_INSTANCE)
649 gnc_commodity_init(gnc_commodity* com)
653 priv = GET_PRIVATE(com);
655 priv->name_space = NULL;
656 priv->fullname = CACHE_INSERT(
"");
657 priv->mnemonic = CACHE_INSERT(
"");
658 priv->cusip = CACHE_INSERT(
"");
659 priv->fraction = 10000;
660 priv->quote_flag = 0;
661 priv->quote_source = NULL;
662 priv->quote_tz = CACHE_INSERT(
"");
664 reset_printname(priv);
665 reset_unique_name(priv);
669 gnc_commodity_dispose(GObject *comp)
671 G_OBJECT_CLASS(gnc_commodity_parent_class)->dispose(comp);
675 gnc_commodity_finalize(GObject* comp)
677 G_OBJECT_CLASS(gnc_commodity_parent_class)->finalize(comp);
686 gnc_commodity_get_property (GObject *
object,
691 gnc_commodity *commodity;
694 g_return_if_fail(GNC_IS_COMMODITY(
object));
696 commodity = GNC_COMMODITY(
object);
697 priv = GET_PRIVATE(commodity);
701 g_value_take_object(value, priv->name_space);
704 g_value_set_string(value, priv->fullname);
707 g_value_set_string(value, priv->mnemonic);
710 g_value_set_string(value, priv->printname);
713 g_value_set_string(value, priv->cusip);
716 g_value_set_int(value, priv->fraction);
718 case PROP_UNIQUE_NAME:
719 g_value_set_string(value, priv->unique_name);
721 case PROP_QUOTE_FLAG:
722 g_value_set_boolean(value, priv->quote_flag);
724 case PROP_QUOTE_SOURCE:
725 g_value_set_pointer(value, priv->quote_source);
728 g_value_set_string(value, priv->quote_tz);
731 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
737 gnc_commodity_set_property (GObject *
object,
742 gnc_commodity *commodity;
744 g_return_if_fail(GNC_IS_COMMODITY(
object));
746 commodity = GNC_COMMODITY(
object);
747 g_assert (qof_instance_get_editlevel(commodity));
766 case PROP_QUOTE_FLAG:
769 case PROP_QUOTE_SOURCE:
776 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
783 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
785 gobject_class->dispose = gnc_commodity_dispose;
786 gobject_class->finalize = gnc_commodity_finalize;
787 gobject_class->set_property = gnc_commodity_set_property;
788 gobject_class->get_property = gnc_commodity_get_property;
790 g_object_class_install_property(gobject_class,
792 g_param_spec_object (
"namespace",
794 "The namespace field denotes the " 795 "namespace for this commodity, either " 796 "a currency or symbol from a quote source.",
797 GNC_TYPE_COMMODITY_NAMESPACE,
799 g_object_class_install_property(gobject_class,
801 g_param_spec_string (
"fullname",
802 "Full Commodity Name",
803 "The fullname is the official full name of" 807 g_object_class_install_property(gobject_class,
809 g_param_spec_string (
"mnemonic",
810 "Commodity Mnemonic",
811 "The mnemonic is the official abbreviated" 812 "designation for the currency.",
815 g_object_class_install_property(gobject_class,
817 g_param_spec_string (
"printname",
818 "Commodity Print Name",
819 "Printable form of the commodity name.",
822 g_object_class_install_property(gobject_class,
824 g_param_spec_string (
"cusip",
825 "Commodity CUSIP Code",
829 g_object_class_install_property(gobject_class,
831 g_param_spec_int (
"fraction",
833 "The fraction is the number of sub-units that " 834 "the basic commodity can be divided into.",
839 g_object_class_install_property(gobject_class,
841 g_param_spec_string (
"unique-name",
842 "Commodity Unique Name",
843 "Unique form of the commodity name which combines " 844 "the namespace name and the commodity name.",
847 g_object_class_install_property(gobject_class,
849 g_param_spec_boolean (
"quote_flag",
851 "TRUE if prices are to be downloaded for this " 852 "commodity from a quote source.",
855 g_object_class_install_property(gobject_class,
857 g_param_spec_pointer(
"quote-source",
859 "The quote source from which prices are downloaded.",
861 g_object_class_install_property(gobject_class,
863 g_param_spec_string (
"quote-tz",
864 "Commodity Quote Timezone",
872 const char * name_space,
const char * mnemonic,
873 const char * cusip,
int fraction)
875 gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
878 gnc_commodity_begin_edit(retval);
880 if ( name_space != NULL )
883 if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
884 g_strcmp0 (mnemonic,
"template") != 0)
886 PWARN(
"Converting commodity %s from namespace template to " 887 "namespace User", mnemonic);
901 mark_commodity_dirty (retval);
902 gnc_commodity_commit_edit(retval);
915 commodity_free(gnc_commodity * cm)
918 gnc_commodity_table *
table;
926 priv = GET_PRIVATE(cm);
931 CACHE_REMOVE (priv->fullname);
932 CACHE_REMOVE (priv->cusip);
933 CACHE_REMOVE (priv->mnemonic);
934 CACHE_REMOVE (priv->quote_tz);
935 priv->name_space = NULL;
938 priv->quote_source = NULL;
941 g_free(priv->printname);
942 priv->printname = NULL;
944 g_free(priv->unique_name);
945 priv->unique_name = NULL;
947 #ifdef ACCOUNTS_CLEANED_UP 952 if (priv->usage_count != 0)
954 PWARN(
"Destroying commodity (%p) with non-zero usage_count (%d).", cm,
966 gnc_commodity_begin_edit(cm);
967 qof_instance_set_destroying(cm, TRUE);
968 gnc_commodity_commit_edit(cm);
979 dest_priv->name_space = src_priv->name_space;
985 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
994 gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
996 src_priv = GET_PRIVATE(src);
997 dest_priv = GET_PRIVATE(dest);
999 dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
1000 dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
1001 dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
1002 dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
1004 dest_priv->name_space = src_priv->name_space;
1006 dest_priv->fraction = src_priv->fraction;
1007 dest_priv->quote_flag = src_priv->quote_flag;
1011 qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
1013 reset_printname(dest_priv);
1014 reset_unique_name(dest_priv);
1026 if (!cm)
return NULL;
1027 return GET_PRIVATE(cm)->mnemonic;
1037 if (!cm)
return NULL;
1038 return GET_PRIVATE(cm)->printname;
1049 if (!cm)
return NULL;
1053 gnc_commodity_namespace *
1056 if (!cm)
return NULL;
1057 return GET_PRIVATE(cm)->name_space;
1067 if (!cm)
return NULL;
1068 return GET_PRIVATE(cm)->fullname;
1079 if (!cm)
return NULL;
1080 return GET_PRIVATE(cm)->unique_name;
1091 if (!cm)
return NULL;
1092 return GET_PRIVATE(cm)->cusip;
1103 return GET_PRIVATE(cm)->fraction;
1111 gnc_commodity_get_auto_quote_control_flag(
const gnc_commodity *cm)
1113 GValue v = G_VALUE_INIT;
1114 gboolean retval = TRUE;
1116 if (!cm)
return FALSE;
1118 if (G_VALUE_HOLDS_STRING (&v) &&
1119 strcmp(g_value_get_string (&v),
"false") == 0)
1132 if (!cm)
return FALSE;
1133 return (GET_PRIVATE(cm)->quote_flag);
1145 if (!cm)
return NULL;
1146 priv = GET_PRIVATE(cm);
1148 return ¤cy_quote_source;
1149 return priv->quote_source;
1153 gnc_commodity_get_default_quote_source(
const gnc_commodity *cm)
1156 return ¤cy_quote_source;
1168 if (!cm)
return NULL;
1169 return GET_PRIVATE(cm)->quote_tz;
1178 g_return_val_if_fail (GNC_IS_COMMODITY (cm), NULL);
1180 GValue v = G_VALUE_INIT;
1182 const char *rv = G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (&v) : NULL;
1193 if (!cm)
return NULL;
1194 return GET_PRIVATE(cm)->default_symbol;
1203 const char *nice_symbol;
1205 if (!cm)
return NULL;
1208 if (nice_symbol && *nice_symbol)
1211 lc = gnc_localeconv();
1212 nice_symbol = lc->currency_symbol;
1217 if (nice_symbol && *nice_symbol)
1233 priv = GET_PRIVATE(cm);
1234 if (priv->mnemonic == mnemonic)
return;
1236 gnc_commodity_begin_edit(cm);
1237 CACHE_REMOVE (priv->mnemonic);
1238 priv->mnemonic = CACHE_INSERT(mnemonic);
1240 mark_commodity_dirty (cm);
1241 reset_printname(priv);
1242 reset_unique_name(priv);
1243 gnc_commodity_commit_edit(cm);
1254 gnc_commodity_table *
table;
1255 gnc_commodity_namespace *nsp;
1259 priv = GET_PRIVATE(cm);
1263 if (priv->name_space == nsp)
1266 gnc_commodity_begin_edit(cm);
1267 priv->name_space = nsp;
1270 mark_commodity_dirty(cm);
1271 reset_printname(priv);
1272 reset_unique_name(priv);
1273 gnc_commodity_commit_edit(cm);
1286 priv = GET_PRIVATE(cm);
1287 if (priv->fullname == fullname)
return;
1289 CACHE_REMOVE (priv->fullname);
1290 priv->fullname = CACHE_INSERT (fullname);
1292 gnc_commodity_begin_edit(cm);
1293 mark_commodity_dirty(cm);
1294 reset_printname(priv);
1295 gnc_commodity_commit_edit(cm);
1310 priv = GET_PRIVATE(cm);
1311 if (priv->cusip == cusip)
return;
1313 gnc_commodity_begin_edit(cm);
1314 CACHE_REMOVE (priv->cusip);
1315 priv->cusip = CACHE_INSERT (cusip);
1316 mark_commodity_dirty(cm);
1317 gnc_commodity_commit_edit(cm);
1328 gnc_commodity_begin_edit(cm);
1329 GET_PRIVATE(cm)->fraction = fraction;
1330 mark_commodity_dirty(cm);
1331 gnc_commodity_commit_edit(cm);
1339 gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
1340 const gboolean flag)
1342 GValue v = G_VALUE_INIT;
1343 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1350 gnc_commodity_begin_edit(cm);
1355 g_value_init (&v, G_TYPE_STRING);
1356 g_value_set_string (&v,
"false");
1360 mark_commodity_dirty(cm);
1361 gnc_commodity_commit_edit(cm);
1374 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1382 priv = GET_PRIVATE(cm);
1383 gnc_commodity_begin_edit(cm);
1394 gnc_commodity_set_auto_quote_control_flag(cm,
1395 (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1397 gnc_commodity_commit_edit(cm);
1408 ENTER (
"(cm=%p, flag=%d)", cm, flag);
1411 gnc_commodity_begin_edit(cm);
1412 GET_PRIVATE(cm)->quote_flag = flag;
1413 mark_commodity_dirty(cm);
1414 gnc_commodity_commit_edit(cm);
1425 ENTER (
"(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name :
"unknown");
1428 gnc_commodity_begin_edit(cm);
1429 GET_PRIVATE(cm)->quote_source = src;
1430 mark_commodity_dirty(cm);
1431 gnc_commodity_commit_edit(cm);
1446 ENTER (
"(cm=%p, tz=%s)", cm, tz ? tz :
"(null)");
1448 priv = GET_PRIVATE(cm);
1450 if (tz == priv->quote_tz)
1452 LEAVE(
"Already correct TZ");
1456 gnc_commodity_begin_edit(cm);
1457 CACHE_REMOVE (priv->quote_tz);
1458 priv->quote_tz = CACHE_INSERT (tz);
1459 mark_commodity_dirty(cm);
1460 gnc_commodity_commit_edit(cm);
1475 ENTER (
"(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol :
"(null)");
1477 lc = gnc_localeconv();
1478 if (!user_symbol || !*user_symbol)
1481 !g_strcmp0(lc->currency_symbol, user_symbol))
1488 gnc_commodity_begin_edit (cm);
1492 GValue v = G_VALUE_INIT;
1493 g_value_init (&v, G_TYPE_STRING);
1494 g_value_set_static_string (&v, user_symbol);
1503 mark_commodity_dirty(cm);
1504 gnc_commodity_commit_edit(cm);
1515 gnc_commodity_set_default_symbol(gnc_commodity * cm,
1516 const char * default_symbol)
1518 GET_PRIVATE(cm)->default_symbol = default_symbol;
1530 ENTER(
"(cm=%p)", cm);
1538 priv = GET_PRIVATE(cm);
1540 if ((priv->usage_count == 0) && !priv->quote_flag
1541 && gnc_commodity_get_auto_quote_control_flag(cm)
1546 gnc_commodity_begin_edit(cm);
1549 gnc_commodity_get_default_quote_source(cm));
1550 gnc_commodity_commit_edit(cm);
1552 priv->usage_count++;
1553 LEAVE(
"(usage_count=%d)", priv->usage_count);
1565 ENTER(
"(cm=%p)", cm);
1573 priv = GET_PRIVATE(cm);
1575 if (priv->usage_count == 0)
1577 PWARN(
"usage_count already zero");
1582 priv->usage_count--;
1583 if ((priv->usage_count == 0) && priv->quote_flag
1584 && gnc_commodity_get_auto_quote_control_flag(cm)
1591 LEAVE(
"(usage_count=%d)", priv->usage_count);
1609 if (a == b)
return TRUE;
1610 if (!a || !b)
return FALSE;
1612 priv_a = GET_PRIVATE(a);
1613 priv_b = GET_PRIVATE(b);
1614 if (priv_a->name_space != priv_b->name_space)
return FALSE;
1615 if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
return FALSE;
1630 if (a == b)
return 0;
1631 if (a && !b)
return 1;
1632 if (b && !a)
return -1;
1659 if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
1660 return GNC_COMMODITY_NS_ISO_GUI;
1670 return name_space->cm_list;
1676 return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1677 (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1680 static const gchar *
1681 gnc_commodity_table_map_namespace(
const char * name_space)
1683 if (g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0)
1684 return GNC_COMMODITY_NS_CURRENCY;
1693 gnc_commodity_table *
1696 gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1697 retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1698 retval->ns_list = NULL;
1706 gnc_commodity_table *
1709 if (!book)
return NULL;
1716 gnc_commodity *twin;
1718 gnc_commodity_table * comtbl;
1720 if (!from)
return NULL;
1722 if (!comtbl)
return NULL;
1725 twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1740 count_coms(gpointer key, gpointer value, gpointer user_data)
1742 GHashTable *tbl = ((gnc_commodity_namespace*)value)->cm_table;
1743 guint *count = (guint*)user_data;
1745 if (g_strcmp0((
char*)key, GNC_COMMODITY_NS_CURRENCY) == 0)
1753 *count += g_hash_table_size(tbl);
1760 g_return_val_if_fail(tbl, 0);
1761 g_return_val_if_fail(tbl->ns_table, 0);
1763 g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1774 gnc_commodity_table_lookup(
const gnc_commodity_table *
table,
1775 const char * name_space,
const char * mnemonic)
1777 gnc_commodity_namespace * nsp = NULL;
1780 if (!
table || !name_space || !mnemonic)
return NULL;
1792 for (i = 0; i < GNC_NEW_ISO_CODES; i++)
1794 if (strcmp(mnemonic, gnc_new_iso_codes[i].old_code) == 0)
1796 mnemonic = gnc_new_iso_codes[i].new_code;
1801 return g_hash_table_lookup(nsp->cm_table, (gpointer)mnemonic);
1815 gnc_commodity_table_lookup_unique(
const gnc_commodity_table *
table,
1816 const char * unique_name)
1820 gnc_commodity *commodity;
1822 if (!
table || !unique_name)
return NULL;
1824 name_space = g_strdup (unique_name);
1825 mnemonic = strstr (name_space,
"::");
1828 g_free (name_space);
1835 commodity = gnc_commodity_table_lookup (
table, name_space, mnemonic);
1837 g_free (name_space);
1848 gnc_commodity_table_find_full(
const gnc_commodity_table *
table,
1849 const char * name_space,
1850 const char * fullname)
1852 gnc_commodity * retval = NULL;
1856 if (!fullname || (fullname[0] ==
'\0'))
1861 for (iterator = all; iterator; iterator = iterator->next)
1863 if (!strcmp(fullname,
1866 retval = iterator->data;
1884 gnc_commodity * comm)
1886 gnc_commodity_namespace * nsp = NULL;
1888 const char *ns_name;
1892 if (!
table)
return NULL;
1893 if (!comm)
return NULL;
1895 priv = GET_PRIVATE(comm);
1897 ENTER (
"(table=%p, comm=%p) %s %s",
table, comm,
1898 (priv->mnemonic == NULL ?
"(null)" : priv->mnemonic),
1899 (priv->fullname == NULL ?
"(null)" : priv->fullname));
1901 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1907 LEAVE(
"already in table");
1913 if (priv->name_space->iso4217)
1916 for (i = 0; i < GNC_NEW_ISO_CODES; i++)
1919 || !strcmp(priv->mnemonic, gnc_new_iso_codes[i].old_code))
1928 LEAVE(
"found at %p", c);
1933 if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
1934 g_strcmp0 (priv->mnemonic,
"template") != 0)
1936 PWARN(
"Converting commodity %s from namespace template to " 1937 "namespace User", priv->mnemonic);
1940 mark_commodity_dirty (comm);
1946 PINFO (
"insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1947 nsp->cm_table, nsp->name);
1948 g_hash_table_insert(nsp->cm_table,
1949 (gpointer)CACHE_INSERT(priv->mnemonic),
1951 nsp->cm_list = g_list_append(nsp->cm_list, comm);
1965 gnc_commodity * comm)
1967 gnc_commodity_namespace * nsp;
1970 const char *ns_name;
1975 priv = GET_PRIVATE(comm);
1977 c = gnc_commodity_table_lookup (
table, ns_name, priv->mnemonic);
1978 if (c != comm)
return;
1985 nsp->cm_list = g_list_remove(nsp->cm_list, comm);
1986 g_hash_table_remove (nsp->cm_table, priv->mnemonic);
1997 const char * name_space)
1999 gnc_commodity_namespace * nsp = NULL;
2001 if (!
table || !name_space)
2018 hash_keys_helper(gpointer key, gpointer value, gpointer data)
2021 *l = g_list_prepend(*l, key);
2025 g_hash_table_keys(GHashTable *
table)
2028 g_hash_table_foreach(
table, &hash_keys_helper, (gpointer) &l);
2033 hash_values_helper(gpointer key, gpointer value, gpointer data)
2036 *l = g_list_prepend(*l, value);
2040 g_hash_table_values(GHashTable *
table)
2043 g_hash_table_foreach(
table, &hash_values_helper, (gpointer) &l);
2058 return g_hash_table_keys(
table->ns_table);
2067 return table->ns_list;
2081 if (!cm)
return FALSE;
2083 priv = GET_PRIVATE(cm);
2084 if ( !priv->name_space)
return FALSE;
2085 return priv->name_space->iso4217;
2091 const char *ns_name;
2092 if (!cm)
return FALSE;
2096 !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
2104 static CommodityList*
2105 commodity_table_get_all_noncurrency_commodities(
const gnc_commodity_table*
table)
2108 CommodityList *retval = NULL;
2109 for (node = nslist; node; node=g_list_next(node))
2111 gnc_commodity_namespace *ns = NULL;
2112 if (g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_CURRENCY) == 0
2113 || g_strcmp0((
char*)(node->data), GNC_COMMODITY_NS_TEMPLATE) == 0)
2118 retval = g_list_concat(g_hash_table_values(ns->cm_table), retval);
2120 g_list_free(nslist);
2126 const char * name_space)
2128 gnc_commodity_namespace * ns = NULL;
2132 if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONISO_GUI) == 0)
2133 return commodity_table_get_all_noncurrency_commodities(
table);
2138 return g_hash_table_values(ns->cm_table);
2147 get_quotables_helper1(gpointer key, gpointer value, gpointer data)
2149 gnc_commodity *comm = value;
2153 if (!priv->quote_flag ||
2154 !priv->quote_source || !priv->quote_source->supported)
2156 *l = g_list_prepend(*l, value);
2160 get_quotables_helper2 (gnc_commodity *comm, gpointer data)
2165 if (!priv->quote_flag ||
2166 !priv->quote_source || !priv->quote_source->supported)
2168 *l = g_list_prepend(*l, comm);
2175 gnc_commodity_namespace * ns = NULL;
2176 const char *name_space;
2177 GList * nslist, * tmp;
2180 const char *expression = gnc_prefs_get_namespace_regexp();
2182 ENTER(
"table=%p, expression=%s",
table, expression);
2186 if (expression && *expression)
2188 if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2190 LEAVE(
"Cannot compile regex");
2195 for (tmp = nslist; tmp; tmp = tmp->next)
2197 name_space = tmp->data;
2198 if (regexec(&pattern, name_space, 0, NULL, 0) == 0)
2200 DEBUG(
"Running list of %s commodities", name_space);
2204 g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2208 g_list_free(nslist);
2216 LEAVE(
"list head %p", l);
2226 QOF_GOBJECT_IMPL(gnc_commodity_namespace, gnc_commodity_namespace, QOF_TYPE_INSTANCE)
2229 gnc_commodity_namespace_init(gnc_commodity_namespace* ns)
2234 gnc_commodity_namespace_dispose_real (GObject *nsp)
2239 gnc_commodity_namespace_finalize_real(GObject* nsp)
2243 gnc_commodity_namespace *
2245 const char * name_space,
2248 gnc_commodity_namespace * ns = NULL;
2250 if (!
table)
return NULL;
2252 name_space = gnc_commodity_table_map_namespace(name_space);
2256 ns = g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, NULL);
2257 ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2258 ns->name = CACHE_INSERT((gpointer)name_space);
2263 g_hash_table_insert(
table->ns_table,
2264 (gpointer) ns->name,
2266 table->ns_list = g_list_append(
table->ns_list, ns);
2273 gnc_commodity_namespace *
2275 const char * name_space)
2277 if (!
table || !name_space)
2280 name_space = gnc_commodity_table_map_namespace(name_space);
2281 return g_hash_table_lookup(
table->ns_table, (gpointer)name_space);
2286 gnc_commodity_find_commodity_by_guid(
const GncGUID *guid, QofBook *book)
2289 if (!guid || !book)
return NULL;
2300 ns_helper(gpointer key, gpointer value, gpointer user_data)
2302 gnc_commodity * c = value;
2310 const char * name_space)
2312 gnc_commodity_namespace * ns;
2321 g_hash_table_remove(
table->ns_table, name_space);
2322 table->ns_list = g_list_remove(
table->ns_list, ns);
2324 g_list_free(ns->cm_list);
2327 g_hash_table_foreach_remove(ns->cm_table, ns_helper, NULL);
2328 g_hash_table_destroy(ns->cm_table);
2329 CACHE_REMOVE(ns->name);
2345 gboolean (*func)(gnc_commodity *, gpointer);
2350 iter_commodity (gpointer key, gpointer value, gpointer user_data)
2353 gnc_commodity *cm = (gnc_commodity *) value;
2357 iter_data->ok = (iter_data->func)(cm, iter_data->user_data);
2362 iter_namespace (gpointer key, gpointer value, gpointer user_data)
2364 GHashTable *namespace_hash = ((gnc_commodity_namespace *) value)->cm_table;
2365 g_hash_table_foreach (namespace_hash, iter_commodity, user_data);
2370 gboolean (*f)(gnc_commodity *, gpointer),
2375 if (!tbl || !f)
return FALSE;
2377 iter_data.ok = TRUE;
2379 iter_data.user_data = user_data;
2381 g_hash_table_foreach(tbl->ns_table, iter_namespace, (gpointer)&iter_data);
2383 return iter_data.ok;
2392 gnc_commodity_table_destroy(gnc_commodity_table * t)
2394 gnc_commodity_namespace * ns;
2398 ENTER (
"table=%p", t);
2400 for (item = t->ns_list; item; item = next)
2402 next = g_list_next(item);
2407 g_list_free(t->ns_list);
2409 g_hash_table_destroy(t->ns_table);
2411 LEAVE (
"table=%p", t);
2421 #define CUR_I18N(String) dgettext ("iso_4217", String) 2431 c =
gnc_commodity_new(book,
"template", GNC_COMMODITY_NS_TEMPLATE,
"template",
"template", 1);
2434 #include "iso-4217-currencies.c" 2459 static QofObject commodity_object_def =
2462 DI(.e_type = ) GNC_ID_COMMODITY,
2463 DI(.type_label = ) "Commodity",
2464 DI(.create = ) NULL,
2465 DI(.book_begin = ) NULL,
2466 DI(.book_end = ) NULL,
2473 static QofObject namespace_object_def =
2476 DI(.e_type = ) GNC_ID_COMMODITY_NAMESPACE,
2477 DI(.type_label = ) "Namespace",
2478 DI(.create = ) NULL,
2479 DI(.book_begin = ) NULL,
2480 DI(.book_end = ) NULL,
2481 DI(.is_dirty = ) NULL,
2482 DI(.mark_clean = ) NULL,
2483 DI(.foreach = ) NULL,
2484 DI(.printable = ) NULL,
2488 commodity_table_book_begin (QofBook *book)
2490 gnc_commodity_table *ct;
2491 ENTER (
"book=%p", book);
2501 PWARN(
"unable to initialize book's commodity_table");
2504 LEAVE (
"book=%p", book);
2508 commodity_table_book_end (QofBook *book)
2510 gnc_commodity_table *ct;
2514 gnc_commodity_table_destroy (ct);
2517 static QofObject commodity_table_object_def =
2520 DI(.e_type = ) GNC_ID_COMMODITY_TABLE,
2521 DI(.type_label = ) "CommodityTable",
2522 DI(.create = ) NULL,
2523 DI(.book_begin = ) commodity_table_book_begin,
2524 DI(.book_end = ) commodity_table_book_end,
2527 DI(.foreach = ) NULL,
2528 DI(.printable = ) NULL,
2529 DI(.version_cmp = ) NULL,
2535 gnc_quote_source_init_tables();
2552 MonetaryList *l = list, *tmp;
2553 for (tmp = list; tmp; tmp = tmp->next)
2555 gnc_monetary *list_mon = tmp->data;
2567 gnc_monetary *new_mon = g_new0(gnc_monetary, 1);
2569 l = g_list_prepend(l, new_mon);
2580 MonetaryList *node, *next;
2581 for (node = list; node; node = next)
2583 gnc_monetary *mon = node->data;
2588 list = g_list_delete_link(list, node);
2599 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...
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.
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.
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...