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

« back to all changes in this revision

Viewing changes to gui/simple-chooser/gdm-host-chooser-dialog.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) 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
 
 
38
struct GdmHostChooserDialogPrivate
 
39
{
 
40
        GtkWidget *chooser_widget;
 
41
        int        kind_mask;
 
42
};
 
43
 
 
44
enum {
 
45
        PROP_0,
 
46
        PROP_KIND_MASK,
 
47
};
 
48
 
 
49
static void     gdm_host_chooser_dialog_class_init  (GdmHostChooserDialogClass *klass);
 
50
static void     gdm_host_chooser_dialog_init        (GdmHostChooserDialog      *host_chooser_dialog);
 
51
static void     gdm_host_chooser_dialog_finalize    (GObject                   *object);
 
52
 
 
53
G_DEFINE_TYPE (GdmHostChooserDialog, gdm_host_chooser_dialog, GTK_TYPE_DIALOG)
 
54
 
 
55
GdmChooserHost *
 
56
gdm_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
 
 
67
static 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
 
 
76
static void
 
77
gdm_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
 
 
96
static void
 
97
gdm_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
 
 
109
static void
 
110
on_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
 
 
123
static GObject *
 
124
gdm_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
 
 
161
static void
 
162
gdm_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
 
 
169
static void
 
170
gdm_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
 
 
193
static void
 
194
gdm_host_chooser_dialog_init (GdmHostChooserDialog *dialog)
 
195
{
 
196
        dialog->priv = GDM_HOST_CHOOSER_DIALOG_GET_PRIVATE (dialog);
 
197
}
 
198
 
 
199
static void
 
200
gdm_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
 
 
214
GtkWidget *
 
215
gdm_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
}