mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-16 18:25:11 -06:00
Move the F::Q stuff from the util files to live with the rest of the
commodity code in gnc-commodity.c. Turn quote sources into an object. Eliminate the gnucash internal quote source names in favor of the F::Q names. Dynamically find and add installed F::Q sources that aren't hard coded into gnucash. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8812 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
fdc8099bcf
commit
b9bf61723a
29
ChangeLog
29
ChangeLog
@ -1,3 +1,32 @@
|
||||
2003-07-01 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/app-utils/gnc-ui-util.[ch]:
|
||||
* src/app-utils/gw-app-utils-spec.scm:
|
||||
* src/engine/gnc-commodity.[ch]:
|
||||
* src/engine/gw-engine-spec.scm:
|
||||
Move Finance::Quote related information to live with the rest of
|
||||
the commodity related code.
|
||||
|
||||
* src/engine/gnc-engine.h:
|
||||
* src/engine/gnc-commodity.[ch]: Convert the price quote source
|
||||
data into an object of its own. Eliminate the old "internal" name
|
||||
in favor of the F::Q name. Dynamically find and add new quote
|
||||
sources when the user runs gnucash.
|
||||
|
||||
* src/backend/file/gnc-account-xml-v2.c:
|
||||
* src/backend/file/gnc-commodity-xml-v2.c:
|
||||
* src/engine/Scrub.c: Ensure backwards compatability of the XML file.
|
||||
|
||||
* src/app-utils/gnc-helpers.c: Update for changes in accessing
|
||||
quote source information.
|
||||
|
||||
* src/gnome-utils/commodity.glade:
|
||||
* src/gnome-utils/dialog-commodity.c: Reorganize the dialog for
|
||||
selection price quote information.
|
||||
|
||||
* src/scm/price-quotes.scm: Print debugging info when getting
|
||||
stock quotes if gnucash is run with the --debug flag.
|
||||
|
||||
2003-06-30 Derek Atkins <derek@ihtfp.com>
|
||||
|
||||
* macros/acx_pthread.m4: macro to find the pthread library for
|
||||
|
@ -137,13 +137,15 @@ gnc_printinfo_p(SCM info_scm)
|
||||
SCM
|
||||
gnc_quoteinfo2scm(gnc_commodity *comm)
|
||||
{
|
||||
const char *source, *tz;
|
||||
gnc_quote_source *source;
|
||||
const char *name, *tz;
|
||||
SCM info_scm = SCM_EOL, comm_scm, def_comm_scm;
|
||||
|
||||
if (!comm)
|
||||
return SCM_EOL;
|
||||
|
||||
source = gnc_price_source_internal2fq (gnc_commodity_get_quote_source (comm));
|
||||
source = gnc_commodity_get_quote_source (comm);
|
||||
name = gnc_quote_source_get_internal_name (source);
|
||||
tz = gnc_commodity_get_quote_tz (comm);
|
||||
comm_scm = gw_wcp_assimilate_ptr (comm, scm_c_eval_string("<gnc:commodity*>"));
|
||||
def_comm_scm = gw_wcp_assimilate_ptr (gnc_default_currency (),
|
||||
@ -155,7 +157,7 @@ gnc_quoteinfo2scm(gnc_commodity *comm)
|
||||
info_scm = scm_cons (SCM_BOOL_F, info_scm);
|
||||
info_scm = scm_cons (def_comm_scm, info_scm);
|
||||
info_scm = scm_cons (comm_scm, info_scm);
|
||||
info_scm = scm_cons (scm_makfrom0str (source), info_scm);
|
||||
info_scm = scm_cons (scm_makfrom0str (name), info_scm);
|
||||
return info_scm;
|
||||
}
|
||||
|
||||
|
@ -59,49 +59,6 @@ static int auto_decimal_places = 2; /* default, can be changed */
|
||||
static gboolean reverse_balance_inited = FALSE;
|
||||
static SCM reverse_balance_callback_id = SCM_UNDEFINED;
|
||||
static gboolean reverse_type[NUM_ACCOUNT_TYPES];
|
||||
static gboolean fq_is_installed = FALSE;
|
||||
|
||||
typedef struct quote_source_t {
|
||||
gboolean supported;
|
||||
gboolean translate;
|
||||
char *user_name; /* User friendly name */
|
||||
char *internal_name; /* Name used internally. */
|
||||
char *fq_name; /* Name used by finance::quote. */
|
||||
} quote_source;
|
||||
|
||||
static quote_source quote_sources[NUM_SOURCES] = {
|
||||
{ TRUE, TRUE, N_("(none)"), NULL, NULL },
|
||||
{ FALSE, TRUE, N_("-- Single Sources --"), NULL, NULL },
|
||||
{ FALSE, FALSE, "AEX", "AEX", "aex" },
|
||||
{ FALSE, FALSE, "ASX", "ASX", "asx" },
|
||||
{ FALSE, FALSE, "DWS", "DWS", "dwsfunds" },
|
||||
{ FALSE, FALSE, "Fidelity Direct", "FIDELITY_DIRECT", "fidelity_direct" },
|
||||
{ FALSE, FALSE, "Motley Fool", "FOOL", "fool" },
|
||||
{ FALSE, FALSE, "Fund Library", "FUNDLIBRARY", "fundlibrary" },
|
||||
{ FALSE, FALSE, "TD Waterhouse Canada", "TDWATERHOUSE", "tdwaterhouse" },
|
||||
{ FALSE, FALSE, "TIAA-CREF", "TIAACREF", "tiaacref" },
|
||||
{ FALSE, FALSE, "T. Rowe Price", "TRPRICE_DIRECT", "troweprice_direct" }, /* Not Implemented */
|
||||
{ FALSE, FALSE, "Trustnet", "TRUSTNET", "trustnet" },
|
||||
{ FALSE, FALSE, "Union Investments", "UNIONFUNDS", "unionfunds" },
|
||||
{ FALSE, FALSE, "Vanguard", "VANGUARD", "vanguard" },
|
||||
{ FALSE, FALSE, "VWD", "VWD", "vwd" },
|
||||
{ FALSE, FALSE, "Yahoo", "YAHOO", "yahoo" },
|
||||
{ FALSE, FALSE, "Yahoo Asia", "YAHOO_ASIA", "yahoo_asia" },
|
||||
{ FALSE, FALSE, "Yahoo Australia", "YAHOO_AUSTRALIA", "yahoo_australia" },
|
||||
{ FALSE, FALSE, "Yahoo Europe", "YAHOO_EUROPE", "yahoo_europe" },
|
||||
{ FALSE, FALSE, "Zuerich Investments", "ZIFUNDS", "zifunds" },
|
||||
{ FALSE, TRUE, N_("-- Multiple Sources --"), NULL, NULL },
|
||||
{ FALSE, FALSE, "Asia (Yahoo, ...)", "ASIA", "asia" },
|
||||
{ FALSE, FALSE, "Australia (ASX, Yahoo, ...)", "AUSTRALIA", "australia" },
|
||||
{ FALSE, FALSE, "Canada (Yahoo, ...)", "CANADA", "canada" },
|
||||
{ FALSE, FALSE, "Canada Mutual (Fund Library, ...)", "CANADAMUTUAL", "canadamutual" },
|
||||
{ FALSE, FALSE, "Dutch (AEX, ...)", "DUTCH", "dutch" },
|
||||
{ FALSE, FALSE, "Europe (Yahoo, ...)", "EUROPE", "europe" },
|
||||
{ FALSE, FALSE, "Fidelity (Fidelity, ...)", "FIDELITY", "fidelity" },
|
||||
{ FALSE, FALSE, "T. Rowe Price", "TRPRICE", "troweprice" },
|
||||
{ FALSE, FALSE, "U.K. Unit Trusts", "UKUNITTRUSTS", "uk_unit_trusts" },
|
||||
{ FALSE, FALSE, "USA (Yahoo, Fool ...)", "USA", "usa" },
|
||||
};
|
||||
|
||||
/********************************************************************\
|
||||
* gnc_color_deficits *
|
||||
@ -703,131 +660,6 @@ gnc_get_reconcile_flag_order (void)
|
||||
}
|
||||
|
||||
|
||||
/* Get the full name of a quote source */
|
||||
const char *
|
||||
gnc_price_source_enum2name (PriceSourceCode source)
|
||||
{
|
||||
if (source >= NUM_SOURCES) {
|
||||
PWARN("Unknown source %d", source);
|
||||
return NULL;
|
||||
}
|
||||
return quote_sources[source].user_name;
|
||||
}
|
||||
|
||||
/* Get the codename string of a quote source */
|
||||
const char *
|
||||
gnc_price_source_enum2internal (PriceSourceCode source)
|
||||
{
|
||||
if (source >= NUM_SOURCES) {
|
||||
PWARN("Unknown source %d", source);
|
||||
return NULL;
|
||||
}
|
||||
return quote_sources[source].internal_name;
|
||||
}
|
||||
|
||||
/* Get the codename string of a source */
|
||||
PriceSourceCode
|
||||
gnc_price_source_internal2enum (const char * internal_name)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if (internal_name == NULL)
|
||||
return SOURCE_NONE;
|
||||
|
||||
if (safe_strcmp(internal_name, "") == 0)
|
||||
return SOURCE_NONE;
|
||||
|
||||
for (i = 1; i < NUM_SOURCES; i++)
|
||||
if (safe_strcmp(internal_name, quote_sources[i].internal_name) == 0)
|
||||
return i;
|
||||
|
||||
PWARN("Unknown source %s", internal_name);
|
||||
return SOURCE_NONE;
|
||||
}
|
||||
|
||||
/* Get the codename string of a source */
|
||||
PriceSourceCode
|
||||
gnc_price_source_fq2enum (const char * fq_name)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if (fq_name == NULL)
|
||||
return SOURCE_NONE;
|
||||
|
||||
if (safe_strcmp(fq_name, "") == 0)
|
||||
return SOURCE_NONE;
|
||||
|
||||
for (i = 1; i < NUM_SOURCES; i++)
|
||||
if (safe_strcmp(fq_name, quote_sources[i].fq_name) == 0)
|
||||
return i;
|
||||
|
||||
// NYSE and Nasdaq have deliberately been left out. Don't always print them.
|
||||
// PWARN("Unknown source %s", fq_name);
|
||||
return SOURCE_NONE;
|
||||
}
|
||||
|
||||
/* Get the codename string of a source */
|
||||
const char *
|
||||
gnc_price_source_internal2fq (const char * codename)
|
||||
{
|
||||
gint i;
|
||||
|
||||
if (codename == NULL)
|
||||
return NULL;
|
||||
|
||||
if (safe_strcmp(codename, "") == 0)
|
||||
return NULL;
|
||||
|
||||
if (safe_strcmp(codename, "CURRENCY") == 0)
|
||||
return "currency";
|
||||
|
||||
for (i = 1; i < NUM_SOURCES; i++)
|
||||
if (safe_strcmp(codename, quote_sources[i].internal_name) == 0)
|
||||
return quote_sources[i].fq_name;
|
||||
|
||||
PWARN("Unknown source %s", codename);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Get whether or not a quote source should be sensitive in the menu */
|
||||
void
|
||||
gnc_price_source_set_fq_installed (GList *sources_list)
|
||||
{
|
||||
GList *node;
|
||||
PriceSourceCode code;
|
||||
char *source;
|
||||
|
||||
if (!sources_list)
|
||||
return;
|
||||
|
||||
fq_is_installed = TRUE;
|
||||
for (node = sources_list; node; node = node->next) {
|
||||
source = node->data;
|
||||
code = gnc_price_source_fq2enum (source);
|
||||
if ((code != SOURCE_NONE) && (code < NUM_SOURCES)) {
|
||||
quote_sources[code].supported = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_price_source_have_fq (void)
|
||||
{
|
||||
return fq_is_installed;
|
||||
}
|
||||
|
||||
/* Get whether or not a quote source should be sensitive in the menu */
|
||||
gboolean
|
||||
gnc_price_source_sensitive (PriceSourceCode source)
|
||||
{
|
||||
if (source >= NUM_SOURCES) {
|
||||
PWARN("Unknown source");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return quote_sources[source].supported;
|
||||
}
|
||||
|
||||
static const char *
|
||||
equity_base_name (GNCEquityType equity_type)
|
||||
{
|
||||
|
@ -161,58 +161,6 @@ gboolean gnc_account_create_opening_balance (Account *account,
|
||||
char * gnc_account_get_full_name (Account *account);
|
||||
|
||||
|
||||
/* Price source functions *******************************************/
|
||||
|
||||
/* NOTE: If you modify PriceSourceCode, please update price-quotes.scm
|
||||
as well. */
|
||||
typedef enum
|
||||
{
|
||||
SOURCE_NONE = 0,
|
||||
SPECIFIC_SOURCES,
|
||||
SOURCE_AEX,
|
||||
SOURCE_ASX,
|
||||
SOURCE_DWS,
|
||||
SOURCE_FIDELITY_DIRECT,
|
||||
SOURCE_FOOL,
|
||||
SOURCE_FUNDLIBRARY,
|
||||
SOURCE_TDWATERHOUSE,
|
||||
SOURCE_TIAA_CREF,
|
||||
SOURCE_TROWEPRICE_DIRECT,
|
||||
SOURCE_TRUSTNET,
|
||||
SOURCE_UNION,
|
||||
SOURCE_VANGUARD,
|
||||
SOURCE_VWD,
|
||||
SOURCE_YAHOO,
|
||||
SOURCE_YAHOO_ASIA,
|
||||
SOURCE_YAHOO_AUSTRALIA,
|
||||
SOURCE_YAHOO_EUROPE,
|
||||
SOURCE_ZUERICH,
|
||||
GENERAL_SOURCES,
|
||||
SOURCE_ASIA,
|
||||
SOURCE_AUSTRALIA,
|
||||
SOURCE_CANADA,
|
||||
SOURCE_CANADAMUTUAL,
|
||||
SOURCE_DUTCH,
|
||||
SOURCE_EUROPE,
|
||||
SOURCE_FIDELITY,
|
||||
SOURCE_TROWEPRICE,
|
||||
SOURCE_UKUNITTRUSTS,
|
||||
SOURCE_USA,
|
||||
NUM_SOURCES
|
||||
} PriceSourceCode;
|
||||
/* NOTE: If you modify PriceSourceCode, please update price-quotes.scm
|
||||
as well. */
|
||||
|
||||
const char * gnc_price_source_enum2name (PriceSourceCode source);
|
||||
const char * gnc_price_source_enum2internal (PriceSourceCode source);
|
||||
const char * gnc_price_source_internal2fq (const char * codename);
|
||||
PriceSourceCode gnc_price_source_internal2enum (const char * internal_name);
|
||||
PriceSourceCode gnc_price_source_fq2enum (const char * fq_name);
|
||||
gboolean gnc_price_source_sensitive (PriceSourceCode source);
|
||||
void gnc_price_source_set_fq_installed (GList *sources_list);
|
||||
gboolean gnc_price_source_have_fq (void);
|
||||
|
||||
|
||||
/* Locale functions *************************************************/
|
||||
|
||||
/* The gnc_localeconv() subroutine returns an lconv structure
|
||||
|
@ -451,22 +451,6 @@ determines formatting details.")
|
||||
'()
|
||||
"Returns the commodity EURO")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:price-source-internal2fq
|
||||
'(<gw:mchars> callee-owned const)
|
||||
"gnc_price_source_internal2fq"
|
||||
'(((<gw:mchars> caller-owned const) str))
|
||||
"Returns a string with the Finace::Quote identifier correspopnding to the internal name.")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:price-source-set-fq-installed
|
||||
'<gw:void>
|
||||
"gnc_price_source_set_fq_installed"
|
||||
'(((gw:glist-of (<gw:mchars> callee-owned) callee-owned) choices))
|
||||
"Takes a list of installed Finance::Quote souces and records it internally.")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:commodity-table-get-quotable-commodities-info
|
||||
|
@ -126,6 +126,7 @@ gnc_account_dom_tree_create(Account *act, gboolean exporting)
|
||||
* to fall back to the production code. */
|
||||
xmlNodePtr slot_node, val_node;
|
||||
gnc_commodity *com;
|
||||
gnc_quote_source *source;
|
||||
const gchar *tz;
|
||||
|
||||
com = xaccAccountGetCommodity(act);
|
||||
@ -137,8 +138,10 @@ gnc_account_dom_tree_create(Account *act, gboolean exporting)
|
||||
|
||||
slot_node = xmlNewChild(kvpnode, NULL, "slot", NULL);
|
||||
xmlNewTextChild(slot_node, NULL, "slot:key", "old-price-source");
|
||||
|
||||
source = gnc_commodity_get_quote_source(com);
|
||||
val_node = xmlNewTextChild(slot_node, NULL, "slot:value",
|
||||
gnc_commodity_get_quote_source(com));
|
||||
gnc_quote_source_get_old_internal_name(source));
|
||||
xmlSetProp(val_node, "type", "string");
|
||||
|
||||
tz = gnc_commodity_get_quote_tz(com);
|
||||
|
@ -63,6 +63,7 @@ const gchar *commodity_version_string = "2.0.0";
|
||||
xmlNodePtr
|
||||
gnc_commodity_dom_tree_create(const gnc_commodity *com)
|
||||
{
|
||||
gnc_quote_source *source;
|
||||
const char *string;
|
||||
xmlNodePtr ret;
|
||||
|
||||
@ -92,15 +93,16 @@ gnc_commodity_dom_tree_create(const gnc_commodity *com)
|
||||
xmlAddChild(ret, int_to_dom_tree(cmdty_fraction,
|
||||
gnc_commodity_get_fraction(com)));
|
||||
|
||||
if (gnc_commodity_get_quote_flag(com))
|
||||
if (gnc_commodity_get_quote_flag(com)) {
|
||||
xmlNewChild(ret, NULL, cmdty_get_quotes, NULL);
|
||||
string = gnc_commodity_get_quote_source(com);
|
||||
if (string)
|
||||
xmlAddChild(ret, text_to_dom_tree(cmdty_quote_source, string));
|
||||
string = gnc_commodity_get_quote_tz(com);
|
||||
if (string)
|
||||
xmlAddChild(ret, text_to_dom_tree(cmdty_quote_tz, string));
|
||||
|
||||
source = gnc_commodity_get_quote_source(com);
|
||||
if (source)
|
||||
xmlAddChild(ret, text_to_dom_tree(cmdty_quote_source,
|
||||
gnc_quote_source_get_internal_name(source)));
|
||||
string = gnc_commodity_get_quote_tz(com);
|
||||
if (string)
|
||||
xmlAddChild(ret, text_to_dom_tree(cmdty_quote_tz, string));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -117,7 +119,6 @@ struct com_char_handler com_handlers[] = {
|
||||
{ cmdty_id, gnc_commodity_set_mnemonic },
|
||||
{ cmdty_name, gnc_commodity_set_fullname },
|
||||
{ cmdty_xcode, gnc_commodity_set_exchange_code },
|
||||
{ cmdty_quote_source, gnc_commodity_set_quote_source },
|
||||
{ cmdty_quote_tz, gnc_commodity_set_quote_tz },
|
||||
{ 0, 0 }
|
||||
};
|
||||
@ -139,10 +140,18 @@ set_commodity_value(xmlNodePtr node, gnc_commodity* com)
|
||||
}
|
||||
else if(safe_strcmp(node->name, cmdty_get_quotes) == 0)
|
||||
{
|
||||
gnc_commodity_set_quote_flag(com, TRUE);
|
||||
}
|
||||
else if(safe_strcmp(node->name, cmdty_quote_source) == 0)
|
||||
{
|
||||
gnc_quote_source *source;
|
||||
char *string;
|
||||
|
||||
string = xmlNodeGetContent (node->xmlChildrenNode);
|
||||
gnc_commodity_set_quote_flag(com, TRUE);
|
||||
source = gnc_quote_source_lookup_by_internal(string);
|
||||
if (!source)
|
||||
source = gnc_quote_source_add_new(string, FALSE);
|
||||
gnc_commodity_set_quote_source(com, source);
|
||||
xmlFree (string);
|
||||
}
|
||||
else
|
||||
|
@ -588,6 +588,7 @@ static gpointer
|
||||
move_quote_source (Account *account, gpointer data)
|
||||
{
|
||||
gnc_commodity *com;
|
||||
gnc_quote_source *quote_source;
|
||||
gboolean new_style = GPOINTER_TO_INT(data);
|
||||
const char *source, *tz;
|
||||
|
||||
@ -604,7 +605,10 @@ move_quote_source (Account *account, gpointer data)
|
||||
PINFO("to %8s from %s", gnc_commodity_get_mnemonic(com),
|
||||
xaccAccountGetName(account));
|
||||
gnc_commodity_set_quote_flag(com, TRUE);
|
||||
gnc_commodity_set_quote_source(com, source);
|
||||
quote_source = gnc_quote_source_lookup_by_internal(source);
|
||||
if (!quote_source)
|
||||
quote_source = gnc_quote_source_add_new(source, FALSE);
|
||||
gnc_commodity_set_quote_source(com, quote_source);
|
||||
gnc_commodity_set_quote_tz(com, tz);
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
@ -57,7 +58,7 @@ struct gnc_commodity_s
|
||||
gint16 mark; /* user-defined mark, handy for traversals */
|
||||
|
||||
gboolean quote_flag; /* user wants price quotes */
|
||||
char * quote_source; /* current/old source of quotes */
|
||||
gnc_quote_source * quote_source; /* current/old source of quotes */
|
||||
char * quote_tz;
|
||||
};
|
||||
|
||||
@ -80,7 +81,353 @@ struct gnc_new_iso_code {
|
||||
};
|
||||
#define GNC_NEW_ISO_CODES \
|
||||
(sizeof(gnc_new_iso_codes) / sizeof(struct gnc_new_iso_code))
|
||||
|
||||
static gboolean fq_is_installed = FALSE;
|
||||
|
||||
struct gnc_quote_source_s {
|
||||
gboolean supported;
|
||||
QuoteSourceType type;
|
||||
gint index;
|
||||
char *user_name; /* User friendly name */
|
||||
char *old_internal_name; /* Name used internally (deprecated) */
|
||||
char *internal_name; /* Name used internally and by finance::quote. */
|
||||
};
|
||||
|
||||
static gnc_quote_source currency_quote_source =
|
||||
{ TRUE, 0, 0, "CURRENCY", "currency", "currency" };
|
||||
|
||||
static gnc_quote_source single_quote_sources[] = {
|
||||
{ FALSE, 0, 0, "AEX", "AEX", "aex" },
|
||||
{ FALSE, 0, 0, "ASX", "ASX", "asx" },
|
||||
{ FALSE, 0, 0, "DWS", "DWS", "dwsfunds" },
|
||||
{ FALSE, 0, 0, "Fidelity Direct", "FIDELITY_DIRECT", "fidelity_direct" },
|
||||
{ FALSE, 0, 0, "Motley Fool", "FOOL", "fool" },
|
||||
{ FALSE, 0, 0, "Fund Library", "FUNDLIBRARY", "fundlibrary" },
|
||||
{ FALSE, 0, 0, "TD Waterhouse Canada", "TDWATERHOUSE", "tdwaterhouse" },
|
||||
{ FALSE, 0, 0, "TIAA-CREF", "TIAACREF", "tiaacref" },
|
||||
{ FALSE, 0, 0, "T. Rowe Price", "TRPRICE_DIRECT", "troweprice_direct" },
|
||||
{ FALSE, 0, 0, "Trustnet", "TRUSTNET", "trustnet" },
|
||||
{ FALSE, 0, 0, "Union Investments", "UNIONFUNDS", "unionfunds" },
|
||||
{ FALSE, 0, 0, "Vanguard", "VANGUARD", "vanguard" },
|
||||
{ FALSE, 0, 0, "VWD", "VWD", "vwd" },
|
||||
{ FALSE, 0, 0, "Yahoo", "YAHOO", "yahoo" },
|
||||
{ FALSE, 0, 0, "Yahoo Asia", "YAHOO_ASIA", "yahoo_asia" },
|
||||
{ FALSE, 0, 0, "Yahoo Australia", "YAHOO_AUSTRALIA", "yahoo_australia" },
|
||||
{ FALSE, 0, 0, "Yahoo Europe", "YAHOO_EUROPE", "yahoo_europe" },
|
||||
{ FALSE, 0, 0, "Zuerich Investments", "ZIFUNDS", "zifunds" },
|
||||
};
|
||||
static gnc_quote_source multiple_quote_sources[] = {
|
||||
{ FALSE, 0, 0, "Asia (Yahoo, ...)", "ASIA", "asia" },
|
||||
{ FALSE, 0, 0, "Australia (ASX, Yahoo, ...)", "AUSTRALIA", "australia" },
|
||||
{ FALSE, 0, 0, "Canada (Yahoo, ...)", "CANADA", "canada" },
|
||||
{ FALSE, 0, 0, "Canada Mutual (Fund Library, ...)", "CANADAMUTUAL", "canadamutual" },
|
||||
{ FALSE, 0, 0, "Dutch (AEX, ...)", "DUTCH", "dutch" },
|
||||
{ FALSE, 0, 0, "Europe (Yahoo, ...)", "EUROPE", "europe" },
|
||||
{ FALSE, 0, 0, "Fidelity (Fidelity, ...)", "FIDELITY", "fidelity" },
|
||||
{ FALSE, 0, 0, "Nasdaq (Yahoo, ...)", "NASDAQ", "nasdaq" },
|
||||
{ FALSE, 0, 0, "NYSE (Yahoo, ...)", "NYSE", "nyse" },
|
||||
{ FALSE, 0, 0, "T. Rowe Price", "TRPRICE", "troweprice" },
|
||||
{ FALSE, 0, 0, "U.K. Unit Trusts", "UKUNITTRUSTS", "uk_unit_trusts" },
|
||||
{ FALSE, 0, 0, "USA (Yahoo, Fool ...)", "USA", "usa" },
|
||||
};
|
||||
|
||||
static const int num_single_quote_sources =
|
||||
sizeof(single_quote_sources) / sizeof(gnc_quote_source);
|
||||
static const int num_multiple_quote_sources =
|
||||
sizeof(multiple_quote_sources) / sizeof(gnc_quote_source);
|
||||
static GList *new_quote_sources = NULL;
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* gnc_quote_source_fq_installed
|
||||
*
|
||||
* This function indicates whether or not the Finance::Quote module
|
||||
* is installed on a users computer.
|
||||
********************************************************************/
|
||||
gboolean
|
||||
gnc_quote_source_fq_installed (void)
|
||||
{
|
||||
return fq_is_installed;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* gnc_quote_source_num_entries
|
||||
*
|
||||
* Return the number of entries for a given type of price source.
|
||||
********************************************************************/
|
||||
gint gnc_quote_source_num_entries(QuoteSourceType type)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* gnc_quote_source_init_tables
|
||||
*
|
||||
* Update the type/index values for prices sources.
|
||||
********************************************************************/
|
||||
static void
|
||||
gnc_quote_source_init_tables (void)
|
||||
{
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < num_single_quote_sources; i++) {
|
||||
single_quote_sources[i].type = SOURCE_SINGLE;
|
||||
single_quote_sources[i].index = i;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_multiple_quote_sources; i++) {
|
||||
multiple_quote_sources[i].type = SOURCE_MULTI;
|
||||
multiple_quote_sources[i].index = i;
|
||||
}
|
||||
|
||||
currency_quote_source.type = SOURCE_CURRENCY;
|
||||
currency_quote_source.index = 0;
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* gnc_quote_source_add_new
|
||||
*
|
||||
* Add a new price source. Called when unknown source names are found
|
||||
* either in the F::Q installation (a newly available source) or in
|
||||
* the user's data file (a source that has vanished but needs to be
|
||||
* tracked.)
|
||||
********************************************************************/
|
||||
gnc_quote_source *
|
||||
gnc_quote_source_add_new (const char *source_name, gboolean supported)
|
||||
{
|
||||
gnc_quote_source *new_source;
|
||||
|
||||
DEBUG("Creating new source %s", 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 = 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 = strdup(source_name);
|
||||
new_source->internal_name = strdup(source_name);
|
||||
new_quote_sources = g_list_append(new_quote_sources, new_source);
|
||||
return new_source;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* gnc_quote_source_lookup_by_xxx
|
||||
*
|
||||
* Lookup a price source data structure based upon various criteria.
|
||||
********************************************************************/
|
||||
gnc_quote_source *
|
||||
gnc_quote_source_lookup_by_ti (QuoteSourceType type, gint index)
|
||||
{
|
||||
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 ¤cy_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;
|
||||
}
|
||||
|
||||
gnc_quote_source *
|
||||
gnc_quote_source_lookup_by_internal(const char * name)
|
||||
{
|
||||
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 ¤cy_quote_source;
|
||||
if (safe_strcmp(name, currency_quote_source.old_internal_name) == 0)
|
||||
return ¤cy_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;
|
||||
}
|
||||
|
||||
LEAVE("Unknown source %s", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* gnc_quote_source_get_xxx
|
||||
*
|
||||
* Accessor functions - get functions only. There are no set functions.
|
||||
********************************************************************/
|
||||
QuoteSourceType
|
||||
gnc_quote_source_get_type (gnc_quote_source *source)
|
||||
{
|
||||
ENTER("%p", source);
|
||||
if (!source) {
|
||||
LEAVE("bad source");
|
||||
return SOURCE_SINGLE;
|
||||
}
|
||||
|
||||
DEBUG("type is %d",source->type);
|
||||
return source->type;
|
||||
}
|
||||
|
||||
gint
|
||||
gnc_quote_source_get_index (gnc_quote_source *source)
|
||||
{
|
||||
ENTER("%p", source);
|
||||
if (!source) {
|
||||
LEAVE("bad source");
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEBUG("index is %d", source->index);
|
||||
return source->index;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_quote_source_get_supported (gnc_quote_source *source)
|
||||
{
|
||||
ENTER("%p", source);
|
||||
if (!source) {
|
||||
LEAVE("bad source");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DEBUG("%ssupported", source && source->supported ? "" : "not ");
|
||||
return source->supported;
|
||||
}
|
||||
|
||||
const char *
|
||||
gnc_quote_source_get_user_name (gnc_quote_source *source)
|
||||
{
|
||||
ENTER("%p", source);
|
||||
if (!source) {
|
||||
LEAVE("bad source");
|
||||
return NULL;
|
||||
}
|
||||
LEAVE("user name %s", source->user_name);
|
||||
return source->user_name;
|
||||
}
|
||||
|
||||
const char *
|
||||
gnc_quote_source_get_old_internal_name (gnc_quote_source *source)
|
||||
{
|
||||
ENTER("%p", source);
|
||||
if (!source) {
|
||||
LEAVE("bad source");
|
||||
return NULL;
|
||||
}
|
||||
LEAVE("old internal name %s", source->old_internal_name);
|
||||
return source->old_internal_name;
|
||||
}
|
||||
|
||||
const char *
|
||||
gnc_quote_source_get_internal_name (gnc_quote_source *source)
|
||||
{
|
||||
ENTER("%p", source);
|
||||
if (!source) {
|
||||
LEAVE("bad source");
|
||||
return NULL;
|
||||
}
|
||||
LEAVE("internal name %s", source->internal_name);
|
||||
return source->internal_name;
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* gnc_quote_source_set_fq_installed
|
||||
*
|
||||
* Update gnucash internal tables on what Finance::Quote sources are
|
||||
* installed.
|
||||
********************************************************************/
|
||||
void
|
||||
gnc_quote_source_set_fq_installed (GList *sources_list)
|
||||
{
|
||||
gnc_quote_source *source;
|
||||
char *source_name;
|
||||
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(" ");
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* gnc_commodity_new
|
||||
********************************************************************/
|
||||
@ -148,7 +495,6 @@ gnc_commodity_destroy(gnc_commodity * cm)
|
||||
cm->mnemonic = NULL;
|
||||
|
||||
/* Set through accessor functions */
|
||||
g_free(cm->quote_source);
|
||||
cm->quote_source = NULL;
|
||||
|
||||
g_free(cm->quote_tz);
|
||||
@ -274,15 +620,24 @@ gnc_commodity_get_quote_flag(const gnc_commodity *cm)
|
||||
* gnc_commodity_get_quote_source
|
||||
********************************************************************/
|
||||
|
||||
const char*
|
||||
gnc_quote_source*
|
||||
gnc_commodity_get_quote_source(const gnc_commodity *cm)
|
||||
{
|
||||
if(!cm) return NULL;
|
||||
if (!cm->quote_source && gnc_commodity_is_iso(cm))
|
||||
return "CURRENCY";
|
||||
return ¤cy_quote_source;
|
||||
return cm->quote_source;
|
||||
}
|
||||
|
||||
gnc_quote_source*
|
||||
gnc_commodity_get_default_quote_source(const gnc_commodity *cm)
|
||||
{
|
||||
if (cm && gnc_commodity_is_iso(cm))
|
||||
return ¤cy_quote_source;
|
||||
/* Should make this a user option at some point. */
|
||||
return gnc_quote_source_lookup_by_internal("yahoo");
|
||||
}
|
||||
|
||||
/********************************************************************
|
||||
* gnc_commodity_get_quote_tz
|
||||
********************************************************************/
|
||||
@ -400,18 +755,12 @@ gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag)
|
||||
********************************************************************/
|
||||
|
||||
void
|
||||
gnc_commodity_set_quote_source(gnc_commodity *cm, const char *src)
|
||||
gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src)
|
||||
{
|
||||
ENTER ("(cm=%p, src=%s)", cm, src);
|
||||
ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name : "unknown");
|
||||
|
||||
if(!cm) return;
|
||||
if (cm->quote_source) {
|
||||
g_free(cm->quote_source);
|
||||
cm->quote_source = NULL;
|
||||
}
|
||||
|
||||
if (src && *src)
|
||||
cm->quote_source = g_strdup(src);
|
||||
cm->quote_source = src;
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
@ -864,7 +1213,8 @@ get_quotables_helper1(gpointer key, gpointer value, gpointer data)
|
||||
gnc_commodity *comm = value;
|
||||
GList ** l = data;
|
||||
|
||||
if (!comm->quote_flag)
|
||||
if (!comm->quote_flag ||
|
||||
!comm->quote_source || !comm->quote_source->supported)
|
||||
return;
|
||||
*l = g_list_prepend(*l, value);
|
||||
}
|
||||
@ -874,7 +1224,8 @@ get_quotables_helper2 (gnc_commodity *comm, gpointer data)
|
||||
{
|
||||
GList ** l = data;
|
||||
|
||||
if (!comm->quote_flag)
|
||||
if (!comm->quote_flag ||
|
||||
!comm->quote_source || !comm->quote_source->supported)
|
||||
return TRUE;
|
||||
*l = g_list_prepend(*l, comm);
|
||||
return TRUE;
|
||||
@ -1140,6 +1491,7 @@ static QofObject commodity_table_object_def =
|
||||
gboolean
|
||||
gnc_commodity_table_register (void)
|
||||
{
|
||||
gnc_quote_source_init_tables();
|
||||
return qof_object_register (&commodity_table_object_def);
|
||||
}
|
||||
|
||||
|
@ -64,6 +64,155 @@
|
||||
#define GNC_COMMODITY_NS_ASX "ASX"
|
||||
|
||||
|
||||
/** @name Commodity Quote Source functions */
|
||||
/** @{ */
|
||||
|
||||
/** 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.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
SOURCE_SINGLE = 0, /**< 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_MAX,
|
||||
SOURCE_CURRENCY = SOURCE_MAX, /**< The special currency quote source. */
|
||||
} QuoteSourceType;
|
||||
|
||||
/** 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.
|
||||
*
|
||||
* @return TRUE is F::Q is installed properly.
|
||||
*/
|
||||
gboolean gnc_quote_source_fq_installed (void);
|
||||
|
||||
/** 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.
|
||||
*
|
||||
* @param sources_list A list of strings containing the source names
|
||||
* as they are known to F::Q.
|
||||
*/
|
||||
void gnc_quote_source_set_fq_installed (GList *sources_list);
|
||||
|
||||
/** Return the number of entries for a given type of quote source.
|
||||
*
|
||||
* @param type The quote source type whose count should be returned.
|
||||
*
|
||||
* @return The number of entries for this type of quote source.
|
||||
*/
|
||||
gint gnc_quote_source_num_entries(QuoteSourceType type);
|
||||
|
||||
/** 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.
|
||||
*
|
||||
* @param name The internal name for this new quote source.
|
||||
*
|
||||
* @param supported TRUE is this quote source is supported by F::Q.
|
||||
* Should only be set by the F::Q startup routine.
|
||||
*
|
||||
* @return A pointer to the newly created quote source.
|
||||
*/
|
||||
gnc_quote_source *gnc_quote_source_add_new(const char * name, gboolean supported);
|
||||
|
||||
/** Given the internal (gnucash or F::Q) name of a quote source, find
|
||||
* the data structure identified by this name.
|
||||
*
|
||||
* @param internal_name The name of this quote source.
|
||||
*
|
||||
* @return A pointer to the price quote source that has the specified
|
||||
* internal name.
|
||||
*/
|
||||
gnc_quote_source *gnc_quote_source_lookup_by_internal(const char * internal_name);
|
||||
|
||||
/** Given the type/index of a quote source, find the data structure
|
||||
* identified by this pair.
|
||||
*
|
||||
* @param type The type of this quote source.
|
||||
*
|
||||
* @param index The index of this quote source within its type.
|
||||
*
|
||||
* @return A pointer to the price quote source that has the specified
|
||||
* type/index.
|
||||
*/
|
||||
gnc_quote_source *gnc_quote_source_lookup_by_ti(QuoteSourceType type, gint i);
|
||||
|
||||
/** 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.
|
||||
*
|
||||
* @param source The quote source in question.
|
||||
*
|
||||
* @return TRUE if the user's computer supports this quote source.
|
||||
*/
|
||||
gboolean gnc_quote_source_get_supported (gnc_quote_source *source);
|
||||
|
||||
/** Given a gnc_quote_source data structure, return the type of this
|
||||
* particular quote source. (SINGLE, MULTI, UNKNOWN)
|
||||
*
|
||||
* @param source The quote source in question.
|
||||
*
|
||||
* @return The type of this quote source.
|
||||
*/
|
||||
QuoteSourceType gnc_quote_source_get_type (gnc_quote_source *source);
|
||||
|
||||
/** Given a gnc_quote_source data structure, return the index of this
|
||||
* particular quote source within its type.
|
||||
*
|
||||
* @param source The quote source in question.
|
||||
*
|
||||
* @return The index of this quote source in its type.
|
||||
*/
|
||||
gint gnc_quote_source_get_index (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, ...)"
|
||||
*
|
||||
* @param source The quote source in question.
|
||||
*
|
||||
* @return The user friendly name.
|
||||
*/
|
||||
const char *gnc_quote_source_get_user_name (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"
|
||||
*
|
||||
* @param source The quote source in question.
|
||||
*
|
||||
* @return The internal name.
|
||||
*/
|
||||
const char *gnc_quote_source_get_internal_name (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"
|
||||
*
|
||||
* @note This routine should only be used for backward compatability
|
||||
* with the existing XML files. The rest of the code should use the
|
||||
* gnc_quote_source_lookup_by_internal() routine.
|
||||
*
|
||||
* @param source The quote source in question.
|
||||
*
|
||||
* @return The internal name.
|
||||
*/
|
||||
const char *gnc_quote_source_get_old_internal_name (gnc_quote_source *source);
|
||||
/** @} */
|
||||
|
||||
|
||||
/** @name Commodity Creation */
|
||||
/** @{ */
|
||||
@ -235,7 +384,8 @@ gboolean gnc_commodity_get_quote_flag(const gnc_commodity *cm);
|
||||
* This string is owned by the engine and should not be freed by the
|
||||
* caller.
|
||||
*/
|
||||
const char* gnc_commodity_get_quote_source(const gnc_commodity *cm);
|
||||
gnc_quote_source* gnc_commodity_get_quote_source(const gnc_commodity *cm);
|
||||
gnc_quote_source* gnc_commodity_get_default_quote_source(const gnc_commodity *cm);
|
||||
|
||||
/** Retrieve the automatic price quote timezone for the specified
|
||||
* commodity. This will be a pointer to a null terminated string of
|
||||
@ -351,7 +501,7 @@ void gnc_commodity_set_quote_flag(gnc_commodity *cm, const gboolean flag);
|
||||
* This string belongs to the caller and will be duplicated by the
|
||||
* engine.
|
||||
*/
|
||||
void gnc_commodity_set_quote_source(gnc_commodity *cm, const char *src);
|
||||
void gnc_commodity_set_quote_source(gnc_commodity *cm, gnc_quote_source *src);
|
||||
|
||||
/** Set the automatic price quote timezone for the specified
|
||||
* commodity. This should be a pointer to a null terminated string
|
||||
|
@ -135,6 +135,8 @@ typedef struct gnc_commodity_s gnc_commodity;
|
||||
/** @brief A gnc_commodity_table is a database of commodity info. */
|
||||
typedef struct gnc_commodity_table_s gnc_commodity_table;
|
||||
|
||||
typedef struct gnc_quote_source_s gnc_quote_source;
|
||||
|
||||
/**
|
||||
* A GNCLot implements the fundamental conceptual idea behind
|
||||
* invoices, inventory lots, and stock market investment lots.
|
||||
|
@ -2484,3 +2484,11 @@ the timepair representing midday on that day")
|
||||
"gnc_engine_resume_events"
|
||||
'()
|
||||
"Resume engine event generation.")
|
||||
|
||||
(gw:wrap-function
|
||||
ws
|
||||
'gnc:quote-source-set-fq-installed
|
||||
'<gw:void>
|
||||
"gnc_quote_source_set_fq_installed"
|
||||
'(((gw:glist-of (<gw:mchars> callee-owned) callee-owned) choices))
|
||||
"Takes a list of installed Finance::Quote souces and records it internally.")
|
||||
|
@ -763,8 +763,8 @@
|
||||
<can_focus>True</can_focus>
|
||||
<signal>
|
||||
<name>toggled</name>
|
||||
<handler>gnc_ui_commodity_quote_cb</handler>
|
||||
<last_modification_time>Sun, 20 Apr 2003 03:35:34 GMT</last_modification_time>
|
||||
<handler>gnc_ui_commodity_quote_info_cb</handler>
|
||||
<last_modification_time>Wed, 25 Jun 2003 06:17:32 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>Get Online Quotes</label>
|
||||
<active>False</active>
|
||||
@ -779,8 +779,8 @@
|
||||
<widget>
|
||||
<class>GtkTable</class>
|
||||
<name>table2</name>
|
||||
<rows>2</rows>
|
||||
<columns>2</columns>
|
||||
<rows>5</rows>
|
||||
<columns>3</columns>
|
||||
<homogeneous>False</homogeneous>
|
||||
<row_spacing>3</row_spacing>
|
||||
<column_spacing>3</column_spacing>
|
||||
@ -802,7 +802,7 @@
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<left_attach>0</left_attach>
|
||||
<right_attach>1</right_attach>
|
||||
<right_attach>2</right_attach>
|
||||
<top_attach>0</top_attach>
|
||||
<bottom_attach>1</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
@ -816,6 +816,118 @@
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkRadioButton</class>
|
||||
<name>single_source_button</name>
|
||||
<can_focus>True</can_focus>
|
||||
<signal>
|
||||
<name>toggled</name>
|
||||
<handler>gnc_ui_commodity_quote_info_cb</handler>
|
||||
<last_modification_time>Wed, 25 Jun 2003 06:17:44 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>single source</label>
|
||||
<active>False</active>
|
||||
<draw_indicator>True</draw_indicator>
|
||||
<group>stock source</group>
|
||||
<child>
|
||||
<left_attach>1</left_attach>
|
||||
<right_attach>2</right_attach>
|
||||
<top_attach>1</top_attach>
|
||||
<bottom_attach>2</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>False</xexpand>
|
||||
<yexpand>False</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>False</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkRadioButton</class>
|
||||
<name>multi_source_button</name>
|
||||
<can_focus>True</can_focus>
|
||||
<signal>
|
||||
<name>toggled</name>
|
||||
<handler>gnc_ui_commodity_quote_info_cb</handler>
|
||||
<last_modification_time>Wed, 25 Jun 2003 06:17:53 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>multiple sources</label>
|
||||
<active>False</active>
|
||||
<draw_indicator>True</draw_indicator>
|
||||
<group>stock source</group>
|
||||
<child>
|
||||
<left_attach>1</left_attach>
|
||||
<right_attach>2</right_attach>
|
||||
<top_attach>2</top_attach>
|
||||
<bottom_attach>3</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>False</xexpand>
|
||||
<yexpand>False</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>False</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkRadioButton</class>
|
||||
<name>unknown_source_button</name>
|
||||
<can_focus>True</can_focus>
|
||||
<signal>
|
||||
<name>toggled</name>
|
||||
<handler>gnc_ui_commodity_quote_info_cb</handler>
|
||||
<last_modification_time>Wed, 25 Jun 2003 06:18:00 GMT</last_modification_time>
|
||||
</signal>
|
||||
<label>unknown sources</label>
|
||||
<active>False</active>
|
||||
<draw_indicator>True</draw_indicator>
|
||||
<group>stock source</group>
|
||||
<child>
|
||||
<left_attach>1</left_attach>
|
||||
<right_attach>2</right_attach>
|
||||
<top_attach>3</top_attach>
|
||||
<bottom_attach>4</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>False</xexpand>
|
||||
<yexpand>False</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>False</yfill>
|
||||
</child>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkHBox</class>
|
||||
<name>quote_tz_box</name>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<left_attach>2</left_attach>
|
||||
<right_attach>3</right_attach>
|
||||
<top_attach>4</top_attach>
|
||||
<bottom_attach>5</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>False</xexpand>
|
||||
<yexpand>False</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>True</yfill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>Placeholder</class>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkLabel</class>
|
||||
<name>quote_tz_label</name>
|
||||
@ -828,9 +940,9 @@
|
||||
<ypad>0</ypad>
|
||||
<child>
|
||||
<left_attach>0</left_attach>
|
||||
<right_attach>1</right_attach>
|
||||
<top_attach>1</top_attach>
|
||||
<bottom_attach>2</bottom_attach>
|
||||
<right_attach>2</right_attach>
|
||||
<top_attach>4</top_attach>
|
||||
<bottom_attach>5</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>False</xexpand>
|
||||
@ -844,17 +956,17 @@
|
||||
|
||||
<widget>
|
||||
<class>GtkHBox</class>
|
||||
<name>source_box</name>
|
||||
<name>multi_source_box</name>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<left_attach>1</left_attach>
|
||||
<right_attach>2</right_attach>
|
||||
<top_attach>0</top_attach>
|
||||
<bottom_attach>1</bottom_attach>
|
||||
<left_attach>2</left_attach>
|
||||
<right_attach>3</right_attach>
|
||||
<top_attach>2</top_attach>
|
||||
<bottom_attach>3</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>True</xexpand>
|
||||
<xexpand>False</xexpand>
|
||||
<yexpand>False</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
@ -869,17 +981,42 @@
|
||||
|
||||
<widget>
|
||||
<class>GtkHBox</class>
|
||||
<name>quote_tz_box</name>
|
||||
<name>unknown_source_box</name>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<left_attach>1</left_attach>
|
||||
<right_attach>2</right_attach>
|
||||
<left_attach>2</left_attach>
|
||||
<right_attach>3</right_attach>
|
||||
<top_attach>3</top_attach>
|
||||
<bottom_attach>4</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>False</xexpand>
|
||||
<yexpand>False</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
<xfill>True</xfill>
|
||||
<yfill>True</yfill>
|
||||
</child>
|
||||
|
||||
<widget>
|
||||
<class>Placeholder</class>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
<widget>
|
||||
<class>GtkHBox</class>
|
||||
<name>single_source_box</name>
|
||||
<homogeneous>False</homogeneous>
|
||||
<spacing>0</spacing>
|
||||
<child>
|
||||
<left_attach>2</left_attach>
|
||||
<right_attach>3</right_attach>
|
||||
<top_attach>1</top_attach>
|
||||
<bottom_attach>2</bottom_attach>
|
||||
<xpad>0</xpad>
|
||||
<ypad>0</ypad>
|
||||
<xexpand>False</xexpand>
|
||||
<xexpand>True</xexpand>
|
||||
<yexpand>False</yexpand>
|
||||
<xshrink>False</xshrink>
|
||||
<yshrink>False</yshrink>
|
||||
|
@ -72,7 +72,8 @@ struct commodity_window {
|
||||
GtkWidget * fraction_spinbutton;
|
||||
GtkWidget * get_quote_check;
|
||||
GtkWidget * source_label;
|
||||
GtkWidget * source_menu;
|
||||
GtkWidget * source_button[SOURCE_MAX];
|
||||
GtkWidget * source_menu[SOURCE_MAX];
|
||||
GtkWidget * quote_tz_label;
|
||||
GtkWidget * quote_tz_menu;
|
||||
GtkWidget * ok_button;
|
||||
@ -101,7 +102,7 @@ void gnc_ui_select_commodity_namespace_changed_cb(GtkEditable * entry,
|
||||
void gnc_ui_commodity_changed_cb(GtkWidget * dummy, gpointer user_data);
|
||||
void gnc_ui_commodity_ok_cb(GtkButton * button, gpointer user_data);
|
||||
void gnc_ui_commodity_help_cb(GtkButton * button, gpointer user_data);
|
||||
void gnc_ui_commodity_quote_cb(GtkWidget *w, gpointer data);
|
||||
void gnc_ui_commodity_quote_info_cb(GtkWidget *w, gpointer data);
|
||||
|
||||
|
||||
/********************************************************************
|
||||
@ -509,21 +510,31 @@ gnc_ui_namespace_picker_ns (GtkWidget *combobox)
|
||||
/********************************************************************/
|
||||
|
||||
void
|
||||
gnc_ui_commodity_quote_cb (GtkWidget *w, gpointer data)
|
||||
gnc_ui_commodity_quote_info_cb (GtkWidget *w, gpointer data)
|
||||
{
|
||||
CommodityWindow *cw = data;
|
||||
gboolean get_quote, allow_src;
|
||||
gboolean get_quote, allow_src, active;
|
||||
const char *text;
|
||||
gint i;
|
||||
|
||||
ENTER(" ");
|
||||
get_quote = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
|
||||
|
||||
text = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(cw->namespace_combo)->entry));
|
||||
allow_src = !gnc_commodity_namespace_is_iso(text);
|
||||
gtk_widget_set_sensitive(cw->source_label, get_quote && allow_src);
|
||||
gtk_widget_set_sensitive(cw->source_menu, get_quote && allow_src);
|
||||
|
||||
for (i = SOURCE_SINGLE; i < SOURCE_MAX; i++) {
|
||||
if (!cw->source_button[i])
|
||||
continue;
|
||||
active =
|
||||
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw->source_button[i]));
|
||||
gtk_widget_set_sensitive(cw->source_button[i], get_quote && allow_src);
|
||||
gtk_widget_set_sensitive(cw->source_menu[i], get_quote && allow_src && active);
|
||||
}
|
||||
gtk_widget_set_sensitive(cw->quote_tz_label, get_quote);
|
||||
gtk_widget_set_sensitive(cw->quote_tz_menu, get_quote);
|
||||
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
void
|
||||
@ -559,20 +570,25 @@ gnc_ui_commodity_changed_cb(GtkWidget * dummy, gpointer user_data)
|
||||
* Returns: the menu *
|
||||
\*******************************************************************/
|
||||
static GtkWidget *
|
||||
gnc_ui_source_menu_create(void)
|
||||
gnc_ui_source_menu_create(QuoteSourceType type)
|
||||
{
|
||||
gint i;
|
||||
gint i, max;
|
||||
GtkMenu *menu;
|
||||
GtkWidget *item;
|
||||
GtkWidget *omenu;
|
||||
gnc_quote_source *source;
|
||||
|
||||
menu = GTK_MENU(gtk_menu_new());
|
||||
gtk_widget_show(GTK_WIDGET(menu));
|
||||
|
||||
for (i = 0; i < NUM_SOURCES; i++)
|
||||
max = gnc_quote_source_num_entries(type);
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
item = gtk_menu_item_new_with_label(gnc_price_source_enum2name(i));
|
||||
gtk_widget_set_sensitive(item, gnc_price_source_sensitive(i));
|
||||
source = gnc_quote_source_lookup_by_ti(type, i);
|
||||
if (source == NULL)
|
||||
break;
|
||||
item = gtk_menu_item_new_with_label(gnc_quote_source_get_user_name(source));
|
||||
gtk_widget_set_sensitive(item, gnc_quote_source_get_supported(source));
|
||||
gtk_widget_show(item);
|
||||
gtk_menu_append(menu, item);
|
||||
}
|
||||
@ -675,6 +691,7 @@ gnc_ui_new_commodity_dialog(const char * selected_namespace,
|
||||
CommodityWindow * retval = g_new0(CommodityWindow, 1);
|
||||
GtkWidget *help_button;
|
||||
GtkWidget *box;
|
||||
GtkWidget *menu;
|
||||
GladeXML *xml;
|
||||
gboolean include_iso;
|
||||
|
||||
@ -706,13 +723,31 @@ gnc_ui_new_commodity_dialog(const char * selected_namespace,
|
||||
retval->ok_button = glade_xml_get_widget (xml, "ok_button");
|
||||
retval->get_quote_check = glade_xml_get_widget (xml, "get_quote_check");
|
||||
retval->source_label = glade_xml_get_widget (xml, "source_label");
|
||||
retval->source_button[SOURCE_SINGLE] = glade_xml_get_widget (xml, "single_source_button");
|
||||
retval->source_button[SOURCE_MULTI] = glade_xml_get_widget (xml, "multi_source_button");
|
||||
retval->quote_tz_label = glade_xml_get_widget (xml, "quote_tz_label");
|
||||
|
||||
|
||||
/* Build custom widgets */
|
||||
box = glade_xml_get_widget (xml, "source_box");
|
||||
retval->source_menu = gnc_ui_source_menu_create();
|
||||
gtk_box_pack_start(GTK_BOX(box), retval->source_menu, TRUE, TRUE, 0);
|
||||
box = glade_xml_get_widget (xml, "single_source_box");
|
||||
menu = gnc_ui_source_menu_create(SOURCE_SINGLE);
|
||||
retval->source_menu[SOURCE_SINGLE] = menu;
|
||||
gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
|
||||
|
||||
box = glade_xml_get_widget (xml, "multi_source_box");
|
||||
menu = gnc_ui_source_menu_create(SOURCE_MULTI);
|
||||
retval->source_menu[SOURCE_MULTI] = menu;
|
||||
gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
|
||||
|
||||
if (gnc_quote_source_num_entries(SOURCE_UNKNOWN)) {
|
||||
retval->source_button[SOURCE_UNKNOWN] =
|
||||
glade_xml_get_widget (xml, "unknown_source_button");
|
||||
box = glade_xml_get_widget (xml, "unknown_source_box");
|
||||
menu = gnc_ui_source_menu_create(SOURCE_UNKNOWN);
|
||||
retval->source_menu[SOURCE_UNKNOWN] = menu;
|
||||
gtk_box_pack_start(GTK_BOX(box), menu, TRUE, TRUE, 0);
|
||||
}
|
||||
|
||||
box = glade_xml_get_widget (xml, "quote_tz_box");
|
||||
retval->quote_tz_menu = gnc_ui_quote_tz_menu_create();
|
||||
gtk_box_pack_start(GTK_BOX(box), retval->quote_tz_menu, TRUE, TRUE, 0);
|
||||
@ -727,7 +762,7 @@ gnc_ui_new_commodity_dialog(const char * selected_namespace,
|
||||
}
|
||||
|
||||
/* Are price quotes supported */
|
||||
if (gnc_price_source_have_fq()) {
|
||||
if (gnc_quote_source_fq_installed()) {
|
||||
gtk_widget_destroy(glade_xml_get_widget (xml, "finance_quote_warning"));
|
||||
} else {
|
||||
gtk_widget_set_sensitive(glade_xml_get_widget (xml, "price_quote_frame"),
|
||||
@ -765,20 +800,28 @@ static void
|
||||
gnc_ui_commodity_update_quote_info(CommodityWindow *win,
|
||||
gnc_commodity *commodity)
|
||||
{
|
||||
gnc_quote_source *source;
|
||||
QuoteSourceType type;
|
||||
gboolean has_quote_src;
|
||||
const char *quote_src, *quote_tz;
|
||||
const char *quote_tz;
|
||||
int pos = 0;
|
||||
|
||||
ENTER(" ");
|
||||
has_quote_src = gnc_commodity_get_quote_flag (commodity);
|
||||
quote_src = gnc_commodity_get_quote_source (commodity);
|
||||
source = gnc_commodity_get_quote_source (commodity);
|
||||
if (source == NULL)
|
||||
source = gnc_commodity_get_default_quote_source (commodity);
|
||||
quote_tz = gnc_commodity_get_quote_tz (commodity);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (win->get_quote_check),
|
||||
has_quote_src);
|
||||
if (!gnc_commodity_is_iso(commodity))
|
||||
gtk_option_menu_set_history (GTK_OPTION_MENU (win->source_menu),
|
||||
gnc_price_source_internal2enum (quote_src));
|
||||
if (!gnc_commodity_is_iso(commodity)) {
|
||||
type = gnc_quote_source_get_type(source);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(win->source_button[type]), TRUE);
|
||||
gtk_option_menu_set_history (GTK_OPTION_MENU (win->source_menu[type]),
|
||||
gnc_quote_source_get_index(source));
|
||||
}
|
||||
|
||||
if (quote_tz) {
|
||||
pos = gnc_find_timezone_menu_position(quote_tz);
|
||||
if(pos == 0) {
|
||||
@ -825,13 +868,11 @@ gnc_ui_common_commodity_modal(gnc_commodity *commodity,
|
||||
mnemonic, code, fraction);
|
||||
|
||||
/* Update stock quote info based on existing commodity */
|
||||
if (commodity) {
|
||||
gnc_ui_commodity_update_quote_info(win, commodity);
|
||||
win->edit_commodity = commodity;
|
||||
}
|
||||
gnc_ui_commodity_update_quote_info(win, commodity);
|
||||
win->edit_commodity = commodity;
|
||||
|
||||
/* Update stock quote sensitivities based on check box */
|
||||
gnc_ui_commodity_quote_cb(win->get_quote_check, win);
|
||||
gnc_ui_commodity_quote_info_cb(win->get_quote_check, win);
|
||||
|
||||
/* Run the dialog, handling the terminal conditions. */
|
||||
done = FALSE;
|
||||
@ -928,7 +969,8 @@ gnc_ui_commodity_ok_cb(GtkButton * button,
|
||||
gpointer user_data)
|
||||
{
|
||||
CommodityWindow * w = user_data;
|
||||
|
||||
gnc_quote_source *source;
|
||||
QuoteSourceType type;
|
||||
const char * fullname = gtk_entry_get_text(GTK_ENTRY(w->fullname_entry));
|
||||
const char * namespace = gnc_ui_namespace_picker_ns (w->namespace_combo);
|
||||
const char * mnemonic = gtk_entry_get_text(GTK_ENTRY(w->mnemonic_entry));
|
||||
@ -989,9 +1031,13 @@ gnc_ui_commodity_ok_cb(GtkButton * button,
|
||||
gnc_commodity_set_quote_flag (c, gtk_toggle_button_get_active
|
||||
(GTK_TOGGLE_BUTTON (w->get_quote_check)));
|
||||
|
||||
selection = gnc_option_menu_get_active (w->source_menu);
|
||||
string = gnc_price_source_enum2internal (selection);
|
||||
gnc_commodity_set_quote_source(c, string);
|
||||
for (type = SOURCE_SINGLE; type < SOURCE_MAX; type++) {
|
||||
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w->source_button[type])))
|
||||
break;
|
||||
}
|
||||
selection = gnc_option_menu_get_active (w->source_menu[type]);
|
||||
source = gnc_quote_source_lookup_by_ti (type, selection);
|
||||
gnc_commodity_set_quote_source(c, source);
|
||||
|
||||
selection = gnc_option_menu_get_active (w->quote_tz_menu);
|
||||
string = gnc_timezone_menu_position_to_string(selection);
|
||||
|
@ -448,10 +448,9 @@ string and 'directories' must be a list of strings."
|
||||
|
||||
(gnc:update-splash-screen (_ "Checking Finance::Quote..."))
|
||||
(gnc:use-guile-module-here! '(gnucash price-quotes))
|
||||
; (gnc:price-source-set-fq-installed (gnc:fq-check-sources))
|
||||
(let ((sources (gnc:fq-check-sources)))
|
||||
(if (list? sources)
|
||||
(gnc:price-source-set-fq-installed sources)))
|
||||
(gnc:quote-source-set-fq-installed sources)))
|
||||
|
||||
(gnc:update-splash-screen (_ "Loading tip-of-the-day..."))
|
||||
(gnc:initialize-tip-of-the-day)
|
||||
|
Loading…
Reference in New Issue
Block a user