source: proiecte/PPPP/gdm/gui/simple-greeter/gdm-layout-chooser-dialog.c @ 134

Last change on this file since 134 was 134, checked in by (none), 14 years ago

gdm sources with the modifications for webcam

File size: 7.0 KB
Line 
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
28#include <locale.h>
29
30#include <glib.h>
31#include <glib/gi18n.h>
32#include <glib-object.h>
33#include <gtk/gtk.h>
34
35#include "gdm-layout-chooser-widget.h"
36#include "gdm-layout-chooser-dialog.h"
37
38#define GDM_LAYOUT_CHOOSER_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_LAYOUT_CHOOSER_DIALOG, GdmLayoutChooserDialogPrivate))
39
40struct GdmLayoutChooserDialogPrivate
41{
42        GtkWidget *chooser_widget;
43};
44
45
46static void     gdm_layout_chooser_dialog_class_init  (GdmLayoutChooserDialogClass *klass);
47static void     gdm_layout_chooser_dialog_init        (GdmLayoutChooserDialog      *layout_chooser_dialog);
48static void     gdm_layout_chooser_dialog_finalize    (GObject                       *object);
49
50G_DEFINE_TYPE (GdmLayoutChooserDialog, gdm_layout_chooser_dialog, GTK_TYPE_DIALOG)
51
52char *
53gdm_layout_chooser_dialog_get_current_layout_name (GdmLayoutChooserDialog *dialog)
54{
55        char *layout_name;
56
57        g_return_val_if_fail (GDM_IS_LAYOUT_CHOOSER_DIALOG (dialog), NULL);
58
59        layout_name = gdm_layout_chooser_widget_get_current_layout_name (GDM_LAYOUT_CHOOSER_WIDGET (dialog->priv->chooser_widget));
60
61        return layout_name;
62}
63
64void
65gdm_layout_chooser_dialog_set_current_layout_name (GdmLayoutChooserDialog *dialog,
66                                                   const char             *layout_name)
67{
68
69        g_return_if_fail (GDM_IS_LAYOUT_CHOOSER_DIALOG (dialog));
70
71        gdm_layout_chooser_widget_set_current_layout_name (GDM_LAYOUT_CHOOSER_WIDGET (dialog->priv->chooser_widget), layout_name);
72}
73
74static void
75gdm_layout_chooser_dialog_size_request (GtkWidget      *widget,
76                                        GtkRequisition *requisition)
77{
78        int            screen_w;
79        int            screen_h;
80        GtkRequisition child_requisition;
81
82        if (GTK_WIDGET_CLASS (gdm_layout_chooser_dialog_parent_class)->size_request) {
83                GTK_WIDGET_CLASS (gdm_layout_chooser_dialog_parent_class)->size_request (widget, requisition);
84        }
85
86        screen_w = gdk_screen_get_width (gtk_widget_get_screen (widget));
87        screen_h = gdk_screen_get_height (gtk_widget_get_screen (widget));
88
89        gtk_widget_get_child_requisition (GTK_BIN (widget)->child, &child_requisition);
90        *requisition = child_requisition;
91
92        requisition->width += 2 * GTK_CONTAINER (widget)->border_width;
93        requisition->height += 2 * GTK_CONTAINER (widget)->border_width;
94
95        requisition->width = MIN (requisition->width, .50 * screen_w);
96        requisition->height = MIN (requisition->height, .80 * screen_h);
97}
98
99static void
100gdm_layout_chooser_dialog_realize (GtkWidget *widget)
101{
102        GdmLayoutChooserDialog *chooser_dialog;
103
104        chooser_dialog = GDM_LAYOUT_CHOOSER_DIALOG (widget);
105
106        gtk_widget_show (chooser_dialog->priv->chooser_widget);
107
108        GTK_WIDGET_CLASS (gdm_layout_chooser_dialog_parent_class)->realize (widget);
109}
110
111static void
112gdm_layout_chooser_dialog_class_init (GdmLayoutChooserDialogClass *klass)
113{
114        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
115        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
116
117        object_class->finalize = gdm_layout_chooser_dialog_finalize;
118        widget_class->size_request = gdm_layout_chooser_dialog_size_request;
119        widget_class->realize = gdm_layout_chooser_dialog_realize;
120
121        g_type_class_add_private (klass, sizeof (GdmLayoutChooserDialogPrivate));
122}
123
124static gboolean
125respond (GdmLayoutChooserDialog *dialog)
126{
127        gtk_dialog_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
128
129        return FALSE;
130}
131
132static void
133queue_response (GdmLayoutChooserDialog *dialog)
134{
135        g_idle_add ((GSourceFunc) respond, dialog);
136}
137
138static void
139gdm_layout_chooser_dialog_init (GdmLayoutChooserDialog *dialog)
140{
141
142        dialog->priv = GDM_LAYOUT_CHOOSER_DIALOG_GET_PRIVATE (dialog);
143
144        dialog->priv->chooser_widget = gdm_layout_chooser_widget_new ();
145        gdm_chooser_widget_set_hide_inactive_items (GDM_CHOOSER_WIDGET (dialog->priv->chooser_widget),
146                                                    FALSE);
147
148        gdm_layout_chooser_widget_set_current_layout_name (GDM_LAYOUT_CHOOSER_WIDGET (dialog->priv->chooser_widget),
149                                                               setlocale (LC_MESSAGES, NULL));
150        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), dialog->priv->chooser_widget);
151
152        g_signal_connect_swapped (G_OBJECT (dialog->priv->chooser_widget),
153                                  "activated", G_CALLBACK (queue_response),
154                                  dialog);
155
156        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
157                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
158                                GTK_STOCK_OK, GTK_RESPONSE_OK,
159                                NULL);
160
161        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
162        gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
163        gtk_container_set_border_width (GTK_CONTAINER (dialog->priv->chooser_widget), 5);
164        gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
165        gtk_window_set_default_size (GTK_WINDOW (dialog), 512, 440);
166        gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
167}
168
169static void
170gdm_layout_chooser_dialog_finalize (GObject *object)
171{
172        GdmLayoutChooserDialog *layout_chooser_dialog;
173
174        g_return_if_fail (object != NULL);
175        g_return_if_fail (GDM_IS_LAYOUT_CHOOSER_DIALOG (object));
176
177        layout_chooser_dialog = GDM_LAYOUT_CHOOSER_DIALOG (object);
178
179        g_return_if_fail (layout_chooser_dialog->priv != NULL);
180
181        G_OBJECT_CLASS (gdm_layout_chooser_dialog_parent_class)->finalize (object);
182}
183
184GtkWidget *
185gdm_layout_chooser_dialog_new (void)
186{
187        GObject *object;
188
189        object = g_object_new (GDM_TYPE_LAYOUT_CHOOSER_DIALOG,
190                               "icon-name", "preferences-desktop-keyboard",
191                               "title", _("Keyboard layouts"),
192                               "border-width", 8,
193                               "modal", TRUE,
194                               NULL);
195
196        return GTK_WIDGET (object);
197}
Note: See TracBrowser for help on using the repository browser.