26 #include <glib/gi18n.h>
29 #include "swig-runtime.h"
32 #include "dialog-options.h"
33 #include "dialog-utils.h"
35 #include "option-util.h"
36 #include "window-report.h"
37 #include "guile-mappings.h"
38 #include "gnc-guile-utils.h"
39 #include "gnc-gui-query.h"
41 #include "gnc-report.h"
44 #define GNC_PREFS_GROUP_REPORT_SAVED_CONFIGS "dialogs.report-saved-configs"
69 GtkWidget *reportview;
71 GtkTreeViewColumn *namecol;
72 GtkCellRenderer *namerenderer;
73 GtkTreeViewColumn *runcol;
74 GtkTreeViewColumn *editcol;
75 GtkTreeViewColumn *delcol;
82 void custom_report_dialog_close_cb(GtkWidget* widget, gpointer data);
83 void custom_report_help_cb(GtkWidget* widget, gpointer data);
84 void close_custom_report_clicked_cb(GtkWidget* widget, gpointer data);
85 void custom_report_list_view_row_activated_cb(GtkTreeView *view, GtkTreePath *path,
86 GtkTreeViewColumn *column, gpointer data);
87 void custom_report_list_view_clicked_cb(GtkTreeView *view, GdkEventButton *event, gpointer data);
88 void custom_report_name_edited_cb(GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer data);
89 void custom_report_query_tooltip_cb (GtkTreeView *view,
92 gboolean keyboard_mode,
97 custom_report_dialog_close_cb(GtkWidget* widget, gpointer data)
100 gnc_save_window_size(GNC_PREFS_GROUP_REPORT_SAVED_CONFIGS, GTK_WINDOW(crd->dialog));
102 gtk_widget_destroy(crd->dialog);
107 custom_report_help_cb (GtkWidget *widget, gpointer data)
113 close_custom_report_clicked_cb(GtkWidget* widget, gpointer data)
116 custom_report_dialog_close_cb(NULL, crd);
129 SCM get_rpt_guids = scm_c_eval_string(
"gnc:custom-report-template-guids");
130 SCM template_menu_name = scm_c_eval_string(
"gnc:report-template-menu-name/report-guid");
134 GtkTreeModel *model = GTK_TREE_MODEL (store);
137 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
COL_NAME, GTK_SORT_ASCENDING);
139 crd->reportlist = scm_call_0(get_rpt_guids);
140 rpt_guids = crd->reportlist;
143 valid_iter = gtk_tree_model_get_iter_first (model, &iter);
146 GValue value = { 0, };
148 g_value_init ( &value, G_TYPE_POINTER);
149 gtk_tree_model_get_value (model, &iter, COL_NUM, &value);
150 row_guid = (
GncGUID *) g_value_get_pointer (&value);
151 guid_free (row_guid);
152 g_value_unset (&value);
153 valid_iter = gtk_tree_model_iter_next (model, &iter);
155 gtk_list_store_clear(store);
157 if (scm_is_list(rpt_guids))
161 for (i = 0; !scm_is_null(rpt_guids); i++)
164 gchar *guid_str = scm_to_utf8_string (SCM_CAR(rpt_guids));
165 gchar *name = gnc_scm_to_utf8_string (scm_call_2(template_menu_name, SCM_CAR(rpt_guids), SCM_BOOL_F));
169 gtk_list_store_append(store, &iter);
170 gtk_list_store_set(store, &iter,
178 rpt_guids = SCM_CDR(rpt_guids);
184 static GtkTreeModel *
189 store = gtk_list_store_new(NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
191 update_report_list(store, crd);
193 return GTK_TREE_MODEL (store);
200 GtkCellRenderer *renderer;
202 GtkTreeViewColumn * col;
205 crd->namerenderer = gtk_cell_renderer_text_new();
206 g_signal_connect (G_OBJECT (crd->namerenderer),
"edited",
207 G_CALLBACK (custom_report_name_edited_cb), crd);
208 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (crd->reportview), -1,
209 "Report Name", crd->namerenderer,
212 crd->namecol = gtk_tree_view_get_column (GTK_TREE_VIEW (crd->reportview), VIEW_COL_NAME);
213 gtk_tree_view_column_set_expand (crd->namecol, TRUE);
215 renderer = gtk_cell_renderer_pixbuf_new();
216 g_object_set (G_OBJECT (renderer),
"stock-id", GTK_STOCK_EXECUTE, NULL);
217 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (crd->reportview), -1,
220 crd->runcol = gtk_tree_view_get_column (GTK_TREE_VIEW (crd->reportview), VIEW_COL_RUN);
222 renderer = gtk_cell_renderer_pixbuf_new();
223 g_object_set (G_OBJECT (renderer),
"stock-id", GTK_STOCK_EDIT, NULL);
224 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (crd->reportview), -1,
227 crd->editcol = gtk_tree_view_get_column (GTK_TREE_VIEW (crd->reportview), VIEW_COL_EDIT);
229 renderer = gtk_cell_renderer_pixbuf_new();
230 g_object_set (G_OBJECT (renderer),
"stock-id", GTK_STOCK_DELETE, NULL);
231 colnum = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (crd->reportview), -1,
234 crd->delcol = gtk_tree_view_get_column (GTK_TREE_VIEW (crd->reportview), VIEW_COL_DELETE);
236 model = create_and_fill_report_list(crd);
238 gtk_tree_view_set_model (GTK_TREE_VIEW (crd->reportview), model);
240 g_object_unref(model);
251 custom_report_run_report(SCM guid,
254 SCM make_report = scm_c_eval_string(
"gnc:make-report");
258 if (scm_is_null(guid))
262 report_id = scm_to_int (scm_call_1(make_report, guid));
266 custom_report_dialog_close_cb(NULL, crd);
269 gnc_main_window_open_report(report_id, window);
280 custom_report_edit_report_name (SCM guid,
284 SCM rename_report = scm_c_eval_string(
"gnc:rename-report");
285 SCM new_name_scm = scm_from_utf8_string(new_name);
287 if (scm_is_null(guid) || !new_name || (*new_name ==
'\0'))
291 scm_call_2(rename_report, guid, new_name_scm);
292 update_report_list(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(crd->reportview))),
306 SCM template_menu_name = scm_c_eval_string(
"gnc:report-template-menu-name/report-guid");
309 if (scm_is_null (guid))
312 report_name = gnc_scm_to_utf8_string(scm_call_2(template_menu_name, guid, SCM_BOOL_F));
315 if (gnc_verify_dialog(crd->dialog, FALSE,
"Are you sure you want to delete %s?", report_name))
317 SCM del_report = scm_c_eval_string(
"gnc:delete-report");
318 scm_call_1(del_report, guid);
319 update_report_list(GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(crd->reportview))),
322 g_free (report_name);
339 const gchar* message)
341 GtkTreeSelection *sel;
347 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(crd->reportview));
349 if (gtk_tree_selection_get_selected(sel, &model, &iter))
351 gtk_tree_model_get(model, &iter, COL_NUM, &guid, -1);
358 gnc_error_dialog(GTK_WIDGET(crd->window),
"%s", message);
362 return scm_from_utf8_string (guid_str);
374 custom_report_list_view_row_activated_cb(GtkTreeView *view, GtkTreePath *path,
375 GtkTreeViewColumn *column, gpointer data)
381 model = gtk_tree_view_get_model(view);
383 if (gtk_tree_model_get_iter(model, &iter, path))
388 gtk_tree_model_get(model, &iter, COL_NUM, &guid, -1);
392 custom_report_run_report(scm_from_utf8_string (guid_str), crd);
406 custom_report_list_view_clicked_cb(GtkTreeView *view, GdkEventButton *event, gpointer data)
409 GtkTreePath *path = NULL;
410 GtkTreeViewColumn *column = NULL;
413 g_return_if_fail ( view != NULL );
415 if (gtk_tree_view_get_path_at_pos (view, event->x, event->y,
419 if (column == crd->runcol)
421 SCM guid = get_custom_report_selection(crd, _(
"You must select a report configuration to load."));
422 custom_report_run_report (guid, crd);
424 else if (column == crd->editcol)
426 g_object_set(G_OBJECT(crd->namerenderer),
"editable", TRUE, NULL);
427 gtk_tree_view_set_cursor_on_cell (view, path, crd->namecol,
428 crd->namerenderer, TRUE);
430 else if (column == crd->delcol)
432 SCM guid = get_custom_report_selection(crd, _(
"You must select a report configuration to delete."));
433 custom_report_delete (guid, crd);
438 void custom_report_name_edited_cb(GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer data)
441 SCM guid = get_custom_report_selection(crd, _(
"Unable to change report configuration name."));
442 SCM unique_name_func = scm_c_eval_string(
"gnc:report-template-has-unique-name?");
443 SCM new_name_scm = scm_from_utf8_string(new_text);
445 g_object_set(G_OBJECT(crd->namerenderer),
"editable", FALSE, NULL);
446 if (scm_is_null (guid))
449 if (scm_is_true (scm_call_2 (unique_name_func, guid, new_name_scm)))
450 custom_report_edit_report_name (guid, crd, new_text);
452 gnc_error_dialog(crd->dialog,
"%s",
453 _(
"A saved report configuration with this name already exists, please choose another name.") );
457 void custom_report_query_tooltip_cb (GtkTreeView *view,
460 gboolean keyboard_mode,
465 GtkTreePath *path = NULL;
466 GtkTreeViewColumn *column = NULL;
469 g_return_if_fail ( view != NULL );
471 if (gtk_tree_view_get_path_at_pos (view, x, y,
475 gtk_tree_view_set_tooltip_cell (view, tooltip, path, column, NULL);
476 if (column == crd->runcol)
477 gtk_tooltip_set_text (tooltip, _(
"Load report configuration"));
478 else if (column == crd->editcol)
479 gtk_tooltip_set_text (tooltip, _(
"Edit report configuration name"));
480 else if (column == crd->delcol)
481 gtk_tooltip_set_text (tooltip, _(
"Delete report configuration"));
483 gtk_tooltip_set_text (tooltip, NULL);
496 GtkWidget *no_report_notification;
500 builder = gtk_builder_new();
501 gnc_builder_add_from_file (builder,
"dialog-custom-report.glade",
"custom_report_dialog");
503 crd->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"custom_report_dialog"));
504 crd->reportview = GTK_WIDGET(gtk_builder_get_object (builder,
"custom_report_list_view"));
505 no_report_notification = GTK_WIDGET(gtk_builder_get_object (builder,
"label2"));
506 set_reports_view_and_model(crd);
507 crd->window = window;
509 gnc_restore_window_size (GNC_PREFS_GROUP_REPORT_SAVED_CONFIGS, GTK_WINDOW(crd->dialog));
512 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, crd);
514 gtk_widget_show_all(crd->dialog);
518 model = gtk_tree_view_get_model (GTK_TREE_VIEW (crd->reportview));
519 if (gtk_tree_model_get_iter_first (model, &iter))
523 gtk_widget_hide(no_report_notification);
528 gtk_widget_hide(crd->reportview);
531 g_object_unref(G_OBJECT(builder));
544 gnc_ui_custom_report_internal (window);
554 void gnc_ui_custom_report_edit_name (
GncMainWindow * window, SCM scm_guid)
556 SCM is_custom_report;
564 is_custom_report = scm_c_eval_string (
"gnc:report-template-is-custom/template-guid?");
565 if (scm_is_false (scm_call_1 (is_custom_report, scm_guid)))
569 guid_str = scm_to_utf8_string (scm_guid);
574 model = gtk_tree_view_get_model (GTK_TREE_VIEW (crd->reportview));
575 valid_iter = gtk_tree_model_get_iter_first (model, &iter);
579 GValue value = { 0, };
581 g_value_init (&value, G_TYPE_POINTER);
582 gtk_tree_model_get_value (model, &iter, COL_NUM, &value);
583 row_guid = (
GncGUID *) g_value_get_pointer (&value);
592 GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (crd->reportview));
593 gtk_tree_selection_select_iter (selection, &iter);
594 path = gtk_tree_model_get_path (model, &iter);
595 g_object_set(G_OBJECT(crd->namerenderer),
"editable", TRUE, NULL);
596 gtk_tree_view_set_cursor_on_cell (GTK_TREE_VIEW (crd->reportview),
598 crd->namerenderer, TRUE);
602 g_value_unset (&value);
603 valid_iter = gtk_tree_model_iter_next (model, &iter);
gboolean string_to_guid(const gchar *string, GncGUID *guid)
gchar * guid_to_string_buff(const GncGUID *guid, gchar *buff)
Functions for adding content to a window.
GncGUID * guid_malloc(void)
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
#define GUID_ENCODING_LENGTH
void gnc_gnome_help(const char *file_name, const char *anchor)