[gnc-commodity.cpp] gnc_quote_source_set_fq_installed takes a StrVec

instead of a GList* of strdup'd chars
This commit is contained in:
Christopher Lam 2024-02-12 10:40:11 +08:00
parent 47a1a56f16
commit 346499ae04
6 changed files with 21 additions and 27 deletions

View File

@ -361,9 +361,8 @@ Gnucash::add_quotes (const bo_str& uri)
{
GncQuotes quotes;
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << std::endl;
auto quote_sources = quotes.sources_as_glist();
auto quote_sources = quotes.sources();
gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
g_list_free_full (quote_sources, g_free);
quotes.fetch(qof_session_get_book(session));
if (quotes.had_failures())
std::cerr << quotes.report_failures() << std::endl;

View File

@ -178,9 +178,8 @@ scm_run_gnucash (void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **
gnc_update_splash_screen (checking, GNC_SPLASH_PERCENTAGE_UNKNOWN);
GncQuotes quotes;
auto found = (bl::format (std::string{_("Found Finance::Quote version {1}.")}) % quotes.version()).str();
auto quote_sources = quotes.sources_as_glist();
auto quote_sources = quotes.sources();
gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
g_list_free_full (quote_sources, g_free);
gnc_update_splash_screen (found.c_str(), GNC_SPLASH_PERCENTAGE_UNKNOWN);
}
catch (const GncQuoteException& err)

View File

@ -127,9 +127,8 @@ protected:
gnc_commodity_set_quote_source(fkcm, source);
gnc_commodity_commit_edit(fkcm);
gnc_commodity_table_insert(comm_table, fkcm);
GList *sources = g_list_prepend(nullptr, (void*)"alphavantage");
std::vector<std::string> sources = {"alphavantage"};
gnc_quote_source_set_fq_installed("TestSuite", sources);
g_list_free(sources);
}
~GncQuotesTest() {
gnc_clear_current_session();

View File

@ -35,6 +35,7 @@
#include <regex.h>
#include <qofinstance-p.h>
#include "gnc-commodity.hpp"
#include "gnc-commodity.h"
#include "gnc-locale-utils.h"
#include "gnc-prefs.h"
@ -537,15 +538,11 @@ gnc_quote_source_get_internal_name (const gnc_quote_source *source)
********************************************************************/
void
gnc_quote_source_set_fq_installed (const char* version_string,
const GList *sources_list)
const std::vector<std::string>& sources_list)
{
gnc_quote_source *source;
char *source_name;
const GList *node;
ENTER(" ");
if (!sources_list)
if (sources_list.empty())
return;
if (version_string)
@ -553,11 +550,11 @@ gnc_quote_source_set_fq_installed (const char* version_string,
else
fq_version.clear();
for (node = sources_list; node; node = node->next)
for (const auto& source_name_str : sources_list)
{
source_name = static_cast<char*>(node->data);
auto source_name = source_name_str.c_str();
auto source = gnc_quote_source_lookup_by_internal(source_name);
source = gnc_quote_source_lookup_by_internal(source_name);
if (source != NULL)
{
DEBUG("Found source %s: %s", source_name, source->user_name);

View File

@ -158,18 +158,6 @@ gboolean gnc_quote_source_fq_installed (void);
*/
const char* gnc_quote_source_fq_version (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 (const char* version_string,
const 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.

View File

@ -39,6 +39,18 @@
using CommVec = std::vector<gnc_commodity*>;
/** 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 (const char* version_string,
const std::vector<std::string>& sources_list);
#endif /* GNC_COMMODITY_HPP */
/** @} */
/** @} */