]> git.sur5r.net Git - glabels/blob - glabels2/src/splash.c
Initial revision
[glabels] / glabels2 / src / splash.c
1 /*
2  *  (GLABELS) Label and Business Card Creation program for GNOME
3  *
4  *  splash.c:  Splash screen module
5  *
6  *  Copyright (C) 2001-2002  Jim Evins <evins@snaught.com>.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  */
22
23 #include "config.h"
24
25 #include <gtk/gtk.h>
26 #include <libgnome/libgnome.h>
27
28 #include "splash.h"
29
30 #include "debug.h"
31
32 #ifdef PACKAGE_DATA_DIR
33 #define SPLASH_PIXMAP (PACKAGE_DATA_DIR "/pixmaps/glabels/glabels-logo.png")
34 #else
35 #define SPLASH_PIXMAP gnome_pixmap_file("glabels/glabels-logo.png")
36 #endif
37
38 #define SPLASH_TIMEOUT 2000
39
40 static GtkWidget *splash = NULL;
41
42 static gint splash_timeout (gpointer not_used);
43
44 \f
45 /***************************************************************************/
46 /* Create splash screen.                                                   */
47 /***************************************************************************/
48 void
49 gl_splash (void)
50 {
51         GtkWidget *wimage, *wvbox, *whbox, *wframe1, *wframe2;
52         gchar *label;
53         GdkPixbuf *pixbuf;
54         GError *gerror = NULL;
55
56         if (splash)
57                 return;
58
59         splash = gtk_window_new (GTK_WINDOW_POPUP);
60         gtk_window_set_position (GTK_WINDOW (splash), GTK_WIN_POS_CENTER);
61
62         wframe1 = gtk_frame_new (NULL);
63         gtk_frame_set_shadow_type (GTK_FRAME (wframe1), GTK_SHADOW_OUT);
64         wframe2 = gtk_frame_new (NULL);
65
66         wvbox = gtk_vbox_new (FALSE, 5);
67         gtk_container_set_border_width (GTK_CONTAINER (wvbox), 2);
68
69         whbox = gtk_hbox_new (FALSE, 5);
70
71         if (!g_file_test (SPLASH_PIXMAP, G_FILE_TEST_EXISTS)) {
72                 g_warning ("Could not find %s", SPLASH_PIXMAP);
73         }
74         pixbuf = gdk_pixbuf_new_from_file (SPLASH_PIXMAP, &gerror);
75         if (gerror != NULL) {
76                 g_warning ("cannot open splash pixbuf: %s", gerror->message );
77                 gtk_widget_destroy (splash);
78                 return;
79         }
80         wimage = gtk_image_new_from_pixbuf (pixbuf);
81
82         gtk_container_add (GTK_CONTAINER (splash), wframe1);
83         gtk_container_add (GTK_CONTAINER (wframe1), wframe2);
84         gtk_container_add (GTK_CONTAINER (wframe2), wvbox);
85
86         gtk_box_pack_start (GTK_BOX (wvbox), wimage, TRUE, TRUE, 0);
87
88         label = g_strdup_printf ("Version %s", VERSION);
89         gtk_box_pack_start (GTK_BOX (wvbox),
90                             gtk_label_new (label), TRUE, TRUE, 0);
91         g_free (label);
92
93         gtk_widget_show_all (splash);
94
95         gtk_timeout_add (SPLASH_TIMEOUT, splash_timeout, NULL);
96
97         while (gtk_events_pending ()) {
98                 gtk_main_iteration ();
99         }
100 }
101
102 /*-------------------------------------------------------------------------*/
103 /* PRIVATE.  Callback to tear-down splash screen once timer has expired.   */
104 /*-------------------------------------------------------------------------*/
105 static gint
106 splash_timeout (gpointer not_used)
107 {
108         if (splash) {
109                 gtk_widget_destroy (splash);
110                 splash = NULL;
111         }
112
113         return FALSE;
114 }
115