Debian Codegraph @

lib/packagekit-glib2/pk-source.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2009 Richard Hughes <[email protected]>
4 *
5 * Licensed under the GNU Lesser General Public License Version 2.1
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library 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 GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * SECTION:pk-source
24 * @short_description: Source object
25 *
26 * This GObject holds details about the source of the transaction object, and
27 * are therefore shared properties that all data objects have.
28 */
29
30 #include "config.h"
31
32 #include <glib-object.h>
33
34 #include <packagekit-glib2/pk-source.h>
35 #include <packagekit-glib2/pk-enum.h>
36 #include <packagekit-glib2/pk-enum-types.h>
37
38 static void pk_source_finalize (GObject *object);
39
40 /**
41 * PkSourcePrivate:
42 *
43 * Private #PkSource data
44 **/
45 struct _PkSourcePrivate
46 {
47 PkRoleEnum role;
48 gchar *transaction_id;
49 };
50
51 enum {
52 PROP_0,
53 PROP_ROLE,
54 PROP_TRANSACTION_ID,
55 PROP_LAST
56 };
57
58 G_DEFINE_TYPE_WITH_PRIVATE (PkSource, pk_source, G_TYPE_OBJECT)
59 #define GET_PRIVATE(o) (pk_source_get_instance_private (o))
60
61 /*
62 * pk_source_get_property:
63 **/
64 static void
65 pk_source_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
66 {
67 PkSource *source = PK_SOURCE (object);
68 PkSourcePrivate *priv = GET_PRIVATE(source);
69
70 switch (prop_id) {
71 case PROP_ROLE:
72 g_value_set_enum (value, priv->role);
73 break;
74 case PROP_TRANSACTION_ID:
75 g_value_set_string (value, priv->transaction_id);
76 break;
77 default:
78 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
79 break;
80 }
81 }
82
83 /*
84 * pk_source_set_property:
85 **/
86 static void
87 pk_source_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
88 {
89 PkSource *source = PK_SOURCE (object);
90 PkSourcePrivate *priv = GET_PRIVATE(source);
91
92 switch (prop_id) {
93 case PROP_ROLE:
94 priv->role = g_value_get_enum (value);
95 break;
96 case PROP_TRANSACTION_ID:
97 g_free (priv->transaction_id);
98 priv->transaction_id = g_value_dup_string (value);
99 break;
100 default:
101 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
102 break;
103 }
104 }
105
106 /*
107 * pk_source_class_init:
108 **/
109 static void
110 pk_source_class_init (PkSourceClass *klass)
111 {
112 GParamSpec *pspec;
113 GObjectClass *object_class = G_OBJECT_CLASS (klass);
114 object_class->finalize = pk_source_finalize;
115 object_class->get_property = pk_source_get_property;
116 object_class->set_property = pk_source_set_property;
117
118 /**
119 * PkSource:role:
120 *
121 * Since: 0.6.0
122 */
123 pspec = g_param_spec_enum ("role", NULL, NULL,
124 PK_TYPE_ROLE_ENUM, PK_ROLE_ENUM_UNKNOWN,
125 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
126 g_object_class_install_property (object_class, PROP_ROLE, pspec);
127
128 /**
129 * PkSource:transaction-id:
130 *
131 * Since: 0.6.0
132 */
133 pspec = g_param_spec_string ("transaction-id", NULL, NULL,
134 NULL,
135 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
136 g_object_class_install_property (object_class, PROP_TRANSACTION_ID, pspec);
137 }
138
139 /*
140 * pk_source_init:
141 **/
142 static void
143 pk_source_init (PkSource *source)
144 {
145 source->priv = GET_PRIVATE(source);
146 }
147
148 /*
149 * pk_source_finalize:
150 **/
151 static void
152 pk_source_finalize (GObject *object)
153 {
154 PkSource *source = PK_SOURCE (object);
155 PkSourcePrivate *priv = GET_PRIVATE(source);
156
157 g_clear_pointer (&priv->transaction_id, g_free);
158
159 G_OBJECT_CLASS (pk_source_parent_class)->finalize (object);
160 }
161
162 /**
163 * pk_source_new:
164 *
165 * Return value: a new #PkSource object.
166 *
167 * Since: 0.6.0
168 **/
169 PkSource *
170 pk_source_new (void)
171 {
172 PkSource *source;
173 source = g_object_new (PK_TYPE_SOURCE, NULL);
174 return PK_SOURCE (source);
175 }