Various changes to comments in source files and displayed text.

This commit is contained in:
Robert Fewell 2017-12-01 11:49:28 +00:00
parent 1bb2d1dc38
commit 61f860bcfc
5 changed files with 40 additions and 36 deletions

View File

@ -434,7 +434,7 @@ GtkTreeModel *get_model (bool all_commodity)
/* Hide the template entry */
if (g_utf8_collate (tmp_namespace, "template" ) != 0)
{
if ((g_utf8_collate (tmp_namespace, GNC_COMMODITY_NS_CURRENCY ) == 0) || (all_commodity == true))
if ((g_utf8_collate (tmp_namespace, GNC_COMMODITY_NS_CURRENCY ) == 0) || (all_commodity == true))
{
commodity_list = gnc_commodity_table_get_commodities (commodity_table, tmp_namespace);
commodity_list = g_list_first (commodity_list);
@ -1727,10 +1727,10 @@ CsvImpPriceAssist::assist_summary_page_prepare ()
{
auto text = std::string("<span size=\"medium\"><b>");
text += _("The prices were imported from the file '") + m_file_name + "'.";
text += _("\n\nThe number of Prices added was ") + std::to_string(price_imp->m_prices_added);
text += _(", duplicated was ") + std::to_string(price_imp->m_prices_duplicated);
text += _(" and replaced was ") + std::to_string(price_imp->m_prices_replaced);
text += ".</b></span>";
text += _("\n\nThere were ") + std::to_string(price_imp->m_prices_added);
text += _(" Prices added, ") + std::to_string(price_imp->m_prices_duplicated);
text += _(" duplicated and ") + std::to_string(price_imp->m_prices_replaced);
text += _(" replaced.</b></span>");
gtk_label_set_markup (GTK_LABEL(summary_label), text.c_str());
}

View File

@ -43,21 +43,27 @@
<signal name="apply" handler="csv_price_imp_assist_finish_cb" swapped="no"/>
<signal name="prepare" handler="csv_price_imp_assist_prepare_cb" swapped="no"/>
<signal name="cancel" handler="csv_price_imp_assist_cancel_cb" swapped="no"/>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="start_page">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">This assistant will help you import Prices from a CSV file.
There is a minimum number of columns that have to be present for a successful import, for Stock prices these are Date, Amount, Symbol From and for Currency they are Date, Amount, Currency From and Currency To.
There is a minimum number of columns that have to be present for a successful import, these are Date, Amount, Commodity From and Currency To. If all entries are for the same Commodity / Currency then you can select them and then the columns will be Date and Amount.
Various options exist for specifying the delimiter as well as a fixed width option. With the fixed width option, double click on the bar above the displayed rows to set the column width.
Various options exist for specifying the delimiter as well as a fixed width option. With the fixed width option, double click on the table of rows displayed to set a column width, then right mouse to change if required.
Examples are "RR.L","21/11/2016",5.345,"GBP" and "USD","2016-11-21",1.56,"GBP"
There is an option for specifying the start row, end row and an option to skip alternate rows beginning from the start row which can be used if you have some header text. Also there is an option to over write existing prices for that day if required.
On the preview page you can Load and Save the settings. To save the settings, select a previously saved entry or replace the text and press the Save Settings button.
Lastly, for repeated imports the preview page has buttons to Load and Save the settings. To save the settings, tweak the settings to your preferences (optionally starting from an existing preset), then (optionally change the settings name and press the Save Settings button. Note you can't save to built-in presets.
This operation is not reversable, so make sure you have a working backup.
@ -536,6 +542,7 @@ Select location and file name for the Import, then click 'OK'...
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Normally prices are not over written, select this to change that. This setting is not saved.</property>
<property name="focus_on_click">False</property>
<property name="draw_indicator">True</property>
<signal name="toggled" handler="csv_price_imp_preview_overwrite_cb" swapped="no"/>
</object>
@ -1094,8 +1101,9 @@ For example
<object class="GtkLabel" id="finish_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Press Apply to add Prices.
Cancel to abort.</property>
<property name="label" translatable="yes">&lt;b&gt;Press Apply to add the Prices.
Cancel to abort.&lt;/b&gt;</property>
<property name="use_markup">True</property>
<property name="justify">center</property>
<property name="wrap">True</property>
</object>

View File

@ -62,7 +62,7 @@ const gchar* currency_format_user_price[] = {N_("Locale"),
/** Constructor for GncPriceImport.
* @return Pointer to a new GncCSvParseData
* @return Pointer to a new GncCsvParseData
*/
GncPriceImport::GncPriceImport(GncImpFileFormat format)
{
@ -142,7 +142,7 @@ bool GncPriceImport::over_write () { return m_over_write; }
/** Sets a from commodity. This is the commodity all import data relates to.
* When a from commodity is set, there can't be any from columns selected
* in the import data.
* @param from_commodity Pointer to a commodity or NULL.
* @param from_commodity pointer to a commodity or NULL.
*/
void GncPriceImport::from_commodity (gnc_commodity* from_commodity)
{
@ -164,7 +164,7 @@ gnc_commodity *GncPriceImport::from_commodity () { return m_settings.m_from_comm
/** Sets a to currency. This is the to currency all import data relates to.
* When a to currency is set, there can't be any to currency columns selected
* in the import data.
* @param to_currency Pointer to a commodity or NULL.
* @param to_currency pointer to a commodity or NULL.
*/
void GncPriceImport::to_currency (gnc_commodity* to_currency)
{
@ -221,7 +221,6 @@ int GncPriceImport::date_format () { return m_settings.m_date_format; }
*/
void GncPriceImport::encoding (const std::string& encoding)
{
// TODO investigate if we can catch conversion errors and report them
if (m_tokenizer)
{
@ -309,12 +308,10 @@ void GncPriceImport::settings (const CsvTransSettings& settings)
std::copy_n (settings.m_column_types_price.begin(),
std::min (m_settings.m_column_types_price.size(), settings.m_column_types_price.size()),
m_settings.m_column_types_price.begin());
}
bool GncPriceImport::save_settings ()
{
if (trans_preset_is_reserved_name (m_settings.m_name))
return true;
@ -327,7 +324,6 @@ bool GncPriceImport::save_settings ()
auto fwtok = dynamic_cast<GncFwTokenizer*>(m_tokenizer.get());
m_settings.m_column_widths = fwtok->get_columns();
}
return m_settings.save();
}
@ -342,7 +338,6 @@ std::string GncPriceImport::settings_name () { return m_settings.m_name; }
*/
void GncPriceImport::load_file (const std::string& filename)
{
/* Get the raw data first and handle an error if one occurs. */
try
{
@ -407,7 +402,6 @@ void GncPriceImport::tokenize (bool guessColTypes)
}
}
struct ErrorListPrice
{
public:
@ -428,7 +422,6 @@ std::string ErrorListPrice::str()
return m_error.substr(0, m_error.size() - 1);
}
/* Test for the required minimum number of columns selected and
* the selection is consistent.
* @param An ErrorListPrice object to which all found issues are added.
@ -450,7 +443,7 @@ void GncPriceImport::verify_column_selections (ErrorListPrice& error_msg)
if (!check_for_column_type(GncPricePropType::TO_CURRENCY))
{
if (!m_settings.m_to_currency)
error_msg.add_error( _("Please select a Currency to column or set a Currency in the Currency To field."));
error_msg.add_error( _("Please select a 'Currency to' column or set a Currency in the 'Currency To' field."));
}
/* Verify a Commodity from column is selected.
@ -458,11 +451,10 @@ void GncPriceImport::verify_column_selections (ErrorListPrice& error_msg)
if (!check_for_column_type(GncPricePropType::FROM_COMMODITY))
{
if (!m_settings.m_from_commodity)
error_msg.add_error( _("Please select a Commodity from column or set a Commodity in the Commodity From field."));
error_msg.add_error( _("Please select a 'Commodity from' column or set a Commodity in the 'Commodity From' field."));
}
}
/* Check whether the chosen settings can successfully parse
* the import data. This will check:
* - there's at least one line selected for import
@ -547,7 +539,7 @@ void GncPriceImport::create_price (std::vector<parse_line_t>::iterator& parsed_l
error_message.clear();
// Add a CURRENCY_TO property with the default currency to if no currency to column was set by the user
// Add a CURRENCY_TO property with the selected 'currency to' if no 'currency to' column was set by the user
auto line_to_currency = price_props->get_to_currency();
if (!line_to_currency)
{
@ -555,16 +547,16 @@ void GncPriceImport::create_price (std::vector<parse_line_t>::iterator& parsed_l
price_props->set_to_currency(m_settings.m_to_currency);
else
{
// Oops - the user didn't select an Account column *and* we didn't get a default value either!
// Oops - the user didn't select a 'currency to' column *and* we didn't get a selected value either!
// Note if you get here this suggests a bug in the code!
error_message = _("No Currency to column selected and no default Currency specified either.\n"
error_message = _("No 'Currency to' column selected and no selected Currency specified either.\n"
"This should never happen. Please report this as a bug.");
PINFO("User warning: %s", error_message.c_str());
throw std::invalid_argument(error_message);
}
}
// Add a COMMODITY_FROM property with the default commodity from if no commodity from column was set by the user
// Add a COMMODITY_FROM property with the selected 'commodity from' if no 'commodity from' column was set by the user
auto line_from_commodity = price_props->get_from_commodity();
if (!line_from_commodity)
{
@ -572,9 +564,9 @@ void GncPriceImport::create_price (std::vector<parse_line_t>::iterator& parsed_l
price_props->set_from_commodity(m_settings.m_from_commodity);
else
{
// Oops - the user didn't select an Account column *and* we didn't get a default value either!
// Oops - the user didn't select a 'commodity from' column *and* we didn't get a selected value either!
// Note if you get here this suggests a bug in the code!
error_message = _("No Commodity from column selected and no default Commodity specified either.\n"
error_message = _("No 'Commodity from' column selected and no selected Commodity specified either.\n"
"This should never happen. Please report this as a bug.");
PINFO("User warning: %s", error_message.c_str());
throw std::invalid_argument(error_message);
@ -605,7 +597,6 @@ void GncPriceImport::create_price (std::vector<parse_line_t>::iterator& parsed_l
}
}
/** Creates a list of prices from parsed data. The parsed data
* will first be validated. If any errors are found in lines that are marked
* for processing (ie not marked to skip) this function will
@ -697,11 +688,11 @@ GncPriceImport::set_column_type_price (uint32_t position, GncPricePropType type,
m_settings.m_column_types_price.at (position) = type;
// If the user has set a Commodity from column, we can't have a commodity from default set
// If the user has set a 'commodity from' column, we can't have a commodity from selected
if (type == GncPricePropType::FROM_COMMODITY)
from_commodity (nullptr);
// If the user has set a Currency to column, we can't have a currency to default set
// If the user has set a 'currency to' column, we can't have a currency to selected
if (type == GncPricePropType::TO_CURRENCY)
to_currency (nullptr);

View File

@ -160,7 +160,7 @@ time64 parse_date_price (const std::string &date_str, int format)
}
/** Convert str into a GncRational using the user-specified (import) currency format.
/** Convert str into a GncNumeric using the user-specified (import) currency format.
* @param str The string to be parsed
* @param currency_format The currency format to use.
* @return a GncNumeric
@ -200,6 +200,11 @@ GncNumeric parse_amount_price (const std::string &str, int currency_format)
return GncNumeric(val);
}
/** Convert comm_str into a gnc_commodity.
* @param comm_str The string to be parsed
* @return a gnc_commodity
* @exception May throw std::invalid argument if string can't be parsed properly
*/
gnc_commodity* parse_commodity_price_comm (const std::string& comm_str)
{
if (comm_str.empty())
@ -324,9 +329,9 @@ std::string GncImportPrice::verify_essentials (void)
else if (m_amount == boost::none)
return _("No amount column.");
else if (m_to_currency == boost::none)
return _("No Currency to column.");
return _("No 'Currency to' column.");
else if (m_from_commodity == boost::none)
return _("No Commodity from column.");
return _("No 'Commodity from' column.");
else
return std::string();
}
@ -417,7 +422,6 @@ Result GncImportPrice::create_price (QofBook* book, GNCPriceDB *pdb, bool over)
if (perr == false)
throw std::invalid_argument (_("Failed to create price from selected columns."));
//FIXME Not sure about this, should this be a PWARN
}
else
{

View File

@ -90,6 +90,7 @@ public:
void set_date_format (int date_format) { m_date_format = date_format ;}
void set_currency_format (int currency_format) { m_currency_format = currency_format ;}
void reset (GncPricePropType prop_type);
std::string verify_essentials (void);
Result create_price (QofBook* book, GNCPriceDB *pdb, bool over);
gnc_commodity* get_from_commodity () { if (m_from_commodity) return *m_from_commodity; else return nullptr; }