Skip to content

Commit

Permalink
[gnc-commodity.cpp] gnc_quote_source_set_fq_installed takes a StrVec
Browse files Browse the repository at this point in the history
instead of a GList* of strdup'd chars
  • Loading branch information
christopherlam committed Feb 17, 2024
1 parent 47a1a56 commit 346499a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 27 deletions.
3 changes: 1 addition & 2 deletions gnucash/gnucash-commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions gnucash/gnucash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions libgnucash/app-utils/test/gtest-gnc-quotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ class GncQuotesTest : public ::testing::Test
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();
Expand Down
15 changes: 6 additions & 9 deletions libgnucash/engine/gnc-commodity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -537,27 +538,23 @@ 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)
fq_version = 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);
Expand Down
12 changes: 0 additions & 12 deletions libgnucash/engine/gnc-commodity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions libgnucash/engine/gnc-commodity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/** @} */
/** @} */

0 comments on commit 346499a

Please sign in to comment.