1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
---|
2 | * |
---|
3 | * Copyright (C) 2008 Red Hat, Inc. |
---|
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 | |
---|
29 | #include <glib.h> |
---|
30 | #include <glib/gi18n.h> |
---|
31 | #include <glib-object.h> |
---|
32 | |
---|
33 | #include "gdm-address.h" |
---|
34 | #include "gdm-chooser-host.h" |
---|
35 | |
---|
36 | #define GDM_CHOOSER_HOST_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_CHOOSER_HOST, GdmChooserHostPrivate)) |
---|
37 | |
---|
38 | struct GdmChooserHostPrivate |
---|
39 | { |
---|
40 | GdmAddress *address; |
---|
41 | char *description; |
---|
42 | GdmChooserHostKind kind; |
---|
43 | gboolean willing; |
---|
44 | }; |
---|
45 | |
---|
46 | enum { |
---|
47 | PROP_0, |
---|
48 | PROP_ADDRESS, |
---|
49 | PROP_DESCRIPTION, |
---|
50 | PROP_KIND, |
---|
51 | PROP_WILLING, |
---|
52 | }; |
---|
53 | |
---|
54 | static void gdm_chooser_host_class_init (GdmChooserHostClass *klass); |
---|
55 | static void gdm_chooser_host_init (GdmChooserHost *chooser_host); |
---|
56 | static void gdm_chooser_host_finalize (GObject *object); |
---|
57 | |
---|
58 | G_DEFINE_TYPE (GdmChooserHost, gdm_chooser_host, G_TYPE_OBJECT) |
---|
59 | |
---|
60 | GdmAddress * |
---|
61 | gdm_chooser_host_get_address (GdmChooserHost *host) |
---|
62 | { |
---|
63 | g_return_val_if_fail (GDM_IS_CHOOSER_HOST (host), NULL); |
---|
64 | |
---|
65 | return host->priv->address; |
---|
66 | } |
---|
67 | |
---|
68 | G_CONST_RETURN char * |
---|
69 | gdm_chooser_host_get_description (GdmChooserHost *host) |
---|
70 | { |
---|
71 | g_return_val_if_fail (GDM_IS_CHOOSER_HOST (host), NULL); |
---|
72 | |
---|
73 | return host->priv->description; |
---|
74 | } |
---|
75 | |
---|
76 | GdmChooserHostKind |
---|
77 | gdm_chooser_host_get_kind (GdmChooserHost *host) |
---|
78 | { |
---|
79 | g_return_val_if_fail (GDM_IS_CHOOSER_HOST (host), 0); |
---|
80 | |
---|
81 | return host->priv->kind; |
---|
82 | } |
---|
83 | |
---|
84 | gboolean |
---|
85 | gdm_chooser_host_get_willing (GdmChooserHost *host) |
---|
86 | { |
---|
87 | g_return_val_if_fail (GDM_IS_CHOOSER_HOST (host), FALSE); |
---|
88 | |
---|
89 | return host->priv->willing; |
---|
90 | } |
---|
91 | |
---|
92 | static void |
---|
93 | _gdm_chooser_host_set_address (GdmChooserHost *host, |
---|
94 | GdmAddress *address) |
---|
95 | { |
---|
96 | if (host->priv->address != NULL) { |
---|
97 | gdm_address_free (host->priv->address); |
---|
98 | } |
---|
99 | |
---|
100 | g_assert (address != NULL); |
---|
101 | |
---|
102 | gdm_address_debug (address); |
---|
103 | host->priv->address = gdm_address_copy (address); |
---|
104 | } |
---|
105 | |
---|
106 | static void |
---|
107 | _gdm_chooser_host_set_description (GdmChooserHost *host, |
---|
108 | const char *description) |
---|
109 | { |
---|
110 | g_free (host->priv->description); |
---|
111 | host->priv->description = g_strdup (description); |
---|
112 | } |
---|
113 | |
---|
114 | static void |
---|
115 | _gdm_chooser_host_set_kind (GdmChooserHost *host, |
---|
116 | int kind) |
---|
117 | { |
---|
118 | if (host->priv->kind != kind) { |
---|
119 | host->priv->kind = kind; |
---|
120 | } |
---|
121 | } |
---|
122 | |
---|
123 | static void |
---|
124 | _gdm_chooser_host_set_willing (GdmChooserHost *host, |
---|
125 | gboolean willing) |
---|
126 | { |
---|
127 | if (host->priv->willing != willing) { |
---|
128 | host->priv->willing = willing; |
---|
129 | } |
---|
130 | } |
---|
131 | |
---|
132 | static void |
---|
133 | gdm_chooser_host_set_property (GObject *object, |
---|
134 | guint param_id, |
---|
135 | const GValue *value, |
---|
136 | GParamSpec *pspec) |
---|
137 | { |
---|
138 | GdmChooserHost *host; |
---|
139 | |
---|
140 | host = GDM_CHOOSER_HOST (object); |
---|
141 | |
---|
142 | switch (param_id) { |
---|
143 | case PROP_ADDRESS: |
---|
144 | _gdm_chooser_host_set_address (host, g_value_get_boxed (value)); |
---|
145 | break; |
---|
146 | case PROP_DESCRIPTION: |
---|
147 | _gdm_chooser_host_set_description (host, g_value_get_string (value)); |
---|
148 | break; |
---|
149 | case PROP_KIND: |
---|
150 | _gdm_chooser_host_set_kind (host, g_value_get_int (value)); |
---|
151 | break; |
---|
152 | case PROP_WILLING: |
---|
153 | _gdm_chooser_host_set_willing (host, g_value_get_boolean (value)); |
---|
154 | break; |
---|
155 | default: |
---|
156 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
---|
157 | break; |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | static void |
---|
162 | gdm_chooser_host_get_property (GObject *object, |
---|
163 | guint param_id, |
---|
164 | GValue *value, |
---|
165 | GParamSpec *pspec) |
---|
166 | { |
---|
167 | GdmChooserHost *host; |
---|
168 | |
---|
169 | host = GDM_CHOOSER_HOST (object); |
---|
170 | |
---|
171 | switch (param_id) { |
---|
172 | case PROP_ADDRESS: |
---|
173 | g_value_set_boxed (value, host->priv->address); |
---|
174 | break; |
---|
175 | case PROP_DESCRIPTION: |
---|
176 | g_value_set_string (value, host->priv->description); |
---|
177 | break; |
---|
178 | case PROP_KIND: |
---|
179 | g_value_set_int (value, host->priv->kind); |
---|
180 | break; |
---|
181 | case PROP_WILLING: |
---|
182 | g_value_set_boolean (value, host->priv->willing); |
---|
183 | break; |
---|
184 | default: |
---|
185 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); |
---|
186 | break; |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | static void |
---|
191 | gdm_chooser_host_class_init (GdmChooserHostClass *klass) |
---|
192 | { |
---|
193 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
---|
194 | |
---|
195 | object_class->set_property = gdm_chooser_host_set_property; |
---|
196 | object_class->get_property = gdm_chooser_host_get_property; |
---|
197 | object_class->finalize = gdm_chooser_host_finalize; |
---|
198 | |
---|
199 | |
---|
200 | g_object_class_install_property (object_class, |
---|
201 | PROP_ADDRESS, |
---|
202 | g_param_spec_boxed ("address", |
---|
203 | "address", |
---|
204 | "address", |
---|
205 | GDM_TYPE_ADDRESS, |
---|
206 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
---|
207 | g_object_class_install_property (object_class, |
---|
208 | PROP_DESCRIPTION, |
---|
209 | g_param_spec_string ("description", |
---|
210 | "description", |
---|
211 | "description", |
---|
212 | NULL, |
---|
213 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
---|
214 | |
---|
215 | g_object_class_install_property (object_class, |
---|
216 | PROP_KIND, |
---|
217 | g_param_spec_int ("kind", |
---|
218 | "kind", |
---|
219 | "kind", |
---|
220 | 0, |
---|
221 | G_MAXINT, |
---|
222 | 0, |
---|
223 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
---|
224 | g_object_class_install_property (object_class, |
---|
225 | PROP_WILLING, |
---|
226 | g_param_spec_boolean ("willing", |
---|
227 | "willing", |
---|
228 | "willing", |
---|
229 | FALSE, |
---|
230 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); |
---|
231 | |
---|
232 | |
---|
233 | g_type_class_add_private (klass, sizeof (GdmChooserHostPrivate)); |
---|
234 | } |
---|
235 | |
---|
236 | static void |
---|
237 | gdm_chooser_host_init (GdmChooserHost *widget) |
---|
238 | { |
---|
239 | widget->priv = GDM_CHOOSER_HOST_GET_PRIVATE (widget); |
---|
240 | } |
---|
241 | |
---|
242 | static void |
---|
243 | gdm_chooser_host_finalize (GObject *object) |
---|
244 | { |
---|
245 | GdmChooserHost *host; |
---|
246 | |
---|
247 | g_return_if_fail (object != NULL); |
---|
248 | g_return_if_fail (GDM_IS_CHOOSER_HOST (object)); |
---|
249 | |
---|
250 | host = GDM_CHOOSER_HOST (object); |
---|
251 | |
---|
252 | g_return_if_fail (host->priv != NULL); |
---|
253 | |
---|
254 | g_free (host->priv->description); |
---|
255 | gdm_address_free (host->priv->address); |
---|
256 | |
---|
257 | G_OBJECT_CLASS (gdm_chooser_host_parent_class)->finalize (object); |
---|
258 | } |
---|