source: proiecte/PPPP/gdm/gui/simple-chooser/gdm-host-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.8 KB
Line 
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 *
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 <glib.h>
29#include <glib/gi18n.h>
30#include <glib-object.h>
31#include <gtk/gtk.h>
32
33#include "gdm-host-chooser-dialog.h"
34#include "gdm-host-chooser-widget.h"
35
36#define GDM_HOST_CHOOSER_DIALOG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_HOST_CHOOSER_DIALOG, GdmHostChooserDialogPrivate))
37
38struct GdmHostChooserDialogPrivate
39{
40        GtkWidget *chooser_widget;
41        int        kind_mask;
42};
43
44enum {
45        PROP_0,
46        PROP_KIND_MASK,
47};
48
49static void     gdm_host_chooser_dialog_class_init  (GdmHostChooserDialogClass *klass);
50static void     gdm_host_chooser_dialog_init        (GdmHostChooserDialog      *host_chooser_dialog);
51static void     gdm_host_chooser_dialog_finalize    (GObject                   *object);
52
53G_DEFINE_TYPE (GdmHostChooserDialog, gdm_host_chooser_dialog, GTK_TYPE_DIALOG)
54
55GdmChooserHost *
56gdm_host_chooser_dialog_get_host (GdmHostChooserDialog *dialog)
57{
58        GdmChooserHost *host;
59
60        g_return_val_if_fail (GDM_IS_HOST_CHOOSER_DIALOG (dialog), NULL);
61
62        host = gdm_host_chooser_widget_get_host (GDM_HOST_CHOOSER_WIDGET (dialog->priv->chooser_widget));
63
64        return host;
65}
66
67static void
68_gdm_host_chooser_dialog_set_kind_mask (GdmHostChooserDialog *dialog,
69                                        int                   kind_mask)
70{
71        if (dialog->priv->kind_mask != kind_mask) {
72                dialog->priv->kind_mask = kind_mask;
73        }
74}
75
76static void
77gdm_host_chooser_dialog_set_property (GObject        *object,
78                                      guint           prop_id,
79                                      const GValue   *value,
80                                      GParamSpec     *pspec)
81{
82        GdmHostChooserDialog *self;
83
84        self = GDM_HOST_CHOOSER_DIALOG (object);
85
86        switch (prop_id) {
87        case PROP_KIND_MASK:
88                _gdm_host_chooser_dialog_set_kind_mask (self, g_value_get_int (value));
89                break;
90        default:
91                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
92                break;
93        }
94}
95
96static void
97gdm_host_chooser_dialog_get_property (GObject        *object,
98                                      guint           prop_id,
99                                      GValue         *value,
100                                      GParamSpec     *pspec)
101{
102        switch (prop_id) {
103        default:
104                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
105                break;
106        }
107}
108
109static void
110on_response (GdmHostChooserDialog *dialog,
111             gint                  response_id)
112{
113        switch (response_id) {
114        case GTK_RESPONSE_APPLY:
115                gdm_host_chooser_widget_refresh (GDM_HOST_CHOOSER_WIDGET (dialog->priv->chooser_widget));
116                g_signal_stop_emission_by_name (dialog, "response");
117                break;
118        default:
119                break;
120        }
121}
122
123static GObject *
124gdm_host_chooser_dialog_constructor (GType                  type,
125                                     guint                  n_construct_properties,
126                                     GObjectConstructParam *construct_properties)
127{
128        GdmHostChooserDialog      *dialog;
129
130        dialog = GDM_HOST_CHOOSER_DIALOG (G_OBJECT_CLASS (gdm_host_chooser_dialog_parent_class)->constructor (type,
131                                                                                                                           n_construct_properties,
132                                                                                                                           construct_properties));
133
134
135        dialog->priv->chooser_widget = gdm_host_chooser_widget_new (dialog->priv->kind_mask);
136        gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), dialog->priv->chooser_widget);
137        gtk_container_set_border_width (GTK_CONTAINER (dialog->priv->chooser_widget), 5);
138
139        gtk_dialog_add_buttons (GTK_DIALOG (dialog),
140                                GTK_STOCK_REFRESH, GTK_RESPONSE_APPLY,
141                                GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
142                                GTK_STOCK_CONNECT, GTK_RESPONSE_OK,
143                                NULL);
144
145        gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
146        gtk_container_set_border_width (GTK_CONTAINER (dialog), 12);
147        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
148        gtk_window_set_title (GTK_WINDOW (dialog), _("Select System"));
149        gtk_window_set_icon_name (GTK_WINDOW (dialog), "computer");
150
151        g_signal_connect (dialog,
152                          "response",
153                          G_CALLBACK (on_response),
154                          dialog);
155
156        gtk_widget_show_all (GTK_WIDGET (dialog));
157
158        return G_OBJECT (dialog);
159}
160
161static void
162gdm_host_chooser_dialog_dispose (GObject *object)
163{
164        g_debug ("Disposing host_chooser_dialog");
165
166        G_OBJECT_CLASS (gdm_host_chooser_dialog_parent_class)->dispose (object);
167}
168
169static void
170gdm_host_chooser_dialog_class_init (GdmHostChooserDialogClass *klass)
171{
172        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
173
174        object_class->get_property = gdm_host_chooser_dialog_get_property;
175        object_class->set_property = gdm_host_chooser_dialog_set_property;
176        object_class->constructor = gdm_host_chooser_dialog_constructor;
177        object_class->dispose = gdm_host_chooser_dialog_dispose;
178        object_class->finalize = gdm_host_chooser_dialog_finalize;
179
180        g_object_class_install_property (object_class,
181                                         PROP_KIND_MASK,
182                                         g_param_spec_int ("kind-mask",
183                                                           "kind mask",
184                                                           "kind mask",
185                                                           0,
186                                                           G_MAXINT,
187                                                           0,
188                                                           G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
189
190        g_type_class_add_private (klass, sizeof (GdmHostChooserDialogPrivate));
191}
192
193static void
194gdm_host_chooser_dialog_init (GdmHostChooserDialog *dialog)
195{
196        dialog->priv = GDM_HOST_CHOOSER_DIALOG_GET_PRIVATE (dialog);
197}
198
199static void
200gdm_host_chooser_dialog_finalize (GObject *object)
201{
202        GdmHostChooserDialog *host_chooser_dialog;
203
204        g_return_if_fail (object != NULL);
205        g_return_if_fail (GDM_IS_HOST_CHOOSER_DIALOG (object));
206
207        host_chooser_dialog = GDM_HOST_CHOOSER_DIALOG (object);
208
209        g_return_if_fail (host_chooser_dialog->priv != NULL);
210
211        G_OBJECT_CLASS (gdm_host_chooser_dialog_parent_class)->finalize (object);
212}
213
214GtkWidget *
215gdm_host_chooser_dialog_new (int kind_mask)
216{
217        GObject *object;
218
219        object = g_object_new (GDM_TYPE_HOST_CHOOSER_DIALOG,
220                               "kind-mask", kind_mask,
221                               NULL);
222
223        return GTK_WIDGET (object);
224}
Note: See TracBrowser for help on using the repository browser.