mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
gnc_commodity_table_get_namespaces returns std::vector<std::string>
This commit is contained in:
parent
555e23e8b5
commit
746ab554a5
@ -64,6 +64,7 @@ namespace std {
|
|||||||
|
|
||||||
%begin
|
%begin
|
||||||
%{
|
%{
|
||||||
|
#include <gnc-commodity.hpp>
|
||||||
#include <gnc-optiondb.h>
|
#include <gnc-optiondb.h>
|
||||||
#include <gnc-optiondb.hpp>
|
#include <gnc-optiondb.hpp>
|
||||||
#include <gnc-optiondb-impl.hpp>
|
#include <gnc-optiondb-impl.hpp>
|
||||||
@ -1975,26 +1976,13 @@ gnc_register_multichoice_callback_option(GncOptionDBPtr& db,
|
|||||||
const char* key, const char* doc_string,
|
const char* key, const char* doc_string,
|
||||||
const char *value)
|
const char *value)
|
||||||
{
|
{
|
||||||
gnc_commodity* commodity{};
|
|
||||||
const auto book{qof_session_get_book(gnc_get_current_session())};
|
const auto book{qof_session_get_book(gnc_get_current_session())};
|
||||||
const auto commodity_table{gnc_commodity_table_get_table(book)};
|
const auto commodity_table{gnc_commodity_table_get_table(book)};
|
||||||
const auto namespaces{gnc_commodity_table_get_namespaces(commodity_table)};
|
for (const auto& name_space : gnc_commodity_table_get_namespaces(commodity_table))
|
||||||
GncOption* rv = nullptr;
|
if (auto commodity = gnc_commodity_table_lookup (commodity_table, name_space.c_str(),
|
||||||
for (auto node = namespaces; node && commodity == nullptr;
|
value))
|
||||||
node = g_list_next(node))
|
return gnc_make_commodity_option(section, name, key, doc_string, commodity);
|
||||||
{
|
return nullptr;
|
||||||
commodity = gnc_commodity_table_lookup(commodity_table,
|
|
||||||
(const char*)(node->data),
|
|
||||||
value);
|
|
||||||
|
|
||||||
if (commodity)
|
|
||||||
{
|
|
||||||
rv = gnc_make_commodity_option(section, name, key, doc_string, commodity);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_list_free (namespaces);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GncOption*
|
static GncOption*
|
||||||
|
@ -42,12 +42,15 @@
|
|||||||
|
|
||||||
#include "dialog-commodity.h"
|
#include "dialog-commodity.h"
|
||||||
#include "dialog-utils.h"
|
#include "dialog-utils.h"
|
||||||
|
#include "gnc-commodity.hpp"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-gtk-utils.h"
|
#include "gnc-gtk-utils.h"
|
||||||
#include "gnc-gui-query.h"
|
#include "gnc-gui-query.h"
|
||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
#include "gnc-ui.h"
|
#include "gnc-ui.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
/* This static indicates the debugging module that this .o belongs to. */
|
/* This static indicates the debugging module that this .o belongs to. */
|
||||||
static QofLogModule log_module = GNC_MOD_GUI;
|
static QofLogModule log_module = GNC_MOD_GUI;
|
||||||
|
|
||||||
@ -560,7 +563,7 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
|
|||||||
GtkComboBox *combo_box;
|
GtkComboBox *combo_box;
|
||||||
GtkTreeModel *model;
|
GtkTreeModel *model;
|
||||||
GtkTreeIter iter, match;
|
GtkTreeIter iter, match;
|
||||||
GList *namespaces, *node;
|
std::vector<std::string> namespaces;
|
||||||
gboolean matched = FALSE;
|
gboolean matched = FALSE;
|
||||||
|
|
||||||
g_return_if_fail(GTK_IS_COMBO_BOX (cbwe));
|
g_return_if_fail(GTK_IS_COMBO_BOX (cbwe));
|
||||||
@ -582,12 +585,10 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
|
|||||||
case DIAG_COMM_NON_CURRENCY_SELECT:
|
case DIAG_COMM_NON_CURRENCY_SELECT:
|
||||||
namespaces =
|
namespaces =
|
||||||
gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
|
gnc_commodity_table_get_namespaces (gnc_get_current_commodities());
|
||||||
node = g_list_find_custom (namespaces, GNC_COMMODITY_NS_CURRENCY, collate);
|
|
||||||
if (node)
|
if (auto it = std::find (namespaces.begin(), namespaces.end(), GNC_COMMODITY_NS_CURRENCY);
|
||||||
{
|
it != namespaces.end())
|
||||||
namespaces = g_list_remove_link (namespaces, node);
|
namespaces.erase (it);
|
||||||
g_list_free_1 (node);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (gnc_commodity_namespace_is_iso (init_string))
|
if (gnc_commodity_namespace_is_iso (init_string))
|
||||||
init_string = nullptr;
|
init_string = nullptr;
|
||||||
@ -595,7 +596,7 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
|
|||||||
|
|
||||||
case DIAG_COMM_CURRENCY:
|
case DIAG_COMM_CURRENCY:
|
||||||
default:
|
default:
|
||||||
namespaces = g_list_prepend (nullptr, (gpointer)GNC_COMMODITY_NS_CURRENCY);
|
namespaces = { GNC_COMMODITY_NS_CURRENCY };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -623,10 +624,10 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add all others to the combobox */
|
/* add all others to the combobox */
|
||||||
namespaces = g_list_sort(namespaces, collate);
|
std::sort (namespaces.begin(), namespaces.end());
|
||||||
for (node = namespaces; node; node = node->next)
|
for (const auto& ns_str : namespaces)
|
||||||
{
|
{
|
||||||
auto ns = static_cast<const char*>(node->data);
|
auto ns = ns_str.c_str();
|
||||||
/* Skip template, legacy and currency namespaces.
|
/* Skip template, legacy and currency namespaces.
|
||||||
The latter was added as first entry earlier */
|
The latter was added as first entry earlier */
|
||||||
if ((g_utf8_collate(ns, GNC_COMMODITY_NS_LEGACY) == 0) ||
|
if ((g_utf8_collate(ns, GNC_COMMODITY_NS_LEGACY) == 0) ||
|
||||||
@ -650,7 +651,6 @@ gnc_ui_update_namespace_picker (GtkWidget *cbwe,
|
|||||||
|
|
||||||
if (matched)
|
if (matched)
|
||||||
gtk_combo_box_set_active_iter (combo_box, &match);
|
gtk_combo_box_set_active_iter (combo_box, &match);
|
||||||
g_list_free(namespaces);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,11 +242,10 @@ gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
|
|||||||
auto oldest = gnc_time (nullptr);
|
auto oldest = gnc_time (nullptr);
|
||||||
auto model = gtk_tree_view_get_model (view);
|
auto model = gtk_tree_view_get_model (view);
|
||||||
const auto commodity_table = gnc_get_current_commodities ();
|
const auto commodity_table = gnc_get_current_commodities ();
|
||||||
auto namespace_list = gnc_commodity_table_get_namespaces (commodity_table);
|
|
||||||
|
|
||||||
for (auto node_n = namespace_list; node_n; node_n = g_list_next (node_n))
|
for (const auto& tmp_namespace_str : gnc_commodity_table_get_namespaces (commodity_table))
|
||||||
{
|
{
|
||||||
auto tmp_namespace = static_cast<char*>(node_n->data);
|
auto tmp_namespace = tmp_namespace_str.c_str();
|
||||||
DEBUG("Looking at namespace %s", tmp_namespace);
|
DEBUG("Looking at namespace %s", tmp_namespace);
|
||||||
auto commodity_list = gnc_commodity_table_get_commodities (commodity_table, tmp_namespace);
|
auto commodity_list = gnc_commodity_table_get_commodities (commodity_table, tmp_namespace);
|
||||||
for (auto node_c = commodity_list; node_c; node_c = g_list_next (node_c))
|
for (auto node_c = commodity_list; node_c; node_c = g_list_next (node_c))
|
||||||
@ -281,7 +280,6 @@ gnc_prices_dialog_load_view (GtkTreeView *view, GNCPriceDB *pdb)
|
|||||||
}
|
}
|
||||||
g_list_free (commodity_list);
|
g_list_free (commodity_list);
|
||||||
}
|
}
|
||||||
g_list_free (namespace_list);
|
|
||||||
|
|
||||||
return oldest;
|
return oldest;
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#include "gnc-uri-utils.h"
|
#include "gnc-uri-utils.h"
|
||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
#include "dialog-utils.h"
|
#include "dialog-utils.h"
|
||||||
|
#include "gnc-commodity.hpp"
|
||||||
|
|
||||||
#include "gnc-component-manager.h"
|
#include "gnc-component-manager.h"
|
||||||
|
|
||||||
@ -446,8 +447,6 @@ GtkTreeModel *get_model (bool all_commodity)
|
|||||||
GtkTreeModel *store, *model;
|
GtkTreeModel *store, *model;
|
||||||
const gnc_commodity_table *commodity_table = gnc_get_current_commodities ();
|
const gnc_commodity_table *commodity_table = gnc_get_current_commodities ();
|
||||||
gnc_commodity *tmp_commodity = nullptr;
|
gnc_commodity *tmp_commodity = nullptr;
|
||||||
char *tmp_namespace = nullptr;
|
|
||||||
GList *namespace_list = gnc_commodity_table_get_namespaces (commodity_table);
|
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
|
||||||
store = GTK_TREE_MODEL(gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING,
|
store = GTK_TREE_MODEL(gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING,
|
||||||
@ -460,9 +459,9 @@ GtkTreeModel *get_model (bool all_commodity)
|
|||||||
gtk_list_store_set (GTK_LIST_STORE(store), &iter,
|
gtk_list_store_set (GTK_LIST_STORE(store), &iter,
|
||||||
DISPLAYED_COMM, " ", SORT_COMM, " ", COMM_PTR, nullptr, SEP, false, -1);
|
DISPLAYED_COMM, " ", SORT_COMM, " ", COMM_PTR, nullptr, SEP, false, -1);
|
||||||
|
|
||||||
for (auto node = namespace_list; node; node = g_list_next (node))
|
for (const auto& tmp_namespace_str : gnc_commodity_table_get_namespaces (commodity_table))
|
||||||
{
|
{
|
||||||
tmp_namespace = (char*)node->data;
|
auto tmp_namespace = tmp_namespace_str.c_str();
|
||||||
DEBUG("Looking at namespace %s", tmp_namespace);
|
DEBUG("Looking at namespace %s", tmp_namespace);
|
||||||
|
|
||||||
/* Hide the template entry */
|
/* Hide the template entry */
|
||||||
@ -506,7 +505,6 @@ GtkTreeModel *get_model (bool all_commodity)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_list_free (namespace_list);
|
|
||||||
g_object_unref (store);
|
g_object_unref (store);
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
#include "Transaction.h"
|
#include "Transaction.h"
|
||||||
|
#include "gnc-commodity.hpp"
|
||||||
#include "gnc-pricedb.h"
|
#include "gnc-pricedb.h"
|
||||||
#include <gnc-exp-parser.h>
|
#include <gnc-exp-parser.h>
|
||||||
|
|
||||||
@ -201,19 +202,16 @@ gnc_commodity* parse_commodity (const std::string& comm_str)
|
|||||||
if (!comm)
|
if (!comm)
|
||||||
{
|
{
|
||||||
/* If that fails try mnemonic in all other namespaces */
|
/* If that fails try mnemonic in all other namespaces */
|
||||||
auto namespaces = gnc_commodity_table_get_namespaces(table);
|
for (const auto& ns_str : gnc_commodity_table_get_namespaces(table))
|
||||||
for (auto ns = namespaces; ns; ns = ns->next)
|
|
||||||
{
|
{
|
||||||
gchar* ns_str = (gchar*)ns->data;
|
if (ns_str == GNC_COMMODITY_NS_CURRENCY)
|
||||||
if (g_utf8_collate(ns_str, GNC_COMMODITY_NS_CURRENCY) == 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
comm = gnc_commodity_table_lookup (table,
|
comm = gnc_commodity_table_lookup (table,
|
||||||
ns_str, comm_str.c_str());
|
ns_str.c_str(), comm_str.c_str());
|
||||||
if (comm)
|
if (comm)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
g_list_free (namespaces);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!comm)
|
if (!comm)
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
#include "Transaction.h"
|
#include "Transaction.h"
|
||||||
#include "dialog-commodity.h"
|
#include "dialog-commodity.h"
|
||||||
|
#include "gnc-commodity.hpp"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
|
|
||||||
@ -64,11 +65,10 @@ gnc_commodity * gnc_import_select_commodity(const char * cusip,
|
|||||||
DEBUG("Looking for commodity with exchange_code: %s", cusip);
|
DEBUG("Looking for commodity with exchange_code: %s", cusip);
|
||||||
|
|
||||||
g_assert(commodity_table);
|
g_assert(commodity_table);
|
||||||
GList *namespace_list = gnc_commodity_table_get_namespaces(commodity_table);
|
|
||||||
|
|
||||||
for (GList *n = namespace_list; !retval && n; n = g_list_next (n))
|
for (const auto& ns_str : gnc_commodity_table_get_namespaces(commodity_table))
|
||||||
{
|
{
|
||||||
auto ns = static_cast<const char*>(n->data);
|
auto ns = ns_str.c_str();
|
||||||
DEBUG("Looking at namespace %s", ns);
|
DEBUG("Looking at namespace %s", ns);
|
||||||
GList *comm_list = gnc_commodity_table_get_commodities (commodity_table, ns);
|
GList *comm_list = gnc_commodity_table_get_commodities (commodity_table, ns);
|
||||||
for (GList *m = comm_list; !retval && m; m = g_list_next (m))
|
for (GList *m = comm_list; !retval && m; m = g_list_next (m))
|
||||||
@ -82,10 +82,10 @@ gnc_commodity * gnc_import_select_commodity(const char * cusip,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_list_free (comm_list);
|
g_list_free (comm_list);
|
||||||
|
if (retval)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free(namespace_list);
|
|
||||||
|
|
||||||
if (retval == NULL && ask_on_unknown != 0)
|
if (retval == NULL && ask_on_unknown != 0)
|
||||||
{
|
{
|
||||||
const gchar *message =
|
const gchar *message =
|
||||||
|
@ -989,8 +989,6 @@ CommVec
|
|||||||
gnc_quotes_get_quotable_commodities (const gnc_commodity_table * table)
|
gnc_quotes_get_quotable_commodities (const gnc_commodity_table * table)
|
||||||
{
|
{
|
||||||
gnc_commodity_namespace * ns = NULL;
|
gnc_commodity_namespace * ns = NULL;
|
||||||
const char *name_space;
|
|
||||||
GList * nslist, * tmp;
|
|
||||||
CommVec l;
|
CommVec l;
|
||||||
regex_t pattern;
|
regex_t pattern;
|
||||||
const char *expression = gnc_prefs_get_namespace_regexp ();
|
const char *expression = gnc_prefs_get_namespace_regexp ();
|
||||||
@ -1007,10 +1005,9 @@ gnc_quotes_get_quotable_commodities (const gnc_commodity_table * table)
|
|||||||
return CommVec ();
|
return CommVec ();
|
||||||
}
|
}
|
||||||
|
|
||||||
nslist = gnc_commodity_table_get_namespaces (table);
|
for (const auto& name_space_str : gnc_commodity_table_get_namespaces (table))
|
||||||
for (tmp = nslist; tmp; tmp = tmp->next)
|
|
||||||
{
|
{
|
||||||
name_space = static_cast<const char *> (tmp->data);
|
auto name_space = name_space_str.c_str();
|
||||||
if (regexec (&pattern, name_space, 0, NULL, 0) == 0)
|
if (regexec (&pattern, name_space, 0, NULL, 0) == 0)
|
||||||
{
|
{
|
||||||
// DEBUG ("Running list of %s commodities", name_space);
|
// DEBUG ("Running list of %s commodities", name_space);
|
||||||
@ -1023,7 +1020,6 @@ gnc_quotes_get_quotable_commodities (const gnc_commodity_table * table)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_list_free (nslist);
|
|
||||||
regfree (&pattern);
|
regfree (&pattern);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "gnc-commodity.hpp"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-pricedb-p.h"
|
#include "gnc-pricedb-p.h"
|
||||||
#include "Scrub.h"
|
#include "Scrub.h"
|
||||||
@ -929,14 +930,6 @@ write_counts (FILE* out, ...)
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
|
||||||
compare_namespaces (gconstpointer a, gconstpointer b)
|
|
||||||
{
|
|
||||||
const gchar* sa = (const gchar*) a;
|
|
||||||
const gchar* sb = (const gchar*) b;
|
|
||||||
return (g_strcmp0 (sa, sb));
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
compare_commodity_ids (gconstpointer a, gconstpointer b)
|
compare_commodity_ids (gconstpointer a, gconstpointer b)
|
||||||
{
|
{
|
||||||
@ -1039,25 +1032,20 @@ gboolean
|
|||||||
write_commodities (FILE* out, QofBook* book, sixtp_gdv2* gd)
|
write_commodities (FILE* out, QofBook* book, sixtp_gdv2* gd)
|
||||||
{
|
{
|
||||||
gnc_commodity_table* tbl;
|
gnc_commodity_table* tbl;
|
||||||
GList* namespaces;
|
|
||||||
GList* lp;
|
|
||||||
gboolean success = TRUE;
|
gboolean success = TRUE;
|
||||||
|
|
||||||
tbl = gnc_commodity_table_get_table (book);
|
tbl = gnc_commodity_table_get_table (book);
|
||||||
|
|
||||||
namespaces = gnc_commodity_table_get_namespaces (tbl);
|
auto namespaces = gnc_commodity_table_get_namespaces (tbl);
|
||||||
if (namespaces)
|
|
||||||
{
|
|
||||||
namespaces = g_list_sort (namespaces, compare_namespaces);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (lp = namespaces; success && lp; lp = lp->next)
|
std::sort (namespaces.begin(), namespaces.end());
|
||||||
|
|
||||||
|
for (const auto& name_space : namespaces)
|
||||||
{
|
{
|
||||||
GList* comms, *lp2;
|
GList* comms, *lp2;
|
||||||
xmlNodePtr comnode;
|
xmlNodePtr comnode;
|
||||||
|
|
||||||
comms = gnc_commodity_table_get_commodities (tbl,
|
comms = gnc_commodity_table_get_commodities (tbl, name_space.c_str());
|
||||||
static_cast<const char*> (lp->data));
|
|
||||||
comms = g_list_sort (comms, compare_commodity_ids);
|
comms = g_list_sort (comms, compare_commodity_ids);
|
||||||
|
|
||||||
for (lp2 = comms; lp2; lp2 = lp2->next)
|
for (lp2 = comms; lp2; lp2 = lp2->next)
|
||||||
@ -1080,10 +1068,10 @@ write_commodities (FILE* out, QofBook* book, sixtp_gdv2* gd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (comms);
|
g_list_free (comms);
|
||||||
|
if (!success)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (namespaces) g_list_free (namespaces);
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1923,18 +1923,9 @@ gnc_commodity_table_has_namespace(const gnc_commodity_table * table,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
hash_keys_helper(gpointer key, gpointer value, gpointer data)
|
hash_keys_helper (const char* key, gnc_commodity* value, std::vector<std::string> *l)
|
||||||
{
|
{
|
||||||
auto l = (GList**)data;
|
l->push_back (key);
|
||||||
*l = g_list_prepend(*l, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GList *
|
|
||||||
g_hash_table_keys(GHashTable * table)
|
|
||||||
{
|
|
||||||
GList * l = nullptr;
|
|
||||||
g_hash_table_foreach(table, &hash_keys_helper, (gpointer) &l);
|
|
||||||
return l;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1957,13 +1948,15 @@ g_hash_table_values(GHashTable * table)
|
|||||||
* see if any commodities in the namespace exist
|
* see if any commodities in the namespace exist
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
GList *
|
std::vector<std::string>
|
||||||
gnc_commodity_table_get_namespaces(const gnc_commodity_table * table)
|
gnc_commodity_table_get_namespaces(const gnc_commodity_table * table)
|
||||||
{
|
{
|
||||||
|
std::vector<std::string> rv;
|
||||||
if (!table)
|
if (!table)
|
||||||
return nullptr;
|
return rv;
|
||||||
|
|
||||||
return g_hash_table_keys(table->ns_table);
|
g_hash_table_foreach(table->ns_table, (GHFunc)hash_keys_helper, &rv);
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
GList *
|
GList *
|
||||||
@ -2012,20 +2005,17 @@ gnc_commodity_is_currency(const gnc_commodity *cm)
|
|||||||
static CommodityList*
|
static CommodityList*
|
||||||
commodity_table_get_all_noncurrency_commodities(const gnc_commodity_table* table)
|
commodity_table_get_all_noncurrency_commodities(const gnc_commodity_table* table)
|
||||||
{
|
{
|
||||||
GList *node = nullptr, *nslist = gnc_commodity_table_get_namespaces(table);
|
CommodityList *retval = NULL;
|
||||||
CommodityList *retval = nullptr;
|
for (const auto& name_space : gnc_commodity_table_get_namespaces(table))
|
||||||
for (node = nslist; node; node=g_list_next(node))
|
|
||||||
{
|
{
|
||||||
gnc_commodity_namespace *ns = nullptr;
|
gnc_commodity_namespace *ns = NULL;
|
||||||
if (g_strcmp0((char*)(node->data), GNC_COMMODITY_NS_CURRENCY) == 0
|
if (name_space == GNC_COMMODITY_NS_CURRENCY || name_space == GNC_COMMODITY_NS_TEMPLATE)
|
||||||
|| g_strcmp0((char*)(node->data), GNC_COMMODITY_NS_TEMPLATE) == 0)
|
|
||||||
continue;
|
continue;
|
||||||
ns = gnc_commodity_table_find_namespace(table, (char*)(node->data));
|
ns = gnc_commodity_table_find_namespace(table, name_space.c_str());
|
||||||
if (!ns)
|
if (!ns)
|
||||||
continue;
|
continue;
|
||||||
retval = g_list_concat(g_hash_table_values(ns->cm_table), retval);
|
retval = g_list_concat(g_hash_table_values(ns->cm_table), retval);
|
||||||
}
|
}
|
||||||
g_list_free(nslist);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2079,8 +2069,6 @@ CommodityList *
|
|||||||
gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table)
|
gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table)
|
||||||
{
|
{
|
||||||
gnc_commodity_namespace * ns = nullptr;
|
gnc_commodity_namespace * ns = nullptr;
|
||||||
const char *name_space;
|
|
||||||
GList * nslist, * tmp;
|
|
||||||
GList * l = nullptr;
|
GList * l = nullptr;
|
||||||
regex_t pattern;
|
regex_t pattern;
|
||||||
const char *expression = gnc_prefs_get_namespace_regexp();
|
const char *expression = gnc_prefs_get_namespace_regexp();
|
||||||
@ -2097,11 +2085,10 @@ gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
nslist = gnc_commodity_table_get_namespaces(table);
|
for (const auto& name_space_str : gnc_commodity_table_get_namespaces(table))
|
||||||
for (tmp = nslist; tmp; tmp = tmp->next)
|
|
||||||
{
|
{
|
||||||
name_space = static_cast<const char*>(tmp->data);
|
auto name_space = name_space_str.c_str();
|
||||||
if (regexec(&pattern, name_space, 0, nullptr, 0) == 0)
|
if (regexec(&pattern, name_space, 0, NULL, 0) == 0)
|
||||||
{
|
{
|
||||||
DEBUG("Running list of %s commodities", name_space);
|
DEBUG("Running list of %s commodities", name_space);
|
||||||
ns = gnc_commodity_table_find_namespace(table, name_space);
|
ns = gnc_commodity_table_find_namespace(table, name_space);
|
||||||
@ -2111,7 +2098,6 @@ gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_list_free(nslist);
|
|
||||||
regfree(&pattern);
|
regfree(&pattern);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -829,15 +829,6 @@ GList * gnc_commodity_namespace_get_commodity_list(const gnc_commodity_namespace
|
|||||||
int gnc_commodity_table_has_namespace(const gnc_commodity_table * table,
|
int gnc_commodity_table_has_namespace(const gnc_commodity_table * table,
|
||||||
const char * commodity_namespace);
|
const char * commodity_namespace);
|
||||||
|
|
||||||
/** Return a list of all namespaces in the commodity table. This
|
|
||||||
* returns both system and user defined namespaces.
|
|
||||||
*
|
|
||||||
* @return A pointer to the list of names. NULL if an invalid
|
|
||||||
* argument was supplied.
|
|
||||||
*
|
|
||||||
* @note It is the callers responsibility to free the list. */
|
|
||||||
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table * t);
|
|
||||||
|
|
||||||
/** Return a list of all namespace data structures in the commodity table. This
|
/** Return a list of all namespace data structures in the commodity table. This
|
||||||
* returns both system and user defined namespace structures.
|
* returns both system and user defined namespace structures.
|
||||||
*
|
*
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#define GNC_COMMODITY_HPP
|
#define GNC_COMMODITY_HPP
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <gnc-commodity.h>
|
#include <gnc-commodity.h>
|
||||||
|
|
||||||
@ -51,6 +52,14 @@ using CommVec = std::vector<gnc_commodity*>;
|
|||||||
void gnc_quote_source_set_fq_installed (const char* version_string,
|
void gnc_quote_source_set_fq_installed (const char* version_string,
|
||||||
const std::vector<std::string>& sources_list);
|
const std::vector<std::string>& sources_list);
|
||||||
|
|
||||||
|
|
||||||
|
/** Return a list of all namespaces in the commodity table. This
|
||||||
|
* returns both system and user defined namespaces.
|
||||||
|
*
|
||||||
|
* @return A vector to the list of names. An empty vector if an
|
||||||
|
* invalid argument was supplied. */
|
||||||
|
std::vector<std::string> gnc_commodity_table_get_namespaces (const gnc_commodity_table * t);
|
||||||
|
|
||||||
#endif /* GNC_COMMODITY_HPP */
|
#endif /* GNC_COMMODITY_HPP */
|
||||||
/** @} */
|
/** @} */
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#include "kvp-frame.hpp"
|
#include "kvp-frame.hpp"
|
||||||
#include "qofbookslots.h"
|
#include "qofbookslots.h"
|
||||||
#include "guid.hpp"
|
#include "guid.hpp"
|
||||||
|
#include "gnc-commodity.hpp"
|
||||||
#include "gnc-optiondb.h"
|
#include "gnc-optiondb.h"
|
||||||
#include "gnc-optiondb.hpp"
|
#include "gnc-optiondb.hpp"
|
||||||
#include "gnc-optiondb-impl.hpp"
|
#include "gnc-optiondb-impl.hpp"
|
||||||
@ -693,13 +694,9 @@ gnc_register_commodity_option(GncOptionDB* db, const char* section,
|
|||||||
gnc_commodity* commodity{};
|
gnc_commodity* commodity{};
|
||||||
const auto book{qof_session_get_book(gnc_get_current_session())};
|
const auto book{qof_session_get_book(gnc_get_current_session())};
|
||||||
const auto commodity_table{gnc_commodity_table_get_table(book)};
|
const auto commodity_table{gnc_commodity_table_get_table(book)};
|
||||||
const auto namespaces{gnc_commodity_table_get_namespaces(commodity_table)};
|
for (const auto& name_space : gnc_commodity_table_get_namespaces(commodity_table))
|
||||||
for (auto node = namespaces; node && commodity == nullptr;
|
|
||||||
node = g_list_next(node))
|
|
||||||
{
|
{
|
||||||
commodity = gnc_commodity_table_lookup(commodity_table,
|
commodity = gnc_commodity_table_lookup(commodity_table, name_space.c_str(), value);
|
||||||
(const char*)(node->data),
|
|
||||||
value);
|
|
||||||
if (commodity)
|
if (commodity)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -707,7 +704,6 @@ gnc_register_commodity_option(GncOptionDB* db, const char* section,
|
|||||||
commodity,
|
commodity,
|
||||||
GncOptionUIType::COMMODITY}};
|
GncOptionUIType::COMMODITY}};
|
||||||
db->register_option(section, std::move(option));
|
db->register_option(section, std::move(option));
|
||||||
g_list_free (namespaces);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
|
|
||||||
#include "Account.h"
|
#include "Account.h"
|
||||||
#include "AccountP.hpp"
|
#include "AccountP.hpp"
|
||||||
|
#include "gnc-commodity.hpp"
|
||||||
#include "gnc-engine.h"
|
#include "gnc-engine.h"
|
||||||
#include "gnc-session.h"
|
#include "gnc-session.h"
|
||||||
#include "Transaction.h"
|
#include "Transaction.h"
|
||||||
@ -446,21 +447,19 @@ get_random_commodity_namespace(void)
|
|||||||
static gnc_commodity *
|
static gnc_commodity *
|
||||||
get_random_commodity_from_table (gnc_commodity_table *table)
|
get_random_commodity_from_table (gnc_commodity_table *table)
|
||||||
{
|
{
|
||||||
GList *namespaces;
|
|
||||||
gnc_commodity *com = NULL;
|
gnc_commodity *com = NULL;
|
||||||
|
|
||||||
g_return_val_if_fail (table, NULL);
|
g_return_val_if_fail (table, NULL);
|
||||||
|
|
||||||
namespaces = gnc_commodity_table_get_namespaces (table);
|
auto namespaces = gnc_commodity_table_get_namespaces (table);
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
GList *commodities;
|
GList *commodities;
|
||||||
char *name_space;
|
|
||||||
|
|
||||||
name_space = static_cast<char*>(get_random_list_element (namespaces));
|
auto name_space = namespaces.at (get_random_int_in_range (0, namespaces.size() - 1));
|
||||||
|
|
||||||
commodities = gnc_commodity_table_get_commodities (table, name_space);
|
commodities = gnc_commodity_table_get_commodities (table, name_space.c_str());
|
||||||
if (!commodities)
|
if (!commodities)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -471,9 +470,6 @@ get_random_commodity_from_table (gnc_commodity_table *table)
|
|||||||
}
|
}
|
||||||
while (!com);
|
while (!com);
|
||||||
|
|
||||||
|
|
||||||
g_list_free (namespaces);
|
|
||||||
|
|
||||||
return com;
|
return com;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,16 +553,13 @@ make_random_changes_to_commodity (gnc_commodity *com)
|
|||||||
void
|
void
|
||||||
make_random_changes_to_commodity_table (gnc_commodity_table *table)
|
make_random_changes_to_commodity_table (gnc_commodity_table *table)
|
||||||
{
|
{
|
||||||
GList *namespaces;
|
|
||||||
GList *node;
|
|
||||||
|
|
||||||
g_return_if_fail (table);
|
g_return_if_fail (table);
|
||||||
|
|
||||||
namespaces = gnc_commodity_table_get_namespaces (table);
|
auto namespaces = gnc_commodity_table_get_namespaces (table);
|
||||||
|
|
||||||
for (node = namespaces; node; node = node->next)
|
for (const auto& ns_str : namespaces)
|
||||||
{
|
{
|
||||||
auto ns = static_cast<const char *>(node->data);
|
auto ns = ns_str.c_str();
|
||||||
GList *commodities;
|
GList *commodities;
|
||||||
GList *com_node;
|
GList *com_node;
|
||||||
|
|
||||||
@ -586,8 +579,6 @@ make_random_changes_to_commodity_table (gnc_commodity_table *table)
|
|||||||
|
|
||||||
g_list_free (commodities);
|
g_list_free (commodities);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_free (namespaces);
|
|
||||||
}
|
}
|
||||||
/* ================================================================= */
|
/* ================================================================= */
|
||||||
/* Price stuff */
|
/* Price stuff */
|
||||||
|
Loading…
Reference in New Issue
Block a user