[glom] Document: Allow the database title to be translated.



commit 18ec008298f08dab8a744dbd52a10f552c58880b
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Jan 23 14:39:15 2012 +0100

    Document: Allow the database title to be translated.
    
    * glom/libglom/filelist.am:
    * glom/libglom/database_title.[h|cc]: Add this new TranslatableItem.
    * glom/libglom/document/document.[h|cc]: Use DatabaseTitle instead of just
    a string, and load/save it in the database.
    get_database_title(): Add a locale parameter and add
    get_database_title_original().
    * glom/application.cc:
    * glom/libglom/connectionpool.cc:
    * glom/libglom/data_structure/translatable_item.[h|cc]:
    * glom/libglom/db_utils.cc:
    * glom/libglom/example_document_load.cc:
    * glom/libglom/translations_po.cc:
    * tests/test_document_autosave.cc:
    * tests/test_document_change.cc:
    * tests/test_document_load.cc:
    * tests/test_document_load_translations.cc: Adapt.

 ChangeLog                                        |   21 ++++++++++++++
 glom/application.cc                              |    6 ++--
 glom/libglom/connectionpool.cc                   |    2 +-
 glom/libglom/data_structure/translatable_item.cc |    4 ++
 glom/libglom/data_structure/translatable_item.h  |    3 +-
 glom/libglom/db_utils.cc                         |    6 ++--
 glom/libglom/document/document.cc                |   33 ++++++++++++++++------
 glom/libglom/document/document.h                 |   10 ++++--
 glom/libglom/example_document_load.cc            |    2 +-
 glom/libglom/filelist.am                         |    2 +
 glom/libglom/translations_po.cc                  |    2 +-
 tests/test_document_autosave.cc                  |    8 ++--
 tests/test_document_change.cc                    |    4 +-
 tests/test_document_load.cc                      |    2 +-
 tests/test_document_load_translations.cc         |    3 ++
 15 files changed, 78 insertions(+), 30 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c4111a0..1a10b57 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 2012-01-23  Murray Cumming  <murrayc murrayc com>
 
+	Document: Allow the database title to be translated.
+
+	* glom/libglom/filelist.am:
+	* glom/libglom/database_title.[h|cc]: Add this new TranslatableItem.
+	* glom/libglom/document/document.[h|cc]: Use DatabaseTitle instead of just
+	a string, and load/save it in the database.
+	get_database_title(): Add a locale parameter and add 
+	get_database_title_original().
+	* glom/application.cc:
+	* glom/libglom/connectionpool.cc:
+	* glom/libglom/data_structure/translatable_item.[h|cc]:
+	* glom/libglom/db_utils.cc:
+	* glom/libglom/example_document_load.cc:
+	* glom/libglom/translations_po.cc:
+	* tests/test_document_autosave.cc:
+	* tests/test_document_change.cc:
+	* tests/test_document_load.cc:
+	* tests/test_document_load_translations.cc: Adapt.
+
+2012-01-23  Murray Cumming  <murrayc murrayc com>
+
 	Document: load_after_translation(), save_before_translation(): Use sharedptr.
 
 	* glom/libglom/document/document.[h|cc]: load_after_translation(), 
diff --git a/glom/application.cc b/glom/application.cc
index 60b5e61..baa35b9 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -1070,7 +1070,7 @@ bool Application::on_document_load()
       if(!get_operation_cancelled())
       {
         //Get the results from the extended save dialog:
-        pDocument->set_database_title(m_ui_save_extra_newdb_title);
+        pDocument->set_database_title_original(m_ui_save_extra_newdb_title);
         pDocument->set_hosting_mode(m_ui_save_extra_newdb_hosting_mode);
         m_ui_save_extra_newdb_hosting_mode = Document::HOSTING_MODE_DEFAULT;
         pDocument->set_is_example_file(false);
@@ -1559,7 +1559,7 @@ void Application::existing_or_new_new()
       {
         const Glib::ustring database_name_used = document->get_connection_database();
         ConnectionPool::get_instance()->set_database(database_name_used);
-        document->set_database_title(db_title);
+        document->set_database_title_original(db_title);
         m_pFrame->set_databases_selected(database_name_used);
 
         // Add the document to recent files
@@ -1685,7 +1685,7 @@ bool Application::recreate_database_from_example(bool& user_cancelled)
 
   //Create the database: (This will show a connection dialog)
   connection_pool->set_database( Glib::ustring() );
-  const bool db_created = m_pFrame->create_database(db_name, pDocument->get_database_title());
+  const bool db_created = m_pFrame->create_database(db_name, pDocument->get_database_title_original());
 
   if(!db_created)
   {
diff --git a/glom/libglom/connectionpool.cc b/glom/libglom/connectionpool.cc
index 56e4fc0..4fa9298 100644
--- a/glom/libglom/connectionpool.cc
+++ b/glom/libglom/connectionpool.cc
@@ -878,7 +878,7 @@ void ConnectionPool::avahi_start_publishing()
   if(!document)
     return;
 
-  m_epc_publisher = epc_publisher_new(document->get_database_title().c_str(), "glom", 0);
+  m_epc_publisher = epc_publisher_new(document->get_database_title_original().c_str(), "glom", 0);
   epc_publisher_set_protocol(m_epc_publisher, publish_protocol);
 
   epc_publisher_add_handler(m_epc_publisher, "document", on_publisher_document_requested, this /* user_data */, 0);
diff --git a/glom/libglom/data_structure/translatable_item.cc b/glom/libglom/data_structure/translatable_item.cc
index 225b2b0..7cd767b 100644
--- a/glom/libglom/data_structure/translatable_item.cc
+++ b/glom/libglom/data_structure/translatable_item.cc
@@ -216,6 +216,8 @@ Glib::ustring TranslatableItem::get_translatable_type_name_nontranslated(enumTra
     return "Image";
   else if(item_type == TRANSLATABLE_TYPE_CHOICEVALUE)
     return "Field Choice";
+  else if(item_type == TRANSLATABLE_TYPE_DATABASE_TITLE)
+    return "Database Title";
   else
     return "Unknown";
 }
@@ -248,6 +250,8 @@ Glib::ustring TranslatableItem::get_translatable_type_name(enumTranslatableItemT
     return _("Image");
   else if(item_type == TRANSLATABLE_TYPE_CHOICEVALUE)
     return _("Field Choice");
+  else if(item_type == TRANSLATABLE_TYPE_DATABASE_TITLE)
+    return _("Database Title");
   else
     return _("Unknown");
 }
diff --git a/glom/libglom/data_structure/translatable_item.h b/glom/libglom/data_structure/translatable_item.h
index 99758bf..83fa3d3 100644
--- a/glom/libglom/data_structure/translatable_item.h
+++ b/glom/libglom/data_structure/translatable_item.h
@@ -111,7 +111,8 @@ public:
      TRANSLATABLE_TYPE_BUTTON,
      TRANSLATABLE_TYPE_TEXTOBJECT,
      TRANSLATABLE_TYPE_IMAGEOBJECT,
-     TRANSLATABLE_TYPE_CHOICEVALUE
+     TRANSLATABLE_TYPE_CHOICEVALUE,
+     TRANSLATABLE_TYPE_DATABASE_TITLE
    };
 
   enumTranslatableItemType get_translatable_item_type() const;
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index ebb1281..8164dde 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -232,7 +232,7 @@ bool recreate_database_from_document(Document* document, const sigc::slot<void>&
   //Create the database:
   progress();
   connection_pool->set_database( Glib::ustring() );
-  const bool db_created = create_database(document, db_name, document->get_database_title(), progress);
+  const bool db_created = create_database(document, db_name, document->get_database_title_original(), progress);
 
   if(!db_created)
   {
@@ -440,7 +440,7 @@ void set_database_preferences(Document* document, const SystemPrefs& prefs)
     std::cerr << G_STRFUNC << ": UPDATE failed." << std::endl;
 
   //Set some information in the document too, so we can use it to recreate the database:
-  document->set_database_title(prefs.m_name);
+  document->set_database_title_original(prefs.m_name);
 }
 
 
@@ -467,7 +467,7 @@ bool add_standard_tables(Document* document)
           std::cerr << G_STRFUNC << ": INSERT failed." << std::endl;
 
         //Use the database title from the document, if there is one:
-        const Glib::ustring system_name = document->get_database_title();
+        const Glib::ustring system_name = document->get_database_title_original();
         if(!system_name.empty())
         {
           Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 97dbd37..3b64374 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -281,6 +281,8 @@ Document::Document()
   m_is_backup(false),
   m_opened_from_browse(false)
 {
+  m_database_title = sharedptr<DatabaseTitle>::create();
+
   //Prevent autosaving during the constructor:
   set_allow_autosave(false); //Prevent saving while we modify the document.
 
@@ -2667,7 +2669,9 @@ bool Document::load_after(int& failure_code)
 
       m_is_example = get_node_attribute_value_as_bool(nodeRoot, GLOM_ATTRIBUTE_IS_EXAMPLE);
       m_is_backup = get_node_attribute_value_as_bool(nodeRoot, GLOM_ATTRIBUTE_IS_BACKUP);
-      m_database_title = get_node_attribute_value(nodeRoot, GLOM_ATTRIBUTE_CONNECTION_DATABASE_TITLE);
+      m_database_title->set_title_original( 
+        get_node_attribute_value(nodeRoot, GLOM_ATTRIBUTE_CONNECTION_DATABASE_TITLE) );
+      load_after_translations(nodeRoot, m_database_title);
 
       m_startup_script = get_child_text_node(nodeRoot, GLOM_NODE_STARTUP_SCRIPT);
 
@@ -3719,7 +3723,10 @@ bool Document::save_before()
 
     set_node_attribute_value_as_bool(nodeRoot, GLOM_ATTRIBUTE_IS_EXAMPLE, m_is_example);
     set_node_attribute_value_as_bool(nodeRoot, GLOM_ATTRIBUTE_IS_BACKUP, m_is_backup);
-    set_node_attribute_value(nodeRoot, GLOM_ATTRIBUTE_CONNECTION_DATABASE_TITLE, m_database_title);
+
+    set_node_attribute_value(nodeRoot, GLOM_ATTRIBUTE_CONNECTION_DATABASE_TITLE, 
+      m_database_title->get_title_original());
+    save_before_translations(nodeRoot, m_database_title);   
 
     set_child_text_node(nodeRoot, GLOM_NODE_STARTUP_SCRIPT, m_startup_script);
 
@@ -4045,16 +4052,21 @@ bool Document::save_before()
   return GlomBakery::Document_XML::save_before();
 }
 
-Glib::ustring Document::get_database_title() const
+Glib::ustring Document::get_database_title_original() const
+{
+  return m_database_title->get_title_original();
+}
+
+Glib::ustring Document::get_database_title(const Glib::ustring& locale) const
 {
-  return m_database_title; //TODO: Allow this to be translated.
+  return m_database_title->get_title(locale);
 }
 
-void Document::set_database_title(const Glib::ustring& title)
+void Document::set_database_title_original(const Glib::ustring& title)
 {
-  if(m_database_title != title)
+  if(get_database_title_original() != title)
   {
-    m_database_title = title;
+    m_database_title->set_title_original(title);
     set_modified();
   }
 }
@@ -4062,10 +4074,11 @@ void Document::set_database_title(const Glib::ustring& title)
 Glib::ustring Document::get_name() const
 {
   //Show the database title in the window title bar:
-  if(m_database_title.empty())
+  const Glib::ustring title = get_database_title_original();
+  if(title.empty())
     return GlomBakery::Document_XML::get_name();
   else
-    return m_database_title;
+    return title;
 }
 
 Document::type_list_groups Document::get_groups() const
@@ -4429,6 +4442,8 @@ static void translatable_items_append_with_hint(Document::type_list_translatable
 Document::type_list_translatables Document::get_translatable_items()
 {
   type_list_translatables result;
+  
+  result.push_back( pair_translatable_item_and_hint(m_database_title, "Database Title") );
 
   //Add tables:
   type_listTableInfo tables = get_tables();
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index fc17824..284521f 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -37,6 +37,7 @@
 #include <libglom/data_structure/report.h>
 #include <libglom/data_structure/print_layout.h>
 #include <libglom/data_structure/foundset.h>
+#include <libglom/data_structure/database_title.h>
 #include <libglom/appstate.h>
 #include <vector>
 #include <map>
@@ -260,7 +261,7 @@ public:
   /// The translatable item and a hint about what it is.
   typedef std::pair< sharedptr<TranslatableItem>, Glib::ustring> pair_translatable_item_and_hint;
 
-  typedef std::list<pair_translatable_item_and_hint> type_list_translatables;
+  typedef std::vector<pair_translatable_item_and_hint> type_list_translatables;
   type_list_translatables get_translatable_items();
 
   static void fill_translatable_custom_choices(FieldFormatting& formatting, type_list_translatables& the_list, const Glib::ustring& hint);
@@ -320,8 +321,9 @@ public:
   Glib::ustring get_default_table() const;
   Glib::ustring get_first_table() const;
 
-  Glib::ustring get_database_title() const;
-  void set_database_title(const Glib::ustring& title);
+  Glib::ustring get_database_title_original() const;
+  Glib::ustring get_database_title(const Glib::ustring& locale) const;
+  void set_database_title_original(const Glib::ustring& title);
 
   std::vector<Glib::ustring> get_library_module_names() const;
   void set_library_module(const Glib::ustring& name, const Glib::ustring& script);
@@ -650,7 +652,7 @@ private:
   typedef std::map<Glib::ustring, GroupInfo> type_map_groups;
   type_map_groups m_groups;
 
-  Glib::ustring m_database_title;
+  sharedptr<DatabaseTitle> m_database_title;
   Glib::ustring m_translation_original_locale;
   std::vector<Glib::ustring> m_translation_available_locales; //Just a cache, based on other data.
 
diff --git a/glom/libglom/example_document_load.cc b/glom/libglom/example_document_load.cc
index adb8d82..249b891 100644
--- a/glom/libglom/example_document_load.cc
+++ b/glom/libglom/example_document_load.cc
@@ -102,7 +102,7 @@ int main()
   if(!test)
     return 1;
 
-  std::cout << "Database Title: " << document.get_database_title() << std::endl;
+  std::cout << "Database Title: " << document.get_database_title_original() << std::endl;
   std::cout << "Default Table: " << document.get_default_table() << std::endl;
 
 
diff --git a/glom/libglom/filelist.am b/glom/libglom/filelist.am
index 16298f2..cc05d63 100644
--- a/glom/libglom/filelist.am
+++ b/glom/libglom/filelist.am
@@ -29,6 +29,7 @@ libglom_toplevel_headers =				\
 	glom/libglom/translations_po.h
 
 libglom_data_structure_headers =				\
+	glom/libglom/data_structure/database_title.h		\
 	glom/libglom/data_structure/choicevalue.h		\
 	glom/libglom/data_structure/field.h			\
 	glom/libglom/data_structure/fieldtypes.h		\
@@ -121,6 +122,7 @@ libglom_sources =							\
 	glom/libglom/xsl_utils.h					\
 	glom/libglom/connectionpool_backends/backend.cc			\
 	glom/libglom/connectionpool_backends/backend.h			\
+  glom/libglom/data_structure/database_title.cc \
   glom/libglom/data_structure/choicevalue.cc \
 	glom/libglom/data_structure/field.cc				\
 	glom/libglom/data_structure/fieldtypes.cc			\
diff --git a/glom/libglom/translations_po.cc b/glom/libglom/translations_po.cc
index f6d2ca8..500e31c 100644
--- a/glom/libglom/translations_po.cc
+++ b/glom/libglom/translations_po.cc
@@ -196,7 +196,7 @@ bool write_translations_to_po_file(Document* document, const Glib::ustring& po_f
   const Glib::DateTime revision_date = Glib::DateTime::create_now_local();
   const Glib::ustring revision_date_str = revision_date.format("%F %R%z");
   const Glib::ustring header = Glib::ustring::compose(GLOM_PO_HEADER,
-    document->get_database_title(), revision_date_str, locale_name);
+    document->get_database_title_original(), revision_date_str, locale_name);
   
   const Glib::ustring full = header + "\n\n" + data;
   Glib::file_set_contents(filename, full);
diff --git a/tests/test_document_autosave.cc b/tests/test_document_autosave.cc
index 8d9da44..f7da630 100644
--- a/tests/test_document_autosave.cc
+++ b/tests/test_document_autosave.cc
@@ -71,7 +71,7 @@ int main()
     document.set_allow_autosave(false);
     document.set_file_uri(file_uri);
     document.set_hosting_mode(Glom::Document::HOSTING_MODE_POSTGRES_CENTRAL);
-    document.set_database_title(test_title);
+    document.set_database_title_original(test_title);
     const bool saved = document.save();
     g_assert(saved);
   }
@@ -82,7 +82,7 @@ int main()
     const bool test = document.load(failure_code);
     g_assert(test);
 
-    g_assert( document.get_database_title() == test_title );
+    g_assert( document.get_database_title_original() == test_title );
   }
 
   cleanup();
@@ -93,7 +93,7 @@ int main()
     document.set_file_uri(file_uri);
     document.set_hosting_mode(Glom::Document::HOSTING_MODE_POSTGRES_CENTRAL);
     document.set_allow_autosave();
-    document.set_database_title(test_title);
+    document.set_database_title_original(test_title);
     g_assert( !document.get_modified() );
   }
   {
@@ -103,7 +103,7 @@ int main()
     const bool test = document.load(failure_code);
     g_assert(test);
 
-    g_assert( document.get_database_title() == test_title );
+    g_assert( document.get_database_title_original() == test_title );
   }
 
   cleanup();
diff --git a/tests/test_document_change.cc b/tests/test_document_change.cc
index 467d863..08a2036 100644
--- a/tests/test_document_change.cc
+++ b/tests/test_document_change.cc
@@ -53,8 +53,8 @@ int main()
 
   //Test some simple get/set operations:
   const char* title = "Music Collection";
-  document.set_database_title(title);
-  g_assert(document.get_database_title() == title);
+  document.set_database_title_original(title);
+  g_assert(document.get_database_title_original() == title);
 
   const char* value = "someuser";
   document.set_connection_user(value);
diff --git a/tests/test_document_load.cc b/tests/test_document_load.cc
index e9b2228..f749bb4 100644
--- a/tests/test_document_load.cc
+++ b/tests/test_document_load.cc
@@ -160,7 +160,7 @@ int main()
 
   //Test some known details:
   g_assert(document.get_is_example_file());
-  g_assert(document.get_database_title() == "Openismus Film Manager");
+  g_assert(document.get_database_title_original() == "Openismus Film Manager");
 
   const std::vector<Glib::ustring> table_names = document.get_table_names();
   g_assert(contains(table_names, "accommodation"));
diff --git a/tests/test_document_load_translations.cc b/tests/test_document_load_translations.cc
index 00ed02f..b637cc4 100644
--- a/tests/test_document_load_translations.cc
+++ b/tests/test_document_load_translations.cc
@@ -312,6 +312,9 @@ int main()
   //Check the whole list of translatable items:
   Glom::Document::type_list_translatables list_layout_items = document.get_translatable_items();
   g_assert(!list_layout_items.empty());
+  const bool contains_databasetitle =
+    contains_item_type<Glom::DatabaseTitle>(list_layout_items);
+  g_assert( contains_databasetitle );
   const bool contains_tableinfo =
     contains_item_type<Glom::TableInfo>(list_layout_items);
   g_assert( contains_tableinfo );



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