GnuCash  5.6-150-g038405b370+
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.
 
file  gnc-commodity.hpp
 Commodity handling public routines (C++ api)
 

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_NONCURRENCY   "NONCURRENCY"
 
#define GNC_COMMODITY_NS_NONISO_GUI   NC_("Commodity Type", "All non-currency")
 
#define GNC_COMMODITY_NS_ISO_GUI   NC_("Commodity Type", "Currencies")
 
#define GNC_COMMODITY_MAX_FRACTION   1000000000
 Max fraction is 10^9 because 10^10 would require changing it to an int64_t.
 

Typedefs

typedef GList CommodityList
 
using CommVec = std::vector< gnc_commodity * >
 

Functions

GType gnc_commodity_get_type (void)
 
GType gnc_commodity_namespace_get_type (void)
 
void gnc_quote_source_set_fq_installed (const char *version_string, const std::vector< std::string > &sources_list)
 Update gnucash internal tables based on what Finance::Quote sources are installed. More...
 
bool gnc_commodity_table_rename_namespace (const gnc_commodity_table *table, const char *namespace_name, const char *new_namespace_name)
 This function renames a namespace. More...
 

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...
 
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

gboolean gnc_commodity_get_auto_quote_control_flag (const gnc_commodity *cm)
 
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 structure 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_auto_quote_control_flag (gnc_commodity *cm, const gboolean flag)
 
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 structure. More...
 
const char * gnc_commodity_namespace_get_gui_name (const gnc_commodity_namespace *ns)
 Return the textual name of a namespace data structure in a form suitable to present to the user. 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 probably shouldn't be using gnc_commodity_table_new() directly, it's 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 987 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 103 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 1503 of file gnc-commodity.cpp.

1504 {
1505  if (a == b) return 0;
1506  if (a && !b) return 1;
1507  if (b && !a) return -1;
1508  if (auto rv = g_strcmp0 (gnc_commodity_get_unique_name (a), gnc_commodity_get_unique_name (b)))
1509  return rv;
1510  return qof_instance_guid_compare(a, b);
1511 }
gint qof_instance_guid_compare(gconstpointer ptr1, gconstpointer ptr2)
Compare the GncGUID values of two instances.
const char * gnc_commodity_get_unique_name(const gnc_commodity *cm)
Retrieve the &#39;unique&#39; name for the specified commodity.

◆ 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 1438 of file gnc-commodity.cpp.

1439 {
1440  gnc_commodityPrivate* priv;
1441 
1442  ENTER("(cm=%p)", cm);
1443 
1444  if (!cm)
1445  {
1446  LEAVE("");
1447  return;
1448  }
1449 
1450  priv = GET_PRIVATE(cm);
1451 
1452  if (priv->usage_count == 0)
1453  {
1454  PWARN("usage_count already zero");
1455  LEAVE("");
1456  return;
1457  }
1458 
1459  priv->usage_count--;
1460  if ((priv->usage_count == 0) && priv->quote_flag
1461  && gnc_commodity_get_auto_quote_control_flag(cm)
1462  && gnc_commodity_is_iso(cm))
1463  {
1464  /* if this is a currency with auto quote control enabled and no more
1465  * accounts reference this currency, disable quote retrieval */
1466  gnc_commodity_set_quote_flag(cm, FALSE);
1467  }
1468  LEAVE("(usage_count=%d)", priv->usage_count);
1469 }
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:272
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
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 869 of file gnc-commodity.cpp.

870 {
871  gnc_commodity_begin_edit(cm);
872  qof_instance_set_destroying(cm, TRUE);
873  gnc_commodity_commit_edit(cm);
874 }

◆ 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 1498 of file gnc-commodity.cpp.

1499 {
1500  return gnc_commodity_compare(a, b) == 0;
1501 }
int gnc_commodity_compare(const gnc_commodity *a, const gnc_commodity *b)
This routine returns 0 if the two commodities are equal, 1 otherwise.

◆ 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 1481 of file gnc-commodity.cpp.

1482 {
1483  gnc_commodityPrivate* priv_a;
1484  gnc_commodityPrivate* priv_b;
1485 
1486  if (a == b) return TRUE;
1487  if (!a || !b) return FALSE;
1488 
1489  priv_a = GET_PRIVATE(a);
1490  priv_b = GET_PRIVATE(b);
1491  if (priv_a->name_space != priv_b->name_space) return FALSE;
1492  if (g_strcmp0(priv_a->mnemonic, priv_b->mnemonic) != 0) return FALSE;
1493 
1494  return TRUE;
1495 }

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

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

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

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

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

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

◆ 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 970 of file gnc-commodity.cpp.

971 {
972  if (!cm) return nullptr;
973  return GET_PRIVATE(cm)->fullname;
974 }

◆ 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 929 of file gnc-commodity.cpp.

930 {
931  if (!cm) return nullptr;
932  return GET_PRIVATE(cm)->mnemonic;
933 }

◆ 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 952 of file gnc-commodity.cpp.

953 {
954  if (!cm) return nullptr;
955  return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
956 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure.

◆ gnc_commodity_get_namespace_ds()

gnc_commodity_namespace* gnc_commodity_get_namespace_ds ( const gnc_commodity *  cm)

Retrieve the namespace data structure 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 959 of file gnc-commodity.cpp.

960 {
961  if (!cm) return nullptr;
962  return GET_PRIVATE(cm)->name_space;
963 }

◆ 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 1096 of file gnc-commodity.cpp.

1097 {
1098  const char *nice_symbol;
1099  struct lconv *lc;
1100  if (!cm) return nullptr;
1101 
1102  nice_symbol = gnc_commodity_get_user_symbol(cm);
1103  if (nice_symbol && *nice_symbol)
1104  return nice_symbol;
1105 
1106  lc = gnc_localeconv();
1107  nice_symbol = lc->currency_symbol;
1108  if (!g_strcmp0(gnc_commodity_get_mnemonic(cm), lc->int_curr_symbol))
1109  return nice_symbol;
1110 
1111  nice_symbol = gnc_commodity_get_default_symbol(cm);
1112  if (nice_symbol && *nice_symbol)
1113  return nice_symbol;
1114 
1115  return gnc_commodity_get_mnemonic(cm);
1116 }
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 940 of file gnc-commodity.cpp.

941 {
942  if (!cm) return nullptr;
943  return GET_PRIVATE(cm)->printname;
944 }

◆ 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 1028 of file gnc-commodity.cpp.

1029 {
1030  if (!cm) return FALSE;
1031  return (GET_PRIVATE(cm)->quote_flag);
1032 }

◆ 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 1039 of file gnc-commodity.cpp.

1040 {
1041  gnc_commodityPrivate* priv;
1042 
1043  if (!cm) return nullptr;
1044  priv = GET_PRIVATE(cm);
1045  if (!priv->quote_source && gnc_commodity_is_iso(cm))
1046  return &currency_quote_sources.front();
1047  return priv->quote_source;
1048 }
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 1064 of file gnc-commodity.cpp.

1065 {
1066  if (!cm) return nullptr;
1067  return GET_PRIVATE(cm)->quote_tz;
1068 }

◆ 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 982 of file gnc-commodity.cpp.

983 {
984  if (!cm) return nullptr;
985  return GET_PRIVATE(cm)->unique_name;
986 }

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

1075 {
1076  g_return_val_if_fail (GNC_IS_COMMODITY (cm), nullptr);
1077 
1078  auto sym{qof_instance_get_path_kvp<const char*> (QOF_INSTANCE(cm), {"user_symbol"})};
1079  return sym ? *sym : nullptr;
1080 }

◆ 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 1403 of file gnc-commodity.cpp.

1404 {
1405  gnc_commodityPrivate* priv;
1406 
1407  ENTER("(cm=%p)", cm);
1408 
1409  if (!cm)
1410  {
1411  LEAVE("");
1412  return;
1413  }
1414 
1415  priv = GET_PRIVATE(cm);
1416 
1417  if ((priv->usage_count == 0) && !priv->quote_flag
1418  && gnc_commodity_get_auto_quote_control_flag(cm)
1419  && gnc_commodity_is_iso(cm))
1420  {
1421  /* compatibility hack - Gnucash 1.8 gets currency quotes when a
1422  non-default currency is assigned to an account. */
1423  gnc_commodity_begin_edit(cm);
1424  gnc_commodity_set_quote_flag(cm, TRUE);
1426  gnc_commodity_get_default_quote_source(cm));
1427  gnc_commodity_commit_edit(cm);
1428  }
1429  priv->usage_count++;
1430  LEAVE("(usage_count=%d)", priv->usage_count);
1431 }
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:272
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:282
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 1954 of file gnc-commodity.cpp.

1955 {
1956  const char *ns_name;
1957  if (!cm) return FALSE;
1958 
1959  ns_name = gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->name_space);
1960  return (!g_strcmp0(ns_name, GNC_COMMODITY_NS_LEGACY) ||
1961  !g_strcmp0(ns_name, GNC_COMMODITY_NS_CURRENCY));
1962 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure.
#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 1942 of file gnc-commodity.cpp.

1943 {
1944  gnc_commodityPrivate* priv;
1945 
1946  if (!cm) return FALSE;
1947 
1948  priv = GET_PRIVATE(cm);
1949  if ( !priv->name_space) return FALSE;
1950  return priv->name_space->iso4217;
1951 }

◆ 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 caller who must free the list.

Definition at line 1542 of file gnc-commodity.cpp.

1543 {
1544  if (!name_space)
1545  return nullptr;
1546 
1547  return g_list_copy (name_space->cm_list);
1548 }

◆ 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 structure in a form suitable to present to the user.

Parameters
nsA pointer to the namespace data structure.
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 1532 of file gnc-commodity.cpp.

1533 {
1534  if (ns == nullptr)
1535  return nullptr;
1536  if (g_strcmp0 (ns->name, GNC_COMMODITY_NS_CURRENCY) == 0)
1537  return GNC_COMMODITY_NS_ISO_GUI;
1538  return ns->name;
1539 }

◆ 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 structure.

Parameters
nsA pointer to the namespace data structure.
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 1524 of file gnc-commodity.cpp.

1525 {
1526  if (ns == nullptr)
1527  return nullptr;
1528  return ns->name;
1529 }

◆ 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 1551 of file gnc-commodity.cpp.

1552 {
1553  return ((g_strcmp0(name_space, GNC_COMMODITY_NS_ISO) == 0) ||
1554  (g_strcmp0(name_space, GNC_COMMODITY_NS_CURRENCY) == 0));
1555 }

◆ 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 776 of file gnc-commodity.cpp.

779 {
780  auto retval = GNC_COMMODITY(g_object_new(GNC_TYPE_COMMODITY, nullptr));
781 
782  qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
783  gnc_commodity_begin_edit(retval);
784 
785  if ( name_space != nullptr )
786  {
787  /* Prevent setting anything except template in namespace template. */
788  if (g_strcmp0 (name_space, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
789  g_strcmp0 (mnemonic, "template") != 0)
790  {
791  PWARN("Converting commodity %s from namespace template to "
792  "namespace User", mnemonic);
793  name_space = "User";
794  }
795  gnc_commodity_set_namespace(retval, name_space);
796  if (gnc_commodity_namespace_is_iso(name_space))
797  {
800  }
801  }
802  gnc_commodity_set_fullname(retval, fullname);
803  gnc_commodity_set_mnemonic(retval, mnemonic);
804  gnc_commodity_set_cusip(retval, cusip);
805  gnc_commodity_set_fraction(retval, fraction);
806  mark_commodity_dirty (retval);
807  gnc_commodity_commit_edit(retval);
808 
809  qof_event_gen (&retval->inst, QOF_EVENT_CREATE, nullptr);
810 
811  return retval;
812 }
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:250
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:231

◆ 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 1591 of file gnc-commodity.cpp.

1592 {
1593  gnc_commodity *twin;
1594  const char * ucom;
1595  gnc_commodity_table * comtbl;
1596 
1597  if (!from) return nullptr;
1598  comtbl = gnc_commodity_table_get_table (book);
1599  if (!comtbl) return nullptr;
1600 
1601  ucom = gnc_commodity_get_unique_name (from);
1602  twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
1603  if (!twin)
1604  {
1605  twin = gnc_commodity_clone (from, book);
1606  twin = gnc_commodity_table_insert (comtbl, twin);
1607  }
1608  return twin;
1609 }
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 1198 of file gnc-commodity.cpp.

1200 {
1201  gnc_commodityPrivate* priv;
1202 
1203  if (!cm) return;
1204 
1205  priv = GET_PRIVATE(cm);
1206  if (priv->cusip == cusip) return;
1207 
1208  gnc_commodity_begin_edit(cm);
1209  CACHE_REMOVE (priv->cusip);
1210  priv->cusip = CACHE_INSERT (cusip);
1211  mark_commodity_dirty(cm);
1212  gnc_commodity_commit_edit(cm);
1213 }

◆ 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 1220 of file gnc-commodity.cpp.

1221 {
1222  if (!cm) return;
1223  gnc_commodity_begin_edit(cm);
1224  GET_PRIVATE(cm)->fraction = fraction;
1225  mark_commodity_dirty(cm);
1226  gnc_commodity_commit_edit(cm);
1227 }

◆ 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 1176 of file gnc-commodity.cpp.

1177 {
1178  gnc_commodityPrivate* priv;
1179 
1180  if (!cm) return;
1181  priv = GET_PRIVATE(cm);
1182  if (priv->fullname == fullname) return;
1183 
1184  CACHE_REMOVE (priv->fullname);
1185  priv->fullname = CACHE_INSERT (fullname);
1186 
1187  gnc_commodity_begin_edit(cm);
1188  mark_commodity_dirty(cm);
1189  reset_printname(priv);
1190  gnc_commodity_commit_edit(cm);
1191 }

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

1124 {
1125  gnc_commodityPrivate* priv;
1126 
1127  if (!cm) return;
1128  priv = GET_PRIVATE(cm);
1129  if (priv->mnemonic == mnemonic) return;
1130 
1131  gnc_commodity_begin_edit(cm);
1132  CACHE_REMOVE (priv->mnemonic);
1133  priv->mnemonic = CACHE_INSERT(mnemonic);
1134 
1135  mark_commodity_dirty (cm);
1136  reset_printname(priv);
1137  reset_unique_name(priv);
1138  gnc_commodity_commit_edit(cm);
1139 }

◆ 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 1146 of file gnc-commodity.cpp.

1147 {
1148  QofBook *book;
1149  gnc_commodity_table *table;
1150  gnc_commodity_namespace *nsp;
1151  gnc_commodityPrivate* priv;
1152 
1153  if (!cm) return;
1154  priv = GET_PRIVATE(cm);
1155  book = qof_instance_get_book (&cm->inst);
1157  nsp = gnc_commodity_table_add_namespace(table, name_space, book);
1158  if (priv->name_space == nsp)
1159  return;
1160 
1161  gnc_commodity_begin_edit(cm);
1162  priv->name_space = nsp;
1163  if (nsp->iso4217)
1164  priv->quote_source = gnc_quote_source_lookup_by_internal("currency");
1165  mark_commodity_dirty(cm);
1166  reset_printname(priv);
1167  reset_unique_name(priv);
1168  gnc_commodity_commit_edit(cm);
1169 }
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...
QofBook reference.
Definition: qofbook-p.hpp:46

◆ 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 1293 of file gnc-commodity.cpp.

1294 {
1295  ENTER ("(cm=%p, flag=%d)", cm, flag);
1296 
1297  if (!cm) return;
1298  gnc_commodity_begin_edit(cm);
1299  GET_PRIVATE(cm)->quote_flag = flag;
1300  mark_commodity_dirty(cm);
1301  gnc_commodity_commit_edit(cm);
1302  LEAVE(" ");
1303 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 1310 of file gnc-commodity.cpp.

1311 {
1312  ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->get_internal_name() : "unknown");
1313 
1314  if (!cm) return;
1315  gnc_commodity_begin_edit(cm);
1316  GET_PRIVATE(cm)->quote_source = src;
1317  mark_commodity_dirty(cm);
1318  gnc_commodity_commit_edit(cm);
1319  LEAVE(" ");
1320 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 1327 of file gnc-commodity.cpp.

1328 {
1329  gnc_commodityPrivate* priv;
1330 
1331  if (!cm) return;
1332 
1333  ENTER ("(cm=%p, tz=%s)", cm, tz ? tz : "(null)");
1334 
1335  priv = GET_PRIVATE(cm);
1336 
1337  if (tz == priv->quote_tz)
1338  {
1339  LEAVE("Already correct TZ");
1340  return;
1341  }
1342 
1343  gnc_commodity_begin_edit(cm);
1344  CACHE_REMOVE (priv->quote_tz);
1345  priv->quote_tz = CACHE_INSERT (tz);
1346  mark_commodity_dirty(cm);
1347  gnc_commodity_commit_edit(cm);
1348  LEAVE(" ");
1349 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 1356 of file gnc-commodity.cpp.

1357 {
1358  struct lconv *lc;
1359 
1360  if (!cm) return;
1361 
1362  ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
1363 
1364  lc = gnc_localeconv();
1365  if (!user_symbol || !*user_symbol)
1366  user_symbol = nullptr;
1367  else if (!g_strcmp0(lc->int_curr_symbol, gnc_commodity_get_mnemonic(cm)) &&
1368  !g_strcmp0(lc->currency_symbol, user_symbol))
1369  /* if the user gives the ISO symbol for the locale currency or the
1370  * default symbol, actually remove the user symbol */
1371  user_symbol = nullptr;
1372  else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
1373  user_symbol = nullptr;
1374 
1375  gnc_commodity_begin_edit (cm);
1376 
1377  auto val = user_symbol ? std::make_optional<const char*>(g_strdup(user_symbol)) : std::nullopt;
1378  qof_instance_set_path_kvp<const char*> (QOF_INSTANCE(cm), val, {"user_symbol"});
1379 
1380  mark_commodity_dirty(cm);
1381  gnc_commodity_commit_edit(cm);
1382 
1383  LEAVE(" ");
1384 }
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:272
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:282

◆ 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 2318 of file gnc-commodity.cpp.

2319 {
2320  QofCollection *col;
2321  gnc_commodity* c;
2322 
2323  ENTER ("table=%p", table);
2324  gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_TEMPLATE, book);
2325  c = gnc_commodity_new(book, "template", GNC_COMMODITY_NS_TEMPLATE, "template", "template", 1);
2327 
2328 #include "iso-4217-currencies.c"
2329 
2330  /* We've just created the default namespaces and currencies. Mark
2331  * these collections as clean because there is no USER entered data
2332  * in these collections as of yet. */
2333  col = qof_book_get_collection(book, GNC_ID_COMMODITY);
2335  col = qof_book_get_collection(book, GNC_ID_COMMODITY_NAMESPACE);
2337 
2338  LEAVE ("table=%p", table);
2339  return TRUE;
2340 }
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:272
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:238
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
Definition: qofbook.cpp:521

◆ 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 2107 of file gnc-commodity.cpp.

2110 {
2111  gnc_commodity_namespace * ns = nullptr;
2112 
2113  if (!table) return nullptr;
2114 
2115  name_space = gnc_commodity_table_map_namespace(name_space);
2116  ns = gnc_commodity_table_find_namespace(table, name_space);
2117  if (!ns)
2118  {
2119  ns = static_cast<gnc_commodity_namespace*>(g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, nullptr));
2120  ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
2121  ns->name = CACHE_INSERT(static_cast<const char*>(name_space));
2122  ns->iso4217 = gnc_commodity_namespace_is_iso(name_space);
2123  qof_instance_init_data (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
2124  qof_event_gen (&ns->inst, QOF_EVENT_CREATE, nullptr);
2125 
2126  g_hash_table_insert(table->ns_table,
2127  (gpointer) ns->name,
2128  (gpointer) ns);
2129  table->ns_list = g_list_append(table->ns_list, ns);
2130  qof_event_gen (&ns->inst, QOF_EVENT_ADD, nullptr);
2131  }
2132  return ns;
2133 }
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:231

◆ 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 2203 of file gnc-commodity.cpp.

2205 {
2206  gnc_commodity_namespace * ns;
2207 
2208  if (!table) return;
2209 
2210  ns = gnc_commodity_table_find_namespace(table, name_space);
2211  if (!ns)
2212  return;
2213 
2214  qof_event_gen (&ns->inst, QOF_EVENT_REMOVE, nullptr);
2215  g_hash_table_remove(table->ns_table, name_space);
2216  table->ns_list = g_list_remove(table->ns_list, ns);
2217 
2218  g_list_free(ns->cm_list);
2219  ns->cm_list = nullptr;
2220 
2221  g_hash_table_foreach_remove(ns->cm_table, ns_helper, nullptr);
2222  g_hash_table_destroy(ns->cm_table);
2223  CACHE_REMOVE(ns->name);
2224 
2225  qof_event_gen (&ns->inst, QOF_EVENT_DESTROY, nullptr);
2226  /* qof_instance_release(&ns->inst); */
2227  g_object_unref(ns);
2228 }
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:231

◆ 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 2168 of file gnc-commodity.cpp.

2170 {
2171  if (!table || !name_space)
2172  return nullptr;
2173 
2174  name_space = gnc_commodity_table_map_namespace(name_space);
2175  return static_cast<gnc_commodity_namespace*>(g_hash_table_lookup(table->ns_table, (gpointer)name_space));
2176 }

◆ 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 1990 of file gnc-commodity.cpp.

1992 {
1993  gnc_commodity_namespace * ns = nullptr;
1994 
1995  if (!table)
1996  return nullptr;
1997  if (g_strcmp0(name_space, GNC_COMMODITY_NS_NONISO_GUI) == 0)
1998  return commodity_table_get_all_noncurrency_commodities(table);
1999  ns = gnc_commodity_table_find_namespace(table, name_space);
2000  if (!ns)
2001  return nullptr;
2002 
2003  return g_hash_table_values(ns->cm_table);
2004 }
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 1918 of file gnc-commodity.cpp.

1919 {
1920  if (!table)
1921  return nullptr;
1922 
1923  return g_hash_table_keys(table->ns_table);
1924 }

◆ 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 caller who must free the list.

Definition at line 1927 of file gnc-commodity.cpp.

1928 {
1929  if (!table)
1930  return nullptr;
1931 
1932  return g_list_copy (table->ns_list);
1933 }

◆ 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 2036 of file gnc-commodity.cpp.

2037 {
2038  gnc_commodity_namespace * ns = nullptr;
2039  const char *name_space;
2040  GList * nslist, * tmp;
2041  GList * l = nullptr;
2042  regex_t pattern;
2043  const char *expression = gnc_prefs_get_namespace_regexp();
2044 
2045  ENTER("table=%p, expression=%s", table, expression);
2046  if (!table)
2047  return nullptr;
2048 
2049  if (expression && *expression)
2050  {
2051  if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
2052  {
2053  LEAVE("Cannot compile regex");
2054  return nullptr;
2055  }
2056 
2058  for (tmp = nslist; tmp; tmp = tmp->next)
2059  {
2060  name_space = static_cast<const char*>(tmp->data);
2061  if (regexec(&pattern, name_space, 0, nullptr, 0) == 0)
2062  {
2063  DEBUG("Running list of %s commodities", name_space);
2064  ns = gnc_commodity_table_find_namespace(table, name_space);
2065  if (ns)
2066  {
2067  g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
2068  }
2069  }
2070  }
2071  g_list_free(nslist);
2072  regfree(&pattern);
2073  }
2074  else
2075  {
2076  gnc_commodity_table_foreach_commodity(table, get_quotables_helper2,
2077  (gpointer) &l);
2078  }
2079  LEAVE("list head %p", l);
2080  return l;
2081 }
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:264
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
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:282

◆ 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 1634 of file gnc-commodity.cpp.

1635 {
1636  guint count = 0;
1637  g_return_val_if_fail(tbl, 0);
1638  g_return_val_if_fail(tbl->ns_table, 0);
1639 
1640  g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);
1641 
1642  return count;
1643 }

◆ 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 1861 of file gnc-commodity.cpp.

1863 {
1864  gnc_commodity_namespace * nsp = nullptr;
1865 
1866  if (!table || !name_space)
1867  {
1868  return 0;
1869  }
1870 
1871  nsp = gnc_commodity_table_find_namespace(table, name_space);
1872  if (nsp)
1873  {
1874  return 1;
1875  }
1876  else
1877  {
1878  return 0;
1879  }
1880 }
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 1755 of file gnc-commodity.cpp.

1757 {
1758  gnc_commodity_namespace * nsp = nullptr;
1759  gnc_commodity *c;
1760  const char *ns_name;
1761  gnc_commodityPrivate* priv;
1762  QofBook *book;
1763 
1764  if (!table) return nullptr;
1765  if (!comm) return nullptr;
1766 
1767  priv = GET_PRIVATE(comm);
1768 
1769  ENTER ("(table=%p, comm=%p) %s %s", table, comm,
1770  (priv->mnemonic == nullptr ? "(null)" : priv->mnemonic),
1771  (priv->fullname == nullptr ? "(null)" : priv->fullname));
1772  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1773  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1774 
1775  if (c)
1776  {
1777  if (c == comm)
1778  {
1779  LEAVE("already in table");
1780  return c;
1781  }
1782 
1783  /* Backward compatibility support for currencies that have
1784  * recently changed. */
1785  if (priv->name_space->iso4217)
1786  {
1787  auto it = gnc_new_iso_codes.find (priv->mnemonic);
1788  if (it != gnc_new_iso_codes.end())
1789  gnc_commodity_set_mnemonic(comm, it->second.c_str());
1790  }
1791  gnc_commodity_copy (c, comm);
1792  gnc_commodity_destroy (comm);
1793  LEAVE("found at %p", c);
1794  return c;
1795  }
1796 
1797  /* Prevent setting anything except template in namespace template. */
1798  if (g_strcmp0 (ns_name, GNC_COMMODITY_NS_TEMPLATE) == 0 &&
1799  g_strcmp0 (priv->mnemonic, "template") != 0)
1800  {
1801  PWARN("Converting commodity %s from namespace template to "
1802  "namespace User", priv->mnemonic);
1803  gnc_commodity_set_namespace (comm, "User");
1804  ns_name = "User";
1805  mark_commodity_dirty (comm);
1806  }
1807 
1808  book = qof_instance_get_book (&comm->inst);
1809  nsp = gnc_commodity_table_add_namespace(table, ns_name, book);
1810 
1811  PINFO ("insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
1812  nsp->cm_table, nsp->name);
1813  g_hash_table_insert(nsp->cm_table,
1814  (gpointer)CACHE_INSERT(priv->mnemonic),
1815  (gpointer)comm);
1816  nsp->cm_list = g_list_append(nsp->cm_list, comm);
1817 
1818  qof_event_gen (&comm->inst, QOF_EVENT_ADD, nullptr);
1819  LEAVE ("(table=%p, comm=%p)", table, comm);
1820  return comm;
1821 }
QofBook * qof_instance_get_book(gconstpointer inst)
Return the book pointer.
#define PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
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 structure.
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250
QofBook reference.
Definition: qofbook-p.hpp:46
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:282
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:231
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 probably shouldn't be using gnc_commodity_table_new() directly, it's for internal use only.

You should probably be using gnc_commodity_table_get_table()

Definition at line 1571 of file gnc-commodity.cpp.

1572 {
1573  gnc_commodity_table * retval = g_new0(gnc_commodity_table, 1);
1574  retval->ns_table = g_hash_table_new(&g_str_hash, &g_str_equal);
1575  retval->ns_list = nullptr;
1576  return retval;
1577 }

◆ 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 1829 of file gnc-commodity.cpp.

1831 {
1832  gnc_commodity_namespace * nsp;
1833  gnc_commodity *c;
1834  gnc_commodityPrivate* priv;
1835  const char *ns_name;
1836 
1837  if (!table) return;
1838  if (!comm) return;
1839 
1840  priv = GET_PRIVATE(comm);
1841  ns_name = gnc_commodity_namespace_get_name(priv->name_space);
1842  c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
1843  if (c != comm) return;
1844 
1845  qof_event_gen (&comm->inst, QOF_EVENT_REMOVE, nullptr);
1846 
1847  nsp = gnc_commodity_table_find_namespace(table, ns_name);
1848  if (!nsp) return;
1849 
1850  nsp->cm_list = g_list_remove(nsp->cm_list, comm);
1851  g_hash_table_remove (nsp->cm_table, priv->mnemonic);
1852  /* XXX minor mem leak, should remove the key as well */
1853 }
const char * gnc_commodity_namespace_get_name(const gnc_commodity_namespace *ns)
Return the textual name of a namespace data structure.
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:231

◆ gnc_commodity_table_rename_namespace()

bool gnc_commodity_table_rename_namespace ( const gnc_commodity_table *  table,
const char *  namespace_name,
const char *  new_namespace_name 
)

This function renames a namespace.

Parameters
tableA pointer to the commodity table
namespace_nameThe name of the namespace to rename.
new_namespace_nameThe new name for the namespace.
Returns
Return true if rename successful.

Definition at line 2136 of file gnc-commodity.cpp.

2139 {
2140  if (!table || !namespace_name || !new_namespace_name ||
2141  (g_strcmp0 (namespace_name, new_namespace_name) == 0) ||
2142  (g_strcmp0 (new_namespace_name, GNC_COMMODITY_NS_ISO_GUI) == 0) ||
2143  (g_strcmp0 (new_namespace_name, _(GNC_COMMODITY_NS_ISO_GUI)) == 0) ||
2144  gnc_commodity_table_find_namespace (table, new_namespace_name))
2145  return false;
2146 
2147  auto ns = gnc_commodity_table_find_namespace (table, namespace_name);
2148  if (!ns)
2149  return false;
2150 
2151  ns->name = CACHE_INSERT(static_cast<const char*>(new_namespace_name));
2152 
2153  g_hash_table_insert (table->ns_table,
2154  (gpointer) ns->name,
2155  (gpointer) ns);
2156 
2157  g_hash_table_remove (table->ns_table,
2158  (gpointer) namespace_name);
2159 
2160  CACHE_REMOVE(namespace_name);
2161 
2162  qof_instance_set_dirty (&ns->inst);
2163  qof_event_gen (&ns->inst, QOF_EVENT_MODIFY, nullptr);
2164  return true;
2165 }
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:231

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

1258 {
1259  gnc_commodityPrivate* priv;
1260 
1261  ENTER ("(cm=%p, flag=%d)", cm, flag);
1262 
1263  if (!cm)
1264  {
1265  LEAVE("");
1266  return;
1267  }
1268 
1269  priv = GET_PRIVATE(cm);
1270  gnc_commodity_begin_edit(cm);
1271  gnc_commodity_set_quote_flag(cm, flag);
1272  if (gnc_commodity_is_iso(cm))
1273  {
1274  /* For currencies, disable auto quote control if the quote flag is being
1275  * changed from its default value and enable it if the quote flag is being
1276  * reset to its default value. The defaults for the quote flag are
1277  * disabled if no accounts are using the currency, and true otherwise.
1278  * Thus enable auto quote control if flag is FALSE and there are not any
1279  * accounts using this currency OR flag is TRUE and there are accounts
1280  * using this currency; otherwise disable auto quote control */
1281  gnc_commodity_set_auto_quote_control_flag(cm,
1282  (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
1283  }
1284  gnc_commodity_commit_edit(cm);
1285  LEAVE("");
1286 }
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:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282
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 2470 of file gnc-commodity.cpp.

2471 {
2472  MonetaryList *node, *next;
2473  for (node = list; node; node = next)
2474  {
2475  auto mon = static_cast<gnc_monetary*>(node->data);
2476  next = node->next;
2477  if (gnc_numeric_zero_p(mon->value))
2478  {
2479  g_free(mon);
2480  list = g_list_delete_link(list, node);
2481  }
2482  }
2483  return list;
2484 }
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 2488 of file gnc-commodity.cpp.

2489 {
2490  MonetaryList *tmp;
2491  for (tmp = list; tmp; tmp = tmp->next)
2492  {
2493  g_free(tmp->data);
2494  }
2495 
2496  g_list_free(list);
2497 }

◆ 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 318 of file gnc-commodity.cpp.

319 {
320  DEBUG("Creating new source %s", (!source_name ? "(null)" : source_name));
321  /* This name can be changed if/when support for this price source is
322  * integrated into gnucash. */
323  /* This name is permanent and must be kept the same if/when support
324  * for this price source is integrated into gnucash (i.e. for a
325  * nice user name). */
326  return &new_quote_sources.emplace_back (supported, SOURCE_UNKNOWN, source_name, source_name);
327 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264
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 266 of file gnc-commodity.cpp.

267 {
268  return (!fq_version.empty());
269 }

◆ 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 279 of file gnc-commodity.cpp.

280 {
281  return fq_version.c_str();
282 }

◆ 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 389 of file gnc-commodity.cpp.

390 {
391  if (!source)
392  {
393  PWARN ("bad source");
394  return 0;
395  }
396 
397  auto& sources = get_quote_source_from_type (source->get_type());
398  auto is_source = [&source](const auto& findif_source)
399  { return &findif_source == source; };
400 
401  auto iter = std::find_if (sources.begin(), sources.end(), is_source);
402  if (iter != sources.end())
403  return std::distance (sources.begin(), iter);
404 
405  PWARN ("couldn't locate source");
406  return 0;
407 }
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250

◆ 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 437 of file gnc-commodity.cpp.

438 {
439  ENTER("%p", source);
440  if (!source)
441  {
442  LEAVE("bad source");
443  return nullptr;
444  }
445  LEAVE("internal name %s", source->get_internal_name());
446  return source->get_internal_name();
447 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 410 of file gnc-commodity.cpp.

411 {
412  ENTER("%p", source);
413  if (!source)
414  {
415  LEAVE("bad source");
416  return FALSE;
417  }
418 
419  LEAVE("%s supported", source && source->get_supported() ? "" : "not ");
420  return source->get_supported();
421 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 375 of file gnc-commodity.cpp.

376 {
377  ENTER("%p", source);
378  if (!source)
379  {
380  LEAVE("bad source");
381  return SOURCE_SINGLE;
382  }
383 
384  LEAVE("type is %d", source->get_type());
385  return source->get_type();
386 }
This quote source pulls from a single specific web site.
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 424 of file gnc-commodity.cpp.

425 {
426  ENTER("%p", source);
427  if (!source)
428  {
429  LEAVE("bad source");
430  return nullptr;
431  }
432  LEAVE("user name %s", source->get_user_name());
433  return source->get_user_name();
434 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 351 of file gnc-commodity.cpp.

352 {
353  if (!name || !*name)
354  return nullptr;
355 
356  for (const auto& [_, sources] : quote_sources_map)
357  {
358  auto source_it = std::find_if (sources.begin(), sources.end(),
359  [name] (const auto& qs)
360  { return (g_strcmp0(name, qs.get_internal_name()) == 0); });
361  if (source_it != sources.end())
362  return &(*source_it);
363  }
364 
365  DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
366  return nullptr;
367 }
#define DEBUG(format, args...)
Print a debugging message.
Definition: qoflog.h:264

◆ 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 335 of file gnc-commodity.cpp.

336 {
337  ENTER("type/index is %d/%d", type, index);
338  auto& sources = get_quote_source_from_type (type);
339  if ((size_t) index < sources.size())
340  {
341  auto it = std::next(sources.begin(), index);
342  LEAVE("found %s", it->get_user_name());
343  return &*it;
344  }
345 
346  LEAVE("not found");
347  return nullptr;
348 }
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition: qoflog.h:282

◆ 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 302 of file gnc-commodity.cpp.

303 {
304  return get_quote_source_from_type(type).size();
305 }

◆ gnc_quote_source_set_fq_installed()

void gnc_quote_source_set_fq_installed ( const char *  version_string,
const std::vector< std::string > &  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 457 of file gnc-commodity.cpp.

459 {
460  ENTER(" ");
461 
462  if (sources_list.empty())
463  return;
464 
465  if (version_string)
466  fq_version = version_string;
467  else
468  fq_version.clear();
469 
470  for (const auto& source_name_str : sources_list)
471  {
472  auto source_name = source_name_str.c_str();
473  auto source = gnc_quote_source_lookup_by_internal(source_name);
474 
475  if (source)
476  {
477  DEBUG("Found source %s: %s", source_name, source->get_user_name());
478  source->set_supported (true);
479  continue;
480  }
481 
482  gnc_quote_source_add_new(source_name, TRUE);
483  }
484  LEAVE(" ");
485 }
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:264
#define ENTER(format, args...)
Print a function entry debugging message.
Definition: qoflog.h:272
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:282