~ubuntu-branches/ubuntu/oneiric/gdm3/oneiric

« back to all changes in this revision

Viewing changes to gui/simple-greeter/gdm-layout-chooser-widget.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2010-03-25 20:02:20 UTC
  • Revision ID: james.westby@ubuntu.com-20100325200220-12cap62s6p304nuh
Tags: upstream-2.29.92
ImportĀ upstreamĀ versionĀ 2.29.92

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
 
2
 *
 
3
 * Copyright (C) 2008 Matthias Clasen <mclasen@redhat.com>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <unistd.h>
 
26
#include <string.h>
 
27
#include <errno.h>
 
28
#include <dirent.h>
 
29
#include <locale.h>
 
30
#include <sys/stat.h>
 
31
 
 
32
#include <fontconfig/fontconfig.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-layout-chooser-widget.h"
 
40
#include "gdm-chooser-widget.h"
 
41
#include "gdm-layouts.h"
 
42
 
 
43
#define GDM_LAYOUT_CHOOSER_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_LAYOUT_CHOOSER_WIDGET, GdmLayoutChooserWidgetPrivate))
 
44
 
 
45
struct GdmLayoutChooserWidgetPrivate
 
46
{
 
47
        guint               layouts_added : 1;
 
48
};
 
49
 
 
50
static void     gdm_layout_chooser_widget_class_init  (GdmLayoutChooserWidgetClass *klass);
 
51
static void     gdm_layout_chooser_widget_init        (GdmLayoutChooserWidget      *layout_chooser_widget);
 
52
static void     gdm_layout_chooser_widget_finalize    (GObject                     *object);
 
53
 
 
54
G_DEFINE_TYPE (GdmLayoutChooserWidget, gdm_layout_chooser_widget, GDM_TYPE_CHOOSER_WIDGET)
 
55
 
 
56
enum {
 
57
        CHOOSER_LIST_TITLE_COLUMN = 0,
 
58
        CHOOSER_LIST_TRANSLATED_COLUMN,
 
59
        CHOOSER_LIST_LOCALE_COLUMN
 
60
};
 
61
 
 
62
char *
 
63
gdm_layout_chooser_widget_get_current_layout_name (GdmLayoutChooserWidget *widget)
 
64
{
 
65
        char *id;
 
66
 
 
67
        g_return_val_if_fail (GDM_IS_LAYOUT_CHOOSER_WIDGET (widget), NULL);
 
68
 
 
69
        id = gdm_chooser_widget_get_selected_item (GDM_CHOOSER_WIDGET (widget));
 
70
 
 
71
        if (id == NULL) {
 
72
                id = g_strdup ("us");
 
73
        }
 
74
 
 
75
        return id;
 
76
}
 
77
 
 
78
void
 
79
gdm_layout_chooser_widget_set_current_layout_name (GdmLayoutChooserWidget *widget,
 
80
                                                   const char             *id)
 
81
{
 
82
        g_return_if_fail (GDM_IS_LAYOUT_CHOOSER_WIDGET (widget));
 
83
 
 
84
        if (id == NULL) {
 
85
                gdm_chooser_widget_set_selected_item (GDM_CHOOSER_WIDGET (widget),
 
86
                                                      NULL);
 
87
                return;
 
88
        }
 
89
 
 
90
        gdm_chooser_widget_set_selected_item (GDM_CHOOSER_WIDGET (widget), id);
 
91
}
 
92
 
 
93
static void
 
94
gdm_layout_chooser_widget_add_layout (GdmLayoutChooserWidget *widget,
 
95
                                          const char         *name)
 
96
{
 
97
        char *layout;
 
98
        char *escaped;
 
99
 
 
100
        layout = gdm_get_layout_from_name (name);
 
101
 
 
102
        if (layout != NULL) {
 
103
                escaped = g_markup_escape_text (layout, -1);
 
104
                gdm_chooser_widget_add_item (GDM_CHOOSER_WIDGET (widget),
 
105
                                             name,
 
106
                                             NULL,
 
107
                                             escaped,
 
108
                                             NULL,
 
109
                                             0,
 
110
                                             FALSE,
 
111
                                             FALSE);
 
112
                g_free (escaped);
 
113
                g_free (layout);
 
114
        }
 
115
}
 
116
 
 
117
static void
 
118
add_available_layouts (GdmLayoutChooserWidget *widget)
 
119
{
 
120
        char **layout_names;
 
121
        int    i;
 
122
 
 
123
        layout_names = gdm_get_all_layout_names ();
 
124
 
 
125
        if (layout_names == NULL)
 
126
           return;
 
127
 
 
128
        for (i = 0; layout_names[i] != NULL; i++) {
 
129
                gdm_layout_chooser_widget_add_layout (widget,
 
130
                                                      layout_names[i]);
 
131
        }
 
132
 
 
133
        g_strfreev (layout_names);
 
134
}
 
135
 
 
136
static void
 
137
gdm_layout_chooser_widget_dispose (GObject *object)
 
138
{
 
139
        G_OBJECT_CLASS (gdm_layout_chooser_widget_parent_class)->dispose (object);
 
140
}
 
141
 
 
142
static void
 
143
gdm_layout_chooser_widget_realize (GtkWidget *widget)
 
144
{
 
145
        GdmLayoutChooserWidget *chooser;
 
146
 
 
147
        chooser = GDM_LAYOUT_CHOOSER_WIDGET (widget);
 
148
 
 
149
        GTK_WIDGET_CLASS (gdm_layout_chooser_widget_parent_class)->realize (widget);
 
150
 
 
151
        if (!chooser->priv->layouts_added) {
 
152
                add_available_layouts (chooser);
 
153
                chooser->priv->layouts_added = TRUE;
 
154
        }
 
155
}
 
156
 
 
157
static void
 
158
gdm_layout_chooser_widget_class_init (GdmLayoutChooserWidgetClass *klass)
 
159
{
 
160
        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
161
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
162
 
 
163
        object_class->dispose = gdm_layout_chooser_widget_dispose;
 
164
        object_class->finalize = gdm_layout_chooser_widget_finalize;
 
165
        widget_class->realize = gdm_layout_chooser_widget_realize;
 
166
 
 
167
        g_type_class_add_private (klass, sizeof (GdmLayoutChooserWidgetPrivate));
 
168
}
 
169
 
 
170
static void
 
171
gdm_layout_chooser_widget_init (GdmLayoutChooserWidget *widget)
 
172
{
 
173
        widget->priv = GDM_LAYOUT_CHOOSER_WIDGET_GET_PRIVATE (widget);
 
174
 
 
175
        gdm_chooser_widget_set_separator_position (GDM_CHOOSER_WIDGET (widget),
 
176
                                                   GDM_CHOOSER_WIDGET_POSITION_TOP);
 
177
}
 
178
 
 
179
static void
 
180
gdm_layout_chooser_widget_finalize (GObject *object)
 
181
{
 
182
        GdmLayoutChooserWidget *layout_chooser_widget;
 
183
 
 
184
        g_return_if_fail (object != NULL);
 
185
        g_return_if_fail (GDM_IS_LAYOUT_CHOOSER_WIDGET (object));
 
186
 
 
187
        layout_chooser_widget = GDM_LAYOUT_CHOOSER_WIDGET (object);
 
188
 
 
189
        g_return_if_fail (layout_chooser_widget->priv != NULL);
 
190
 
 
191
        G_OBJECT_CLASS (gdm_layout_chooser_widget_parent_class)->finalize (object);
 
192
}
 
193
 
 
194
GtkWidget *
 
195
gdm_layout_chooser_widget_new (void)
 
196
{
 
197
        GObject *object;
 
198
 
 
199
        object = g_object_new (GDM_TYPE_LAYOUT_CHOOSER_WIDGET,
 
200
                               "inactive-text", _("_Keyboard:"),
 
201
                               "active-text", _("_Keyboard:"),
 
202
                               NULL);
 
203
 
 
204
        return GTK_WIDGET (object);
 
205
}