Debian Codegraph @

lib/packagekit-glib2/pk-transaction-past.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-transaction-past
24 * @short_description: TransactionPast object
25 *
26 * This GObject represents a transaction_past from a transaction_past.
27 * These objects represent single items of data from the transaction, and are
28 * often present in lists (#PkResults) or just refcounted in client programs.
29 */
30
31 #include "config.h"
32
33 #include <glib-object.h>
34
35 #include <packagekit-glib2/pk-transaction-past.h>
36 #include <packagekit-glib2/pk-common.h>
37 #include <packagekit-glib2/pk-enum.h>
38 #include <packagekit-glib2/pk-enum-types.h>
39
40 static void pk_transaction_past_finalize (GObject *object);
41
42 /**
43 * PkTransactionPastPrivate:
44 *
45 * Private #PkTransactionPast data
46 **/
47 struct _PkTransactionPastPrivate
48 {
49 gchar *tid;
50 gchar *timespec;
51 gboolean succeeded;
52 PkRoleEnum role;
53 guint duration; /* ms */
54 gchar *data;
55 guint uid;
56 gchar *cmdline;
57 };
58
59 enum {
60 PROP_0,
61 PROP_TID,
62 PROP_TIMESPEC,
63 PROP_SUCCEEDED,
64 PROP_ROLE,
65 PROP_DURATION,
66 PROP_DATA,
67 PROP_UID,
68 PROP_CMDLINE,
69 PROP_LAST
70 };
71
72 G_DEFINE_TYPE_WITH_PRIVATE (PkTransactionPast, pk_transaction_past, PK_TYPE_SOURCE)
73 #define GET_PRIVATE(o) (pk_transaction_past_get_instance_private (o))
74
75 /**
76 * pk_transaction_past_get_id:
77 * @past: a valid #PkTransactionPast instance
78 *
79 * Gets the past transaction ID value;
80 *
81 * Return value: The transaction data
82 *
83 * Since: 0.8.11
84 **/
85 const gchar *
86 pk_transaction_past_get_id (PkTransactionPast *past)
87 {
88 PkTransactionPastPrivate *priv = GET_PRIVATE(past);
89
90 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), NULL);
91
92 return priv->tid;
93 }
94
95 /**
96 * pk_transaction_past_get_timespec:
97 * @past: a valid #PkTransactionPast instance
98 *
99 * Gets the past transaction timespec value;
100 *
101 * Return value: The transaction data
102 *
103 * Since: 0.8.11
104 **/
105 const gchar *
106 pk_transaction_past_get_timespec (PkTransactionPast *past)
107 {
108 PkTransactionPastPrivate *priv = GET_PRIVATE(past);
109
110 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), NULL);
111
112 return priv->timespec;
113 }
114
115 /**
116 * pk_transaction_past_get_datetime:
117 * @past: a valid #PkTransactionPast instance
118 *
119 * Gets the past transaction date & time value;
120 *
121 * Return value: The transaction data, or %NULL if it's not available
122 *
123 * Since: 0.8.11
124 **/
125 GDateTime *
126 pk_transaction_past_get_datetime (PkTransactionPast *past)
127 {
128 PkTransactionPastPrivate *priv = GET_PRIVATE(past);
129
130 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), NULL);
131
132 if (priv->timespec == NULL)
133 return NULL;
134
135 return pk_iso8601_to_datetime (priv->timespec);
136 }
137
138 /**
139 * pk_transaction_past_get_timestamp:
140 * @past: a valid #PkTransactionPast instance
141 *
142 * Gets the past transaction timestamp
143 *
144 * Return value: The transaction data, or 0 if it's not available
145 *
146 * Since: 0.8.11
147 **/
148 gint64
149 pk_transaction_past_get_timestamp (PkTransactionPast *past)
150 {
151 GDateTime *datetime;
152 gint64 timestamp;
153
154 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), 0);
155
156 datetime = pk_transaction_past_get_datetime (past);
157 if (datetime == NULL)
158 return 0;
159 timestamp = g_date_time_to_unix (datetime);
160 g_date_time_unref (datetime);
161 return timestamp;
162 }
163
164 /**
165 * pk_transaction_past_get_succeeded:
166 * @past: a valid #PkTransactionPast instance
167 *
168 * Gets the past transaction succeeded value;
169 *
170 * Return value: The transaction data
171 *
172 * Since: 0.8.11
173 **/
174 gboolean
175 pk_transaction_past_get_succeeded (PkTransactionPast *past)
176 {
177 PkTransactionPastPrivate *priv = GET_PRIVATE(past);
178
179 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), FALSE);
180
181 return priv->succeeded;
182 }
183
184 /**
185 * pk_transaction_past_get_role:
186 * @past: a valid #PkTransactionPast instance
187 *
188 * Gets the past transaction role;
189 *
190 * Return value: The transaction data
191 *
192 * Since: 0.8.11
193 **/
194 PkRoleEnum
195 pk_transaction_past_get_role (PkTransactionPast *past)
196 {
197 PkTransactionPastPrivate *priv = GET_PRIVATE(past);
198
199 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), PK_ROLE_ENUM_UNKNOWN);
200
201 return priv->role;
202 }
203
204 /**
205 * pk_transaction_past_get_duration:
206 * @past: a valid #PkTransactionPast instance
207 *
208 * Gets the past transaction duration;
209 *
210 * Return value: The transaction duration in ms
211 *
212 * Since: 0.8.11
213 **/
214 guint
215 pk_transaction_past_get_duration (PkTransactionPast *past)
216 {
217 PkTransactionPastPrivate *priv = GET_PRIVATE(past);
218
219 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), 0);
220
221 return priv->duration;
222 }
223
224 /**
225 * pk_transaction_past_get_data:
226 * @past: a valid #PkTransactionPast instance
227 *
228 * Gets the past transaction data;
229 *
230 * Return value: The transaction data
231 *
232 * Since: 0.8.11
233 **/
234 const gchar *
235 pk_transaction_past_get_data (PkTransactionPast *past)
236 {
237 PkTransactionPastPrivate *priv = GET_PRIVATE(past);
238
239 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), NULL);
240 return priv->data;
241 }
242
243 /**
244 * pk_transaction_past_get_uid:
245 * @past: a valid #PkTransactionPast instance
246 *
247 * Gets the past transaction uid;
248 *
249 * Return value: The transaction data
250 *
251 * Since: 0.8.11
252 **/
253 guint
254 pk_transaction_past_get_uid (PkTransactionPast *past)
255 {
256 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), 0);
257 return past->priv->uid;
258 }
259
260 /**
261 * pk_transaction_past_get_cmdline:
262 * @past: a valid #PkTransactionPast instance
263 *
264 * Gets the past transaction cmdline value;
265 *
266 * Return value: The transaction data
267 *
268 * Since: 0.8.11
269 **/
270 const gchar *
271 pk_transaction_past_get_cmdline (PkTransactionPast *past)
272 {
273 g_return_val_if_fail (PK_IS_TRANSACTION_PAST (past), NULL);
274 return past->priv->cmdline;
275 }
276
277 /*
278 * pk_transaction_past_get_property:
279 **/
280 static void
281 pk_transaction_past_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
282 {
283 PkTransactionPast *transaction_past = PK_TRANSACTION_PAST (object);
284 PkTransactionPastPrivate *priv = transaction_past->priv;
285
286 switch (prop_id) {
287 case PROP_TID:
288 g_value_set_string (value, priv->tid);
289 break;
290 case PROP_TIMESPEC:
291 g_value_set_string (value, priv->timespec);
292 break;
293 case PROP_SUCCEEDED:
294 g_value_set_boolean (value, priv->succeeded);
295 break;
296 case PROP_ROLE:
297 g_value_set_enum (value, priv->role);
298 break;
299 case PROP_DURATION:
300 g_value_set_uint (value, priv->duration);
301 break;
302 case PROP_DATA:
303 g_value_set_string (value, priv->data);
304 break;
305 case PROP_UID:
306 g_value_set_uint (value, priv->uid);
307 break;
308 case PROP_CMDLINE:
309 g_value_set_string (value, priv->cmdline);
310 break;
311 default:
312 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
313 break;
314 }
315 }
316
317 /*
318 * pk_transaction_past_set_property:
319 **/
320 static void
321 pk_transaction_past_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
322 {
323 PkTransactionPast *transaction_past = PK_TRANSACTION_PAST (object);
324 PkTransactionPastPrivate *priv = GET_PRIVATE(transaction_past);
325
326 switch (prop_id) {
327 case PROP_TID:
328 g_free (priv->tid);
329 priv->tid = g_value_dup_string (value);
330 break;
331 case PROP_TIMESPEC:
332 g_free (priv->timespec);
333 priv->timespec = g_value_dup_string (value);
334 break;
335 case PROP_SUCCEEDED:
336 priv->succeeded = g_value_get_boolean (value);
337 break;
338 case PROP_ROLE:
339 priv->role = g_value_get_enum (value);
340 break;
341 case PROP_DURATION:
342 priv->duration = g_value_get_uint (value);
343 break;
344 case PROP_DATA:
345 g_free (priv->data);
346 priv->data = g_value_dup_string (value);
347 break;
348 case PROP_UID:
349 priv->uid = g_value_get_uint (value);
350 break;
351 case PROP_CMDLINE:
352 g_free (priv->cmdline);
353 priv->cmdline = g_value_dup_string (value);
354 break;
355 default:
356 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
357 break;
358 }
359 }
360
361 /*
362 * pk_transaction_past_class_init:
363 **/
364 static void
365 pk_transaction_past_class_init (PkTransactionPastClass *klass)
366 {
367 GParamSpec *pspec;
368 GObjectClass *object_class = G_OBJECT_CLASS (klass);
369 object_class->finalize = pk_transaction_past_finalize;
370 object_class->get_property = pk_transaction_past_get_property;
371 object_class->set_property = pk_transaction_past_set_property;
372
373 /**
374 * PkTransactionPast:tid:
375 *
376 * Since: 0.5.4
377 */
378 pspec = g_param_spec_string ("tid", NULL, NULL,
379 NULL,
380 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
381 g_object_class_install_property (object_class, PROP_TID, pspec);
382
383 /**
384 * PkTransactionPast:timespec:
385 *
386 * Since: 0.5.4
387 */
388 pspec = g_param_spec_string ("timespec", NULL, NULL,
389 NULL,
390 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
391 g_object_class_install_property (object_class, PROP_TIMESPEC, pspec);
392
393 /**
394 * PkTransactionPast:succeeded:
395 *
396 * Since: 0.5.4
397 */
398 pspec = g_param_spec_boolean ("succeeded", NULL, NULL,
399 FALSE,
400 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
401 g_object_class_install_property (object_class, PROP_SUCCEEDED, pspec);
402
403 /**
404 * PkTransactionPast:role:
405 *
406 * Since: 0.5.4
407 */
408 pspec = g_param_spec_enum ("role", NULL, NULL,
409 PK_TYPE_ROLE_ENUM, PK_ROLE_ENUM_UNKNOWN,
410 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
411 g_object_class_install_property (object_class, PROP_ROLE, pspec);
412
413 /**
414 * PkTransactionPast:duration:
415 *
416 * Since: 0.5.4
417 */
418 pspec = g_param_spec_uint ("duration", NULL, NULL,
419 0, G_MAXUINT, 0,
420 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
421 g_object_class_install_property (object_class, PROP_DURATION, pspec);
422
423 /**
424 * PkTransactionPast:data:
425 *
426 * Since: 0.5.4
427 */
428 pspec = g_param_spec_string ("data", NULL, NULL,
429 NULL,
430 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
431 g_object_class_install_property (object_class, PROP_DATA, pspec);
432
433 /**
434 * PkTransactionPast:uid:
435 *
436 * Since: 0.5.4
437 */
438 pspec = g_param_spec_uint ("uid", NULL, NULL,
439 0, G_MAXUINT, G_MAXUINT,
440 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
441 g_object_class_install_property (object_class, PROP_UID, pspec);
442
443 /**
444 * PkTransactionPast:cmdline:
445 *
446 * Since: 0.5.4
447 */
448 pspec = g_param_spec_string ("cmdline", NULL, NULL,
449 NULL,
450 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
451 g_object_class_install_property (object_class, PROP_CMDLINE, pspec);
452 }
453
454 /*
455 * pk_transaction_past_init:
456 **/
457 static void
458 pk_transaction_past_init (PkTransactionPast *transaction_past)
459 {
460 transaction_past->priv = GET_PRIVATE(transaction_past);
461 }
462
463 /*
464 * pk_transaction_past_finalize:
465 **/
466 static void
467 pk_transaction_past_finalize (GObject *object)
468 {
469 PkTransactionPast *transaction_past = PK_TRANSACTION_PAST (object);
470 PkTransactionPastPrivate *priv = GET_PRIVATE(transaction_past);
471
472 g_clear_pointer (&priv->tid, g_free);
473 g_clear_pointer (&priv->timespec, g_free);
474 g_clear_pointer (&priv->data, g_free);
475 g_clear_pointer (&priv->cmdline, g_free);
476
477 G_OBJECT_CLASS (pk_transaction_past_parent_class)->finalize (object);
478 }
479
480 /**
481 * pk_transaction_past_new:
482 *
483 * Return value: a new #PkTransactionPast object.
484 *
485 * Since: 0.5.4
486 **/
487 PkTransactionPast *
488 pk_transaction_past_new (void)
489 {
490 PkTransactionPast *transaction_past;
491 transaction_past = g_object_new (PK_TYPE_TRANSACTION_PAST, NULL);
492 return PK_TRANSACTION_PAST (transaction_past);
493 }