1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
3
* Copyright (C) 2008 Matthias Clasen <mclasen@redhat.com>
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.
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.
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.
32
#include <fontconfig/fontconfig.h>
35
#include <glib/gi18n.h>
36
#include <glib/gstdio.h>
39
#include "gdm-layout-chooser-widget.h"
40
#include "gdm-chooser-widget.h"
41
#include "gdm-layouts.h"
43
#define GDM_LAYOUT_CHOOSER_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_LAYOUT_CHOOSER_WIDGET, GdmLayoutChooserWidgetPrivate))
45
struct GdmLayoutChooserWidgetPrivate
47
guint layouts_added : 1;
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);
54
G_DEFINE_TYPE (GdmLayoutChooserWidget, gdm_layout_chooser_widget, GDM_TYPE_CHOOSER_WIDGET)
57
CHOOSER_LIST_TITLE_COLUMN = 0,
58
CHOOSER_LIST_TRANSLATED_COLUMN,
59
CHOOSER_LIST_LOCALE_COLUMN
63
gdm_layout_chooser_widget_get_current_layout_name (GdmLayoutChooserWidget *widget)
67
g_return_val_if_fail (GDM_IS_LAYOUT_CHOOSER_WIDGET (widget), NULL);
69
id = gdm_chooser_widget_get_selected_item (GDM_CHOOSER_WIDGET (widget));
79
gdm_layout_chooser_widget_set_current_layout_name (GdmLayoutChooserWidget *widget,
82
g_return_if_fail (GDM_IS_LAYOUT_CHOOSER_WIDGET (widget));
85
gdm_chooser_widget_set_selected_item (GDM_CHOOSER_WIDGET (widget),
90
gdm_chooser_widget_set_selected_item (GDM_CHOOSER_WIDGET (widget), id);
94
gdm_layout_chooser_widget_add_layout (GdmLayoutChooserWidget *widget,
100
layout = gdm_get_layout_from_name (name);
102
if (layout != NULL) {
103
escaped = g_markup_escape_text (layout, -1);
104
gdm_chooser_widget_add_item (GDM_CHOOSER_WIDGET (widget),
118
add_available_layouts (GdmLayoutChooserWidget *widget)
123
layout_names = gdm_get_all_layout_names ();
125
if (layout_names == NULL)
128
for (i = 0; layout_names[i] != NULL; i++) {
129
gdm_layout_chooser_widget_add_layout (widget,
133
g_strfreev (layout_names);
137
gdm_layout_chooser_widget_dispose (GObject *object)
139
G_OBJECT_CLASS (gdm_layout_chooser_widget_parent_class)->dispose (object);
143
gdm_layout_chooser_widget_realize (GtkWidget *widget)
145
GdmLayoutChooserWidget *chooser;
147
chooser = GDM_LAYOUT_CHOOSER_WIDGET (widget);
149
GTK_WIDGET_CLASS (gdm_layout_chooser_widget_parent_class)->realize (widget);
151
if (!chooser->priv->layouts_added) {
152
add_available_layouts (chooser);
153
chooser->priv->layouts_added = TRUE;
158
gdm_layout_chooser_widget_class_init (GdmLayoutChooserWidgetClass *klass)
160
GObjectClass *object_class = G_OBJECT_CLASS (klass);
161
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
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;
167
g_type_class_add_private (klass, sizeof (GdmLayoutChooserWidgetPrivate));
171
gdm_layout_chooser_widget_init (GdmLayoutChooserWidget *widget)
173
widget->priv = GDM_LAYOUT_CHOOSER_WIDGET_GET_PRIVATE (widget);
175
gdm_chooser_widget_set_separator_position (GDM_CHOOSER_WIDGET (widget),
176
GDM_CHOOSER_WIDGET_POSITION_TOP);
180
gdm_layout_chooser_widget_finalize (GObject *object)
182
GdmLayoutChooserWidget *layout_chooser_widget;
184
g_return_if_fail (object != NULL);
185
g_return_if_fail (GDM_IS_LAYOUT_CHOOSER_WIDGET (object));
187
layout_chooser_widget = GDM_LAYOUT_CHOOSER_WIDGET (object);
189
g_return_if_fail (layout_chooser_widget->priv != NULL);
191
G_OBJECT_CLASS (gdm_layout_chooser_widget_parent_class)->finalize (object);
195
gdm_layout_chooser_widget_new (void)
199
object = g_object_new (GDM_TYPE_LAYOUT_CHOOSER_WIDGET,
200
"inactive-text", _("_Keyboard:"),
201
"active-text", _("_Keyboard:"),
204
return GTK_WIDGET (object);