GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Files | Data Structures | Macros | Typedefs | Functions

Files

file  gnc-commodity.h
 Commodity handling public routines.
 

Data Structures

struct  _gnc_monetary
 

Macros

#define GNC_TYPE_COMMODITY   (gnc_commodity_get_type ())
 
#define GNC_COMMODITY(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_COMMODITY, gnc_commodity))
 
#define GNC_COMMODITY_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_COMMODITY, gnc_commodityClass))
 
#define GNC_IS_COMMODITY(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_COMMODITY))
 
#define GNC_IS_COMMODITY_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_COMMODITY))
 
#define GNC_COMMODITY_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_COMMODITY, gnc_commodityClass))
 
#define GNC_TYPE_COMMODITY_NAMESPACE   (gnc_commodity_namespace_get_type ())
 
#define GNC_COMMODITY_NAMESPACE(o)   (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespace))
 
#define GNC_COMMODITY_NAMESPACE_CLASS(k)   (G_TYPE_CHECK_CLASS_CAST((k), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespaceClass))
 
#define GNC_IS_COMMODITY_NAMESPACE(o)   (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_COMMODITY_NAMESPACE))
 
#define GNC_IS_COMMODITY_NAMESPACE_CLASS(k)   (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_COMMODITY_NAMESPACE))
 
#define GNC_COMMODITY_NAMESPACE_GET_CLASS(o)   (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_COMMODITY_NAMESPACE, gnc_commodity_namespaceClass))
 
#define GNC_COMMODITY_TABLE   "gnc_commodity_table"
 
#define GNC_COMMODITY_NS_LEGACY   "GNC_LEGACY_CURRENCIES"
 
#define GNC_COMMODITY_NS_ISO   "ISO4217"
 
#define GNC_COMMODITY_NS_CURRENCY   "CURRENCY"
 
#define GNC_COMMODITY_NS_NASDAQ   "NASDAQ"
 
#define GNC_COMMODITY_NS_NYSE   "NYSE"
 
#define GNC_COMMODITY_NS_EUREX   "EUREX"
 
#define GNC_COMMODITY_NS_MUTUAL   "FUND"
 
#define GNC_COMMODITY_NS_AMEX   "AMEX"
 
#define GNC_COMMODITY_NS_ASX   "ASX"
 

Typedefs

typedef struct _GncCommodityClass gnc_commodityClass
 
typedef struct
_GncCommodityNamespaceClass 
gnc_commodity_namespaceClass
 
typedef GList CommodityList
 

Functions

GType gnc_commodity_get_type (void)
 
GType gnc_commodity_namespace_get_type (void)
 

Commodity Quote Source functions

enum  QuoteSourceType {
  SOURCE_SINGLE = 0, SOURCE_MULTI, SOURCE_UNKNOWN, SOURCE_MAX,
  SOURCE_CURRENCY = SOURCE_MAX
}
 
gboolean gnc_quote_source_fq_installed (void)
 
void gnc_quote_source_set_fq_installed (const GList *sources_list)
 
gint gnc_quote_source_num_entries (QuoteSourceType type)
 
gnc_quote_sourcegnc_quote_source_add_new (const char *name, gboolean supported)
 
gnc_quote_sourcegnc_quote_source_lookup_by_internal (const char *internal_name)
 
gnc_quote_sourcegnc_quote_source_lookup_by_ti (QuoteSourceType type, gint index)
 
gboolean gnc_quote_source_get_supported (const gnc_quote_source *source)
 
QuoteSourceType gnc_quote_source_get_type (const gnc_quote_source *source)
 
gint gnc_quote_source_get_index (const gnc_quote_source *source)
 
const char * gnc_quote_source_get_user_name (const gnc_quote_source *source)
 
const char * gnc_quote_source_get_internal_name (const gnc_quote_source *source)
 

Commodity Creation

gnc_commoditygnc_commodity_new (QofBook *book, const char *fullname, const char *commodity_namespace, const char *mnemonic, const char *cusip, int fraction)
 
void gnc_commodity_destroy (gnc_commodity *cm)
 
void gnc_commodity_copy (gnc_commodity *dest, const gnc_commodity *src)
 
gnc_commoditygnc_commodity_clone (const gnc_commodity *src, QofBook *dest_book)
 

Commodity Accessor Routines - Get

const char * gnc_commodity_get_mnemonic (const gnc_commodity *cm)
 
const char * gnc_commodity_get_namespace (const gnc_commodity *cm)
 
const char * gnc_commodity_get_namespace_compat (const gnc_commodity *cm)
 
gnc_commodity_namespacegnc_commodity_get_namespace_ds (const gnc_commodity *cm)
 
const char * gnc_commodity_get_fullname (const gnc_commodity *cm)
 
const char * gnc_commodity_get_printname (const gnc_commodity *cm)
 
const char * gnc_commodity_get_cusip (const gnc_commodity *cm)
 
const char * gnc_commodity_get_unique_name (const gnc_commodity *cm)
 
int gnc_commodity_get_fraction (const gnc_commodity *cm)
 
gboolean gnc_commodity_get_quote_flag (const gnc_commodity *cm)
 
gnc_quote_sourcegnc_commodity_get_quote_source (const gnc_commodity *cm)
 
gnc_quote_sourcegnc_commodity_get_default_quote_source (const gnc_commodity *cm)
 
const char * gnc_commodity_get_quote_tz (const gnc_commodity *cm)
 
const char * gnc_commodity_get_user_symbol (const gnc_commodity *cm)
 
const char * gnc_commodity_get_default_symbol (const gnc_commodity *cm)
 
const char * gnc_commodity_get_nice_symbol (const gnc_commodity *cm)
 

Commodity Accessor Routines - Set

void gnc_commodity_set_mnemonic (gnc_commodity *cm, const char *mnemonic)
 
void gnc_commodity_set_namespace (gnc_commodity *cm, const char *new_namespace)
 
void gnc_commodity_set_fullname (gnc_commodity *cm, const char *fullname)
 
void gnc_commodity_set_cusip (gnc_commodity *cm, const char *cusip)
 
void gnc_commodity_set_fraction (gnc_commodity *cm, int smallest_fraction)
 
void gnc_commodity_user_set_quote_flag (gnc_commodity *cm, const gboolean flag)
 
void gnc_commodity_set_quote_flag (gnc_commodity *cm, const gboolean flag)
 
void gnc_commodity_set_quote_source (gnc_commodity *cm, gnc_quote_source *src)
 
void gnc_commodity_set_quote_tz (gnc_commodity *cm, const char *tz)
 
void gnc_commodity_set_user_symbol (gnc_commodity *cm, const char *user_symbol)
 

Commodity Usage Count Adjustment Routines

void gnc_commodity_increment_usage_count (gnc_commodity *cm)
 
void gnc_commodity_decrement_usage_count (gnc_commodity *cm)
 

Commodity Comparison

gboolean gnc_commodity_equiv (const gnc_commodity *a, const gnc_commodity *b)
 
gboolean gnc_commodity_equal (const gnc_commodity *a, const gnc_commodity *b)
 
int gnc_commodity_compare (const gnc_commodity *a, const gnc_commodity *b)
 
int gnc_commodity_compare_void (const void *a, const void *b)
 

Currency Checks

gboolean gnc_commodity_namespace_is_iso (const char *commodity_namespace)
 
gboolean gnc_commodity_is_iso (const gnc_commodity *cm)
 
gboolean gnc_commodity_is_currency (const gnc_commodity *cm)
 

Commodity Table

gnc_commodity_tablegnc_commodity_table_get_table (QofBook *book)
 

Commodity Table Lookup functions

gnc_commoditygnc_commodity_table_lookup (const gnc_commodity_table *table, const char *commodity_namespace, const char *mnemonic)
 
gnc_commoditygnc_commodity_table_lookup_unique (const gnc_commodity_table *table, const char *unique_name)
 
gnc_commoditygnc_commodity_table_find_full (const gnc_commodity_table *t, const char *commodity_namespace, const char *fullname)
 
gnc_commoditygnc_commodity_find_commodity_by_guid (const GncGUID *guid, QofBook *book)
 

Commodity Table Maintenance functions

gnc_commoditygnc_commodity_table_insert (gnc_commodity_table *table, gnc_commodity *comm)
 
void gnc_commodity_table_remove (gnc_commodity_table *table, gnc_commodity *comm)
 
gboolean gnc_commodity_table_add_default_data (gnc_commodity_table *table, QofBook *book)
 

Commodity Table Namespace functions

const char * gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns)
 
GList * gnc_commodity_namespace_get_commodity_list (const gnc_commodity_namespace *ns)
 
int gnc_commodity_table_has_namespace (const gnc_commodity_table *table, const char *commodity_namespace)
 
GList * gnc_commodity_table_get_namespaces (const gnc_commodity_table *t)
 
GList * gnc_commodity_table_get_namespaces_list (const gnc_commodity_table *t)
 
gnc_commodity_namespacegnc_commodity_table_add_namespace (gnc_commodity_table *table, const char *commodity_namespace, QofBook *book)
 
gnc_commodity_namespacegnc_commodity_table_find_namespace (const gnc_commodity_table *table, const char *commodity_namespace)
 
void gnc_commodity_table_delete_namespace (gnc_commodity_table *table, const char *commodity_namespace)
 

Commodity Table Accessor functions

guint gnc_commodity_table_get_size (const gnc_commodity_table *tbl)
 
CommodityList * gnc_commodity_table_get_commodities (const gnc_commodity_table *table, const char *commodity_namespace)
 
CommodityList * gnc_commodity_table_get_quotable_commodities (const gnc_commodity_table *table)
 
gboolean gnc_commodity_table_foreach_commodity (const gnc_commodity_table *table, gboolean(*f)(gnc_commodity *cm, gpointer user_data), gpointer user_data)
 

Commodity Table Private/Internal-Use Only Routines

gnc_commodity_tablegnc_commodity_table_new (void)
 
void gnc_commodity_table_destroy (gnc_commodity_table *table)
 
gnc_commoditygnc_commodity_obtain_twin (const gnc_commodity *findlike, QofBook *book)
 
gboolean gnc_commodity_table_register (void)
 
void gnc_commodity_begin_edit (gnc_commodity *cm)
 
void gnc_commodity_commit_edit (gnc_commodity *cm)
 
#define gnc_commodity_get_kvp_frame(cm)   qof_instance_get_slots(QOF_INSTANCE(cm))
 

Monetary value, commodity identity and numeric value

typedef struct _gnc_monetary gnc_monetary
 
typedef GList MonetaryList
 

Manipulate MonetaryList lists

MonetaryList * gnc_monetary_list_add_monetary (MonetaryList *list, gnc_monetary mon)
 
MonetaryList * gnc_monetary_list_delete_zeros (MonetaryList *list)
 
void gnc_monetary_list_free (MonetaryList *list)
 

Detailed Description

A commodity is something of value that is easily tradeable or sellable; for example, currencies, stocks, bonds, grain, copper, and oil are all commodities. This file provides an API for defining a commodities, and for working with collections of commodities. All GnuCash financial transactions must identify the commodity that is being traded.

Warning
The system used here does not follow the object handling and identification system (GncGUID's, Entities, etc.) that the other parts of GnuCash use. The API really should be ported over. This would allow us to get rid of the commodity table routines defined below.

Macro Definition Documentation

#define gnc_commodity_get_kvp_frame (   cm)    qof_instance_get_slots(QOF_INSTANCE(cm))

Get the internal KVP from of the currency. You should rather use the individual accessors for individual properties

Definition at line 977 of file gnc-commodity.h.

#define GNC_COMMODITY_NS_LEGACY   "GNC_LEGACY_CURRENCIES"

The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the exchange where it is traded.

The LEGACY name is only used by the file i/o routines, and is converted to another commodity namespace before it is seen by the rest of the system. The ISO namespace represents currencies. With the exception of the NASDAQ namespace (which is used once in the binary importer) the rest of the namespace declarations are only used to populate an option menu in the commodity selection window.

Definition at line 97 of file gnc-commodity.h.

Enumeration Type Documentation

The quote source type enum account types are used to determine how the transaction data in the account is displayed. These values can be safely changed from one release to the next.

Enumerator
SOURCE_SINGLE 

This quote source pulls from a single specific web site. For example, the yahoo_australia source only pulls from the yahoo web site.

SOURCE_MULTI 

This quote source may pull from multiple web sites. For example, the australia source may pull from ASX, yahoo, etc.

SOURCE_UNKNOWN 

This is a locally installed quote source that gnucash knows nothing about. May pull from single or multiple locations.

SOURCE_CURRENCY 

The special currency quote source.

Definition at line 118 of file gnc-commodity.h.

119 {
120  SOURCE_SINGLE = 0,
124  SOURCE_MULTI,
131  SOURCE_MAX,
132  SOURCE_CURRENCY = SOURCE_MAX,
QuoteSourceType

Function Documentation

gnc_commodity* gnc_commodity_clone ( const gnc_commodity src,
QofBook dest_book 
)

allocate and copy

Definition at line 948 of file gnc-commodity.c.

949 {
950  CommodityPrivate* src_priv;
951  CommodityPrivate* dest_priv;
952 
953  gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
954  qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, dest_book);
955  src_priv = GET_PRIVATE(src);
956  dest_priv = GET_PRIVATE(dest);
957 
958  dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
959  dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
960  dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
961  dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
962 
963  dest_priv->name_space = src_priv->name_space;
964 
965  dest_priv->fraction = src_priv->fraction;
966  dest_priv->quote_flag = src_priv->quote_flag;
967 
969 
970  kvp_frame_delete (dest->inst.kvp_data);
971  dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
972 
973  reset_printname(dest_priv);
974  reset_unique_name(dest_priv);
975 
976  return dest;
977 }
KvpFrame * kvp_frame_copy(const KvpFrame *frame)
void kvp_frame_delete(KvpFrame *frame)
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
int gnc_commodity_compare ( const gnc_commodity a,
const gnc_commodity b 
)

This routine returns 0 if the two commodities are equal, 1 otherwise. Commodities are equal if they have the same namespace, mnemonic, fullname, exchange private code and fraction. This function is useful for list-traversal comparison purposes where The semantics are 0, <0, or >0 (equal, greater than, less than) rather than "true or false"

Definition at line 1625 of file gnc-commodity.c.

1626 {
1627  if (gnc_commodity_equal(a, b))
1628  {
1629  return 0;
1630  }
1631  else
1632  {
1633  return 1;
1634  }
1635 }
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
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_list_find_custom(), which needs void pointers instead of gnc_commodity ones.

Definition at line 1637 of file gnc-commodity.c.

1638 {
1639  return gnc_commodity_compare(a, b);
1640 }
int gnc_commodity_compare(const gnc_commodity *a, const gnc_commodity *b)
void gnc_commodity_copy ( gnc_commodity dest,
const gnc_commodity src 
)

Copy src into dest

Definition at line 930 of file gnc-commodity.c.

931 {
932  CommodityPrivate* src_priv = GET_PRIVATE(src);
933  CommodityPrivate* dest_priv = GET_PRIVATE(dest);
934 
935  gnc_commodity_set_fullname (dest, src_priv->fullname);
936  gnc_commodity_set_mnemonic (dest, src_priv->mnemonic);
937  dest_priv->name_space = src_priv->name_space;
938  gnc_commodity_set_fraction (dest, src_priv->fraction);
939  gnc_commodity_set_cusip (dest, src_priv->cusip);
940  gnc_commodity_set_quote_flag (dest, src_priv->quote_flag);
942  gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
943  kvp_frame_delete (dest->inst.kvp_data);
944  dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
945 }
void gnc_commodity_set_quote_tz(gnc_commodity *cm, const char *tz)
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
KvpFrame * kvp_frame_copy(const KvpFrame *frame)
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
void kvp_frame_delete(KvpFrame *frame)
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
gnc_quote_source * gnc_commodity_get_quote_source(const gnc_commodity *cm)
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
void gnc_commodity_decrement_usage_count ( gnc_commodity cm)

Decrement a commodity's internal counter that tracks how many accounts are using that commodity. For currencies, this may have the side effect of disabling the commodity's quote flag.

Parameters
cmA pointer to a commodity data structure.

Definition at line 1511 of file gnc-commodity.c.

1512 {
1513  CommodityPrivate* priv;
1514 
1515  ENTER("(cm=%p)", cm);
1516 
1517  if (!cm)
1518  {
1519  LEAVE("");
1520  return;
1521  }
1522 
1523  priv = GET_PRIVATE(cm);
1524 
1525  if (priv->usage_count == 0)
1526  {
1527  PWARN("usage_count already zero");
1528  LEAVE("");
1529  return;
1530  }
1531 
1532  priv->usage_count--;
1533  if ((priv->usage_count == 0) && priv->quote_flag
1534  && gnc_commodity_get_auto_quote_control_flag(cm)
1535  && gnc_commodity_is_iso(cm))
1536  {
1537  /* if this is a currency with auto quote control enabled and no more
1538  * accounts reference this currency, disable quote retrieval */
1539  gnc_commodity_set_quote_flag(cm, FALSE);
1540  }
1541  LEAVE("(usage_count=%d)", priv->usage_count);
1542 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
#define ENTER(format, args...)
Definition: qoflog.h:261
#define PWARN(format, args...)
Definition: qoflog.h:243
#define LEAVE(format, args...)
Definition: qoflog.h:271
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
void gnc_commodity_destroy ( gnc_commodity cm)

Destroy a commodity. Release all memory attached to this data structure.

Note
This function does not (can not) check to see if the commodity is referenced anywhere.
Parameters
cmThe commodity to destroy.

Definition at line 922 of file gnc-commodity.c.

923 {
924  gnc_commodity_begin_edit(cm);
925  qof_instance_set_destroying(cm, TRUE);
926  gnc_commodity_commit_edit(cm);
927 }
gboolean gnc_commodity_equal ( const gnc_commodity a,
const gnc_commodity b 
)

This routine returns TRUE if the two commodities are equal. Commodities are equal if they have the same namespace, mnemonic, fullname, exchange private code and fraction.

Definition at line 1570 of file gnc-commodity.c.

1571 {
1572  CommodityPrivate* priv_a;
1573  CommodityPrivate* priv_b;
1574  gboolean same_book;
1575 
1576  if (a == b) return TRUE;
1577 
1578  if (!a || !b)
1579  {
1580  DEBUG ("one is NULL");
1581  return FALSE;
1582  }
1583 
1584  priv_a = GET_PRIVATE(a);
1585  priv_b = GET_PRIVATE(b);
1586  same_book = qof_instance_get_book(QOF_INSTANCE(a)) == qof_instance_get_book(QOF_INSTANCE(b));
1587 
1588  if ((same_book && priv_a->name_space != priv_b->name_space)
1589  || (!same_book && g_strcmp0( gnc_commodity_namespace_get_name(priv_a->name_space),
1590  gnc_commodity_namespace_get_name(priv_b->name_space)) != 0))
1591  {
1592  DEBUG ("namespaces differ: %p(%s) vs %p(%s)",
1593  priv_a->name_space, gnc_commodity_namespace_get_name(priv_a->name_space),
1594  priv_b->name_space, gnc_commodity_namespace_get_name(priv_b->name_space));
1595  return FALSE;
1596  }
1597 
1598  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
1599  {
1600  DEBUG ("mnemonics differ: %s vs %s", priv_a->mnemonic, priv_b->mnemonic);
1601  return FALSE;
1602  }
1603 
1604  if (g_strcmp0(priv_a->fullname, priv_b->fullname) != 0)
1605  {
1606  DEBUG ("fullnames differ: %s vs %s", priv_a->fullname, priv_b->fullname);
1607  return FALSE;
1608  }
1609 
1610  if (g_strcmp0(priv_a->cusip, priv_b->cusip) != 0)
1611  {
1612  DEBUG ("cusips differ: %s vs %s", priv_a->cusip, priv_b->cusip);
1613  return FALSE;
1614  }
1615 
1616  if (priv_a->fraction != priv_b->fraction)
1617  {
1618  DEBUG ("fractions differ: %d vs %d", priv_a->fraction, priv_b->fraction);
1619  return FALSE;
1620  }
1621 
1622  return TRUE;
1623 }
QofBook * qof_instance_get_book(gconstpointer)
#define DEBUG(format, args...)
Definition: qoflog.h:255
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
gboolean gnc_commodity_equiv ( const gnc_commodity a,
const gnc_commodity b 
)

This routine returns TRUE if the two commodities are equivalent. Commodities are equivalent if they have the same namespace and mnemonic. Equivalent commodities may belong to different exchanges, may have different fullnames, and may have different fractions.

Definition at line 1554 of file gnc-commodity.c.

1555 {
1556  CommodityPrivate* priv_a;
1557  CommodityPrivate* priv_b;
1558 
1559  if (a == b) return TRUE;
1560  if (!a || !b) return FALSE;
1561 
1562  priv_a = GET_PRIVATE(a);
1563  priv_b = GET_PRIVATE(b);
1564  if (priv_a->name_space != priv_b->name_space) return FALSE;
1565  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0) return FALSE;
1566  return TRUE;
1567 }
const char* gnc_commodity_get_cusip ( const gnc_commodity cm)

Retrieve the 'exchange code' for the specified commodity. This will be a pointer to a null terminated string of the form "AXQ14728", etc. This field is often used when presenting information to the user.

Note
This is a unique code that specifies a particular item or set of shares of a commodity, not a code that specifies a stock exchange. That is the namespace field.
Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the exchange code for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 1065 of file gnc-commodity.c.

1066 {
1067  if (!cm) return NULL;
1068  return GET_PRIVATE(cm)->cusip;
1069 }
const char* gnc_commodity_get_default_symbol ( const gnc_commodity cm)

Retrieve the default symbol for the specified commodity. This will be a pointer to a nul terminated string like "£", "US$", etc. Note that for the locale currency, you probably want to look at the system-provided symbol first. See gnc_commodity_get_nice_symbol.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the default symbol for this commodity.

Definition at line 1159 of file gnc-commodity.c.

1160 {
1161  const char *str;
1162  if (!cm) return NULL;
1163  return GET_PRIVATE(cm)->default_symbol;
1164 }
int gnc_commodity_get_fraction ( const gnc_commodity cm)

Retrieve the fraction for the specified commodity. This will be an integer value specifying the number of fractional units that one of these commodities can be divided into. Should always be a power of 10.

Parameters
cmA pointer to a commodity data structure.
Returns
The number of fractional units that one of these commodities can be divided into.

Definition at line 1076 of file gnc-commodity.c.

1077 {
1078  if (!cm) return 0;
1079  return GET_PRIVATE(cm)->fraction;
1080 }
const char* gnc_commodity_get_fullname ( const gnc_commodity cm)

Retrieve the full name for the specified commodity. This will be a pointer to a null terminated string of the form "Acme Systems, Inc.", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the full name for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 1041 of file gnc-commodity.c.

1042 {
1043  if (!cm) return NULL;
1044  return GET_PRIVATE(cm)->fullname;
1045 }
const char* gnc_commodity_get_mnemonic ( const gnc_commodity cm)

Retrieve the mnemonic for the specified commodity. This will be a pointer to a null terminated string of the form "ACME", "QWER", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the mnemonic for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 984 of file gnc-commodity.c.

985 {
986  if (!cm) return NULL;
987  return GET_PRIVATE(cm)->mnemonic;
988 }
const char* gnc_commodity_get_namespace ( const gnc_commodity cm)

Retrieve the namespace for the specified commodity. This will be a pointer to a null terminated string of the form "AMEX", "NASDAQ", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the namespace for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 1007 of file gnc-commodity.c.

1008 {
1009  if (!cm) return NULL;
1010  return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
1011 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
const char* gnc_commodity_get_namespace_compat ( const gnc_commodity cm)

Retrieve the namespace for the specified commodity. This will be a pointer to a null terminated string of the form "AMEX", "NASDAQ", etc. The only difference between function and gnc_commodity_get_namespace() is that this function returns ISO4217 instead of CURRENCY for backward compatability with the 1.8 data files.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the namespace for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 1014 of file gnc-commodity.c.

1015 {
1016  CommodityPrivate* priv;
1017 
1018  if (!cm) return NULL;
1019  priv = GET_PRIVATE(cm);
1020  if (!priv->name_space) return NULL;
1021  if (priv->name_space->iso4217)
1022  {
1023  /* Data files are still written with ISO4217. */
1024  return GNC_COMMODITY_NS_ISO;
1025  }
1026  return gnc_commodity_namespace_get_name(priv->name_space);
1027 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
gnc_commodity_namespace* gnc_commodity_get_namespace_ds ( const gnc_commodity cm)

Retrieve the namespace data strucure for the specified commodity. This will be a pointer to another data structure.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the namespace data structure for this commodity.

Definition at line 1030 of file gnc-commodity.c.

1031 {
1032  if (!cm) return NULL;
1033  return GET_PRIVATE(cm)->name_space;
1034 }
const char* gnc_commodity_get_nice_symbol ( const gnc_commodity cm)

Retrieve a symbol for the specified commodity, suitable for display to the user. This will be a pointer to a nul terminated string like "£", "US$", etc. That function is locale-aware and will base its choice of symbol on the user-configured symbol, the locale a

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the symbol for this commodity.

Definition at line 1170 of file gnc-commodity.c.

1171 {
1172  const char *nice_symbol;
1173  struct lconv *lc;
1174  if (!cm) return NULL;
1175 
1176  nice_symbol = gnc_commodity_get_user_symbol(cm);
1177  if (nice_symbol && *nice_symbol)
1178  return nice_symbol;
1179 
1180  lc = gnc_localeconv();
1181  nice_symbol = lc->currency_symbol;
1182  if (!g_strcmp0(gnc_commodity_get_mnemonic(cm), lc->int_curr_symbol))
1183  return nice_symbol;
1184 
1185  nice_symbol = gnc_commodity_get_default_symbol(cm);
1186  if (nice_symbol && *nice_symbol)
1187  return nice_symbol;
1188 
1189  return gnc_commodity_get_mnemonic(cm);
1190 }
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
const char * gnc_commodity_get_user_symbol(const gnc_commodity *cm)
const char * gnc_commodity_get_default_symbol(const gnc_commodity *cm)
const char* gnc_commodity_get_printname ( const gnc_commodity cm)

Retrieve the 'print' name for the specified commodity. This will be a pointer to a null terminated string of the form "Acme Systems, Inc. (ACME)", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the print name for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 995 of file gnc-commodity.c.

996 {
997  if (!cm) return NULL;
998  return GET_PRIVATE(cm)->printname;
999 }
gboolean gnc_commodity_get_quote_flag ( const gnc_commodity cm)

Retrieve the automatic price quote flag for the specified commodity. This flag indicates whether stock quotes should be retrieved for the specified stock.

Parameters
cmA pointer to a commodity data structure.
Returns
TRUE if quotes should be pulled for this commodity, FALSE otherwise.

Definition at line 1102 of file gnc-commodity.c.

1103 {
1104  if (!cm) return FALSE;
1105  return (GET_PRIVATE(cm)->quote_flag);
1106 }
gnc_quote_source* gnc_commodity_get_quote_source ( const gnc_commodity cm)

Retrieve the automatic price quote source for the specified commodity. This will be a pointer to a null terminated string of the form "Yahoo (Asia)", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the price quote source for this commodity.

Definition at line 1113 of file gnc-commodity.c.

1114 {
1115  CommodityPrivate* priv;
1116 
1117  if (!cm) return NULL;
1118  priv = GET_PRIVATE(cm);
1119  if (!priv->quote_source && gnc_commodity_is_iso(cm))
1120  return &currency_quote_source;
1121  return priv->quote_source;
1122 }
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
const char* gnc_commodity_get_quote_tz ( const gnc_commodity cm)

Retrieve the automatic price quote timezone for the specified commodity. This will be a pointer to a null terminated string of the form "America/New_York", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the price quote timezone for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 1138 of file gnc-commodity.c.

1139 {
1140  if (!cm) return NULL;
1141  return GET_PRIVATE(cm)->quote_tz;
1142 }
const char* gnc_commodity_get_unique_name ( const gnc_commodity cm)

Retrieve the 'unique' name for the specified commodity. This will be a pointer to a null terminated string of the form "AMEX::ACME", etc. This field is often used when performing comparisons or other functions invisible to the user.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the 'unique' name for this commodity. This string is owned by the engine and should not be freed by the caller.

Definition at line 1053 of file gnc-commodity.c.

1054 {
1055  if (!cm) return NULL;
1056  return GET_PRIVATE(cm)->unique_name;
1057 }
const char* gnc_commodity_get_user_symbol ( const gnc_commodity cm)

Retrieve the user-defined symbol for the specified commodity. This will be a pointer to a nul terminated string like "£", "US$", etc.

Parameters
cmA pointer to a commodity data structure.
Returns
A pointer to the user-defined symbol for this commodity. NULL means that the user didn't define any symbol, and that fallback to e.g. the mnemonic is in order. This string is owned by the engine and should not be freed by the caller.

Definition at line 1148 of file gnc-commodity.c.

1149 {
1150  const char *str;
1151  if (!cm) return NULL;
1152  return kvp_frame_get_string(cm->inst.kvp_data, "user_symbol");
1153 }
void gnc_commodity_increment_usage_count ( gnc_commodity cm)

Increment a commodity's internal counter that tracks how many accounts are using that commodity. For currencies, this may have the side effect of enabling the commodity's quote flag.

Parameters
cmA pointer to a commodity data structure.

Definition at line 1476 of file gnc-commodity.c.

1477 {
1478  CommodityPrivate* priv;
1479 
1480  ENTER("(cm=%p)", cm);
1481 
1482  if (!cm)
1483  {
1484  LEAVE("");
1485  return;
1486  }
1487 
1488  priv = GET_PRIVATE(cm);
1489 
1490  if ((priv->usage_count == 0) && !priv->quote_flag
1491  && gnc_commodity_get_auto_quote_control_flag(cm)
1492  && gnc_commodity_is_iso(cm))
1493  {
1494  /* compatability hack - Gnucash 1.8 gets currency quotes when a
1495  non-default currency is assigned to an account. */
1496  gnc_commodity_begin_edit(cm);
1497  gnc_commodity_set_quote_flag(cm, TRUE);
1499  gnc_commodity_get_default_quote_source(cm));
1500  gnc_commodity_commit_edit(cm);
1501  }
1502  priv->usage_count++;
1503  LEAVE("(usage_count=%d)", priv->usage_count);
1504 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
#define ENTER(format, args...)
Definition: qoflog.h:261
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
#define LEAVE(format, args...)
Definition: qoflog.h:271
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
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.

Parameters
cmThe commodity to check.
Returns
TRUE if the commodity represents a currency, FALSE otherwise.

Definition at line 2078 of file gnc-commodity.c.

2079 {
2080  const char *ns_name;
2081  if (!cm) return FALSE;
2082 
2083  ns_name = gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
2084  return (!g_strcmp0(ns_name, GNC_COMMODITY_NS_LEGACY) ||
2085  !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
2086 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
#define GNC_COMMODITY_NS_LEGACY
Definition: gnc-commodity.h:97
gboolean gnc_commodity_is_iso ( const gnc_commodity cm)

Checks to see if the specified commodity is an ISO 4217 recognized currency.

Parameters
cmThe commodity to check.
Returns
TRUE if the commodity represents a currency, FALSE otherwise.

Definition at line 2066 of file gnc-commodity.c.

2067 {
2068  CommodityPrivate* priv;
2069 
2070  if (!cm) return FALSE;
2071 
2072  priv = GET_PRIVATE(cm);
2073  if ( !priv->name_space) return FALSE;
2074  return priv->name_space->iso4217;
2075 }
GList* gnc_commodity_namespace_get_commodity_list ( const gnc_commodity_namespace ns)

Return a list of all commodity data structures in the specified namespace.

Returns
A pointer to the list of structures. NULL if an invalid argument was supplied.
Note
This list is owned by the engine. The caller must not free the list.

Definition at line 1654 of file gnc-commodity.c.

1655 {
1656  if (!name_space)
1657  return NULL;
1658 
1659  return name_space->cm_list;
1660 }
const char* gnc_commodity_namespace_get_name ( const gnc_commodity_namespace ns)

Return the textual name of a namespace data strucure.

Parameters
nsA pointer to the namespace data strucure.
Returns
A pointer to the name of the namespace. This string is owned by the engine and should not be freed by the caller.

Definition at line 1646 of file gnc-commodity.c.

1647 {
1648  if (ns == NULL)
1649  return NULL;
1650  return ns->name;
1651 }
gboolean gnc_commodity_namespace_is_iso ( const char *  commodity_namespace)

Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.

Parameters
commodity_namespaceThe string to check.
Returns
TRUE if the string indicates an ISO currency, FALSE otherwise.

Definition at line 1663 of file gnc-commodity.c.

1664 {
1665  return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1666  (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1667 }
gnc_commodity* gnc_commodity_new ( QofBook book,
const char *  fullname,
const char *  commodity_namespace,
const char *  mnemonic,
const char *  cusip,
int  fraction 
)

Create a new commodity. This function allocates a new commodity data structure, populates it with the data provided, and then generates the dynamic names that exist as part of a commodity.

Note
This function does not check to see if the commodity exists before adding a new commodity.
Parameters
bookThe book that the new commodity will belong to.
fullnameThe complete name of this commodity. E.G. "Acme Systems, Inc."
commodity_namespaceAn aggregation of commodities. E.G. ISO4217, Nasdaq, Downbelow, etc.
mnemonicAn abbreviation for this stock. For publicly traced stocks, this field should contain the stock ticker symbol. This field is used to get online price quotes, so it must match the stock ticker symbol used by the exchange where you want to get automatic stock quote updates. E.G. ACME, ACME.US, etc.
cusipA string containing the CUSIP code or similar UNIQUE code for this commodity like the ISIN. The stock ticker is NOT appropriate as that goes in the mnemonic field.
fractionThe smallest division of this commodity allowed. I.E. If this is 1, then the commodity must be traded in whole units; if 100 then the commodity may be traded in 0.01 units, etc.
Returns
A pointer to the new commodity.

Definition at line 829 of file gnc-commodity.c.

832 {
833  gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
834 
835  qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
836  gnc_commodity_begin_edit(retval);
837 
838  if ( name_space != NULL )
839  {
840  /* Prevent setting anything except template in namespace template. */
841  if (g_strcmp0 (name_space, "template") == 0 &&
842  g_strcmp0 (mnemonic, "template") != 0)
843  {
844  PWARN("Converting commodity %s from namespace template to "
845  "namespace User", mnemonic);
846  name_space = "User";
847  }
848  gnc_commodity_set_namespace(retval, name_space);
849  if (gnc_commodity_namespace_is_iso(name_space))
850  {
853  }
854  }
855  gnc_commodity_set_fullname(retval, fullname);
856  gnc_commodity_set_mnemonic(retval, mnemonic);
857  gnc_commodity_set_cusip(retval, cusip);
858  gnc_commodity_set_fraction(retval, fraction);
859  mark_commodity_dirty (retval);
860  gnc_commodity_commit_edit(retval);
861 
862  qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL);
863 
864  return retval;
865 }
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
#define PWARN(format, args...)
Definition: qoflog.h:243
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
gnc_commodity* gnc_commodity_obtain_twin ( const gnc_commodity findlike,
QofBook book 
)

Given the commodity 'findlike', this routine will find and return the equivalent commodity (commodity with the same 'unique name') in the indicated book. This routine is primarily useful for setting up clones of things across multiple books.

Definition at line 1703 of file gnc-commodity.c.

1704 {
1705  gnc_commodity *twin;
1706  const char * ucom;
1707  gnc_commodity_table * comtbl;
1708 
1709  if (!from) return NULL;
1710  comtbl = gnc_commodity_table_get_table (book);
1711  if (!comtbl) return NULL;
1712 
1713  ucom = gnc_commodity_get_unique_name (from);
1714  twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1715  if (!twin)
1716  {
1717  twin = gnc_commodity_clone (from, book);
1718  twin = gnc_commodity_table_insert (comtbl, twin);
1719  }
1720  return twin;
1721 }
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
gnc_commodity * gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
void gnc_commodity_set_cusip ( gnc_commodity cm,
const char *  cusip 
)

Set the 'exchange code' for the specified commodity. This should be a pointer to a null terminated string of the form "AXQ14728", etc.

Note
This is a unique code that specifies a particular item or set of shares of a commodity, not a code that specifies a stock exchange. That is the namespace field.
Parameters
cmA pointer to a commodity data structure.
cusipA pointer to the cusip or other exchange specific data for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1272 of file gnc-commodity.c.

1274 {
1275  CommodityPrivate* priv;
1276 
1277  if (!cm) return;
1278 
1279  priv = GET_PRIVATE(cm);
1280  if (priv->cusip == cusip) return;
1281 
1282  gnc_commodity_begin_edit(cm);
1283  CACHE_REMOVE (priv->cusip);
1284  priv->cusip = CACHE_INSERT (cusip);
1285  mark_commodity_dirty(cm);
1286  gnc_commodity_commit_edit(cm);
1287 }
void gnc_commodity_set_fraction ( gnc_commodity cm,
int  smallest_fraction 
)

Set the fraction for the specified commodity. This should be an integer value specifying the number of fractional units that one of these commodities can be divided into. Should always be a power of 10.

Parameters
cmA pointer to a commodity data structure.
smallest_fractionThe number of fractional units that one of these commodities can be divided into.

Definition at line 1294 of file gnc-commodity.c.

1295 {
1296  if (!cm) return;
1297  gnc_commodity_begin_edit(cm);
1298  GET_PRIVATE(cm)->fraction = fraction;
1299  mark_commodity_dirty(cm);
1300  gnc_commodity_commit_edit(cm);
1301 }
void gnc_commodity_set_fullname ( gnc_commodity cm,
const char *  fullname 
)

Set the full name for the specified commodity. This should be a pointer to a null terminated string of the form "Acme Systems, Inc.", etc.

Parameters
cmA pointer to a commodity data structure.
fullnameA pointer to the full name for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1250 of file gnc-commodity.c.

1251 {
1252  CommodityPrivate* priv;
1253 
1254  if (!cm) return;
1255  priv = GET_PRIVATE(cm);
1256  if (priv->fullname == fullname) return;
1257 
1258  CACHE_REMOVE (priv->fullname);
1259  priv->fullname = CACHE_INSERT (fullname);
1260 
1261  gnc_commodity_begin_edit(cm);
1262  mark_commodity_dirty(cm);
1263  reset_printname(priv);
1264  gnc_commodity_commit_edit(cm);
1265 }
void gnc_commodity_set_mnemonic ( gnc_commodity cm,
const char *  mnemonic 
)

Set the mnemonic for the specified commodity. This should be a pointer to a null terminated string of the form "ACME", "QWER", etc.

Parameters
cmA pointer to a commodity data structure.
mnemonicA pointer to the mnemonic for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1197 of file gnc-commodity.c.

1198 {
1199  CommodityPrivate* priv;
1200 
1201  if (!cm) return;
1202  priv = GET_PRIVATE(cm);
1203  if (priv->mnemonic == mnemonic) return;
1204 
1205  gnc_commodity_begin_edit(cm);
1206  CACHE_REMOVE (priv->mnemonic);
1207  priv->mnemonic = CACHE_INSERT(mnemonic);
1208 
1209  mark_commodity_dirty (cm);
1210  reset_printname(priv);
1211  reset_unique_name(priv);
1212  gnc_commodity_commit_edit(cm);
1213 }
void gnc_commodity_set_namespace ( gnc_commodity cm,
const char *  new_namespace 
)

Set the namespace for the specified commodity. This should be a pointer to a null terminated string of the form "AMEX", "NASDAQ", etc.

Parameters
cmA pointer to a commodity data structure.
new_namespaceA pointer to the namespace for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1220 of file gnc-commodity.c.

1221 {
1222  QofBook *book;
1225  CommodityPrivate* priv;
1226 
1227  if (!cm) return;
1228  priv = GET_PRIVATE(cm);
1229  book = qof_instance_get_book (&cm->inst);
1230  table = gnc_commodity_table_get_table(book);
1231  nsp = gnc_commodity_table_add_namespace(table, name_space, book);
1232  if (priv->name_space == nsp)
1233  return;
1234 
1235  gnc_commodity_begin_edit(cm);
1236  priv->name_space = nsp;
1237  if (nsp->iso4217)
1238  priv->quote_source = gnc_quote_source_lookup_by_internal("currency");
1239  mark_commodity_dirty(cm);
1240  reset_printname(priv);
1241  reset_unique_name(priv);
1242  gnc_commodity_commit_edit(cm);
1243 }
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
QofBook * qof_instance_get_book(gconstpointer)
gnc_commodity_namespace * gnc_commodity_table_add_namespace(gnc_commodity_table *table, const char *name_space, QofBook *book)
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
void gnc_commodity_set_quote_flag ( gnc_commodity cm,
const gboolean  flag 
)

Set the automatic price quote flag for the specified commodity. This flag indicates whether stock quotes should be retrieved for the specified stock.

Parameters
cmA pointer to a commodity data structure.
flagTRUE if quotes should be pulled for this commodity, FALSE otherwise.

Definition at line 1368 of file gnc-commodity.c.

1369 {
1370  ENTER ("(cm=%p, flag=%d)", cm, flag);
1371 
1372  if (!cm) return;
1373  gnc_commodity_begin_edit(cm);
1374  GET_PRIVATE(cm)->quote_flag = flag;
1375  mark_commodity_dirty(cm);
1376  gnc_commodity_commit_edit(cm);
1377  LEAVE(" ");
1378 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
void gnc_commodity_set_quote_source ( gnc_commodity cm,
gnc_quote_source src 
)

Set the automatic price quote source for the specified commodity. This should be a pointer to a null terminated string of the form "Yahoo (Asia)", etc. Legal values can be found in the quote_sources array in the file gnc-ui-util.c.

Parameters
cmA pointer to a commodity data structure.
srcA pointer to the price quote source for this commodity.

Definition at line 1385 of file gnc-commodity.c.

1386 {
1387  ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name : "unknown");
1388 
1389  if (!cm) return;
1390  gnc_commodity_begin_edit(cm);
1391  GET_PRIVATE(cm)->quote_source = src;
1392  mark_commodity_dirty(cm);
1393  gnc_commodity_commit_edit(cm);
1394  LEAVE(" ");
1395 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
void gnc_commodity_set_quote_tz ( gnc_commodity cm,
const char *  tz 
)

Set the automatic price quote timezone for the specified commodity. This should be a pointer to a null terminated string of the form "America/New_York", etc. Legal values can be found in the known_timezones array in the file src/gnome-utils/dialog-commodity.c.

Parameters
cmA pointer to a commodity data structure.
tzA pointer to the price quote timezone for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1402 of file gnc-commodity.c.

1403 {
1404  CommodityPrivate* priv;
1405 
1406  if (!cm) return;
1407 
1408  ENTER ("(cm=%p, tz=%s)", cm, tz ? tz : "(null)");
1409 
1410  priv = GET_PRIVATE(cm);
1411 
1412  if (tz == priv->quote_tz)
1413  {
1414  LEAVE("Already correct TZ");
1415  return;
1416  }
1417 
1418  gnc_commodity_begin_edit(cm);
1419  CACHE_REMOVE (priv->quote_tz);
1420  priv->quote_tz = CACHE_INSERT (tz);
1421  mark_commodity_dirty(cm);
1422  gnc_commodity_commit_edit(cm);
1423  LEAVE(" ");
1424 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
void gnc_commodity_set_user_symbol ( gnc_commodity cm,
const char *  user_symbol 
)

Set a user-defined symbol for the specified commodity. This should be a pointer to a nul terminated string like "£", "US$", etc.

Parameters
cmA pointer to a commodity data structure.
tzA pointer to the symbol for this commodity. This string belongs to the caller and will be duplicated by the engine.

Definition at line 1431 of file gnc-commodity.c.

1432 {
1433  struct lconv *lc;
1434 
1435  if (!cm) return;
1436 
1437  ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
1438 
1439  gnc_commodity_begin_edit(cm);
1440 
1441  lc = gnc_localeconv();
1442  if (!user_symbol || !*user_symbol)
1443  user_symbol = NULL;
1444  else if (!g_strcmp0(lc->int_curr_symbol, gnc_commodity_get_mnemonic(cm)) &&
1445  !g_strcmp0(lc->currency_symbol, user_symbol))
1446  /* if the user gives the ISO symbol for the locale currency or the
1447  * default symbol, actually remove the user symbol */
1448  user_symbol = NULL;
1449  else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
1450  user_symbol = NULL;
1451 
1452  kvp_frame_set_string(cm->inst.kvp_data, "user_symbol", user_symbol);
1453  mark_commodity_dirty(cm);
1454  gnc_commodity_commit_edit(cm);
1455 
1456  LEAVE(" ");
1457 }
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
#define ENTER(format, args...)
Definition: qoflog.h:261
const char * gnc_commodity_get_default_symbol(const gnc_commodity *cm)
#define LEAVE(format, args...)
Definition: qoflog.h:271
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.
gboolean gnc_commodity_table_add_default_data ( gnc_commodity_table table,
QofBook book 
)

Add all the standard namespaces and currencies to the commodity table. This routine creates the namespaces for the NYSE, NASDAQ, etc. It also adds all of the ISO 4217 currencies to the commodity table.

Parameters
tableA pointer to the commodity table.
bookUnused.

Definition at line 2392 of file gnc-commodity.c.

2393 {
2394  QofCollection *col;
2395  gnc_commodity* c;
2396 
2397  ENTER ("table=%p", table);
2398  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_AMEX, book);
2399  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NYSE, book);
2400  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NASDAQ, book);
2401  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_EUREX, book);
2402  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_MUTUAL, book);
2403  gnc_commodity_table_add_namespace(table, "template", book);
2404  c = gnc_commodity_new(book, "template", "template", "template", "template", 1);
2405  gnc_commodity_table_insert(table, c);
2406 
2407 #include "iso-4217-currencies.c"
2408 
2409  /* We've just created the default namespaces and currencies. Mark
2410  * these collections as clean because there is no USER entered data
2411  * in these collections as of yet. */
2412  col = qof_book_get_collection(book, GNC_ID_COMMODITY);
2414  col = qof_book_get_collection(book, GNC_ID_COMMODITY_NAMESPACE);
2416 
2417  LEAVE ("table=%p", table);
2418  return TRUE;
2419 }
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
#define ENTER(format, args...)
Definition: qoflog.h:261
gnc_commodity_namespace * gnc_commodity_table_add_namespace(gnc_commodity_table *table, const char *name_space, QofBook *book)
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
void qof_collection_mark_clean(QofCollection *)
#define LEAVE(format, args...)
Definition: qoflog.h:271
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
gnc_commodity_namespace* gnc_commodity_table_add_namespace ( gnc_commodity_table table,
const char *  commodity_namespace,
QofBook book 
)

This function adds a new string to the list of commodity namespaces. If the new namespace already exists, nothing happens.

Parameters
tableA pointer to the commodity table
commodity_namespaceThe new namespace to be added.
bookThe book that the new namespace will belong to.
Returns
A pointer to the newly created namespace.

Definition at line 2212 of file gnc-commodity.c.

2215 {
2216  gnc_commodity_namespace * ns = NULL;
2217 
2218  if (!table) return NULL;
2219 
2220  name_space = gnc_commodity_table_map_namespace(name_space);
2221  ns = gnc_commodity_table_find_namespace(table, name_space);
2222  if (!ns)
2223  {
2224  ns = g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, NULL);
2225  ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2226  ns->name = CACHE_INSERT((gpointer)name_space);
2227  ns->iso4217 = gnc_commodity_namespace_is_iso(name_space);
2228  qof_instance_init_data (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
2229  qof_event_gen (&ns->inst, QOF_EVENT_CREATE, NULL);
2230 
2231  g_hash_table_insert(table->ns_table,
2232  (gpointer) ns->name,
2233  (gpointer) ns);
2234  table->ns_list = g_list_append(table->ns_list, ns);
2235  qof_event_gen (&ns->inst, QOF_EVENT_ADD, NULL);
2236  }
2237  return ns;
2238 }
void qof_instance_init_data(QofInstance *, QofIdType, QofBook *)
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
void gnc_commodity_table_delete_namespace ( gnc_commodity_table table,
const char *  commodity_namespace 
)

This function deletes a string from the list of commodity namespaces. If the namespace does not exist, nothing happens.

Parameters
tableA pointer to the commodity table
commodity_namespaceThe namespace to be deleted.
Note
This routine will destroy any commodities that exist as part of this namespace. Use it carefully.

Definition at line 2277 of file gnc-commodity.c.

2279 {
2281 
2282  if (!table) return;
2283 
2284  ns = gnc_commodity_table_find_namespace(table, name_space);
2285  if (!ns)
2286  return;
2287 
2288  qof_event_gen (&ns->inst, QOF_EVENT_REMOVE, NULL);
2289  g_hash_table_remove(table->ns_table, name_space);
2290  table->ns_list = g_list_remove(table->ns_list, ns);
2291 
2292  g_list_free(ns->cm_list);
2293  ns->cm_list = NULL;
2294 
2295  g_hash_table_foreach_remove(ns->cm_table, ns_helper, NULL);
2296  g_hash_table_destroy(ns->cm_table);
2297  CACHE_REMOVE(ns->name);
2298 
2299  qof_event_gen (&ns->inst, QOF_EVENT_DESTROY, NULL);
2300  /* qof_instance_release(&ns->inst); */
2301  g_object_unref(ns);
2302 }
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
gnc_commodity_namespace* gnc_commodity_table_find_namespace ( const gnc_commodity_table table,
const char *  commodity_namespace 
)

This function finds a commodity namespace in the set of existing commodity namespaces.

Parameters
tableA pointer to the commodity table
commodity_namespaceThe new namespace to be added.
Returns
The a pointer to the namespace found, or NULL if the namespace doesn't exist.

Definition at line 2242 of file gnc-commodity.c.

2244 {
2245  if (!table || !name_space)
2246  return NULL;
2247 
2248  name_space = gnc_commodity_table_map_namespace(name_space);
2249  return g_hash_table_lookup(table->ns_table, (gpointer)name_space);
2250 }
gboolean gnc_commodity_table_foreach_commodity ( const gnc_commodity_table table,
gboolean(*)(gnc_commodity *cm, gpointer user_data)  f,
gpointer  user_data 
)

Call a function once for each commodity in the commodity table. This table walk returns whenever the end of the table is reached, or the function returns FALSE.

Parameters
tableA pointer to the commodity table
fThe function to call for each commodity.
user_dataA pointer that is passed into the function unchanged by the table walk routine.
CommodityList* gnc_commodity_table_get_commodities ( const gnc_commodity_table table,
const char *  commodity_namespace 
)

Return a list of all commodities in the commodity table that are in the given namespace.

Parameters
tableA pointer to the commodity table
commodity_namespaceA string indicating which commodities should be returned. It is a required argument.
Returns
A pointer to the list of commodities. NULL if an invalid argument was supplied, or the namespace could not be found.
Note
It is the callers responsibility to free the list.

Definition at line 2094 of file gnc-commodity.c.

2096 {
2097  gnc_commodity_namespace * ns = NULL;
2098 
2099  if (!table)
2100  return NULL;
2101 
2102  ns = gnc_commodity_table_find_namespace(table, name_space);
2103  if (!ns)
2104  return NULL;
2105 
2106  return g_hash_table_values(ns->cm_table);
2107 }
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
GList* gnc_commodity_table_get_namespaces ( const gnc_commodity_table t)

Return a list of all namespaces in the commodity table. This returns both system and user defined namespaces.

Returns
A pointer to the list of names. NULL if an invalid argument was supplied.
Note
It is the callers responsibility to free the list.

Definition at line 2042 of file gnc-commodity.c.

2043 {
2044  if (!table)
2045  return NULL;
2046 
2047  return g_hash_table_keys(table->ns_table);
2048 }
GList* gnc_commodity_table_get_namespaces_list ( const gnc_commodity_table t)

Return a list of all namespace data structures in the commodity table. This returns both system and user defined namespace structures.

Returns
A pointer to the list of structures. NULL if an invalid argument was supplied.
Note
This list is owned by the engine. The caller must not free the list.

Definition at line 2051 of file gnc-commodity.c.

2052 {
2053  if (!table)
2054  return NULL;
2055 
2056  return table->ns_list;
2057 }
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. It will scan the entire commodity table (or a subset) and check each commodity to see if the price_quote_flag field has been set. All matching commodities are queued onto a list, and the head of that list is returned. Use the command-line given expression as a filter on the commodities to be returned. If non-null, only commodities in namespace that match the specified regular expression are checked. If none was given, all commodities are checked.

Parameters
tableA pointer to the commodity table
Returns
A pointer to a list of commodities. NULL if invalid arguments were supplied or if there no commodities are flagged for quote retrieval.
Note
It is the callers responsibility to free the list.

Definition at line 2141 of file gnc-commodity.c.

2142 {
2143  gnc_commodity_namespace * ns = NULL;
2144  const char *name_space;
2145  GList * nslist, * tmp;
2146  GList * l = NULL;
2147  regex_t pattern;
2148  const char *expression = gnc_prefs_get_namespace_regexp();
2149 
2150  ENTER("table=%p, expression=%s", table, expression);
2151  if (!table)
2152  return NULL;
2153 
2154  if (expression && *expression)
2155  {
2156  if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2157  {
2158  LEAVE("Cannot compile regex");
2159  return NULL;
2160  }
2161 
2162  nslist = gnc_commodity_table_get_namespaces(table);
2163  for (tmp = nslist; tmp; tmp = tmp->next)
2164  {
2165  name_space = tmp->data;
2166  if (regexec(&pattern, name_space, 0, NULL, 0) == 0)
2167  {
2168  DEBUG("Running list of %s commodities", name_space);
2169  ns = gnc_commodity_table_find_namespace(table, name_space);
2170  if (ns)
2171  {
2172  g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2173  }
2174  }
2175  }
2176  g_list_free(nslist);
2177  regfree(&pattern);
2178  }
2179  else
2180  {
2181  gnc_commodity_table_foreach_commodity(table, get_quotables_helper2,
2182  (gpointer) &l);
2183  }
2184  LEAVE("list head %p", l);
2185  return l;
2186 }
gboolean gnc_commodity_table_foreach_commodity(const gnc_commodity_table *table, gboolean(*f)(gnc_commodity *cm, gpointer user_data), gpointer user_data)
#define DEBUG(format, args...)
Definition: qoflog.h:255
#define ENTER(format, args...)
Definition: qoflog.h:261
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
#define LEAVE(format, args...)
Definition: qoflog.h:271
guint gnc_commodity_table_get_size ( const gnc_commodity_table tbl)

Returns the number of commodities in the commodity table.

Parameters
tblA pointer to the commodity table
Returns
The number of commodities in the table. 0 if there are no commodities, or the routine was passed a bad argument.

Definition at line 1746 of file gnc-commodity.c.

1747 {
1748  guint count = 0;
1749  g_return_val_if_fail(tbl, 0);
1750  g_return_val_if_fail(tbl->ns_table, 0);
1751 
1752  g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1753 
1754  return count;
1755 }
gnc_commodity_table* gnc_commodity_table_get_table ( QofBook book)

Returns the commodity table associated with a book.

Definition at line 1696 of file gnc-commodity.c.

1697 {
1698  if (!book) return NULL;
1699  return qof_book_get_data (book, GNC_COMMODITY_TABLE);
1700 }
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
int gnc_commodity_table_has_namespace ( const gnc_commodity_table table,
const char *  commodity_namespace 
)

Test to see if the indicated namespace exits in the commodity table.

Parameters
tableA pointer to the commodity table
commodity_namespaceThe new namespace to check.
Returns
1 if the namespace exists. 0 if it doesn't exist, or the routine was passed a bad argument.

Definition at line 1985 of file gnc-commodity.c.

1987 {
1988  gnc_commodity_namespace * nsp = NULL;
1989 
1990  if (!table || !name_space)
1991  {
1992  return 0;
1993  }
1994 
1995  nsp = gnc_commodity_table_find_namespace(table, name_space);
1996  if (nsp)
1997  {
1998  return 1;
1999  }
2000  else
2001  {
2002  return 0;
2003  }
2004 }
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
gnc_commodity* gnc_commodity_table_insert ( gnc_commodity_table table,
gnc_commodity comm 
)

Add a new commodity to the commodity table. This routine handles the cases where the commodity already exists in the database (does nothing), or another entries has the same namespace and mnemonic (updates the existing entry).

Parameters
tableA pointer to the commodity table
commA pointer to the commodity to add.
Returns
The added commodity. Null on error.
Note
The commodity pointer passed to this function should not be used after its return, as it may have been destroyed. Use the return value which is guaranteed to be valid.

Definition at line 1872 of file gnc-commodity.c.

1874 {
1875  gnc_commodity_namespace * nsp = NULL;
1876  gnc_commodity *c;
1877  const char *ns_name;
1878  CommodityPrivate* priv;
1879  QofBook *book;
1880 
1881  if (!table) return NULL;
1882  if (!comm) return NULL;
1883 
1884  priv = GET_PRIVATE(comm);
1885 
1886  ENTER ("(table=%p, comm=%p) %s %s", table, comm,
1887  (priv->mnemonic == NULL ? "(null)" : priv->mnemonic),
1888  (priv->fullname == NULL ? "(null)" : priv->fullname));
1889  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1890  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1891 
1892  if (c)
1893  {
1894  if (c == comm)
1895  {
1896  LEAVE("already in table");
1897  return c;
1898  }
1899 
1900  /* Backward compatability support for currencies that have
1901  * recently changed. */
1902  if (priv->name_space->iso4217)
1903  {
1904  guint i;
1905  for (i = 0; i < GNC_NEW_ISO_CODES; i++)
1906  {
1907  if (!priv->mnemonic
1908  || !strcmp(priv->mnemonic, gnc_new_iso_codes[i].old_code))
1909  {
1910  gnc_commodity_set_mnemonic(comm, gnc_new_iso_codes[i].new_code);
1911  break;
1912  }
1913  }
1914  }
1915  gnc_commodity_copy (c, comm);
1916  gnc_commodity_destroy (comm);
1917  LEAVE("found at %p", c);
1918  return c;
1919  }
1920 
1921  /* Prevent setting anything except template in namespace template. */
1922  if (g_strcmp0 (ns_name, "template") == 0 &&
1923  g_strcmp0 (priv->mnemonic, "template") != 0)
1924  {
1925  PWARN("Converting commodity %s from namespace template to "
1926  "namespace User", priv->mnemonic);
1927  gnc_commodity_set_namespace (comm, "User");
1928  ns_name = "User";
1929  mark_commodity_dirty (comm);
1930  }
1931 
1932  book = qof_instance_get_book (&comm->inst);
1933  nsp = gnc_commodity_table_add_namespace(table, ns_name, book);
1934 
1935  PINFO ("insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1936  nsp->cm_table, nsp->name);
1937  g_hash_table_insert(nsp->cm_table,
1938  CACHE_INSERT(priv->mnemonic),
1939  (gpointer)comm);
1940  nsp->cm_list = g_list_append(nsp->cm_list, comm);
1941 
1942  qof_event_gen (&comm->inst, QOF_EVENT_ADD, NULL);
1943  LEAVE ("(table=%p, comm=%p)", table, comm);
1944  return comm;
1945 }
QofBook * qof_instance_get_book(gconstpointer)
#define PINFO(format, args...)
Definition: qoflog.h:249
#define ENTER(format, args...)
Definition: qoflog.h:261
gnc_commodity_namespace * gnc_commodity_table_add_namespace(gnc_commodity_table *table, const char *name_space, QofBook *book)
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
#define PWARN(format, args...)
Definition: qoflog.h:243
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
#define LEAVE(format, args...)
Definition: qoflog.h:271
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
void gnc_commodity_copy(gnc_commodity *dest, const gnc_commodity *src)
void gnc_commodity_destroy(gnc_commodity *cm)
gnc_commodity_table* gnc_commodity_table_new ( void  )

You proably shouldn't be using gnc_commodity_table_new() directly, its for internal use only. You should probably be using gnc_commodity_table_get_table()

Definition at line 1683 of file gnc-commodity.c.

1684 {
1685  gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1686  retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1687  retval->ns_list = NULL;
1688  return retval;
1689 }
gboolean gnc_commodity_table_register ( void  )

You should probably not be using gnc_commodity_table_register() It is an internal routine for registering the gncObject for the commodity table.

Definition at line 2506 of file gnc-commodity.c.

2507 {
2508  gnc_quote_source_init_tables();
2509 
2510  if (!qof_object_register (&commodity_object_def))
2511  return FALSE;
2512  if (!qof_object_register (&namespace_object_def))
2513  return FALSE;
2514  return qof_object_register (&commodity_table_object_def);
2515 }
gboolean qof_object_register(const QofObject *object)
void gnc_commodity_table_remove ( gnc_commodity_table table,
gnc_commodity comm 
)

Remove a commodity from the commodity table. If the commodity to remove doesn't exist, nothing happens.

Parameters
tableA pointer to the commodity table
commA pointer to the commodity to remove.

Definition at line 1953 of file gnc-commodity.c.

1955 {
1957  gnc_commodity *c;
1958  CommodityPrivate* priv;
1959  const char *ns_name;
1960 
1961  if (!table) return;
1962  if (!comm) return;
1963 
1964  priv = GET_PRIVATE(comm);
1965  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1966  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1967  if (c != comm) return;
1968 
1969  qof_event_gen (&comm->inst, QOF_EVENT_REMOVE, NULL);
1970 
1971  nsp = gnc_commodity_table_find_namespace(table, ns_name);
1972  if (!nsp) return;
1973 
1974  nsp->cm_list = g_list_remove(nsp->cm_list, comm);
1975  g_hash_table_remove (nsp->cm_table, priv->mnemonic);
1976  /* XXX minor mem leak, should remove the key as well */
1977 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
void qof_event_gen(QofInstance *entity, QofEventId event_type, gpointer event_data)
Invoke all registered event handlers using the given arguments.
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. This flag indicates whether stock quotes should be retrieved for the specified stock.

It is necessary to have a separate function to distinguish when this setting is being modified by a user so that the auto-enabling/auto-disabling of currencies can be handled properly.

Parameters
cmA pointer to a commodity data structure.
flagTRUE if quotes should be pulled for this commodity, FALSE otherwise.

Definition at line 1332 of file gnc-commodity.c.

1333 {
1334  CommodityPrivate* priv;
1335 
1336  ENTER ("(cm=%p, flag=%d)", cm, flag);
1337 
1338  if (!cm)
1339  {
1340  LEAVE("");
1341  return;
1342  }
1343 
1344  priv = GET_PRIVATE(cm);
1345  gnc_commodity_begin_edit(cm);
1346  gnc_commodity_set_quote_flag(cm, flag);
1347  if (gnc_commodity_is_iso(cm))
1348  {
1349  /* For currencies, disable auto quote control if the quote flag is being
1350  * changed from its default value and enable it if the quote flag is being
1351  * reset to its default value. The defaults for the quote flag are
1352  * disabled if no accounts are using the currency, and true otherwise.
1353  * Thus enable auto quote control if flag is FALSE and there are not any
1354  * accounts using this currency OR flag is TRUE and there are accounts
1355  * using this currency; otherwise disable auto quote control */
1356  gnc_commodity_set_auto_quote_control_flag(cm,
1357  (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1358  }
1359  gnc_commodity_commit_edit(cm);
1360  LEAVE("");
1361 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
MonetaryList* gnc_monetary_list_add_monetary ( MonetaryList *  list,
gnc_monetary  add_mon 
)

Add a gnc_monetary to the list

Definition at line 2523 of file gnc-commodity.c.

2524 {
2525  MonetaryList *l = list, *tmp;
2526  for (tmp = list; tmp; tmp = tmp->next)
2527  {
2528  gnc_monetary *list_mon = tmp->data;
2529  if (gnc_commodity_equiv(list_mon->commodity, add_mon.commodity))
2530  {
2531  list_mon->value = gnc_numeric_add(list_mon->value, add_mon.value,
2533  break;
2534  }
2535  }
2536 
2537  /* See if we found an entry, and add one if not */
2538  if (tmp == NULL)
2539  {
2540  gnc_monetary *new_mon = g_new0(gnc_monetary, 1);
2541  *new_mon = add_mon;
2542  l = g_list_prepend(l, new_mon);
2543  }
2544 
2545  return l;
2546 }
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
#define GNC_DENOM_AUTO
Definition: gnc-numeric.h:246
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
MonetaryList* gnc_monetary_list_delete_zeros ( MonetaryList *  list)

Delete all the zero-value entries from a list

Delete all entries in the list that have zero value. Return list pointer will be a null pointer if there are no non-zero entries

Definition at line 2551 of file gnc-commodity.c.

2552 {
2553  MonetaryList *node, *next;
2554  for (node = list; node; node = next)
2555  {
2556  gnc_monetary *mon = node->data;
2557  next = node->next;
2558  if (gnc_numeric_zero_p(mon->value))
2559  {
2560  g_free(mon);
2561  list = g_list_delete_link(list, node);
2562  }
2563  }
2564  return list;
2565 }
gboolean gnc_numeric_zero_p(gnc_numeric a)
void gnc_monetary_list_free ( MonetaryList *  list)

Free a monetary list and all the items it points to

Free a MonetaryList and all the monetaries it points to

Definition at line 2569 of file gnc-commodity.c.

2570 {
2571  MonetaryList *tmp;
2572  for (tmp = list; tmp; tmp = tmp->next)
2573  {
2574  g_free(tmp->data);
2575  }
2576 
2577  g_list_free(list);
2578 }
gnc_quote_source* gnc_quote_source_add_new ( const char *  name,
gboolean  supported 
)

Create a new quote source. This is called by the F::Q startup code or the XML parsing code to add new entries to the list of available quote sources.

Parameters
nameThe internal name for this new quote source.
supportedTRUE if this quote source is supported by F::Q. Should only be set by the F::Q startup routine.
Returns
A pointer to the newly created quote source.

Definition at line 309 of file gnc-commodity.c.

310 {
311  gnc_quote_source *new_source;
312 
313  DEBUG("Creating new source %s", (source_name == NULL ? "(null)" : source_name));
314  new_source = malloc(sizeof(gnc_quote_source));
315  new_source->supported = supported;
316  new_source->type = SOURCE_UNKNOWN;
317  new_source->index = g_list_length(new_quote_sources);
318 
319  /* This name can be changed if/when support for this price source is
320  * integrated into gnucash. */
321  new_source->user_name = g_strdup(source_name);
322 
323  /* This name is permanent and must be kept the same if/when support
324  * for this price source is integrated into gnucash (i.e. for a
325  * nice user name). */
326  new_source->old_internal_name = g_strdup(source_name);
327  new_source->internal_name = g_strdup(source_name);
328  new_quote_sources = g_list_append(new_quote_sources, new_source);
329  return new_source;
330 }
#define DEBUG(format, args...)
Definition: qoflog.h:255
gboolean gnc_quote_source_fq_installed ( void  )

This function indicates whether or not the Finance::Quote module is installed on a users computer. This includes any other related modules that gnucash need to process F::Q information.

Returns
TRUE is F::Q is installed properly.

Definition at line 249 of file gnc-commodity.c.

250 {
251  return fq_is_installed;
252 }
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 type.

Parameters
sourceThe quote source in question.
Returns
The index of this quote source in its type.

Definition at line 449 of file gnc-commodity.c.

450 {
451  ENTER("%p", source);
452  if (!source)
453  {
454  LEAVE("bad source");
455  return 0;
456  }
457 
458  LEAVE("index is %d", source->index);
459  return source->index;
460 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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. This is the name used by both gnucash and by Finance::Quote. E.G. "yahoo_australia" or "australia"

Parameters
sourceThe quote source in question.
Returns
The internal name.

Definition at line 490 of file gnc-commodity.c.

491 {
492  ENTER("%p", source);
493  if (!source)
494  {
495  LEAVE("bad source");
496  return NULL;
497  }
498  LEAVE("internal name %s", source->internal_name);
499  return source->internal_name;
500 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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 source is supported by the user's F::Q installation.

Parameters
sourceThe quote source in question.
Returns
TRUE if the user's computer supports this quote source.

Definition at line 463 of file gnc-commodity.c.

464 {
465  ENTER("%p", source);
466  if (!source)
467  {
468  LEAVE("bad source");
469  return FALSE;
470  }
471 
472  LEAVE("%ssupported", source && source->supported ? "" : "not ");
473  return source->supported;
474 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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. (SINGLE, MULTI, UNKNOWN)

Parameters
sourceThe quote source in question.
Returns
The type of this quote source.

Definition at line 435 of file gnc-commodity.c.

436 {
437  ENTER("%p", source);
438  if (!source)
439  {
440  LEAVE("bad source");
441  return SOURCE_SINGLE;
442  }
443 
444  LEAVE("type is %d", source->type);
445  return source->type;
446 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
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. E.G. "Yahoo Australia" or "Australia (Yahoo, ASX, ...)"

Parameters
sourceThe quote source in question.
Returns
The user friendly name.

Definition at line 477 of file gnc-commodity.c.

478 {
479  ENTER("%p", source);
480  if (!source)
481  {
482  LEAVE("bad source");
483  return NULL;
484  }
485  LEAVE("user name %s", source->user_name);
486  return source->user_name;
487 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
gnc_quote_source* gnc_quote_source_lookup_by_internal ( const char *  internal_name)

Given the internal (gnucash or F::Q) name of a quote source, find the data structure identified by this name.

Parameters
internal_nameThe name of this quote source.
Returns
A pointer to the price quote source that has the specified internal name.

Definition at line 384 of file gnc-commodity.c.

385 {
386  gnc_quote_source *source;
387  GList *node;
388  gint i;
389 
390  if ((name == NULL) || (g_strcmp0(name, "") == 0))
391  {
392  return NULL;
393  }
394 
395  if (g_strcmp0(name, currency_quote_source.internal_name) == 0)
396  return &currency_quote_source;
397  if (g_strcmp0(name, currency_quote_source.old_internal_name) == 0)
398  return &currency_quote_source;
399 
400  for (i = 0; i < num_single_quote_sources; i++)
401  {
402  if (g_strcmp0(name, single_quote_sources[i].internal_name) == 0)
403  return &single_quote_sources[i];
404  if (g_strcmp0(name, single_quote_sources[i].old_internal_name) == 0)
405  return &single_quote_sources[i];
406  }
407 
408  for (i = 0; i < num_multiple_quote_sources; i++)
409  {
410  if (g_strcmp0(name, multiple_quote_sources[i].internal_name) == 0)
411  return &multiple_quote_sources[i];
412  if (g_strcmp0(name, multiple_quote_sources[i].old_internal_name) == 0)
413  return &multiple_quote_sources[i];
414  }
415 
416  for (i = 0, node = new_quote_sources; node; node = node->next, i++)
417  {
418  source = node->data;
419  if (g_strcmp0(name, source->internal_name) == 0)
420  return source;
421  if (g_strcmp0(name, source->old_internal_name) == 0)
422  return source;
423  }
424 
425  DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
426  return NULL;
427 }
#define DEBUG(format, args...)
Definition: qoflog.h:255
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.

Parameters
typeThe type of this quote source.
indexThe index of this quote source within its type.
Returns
A pointer to the price quote source that has the specified type/index.

Definition at line 338 of file gnc-commodity.c.

339 {
340  gnc_quote_source *source;
341  GList *node;
342 
343  ENTER("type/index is %d/%d", type, index);
344  switch (type)
345  {
346  case SOURCE_CURRENCY:
347  LEAVE("found %s", currency_quote_source.user_name);
348  return &currency_quote_source;
349  break;
350 
351  case SOURCE_SINGLE:
352  if (index < num_single_quote_sources)
353  {
354  LEAVE("found %s", single_quote_sources[index].user_name);
355  return &single_quote_sources[index];
356  }
357  break;
358 
359  case SOURCE_MULTI:
360  if (index < num_multiple_quote_sources)
361  {
362  LEAVE("found %s", multiple_quote_sources[index].user_name);
363  return &multiple_quote_sources[index];
364  }
365  break;
366 
367  case SOURCE_UNKNOWN:
368  default:
369  node = g_list_nth(new_quote_sources, index);
370  if (node)
371  {
372  source = node->data;
373  LEAVE("found %s", source->user_name);
374  return source;
375  }
376  break;
377  }
378 
379  LEAVE("not found");
380  return NULL;
381 }
#define ENTER(format, args...)
Definition: qoflog.h:261
#define LEAVE(format, args...)
Definition: qoflog.h:271
gint gnc_quote_source_num_entries ( QuoteSourceType  type)

Return the number of entries for a given type of quote source.

Parameters
typeThe quote source type whose count should be returned.
Returns
The number of entries for this type of quote source.

Definition at line 259 of file gnc-commodity.c.

260 {
261  if (type == SOURCE_CURRENCY)
262  return 1;
263 
264  if (type == SOURCE_SINGLE)
265  return num_single_quote_sources;
266 
267  if (type == SOURCE_MULTI)
268  return num_multiple_quote_sources;
269 
270  return g_list_length(new_quote_sources);
271 }
void gnc_quote_source_set_fq_installed ( const GList *  sources_list)

Update gnucash internal tables based on what Finance::Quote sources are installed. Sources that have been explicitly coded into gnucash are marked sensitive/insensitive based upon whether they are present. New sources that gnucash doesn't know about are added to its internal tables.

Parameters
sources_listA list of strings containing the source names as they are known to F::Q.

Definition at line 509 of file gnc-commodity.c.

510 {
511  gnc_quote_source *source;
512  char *source_name;
513  const GList *node;
514 
515  ENTER(" ");
516  fq_is_installed = TRUE;
517 
518  if (!sources_list)
519  return;
520 
521  for (node = sources_list; node; node = node->next)
522  {
523  source_name = node->data;
524 
525  source = gnc_quote_source_lookup_by_internal(source_name);
526  if (source != NULL)
527  {
528  DEBUG("Found source %s: %s", source_name, source->user_name);
529  source->supported = TRUE;
530  continue;
531  }
532 
533  gnc_quote_source_add_new(source_name, TRUE);
534  }
535  LEAVE(" ");
536 }
gnc_quote_source * gnc_quote_source_add_new(const char *source_name, gboolean supported)
#define DEBUG(format, args...)
Definition: qoflog.h:255
#define ENTER(format, args...)
Definition: qoflog.h:261
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
#define LEAVE(format, args...)
Definition: qoflog.h:271