GnuCash c935c2f+
Loading...
Searching...
No Matches
gnc-window.c
1/*
2 * gnc-window.c -- structure which represents a GnuCash window.
3 *
4 * Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
5 * Copyright (C) 2003 David Hampton <hampton@employees.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, contact:
19 *
20 * Free Software Foundation Voice: +1-617-542-5942
21 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
22 * Boston, MA 02110-1301, USA gnu@gnu.org
23 */
24
25#include <config.h>
26
27#include <gtk/gtk.h>
28#include <math.h>
29
30#include "gnc-engine.h"
31#include "gnc-plugin-page.h"
32#include "gnc-window.h"
33#include "gnc-splash.h"
34
35static QofLogModule log_module = GNC_MOD_GUI;
36
37G_DEFINE_INTERFACE (GncWindow, gnc_window, G_TYPE_OBJECT)
38
39static void
40gnc_window_default_init (GncWindowInterface *klass)
41{
42}
43
44/************************************************************
45 * Interface access functions *
46 ************************************************************/
47
48GtkWindow *
49gnc_window_get_gtk_window (GncWindow *window)
50{
51 g_return_val_if_fail(GNC_WINDOW (window), NULL);
52
53 /* mandatory */
54 g_return_val_if_fail(GNC_WINDOW_GET_IFACE (window)->get_gtk_window, NULL);
55
56 return GNC_WINDOW_GET_IFACE (window)->get_gtk_window (window);
57}
58
59GtkWidget *
60gnc_window_get_statusbar (GncWindow *window)
61{
62 g_return_val_if_fail(GNC_WINDOW (window), NULL);
63
64 /* mandatory */
65 g_return_val_if_fail(GNC_WINDOW_GET_IFACE (window)->get_statusbar, NULL);
66
67 return GNC_WINDOW_GET_IFACE (window)->get_statusbar (window);
68}
69
70GtkWidget *
71gnc_window_get_progressbar (GncWindow *window)
72{
73 g_return_val_if_fail(GNC_WINDOW (window), NULL);
74
75 /* optional */
76 if (GNC_WINDOW_GET_IFACE (window)->get_progressbar == NULL)
77 return NULL;
78
79 return GNC_WINDOW_GET_IFACE (window)->get_progressbar (window);
80}
81
82GtkWidget *
83gnc_window_get_menubar (GncWindow *window)
84{
85 g_return_val_if_fail (GNC_WINDOW(window), NULL);
86
87 /* optional */
88 if (GNC_WINDOW_GET_IFACE(window)->get_menubar == NULL)
89 return NULL;
90
91 return GNC_WINDOW_GET_IFACE(window)->get_menubar (window);
92}
93
94GtkWidget *
95gnc_window_get_toolbar (GncWindow *window)
96{
97 g_return_val_if_fail (GNC_WINDOW(window), NULL);
98
99 /* optional */
100 if (GNC_WINDOW_GET_IFACE(window)->get_toolbar == NULL)
101 return NULL;
102
103 return GNC_WINDOW_GET_IFACE(window)->get_toolbar (window);
104}
105
106GMenuModel *
107gnc_window_get_menubar_model (GncWindow *window)
108{
109 g_return_val_if_fail (GNC_WINDOW(window), NULL);
110
111 /* optional */
112 if (GNC_WINDOW_GET_IFACE(window)->get_menubar_model == NULL)
113 return NULL;
114
115 return GNC_WINDOW_GET_IFACE(window)->get_menubar_model (window);
116}
117
118GtkAccelGroup *
119gnc_window_get_accel_group (GncWindow *window)
120{
121 g_return_val_if_fail (GNC_WINDOW(window), NULL);
122
123 /* optional */
124 if (GNC_WINDOW_GET_IFACE(window)->get_accel_group == NULL)
125 return NULL;
126
127 return GNC_WINDOW_GET_IFACE(window)->get_accel_group (window);
128}
129/************************************************************
130 * Auxiliary status bar functions *
131 ************************************************************/
132
133void
134gnc_window_update_status (GncWindow *window, GncPluginPage *page)
135{
136 GtkWidget *statusbar;
137 const gchar *message;
138
139 g_return_if_fail(GNC_WINDOW (window));
140
141 statusbar = gnc_window_get_statusbar (window);
143 gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 0);
144 gtk_statusbar_push(GTK_STATUSBAR(statusbar), 0, message ? message : " ");
145}
146
147void
148gnc_window_set_status (GncWindow *window, GncPluginPage *page,
149 const gchar *message)
150{
151 g_return_if_fail(GNC_WINDOW (window));
152 g_return_if_fail(GNC_PLUGIN_PAGE (page));
153
154 gnc_plugin_page_set_statusbar_text(page, message);
155 gnc_window_update_status (window, page);
156}
157
158/************************************************************
159 * Auxiliary progress bar functions *
160 ************************************************************/
161
162/*
163 * Single threaded hack. Otherwise the window value has to be passed
164 * all the way down to the backend and then back out again. Not too
165 * bad from C, but also has to be done in Scheme.
166 */
167static GncWindow *progress_bar_hack_window = NULL;
168
169/*
170 * Must be set to a valid window or to NULL (no window).
171 */
172void
173gnc_window_set_progressbar_window (GncWindow *window)
174{
175 if (window != NULL)
176 {
177 g_return_if_fail(GNC_WINDOW (window));
178 }
179
180 progress_bar_hack_window = window;
181}
182
183
184GncWindow *
185gnc_window_get_progressbar_window (void)
186{
187 return progress_bar_hack_window;
188}
189
190
191void
192gnc_window_show_progress (const char *message, double percentage)
193{
194 GncWindow *window;
195 GtkWidget *progressbar;
196 double curr_fraction;
197
198 window = progress_bar_hack_window;
199 if (window == NULL)
200 return;
201
202 progressbar = gnc_window_get_progressbar (window);
203 if (progressbar == NULL)
204 {
205 DEBUG( "no progressbar in hack-window" );
206 return;
207 }
208
209 curr_fraction =
210 round(gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progressbar)) * 100.0);
211
212 if (percentage >= 0 && percentage <= 100 &&
213 round(percentage) == curr_fraction)
214 return; // No change, so don't waste time running the main loop.
215
216 gnc_update_splash_screen(message, percentage);
217
218 if (percentage < 0)
219 {
220 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar), " ");
221 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar), 0.0);
222 if (GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive != NULL)
223 GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive(window, TRUE);
224 }
225 else
226 {
227 if (message && *message)
228 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar), message);
229 if ((percentage == 0.0) &&
230 (GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive != NULL))
231 GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive(window, FALSE);
232 if (percentage <= 100.0)
233 {
234 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar),
235 percentage / 100.0);
236 }
237 else
238 {
239 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
240 }
241 }
242
243 /* make sure new text is up */
244 while (gtk_events_pending ())
245 gtk_main_iteration ();
246}
All type declarations for the whole Gnucash engine.
Functions for adding plugins to a GnuCash window.
Functions that are supported by all types of windows.
const gchar * gnc_plugin_page_get_statusbar_text(GncPluginPage *page)
Retrieve the statusbar text associated with this page.
#define DEBUG(format, args...)
Print a debugging message.
Definition qoflog.h:264
The instance data structure for a content plugin.