[glom] ReportBuilder: Take a std::locale instead of a std::string locale name.



commit 0bcb5625e067f35c2d719fd2660dabbb323734e6
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Mar 5 20:09:33 2014 +0100

    ReportBuilder: Take a std::locale instead of a std::string locale name.
    
    * glom/libglom/data_structure/glomconversions.[h|cc]:
      Remove the recently-added get_text_for_gda_value() overload
      that took a ustring locale ID.
    * glom/libglom/report_builder.[h|cc]: Constructor: Take a
      std::locale instead of just a locale name, because we need the
      full locale (name) for use with get_text_for_gda_value().
      Use Utils::locale_simplify() to get the locale ID for use with
      translations.
      This means that we will ignore a temporarily-chosen translation,
      because we have no way to get the full locale name from the
      simpler currently-set locale ID, but that is not so bad.
    * glom/frame_glom.cc:
    * glom/mode_data/box_data_manyrecords.cc:
    * tests/test_selfhosting_new_then_report.cc:
    * tests/test_selfhosting_new_then_report_summary.cc: Adapted.

 glom/frame_glom.cc                                |    3 ++-
 glom/libglom/data_structure/glomconversions.cc    |    5 -----
 glom/libglom/data_structure/glomconversions.h     |    1 -
 glom/libglom/report_builder.cc                    |   15 ++++++++-------
 glom/libglom/report_builder.h                     |    6 ++++--
 glom/mode_data/box_data_manyrecords.cc            |    3 ++-
 tests/test_selfhosting_new_then_report.cc         |    2 +-
 tests/test_selfhosting_new_then_report_summary.cc |    2 +-
 8 files changed, 18 insertions(+), 19 deletions(-)
---
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 34177a4..082bfba 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -2422,7 +2422,8 @@ void Frame_Glom::on_menu_report_selected(const Glib::ustring& report_name)
 
   FoundSet found_set = m_Notebook_Data.get_found_set();
 
-  ReportBuilder report_builder(AppWindow::get_current_locale());
+  //TODO: Find a way to get a full locale name from the simplified locale name from 
AppWindow::get_current_locale():
+  ReportBuilder report_builder(std::locale("") /* the user's current locale */);
   report_builder.set_document(document);
   const std::string filepath = 
     report_builder.report_build_and_save(found_set, report); //TODO: Use found set's where_clause.
diff --git a/glom/libglom/data_structure/glomconversions.cc b/glom/libglom/data_structure/glomconversions.cc
index 7b4dbed..9a407ce 100644
--- a/glom/libglom/data_structure/glomconversions.cc
+++ b/glom/libglom/data_structure/glomconversions.cc
@@ -339,11 +339,6 @@ double Conversions::get_double_for_gda_value_numeric(const Gnome::Gda::Value& va
   return numeric.get_double();
 }
 
-Glib::ustring Conversions::get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& 
value, const Glib::ustring& locale, const NumericFormat& numeric_format, bool iso_format)
-{
-  return get_text_for_gda_value(glom_type, value, std::locale(locale.c_str()), numeric_format, iso_format);
-}
-
 Glib::ustring Conversions::get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& 
value, const std::locale& locale, const NumericFormat& numeric_format, bool iso_format)
 {
   if(value.is_null()) //The type can be null for any of the actual field types.
diff --git a/glom/libglom/data_structure/glomconversions.h b/glom/libglom/data_structure/glomconversions.h
index 88152bb..87e25b2 100644
--- a/glom/libglom/data_structure/glomconversions.h
+++ b/glom/libglom/data_structure/glomconversions.h
@@ -35,7 +35,6 @@ namespace Conversions
   ///Get text for display to the user.
   Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value, 
const NumericFormat& numeric_format = NumericFormat());
   Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value, 
const std::locale& locale, const NumericFormat& numeric_format = NumericFormat(), bool iso_format = false);
-  Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value, 
const Glib::ustring& locale, const NumericFormat& numeric_format = NumericFormat(), bool iso_format = false);
 
   //This is easier than using the GdaNumeric API,
   //which normally involves text-to-number parsing.
diff --git a/glom/libglom/report_builder.cc b/glom/libglom/report_builder.cc
index f19188e..5c13b3b 100644
--- a/glom/libglom/report_builder.cc
+++ b/glom/libglom/report_builder.cc
@@ -31,10 +31,11 @@
 namespace Glom
 {
 
-ReportBuilder::ReportBuilder(const Glib::ustring& locale)
+ReportBuilder::ReportBuilder(const std::locale& locale)
 : m_document(0),
   m_locale(locale)
 {
+  m_locale_id = Utils::locale_simplify(locale.name());
 }
 
 ReportBuilder::~ReportBuilder()
@@ -259,7 +260,7 @@ bool ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
         xmlpp::Element* nodeGroupBy = parent_node.add_child(group_by->get_report_part_id());
         XmlUtils::set_node_attribute_value_as_decimal_double(nodeGroupBy, "border_width", 
group_by->get_border_width());
 
-        nodeGroupBy->set_attribute("group_field", field_group_by->get_title_or_name(m_locale));
+        nodeGroupBy->set_attribute("group_field", field_group_by->get_title_or_name(m_locale_id));
         nodeGroupBy->set_attribute("group_value",
           Conversions::get_text_for_gda_value(field_group_by->get_glom_type(), group_value, m_locale, 
field_group_by->get_formatting_used().m_numeric_format) );
 
@@ -361,7 +362,7 @@ bool ReportBuilder::report_build_records(const FoundSet& found_set, xmlpp::Eleme
         nodeFieldHeading->set_attribute("field_type", "numeric"); //TODO: More sophisticated formatting.
 
       nodeFieldHeading->set_attribute("name", layout_item->get_name()); //Not really necessary, but maybe 
useful.
-      nodeFieldHeading->set_attribute("title", layout_item->get_title_or_name(m_locale));
+      nodeFieldHeading->set_attribute("title", layout_item->get_title_or_name(m_locale_id));
     }
 
     //Get list of fields to get from the database.
@@ -503,7 +504,7 @@ bool ReportBuilder::report_build_records_field(const FoundSet& found_set, xmlpp:
     value = datamodel->get_value_at(colField, row); //TODO: Catch exceptions.
   }
 
-  nodeField->set_attribute("title", field->get_title_or_name(m_locale)); //Not always used, but useful.
+  nodeField->set_attribute("title", field->get_title_or_name(m_locale_id)); //Not always used, but useful.
 
   //Handle the value:
   if(field_type == Field::TYPE_IMAGE)
@@ -532,7 +533,7 @@ bool ReportBuilder::report_build_records_text(const FoundSet& /* found_set */, x
 {
   //Text object:
   xmlpp::Element* nodeField = nodeParent.add_child(textobject->get_report_part_id()); //We reuse this node 
type for text objects.
-  nodeField->set_attribute("value", textobject->get_text(m_locale));
+  nodeField->set_attribute("value", textobject->get_text(m_locale_id));
 
   if(vertical)
     nodeField->set_attribute("vertical", "true");
@@ -663,7 +664,7 @@ Glib::ustring ReportBuilder::report_build(const FoundSet& found_set, const share
     nodeRoot = pDocument->create_root_node("report_print");
   }
 
-  Glib::ustring table_title = get_document()->get_table_title(found_set.m_table_name, m_locale);
+  Glib::ustring table_title = get_document()->get_table_title(found_set.m_table_name, m_locale_id);
   if(table_title.empty())
     table_title = found_set.m_table_name;
 
@@ -676,7 +677,7 @@ Glib::ustring ReportBuilder::report_build(const FoundSet& found_set, const share
   xmlpp::Element* nodeParent = nodeRoot;
 
 
-  nodeRoot->set_attribute("title", report->get_title_or_name(m_locale));
+  nodeRoot->set_attribute("title", report->get_title_or_name(m_locale_id));
 
   type_vecLayoutItems itemsToGet_TopLevel;
 
diff --git a/glom/libglom/report_builder.h b/glom/libglom/report_builder.h
index 4e1008b..d234194 100644
--- a/glom/libglom/report_builder.h
+++ b/glom/libglom/report_builder.h
@@ -35,7 +35,8 @@ namespace Glom
 class ReportBuilder
 {
 public:
-  explicit ReportBuilder(const Glib::ustring& locale);
+  explicit ReportBuilder(const std::locale& locale);
+
   virtual ~ReportBuilder();
 
   static sharedptr<Report> create_standard_list_report(const Document* document, const Glib::ustring& 
table_name);
@@ -78,7 +79,8 @@ private:
 
   Document* m_document;
 
-  Glib::ustring m_locale;
+  std::locale m_locale; //For use with GlomConversions
+  Glib::ustring m_locale_id; //To get the appropriate translations.
 };
 
 } //namespace Glom
diff --git a/glom/mode_data/box_data_manyrecords.cc b/glom/mode_data/box_data_manyrecords.cc
index 1b360c4..ba19aa3 100644
--- a/glom/mode_data/box_data_manyrecords.cc
+++ b/glom/mode_data/box_data_manyrecords.cc
@@ -87,7 +87,8 @@ void Box_Data_ManyRecords::print_layout()
     Document* document = get_document();
     sharedptr<Report> report_temp = ReportBuilder::create_standard_list_report(document, m_table_name);
 
-    ReportBuilder report_builder(AppWindow::get_current_locale());
+    //TODO: Find a way to get a full locale name from the simplified locale name from 
AppWindow::get_current_locale():
+    ReportBuilder report_builder(std::locale("") /* the user's current locale */);
     report_builder.set_document(document);
     const std::string filepath = 
       report_builder.report_build_and_save(m_found_set, report_temp);
diff --git a/tests/test_selfhosting_new_then_report.cc b/tests/test_selfhosting_new_then_report.cc
index 0d3953b..f0ed70f 100644
--- a/tests/test_selfhosting_new_then_report.cc
+++ b/tests/test_selfhosting_new_then_report.cc
@@ -43,7 +43,7 @@ static bool test(Glom::Document::HostingMode hosting_mode)
   Glom::FoundSet found_set; //TODO: Test a where clause.
   found_set.m_table_name = "albums";
 
-  const Glib::ustring locale = "en_US.UTF-8"; //Instead of just "" (current locale) so we get the same 
results each time.
+  const std::locale locale("en_US.UTF-8"); //Instead of just "" (current locale) so we get the same results 
each time.
   Glom::ReportBuilder report_builder(locale);
   report_builder.set_document(&document);
   const Glib::ustring html = 
diff --git a/tests/test_selfhosting_new_then_report_summary.cc 
b/tests/test_selfhosting_new_then_report_summary.cc
index 490606b..3842e40 100644
--- a/tests/test_selfhosting_new_then_report_summary.cc
+++ b/tests/test_selfhosting_new_then_report_summary.cc
@@ -48,7 +48,7 @@ static bool test(Glom::Document::HostingMode hosting_mode)
   Glom::FoundSet found_set; //TODO: Test a where clause.
   found_set.m_table_name = "invoices";
 
-  const Glib::ustring locale = "en_US.UTF-8"; //Instead of just "" (current locale) so we know what numeric 
representations to expect and check for.
+  const std::locale locale("en_US.UTF-8"); //Instead of just "" (current locale) so we know what numeric 
representations to expect and check for.
   Glom::ReportBuilder report_builder(locale);
   report_builder.set_document(&document);
   const Glib::ustring html = 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]