Debian Codegraph @

lib/packagekit-glib2/pk-results.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-results
24 * @short_description: Transaction results
25 *
26 * This GObject allows a client program to query the results sent from
27 * PackageKit. This will include Package(), ErrorCode() and all the other types
28 * of objects. Everything is refcounted, so ensure you unref when done with the
29 * data.
30 */
31
32 #include "config.h"
33
34 #include <glib-object.h>
35
36 #include <packagekit-glib2/pk-results.h>
37 #include <packagekit-glib2/pk-enum.h>
38 #include <packagekit-glib2/pk-enum-types.h>
39
40 static void pk_results_finalize (GObject *object);
41
42 /**
43 * PkResultsPrivate:
44 *
45 * Private #PkResults data
46 **/
47 struct _PkResultsPrivate
48 {
49 PkRoleEnum role;
50 PkBitfield transaction_flags;
51 guint inputs;
52 PkProgress *progress;
53 PkExitEnum exit_enum;
54 PkError *error_code;
55 GPtrArray *details_array;
56 GPtrArray *update_detail_array;
57 GPtrArray *category_array;
58 GPtrArray *distro_upgrade_array;
59 GPtrArray *require_restart_array;
60 GPtrArray *transaction_array;
61 GPtrArray *files_array;
62 GPtrArray *repo_signature_required_array;
63 GPtrArray *eula_required_array;
64 GPtrArray *media_change_required_array;
65 GPtrArray *repo_detail_array;
66 PkPackageSack *package_sack;
67 };
68
69 enum {
70 PROP_0,
71 PROP_ROLE,
72 PROP_TRANSACTION_FLAGS,
73 PROP_INPUTS,
74 PROP_PROGRESS,
75 PROP_LAST
76 };
77
78 G_DEFINE_TYPE_WITH_PRIVATE (PkResults, pk_results, G_TYPE_OBJECT)
79 #define GET_PRIVATE(o) (pk_results_get_instance_private (o))
80
81 /*
82 * pk_results_get_property:
83 **/
84 static void
85 pk_results_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
86 {
87 PkResults *results = PK_RESULTS (object);
88 PkResultsPrivate *priv = GET_PRIVATE(results);
89
90 switch (prop_id) {
91 case PROP_ROLE:
92 g_value_set_enum (value, priv->role);
93 break;
94 case PROP_TRANSACTION_FLAGS:
95 g_value_set_uint64 (value, priv->transaction_flags);
96 break;
97 case PROP_INPUTS:
98 g_value_set_uint (value, priv->inputs);
99 break;
100 case PROP_PROGRESS:
101 g_value_set_object (value, priv->progress);
102 break;
103 default:
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
105 break;
106 }
107 }
108
109 /*
110 * pk_results_set_property:
111 **/
112 static void
113 pk_results_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
114 {
115 PkResults *results = PK_RESULTS (object);
116 PkResultsPrivate *priv = GET_PRIVATE(results);
117
118 switch (prop_id) {
119 case PROP_ROLE:
120 priv->role = g_value_get_enum (value);
121 break;
122 case PROP_TRANSACTION_FLAGS:
123 priv->transaction_flags = g_value_get_uint64 (value);
124 break;
125 case PROP_INPUTS:
126 priv->inputs = g_value_get_uint (value);
127 break;
128 case PROP_PROGRESS:
129 g_set_object (&priv->progress, g_value_get_object (value));
130 break;
131 default:
132 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
133 break;
134 }
135 }
136
137 /**
138 * pk_results_set_role:
139 * @results: a valid #PkResults instance
140 * @role: the role enum
141 *
142 * Sets the results object to have the given role enum.
143 *
144 * Return value: %TRUE if the value was set
145 *
146 * Since: 1.1.8
147 **/
148 gboolean
149 pk_results_set_role (PkResults *results, PkRoleEnum role)
150 {
151 PkResultsPrivate *priv = GET_PRIVATE(results);
152
153 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
154 g_return_val_if_fail (role != PK_ROLE_ENUM_UNKNOWN, FALSE);
155
156 if (priv->role != role) {
157 priv->role = role;
158 return TRUE;
159 }
160
161 return FALSE;
162 }
163
164 /**
165 * pk_results_set_exit_code:
166 * @results: a valid #PkResults instance
167 * @exit_enum: the exit code
168 *
169 * Sets the results object to have the given exit code.
170 *
171 * Return value: %TRUE if the value was set
172 *
173 * Since: 0.5.2
174 **/
175 gboolean
176 pk_results_set_exit_code (PkResults *results, PkExitEnum exit_enum)
177 {
178 PkResultsPrivate *priv = GET_PRIVATE(results);
179
180 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
181 g_return_val_if_fail (exit_enum != PK_EXIT_ENUM_UNKNOWN, FALSE);
182
183 if (priv->exit_enum != exit_enum) {
184 priv->exit_enum = exit_enum;
185 return TRUE;
186 }
187
188 return FALSE;
189 }
190
191 /**
192 * pk_results_add_package:
193 * @results: a valid #PkResults instance
194 * @item: the object to add to the array
195 *
196 * Adds a package to the results set.
197 *
198 * Return value: %TRUE if the value was set
199 *
200 * Since: 0.5.3
201 **/
202 gboolean
203 pk_results_add_package (PkResults *results, PkPackage *item)
204 {
205 PkResultsPrivate *priv = GET_PRIVATE(results);
206
207 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
208 g_return_val_if_fail (item != NULL, FALSE);
209
210 /* do not allow finished types */
211 if (pk_package_get_info (item) == PK_INFO_ENUM_FINISHED) {
212 g_warning ("Finished packages cannot be added to PkResults");
213 return FALSE;
214 }
215
216 pk_package_sack_add_package (priv->package_sack, item);
217 return TRUE;
218 }
219
220 /**
221 * pk_results_add_details:
222 * @results: a valid #PkResults instance
223 * @item: the object to add to the array
224 *
225 * Adds some package details to the results set.
226 *
227 * Return value: %TRUE if the value was set
228 *
229 * Since: 0.5.2
230 **/
231 gboolean
232 pk_results_add_details (PkResults *results, PkDetails *item)
233 {
234 PkResultsPrivate *priv = GET_PRIVATE(results);
235
236 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
237 g_return_val_if_fail (item != NULL, FALSE);
238
239 /* copy and add to array */
240 g_ptr_array_add (priv->details_array, g_object_ref (item));
241
242 return TRUE;
243 }
244
245 /**
246 * pk_results_add_update_detail:
247 * @results: a valid #PkResults instance
248 * @item: the object to add to the array
249 *
250 * Adds some update details to the results set.
251 *
252 * Return value: %TRUE if the value was set
253 *
254 * Since: 0.5.2
255 **/
256 gboolean
257 pk_results_add_update_detail (PkResults *results, PkUpdateDetail *item)
258 {
259 PkResultsPrivate *priv = GET_PRIVATE(results);
260
261 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
262 g_return_val_if_fail (item != NULL, FALSE);
263
264 /* copy and add to array */
265 g_ptr_array_add (priv->update_detail_array, g_object_ref (item));
266
267 return TRUE;
268 }
269
270 /**
271 * pk_results_add_category:
272 * @results: a valid #PkResults instance
273 * @item: the object to add to the array
274 *
275 * Adds a category item to the results set.
276 *
277 * Return value: %TRUE if the value was set
278 *
279 * Since: 0.5.2
280 **/
281 gboolean
282 pk_results_add_category (PkResults *results, PkCategory *item)
283 {
284 PkResultsPrivate *priv = GET_PRIVATE(results);
285
286 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
287 g_return_val_if_fail (item != NULL, FALSE);
288
289 /* copy and add to array */
290 g_ptr_array_add (priv->category_array, g_object_ref (item));
291
292 return TRUE;
293 }
294
295 /**
296 * pk_results_add_distro_upgrade:
297 * @results: a valid #PkResults instance
298 * @item: the object to add to the array
299 *
300 * Adds a distribution upgrade item to the results set.
301 *
302 * Return value: %TRUE if the value was set
303 *
304 * Since: 0.5.2
305 **/
306 gboolean
307 pk_results_add_distro_upgrade (PkResults *results, PkDistroUpgrade *item)
308 {
309 PkResultsPrivate *priv = GET_PRIVATE(results);
310
311 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
312 g_return_val_if_fail (item != NULL, FALSE);
313
314 /* copy and add to array */
315 g_ptr_array_add (priv->distro_upgrade_array, g_object_ref (item));
316
317 return TRUE;
318 }
319
320 /**
321 * pk_results_add_require_restart:
322 * @results: a valid #PkResults instance
323 * @item: the object to add to the array
324 *
325 * Adds a require restart item to the results set.
326 *
327 * Return value: %TRUE if the value was set
328 *
329 * Since: 0.5.2
330 **/
331 gboolean
332 pk_results_add_require_restart (PkResults *results, PkRequireRestart *item)
333 {
334 PkResultsPrivate *priv = GET_PRIVATE(results);
335
336 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
337 g_return_val_if_fail (item != NULL, FALSE);
338
339 /* copy and add to array */
340 g_ptr_array_add (priv->require_restart_array, g_object_ref (item));
341
342 return TRUE;
343 }
344
345 /**
346 * pk_results_add_transaction:
347 * @results: a valid #PkResults instance
348 * @item: the object to add to the array
349 *
350 * Adds a transaction item to the results set.
351 *
352 * Return value: %TRUE if the value was set
353 *
354 * Since: 0.5.2
355 **/
356 gboolean
357 pk_results_add_transaction (PkResults *results, PkTransactionPast *item)
358 {
359 PkResultsPrivate *priv = GET_PRIVATE(results);
360
361 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
362 g_return_val_if_fail (item != NULL, FALSE);
363
364 /* copy and add to array */
365 g_ptr_array_add (priv->transaction_array, g_object_ref (item));
366
367 return TRUE;
368 }
369
370 /**
371 * pk_results_add_files:
372 * @results: a valid #PkResults instance
373 * @item: the object to add to the array
374 *
375 * Adds some files details to the results set.
376 *
377 * Return value: %TRUE if the value was set
378 *
379 * Since: 0.5.2
380 **/
381 gboolean
382 pk_results_add_files (PkResults *results, PkFiles *item)
383 {
384 PkResultsPrivate *priv = GET_PRIVATE(results);
385
386 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
387 g_return_val_if_fail (item != NULL, FALSE);
388
389 /* copy and add to array */
390 g_ptr_array_add (priv->files_array, g_object_ref (item));
391
392 return TRUE;
393 }
394
395 /**
396 * pk_results_add_repo_signature_required:
397 * @results: a valid #PkResults instance
398 * @item: the object to add to the array
399 *
400 * Adds some repository signature details to the results set.
401 *
402 * Return value: %TRUE if the value was set
403 *
404 * Since: 0.5.2
405 **/
406 gboolean
407 pk_results_add_repo_signature_required (PkResults *results, PkRepoSignatureRequired *item)
408 {
409 PkResultsPrivate *priv = GET_PRIVATE(results);
410
411 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
412 g_return_val_if_fail (item != NULL, FALSE);
413
414 /* copy and add to array */
415 g_ptr_array_add (priv->repo_signature_required_array, g_object_ref (item));
416
417 return TRUE;
418 }
419
420 /**
421 * pk_results_add_eula_required:
422 * @results: a valid #PkResults instance
423 * @item: the object to add to the array
424 *
425 * Adds some EULA details to the results set.
426 *
427 * Return value: %TRUE if the value was set
428 *
429 * Since: 0.5.2
430 **/
431 gboolean
432 pk_results_add_eula_required (PkResults *results, PkEulaRequired *item)
433 {
434 PkResultsPrivate *priv = GET_PRIVATE(results);
435
436 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
437 g_return_val_if_fail (item != NULL, FALSE);
438
439 /* copy and add to array */
440 g_ptr_array_add (priv->eula_required_array, g_object_ref (item));
441
442 return TRUE;
443 }
444
445 /**
446 * pk_results_add_media_change_required:
447 * @results: a valid #PkResults instance
448 * @item: the object to add to the array
449 *
450 * Adds some media change details to the results set.
451 *
452 * Return value: %TRUE if the value was set
453 *
454 * Since: 0.5.2
455 **/
456 gboolean
457 pk_results_add_media_change_required (PkResults *results, PkMediaChangeRequired *item)
458 {
459 PkResultsPrivate *priv = GET_PRIVATE(results);
460
461 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
462 g_return_val_if_fail (item != NULL, FALSE);
463
464 /* copy and add to array */
465 g_ptr_array_add (priv->media_change_required_array, g_object_ref (item));
466
467 return TRUE;
468 }
469
470 /**
471 * pk_results_add_repo_detail:
472 * @results: a valid #PkResults instance
473 * @item: the object to add to the array
474 *
475 * Adds some repository details to the results set.
476 *
477 * Return value: %TRUE if the value was set
478 *
479 * Since: 0.5.2
480 **/
481 gboolean
482 pk_results_add_repo_detail (PkResults *results, PkRepoDetail *item)
483 {
484 PkResultsPrivate *priv = GET_PRIVATE(results);
485
486 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
487 g_return_val_if_fail (item != NULL, FALSE);
488
489 /* copy and add to array */
490 g_ptr_array_add (priv->repo_detail_array, g_object_ref (item));
491
492 return TRUE;
493 }
494
495 /**
496 * pk_results_set_error_code:
497 * @results: a valid #PkResults instance
498 * @item: the object to add to the array
499 *
500 * Adds some error details to the results set.
501 *
502 * Return value: %TRUE if the value was set
503 *
504 * Since: 0.5.2
505 **/
506 gboolean
507 pk_results_set_error_code (PkResults *results, PkError *item)
508 {
509 PkResultsPrivate *priv = GET_PRIVATE(results);
510
511 g_return_val_if_fail (PK_IS_RESULTS (results), FALSE);
512 g_return_val_if_fail (item != NULL, FALSE);
513
514 g_set_object (&priv->error_code, item);
515 return TRUE;
516 }
517
518 /**
519 * pk_results_get_exit_code:
520 * @results: a valid #PkResults instance
521 *
522 * Gets the exit enum. You probably don't want to be using this function, and
523 * instead using the much more useful pk_results_get_error_code() function.
524 *
525 * Return value: The #PkExitEnum or %PK_EXIT_ENUM_UNKNOWN for error or if it was not set
526 *
527 * Since: 0.5.2
528 **/
529 PkExitEnum
530 pk_results_get_exit_code (PkResults *results)
531 {
532 PkResultsPrivate *priv = GET_PRIVATE(results);
533
534 g_return_val_if_fail (PK_IS_RESULTS (results), PK_EXIT_ENUM_UNKNOWN);
535
536 return priv->exit_enum;
537 }
538
539 /**
540 * pk_results_get_role:
541 * @results: a valid #PkResults instance
542 *
543 * Gets the role that produced these results.
544 *
545 * Return value: The #PkRoleEnum or %PK_ROLE_ENUM_UNKNOWN if not set
546 *
547 * Since: 0.7.5
548 **/
549 PkRoleEnum
550 pk_results_get_role (PkResults *results)
551 {
552 PkResultsPrivate *priv = GET_PRIVATE(results);
553
554 g_return_val_if_fail (PK_IS_RESULTS (results), PK_ROLE_ENUM_UNKNOWN);
555
556 return priv->role;
557 }
558
559 /**
560 * pk_results_get_transaction_flags:
561 * @results: a valid #PkResults instance
562 *
563 * Gets the transaction flag for these results.
564 *
565 * Return value: a #PkBitfield containing #PkTransactionFlagEnum 0 if not set
566 *
567 * Since: 0.8.1
568 **/
569 PkBitfield
570 pk_results_get_transaction_flags (PkResults *results)
571 {
572 PkResultsPrivate *priv = GET_PRIVATE(results);
573
574 g_return_val_if_fail (PK_IS_RESULTS (results), 0);
575
576 return priv->transaction_flags;
577 }
578
579 /**
580 * pk_results_get_error_code:
581 * @results: a valid #PkResults instance
582 *
583 * Gets the last error code from the transaction.
584 *
585 * Return value: (transfer full): A #PkError, or %NULL, free with g_object_unref()
586 *
587 * Since: 0.5.2
588 **/
589 PkError *
590 pk_results_get_error_code (PkResults *results)
591 {
592 PkResultsPrivate *priv = GET_PRIVATE(results);
593
594 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
595
596 /* failed, but no exit code? */
597 if (priv->error_code == NULL && priv->exit_enum != PK_EXIT_ENUM_SUCCESS) {
598 g_warning ("internal error: failed, but no error code: %s",
599 pk_exit_enum_to_string (priv->exit_enum));
600 return NULL;
601 }
602
603 if (priv->error_code == NULL)
604 return NULL;
605
606 return g_object_ref (priv->error_code);
607 }
608
609 /**
610 * pk_results_get_package_array:
611 * @results: a valid #PkResults instance
612 *
613 * Gets the packages from the transaction.
614 *
615 * Return value: (element-type PkPackage) (transfer container): A #GPtrArray array of #PkPackage's, free with g_ptr_array_unref().
616 *
617 * Since: 0.5.2
618 **/
619 GPtrArray *
620 pk_results_get_package_array (PkResults *results)
621 {
622 PkResultsPrivate *priv = GET_PRIVATE(results);
623
624 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
625
626 return pk_package_sack_get_array (priv->package_sack);
627 }
628
629 /**
630 * pk_results_get_package_sack:
631 * @results: a valid #PkResults instance
632 *
633 * Gets a package sack from the transaction.
634 *
635 * Return value: (transfer full): A #PkPackageSack of data, g_object_unref() to free.
636 *
637 * Since: 0.5.2
638 **/
639 PkPackageSack *
640 pk_results_get_package_sack (PkResults *results)
641 {
642 PkResultsPrivate *priv = GET_PRIVATE(results);
643
644 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
645
646 return g_object_ref (priv->package_sack);
647 }
648
649 /**
650 * pk_results_get_details_array:
651 * @results: a valid #PkResults instance
652 *
653 * Gets the package details from the transaction.
654 *
655 * Return value: (element-type PkDetails) (transfer container): A #GPtrArray array of #PkDetails's, free with g_ptr_array_unref().
656 *
657 * Since: 0.5.2
658 **/
659 GPtrArray *
660 pk_results_get_details_array (PkResults *results)
661 {
662 PkResultsPrivate *priv = GET_PRIVATE(results);
663
664 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
665
666 return g_ptr_array_ref (priv->details_array);
667 }
668
669 /**
670 * pk_results_get_update_detail_array:
671 * @results: a valid #PkResults instance
672 *
673 * Gets the update details from the transaction.
674 *
675 * Return value: (element-type PkUpdateDetail) (transfer container): A #GPtrArray array of #PkUpdateDetail's, free with g_ptr_array_unref().
676 *
677 * Since: 0.5.2
678 **/
679 GPtrArray *
680 pk_results_get_update_detail_array (PkResults *results)
681 {
682 PkResultsPrivate *priv = GET_PRIVATE(results);
683
684 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
685
686 return g_ptr_array_ref (priv->update_detail_array);
687 }
688
689 /**
690 * pk_results_get_category_array:
691 * @results: a valid #PkResults instance
692 *
693 * Gets the categories from the transaction.
694 *
695 * Return value: (element-type PkCategory) (transfer container): A #GPtrArray array of #PkCategory's, free with g_ptr_array_unref().
696 *
697 * Since: 0.5.2
698 **/
699 GPtrArray *
700 pk_results_get_category_array (PkResults *results)
701 {
702 PkResultsPrivate *priv = GET_PRIVATE(results);
703
704 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
705
706 return g_ptr_array_ref (priv->category_array);
707 }
708
709 /**
710 * pk_results_get_distro_upgrade_array:
711 * @results: a valid #PkResults instance
712 *
713 * Gets the distribution upgrades from the transaction.
714 *
715 * Return value: (element-type PkDistroUpgrade) (transfer container): A #GPtrArray array of #PkDistroUpgrade's, free with g_ptr_array_unref().
716 *
717 * Since: 0.5.2
718 **/
719 GPtrArray *
720 pk_results_get_distro_upgrade_array (PkResults *results)
721 {
722 PkResultsPrivate *priv = GET_PRIVATE(results);
723
724 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
725
726 return g_ptr_array_ref (priv->distro_upgrade_array);
727 }
728
729 /**
730 * pk_results_get_require_restart_array:
731 * @results: a valid #PkResults instance
732 *
733 * Gets the require restarts from the transaction.
734 *
735 * Return value: (element-type PkRequireRestart) (transfer container): A #GPtrArray array of #PkRequireRestart's, free with g_ptr_array_unref().
736 *
737 * Since: 0.5.2
738 **/
739 GPtrArray *
740 pk_results_get_require_restart_array (PkResults *results)
741 {
742 PkResultsPrivate *priv = GET_PRIVATE(results);
743
744 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
745
746 return g_ptr_array_ref (priv->require_restart_array);
747 }
748
749 /**
750 * pk_results_get_require_restart_worst:
751 * @results: a valid #PkResults instance
752 *
753 * This method returns the 'worst' restart of all the transactions.
754 * It is needed as multiple sub-transactions may emit require-restart with
755 * different values, and we always want to get the most invasive of all.
756 *
757 * For instance, if a transaction emits RequireRestart(system) and then
758 * RequireRestart(session) then pk_client_get_require_restart will return
759 * system as a session restart is implied with a system restart.
760 *
761 * Return value: a #PkRestartEnum value, e.g. PK_RESTART_ENUM_SYSTEM
762 *
763 * Since: 0.5.2
764 **/
765 PkRestartEnum
766 pk_results_get_require_restart_worst (PkResults *results)
767 {
768 PkResultsPrivate *priv = GET_PRIVATE(results);
769 GPtrArray *array;
770 PkRestartEnum worst = 0;
771 PkRestartEnum restart;
772 guint i;
773 PkRequireRestart *item;
774
775 g_return_val_if_fail (PK_IS_RESULTS (results), 0);
776
777 array = priv->require_restart_array;
778 for (i = 0; i < array->len; i++) {
779 item = g_ptr_array_index (array, i);
780 g_object_get (item,
781 "restart", &restart,
782 NULL);
783 if (restart > worst)
784 worst = restart;
785 }
786
787 return worst;
788 }
789
790 /**
791 * pk_results_get_transaction_array:
792 * @results: a valid #PkResults instance
793 *
794 * Gets the transactions from the transaction.
795 *
796 * Return value: (element-type PkTransactionPast) (transfer container): A #GPtrArray array of #PkTransactionPast's, free with g_ptr_array_unref().
797 *
798 * Since: 0.5.2
799 **/
800 GPtrArray *
801 pk_results_get_transaction_array (PkResults *results)
802 {
803 PkResultsPrivate *priv = GET_PRIVATE(results);
804
805 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
806
807 return g_ptr_array_ref (priv->transaction_array);
808 }
809
810 /**
811 * pk_results_get_files_array:
812 * @results: a valid #PkResults instance
813 *
814 * Gets the files from the transaction.
815 *
816 * Return value: (element-type PkFiles) (transfer container): A #GPtrArray array of #PkFiles's, free with g_ptr_array_unref().
817 *
818 * Since: 0.5.2
819 **/
820 GPtrArray *
821 pk_results_get_files_array (PkResults *results)
822 {
823 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
824 return g_ptr_array_ref (results->priv->files_array);
825 }
826
827 /**
828 * pk_results_get_repo_signature_required_array:
829 * @results: a valid #PkResults instance
830 *
831 * Gets the repository signatures required from the transaction.
832 *
833 * Return value: (element-type PkRepoSignatureRequired) (transfer container): A #GPtrArray array of #PkRepoSignatureRequired's, free with g_ptr_array_unref().
834 *
835 * Since: 0.5.2
836 **/
837 GPtrArray *
838 pk_results_get_repo_signature_required_array (PkResults *results)
839 {
840 PkResultsPrivate *priv = GET_PRIVATE(results);
841
842 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
843
844 return g_ptr_array_ref (priv->repo_signature_required_array);
845 }
846
847 /**
848 * pk_results_get_eula_required_array:
849 * @results: a valid #PkResults instance
850 *
851 * Gets the eulas required from the transaction.
852 *
853 * Return value: (element-type PkEulaRequired) (transfer container): A #GPtrArray array of #PkEulaRequired's, free with g_ptr_array_unref().
854 *
855 * Since: 0.5.2
856 **/
857 GPtrArray *
858 pk_results_get_eula_required_array (PkResults *results)
859 {
860 PkResultsPrivate *priv = GET_PRIVATE(results);
861
862 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
863
864 return g_ptr_array_ref (priv->eula_required_array);
865 }
866
867 /**
868 * pk_results_get_media_change_required_array:
869 * @results: a valid #PkResults instance
870 *
871 * Gets the media changes required from the transaction.
872 *
873 * Return value: (element-type PkMediaChangeRequired) (transfer container): A #GPtrArray array of #PkMediaChangeRequired's, free with g_ptr_array_unref().
874 *
875 * Since: 0.5.2
876 **/
877 GPtrArray *
878 pk_results_get_media_change_required_array (PkResults *results)
879 {
880 PkResultsPrivate *priv = GET_PRIVATE(results);
881
882 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
883
884 return g_ptr_array_ref (priv->media_change_required_array);
885 }
886
887 /**
888 * pk_results_get_repo_detail_array:
889 * @results: a valid #PkResults instance
890 *
891 * Gets the repository details from the transaction.
892 *
893 * Return value: (element-type PkRepoDetail) (transfer container): A #GPtrArray array of #PkRepoDetail's, free with g_ptr_array_unref().
894 *
895 * Since: 0.5.2
896 **/
897 GPtrArray *
898 pk_results_get_repo_detail_array (PkResults *results)
899 {
900 PkResultsPrivate *priv = GET_PRIVATE(results);
901
902 g_return_val_if_fail (PK_IS_RESULTS (results), NULL);
903
904 return g_ptr_array_ref (priv->repo_detail_array);
905 }
906
907 /*
908 * pk_results_class_init:
909 **/
910 static void
911 pk_results_class_init (PkResultsClass *klass)
912 {
913 GParamSpec *pspec;
914 GObjectClass *object_class = G_OBJECT_CLASS (klass);
915 object_class->finalize = pk_results_finalize;
916 object_class->get_property = pk_results_get_property;
917 object_class->set_property = pk_results_set_property;
918
919 /**
920 * PkResults:role:
921 *
922 * The #PkRoleEnum or %PK_ROLE_ENUM_UNKNOWN if not set
923 *
924 * Since: 0.5.2
925 */
926 pspec = g_param_spec_enum ("role", NULL, NULL,
927 PK_TYPE_ROLE_ENUM, PK_ROLE_ENUM_UNKNOWN,
928 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
929 g_object_class_install_property (object_class, PROP_ROLE, pspec);
930
931 /**
932 * PkResults:transaction-flags:
933 *
934 * A #PkBitfield containing #PkTransactionFlagEnum for this result.
935 *
936 * Since: 0.8.1
937 */
938 pspec = g_param_spec_uint64 ("transaction-flags", NULL, NULL,
939 0, G_MAXUINT64, 0,
940 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
941 g_object_class_install_property (object_class, PROP_TRANSACTION_FLAGS, pspec);
942
943 /**
944 * PkResults:inputs:
945 *
946 * Since: 0.5.3
947 */
948 pspec = g_param_spec_uint ("inputs", NULL, NULL,
949 0, G_MAXUINT, 0,
950 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
951 g_object_class_install_property (object_class, PROP_INPUTS, pspec);
952
953 /**
954 * PkResults:progress:
955 *
956 * Since: 0.5.3
957 */
958 pspec = g_param_spec_object ("progress", NULL,
959 "The progress instance",
960 PK_TYPE_PROGRESS,
961 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
962 g_object_class_install_property (object_class, PROP_PROGRESS, pspec);
963 }
964
965 /*
966 * pk_results_init:
967 **/
968 static void
969 pk_results_init (PkResults *results)
970 {
971 PkResultsPrivate *priv = GET_PRIVATE(results);
972
973 results->priv = priv;
974 priv->role = PK_ROLE_ENUM_UNKNOWN;
975 priv->exit_enum = PK_EXIT_ENUM_UNKNOWN;
976 priv->inputs = 0;
977 priv->progress = NULL;
978 priv->error_code = NULL;
979 priv->package_sack = pk_package_sack_new ();
980 priv->details_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
981 priv->update_detail_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
982 priv->category_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
983 priv->distro_upgrade_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
984 priv->require_restart_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
985 priv->transaction_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
986 priv->files_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
987 priv->repo_signature_required_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
988 priv->eula_required_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
989 priv->media_change_required_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
990 priv->repo_detail_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
991 }
992
993 /*
994 * pk_results_finalize:
995 **/
996 static void
997 pk_results_finalize (GObject *object)
998 {
999 PkResults *results = PK_RESULTS (object);
1000 PkResultsPrivate *priv = GET_PRIVATE(results);
1001
1002 g_clear_pointer (&priv->details_array, g_ptr_array_unref);
1003 g_clear_pointer (&priv->update_detail_array, g_ptr_array_unref);
1004 g_clear_pointer (&priv->category_array, g_ptr_array_unref);
1005 g_clear_pointer (&priv->distro_upgrade_array, g_ptr_array_unref);
1006 g_clear_pointer (&priv->require_restart_array, g_ptr_array_unref);
1007 g_clear_pointer (&priv->transaction_array, g_ptr_array_unref);
1008 g_clear_pointer (&priv->files_array, g_ptr_array_unref);
1009 g_clear_pointer (&priv->repo_signature_required_array, g_ptr_array_unref);
1010 g_clear_pointer (&priv->eula_required_array, g_ptr_array_unref);
1011 g_clear_pointer (&priv->media_change_required_array, g_ptr_array_unref);
1012 g_clear_pointer (&priv->repo_detail_array, g_ptr_array_unref);
1013 g_clear_object (&priv->package_sack);
1014 g_clear_object (&priv->progress);
1015 g_clear_object (&priv->error_code);
1016
1017 G_OBJECT_CLASS (pk_results_parent_class)->finalize (object);
1018 }
1019
1020 /**
1021 * pk_results_new:
1022 *
1023 * Return value: a new #PkResults object.
1024 *
1025 * Since: 0.5.2
1026 **/
1027 PkResults *
1028 pk_results_new (void)
1029 {
1030 PkResults *results;
1031 results = g_object_new (PK_TYPE_RESULTS, NULL);
1032 return PK_RESULTS (results);
1033 }