[glom] Move report building code around.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Move report building code around.
- Date: Mon, 17 Oct 2011 16:27:43 +0000 (UTC)
commit c3d479cdab4101dbabb293a691651a507f5d7362
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Oct 17 18:27:32 2011 +0200
Move report building code around.
* glom/report_builder.[h|cc]: report_build(): Return the filepath,
instead of opening it in the browser.
* glom/xsl_utils[h|cc]: transform_and_open(): Rename to transform(),
returning the filepath. Also correct some ustring filepath to std::string.
* glom/utils_ui[h|cc]: Added show_report_in_browser().
* glom/frame_glom.cc: on_menu_report_selected():
* glom/mode_data/box_data_manyrecords.cc: print_layout: Adapted.
ChangeLog | 12 +++++++++
glom/frame_glom.cc | 4 ++-
glom/mode_data/box_data_manyrecords.cc | 5 +++-
glom/report_builder.cc | 8 +++---
glom/report_builder.h | 7 +++--
glom/utils_ui.cc | 39 ++++++++++++++++++++++++++++++
glom/utils_ui.h | 2 +
glom/xsl_utils.cc | 41 +++++++-------------------------
glom/xsl_utils.h | 9 +++----
9 files changed, 81 insertions(+), 46 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 0fa586b..3a77655 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2011-10-17 Murray Cumming <murrayc murrayc com>
+ Move report building code around.
+
+ * glom/report_builder.[h|cc]: report_build(): Return the filepath,
+ instead of opening it in the browser.
+ * glom/xsl_utils[h|cc]: transform_and_open(): Rename to transform(),
+ returning the filepath. Also correct some ustring filepath to std::string.
+ * glom/utils_ui[h|cc]: Added show_report_in_browser().
+ * glom/frame_glom.cc: on_menu_report_selected():
+ * glom/mode_data/box_data_manyrecords.cc: print_layout: Adapted.
+
+2011-10-17 Murray Cumming <murrayc murrayc com>
+
Move some XSLT-processing code around.
* glom/mode_data/box_data.h: Remove declaration of non-implemented
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 546aff6..7c182f3 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -2316,7 +2316,9 @@ void Frame_Glom::on_menu_report_selected(const Glib::ustring& report_name)
ReportBuilder report_builder;
report_builder.set_document(document);
- report_builder.report_build(found_set, report, get_app_window()); //TODO: Use found set's where_clause.
+ const std::string filepath =
+ report_builder.report_build(found_set, report); //TODO: Use found set's where_clause.
+ Utils::show_report_in_browser(filepath, get_app_window());
}
#ifndef GLOM_ENABLE_CLIENT_ONLY
diff --git a/glom/mode_data/box_data_manyrecords.cc b/glom/mode_data/box_data_manyrecords.cc
index 6f56f08..b8dc88d 100644
--- a/glom/mode_data/box_data_manyrecords.cc
+++ b/glom/mode_data/box_data_manyrecords.cc
@@ -23,6 +23,7 @@
#include <glom/glade_utils.h>
#include <glom/report_builder.h>
#include <glom/mode_design/layout/dialog_layout_list.h>
+#include <glom/utils_ui.h>
#include <libglom/privs.h>
#include <libglom/utils.h> //For bold_message()).
#include <sstream> //For stringstream
@@ -83,7 +84,9 @@ void Box_Data_ManyRecords::print_layout()
ReportBuilder report_builder;
report_builder.set_document(document);
- report_builder.report_build(m_found_set, report_temp, get_app_window());
+ const std::string filepath =
+ report_builder.report_build(m_found_set, report_temp);
+ Utils::show_report_in_browser(filepath, get_app_window());
}
}
diff --git a/glom/report_builder.cc b/glom/report_builder.cc
index b80fa60..832e3a5 100644
--- a/glom/report_builder.cc
+++ b/glom/report_builder.cc
@@ -484,7 +484,7 @@ void ReportBuilder::report_build_records_vertical_group(const FoundSet& found_se
}
-void ReportBuilder::report_build(const FoundSet& found_set, const sharedptr<const Report>& report, Gtk::Window* parent_window)
+std::string ReportBuilder::report_build(const FoundSet& found_set, const sharedptr<const Report>& report)
{
//Create a DOM Document with the XML:
xmlpp::DomParser dom_parser;;
@@ -566,17 +566,17 @@ void ReportBuilder::report_build(const FoundSet& found_set, const sharedptr<cons
{
//Handle database errors here rather than crashing the whole application:
handle_error(ex);
- return;
+ return std::string();
}
catch(const std::exception& ex)
{
//Handle database errors here rather than crashing the whole application:
handle_error(ex);
- return;
+ return std::string();
}
}
- GlomXslUtils::transform_and_open(*pDocument, "print_report_to_html.xsl", parent_window);
+ return GlomXslUtils::transform(*pDocument, "print_report_to_html.xsl");
}
static void fill_standard_list_report_fill(const sharedptr<Report>& report, const sharedptr<const LayoutGroup>& layout_group)
diff --git a/glom/report_builder.h b/glom/report_builder.h
index 49a6a0c..00e02b3 100644
--- a/glom/report_builder.h
+++ b/glom/report_builder.h
@@ -39,10 +39,11 @@ public:
//void set_report(const Glib::ustring& table_name, const sharedptr<const Report>& report);
//sharedptr<Report> get_report();
- void report_build(const FoundSet& found_set, const sharedptr<const Report>& report, Gtk::Window* parent_window = 0);
-
+ /**
+ * @result The filepath of the generated HTML file.
+ */
+ std::string report_build(const FoundSet& found_set, const sharedptr<const Report>& report);
-
private:
void report_build_groupby(const FoundSet& found_set_parent, xmlpp::Element& parent_node, const sharedptr<LayoutItem_GroupBy>& group_by);
diff --git a/glom/utils_ui.cc b/glom/utils_ui.cc
index d1d4408..8ea3384 100644
--- a/glom/utils_ui.cc
+++ b/glom/utils_ui.cc
@@ -49,6 +49,11 @@
#include <stack>
+// For ShellExecute:
+#ifdef G_OS_WIN32
+# include <windows.h>
+#endif
+
namespace
{
@@ -478,4 +483,38 @@ bool Utils::show_warning_no_records_found(Gtk::Window& transient_for)
}
+void Utils::show_report_in_browser(const std::string& filepath, Gtk::Window* parent_window)
+{
+ //Give the user a clue, in case the web browser opens in the background, for instance in a new tab:
+ if(parent_window)
+ show_ok_dialog(_("Report Finished"), _("The report will now be opened in your web browser."), *parent_window, Gtk::MESSAGE_INFO);
+
+#ifdef G_OS_WIN32
+ // gtk_show_uri doesn't seem to work on Win32, at least not for local files
+ // We use Windows API instead.
+ // TODO: Check it again and file a bug if necessary.
+ ShellExecute(0, "open", filepath.c_str(), 0, 0, SW_SHOW);
+#else
+
+ Glib::ustring uri;
+ try
+ {
+ uri = Glib::filename_to_uri(filepath);
+ }
+ catch(const Glib::ConvertError& ex)
+ {
+ std::cerr << G_STRFUNC << ": Could not convert filepath to URI: " << filepath << std::endl;
+ return;
+ }
+
+ //Use the GNOME browser:
+ GError* gerror = 0;
+ if(!gtk_show_uri(0 /* screen */, uri.c_str(), GDK_CURRENT_TIME, &gerror))
+ {
+ std::cerr << G_STRFUNC << ": " << gerror->message << std::endl;
+ g_error_free(gerror);
+ }
+#endif //G_OS_WIN32
+}
+
} //namespace Glom
diff --git a/glom/utils_ui.h b/glom/utils_ui.h
index 550074c..c13fb6e 100644
--- a/glom/utils_ui.h
+++ b/glom/utils_ui.h
@@ -94,6 +94,8 @@ Glib::RefPtr<Gdk::Pixbuf> image_scale_keeping_ratio(const Glib::RefPtr<Gdk::Pixb
///@result Whether the user would like to find again.
bool show_warning_no_records_found(Gtk::Window& transient_for);
+void show_report_in_browser(const std::string& filepath, Gtk::Window* parent_window);
+
} //namespace Utils
} //namespace Glom
diff --git a/glom/xsl_utils.cc b/glom/xsl_utils.cc
index 2ee52b7..bc2a31f 100644
--- a/glom/xsl_utils.cc
+++ b/glom/xsl_utils.cc
@@ -24,7 +24,6 @@
#include <libglom/connectionpool.h>
#include <libglom/data_structure/layout/report_parts/layoutitem_fieldsummary.h>
#include <libglom/data_structure/glomconversions.h>
-#include <glom/frame_glom.h>
#include <libxml++/libxml++.h>
#include <libxslt/transform.h>
//#include <libexslt/exslt.h> //For exsltRegisterAll().
@@ -41,18 +40,14 @@
#include <iostream> // for cout, endl
#include <iomanip>
-// For ShellExecute:
-#ifdef G_OS_WIN32
-# include <windows.h>
-#endif
namespace
{
- Glib::ustring get_xslt_file(const Glib::ustring& xsl_file)
+ std::string get_xslt_file(const std::string& xsl_file)
{
#ifdef G_OS_WIN32
gchar* directory = g_win32_get_package_installation_directory_of_module(0);
- Glib::ustring xsltdir = Glib::build_filename(Glib::build_filename(directory,
+ std::string xsltdir = Glib::build_filename(Glib::build_filename(directory,
"share" G_DIR_SEPARATOR_S "glom" G_DIR_SEPARATOR_S "xslt"), xsl_file);
g_free(directory);
return xsltdir;
@@ -75,7 +70,7 @@ static Glib::ustring xslt_process(const xmlpp::Document& xml_document, const std
//nonconst.write_to_stream_formatted(std::cout);
//std::cout << std::endl;
- Glib::ustring result;
+ Glib::ustring result;
//Use libxslt to transform the XML:
xmlDocPtr style = xmlReadFile(filepath_xslt.c_str(), 0, 0);
@@ -119,14 +114,14 @@ static Glib::ustring xslt_process(const xmlpp::Document& xml_document, const std
return result;
}
-void GlomXslUtils::transform_and_open(const xmlpp::Document& xml_document, const Glib::ustring& xsl_file_path, Gtk::Window* parent_window)
+std::string GlomXslUtils::transform(const xmlpp::Document& xml_document, const std::string& xsl_file_path)
{
//Use libxslt to convert the XML to HTML:
const Glib::ustring result = xslt_process(xml_document, get_xslt_file(xsl_file_path));
//std::cout << "After xslt: " << result << std::endl;
//Save it to a temporary file and show it in a browser:
- const Glib::ustring temp_path = Glib::build_filename(
+ const std::string temp_path = Glib::build_filename(
Glib::get_tmp_dir(), "glom_printout.html");
std::cout << "temp_path=" << temp_path << std::endl;
@@ -150,7 +145,7 @@ void GlomXslUtils::transform_and_open(const xmlpp::Document& xml_document, const
catch(const Gio::Error& ex)
{
// If the operation was not successful, print the error and abort
- return; // false; // print_error(ex, output_uri_string);
+ return std::string(); // print_error(ex, output_uri_string);
}
//Write the data to the output uri
@@ -163,31 +158,13 @@ void GlomXslUtils::transform_and_open(const xmlpp::Document& xml_document, const
catch(const Gio::Error& ex)
{
// If the operation was not successful, print the error and abort
- return; // false; //print_error(ex, output_uri_string);
+ return std::string(); // false; //print_error(ex, output_uri_string);
}
if(bytes_written != (gssize)result_bytes)
- return; //false
-
-
- //Give the user a clue, in case the web browser opens in the background, for instance in a new tab:
- if(parent_window)
- Frame_Glom::show_ok_dialog(_("Report Finished"), _("The report will now be opened in your web browser."), *parent_window, Gtk::MESSAGE_INFO);
+ return std::string(); //false
-#ifdef G_OS_WIN32
- // gtk_show_uri doesn't seem to work on Win32, at least not for local files
- // We use Windows API instead.
- // TODO: Check it again and file a bug if necessary.
- ShellExecute(0, "open", file->get_path().c_str(), 0, 0, SW_SHOW);
-#else
- //Use the GNOME browser:
- GError* gerror = 0;
- if(!gtk_show_uri(0 /* screen */, file->get_uri().c_str(), GDK_CURRENT_TIME, &gerror))
- {
- std::cerr << G_STRFUNC << ": " << gerror->message << std::endl;
- g_error_free(gerror);
- }
-#endif //G_OS_WIN32
+ return file->get_path();
}
} //namespace Glom
diff --git a/glom/xsl_utils.h b/glom/xsl_utils.h
index a497733..2f7741d 100644
--- a/glom/xsl_utils.h
+++ b/glom/xsl_utils.h
@@ -27,10 +27,6 @@
#include <libglom/data_structure/layout/layoutitem_field.h>
#include <libxml++/libxml++.h>
-namespace Gtk
-{
- class Window;
-}
namespace Glom
{
@@ -42,7 +38,10 @@ typedef std::list<type_pair_sort_field> type_sort_clause;
namespace GlomXslUtils
{
-void transform_and_open(const xmlpp::Document& xml_document, const Glib::ustring& xsl_file_path, Gtk::Window* parent_window = 0);
+/**
+ * @result the filepath of the generated HTML file.
+ */
+std::string transform(const xmlpp::Document& xml_document, const std::string& xsl_file_path);
} //namespace GlomXslUtils
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]