gdm r5705 - in trunk: . gui/simple-greeter
- From: halfline svn gnome org
- To: svn-commits-list gnome org
- Subject: gdm r5705 - in trunk: . gui/simple-greeter
- Date: Thu, 7 Feb 2008 01:32:02 +0000 (GMT)
Author: halfline
Date: Thu Feb 7 01:32:02 2008
New Revision: 5705
URL: http://svn.gnome.org/viewvc/gdm?rev=5705&view=rev
Log:
2008-02-06 Ray Strode <rstrode redhat com>
* gui/simple-greeter/gdm-sessions.[ch]:
Copy session handling code from gdm-session-chooser-widget
to its own file (sort of like gdm-languages.c but for sessions)
This will make it easier to add a session option widget to the
panel.
Added:
trunk/gui/simple-greeter/gdm-sessions.c
trunk/gui/simple-greeter/gdm-sessions.h
Modified:
trunk/ChangeLog
Added: trunk/gui/simple-greeter/gdm-sessions.c
==============================================================================
--- (empty file)
+++ trunk/gui/simple-greeter/gdm-sessions.c Thu Feb 7 01:32:02 2008
@@ -0,0 +1,262 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2008 Red Hat, Inc,
+ * 2007 William Jon McCann <mccann jhu edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Written by : William Jon McCann <mccann jhu edu>
+ * Ray Strode <rstrode redhat com>
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+
+#include "gdm-languages.h"
+
+typedef struct _GdmSessionFile {
+ char *filename;
+ char *path;
+ char *translated_name;
+ char *translated_comment;
+} GdmSessionFile;
+
+static GHashTable *gdm_available_sessions_map;
+
+static gboolean gdm_sessions_map_is_initialized = FALSE;
+
+/* adapted from gnome-menus desktop-entries.c */
+static gboolean
+key_file_is_relevant (GKeyFile *key_file)
+{
+ GError *error;
+ gboolean no_display;
+ gboolean hidden;
+ gboolean tryexec_failed;
+ char *tryexec;
+
+ error = NULL;
+ no_display = g_key_file_get_boolean (key_file,
+ G_KEY_FILE_DESKTOP_GROUP,
+ "NoDisplay",
+ &error);
+ if (error) {
+ no_display = FALSE;
+ g_error_free (error);
+ }
+
+ error = NULL;
+ hidden = g_key_file_get_boolean (key_file,
+ G_KEY_FILE_DESKTOP_GROUP,
+ "Hidden",
+ &error);
+ if (error) {
+ hidden = FALSE;
+ g_error_free (error);
+ }
+
+ tryexec_failed = FALSE;
+ tryexec = g_key_file_get_string (key_file,
+ G_KEY_FILE_DESKTOP_GROUP,
+ "TryExec",
+ NULL);
+ if (tryexec) {
+ char *path;
+
+ path = g_find_program_in_path (g_strstrip (tryexec));
+
+ tryexec_failed = (path == NULL);
+
+ g_free (path);
+ g_free (tryexec);
+ }
+
+ if (no_display || hidden || tryexec_failed) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+load_session_file (const char *name,
+ const char *path)
+{
+ GKeyFile *key_file;
+ GError *error;
+ gboolean res;
+ GdmSessionFile *session;
+
+ key_file = g_key_file_new ();
+
+ error = NULL;
+ res = g_key_file_load_from_file (key_file, path, 0, &error);
+
+ if (!res) {
+ g_debug ("Failed to load \"%s\": %s\n", path, error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ if (! g_key_file_has_group (key_file, G_KEY_FILE_DESKTOP_GROUP)) {
+ goto out;
+ }
+
+ res = g_key_file_has_key (key_file, G_KEY_FILE_DESKTOP_GROUP, "Name", NULL);
+ if (! res) {
+ g_debug ("\"%s\" contains no \"Name\" key\n", path);
+ goto out;
+ }
+
+ if (!key_file_is_relevant (key_file)) {
+ g_debug ("\"%s\" is hidden or contains non-executable TryExec program\n", path);
+ goto out;
+ }
+
+ session = g_new0 (GdmSessionFile, 1);
+
+ session->filename = g_strdup (name);
+ session->path = g_strdup (path);
+
+ session->translated_name = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Name", NULL, NULL);
+ session->translated_comment = g_key_file_get_locale_string (key_file, G_KEY_FILE_DESKTOP_GROUP, "Comment", NULL, NULL);
+
+ g_hash_table_insert (gdm_available_sessions_map,
+ g_strdup (session->path),
+ session);
+ out:
+ g_key_file_free (key_file);
+}
+
+static void
+collect_sessions_from_directory (const char *dirname)
+{
+ GDir *dir;
+ const char *filename;
+
+ /* FIXME: add file monitor to directory */
+
+ dir = g_dir_open (dirname, 0, NULL);
+ if (dir == NULL) {
+ return;
+ }
+
+ while ((filename = g_dir_read_name (dir))) {
+ char *full_path;
+
+ if (! g_str_has_suffix (filename, ".desktop")) {
+ continue;
+ }
+
+ full_path = g_build_filename (dirname, filename, NULL);
+
+ load_session_file (filename, full_path);
+
+ g_free (full_path);
+ }
+
+ g_dir_close (dir);
+}
+
+static void
+collect_sessions (void)
+{
+ int i;
+ const char *search_dirs[] = {
+ "/etc/X11/sessions/",
+ DMCONFDIR "/Sessions/",
+ DATADIR "/gdm/BuiltInSessions/",
+ DATADIR "/xsessions/",
+ NULL
+ };
+
+ if (gdm_available_sessions_map == NULL) {
+ gdm_available_sessions_map = g_hash_table_new_full (g_str_hash, g_str_equal,
+ g_free, g_free);
+ }
+
+ for (i = 0; search_dirs [i] != NULL; i++) {
+ collect_sessions_from_directory (search_dirs [i]);
+ }
+}
+
+char **
+gdm_get_all_sessions (void)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+ GPtrArray *array;
+
+ if (!gdm_sessions_map_is_initialized) {
+ collect_sessions ();
+
+ gdm_sessions_map_is_initialized = TRUE;
+ }
+
+ array = g_ptr_array_new ();
+ g_hash_table_iter_init (&iter, gdm_available_sessions_map);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ GdmSessionFile *session;
+
+ session = (GdmSessionFile *) value;
+
+ g_ptr_array_add (array, g_strdup (session->path));
+ }
+ g_ptr_array_add (array, NULL);
+
+ return (char **) g_ptr_array_free (array, FALSE);
+}
+
+gboolean
+gdm_get_details_for_session (const char *filename,
+ char **name,
+ char **comment)
+{
+ GdmSessionFile *session;
+
+ if (!gdm_sessions_map_is_initialized) {
+ collect_sessions ();
+
+ gdm_sessions_map_is_initialized = TRUE;
+ }
+
+ session = (GdmSessionFile *) g_hash_table_lookup (gdm_available_sessions_map,
+ filename);
+
+ if (session == NULL) {
+ return FALSE;
+ }
+
+ if (name != NULL) {
+ *name = g_strdup (session->translated_name);
+ }
+
+ if (comment != NULL) {
+ *comment = g_strdup (session->translated_comment);
+ }
+
+ return TRUE;
+}
Added: trunk/gui/simple-greeter/gdm-sessions.h
==============================================================================
--- (empty file)
+++ trunk/gui/simple-greeter/gdm-sessions.h Thu Feb 7 01:32:02 2008
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright 2008 Red Hat, Inc.
+ * Copyright 2007 William Jon McCann <mccann jhu edu>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Written by: Ray Strode
+ * William Jon McCann
+ */
+
+#ifndef __GDM_SESSIONS_H
+#define __GDM_SESSIONS_H
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+char ** gdm_get_all_sessions (void);
+gboolean gdm_get_details_for_session (const char *filename,
+ char **name,
+ char **comment);
+
+G_END_DECLS
+
+#endif /* __GDM_SESSION_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]