GnuCash  2.6.99
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_ISO   "ISO4217"
 
#define GNC_COMMODITY_NS_CURRENCY   _("CURRENCY")
 
#define GNC_COMMODITY_NS_NASDAQ   "NASDAQ"
 
#define GNC_COMMODITY_NS_NYSE   "NYSE"
 
#define GNC_COMMODITY_NS_EUREX   "EUREX"
 
#define GNC_COMMODITY_NS_MUTUAL   "FUND"
 
#define GNC_COMMODITY_NS_AMEX   "AMEX"
 
#define GNC_COMMODITY_NS_ASX   "ASX"
 
#define GNC_COMMODITY_NS_NONCURRENCY   _("ALL NON-CURRENCY")
 

Typedefs

typedef GList CommodityList
 

Functions

GType gnc_commodity_get_type (void)
 
GType gnc_commodity_namespace_get_type (void)
 

Commodity Quote Source functions

enum  QuoteSourceType {
  SOURCE_SINGLE = 0, SOURCE_MULTI, SOURCE_UNKNOWN, SOURCE_MAX,
  SOURCE_CURRENCY = SOURCE_MAX
}
 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 users computer. More...
 
void gnc_quote_source_set_fq_installed (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...
 
const char * gnc_commodity_get_namespace_compat (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...
 
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 978 of file gnc-commodity.h.

◆ GNC_COMMODITY_NS_LEGACY

#define GNC_COMMODITY_NS_LEGACY   "GNC_LEGACY_CURRENCIES"

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

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

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

Enumeration Type Documentation

◆ QuoteSourceType

The quote source type enum account types are used to determine how the transaction data in the account is displayed.

These values can be safely changed from one release to the next.

Enumerator
SOURCE_SINGLE 

This quote source pulls from a single specific web site.

For example, the yahoo_australia source only pulls from the yahoo web site.

SOURCE_MULTI 

This quote source may pull from multiple web sites.

For example, the australia source may pull from ASX, yahoo, etc.

SOURCE_UNKNOWN 

This is a locally installed quote source that gnucash knows nothing about.

May pull from single or multiple locations.

SOURCE_CURRENCY 

The special currency quote source.

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

120 {
121  SOURCE_SINGLE = 0,
125  SOURCE_MULTI,
132  SOURCE_MAX,
133  SOURCE_CURRENCY = SOURCE_MAX,
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 1655 of file gnc-commodity.c.

1656 {
1657  if (gnc_commodity_equal(a, b))
1658  {
1659  return 0;
1660  }
1661  else
1662  {
1663  return 1;
1664  }
1665 }
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 1541 of file gnc-commodity.c.

1542 {
1543  CommodityPrivate* priv;
1544 
1545  ENTER("(cm=%p)", cm);
1546 
1547  if (!cm)
1548  {
1549  LEAVE("");
1550  return;
1551  }
1552 
1553  priv = GET_PRIVATE(cm);
1554 
1555  if (priv->usage_count == 0)
1556  {
1557  PWARN("usage_count already zero");
1558  LEAVE("");
1559  return;
1560  }
1561 
1562  priv->usage_count--;
1563  if ((priv->usage_count == 0) && priv->quote_flag
1564  && gnc_commodity_get_auto_quote_control_flag(cm)
1565  && gnc_commodity_is_iso(cm))
1566  {
1567  /* if this is a currency with auto quote control enabled and no more
1568  * accounts reference this currency, disable quote retrieval */
1569  gnc_commodity_set_quote_flag(cm, FALSE);
1570  }
1571  LEAVE("(usage_count=%d)", priv->usage_count);
1572 }
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:261
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:243
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271
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 934 of file gnc-commodity.c.

935 {
936  gnc_commodity_begin_edit(cm);
937  qof_instance_set_destroying(cm, TRUE);
938  gnc_commodity_commit_edit(cm);
939 }

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

1601 {
1602  CommodityPrivate* priv_a;
1603  CommodityPrivate* priv_b;
1604  gboolean same_book;
1605 
1606  if (a == b) return TRUE;
1607 
1608  if (!a || !b)
1609  {
1610  DEBUG ("one is NULL");
1611  return FALSE;
1612  }
1613 
1614  priv_a = GET_PRIVATE(a);
1615  priv_b = GET_PRIVATE(b);
1616  same_book = qof_instance_get_book(QOF_INSTANCE(a)) == qof_instance_get_book(QOF_INSTANCE(b));
1617 
1618  if ((same_book && priv_a->name_space != priv_b->name_space)
1619  || (!same_book && g_strcmp0( gnc_commodity_namespace_get_name(priv_a->name_space),
1620  gnc_commodity_namespace_get_name(priv_b->name_space)) != 0))
1621  {
1622  DEBUG ("namespaces differ: %p(%s) vs %p(%s)",
1623  priv_a->name_space, gnc_commodity_namespace_get_name(priv_a->name_space),
1624  priv_b->name_space, gnc_commodity_namespace_get_name(priv_b->name_space));
1625  return FALSE;
1626  }
1627 
1628  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0)
1629  {
1630  DEBUG ("mnemonics differ: %s vs %s", priv_a->mnemonic, priv_b->mnemonic);
1631  return FALSE;
1632  }
1633 
1634  if (g_strcmp0(priv_a->fullname, priv_b->fullname) != 0)
1635  {
1636  DEBUG ("fullnames differ: %s vs %s", priv_a->fullname, priv_b->fullname);
1637  return FALSE;
1638  }
1639 
1640  if (g_strcmp0(priv_a->cusip, priv_b->cusip) != 0)
1641  {
1642  DEBUG ("cusips differ: %s vs %s", priv_a->cusip, priv_b->cusip);
1643  return FALSE;
1644  }
1645 
1646  if (priv_a->fraction != priv_b->fraction)
1647  {
1648  DEBUG ("fractions differ: %d vs %d", priv_a->fraction, priv_b->fraction);
1649  return FALSE;
1650  }
1651 
1652  return TRUE;
1653 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:255
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 1584 of file gnc-commodity.c.

1585 {
1586  CommodityPrivate* priv_a;
1587  CommodityPrivate* priv_b;
1588 
1589  if (a == b) return TRUE;
1590  if (!a || !b) return FALSE;
1591 
1592  priv_a = GET_PRIVATE(a);
1593  priv_b = GET_PRIVATE(b);
1594  if (priv_a->name_space != priv_b->name_space) return FALSE;
1595  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0) return FALSE;
1596  return TRUE;
1597 }

◆ gnc_commodity_get_cusip()

const char* gnc_commodity_get_cusip ( const gnc_commodity *  cm)

Retrieve the 'exchange code' for the specified commodity.

This will be a pointer to a null terminated string of the form "AXQ14728", etc. This field is often used when presenting information to the user.

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

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

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

◆ gnc_commodity_get_default_symbol()

const char* gnc_commodity_get_default_symbol ( const gnc_commodity *  cm)

Retrieve the default symbol for the specified commodity.

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

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

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

1177 {
1178  const char *str;
1179  if (!cm) return NULL;
1180  return GET_PRIVATE(cm)->default_symbol;
1181 }

◆ gnc_commodity_get_fraction()

int gnc_commodity_get_fraction ( const gnc_commodity *  cm)

Retrieve the fraction for the specified commodity.

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

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

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

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

◆ gnc_commodity_get_fullname()

const char* gnc_commodity_get_fullname ( const gnc_commodity *  cm)

Retrieve the full name for the specified commodity.

This will be a pointer to a null terminated string of the form "Acme Systems, Inc.", etc.

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

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

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

◆ gnc_commodity_get_mnemonic()

const char* gnc_commodity_get_mnemonic ( const gnc_commodity *  cm)

Retrieve the mnemonic for the specified commodity.

This will be a pointer to a null terminated string of the form "ACME", "QWER", etc.

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

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

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

◆ gnc_commodity_get_namespace()

const char* gnc_commodity_get_namespace ( const gnc_commodity *  cm)

Retrieve the namespace for the specified commodity.

This will be a pointer to a null terminated string of the form "AMEX", "NASDAQ", etc.

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

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

1018 {
1019  if (!cm) return NULL;
1020  return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
1021 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data strucure.

◆ gnc_commodity_get_namespace_compat()

const char* gnc_commodity_get_namespace_compat ( const gnc_commodity *  cm)

Retrieve the namespace for the specified commodity.

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

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

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

1025 {
1026  CommodityPrivate* priv;
1027 
1028  if (!cm) return NULL;
1029  priv = GET_PRIVATE(cm);
1030  if (!priv->name_space) return NULL;
1031  if (priv->name_space->iso4217)
1032  {
1033  /* Data files are still written with ISO4217. */
1034  return GNC_COMMODITY_NS_ISO;
1035  }
1036  return gnc_commodity_namespace_get_name(priv->name_space);
1037 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
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 1040 of file gnc-commodity.c.

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

◆ gnc_commodity_get_nice_symbol()

const char* gnc_commodity_get_nice_symbol ( const gnc_commodity *  cm)

Retrieve a symbol for the specified commodity, suitable for display to the user.

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

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

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

1188 {
1189  const char *nice_symbol;
1190  struct lconv *lc;
1191  if (!cm) return NULL;
1192 
1193  nice_symbol = gnc_commodity_get_user_symbol(cm);
1194  if (nice_symbol && *nice_symbol)
1195  return nice_symbol;
1196 
1197  lc = gnc_localeconv();
1198  nice_symbol = lc->currency_symbol;
1199  if (!g_strcmp0(gnc_commodity_get_mnemonic(cm), lc->int_curr_symbol))
1200  return nice_symbol;
1201 
1202  nice_symbol = gnc_commodity_get_default_symbol(cm);
1203  if (nice_symbol && *nice_symbol)
1204  return nice_symbol;
1205 
1206  return gnc_commodity_get_mnemonic(cm);
1207 }
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 1005 of file gnc-commodity.c.

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

◆ gnc_commodity_get_quote_flag()

gboolean gnc_commodity_get_quote_flag ( const gnc_commodity *  cm)

Retrieve the automatic price quote flag for the specified commodity.

This flag indicates whether stock quotes should be retrieved for the specified stock.

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

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

1116 {
1117  if (!cm) return FALSE;
1118  return (GET_PRIVATE(cm)->quote_flag);
1119 }

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

1127 {
1128  CommodityPrivate* priv;
1129 
1130  if (!cm) return NULL;
1131  priv = GET_PRIVATE(cm);
1132  if (!priv->quote_source && gnc_commodity_is_iso(cm))
1133  return &currency_quote_source;
1134  return priv->quote_source;
1135 }
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 1151 of file gnc-commodity.c.

1152 {
1153  if (!cm) return NULL;
1154  return GET_PRIVATE(cm)->quote_tz;
1155 }

◆ gnc_commodity_get_unique_name()

const char* gnc_commodity_get_unique_name ( const gnc_commodity *  cm)

Retrieve the 'unique' name for the specified commodity.

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

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

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

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

◆ gnc_commodity_get_user_symbol()

const char* gnc_commodity_get_user_symbol ( const gnc_commodity *  cm)

Retrieve the user-defined symbol for the specified commodity.

This will be a pointer to a nul terminated string like "£", "US$", etc.

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

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

1162 {
1163  const char *str;
1164  GValue v = G_VALUE_INIT;
1165  if (!cm) return NULL;
1166  qof_instance_get_kvp (QOF_INSTANCE(cm), "user_symbol", &v);
1167  if (G_VALUE_HOLDS_STRING (&v))
1168  return g_value_get_string (&v);
1169  return NULL;
1170 }
void qof_instance_get_kvp(const QofInstance *inst, const gchar *key, GValue *value)
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 1506 of file gnc-commodity.c.

1507 {
1508  CommodityPrivate* priv;
1509 
1510  ENTER("(cm=%p)", cm);
1511 
1512  if (!cm)
1513  {
1514  LEAVE("");
1515  return;
1516  }
1517 
1518  priv = GET_PRIVATE(cm);
1519 
1520  if ((priv->usage_count == 0) && !priv->quote_flag
1521  && gnc_commodity_get_auto_quote_control_flag(cm)
1522  && gnc_commodity_is_iso(cm))
1523  {
1524  /* compatibility hack - Gnucash 1.8 gets currency quotes when a
1525  non-default currency is assigned to an account. */
1526  gnc_commodity_begin_edit(cm);
1527  gnc_commodity_set_quote_flag(cm, TRUE);
1529  gnc_commodity_get_default_quote_source(cm));
1530  gnc_commodity_commit_edit(cm);
1531  }
1532  priv->usage_count++;
1533  LEAVE("(usage_count=%d)", priv->usage_count);
1534 }
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:261
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:271
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 2108 of file gnc-commodity.c.

2109 {
2110  const char *ns_name;
2111  if (!cm) return FALSE;
2112 
2113  ns_name = gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
2114  return (!g_strcmp0(ns_name, GNC_COMMODITY_NS_LEGACY) ||
2115  !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
2116 }
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...
Definition: gnc-commodity.h:97

◆ gnc_commodity_is_iso()

gboolean gnc_commodity_is_iso ( const gnc_commodity *  cm)

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

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

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

2097 {
2098  CommodityPrivate* priv;
2099 
2100  if (!cm) return FALSE;
2101 
2102  priv = GET_PRIVATE(cm);
2103  if ( !priv->name_space) return FALSE;
2104  return priv->name_space->iso4217;
2105 }

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

1685 {
1686  if (!name_space)
1687  return NULL;
1688 
1689  return name_space->cm_list;
1690 }

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

1677 {
1678  if (ns == NULL)
1679  return NULL;
1680  return ns->name;
1681 }

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

1694 {
1695  return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1696  (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1697 }

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

844 {
845  gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);
846 
847  qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
848  gnc_commodity_begin_edit(retval);
849 
850  if ( name_space != NULL )
851  {
852  /* Prevent setting anything except template in namespace template. */
853  if (g_strcmp0 (name_space, "template") == 0 &&
854  g_strcmp0 (mnemonic, "template") != 0)
855  {
856  PWARN("Converting commodity %s from namespace template to "
857  "namespace User", mnemonic);
858  name_space = "User";
859  }
860  gnc_commodity_set_namespace(retval, name_space);
861  if (gnc_commodity_namespace_is_iso(name_space))
862  {
865  }
866  }
867  gnc_commodity_set_fullname(retval, fullname);
868  gnc_commodity_set_mnemonic(retval, mnemonic);
869  gnc_commodity_set_cusip(retval, cusip);
870  gnc_commodity_set_fraction(retval, fraction);
871  mark_commodity_dirty (retval);
872  gnc_commodity_commit_edit(retval);
873 
874  qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL);
875 
876  return retval;
877 }
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:243
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 1733 of file gnc-commodity.c.

1734 {
1735  gnc_commodity *twin;
1736  const char * ucom;
1737  gnc_commodity_table * comtbl;
1738 
1739  if (!from) return NULL;
1740  comtbl = gnc_commodity_table_get_table (book);
1741  if (!comtbl) return NULL;
1742 
1743  ucom = gnc_commodity_get_unique_name (from);
1744  twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1745  if (!twin)
1746  {
1747  twin = gnc_commodity_clone (from, book);
1748  twin = gnc_commodity_table_insert (comtbl, twin);
1749  }
1750  return twin;
1751 }
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 1289 of file gnc-commodity.c.

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

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

1312 {
1313  if (!cm) return;
1314  gnc_commodity_begin_edit(cm);
1315  GET_PRIVATE(cm)->fraction = fraction;
1316  mark_commodity_dirty(cm);
1317  gnc_commodity_commit_edit(cm);
1318 }

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

1268 {
1269  CommodityPrivate* priv;
1270 
1271  if (!cm) return;
1272  priv = GET_PRIVATE(cm);
1273  if (priv->fullname == fullname) return;
1274 
1275  CACHE_REMOVE (priv->fullname);
1276  priv->fullname = CACHE_INSERT (fullname);
1277 
1278  gnc_commodity_begin_edit(cm);
1279  mark_commodity_dirty(cm);
1280  reset_printname(priv);
1281  gnc_commodity_commit_edit(cm);
1282 }

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

1215 {
1216  CommodityPrivate* priv;
1217 
1218  if (!cm) return;
1219  priv = GET_PRIVATE(cm);
1220  if (priv->mnemonic == mnemonic) return;
1221 
1222  gnc_commodity_begin_edit(cm);
1223  CACHE_REMOVE (priv->mnemonic);
1224  priv->mnemonic = CACHE_INSERT(mnemonic);
1225 
1226  mark_commodity_dirty (cm);
1227  reset_printname(priv);
1228  reset_unique_name(priv);
1229  gnc_commodity_commit_edit(cm);
1230 }

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

1238 {
1239  QofBook *book;
1240  gnc_commodity_table *table;
1241  gnc_commodity_namespace *nsp;
1242  CommodityPrivate* priv;
1243 
1244  if (!cm) return;
1245  priv = GET_PRIVATE(cm);
1246  book = qof_instance_get_book (&cm->inst);
1247  table = gnc_commodity_table_get_table(book);
1248  nsp = gnc_commodity_table_add_namespace(table, name_space, book);
1249  if (priv->name_space == nsp)
1250  return;
1251 
1252  gnc_commodity_begin_edit(cm);
1253  priv->name_space = nsp;
1254  if (nsp->iso4217)
1255  priv->quote_source = gnc_quote_source_lookup_by_internal("currency");
1256  mark_commodity_dirty(cm);
1257  reset_printname(priv);
1258  reset_unique_name(priv);
1259  gnc_commodity_commit_edit(cm);
1260 }
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 1391 of file gnc-commodity.c.

1392 {
1393  ENTER ("(cm=%p, flag=%d)", cm, flag);
1394 
1395  if (!cm) return;
1396  gnc_commodity_begin_edit(cm);
1397  GET_PRIVATE(cm)->quote_flag = flag;
1398  mark_commodity_dirty(cm);
1399  gnc_commodity_commit_edit(cm);
1400  LEAVE(" ");
1401 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271

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

1409 {
1410  ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name : "unknown");
1411 
1412  if (!cm) return;
1413  gnc_commodity_begin_edit(cm);
1414  GET_PRIVATE(cm)->quote_source = src;
1415  mark_commodity_dirty(cm);
1416  gnc_commodity_commit_edit(cm);
1417  LEAVE(" ");
1418 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271

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

1426 {
1427  CommodityPrivate* priv;
1428 
1429  if (!cm) return;
1430 
1431  ENTER ("(cm=%p, tz=%s)", cm, tz ? tz : "(null)");
1432 
1433  priv = GET_PRIVATE(cm);
1434 
1435  if (tz == priv->quote_tz)
1436  {
1437  LEAVE("Already correct TZ");
1438  return;
1439  }
1440 
1441  gnc_commodity_begin_edit(cm);
1442  CACHE_REMOVE (priv->quote_tz);
1443  priv->quote_tz = CACHE_INSERT (tz);
1444  mark_commodity_dirty(cm);
1445  gnc_commodity_commit_edit(cm);
1446  LEAVE(" ");
1447 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271

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

1455 {
1456  struct lconv *lc;
1457  GValue v = G_VALUE_INIT;
1458  if (!cm) return;
1459 
1460  ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
1461 
1462  gnc_commodity_begin_edit(cm);
1463 
1464  lc = gnc_localeconv();
1465  if (!user_symbol || !*user_symbol)
1466  user_symbol = NULL;
1467  else if (!g_strcmp0(lc->int_curr_symbol, gnc_commodity_get_mnemonic(cm)) &&
1468  !g_strcmp0(lc->currency_symbol, user_symbol))
1469  /* if the user gives the ISO symbol for the locale currency or the
1470  * default symbol, actually remove the user symbol */
1471  user_symbol = NULL;
1472  else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
1473  user_symbol = NULL;
1474  if (user_symbol)
1475  {
1476  g_value_init (&v, G_TYPE_STRING);
1477  g_value_set_string (&v, user_symbol);
1478  qof_instance_set_kvp (QOF_INSTANCE(cm), "user_symbol", &v);
1479  }
1480  else
1481  qof_instance_set_kvp (QOF_INSTANCE(cm), "user_symbol", NULL);
1482 
1483  mark_commodity_dirty(cm);
1484  gnc_commodity_commit_edit(cm);
1485 
1486  LEAVE(" ");
1487 }
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:261
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:271
void qof_instance_set_kvp(QofInstance *inst, const gchar *key, const GValue *value)
Sets a KVP slot to a value from a GValue.

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

2444 {
2445  QofCollection *col;
2446  gnc_commodity* c;
2447 
2448  ENTER ("table=%p", table);
2449  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_AMEX, book);
2450  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NYSE, book);
2451  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NASDAQ, book);
2452  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_EUREX, book);
2453  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_MUTUAL, book);
2454  gnc_commodity_table_add_namespace(table, "template", book);
2455  c = gnc_commodity_new(book, "template", "template", "template", "template", 1);
2457 
2458 #include "iso-4217-currencies.c"
2459 
2460  /* We've just created the default namespaces and currencies. Mark
2461  * these collections as clean because there is no USER entered data
2462  * in these collections as of yet. */
2463  col = qof_book_get_collection(book, GNC_ID_COMMODITY);
2465  col = qof_book_get_collection(book, GNC_ID_COMMODITY_NAMESPACE);
2467 
2468  LEAVE ("table=%p", table);
2469  return TRUE;
2470 }
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:261
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:271
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:599

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

2266 {
2267  gnc_commodity_namespace * ns = NULL;
2268 
2269  if (!table) return NULL;
2270 
2271  name_space = gnc_commodity_table_map_namespace(name_space);
2272  ns = gnc_commodity_table_find_namespace(table, name_space);
2273  if (!ns)
2274  {
2275  ns = g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, NULL);
2276  ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2277  ns->name = CACHE_INSERT((gpointer)name_space);
2278  ns->iso4217 = gnc_commodity_namespace_is_iso(name_space);
2279  qof_instance_init_data (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
2280  qof_event_gen (&ns->inst, QOF_EVENT_CREATE, NULL);
2281 
2282  g_hash_table_insert(table->ns_table,
2283  (gpointer) ns->name,
2284  (gpointer) ns);
2285  table->ns_list = g_list_append(table->ns_list, ns);
2286  qof_event_gen (&ns->inst, QOF_EVENT_ADD, NULL);
2287  }
2288  return ns;
2289 }
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 2328 of file gnc-commodity.c.

2330 {
2331  gnc_commodity_namespace * ns;
2332 
2333  if (!table) return;
2334 
2335  ns = gnc_commodity_table_find_namespace(table, name_space);
2336  if (!ns)
2337  return;
2338 
2339  qof_event_gen (&ns->inst, QOF_EVENT_REMOVE, NULL);
2340  g_hash_table_remove(table->ns_table, name_space);
2341  table->ns_list = g_list_remove(table->ns_list, ns);
2342 
2343  g_list_free(ns->cm_list);
2344  ns->cm_list = NULL;
2345 
2346  g_hash_table_foreach_remove(ns->cm_table, ns_helper, NULL);
2347  g_hash_table_destroy(ns->cm_table);
2348  CACHE_REMOVE(ns->name);
2349 
2350  qof_event_gen (&ns->inst, QOF_EVENT_DESTROY, NULL);
2351  /* qof_instance_release(&ns->inst); */
2352  g_object_unref(ns);
2353 }
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 2293 of file gnc-commodity.c.

2295 {
2296  if (!table || !name_space)
2297  return NULL;
2298 
2299  name_space = gnc_commodity_table_map_namespace(name_space);
2300  return g_hash_table_lookup(table->ns_table, (gpointer)name_space);
2301 }

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

2146 {
2147  gnc_commodity_namespace * ns = NULL;
2148 
2149  if (!table)
2150  return NULL;
2151  if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONCURRENCY) == 0)
2152  return commodity_table_get_all_noncurrency_commodities(table);
2153  ns = gnc_commodity_table_find_namespace(table, name_space);
2154  if (!ns)
2155  return NULL;
2156 
2157  return g_hash_table_values(ns->cm_table);
2158 }
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 2072 of file gnc-commodity.c.

2073 {
2074  if (!table)
2075  return NULL;
2076 
2077  return g_hash_table_keys(table->ns_table);
2078 }

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

2082 {
2083  if (!table)
2084  return NULL;
2085 
2086  return table->ns_list;
2087 }

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

2193 {
2194  gnc_commodity_namespace * ns = NULL;
2195  const char *name_space;
2196  GList * nslist, * tmp;
2197  GList * l = NULL;
2198  regex_t pattern;
2199  const char *expression = gnc_prefs_get_namespace_regexp();
2200 
2201  ENTER("table=%p, expression=%s", table, expression);
2202  if (!table)
2203  return NULL;
2204 
2205  if (expression && *expression)
2206  {
2207  if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2208  {
2209  LEAVE("Cannot compile regex");
2210  return NULL;
2211  }
2212 
2214  for (tmp = nslist; tmp; tmp = tmp->next)
2215  {
2216  name_space = tmp->data;
2217  if (regexec(&pattern, name_space, 0, NULL, 0) == 0)
2218  {
2219  DEBUG("Running list of %s commodities", name_space);
2220  ns = gnc_commodity_table_find_namespace(table, name_space);
2221  if (ns)
2222  {
2223  g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2224  }
2225  }
2226  }
2227  g_list_free(nslist);
2228  regfree(&pattern);
2229  }
2230  else
2231  {
2232  gnc_commodity_table_foreach_commodity(table, get_quotables_helper2,
2233  (gpointer) &l);
2234  }
2235  LEAVE("list head %p", l);
2236  return l;
2237 }
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:255
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
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:271

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

1777 {
1778  guint count = 0;
1779  g_return_val_if_fail(tbl, 0);
1780  g_return_val_if_fail(tbl->ns_table, 0);
1781 
1782  g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1783 
1784  return count;
1785 }

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

2017 {
2018  gnc_commodity_namespace * nsp = NULL;
2019 
2020  if (!table || !name_space)
2021  {
2022  return 0;
2023  }
2024 
2025  nsp = gnc_commodity_table_find_namespace(table, name_space);
2026  if (nsp)
2027  {
2028  return 1;
2029  }
2030  else
2031  {
2032  return 0;
2033  }
2034 }
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 1902 of file gnc-commodity.c.

1904 {
1905  gnc_commodity_namespace * nsp = NULL;
1906  gnc_commodity *c;
1907  const char *ns_name;
1908  CommodityPrivate* priv;
1909  QofBook *book;
1910 
1911  if (!table) return NULL;
1912  if (!comm) return NULL;
1913 
1914  priv = GET_PRIVATE(comm);
1915 
1916  ENTER ("(table=%p, comm=%p) %s %s", table, comm,
1917  (priv->mnemonic == NULL ? "(null)" : priv->mnemonic),
1918  (priv->fullname == NULL ? "(null)" : priv->fullname));
1919  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1920  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1921 
1922  if (c)
1923  {
1924  if (c == comm)
1925  {
1926  LEAVE("already in table");
1927  return c;
1928  }
1929 
1930  /* Backward compatibility support for currencies that have
1931  * recently changed. */
1932  if (priv->name_space->iso4217)
1933  {
1934  guint i;
1935  for (i = 0; i < GNC_NEW_ISO_CODES; i++)
1936  {
1937  if (!priv->mnemonic
1938  || !strcmp(priv->mnemonic, gnc_new_iso_codes[i].old_code))
1939  {
1940  gnc_commodity_set_mnemonic(comm, gnc_new_iso_codes[i].new_code);
1941  break;
1942  }
1943  }
1944  }
1945  gnc_commodity_copy (c, comm);
1946  gnc_commodity_destroy (comm);
1947  LEAVE("found at %p", c);
1948  return c;
1949  }
1950 
1951  /* Prevent setting anything except template in namespace template. */
1952  if (g_strcmp0 (ns_name, "template") == 0 &&
1953  g_strcmp0 (priv->mnemonic, "template") != 0)
1954  {
1955  PWARN("Converting commodity %s from namespace template to "
1956  "namespace User", priv->mnemonic);
1957  gnc_commodity_set_namespace (comm, "User");
1958  ns_name = "User";
1959  mark_commodity_dirty (comm);
1960  }
1961 
1962  book = qof_instance_get_book (&comm->inst);
1963  nsp = gnc_commodity_table_add_namespace(table, ns_name, book);
1964 
1965  PINFO ("insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1966  nsp->cm_table, nsp->name);
1967  g_hash_table_insert(nsp->cm_table,
1968  CACHE_INSERT(priv->mnemonic),
1969  (gpointer)comm);
1970  nsp->cm_list = g_list_append(nsp->cm_list, comm);
1971 
1972  qof_event_gen (&comm->inst, QOF_EVENT_ADD, NULL);
1973  LEAVE ("(table=%p, comm=%p)", table, comm);
1974  return comm;
1975 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:249
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
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:243
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:271
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 1713 of file gnc-commodity.c.

1714 {
1715  gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1716  retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1717  retval->ns_list = NULL;
1718  return retval;
1719 }

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

1985 {
1986  gnc_commodity_namespace * nsp;
1987  gnc_commodity *c;
1988  CommodityPrivate* priv;
1989  const char *ns_name;
1990 
1991  if (!table) return;
1992  if (!comm) return;
1993 
1994  priv = GET_PRIVATE(comm);
1995  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1996  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1997  if (c != comm) return;
1998 
1999  qof_event_gen (&comm->inst, QOF_EVENT_REMOVE, NULL);
2000 
2001  nsp = gnc_commodity_table_find_namespace(table, ns_name);
2002  if (!nsp) return;
2003 
2004  nsp->cm_list = g_list_remove(nsp->cm_list, comm);
2005  g_hash_table_remove (nsp->cm_table, priv->mnemonic);
2006  /* XXX minor mem leak, should remove the key as well */
2007 }
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 1355 of file gnc-commodity.c.

1356 {
1357  CommodityPrivate* priv;
1358 
1359  ENTER ("(cm=%p, flag=%d)", cm, flag);
1360 
1361  if (!cm)
1362  {
1363  LEAVE("");
1364  return;
1365  }
1366 
1367  priv = GET_PRIVATE(cm);
1368  gnc_commodity_begin_edit(cm);
1369  gnc_commodity_set_quote_flag(cm, flag);
1370  if (gnc_commodity_is_iso(cm))
1371  {
1372  /* For currencies, disable auto quote control if the quote flag is being
1373  * changed from its default value and enable it if the quote flag is being
1374  * reset to its default value. The defaults for the quote flag are
1375  * disabled if no accounts are using the currency, and true otherwise.
1376  * Thus enable auto quote control if flag is FALSE and there are not any
1377  * accounts using this currency OR flag is TRUE and there are accounts
1378  * using this currency; otherwise disable auto quote control */
1379  gnc_commodity_set_auto_quote_control_flag(cm,
1380  (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1381  }
1382  gnc_commodity_commit_edit(cm);
1383  LEAVE("");
1384 }
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:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271
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 2602 of file gnc-commodity.c.

2603 {
2604  MonetaryList *node, *next;
2605  for (node = list; node; node = next)
2606  {
2607  gnc_monetary *mon = node->data;
2608  next = node->next;
2609  if (gnc_numeric_zero_p(mon->value))
2610  {
2611  g_free(mon);
2612  list = g_list_delete_link(list, node);
2613  }
2614  }
2615  return list;
2616 }
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 2620 of file gnc-commodity.c.

2621 {
2622  MonetaryList *tmp;
2623  for (tmp = list; tmp; tmp = tmp->next)
2624  {
2625  g_free(tmp->data);
2626  }
2627 
2628  g_list_free(list);
2629 }

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

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

This includes any other related modules that gnucash need to process F::Q information.

Returns
TRUE is F::Q is installed properly.

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

262 {
263  return fq_is_installed;
264 }

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

462 {
463  ENTER("%p", source);
464  if (!source)
465  {
466  LEAVE("bad source");
467  return 0;
468  }
469 
470  LEAVE("index is %d", source->index);
471  return source->index;
472 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271

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

503 {
504  ENTER("%p", source);
505  if (!source)
506  {
507  LEAVE("bad source");
508  return NULL;
509  }
510  LEAVE("internal name %s", source->internal_name);
511  return source->internal_name;
512 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271

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

476 {
477  ENTER("%p", source);
478  if (!source)
479  {
480  LEAVE("bad source");
481  return FALSE;
482  }
483 
484  LEAVE("%ssupported", source && source->supported ? "" : "not ");
485  return source->supported;
486 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271

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

448 {
449  ENTER("%p", source);
450  if (!source)
451  {
452  LEAVE("bad source");
453  return SOURCE_SINGLE;
454  }
455 
456  LEAVE("type is %d", source->type);
457  return source->type;
458 }
This quote source pulls from a single specific web site.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271

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

490 {
491  ENTER("%p", source);
492  if (!source)
493  {
494  LEAVE("bad source");
495  return NULL;
496  }
497  LEAVE("user name %s", source->user_name);
498  return source->user_name;
499 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:271

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

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

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

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

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

272 {
273  if (type == SOURCE_CURRENCY)
274  return 1;
275 
276  if (type == SOURCE_SINGLE)
277  return num_single_quote_sources;
278 
279  if (type == SOURCE_MULTI)
280  return num_multiple_quote_sources;
281 
282  return g_list_length(new_quote_sources);
283 }
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 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 521 of file gnc-commodity.c.

522 {
523  gnc_quote_source *source;
524  char *source_name;
525  const GList *node;
526 
527  ENTER(" ");
528  fq_is_installed = TRUE;
529 
530  if (!sources_list)
531  return;
532 
533  for (node = sources_list; node; node = node->next)
534  {
535  source_name = node->data;
536 
537  source = gnc_quote_source_lookup_by_internal(source_name);
538  if (source != NULL)
539  {
540  DEBUG("Found source %s: %s", source_name, source->user_name);
541  source->supported = TRUE;
542  continue;
543  }
544 
545  gnc_quote_source_add_new(source_name, TRUE);
546  }
547  LEAVE(" ");
548 }
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:255
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:261
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:271