GnuCash  3.0-87-g14c3034+
Files | Data Structures | Macros | Typedefs | Functions

A commodity is something of value that is easily tradeable or sellable; for example, currencies, stocks, bonds, grain, copper, and oil are all commodities. More...

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"
 The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the exchange where it is traded. More...
 
#define GNC_COMMODITY_NS_TEMPLATE   "template"
 
#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")
 
#define GNC_COMMODITY_NS_ISO_GUI   N_("Currencies")
 

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
}
 The quote source type enum account types are used to determine how the transaction data in the account is displayed. More...
 
gboolean gnc_quote_source_fq_installed (void)
 This function indicates whether or not the Finance::Quote module is installed on a user's computer. More...
 
const char * gnc_quote_source_fq_version (void)
 This function returns the version of the Finance::Quote module installed on a user's computer. More...
 
void gnc_quote_source_set_fq_installed (const char *version_string, const GList *sources_list)
 Update gnucash internal tables based on what Finance::Quote sources are installed. More...
 
gint gnc_quote_source_num_entries (QuoteSourceType type)
 Return the number of entries for a given type of quote source. More...
 
gnc_quote_source * gnc_quote_source_add_new (const char *name, gboolean supported)
 Create a new quote source. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 

Commodity Creation

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. More...
 
void gnc_commodity_destroy (gnc_commodity *cm)
 Destroy a commodity. More...
 
void gnc_commodity_copy (gnc_commodity *dest, const gnc_commodity *src)
 Copy src into dest.
 
gnc_commodity * gnc_commodity_clone (const gnc_commodity *src, QofBook *dest_book)
 allocate and copy
 

Commodity Accessor Routines - Get

const char * gnc_commodity_get_mnemonic (const gnc_commodity *cm)
 Retrieve the mnemonic for the specified commodity. More...
 
const char * gnc_commodity_get_namespace (const gnc_commodity *cm)
 Retrieve the namespace for the specified commodity. More...
 
gnc_commodity_namespace * gnc_commodity_get_namespace_ds (const gnc_commodity *cm)
 Retrieve the namespace data strucure for the specified commodity. More...
 
const char * gnc_commodity_get_fullname (const gnc_commodity *cm)
 Retrieve the full name for the specified commodity. More...
 
const char * gnc_commodity_get_printname (const gnc_commodity *cm)
 Retrieve the 'print' name for the specified commodity. More...
 
const char * gnc_commodity_get_cusip (const gnc_commodity *cm)
 Retrieve the 'exchange code' for the specified commodity. More...
 
const char * gnc_commodity_get_unique_name (const gnc_commodity *cm)
 Retrieve the 'unique' name for the specified commodity. More...
 
int gnc_commodity_get_fraction (const gnc_commodity *cm)
 Retrieve the fraction for the specified commodity. More...
 
gboolean gnc_commodity_get_quote_flag (const gnc_commodity *cm)
 Retrieve the automatic price quote flag for the specified commodity. More...
 
gnc_quote_source * gnc_commodity_get_quote_source (const gnc_commodity *cm)
 Retrieve the automatic price quote source for the specified commodity. More...
 
gnc_quote_source * gnc_commodity_get_default_quote_source (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. More...
 
const char * gnc_commodity_get_user_symbol (const gnc_commodity *cm)
 Retrieve the user-defined symbol for the specified commodity. More...
 
const char * gnc_commodity_get_default_symbol (const gnc_commodity *cm)
 Retrieve the default symbol for the specified commodity. More...
 
const char * gnc_commodity_get_nice_symbol (const gnc_commodity *cm)
 Retrieve a symbol for the specified commodity, suitable for display to the user. More...
 

Commodity Accessor Routines - Set

void gnc_commodity_set_mnemonic (gnc_commodity *cm, const char *mnemonic)
 Set the mnemonic for the specified commodity. More...
 
void gnc_commodity_set_namespace (gnc_commodity *cm, const char *new_namespace)
 Set the namespace for the specified commodity. More...
 
void gnc_commodity_set_fullname (gnc_commodity *cm, const char *fullname)
 Set the full name for the specified commodity. More...
 
void gnc_commodity_set_cusip (gnc_commodity *cm, const char *cusip)
 Set the 'exchange code' for the specified commodity. More...
 
void gnc_commodity_set_fraction (gnc_commodity *cm, int smallest_fraction)
 Set the fraction for the specified commodity. More...
 
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. More...
 
void gnc_commodity_set_quote_flag (gnc_commodity *cm, const gboolean flag)
 Set the automatic price quote flag for the specified commodity. More...
 
void gnc_commodity_set_quote_source (gnc_commodity *cm, gnc_quote_source *src)
 Set the automatic price quote source for the specified commodity. More...
 
void gnc_commodity_set_quote_tz (gnc_commodity *cm, const char *tz)
 Set the automatic price quote timezone for the specified commodity. More...
 
void gnc_commodity_set_user_symbol (gnc_commodity *cm, const char *user_symbol)
 Set a user-defined symbol for the specified commodity. More...
 

Commodity Usage Count Adjustment Routines

void gnc_commodity_increment_usage_count (gnc_commodity *cm)
 Increment a commodity's internal counter that tracks how many accounts are using that commodity. More...
 
void gnc_commodity_decrement_usage_count (gnc_commodity *cm)
 Decrement a commodity's internal counter that tracks how many accounts are using that commodity. More...
 

Commodity Comparison

gboolean gnc_commodity_equiv (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns TRUE if the two commodities are equivalent. More...
 
gboolean gnc_commodity_equal (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns TRUE if the two commodities are equal. More...
 
int gnc_commodity_compare (const gnc_commodity *a, const gnc_commodity *b)
 This routine returns 0 if the two commodities are equal, 1 otherwise. More...
 
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.
 

Currency Checks

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. More...
 
gboolean gnc_commodity_is_iso (const gnc_commodity *cm)
 Checks to see if the specified commodity is an ISO 4217 recognized currency. More...
 
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. More...
 

Commodity Table

gnc_commodity_table * gnc_commodity_table_get_table (QofBook *book)
 Returns the commodity table associated with a 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)
 Add a new commodity to the commodity table. More...
 
void gnc_commodity_table_remove (gnc_commodity_table *table, gnc_commodity *comm)
 Remove a commodity from the commodity table. More...
 
gboolean gnc_commodity_table_add_default_data (gnc_commodity_table *table, QofBook *book)
 Add all the standard namespaces and currencies to the commodity table. More...
 

Commodity Table Namespace functions

const char * gnc_commodity_namespace_get_name (const gnc_commodity_namespace *ns)
 Return the textual name of a namespace data strucure. More...
 
const char * gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace *ns)
 Return the textual name of a namespace data strucure in a form suitable to present to the user. More...
 
GList * gnc_commodity_namespace_get_commodity_list (const gnc_commodity_namespace *ns)
 Return a list of all commodity data structures in the specified namespace. More...
 
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. More...
 
GList * gnc_commodity_table_get_namespaces (const gnc_commodity_table *t)
 Return a list of all namespaces in the commodity table. More...
 
GList * gnc_commodity_table_get_namespaces_list (const gnc_commodity_table *t)
 Return a list of all namespace data structures in the commodity table. More...
 
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. More...
 
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. More...
 
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. More...
 

Commodity Table Accessor functions

guint gnc_commodity_table_get_size (const gnc_commodity_table *tbl)
 Returns the number of commodities in the commodity table. More...
 
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. More...
 
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. More...
 
gboolean gnc_commodity_table_foreach_commodity (const gnc_commodity_table *table, gboolean(*f)(gnc_commodity *cm, gpointer user_data), gpointer user_data)
 Call a function once for each commodity in the commodity table. More...
 

Commodity Table Private/Internal-Use Only Routines

gnc_commodity_table * gnc_commodity_table_new (void)
 You proably shouldn't be using gnc_commodity_table_new() directly, its for internal use only. More...
 
void gnc_commodity_table_destroy (gnc_commodity_table *table)
 
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. More...
 
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.
 
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))
 Get the internal KVP from of the currency. More...
 

Monetary value, commodity identity and numeric value

typedef GList MonetaryList
 

Manipulate MonetaryList lists

MonetaryList * gnc_monetary_list_add_monetary (MonetaryList *list, gnc_monetary mon)
 Add a gnc_monetary to the list.
 
MonetaryList * gnc_monetary_list_delete_zeros (MonetaryList *list)
 Delete all the zero-value entries from a list. More...
 
void gnc_monetary_list_free (MonetaryList *list)
 Free a monetary list and all the items it points to. More...
 

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 995 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 102 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 128 of file gnc-commodity.h.

129 {
130  SOURCE_SINGLE = 0,
134  SOURCE_MULTI,
141  SOURCE_MAX,
142  SOURCE_CURRENCY = SOURCE_MAX,
This quote source pulls from a single specific web site.
The special currency quote source.
This is a locally installed quote source that gnucash knows nothing about.
QuoteSourceType
The quote source type enum account types are used to determine how the transaction data in the accoun...
This quote source may pull from multiple web sites.

Function Documentation

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

1676 {
1677  if (gnc_commodity_equal(a, b))
1678  {
1679  return 0;
1680  }
1681  else
1682  {
1683  return 1;
1684  }
1685 }
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.

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

1562 {
1563  CommodityPrivate* priv;
1564 
1565  ENTER("(cm=%p)", cm);
1566 
1567  if (!cm)
1568  {
1569  LEAVE("");
1570  return;
1571  }
1572 
1573  priv = GET_PRIVATE(cm);
1574 
1575  if (priv->usage_count == 0)
1576  {
1577  PWARN("usage_count already zero");
1578  LEAVE("");
1579  return;
1580  }
1581 
1582  priv->usage_count--;
1583  if ((priv->usage_count == 0) && priv->quote_flag
1584  && gnc_commodity_get_auto_quote_control_flag(cm)
1585  && gnc_commodity_is_iso(cm))
1586  {
1587  /* if this is a currency with auto quote control enabled and no more
1588  * accounts reference this currency, disable quote retrieval */
1589  gnc_commodity_set_quote_flag(cm, FALSE);
1590  }
1591  LEAVE("(usage_count=%d)", priv->usage_count);
1592 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:248
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.

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

974 {
975  gnc_commodity_begin_edit(cm);
976  qof_instance_set_destroying(cm, TRUE);
977  gnc_commodity_commit_edit(cm);
978 }

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

1621 {
1622  CommodityPrivate* priv_a;
1623  CommodityPrivate* priv_b;
1624  gboolean same_book;
1625 
1626  if (a == b) return TRUE;
1627 
1628  if (!a || !b)
1629  {
1630  DEBUG ("one is NULL");
1631  return FALSE;
1632  }
1633 
1634  priv_a = GET_PRIVATE(a);
1635  priv_b = GET_PRIVATE(b);
1636  same_book = qof_instance_get_book(QOF_INSTANCE(a)) == qof_instance_get_book(QOF_INSTANCE(b));
1637 
1638  if ((same_book && priv_a->name_space != priv_b->name_space)
1639  || (!same_book && g_strcmp0( gnc_commodity_namespace_get_name(priv_a->name_space),
1640  gnc_commodity_namespace_get_name(priv_b->name_space)) != 0))
1641  {
1642  DEBUG ("namespaces differ: %p(%s) vs %p(%s)",
1643  priv_a->name_space, gnc_commodity_namespace_get_name(priv_a->name_space),
1644  priv_b->name_space, gnc_commodity_namespace_get_name(priv_b->name_space));
1645  return FALSE;
1646  }
1647 
1648  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
1649  {
1650  DEBUG ("mnemonics differ: %s vs %s", priv_a->mnemonic, priv_b->mnemonic);
1651  return FALSE;
1652  }
1653 
1654  if (g_strcmp0(priv_a->fullname, priv_b->fullname) != 0)
1655  {
1656  DEBUG ("fullnames differ: %s vs %s", priv_a->fullname, priv_b->fullname);
1657  return FALSE;
1658  }
1659 
1660  if (g_strcmp0(priv_a->cusip, priv_b->cusip) != 0)
1661  {
1662  DEBUG ("cusips differ: %s vs %s", priv_a->cusip, priv_b->cusip);
1663  return FALSE;
1664  }
1665 
1666  if (priv_a->fraction != priv_b->fraction)
1667  {
1668  DEBUG ("fractions differ: %d vs %d", priv_a->fraction, priv_b->fraction);
1669  return FALSE;
1670  }
1671 
1672  return TRUE;
1673 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:260
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data strucure.

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

1605 {
1606  CommodityPrivate* priv_a;
1607  CommodityPrivate* priv_b;
1608 
1609  if (a == b) return TRUE;
1610  if (!a || !b) return FALSE;
1611 
1612  priv_a = GET_PRIVATE(a);
1613  priv_b = GET_PRIVATE(b);
1614  if (priv_a->name_space != priv_b->name_space) return FALSE;
1615  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0) return FALSE;
1616  return TRUE;
1617 }

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

1099 {
1100  if (!cm) return NULL;
1101  return GET_PRIVATE(cm)->cusip;
1102 }

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

1198 {
1199  if (!cm) return NULL;
1200  return GET_PRIVATE(cm)->default_symbol;
1201 }

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

1110 {
1111  if (!cm) return 0;
1112  return GET_PRIVATE(cm)->fraction;
1113 }

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

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

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

1034 {
1035  if (!cm) return NULL;
1036  return GET_PRIVATE(cm)->mnemonic;
1037 }

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

1057 {
1058  if (!cm) return NULL;
1059  return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
1060 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data strucure.

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

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

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

1208 {
1209  const char *nice_symbol;
1210  struct lconv *lc;
1211  if (!cm) return NULL;
1212 
1213  nice_symbol = gnc_commodity_get_user_symbol(cm);
1214  if (nice_symbol && *nice_symbol)
1215  return nice_symbol;
1216 
1217  lc = gnc_localeconv();
1218  nice_symbol = lc->currency_symbol;
1219  if (!g_strcmp0(gnc_commodity_get_mnemonic(cm), lc->int_curr_symbol))
1220  return nice_symbol;
1221 
1222  nice_symbol = gnc_commodity_get_default_symbol(cm);
1223  if (nice_symbol && *nice_symbol)
1224  return nice_symbol;
1225 
1226  return gnc_commodity_get_mnemonic(cm);
1227 }
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
const char * gnc_commodity_get_user_symbol(const gnc_commodity *cm)
Retrieve the user-defined symbol for the specified commodity.
const char * gnc_commodity_get_default_symbol(const gnc_commodity *cm)
Retrieve the default symbol for the specified commodity.

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

1045 {
1046  if (!cm) return NULL;
1047  return GET_PRIVATE(cm)->printname;
1048 }

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

1138 {
1139  if (!cm) return FALSE;
1140  return (GET_PRIVATE(cm)->quote_flag);
1141 }

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

1149 {
1150  CommodityPrivate* priv;
1151 
1152  if (!cm) return NULL;
1153  priv = GET_PRIVATE(cm);
1154  if (!priv->quote_source && gnc_commodity_is_iso(cm))
1155  return &currency_quote_source;
1156  return priv->quote_source;
1157 }
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.

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

1174 {
1175  if (!cm) return NULL;
1176  return GET_PRIVATE(cm)->quote_tz;
1177 }

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

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

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

1184 {
1185  GValue v = G_VALUE_INIT;
1186  if (!cm) return NULL;
1187  qof_instance_get_kvp (QOF_INSTANCE(cm), &v, 1, "user_symbol");
1188  if (G_VALUE_HOLDS_STRING (&v))
1189  return g_value_get_string (&v);
1190  return NULL;
1191 }
void qof_instance_get_kvp(QofInstance *, GValue *value, unsigned count,...)
Retrieves the contents of a KVP slot into a provided GValue.

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

1527 {
1528  CommodityPrivate* priv;
1529 
1530  ENTER("(cm=%p)", cm);
1531 
1532  if (!cm)
1533  {
1534  LEAVE("");
1535  return;
1536  }
1537 
1538  priv = GET_PRIVATE(cm);
1539 
1540  if ((priv->usage_count == 0) && !priv->quote_flag
1541  && gnc_commodity_get_auto_quote_control_flag(cm)
1542  && gnc_commodity_is_iso(cm))
1543  {
1544  /* compatibility hack - Gnucash 1.8 gets currency quotes when a
1545  non-default currency is assigned to an account. */
1546  gnc_commodity_begin_edit(cm);
1547  gnc_commodity_set_quote_flag(cm, TRUE);
1549  gnc_commodity_get_default_quote_source(cm));
1550  gnc_commodity_commit_edit(cm);
1551  }
1552  priv->usage_count++;
1553  LEAVE("(usage_count=%d)", priv->usage_count);
1554 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.

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

2139 {
2140  const char *ns_name;
2141  if (!cm) return FALSE;
2142 
2143  ns_name = gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
2144  return (!g_strcmp0(ns_name, GNC_COMMODITY_NS_LEGACY) ||
2145  !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
2146 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data strucure.
#define GNC_COMMODITY_NS_LEGACY
The commodity namespace definitions are used to tag a commodity by its type, or a stocks by the excha...

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

2127 {
2128  CommodityPrivate* priv;
2129 
2130  if (!cm) return FALSE;
2131 
2132  priv = GET_PRIVATE(cm);
2133  if ( !priv->name_space) return FALSE;
2134  return priv->name_space->iso4217;
2135 }

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

1715 {
1716  if (!name_space)
1717  return NULL;
1718 
1719  return name_space->cm_list;
1720 }

◆ gnc_commodity_namespace_get_gui_name()

const char* gnc_commodity_namespace_get_gui_name ( const gnc_commodity_namespace *  ns)

Return the textual name of a namespace data strucure in a form suitable to present to the user.

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

The returned string is marked for translation, but not translated yet. If you want it translated pass the return value on to gettext.

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

1705 {
1706  if (ns == NULL)
1707  return NULL;
1708  if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
1709  return GNC_COMMODITY_NS_ISO_GUI;
1710  return ns->name;
1711 }

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

1697 {
1698  if (ns == NULL)
1699  return NULL;
1700  return ns->name;
1701 }

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

1724 {
1725  return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1726  (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1727 }

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

883 {
884  gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
885 
886  qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
887  gnc_commodity_begin_edit(retval);
888 
889  if ( name_space != NULL )
890  {
891  /* Prevent setting anything except template in namespace template. */
892  if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
893  g_strcmp0 (mnemonic, "template") != 0)
894  {
895  PWARN("Converting commodity %s from namespace template to "
896  "namespace User", mnemonic);
897  name_space = "User";
898  }
899  gnc_commodity_set_namespace(retval, name_space);
900  if (gnc_commodity_namespace_is_iso(name_space))
901  {
904  }
905  }
906  gnc_commodity_set_fullname(retval, fullname);
907  gnc_commodity_set_mnemonic(retval, mnemonic);
908  gnc_commodity_set_cusip(retval, cusip);
909  gnc_commodity_set_fraction(retval, fraction);
910  mark_commodity_dirty (retval);
911  gnc_commodity_commit_edit(retval);
912 
913  qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL);
914 
915  return retval;
916 }
void gnc_commodity_set_fraction(gnc_commodity *cm, int fraction)
Set the fraction for the specified commodity.
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:248
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
Set the automatic price quote source for the specified commodity.
void gnc_commodity_set_cusip(gnc_commodity *cm, const char *cusip)
Set the &#39;exchange code&#39; for the specified commodity.
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
Given the internal (gnucash or F::Q) name of a quote source, find the data structure identified by th...
void gnc_commodity_set_fullname(gnc_commodity *cm, const char *fullname)
Set the full name for the specified commodity.
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
Set the mnemonic for the specified commodity.
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
Set the namespace for the specified commodity.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:234

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

1764 {
1765  gnc_commodity *twin;
1766  const char * ucom;
1767  gnc_commodity_table * comtbl;
1768 
1769  if (!from) return NULL;
1770  comtbl = gnc_commodity_table_get_table (book);
1771  if (!comtbl) return NULL;
1772 
1773  ucom = gnc_commodity_get_unique_name (from);
1774  twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1775  if (!twin)
1776  {
1777  twin = gnc_commodity_clone (from, book);
1778  twin = gnc_commodity_table_insert (comtbl, twin);
1779  }
1780  return twin;
1781 }
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
Add a new commodity to the commodity table.
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
gnc_commodity * gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
allocate and copy
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the &#39;unique&#39; name for the specified commodity.

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

1311 {
1312  CommodityPrivate* priv;
1313 
1314  if (!cm) return;
1315 
1316  priv = GET_PRIVATE(cm);
1317  if (priv->cusip == cusip) return;
1318 
1319  gnc_commodity_begin_edit(cm);
1320  CACHE_REMOVE (priv->cusip);
1321  priv->cusip = CACHE_INSERT (cusip);
1322  mark_commodity_dirty(cm);
1323  gnc_commodity_commit_edit(cm);
1324 }

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

1332 {
1333  if (!cm) return;
1334  gnc_commodity_begin_edit(cm);
1335  GET_PRIVATE(cm)->fraction = fraction;
1336  mark_commodity_dirty(cm);
1337  gnc_commodity_commit_edit(cm);
1338 }

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

1288 {
1289  CommodityPrivate* priv;
1290 
1291  if (!cm) return;
1292  priv = GET_PRIVATE(cm);
1293  if (priv->fullname == fullname) return;
1294 
1295  CACHE_REMOVE (priv->fullname);
1296  priv->fullname = CACHE_INSERT (fullname);
1297 
1298  gnc_commodity_begin_edit(cm);
1299  mark_commodity_dirty(cm);
1300  reset_printname(priv);
1301  gnc_commodity_commit_edit(cm);
1302 }

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

1235 {
1236  CommodityPrivate* priv;
1237 
1238  if (!cm) return;
1239  priv = GET_PRIVATE(cm);
1240  if (priv->mnemonic == mnemonic) return;
1241 
1242  gnc_commodity_begin_edit(cm);
1243  CACHE_REMOVE (priv->mnemonic);
1244  priv->mnemonic = CACHE_INSERT(mnemonic);
1245 
1246  mark_commodity_dirty (cm);
1247  reset_printname(priv);
1248  reset_unique_name(priv);
1249  gnc_commodity_commit_edit(cm);
1250 }

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

1258 {
1259  QofBook *book;
1260  gnc_commodity_table *table;
1261  gnc_commodity_namespace *nsp;
1262  CommodityPrivate* priv;
1263 
1264  if (!cm) return;
1265  priv = GET_PRIVATE(cm);
1266  book = qof_instance_get_book (&cm->inst);
1267  table = gnc_commodity_table_get_table(book);
1268  nsp = gnc_commodity_table_add_namespace(table, name_space, book);
1269  if (priv->name_space == nsp)
1270  return;
1271 
1272  gnc_commodity_begin_edit(cm);
1273  priv->name_space = nsp;
1274  if (nsp->iso4217)
1275  priv->quote_source = gnc_quote_source_lookup_by_internal("currency");
1276  mark_commodity_dirty(cm);
1277  reset_printname(priv);
1278  reset_unique_name(priv);
1279  gnc_commodity_commit_edit(cm);
1280 }
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
gnc_commodity_namespace * gnc_commodity_table_add_namespace(gnc_commodity_table *table, const char *name_space, QofBook *book)
This function adds a new string to the list of commodity namespaces.
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
Given the internal (gnucash or F::Q) name of a quote source, find the data structure identified by th...

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

1412 {
1413  ENTER ("(cm=%p, flag=%d)", cm, flag);
1414 
1415  if (!cm) return;
1416  gnc_commodity_begin_edit(cm);
1417  GET_PRIVATE(cm)->quote_flag = flag;
1418  mark_commodity_dirty(cm);
1419  gnc_commodity_commit_edit(cm);
1420  LEAVE(" ");
1421 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

1429 {
1430  ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name : "unknown");
1431 
1432  if (!cm) return;
1433  gnc_commodity_begin_edit(cm);
1434  GET_PRIVATE(cm)->quote_source = src;
1435  mark_commodity_dirty(cm);
1436  gnc_commodity_commit_edit(cm);
1437  LEAVE(" ");
1438 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

1446 {
1447  CommodityPrivate* priv;
1448 
1449  if (!cm) return;
1450 
1451  ENTER ("(cm=%p, tz=%s)", cm, tz ? tz : "(null)");
1452 
1453  priv = GET_PRIVATE(cm);
1454 
1455  if (tz == priv->quote_tz)
1456  {
1457  LEAVE("Already correct TZ");
1458  return;
1459  }
1460 
1461  gnc_commodity_begin_edit(cm);
1462  CACHE_REMOVE (priv->quote_tz);
1463  priv->quote_tz = CACHE_INSERT (tz);
1464  mark_commodity_dirty(cm);
1465  gnc_commodity_commit_edit(cm);
1466  LEAVE(" ");
1467 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

1475 {
1476  struct lconv *lc;
1477  GValue v = G_VALUE_INIT;
1478  if (!cm) return;
1479 
1480  ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
1481 
1482  gnc_commodity_begin_edit(cm);
1483 
1484  lc = gnc_localeconv();
1485  if (!user_symbol || !*user_symbol)
1486  user_symbol = NULL;
1487  else if (!g_strcmp0(lc->int_curr_symbol, gnc_commodity_get_mnemonic(cm)) &&
1488  !g_strcmp0(lc->currency_symbol, user_symbol))
1489  /* if the user gives the ISO symbol for the locale currency or the
1490  * default symbol, actually remove the user symbol */
1491  user_symbol = NULL;
1492  else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
1493  user_symbol = NULL;
1494  if (user_symbol)
1495  {
1496  g_value_init (&v, G_TYPE_STRING);
1497  g_value_set_string (&v, user_symbol);
1498  qof_instance_set_kvp (QOF_INSTANCE(cm), &v, 1, "user_symbol");
1499  }
1500  else
1501  qof_instance_set_kvp (QOF_INSTANCE(cm), NULL, 1, "user_symbol");
1502 
1503  mark_commodity_dirty(cm);
1504  gnc_commodity_commit_edit(cm);
1505 
1506  LEAVE(" ");
1507 }
void qof_instance_set_kvp(QofInstance *, GValue const *value, unsigned count,...)
Sets a KVP slot to a value from a GValue.
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
const char * gnc_commodity_get_default_symbol(const gnc_commodity *cm)
Retrieve the default symbol for the specified commodity.
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

2474 {
2475  QofCollection *col;
2476  gnc_commodity* c;
2477 
2478  ENTER ("table=%p", table);
2479  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_AMEX, book);
2480  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NYSE, book);
2481  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NASDAQ, book);
2482  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_EUREX, book);
2483  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_MUTUAL, book);
2484  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_TEMPLATE, book);
2485  c = gnc_commodity_new(book, "template", GNC_COMMODITY_NS_TEMPLATE, "template", "template", 1);
2487 
2488 #include "iso-4217-currencies.c"
2489 
2490  /* We've just created the default namespaces and currencies. Mark
2491  * these collections as clean because there is no USER entered data
2492  * in these collections as of yet. */
2493  col = qof_book_get_collection(book, GNC_ID_COMMODITY);
2495  col = qof_book_get_collection(book, GNC_ID_COMMODITY_NAMESPACE);
2497 
2498  LEAVE ("table=%p", table);
2499  return TRUE;
2500 }
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
Add a new commodity to the commodity table.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
gnc_commodity_namespace * gnc_commodity_table_add_namespace(gnc_commodity_table *table, const char *name_space, QofBook *book)
This function adds a new string to the list of commodity namespaces.
gnc_commodity * gnc_commodity_new(QofBook *book, const char *fullname, const char *name_space, const char *mnemonic, const char *cusip, int fraction)
Create a new commodity.
void qof_collection_mark_clean(QofCollection *)
reset value of dirty flag
Definition: qofid.cpp:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:554

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

2296 {
2297  gnc_commodity_namespace * ns = NULL;
2298 
2299  if (!table) return NULL;
2300 
2301  name_space = gnc_commodity_table_map_namespace(name_space);
2302  ns = gnc_commodity_table_find_namespace(table, name_space);
2303  if (!ns)
2304  {
2305  ns = g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, NULL);
2306  ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2307  ns->name = CACHE_INSERT((gpointer)name_space);
2308  ns->iso4217 = gnc_commodity_namespace_is_iso(name_space);
2309  qof_instance_init_data (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
2310  qof_event_gen (&ns->inst, QOF_EVENT_CREATE, NULL);
2311 
2312  g_hash_table_insert(table->ns_table,
2313  (gpointer) ns->name,
2314  (gpointer) ns);
2315  table->ns_list = g_list_append(table->ns_list, ns);
2316  qof_event_gen (&ns->inst, QOF_EVENT_ADD, NULL);
2317  }
2318  return ns;
2319 }
void qof_instance_init_data(QofInstance *inst, QofIdType type, QofBook *book)
Initialise the settings associated with an instance.
gboolean gnc_commodity_namespace_is_iso(const char *name_space)
Checks to see if the specified commodity namespace is the namespace for ISO 4217 currencies.
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
This function finds a commodity namespace in the set of existing commodity namespaces.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:234

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

2360 {
2361  gnc_commodity_namespace * ns;
2362 
2363  if (!table) return;
2364 
2365  ns = gnc_commodity_table_find_namespace(table, name_space);
2366  if (!ns)
2367  return;
2368 
2369  qof_event_gen (&ns->inst, QOF_EVENT_REMOVE, NULL);
2370  g_hash_table_remove(table->ns_table, name_space);
2371  table->ns_list = g_list_remove(table->ns_list, ns);
2372 
2373  g_list_free(ns->cm_list);
2374  ns->cm_list = NULL;
2375 
2376  g_hash_table_foreach_remove(ns->cm_table, ns_helper, NULL);
2377  g_hash_table_destroy(ns->cm_table);
2378  CACHE_REMOVE(ns->name);
2379 
2380  qof_event_gen (&ns->inst, QOF_EVENT_DESTROY, NULL);
2381  /* qof_instance_release(&ns->inst); */
2382  g_object_unref(ns);
2383 }
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
This function finds a commodity namespace in the set of existing commodity namespaces.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:234

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

2325 {
2326  if (!table || !name_space)
2327  return NULL;
2328 
2329  name_space = gnc_commodity_table_map_namespace(name_space);
2330  return g_hash_table_lookup(table->ns_table, (gpointer)name_space);
2331 }

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

2176 {
2177  gnc_commodity_namespace * ns = NULL;
2178 
2179  if (!table)
2180  return NULL;
2181  if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONCURRENCY) == 0)
2182  return commodity_table_get_all_noncurrency_commodities(table);
2183  ns = gnc_commodity_table_find_namespace(table, name_space);
2184  if (!ns)
2185  return NULL;
2186 
2187  return g_hash_table_values(ns->cm_table);
2188 }
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
This function finds a commodity namespace in the set of existing commodity namespaces.

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

2103 {
2104  if (!table)
2105  return NULL;
2106 
2107  return g_hash_table_keys(table->ns_table);
2108 }

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

2112 {
2113  if (!table)
2114  return NULL;
2115 
2116  return table->ns_list;
2117 }

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

2223 {
2224  gnc_commodity_namespace * ns = NULL;
2225  const char *name_space;
2226  GList * nslist, * tmp;
2227  GList * l = NULL;
2228  regex_t pattern;
2229  const char *expression = gnc_prefs_get_namespace_regexp();
2230 
2231  ENTER("table=%p, expression=%s", table, expression);
2232  if (!table)
2233  return NULL;
2234 
2235  if (expression && *expression)
2236  {
2237  if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2238  {
2239  LEAVE("Cannot compile regex");
2240  return NULL;
2241  }
2242 
2244  for (tmp = nslist; tmp; tmp = tmp->next)
2245  {
2246  name_space = tmp->data;
2247  if (regexec(&pattern, name_space, 0, NULL, 0) == 0)
2248  {
2249  DEBUG("Running list of %s commodities", name_space);
2250  ns = gnc_commodity_table_find_namespace(table, name_space);
2251  if (ns)
2252  {
2253  g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2254  }
2255  }
2256  }
2257  g_list_free(nslist);
2258  regfree(&pattern);
2259  }
2260  else
2261  {
2262  gnc_commodity_table_foreach_commodity(table, get_quotables_helper2,
2263  (gpointer) &l);
2264  }
2265  LEAVE("list head %p", l);
2266  return l;
2267 }
gboolean gnc_commodity_table_foreach_commodity(const gnc_commodity_table *table, gboolean(*f)(gnc_commodity *cm, gpointer user_data), gpointer user_data)
Call a function once for each commodity in the commodity table.
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:260
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
Return a list of all namespaces in the commodity table.
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
This function finds a commodity namespace in the set of existing commodity namespaces.
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

1807 {
1808  guint count = 0;
1809  g_return_val_if_fail(tbl, 0);
1810  g_return_val_if_fail(tbl->ns_table, 0);
1811 
1812  g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1813 
1814  return count;
1815 }

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

2047 {
2048  gnc_commodity_namespace * nsp = NULL;
2049 
2050  if (!table || !name_space)
2051  {
2052  return 0;
2053  }
2054 
2055  nsp = gnc_commodity_table_find_namespace(table, name_space);
2056  if (nsp)
2057  {
2058  return 1;
2059  }
2060  else
2061  {
2062  return 0;
2063  }
2064 }
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
This function finds a commodity namespace in the set of existing commodity namespaces.

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

1934 {
1935  gnc_commodity_namespace * nsp = NULL;
1936  gnc_commodity *c;
1937  const char *ns_name;
1938  CommodityPrivate* priv;
1939  QofBook *book;
1940 
1941  if (!table) return NULL;
1942  if (!comm) return NULL;
1943 
1944  priv = GET_PRIVATE(comm);
1945 
1946  ENTER ("(table=%p, comm=%p) %s %s", table, comm,
1947  (priv->mnemonic == NULL ? "(null)" : priv->mnemonic),
1948  (priv->fullname == NULL ? "(null)" : priv->fullname));
1949  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1950  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1951 
1952  if (c)
1953  {
1954  if (c == comm)
1955  {
1956  LEAVE("already in table");
1957  return c;
1958  }
1959 
1960  /* Backward compatibility support for currencies that have
1961  * recently changed. */
1962  if (priv->name_space->iso4217)
1963  {
1964  guint i;
1965  for (i = 0; i < GNC_NEW_ISO_CODES; i++)
1966  {
1967  if (!priv->mnemonic
1968  || !strcmp(priv->mnemonic, gnc_new_iso_codes[i].old_code))
1969  {
1970  gnc_commodity_set_mnemonic(comm, gnc_new_iso_codes[i].new_code);
1971  break;
1972  }
1973  }
1974  }
1975  gnc_commodity_copy (c, comm);
1976  gnc_commodity_destroy (comm);
1977  LEAVE("found at %p", c);
1978  return c;
1979  }
1980 
1981  /* Prevent setting anything except template in namespace template. */
1982  if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
1983  g_strcmp0 (priv->mnemonic, "template") != 0)
1984  {
1985  PWARN("Converting commodity %s from namespace template to "
1986  "namespace User", priv->mnemonic);
1987  gnc_commodity_set_namespace (comm, "User");
1988  ns_name = "User";
1989  mark_commodity_dirty (comm);
1990  }
1991 
1992  book = qof_instance_get_book (&comm->inst);
1993  nsp = gnc_commodity_table_add_namespace(table, ns_name, book);
1994 
1995  PINFO ("insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1996  nsp->cm_table, nsp->name);
1997  g_hash_table_insert(nsp->cm_table,
1998  CACHE_INSERT(priv->mnemonic),
1999  (gpointer)comm);
2000  nsp->cm_list = g_list_append(nsp->cm_list, comm);
2001 
2002  qof_event_gen (&comm->inst, QOF_EVENT_ADD, NULL);
2003  LEAVE ("(table=%p, comm=%p)", table, comm);
2004  return comm;
2005 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:254
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
gnc_commodity_namespace * gnc_commodity_table_add_namespace(gnc_commodity_table *table, const char *name_space, QofBook *book)
This function adds a new string to the list of commodity namespaces.
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data strucure.
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:248
void gnc_commodity_set_mnemonic(gnc_commodity *cm, const char *mnemonic)
Set the mnemonic for the specified commodity.
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276
void gnc_commodity_set_namespace(gnc_commodity *cm, const char *name_space)
Set the namespace for the specified commodity.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:234
void gnc_commodity_copy(gnc_commodity *dest, const gnc_commodity *src)
Copy src into dest.
void gnc_commodity_destroy(gnc_commodity *cm)
Destroy a commodity.

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

1744 {
1745  gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1746  retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1747  retval->ns_list = NULL;
1748  return retval;
1749 }

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

2015 {
2016  gnc_commodity_namespace * nsp;
2017  gnc_commodity *c;
2018  CommodityPrivate* priv;
2019  const char *ns_name;
2020 
2021  if (!table) return;
2022  if (!comm) return;
2023 
2024  priv = GET_PRIVATE(comm);
2025  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
2026  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
2027  if (c != comm) return;
2028 
2029  qof_event_gen (&comm->inst, QOF_EVENT_REMOVE, NULL);
2030 
2031  nsp = gnc_commodity_table_find_namespace(table, ns_name);
2032  if (!nsp) return;
2033 
2034  nsp->cm_list = g_list_remove(nsp->cm_list, comm);
2035  g_hash_table_remove (nsp->cm_table, priv->mnemonic);
2036  /* XXX minor mem leak, should remove the key as well */
2037 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data strucure.
gnc_commodity_namespace * gnc_commodity_table_find_namespace(const gnc_commodity_table *table, const char *name_space)
This function finds a commodity namespace in the set of existing commodity namespaces.
void qof_event_gen(QofInstance *entity, QofEventId event_id, gpointer event_data)
Invoke all registered event handlers using the given arguments.
Definition: qofevent.cpp:234

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

1376 {
1377  CommodityPrivate* priv;
1378 
1379  ENTER ("(cm=%p, flag=%d)", cm, flag);
1380 
1381  if (!cm)
1382  {
1383  LEAVE("");
1384  return;
1385  }
1386 
1387  priv = GET_PRIVATE(cm);
1388  gnc_commodity_begin_edit(cm);
1389  gnc_commodity_set_quote_flag(cm, flag);
1390  if (gnc_commodity_is_iso(cm))
1391  {
1392  /* For currencies, disable auto quote control if the quote flag is being
1393  * changed from its default value and enable it if the quote flag is being
1394  * reset to its default value. The defaults for the quote flag are
1395  * disabled if no accounts are using the currency, and true otherwise.
1396  * Thus enable auto quote control if flag is FALSE and there are not any
1397  * accounts using this currency OR flag is TRUE and there are accounts
1398  * using this currency; otherwise disable auto quote control */
1399  gnc_commodity_set_auto_quote_control_flag(cm,
1400  (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1401  }
1402  gnc_commodity_commit_edit(cm);
1403  LEAVE("");
1404 }
void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
Set the automatic price quote flag for the specified commodity.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276
gboolean gnc_commodity_is_iso(const gnc_commodity *cm)
Checks to see if the specified commodity is an ISO 4217 recognized currency.

◆ gnc_monetary_list_delete_zeros()

MonetaryList* gnc_monetary_list_delete_zeros ( MonetaryList *  list)

Delete all the zero-value entries from a list.

Delete all the zero-value entries from a list.

Return list pointer will be a null pointer if there are no non-zero entries

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

2633 {
2634  MonetaryList *node, *next;
2635  for (node = list; node; node = next)
2636  {
2637  gnc_monetary *mon = node->data;
2638  next = node->next;
2639  if (gnc_numeric_zero_p(mon->value))
2640  {
2641  g_free(mon);
2642  list = g_list_delete_link(list, node);
2643  }
2644  }
2645  return list;
2646 }
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.

◆ gnc_monetary_list_free()

void gnc_monetary_list_free ( MonetaryList *  list)

Free a monetary list and all the items it points to.

Free a monetary list and all the items it points to.

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

2651 {
2652  MonetaryList *tmp;
2653  for (tmp = list; tmp; tmp = tmp->next)
2654  {
2655  g_free(tmp->data);
2656  }
2657 
2658  g_list_free(list);
2659 }

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

351 {
352  gnc_quote_source *new_source;
353 
354  DEBUG("Creating new source %s", (source_name == NULL ? "(null)" : source_name));
355  new_source = malloc(sizeof(gnc_quote_source));
356  new_source->supported = supported;
357  new_source->type = SOURCE_UNKNOWN;
358  new_source->index = g_list_length(new_quote_sources);
359 
360  /* This name can be changed if/when support for this price source is
361  * integrated into gnucash. */
362  new_source->user_name = g_strdup(source_name);
363 
364  /* This name is permanent and must be kept the same if/when support
365  * for this price source is integrated into gnucash (i.e. for a
366  * nice user name). */
367  new_source->old_internal_name = g_strdup(source_name);
368  new_source->internal_name = g_strdup(source_name);
369  new_quote_sources = g_list_append(new_quote_sources, new_source);
370  return new_source;
371 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:260
This is a locally installed quote source that gnucash knows nothing about.

◆ 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 user's 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 277 of file gnc-commodity.c.

278 {
279  return (fq_version != NULL);
280 }

◆ gnc_quote_source_fq_version()

const char* gnc_quote_source_fq_version ( void  )

This function returns the version of the Finance::Quote module installed on a user's computer.

If no proper installation is found it will return NULL.

Returns
a version string or NULL

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

291 {
292  return fq_version;
293 }

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

491 {
492  ENTER("%p", source);
493  if (!source)
494  {
495  LEAVE("bad source");
496  return 0;
497  }
498 
499  LEAVE("index is %d", source->index);
500  return source->index;
501 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

532 {
533  ENTER("%p", source);
534  if (!source)
535  {
536  LEAVE("bad source");
537  return NULL;
538  }
539  LEAVE("internal name %s", source->internal_name);
540  return source->internal_name;
541 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

505 {
506  ENTER("%p", source);
507  if (!source)
508  {
509  LEAVE("bad source");
510  return FALSE;
511  }
512 
513  LEAVE("%ssupported", source && source->supported ? "" : "not ");
514  return source->supported;
515 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

477 {
478  ENTER("%p", source);
479  if (!source)
480  {
481  LEAVE("bad source");
482  return SOURCE_SINGLE;
483  }
484 
485  LEAVE("type is %d", source->type);
486  return source->type;
487 }
This quote source pulls from a single specific web site.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

519 {
520  ENTER("%p", source);
521  if (!source)
522  {
523  LEAVE("bad source");
524  return NULL;
525  }
526  LEAVE("user name %s", source->user_name);
527  return source->user_name;
528 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

426 {
427  gnc_quote_source *source;
428  GList *node;
429  gint i;
430 
431  if ((name == NULL) || (g_strcmp0(name, "") == 0))
432  {
433  return NULL;
434  }
435 
436  if (g_strcmp0(name, currency_quote_source.internal_name) == 0)
437  return &currency_quote_source;
438  if (g_strcmp0(name, currency_quote_source.old_internal_name) == 0)
439  return &currency_quote_source;
440 
441  for (i = 0; i < num_single_quote_sources; i++)
442  {
443  if (g_strcmp0(name, single_quote_sources[i].internal_name) == 0)
444  return &single_quote_sources[i];
445  if (g_strcmp0(name, single_quote_sources[i].old_internal_name) == 0)
446  return &single_quote_sources[i];
447  }
448 
449  for (i = 0; i < num_multiple_quote_sources; i++)
450  {
451  if (g_strcmp0(name, multiple_quote_sources[i].internal_name) == 0)
452  return &multiple_quote_sources[i];
453  if (g_strcmp0(name, multiple_quote_sources[i].old_internal_name) == 0)
454  return &multiple_quote_sources[i];
455  }
456 
457  for (i = 0, node = new_quote_sources; node; node = node->next, i++)
458  {
459  source = node->data;
460  if (g_strcmp0(name, source->internal_name) == 0)
461  return source;
462  if (g_strcmp0(name, source->old_internal_name) == 0)
463  return source;
464  }
465 
466  DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
467  return NULL;
468 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:260

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

380 {
381  gnc_quote_source *source;
382  GList *node;
383 
384  ENTER("type/index is %d/%d", type, index);
385  switch (type)
386  {
387  case SOURCE_CURRENCY:
388  LEAVE("found %s", currency_quote_source.user_name);
389  return &currency_quote_source;
390  break;
391 
392  case SOURCE_SINGLE:
393  if (index < num_single_quote_sources)
394  {
395  LEAVE("found %s", single_quote_sources[index].user_name);
396  return &single_quote_sources[index];
397  }
398  break;
399 
400  case SOURCE_MULTI:
401  if (index < num_multiple_quote_sources)
402  {
403  LEAVE("found %s", multiple_quote_sources[index].user_name);
404  return &multiple_quote_sources[index];
405  }
406  break;
407 
408  case SOURCE_UNKNOWN:
409  default:
410  node = g_list_nth(new_quote_sources, index);
411  if (node)
412  {
413  source = node->data;
414  LEAVE("found %s", source->user_name);
415  return source;
416  }
417  break;
418  }
419 
420  LEAVE("not found");
421  return NULL;
422 }
This quote source pulls from a single specific web site.
The special currency quote source.
This is a locally installed quote source that gnucash knows nothing about.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
This quote source may pull from multiple web sites.
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276

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

301 {
302  if (type == SOURCE_CURRENCY)
303  return 1;
304 
305  if (type == SOURCE_SINGLE)
306  return num_single_quote_sources;
307 
308  if (type == SOURCE_MULTI)
309  return num_multiple_quote_sources;
310 
311  return g_list_length(new_quote_sources);
312 }
This quote source pulls from a single specific web site.
The special currency quote source.
This quote source may pull from multiple web sites.

◆ gnc_quote_source_set_fq_installed()

void gnc_quote_source_set_fq_installed ( const char *  version_string,
const GList *  sources_list 
)

Update gnucash internal tables based on what Finance::Quote sources are installed.

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

553 {
554  gnc_quote_source *source;
555  char *source_name;
556  const GList *node;
557 
558  ENTER(" ");
559 
560  if (!sources_list)
561  return;
562 
563  if (fq_version)
564  {
565  g_free (fq_version);
566  fq_version = NULL;
567  }
568 
569  if (version_string)
570  fq_version = g_strdup (version_string);
571 
572  for (node = sources_list; node; node = node->next)
573  {
574  source_name = node->data;
575 
576  source = gnc_quote_source_lookup_by_internal(source_name);
577  if (source != NULL)
578  {
579  DEBUG("Found source %s: %s", source_name, source->user_name);
580  source->supported = TRUE;
581  continue;
582  }
583 
584  gnc_quote_source_add_new(source_name, TRUE);
585  }
586  LEAVE(" ");
587 }
gnc_quote_source * gnc_quote_source_add_new(const char *source_name, gboolean supported)
Create a new quote source.
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:260
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:266
gnc_quote_source * gnc_quote_source_lookup_by_internal(const char *name)
Given the internal (gnucash or F::Q) name of a quote source, find the data structure identified by th...
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:276