[glom: 9/12] Maemo: Allow Relationships to have singular titles too. Use them.



commit e38fcaab322d4774faae2ecb707cdf67f84dd6ea
Author: Murray Cumming <murrayc murrayc com>
Date:   Fri Oct 16 09:49:58 2009 +0200

    Maemo: Allow Relationships to have singular titles too. Use them.
    
    	* glom/libglom/data_structure/has_title_singular.[h|cc]: Added this new
    	base class, to be inherited by any TranslatableItem that could also have a
    	singular form.
    	* glom/libglom/data_structure/table_info.[h|cc]:
    	* glom/libglom/data_structure/relationship.[h|cc]: Derive
    	from HasTitleSingular, instead of just having the methods in TableInfo.
    	* glom/libglom/document/document.[h|cc]: Added get_table_title_singular() to
    	match the existing get_table_title().
    	* glom/mode_data/box_data_portal.[h|cc]: Added get_title_singular() to match
    	the existing get_title() and use it in the details window title and AppMenu
    	Add Related button.
    	* glom/mode_data/notebook_data.cc: Use the singular table title for the
    	details window title.

 ChangeLog                                          |   18 ++++
 Makefile_libglom.am                                |    2 +
 .../test_sqlite_music/test_sqlite_music.glom       |   12 ++-
 glom/libglom/data_structure/has_title_singular.cc  |   95 ++++++++++++++++++++
 glom/libglom/data_structure/has_title_singular.h   |   69 ++++++++++++++
 .../data_structure/layout/layoutitem_portal.cc     |    2 +
 .../data_structure/layout/layoutitem_portal.h      |    6 +-
 .../data_structure/layout/usesrelationship.cc      |   16 ++++
 .../data_structure/layout/usesrelationship.h       |    8 ++
 glom/libglom/data_structure/relationship.cc        |    5 +-
 glom/libglom/data_structure/relationship.h         |    7 +-
 glom/libglom/data_structure/tableinfo.cc           |   35 +-------
 glom/libglom/data_structure/tableinfo.h            |   28 +-----
 glom/libglom/document/document.cc                  |   32 ++++++-
 glom/libglom/document/document.h                   |    2 +
 glom/mode_data/box_data_portal.cc                  |   24 +++++-
 glom/mode_data/box_data_portal.h                   |    8 ++-
 glom/mode_data/notebook_data.cc                    |    2 +-
 glom/mode_design/box_db_table_relationships.cc     |    5 +
 glom/mode_design/box_db_table_relationships.h      |    2 +-
 20 files changed, 308 insertions(+), 70 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ca3e7ce..1785880 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-10-16  Murray Cumming  <murrayc murrayc com>
+
+	Maemo: Allow Relationships to have singular titles too. Use them.
+	
+	* glom/libglom/data_structure/has_title_singular.[h|cc]: Added this new 
+	base class, to be inherited by any TranslatableItem that could also have a 
+	singular form. 
+	* glom/libglom/data_structure/table_info.[h|cc]:
+	* glom/libglom/data_structure/relationship.[h|cc]: Derive 
+	from HasTitleSingular, instead of just having the methods in TableInfo.
+	* glom/libglom/document/document.[h|cc]: Added get_table_title_singular() to 
+	match the existing get_table_title().
+	* glom/mode_data/box_data_portal.[h|cc]: Added get_title_singular() to match 
+	the existing get_title() and use it in the details window title and AppMenu 
+	Add Related button.
+	* glom/mode_data/notebook_data.cc: Use the singular table title for the 
+	details window title.
+
 2009-10-15  Murray Cumming  <murrayc murrayc com>
 
 	Maemo: Show a new Details window when adding related records.
diff --git a/Makefile_libglom.am b/Makefile_libglom.am
index 503de46..b6de14d 100644
--- a/Makefile_libglom.am
+++ b/Makefile_libglom.am
@@ -28,6 +28,7 @@ libglom_data_structure_include_HEADERS =			\
 	glom/libglom/data_structure/field.h			\
 	glom/libglom/data_structure/fieldtypes.h		\
 	glom/libglom/data_structure/foundset.h			\
+	glom/libglom/data_structure/has_title_singular.h
 	glom/libglom/data_structure/glomconversions.h		\
 	glom/libglom/data_structure/groupinfo.h			\
 	glom/libglom/data_structure/numeric_format.h		\
@@ -102,6 +103,7 @@ glom_libglom_libglom_1_12_la_SOURCES =					\
 	glom/libglom/data_structure/foundset.cc				\
 	glom/libglom/data_structure/glomconversions.cc			\
 	glom/libglom/data_structure/groupinfo.cc			\
+	glom/libglom/data_structure/has_title_singular.cc		\
 	glom/libglom/data_structure/numeric_format.cc			\
 	glom/libglom/data_structure/parameternamegenerator.cc		\
 	glom/libglom/data_structure/print_layout.cc			\
diff --git a/examples/sqlite/test_sqlite_music/test_sqlite_music.glom b/examples/sqlite/test_sqlite_music/test_sqlite_music.glom
index 16433d7..ee11f3b 100644
--- a/examples/sqlite/test_sqlite_music/test_sqlite_music.glom
+++ b/examples/sqlite/test_sqlite_music/test_sqlite_music.glom
@@ -2,6 +2,7 @@
 <glom_document translation_original_locale="en_US" database_title="Music Collection" is_example="false" format_version="4">
   <connection server="localhost" database="glom_musiccollection21" port="0" self_hosted="true" try_other_ports="true" hosting_mode="sqlite"/>
   <table name="albums" overview_x="15" overview_y="9" title="Albums">
+    <title_singular title="Album" />
     <fields>
       <field name="album_id" primary_key="true" unique="true" auto_increment="true" type="Number" title="Album ID">
         <calculation/>
@@ -31,7 +32,9 @@
     <relationships>
       <relationship name="artist" key="artist_id" other_table="artists" other_key="artist_id" title="Artist"/>
       <relationship name="publisher" key="publisher_id" other_table="publishers" other_key="publishers_id" title="Publisher"/>
-      <relationship name="songs" key="album_id" other_table="songs" other_key="album_id" auto_create="true" allow_edit="true" title="Songs"/>
+      <relationship name="songs" key="album_id" other_table="songs" other_key="album_id" auto_create="true" allow_edit="true" title="Songs">
+        <title_singular title="Song" />
+      </relationship>
     </relationships>
     <data_layouts>
       <data_layout name="details" parent_table="albums">
@@ -132,6 +135,7 @@
     <print_layouts/>
   </table>
   <table name="artists" default="true" overview_x="407" overview_y="119" title="Artists">
+    <title_singular title="Artist" />
     <fields>
       <field name="artist_id" primary_key="true" unique="true" auto_increment="true" type="Number" title="Artist ID">
         <calculation/>
@@ -151,7 +155,9 @@
       </field>
     </fields>
     <relationships>
-      <relationship name="albums" key="artist_id" other_table="albums" other_key="artist_id" auto_create="true" allow_edit="true" title="Albums"/>
+      <relationship name="albums" key="artist_id" other_table="albums" other_key="artist_id" auto_create="true" allow_edit="true" title="Albums">
+        <title_singular title="Album" />
+      </relationship>
     </relationships>
     <data_layouts>
       <data_layout name="details" parent_table="artists">
@@ -213,6 +219,7 @@
     <print_layouts/>
   </table>
   <table name="publishers" overview_x="411" overview_y="235" title="Publishers">
+    <title_singular title="Publisher" />
     <fields>
       <field name="publishers_id" primary_key="true" unique="true" auto_increment="true" type="Number" title="Publisher ID">
         <calculation/>
@@ -287,6 +294,7 @@
     <print_layouts/>
   </table>
   <table name="songs" overview_x="407" overview_y="7" title="Songs">
+    <title_singular title="Song" />
     <fields>
       <field name="songs_id" primary_key="true" unique="true" auto_increment="true" type="Number" title="Song ID">
         <calculation/>
diff --git a/glom/libglom/data_structure/has_title_singular.cc b/glom/libglom/data_structure/has_title_singular.cc
new file mode 100644
index 0000000..a1ed089
--- /dev/null
+++ b/glom/libglom/data_structure/has_title_singular.cc
@@ -0,0 +1,95 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "has_title_singular.h"
+#include <glibmm/i18n.h>
+
+namespace Glom
+{
+
+
+HasTitleSingular::HasTitleSingular()
+{
+}
+
+HasTitleSingular::HasTitleSingular(const HasTitleSingular& src)
+: m_title_singular(src.m_title_singular)
+{
+
+}
+
+HasTitleSingular::~HasTitleSingular()
+{
+}
+
+HasTitleSingular& HasTitleSingular::operator=(const HasTitleSingular& src)
+{
+  m_title_singular = src.m_title_singular;
+
+  return *this;
+}
+
+bool HasTitleSingular::operator==(const HasTitleSingular& src) const
+{
+  const bool bResult = (m_title_singular == m_title_singular);
+
+  return bResult;
+}
+
+bool HasTitleSingular::operator!=(const HasTitleSingular& src) const
+{
+  return !(operator==(src));
+}
+
+
+Glib::ustring HasTitleSingular::get_title_singular() const
+{
+  Glib::ustring result;
+  if(m_title_singular)
+    result = m_title_singular->get_title();
+
+  return result;
+}
+
+Glib::ustring HasTitleSingular::get_title_singular_with_fallback() const
+{
+  const Glib::ustring result = get_title_singular();
+  if(!result.empty())
+    return result;
+  
+  //If it this is also a regular TranslatableItem (usually it is), 
+  //then try getting the regular title instead.
+  const TranslatableItem* translatable = dynamic_cast<const TranslatableItem*>(this);
+  if(translatable)
+    return translatable->get_title_or_name();
+
+  return result;
+}
+
+
+void HasTitleSingular::set_title_singular(const Glib::ustring& title)
+{
+  if(!m_title_singular)
+    m_title_singular = sharedptr<TranslatableItem>::create();
+
+  m_title_singular->set_title(title);
+}
+
+} //namespace Glom
diff --git a/glom/libglom/data_structure/has_title_singular.h b/glom/libglom/data_structure/has_title_singular.h
new file mode 100644
index 0000000..b16a2b1
--- /dev/null
+++ b/glom/libglom/data_structure/has_title_singular.h
@@ -0,0 +1,69 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GLOM_DATASTRUCTURE_HAS_TITLE_SINGULAR_H
+#define GLOM_DATASTRUCTURE_HAS_TITLE_SINGULAR_H
+
+#include <libglom/data_structure/translatable_item.h>
+
+namespace Glom
+{
+
+/** HasTitleSingular instances may have a (translated) singular form of their title.
+ * For instance, "Album" instead of "Albums".
+ * This is useful in some generated UI strings.
+ */
+class HasTitleSingular
+{
+public:
+  HasTitleSingular();
+  HasTitleSingular(const HasTitleSingular& src);
+  virtual ~HasTitleSingular();
+
+  HasTitleSingular& operator=(const HasTitleSingular& src);
+
+  bool operator==(const HasTitleSingular& src) const;
+  bool operator!=(const HasTitleSingular& src) const;
+
+  /** Get the (translation of the) singular form of the title, in the current locale, 
+   * if specified.
+   */
+  Glib::ustring get_title_singular() const;
+
+  /** Get the (translation of the) singular form of the title, in the current locale, 
+   * if specified, falling back to the non-singular title, and 
+   * then falling back to the table name.
+   */
+  Glib::ustring get_title_singular_with_fallback() const;
+
+  /** Set the singular title's translation for the current locale.
+   */
+  void set_title_singular(const Glib::ustring& title);
+
+  /** For instance, "Customer" if the table is titled "Customers".
+   * This is useful in some UI strings.
+   */
+  sharedptr<TranslatableItem> m_title_singular;
+};
+
+} //namespace Glom
+
+#endif //GLOM_DATASTRUCTURE_HAS_TITLE_SINGULAR_H
+
diff --git a/glom/libglom/data_structure/layout/layoutitem_portal.cc b/glom/libglom/data_structure/layout/layoutitem_portal.cc
index 8c71fdf..c5ed4f5 100644
--- a/glom/libglom/data_structure/layout/layoutitem_portal.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_portal.cc
@@ -33,6 +33,7 @@ LayoutItem_Portal::LayoutItem_Portal()
 LayoutItem_Portal::LayoutItem_Portal(const LayoutItem_Portal& src)
 : LayoutGroup(src),
   UsesRelationship(src),
+  //HasTitleSingular(src),
   m_navigation_relationship_specific(src.m_navigation_relationship_specific),
   m_print_layout_row_height(src.m_print_layout_row_height),
   m_navigation_type(src.m_navigation_type)
@@ -53,6 +54,7 @@ LayoutItem_Portal& LayoutItem_Portal::operator=(const LayoutItem_Portal& src)
 {
   LayoutGroup::operator=(src);
   UsesRelationship::operator=(src);
+  //HasTitleSingular::operator=(src);
 
   m_navigation_relationship_specific = src.m_navigation_relationship_specific;
   m_print_layout_row_height = src.m_print_layout_row_height;
diff --git a/glom/libglom/data_structure/layout/layoutitem_portal.h b/glom/libglom/data_structure/layout/layoutitem_portal.h
index 1a706be..962a1d8 100644
--- a/glom/libglom/data_structure/layout/layoutitem_portal.h
+++ b/glom/libglom/data_structure/layout/layoutitem_portal.h
@@ -21,9 +21,10 @@
 #ifndef GLOM_DATASTRUCTURE_LAYOUTITEM_PORTAL_H
 #define GLOM_DATASTRUCTURE_LAYOUTITEM_PORTAL_H
 
-#include "layoutgroup.h"
+#include <libglom/data_structure/layout/layoutgroup.h>
 #include <libglom/data_structure/field.h>
 #include <libglom/data_structure/relationship.h>
+//#include <libglom/data_structure/has_title_singular.h>
 
 namespace Glom
 {
@@ -31,6 +32,9 @@ namespace Glom
 class LayoutItem_Portal
 : public LayoutGroup,
   public UsesRelationship
+  
+  //TODO: Allow portals to have custom titles that override the relationship titles?
+  //public HasTitleSingular
 {
 public:
 
diff --git a/glom/libglom/data_structure/layout/usesrelationship.cc b/glom/libglom/data_structure/layout/usesrelationship.cc
index 341421f..f62a4cc 100644
--- a/glom/libglom/data_structure/layout/usesrelationship.cc
+++ b/glom/libglom/data_structure/layout/usesrelationship.cc
@@ -145,6 +145,22 @@ Glib::ustring UsesRelationship::get_title_used(const Glib::ustring& parent_table
     return parent_table_title;
 }
 
+Glib::ustring UsesRelationship::get_title_singular_used(const Glib::ustring& parent_table_title) const
+{
+  sharedptr<Relationship> used = m_related_relationship;
+  if(!used)
+    used = m_relationship;
+    
+  if(!used)
+    return Glib::ustring();
+    
+  const Glib::ustring result = used->get_title_singular();
+  if(!result.empty())
+    return result;
+  else
+    return get_title_used(parent_table_title);
+}
+
 Glib::ustring UsesRelationship::get_to_field_used() const
 {
   if(m_related_relationship)
diff --git a/glom/libglom/data_structure/layout/usesrelationship.h b/glom/libglom/data_structure/layout/usesrelationship.h
index 9e9d326..4bedcde 100644
--- a/glom/libglom/data_structure/layout/usesrelationship.h
+++ b/glom/libglom/data_structure/layout/usesrelationship.h
@@ -66,7 +66,15 @@ public:
    */
   Glib::ustring get_table_used(const Glib::ustring& parent_table) const;
 
+  /** Get the title of the relationship that is actually used,
+   * falling back to the relationship's name.
+   */
   Glib::ustring get_title_used(const Glib::ustring& parent_table_title) const;
+  
+  /** Get the singular title of the relationship that is actually used,
+   * falling back to the regular (plural) title, and then to the relationship's name.
+   */
+  Glib::ustring get_title_singular_used(const Glib::ustring& parent_table_title) const;
 
   Glib::ustring get_to_field_used() const;
 
diff --git a/glom/libglom/data_structure/relationship.cc b/glom/libglom/data_structure/relationship.cc
index 4e6abe9..ebb73f8 100644
--- a/glom/libglom/data_structure/relationship.cc
+++ b/glom/libglom/data_structure/relationship.cc
@@ -30,7 +30,8 @@ Relationship::Relationship()
 }
 
 Relationship::Relationship(const Relationship& src)
-: TranslatableItem(src)
+: TranslatableItem(src),
+  HasTitleSingular(src)
 {
   operator=(src); //TODO_Performance: Implement properly.
 }
@@ -42,6 +43,7 @@ Relationship::~Relationship()
 Relationship& Relationship::operator=(const Relationship& src)
 {
   TranslatableItem::operator=(src);
+  HasTitleSingular::operator=(src);
 
   m_strFrom_Table = src.m_strFrom_Table;
   m_strFrom_Field = src.m_strFrom_Field;
@@ -56,6 +58,7 @@ Relationship& Relationship::operator=(const Relationship& src)
 bool Relationship::operator==(const Relationship& src) const
 {
   return TranslatableItem::operator==(src)
+         && HasTitleSingular::operator==(src)
          && (m_strFrom_Table == src.m_strFrom_Table)
          && (m_strFrom_Field == src.m_strFrom_Field)
          && (m_strTo_Table == src.m_strTo_Table)
diff --git a/glom/libglom/data_structure/relationship.h b/glom/libglom/data_structure/relationship.h
index afb52f4..693c9b1 100644
--- a/glom/libglom/data_structure/relationship.h
+++ b/glom/libglom/data_structure/relationship.h
@@ -21,13 +21,16 @@
 #ifndef RELATIONSHIP_H
 #define RELATIONSHIP_H
 
-#include "translatable_item.h"
+#include <libglom/data_structure/translatable_item.h>
+#include <libglom/data_structure/has_title_singular.h>
 #include <glibmm/ustring.h>
 
 namespace Glom
 {
 
-class Relationship : public TranslatableItem
+class Relationship
+ : public TranslatableItem,
+   public HasTitleSingular
 {
 public: 
   Relationship();
diff --git a/glom/libglom/data_structure/tableinfo.cc b/glom/libglom/data_structure/tableinfo.cc
index 9ef0317..79340e5 100644
--- a/glom/libglom/data_structure/tableinfo.cc
+++ b/glom/libglom/data_structure/tableinfo.cc
@@ -33,51 +33,24 @@ TableInfo::TableInfo()
 
 TableInfo::TableInfo(const TableInfo& src)
 : TranslatableItem(src),
+  HasTitleSingular(src),
   m_sequence(src.m_sequence),
   m_hidden(src.m_hidden),
-  m_default(src.m_default),
-  m_title_singular(src.m_title_singular)
+  m_default(src.m_default)
 {
 }
 
 TableInfo& TableInfo::operator=(const TableInfo& src)
 {
   TranslatableItem::operator=(src);
-
+  HasTitleSingular::operator=(src);
+  
   m_sequence = src.m_sequence;
   m_hidden = src.m_hidden;
   m_default = src.m_default;
-  m_title_singular = src.m_title_singular;
 
   return *this;
 }
 
-Glib::ustring TableInfo::get_title_singular() const
-{
-  Glib::ustring result;
-  if(m_title_singular)
-    result = m_title_singular->get_title();
-
-  return result;
-}
-
-Glib::ustring TableInfo::get_title_singular_with_fallback() const
-{
-  const Glib::ustring result = get_title_singular();
-  if(result.empty())
-    return get_title_or_name();
-
-  return result;
-}
-
-void TableInfo::set_title_singular(const Glib::ustring& title)
-{
-  if(!m_title_singular)
-    m_title_singular = sharedptr<TranslatableItem>::create();
-
-  m_title_singular->set_title(title);
-}
-
-
 
 } //namespace Glom
diff --git a/glom/libglom/data_structure/tableinfo.h b/glom/libglom/data_structure/tableinfo.h
index 64197c9..f74a9ef 100644
--- a/glom/libglom/data_structure/tableinfo.h
+++ b/glom/libglom/data_structure/tableinfo.h
@@ -21,13 +21,15 @@
 #ifndef GLOM_DATASTRUCTURE_TABLEINFO_H
 #define GLOM_DATASTRUCTURE_TABLEINFO_H
 
-#include "translatable_item.h"
-#include <glibmm/ustring.h>
+#include <libglom/data_structure/translatable_item.h>
+#include <libglom/data_structure/has_title_singular.h>
 
 namespace Glom
 {
 
-class TableInfo : public TranslatableItem
+class TableInfo
+ : public TranslatableItem,
+   public HasTitleSingular
 {
 public:
   TableInfo();
@@ -37,26 +39,6 @@ public:
   guint m_sequence; //TODO: Use this?
   bool m_hidden;
   bool m_default;
-
-  /** Get the (translation of the) singular form of the title, in the current locale, 
-   * if specified.
-   */
-  Glib::ustring get_title_singular() const;
-
-  /** Get the (translation of the) singular form of the title, in the current locale, 
-   * if specified, falling back to the non-singular title, and 
-   * then falling back to the table name.
-   */
-  Glib::ustring get_title_singular_with_fallback() const;
-
-  /** Set the singular title's translation for the current locale.
-   */
-  void set_title_singular(const Glib::ustring& title);
-
-  /** For instance, "Customer" if the table is titled "Customers".
-   * This is useful in some UI strings.
-   */
-  sharedptr<TranslatableItem> m_title_singular;
 };
 
 } //namespace Glom
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 018f77e..a52fe84 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -1635,6 +1635,15 @@ Glib::ustring Document::get_table_title(const Glib::ustring& table_name) const
     return Glib::ustring();
 }
 
+Glib::ustring Document::get_table_title_singular(const Glib::ustring& table_name) const
+{
+  type_tables::const_iterator iterFind = m_tables.find(table_name);
+  if(iterFind != m_tables.end())
+    return iterFind->second.m_info->get_title_singular_with_fallback();
+  else
+    return Glib::ustring();
+}
+
 void Document::set_table_title(const Glib::ustring& table_name, const Glib::ustring& value)
 {
   //std::cout << "debug: Document::set_table_title(): table_name=" << table_name << ", value=" << value << std::endl;
@@ -2308,6 +2317,15 @@ void Document::load_after_translations(const xmlpp::Element* element, Translatab
       }
     }
   }
+  
+  //If it has a singular title, then load that too:
+  HasTitleSingular* has_title_singular = 
+    dynamic_cast<HasTitleSingular*>(&item);
+  if(has_title_singular)
+  {
+    const xmlpp::Element* nodeTitleSingular = get_node_child_named(element, GLOM_NODE_TABLE_TITLE_SINGULAR);
+    load_after_translations(nodeTitleSingular, *(has_title_singular->m_title_singular));
+  }
 }
 
 void Document::load_after_print_layout_position(const xmlpp::Element* nodeItem, const sharedptr<LayoutItem>& item)
@@ -3218,6 +3236,15 @@ void Document::save_before_translations(xmlpp::Element* element, const Translata
     set_node_attribute_value(childItem, GLOM_ATTRIBUTE_TRANSLATION_LOCALE, iter->first);
     set_node_attribute_value(childItem, GLOM_ATTRIBUTE_TRANSLATION_VALUE, iter->second);
   }
+  
+  //If it has a singular title, then save that too:
+  const HasTitleSingular* has_title_singular = 
+    dynamic_cast<const HasTitleSingular*>(&item);
+  if(has_title_singular)
+  {
+    xmlpp::Element* nodeTitleSingular = element->add_child(GLOM_NODE_TABLE_TITLE_SINGULAR);
+    save_before_translations(nodeTitleSingular, *(has_title_singular->m_title_singular));
+  }
 }
 
 void Document::save_before_print_layout_position(xmlpp::Element* nodeItem, const sharedptr<const LayoutItem>& item)
@@ -3347,11 +3374,6 @@ bool Document::save_before()
         //Translations:
         save_before_translations(nodeTable, *(doctableinfo.m_info));
 
-        //Save the singular table name:
-        xmlpp::Element* nodeTableSingluar = nodeTable->add_child(GLOM_NODE_TABLE_TITLE_SINGULAR);
-        save_before_translations(nodeTableSingluar, *(doctableinfo.m_info->m_title_singular));
-
-
         //Fields:
         xmlpp::Element* elemFields = nodeTable->add_child(GLOM_NODE_FIELDS);
 
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index b9b8758..5e5769d 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -270,6 +270,8 @@ public:
   Glib::ustring get_table_title(const Glib::ustring& table_name) const;
   void set_table_title(const Glib::ustring& table_name, const Glib::ustring& value);
 
+  Glib::ustring get_table_title_singular(const Glib::ustring& table_name) const;
+  
   typedef std::vector< Gnome::Gda::Value > type_row_data;
   typedef std::vector< type_row_data > type_example_rows;
 
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index 4c5cb21..ff2fc95 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -118,6 +118,9 @@ void Box_Data_Portal::make_record_related(const Gnome::Gda::Value& related_recor
 #ifdef GLOM_ENABLE_MAEMO
 void Box_Data_Portal::on_maemo_appmenubutton_add()
 {
+  if(!m_portal)
+    return;
+    
   if(m_window_maemo_details)
     delete m_window_maemo_details;
     
@@ -142,7 +145,7 @@ void Box_Data_Portal::on_maemo_appmenubutton_add()
 
   const Glib::ustring title = 
     Glib::ustring::compose(_("New Related %1"), 
-      get_title());
+      get_title_singular());
   pWindow->set_title(title);
   
   FoundSet found_set;
@@ -166,13 +169,16 @@ void Box_Data_Portal::on_maemo_appmenubutton_add()
 
 void Box_Data_Portal::on_realize()
 {
+  if(!m_portal)
+    return;
+    
   // Add an Add Related Something button to the application's AppMenu.
   // This will be removed when the portal is hidden.
   //TODO: Use the ustring compose thingy. murrayc.
   //TODO: Allow the designer to specify a singluar form for tables (and portals), 
   //so we can say Add Related Something instead of Somethings: Add Related.
   const Glib::ustring title = 
-    Glib::ustring::compose(_("%1: Add Related"), get_title());
+    Glib::ustring::compose(_("Add Related %1"), get_title_singular());
   m_maemo_appmenubutton_add.set_title(title);
   m_maemo_appmenubutton_add.set_value(_("Add related record"));
   App_Glom* app = App_Glom::get_application();
@@ -234,6 +240,20 @@ Glib::ustring Box_Data_Portal::get_title() const
   return relationship_title;
 }
 
+Glib::ustring Box_Data_Portal::get_title_singular() const
+{
+  Glib::ustring relationship_title;
+  if(m_portal && m_portal->get_has_relationship_name())
+    relationship_title = m_portal->get_title_singular_used(Glib::ustring() /* parent title - not relevant */);
+  else
+  {
+    //Note to translators: This text is shown instead of a table title, when the table has not yet been chosen.
+    relationship_title = _("Undefined Table");
+  }
+  
+  return relationship_title;
+}
+
 //TODO: Is this base class implemenation actually called by anything?
 bool Box_Data_Portal::init_db_details(const Glib::ustring& parent_table, bool show_title)
 {
diff --git a/glom/mode_data/box_data_portal.h b/glom/mode_data/box_data_portal.h
index 59fc84f..5b1e8d5 100644
--- a/glom/mode_data/box_data_portal.h
+++ b/glom/mode_data/box_data_portal.h
@@ -100,8 +100,14 @@ protected:
 
   void make_record_related(const Gnome::Gda::Value& related_record_primary_key_value);
 
+  /** Get the title of the relationship used by the portal.
+   */
   Glib::ustring get_title() const;
-
+  
+  /** Get the singular title of the relationship used by the portal.
+   */
+  Glib::ustring get_title_singular() const;  
+  
   Gtk::Frame m_Frame;
   Gtk::Alignment m_Alignment;
   Gtk::Label m_Label;
diff --git a/glom/mode_data/notebook_data.cc b/glom/mode_data/notebook_data.cc
index 4cdf38f..1b451fe 100644
--- a/glom/mode_data/notebook_data.cc
+++ b/glom/mode_data/notebook_data.cc
@@ -236,7 +236,7 @@ void Notebook_Data::show_details(const Gnome::Gda::Value& primary_key_value)
   g_assert(document);
   const Glib::ustring title = 
     Glib::ustring::compose(_("%1 Details"), 
-      document->get_table_title(m_table_name));
+      document->get_table_title_singular(m_table_name));
   m_window_maemo_details->set_title(title);
   
   m_window_maemo_details->show();
diff --git a/glom/mode_design/box_db_table_relationships.cc b/glom/mode_design/box_db_table_relationships.cc
index 5ec4c3f..f865399 100644
--- a/glom/mode_design/box_db_table_relationships.cc
+++ b/glom/mode_design/box_db_table_relationships.cc
@@ -52,6 +52,9 @@ void Box_DB_Table_Relationships::init()
   m_colToField = m_AddDel.add_column(_("To Field"), AddDelColumnInfo::STYLE_Choices);
   m_colAllowEdit = m_AddDel.add_column(_("Allow Editing"),  AddDelColumnInfo::STYLE_Boolean);
   m_colAutoCreate = m_AddDel.add_column(_("Automatic Creation"),  AddDelColumnInfo::STYLE_Boolean);
+  
+  m_colTitleSingular = m_AddDel.add_column(_("Title (Singular Form)"));
+  
 
   //Connect signals:
   m_AddDel.signal_user_activated().connect(sigc::mem_fun(*this, &Box_DB_Table_Relationships::on_adddel_user_activated));
@@ -107,6 +110,7 @@ bool Box_DB_Table_Relationships::fill_from_database()
 
         //Title:
         m_AddDel.set_value(iterTree, m_colTitle, relationship->get_title());
+        m_AddDel.set_value(iterTree, m_colTitleSingular, relationship->get_title_singular());
 
         //From Field:
         m_AddDel.set_value(iterTree, m_colFromField, relationship->get_from_field());
@@ -153,6 +157,7 @@ void Box_DB_Table_Relationships::save_to_document()
 
         relationship->set_name(name);
         relationship->set_title(m_AddDel.get_value(iter, m_colTitle));
+        relationship->set_title_singular(m_AddDel.get_value(iter, m_colTitleSingular));
         relationship->set_from_table(m_table_name);
         relationship->set_from_field(m_AddDel.get_value(iter, m_colFromField));
         relationship->set_to_table(m_AddDel.get_value(iter, m_colToTable));
diff --git a/glom/mode_design/box_db_table_relationships.h b/glom/mode_design/box_db_table_relationships.h
index 6cc05a7..280e347 100644
--- a/glom/mode_design/box_db_table_relationships.h
+++ b/glom/mode_design/box_db_table_relationships.h
@@ -47,7 +47,7 @@ private:
   void on_adddel_user_requested_delete(const Gtk::TreeModel::iterator& rowStart, const Gtk::TreeModel::iterator& rowEnd);
   void on_adddel_user_added(const Gtk::TreeModel::iterator& row);
 
-  guint m_colName, m_colTitle, m_colFromField, m_colToTable, m_colToField, m_colAllowEdit, m_colAutoCreate;
+  guint m_colName, m_colTitle, m_colFromField, m_colToTable, m_colToField, m_colAllowEdit, m_colAutoCreate, m_colTitleSingular;
 
   mutable AddDel_WithButtons m_AddDel; //mutable because its get_ methods aren't const.
   Gtk::Button m_Button_Guess;



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