26 #include <glib/gi18n.h> 28 #include "dialog-report-style-sheet.h" 32 #include "gnc-guile-utils.h" 34 #include "gnc-plugin-report-system.h" 36 #include "gnc-report.h" 38 #include "window-report.h" 40 static void gnc_plugin_report_system_finalize (GObject *
object);
44 static void gnc_plugin_report_system_cmd_edit_style_sheet (GSimpleAction *simple, GVariant *parameter, gpointer user_data);
47 #define PLUGIN_ACTIONS_NAME "gnc-plugin-report-system-actions" 48 #define PLUGIN_UI_FILENAME "gnc-plugin-report-system.ui" 50 static GActionEntry gnc_plugin_actions [] =
52 {
"EditStyleSheetsAction", gnc_plugin_report_system_cmd_edit_style_sheet, NULL, NULL, NULL },
55 static guint gnc_plugin_n_actions = G_N_ELEMENTS (gnc_plugin_actions);
58 static const gchar *gnc_plugin_load_ui_items [] =
69 G_DEFINE_TYPE(GncPluginReportSystem, gnc_plugin_report_system, GNC_TYPE_PLUGIN)
76 gnc_plugin_report_system_class_init (GncPluginReportSystemClass *klass)
78 GObjectClass *object_class = G_OBJECT_CLASS (klass);
79 GncPluginClass *plugin_class = GNC_PLUGIN_CLASS (klass);
81 object_class->finalize = gnc_plugin_report_system_finalize;
84 plugin_class->plugin_name = GNC_PLUGIN_REPORT_SYSTEM_NAME;
88 plugin_class->actions = gnc_plugin_actions;
89 plugin_class->n_actions = gnc_plugin_n_actions;
91 plugin_class->ui_updates = gnc_plugin_load_ui_items;
95 gnc_plugin_report_system_init (GncPluginReportSystem *plugin)
100 gnc_plugin_report_system_finalize (GObject *
object)
102 g_return_if_fail (GNC_IS_PLUGIN_REPORT_SYSTEM (
object));
104 G_OBJECT_CLASS (gnc_plugin_report_system_parent_class)->finalize (
object);
112 gnc_plugin_report_system_cmd_edit_style_sheet (GSimpleAction *simple,
117 gnc_style_sheet_dialog_open (GTK_WINDOW(data->window));
125 gnc_report_system_file_stream_cb (
const char *location,
char ** data,
int *len)
132 html_sanitize (
const char *str)
134 g_return_val_if_fail (str, NULL);
135 GString *gs = g_string_sized_new (strlen (str));
136 for (
const char *c = str; *c; c++)
139 gs = g_string_append (gs,
"&");
141 gs = g_string_append (gs,
"<");
143 gs = g_string_append (gs,
">");
145 gs = g_string_append_c (gs, *c);
147 return g_string_free (gs, FALSE);
151 gnc_report_system_report_stream_cb (
const char *location,
char ** data,
int *len)
153 gchar *captured_str = NULL;
155 gnc_run_report_id_string_with_error_handling (location, data,
160 char *sanitized = html_sanitize (captured_str);
161 *data = g_strdup_printf (
"<html><body><h3>%s</h3>" 162 "<p>%s</p><pre>%s</pre></body></html>",
164 _(
"An error occurred while running the report."),
168 g_free(captured_str);
174 scm_c_eval_string(
"(gnc:report-finished)");
177 *len = strlen(*data);
183 gnc_report_system_options_url_cb (
const char *location,
const char *label,
189 g_return_val_if_fail (location != NULL, FALSE);
190 g_return_val_if_fail (result != NULL, FALSE);
192 result->load_to_stream = FALSE;
195 if (strncmp (
"report-id=", location, 10) == 0)
197 if (sscanf (location + 10,
"%d", &report_id) != 1)
199 result->error_message =
200 g_strdup_printf (_(
"Badly formed options URL: %s"), location);
205 report = gnc_report_find(report_id);
206 if (report == SCM_UNDEFINED ||
207 report == SCM_BOOL_F)
209 result->error_message =
210 g_strdup_printf (_(
"Badly-formed report id: %s"), location);
215 gnc_report_edit_options (report, GTK_WINDOW(result->parent));
221 result->error_message =
222 g_strdup_printf (_(
"Badly formed options URL: %s"), location);
229 gnc_report_system_report_url_cb (
const char *location,
const char *label,
232 g_return_val_if_fail (location != NULL, FALSE);
233 g_return_val_if_fail (result != NULL, FALSE);
240 url = gnc_build_url (URL_TYPE_REPORT, location, label);
241 gnc_main_window_open_report_url (url, GNC_MAIN_WINDOW(result->parent));
244 result->load_to_stream = FALSE;
248 result->load_to_stream = TRUE;
255 gnc_report_system_help_url_cb (
const char *location,
const char *label,
258 g_return_val_if_fail (location != NULL, FALSE);
260 if (label && (*label !=
'\0'))
273 gnc_plugin_report_system_new (
void)
279 GNC_TYPE_PLUGIN_PAGE_REPORT;
282 gnc_html_register_stream_handler (URL_TYPE_HELP, gnc_report_system_file_stream_cb);
283 gnc_html_register_stream_handler (URL_TYPE_FILE, gnc_report_system_file_stream_cb);
284 gnc_html_register_stream_handler (URL_TYPE_REPORT, gnc_report_system_report_stream_cb);
286 gnc_html_register_url_handler (URL_TYPE_OPTIONS, gnc_report_system_options_url_cb);
287 gnc_html_register_url_handler (URL_TYPE_REPORT, gnc_report_system_report_url_cb);
288 gnc_html_register_url_handler (URL_TYPE_HELP, gnc_report_system_help_url_cb);
290 scm_c_use_module(
"gnucash reports");
291 scm_c_use_module(
"gnucash report-menus");
292 scm_c_eval_string(
"(gnc:report-menu-setup)");
294 plugin = GNC_PLUGIN (g_object_new (GNC_TYPE_PLUGIN_REPORT_SYSTEM, NULL));
Plugin management functions for the GnuCash UI.
void gnc_plugin_manager_add_plugin(GncPluginManager *manager, GncPlugin *plugin)
Add a plugin to the list maintained by the plugin manager.
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome's yelp for linux, and open to a given link within a gi...
GncPluginManager * gnc_plugin_manager_get(void)
Retrieve a pointer to the plugin manager.
Gnome specific utility functions.
All type declarations for the whole Gnucash engine.
Utility functions for file access.
#define PLUGIN_ACTIONS_NAME
The label given to the main window for this plugin.
#define PLUGIN_UI_FILENAME
The name of the UI description file for this plugin.
int gncReadFile(const char *filename, char **data)
Reads the contents of a file into a buffer for further processing.