~ubuntu-branches/ubuntu/karmic/xfce4-session/karmic

« back to all changes in this revision

Viewing changes to xfce4-session/xfsm-splash-screen.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2005-11-06 22:01:12 UTC
  • mto: (4.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20051106220112-5rusox237ymjghsp
Tags: upstream-4.2.3
ImportĀ upstreamĀ versionĀ 4.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: xfsm-splash-screen.c 4711 2004-11-01 16:10:55Z benny $ */
 
2
/*-
 
3
 * Copyright (c) 2003-2004 Benedikt Meurer <benny@xfce.org>
 
4
 * All rights reserved.
 
5
 *
 
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)
 
9
 * any later version.
 
10
 *                                                                              
 
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.
 
15
 *                                                                              
 
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
 
19
 * 02111-1307, USA.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#ifdef HAVE_STDLIB_H
 
27
#include <stdlib.h>
 
28
#endif
 
29
#ifdef HAVE_STRING_H
 
30
#include <string.h>
 
31
#endif
 
32
 
 
33
#include <gmodule.h>
 
34
 
 
35
#include <libxfce4util/libxfce4util.h>
 
36
#include <libxfcegui4/libxfcegui4.h>
 
37
 
 
38
#include <libxfsm/xfsm-splash-engine.h>
 
39
#include <libxfsm/xfsm-util.h>
 
40
 
 
41
#include <xfce4-session/xfsm-chooser.h>
 
42
#include <xfce4-session/xfsm-splash-screen.h>
 
43
 
 
44
 
 
45
struct _XfsmSplashScreen
 
46
{
 
47
  XfsmSplashEngine engine;
 
48
  GModule         *module;
 
49
};
 
50
 
 
51
 
 
52
static void xfsm_splash_screen_load (XfsmSplashScreen *splash,
 
53
                                     const gchar      *engine);
 
54
 
 
55
 
 
56
XfsmSplashScreen*
 
57
xfsm_splash_screen_new (GdkDisplay  *display,
 
58
                        const gchar *engine)
 
59
{
 
60
  XfsmSplashScreen *splash;
 
61
  XfsmSplashRc     *splash_rc;
 
62
  GdkScreen        *screen;
 
63
  gchar             name[128];
 
64
  int               monitor;
 
65
  XfceRc           *rc;
 
66
 
 
67
  /* locate monitor with pointer */
 
68
  screen = xfce_gdk_display_locate_monitor_with_pointer (display, &monitor);
 
69
  if (G_UNLIKELY (screen == NULL))
 
70
    {
 
71
      screen  = gdk_display_get_screen (display, 0);
 
72
      monitor = 0;
 
73
    }
 
74
 
 
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;
 
80
 
 
81
  /* load and setup the engine */
 
82
  if (G_LIKELY (engine != NULL && *engine != '\0'))
 
83
    {
 
84
      xfsm_splash_screen_load (splash, engine);
 
85
      if (G_LIKELY (splash->engine.setup != NULL))
 
86
        {
 
87
          rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG,
 
88
                                    "xfce4-session/xfce4-splash.rc",
 
89
                                    TRUE);
 
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);
 
94
          xfce_rc_close (rc);
 
95
 
 
96
          gdk_flush ();
 
97
        }
 
98
    }
 
99
 
 
100
  return splash;
 
101
}
 
102
 
 
103
 
 
104
void
 
105
xfsm_splash_screen_start (XfsmSplashScreen *splash,
 
106
                          const gchar      *name,
 
107
                          GdkPixbuf        *preview,
 
108
                          unsigned          steps)
 
109
{
 
110
  if (G_LIKELY (splash->engine.start != NULL))
 
111
    {
 
112
      splash->engine.start (&splash->engine, name, preview, steps);
 
113
      gdk_flush ();
 
114
    }
 
115
}
 
116
 
 
117
 
 
118
void
 
119
xfsm_splash_screen_next (XfsmSplashScreen *splash,
 
120
                         const gchar      *text)
 
121
{
 
122
  if (G_LIKELY (splash->engine.next != NULL))
 
123
    {
 
124
      splash->engine.next (&splash->engine, text);
 
125
      gdk_flush ();
 
126
    }
 
127
}
 
128
 
 
129
 
 
130
int
 
131
xfsm_splash_screen_run (XfsmSplashScreen *splash,
 
132
                        GtkWidget        *dialog)
 
133
{
 
134
  int result;
 
135
 
 
136
  if (G_LIKELY (splash->engine.run != NULL))
 
137
    {
 
138
      result = splash->engine.run (&splash->engine, dialog);
 
139
    }
 
140
  else
 
141
    {
 
142
      xfce_gtk_window_center_on_monitor (GTK_WINDOW (dialog),
 
143
                                         splash->engine.primary_screen,
 
144
                                         splash->engine.primary_monitor);
 
145
 
 
146
      result = gtk_dialog_run (GTK_DIALOG (dialog));
 
147
    }
 
148
 
 
149
  return result;
 
150
}
 
151
 
 
152
 
 
153
int
 
154
xfsm_splash_screen_choose (XfsmSplashScreen *splash,
 
155
                           GList            *sessions,
 
156
                           const gchar      *default_session,
 
157
                           gchar           **name_return)
 
158
{
 
159
  GtkWidget *chooser;
 
160
  GtkWidget *label;
 
161
  GtkWidget *dialog;
 
162
  GtkWidget *entry;
 
163
  gchar      title[256];
 
164
  int        result;
 
165
 
 
166
  g_assert (default_session != NULL);
 
167
 
 
168
  if (splash->engine.choose != NULL)
 
169
    {
 
170
      result = splash->engine.choose (&splash->engine,
 
171
                                      sessions,
 
172
                                      default_session,
 
173
                                      name_return);
 
174
    }
 
175
  else
 
176
    {
 
177
again:
 
178
      xfsm_splash_screen_next (splash, _("Choose session"));
 
179
 
 
180
      chooser = g_object_new (XFSM_TYPE_CHOOSER,
 
181
                              "screen", splash->engine.primary_screen,
 
182
                              "type", GTK_WINDOW_POPUP,
 
183
                              NULL);
 
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);
 
188
 
 
189
      if (result == XFSM_RESPONSE_LOAD) 
 
190
        {
 
191
          if (name_return != NULL)
 
192
            *name_return = xfsm_chooser_get_session (XFSM_CHOOSER (chooser));
 
193
          result = XFSM_CHOOSE_LOAD;
 
194
        }
 
195
      else if (result == XFSM_RESPONSE_NEW)
 
196
        {
 
197
          result = XFSM_CHOOSE_NEW;
 
198
        }
 
199
      else
 
200
        {
 
201
          result = XFSM_CHOOSE_LOGOUT;
 
202
        }
 
203
 
 
204
      gtk_widget_destroy (chooser);
 
205
 
 
206
      if (result == XFSM_CHOOSE_NEW)
 
207
        {
 
208
          xfsm_splash_screen_next (splash, _("Choose session name"));
 
209
 
 
210
          dialog = gtk_dialog_new_with_buttons (NULL,
 
211
                                                NULL,
 
212
                                                GTK_DIALOG_NO_SEPARATOR,
 
213
                                                GTK_STOCK_CANCEL,
 
214
                                                GTK_RESPONSE_CANCEL,
 
215
                                                GTK_STOCK_OK, 
 
216
                                                GTK_RESPONSE_OK,
 
217
                                                NULL);
 
218
          gtk_dialog_set_default_response (GTK_DIALOG (dialog),
 
219
                                           GTK_RESPONSE_OK);
 
220
 
 
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);
 
228
 
 
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);
 
233
 
 
234
          xfsm_window_add_border (GTK_WINDOW (dialog));
 
235
 
 
236
again1:
 
237
          result = xfsm_splash_screen_run (splash, dialog);
 
238
 
 
239
          if (result != GTK_RESPONSE_OK)
 
240
            {
 
241
              gtk_widget_destroy (dialog);
 
242
              goto again;
 
243
            }
 
244
 
 
245
          if (name_return != NULL)
 
246
            {
 
247
              *name_return = gtk_editable_get_chars (GTK_EDITABLE (entry),
 
248
                                                     0, -1);
 
249
              if (strlen (*name_return) == 0)
 
250
                {
 
251
                  g_free (*name_return);
 
252
                  goto again1;
 
253
                }
 
254
            }
 
255
 
 
256
          gtk_widget_destroy (dialog);
 
257
          result = XFSM_CHOOSE_NEW;
 
258
        }
 
259
    }
 
260
 
 
261
  return result;
 
262
}
 
263
 
 
264
 
 
265
void
 
266
xfsm_splash_screen_free (XfsmSplashScreen *splash)
 
267
{
 
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);
 
272
  g_free (splash);
 
273
}
 
274
 
 
275
 
 
276
static void
 
277
xfsm_splash_screen_load (XfsmSplashScreen *splash,
 
278
                         const gchar      *engine)
 
279
{
 
280
  void (*init) (XfsmSplashEngine *engine);
 
281
  gchar *filename;
 
282
 
 
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);
 
286
#else
 
287
  splash->module = g_module_open (filename, 0);
 
288
#endif
 
289
  g_free (filename);
 
290
 
 
291
  if (G_LIKELY (splash->module != NULL))
 
292
    {
 
293
      if (g_module_symbol (splash->module, "engine_init", (gpointer)&init))
 
294
        {
 
295
          init (&splash->engine);
 
296
        }
 
297
      else
 
298
        {
 
299
          g_module_close (splash->module);
 
300
          splash->module = NULL;
 
301
        }
 
302
    }
 
303
  else
 
304
    {
 
305
      g_warning ("Unable to load engine \"%s\": %s", engine, g_module_error ());
 
306
    }
 
307
}
 
308
 
 
309