43 #include <glib/gi18n.h>
44 #include <glib/gstdio.h>
51 #include "gnc-component-manager.h"
54 #include "gnc-guile-utils.h"
55 #include "gnc-html-history.h"
57 #include "gnc-html-factory.h"
63 #include "gnc-report.h"
64 #include "gnc-session.h"
68 #include "option-util.h"
69 #include "window-report.h"
70 #include "swig-runtime.h"
71 #include "app-utils/business-options.h"
72 #include "gnome-utils/gnc-icons.h"
75 #define WINDOW_REPORT_CM_CLASS "window-report"
83 static GObjectClass *parent_class = NULL;
89 static GHashTable *static_report_printnames = NULL;
102 gint component_manager_id;
108 SCM option_change_cb_id;
115 SCM name_change_cb_id;
122 gboolean need_reload;
135 #define GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(o) \
136 (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_PLUGIN_PAGE_REPORT, GncPluginPageReportPrivate))
140 static GObject *gnc_plugin_page_report_constructor(GType this_type, guint n_properties, GObjectConstructParam *properties);
141 static void gnc_plugin_page_report_finalize (GObject *
object);
142 static void gnc_plugin_page_report_setup(
GncPluginPage *ppage );
144 static void gnc_plugin_page_report_constr_init(
GncPluginPageReport *plugin_page, gint reportId);
146 static GtkWidget* gnc_plugin_page_report_create_widget(
GncPluginPage *plugin_page );
147 static void gnc_plugin_page_report_destroy_widget(
GncPluginPage *plugin_page );
148 static void gnc_plugin_page_report_save_page (
GncPluginPage *plugin_page, GKeyFile *file,
const gchar *group);
149 static GncPluginPage *gnc_plugin_page_report_recreate_page (GtkWidget *window, GKeyFile *file,
const gchar *group);
150 static void gnc_plugin_page_report_name_changed (
GncPluginPage *page,
const gchar *name);
151 static void gnc_plugin_page_report_update_edit_menu (
GncPluginPage *page, gboolean hide);
152 static gboolean gnc_plugin_page_report_finish_pending (
GncPluginPage *page);
154 static int gnc_plugin_page_report_check_urltype(URLType t);
156 static void gnc_plugin_page_report_load_cb(
GncHtml * html, URLType type,
157 const gchar * location,
const gchar * label,
159 static void gnc_plugin_page_report_expose_event_cb(GtkWidget *unused, GdkEventExpose *unused1, gpointer data);
160 static void gnc_plugin_page_report_refresh (gpointer data);
161 static void gnc_plugin_page_report_set_fwd_button(
GncPluginPageReport * page,
int enabled);
162 static void gnc_plugin_page_report_set_back_button(
GncPluginPageReport * page,
int enabled);
163 static void gnc_plugin_page_report_history_destroy_cb(
gnc_html_history_node * node, gpointer user_data);
164 static void close_handler(gpointer user_data);
166 static void gnc_plugin_page_report_option_change_cb(gpointer data);
170 void gnc_plugin_page_report_raise_editor(SCM report);
177 static void gnc_plugin_page_report_save_as_cb(GtkAction *action,
GncPluginPageReport *rep);
179 static void gnc_plugin_page_report_options_cb(GtkAction *action,
GncPluginPageReport *rep);
181 static void gnc_plugin_page_report_exportpdf_cb(GtkAction *action,
GncPluginPageReport *rep);
187 static GType gnc_plugin_page_report_type = 0;
189 if (gnc_plugin_page_report_type == 0)
191 static const GTypeInfo our_info =
196 (GClassInitFunc) gnc_plugin_page_report_class_init,
201 (GInstanceInitFunc) gnc_plugin_page_report_init
204 gnc_plugin_page_report_type = g_type_register_static (GNC_TYPE_PLUGIN_PAGE,
205 "GncPluginPageReport",
209 return gnc_plugin_page_report_type;
213 gnc_plugin_page_report_get_property( GObject *obj,
221 rep = GNC_PLUGIN_PAGE_REPORT( obj );
222 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(rep);
227 g_value_set_int( value, priv->
reportId );
230 PERR(
"Unknown property id %d", prop_id );
236 gnc_plugin_page_report_set_property( GObject *obj,
244 rep = GNC_PLUGIN_PAGE_REPORT( obj );
245 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(rep);
247 DEBUG(
"setting property with id %d / %p to value %d",
248 prop_id, priv, g_value_get_int( value ) );
253 priv->
reportId = g_value_get_int( value );
256 PERR(
"unknown property id %d", prop_id );
265 GObjectClass *object_class = G_OBJECT_CLASS (klass);
268 parent_class = g_type_class_peek_parent (klass);
270 object_class->constructor = gnc_plugin_page_report_constructor;
271 object_class->finalize = gnc_plugin_page_report_finalize;
273 object_class->set_property = gnc_plugin_page_report_set_property;
274 object_class->get_property = gnc_plugin_page_report_get_property;
278 gnc_plugin_page_class->
plugin_name = GNC_PLUGIN_PAGE_REPORT_NAME;
280 gnc_plugin_page_class->
create_widget = gnc_plugin_page_report_create_widget;
281 gnc_plugin_page_class->
destroy_widget = gnc_plugin_page_report_destroy_widget;
282 gnc_plugin_page_class->
save_page = gnc_plugin_page_report_save_page;
283 gnc_plugin_page_class->
recreate_page = gnc_plugin_page_report_recreate_page;
286 gnc_plugin_page_class->
finish_pending = gnc_plugin_page_report_finish_pending;
291 g_object_class_install_property( object_class,
293 g_param_spec_int(
"report-id",
294 _(
"The numeric ID of the report."),
295 _(
"The numeric ID of the report."),
296 -1, G_MAXINT, -1, G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE ) );
311 if (!static_report_printnames)
312 static_report_printnames = g_hash_table_new_full(g_str_hash,
313 g_str_equal, g_free, NULL);
317 gnc_plugin_page_report_finalize (GObject *
object)
319 g_return_if_fail (GNC_IS_PLUGIN_PAGE_REPORT (
object));
321 ENTER(
"object %p",
object);
322 G_OBJECT_CLASS (parent_class)->finalize (
object);
336 char * url_location = NULL;
337 char * url_label = NULL;
339 ENTER(
"page %p", page);
341 report = GNC_PLUGIN_PAGE_REPORT(page);
342 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
346 priv->
html = gnc_html_factory_create_html();
347 gnc_html_set_parent( priv->
html, topLvl );
349 gnc_html_history_set_node_destroy_cb(gnc_html_get_history(priv->
html),
350 gnc_plugin_page_report_history_destroy_cb,
353 priv->
container = GTK_CONTAINER(gtk_frame_new(NULL));
354 gtk_frame_set_shadow_type(GTK_FRAME(priv->
container), GTK_SHADOW_NONE);
356 gtk_container_add(GTK_CONTAINER(priv->
container),
357 gnc_html_get_widget(priv->
html));
359 priv->component_manager_id =
360 gnc_register_gui_component(WINDOW_REPORT_CM_CLASS, NULL,
361 close_handler, page);
362 gnc_gui_component_set_session(priv->component_manager_id,
363 gnc_get_current_session());
365 gnc_html_set_urltype_cb(priv->
html, gnc_plugin_page_report_check_urltype);
366 gnc_html_set_load_cb(priv->
html, gnc_plugin_page_report_load_cb, report);
370 id_name = g_strdup_printf(
"id=%d", priv->
reportId );
371 child_name = gnc_build_url( URL_TYPE_REPORT, id_name, NULL );
372 type = gnc_html_parse_url( priv->
html, child_name, &url_location, &url_label);
373 DEBUG(
"passing id_name=[%s] child_name=[%s] type=[%s], location=[%s], label=[%s]",
374 id_name, child_name ? child_name :
"(null)",
375 type ? type :
"(null)", url_location ? url_location :
"(null)",
376 url_label ? url_label :
"(null)" );
380 gnc_window_set_progressbar_window( GNC_WINDOW(page->
window) );
381 gnc_html_show_url(priv->
html, type, url_location, url_label, 0);
382 g_free(url_location);
383 gnc_window_set_progressbar_window( NULL );
385 g_signal_connect(priv->
container,
"expose_event",
386 G_CALLBACK(gnc_plugin_page_report_expose_event_cb), report);
388 gtk_widget_show_all( GTK_WIDGET(priv->
container) );
400 gnc_plugin_page_report_check_urltype(URLType t)
402 if (!g_strcmp0 (t, URL_TYPE_REPORT))
421 SCM set_needs_save = scm_c_eval_string(
"gnc:report-set-needs-save?!");
425 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
427 priv->initial_report = SCM_BOOL_F;
428 priv->edited_reports = SCM_EOL;
429 priv->name_change_cb_id = SCM_BOOL_F;
431 g_object_get( ppage,
"report-id", &report_id, NULL );
433 PINFO(
"report-id: %d\n", report_id);
437 if ((inst_report = gnc_report_find(report_id)) == SCM_BOOL_F)
442 if (priv->initial_report == SCM_BOOL_F)
444 priv->initial_report = inst_report;
445 scm_gc_protect_object(priv->initial_report);
449 PINFO(
"set needs save");
450 scm_call_2(set_needs_save, inst_report, SCM_BOOL_T);
459 gnc_plugin_page_report_load_cb(
GncHtml * html, URLType type,
460 const gchar * location,
const gchar * label,
466 SCM get_options = scm_c_eval_string(
"gnc:report-options");
467 SCM set_needs_save = scm_c_eval_string(
"gnc:report-set-needs-save?!");
470 ENTER(
"load_cb: type=[%s], location=[%s], label=[%s]",
471 type ? type :
"(null)", location ? location :
"(null)",
472 label ? label :
"(null)" );
477 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
478 if (!g_strcmp0 (type, URL_TYPE_REPORT)
480 && (strlen(location) > 3)
481 && !strncmp(
"id=", location, 3))
483 report_id = atoi(location + 3);
484 DEBUG(
"parsed id=%d", report_id );
486 else if (!g_strcmp0( type, URL_TYPE_OPTIONS)
488 && (strlen(location) > 10)
489 && !strncmp(
"report-id=", location, 10))
491 report_id = atoi(location + 10);
492 inst_report = gnc_report_find(report_id);
493 if (inst_report != SCM_BOOL_F)
495 gnc_plugin_page_report_add_edited_report(priv, inst_report);
502 LEAVE(
" unknown URL type [%s] location [%s]", type, location );
508 if ((inst_report = gnc_report_find(report_id)) == SCM_BOOL_F)
510 LEAVE(
"error getting inst_report" );
514 if (priv->initial_report == SCM_BOOL_F)
516 priv->initial_report = inst_report;
517 scm_gc_protect_object(priv->initial_report);
519 DEBUG(
"calling set_needs_save for report with id=%d", report_id);
520 scm_call_2(set_needs_save, inst_report, SCM_BOOL_T);
522 priv->initial_odb = gnc_option_db_new(scm_call_1(get_options, inst_report));
523 priv->name_change_cb_id =
524 gnc_option_db_register_change_callback(priv->initial_odb,
525 gnc_plugin_page_report_refresh,
527 "General",
"Report name");
532 gnc_option_db_unregister_change_callback_id(priv->
cur_odb,
533 priv->option_change_cb_id);
534 gnc_option_db_destroy(priv->
cur_odb);
543 priv->
cur_odb = gnc_option_db_new(scm_call_1(get_options, inst_report));
544 priv->option_change_cb_id =
545 gnc_option_db_register_change_callback(priv->
cur_odb,
546 gnc_plugin_page_report_option_change_cb,
549 if (gnc_html_history_forward_p(gnc_html_get_history(priv->
html)))
551 gnc_plugin_page_report_set_fwd_button(report, TRUE);
555 gnc_plugin_page_report_set_fwd_button(report, FALSE);
558 if (gnc_html_history_back_p(gnc_html_get_history(priv->
html)))
560 gnc_plugin_page_report_set_back_button(report, TRUE);
564 gnc_plugin_page_report_set_back_button(report, FALSE);
583 gnc_plugin_page_report_option_change_cb(gpointer data)
587 SCM dirty_report = scm_c_eval_string(
"gnc:report-set-dirty?!");
588 const gchar *old_name;
590 gchar *new_name_escaped;
592 g_return_if_fail(GNC_IS_PLUGIN_PAGE_REPORT(data));
593 report = GNC_PLUGIN_PAGE_REPORT(data);
594 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
596 DEBUG(
"option_change" );
599 DEBUG(
"set-dirty, queue-draw" );
603 new_name = gnc_option_db_lookup_string_option(priv->
cur_odb,
"General",
604 "Report name", NULL);
605 if (strcmp(old_name, new_name) != 0)
608 new_name_escaped = g_strescape(new_name,NULL);
609 ENTER(
"Escaped new report name: %s", new_name_escaped);
611 g_free(new_name_escaped);
616 scm_call_2(dirty_report, priv->
cur_report, SCM_BOOL_T);
619 priv->need_reload = TRUE;
621 gtk_widget_queue_draw( GTK_WIDGET(priv->
container) );
623 gnc_html_reload( priv->
html );
632 static SCM remover = SCM_BOOL_F;
635 if (remover == SCM_BOOL_F)
637 remover = scm_c_eval_string(
"gnc:report-remove-by-id");
641 && !g_strcmp0 (node->type, URL_TYPE_REPORT)\
642 && !strncmp(
"id=", node->location, 3))
644 sscanf(node->location + 3,
"%d", &report_id);
657 gnc_plugin_page_report_expose_event_cb(GtkWidget *unused, GdkEventExpose *unused1, gpointer data)
662 g_return_if_fail(GNC_IS_PLUGIN_PAGE_REPORT(page));
664 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(page);
665 ENTER(
"report_draw" );
666 if (!priv->need_reload)
668 LEAVE(
"no reload needed" );
672 priv->need_reload = FALSE;
673 gnc_window_set_progressbar_window( GNC_WINDOW(GNC_PLUGIN_PAGE(page)->window) );
674 gnc_html_reload(priv->
html);
675 gnc_window_set_progressbar_window( NULL );
676 LEAVE(
"reload forced" );
681 gnc_plugin_page_report_refresh(gpointer data)
684 DEBUG(
"report-refresh called" );
690 gnc_plugin_page_report_destroy_widget(
GncPluginPage *plugin_page)
696 PINFO(
"destroy widget");
697 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(plugin_page);
699 if (priv->component_manager_id)
701 gnc_unregister_gui_component(priv->component_manager_id);
702 priv->component_manager_id = 0;
705 gnc_plugin_page_report_destroy(priv);
706 gnc_report_remove_by_id(priv->
reportId);
712 #define SCHEME_OPTIONS "SchemeOptions"
713 #define SCHEME_OPTIONS_N "SchemeOptions%d"
726 gnc_plugin_page_report_save_page (
GncPluginPage *plugin_page,
728 const gchar *group_name)
732 SCM gen_save_text, scm_text;
733 SCM get_embedded_list, embedded, item, tmp_report;
736 gchar *text, *key_name;
738 g_return_if_fail (GNC_IS_PLUGIN_PAGE_REPORT(plugin_page));
739 g_return_if_fail (key_file != NULL);
740 g_return_if_fail (group_name != NULL);
742 ENTER(
"page %p, key_file %p, group_name %s", plugin_page, key_file,
745 report = GNC_PLUGIN_PAGE_REPORT(plugin_page);
746 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
751 LEAVE(
"not saving invalid report");
755 gen_save_text = scm_c_eval_string(
"gnc:report-serialize");
756 get_embedded_list = scm_c_eval_string(
"gnc:report-embedded-list");
757 get_options = scm_c_eval_string(
"gnc:report-options");
758 embedded = scm_call_1(get_embedded_list, scm_call_1(get_options, priv->
cur_report));
759 count = scm_ilength(embedded);
762 item = SCM_CAR(embedded);
763 embedded = SCM_CDR(embedded);
764 if (!scm_is_number(item))
766 id = scm_to_int (item);
767 tmp_report = gnc_report_find(
id);
768 scm_text = scm_call_1(gen_save_text, tmp_report);
769 if (!scm_is_string (scm_text))
771 DEBUG(
"child report %d: nothing to save",
id);
775 key_name = g_strdup_printf(SCHEME_OPTIONS_N,
id);
776 text = gnc_scm_strip_comments(scm_text);
777 g_key_file_set_value(key_file, group_name, key_name, text);
782 scm_text = scm_call_1(gen_save_text, priv->
cur_report);
783 if (!scm_is_string (scm_text))
785 LEAVE(
"nothing to save");
789 text = gnc_scm_strip_comments(scm_text);
806 gnc_plugin_page_report_recreate_page (GtkWidget *window,
808 const gchar *group_name)
813 GError *error = NULL;
814 gchar *option_string;
816 SCM scm_id, final_id = SCM_BOOL_F;
819 g_return_val_if_fail(key_file, NULL);
820 g_return_val_if_fail(group_name, NULL);
821 ENTER(
"key_file %p, group_name %s", key_file, group_name);
823 keys = g_key_file_get_keys(key_file, group_name, &num_keys, &error);
826 g_warning(
"error reading group %s key list: %s",
827 group_name, error->message);
833 for (i = 0; i < num_keys; i++)
837 option_string = g_key_file_get_value(key_file, group_name,
841 g_warning(
"error reading group %s key %s: %s",
842 group_name, keys[i], error->message);
848 scm_id = scm_c_eval_string(option_string);
849 g_free(option_string);
851 if (!scm_integer_p(scm_id))
853 DEBUG(
"report id not an integer for key %s", keys[i]);
857 if (final_id == SCM_BOOL_F)
866 if (final_id == SCM_BOOL_F)
868 LEAVE(
"report not specified");
872 report_id = scm_to_int(final_id);
873 report = gnc_report_find(report_id);
876 LEAVE(
"report doesn't exist");
898 gnc_plugin_page_report_name_changed (
GncPluginPage *page,
const gchar *name)
901 const gchar *old_name;
903 g_return_if_fail(GNC_IS_PLUGIN_PAGE_REPORT(page));
904 g_return_if_fail(name != NULL);
906 ENTER(
"page %p, name %s", page, name);
907 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(page);
910 old_name = gnc_option_db_lookup_string_option(priv->
cur_odb,
"General",
911 "Report name", NULL);
912 DEBUG(
"Comparing old name '%s' to new name '%s'",
913 old_name ? old_name :
"(null)", name);
914 if (old_name && (strcmp(old_name, name) == 0))
921 gnc_option_db_set_string_option(priv->
cur_odb,
"General",
922 "Report name", name);
925 gnc_plugin_page_report_option_change_cb(page);
930 gnc_plugin_page_report_update_edit_menu (
GncPluginPage *page, gboolean hide)
935 gtk_action_set_sensitive (action, TRUE);
936 gtk_action_set_visible (action, TRUE);
938 gtk_action_set_sensitive (action, FALSE);
939 gtk_action_set_visible (action, !hide);
941 gtk_action_set_sensitive (action, FALSE);
942 gtk_action_set_visible (action, !hide);
951 report = GNC_PLUGIN_PAGE_REPORT(page);
952 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
953 return !priv->reloading;
964 SCM get_editor = scm_c_eval_string(
"gnc:report-editor-widget");
965 SCM set_editor = scm_c_eval_string(
"gnc:report-set-editor-widget!");
969 for (edited = scm_list_copy(priv->edited_reports); !scm_is_null(edited);
970 edited = SCM_CDR(edited))
972 editor = scm_call_1(get_editor, SCM_CAR(edited));
973 scm_call_2(set_editor, SCM_CAR(edited), SCM_BOOL_F);
974 if (editor != SCM_BOOL_F)
977 #define FUNC_NAME "gtk_widget_destroy"
978 w = SWIG_MustGetPtr(editor,
979 SWIG_TypeQuery(
"_p_GtkWidget"), 1, 0);
981 gtk_widget_destroy(GTK_WIDGET(w));
985 if (priv->initial_odb)
987 gnc_option_db_unregister_change_callback_id(priv->initial_odb,
988 priv->name_change_cb_id);
990 gnc_option_db_destroy(priv->initial_odb);
991 priv->initial_odb = NULL;
994 gnc_html_destroy(priv->
html);
1001 if (priv->edited_reports != SCM_EOL)
1002 scm_gc_unprotect_object(priv->edited_reports);
1005 static GtkActionEntry report_actions[] =
1008 "FilePrintAction", GTK_STOCK_PRINT, N_(
"_Print Report..."),
"<control>p",
1009 N_(
"Print the current report"),
1010 G_CALLBACK(gnc_plugin_page_report_print_cb)
1013 "FilePrintPDFAction", GNC_STOCK_PDF_EXPORT, N_(
"Export as P_DF..."), NULL,
1014 N_(
"Export the current report as a PDF document"),
1015 G_CALLBACK(gnc_plugin_page_report_exportpdf_cb)
1018 "EditCutAction", GTK_STOCK_CUT, N_(
"Cu_t"), NULL,
1019 N_(
"Cut the current selection and copy it to clipboard"),
1023 "EditCopyAction", GTK_STOCK_COPY, N_(
"_Copy"), NULL,
1024 N_(
"Copy the current selection to clipboard"),
1025 G_CALLBACK(gnc_plugin_page_report_copy_cb)
1028 "EditPasteAction", GTK_STOCK_PASTE, N_(
"_Paste"), NULL,
1029 N_(
"Paste the clipboard content at the cursor position"),
1033 "ViewRefreshAction", GTK_STOCK_REFRESH, N_(
"_Refresh"),
"<control>r",
1034 N_(
"Refresh this window"),
1035 G_CALLBACK (gnc_plugin_page_report_reload_cb)
1038 "ReportSaveAction", GTK_STOCK_SAVE, N_(
"Save _Report Configuration"),
"<control><alt>s",
1039 N_(
"Update the current report's saved configuration. "
1040 "The report will be saved in the file ~/.gnucash/saved-reports-2.4. "),
1041 G_CALLBACK(gnc_plugin_page_report_save_cb)
1044 "ReportSaveAsAction", GTK_STOCK_SAVE_AS, N_(
"Save Report Configuration As..."),
"<control><alt><shift>s",
1045 N_(
"Add the current report's configuration to the `Saved Report Configurations' menu. "
1046 "The report will be saved in the file ~/.gnucash/saved-reports-2.4. "),
1047 G_CALLBACK(gnc_plugin_page_report_save_as_cb)
1050 "ReportExportAction", GTK_STOCK_CONVERT, N_(
"Export _Report"), NULL,
1051 N_(
"Export HTML-formatted report to file"),
1052 G_CALLBACK(gnc_plugin_page_report_export_cb)
1055 "ReportOptionsAction", GTK_STOCK_PROPERTIES, N_(
"_Report Options"), NULL,
1056 N_(
"Edit report options"),
1057 G_CALLBACK(gnc_plugin_page_report_options_cb)
1061 "ReportBackAction", GTK_STOCK_GO_BACK, N_(
"Back"), NULL,
1062 N_(
"Move back one step in the history"),
1063 G_CALLBACK(gnc_plugin_page_report_back_cb)
1066 "ReportForwAction", GTK_STOCK_GO_FORWARD, N_(
"Forward"), NULL,
1067 N_(
"Move forward one step in the history"),
1068 G_CALLBACK(gnc_plugin_page_report_forw_cb)
1071 "ReportReloadAction", GTK_STOCK_REFRESH, N_(
"Reload"), NULL,
1072 N_(
"Reload the current page"),
1073 G_CALLBACK(gnc_plugin_page_report_reload_cb)
1076 "ReportStopAction", GTK_STOCK_STOP, N_(
"Stop"), NULL,
1077 N_(
"Cancel outstanding HTML requests"),
1078 G_CALLBACK(gnc_plugin_page_report_stop_cb)
1081 static guint num_report_actions = G_N_ELEMENTS( report_actions );
1086 {
"FilePrintAction", N_(
"Print") },
1087 {
"ReportExportAction", N_(
"Export") },
1088 {
"ReportOptionsAction", N_(
"Options") },
1092 static const gchar *initially_insensitive_actions[] =
1103 gnc_plugin_page_report_constructor(GType this_type, guint n_properties, GObjectConstructParam *properties)
1107 GObjectClass *parent_class;
1108 gint reportId = -42;
1111 our_class = GNC_PLUGIN_PAGE_REPORT_CLASS (
1112 g_type_class_peek (GNC_TYPE_PLUGIN_PAGE_REPORT));
1113 parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (our_class));
1114 obj = parent_class->constructor(this_type, n_properties, properties);
1116 for (i = 0; i < n_properties; i++)
1118 GObjectConstructParam prop = properties[i];
1119 if (strcmp(prop.pspec->name,
"report-id") == 0)
1121 reportId = g_value_get_int(prop.value);
1125 gnc_plugin_page_report_constr_init(GNC_PLUGIN_PAGE_REPORT(obj), reportId);
1134 GtkActionGroup *action_group;
1139 DEBUG(
"property reportId=%d", reportId );
1140 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(plugin_page);
1143 gnc_plugin_page_report_setup( GNC_PLUGIN_PAGE(plugin_page) );
1146 parent = GNC_PLUGIN_PAGE(plugin_page);
1148 name = gnc_report_name( priv->initial_report );
1149 g_object_set(G_OBJECT(plugin_page),
1151 "page-uri",
"default:",
1152 "ui-description",
"gnc-plugin-page-report-ui.xml",
1153 "use-new-window", use_new,
1163 "GncPluginPageReportActions");
1164 gtk_action_group_add_actions( action_group,
1169 initially_insensitive_actions,
1170 "sensitive", FALSE);
1179 DEBUG(
"report id = %d", reportId );
1180 plugin_page = g_object_new( GNC_TYPE_PLUGIN_PAGE_REPORT,
1181 "report-id", reportId, NULL );
1182 DEBUG(
"plugin_page: %p", plugin_page );
1183 DEBUG(
"set %d on page %p", reportId, plugin_page );
1184 return GNC_PLUGIN_PAGE( plugin_page );
1191 SCM new_edited = scm_delete(priv->edited_reports, report);
1192 if (priv->edited_reports != SCM_EOL)
1193 scm_gc_unprotect_object(priv->edited_reports);
1194 priv->edited_reports = new_edited;
1195 if (new_edited != SCM_EOL)
1196 scm_gc_protect_object(priv->edited_reports);
1203 SCM new_edited = scm_cons(report, priv->edited_reports);
1204 if (priv->edited_reports != SCM_EOL)
1205 scm_gc_unprotect_object(priv->edited_reports);
1206 priv->edited_reports = new_edited;
1207 if (new_edited != SCM_EOL)
1208 scm_gc_protect_object(priv->edited_reports);
1212 gnc_plugin_page_report_raise_editor(SCM report)
1214 SCM get_editor = scm_c_eval_string(
"gnc:report-editor-widget");
1215 SCM editor = scm_call_1(get_editor, report);
1216 #define FUNC_NAME "gtk_window_present"
1217 GtkWidget *w = SWIG_MustGetPtr(editor,
1218 SWIG_TypeQuery(
"_p_GtkWidget"), 1, 0);
1220 gtk_window_present(GTK_WINDOW(w));
1224 close_handler (gpointer user_data)
1227 DEBUG(
"in close handler\n");
1237 "ReportForwAction" );
1238 gtk_action_set_sensitive(act, enabled);
1247 "ReportBackAction" );
1248 gtk_action_set_sensitive(act, enabled);
1261 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1262 gnc_html_history_forward(gnc_html_get_history(priv->
html));
1263 node = gnc_html_history_get_current(gnc_html_get_history(priv->
html));
1266 gnc_html_show_url(priv->
html, node->type, node->location,
1278 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1279 gnc_html_history_back(gnc_html_get_history(priv->
html));
1280 node = gnc_html_history_get_current(gnc_html_get_history(priv->
html));
1283 gnc_html_show_url(priv->
html, node->type, node->location,
1295 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1299 DEBUG(
"reload-redraw" );
1300 dirty_report = scm_c_eval_string(
"gnc:report-set-dirty?!");
1301 scm_call_2(dirty_report, priv->
cur_report, SCM_BOOL_T);
1303 priv->need_reload = TRUE;
1307 gtk_widget_queue_draw( GTK_WIDGET(priv->
container) );
1310 priv->reloading = TRUE;
1311 gnc_html_reload( priv->
html );
1312 priv->reloading = FALSE;
1320 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1321 gnc_html_cancel(priv->
html);
1327 gnc_get_export_type_choice (SCM export_types)
1329 GList * choices = NULL;
1330 gboolean bad = FALSE;
1335 if (!scm_is_list (export_types))
1338 for (tail = export_types; !scm_is_null (tail); tail = SCM_CDR (tail))
1340 SCM pair = SCM_CAR (tail);
1344 if (!scm_is_pair (pair))
1346 g_warning (
"unexpected list element");
1351 scm = SCM_CAR (pair);
1352 if (!scm_is_string (scm))
1354 g_warning (
"unexpected pair element");
1359 name = gnc_scm_to_utf8_string (scm);
1360 choices = g_list_prepend (choices, name);
1365 choices = g_list_reverse (choices);
1367 choices = g_list_prepend (choices, g_strdup (_(
"HTML")));
1369 choice = gnc_choose_radio_option_dialog
1370 (NULL, _(
"Choose export format"),
1371 _(
"Choose the export format for this report:"),
1377 for (node = choices; node; node = node->next)
1378 g_free (node->data);
1379 g_list_free (choices);
1388 if (choice >= scm_ilength (export_types))
1391 return scm_list_ref (export_types, scm_from_int (choice));
1395 gnc_get_export_filename (SCM choice)
1398 struct stat statbuf;
1400 const gchar * html_type = _(
"HTML");
1405 if (choice == SCM_BOOL_T)
1406 type = g_strdup (html_type);
1408 type = gnc_scm_to_utf8_string(SCM_CAR (choice));
1411 title = g_strdup_printf (_(
"Save %s To File"), type);
1412 default_dir = gnc_get_default_directory(GNC_PREFS_GROUP_REPORT);
1414 filepath = gnc_file_dialog (title, NULL, default_dir, GNC_FILE_DIALOG_EXPORT);
1417 if (g_strrstr(filepath,
".") == NULL)
1418 filepath = g_strconcat(filepath,
".", g_ascii_strdown(type, strlen(type)), NULL);
1422 g_free (default_dir);
1427 default_dir = g_path_get_dirname(filepath);
1428 gnc_set_default_directory (GNC_PREFS_GROUP_REPORT, default_dir);
1429 g_free(default_dir);
1431 rc = g_stat (filepath, &statbuf);
1434 if (rc != 0 && errno != ENOENT)
1437 const char *format = _(
"You cannot save to that filename.\n\n%s");
1439 gnc_error_dialog (NULL, format, strerror(errno));
1445 if (rc == 0 && !S_ISREG (statbuf.st_mode))
1447 const char *message = _(
"You cannot save to that file.");
1449 gnc_error_dialog (NULL,
"%s", message);
1456 const char *format = _(
"The file %s already exists. "
1457 "Are you sure you want to overwrite it?");
1459 if (!gnc_verify_dialog (NULL, FALSE, format, filepath))
1476 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1483 save_func = scm_c_eval_string(
"gnc:report-to-template-new");
1484 rpt_id = scm_call_1(save_func, priv->
cur_report);
1487 if (!scm_is_null (rpt_id))
1490 GtkWidget *window = reportPage->
window;
1493 g_return_if_fail(GNC_IS_MAIN_WINDOW(window));
1495 gnc_ui_custom_report_edit_name (GNC_MAIN_WINDOW (window), rpt_id);
1504 SCM check_func, save_func;
1507 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1511 check_func = scm_c_eval_string(
"gnc:is-custom-report-type");
1512 if (scm_is_true (scm_call_1 (check_func, priv->
cur_report)))
1517 save_func = scm_c_eval_string(
"gnc:report-to-template-update");
1518 rpt_id = scm_call_1(save_func, priv->
cur_report);
1526 gnc_plugin_page_report_save_as_cb (action, report);
1540 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1541 export_types = scm_call_1 (scm_c_eval_string (
"gnc:report-export-types"),
1544 export_thunk = scm_call_1 (scm_c_eval_string (
"gnc:report-export-thunk"),
1547 if (scm_is_list (export_types) && scm_is_procedure (export_thunk))
1548 choice = gnc_get_export_type_choice (export_types);
1550 choice = SCM_BOOL_T;
1552 if (choice == SCM_BOOL_F)
1555 filepath = gnc_get_export_filename (choice);
1559 if (scm_is_pair (choice))
1564 choice = SCM_CDR (choice);
1565 file_scm = scm_from_locale_string (filepath);
1567 res = scm_call_3 (export_thunk, priv->
cur_report, choice, file_scm);
1569 result = (res != SCM_BOOL_F);
1572 result = gnc_html_export_to_file (priv->
html, filepath);
1576 const char *fmt = _(
"Could not open the file %s. "
1577 "The error is: %s");
1578 gnc_error_dialog( NULL, fmt, filepath ? filepath :
"(null)",
1579 strerror (errno) ? strerror (errno) :
"" );
1587 error_handler(
const char *str)
1589 PWARN(
"Report Error: %s", str);
1597 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1601 if (gnc_report_edit_options (priv->
cur_report))
1602 gnc_plugin_page_report_add_edited_report(priv, priv->
cur_report);
1608 return gnc_option_db_lookup_invoice_option(priv->
cur_odb,
"General",
1609 "Invoice Number", NULL);
1612 #define GNC_PREFS_GROUP_REPORT_PDFEXPORT GNC_PREFS_GROUP_GENERAL_REPORT ".pdf-export"
1613 #define GNC_PREF_FILENAME_DATE_FMT "filename-date-format"
1614 #define GNC_PREF_FILENAME_FMT "filename-format"
1618 gchar *job_name = NULL;
1619 gchar *report_name = NULL;
1620 const gchar *report_number =
"";
1622 const gchar *default_jobname = N_(
"GnuCash-Report");
1631 GNC_PREF_FILENAME_DATE_FMT);
1632 if (*format_code ==
'\0')
1634 g_free(format_code);
1635 format_code = g_strdup(
"locale");
1640 PERR(
"Incorrect date format code");
1641 if (format_code != NULL)
1660 report_name = g_strdup (_(default_jobname));
1675 report_name = gnc_option_db_lookup_string_option(priv->
cur_odb,
"General",
1676 "Report name", NULL);
1678 report_name = g_strdup (_(default_jobname));
1679 if (g_strcmp0(report_name, _(
"Printable Invoice")) == 0
1680 || g_strcmp0(report_name, _(
"Tax Invoice")) == 0
1681 || g_strcmp0(report_name, _(
"Easy Invoice")) == 0
1682 || g_strcmp0(report_name, _(
"Fancy Invoice")) == 0)
1686 g_free(report_name);
1687 report_name = g_strdup(_(
"Invoice"));
1690 invoice = lookup_invoice(priv);
1694 report_number = gncInvoiceGetID(invoice);
1698 if (report_name && job_date)
1703 job_name = g_strdup_printf(format, report_name, report_number, job_date);
1707 g_free (report_name);
1711 char forbidden_char =
'/';
1714 while (strchr(job_name, forbidden_char))
1716 *strchr(job_name, forbidden_char) =
'_';
1727 gboolean already_found;
1728 g_assert(static_report_printnames);
1731 value = g_hash_table_lookup(static_report_printnames, job_name);
1732 already_found = (value != NULL);
1735 value = GINT_TO_POINTER(0);
1739 value = GINT_TO_POINTER(1 + GPOINTER_TO_INT(value));
1741 g_hash_table_insert(static_report_printnames, g_strdup(job_name), value);
1748 gchar *tmp = g_strdup_printf(
"%s_%d", job_name, (
int) GPOINTER_TO_INT(value));
1761 gchar *job_name = report_create_jobname(priv);
1765 gnc_html_print(priv->
html, job_name, FALSE);
1774 gchar *job_name = report_create_jobname(priv);
1779 invoice = lookup_invoice(priv);
1783 owner = (
GncOwner*) gncInvoiceGetOwner(invoice);
1787 gchar *dirname = NULL;
1792 if (dirname && g_file_test(dirname,
1793 G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
1795 gchar *tmp = g_build_filename(dirname, job_name, NULL);
1804 gnc_html_print(priv->
html, job_name, TRUE);
1813 if (print_settings &&
1814 gtk_print_settings_has_key(print_settings,
1817 const char* dirname = gtk_print_settings_get(print_settings,
1820 if (g_file_test(dirname, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
1825 gncOwnerCommitEdit(owner);
1838 priv = GNC_PLUGIN_PAGE_REPORT_GET_PRIVATE(report);
1839 gnc_html_copy_to_clipboard(priv->
html);
1848 gnc_main_window_open_report(
int report_id,
GncMainWindow *window)
1853 g_return_if_fail(GNC_IS_MAIN_WINDOW(window));
1860 gnc_main_window_open_report_url(
const char * url,
GncMainWindow *window)
1864 DEBUG(
"report url: [%s]\n", url );
1867 g_return_if_fail(GNC_IS_MAIN_WINDOW(window));
void qof_instance_get(const QofInstance *inst, const gchar *first_param,...)
Wrapper for g_object_get.
gchar * gnc_prefs_get_string(const gchar *group, const gchar *pref_name)
GncPluginPage *(* recreate_page)(GtkWidget *window, GKeyFile *file, const gchar *group)
void(* page_name_changed)(GncPluginPage *plugin_page, const gchar *name)
void(* update_edit_menu_actions)(GncPluginPage *plugin_page, gboolean hide)
#define GNC_GTK_PRINT_SETTINGS_EXPORT_DIR
utility functions for the GnuCash UI
#define PINFO(format, args...)
#define DEBUG(format, args...)
const gchar * gnc_plugin_page_get_page_name(GncPluginPage *page)
Functions that are supported by all types of windows.
void qof_instance_set(QofInstance *inst, const gchar *first_param,...)
Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
#define PERR(format, args...)
#define ENTER(format, args...)
void gncOwnerBeginEdit(GncOwner *owner)
void gnc_main_window_open_page(GncMainWindow *window, GncPluginPage *page)
QofInstance * qofOwnerGetOwner(const GncOwner *owner)
gboolean(* finish_pending)(GncPluginPage *plugin_page)
#define PWARN(format, args...)
char * qof_print_date(time64 secs)
GType gnc_plugin_page_report_get_type(void)
Functions providing the file history menu.
void(* destroy_widget)(GncPluginPage *plugin_page)
const gchar * plugin_name
Gnome specific utility functions.
All type declarations for the whole Gnucash engine.
GncPluginPage * gnc_plugin_page_report_new(int reportId)
GtkPrintSettings * gnc_print_get_settings()
Generic api to store and retrieve preferences.
GtkAction * gnc_plugin_page_get_action(GncPluginPage *page, const gchar *name)
GtkWidget *(* create_widget)(GncPluginPage *plugin_page)
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
void gnc_main_window_close_page(GncPluginPage *page)
Functions for adding plugins to a GnuCash window.
QofDateFormat qof_date_format_get(void)
#define LEAVE(format, args...)
void(* save_page)(GncPluginPage *page, GKeyFile *file, const gchar *group)
void qof_date_format_set(QofDateFormat df)
void gnc_plugin_page_add_book(GncPluginPage *page, QofBook *book)
GtkWidget * gnc_ui_get_toplevel(void)
GtkActionGroup * gnc_plugin_page_create_action_group(GncPluginPage *page, const gchar *group_name)
gboolean gnc_date_string_to_dateformat(const gchar *format_string, QofDateFormat *format)
Converts the date format to a printable string.
void main_window_update_page_name(GncPluginPage *page, const gchar *name_in)
const gchar * QofLogModule