107
111
*sessions = g_list_prepend (*sessions, g_strdup (key));
114
/* Just a wrapper to ensure compatibility with the
111
117
gdm_session_list_init ()
119
_gdm_session_list_init (&sessnames, &sessions,
120
&default_session, ¤t_session);
123
/* The real gdm_session_list_init */
125
_gdm_session_list_init (GHashTable **sessnames, GList **sessions,
126
gchar **default_session, const gchar **current_session)
113
129
GdmSession *session = NULL;
114
130
gboolean some_dir_exists = FALSE;
115
131
gboolean searching_for_default = TRUE;
130
146
"and it is only to be used when you can't log "
131
147
"in otherwise. GNOME will use the 'Default' "
133
g_hash_table_insert (sessnames, g_strdup (GDM_SESSION_FAILSAFE_GNOME), session);
149
g_hash_table_insert (*sessnames, g_strdup (GDM_SESSION_FAILSAFE_GNOME), session);
136
152
if (gdm_config_get_bool (GDM_KEY_SHOW_XTERM_FAILSAFE)) {
143
159
"and it is only to be used when you can't log "
144
160
"in otherwise. To exit the terminal, "
145
161
"type 'exit'."));
146
g_hash_table_insert (sessnames, g_strdup (GDM_SESSION_FAILSAFE_XTERM),
162
g_hash_table_insert (*sessnames, g_strdup (GDM_SESSION_FAILSAFE_XTERM),
185
202
/* already found this session, ignore */
186
if (g_hash_table_lookup (sessnames, dent->d_name) != NULL) {
203
if (g_hash_table_lookup (*sessnames, dent->d_name) != NULL) {
187
204
dent = readdir (sessdir);
191
208
s = g_strconcat (dir, "/", dent->d_name, NULL);
192
cfg = ve_config_new (s);
209
cfg = gdm_common_config_load (s, NULL);
195
if (ve_config_get_bool (cfg, "Desktop Entry/Hidden=false")) {
196
session = g_new0 (GdmSession, 1);
197
session->name = g_strdup (dent->d_name);
198
session->clearname = NULL;
199
g_hash_table_insert (sessnames, g_strdup (dent->d_name), session);
200
ve_config_destroy (cfg);
213
gdm_common_config_get_boolean (cfg, "Desktop Entry/Hidden=false", &hidden, NULL);
215
g_key_file_free (cfg);
201
216
dent = readdir (sessdir);
205
tryexec = ve_config_get_string (cfg, "Desktop Entry/TryExec");
221
gdm_common_config_get_string (cfg, "Desktop Entry/TryExec", &tryexec, NULL);
206
222
if ( ! ve_string_empty (tryexec)) {
207
223
char **tryexecvec = g_strsplit (tryexec, " ", -1);
208
224
char *full = NULL;
215
231
session = g_new0 (GdmSession, 1);
216
232
session->name = g_strdup (dent->d_name);
217
233
session->clearname = NULL;
218
g_hash_table_insert (sessnames, g_strdup (dent->d_name),
234
g_hash_table_insert (*sessnames, g_strdup (dent->d_name),
220
236
g_free (tryexec);
221
ve_config_destroy (cfg);
237
g_key_file_free (cfg);
222
238
dent = readdir (sessdir);
228
244
g_free (tryexec);
230
exec = ve_config_get_string (cfg, "Desktop Entry/Exec");
231
name = ve_config_get_translated_string (cfg, "Desktop Entry/Name");
232
comment = ve_config_get_translated_string (cfg, "Desktop Entry/Comment");
234
ve_config_destroy (cfg);
249
gdm_common_config_get_string (cfg, "Desktop Entry/Exec", &exec, NULL);
250
gdm_common_config_get_translated_string (cfg, "Desktop Entry/Name", &name, NULL);
251
gdm_common_config_get_translated_string (cfg, "Desktop Entry/Comment", &comment, NULL);
252
g_key_file_free (cfg);
236
254
if G_UNLIKELY (ve_string_empty (exec) || ve_string_empty (name)) {
237
255
session = g_new0 (GdmSession, 1);
238
256
session->name = g_strdup (dent->d_name);
239
257
session->clearname = NULL;
240
g_hash_table_insert (sessnames, g_strdup (dent->d_name), session);
258
g_hash_table_insert (*sessnames, g_strdup (dent->d_name), session);
243
261
g_free (comment);
248
266
/* if we found the default session */
249
if ( ! ve_string_empty (gdm_config_get_string (GDM_KEY_DEFAULT_SESSION)) &&
250
strcmp (dent->d_name, gdm_config_get_string (GDM_KEY_DEFAULT_SESSION)) == 0) {
251
g_free (default_session);
252
default_session = g_strdup (dent->d_name);
253
searching_for_default = FALSE;
256
/* if there is a session called Default */
257
if (searching_for_default &&
258
g_ascii_strcasecmp (dent->d_name, "default.desktop") == 0) {
259
g_free (default_session);
260
default_session = g_strdup (dent->d_name);
263
if (searching_for_default &&
264
g_ascii_strcasecmp (dent->d_name, "gnome.desktop") == 0) {
265
/* Just in case there is no default session and
266
* no default link, make gnome the default */
267
if (default_session == NULL)
268
default_session = g_strdup (dent->d_name);
267
if (default_session != NULL) {
268
if ( ! ve_string_empty (gdm_config_get_string (GDM_KEY_DEFAULT_SESSION)) &&
269
strcmp (dent->d_name, gdm_config_get_string (GDM_KEY_DEFAULT_SESSION)) == 0) {
270
g_free (*default_session);
271
*default_session = g_strdup (dent->d_name);
272
searching_for_default = FALSE;
275
/* if there is a session called Default */
276
if (searching_for_default &&
277
g_ascii_strcasecmp (dent->d_name, "default.desktop") == 0) {
278
g_free (*default_session);
279
*default_session = g_strdup (dent->d_name);
282
if (searching_for_default &&
283
g_ascii_strcasecmp (dent->d_name, "gnome.desktop") == 0) {
284
/* Just in case there is no default session and
285
* no default link, make gnome the default */
286
if (*default_session == NULL)
287
*default_session = g_strdup (dent->d_name);
272
292
session = g_new0 (GdmSession, 1);
273
293
session->name = g_strdup (name);
274
294
session->clearname = NULL;
275
295
session->comment = g_strdup (comment);
276
g_hash_table_insert (sessnames, g_strdup (dent->d_name), session);
296
g_hash_table_insert (*sessnames, g_strdup (dent->d_name), session);
278
298
g_free (comment);
279
299
dent = readdir (sessdir);
293
313
session_dir_whacked_out = TRUE;
296
if G_UNLIKELY (g_hash_table_size (sessnames) == 0) {
316
if G_UNLIKELY (g_hash_table_size (*sessnames) == 0) {
297
317
gdm_common_warning ("Error, no sessions found in the session directory <%s>.",
298
318
ve_sure_string (gdm_config_get_string (GDM_KEY_SESSION_DESKTOP_DIR)));
300
320
session_dir_whacked_out = TRUE;
301
default_session = g_strdup (GDM_SESSION_FAILSAFE_GNOME);
321
if (default_session != NULL)
322
*default_session = g_strdup (GDM_SESSION_FAILSAFE_GNOME);
311
332
"and it is only to be used when you can't log "
312
333
"in otherwise. GNOME will use the 'Default' "
314
g_hash_table_insert (sessnames,
335
g_hash_table_insert (*sessnames,
315
336
g_strdup (GDM_SESSION_FAILSAFE_GNOME), session);
324
345
"and it is only to be used when you can't log "
325
346
"in otherwise. To exit the terminal, "
326
347
"type 'exit'."));
327
g_hash_table_insert (sessnames,
348
g_hash_table_insert (*sessnames,
328
349
g_strdup (GDM_SESSION_FAILSAFE_XTERM), session);
331
352
/* Convert to list (which is unsorted) */
332
g_hash_table_foreach (sessnames,
333
(GHFunc) gdm_session_list_from_hash_table_func, &sessions);
353
g_hash_table_foreach (*sessnames,
354
(GHFunc) gdm_session_list_from_hash_table_func, sessions);
335
356
/* Prioritize and sort the list */
336
sessions = g_list_sort (sessions, (GCompareFunc) gdm_session_sort_func);
357
*sessions = g_list_sort (*sessions, (GCompareFunc) gdm_session_sort_func);
338
if G_UNLIKELY (default_session == NULL) {
339
default_session = g_strdup (GDM_SESSION_FAILSAFE_GNOME);
340
gdm_common_warning ("No default session link found. Using Failsafe GNOME.");
359
if (default_session != NULL)
360
if G_UNLIKELY (*default_session == NULL) {
361
*default_session = g_strdup (GDM_SESSION_FAILSAFE_GNOME);
362
gdm_common_warning ("No default session link found. Using Failsafe GNOME.");
365
if (current_session != NULL &&
366
default_session != NULL) {
367
if (*current_session == NULL)
368
*current_session = *default_session;
343
if (current_session == NULL)
344
current_session = default_session;
374
gdm_session_lookup (const char *saved_session)
399
gdm_session_lookup (const char *saved_session, gint *lookup_status)
376
401
gchar *session = NULL;
403
/* Assume that the lookup will go well */
404
*lookup_status = SESSION_LOOKUP_SUCCESS;
378
406
/* Don't save session unless told otherwise */
379
407
save_session = GTK_RESPONSE_NO;
402
430
/* Check if user's saved session exists on this box */
403
431
if (!gdm_login_list_lookup (sessions, session))
408
434
g_free (session);
409
435
session = g_strdup (default_session);
410
firstmsg = g_strdup_printf (_("Do you wish to make %s the default for "
412
gdm_session_name (saved_session));
413
secondmsg = g_strdup_printf (_("Your preferred session type %s is not "
414
"installed on this computer."),
415
gdm_session_name (default_session));
416
save_session = gdm_wm_query_dialog (firstmsg, secondmsg,
417
_("Make _Default"), _("Just _Log In"), TRUE);
436
*lookup_status = SESSION_LOOKUP_PREFERRED_MISSING;
422
439
else /* One of the other available session types is selected */
437
454
save_session = GTK_RESPONSE_NO;
439
456
else if (strcmp (saved_session, session) != 0)
441
gchar *firstmsg = NULL;
442
gchar *secondmsg = NULL;
444
458
if (gdm_config_get_bool (GDM_KEY_SHOW_LAST_SESSION))
446
firstmsg = g_strdup_printf (_("Do you wish to make %s the default for "
448
gdm_session_name (session));
449
secondmsg = g_strdup_printf (_("You have chosen %s for this "
450
"session, but your default "
452
gdm_session_name (session),
453
gdm_session_name (saved_session));
454
save_session = gdm_wm_query_dialog (firstmsg, secondmsg,
455
_("Make _Default"), _("Just For _This Session"), TRUE);
460
*lookup_status = SESSION_LOOKUP_DEFAULT_MISMATCH;
457
462
else if (strcmp (session, default_session) != 0 &&
458
463
strcmp (session, saved_session) != 0 &&
466
471
if (g_access ("/usr/bin/switchdesk", F_OK) == 0)
468
firstmsg = g_strdup_printf (_("You have chosen %s for this "
470
gdm_session_name (session));
471
secondmsg = g_strdup_printf (_("If you wish to make %s "
472
"the default for future sessions, "
473
"run the 'switchdesk' utility "
474
"(System->Desktop Switching Tool from "
476
gdm_session_name (session));
477
gdm_wm_message_dialog (firstmsg, secondmsg);
473
*lookup_status = SESSION_LOOKUP_USE_SWITCHDESK;
479
475
save_session = GTK_RESPONSE_NO;