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.
pull/892/head
Geert Janssens 5 years ago committed by John Ralls
parent 4c2863966b
commit 70ab8a8a46

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

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

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

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

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

Loading…
Cancel
Save