[134] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
| 2 | * |
---|
| 3 | * Copyright (C) 2007 William Jon McCann <mccann@jhu.edu> |
---|
| 4 | * Copyright (C) 2008 Red Hat, Inc. |
---|
| 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 of the License, or |
---|
| 9 | * (at your option) 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 02111-1307, USA. |
---|
| 19 | * |
---|
| 20 | * Written by: William Jon McCann <mccann@jhu.edu> |
---|
| 21 | * Ray Strode <rstrode@redhat.com> |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | #include "config.h" |
---|
| 25 | |
---|
| 26 | #include <stdlib.h> |
---|
| 27 | #include <stdio.h> |
---|
| 28 | #include <unistd.h> |
---|
| 29 | #include <string.h> |
---|
| 30 | #include <errno.h> |
---|
| 31 | #include <dirent.h> |
---|
| 32 | #include <sys/stat.h> |
---|
| 33 | |
---|
| 34 | #include <glib.h> |
---|
| 35 | #include <glib/gi18n.h> |
---|
| 36 | #include <glib/gstdio.h> |
---|
| 37 | #include <gtk/gtk.h> |
---|
| 38 | |
---|
| 39 | #include "gdm-session-option-widget.h" |
---|
| 40 | #include "gdm-sessions.h" |
---|
| 41 | |
---|
| 42 | #define GDM_SESSION_OPTION_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_SESSION_OPTION_WIDGET, GdmSessionOptionWidgetPrivate)) |
---|
| 43 | |
---|
| 44 | #define GDM_SESSION_OPTION_WIDGET_LAST_SESSION "__previous" |
---|
| 45 | |
---|
| 46 | struct GdmSessionOptionWidgetPrivate |
---|
| 47 | { |
---|
| 48 | gpointer dummy; |
---|
| 49 | }; |
---|
| 50 | |
---|
| 51 | enum { |
---|
| 52 | PROP_0, |
---|
| 53 | }; |
---|
| 54 | |
---|
| 55 | enum { |
---|
| 56 | SESSION_ACTIVATED, |
---|
| 57 | NUMBER_OF_SIGNALS |
---|
| 58 | }; |
---|
| 59 | |
---|
| 60 | static guint signals [NUMBER_OF_SIGNALS] = { 0, }; |
---|
| 61 | |
---|
| 62 | static void gdm_session_option_widget_class_init (GdmSessionOptionWidgetClass *klass); |
---|
| 63 | static void gdm_session_option_widget_init (GdmSessionOptionWidget *session_option_widget); |
---|
| 64 | static void gdm_session_option_widget_finalize (GObject *object); |
---|
| 65 | |
---|
| 66 | G_DEFINE_TYPE (GdmSessionOptionWidget, gdm_session_option_widget, GDM_TYPE_OPTION_WIDGET) |
---|
| 67 | static void |
---|
| 68 | gdm_session_option_widget_activated (GdmOptionWidget *widget) |
---|
| 69 | { |
---|
| 70 | char *active_item_id; |
---|
| 71 | |
---|
| 72 | active_item_id = gdm_option_widget_get_active_item (GDM_OPTION_WIDGET (widget)); |
---|
| 73 | if (active_item_id == NULL) { |
---|
| 74 | return; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | g_signal_emit (G_OBJECT (widget), signals[SESSION_ACTIVATED], 0); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | static void |
---|
| 82 | gdm_session_option_widget_class_init (GdmSessionOptionWidgetClass *klass) |
---|
| 83 | { |
---|
| 84 | GObjectClass *object_class; |
---|
| 85 | GdmOptionWidgetClass *option_widget_class; |
---|
| 86 | |
---|
| 87 | object_class = G_OBJECT_CLASS (klass); |
---|
| 88 | option_widget_class = GDM_OPTION_WIDGET_CLASS (klass); |
---|
| 89 | |
---|
| 90 | object_class->finalize = gdm_session_option_widget_finalize; |
---|
| 91 | option_widget_class->activated = gdm_session_option_widget_activated; |
---|
| 92 | |
---|
| 93 | signals[SESSION_ACTIVATED] = g_signal_new ("session-activated", |
---|
| 94 | G_TYPE_FROM_CLASS (object_class), |
---|
| 95 | G_SIGNAL_RUN_FIRST, |
---|
| 96 | G_STRUCT_OFFSET (GdmSessionOptionWidgetClass, session_activated), |
---|
| 97 | NULL, |
---|
| 98 | NULL, |
---|
| 99 | g_cclosure_marshal_VOID__VOID, |
---|
| 100 | G_TYPE_NONE, |
---|
| 101 | 0); |
---|
| 102 | |
---|
| 103 | g_type_class_add_private (klass, sizeof (GdmSessionOptionWidgetPrivate)); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | static void |
---|
| 107 | add_available_sessions (GdmSessionOptionWidget *widget) |
---|
| 108 | { |
---|
| 109 | char **session_ids; |
---|
| 110 | int i; |
---|
| 111 | |
---|
| 112 | session_ids = gdm_get_all_sessions (); |
---|
| 113 | |
---|
| 114 | for (i = 0; session_ids[i] != NULL; i++) { |
---|
| 115 | char *name; |
---|
| 116 | char *comment; |
---|
| 117 | |
---|
| 118 | if (!gdm_get_details_for_session (session_ids[i], |
---|
| 119 | &name, &comment)) { |
---|
| 120 | continue; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | gdm_option_widget_add_item (GDM_OPTION_WIDGET (widget), |
---|
| 124 | session_ids[i], name, comment, |
---|
| 125 | GDM_OPTION_WIDGET_POSITION_MIDDLE); |
---|
| 126 | g_free (name); |
---|
| 127 | g_free (comment); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | g_strfreev (session_ids); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | static void |
---|
| 134 | gdm_session_option_widget_init (GdmSessionOptionWidget *widget) |
---|
| 135 | { |
---|
| 136 | widget->priv = GDM_SESSION_OPTION_WIDGET_GET_PRIVATE (widget); |
---|
| 137 | |
---|
| 138 | add_available_sessions (widget); |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | static void |
---|
| 142 | gdm_session_option_widget_finalize (GObject *object) |
---|
| 143 | { |
---|
| 144 | GdmSessionOptionWidget *session_option_widget; |
---|
| 145 | |
---|
| 146 | g_return_if_fail (object != NULL); |
---|
| 147 | g_return_if_fail (GDM_IS_SESSION_OPTION_WIDGET (object)); |
---|
| 148 | |
---|
| 149 | session_option_widget = GDM_SESSION_OPTION_WIDGET (object); |
---|
| 150 | |
---|
| 151 | g_return_if_fail (session_option_widget->priv != NULL); |
---|
| 152 | |
---|
| 153 | G_OBJECT_CLASS (gdm_session_option_widget_parent_class)->finalize (object); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | GtkWidget * |
---|
| 157 | gdm_session_option_widget_new (void) |
---|
| 158 | { |
---|
| 159 | GObject *object; |
---|
| 160 | |
---|
| 161 | object = g_object_new (GDM_TYPE_SESSION_OPTION_WIDGET, |
---|
| 162 | "label-text", _("_Sessions:"), |
---|
| 163 | "icon-name", "session-properties", |
---|
| 164 | NULL); |
---|
| 165 | |
---|
| 166 | return GTK_WIDGET (object); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | char * |
---|
| 170 | gdm_session_option_widget_get_current_session (GdmSessionOptionWidget *widget) |
---|
| 171 | { |
---|
| 172 | char *active_item_id; |
---|
| 173 | |
---|
| 174 | active_item_id = gdm_option_widget_get_active_item (GDM_OPTION_WIDGET (widget)); |
---|
| 175 | if (active_item_id == NULL) { |
---|
| 176 | return NULL; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | return active_item_id; |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | void |
---|
| 183 | gdm_session_option_widget_set_current_session (GdmSessionOptionWidget *widget, |
---|
| 184 | const char *session) |
---|
| 185 | { |
---|
| 186 | if (session == NULL) { |
---|
| 187 | gdm_option_widget_set_active_item (GDM_OPTION_WIDGET (widget), |
---|
| 188 | GDM_SESSION_OPTION_WIDGET_LAST_SESSION); |
---|
| 189 | } else if (gdm_option_widget_lookup_item (GDM_OPTION_WIDGET (widget), session, |
---|
| 190 | NULL, NULL, NULL)) { |
---|
| 191 | gdm_option_widget_set_active_item (GDM_OPTION_WIDGET (widget), session); |
---|
| 192 | } |
---|
| 193 | } |
---|