~ubuntu-branches/ubuntu/trusty/unity-control-center/trusty

« back to all changes in this revision

Viewing changes to panels/network/net-object.c

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2014-01-08 16:29:18 UTC
  • Revision ID: package-import@ubuntu.com-20140108162918-g29dd08tr913y2qh
Tags: upstream-14.04.0
ImportĀ upstreamĀ versionĀ 14.04.0

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) 2011 Richard Hughes <richard@hughsie.com>
 
4
 *
 
5
 * Licensed under the GNU General Public License Version 2
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
20
 */
 
21
 
 
22
#include "config.h"
 
23
 
 
24
#include <glib-object.h>
 
25
#include <glib/gi18n.h>
 
26
 
 
27
#include "net-object.h"
 
28
 
 
29
#define NET_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NET_TYPE_OBJECT, NetObjectPrivate))
 
30
 
 
31
struct _NetObjectPrivate
 
32
{
 
33
        gchar                           *id;
 
34
        gchar                           *title;
 
35
        gboolean                         removable;
 
36
        GCancellable                    *cancellable;
 
37
        NMClient                        *client;
 
38
        NMRemoteSettings                *remote_settings;
 
39
        CcNetworkPanel                  *panel;
 
40
};
 
41
 
 
42
enum {
 
43
        PROP_0,
 
44
        PROP_ID,
 
45
        PROP_TITLE,
 
46
        PROP_REMOVABLE,
 
47
        PROP_CLIENT,
 
48
        PROP_REMOTE_SETTINGS,
 
49
        PROP_CANCELLABLE,
 
50
        PROP_PANEL,
 
51
        PROP_LAST
 
52
};
 
53
 
 
54
enum {
 
55
        SIGNAL_CHANGED,
 
56
        SIGNAL_REMOVED,
 
57
        SIGNAL_LAST
 
58
};
 
59
 
 
60
static guint signals[SIGNAL_LAST] = { 0 };
 
61
G_DEFINE_TYPE (NetObject, net_object, G_TYPE_OBJECT)
 
62
 
 
63
void
 
64
net_object_emit_changed (NetObject *object)
 
65
{
 
66
        g_return_if_fail (NET_IS_OBJECT (object));
 
67
        g_debug ("NetObject: %s emit 'changed'", object->priv->id);
 
68
        g_signal_emit (object, signals[SIGNAL_CHANGED], 0);
 
69
}
 
70
 
 
71
void
 
72
net_object_emit_removed (NetObject *object)
 
73
{
 
74
        g_return_if_fail (NET_IS_OBJECT (object));
 
75
        g_debug ("NetObject: %s emit 'removed'", object->priv->id);
 
76
        g_signal_emit (object, signals[SIGNAL_REMOVED], 0);
 
77
}
 
78
 
 
79
const gchar *
 
80
net_object_get_id (NetObject *object)
 
81
{
 
82
        g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
 
83
        return object->priv->id;
 
84
}
 
85
 
 
86
void
 
87
net_object_set_id (NetObject *object, const gchar *id)
 
88
{
 
89
        g_return_if_fail (NET_IS_OBJECT (object));
 
90
        object->priv->id = g_strdup (id);
 
91
}
 
92
 
 
93
gboolean
 
94
net_object_get_removable (NetObject *object)
 
95
{
 
96
        g_return_val_if_fail (NET_IS_OBJECT (object), FALSE);
 
97
        return object->priv->removable;
 
98
}
 
99
 
 
100
const gchar *
 
101
net_object_get_title (NetObject *object)
 
102
{
 
103
        g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
 
104
        return object->priv->title;
 
105
}
 
106
 
 
107
void
 
108
net_object_set_title (NetObject *object, const gchar *title)
 
109
{
 
110
        g_return_if_fail (NET_IS_OBJECT (object));
 
111
        object->priv->title = g_strdup (title);
 
112
}
 
113
 
 
114
NMClient *
 
115
net_object_get_client (NetObject *object)
 
116
{
 
117
        g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
 
118
        return object->priv->client;
 
119
}
 
120
 
 
121
NMRemoteSettings *
 
122
net_object_get_remote_settings (NetObject *object)
 
123
{
 
124
        g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
 
125
        return object->priv->remote_settings;
 
126
}
 
127
 
 
128
GCancellable *
 
129
net_object_get_cancellable (NetObject *object)
 
130
{
 
131
        g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
 
132
        return object->priv->cancellable;
 
133
}
 
134
 
 
135
CcNetworkPanel *
 
136
net_object_get_panel (NetObject *object)
 
137
{
 
138
        g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
 
139
        return object->priv->panel;
 
140
}
 
141
 
 
142
GtkWidget *
 
143
net_object_add_to_notebook (NetObject *object,
 
144
                            GtkNotebook *notebook,
 
145
                            GtkSizeGroup *heading_size_group)
 
146
{
 
147
        GtkWidget *widget;
 
148
        NetObjectClass *klass = NET_OBJECT_GET_CLASS (object);
 
149
        if (klass->add_to_notebook != NULL) {
 
150
                widget = klass->add_to_notebook (object,
 
151
                                                 notebook,
 
152
                                                 heading_size_group);
 
153
                g_object_set_data_full (G_OBJECT (widget),
 
154
                                        "NetObject::id",
 
155
                                        g_strdup (object->priv->id),
 
156
                                        g_free);
 
157
                return widget;
 
158
        }
 
159
        g_debug ("no klass->add_to_notebook for %s", object->priv->id);
 
160
        return NULL;
 
161
}
 
162
 
 
163
void
 
164
net_object_delete (NetObject *object)
 
165
{
 
166
        NetObjectClass *klass = NET_OBJECT_GET_CLASS (object);
 
167
        if (klass->delete != NULL)
 
168
                klass->delete (object);
 
169
}
 
170
 
 
171
void
 
172
net_object_refresh (NetObject *object)
 
173
{
 
174
        NetObjectClass *klass = NET_OBJECT_GET_CLASS (object);
 
175
        if (klass->refresh != NULL)
 
176
                klass->refresh (object);
 
177
}
 
178
 
 
179
void
 
180
net_object_edit (NetObject *object)
 
181
{
 
182
        NetObjectClass *klass = NET_OBJECT_GET_CLASS (object);
 
183
        if (klass->edit != NULL)
 
184
                klass->edit (object);
 
185
}
 
186
 
 
187
/**
 
188
 * net_object_get_property:
 
189
 **/
 
190
static void
 
191
net_object_get_property (GObject *object_,
 
192
                         guint prop_id,
 
193
                         GValue *value,
 
194
                         GParamSpec *pspec)
 
195
{
 
196
        NetObject *object = NET_OBJECT (object_);
 
197
        NetObjectPrivate *priv = object->priv;
 
198
 
 
199
        switch (prop_id) {
 
200
        case PROP_ID:
 
201
                g_value_set_string (value, priv->id);
 
202
                break;
 
203
        case PROP_TITLE:
 
204
                g_value_set_string (value, priv->title);
 
205
                break;
 
206
        case PROP_REMOVABLE:
 
207
                g_value_set_boolean (value, priv->removable);
 
208
                break;
 
209
        case PROP_CLIENT:
 
210
                g_value_set_object (value, priv->client);
 
211
                break;
 
212
        case PROP_REMOTE_SETTINGS:
 
213
                g_value_set_object (value, priv->remote_settings);
 
214
                break;
 
215
        case PROP_CANCELLABLE:
 
216
                g_value_set_object (value, priv->cancellable);
 
217
                break;
 
218
        case PROP_PANEL:
 
219
                g_value_set_object (value, priv->panel);
 
220
                break;
 
221
        default:
 
222
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
223
                break;
 
224
        }
 
225
}
 
226
 
 
227
/**
 
228
 * net_object_set_property:
 
229
 **/
 
230
static void
 
231
net_object_set_property (GObject *object_,
 
232
                         guint prop_id,
 
233
                         const GValue *value,
 
234
                         GParamSpec *pspec)
 
235
{
 
236
        NetObject *object = NET_OBJECT (object_);
 
237
        NetObjectPrivate *priv = object->priv;
 
238
 
 
239
        switch (prop_id) {
 
240
        case PROP_ID:
 
241
                g_free (priv->id);
 
242
                priv->id = g_strdup (g_value_get_string (value));
 
243
                break;
 
244
        case PROP_TITLE:
 
245
                g_free (priv->title);
 
246
                priv->title = g_strdup (g_value_get_string (value));
 
247
                break;
 
248
        case PROP_REMOVABLE:
 
249
                priv->removable = g_value_get_boolean (value);
 
250
                break;
 
251
        case PROP_CLIENT:
 
252
                priv->client = g_value_dup_object (value);
 
253
                break;
 
254
        case PROP_REMOTE_SETTINGS:
 
255
                priv->remote_settings = g_value_dup_object (value);
 
256
                break;
 
257
        case PROP_CANCELLABLE:
 
258
                priv->cancellable = g_value_dup_object (value);
 
259
                break;
 
260
        case PROP_PANEL:
 
261
                priv->panel = g_value_dup_object (value);
 
262
                break;
 
263
        default:
 
264
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
265
                break;
 
266
        }
 
267
}
 
268
 
 
269
static void
 
270
net_object_finalize (GObject *object)
 
271
{
 
272
        NetObject *nm_object = NET_OBJECT (object);
 
273
        NetObjectPrivate *priv = nm_object->priv;
 
274
 
 
275
        g_free (priv->id);
 
276
        g_free (priv->title);
 
277
        if (priv->client != NULL)
 
278
                g_object_unref (priv->client);
 
279
        if (priv->remote_settings != NULL)
 
280
                g_object_unref (priv->remote_settings);
 
281
        if (priv->cancellable != NULL)
 
282
                g_object_unref (priv->cancellable);
 
283
        if (priv->panel != NULL)
 
284
                g_object_unref (priv->panel);
 
285
        G_OBJECT_CLASS (net_object_parent_class)->finalize (object);
 
286
}
 
287
 
 
288
static void
 
289
net_object_class_init (NetObjectClass *klass)
 
290
{
 
291
        GParamSpec *pspec;
 
292
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
293
        object_class->finalize = net_object_finalize;
 
294
        object_class->get_property = net_object_get_property;
 
295
        object_class->set_property = net_object_set_property;
 
296
 
 
297
        pspec = g_param_spec_string ("id", NULL, NULL,
 
298
                                     NULL,
 
299
                                     G_PARAM_READWRITE);
 
300
        g_object_class_install_property (object_class, PROP_ID, pspec);
 
301
 
 
302
        pspec = g_param_spec_string ("title", NULL, NULL,
 
303
                                     NULL,
 
304
                                     G_PARAM_READWRITE);
 
305
        g_object_class_install_property (object_class, PROP_TITLE, pspec);
 
306
 
 
307
        pspec = g_param_spec_boolean ("removable", NULL, NULL,
 
308
                                      TRUE,
 
309
                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
 
310
        g_object_class_install_property (object_class, PROP_REMOVABLE, pspec);
 
311
 
 
312
        pspec = g_param_spec_object ("client", NULL, NULL,
 
313
                                     NM_TYPE_CLIENT,
 
314
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
 
315
        g_object_class_install_property (object_class, PROP_CLIENT, pspec);
 
316
 
 
317
        pspec = g_param_spec_object ("remote-settings", NULL, NULL,
 
318
                                     NM_TYPE_REMOTE_SETTINGS,
 
319
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
 
320
        g_object_class_install_property (object_class, PROP_REMOTE_SETTINGS, pspec);
 
321
 
 
322
        pspec = g_param_spec_object ("cancellable", NULL, NULL,
 
323
                                     G_TYPE_CANCELLABLE,
 
324
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
 
325
        g_object_class_install_property (object_class, PROP_CANCELLABLE, pspec);
 
326
 
 
327
        pspec = g_param_spec_object ("panel", NULL, NULL,
 
328
                                     CC_TYPE_NETWORK_PANEL,
 
329
                                     G_PARAM_READWRITE | G_PARAM_CONSTRUCT);
 
330
        g_object_class_install_property (object_class, PROP_PANEL, pspec);
 
331
 
 
332
        signals[SIGNAL_CHANGED] =
 
333
                g_signal_new ("changed",
 
334
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
 
335
                              G_STRUCT_OFFSET (NetObjectClass, changed),
 
336
                              NULL, NULL, g_cclosure_marshal_VOID__VOID,
 
337
                              G_TYPE_NONE, 0);
 
338
        signals[SIGNAL_REMOVED] =
 
339
                g_signal_new ("removed",
 
340
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
 
341
                              G_STRUCT_OFFSET (NetObjectClass, changed),
 
342
                              NULL, NULL, g_cclosure_marshal_VOID__VOID,
 
343
                              G_TYPE_NONE, 0);
 
344
 
 
345
        g_type_class_add_private (klass, sizeof (NetObjectPrivate));
 
346
}
 
347
 
 
348
static void
 
349
net_object_init (NetObject *object)
 
350
{
 
351
        object->priv = NET_OBJECT_GET_PRIVATE (object);
 
352
}
 
353