GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-window.c
1 /*
2  * gnc-window.c -- structure which represents a GnuCash window.
3  *
4  * Copyright (C) 2003 Jan Arne Petersen <[email protected]>
5  * Copyright (C) 2003 David Hampton <[email protected]>
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 [email protected]
23  */
24 
25 #include "config.h"
26 
27 #include <gtk/gtk.h>
28 
29 #include "gnc-engine.h"
30 #include "gnc-plugin-page.h"
31 #include "gnc-window.h"
32 #include "gnc-splash.h"
33 
34 static QofLogModule log_module = GNC_MOD_GUI;
35 
36 GType
37 gnc_window_get_type (void)
38 {
39  static GType gnc_window_type = 0;
40 
41  if (gnc_window_type == 0)
42  {
43  static const GTypeInfo our_info =
44  {
45  sizeof (GncWindowIface),
46  NULL,
47  NULL,
48  NULL,
49  NULL,
50  NULL,
51  0,
52  0,
53  NULL
54  };
55 
56  gnc_window_type = g_type_register_static (G_TYPE_INTERFACE,
57  "GncWindow",
58  &our_info, 0);
59  g_type_interface_add_prerequisite (gnc_window_type, G_TYPE_OBJECT);
60  }
61 
62  return gnc_window_type;
63 }
64 
65 /************************************************************
66  * Interface access functions *
67  ************************************************************/
68 
69 GtkWindow *
70 gnc_window_get_gtk_window (GncWindow *window)
71 {
72  g_return_val_if_fail(GNC_WINDOW (window), NULL);
73 
74  /* mandatory */
75  g_return_val_if_fail(GNC_WINDOW_GET_IFACE (window)->get_gtk_window, NULL);
76 
77  return GNC_WINDOW_GET_IFACE (window)->get_gtk_window (window);
78 }
79 
80 static GtkWidget *
81 gnc_window_get_statusbar (GncWindow *window)
82 {
83  g_return_val_if_fail(GNC_WINDOW (window), NULL);
84 
85  /* mandatory */
86  g_return_val_if_fail(GNC_WINDOW_GET_IFACE (window)->get_statusbar, NULL);
87 
88  return GNC_WINDOW_GET_IFACE (window)->get_statusbar (window);
89 }
90 
91 static GtkWidget *
92 gnc_window_get_progressbar (GncWindow *window)
93 {
94  g_return_val_if_fail(GNC_WINDOW (window), NULL);
95 
96  /* optional */
97  if (GNC_WINDOW_GET_IFACE (window)->get_progressbar == NULL)
98  return NULL;
99 
100  return GNC_WINDOW_GET_IFACE (window)->get_progressbar (window);
101 }
102 
103 /************************************************************
104  * Auxiliary status bar functions *
105  ************************************************************/
106 
107 void
108 gnc_window_update_status (GncWindow *window, GncPluginPage *page)
109 {
110  GtkWidget *statusbar;
111  const gchar *message;
112 
113  g_return_if_fail(GNC_WINDOW (window));
114 
115  statusbar = gnc_window_get_statusbar (window);
116  message = gnc_plugin_page_get_statusbar_text(page);
117  gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 0);
118  gtk_statusbar_push(GTK_STATUSBAR(statusbar), 0, message ? message : "");
119 }
120 
121 void
122 gnc_window_set_status (GncWindow *window, GncPluginPage *page,
123  const gchar *message)
124 {
125  g_return_if_fail(GNC_WINDOW (window));
126  g_return_if_fail(GNC_PLUGIN_PAGE (page));
127 
128  gnc_plugin_page_set_statusbar_text(page, message);
129  gnc_window_update_status (window, page);
130 }
131 
132 /************************************************************
133  * Auxiliary progress bar functions *
134  ************************************************************/
135 
136 /*
137  * Single threaded hack. Otherwise the window value has to be passed
138  * all the way down to the backend and then back out again. Not too
139  * bad from C, but also has to be done in Scheme.
140  */
141 static GncWindow *progress_bar_hack_window = NULL;
142 
143 /*
144  * Must be set to a valid window or to NULL (no window).
145  */
146 void
147 gnc_window_set_progressbar_window (GncWindow *window)
148 {
149  if (window != NULL)
150  {
151  g_return_if_fail(GNC_WINDOW (window));
152  }
153 
154  progress_bar_hack_window = window;
155 }
156 
157 
158 GncWindow *
159 gnc_window_get_progressbar_window (void)
160 {
161  return progress_bar_hack_window;
162 }
163 
164 
165 void
166 gnc_window_show_progress (const char *message, double percentage)
167 {
168  GncWindow *window;
169  GtkWidget *progressbar;
170 
171  window = progress_bar_hack_window;
172  if (window == NULL)
173  return;
174 
175  progressbar = gnc_window_get_progressbar (window);
176  if (progressbar == NULL)
177  {
178  DEBUG( "no progressbar in hack-window" );
179  return;
180  }
181 
182  gnc_update_splash_screen(message, percentage);
183 
184  if (percentage < 0)
185  {
186  gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar), " ");
187  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar), 0.0);
188  if (GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive != NULL)
189  GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive(window, TRUE);
190  }
191  else
192  {
193  if (message)
194  gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar), message);
195  if ((percentage == 0) &&
196  (GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive != NULL))
197  GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive(window, FALSE);
198  if (percentage <= 100)
199  {
200  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar),
201  percentage / 100);
202  }
203  else
204  {
205  gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar));
206  }
207  }
208 
209  /* make sure new text is up */
210  while (gtk_events_pending ())
211  gtk_main_iteration ();
212 }
void gnc_plugin_page_set_statusbar_text(GncPluginPage *page, const char *name)
#define DEBUG(format, args...)
Definition: qoflog.h:255
Functions that are supported by all types of windows.
Functions for adding plugins to a GnuCash window.
const gchar * gnc_plugin_page_get_statusbar_text(GncPluginPage *page)
All type declarations for the whole Gnucash engine.
const gchar * QofLogModule
Definition: qofid.h:89