1 /* XQF - Quake server browser and launcher
2  * Splash screen
3  * Copyright (C) 2002 Ludwig Nussel <l-n@users.sourceforge.net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (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, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18  */
19 
20 #include "gnuconfig.h"
21 
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <unistd.h>
25 #include <string.h>
26 
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtk.h>
29 
30 #include "splash.h"
31 #include "xqf-ui.h"
32 #include "loadpixmap.h"
33 #include "i18n.h"
34 #include "pref.h"
35 #include "xutils.h"
36 
37 static GtkWidget* splashscreen;
38 static guint current_progress;
39 
destroy_splashscreen(void)40 void destroy_splashscreen(void) {
41 	if (!splashscreen) return;
42 
43 	gtk_widget_destroy(splashscreen);
44 	splashscreen = NULL;
45 }
46 
create_splashscreen(void)47 void create_splashscreen (void) {
48 	GtkWidget *vbox1;
49 	GtkWidget *logo;
50 	GtkWidget *entry;
51 	GtkWidget *progress;
52 
53 	if (splashscreen) return;
54 
55 	if (!default_show_splash) return;
56 
57 	splashscreen = gtk_window_new (GTK_WINDOW_TOPLEVEL);
58 	gtk_object_set_data (GTK_OBJECT (splashscreen), "splashscreen", splashscreen);
59 	gtk_window_set_title (GTK_WINDOW (splashscreen), _("XQF: Loading"));
60 	gtk_window_set_position (GTK_WINDOW (splashscreen), GTK_WIN_POS_CENTER);
61 	gtk_window_set_modal (GTK_WINDOW (splashscreen), TRUE);
62 	gtk_window_set_type_hint(GTK_WINDOW (splashscreen), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
63 
64 	vbox1 = gtk_vbox_new (FALSE, 0);
65 	gtk_widget_ref (vbox1);
66 	gtk_object_set_data_full (GTK_OBJECT (splashscreen), "vbox1", vbox1,
67 			(GtkDestroyNotify) gtk_widget_unref);
68 	gtk_widget_show (vbox1);
69 	gtk_container_add (GTK_CONTAINER (splashscreen), vbox1);
70 	gtk_container_set_border_width (GTK_CONTAINER (vbox1), 3);
71 
72 	logo = load_pixmap (splashscreen, "splash.png");
73 	gtk_widget_ref (logo);
74 	gtk_object_set_data_full (GTK_OBJECT (splashscreen), "logo", logo,
75 			(GtkDestroyNotify) gtk_widget_unref);
76 	gtk_widget_show (logo);
77 	gtk_box_pack_start (GTK_BOX (vbox1), logo, TRUE, TRUE, 0);
78 
79 	entry = gtk_entry_new ();
80 	gtk_widget_ref (entry);
81 	gtk_object_set_data_full (GTK_OBJECT (splashscreen), "entry", entry,
82 			(GtkDestroyNotify) gtk_widget_unref);
83 	gtk_widget_show (entry);
84 	gtk_box_pack_start (GTK_BOX (vbox1), entry, FALSE, FALSE, 0);
85 	gtk_entry_set_editable (GTK_ENTRY (entry), FALSE);
86 	gtk_entry_set_text (GTK_ENTRY (entry), _("Loading ..."));
87 
88 	progress = gtk_progress_bar_new ();
89 	gtk_widget_ref (progress);
90 	gtk_object_set_data_full (GTK_OBJECT (splashscreen), "progress", progress,
91 			(GtkDestroyNotify) gtk_widget_unref);
92 	gtk_widget_show (progress);
93 	gtk_box_pack_start (GTK_BOX (vbox1), progress, FALSE, FALSE, 0);
94 	gtk_progress_configure (GTK_PROGRESS (progress), 42, 0, 100);
95 
96 	gtk_signal_connect (GTK_OBJECT (splashscreen), "destroy",
97 			GTK_SIGNAL_FUNC (destroy_splashscreen), NULL);
98 
99 	gtk_widget_show (splashscreen);
100 
101 	// force it to draw now.
102 	gdk_flush();
103 
104 	// go into main loop, processing events.
105 	while (gtk_events_pending() || !GTK_WIDGET_REALIZED(logo))
106 		gtk_main_iteration();
107 
108 	// test
109 	while (gdk_events_pending())
110 		gdk_flush();
111 
112 	current_progress = 0;
113 }
114 
115 /* set percentage on splash screen, thanks to lopster for this code */
splash_set_progress(const char * message,guint per)116 void splash_set_progress(const char* message, guint per) {
117 	GtkProgressBar* progress;
118 	GtkEntry* entry;
119 
120 	if (!splashscreen) return;
121 
122 	if (per > 100) per = 100;
123 
124 	current_progress = per;
125 
126 	progress = GTK_PROGRESS_BAR(lookup_widget(splashscreen, "progress"));
127 	entry = GTK_ENTRY(lookup_widget(splashscreen, "entry"));
128 	if (message)
129 		gtk_entry_set_text(entry, message);
130 	gtk_progress_bar_update(progress, per*1.0/100);
131 
132 	while (gtk_events_pending())
133 		gtk_main_iteration();
134 }
135 
splash_increase_progress(const char * message,guint per)136 void splash_increase_progress(const char* message, guint per) {
137 	if (!splashscreen) return;
138 	splash_set_progress(message,current_progress+per);
139 }
140