GnuCash  2.6.16
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"
 
#define GNC_COMMODITY_NS_NONCURRENCY   _("ALL NON-CURRENCY")
 

Typedefs

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_source * gnc_quote_source_add_new (const char *name, gboolean supported)
 
gnc_quote_source * gnc_quote_source_lookup_by_internal (const char *internal_name)
 
gnc_quote_source * gnc_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_commodity * gnc_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_commodity * gnc_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_namespace * gnc_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_source * gnc_commodity_get_quote_source (const gnc_commodity *cm)
 
gnc_quote_source * gnc_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_table * gnc_commodity_table_get_table (QofBook *book)
 

Commodity Table Lookup functions

gnc_commodity * gnc_commodity_table_lookup (const gnc_commodity_table *table, const char *commodity_namespace, const char *mnemonic)
 
gnc_commodity * gnc_commodity_table_lookup_unique (const gnc_commodity_table *table, const char *unique_name)
 
gnc_commodity * gnc_commodity_table_find_full (const gnc_commodity_table *t, const char *commodity_namespace, const char *fullname)
 
gnc_commodity * gnc_commodity_find_commodity_by_guid (const GncGUID *guid, QofBook *book)
 

Commodity Table Maintenance functions

gnc_commodity * gnc_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_namespace * gnc_commodity_table_add_namespace (gnc_commodity_table *table, const char *commodity_namespace, QofBook *book)
 
gnc_commodity_namespace * gnc_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_table * gnc_commodity_table_new (void)
 
void gnc_commodity_table_destroy (gnc_commodity_table *table)
 
gnc_commodity * gnc_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 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

◆ gnc_commodity_get_kvp_frame

#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 978 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_LEGACY

#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

◆ QuoteSourceType

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 119 of file gnc-commodity.h.

120 {
121  SOURCE_SINGLE = 0,
125  SOURCE_MULTI,
132  SOURCE_MAX,
133  SOURCE_CURRENCY = SOURCE_MAX,
QuoteSourceType

Function Documentation

◆ gnc_commodity_clone()

gnc_commodity* gnc_commodity_clone ( const gnc_commodity *  src,
QofBook *  dest_book 
)

allocate and copy

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

959 {
960  CommodityPrivate* src_priv;
961  CommodityPrivate* dest_priv;
962 
963  gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
964  qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, dest_book);
965  src_priv = GET_PRIVATE(src);
966  dest_priv = GET_PRIVATE(dest);
967 
968  dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
969  dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
970  dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
971  dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);
972 
973  dest_priv->name_space = src_priv->name_space;
974 
975  dest_priv->fraction = src_priv->fraction;
976  dest_priv->quote_flag = src_priv->quote_flag;
977 
979 
980  kvp_frame_delete (dest->inst.kvp_data);
981  dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
982 
983  reset_printname(dest_priv);
984  reset_unique_name(dest_priv);
985 
986  return dest;
987 }
KvpFrame * kvp_frame_copy(const KvpFrame *frame)
Definition: kvp_frame.c:151
void kvp_frame_delete(KvpFrame *frame)
Definition: kvp_frame.c:116
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Definition: qofinstance.c:282
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)

◆ gnc_commodity_compare()

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 1635 of file gnc-commodity.c.

1636 {
1637  if (gnc_commodity_equal(a, b))
1638  {
1639  return 0;
1640  }
1641  else
1642  {
1643  return 1;
1644  }
1645 }
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)

◆ gnc_commodity_compare_void()

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 1647 of file gnc-commodity.c.

1648 {
1649  return gnc_commodity_compare(a, b);
1650 }
int gnc_commodity_compare(const gnc_commodity *a, const gnc_commodity *b)

◆ gnc_commodity_copy()

void gnc_commodity_copy ( gnc_commodity *  dest,
const gnc_commodity *  src 
)

Copy src into dest

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

941 {
942  CommodityPrivate* src_priv = GET_PRIVATE(src);
943  CommodityPrivate* dest_priv = GET_PRIVATE(dest);
944 
945  gnc_commodity_set_fullname (dest, src_priv->fullname);
946  gnc_commodity_set_mnemonic (dest, src_priv->mnemonic);
947  dest_priv->name_space = src_priv->name_space;
948  gnc_commodity_set_fraction (dest, src_priv->fraction);
949  gnc_commodity_set_cusip (dest, src_priv->cusip);
950  gnc_commodity_set_quote_flag (dest, src_priv->quote_flag);
952  gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
953  kvp_frame_delete (dest->inst.kvp_data);
954  dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
955 }
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)
Definition: kvp_frame.c:151
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
void kvp_frame_delete(KvpFrame *frame)
Definition: kvp_frame.c:116
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)

◆ gnc_commodity_decrement_usage_count()

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 1521 of file gnc-commodity.c.

1522 {
1523  CommodityPrivate* priv;
1524 
1525  ENTER("(cm=%p)", cm);
1526 
1527  if (!cm)
1528  {
1529  LEAVE("");
1530  return;
1531  }
1532 
1533  priv = GET_PRIVATE(cm);
1534 
1535  if (priv->usage_count == 0)
1536  {
1537  PWARN("usage_count already zero");
1538  LEAVE("");
1539  return;
1540  }
1541 
1542  priv->usage_count--;
1543  if ((priv->usage_count == 0) && priv->quote_flag
1544  && gnc_commodity_get_auto_quote_control_flag(cm)
1545  && gnc_commodity_is_iso(cm))
1546  {
1547  /* if this is a currency with auto quote control enabled and no more
1548  * accounts reference this currency, disable quote retrieval */
1549  gnc_commodity_set_quote_flag(cm, FALSE);
1550  }
1551  LEAVE("(usage_count=%d)", priv->usage_count);
1552 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
#define ENTER(format, args...)
Definition: qoflog.h:256
#define PWARN(format, args...)
Definition: qoflog.h:238
#define LEAVE(format, args...)
Definition: qoflog.h:266
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)

◆ gnc_commodity_destroy()

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 932 of file gnc-commodity.c.

933 {
934  gnc_commodity_begin_edit(cm);
935  qof_instance_set_destroying(cm, TRUE);
936  gnc_commodity_commit_edit(cm);
937 }
void qof_instance_set_destroying(gpointer ptr, gboolean value)
Definition: qofinstance.c:667

◆ gnc_commodity_equal()

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 1580 of file gnc-commodity.c.

1581 {
1582  CommodityPrivate* priv_a;
1583  CommodityPrivate* priv_b;
1584  gboolean same_book;
1585 
1586  if (a == b) return TRUE;
1587 
1588  if (!a || !b)
1589  {
1590  DEBUG ("one is NULL");
1591  return FALSE;
1592  }
1593 
1594  priv_a = GET_PRIVATE(a);
1595  priv_b = GET_PRIVATE(b);
1596  same_book = qof_instance_get_book(QOF_INSTANCE(a)) == qof_instance_get_book(QOF_INSTANCE(b));
1597 
1598  if ((same_book && priv_a->name_space != priv_b->name_space)
1599  || (!same_book && g_strcmp0( gnc_commodity_namespace_get_name(priv_a->name_space),
1600  gnc_commodity_namespace_get_name(priv_b->name_space)) != 0))
1601  {
1602  DEBUG ("namespaces differ: %p(%s) vs %p(%s)",
1603  priv_a->name_space, gnc_commodity_namespace_get_name(priv_a->name_space),
1604  priv_b->name_space, gnc_commodity_namespace_get_name(priv_b->name_space));
1605  return FALSE;
1606  }
1607 
1608  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
1609  {
1610  DEBUG ("mnemonics differ: %s vs %s", priv_a->mnemonic, priv_b->mnemonic);
1611  return FALSE;
1612  }
1613 
1614  if (g_strcmp0(priv_a->fullname, priv_b->fullname) != 0)
1615  {
1616  DEBUG ("fullnames differ: %s vs %s", priv_a->fullname, priv_b->fullname);
1617  return FALSE;
1618  }
1619 
1620  if (g_strcmp0(priv_a->cusip, priv_b->cusip) != 0)
1621  {
1622  DEBUG ("cusips differ: %s vs %s", priv_a->cusip, priv_b->cusip);
1623  return FALSE;
1624  }
1625 
1626  if (priv_a->fraction != priv_b->fraction)
1627  {
1628  DEBUG ("fractions differ: %d vs %d", priv_a->fraction, priv_b->fraction);
1629  return FALSE;
1630  }
1631 
1632  return TRUE;
1633 }
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
#define DEBUG(format, args...)
Definition: qoflog.h:250
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)

◆ gnc_commodity_equiv()

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 1564 of file gnc-commodity.c.

1565 {
1566  CommodityPrivate* priv_a;
1567  CommodityPrivate* priv_b;
1568 
1569  if (a == b) return TRUE;
1570  if (!a || !b) return FALSE;
1571 
1572  priv_a = GET_PRIVATE(a);
1573  priv_b = GET_PRIVATE(b);
1574  if (priv_a->name_space != priv_b->name_space) return FALSE;
1575  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0) return FALSE;
1576  return TRUE;
1577 }

◆ gnc_commodity_get_cusip()

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 1075 of file gnc-commodity.c.

1076 {
1077  if (!cm) return NULL;
1078  return GET_PRIVATE(cm)->cusip;
1079 }

◆ gnc_commodity_get_default_symbol()

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 1169 of file gnc-commodity.c.

1170 {
1171  const char *str;
1172  if (!cm) return NULL;
1173  return GET_PRIVATE(cm)->default_symbol;
1174 }

◆ gnc_commodity_get_fraction()

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 1086 of file gnc-commodity.c.

1087 {
1088  if (!cm) return 0;
1089  return GET_PRIVATE(cm)->fraction;
1090 }

◆ gnc_commodity_get_fullname()

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 1051 of file gnc-commodity.c.

1052 {
1053  if (!cm) return NULL;
1054  return GET_PRIVATE(cm)->fullname;
1055 }

◆ gnc_commodity_get_mnemonic()

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 994 of file gnc-commodity.c.

995 {
996  if (!cm) return NULL;
997  return GET_PRIVATE(cm)->mnemonic;
998 }

◆ gnc_commodity_get_namespace()

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 1017 of file gnc-commodity.c.

1018 {
1019  if (!cm) return NULL;
1020  return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
1021 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)

◆ gnc_commodity_get_namespace_compat()

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 compatibility 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 1024 of file gnc-commodity.c.

1025 {
1026  CommodityPrivate* priv;
1027 
1028  if (!cm) return NULL;
1029  priv = GET_PRIVATE(cm);
1030  if (!priv->name_space) return NULL;
1031  if (priv->name_space->iso4217)
1032  {
1033  /* Data files are still written with ISO4217. */
1034  return GNC_COMMODITY_NS_ISO;
1035  }
1036  return gnc_commodity_namespace_get_name(priv->name_space);
1037 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)

◆ gnc_commodity_get_namespace_ds()

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 1040 of file gnc-commodity.c.

1041 {
1042  if (!cm) return NULL;
1043  return GET_PRIVATE(cm)->name_space;
1044 }

◆ gnc_commodity_get_nice_symbol()

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 1180 of file gnc-commodity.c.

1181 {
1182  const char *nice_symbol;
1183  struct lconv *lc;
1184  if (!cm) return NULL;
1185 
1186  nice_symbol = gnc_commodity_get_user_symbol(cm);
1187  if (nice_symbol && *nice_symbol)
1188  return nice_symbol;
1189 
1190  lc = gnc_localeconv();
1191  nice_symbol = lc->currency_symbol;
1192  if (!g_strcmp0(gnc_commodity_get_mnemonic(cm), lc->int_curr_symbol))
1193  return nice_symbol;
1194 
1195  nice_symbol = gnc_commodity_get_default_symbol(cm);
1196  if (nice_symbol && *nice_symbol)
1197  return nice_symbol;
1198 
1199  return gnc_commodity_get_mnemonic(cm);
1200 }
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)

◆ gnc_commodity_get_printname()

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 1005 of file gnc-commodity.c.

1006 {
1007  if (!cm) return NULL;
1008  return GET_PRIVATE(cm)->printname;
1009 }

◆ gnc_commodity_get_quote_flag()

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 1112 of file gnc-commodity.c.

1113 {
1114  if (!cm) return FALSE;
1115  return (GET_PRIVATE(cm)->quote_flag);
1116 }

◆ gnc_commodity_get_quote_source()

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 1123 of file gnc-commodity.c.

1124 {
1125  CommodityPrivate* priv;
1126 
1127  if (!cm) return NULL;
1128  priv = GET_PRIVATE(cm);
1129  if (!priv->quote_source && gnc_commodity_is_iso(cm))
1130  return &currency_quote_source;
1131  return priv->quote_source;
1132 }
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)

◆ gnc_commodity_get_quote_tz()

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 1148 of file gnc-commodity.c.

1149 {
1150  if (!cm) return NULL;
1151  return GET_PRIVATE(cm)->quote_tz;
1152 }

◆ gnc_commodity_get_unique_name()

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 1063 of file gnc-commodity.c.

1064 {
1065  if (!cm) return NULL;
1066  return GET_PRIVATE(cm)->unique_name;
1067 }

◆ gnc_commodity_get_user_symbol()

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 1158 of file gnc-commodity.c.

1159 {
1160  const char *str;
1161  if (!cm) return NULL;
1162  return kvp_frame_get_string(cm->inst.kvp_data, "user_symbol");
1163 }

◆ gnc_commodity_increment_usage_count()

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 1486 of file gnc-commodity.c.

1487 {
1488  CommodityPrivate* priv;
1489 
1490  ENTER("(cm=%p)", cm);
1491 
1492  if (!cm)
1493  {
1494  LEAVE("");
1495  return;
1496  }
1497 
1498  priv = GET_PRIVATE(cm);
1499 
1500  if ((priv->usage_count == 0) && !priv->quote_flag
1501  && gnc_commodity_get_auto_quote_control_flag(cm)
1502  && gnc_commodity_is_iso(cm))
1503  {
1504  /* compatibility hack - Gnucash 1.8 gets currency quotes when a
1505  non-default currency is assigned to an account. */
1506  gnc_commodity_begin_edit(cm);
1507  gnc_commodity_set_quote_flag(cm, TRUE);
1509  gnc_commodity_get_default_quote_source(cm));
1510  gnc_commodity_commit_edit(cm);
1511  }
1512  priv->usage_count++;
1513  LEAVE("(usage_count=%d)", priv->usage_count);
1514 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
#define ENTER(format, args...)
Definition: qoflog.h:256
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
#define LEAVE(format, args...)
Definition: qoflog.h:266
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)

◆ gnc_commodity_is_currency()

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 2088 of file gnc-commodity.c.

2089 {
2090  const char *ns_name;
2091  if (!cm) return FALSE;
2092 
2093  ns_name = gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
2094  return (!g_strcmp0(ns_name, GNC_COMMODITY_NS_LEGACY) ||
2095  !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
2096 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
#define GNC_COMMODITY_NS_LEGACY
Definition: gnc-commodity.h:97

◆ gnc_commodity_is_iso()

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 2076 of file gnc-commodity.c.

2077 {
2078  CommodityPrivate* priv;
2079 
2080  if (!cm) return FALSE;
2081 
2082  priv = GET_PRIVATE(cm);
2083  if ( !priv->name_space) return FALSE;
2084  return priv->name_space->iso4217;
2085 }

◆ gnc_commodity_namespace_get_commodity_list()

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 1664 of file gnc-commodity.c.

1665 {
1666  if (!name_space)
1667  return NULL;
1668 
1669  return name_space->cm_list;
1670 }

◆ gnc_commodity_namespace_get_name()

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 1656 of file gnc-commodity.c.

1657 {
1658  if (ns == NULL)
1659  return NULL;
1660  return ns->name;
1661 }

◆ gnc_commodity_namespace_is_iso()

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 1673 of file gnc-commodity.c.

1674 {
1675  return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1676  (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1677 }

◆ gnc_commodity_new()

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 839 of file gnc-commodity.c.

842 {
843  gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
844 
845  qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
846  gnc_commodity_begin_edit(retval);
847 
848  if ( name_space != NULL )
849  {
850  /* Prevent setting anything except template in namespace template. */
851  if (g_strcmp0 (name_space, "template") == 0 &&
852  g_strcmp0 (mnemonic, "template") != 0)
853  {
854  PWARN("Converting commodity %s from namespace template to "
855  "namespace User", mnemonic);
856  name_space = "User";
857  }
858  gnc_commodity_set_namespace(retval, name_space);
859  if (gnc_commodity_namespace_is_iso(name_space))
860  {
863  }
864  }
865  gnc_commodity_set_fullname(retval, fullname);
866  gnc_commodity_set_mnemonic(retval, mnemonic);
867  gnc_commodity_set_cusip(retval, cusip);
868  gnc_commodity_set_fraction(retval, fraction);
869  mark_commodity_dirty (retval);
870  gnc_commodity_commit_edit(retval);
871 
872  qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL);
873 
874  return retval;
875 }
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
#define PWARN(format, args...)
Definition: qoflog.h:238
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Definition: qofinstance.c:282
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_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ gnc_commodity_obtain_twin()

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 1713 of file gnc-commodity.c.

1714 {
1715  gnc_commodity *twin;
1716  const char * ucom;
1717  gnc_commodity_table * comtbl;
1718 
1719  if (!from) return NULL;
1720  comtbl = gnc_commodity_table_get_table (book);
1721  if (!comtbl) return NULL;
1722 
1723  ucom = gnc_commodity_get_unique_name (from);
1724  twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1725  if (!twin)
1726  {
1727  twin = gnc_commodity_clone (from, book);
1728  twin = gnc_commodity_table_insert (comtbl, twin);
1729  }
1730  return twin;
1731 }
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)

◆ gnc_commodity_set_cusip()

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 1282 of file gnc-commodity.c.

1284 {
1285  CommodityPrivate* priv;
1286 
1287  if (!cm) return;
1288 
1289  priv = GET_PRIVATE(cm);
1290  if (priv->cusip == cusip) return;
1291 
1292  gnc_commodity_begin_edit(cm);
1293  CACHE_REMOVE (priv->cusip);
1294  priv->cusip = CACHE_INSERT (cusip);
1295  mark_commodity_dirty(cm);
1296  gnc_commodity_commit_edit(cm);
1297 }

◆ gnc_commodity_set_fraction()

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 1304 of file gnc-commodity.c.

1305 {
1306  if (!cm) return;
1307  gnc_commodity_begin_edit(cm);
1308  GET_PRIVATE(cm)->fraction = fraction;
1309  mark_commodity_dirty(cm);
1310  gnc_commodity_commit_edit(cm);
1311 }

◆ gnc_commodity_set_fullname()

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 1260 of file gnc-commodity.c.

1261 {
1262  CommodityPrivate* priv;
1263 
1264  if (!cm) return;
1265  priv = GET_PRIVATE(cm);
1266  if (priv->fullname == fullname) return;
1267 
1268  CACHE_REMOVE (priv->fullname);
1269  priv->fullname = CACHE_INSERT (fullname);
1270 
1271  gnc_commodity_begin_edit(cm);
1272  mark_commodity_dirty(cm);
1273  reset_printname(priv);
1274  gnc_commodity_commit_edit(cm);
1275 }

◆ gnc_commodity_set_mnemonic()

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 1207 of file gnc-commodity.c.

1208 {
1209  CommodityPrivate* priv;
1210 
1211  if (!cm) return;
1212  priv = GET_PRIVATE(cm);
1213  if (priv->mnemonic == mnemonic) return;
1214 
1215  gnc_commodity_begin_edit(cm);
1216  CACHE_REMOVE (priv->mnemonic);
1217  priv->mnemonic = CACHE_INSERT(mnemonic);
1218 
1219  mark_commodity_dirty (cm);
1220  reset_printname(priv);
1221  reset_unique_name(priv);
1222  gnc_commodity_commit_edit(cm);
1223 }

◆ gnc_commodity_set_namespace()

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 1230 of file gnc-commodity.c.

1231 {
1232  QofBook *book;
1233  gnc_commodity_table *table;
1234  gnc_commodity_namespace *nsp;
1235  CommodityPrivate* priv;
1236 
1237  if (!cm) return;
1238  priv = GET_PRIVATE(cm);
1239  book = qof_instance_get_book (&cm->inst);
1240  table = gnc_commodity_table_get_table(book);
1241  nsp = gnc_commodity_table_add_namespace(table, name_space, book);
1242  if (priv->name_space == nsp)
1243  return;
1244 
1245  gnc_commodity_begin_edit(cm);
1246  priv->name_space = nsp;
1247  if (nsp->iso4217)
1248  priv->quote_source = gnc_quote_source_lookup_by_internal("currency");
1249  mark_commodity_dirty(cm);
1250  reset_printname(priv);
1251  reset_unique_name(priv);
1252  gnc_commodity_commit_edit(cm);
1253 }
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
QofBook * qof_instance_get_book(gconstpointer inst)
Definition: qofinstance.c:548
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)

◆ gnc_commodity_set_quote_flag()

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 1378 of file gnc-commodity.c.

1379 {
1380  ENTER ("(cm=%p, flag=%d)", cm, flag);
1381 
1382  if (!cm) return;
1383  gnc_commodity_begin_edit(cm);
1384  GET_PRIVATE(cm)->quote_flag = flag;
1385  mark_commodity_dirty(cm);
1386  gnc_commodity_commit_edit(cm);
1387  LEAVE(" ");
1388 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_commodity_set_quote_source()

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 1395 of file gnc-commodity.c.

1396 {
1397  ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name : "unknown");
1398 
1399  if (!cm) return;
1400  gnc_commodity_begin_edit(cm);
1401  GET_PRIVATE(cm)->quote_source = src;
1402  mark_commodity_dirty(cm);
1403  gnc_commodity_commit_edit(cm);
1404  LEAVE(" ");
1405 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_commodity_set_quote_tz()

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 1412 of file gnc-commodity.c.

1413 {
1414  CommodityPrivate* priv;
1415 
1416  if (!cm) return;
1417 
1418  ENTER ("(cm=%p, tz=%s)", cm, tz ? tz : "(null)");
1419 
1420  priv = GET_PRIVATE(cm);
1421 
1422  if (tz == priv->quote_tz)
1423  {
1424  LEAVE("Already correct TZ");
1425  return;
1426  }
1427 
1428  gnc_commodity_begin_edit(cm);
1429  CACHE_REMOVE (priv->quote_tz);
1430  priv->quote_tz = CACHE_INSERT (tz);
1431  mark_commodity_dirty(cm);
1432  gnc_commodity_commit_edit(cm);
1433  LEAVE(" ");
1434 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_commodity_set_user_symbol()

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 1441 of file gnc-commodity.c.

1442 {
1443  struct lconv *lc;
1444 
1445  if (!cm) return;
1446 
1447  ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
1448 
1449  gnc_commodity_begin_edit(cm);
1450 
1451  lc = gnc_localeconv();
1452  if (!user_symbol || !*user_symbol)
1453  user_symbol = NULL;
1454  else if (!g_strcmp0(lc->int_curr_symbol, gnc_commodity_get_mnemonic(cm)) &&
1455  !g_strcmp0(lc->currency_symbol, user_symbol))
1456  /* if the user gives the ISO symbol for the locale currency or the
1457  * default symbol, actually remove the user symbol */
1458  user_symbol = NULL;
1459  else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
1460  user_symbol = NULL;
1461 
1462  kvp_frame_set_string(cm->inst.kvp_data, "user_symbol", user_symbol);
1463  mark_commodity_dirty(cm);
1464  gnc_commodity_commit_edit(cm);
1465 
1466  LEAVE(" ");
1467 }
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
#define ENTER(format, args...)
Definition: qoflog.h:256
const char * gnc_commodity_get_default_symbol(const gnc_commodity *cm)
#define LEAVE(format, args...)
Definition: qoflog.h:266
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.

◆ gnc_commodity_table_add_default_data()

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 2423 of file gnc-commodity.c.

2424 {
2425  QofCollection *col;
2426  gnc_commodity* c;
2427 
2428  ENTER ("table=%p", table);
2429  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_AMEX, book);
2430  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NYSE, book);
2431  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NASDAQ, book);
2432  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_EUREX, book);
2433  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_MUTUAL, book);
2434  gnc_commodity_table_add_namespace(table, "template", book);
2435  c = gnc_commodity_new(book, "template", "template", "template", "template", 1);
2437 
2438 #include "iso-4217-currencies.c"
2439 
2440  /* We've just created the default namespaces and currencies. Mark
2441  * these collections as clean because there is no USER entered data
2442  * in these collections as of yet. */
2443  col = qof_book_get_collection(book, GNC_ID_COMMODITY);
2445  col = qof_book_get_collection(book, GNC_ID_COMMODITY_NAMESPACE);
2447 
2448  LEAVE ("table=%p", table);
2449  return TRUE;
2450 }
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
#define ENTER(format, args...)
Definition: qoflog.h:256
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 *)
Definition: qofid.c:257
#define LEAVE(format, args...)
Definition: qoflog.h:266
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Definition: qofbook.c:306

◆ gnc_commodity_table_add_namespace()

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 2243 of file gnc-commodity.c.

2246 {
2247  gnc_commodity_namespace * ns = NULL;
2248 
2249  if (!table) return NULL;
2250 
2251  name_space = gnc_commodity_table_map_namespace(name_space);
2252  ns = gnc_commodity_table_find_namespace(table, name_space);
2253  if (!ns)
2254  {
2255  ns = g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, NULL);
2256  ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2257  ns->name = CACHE_INSERT((gpointer)name_space);
2258  ns->iso4217 = gnc_commodity_namespace_is_iso(name_space);
2259  qof_instance_init_data (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
2260  qof_event_gen (&ns->inst, QOF_EVENT_CREATE, NULL);
2261 
2262  g_hash_table_insert(table->ns_table,
2263  (gpointer) ns->name,
2264  (gpointer) ns);
2265  table->ns_list = g_list_append(table->ns_list, ns);
2266  qof_event_gen (&ns->inst, QOF_EVENT_ADD, NULL);
2267  }
2268  return ns;
2269 }
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Definition: qofinstance.c:282
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_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ gnc_commodity_table_delete_namespace()

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 2308 of file gnc-commodity.c.

2310 {
2311  gnc_commodity_namespace * ns;
2312 
2313  if (!table) return;
2314 
2315  ns = gnc_commodity_table_find_namespace(table, name_space);
2316  if (!ns)
2317  return;
2318 
2319  qof_event_gen (&ns->inst, QOF_EVENT_REMOVE, NULL);
2320  g_hash_table_remove(table->ns_table, name_space);
2321  table->ns_list = g_list_remove(table->ns_list, ns);
2322 
2323  g_list_free(ns->cm_list);
2324  ns->cm_list = NULL;
2325 
2326  g_hash_table_foreach_remove(ns->cm_table, ns_helper, NULL);
2327  g_hash_table_destroy(ns->cm_table);
2328  CACHE_REMOVE(ns->name);
2329 
2330  qof_event_gen (&ns->inst, QOF_EVENT_DESTROY, NULL);
2331  /* qof_instance_release(&ns->inst); */
2332  g_object_unref(ns);
2333 }
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_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ gnc_commodity_table_find_namespace()

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 2273 of file gnc-commodity.c.

2275 {
2276  if (!table || !name_space)
2277  return NULL;
2278 
2279  name_space = gnc_commodity_table_map_namespace(name_space);
2280  return g_hash_table_lookup(table->ns_table, (gpointer)name_space);
2281 }

◆ gnc_commodity_table_foreach_commodity()

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.

◆ gnc_commodity_table_get_commodities()

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 2124 of file gnc-commodity.c.

2126 {
2127  gnc_commodity_namespace * ns = NULL;
2128 
2129  if (!table)
2130  return NULL;
2131  if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONCURRENCY) == 0)
2132  return commodity_table_get_all_noncurrency_commodities(table);
2133  ns = gnc_commodity_table_find_namespace(table, name_space);
2134  if (!ns)
2135  return NULL;
2136 
2137  return g_hash_table_values(ns->cm_table);
2138 }
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)

◆ gnc_commodity_table_get_namespaces()

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 2052 of file gnc-commodity.c.

2053 {
2054  if (!table)
2055  return NULL;
2056 
2057  return g_hash_table_keys(table->ns_table);
2058 }

◆ gnc_commodity_table_get_namespaces_list()

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 2061 of file gnc-commodity.c.

2062 {
2063  if (!table)
2064  return NULL;
2065 
2066  return table->ns_list;
2067 }

◆ gnc_commodity_table_get_quotable_commodities()

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 2172 of file gnc-commodity.c.

2173 {
2174  gnc_commodity_namespace * ns = NULL;
2175  const char *name_space;
2176  GList * nslist, * tmp;
2177  GList * l = NULL;
2178  regex_t pattern;
2179  const char *expression = gnc_prefs_get_namespace_regexp();
2180 
2181  ENTER("table=%p, expression=%s", table, expression);
2182  if (!table)
2183  return NULL;
2184 
2185  if (expression && *expression)
2186  {
2187  if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2188  {
2189  LEAVE("Cannot compile regex");
2190  return NULL;
2191  }
2192 
2194  for (tmp = nslist; tmp; tmp = tmp->next)
2195  {
2196  name_space = tmp->data;
2197  if (regexec(&pattern, name_space, 0, NULL, 0) == 0)
2198  {
2199  DEBUG("Running list of %s commodities", name_space);
2200  ns = gnc_commodity_table_find_namespace(table, name_space);
2201  if (ns)
2202  {
2203  g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2204  }
2205  }
2206  }
2207  g_list_free(nslist);
2208  regfree(&pattern);
2209  }
2210  else
2211  {
2212  gnc_commodity_table_foreach_commodity(table, get_quotables_helper2,
2213  (gpointer) &l);
2214  }
2215  LEAVE("list head %p", l);
2216  return l;
2217 }
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:250
#define ENTER(format, args...)
Definition: qoflog.h:256
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:266

◆ gnc_commodity_table_get_size()

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 1756 of file gnc-commodity.c.

1757 {
1758  guint count = 0;
1759  g_return_val_if_fail(tbl, 0);
1760  g_return_val_if_fail(tbl->ns_table, 0);
1761 
1762  g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1763 
1764  return count;
1765 }

◆ gnc_commodity_table_get_table()

gnc_commodity_table* gnc_commodity_table_get_table ( QofBook *  book)

Returns the commodity table associated with a book.

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

1707 {
1708  if (!book) return NULL;
1709  return qof_book_get_data (book, GNC_COMMODITY_TABLE);
1710 }
gpointer qof_book_get_data(const QofBook *book, const gchar *key)

◆ gnc_commodity_table_has_namespace()

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 1995 of file gnc-commodity.c.

1997 {
1998  gnc_commodity_namespace * nsp = NULL;
1999 
2000  if (!table || !name_space)
2001  {
2002  return 0;
2003  }
2004 
2005  nsp = gnc_commodity_table_find_namespace(table, name_space);
2006  if (nsp)
2007  {
2008  return 1;
2009  }
2010  else
2011  {
2012  return 0;
2013  }
2014 }
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)

◆ gnc_commodity_table_insert()

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 1882 of file gnc-commodity.c.

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

◆ gnc_commodity_table_new()

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 1693 of file gnc-commodity.c.

1694 {
1695  gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1696  retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1697  retval->ns_list = NULL;
1698  return retval;
1699 }

◆ gnc_commodity_table_register()

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 2537 of file gnc-commodity.c.

2538 {
2539  gnc_quote_source_init_tables();
2540 
2541  if (!qof_object_register (&commodity_object_def))
2542  return FALSE;
2543  if (!qof_object_register (&namespace_object_def))
2544  return FALSE;
2545  return qof_object_register (&commodity_table_object_def);
2546 }
gboolean qof_object_register(const QofObject *object)
Definition: qofobject.c:323

◆ gnc_commodity_table_remove()

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 1963 of file gnc-commodity.c.

1965 {
1966  gnc_commodity_namespace * nsp;
1967  gnc_commodity *c;
1968  CommodityPrivate* priv;
1969  const char *ns_name;
1970 
1971  if (!table) return;
1972  if (!comm) return;
1973 
1974  priv = GET_PRIVATE(comm);
1975  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1976  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1977  if (c != comm) return;
1978 
1979  qof_event_gen (&comm->inst, QOF_EVENT_REMOVE, NULL);
1980 
1981  nsp = gnc_commodity_table_find_namespace(table, ns_name);
1982  if (!nsp) return;
1983 
1984  nsp->cm_list = g_list_remove(nsp->cm_list, comm);
1985  g_hash_table_remove (nsp->cm_table, priv->mnemonic);
1986  /* XXX minor mem leak, should remove the key as well */
1987 }
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_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.c:230

◆ gnc_commodity_user_set_quote_flag()

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 1342 of file gnc-commodity.c.

1343 {
1344  CommodityPrivate* priv;
1345 
1346  ENTER ("(cm=%p, flag=%d)", cm, flag);
1347 
1348  if (!cm)
1349  {
1350  LEAVE("");
1351  return;
1352  }
1353 
1354  priv = GET_PRIVATE(cm);
1355  gnc_commodity_begin_edit(cm);
1356  gnc_commodity_set_quote_flag(cm, flag);
1357  if (gnc_commodity_is_iso(cm))
1358  {
1359  /* For currencies, disable auto quote control if the quote flag is being
1360  * changed from its default value and enable it if the quote flag is being
1361  * reset to its default value. The defaults for the quote flag are
1362  * disabled if no accounts are using the currency, and true otherwise.
1363  * Thus enable auto quote control if flag is FALSE and there are not any
1364  * accounts using this currency OR flag is TRUE and there are accounts
1365  * using this currency; otherwise disable auto quote control */
1366  gnc_commodity_set_auto_quote_control_flag(cm,
1367  (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1368  }
1369  gnc_commodity_commit_edit(cm);
1370  LEAVE("");
1371 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)

◆ gnc_monetary_list_add_monetary()

MonetaryList* gnc_monetary_list_add_monetary ( MonetaryList *  list,
gnc_monetary  add_mon 
)

Add a gnc_monetary to the list

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

2555 {
2556  MonetaryList *l = list, *tmp;
2557  for (tmp = list; tmp; tmp = tmp->next)
2558  {
2559  gnc_monetary *list_mon = tmp->data;
2560  if (gnc_commodity_equiv(list_mon->commodity, add_mon.commodity))
2561  {
2562  list_mon->value = gnc_numeric_add(list_mon->value, add_mon.value,
2564  break;
2565  }
2566  }
2567 
2568  /* See if we found an entry, and add one if not */
2569  if (tmp == NULL)
2570  {
2571  gnc_monetary *new_mon = g_new0(gnc_monetary, 1);
2572  *new_mon = add_mon;
2573  l = g_list_prepend(l, new_mon);
2574  }
2575 
2576  return l;
2577 }
gnc_numeric gnc_numeric_add(gnc_numeric a, gnc_numeric b, gint64 denom, gint how)
Definition: gnc-numeric.c:378
#define GNC_DENOM_AUTO
Definition: gnc-numeric.h:242
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)

◆ gnc_monetary_list_delete_zeros()

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 2582 of file gnc-commodity.c.

2583 {
2584  MonetaryList *node, *next;
2585  for (node = list; node; node = next)
2586  {
2587  gnc_monetary *mon = node->data;
2588  next = node->next;
2589  if (gnc_numeric_zero_p(mon->value))
2590  {
2591  g_free(mon);
2592  list = g_list_delete_link(list, node);
2593  }
2594  }
2595  return list;
2596 }
gboolean gnc_numeric_zero_p(gnc_numeric a)
Definition: gnc-numeric.c:173

◆ gnc_monetary_list_free()

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 2600 of file gnc-commodity.c.

2601 {
2602  MonetaryList *tmp;
2603  for (tmp = list; tmp; tmp = tmp->next)
2604  {
2605  g_free(tmp->data);
2606  }
2607 
2608  g_list_free(list);
2609 }

◆ gnc_quote_source_add_new()

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 320 of file gnc-commodity.c.

321 {
322  gnc_quote_source *new_source;
323 
324  DEBUG("Creating new source %s", (source_name == NULL ? "(null)" : source_name));
325  new_source = malloc(sizeof(gnc_quote_source));
326  new_source->supported = supported;
327  new_source->type = SOURCE_UNKNOWN;
328  new_source->index = g_list_length(new_quote_sources);
329 
330  /* This name can be changed if/when support for this price source is
331  * integrated into gnucash. */
332  new_source->user_name = g_strdup(source_name);
333 
334  /* This name is permanent and must be kept the same if/when support
335  * for this price source is integrated into gnucash (i.e. for a
336  * nice user name). */
337  new_source->old_internal_name = g_strdup(source_name);
338  new_source->internal_name = g_strdup(source_name);
339  new_quote_sources = g_list_append(new_quote_sources, new_source);
340  return new_source;
341 }
#define DEBUG(format, args...)
Definition: qoflog.h:250

◆ gnc_quote_source_fq_installed()

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 260 of file gnc-commodity.c.

261 {
262  return fq_is_installed;
263 }

◆ gnc_quote_source_get_index()

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 460 of file gnc-commodity.c.

461 {
462  ENTER("%p", source);
463  if (!source)
464  {
465  LEAVE("bad source");
466  return 0;
467  }
468 
469  LEAVE("index is %d", source->index);
470  return source->index;
471 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_quote_source_get_internal_name()

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 501 of file gnc-commodity.c.

502 {
503  ENTER("%p", source);
504  if (!source)
505  {
506  LEAVE("bad source");
507  return NULL;
508  }
509  LEAVE("internal name %s", source->internal_name);
510  return source->internal_name;
511 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_quote_source_get_supported()

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 474 of file gnc-commodity.c.

475 {
476  ENTER("%p", source);
477  if (!source)
478  {
479  LEAVE("bad source");
480  return FALSE;
481  }
482 
483  LEAVE("%ssupported", source && source->supported ? "" : "not ");
484  return source->supported;
485 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_quote_source_get_type()

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 446 of file gnc-commodity.c.

447 {
448  ENTER("%p", source);
449  if (!source)
450  {
451  LEAVE("bad source");
452  return SOURCE_SINGLE;
453  }
454 
455  LEAVE("type is %d", source->type);
456  return source->type;
457 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_quote_source_get_user_name()

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 488 of file gnc-commodity.c.

489 {
490  ENTER("%p", source);
491  if (!source)
492  {
493  LEAVE("bad source");
494  return NULL;
495  }
496  LEAVE("user name %s", source->user_name);
497  return source->user_name;
498 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_quote_source_lookup_by_internal()

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 395 of file gnc-commodity.c.

396 {
397  gnc_quote_source *source;
398  GList *node;
399  gint i;
400 
401  if ((name == NULL) || (g_strcmp0(name, "") == 0))
402  {
403  return NULL;
404  }
405 
406  if (g_strcmp0(name, currency_quote_source.internal_name) == 0)
407  return &currency_quote_source;
408  if (g_strcmp0(name, currency_quote_source.old_internal_name) == 0)
409  return &currency_quote_source;
410 
411  for (i = 0; i < num_single_quote_sources; i++)
412  {
413  if (g_strcmp0(name, single_quote_sources[i].internal_name) == 0)
414  return &single_quote_sources[i];
415  if (g_strcmp0(name, single_quote_sources[i].old_internal_name) == 0)
416  return &single_quote_sources[i];
417  }
418 
419  for (i = 0; i < num_multiple_quote_sources; i++)
420  {
421  if (g_strcmp0(name, multiple_quote_sources[i].internal_name) == 0)
422  return &multiple_quote_sources[i];
423  if (g_strcmp0(name, multiple_quote_sources[i].old_internal_name) == 0)
424  return &multiple_quote_sources[i];
425  }
426 
427  for (i = 0, node = new_quote_sources; node; node = node->next, i++)
428  {
429  source = node->data;
430  if (g_strcmp0(name, source->internal_name) == 0)
431  return source;
432  if (g_strcmp0(name, source->old_internal_name) == 0)
433  return source;
434  }
435 
436  DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
437  return NULL;
438 }
#define DEBUG(format, args...)
Definition: qoflog.h:250

◆ gnc_quote_source_lookup_by_ti()

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 349 of file gnc-commodity.c.

350 {
351  gnc_quote_source *source;
352  GList *node;
353 
354  ENTER("type/index is %d/%d", type, index);
355  switch (type)
356  {
357  case SOURCE_CURRENCY:
358  LEAVE("found %s", currency_quote_source.user_name);
359  return &currency_quote_source;
360  break;
361 
362  case SOURCE_SINGLE:
363  if (index < num_single_quote_sources)
364  {
365  LEAVE("found %s", single_quote_sources[index].user_name);
366  return &single_quote_sources[index];
367  }
368  break;
369 
370  case SOURCE_MULTI:
371  if (index < num_multiple_quote_sources)
372  {
373  LEAVE("found %s", multiple_quote_sources[index].user_name);
374  return &multiple_quote_sources[index];
375  }
376  break;
377 
378  case SOURCE_UNKNOWN:
379  default:
380  node = g_list_nth(new_quote_sources, index);
381  if (node)
382  {
383  source = node->data;
384  LEAVE("found %s", source->user_name);
385  return source;
386  }
387  break;
388  }
389 
390  LEAVE("not found");
391  return NULL;
392 }
#define ENTER(format, args...)
Definition: qoflog.h:256
#define LEAVE(format, args...)
Definition: qoflog.h:266

◆ gnc_quote_source_num_entries()

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 270 of file gnc-commodity.c.

271 {
272  if (type == SOURCE_CURRENCY)
273  return 1;
274 
275  if (type == SOURCE_SINGLE)
276  return num_single_quote_sources;
277 
278  if (type == SOURCE_MULTI)
279  return num_multiple_quote_sources;
280 
281  return g_list_length(new_quote_sources);
282 }

◆ gnc_quote_source_set_fq_installed()

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 520 of file gnc-commodity.c.

521 {
522  gnc_quote_source *source;
523  char *source_name;
524  const GList *node;
525 
526  ENTER(" ");
527  fq_is_installed = TRUE;
528 
529  if (!sources_list)
530  return;
531 
532  for (node = sources_list; node; node = node->next)
533  {
534  source_name = node->data;
535 
536  source = gnc_quote_source_lookup_by_internal(source_name);
537  if (source != NULL)
538  {
539  DEBUG("Found source %s: %s", source_name, source->user_name);
540  source->supported = TRUE;
541  continue;
542  }
543 
544  gnc_quote_source_add_new(source_name, TRUE);
545  }
546  LEAVE(" ");
547 }
gnc_quote_source * gnc_quote_source_add_new(const char *source_name, gboolean supported)
#define DEBUG(format, args...)
Definition: qoflog.h:250
#define ENTER(format, args...)
Definition: qoflog.h:256
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
#define LEAVE(format, args...)
Definition: qoflog.h:266