[glom] Details: Print: Use a standard print layout instead of HTML.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Details: Print: Use a standard print layout instead of HTML.
- Date: Tue, 4 Oct 2011 08:31:03 +0000 (UTC)
commit 2e34e628296c413b00b1a8c95189f72b95a3fc40
Author: Murray Cumming <murrayc murrayc com>
Date: Tue Oct 4 10:30:50 2011 +0200
Details: Print: Use a standard print layout instead of HTML.
* glom/frame_glom.[h|cc]: Add a do_print_layout() that takes a PrintLayout
instead of just a print layout name.
* glom/application.[h|cc]: Add a do_print_layout() that forwards to
Frame_Glom.
* glom/mode_data/box_data_details.[h|cc]: print_layout(): Instead of
generating HTML and showing it in a browser, create a standard print layout
and offer it via a normal printing dialog. This is at least as good (not
very good yet) as our generated HTML, but simpler and more normal.
Remove any code that used the old XML+XSLT=HTML way for details.
We still use the generated HTML for the list view, as if it was just another
report. Maybe we can improve that in future too.
ChangeLog | 17 ++++++
glom/application.cc | 6 ++
glom/application.h | 1 +
glom/frame_glom.cc | 19 +++++--
glom/frame_glom.h | 1 +
glom/mode_data/box_data_details.cc | 110 ++++++++---------------------------
glom/mode_data/box_data_details.h | 2 -
glom/mode_data/notebook_data.cc | 2 +-
8 files changed, 65 insertions(+), 93 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 5e473af..5dcf0b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,22 @@
2011-10-04 Murray Cumming <murrayc murrayc com>
+ Details: Print: Use a standard print layout instead of HTML.
+
+ * glom/frame_glom.[h|cc]: Add a do_print_layout() that takes a PrintLayout
+ instead of just a print layout name.
+ * glom/application.[h|cc]: Add a do_print_layout() that forwards to
+ Frame_Glom.
+ * glom/mode_data/box_data_details.[h|cc]: print_layout(): Instead of
+ generating HTML and showing it in a browser, create a standard print layout
+ and offer it via a normal printing dialog. This is at least as good (not
+ very good yet) as our generated HTML, but simpler and more normal.
+ Remove any code that used the old XML+XSLT=HTML way for details.
+
+ We still use the generated HTML for the list view, as if it was just another
+ report. Maybe we can improve that in future too.
+
+2011-10-04 Murray Cumming <murrayc murrayc com>
+
Print Layout: Move create_standard() into a utils file.
* glom/mode_design/print_layouts/window_print_layout_edit.[h|cc]: Move
diff --git a/glom/application.cc b/glom/application.cc
index 750a901..749150e 100644
--- a/glom/application.cc
+++ b/glom/application.cc
@@ -2769,6 +2769,12 @@ void Application::do_print_layout(const Glib::ustring& print_layout_name, bool p
m_pFrame->do_print_layout(print_layout_name, preview, transient_for);
}
+void Application::do_print_layout(const sharedptr<const PrintLayout>& print_layout, bool preview, Gtk::Window* transient_for)
+{
+ m_pFrame->do_print_layout(print_layout, preview, transient_for);
+}
+
+
bool Application::do_restore_backup(const Glib::ustring& backup_uri)
{
// We cannot use an uri here, because we cannot untar remote files.
diff --git a/glom/application.h b/glom/application.h
index 09780fe..2481861 100644
--- a/glom/application.h
+++ b/glom/application.h
@@ -97,6 +97,7 @@ public:
void do_menu_developer_fields(Gtk::Window& parent, const Glib::ustring table_name);
void do_menu_developer_relationships(Gtk::Window& parent, const Glib::ustring table_name);
void do_print_layout(const Glib::ustring& print_layout_name, bool preview = false, Gtk::Window* transient_for = 0);
+ void do_print_layout(const sharedptr<const PrintLayout>& print_layout, bool preview = false, Gtk::Window* transient_for = 0);
bool do_restore_backup(const Glib::ustring& backup_uri);
#endif //GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index ff5e1e7..9222ff3 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -2325,6 +2325,20 @@ void Frame_Glom::on_menu_print_layout_selected(const Glib::ustring& print_layout
void Frame_Glom::do_print_layout(const Glib::ustring& print_layout_name, bool preview, Gtk::Window* transient_for)
{
+ Document* document = get_document();
+ sharedptr<PrintLayout> print_layout = document->get_print_layout(m_table_name, print_layout_name);
+
+ do_print_layout(print_layout, preview, transient_for);
+}
+
+void Frame_Glom::do_print_layout(const sharedptr<const PrintLayout>& print_layout, bool preview, Gtk::Window* transient_for)
+{
+ if(!print_layout)
+ {
+ std::cerr << G_STRFUNC << ": print_layout was null" << std::endl;
+ return;
+ }
+
const Privileges table_privs = Privs::get_current_privs(m_table_name);
//Don't try to print tables that the user can't view.
@@ -2334,11 +2348,6 @@ void Frame_Glom::do_print_layout(const Glib::ustring& print_layout_name, bool pr
return;
}
- Document* document = get_document();
- sharedptr<PrintLayout> print_layout = document->get_print_layout(m_table_name, print_layout_name);
- if(!print_layout)
- return;
-
Canvas_PrintLayout canvas;
add_view(&canvas); //So it has access to the document.
canvas.set_print_layout(m_table_name, print_layout);
diff --git a/glom/frame_glom.h b/glom/frame_glom.h
index 40288cc..4d2568d 100644
--- a/glom/frame_glom.h
+++ b/glom/frame_glom.h
@@ -71,6 +71,7 @@ public:
void set_databases_selected(const Glib::ustring& strName);
void do_print_layout(const Glib::ustring& print_layout_name, bool preview = false, Gtk::Window* transient_for = 0);
+ void do_print_layout(const sharedptr<const PrintLayout>& print_layout, bool preview, Gtk::Window* transient_for = 0);
void on_box_tables_selected(const Glib::ustring& strName);
diff --git a/glom/mode_data/box_data_details.cc b/glom/mode_data/box_data_details.cc
index 8bfb30a..b402685 100644
--- a/glom/mode_data/box_data_details.cc
+++ b/glom/mode_data/box_data_details.cc
@@ -31,6 +31,8 @@
#include <libglom/privs.h>
#include <glom/xsl_utils.h>
#include <glom/python_embed/glom_python.h>
+#include <glom/print_layout_utils.h>
+#include <glom/application.h>
#include <sstream> //For stringstream
#include <glibmm/i18n.h>
@@ -906,99 +908,37 @@ sharedptr<Field> Box_Data_Details::get_field_primary_key() const
return m_field_primary_key;
}
-void Box_Data_Details::print_layout_group(xmlpp::Element* node_parent, const sharedptr<const LayoutGroup>& group)
-{
- xmlpp::Element* nodeChildGroup = node_parent->add_child("group");
- nodeChildGroup->set_attribute("title", group->get_title());
-
- LayoutGroup::type_list_const_items items = group->get_items();
- for(LayoutGroup::type_list_const_items::const_iterator iter = items.begin(); iter != items.end(); ++iter)
- {
- sharedptr<const LayoutItem> layout_item = *iter;
-
- sharedptr<const LayoutGroup> pLayoutGroup = sharedptr<const LayoutGroup>::cast_dynamic(layout_item);
- if(pLayoutGroup)
- print_layout_group(nodeChildGroup, pLayoutGroup); //recurse
- else
- {
- sharedptr<const LayoutItem_Field> pLayoutField = sharedptr<const LayoutItem_Field>::cast_dynamic(layout_item);
- if(pLayoutField)
- {
- xmlpp::Element* nodeField = nodeChildGroup->add_child("field");
-
- nodeField->set_attribute("title", pLayoutField->get_title_or_name());
-
- Gnome::Gda::Value value = m_FlowTable.get_field_value(pLayoutField);
- const Glib::ustring text_representation = Conversions::get_text_for_gda_value(pLayoutField->get_glom_type(), value,
- pLayoutField->get_formatting_used().m_numeric_format); //In the current locale.
-
- nodeField->set_attribute("value", text_representation);
- }
- else
- {
- sharedptr<const LayoutItem_Portal> pLayoutPortal = sharedptr<const LayoutItem_Portal>::cast_dynamic(layout_item);
- if(pLayoutPortal)
- {
- xmlpp::Element* nodePortal = nodeChildGroup->add_child("related_records");
-
- //Box_Data_List_Related* pPortalWidget = m_FlowTable.get_portals();
-
- sharedptr<Relationship> relationship = get_document()->get_relationship(m_table_name, pLayoutPortal->get_relationship_name());
- if(relationship)
- {
- nodePortal->set_attribute("title", relationship->get_title_or_name());
-
- //TODO:
-
- //TODO: Only print this if the user has access rights.
- }
- }
- }
- }
- }
-
-}
-
void Box_Data_Details::print_layout()
{
- const Privileges table_privs = Privs::get_current_privs(m_table_name);
+ const Privileges table_privs = Privs::get_current_privs(m_table_name);
//Don't try to print tables that the user can't view.
if(!table_privs.m_view)
+ return; //TODO: Warn the user.
+
+ const Document* document = dynamic_cast<const Document*>(get_document());
+ if(!document)
{
- //TODO: Warn the user.
+ std::cerr << G_STRFUNC << ": document was null" << std::endl;
+ return;
}
- else
- {
- //Create a DOM Document with the XML:
- xmlpp::DomParser dom_parser;;
-
- xmlpp::Document* pDocument = dom_parser.get_document();
- xmlpp::Element* nodeRoot = pDocument->get_root_node();
- if(!nodeRoot)
- {
- //Add it if it isn't there already:
- nodeRoot = pDocument->create_root_node("details_print");
- }
-
- Glib::ustring table_title = get_document()->get_table_title(m_table_name);
- if(table_title.empty())
- table_title = m_table_name;
- nodeRoot->set_attribute("table", table_title);
-
-
- //The groups:
- xmlpp::Element* nodeParent = nodeRoot;
-
- const Document::type_list_layout_groups layout_groups = get_data_layout_groups(m_layout_name, m_layout_platform);
- for(Document::type_list_layout_groups::const_iterator iter = layout_groups.begin(); iter != layout_groups.end(); ++iter)
- {
- sharedptr<const LayoutGroup> layout_group = *iter;
- print_layout_group(nodeParent, layout_group);
- }
-
- GlomXslUtils::transform_and_open(*pDocument, "print_details_to_html.xsl", get_app_window());
+ Glib::RefPtr<Gtk::PageSetup> page_setup = Gtk::PageSetup::create(); //TODO: m_canvas.get_page_setup();
+ if(!page_setup)
+ {
+ std::cerr << G_STRFUNC << ": page_setup was null" << std::endl;
+ return;
+ }
+
+ sharedptr<PrintLayout> print_layout =
+ PrintLayoutUtils::create_standard(page_setup, m_table_name, document);
+
+ //Show the print preview window:
+ Application* app = Application::get_application();
+ if(app)
+ {
+ app->do_print_layout(print_layout,
+ false /* print, not preview*/, app);
}
}
diff --git a/glom/mode_data/box_data_details.h b/glom/mode_data/box_data_details.h
index ab36196..3ab145d 100644
--- a/glom/mode_data/box_data_details.h
+++ b/glom/mode_data/box_data_details.h
@@ -92,8 +92,6 @@ protected:
virtual sharedptr<Field> get_field_primary_key() const;
void set_found_set_from_primary_key_value();
- void print_layout_group(xmlpp::Element* node_parent, const sharedptr<const LayoutGroup>& group);
-
private:
//Signal handlers:
void on_button_new();
diff --git a/glom/mode_data/notebook_data.cc b/glom/mode_data/notebook_data.cc
index 52a0b22..d563c4f 100644
--- a/glom/mode_data/notebook_data.cc
+++ b/glom/mode_data/notebook_data.cc
@@ -306,7 +306,7 @@ void Notebook_Data::show_layout_toolbar(bool show)
void Notebook_Data::do_menu_file_print()
{
- int iPageCurrent = get_current_page();
+ const int iPageCurrent = get_current_page();
Gtk::Widget* pChild = get_nth_page(iPageCurrent);
if(pChild)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]