File: splash.c

package info (click to toggle)
xqf 1.0.6-5
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 4,048 kB
  • sloc: ansic: 31,166; sh: 1,451; xml: 1,039; makefile: 257; perl: 131
file content (139 lines) | stat: -rw-r--r-- 4,292 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* XQF - Quake server browser and launcher
 * Splash screen
 * Copyright (C) 2002 Ludwig Nussel <l-n@users.sourceforge.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 */

#include "gnuconfig.h"

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>

#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>

#include "splash.h"
#include "xqf-ui.h"
#include "loadpixmap.h"
#include "i18n.h"
#include "pref.h"
#include "xutils.h"

static GtkWidget* splashscreen;
static guint current_progress;

void destroy_splashscreen(void) {
	if (!splashscreen) return;

	gtk_widget_destroy(splashscreen);
	splashscreen = NULL;
}

void create_splashscreen (void) {
	GtkWidget *vbox1;
	GtkWidget *logo;
	GtkWidget *entry;
	GtkWidget *progress;

	if (splashscreen) return;

	if (!default_show_splash) return;

	splashscreen = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_object_set_data (GTK_OBJECT (splashscreen), "splashscreen", splashscreen);
	gtk_window_set_title (GTK_WINDOW (splashscreen), _("XQF: Loading"));
	gtk_window_set_position (GTK_WINDOW (splashscreen), GTK_WIN_POS_CENTER);
	gtk_window_set_modal (GTK_WINDOW (splashscreen), TRUE);
	gtk_window_set_type_hint(GTK_WINDOW (splashscreen), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);

	vbox1 = gtk_vbox_new (FALSE, 0);
	gtk_widget_ref (vbox1);
	gtk_object_set_data_full (GTK_OBJECT (splashscreen), "vbox1", vbox1,
			(GtkDestroyNotify) gtk_widget_unref);
	gtk_widget_show (vbox1);
	gtk_container_add (GTK_CONTAINER (splashscreen), vbox1);
	gtk_container_set_border_width (GTK_CONTAINER (vbox1), 3);

	logo = load_pixmap (splashscreen, "splash.png");
	gtk_widget_ref (logo);
	gtk_object_set_data_full (GTK_OBJECT (splashscreen), "logo", logo,
			(GtkDestroyNotify) gtk_widget_unref);
	gtk_widget_show (logo);
	gtk_box_pack_start (GTK_BOX (vbox1), logo, TRUE, TRUE, 0);

	entry = gtk_entry_new ();
	gtk_widget_ref (entry);
	gtk_object_set_data_full (GTK_OBJECT (splashscreen), "entry", entry,
			(GtkDestroyNotify) gtk_widget_unref);
	gtk_widget_show (entry);
	gtk_box_pack_start (GTK_BOX (vbox1), entry, FALSE, FALSE, 0);
	gtk_entry_set_editable (GTK_ENTRY (entry), FALSE);
	gtk_entry_set_text (GTK_ENTRY (entry), _("Loading ..."));

	progress = gtk_progress_bar_new ();
	gtk_widget_ref (progress);
	gtk_object_set_data_full (GTK_OBJECT (splashscreen), "progress", progress,
			(GtkDestroyNotify) gtk_widget_unref);
	gtk_widget_show (progress);
	gtk_box_pack_start (GTK_BOX (vbox1), progress, FALSE, FALSE, 0);
	gtk_progress_configure (GTK_PROGRESS (progress), 42, 0, 100);

	gtk_signal_connect (GTK_OBJECT (splashscreen), "destroy",
			GTK_SIGNAL_FUNC (destroy_splashscreen), NULL);

	gtk_widget_show (splashscreen);

	// force it to draw now.
	gdk_flush();

	// go into main loop, processing events.
	while (gtk_events_pending() || !GTK_WIDGET_REALIZED(logo))
		gtk_main_iteration();

	// test
	while (gdk_events_pending())
		gdk_flush();

	current_progress = 0;
}

/* set percentage on splash screen, thanks to lopster for this code */
void splash_set_progress(const char* message, guint per) {
	GtkProgressBar* progress;
	GtkEntry* entry;

	if (!splashscreen) return;

	if (per > 100) per = 100;

	current_progress = per;

	progress = GTK_PROGRESS_BAR(lookup_widget(splashscreen, "progress"));
	entry = GTK_ENTRY(lookup_widget(splashscreen, "entry"));
	if (message)
		gtk_entry_set_text(entry, message);
	gtk_progress_bar_update(progress, per*1.0/100);

	while (gtk_events_pending())
		gtk_main_iteration();
}

void splash_increase_progress(const char* message, guint per) {
	if (!splashscreen) return;
	splash_set_progress(message,current_progress+per);
}