~ubuntu-branches/ubuntu/precise/gnome-control-center/precise-updates

« back to all changes in this revision

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

Tags: upstream-3.0.1.1
ImportĀ upstreamĀ versionĀ 3.0.1.1

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
};
 
36
 
 
37
enum {
 
38
        SIGNAL_CHANGED,
 
39
        SIGNAL_REMOVED,
 
40
        SIGNAL_LAST
 
41
};
 
42
 
 
43
static guint signals[SIGNAL_LAST] = { 0 };
 
44
G_DEFINE_TYPE (NetObject, net_object, G_TYPE_OBJECT)
 
45
 
 
46
void
 
47
net_object_emit_changed (NetObject *object)
 
48
{
 
49
        g_return_if_fail (NET_IS_OBJECT (object));
 
50
        g_debug ("NetObject: %s emit 'changed'", object->priv->id);
 
51
        g_signal_emit (object, signals[SIGNAL_CHANGED], 0);
 
52
}
 
53
 
 
54
void
 
55
net_object_emit_removed (NetObject *object)
 
56
{
 
57
        g_return_if_fail (NET_IS_OBJECT (object));
 
58
        g_debug ("NetObject: %s emit 'removed'", object->priv->id);
 
59
        g_signal_emit (object, signals[SIGNAL_REMOVED], 0);
 
60
}
 
61
 
 
62
const gchar *
 
63
net_object_get_id (NetObject *object)
 
64
{
 
65
        g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
 
66
        return object->priv->id;
 
67
}
 
68
 
 
69
void
 
70
net_object_set_id (NetObject *object, const gchar *id)
 
71
{
 
72
        g_return_if_fail (NET_IS_OBJECT (object));
 
73
        object->priv->id = g_strdup (id);
 
74
}
 
75
 
 
76
const gchar *
 
77
net_object_get_title (NetObject *object)
 
78
{
 
79
        g_return_val_if_fail (NET_IS_OBJECT (object), NULL);
 
80
        return object->priv->title;
 
81
}
 
82
 
 
83
void
 
84
net_object_set_title (NetObject *object, const gchar *title)
 
85
{
 
86
        g_return_if_fail (NET_IS_OBJECT (object));
 
87
        object->priv->title = g_strdup (title);
 
88
}
 
89
 
 
90
static void
 
91
net_object_finalize (GObject *object)
 
92
{
 
93
        NetObject *nm_object = NET_OBJECT (object);
 
94
        NetObjectPrivate *priv = nm_object->priv;
 
95
 
 
96
        g_free (priv->id);
 
97
        g_free (priv->title);
 
98
 
 
99
        G_OBJECT_CLASS (net_object_parent_class)->finalize (object);
 
100
}
 
101
 
 
102
static void
 
103
net_object_class_init (NetObjectClass *klass)
 
104
{
 
105
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
106
        object_class->finalize = net_object_finalize;
 
107
 
 
108
        signals[SIGNAL_CHANGED] =
 
109
                g_signal_new ("changed",
 
110
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
 
111
                              G_STRUCT_OFFSET (NetObjectClass, changed),
 
112
                              NULL, NULL, g_cclosure_marshal_VOID__VOID,
 
113
                              G_TYPE_NONE, 0);
 
114
        signals[SIGNAL_REMOVED] =
 
115
                g_signal_new ("removed",
 
116
                              G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
 
117
                              G_STRUCT_OFFSET (NetObjectClass, changed),
 
118
                              NULL, NULL, g_cclosure_marshal_VOID__VOID,
 
119
                              G_TYPE_NONE, 0);
 
120
 
 
121
        g_type_class_add_private (klass, sizeof (NetObjectPrivate));
 
122
}
 
123
 
 
124
static void
 
125
net_object_init (NetObject *object)
 
126
{
 
127
        object->priv = NET_OBJECT_GET_PRIVATE (object);
 
128
}
 
129
 
 
130
NetObject *
 
131
net_object_new (void)
 
132
{
 
133
        NetObject *object;
 
134
        object = g_object_new (NET_TYPE_OBJECT, NULL);
 
135
        return NET_OBJECT (object);
 
136
}
 
137