mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
GncQuotes - add parameterized construction
For all but the basic check a book is required. Might as well be able to pass it directly and store a reference to it. That will simplify member function declarations.
This commit is contained in:
parent
3685e5de73
commit
65ae46426b
@ -82,22 +82,6 @@ scm_add_quotes(void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **ar
|
||||
gnc_prefs_init ();
|
||||
qof_event_suspend();
|
||||
|
||||
GncQuotes quotes;
|
||||
if (quotes.cmd_result() == 0)
|
||||
{
|
||||
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << std::endl;
|
||||
auto quote_sources = quotes.sources_as_glist();
|
||||
gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
|
||||
g_list_free_full (quote_sources, g_free);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << bl::translate ("No quotes retrieved. Finance::Quote isn't "
|
||||
"installed properly.") << "\n";
|
||||
std::cerr << bl::translate ("Error message:") << std::endl;
|
||||
std::cerr << quotes.error_msg() << std::endl;
|
||||
}
|
||||
|
||||
scm_c_eval_string("(debug-set! stack 200000)");
|
||||
|
||||
auto mod = scm_c_resolve_module("gnucash price-quotes");
|
||||
@ -116,6 +100,22 @@ scm_add_quotes(void *data, [[maybe_unused]] int argc, [[maybe_unused]] char **ar
|
||||
if (qof_session_get_error(session) != ERR_BACKEND_NO_ERR)
|
||||
scm_cleanup_and_exit_with_failure (session);
|
||||
|
||||
GncQuotes quotes (qof_session_get_book(session));
|
||||
if (quotes.cmd_result() == 0)
|
||||
{
|
||||
std::cout << bl::format (bl::translate ("Found Finance::Quote version {1}.")) % quotes.version() << std::endl;
|
||||
auto quote_sources = quotes.sources_as_glist();
|
||||
gnc_quote_source_set_fq_installed (quotes.version().c_str(), quote_sources);
|
||||
g_list_free_full (quote_sources, g_free);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << bl::translate ("No quotes retrieved. Finance::Quote isn't "
|
||||
"installed properly.") << "\n";
|
||||
std::cerr << bl::translate ("Error message:") << std::endl;
|
||||
std::cerr << quotes.error_msg() << std::endl;
|
||||
}
|
||||
|
||||
auto scm_book = gnc_book_to_scm(qof_session_get_book(session));
|
||||
auto scm_result = scm_call_2(add_quotes, SCM_BOOL_F, scm_book);
|
||||
|
||||
|
@ -55,18 +55,24 @@ namespace bio = boost::iostreams;
|
||||
CommVec
|
||||
gnc_quotes_get_quotable_commodities(const gnc_commodity_table * table);
|
||||
|
||||
GncQuotes::GncQuotes()
|
||||
GncQuotes::GncQuotes ()
|
||||
{
|
||||
check();
|
||||
check (nullptr);
|
||||
}
|
||||
|
||||
GncQuotes::GncQuotes (QofBook *book)
|
||||
{
|
||||
check (book);
|
||||
}
|
||||
|
||||
void
|
||||
GncQuotes::check (void)
|
||||
GncQuotes::check (QofBook *book)
|
||||
{
|
||||
m_version.clear();
|
||||
m_sources.clear();
|
||||
m_error_msg.clear();
|
||||
m_cmd_result = 0;
|
||||
m_book = book;
|
||||
|
||||
auto perl_executable = bp::search_path("perl");
|
||||
auto fq_check = std::string(gnc_path_get_bindir()) + "/gnc-fq-check";
|
||||
@ -121,7 +127,6 @@ GncQuotes::fetch (const CommVec& commodities)
|
||||
auto key = comm_ns + "." + comm_mnemonic;
|
||||
pt.put (key, "");
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
std::ostringstream result;
|
||||
@ -132,10 +137,10 @@ GncQuotes::fetch (const CommVec& commodities)
|
||||
|
||||
|
||||
void
|
||||
GncQuotes::fetch_all (QofBook *book)
|
||||
GncQuotes::fetch_all ()
|
||||
{
|
||||
auto commodities = gnc_quotes_get_quotable_commodities (
|
||||
gnc_commodity_table_get_table (book));
|
||||
gnc_commodity_table_get_table (m_book));
|
||||
|
||||
fetch (commodities);
|
||||
}
|
||||
|
@ -42,9 +42,11 @@ class GncQuotes
|
||||
{
|
||||
public:
|
||||
// Constructor - checks for presence of Finance::Quote and import version and quote sources
|
||||
GncQuotes();
|
||||
GncQuotes ();
|
||||
GncQuotes (QofBook *book);
|
||||
~GncQuotes () = default;
|
||||
|
||||
void fetch_all (QofBook *book);
|
||||
void fetch_all ();
|
||||
void fetch (const CommVec& commodities);
|
||||
|
||||
const int cmd_result() noexcept { return m_cmd_result; }
|
||||
@ -54,19 +56,23 @@ public:
|
||||
GList* sources_as_glist ();
|
||||
|
||||
private:
|
||||
GncQuotes () = delete;
|
||||
// Check if Finance::Quote is properly installed
|
||||
void check (void);
|
||||
void check (QofBook *book);
|
||||
// Run the command specified. Returns two vectors for further processing by the caller
|
||||
// - one with the contents of stdout
|
||||
// - one with the contents of stderr
|
||||
// Will also set m_cmd_result
|
||||
CmdOutput run_cmd (std::string cmd_name, StrVec args, StrVec input_vec);
|
||||
template <typename BufferT> CmdOutput run_cmd (std::string cmd_name, StrVec args, BufferT input_vec);
|
||||
|
||||
void parse_quotes (std::string);
|
||||
|
||||
|
||||
std::string m_version;
|
||||
QuoteSources m_sources;
|
||||
int m_cmd_result;
|
||||
std::string m_error_msg;
|
||||
QofBook *m_book;
|
||||
};
|
||||
|
||||
#endif /* GNC_QUOTES_HPP */
|
||||
|
Loading…
Reference in New Issue
Block a user