GnuCash  5.6-150-g038405b370+
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 gnu@gnu.org *
21 \********************************************************************/
22 
23 #include <config.h>
24 
25 #include <gtk/gtk.h>
26 #include <glib/gi18n.h>
27 #include <math.h>
28 
29 #include "gnc-gnome-utils.h"
30 #include "gnc-splash.h"
31 #include "gnc-version.h"
32 #include "gnc-prefs.h"
33 #include "dialog-utils.h"
34 
35 #define MARKUP_STRING "<span size='small'>%s</span>"
36 #define GNC_PREF_SHOW_SPLASH "show-splash-screen"
37 
38 static GtkWidget * splash = NULL;
39 static GtkWidget * progress = NULL;
40 static GtkWidget * progress_bar = NULL;
41 
42 static void
43 splash_destroy_cb (GtkWidget *object, gpointer user_data)
44 {
45  splash = NULL;
46 }
47 
48 static gboolean
49 button_press_cb(GtkWidget *widget, GdkEventButton *event, gpointer unused)
50 {
51  if (splash)
52  gtk_window_iconify (GTK_WINDOW (splash));
53  return TRUE;
54 }
55 
56 void
57 gnc_show_splash_screen (void)
58 {
59  GtkWidget *pixmap;
60  GtkWidget *frame;
61  GtkWidget *vbox;
62  GtkWidget *hbox;
63  GtkWidget *version;
64  GtkWidget *separator;
65  gchar *ver_string, *markup;
66 
67  if (splash) return;
68  if (!gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_SHOW_SPLASH)) return;
69 
70  splash = gtk_window_new (GTK_WINDOW_TOPLEVEL);
71  gtk_window_set_decorated(GTK_WINDOW (splash), FALSE);
72  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (splash), TRUE);
73 
74  // Set the name for this dialog so it can be easily manipulated with css
75  gtk_widget_set_name (GTK_WIDGET(splash), "gnc-id-splash");
76 
77  g_signal_connect (splash, "destroy",
78  G_CALLBACK (splash_destroy_cb), NULL);
79 
80  gtk_window_set_title (GTK_WINDOW (splash), "GnuCash");
81  gtk_window_set_position (GTK_WINDOW (splash), GTK_WIN_POS_CENTER);
82  gtk_window_set_type_hint (GTK_WINDOW (splash), GDK_WINDOW_TYPE_HINT_DIALOG);
83 
84  pixmap = gnc_gnome_get_pixmap ("gnucash_splash.png");
85 
86  if (!pixmap)
87  {
88  g_warning ("can't find splash pixmap");
89  gtk_widget_destroy (splash);
90  return;
91  }
92 
93  frame = gtk_frame_new (NULL);
94  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 3);
95  gtk_box_set_homogeneous (GTK_BOX (vbox), FALSE);
96  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
97  gtk_box_set_homogeneous (GTK_BOX (hbox), FALSE);
98 
99  ver_string = g_strdup_printf ("%s: %s, %s: %s", _("Version"),
100  gnc_version(), _("Build ID"), gnc_build_id());
101  version = gtk_label_new(NULL);
102  markup = g_markup_printf_escaped(MARKUP_STRING, ver_string);
103  gtk_label_set_markup(GTK_LABEL(version), markup);
104  g_free(markup);
105  g_free(ver_string);
106  separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
107 
108  progress = gtk_label_new(NULL);
109  /* the set_max_width avoids "bumping" of the splash screen
110  if a long string is given in gnc_update_splash_screen();
111  presumably it would be better to inhibit size change of the
112  top level container, but I don't know how to do this */
113  gtk_label_set_max_width_chars(GTK_LABEL(progress), 34);
114  markup = g_markup_printf_escaped(MARKUP_STRING, _("Loading…"));
115  gtk_label_set_markup(GTK_LABEL(progress), markup);
116  g_free(markup);
117 
118  progress_bar = gtk_progress_bar_new ();
119 
120  gtk_container_add (GTK_CONTAINER (frame), pixmap);
121  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
122  gtk_box_pack_start (GTK_BOX (vbox), version, FALSE, FALSE, 0);
123  gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
124  gtk_box_pack_start (GTK_BOX (hbox), progress, TRUE, TRUE, 0);
125  gtk_box_pack_start (GTK_BOX (hbox), progress_bar, FALSE, FALSE, 0);
126  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
127  gtk_container_add (GTK_CONTAINER (splash), vbox);
128 
129  gtk_widget_add_events(splash, GDK_BUTTON_PRESS_MASK);
130  g_signal_connect(splash, "button_press_event",
131  G_CALLBACK(button_press_cb), NULL);
132 
133  gtk_window_set_auto_startup_notification (FALSE);
134  gtk_widget_show_all (splash);
135  gtk_window_set_auto_startup_notification (TRUE);
136 
137  /* make sure splash is up */
138  while (gtk_events_pending ())
139  gtk_main_iteration ();
140 }
141 
142 void
143 gnc_destroy_splash_screen (void)
144 {
145  if (splash)
146  {
147  gtk_widget_destroy (splash);
148  progress = NULL;
149  progress_bar = NULL;
150  splash = NULL;
151  }
152 }
153 
154 void
155 gnc_update_splash_screen (const gchar *string, double percentage)
156 {
157  gchar *markup;
158 
159  if (progress)
160  {
161  if (string && strcmp(string, ""))
162  {
163  markup = g_markup_printf_escaped(MARKUP_STRING, string);
164  gtk_label_set_markup (GTK_LABEL(progress), markup);
165  g_free (markup);
166 
167  /* make sure new text is up */
168  while (gtk_events_pending ())
169  gtk_main_iteration ();
170  }
171  }
172 
173  if (progress_bar )
174  {
175  double curr_fraction =
176  round(gtk_progress_bar_get_fraction(GTK_PROGRESS_BAR(progress_bar)) * 100.0);
177  if (percentage >= 0 && percentage <= 100.0 &&
178  round(percentage) == curr_fraction)
179  return; // No change so don't waste time running the main loop
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 }
203 
204 GtkWindow *gnc_get_splash_screen (void)
205 {
206  return GTK_WINDOW(splash);
207 }
GtkWidget * gnc_gnome_get_pixmap(const char *name)
Given a file name, find and load the requested pixmap.
functions to query various version related strings that were set at build time.
Gnome specific utility functions.
Generic api to store and retrieve preferences.
gboolean gnc_prefs_get_bool(const gchar *group, const gchar *pref_name)
Get a boolean value from the preferences backend.
const char * gnc_version(void)
Parse <prefix>/etc/gnucash/environment and set environment variables based on the contents of that fi...
Definition: gnc-version.c:35