30 #include <glib/gi18n.h>
35 #include "swig-runtime.h"
36 #include "dialog-options.h"
37 #include "dialog-report-column-view.h"
40 #include "gnc-guile-utils.h"
41 #include "gnc-report.h"
43 #include "option-util.h"
45 #include "window-report.h"
46 #include "guile-mappings.h"
49 #include "gnc-report.h"
51 #define WINDOW_REPORT_CM_CLASS "window-report"
52 #define MDI_CHILD_CONFIG "mdi_child_config"
59 reportWindow(
int report_id)
61 gnc_set_busy_cursor (NULL, TRUE);
62 gnc_main_window_open_report(report_id, NULL);
63 gnc_unset_busy_cursor (NULL);
83 SCM dirty_report = scm_c_eval_string(
"gnc:report-set-dirty?!");
87 gnc_option_db_commit(win->db);
88 scm_call_2(dirty_report, win->cur_report, SCM_BOOL_T);
95 GtkWidget *dialog, *parent;
98 parent = gnc_options_dialog_widget(prm->win);
99 dialog = gtk_message_dialog_new(GTK_WINDOW(parent),
100 GTK_DIALOG_DESTROY_WITH_PARENT,
104 _(
"Set the report options you want using this dialog."));
105 g_signal_connect(G_OBJECT(dialog),
"response",
106 (GCallback)gtk_widget_destroy, NULL);
107 gtk_widget_show(dialog);
115 SCM set_editor = scm_c_eval_string(
"gnc:report-set-editor-widget!");
117 scm_call_2(set_editor, win->cur_report, SCM_BOOL_F);
118 gnc_options_dialog_destroy(win->win);
119 gnc_option_db_destroy(win->db);
120 scm_gc_unprotect_object(win->scm_options);
125 gnc_report_raise_editor(SCM report)
127 SCM get_editor = scm_c_eval_string(
"gnc:report-editor-widget");
128 SCM editor = scm_call_1(get_editor, report);
129 if (editor != SCM_BOOL_F)
131 #define FUNC_NAME "gnc-report-raise-editor"
132 GtkWidget *w = SWIG_MustGetPtr(editor,
133 SWIG_TypeQuery(
"_p_GtkWidget"), 1, 0);
135 gtk_window_present(GTK_WINDOW(w));
144 gnc_report_window_default_params_editor(SCM options, SCM report)
146 SCM get_report_type = scm_c_eval_string(
"gnc:report-type");
147 SCM get_template = scm_c_eval_string(
"gnc:find-report-template");
148 SCM get_template_name = scm_c_eval_string(
"gnc:report-template-name");
151 const gchar *title = NULL;
153 if (gnc_report_raise_editor (report))
160 prm->scm_options = options;
161 prm->cur_report = report;
162 prm->db = gnc_option_db_new(prm->scm_options);
165 ptr = scm_call_1(get_report_type, report);
166 if (ptr != SCM_BOOL_F)
168 ptr = scm_call_1(get_template, ptr);
169 if (ptr != SCM_BOOL_F)
171 ptr = scm_call_1(get_template_name, ptr);
172 if (scm_is_string(ptr))
173 title = gnc_scm_to_utf8_string (ptr);
178 prm->win = gnc_options_dialog_new((gchar*) (title && *title ? _(title) :
""));
180 g_free ((gpointer *) title);
182 scm_gc_protect_object(prm->scm_options);
183 scm_gc_protect_object(prm->cur_report);
185 gnc_options_dialog_build_contents(prm->win, prm->db);
186 gnc_option_db_clean(prm->db);
188 gnc_options_dialog_set_apply_cb(prm->win,
189 gnc_options_dialog_apply_cb,
191 gnc_options_dialog_set_help_cb(prm->win,
192 gnc_options_dialog_help_cb,
194 gnc_options_dialog_set_close_cb(prm->win,
195 gnc_options_dialog_close_cb,
197 return gnc_options_dialog_widget(prm->win);
202 gnc_report_edit_options(SCM report)
204 SCM set_editor = scm_c_eval_string(
"gnc:report-set-editor-widget!");
205 SCM get_options = scm_c_eval_string(
"gnc:report-options");
206 SCM get_report_type = scm_c_eval_string(
"gnc:report-type");
209 GtkWidget *options_widget = NULL;
212 if (gnc_report_raise_editor (report))
216 options = scm_call_1(get_options, report);
217 if (options == SCM_BOOL_F)
220 _(
"There are no options for this report."));
225 ptr = scm_call_1(get_report_type, report);
226 if (scm_is_string(ptr))
228 gchar *rpt_type = gnc_scm_to_utf8_string (ptr);
229 if (g_strcmp0 (rpt_type,
"d8ba4a2e89e8479ca9f6eccdeb164588") == 0)
230 options_widget = gnc_column_view_edit_options (options, report);
232 options_widget = gnc_report_window_default_params_editor (options, report);
237 #define FUNC_NAME "gnc-report-edit-options"
238 ptr = SWIG_NewPointerObj (options_widget, SWIG_TypeQuery(
"_p_GtkWidget"), 0);
240 scm_call_2 (set_editor, report, ptr);
246 gnc_html_file_stream_cb (
const char *location,
char ** data,
int *len)
253 gnc_html_report_stream_cb (
const char *location,
char ** data,
int *len)
257 ok = gnc_run_report_id_string (location, data);
261 *data = g_strdup_printf (
"<html><body><h3>%s</h3>"
262 "<p>%s</p></body></html>",
264 _(
"An error occurred while running the report."));
270 scm_c_eval_string(
"(gnc:report-finished)");
273 *len = strlen(*data);
279 gnc_html_options_url_cb (
const char *location,
const char *label,
285 g_return_val_if_fail (location != NULL, FALSE);
286 g_return_val_if_fail (result != NULL, FALSE);
288 result->load_to_stream = FALSE;
291 if (strncmp (
"report-id=", location, 10) == 0)
293 if (sscanf (location + 10,
"%d", &report_id) != 1)
295 result->error_message =
296 g_strdup_printf (_(
"Badly formed options URL: %s"), location);
301 report = gnc_report_find(report_id);
302 if (report == SCM_UNDEFINED ||
303 report == SCM_BOOL_F)
305 result->error_message =
306 g_strdup_printf (_(
"Badly-formed report id: %s"), location);
311 gnc_report_edit_options (report);
317 result->error_message =
318 g_strdup_printf (_(
"Badly formed options URL: %s"), location);
325 gnc_html_report_url_cb (
const char *location,
const char *label,
328 g_return_val_if_fail (location != NULL, FALSE);
329 g_return_val_if_fail (result != NULL, FALSE);
336 url = gnc_build_url (URL_TYPE_REPORT, location, label);
337 gnc_main_window_open_report_url (url, NULL);
340 result->load_to_stream = FALSE;
344 result->load_to_stream = TRUE;
351 gnc_html_help_url_cb (
const char *location,
const char *label,
354 g_return_val_if_fail (location != NULL, FALSE);
356 if (label && (*label !=
'\0'))
364 gnc_report_init (
void)
368 GNC_TYPE_PLUGIN_PAGE_REPORT;
370 gnc_html_register_stream_handler (URL_TYPE_HELP, gnc_html_file_stream_cb);
371 gnc_html_register_stream_handler (URL_TYPE_FILE, gnc_html_file_stream_cb);
372 gnc_html_register_stream_handler (URL_TYPE_REPORT, gnc_html_report_stream_cb);
374 gnc_html_register_url_handler (URL_TYPE_OPTIONS, gnc_html_options_url_cb);
375 gnc_html_register_url_handler (URL_TYPE_REPORT, gnc_html_report_url_cb);
376 gnc_html_register_url_handler (URL_TYPE_HELP, gnc_html_help_url_cb);
GKeyFile helper routines.
void gnc_gnome_help(const char *file_name, const char *anchor)
Utility functions for file access.
GtkWidget * gnc_ui_get_toplevel(void)
int gncReadFile(const char *filename, char **data)