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

« back to all changes in this revision

Viewing changes to xfce4-session/startup.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
 
/*
2
 
 * Copyright (c) 2003 Benedikt Meurer <benedikt.meurer@unix-ag.uni-siegen.de>
3
 
 * All rights reserved.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions
7
 
 * are met:
8
 
 *
9
 
 * 1. Redistributions of source code must retain the above copyright
10
 
 *    notice, this list of conditions and the following disclaimer.
11
 
 * 2. Redistributions in binary form must reproduce the above copyright
12
 
 *    notice, this list of conditions and the following disclaimer in the
13
 
 *    documentation and/or other materials provided with the distribution.
14
 
 *
15
 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16
 
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
 
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
 
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19
 
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
 
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
 
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 
 */
26
 
 
27
 
#ifdef HAVE_CONFIG_H
28
 
#include <config.h>
29
 
#endif
30
 
 
31
 
#include <X11/ICE/ICElib.h>
32
 
#include <X11/ICE/ICEutil.h>
33
 
#include <X11/SM/SMlib.h>
34
 
#include <X11/Xlib.h>
35
 
 
36
 
#include <libxfce4util/i18n.h>
37
 
#include <libxfce4util/util.h>
38
 
#include <libxfcegui4/netk-util.h>
39
 
#include <gtk/gtk.h>
40
 
 
41
 
#include <xfce4-session/client.h>
42
 
#include <xfce4-session/manager.h>
43
 
#include <xfce4-session/splash-screen.h>
44
 
#include <xfce4-session/startup.h>
45
 
 
46
 
/* list of clients to restore */
47
 
GList   *pendingClients = NULL;
48
 
 
49
 
/* */
50
 
static guint    pendingTimeoutId = 0;
51
 
 
52
 
/* */
53
 
static GtkWidget        *splash = NULL;
54
 
 
55
 
/* */
56
 
gchar           *startupSplashTheme = NULL;
57
 
 
58
 
/* */
59
 
#define PENDING_TIMEOUT         (5 * 1000)
60
 
 
61
 
/*
62
 
 */
63
 
static gboolean
64
 
destroy_splash(void)
65
 
{
66
 
        gtk_widget_destroy(splash);
67
 
        return(FALSE);
68
 
}
69
 
 
70
 
/*
71
 
 * Run ~/Desktop/Autostart/ stuff
72
 
 */
73
 
static gboolean
74
 
pending_Autostart(void)
75
 
{
76
 
        const gchar *entry;
77
 
        GError *error;
78
 
        guint timer;
79
 
        gchar *argv[] = { NULL, NULL };
80
 
        gchar *dir;
81
 
        GDir *dp;
82
 
 
83
 
        dir = xfce_get_homefile("Desktop", "Autostart", NULL);
84
 
        timer = 0;
85
 
 
86
 
        if ((dp = g_dir_open(dir, 0, NULL)) != NULL) {
87
 
                while ((entry = g_dir_read_name(dp)) != NULL) {
88
 
                        *argv = g_build_filename(dir, entry, NULL);
89
 
                        error = NULL;
90
 
 
91
 
                        if (g_spawn_async(NULL, argv, NULL, 0, NULL, NULL, NULL,
92
 
                                                &error)) {
93
 
                                timer++;
94
 
                        }
95
 
                        else {
96
 
                                g_warning("Unable to launch %s: %s", *argv,
97
 
                                                error->message);
98
 
                                g_error_free(error);
99
 
                        }
100
 
 
101
 
                        g_free(*argv);
102
 
                }
103
 
 
104
 
                g_dir_close(dp);
105
 
        }
106
 
 
107
 
        g_free(dir);
108
 
 
109
 
        if (timer > 0)
110
 
                g_timeout_add(timer * 400, (GSourceFunc)destroy_splash, NULL);
111
 
        else
112
 
                destroy_splash();
113
 
 
114
 
        return(FALSE);
115
 
}
116
 
 
117
 
/*
118
 
 */
119
 
static gboolean
120
 
pending_timeout(Client *client)
121
 
{
122
 
        /* client startup timed out */
123
 
        if (client != NULL)
124
 
                g_warning("client %s timed out", client->id);
125
 
        pending_continue(client);
126
 
        return(FALSE);
127
 
}
128
 
 
129
 
/*
130
 
 */
131
 
static gboolean
132
 
pending_launch(void)
133
 
{
134
 
        Client *client;
135
 
        GError *error;
136
 
        gchar *program;
137
 
 
138
 
        for (;;) {
139
 
                /* REQUIRED! */
140
 
                error = NULL;
141
 
 
142
 
                /* check if we are finished */
143
 
                if (g_list_length(pendingClients) == 0) {
144
 
                        /*
145
 
                         * All session aware apps are up and running,
146
 
                         * launch the Autostart stuff.
147
 
                         */
148
 
                        xfsm_splash_screen_set_text(XFSM_SPLASH_SCREEN(splash),
149
 
                                        _("Doing Autostart..."));
150
 
 
151
 
                        g_idle_add((GSourceFunc)pending_Autostart, NULL);
152
 
                        break;
153
 
                }
154
 
 
155
 
                /* get next client to fire up */
156
 
                client = CLIENT(g_list_first(pendingClients)->data);
157
 
 
158
 
                /* try to start client */
159
 
                if (!client_run_command(client, SmRestartCommand, &error)) {
160
 
                        g_warning("Unable to start client %s: %s", client->id,
161
 
                                        error->message);
162
 
                        g_error_free(error);
163
 
 
164
 
                        /* run DiscardCommand */
165
 
                        client_run_command(client, SmDiscardCommand, NULL);
166
 
 
167
 
                        /* remove client */
168
 
                        pendingClients = g_list_remove(pendingClients, client);
169
 
                        client_free(client);
170
 
 
171
 
                        /* try next client */
172
 
                        continue;
173
 
                }
174
 
 
175
 
                /* notify the user of what we are doing */
176
 
                if ((program = client_get_program(client)) != NULL) {
177
 
                        xfsm_splash_screen_launch(XFSM_SPLASH_SCREEN(splash),
178
 
                                        program);
179
 
                        g_free(program);
180
 
                }
181
 
 
182
 
                /* add startup timeout */
183
 
                pendingTimeoutId = g_timeout_add(PENDING_TIMEOUT,
184
 
                                (GSourceFunc)pending_timeout, client);
185
 
                break;
186
 
        }
187
 
 
188
 
        return(FALSE);
189
 
}
190
 
 
191
 
/*
192
 
 */
193
 
void
194
 
pending_continue(Client *client)
195
 
{
196
 
        if (pendingTimeoutId != 0)
197
 
                g_source_remove(pendingTimeoutId);
198
 
 
199
 
        if (client != NULL) {
200
 
                pendingClients = g_list_remove(pendingClients, client);
201
 
                client_free(client);
202
 
        }
203
 
        else if (splash == NULL) {
204
 
                /* Ok, start up the splash screen */
205
 
                splash = xfsm_splash_screen_new(startupSplashTheme,
206
 
                                g_list_length(pendingClients),
207
 
                                _("Starting session manager..."));
208
 
 
209
 
                gtk_widget_show(splash);
210
 
 
211
 
                /* XXX - give time to the splash screen to appear */
212
 
                (void)g_timeout_add(100, (GSourceFunc)pending_timeout, NULL);
213
 
                return;
214
 
        }
215
 
 
216
 
        (void)g_timeout_add(100, (GSourceFunc)pending_launch, NULL);
217
 
}
218
 
 
219