|
GnuCash 2.4.99
|
00001 /* 00002 * gnc-window.c -- structure which represents a GnuCash window. 00003 * 00004 * Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de> 00005 * Copyright (C) 2003 David Hampton <hampton@employees.org> 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License as 00009 * published by the Free Software Foundation; either version 2 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, contact: 00019 * 00020 * Free Software Foundation Voice: +1-617-542-5942 00021 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00022 * Boston, MA 02110-1301, USA gnu@gnu.org 00023 */ 00024 00025 #include "config.h" 00026 00027 #include <gtk/gtk.h> 00028 00029 #include "gnc-engine.h" 00030 #include "gnc-plugin-page.h" 00031 #include "gnc-window.h" 00032 #include "gnc-splash.h" 00033 00034 static QofLogModule log_module = GNC_MOD_GUI; 00035 00036 GType 00037 gnc_window_get_type (void) 00038 { 00039 static GType gnc_window_type = 0; 00040 00041 if (gnc_window_type == 0) 00042 { 00043 static const GTypeInfo our_info = 00044 { 00045 sizeof (GncWindowIface), 00046 NULL, 00047 NULL, 00048 NULL, 00049 NULL, 00050 NULL, 00051 0, 00052 0, 00053 NULL 00054 }; 00055 00056 gnc_window_type = g_type_register_static (G_TYPE_INTERFACE, 00057 "GncWindow", 00058 &our_info, 0); 00059 g_type_interface_add_prerequisite (gnc_window_type, G_TYPE_OBJECT); 00060 } 00061 00062 return gnc_window_type; 00063 } 00064 00065 /************************************************************ 00066 * Interface access functions * 00067 ************************************************************/ 00068 00069 GtkWindow * 00070 gnc_window_get_gtk_window (GncWindow *window) 00071 { 00072 g_return_val_if_fail(GNC_WINDOW (window), NULL); 00073 00074 /* mandatory */ 00075 g_return_val_if_fail(GNC_WINDOW_GET_IFACE (window)->get_gtk_window, NULL); 00076 00077 return GNC_WINDOW_GET_IFACE (window)->get_gtk_window (window); 00078 } 00079 00080 static GtkWidget * 00081 gnc_window_get_statusbar (GncWindow *window) 00082 { 00083 g_return_val_if_fail(GNC_WINDOW (window), NULL); 00084 00085 /* mandatory */ 00086 g_return_val_if_fail(GNC_WINDOW_GET_IFACE (window)->get_statusbar, NULL); 00087 00088 return GNC_WINDOW_GET_IFACE (window)->get_statusbar (window); 00089 } 00090 00091 static GtkWidget * 00092 gnc_window_get_progressbar (GncWindow *window) 00093 { 00094 g_return_val_if_fail(GNC_WINDOW (window), NULL); 00095 00096 /* optional */ 00097 if (GNC_WINDOW_GET_IFACE (window)->get_progressbar == NULL) 00098 return NULL; 00099 00100 return GNC_WINDOW_GET_IFACE (window)->get_progressbar (window); 00101 } 00102 00103 /************************************************************ 00104 * Auxiliary status bar functions * 00105 ************************************************************/ 00106 00107 void 00108 gnc_window_update_status (GncWindow *window, GncPluginPage *page) 00109 { 00110 GtkWidget *statusbar; 00111 const gchar *message; 00112 00113 g_return_if_fail(GNC_WINDOW (window)); 00114 00115 statusbar = gnc_window_get_statusbar (window); 00116 message = gnc_plugin_page_get_statusbar_text(page); 00117 gtk_statusbar_pop(GTK_STATUSBAR(statusbar), 0); 00118 gtk_statusbar_push(GTK_STATUSBAR(statusbar), 0, message ? message : ""); 00119 } 00120 00121 void 00122 gnc_window_set_status (GncWindow *window, GncPluginPage *page, 00123 const gchar *message) 00124 { 00125 g_return_if_fail(GNC_WINDOW (window)); 00126 g_return_if_fail(GNC_PLUGIN_PAGE (page)); 00127 00128 gnc_plugin_page_set_statusbar_text(page, message); 00129 gnc_window_update_status (window, page); 00130 } 00131 00132 /************************************************************ 00133 * Auxiliary progress bar functions * 00134 ************************************************************/ 00135 00136 /* 00137 * Single threaded hack. Otherwise the window value has to be passed 00138 * all the way down to the backend and then back out again. Not too 00139 * bad from C, but also has to be done in Scheme. 00140 */ 00141 static GncWindow *progress_bar_hack_window = NULL; 00142 00143 /* 00144 * Must be set to a valid window or to NULL (no window). 00145 */ 00146 void 00147 gnc_window_set_progressbar_window (GncWindow *window) 00148 { 00149 if (window != NULL) 00150 { 00151 g_return_if_fail(GNC_WINDOW (window)); 00152 } 00153 00154 progress_bar_hack_window = window; 00155 } 00156 00157 00158 GncWindow * 00159 gnc_window_get_progressbar_window (void) 00160 { 00161 return progress_bar_hack_window; 00162 } 00163 00164 00165 void 00166 gnc_window_show_progress (const char *message, double percentage) 00167 { 00168 GncWindow *window; 00169 GtkWidget *progressbar; 00170 00171 window = progress_bar_hack_window; 00172 if (window == NULL) 00173 return; 00174 00175 progressbar = gnc_window_get_progressbar (window); 00176 if (progressbar == NULL) 00177 { 00178 DEBUG( "no progressbar in hack-window" ); 00179 return; 00180 } 00181 00182 gnc_update_splash_screen(message, percentage); 00183 00184 if (percentage < 0) 00185 { 00186 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar), " "); 00187 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar), 0.0); 00188 if (GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive != NULL) 00189 GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive(window, TRUE); 00190 } 00191 else 00192 { 00193 if (message) 00194 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar), message); 00195 if ((percentage == 0) && 00196 (GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive != NULL)) 00197 GNC_WINDOW_GET_IFACE(window)->ui_set_sensitive(window, FALSE); 00198 if (percentage <= 100) 00199 { 00200 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progressbar), 00201 percentage / 100); 00202 } 00203 else 00204 { 00205 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); 00206 } 00207 } 00208 00209 /* make sure new text is up */ 00210 while (gtk_events_pending ()) 00211 gtk_main_iteration (); 00212 }
1.7.4