GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-splash.c
1 /********************************************************************\
2  * gnc-splash.c -- splash screen for GnuCash *
3  * Copyright (C) 2001 Gnumatic, Inc. *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License*
16  * along with this program; if not, contact: *
17  * *
18  * Free Software Foundation Voice: +1-617-542-5942 *
19  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
20  * Boston, MA 02110-1301, USA [email protected] *
21 \********************************************************************/
22 
23 #include "config.h"
24 
25 #include <gtk/gtk.h>
26 #include <glib/gi18n.h>
27 
28 #include "gnc-gnome-utils.h"
29 #include "gnc-splash.h"
30 #include "core-utils/gnc-version.h"
31 #include "gnc-prefs.h"
32 
33 #define MARKUP_STRING "<span size='small'>%s</span>"
34 #define GNC_PREF_SHOW_SPLASH "show-splash-screen"
35 
36 static GtkWidget * splash = NULL;
37 static GtkWidget * progress = NULL;
38 static GtkWidget * progress_bar = NULL;
39 
40 static void
41 splash_destroy_cb (GtkObject *object, gpointer user_data)
42 {
43  splash = NULL;
44 }
45 
46 static gboolean
47 button_press_cb(GtkWidget *widget, GdkEventButton *event, gpointer unused)
48 {
49  gnc_destroy_splash_screen();
50  return TRUE;
51 }
52 
53 void
54 gnc_show_splash_screen (void)
55 {
56  GtkWidget *pixmap;
57  GtkWidget *frame;
58  GtkWidget *vbox;
59  GtkWidget *hbox;
60  GtkWidget *version;
61  GtkWidget *separator;
62  gchar *ver_string, *markup;
63 
64  if (splash) return;
65  if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SHOW_SPLASH)) return;
66 
67  splash = gtk_window_new (GTK_WINDOW_TOPLEVEL);
68  gtk_window_set_decorated(GTK_WINDOW (splash), FALSE);
69  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (splash), TRUE);
70 
71  g_signal_connect (splash, "destroy",
72  G_CALLBACK (splash_destroy_cb), NULL);
73 
74  gtk_window_set_title (GTK_WINDOW (splash), "GnuCash");
75  gtk_window_set_position (GTK_WINDOW (splash), GTK_WIN_POS_CENTER);
76 
77  pixmap = gnc_gnome_get_pixmap ("gnucash_splash.png");
78 
79  if (!pixmap)
80  {
81  g_warning ("can't find splash pixmap");
82  gtk_widget_destroy (splash);
83  return;
84  }
85 
86  frame = gtk_frame_new (NULL);
87  vbox = gtk_vbox_new (FALSE, 3);
88  hbox = gtk_hbox_new (FALSE, 3);
89 #ifdef GNUCASH_SCM
90  /* Development version */
91  /* Translators: 1st %s is the GnuCash version (eg 2.4.11);
92  2nd %s is the scm type (svn/svk/git/bzr);
93  3rd %s is the scm revision number;
94  4th %s is the build date */
95  ver_string = g_strdup_printf(_("Version: GnuCash-%s %s (rev %s built %s)"),
96  VERSION, GNUCASH_SCM, GNUCASH_SCM_REV,
97  GNUCASH_BUILD_DATE);
98 #else
99  /* Dist Tarball */
100  /* Translators: 1st %s is the GnuCash version (eg 2.4.11);
101  2nd %s is the scm (svn/svk/git/bzr) revision number;
102  3rd %s is the build date */
103  ver_string = g_strdup_printf(_("Version: GnuCash-%s (rev %s built %s)"),
104  VERSION, GNUCASH_SCM_REV, GNUCASH_BUILD_DATE);
105 #endif
106 
107  version = gtk_label_new(NULL);
108  markup = g_markup_printf_escaped(MARKUP_STRING, ver_string);
109  gtk_label_set_markup(GTK_LABEL(version), markup);
110  g_free(markup);
111  g_free(ver_string);
112  separator = gtk_hseparator_new();
113 
114  progress = gtk_label_new(NULL);
115  /* the set_max_width avoids "bumping" of the splash screen
116  if a long string is given in gnc_update_splash_screen();
117  presumably it would be better to inhibit size change of the
118  top level container, but I don't know how to do this */
119  gtk_label_set_max_width_chars(GTK_LABEL(progress), 34);
120  markup = g_markup_printf_escaped(MARKUP_STRING, _("Loading..."));
121  gtk_label_set_markup(GTK_LABEL(progress), markup);
122  g_free(markup);
123 
124  progress_bar = gtk_progress_bar_new ();
125 
126  gtk_container_add (GTK_CONTAINER (frame), pixmap);
127  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
128  gtk_box_pack_start (GTK_BOX (vbox), version, FALSE, FALSE, 0);
129  gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
130  gtk_box_pack_start (GTK_BOX (hbox), progress, TRUE, TRUE, 0);
131  gtk_box_pack_start (GTK_BOX (hbox), progress_bar, FALSE, FALSE, 0);
132  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
133  gtk_container_add (GTK_CONTAINER (splash), vbox);
134 
135  gtk_widget_add_events(splash, GDK_BUTTON_PRESS_MASK);
136  g_signal_connect(splash, "button_press_event",
137  G_CALLBACK(button_press_cb), NULL);
138 
139  gtk_window_set_auto_startup_notification (FALSE);
140  gtk_widget_show_all (splash);
141  gtk_window_set_auto_startup_notification (TRUE);
142 
143  /* make sure splash is up */
144  while (gtk_events_pending ())
145  gtk_main_iteration ();
146 }
147 
148 void
149 gnc_destroy_splash_screen (void)
150 {
151  if (splash)
152  {
153  gtk_widget_destroy (splash);
154  progress = NULL;
155  progress_bar = NULL;
156  splash = NULL;
157  }
158 }
159 
160 void
161 gnc_update_splash_screen (const gchar *string, double percentage)
162 {
163  gchar *markup;
164 
165  if (progress)
166  {
167  if (string && strcmp(string, ""))
168  {
169  markup = g_markup_printf_escaped(MARKUP_STRING, string);
170  gtk_label_set_markup (GTK_LABEL(progress), markup);
171  g_free (markup);
172 
173  /* make sure new text is up */
174  while (gtk_events_pending ())
175  gtk_main_iteration ();
176  }
177  }
178 
179  if (progress_bar)
180  {
181  if (percentage < 0)
182  {
183  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), 0.0);
184  }
185  else
186  {
187  if (percentage <= 100)
188  {
189  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar),
190  percentage / 100);
191  }
192  else
193  {
194  gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress_bar));
195  }
196  }
197 
198  /* make sure new status bar is up */
199  while (gtk_events_pending ())
200  gtk_main_iteration ();
201  }
202 }
GtkWidget * gnc_gnome_get_pixmap(const char *name)
Gnome specific utility functions.
Generic api to store and retrieve preferences.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Definition: gnc-prefs.c:196