[glom] Export to po files: Also export text items from Print Layouts.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Export to po files: Also export text items from Print Layouts.
- Date: Mon, 12 Nov 2012 20:16:04 +0000 (UTC)
commit 633d90830a10c4ec150bb9a8bd60141bd066445f
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Nov 12 06:26:59 2012 +0100
Export to po files: Also export text items from Print Layouts.
* glom/libglom/data_structure/layout/static_text.[h|cc]:
A new derived TranslatableItem, just so we can identify its
purpose polymorphically.
* glom/libglom/filelist.am: Mention the new files.
* glom/libglom/data_structure/layout/layoutitem_text.[h|cc]:
Use StaticText instead of TranslatableItem for m_text.
* glom/libglom/data_structure/translatable_item.[h|cc]:
Add an enum for the new derived type, and return its name
from the get_translatable_type*() methods.
These are used of in PrintLayouts.
* glom/libglom/document/document.[h|cc]:
load_after_layout_group(): Adapt.
Add get_translatable_print_layout_items() and use it in
get_translatable_items().
* tests/test_document_load_translations.cc: Check that
get_translatable_items() returns some PrintLayouts.
ChangeLog | 21 ++++++++
.../data_structure/layout/layoutitem_text.cc | 12 ++--
.../data_structure/layout/layoutitem_text.h | 7 ++-
glom/libglom/data_structure/layout/static_text.cc | 55 ++++++++++++++++++++
glom/libglom/data_structure/layout/static_text.h | 49 +++++++++++++++++
glom/libglom/data_structure/translatable_item.cc | 8 ++-
glom/libglom/data_structure/translatable_item.h | 5 +-
glom/libglom/document/document.cc | 34 +++++++++++-
glom/libglom/document/document.h | 3 +-
glom/libglom/filelist.am | 2 +
tests/.gitignore | 1 +
tests/test_document_load_translations.cc | 3 +
12 files changed, 185 insertions(+), 15 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a33f269..50b44bd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
2012-11-11 Murray Cumming <murrayc murrayc com>
+ Export to po files: Also export text items from Print Layouts.
+
+ * glom/libglom/data_structure/layout/static_text.[h|cc]:
+ A new derived TranslatableItem, just so we can identify its
+ purpose polymorphically.
+ * glom/libglom/filelist.am: Mention the new files.
+ * glom/libglom/data_structure/layout/layoutitem_text.[h|cc]:
+ Use StaticText instead of TranslatableItem for m_text.
+ * glom/libglom/data_structure/translatable_item.[h|cc]:
+ Add an enum for the new derived type, and return its name
+ from the get_translatable_type*() methods.
+ These are used of in PrintLayouts.
+ * glom/libglom/document/document.[h|cc]:
+ load_after_layout_group(): Adapt.
+ Add get_translatable_print_layout_items() and use it in
+ get_translatable_items().
+ * tests/test_document_load_translations.cc: Check that
+ get_translatable_items() returns some PrintLayouts.
+
+2012-11-11 Murray Cumming <murrayc murrayc com>
+
Export to .po files: Make sure we export static text items.
* glom/libglom/document/document.cc: fill_translatable_layout_items():
diff --git a/glom/libglom/data_structure/layout/layoutitem_text.cc b/glom/libglom/data_structure/layout/layoutitem_text.cc
index a81df1e..1fab274 100644
--- a/glom/libglom/data_structure/layout/layoutitem_text.cc
+++ b/glom/libglom/data_structure/layout/layoutitem_text.cc
@@ -27,15 +27,15 @@ namespace Glom
LayoutItem_Text::LayoutItem_Text()
{
m_translatable_item_type = TRANSLATABLE_TYPE_TEXTOBJECT;
- m_text = sharedptr<TranslatableItem>::create(); //TODO: Why use a smartpointer?
+ m_text = sharedptr<StaticText>::create(); //TODO: Why use a smartpointer?
}
LayoutItem_Text::LayoutItem_Text(const LayoutItem_Text& src)
: LayoutItem_WithFormatting(src)
{
- //Copy the underlying TranslatableItem, not the shardptr to it:
- const TranslatableItem& src_item = *(src.m_text);
- m_text = sharedptr<TranslatableItem>(new TranslatableItem(src_item));
+ //Copy the underlying TranslatableItem, not the sharedptr to it:
+ const StaticText& src_item = *(src.m_text);
+ m_text = sharedptr<StaticText>(new StaticText(src_item));
}
LayoutItem_Text::~LayoutItem_Text()
@@ -61,8 +61,8 @@ LayoutItem_Text& LayoutItem_Text::operator=(const LayoutItem_Text& src)
LayoutItem_WithFormatting::operator=(src);
//Copy the underlying TranslatableItem, not the shardptr to it:
- const TranslatableItem& src_item = *(src.m_text);
- m_text = sharedptr<TranslatableItem>(new TranslatableItem(src_item));
+ const StaticText& src_item = *(src.m_text);
+ m_text = sharedptr<StaticText>(new StaticText(src_item));
return *this;
}
diff --git a/glom/libglom/data_structure/layout/layoutitem_text.h b/glom/libglom/data_structure/layout/layoutitem_text.h
index 84d0d14..3319310 100644
--- a/glom/libglom/data_structure/layout/layoutitem_text.h
+++ b/glom/libglom/data_structure/layout/layoutitem_text.h
@@ -21,12 +21,17 @@
#ifndef GLOM_DATASTRUCTURE_LAYOUTITEM_TEXT_H
#define GLOM_DATASTRUCTURE_LAYOUTITEM_TEXT_H
+#include <libglom/data_structure/layout/static_text.h>
#include <libglom/data_structure/layout/layoutitem_withformatting.h>
#include <libglom/data_structure/layout/formatting.h>
namespace Glom
{
+/** A layout item for static text, and an optional title.
+ * The base class TranslatableItem holds the title,
+ * and the actual (translatable) text is in the m_text member.
+ */
class LayoutItem_Text
: public LayoutItem_WithFormatting
{
@@ -57,7 +62,7 @@ public:
*/
void set_text_original(const Glib::ustring& text);
- sharedptr<TranslatableItem> m_text; //Reuse the title concept of this class to give us translatable text.
+ sharedptr<StaticText> m_text; //Reuse the title concept of the TranslatableItem base class to give us translatable text.
};
} //namespace Glom
diff --git a/glom/libglom/data_structure/layout/static_text.cc b/glom/libglom/data_structure/layout/static_text.cc
new file mode 100644
index 0000000..3ab1610
--- /dev/null
+++ b/glom/libglom/data_structure/layout/static_text.cc
@@ -0,0 +1,55 @@
+/* Glom
+ *
+ * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#include <libglom/data_structure/layout/static_text.h>
+#include <glibmm/i18n.h>
+
+namespace Glom
+{
+
+StaticText::StaticText()
+{
+ m_translatable_item_type = TRANSLATABLE_TYPE_STATIC_TEXT;
+}
+
+StaticText::StaticText(const StaticText& src)
+: TranslatableItem(src)
+{
+}
+
+StaticText::~StaticText()
+{
+}
+
+bool StaticText::operator==(const StaticText& src) const
+{
+ const bool result = TranslatableItem::operator==(src);
+
+ return result;
+}
+
+//Avoid using this, for performance:
+StaticText& StaticText::operator=(const StaticText& src)
+{
+ TranslatableItem::operator=(src);
+ return *this;
+}
+
+} //namespace Glom
diff --git a/glom/libglom/data_structure/layout/static_text.h b/glom/libglom/data_structure/layout/static_text.h
new file mode 100644
index 0000000..564550d
--- /dev/null
+++ b/glom/libglom/data_structure/layout/static_text.h
@@ -0,0 +1,49 @@
+/* Glom
+ *
+ * Copyright (C) 2012 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ */
+
+#ifndef GLOM_DATASTRUCTURE_LAYOUT_STATIC_TEXT_H
+#define GLOM_DATASTRUCTURE_LAYOUT_STATIC_TEXT_H
+
+#include <libglom/data_structure/translatable_item.h>
+
+namespace Glom
+{
+
+/** This reuses the title concept of the TranslatableItem base class to give us translatable text.
+ */
+class StaticText
+ : public TranslatableItem
+{
+public:
+
+ StaticText();
+ StaticText(const StaticText& src);
+ StaticText& operator=(const StaticText& src);
+ virtual ~StaticText();
+
+ bool operator==(const StaticText& src) const;
+};
+
+} //namespace Glom
+
+#endif //GLOM_DATASTRUCTURE_LAYOUT_CUSTOM_TITLE_H
+
+
+
diff --git a/glom/libglom/data_structure/translatable_item.cc b/glom/libglom/data_structure/translatable_item.cc
index 5efffa7..2610643 100644
--- a/glom/libglom/data_structure/translatable_item.cc
+++ b/glom/libglom/data_structure/translatable_item.cc
@@ -211,13 +211,15 @@ Glib::ustring TranslatableItem::get_translatable_type_name_nontranslated(enumTra
else if(item_type == TRANSLATABLE_TYPE_BUTTON)
return "Button";
else if(item_type == TRANSLATABLE_TYPE_TEXTOBJECT)
- return "Text";
+ return "Text Item";
else if(item_type == TRANSLATABLE_TYPE_IMAGEOBJECT)
return "Image";
else if(item_type == TRANSLATABLE_TYPE_CHOICEVALUE)
return "Field Choice";
else if(item_type == TRANSLATABLE_TYPE_DATABASE_TITLE)
return "Database Title";
+ else if(item_type == TRANSLATABLE_TYPE_STATIC_TEXT)
+ return "Text";
else
return "Unknown";
}
@@ -245,13 +247,15 @@ Glib::ustring TranslatableItem::get_translatable_type_name(enumTranslatableItemT
else if(item_type == TRANSLATABLE_TYPE_BUTTON)
return _("Button");
else if(item_type == TRANSLATABLE_TYPE_TEXTOBJECT)
- return _("Text");
+ return _("Text Item");
else if(item_type == TRANSLATABLE_TYPE_IMAGEOBJECT)
return _("Image");
else if(item_type == TRANSLATABLE_TYPE_CHOICEVALUE)
return _("Field Choice");
else if(item_type == TRANSLATABLE_TYPE_DATABASE_TITLE)
return _("Database Title");
+ else if(item_type == TRANSLATABLE_TYPE_STATIC_TEXT)
+ return _("Text");
else
return _("Unknown");
}
diff --git a/glom/libglom/data_structure/translatable_item.h b/glom/libglom/data_structure/translatable_item.h
index 261e796..4a0599b 100644
--- a/glom/libglom/data_structure/translatable_item.h
+++ b/glom/libglom/data_structure/translatable_item.h
@@ -107,10 +107,11 @@ public:
TRANSLATABLE_TYPE_REPORT,
TRANSLATABLE_TYPE_TABLE,
TRANSLATABLE_TYPE_BUTTON,
- TRANSLATABLE_TYPE_TEXTOBJECT,
+ TRANSLATABLE_TYPE_TEXTOBJECT, //This has a TRANSLATABLE_TYPE_STATIC_TEXT child.
TRANSLATABLE_TYPE_IMAGEOBJECT,
TRANSLATABLE_TYPE_CHOICEVALUE,
- TRANSLATABLE_TYPE_DATABASE_TITLE
+ TRANSLATABLE_TYPE_DATABASE_TITLE,
+ TRANSLATABLE_TYPE_STATIC_TEXT
};
enumTranslatableItemType get_translatable_item_type() const;
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index e450212..61a3a2f 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -2131,7 +2131,7 @@ void Document::load_after_layout_group(const xmlpp::Element* node, const Glib::u
const xmlpp::Element* element_text = XmlUtils::get_node_child_named(element, GLOM_NODE_DATA_LAYOUT_TEXTOBJECT_TEXT);
if(element_text)
{
- sharedptr<TranslatableItem> translatable_text = sharedptr<TranslatableItem>::create();
+ sharedptr<StaticText> translatable_text = sharedptr<StaticText>::create();
load_after_translations(element_text, translatable_text);
item->m_text = translatable_text;
//std::cout << " DEBUG: text: " << item->m_text->get_title_or_name() << std::endl;
@@ -4311,6 +4311,23 @@ Document::type_list_translatables Document::get_translatable_items()
result.insert(result.end(), list_layout_items.begin(), list_layout_items.end());
}
+ //The table's print layout titles:
+ std::vector<Glib::ustring> listPrintLayouts = get_print_layout_names(table_name);
+ for(std::vector<Glib::ustring>::iterator iter = listPrintLayouts.begin(); iter != listPrintLayouts.end(); ++iter)
+ {
+ const Glib::ustring print_layout_name = *iter;
+ sharedptr<PrintLayout> print_layout = get_print_layout(table_name, print_layout_name);
+ if(!print_layout)
+ continue;
+
+ result.push_back( pair_translatable_item_and_hint(print_layout, hint) );
+
+ //Translatable print layout items:
+ const Glib::ustring this_hint = hint + ", Print Layout: " + print_layout->get_name();
+ type_list_translatables list_layout_items = get_translatable_print_layout_items(table_name, print_layout_name, this_hint);
+ result.insert(result.end(), list_layout_items.begin(), list_layout_items.end());
+ }
+
//The table's translatable layout items:
type_list_translatables list_layout_items = get_translatable_layout_items(table_name, hint);
result.insert(result.end(), list_layout_items.begin(), list_layout_items.end());
@@ -4345,17 +4362,28 @@ Document::type_list_translatables Document::get_translatable_layout_items(const
}
-Document::type_list_translatables Document::get_translatable_report_items(const Glib::ustring& table_name, const Glib::ustring& report_title, const Glib::ustring& hint)
+Document::type_list_translatables Document::get_translatable_report_items(const Glib::ustring& table_name, const Glib::ustring& report_name, const Glib::ustring& hint)
{
Document::type_list_translatables the_list;
- sharedptr<Report> report = get_report(table_name, report_title);
+ sharedptr<Report> report = get_report(table_name, report_name);
if(report)
fill_translatable_layout_items(report->get_layout_group(), the_list, hint);
return the_list;
}
+Document::type_list_translatables Document::get_translatable_print_layout_items(const Glib::ustring& table_name, const Glib::ustring& print_layout_name, const Glib::ustring& hint)
+{
+ Document::type_list_translatables the_list;
+
+ sharedptr<PrintLayout> print_layout = get_print_layout(table_name, print_layout_name);
+ if(print_layout)
+ fill_translatable_layout_items(print_layout->get_layout_group(), the_list, hint);
+
+ return the_list;
+}
+
void Document::fill_translatable_custom_choices(Formatting& formatting, type_list_translatables& the_list, const Glib::ustring& hint)
{
if(!formatting.get_has_custom_choices())
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 4b3319d..58d5dfd 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -520,7 +520,8 @@ private:
void fill_sort_field_details(const Glib::ustring& parent_table_name, Formatting::type_list_sort_fields& sort_fields) const;
type_list_translatables get_translatable_layout_items(const Glib::ustring& table_name, const Glib::ustring& hint);
- type_list_translatables get_translatable_report_items(const Glib::ustring& table_name, const Glib::ustring& report_title, const Glib::ustring& hint);
+ type_list_translatables get_translatable_report_items(const Glib::ustring& table_name, const Glib::ustring& report_name, const Glib::ustring& hint);
+ type_list_translatables get_translatable_print_layout_items(const Glib::ustring& table_name, const Glib::ustring& print_layout_name, const Glib::ustring& hint);
AppState m_app_state;
type_signal_userlevel_changed m_signal_userlevel_changed;
diff --git a/glom/libglom/filelist.am b/glom/libglom/filelist.am
index 1881fe9..9ca0169 100644
--- a/glom/libglom/filelist.am
+++ b/glom/libglom/filelist.am
@@ -61,6 +61,7 @@ libglom_ds_layout_headers = \
glom/libglom/data_structure/layout/layoutitem_portal.h \
glom/libglom/data_structure/layout/layoutitem_text.h \
glom/libglom/data_structure/layout/layoutitem_withformatting.h \
+ glom/libglom/data_structure/layout/static_text.h \
glom/libglom/data_structure/layout/usesrelationship.h
libglom_ds_l_report_parts_headers = \
@@ -154,6 +155,7 @@ libglom_sources = \
glom/libglom/data_structure/layout/layoutitem_portal.cc \
glom/libglom/data_structure/layout/layoutitem_text.cc \
glom/libglom/data_structure/layout/layoutitem_withformatting.cc \
+ glom/libglom/data_structure/layout/static_text.cc \
glom/libglom/data_structure/layout/usesrelationship.cc \
glom/libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.cc \
glom/libglom/data_structure/layout/report_parts/layoutitem_footer.cc \
diff --git a/tests/.gitignore b/tests/.gitignore
index 73781da..c9b8c7b 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -13,6 +13,7 @@
/test_document_load
/test_document_load_and_change
/test_document_load_and_save
+/test_document_load_image
/test_document_change
/test_document_load_translations
/test_fake_connection
diff --git a/tests/test_document_load_translations.cc b/tests/test_document_load_translations.cc
index c12d564..196bfa6 100644
--- a/tests/test_document_load_translations.cc
+++ b/tests/test_document_load_translations.cc
@@ -343,6 +343,9 @@ int main()
const bool contains_report =
contains_item_type<Glom::Report>(list_layout_items);
g_assert( contains_report );
+ const bool contains_print_layout =
+ contains_item_type<Glom::PrintLayout>(list_layout_items);
+ g_assert( contains_print_layout );
Glom::libglom_deinit();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]