1
/* $Id: xfsm-splash-screen.c 4711 2004-11-01 16:10:55Z benny $ */
3
* Copyright (c) 2003-2004 Benedikt Meurer <benny@xfce.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2, or (at your option)
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
35
#include <libxfce4util/libxfce4util.h>
36
#include <libxfcegui4/libxfcegui4.h>
38
#include <libxfsm/xfsm-splash-engine.h>
39
#include <libxfsm/xfsm-util.h>
41
#include <xfce4-session/xfsm-chooser.h>
42
#include <xfce4-session/xfsm-splash-screen.h>
45
struct _XfsmSplashScreen
47
XfsmSplashEngine engine;
52
static void xfsm_splash_screen_load (XfsmSplashScreen *splash,
57
xfsm_splash_screen_new (GdkDisplay *display,
60
XfsmSplashScreen *splash;
61
XfsmSplashRc *splash_rc;
67
/* locate monitor with pointer */
68
screen = xfce_gdk_display_locate_monitor_with_pointer (display, &monitor);
69
if (G_UNLIKELY (screen == NULL))
71
screen = gdk_display_get_screen (display, 0);
75
/* initialize the screen struct */
76
splash = g_new0 (XfsmSplashScreen, 1);
77
splash->engine.display = display;
78
splash->engine.primary_screen = screen;
79
splash->engine.primary_monitor = monitor;
81
/* load and setup the engine */
82
if (G_LIKELY (engine != NULL && *engine != '\0'))
84
xfsm_splash_screen_load (splash, engine);
85
if (G_LIKELY (splash->engine.setup != NULL))
87
rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG,
88
"xfce4-session/xfce4-splash.rc",
90
g_snprintf (name, 128, "Engine: %s", engine);
91
splash_rc = xfsm_splash_rc_new (rc, name);
92
splash->engine.setup (&splash->engine, splash_rc);
93
xfsm_splash_rc_free (splash_rc);
105
xfsm_splash_screen_start (XfsmSplashScreen *splash,
110
if (G_LIKELY (splash->engine.start != NULL))
112
splash->engine.start (&splash->engine, name, preview, steps);
119
xfsm_splash_screen_next (XfsmSplashScreen *splash,
122
if (G_LIKELY (splash->engine.next != NULL))
124
splash->engine.next (&splash->engine, text);
131
xfsm_splash_screen_run (XfsmSplashScreen *splash,
136
if (G_LIKELY (splash->engine.run != NULL))
138
result = splash->engine.run (&splash->engine, dialog);
142
xfce_gtk_window_center_on_monitor (GTK_WINDOW (dialog),
143
splash->engine.primary_screen,
144
splash->engine.primary_monitor);
146
result = gtk_dialog_run (GTK_DIALOG (dialog));
154
xfsm_splash_screen_choose (XfsmSplashScreen *splash,
156
const gchar *default_session,
166
g_assert (default_session != NULL);
168
if (splash->engine.choose != NULL)
170
result = splash->engine.choose (&splash->engine,
178
xfsm_splash_screen_next (splash, _("Choose session"));
180
chooser = g_object_new (XFSM_TYPE_CHOOSER,
181
"screen", splash->engine.primary_screen,
182
"type", GTK_WINDOW_POPUP,
184
xfsm_window_add_border (GTK_WINDOW (chooser));
185
xfsm_chooser_set_sessions (XFSM_CHOOSER (chooser),
186
sessions, default_session);
187
result = xfsm_splash_screen_run (splash, chooser);
189
if (result == XFSM_RESPONSE_LOAD)
191
if (name_return != NULL)
192
*name_return = xfsm_chooser_get_session (XFSM_CHOOSER (chooser));
193
result = XFSM_CHOOSE_LOAD;
195
else if (result == XFSM_RESPONSE_NEW)
197
result = XFSM_CHOOSE_NEW;
201
result = XFSM_CHOOSE_LOGOUT;
204
gtk_widget_destroy (chooser);
206
if (result == XFSM_CHOOSE_NEW)
208
xfsm_splash_screen_next (splash, _("Choose session name"));
210
dialog = gtk_dialog_new_with_buttons (NULL,
212
GTK_DIALOG_NO_SEPARATOR,
218
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
221
g_snprintf (title, 256, "<big>%s</big>",
222
_("Choose a name for the new session:"));
223
label = gtk_label_new (title);
224
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
225
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
226
label, TRUE, TRUE, 6);
227
gtk_widget_show (label);
229
entry = gtk_entry_new ();
230
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
231
entry, TRUE, TRUE, 6);
232
gtk_widget_show (entry);
234
xfsm_window_add_border (GTK_WINDOW (dialog));
237
result = xfsm_splash_screen_run (splash, dialog);
239
if (result != GTK_RESPONSE_OK)
241
gtk_widget_destroy (dialog);
245
if (name_return != NULL)
247
*name_return = gtk_editable_get_chars (GTK_EDITABLE (entry),
249
if (strlen (*name_return) == 0)
251
g_free (*name_return);
256
gtk_widget_destroy (dialog);
257
result = XFSM_CHOOSE_NEW;
266
xfsm_splash_screen_free (XfsmSplashScreen *splash)
268
if (G_LIKELY (splash->engine.destroy != NULL))
269
splash->engine.destroy (&splash->engine);
270
if (G_LIKELY (splash->module != NULL))
271
g_module_close (splash->module);
277
xfsm_splash_screen_load (XfsmSplashScreen *splash,
280
void (*init) (XfsmSplashEngine *engine);
283
filename = g_module_build_path (LIBDIR "/xfce4/splash/engines", engine);
284
#if GLIB_CHECK_VERSION(2,4,0)
285
splash->module = g_module_open (filename, G_MODULE_BIND_LOCAL);
287
splash->module = g_module_open (filename, 0);
291
if (G_LIKELY (splash->module != NULL))
293
if (g_module_symbol (splash->module, "engine_init", (gpointer)&init))
295
init (&splash->engine);
299
g_module_close (splash->module);
300
splash->module = NULL;
305
g_warning ("Unable to load engine \"%s\": %s", engine, g_module_error ());