GnuCash c935c2f+
Loading...
Searching...
No Matches
window-report.cpp
1/********************************************************************
2 * window-report.c *
3 * Copyright (C) 1997 Robin D. Clark *
4 * Copyright (C) 1998 Linas Vepstas *
5 * Copyright (C) 1999 Jeremy Collins ( gtk-xmhtml port ) *
6 * Copyright (C) 2000 Dave Peticolas *
7 * Copyright (C) 2000 Bill Gribble *
8 * *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of the GNU General Public License as *
11 * published by the Free Software Foundation; either version 2 of *
12 * the License, or (at your option) any later version. *
13 * *
14 * This program is distributed in the hope that it will be useful, *
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17 * GNU General Public License for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License*
20 * along with this program; if not, contact: *
21 * *
22 * Free Software Foundation Voice: +1-617-542-5942 *
23 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
24 * Boston, MA 02110-1301, USA gnu@gnu.org *
25 * *
26 ********************************************************************/
27#include <glib/gi18n.h>
28#include <memory>
29#include "dialog-options.hpp"
30#include "dialog-report-column-view.hpp"
31#include <libguile.h>
32
33#include <config.h>
34
35#include <errno.h>
36#include <sys/stat.h>
37
38#include "swig-runtime.h"
39#include "gnc-guile-utils.h"
40#include "gnc-ui.h"
41#include "window-report.h"
42#include "guile-mappings.h"
43
45#include "gnc-report.h"
46
47/********************************************************************
48 *
49 ********************************************************************/
50
51void
52reportWindow(int report_id, GtkWindow *parent)
53{
54 gnc_set_busy_cursor (nullptr, TRUE);
55 gnc_main_window_open_report(report_id, GNC_MAIN_WINDOW(parent));
56 gnc_unset_busy_cursor (nullptr);
57}
58
59/********************************************************************
60 * default parameters editor handling
61 ********************************************************************/
62
64{
65 GncOptionsDialog * win;
66 GncOptionDB * odb;
67 SCM cur_report;
68};
69
70
71static void
72gnc_options_dialog_apply_cb(GncOptionsDialog *opt_dialog,
73 gpointer user_data)
74{
75 SCM dirty_report = scm_c_eval_string("gnc:report-set-dirty?!");
76 auto win{static_cast<struct report_default_params_data*>(user_data)};
77
78 if (!win) return;
79 auto results = gnc_option_db_commit (win->odb);
80 for (auto iter = results; iter; iter = iter->next)
81 {
82 auto dialog = gtk_message_dialog_new(GTK_WINDOW (win->win),
83 static_cast<GtkDialogFlags>(0),
84 GTK_MESSAGE_ERROR,
85 GTK_BUTTONS_OK,
86 "%s",
87 (char*)iter->data);
88 gtk_dialog_run(GTK_DIALOG(dialog));
89 gtk_widget_destroy(dialog);
90 g_free (iter->data);
91 }
92 g_list_free (results);
93
94 scm_call_2(dirty_report, win->cur_report, SCM_BOOL_T);
95}
96
97static void
98gnc_options_dialog_help_cb(GncOptionsDialog *opt_dialog,
99 gpointer user_data)
100{
101 auto prm{static_cast<struct report_default_params_data*>(user_data)};
102
103 auto parent = prm->win->get_widget();
104 auto dialog = gtk_message_dialog_new(GTK_WINDOW(parent),
105 GTK_DIALOG_DESTROY_WITH_PARENT,
106 GTK_MESSAGE_INFO,
107 GTK_BUTTONS_OK,
108 "%s",
109 _("Set the report options you want using this dialog."));
110 g_signal_connect(G_OBJECT(dialog), "response",
111 (GCallback)gtk_widget_destroy, nullptr);
112 gtk_widget_show(dialog);
113}
114
115static void
116gnc_options_dialog_close_cb(GncOptionsDialog *opt_dialog,
117 gpointer user_data)
118{
119 auto win{static_cast<struct report_default_params_data*>(user_data)};
120 SCM set_editor = scm_c_eval_string("gnc:report-set-editor-widget!");
121
122 scm_call_2(set_editor, win->cur_report, SCM_BOOL_F);
123 delete win->win;
124 gnc_option_db_destroy(win->odb);
125 g_free(win);
126}
127
128static gboolean
129gnc_report_raise_editor(SCM report)
130{
131 SCM get_editor = scm_c_eval_string("gnc:report-editor-widget");
132 SCM editor = scm_call_1(get_editor, report);
133 if (editor != SCM_BOOL_F)
134 {
135#define FUNC_NAME "gnc-report-raise-editor"
136 auto w{static_cast<GtkWidget *>(SWIG_MustGetPtr(editor, SWIG_TypeQuery("_p_GtkWidget"), 1, 0))};
137#undef FUNC_NAME
138 gtk_window_present(GTK_WINDOW(w));
139 return TRUE;
140 }
141 else
142 return FALSE;
143}
144
145
146GtkWidget *
147gnc_report_window_default_params_editor(GncOptionDB* odb, SCM report,
148 GtkWindow *parent)
149{
150 SCM get_report_type = scm_c_eval_string("gnc:report-type");
151 SCM get_template = scm_c_eval_string("gnc:find-report-template");
152 SCM get_template_name = scm_c_eval_string("gnc:report-template-name");
153 SCM ptr;
154
155 const gchar *title = nullptr;
156
157 if (gnc_report_raise_editor (report))
158 return nullptr;
159 else
160 {
161 struct report_default_params_data * prm =
162 g_new0(struct report_default_params_data, 1);
163
164 prm->odb = odb;
165 prm->cur_report = report;
166
167 /* Get the title of the report's template. */
168 ptr = scm_call_1(get_report_type, report);
169 if (ptr != SCM_BOOL_F)
170 {
171 ptr = scm_call_1(get_template, ptr);
172 if (ptr != SCM_BOOL_F)
173 {
174 ptr = scm_call_1(get_template_name, ptr);
175 if (scm_is_string(ptr))
176 title = gnc_scm_to_utf8_string (ptr);
177 }
178 }
179
180 /* Don't forget to translate the window title */
181 prm->win = new GncOptionsDialog((gchar*) (title && *title ? _(title) : ""), parent);
182
183 g_free ((gpointer *) title);
184
185 scm_gc_protect_object(prm->cur_report);
186
187 prm->win->build_contents(prm->odb);
188
189 prm->win->set_apply_cb(gnc_options_dialog_apply_cb, (gpointer)prm);
190 prm->win->set_help_cb(gnc_options_dialog_help_cb, (gpointer)prm);
191 prm->win->set_close_cb(gnc_options_dialog_close_cb, (gpointer)prm);
192 return prm->win->get_widget();
193 }
194}
195
196gboolean
197gnc_report_edit_options(SCM report, GtkWindow *parent)
198{
199 SCM set_editor = scm_c_eval_string("gnc:report-set-editor-widget!");
200 SCM get_report_type = scm_c_eval_string("gnc:report-type");
201 SCM ptr;
202 GncOptionDB* odb;
203 GtkWidget *options_widget = nullptr;
204
205 /* If the options editor widget already exists we simply raise it */
206 if (gnc_report_raise_editor (report))
207 return TRUE;
208
209 /* Check if this report has options to edit */
210 odb = gnc_get_report_optiondb(report);
211 if (!odb)
212 {
213 gnc_warning_dialog (parent, "%s",
214 _("There are no options for this report."));
215 return FALSE;
216 }
217
218 /* Multi-column type reports need a special options dialog */
219 ptr = scm_call_1(get_report_type, report);
220 if (scm_is_string(ptr))
221 {
222 gchar *rpt_type = gnc_scm_to_utf8_string (ptr);
223 if (g_strcmp0 (rpt_type, "d8ba4a2e89e8479ca9f6eccdeb164588") == 0)
224 options_widget = gnc_column_view_edit_options (odb, report);
225 else
226 options_widget = gnc_report_window_default_params_editor (odb, report, parent);
227 g_free (rpt_type);
228 }
229
230 /* Store the options editor widget for future reuse */
231#define FUNC_NAME "gnc-report-edit-options"
232 ptr = SWIG_NewPointerObj (options_widget, SWIG_TypeQuery("_p_GtkWidget"), 0);
233#undef FUNC_NAME
234 scm_call_2 (set_editor, report, ptr);
235
236 return TRUE;
237}
238
240gnc_get_report_optiondb(SCM report_instance)
241{
242 SCM get_report_options = scm_c_eval_string("gnc:report-options");
243 auto scm_dispatch{scm_call_1(get_report_options, report_instance)};
244 return gnc_get_optiondb_from_dispatcher(scm_dispatch);
245}
Holds all of the options for a book, report, or stylesheet, organized by GncOptionSections.
GList * gnc_option_db_commit(GncOptionDB *odb)
Write all changed ui_item values to their options.
void gnc_option_db_destroy(GncOptionDB *odb)
Destruct and release a GncOptionDB.