GncQuotes - drop parameterized constructor

The book parameter is only needed while fetching quotes.
In case the user passes one or more commodities to process
the book can be readily derived from the commodity/commodities.
In the other case (fetch all quotes) the user now is
required to pass a book to the call.
This commit is contained in:
Geert Janssens 2021-03-18 19:12:23 +01:00 committed by John Ralls
parent 4c2863966b
commit 70ab8a8a46
5 changed files with 23 additions and 32 deletions

View File

@ -1785,7 +1785,7 @@ gnc_xfer_dialog_fetch (GtkButton *button, XferDialog *xferData)
ENTER(" ");
GncQuotes quotes (xferData->book);
GncQuotes quotes;
if (quotes.cmd_result() != 0)
{
if (!quotes.error_msg().empty())
@ -1795,7 +1795,7 @@ gnc_xfer_dialog_fetch (GtkButton *button, XferDialog *xferData)
}
gnc_set_busy_cursor (nullptr, TRUE);
quotes.fetch();
quotes.fetch (xferData->book);
gnc_unset_busy_cursor (nullptr);
/*the results should be in the price db now, but don't crash if not. */

View File

@ -559,7 +559,7 @@ gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
auto pdb_dialog = static_cast<PricesDialog *> (data);
ENTER(" ");
GncQuotes quotes (pdb_dialog->book);
GncQuotes quotes;
if (quotes.cmd_result() != 0)
{
if (!quotes.error_msg().empty())
@ -569,7 +569,7 @@ gnc_prices_dialog_get_quotes_clicked (GtkWidget *widget, gpointer data)
}
gnc_set_busy_cursor (NULL, TRUE);
quotes.fetch();
quotes.fetch (pdb_dialog->book);
gnc_unset_busy_cursor (NULL);
/* Without this, the summary bar on the accounts tab

View File

@ -341,7 +341,7 @@ Gnucash::add_quotes (const bo_str& uri)
if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
cleanup_and_exit_with_failure (session);
GncQuotes quotes (qof_session_get_book(session));
GncQuotes quotes;
if (quotes.cmd_result() == 0)
{
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << std::endl;
@ -356,7 +356,7 @@ Gnucash::add_quotes (const bo_str& uri)
std::cerr << bl::translate ("Error message:") << std::endl;
std::cerr << quotes.error_msg() << std::endl;
}
quotes.fetch ();
quotes.fetch (qof_session_get_book(session));
qof_session_save(session, NULL);
if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)

View File

@ -66,7 +66,7 @@ public:
GncQuotesImpl ();
GncQuotesImpl (QofBook *book);
void fetch ();
void fetch (QofBook *book);
void fetch (CommVec& commodities);
void fetch (gnc_commodity *comm);
@ -100,23 +100,12 @@ private:
/* GncQuotes implementation */
GncQuotesImpl::GncQuotesImpl ()
{
check (nullptr);
}
GncQuotesImpl::GncQuotesImpl (QofBook *book)
{
check (book);
}
void
GncQuotesImpl::check (QofBook *book)
{
m_version.clear();
m_sources.clear();
m_error_msg.clear();
m_cmd_result = 0;
m_book = book;
m_book = nullptr;
m_dflt_curr = gnc_default_currency();
auto perl_executable = bp::search_path("perl");
@ -151,7 +140,11 @@ GncQuotesImpl::sources_as_glist()
void
GncQuotesImpl::fetch (CommVec& commodities)
{
if (commodities.empty())
return;
m_comm_vec = std::move (commodities); // Store for later use
m_book = qof_instance_get_book (m_comm_vec[0]);
bpt::ptree pt, pt_child;
pt.put ("defaultcurrency", gnc_commodity_get_mnemonic (m_dflt_curr));
@ -206,11 +199,16 @@ GncQuotesImpl::fetch (CommVec& commodities)
void
GncQuotesImpl::fetch ()
GncQuotesImpl::fetch (QofBook *book)
{
if (!book)
{
m_cmd_result = 1;
m_error_msg = "No book set\n";
return;
}
auto commodities = gnc_quotes_get_quotable_commodities (
gnc_commodity_table_get_table (m_book));
gnc_commodity_table_get_table (book));
fetch (commodities);
}
@ -219,7 +217,6 @@ void
GncQuotesImpl::fetch (gnc_commodity *comm)
{
auto commodities = CommVec {comm};
fetch (commodities);
}
@ -533,15 +530,10 @@ GncQuotes::GncQuotes ()
m_impl = std::make_unique<GncQuotesImpl> ();
}
GncQuotes::GncQuotes (QofBook *book)
{
m_impl = std::make_unique<GncQuotesImpl> (book);
}
void
GncQuotes::fetch (void)
GncQuotes::fetch (QofBook *book)
{
m_impl->fetch ();
m_impl->fetch (book);
}
void GncQuotes::fetch (CommVec& commodities)

View File

@ -45,11 +45,10 @@ class GncQuotes
public:
// Constructor - checks for presence of Finance::Quote and import version and quote sources
GncQuotes ();
GncQuotes (QofBook *book);
~GncQuotes ();
// Fetch quotes for all commodities in our db that have a quote source set
void fetch (void);
void fetch (QofBook *book);
// Only fetch quotes for the commodities passed that have a quote source set
void fetch (CommVec& commodities);
// Fetch quote for the commodity if it has a quote source set