~darkxst/ubuntu/saucy/gdm/lp1212408

« back to all changes in this revision

Viewing changes to gui/gdmsession.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2008-09-02 10:37:20 UTC
  • mfrom: (1.4.27 upstream)
  • mto: This revision was merged to the branch mainline in revision 261.
  • Revision ID: james.westby@ubuntu.com-20080902103720-p810vv530hqj45wg
Tags: 2.20.7-3
* Install the debian-moreblue-orbit theme, thanks Andre Luiz Rodrigues 
  Ferreira. Closes: #497440.
* 35_gdm.conf.patch: make it the default.
* copyright: fix encoding.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* GDM - The GNOME Display Manager
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 
2
 *
 
3
 * GDM - The GNOME Display Manager
2
4
 * Copyright (C) 1999, 2000 Martin K. Petersen <mkp@mkp.net>
3
5
 *
4
6
 * This file Copyright (c) 2003 George Lebl
21
23
 
22
24
#include "config.h"
23
25
 
 
26
#include <stdlib.h>
24
27
#include <unistd.h>
 
28
#include <string.h>
25
29
#include <dirent.h>
26
30
#include <gtk/gtk.h>
27
31
#include <glib/gi18n.h>
28
32
 
29
 
#include "vicious.h"
30
 
 
31
33
#include "gdm.h"
32
34
#include "gdmsession.h"
33
35
#include "gdmcommon.h"
34
36
#include "gdmconfig.h"
35
 
#include "gdmwm.h"
 
37
 
 
38
#include "gdm-common.h"
 
39
#include "gdm-daemon-config-keys.h"
36
40
 
37
41
GHashTable *sessnames        = NULL;
38
42
gchar *default_session       = NULL;
107
111
        *sessions = g_list_prepend (*sessions, g_strdup (key));
108
112
}
109
113
 
 
114
/* Just a wrapper to ensure compatibility with the
 
115
   existing code */
110
116
void
111
117
gdm_session_list_init ()
112
118
{
 
119
        _gdm_session_list_init (&sessnames, &sessions, 
 
120
                                &default_session, &current_session);    
 
121
}
 
122
 
 
123
/* The real gdm_session_list_init */
 
124
void
 
125
_gdm_session_list_init (GHashTable **sessnames, GList **sessions, 
 
126
                        gchar **default_session, const gchar **current_session)
 
127
{
 
128
 
113
129
    GdmSession *session = NULL;
114
130
    gboolean some_dir_exists = FALSE;
115
131
    gboolean searching_for_default = TRUE;
119
135
    DIR *sessdir;
120
136
    int i;
121
137
 
122
 
    sessnames = g_hash_table_new (g_str_hash, g_str_equal);
 
138
    *sessnames = g_hash_table_new (g_str_hash, g_str_equal);
123
139
 
124
140
    if (gdm_config_get_bool (GDM_KEY_SHOW_GNOME_FAILSAFE)) {
125
141
        session = g_new0 (GdmSession, 1);
130
146
                "and it is only to be used when you can't log "
131
147
                "in otherwise.  GNOME will use the 'Default' "
132
148
                "session."));
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);
134
150
    }
135
151
 
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),
147
163
                session);
148
164
    }
149
165
 
167
183
                    dent = NULL;
168
184
 
169
185
            while (dent != NULL) {
170
 
                    VeConfig *cfg;
 
186
                    GKeyFile *cfg;
171
187
                    char *exec;
172
188
                    char *comment;
173
189
                    char *s;
174
190
                    char *tryexec;
175
191
                    char *ext;
 
192
                    gboolean hidden;
176
193
 
177
194
                    /* ignore everything but the .desktop files */
178
195
                    ext = strstr (dent->d_name, ".desktop");
183
200
                    }
184
201
 
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);
188
205
                            continue;
189
206
                    }
190
207
 
191
208
                    s = g_strconcat (dir, "/", dent->d_name, NULL);
192
 
                    cfg = ve_config_new (s);
 
209
                    cfg = gdm_common_config_load (s, NULL);
193
210
                    g_free (s);
194
211
 
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);
 
212
                    hidden = FALSE;
 
213
                    gdm_common_config_get_boolean (cfg, "Desktop Entry/Hidden=false", &hidden, NULL);
 
214
                    if (hidden) {
 
215
                            g_key_file_free (cfg);
201
216
                            dent = readdir (sessdir);
202
217
                            continue;
203
218
                    }
204
219
 
205
 
                    tryexec = ve_config_get_string (cfg, "Desktop Entry/TryExec");
 
220
                    tryexec = NULL;
 
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),
219
235
                                         session);
220
236
                                    g_free (tryexec);
221
 
                                    ve_config_destroy (cfg);
 
237
                                    g_key_file_free (cfg);
222
238
                                    dent = readdir (sessdir);
223
239
                                    continue;
224
240
                            }
227
243
                    }
228
244
                    g_free (tryexec);
229
245
 
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");
233
 
 
234
 
                    ve_config_destroy (cfg);
 
246
                    exec = NULL;
 
247
                    name = NULL;
 
248
                    comment = NULL;
 
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);
235
253
 
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);
241
259
                            g_free (exec);
242
260
                            g_free (name);
243
261
                            g_free (comment);
246
264
                    }
247
265
 
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;
254
 
                    }
255
 
 
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);
261
 
                    }
262
 
 
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);
269
 
 
 
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;
 
273
                            }               
 
274
 
 
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);
 
280
                            }
 
281
 
 
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);
 
288
 
 
289
                            }
270
290
                    }
271
291
 
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);
277
297
                    g_free (exec);
278
298
                    g_free (comment);
279
299
                    dent = readdir (sessdir);
293
313
        session_dir_whacked_out = TRUE;
294
314
    }
295
315
 
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)));
299
319
 
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);
302
323
    }
303
324
 
304
325
 
311
332
                                    "and it is only to be used when you can't log "
312
333
                                    "in otherwise.  GNOME will use the 'Default' "
313
334
                                    "session."));
314
 
            g_hash_table_insert (sessnames,
 
335
            g_hash_table_insert (*sessnames,
315
336
                g_strdup (GDM_SESSION_FAILSAFE_GNOME), session);
316
337
    }
317
338
 
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);
329
350
    }
330
351
 
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);
334
355
 
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);
337
358
 
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.");
 
363
            }
 
364
    
 
365
    if (current_session != NULL &&
 
366
        default_session != NULL) {
 
367
            if (*current_session == NULL)
 
368
                    *current_session = *default_session;
341
369
    }
342
 
    
343
 
    if (current_session == NULL)
344
 
            current_session = default_session;
345
370
}
346
371
 
347
372
static gboolean
371
396
}
372
397
 
373
398
char *
374
 
gdm_session_lookup (const char *saved_session)
 
399
gdm_session_lookup (const char *saved_session, gint *lookup_status)
375
400
{
376
401
  gchar *session = NULL;
377
402
  
 
403
  /* Assume that the lookup will go well */
 
404
  *lookup_status = SESSION_LOOKUP_SUCCESS;
 
405
 
378
406
  /* Don't save session unless told otherwise */
379
407
  save_session = GTK_RESPONSE_NO;
380
408
 
402
430
      /* Check if user's saved session exists on this box */
403
431
      if (!gdm_login_list_lookup (sessions, session))
404
432
        {
405
 
          gchar *firstmsg;
406
 
          gchar *secondmsg;
407
 
          
 
433
                
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 "
411
 
                                        "future sessions?"),
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);
418
 
          g_free (firstmsg);
419
 
          g_free (secondmsg);
 
436
          *lookup_status = SESSION_LOOKUP_PREFERRED_MISSING;
420
437
        }
421
438
    }
422
439
  else /* One of the other available session types is selected */
437
454
          save_session = GTK_RESPONSE_NO;
438
455
        }
439
456
      else if (strcmp (saved_session, session) != 0)
440
 
        {
441
 
          gchar *firstmsg = NULL;
442
 
          gchar *secondmsg = NULL;
443
 
          
 
457
        {                 
444
458
          if (gdm_config_get_bool (GDM_KEY_SHOW_LAST_SESSION))
445
459
            {
446
 
              firstmsg = g_strdup_printf (_("Do you wish to make %s the default for "
447
 
                                            "future sessions?"),
448
 
                                          gdm_session_name (session));
449
 
              secondmsg = g_strdup_printf (_("You have chosen %s for this "
450
 
                                             "session, but your default "
451
 
                                             "setting is %s."),
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;
456
461
            }
457
462
          else if (strcmp (session, default_session) != 0 &&
458
463
                   strcmp (session, saved_session) != 0 &&
465
470
               */
466
471
              if (g_access ("/usr/bin/switchdesk", F_OK) == 0)
467
472
                {
468
 
                  firstmsg = g_strdup_printf (_("You have chosen %s for this "
469
 
                                                "session"),
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 "
475
 
                                                 "the panel menu)."),
476
 
                                               gdm_session_name (session));                      
477
 
                  gdm_wm_message_dialog (firstmsg, secondmsg);
 
473
                        *lookup_status = SESSION_LOOKUP_USE_SWITCHDESK;
478
474
                }
479
475
              save_session = GTK_RESPONSE_NO;
480
476
            }
481
 
          g_free (firstmsg);
482
 
          g_free (secondmsg);
483
477
        }
484
478
    }
485
479
 
492
486
  return save_session;
493
487
}
494
488
 
 
489
void
 
490
gdm_set_save_session (const gint session)
 
491
{
 
492
        save_session = session;
 
493
}
 
494
 
 
495
const char*
 
496
gdm_get_default_session (void)
 
497
{
 
498
        return default_session;
 
499
}