From ba69a12a2c2dc4cb70b1f46397d82f04730a5950 Mon Sep 17 00:00:00 2001 From: Joshua Sled Date: Tue, 1 Jan 2008 20:07:22 +0000 Subject: [PATCH] Bug#506714: Add progress bar to splash; patch from Herbert Thoma . BP git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@16779 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/bin/gnucash-bin.c | 8 ++++---- src/gnome-utils/gnc-splash.c | 40 ++++++++++++++++++++++++++++++++---- src/gnome-utils/gnc-splash.h | 4 +++- src/gnome-utils/gnc-window.c | 2 +- 4 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/bin/gnucash-bin.c b/src/bin/gnucash-bin.c index 09f0473f96..8b699b9213 100644 --- a/src/bin/gnucash-bin.c +++ b/src/bin/gnucash-bin.c @@ -140,7 +140,7 @@ try_load_config_array(const gchar *fns[]) static void update_message(const gchar *msg) { - gnc_update_splash_screen(msg); + gnc_update_splash_screen(msg, GNC_SPLASH_PERCENTAGE_UNKNOWN); g_message(msg); } @@ -353,7 +353,7 @@ load_gnucash_modules() /* module initializations go here */ len = sizeof(modules) / sizeof(*modules); for (i = 0; i < len; i++) { - gnc_update_splash_screen(modules[i].name); + gnc_update_splash_screen(modules[i].name, GNC_SPLASH_PERCENTAGE_UNKNOWN); if (modules[i].optional) gnc_module_load_optional(modules[i].name, modules[i].version); else @@ -464,14 +464,14 @@ inner_main (void *closure, int argc, char **argv) scm_c_eval_string("(gnc:main)"); /* Install Price Quote Sources */ - gnc_update_splash_screen(_("Checking Finance::Quote...")); + gnc_update_splash_screen(_("Checking Finance::Quote..."), GNC_SPLASH_PERCENTAGE_UNKNOWN); scm_c_use_module("gnucash price-quotes"); scm_c_eval_string("(gnc:price-quotes-install-sources)"); gnc_hook_run(HOOK_STARTUP, NULL); if (!nofile && (fn = get_file_to_load())) { - gnc_update_splash_screen(_("Loading data...")); + gnc_update_splash_screen(_("Loading data..."), GNC_SPLASH_PERCENTAGE_UNKNOWN); gnc_file_open_file(fn); g_free(fn); } diff --git a/src/gnome-utils/gnc-splash.c b/src/gnome-utils/gnc-splash.c index 2cadc5c415..0e38472cc4 100644 --- a/src/gnome-utils/gnc-splash.c +++ b/src/gnome-utils/gnc-splash.c @@ -33,6 +33,7 @@ static GtkWidget * splash = NULL; static GtkWidget * progress = NULL; +static GtkWidget * progress_bar = NULL; static int splash_is_initialized = FALSE; static void @@ -63,6 +64,7 @@ gnc_show_splash_screen (void) GtkWidget *pixmap; GtkWidget *frame; GtkWidget *vbox; + GtkWidget *hbox; GtkWidget *version; GtkWidget *separator; gchar *ver_string, *markup; @@ -90,6 +92,7 @@ gnc_show_splash_screen (void) frame = gtk_frame_new (NULL); vbox = gtk_vbox_new (FALSE, 3); + hbox = gtk_hbox_new (FALSE, 3); #ifdef GNUCASH_SVN /* Development version */ ver_string = g_strdup_printf(_("Version: GnuCash-%s svn (r%s built %s)"), @@ -112,16 +115,20 @@ gnc_show_splash_screen (void) if a long string is given in gnc_update_splash_screen(); presumably it would be better to inhibit size change of the top level container, but I don't know how to do this */ - gtk_label_set_max_width_chars(GTK_LABEL(progress), 50); + gtk_label_set_max_width_chars(GTK_LABEL(progress), 34); markup = g_markup_printf_escaped(MARKUP_STRING, _("Loading...")); gtk_label_set_markup(GTK_LABEL(progress), markup); g_free(markup); + progress_bar = gtk_progress_bar_new (); + gtk_container_add (GTK_CONTAINER (frame), pixmap); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), version, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), progress, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), progress, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (hbox), progress_bar, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (splash), vbox); gtk_widget_add_events(splash, GDK_BUTTON_PRESS_MASK); @@ -144,12 +151,13 @@ gnc_destroy_splash_screen (void) { gtk_widget_destroy (splash); progress = NULL; + progress_bar = NULL; splash = NULL; } } void -gnc_update_splash_screen (const gchar *string) +gnc_update_splash_screen (const gchar *string, double percentage) { gchar *markup; @@ -163,7 +171,31 @@ gnc_update_splash_screen (const gchar *string) /* make sure new text is up */ while (gtk_events_pending ()) - gtk_main_iteration (); + gtk_main_iteration (); } } + + if (progress_bar) + { + if (percentage < 0) + { + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), 0.0); + } + else + { + if (percentage <= 100) + { + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), + percentage/100); + } + else + { + gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar)); + } + } + + /* make sure new status bar is up */ + while (gtk_events_pending ()) + gtk_main_iteration (); + } } diff --git a/src/gnome-utils/gnc-splash.h b/src/gnome-utils/gnc-splash.h index fdaff012b2..1d4402acfb 100644 --- a/src/gnome-utils/gnc-splash.h +++ b/src/gnome-utils/gnc-splash.h @@ -25,7 +25,9 @@ void gnc_show_splash_screen (void); void gnc_destroy_splash_screen (void); -void gnc_update_splash_screen (const gchar *string); +void gnc_update_splash_screen (const gchar *string, double percentage); void gnc_gui_init_splash (void); +#define GNC_SPLASH_PERCENTAGE_UNKNOWN 101 + #endif diff --git a/src/gnome-utils/gnc-window.c b/src/gnome-utils/gnc-window.c index fe46d9f3b5..022d8e14c9 100644 --- a/src/gnome-utils/gnc-window.c +++ b/src/gnome-utils/gnc-window.c @@ -175,7 +175,7 @@ gnc_window_show_progress (const char *message, double percentage) return; } - gnc_update_splash_screen(message); + gnc_update_splash_screen(message, percentage); if (percentage < 0) { gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progressbar), " ");