GnuCash 2.3.0
Data Structures | Files | Defines | Typedefs | Functions
Commodities
GnuCash Engine: Core, Non-GUI Accounting Functions

Data Structures

struct  _gnc_monetary

Files

file  gnc-commodity.h
 

Commodity handling public routines.


Defines

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

Typedefs

typedef struct _GncCommodityClass gnc_commodityClass
typedef struct
_GncCommodityNamespaceClass 
gnc_commodity_namespaceClass
typedef GList CommodityList

Functions

GType gnc_commodity_get_type (void)
GType gnc_commodity_namespace_get_type (void)

Commodity Quote Source functions

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

Commodity Creation

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

Commodity Accessor Routines - Get

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

Commodity Accessor Routines - Set

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

Commodity Usage Count Adjustment Routines

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

Commodity Comparison

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

Currency Checks

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

Commodity Table

gnc_commodity_tablegnc_commodity_table_get_table (QofBook *book)

Commodity Table Lookup functions

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

Commodity Table Maintenance functions

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

Commodity Table Namespace functions

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

Commodity Table Accessor functions

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

Commodity Table Private/Internal-Use Only Routines

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

Monetary value, commodity identity and numeric value

typedef struct _gnc_monetary gnc_monetary
typedef GList MonetaryList

Manipulate MonetaryList lists

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

Detailed Description

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

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

Define Documentation

#define GNC_COMMODITY_NS_LEGACY   "GNC_LEGACY_CURRENCIES"

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

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

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


Enumeration Type Documentation

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

Enumerator:
SOURCE_SINGLE 

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

SOURCE_MULTI 

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

SOURCE_UNKNOWN 

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

SOURCE_CURRENCY 

The special currency quote source.

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


Function Documentation

gnc_commodity* gnc_commodity_clone ( const gnc_commodity src,
QofBook dest_book 
)

allocate and copy

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

{
    CommodityPrivate* src_priv;
    CommodityPrivate* dest_priv;

    gnc_commodity * dest = g_object_new(GNC_TYPE_COMMODITY, NULL);
    qof_instance_init_data (&dest->inst, GNC_ID_COMMODITY, dest_book);
    src_priv = GET_PRIVATE(src);
    dest_priv = GET_PRIVATE(dest);

    dest_priv->fullname = CACHE_INSERT(src_priv->fullname);
    dest_priv->mnemonic = CACHE_INSERT(src_priv->mnemonic);
    dest_priv->cusip = CACHE_INSERT(src_priv->cusip);
    dest_priv->quote_tz = CACHE_INSERT(src_priv->quote_tz);

    dest_priv->namespace = src_priv->namespace;

    dest_priv->fraction = src_priv->fraction;
    dest_priv->quote_flag = src_priv->quote_flag;

    gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));

    kvp_frame_delete (dest->inst.kvp_data);
    dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);

    reset_printname(dest_priv);
    reset_unique_name(dest_priv);

    return dest;
}
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 1512 of file gnc-commodity.c.

{
    if (gnc_commodity_equal(a, b))
    {
        return 0;
    }
    else
    {
        return 1;
    }
}
int gnc_commodity_compare_void ( const void *  a,
const void *  b 
)

A wrapper around gnc_commodity_compare() which offers the function declaration that is needed for g_list_find_custom(), which needs void pointers instead of gnc_commodity ones.

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

{
    return gnc_commodity_compare(a, b);
}
void gnc_commodity_copy ( gnc_commodity dest,
const gnc_commodity src 
)

Copy src into dest

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

{
    CommodityPrivate* src_priv = GET_PRIVATE(src);
    CommodityPrivate* dest_priv = GET_PRIVATE(dest);

    gnc_commodity_set_fullname (dest, src_priv->fullname);
    gnc_commodity_set_mnemonic (dest, src_priv->mnemonic);
    dest_priv->namespace = src_priv->namespace;
    gnc_commodity_set_fraction (dest, src_priv->fraction);
    gnc_commodity_set_cusip (dest, src_priv->cusip);
    gnc_commodity_set_quote_flag (dest, src_priv->quote_flag);
    gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
    gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
    kvp_frame_delete (dest->inst.kvp_data);
    dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
    kvp_frame_delete (dest->inst.kvp_data);
    dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
}
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 1398 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    ENTER("(cm=%p)", cm);

    if (!cm)
    {
        LEAVE("");
        return;
    }

    priv = GET_PRIVATE(cm);

    if (priv->usage_count == 0)
    {
        PWARN("usage_count already zero");
        LEAVE("");
        return;
    }

    priv->usage_count--;
    if ((priv->usage_count == 0) && priv->quote_flag
            && gnc_commodity_get_auto_quote_control_flag(cm)
            && gnc_commodity_is_iso(cm))
    {
        /* if this is a currency with auto quote control enabled and no more
         * accounts reference this currency, disable quote retrieval */
        gnc_commodity_set_quote_flag(cm, FALSE);
    }
    LEAVE("(usage_count=%d)", priv->usage_count);
}
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 900 of file gnc-commodity.c.

{
    gnc_commodity_begin_edit(cm);
    qof_instance_set_destroying(cm, TRUE);
    gnc_commodity_commit_edit(cm);
}
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 1457 of file gnc-commodity.c.

{
    CommodityPrivate* priv_a;
    CommodityPrivate* priv_b;
    gboolean same_book;

    if (a == b) return TRUE;

    if (!a || !b)
    {
        DEBUG ("one is NULL");
        return FALSE;
    }

    priv_a = GET_PRIVATE(a);
    priv_b = GET_PRIVATE(b);
    same_book = qof_instance_get_book(QOF_INSTANCE(a)) == qof_instance_get_book(QOF_INSTANCE(b));

    if ((same_book && priv_a->namespace != priv_b->namespace)
            || (!same_book && safe_strcmp( gnc_commodity_namespace_get_name(priv_a->namespace),
                                           gnc_commodity_namespace_get_name(priv_b->namespace)) != 0))
    {
        DEBUG ("namespaces differ: %p(%s) vs %p(%s)",
               priv_a->namespace, gnc_commodity_namespace_get_name(priv_a->namespace),
               priv_b->namespace, gnc_commodity_namespace_get_name(priv_b->namespace));
        return FALSE;
    }

    if (safe_strcmp(priv_a->mnemonic, priv_b->mnemonic) != 0)
    {
        DEBUG ("mnemonics differ: %s vs %s", priv_a->mnemonic, priv_b->mnemonic);
        return FALSE;
    }

    if (safe_strcmp(priv_a->fullname, priv_b->fullname) != 0)
    {
        DEBUG ("fullnames differ: %s vs %s", priv_a->fullname, priv_b->fullname);
        return FALSE;
    }

    if (safe_strcmp(priv_a->cusip, priv_b->cusip) != 0)
    {
        DEBUG ("cusips differ: %s vs %s", priv_a->cusip, priv_b->cusip);
        return FALSE;
    }

    if (priv_a->fraction != priv_b->fraction)
    {
        DEBUG ("fractions differ: %d vs %d", priv_a->fraction, priv_b->fraction);
        return FALSE;
    }

    return TRUE;
}
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 1441 of file gnc-commodity.c.

{
    CommodityPrivate* priv_a;
    CommodityPrivate* priv_b;

    if (a == b) return TRUE;
    if (!a || !b) return FALSE;

    priv_a = GET_PRIVATE(a);
    priv_b = GET_PRIVATE(b);
    if (priv_a->namespace != priv_b->namespace) return FALSE;
    if (safe_strcmp(priv_a->mnemonic, priv_b->mnemonic) != 0) return FALSE;
    return TRUE;
}
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 1045 of file gnc-commodity.c.

{
    if (!cm) return NULL;
    return GET_PRIVATE(cm)->cusip;
}
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 1056 of file gnc-commodity.c.

{
    if (!cm) return 0;
    return GET_PRIVATE(cm)->fraction;
}
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 1021 of file gnc-commodity.c.

{
    if (!cm) return NULL;
    return GET_PRIVATE(cm)->fullname;
}
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 964 of file gnc-commodity.c.

{
    if (!cm) return NULL;
    return GET_PRIVATE(cm)->mnemonic;
}
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 987 of file gnc-commodity.c.

{
    if (!cm) return NULL;
    return gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->namespace);
}
const char* gnc_commodity_get_namespace_compat ( const gnc_commodity cm)

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

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

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

{
    CommodityPrivate* priv;

    if (!cm) return NULL;
    priv = GET_PRIVATE(cm);
    if (!priv->namespace) return NULL;
    if (priv->namespace->iso4217)
    {
        /* Data files are still written with ISO4217. */
        return GNC_COMMODITY_NS_ISO;
    }
    return gnc_commodity_namespace_get_name(priv->namespace);
}
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 1010 of file gnc-commodity.c.

{
    if (!cm) return NULL;
    return GET_PRIVATE(cm)->namespace;
}
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 975 of file gnc-commodity.c.

{
    if (!cm) return NULL;
    return GET_PRIVATE(cm)->printname;
}
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 1082 of file gnc-commodity.c.

{
    if (!cm) return FALSE;
    return (GET_PRIVATE(cm)->quote_flag);
}
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 1093 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    if (!cm) return NULL;
    priv = GET_PRIVATE(cm);
    if (!priv->quote_source && gnc_commodity_is_iso(cm))
        return &currency_quote_source;
    return priv->quote_source;
}
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 1118 of file gnc-commodity.c.

{
    if (!cm) return NULL;
    return GET_PRIVATE(cm)->quote_tz;
}
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 1033 of file gnc-commodity.c.

{
    if (!cm) return NULL;
    return GET_PRIVATE(cm)->unique_name;
}
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 1363 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    ENTER("(cm=%p)", cm);

    if (!cm)
    {
        LEAVE("");
        return;
    }

    priv = GET_PRIVATE(cm);

    if ((priv->usage_count == 0) && !priv->quote_flag
            && gnc_commodity_get_auto_quote_control_flag(cm)
            && gnc_commodity_is_iso(cm))
    {
        /* compatability hack - Gnucash 1.8 gets currency quotes when a
           non-default currency is assigned to an account.  */
        gnc_commodity_begin_edit(cm);
        gnc_commodity_set_quote_flag(cm, TRUE);
        gnc_commodity_set_quote_source(cm,
                                       gnc_commodity_get_default_quote_source(cm));
        gnc_commodity_commit_edit(cm);
    }
    priv->usage_count++;
    LEAVE("(usage_count=%d)", priv->usage_count);
}
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 1955 of file gnc-commodity.c.

{
    const char *ns_name;
    if (!cm) return FALSE;

    ns_name = gnc_commodity_namespace_get_name(GET_PRIVATE(cm)->namespace);
    return (!safe_strcmp(ns_name, GNC_COMMODITY_NS_LEGACY) ||
            !safe_strcmp(ns_name, GNC_COMMODITY_NS_CURRENCY));
}
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 1943 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    if (!cm) return FALSE;

    priv = GET_PRIVATE(cm);
    if ( !priv->namespace) return FALSE;
    return priv->namespace->iso4217;
}
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 1541 of file gnc-commodity.c.

{
    if (!namespace)
        return NULL;

    return namespace->cm_list;
}
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 1533 of file gnc-commodity.c.

{
    if (ns == NULL)
        return NULL;
    return ns->name;
}
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 1550 of file gnc-commodity.c.

{
    return ((safe_strcmp(namespace, GNC_COMMODITY_NS_ISO) == 0) ||
            (safe_strcmp(namespace, GNC_COMMODITY_NS_CURRENCY) == 0));
}
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 816 of file gnc-commodity.c.

{
    gnc_commodity * retval = g_object_new(GNC_TYPE_COMMODITY, NULL);

    qof_instance_init_data (&retval->inst, GNC_ID_COMMODITY, book);
    gnc_commodity_begin_edit(retval);

    if ( namespace != NULL )
    {
        gnc_commodity_set_namespace(retval, namespace);
        if (gnc_commodity_namespace_is_iso(namespace))
        {
            gnc_commodity_set_quote_source(retval,
                                           gnc_quote_source_lookup_by_internal("currency") );
        }
    }
    gnc_commodity_set_fullname(retval, fullname);
    gnc_commodity_set_mnemonic(retval, mnemonic);
    gnc_commodity_set_cusip(retval, cusip);
    gnc_commodity_set_fraction(retval, fraction);
    gnc_commodity_commit_edit(retval);

    qof_event_gen (&retval->inst, QOF_EVENT_CREATE, NULL);

    return retval;
}
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 1590 of file gnc-commodity.c.

{
    gnc_commodity *twin;
    const char * ucom;
    gnc_commodity_table * comtbl;

    if (!from) return NULL;
    comtbl = gnc_commodity_table_get_table (book);
    if (!comtbl) return NULL;

    ucom = gnc_commodity_get_unique_name (from);
    twin = gnc_commodity_table_lookup_unique (comtbl, ucom);
    if (!twin)
    {
        twin = gnc_commodity_clone (from, book);
        twin = gnc_commodity_table_insert (comtbl, twin);
    }
    return twin;
}
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 1204 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    if (!cm) return;

    priv = GET_PRIVATE(cm);
    if (priv->cusip == cusip) return;

    gnc_commodity_begin_edit(cm);
    CACHE_REMOVE (priv->cusip);
    priv->cusip = CACHE_INSERT (cusip);
    mark_commodity_dirty(cm);
    gnc_commodity_commit_edit(cm);
}
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 1226 of file gnc-commodity.c.

{
    if (!cm) return;
    gnc_commodity_begin_edit(cm);
    GET_PRIVATE(cm)->fraction = fraction;
    mark_commodity_dirty(cm);
    gnc_commodity_commit_edit(cm);
}
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 1182 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    if (!cm) return;
    priv = GET_PRIVATE(cm);
    if (priv->fullname == fullname) return;

    CACHE_REMOVE (priv->fullname);
    priv->fullname = CACHE_INSERT (fullname);

    gnc_commodity_begin_edit(cm);
    mark_commodity_dirty(cm);
    reset_printname(priv);
    gnc_commodity_commit_edit(cm);
}
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 1129 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    if (!cm) return;
    priv = GET_PRIVATE(cm);
    if (priv->mnemonic == mnemonic) return;

    gnc_commodity_begin_edit(cm);
    CACHE_REMOVE (priv->mnemonic);
    priv->mnemonic = CACHE_INSERT(mnemonic);

    mark_commodity_dirty (cm);
    reset_printname(priv);
    reset_unique_name(priv);
    gnc_commodity_commit_edit(cm);
}
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 1152 of file gnc-commodity.c.

{
    QofBook *book;
    gnc_commodity_table *table;
    gnc_commodity_namespace *nsp;
    CommodityPrivate* priv;

    if (!cm) return;
    priv = GET_PRIVATE(cm);
    book = qof_instance_get_book (&cm->inst);
    table = gnc_commodity_table_get_table(book);
    nsp = gnc_commodity_table_add_namespace(table, namespace, book);
    if (priv->namespace == nsp)
        return;

    gnc_commodity_begin_edit(cm);
    priv->namespace = nsp;
    if (nsp->iso4217)
        priv->quote_source = gnc_quote_source_lookup_by_internal("currency");
    mark_commodity_dirty(cm);
    reset_printname(priv);
    reset_unique_name(priv);
    gnc_commodity_commit_edit(cm);
}
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 1300 of file gnc-commodity.c.

{
    ENTER ("(cm=%p, flag=%d)", cm, flag);

    if (!cm) return;
    gnc_commodity_begin_edit(cm);
    GET_PRIVATE(cm)->quote_flag = flag;
    mark_commodity_dirty(cm);
    gnc_commodity_commit_edit(cm);
    LEAVE(" ");
}
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 1317 of file gnc-commodity.c.

{
    ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name : "unknown");

    if (!cm) return;
    gnc_commodity_begin_edit(cm);
    GET_PRIVATE(cm)->quote_source = src;
    mark_commodity_dirty(cm);
    gnc_commodity_commit_edit(cm);
    LEAVE(" ");
}
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 1334 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    if (!cm) return;

    ENTER ("(cm=%p, tz=%s)", cm, tz ? tz : "(null)");

    priv = GET_PRIVATE(cm);

    if (tz == priv->quote_tz)
    {
        LEAVE("Already correct TZ");
        return;
    }

    gnc_commodity_begin_edit(cm);
    CACHE_REMOVE (priv->quote_tz);
    priv->quote_tz = CACHE_INSERT (tz);
    mark_commodity_dirty(cm);
    gnc_commodity_commit_edit(cm);
    LEAVE(" ");
}
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 2269 of file gnc-commodity.c.

{
    QofCollection *col;
    gnc_commodity* c;

    ENTER ("table=%p", table);
    gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_AMEX, book);
    gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NYSE, book);
    gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_NASDAQ, book);
    gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_EUREX, book);
    gnc_commodity_table_add_namespace(table, GNC_COMMODITY_NS_MUTUAL, book);
    gnc_commodity_table_add_namespace(table, "template", book);
    c = gnc_commodity_new(book, "template", "template", "template", "template", 1);
    gnc_commodity_table_insert(table, c);

#include "iso-4217-currencies.c"

    /* We've just created the default namespaces and currencies.  Mark
     * these collections as clean because there is no USER entered data
     * in these collections as of yet. */
    col = qof_book_get_collection(book, GNC_ID_COMMODITY);
    qof_collection_mark_clean(col);
    col = qof_book_get_collection(book, GNC_ID_COMMODITY_NAMESPACE);
    qof_collection_mark_clean(col);

    LEAVE ("table=%p", table);
    return TRUE;
}
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 2089 of file gnc-commodity.c.

{
    gnc_commodity_namespace * ns = NULL;

    if (!table) return NULL;

    namespace = gnc_commodity_table_map_namespace(namespace);
    ns = gnc_commodity_table_find_namespace(table, namespace);
    if (!ns)
    {
        ns = g_object_new(GNC_TYPE_COMMODITY_NAMESPACE, NULL);
        ns->cm_table = g_hash_table_new(g_str_hash, g_str_equal);
        ns->name = CACHE_INSERT((gpointer)namespace);
        ns->iso4217 = gnc_commodity_namespace_is_iso(namespace);
        qof_instance_init_data (&ns->inst, GNC_ID_COMMODITY_NAMESPACE, book);
        qof_event_gen (&ns->inst, QOF_EVENT_CREATE, NULL);

        g_hash_table_insert(table->ns_table,
                            (gpointer) ns->name,
                            (gpointer) ns);
        table->ns_list = g_list_append(table->ns_list, ns);
        qof_event_gen (&ns->inst, QOF_EVENT_ADD, NULL);
    }
    return ns;
}
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 2154 of file gnc-commodity.c.

{
    gnc_commodity_namespace * ns;

    if (!table) return;

    ns = gnc_commodity_table_find_namespace(table, namespace);
    if (!ns)
        return;

    qof_event_gen (&ns->inst, QOF_EVENT_REMOVE, NULL);
    g_hash_table_remove(table->ns_table, namespace);
    table->ns_list = g_list_remove(table->ns_list, ns);

    g_list_free(ns->cm_list);
    ns->cm_list = NULL;

    g_hash_table_foreach_remove(ns->cm_table, ns_helper, NULL);
    g_hash_table_destroy(ns->cm_table);
    CACHE_REMOVE(ns->name);

    qof_event_gen (&ns->inst, QOF_EVENT_DESTROY, NULL);
    /* qof_instance_release(&ns->inst); */
    g_object_unref(ns);
}
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 2119 of file gnc-commodity.c.

{
    if (!table || !namespace)
        return NULL;

    namespace = gnc_commodity_table_map_namespace(namespace);
    return g_hash_table_lookup(table->ns_table, (gpointer)namespace);
}
gboolean gnc_commodity_table_foreach_commodity ( const gnc_commodity_table table,
gboolean(*)(gnc_commodity *cm, gpointer user_data)  f,
gpointer  user_data 
)

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

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

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

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

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

{
    gnc_commodity_namespace * ns = NULL;

    if (!table)
        return NULL;

    ns = gnc_commodity_table_find_namespace(table, namespace);
    if (!ns)
        return NULL;

    return g_hash_table_values(ns->cm_table);
}
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 1919 of file gnc-commodity.c.

{
    if (!table)
        return NULL;

    return g_hash_table_keys(table->ns_table);
}
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 1928 of file gnc-commodity.c.

{
    if (!table)
        return NULL;

    return table->ns_list;
}
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 2018 of file gnc-commodity.c.

{
    gnc_commodity_namespace * ns = NULL;
    const char *namespace;
    GList * nslist, * tmp;
    GList * l = NULL;
    regex_t pattern;
    const char *expression = gnc_main_get_namespace_regexp();

    ENTER("table=%p, expression=%s", table, expression);
    if (!table)
        return NULL;

    if (expression && *expression)
    {
        if (regcomp(&pattern, expression, REG_EXTENDED | REG_ICASE) != 0)
        {
            LEAVE("Cannot compile regex");
            return NULL;
        }

        nslist = gnc_commodity_table_get_namespaces(table);
        for (tmp = nslist; tmp; tmp = tmp->next)
        {
            namespace = tmp->data;
            if (regexec(&pattern, namespace, 0, NULL, 0) == 0)
            {
                DEBUG("Running list of %s commodities", namespace);
                ns = gnc_commodity_table_find_namespace(table, namespace);
                if (ns)
                {
                    g_hash_table_foreach(ns->cm_table, &get_quotables_helper1, (gpointer) &l);
                }
            }
        }
        g_list_free(nslist);
        regfree(&pattern);
    }
    else
    {
        gnc_commodity_table_foreach_commodity(table, get_quotables_helper2,
                                              (gpointer) &l);
    }
    LEAVE("list head %p", l);
    return l;
}
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 1633 of file gnc-commodity.c.

{
    guint count = 0;
    g_return_val_if_fail(tbl, 0);
    g_return_val_if_fail(tbl->ns_table, 0);

    g_hash_table_foreach(tbl->ns_table, count_coms, (gpointer)&count);

    return count;
}
gnc_commodity_table* gnc_commodity_table_get_table ( QofBook book)

Returns the commodity table associated with a book.

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

{
    if (!book) return NULL;
    return qof_book_get_data (book, GNC_COMMODITY_TABLE);
}
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 1862 of file gnc-commodity.c.

{
    gnc_commodity_namespace * nsp = NULL;

    if (!table || !namespace)
    {
        return 0;
    }

    nsp = gnc_commodity_table_find_namespace(table, namespace);
    if (nsp)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
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 1759 of file gnc-commodity.c.

{
    gnc_commodity_namespace * nsp = NULL;
    gnc_commodity *c;
    const char *ns_name;
    CommodityPrivate* priv;
    QofBook *book;

    if (!table) return NULL;
    if (!comm) return NULL;

    priv = GET_PRIVATE(comm);

    ENTER ("(table=%p, comm=%p) %s %s", table, comm,
           (priv->mnemonic == NULL ? "(null)" : priv->mnemonic),
           (priv->fullname == NULL ? "(null)" : priv->fullname));
    ns_name = gnc_commodity_namespace_get_name(priv->namespace);
    c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);

    if (c)
    {
        if (c == comm)
        {
            LEAVE("already in table");
            return c;
        }

        /* Backward compatability support for currencies that have
         * recently changed. */
        if (priv->namespace->iso4217)
        {
            guint i;
            for (i = 0; i < GNC_NEW_ISO_CODES; i++)
            {
                if (!priv->mnemonic
                        || !strcmp(priv->mnemonic, gnc_new_iso_codes[i].old_code))
                {
                    gnc_commodity_set_mnemonic(comm, gnc_new_iso_codes[i].new_code);
                    break;
                }
            }
        }

        gnc_commodity_copy (c, comm);
        gnc_commodity_destroy (comm);
        LEAVE("found at %p", c);
        return c;
    }

    book = qof_instance_get_book (&comm->inst);
    nsp = gnc_commodity_table_add_namespace(table, ns_name, book);

    PINFO ("insert %p %s into nsp=%p %s", priv->mnemonic, priv->mnemonic,
           nsp->cm_table, nsp->name);
    g_hash_table_insert(nsp->cm_table,
                        CACHE_INSERT(priv->mnemonic),
                        (gpointer)comm);
    nsp->cm_list = g_list_append(nsp->cm_list, comm);

    qof_event_gen (&comm->inst, QOF_EVENT_ADD, NULL);
    LEAVE ("(table=%p, comm=%p)", table, comm);
    return comm;
}
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 1570 of file gnc-commodity.c.

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

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

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

{
    gnc_quote_source_init_tables();

    if (!qof_object_register (&commodity_object_def))
        return FALSE;
    if (!qof_object_register (&namespace_object_def))
        return FALSE;
    return qof_object_register (&commodity_table_object_def);
}
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 1830 of file gnc-commodity.c.

{
    gnc_commodity_namespace * nsp;
    gnc_commodity *c;
    CommodityPrivate* priv;
    const char *ns_name;

    if (!table) return;
    if (!comm) return;

    priv = GET_PRIVATE(comm);
    ns_name = gnc_commodity_namespace_get_name(priv->namespace);
    c = gnc_commodity_table_lookup (table, ns_name, priv->mnemonic);
    if (c != comm) return;

    qof_event_gen (&comm->inst, QOF_EVENT_REMOVE, NULL);

    nsp = gnc_commodity_table_find_namespace(table, ns_name);
    if (!nsp) return;

    nsp->cm_list = g_list_remove(nsp->cm_list, comm);
    g_hash_table_remove (nsp->cm_table, priv->mnemonic);
    /* XXX minor mem leak, should remove the key as well */
}
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 1264 of file gnc-commodity.c.

{
    CommodityPrivate* priv;

    ENTER ("(cm=%p, flag=%d)", cm, flag);

    if (!cm)
    {
        LEAVE("");
        return;
    }

    priv = GET_PRIVATE(cm);
    gnc_commodity_begin_edit(cm);
    gnc_commodity_set_quote_flag(cm, flag);
    if (gnc_commodity_is_iso(cm))
    {
        /* For currencies, disable auto quote control if the quote flag is being
         * changed from its default value and enable it if the quote flag is being
         * reset to its default value.  The defaults for the quote flag are
         * disabled if no accounts are using the currency, and true otherwise.
         * Thus enable auto quote control if flag is FALSE and there are not any
         * accounts using this currency OR flag is TRUE and there are accounts
         * using this currency; otherwise disable auto quote control */
        gnc_commodity_set_auto_quote_control_flag(cm,
                (!flag && (priv->usage_count == 0)) || (flag && (priv->usage_count != 0)));
    }
    gnc_commodity_commit_edit(cm);
    LEAVE("");
}
MonetaryList* gnc_monetary_list_add_monetary ( MonetaryList *  list,
gnc_monetary  add_mon 
)

Add a gnc_monetary to the list

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

{
    MonetaryList *l = list, *tmp;
    for (tmp = list; tmp; tmp = tmp->next)
    {
        gnc_monetary *list_mon = tmp->data;
        if (gnc_commodity_equiv(list_mon->commodity, add_mon.commodity))
        {
            list_mon->value = gnc_numeric_add(list_mon->value, add_mon.value,
                                              GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
            break;
        }
    }

    /* See if we found an entry, and add one if not */
    if (tmp == NULL)
    {
        gnc_monetary *new_mon = g_new0(gnc_monetary, 1);
        *new_mon = add_mon;
        l = g_list_prepend(l, new_mon);
    }

    return l;
}
MonetaryList* gnc_monetary_list_delete_zeros ( MonetaryList *  list)

Delete all the zero-value entries from a list

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

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

{
    MonetaryList *node, *next;
    for (node = list; node; node = next)
    {
        gnc_monetary *mon = node->data;
        next = node->next;
        if (gnc_numeric_zero_p(mon->value))
        {
            g_free(mon);
            list = g_list_delete_link(list, node);
        }
    }
    return list;
}
void gnc_monetary_list_free ( MonetaryList *  list)

Free a monetary list and all the items it points to

Free a MonetaryList and all the monetaries it points to

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

{
    MonetaryList *tmp;
    for (tmp = list; tmp; tmp = tmp->next)
    {
        g_free(tmp->data);
    }

    g_list_free(list);
}
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 303 of file gnc-commodity.c.

{
    gnc_quote_source *new_source;

    DEBUG("Creating new source %s", (source_name == NULL ? "(null)" : source_name));
    new_source = malloc(sizeof(gnc_quote_source));
    new_source->supported = supported;
    new_source->type = SOURCE_UNKNOWN;
    new_source->index = g_list_length(new_quote_sources);

    /* This name can be changed if/when support for this price source is
     * integrated into gnucash. */
    new_source->user_name = g_strdup(source_name);

    /* This name is permanent and must be kept the same if/when support
     * for this price source is integrated into gnucash (i.e. for a
     * nice user name). */
    new_source->old_internal_name = g_strdup(source_name);
    new_source->internal_name = g_strdup(source_name);
    new_quote_sources = g_list_append(new_quote_sources, new_source);
    return new_source;
}
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 243 of file gnc-commodity.c.

{
    return fq_is_installed;
}
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 442 of file gnc-commodity.c.

{
    ENTER("%p", source);
    if (!source)
    {
        LEAVE("bad source");
        return 0;
    }

    LEAVE("index is %d", source->index);
    return source->index;
}
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 483 of file gnc-commodity.c.

{
    ENTER("%p", source);
    if (!source)
    {
        LEAVE("bad source");
        return NULL;
    }
    LEAVE("internal name %s", source->internal_name);
    return source->internal_name;
}
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 456 of file gnc-commodity.c.

{
    ENTER("%p", source);
    if (!source)
    {
        LEAVE("bad source");
        return FALSE;
    }

    LEAVE("%ssupported", source && source->supported ? "" : "not ");
    return source->supported;
}
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 428 of file gnc-commodity.c.

{
    ENTER("%p", source);
    if (!source)
    {
        LEAVE("bad source");
        return SOURCE_SINGLE;
    }

    LEAVE("type is %d", source->type);
    return source->type;
}
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 470 of file gnc-commodity.c.

{
    ENTER("%p", source);
    if (!source)
    {
        LEAVE("bad source");
        return NULL;
    }
    LEAVE("user name %s", source->user_name);
    return source->user_name;
}
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 377 of file gnc-commodity.c.

{
    gnc_quote_source *source;
    GList *node;
    gint i;

    if ((name == NULL) || (safe_strcmp(name, "") == 0))
    {
        return NULL;
    }

    if (safe_strcmp(name, currency_quote_source.internal_name) == 0)
        return &currency_quote_source;
    if (safe_strcmp(name, currency_quote_source.old_internal_name) == 0)
        return &currency_quote_source;

    for (i = 0; i < num_single_quote_sources; i++)
    {
        if (safe_strcmp(name, single_quote_sources[i].internal_name) == 0)
            return &single_quote_sources[i];
        if (safe_strcmp(name, single_quote_sources[i].old_internal_name) == 0)
            return &single_quote_sources[i];
    }

    for (i = 0; i < num_multiple_quote_sources; i++)
    {
        if (safe_strcmp(name, multiple_quote_sources[i].internal_name) == 0)
            return &multiple_quote_sources[i];
        if (safe_strcmp(name, multiple_quote_sources[i].old_internal_name) == 0)
            return &multiple_quote_sources[i];
    }

    for (i = 0, node = new_quote_sources; node; node = node->next, i++)
    {
        source = node->data;
        if (safe_strcmp(name, source->internal_name) == 0)
            return source;
        if (safe_strcmp(name, source->old_internal_name) == 0)
            return source;
    }

    DEBUG("gnc_quote_source_lookup_by_internal: Unknown source %s", name);
    return NULL;
}
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 332 of file gnc-commodity.c.

{
    gnc_quote_source *source;
    GList *node;

    ENTER("type/index is %d/%d", type, index);
    switch (type)
    {
    case SOURCE_CURRENCY:
        LEAVE("found %s", currency_quote_source.user_name);
        return &currency_quote_source;
        break;

    case SOURCE_SINGLE:
        if (index < num_single_quote_sources)
        {
            LEAVE("found %s", single_quote_sources[index].user_name);
            return &single_quote_sources[index];
        }
        break;

    case SOURCE_MULTI:
        if (index < num_multiple_quote_sources)
        {
            LEAVE("found %s", multiple_quote_sources[index].user_name);
            return &multiple_quote_sources[index];
        }
        break;

    case SOURCE_UNKNOWN:
    default:
        node = g_list_nth(new_quote_sources, index);
        if (node)
        {
            source = node->data;
            LEAVE("found %s", source->user_name);
            return source;
        }
    }

    LEAVE("not found");
    return NULL;
}
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 253 of file gnc-commodity.c.

{
    if  (type == SOURCE_CURRENCY)
        return 1;

    if  (type == SOURCE_SINGLE)
        return num_single_quote_sources;

    if (type == SOURCE_MULTI)
        return num_multiple_quote_sources;

    return g_list_length(new_quote_sources);
}
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 502 of file gnc-commodity.c.

{
    gnc_quote_source *source;
    char *source_name;
    const GList *node;

    ENTER(" ");
    fq_is_installed = TRUE;

    if (!sources_list)
        return;

    for (node = sources_list; node; node = node->next)
    {
        source_name = node->data;

        source = gnc_quote_source_lookup_by_internal(source_name);
        if (source != NULL)
        {
            DEBUG("Found source %s: %s", source_name, source->user_name);
            source->supported = TRUE;
            continue;
        }

        gnc_quote_source_add_new(source_name, TRUE);
    }
    LEAVE(" ");
}
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines