Debian Codegraph @

lib/packagekit-glib2/pk-client.c

raw
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * Copyright (C) 2008-2014 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-client
24 * @short_description: For creating new transactions
25 *
26 * A GObject to use for accessing PackageKit asynchronously. If you're
27 * using #PkClient to install, remove, or update packages, be prepared that
28 * the eula, gpg and trusted callbacks need to be rescheduled manually, as in
29 * https://www.freedesktop.org/software/PackageKit/gtk-doc/introduction-ideas-transactions.html
30 */
31
32 #include "config.h"
33
34 #include <gio/gio.h>
35 #include <glib-object.h>
36 #include <locale.h>
37 #include <stdlib.h>
38
39 #include <packagekit-glib2/pk-client.h>
40 #include <packagekit-glib2/pk-client-helper.h>
41 #include <packagekit-glib2/pk-common.h>
42 #include <packagekit-glib2/pk-control.h>
43 #include <packagekit-glib2/pk-debug.h>
44 #include <packagekit-glib2/pk-enum.h>
45 #include <packagekit-glib2/pk-package-id.h>
46 #include <packagekit-glib2/pk-package-ids.h>
47 #include <packagekit-glib2/pk-progress-private.h>
48
49 static void pk_client_finalize (GObject *object);
50
51 #define PK_CLIENT_DBUS_METHOD_TIMEOUT G_MAXINT /* ms */
52
53 /**
54 * PkClientPrivate:
55 *
56 * Private #PkClient data
57 **/
58 struct _PkClientPrivate
59 {
60 GDBusConnection *connection;
61 GPtrArray *calls; /* (element-type PkClientState) (owned) */
62 PkControl *control;
63 gchar *locale;
64 gboolean background;
65 gboolean interactive;
66 gboolean details_with_deps_size;
67 guint cache_age;
68 };
69
70 enum {
71 PROP_0,
72 PROP_LOCALE,
73 PROP_BACKGROUND,
74 PROP_INTERACTIVE,
75 PROP_IDLE,
76 PROP_CACHE_AGE,
77 PROP_DETAILS_WITH_DEPS_SIZE,
78 PROP_LAST
79 };
80
81 static GParamSpec *obj_properties[PROP_LAST] = { NULL, };
82
83 G_DEFINE_TYPE_WITH_PRIVATE (PkClient, pk_client, G_TYPE_OBJECT)
84 #define GET_PRIVATE(o) (pk_client_get_instance_private (o))
85
86 #define PK_TYPE_CLIENT_STATE (pk_client_state_get_type ())
87
88 G_DECLARE_FINAL_TYPE (PkClientState, pk_client_state, PK, CLIENT_STATE, GObject)
89
90 static GWeakRef *
91 pk_client_weak_ref_new (gpointer object)
92 {
93 GWeakRef *weak_ref;
94
95 weak_ref = g_slice_new0 (GWeakRef);
96 g_weak_ref_init (weak_ref, object);
97
98 return weak_ref;
99 }
100
101 static void
102 pk_client_weak_ref_free (gpointer ptr)
103 {
104 GWeakRef *weak_ref = ptr;
105
106 g_return_if_fail (weak_ref != NULL);
107
108 g_weak_ref_clear (weak_ref);
109 g_slice_free (GWeakRef, weak_ref);
110 }
111
112 static void
113 pk_client_weak_ref_free_gclosure (gpointer ptr,
114 GClosure *closure)
115 {
116 pk_client_weak_ref_free (ptr);
117 }
118
119 static void
120 pk_client_properties_changed_cb (GDBusProxy *proxy,
121 GVariant *changed_properties,
122 const gchar* const *invalidated_properties,
123 gpointer user_data);
124 static void
125 pk_client_signal_cb (GDBusProxy *proxy,
126 const gchar *sender_name,
127 const gchar *signal_name,
128 GVariant *parameters,
129 gpointer user_data);
130 static void
131 pk_client_notify_name_owner_cb (GObject *obj,
132 GParamSpec *pspec,
133 gpointer user_data);
134
135 struct _PkClientState
136 {
137 GObject parent_instance;
138
139 gboolean allow_deps;
140 gboolean autoremove;
141 gboolean enabled;
142 gboolean force;
143 PkBitfield transaction_flags;
144 gboolean recursive;
145 gboolean ret;
146 gchar *directory;
147 gchar *eula_id;
148 gchar **files;
149 gchar *key_id;
150 gchar *package_id;
151 gchar **package_ids;
152 gchar *parameter;
153 gchar *repo_id;
154 gchar **search;
155 gchar *tid;
156 gchar *distro_id;
157 gchar *transaction_id;
158 gchar *value;
159 gpointer user_data;
160 guint number;
161 gulong cancellable_id;
162 GDBusProxy *proxy;
163 GCancellable *cancellable;
164 GCancellable *cancellable_client;
165 GTask *res;
166 PkBitfield filters;
167 PkClient *client; /* (not nullable) (not owned) */
168 PkProgress *progress;
169 PkResults *results;
170 PkRoleEnum role;
171 PkSigTypeEnum type;
172 PkUpgradeKindEnum upgrade_kind;
173 gint remaining_files_to_copy;
174 PkClientHelper *client_helper;
175 gboolean waiting_for_finished;
176
177 /* True if this PkClientState represents a peek at a transaction which
178 * it doesn’t own, rather than being the owner of the transaction: */
179 gboolean querying_progress;
180 };
181
182 G_DEFINE_TYPE (PkClientState, pk_client_state, G_TYPE_OBJECT)
183
184 static void
185 pk_client_state_unset_proxy (PkClientState *state)
186 {
187 if (state->proxy != NULL) {
188 g_signal_handlers_disconnect_by_func (state->proxy,
189 G_CALLBACK (pk_client_properties_changed_cb),
190 state);
191 g_signal_handlers_disconnect_by_func (state->proxy,
192 G_CALLBACK (pk_client_signal_cb),
193 state);
194 g_signal_handlers_disconnect_by_func (state->proxy,
195 G_CALLBACK (pk_client_notify_name_owner_cb),
196 state);
197 g_clear_object (&state->proxy);
198 }
199 }
200
201 static void
202 pk_client_state_remove (PkClient *client, PkClientState *state)
203 {
204 PkClientPrivate *priv = GET_PRIVATE(client);
205 gboolean was_removed, is_idle;
206
207 was_removed = g_ptr_array_remove_fast (priv->calls, state);
208 g_debug ("%s: PkClientState %p %s removed from PkClient %p",
209 G_STRFUNC, state, was_removed ? "was" : "was not", client);
210 /* state may have been finalised after this point */
211
212 /* has the idle state changed? */
213 is_idle = (priv->calls->len == 0);
214 if (was_removed && is_idle)
215 g_object_notify_by_pspec (G_OBJECT (client), obj_properties[PROP_IDLE]);
216 }
217
218 /*
219 * pk_client_state_finish:
220 * @state: (transfer none): the #PkClientState
221 * @error: (transfer full): the #GError
222 **/
223 static void
224 pk_client_state_finish (PkClientState *state, GError *error)
225 {
226 g_autoptr(PkClientState) state_owned = g_object_ref (state);
227 g_autoptr(GError) error_owned = g_steal_pointer (&error);
228
229 g_debug ("%s: PkClientState %p, error %p, PkClientState.res (GTask) %p",
230 G_STRFUNC, state, error_owned, state->res);
231
232 if (state->res == NULL)
233 return;
234
235 /* Either have to have been successful, or have set an error */
236 g_assert (state->ret || error_owned != NULL);
237
238 /* force finished (if not already set) so clients can update the UI's */
239 if (state->progress != NULL && !state->querying_progress) {
240 pk_progress_set_status (state->progress, PK_STATUS_ENUM_FINISHED);
241 }
242
243 pk_client_state_unset_proxy (state);
244
245 if (state->ret) {
246 g_task_return_pointer (state->res,
247 state->querying_progress ? G_OBJECT (g_object_ref (state->progress)) : G_OBJECT (g_object_ref (state->results)),
248 g_object_unref);
249 } else {
250 g_task_return_error (state->res, g_steal_pointer (&error_owned));
251 }
252
253 /* remove any socket file */
254 if (state->client_helper != NULL) {
255 g_autoptr(GError) error_local = NULL;
256
257 if (!pk_client_helper_stop (state->client_helper, &error_local))
258 g_warning ("failed to stop the client helper: %s", error_local->message);
259 g_object_unref (state->client_helper);
260 }
261
262 /* remove from list */
263 pk_client_state_remove (state->client, state);
264 /* `state_owned` may be the only strong ref to `state` remaining after this point */
265
266 /* mark the state as finished */
267 g_clear_object (&state->res);
268 }
269
270 static void
271 pk_client_state_dispose (GObject *object)
272 {
273 PkClientState *state = PK_CLIENT_STATE (object);
274
275 if (state->cancellable_id > 0) {
276 g_cancellable_disconnect (state->cancellable_client,
277 state->cancellable_id);
278 state->cancellable_id = 0;
279 }
280 g_clear_object (&state->cancellable);
281 g_clear_object (&state->cancellable_client);
282
283 G_OBJECT_CLASS (pk_client_state_parent_class)->dispose (object);
284 }
285
286 static void
287 pk_client_state_finalize (GObject *object)
288 {
289 PkClientState *state = PK_CLIENT_STATE (object);
290
291 g_free (state->directory);
292 g_free (state->eula_id);
293 g_free (state->key_id);
294 g_free (state->package_id);
295 g_free (state->parameter);
296 g_free (state->repo_id);
297 g_strfreev (state->search);
298 g_free (state->value);
299 g_free (state->tid);
300 g_free (state->distro_id);
301 g_free (state->transaction_id);
302 g_strfreev (state->files);
303 g_strfreev (state->package_ids);
304 /* results will not exist if the CreateTransaction fails */
305 g_clear_object (&state->results);
306 g_clear_object (&state->progress);
307 g_clear_object (&state->res);
308 state->client = NULL;
309
310 G_OBJECT_CLASS (pk_client_state_parent_class)->finalize (object);
311 }
312
313 static void
314 pk_client_state_class_init (PkClientStateClass *klass)
315 {
316 GObjectClass *object_class = G_OBJECT_CLASS (klass);
317
318 object_class->dispose = pk_client_state_dispose;
319 object_class->finalize = pk_client_state_finalize;
320 }
321
322 static void
323 pk_client_state_init (PkClientState *state)
324 {
325 }
326
327 static void
328 pk_client_cancel_cb (GObject *source_object,
329 GAsyncResult *res,
330 gpointer user_data)
331 {
332 GDBusProxy *proxy = G_DBUS_PROXY (source_object);
333 GWeakRef *weak_ref = user_data;
334 g_autoptr(GError) error = NULL;
335 g_autoptr(GVariant) value = NULL;
336 g_autoptr(PkClientState) state = NULL;
337
338 state = g_weak_ref_get (weak_ref);
339
340 pk_client_weak_ref_free (weak_ref);
341
342 /* get the result */
343 value = g_dbus_proxy_call_finish (proxy, res, &error);
344 if (value == NULL) {
345 /* Instructing the daemon to cancel failed, so just return an
346 * error to the client so they don’t wait forever. */
347 g_debug ("failed to cancel: %s", error->message);
348
349 if (state)
350 pk_client_state_finish (state, g_steal_pointer (&error));
351 }
352
353 /* wait for the response from the server to the Cancel() method */
354 }
355
356 static void
357 pk_client_cancellable_cancel_cb (GCancellable *cancellable,
358 gpointer user_data)
359 {
360 GWeakRef *weak_ref = user_data;
361 g_autoptr(PkClientState) state = NULL;
362
363 state = g_weak_ref_get (weak_ref);
364
365 if (state == NULL) {
366 g_debug ("Cancelled, but the operation is already over");
367 return;
368 }
369
370 /* D-Bus method has not yet fired. This can happen, for example, when
371 * pk_client_state_new() is called with a #GCancellable which has
372 * already been cancelled. */
373 if (state->proxy == NULL) {
374 g_autoptr(GError) local_error = NULL;
375
376 g_debug ("%s: Cancelled PkClientState %p, but no proxy",
377 G_STRFUNC, state);
378
379 if (!g_cancellable_set_error_if_cancelled (cancellable, &local_error)) {
380 local_error = g_error_new_literal (PK_CLIENT_ERROR, PK_CLIENT_ERROR_FAILED,
381 "PackageKit transaction disappeared");
382 }
383
384 pk_client_state_finish (state, g_steal_pointer (&local_error));
385 return;
386 }
387
388 /* takeover the call with the cancel method */
389 g_debug ("cancelling %s", state->tid);
390 g_dbus_proxy_call (state->proxy, "Cancel",
391 NULL,
392 G_DBUS_CALL_FLAGS_NONE,
393 PK_CLIENT_DBUS_METHOD_TIMEOUT,
394 NULL,
395 pk_client_cancel_cb, pk_client_weak_ref_new (state));
396 }
397
398 static void pk_client_state_add (PkClient *client, PkClientState *state);
399
400 static PkClientState *
401 pk_client_state_new (PkClient *client,
402 GAsyncReadyCallback callback_ready,
403 gpointer user_data,
404 gpointer source_tag,
405 PkRoleEnum role,
406 GCancellable *cancellable)
407 {
408 PkClientState *state;
409
410 state = g_object_new (PK_TYPE_CLIENT_STATE, NULL);
411 state->role = role;
412 state->cancellable = g_cancellable_new ();
413 state->res = g_task_new (client, state->cancellable, callback_ready, user_data);
414 state->client = client;
415 g_task_set_source_tag (state->res, source_tag);
416
417 g_debug ("%s: Created new PkClientState %p with PkClientState.res (GTask) %p for PkClient %p",
418 G_STRFUNC, state, state->res, client);
419
420 /* track state */
421 pk_client_state_add (client, state);
422
423 /* Set up cancellation. If `cancellable` has already been cancelled,
424 * this could result in pk_client_cancellable_cancel_cb() being called
425 * synchronously. */
426 if (cancellable != NULL) {
427 state->cancellable_client = g_object_ref (cancellable);
428 state->cancellable_id = g_cancellable_connect (cancellable,
429 G_CALLBACK (pk_client_cancellable_cancel_cb),
430 pk_client_weak_ref_new (state),
431 pk_client_weak_ref_free);
432 }
433
434 return state;
435 }
436
437 /**
438 * pk_client_error_quark:
439 *
440 * An error quark for #PkClientError.
441 *
442 * Return value: an error quark.
443 *
444 * Since: 0.5.2
445 **/
446 G_DEFINE_QUARK (pk-client-error-quark, pk_client_error)
447
448 /*
449 * pk_client_get_property:
450 **/
451 static void
452 pk_client_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
453 {
454 PkClient *client = PK_CLIENT (object);
455 PkClientPrivate *priv = GET_PRIVATE(client);
456
457 switch (prop_id) {
458 case PROP_LOCALE:
459 g_value_set_string (value, priv->locale);
460 break;
461 case PROP_BACKGROUND:
462 g_value_set_boolean (value, priv->background);
463 break;
464 case PROP_INTERACTIVE:
465 g_value_set_boolean (value, priv->interactive);
466 break;
467 case PROP_IDLE:
468 g_value_set_boolean (value, pk_client_get_idle (client));
469 break;
470 case PROP_CACHE_AGE:
471 g_value_set_uint (value, priv->cache_age);
472 break;
473 case PROP_DETAILS_WITH_DEPS_SIZE:
474 g_value_set_boolean (value, priv->details_with_deps_size);
475 break;
476 default:
477 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
478 break;
479 }
480 }
481
482 /*
483 * pk_client_set_property:
484 **/
485 static void
486 pk_client_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
487 {
488 PkClient *client = PK_CLIENT (object);
489 PkClientPrivate *priv = GET_PRIVATE(client);
490
491 switch (prop_id) {
492 case PROP_LOCALE:
493 g_free (priv->locale);
494 priv->locale = g_strdup (g_value_get_string (value));
495 break;
496 case PROP_BACKGROUND:
497 priv->background = g_value_get_boolean (value);
498 break;
499 case PROP_INTERACTIVE:
500 priv->interactive = g_value_get_boolean (value);
501 break;
502 case PROP_CACHE_AGE:
503 priv->cache_age = g_value_get_uint (value);
504 break;
505 case PROP_DETAILS_WITH_DEPS_SIZE:
506 priv->details_with_deps_size = g_value_get_boolean (value);
507 break;
508 default:
509 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
510 break;
511 }
512 }
513
514 /*
515 * pk_client_fixup_dbus_error:
516 **/
517 static void
518 pk_client_fixup_dbus_error (GError *error)
519 {
520 const gchar *name_suffix = NULL;
521 g_autofree gchar *name = NULL;
522
523 g_return_if_fail (error != NULL);
524
525 /* old style PolicyKit failure */
526 if (g_str_has_prefix (error->message, "org.freedesktop.packagekit.")) {
527 g_debug ("fixing up code for Policykit auth failure");
528 error->code = PK_CLIENT_ERROR_FAILED_AUTH;
529 g_free (error->message);
530 error->message = g_strdup ("PolicyKit authorization failure");
531 return;
532 }
533
534 /* is a remote error? */
535 if (!g_dbus_error_is_remote_error (error))
536 return;
537
538 /* fall back to generic */
539 error->domain = PK_CLIENT_ERROR;
540 error->code = PK_CLIENT_ERROR_FAILED;
541
542 /* parse the remote error */
543 name = g_dbus_error_get_remote_error (error);
544 g_dbus_error_strip_remote_error (error);
545 if (g_str_has_prefix (name, "org.freedesktop.PackageKit.Transaction."))
546 name_suffix = &name[39];
547 if (g_strcmp0 (name_suffix, "Denied") == 0 ||
548 g_strcmp0 (name_suffix, "RefusedByPolicy") == 0) {
549 error->code = PK_CLIENT_ERROR_FAILED_AUTH;
550 return;
551 }
552 if (g_strcmp0 (name_suffix, "PackageIdInvalid") == 0 ||
553 g_strcmp0 (name_suffix, "SearchInvalid") == 0 ||
554 g_strcmp0 (name_suffix, "FilterInvalid") == 0 ||
555 g_strcmp0 (name_suffix, "InvalidProvide") == 0 ||
556 g_strcmp0 (name_suffix, "InputInvalid") == 0) {
557 error->code = PK_CLIENT_ERROR_INVALID_INPUT;
558 return;
559 }
560 if (g_strcmp0 (name_suffix, "PackInvalid") == 0 ||
561 g_strcmp0 (name_suffix, "NoSuchFile") == 0 ||
562 g_strcmp0 (name_suffix, "MimeTypeNotSupported") == 0 ||
563 g_strcmp0 (name_suffix, "NoSuchDirectory") == 0) {
564 error->code = PK_CLIENT_ERROR_INVALID_FILE;
565 return;
566 }
567 if (g_strcmp0 (name_suffix, "NotSupported") == 0) {
568 error->code = PK_CLIENT_ERROR_NOT_SUPPORTED;
569 return;
570 }
571 g_warning ("couldn't parse execption '%s', please report", name);
572 }
573
574 /*
575 * pk_client_real_path:
576 *
577 * Resolves paths like ../../Desktop/bar.rpm to /home/hughsie/Desktop/bar.rpm
578 * TODO: We should use canonicalize_filename() in gio/glocalfile.c as realpath()
579 * is crap.
580 **/
581 static gchar *
582 pk_client_real_path (const gchar *path)
583 {
584 gchar *real = NULL;
585 gchar *temp;
586
587 /* don't trust realpath one little bit */
588 if (path == NULL)
589 return NULL;
590
591 #ifndef __FreeBSD__
592 /* ITS4: ignore, glibc allocates us a buffer to try and fix some brain damage */
593 temp = realpath (path, NULL);
594 if (temp != NULL) {
595 real = g_strdup (temp);
596 /* yes, free, not g_free */
597 free (temp);
598 }
599 #else /* __FreeBSD__ */
600 {
601 gchar abs_path[PATH_MAX];
602 temp = realpath (path, abs_path);
603 if (temp != NULL)
604 real = g_strdup (temp);
605 }
606 #endif
607 return real;
608 }
609
610 /*
611 * pk_client_convert_real_paths:
612 **/
613 static gchar **
614 pk_client_convert_real_paths (gchar **paths, GError **error)
615 {
616 guint i;
617 guint len;
618 g_auto(GStrv) res = NULL;
619
620 /* create output array */
621 len = g_strv_length (paths);
622 res = g_new0 (gchar *, len+1);
623
624 /* resolve each path */
625 for (i = 0; i < len; i++) {
626 res[i] = pk_client_real_path (paths[i]);
627 if (res[i] == NULL) {
628 g_set_error (error,
629 PK_CLIENT_ERROR,
630 PK_CLIENT_ERROR_INVALID_INPUT,
631 "could not resolve: %s", paths[i]);
632 return NULL;
633 }
634 }
635 return g_strdupv (res);
636 }
637
638 /*
639 * pk_client_get_user_temp:
640 *
641 * Return (and create if does not exist) a temporary directory
642 * that is writable only by the user, and readable by root.
643 *
644 * Return value: the temp directory, or %NULL for create error
645 **/
646 static gchar *
647 pk_client_get_user_temp (const gchar *subfolder, GError **error)
648 {
649 gchar *path = NULL;
650 g_autoptr(GFile) file = NULL;
651
652 /* build path in home folder */
653 path = g_build_filename (g_get_user_cache_dir (), "PackageKit", subfolder, NULL);
654
655 /* find if exists */
656 file = g_file_new_for_path (path);
657 if (g_file_query_exists (file, NULL))
658 return path;
659
660 /* create as does not exist */
661 if (!g_file_make_directory_with_parents (file, NULL, error)) {
662 /* return nothing.. */
663 g_free (path);
664 return NULL;
665 }
666 return path;
667 }
668
669 /*
670 * pk_client_is_file_native:
671 **/
672 static gboolean
673 pk_client_is_file_native (const gchar *filename)
674 {
675 g_autoptr(GFile) source = NULL;
676
677 /* does gvfs think the file is on a remote filesystem? */
678 source = g_file_new_for_path (filename);
679 if (!g_file_is_native (source))
680 return FALSE;
681
682 /* are we FUSE mounted */
683 if (g_strstr_len (filename, -1, "/.gvfs/") != NULL)
684 return FALSE;
685 return TRUE;
686 }
687
688 /*
689 * pk_client_percentage_to_signed:
690 */
691 static gint
692 pk_client_percentage_to_signed (guint percentage)
693 {
694 if (percentage == 101)
695 return -1;
696 return (gint) percentage;
697 }
698
699 /*
700 * pk_client_set_property_value:
701 **/
702 static void
703 pk_client_set_property_value (PkClientState *state,
704 const char *key,
705 GVariant *value)
706 {
707 const gchar *package_id;
708
709 /* role */
710 if (g_strcmp0 (key, "Role") == 0) {
711 pk_progress_set_role (state->progress,
712 g_variant_get_uint32 (value));
713 return;
714 }
715
716 /* status */
717 if (g_strcmp0 (key, "Status") == 0) {
718 pk_progress_set_status (state->progress,
719 g_variant_get_uint32 (value));
720 return;
721 }
722
723 /* last-package */
724 if (g_strcmp0 (key, "LastPackage") == 0) {
725 package_id = g_variant_get_string (value, NULL);
726 /* check to see if it's been set yet */
727 if (!pk_package_id_check (package_id))
728 return;
729 pk_progress_set_package_id (state->progress, package_id);
730 return;
731 }
732
733 /* percentage */
734 if (g_strcmp0 (key, "Percentage") == 0) {
735 pk_progress_set_percentage (state->progress,
736 pk_client_percentage_to_signed (g_variant_get_uint32 (value)));
737 return;
738 }
739
740 /* allow-cancel */
741 if (g_strcmp0 (key, "AllowCancel") == 0) {
742 pk_progress_set_allow_cancel (state->progress,
743 g_variant_get_boolean (value));
744 return;
745 }
746
747 /* caller-active */
748 if (g_strcmp0 (key, "CallerActive") == 0) {
749 pk_progress_set_caller_active (state->progress,
750 g_variant_get_boolean (value));
751 return;
752 }
753
754 /* elapsed-time */
755 if (g_strcmp0 (key, "ElapsedTime") == 0) {
756 pk_progress_set_elapsed_time (state->progress,
757 g_variant_get_uint32 (value));
758 return;
759 }
760
761 /* remaining-time */
762 if (g_strcmp0 (key, "RemainingTime") == 0) {
763 pk_progress_set_remaining_time (state->progress,
764 g_variant_get_uint32 (value));
765 return;
766 }
767
768 /* speed */
769 if (g_strcmp0 (key, "Speed") == 0) {
770 pk_progress_set_speed (state->progress,
771 g_variant_get_uint32 (value));
772 return;
773 }
774
775 /* download-size-remaining */
776 if (g_strcmp0 (key, "DownloadSizeRemaining") == 0) {
777 pk_progress_set_download_size_remaining (state->progress,
778 g_variant_get_uint64 (value));
779 return;
780 }
781
782 /* transaction-flags */
783 if (g_strcmp0 (key, "TransactionFlags") == 0) {
784 pk_progress_set_transaction_flags (state->progress,
785 g_variant_get_uint64 (value));
786 return;
787 }
788
789 /* uid */
790 if (g_strcmp0 (key, "Uid") == 0) {
791 pk_progress_set_uid (state->progress,
792 g_variant_get_uint32 (value));
793 return;
794 }
795
796 /* sender */
797 if (g_strcmp0 (key, "Sender") == 0) {
798 pk_progress_set_sender (state->progress,
799 g_variant_get_string (value, NULL));
800 return;
801 }
802
803 g_warning ("unhandled property '%s'", key);
804 }
805
806 /*
807 * pk_client_state_add:
808 **/
809 static void
810 pk_client_state_add (PkClient *client, PkClientState *state)
811 {
812 PkClientPrivate *priv = GET_PRIVATE(client);
813 gboolean was_idle;
814
815 g_debug ("%s: adding PkClientState %p to PkClient %p",
816 G_STRFUNC, state, client);
817
818 was_idle = pk_client_get_idle (client);
819
820 g_ptr_array_add (priv->calls, g_object_ref (state));
821
822 /* has the idle state changed? */
823 if (was_idle)
824 g_object_notify_by_pspec (G_OBJECT (client), obj_properties[PROP_IDLE]);
825 }
826
827 /*
828 * pk_client_properties_changed_cb:
829 **/
830 static void
831 pk_client_properties_changed_cb (GDBusProxy *proxy,
832 GVariant *changed_properties,
833 const gchar* const *invalidated_properties,
834 gpointer user_data)
835 {
836 const gchar *key;
837 GVariantIter *iter;
838 GVariant *value;
839 GWeakRef *weak_ref = user_data;
840 g_autoptr(PkClientState) state = g_weak_ref_get (weak_ref);
841
842 if (!state)
843 return;
844
845 if (g_variant_n_children (changed_properties) > 0) {
846 g_variant_get (changed_properties,
847 "a{sv}",
848 &iter);
849 while (g_variant_iter_loop (iter, "{&sv}", &key, &value))
850 pk_client_set_property_value (state, key, value);
851 g_variant_iter_free (iter);
852 }
853 }
854
855 /*
856 * pk_client_signal_package:
857 */
858 static void
859 pk_client_signal_package (PkClientState *state,
860 PkInfoEnum info_enum,
861 PkInfoEnum update_severity,
862 const gchar *package_id,
863 const gchar *summary)
864 {
865 g_autoptr(GError) error = NULL;
866 g_autoptr(PkPackage) package = NULL;
867
868 /* create virtual package */
869 package = pk_package_new ();
870 if (!pk_package_set_id (package, package_id, &error)) {
871 g_warning ("failed to set package id for %s", package_id);
872 return;
873 }
874 g_object_set (package,
875 "info", info_enum,
876 "summary", summary,
877 "update-severity", update_severity,
878 "role", state->role,
879 "transaction-id", state->transaction_id,
880 NULL);
881
882 /* add to results */
883 if (state->results != NULL && info_enum != PK_INFO_ENUM_FINISHED)
884 pk_results_add_package (state->results, package);
885
886 /* only emit progress for verb packages */
887 switch (info_enum) {
888 case PK_INFO_ENUM_DOWNLOADING:
889 case PK_INFO_ENUM_UPDATING:
890 case PK_INFO_ENUM_INSTALLING:
891 case PK_INFO_ENUM_REMOVING:
892 case PK_INFO_ENUM_CLEANUP:
893 case PK_INFO_ENUM_OBSOLETING:
894 case PK_INFO_ENUM_REINSTALLING:
895 case PK_INFO_ENUM_DOWNGRADING:
896 case PK_INFO_ENUM_PREPARING:
897 case PK_INFO_ENUM_DECOMPRESSING:
898 case PK_INFO_ENUM_FINISHED:
899 pk_progress_set_package_id (state->progress, package_id);
900 pk_progress_set_package (state->progress, package);
901 break;
902 default:
903 break;
904 }
905 }
906
907 /*
908 * pk_client_copy_finished_remove_old_files:
909 *
910 * Removes all the files that do not have the prefix destination path.
911 * This should remove all the old /var/cache/PackageKit/$TMP/powertop-1.8-1.fc8.rpm
912 * and leave the $DESTDIR/powertop-1.8-1.fc8.rpm files.
913 */
914 static void
915 pk_client_copy_finished_remove_old_files (PkClientState *state)
916 {
917 guint i;
918 g_autoptr(GPtrArray) array = NULL;
919
920 /* get the data */
921 array = pk_results_get_files_array (state->results);
922
923 /* remove any without dest path */
924 for (i = 0; i < array->len; ) {
925 PkFiles *item;
926 gchar **files;
927
928 item = g_ptr_array_index (array, i);
929 files = pk_files_get_files (item);
930 if (!g_str_has_prefix (files[0], state->directory))
931 g_ptr_array_remove_index_fast (array, i);
932 else
933 i++;
934 }
935 }
936
937 /*
938 * pk_client_copy_downloaded_finished_cb:
939 */
940 static void
941 pk_client_copy_downloaded_finished_cb (GFile *file, GAsyncResult *res, gpointer user_data)
942 {
943 g_autofree gchar *path = NULL;
944 g_autoptr(GError) error = NULL;
945 g_autoptr(PkClientState) state = user_data;
946
947 /* debug */
948 path = g_file_get_path (file);
949 g_debug ("finished copy of %s", path);
950
951 /* get the result */
952 if (!g_file_copy_finish (file, res, &error)) {
953 pk_client_state_finish (state, g_steal_pointer (&error));
954 return;
955 }
956
957 /* no more copies pending? */
958 if (g_atomic_int_dec_and_test (&state->remaining_files_to_copy)) {
959 pk_client_copy_finished_remove_old_files (state);
960 state->ret = TRUE;
961 pk_client_state_finish (state, NULL);
962 }
963 }
964
965 /*
966 * pk_client_copy_progress_cb:
967 */
968 static void
969 pk_client_copy_progress_cb (goffset current_num_bytes, goffset total_num_bytes, PkClientState *state)
970 {
971 gint percentage = -1;
972
973 /* save status */
974 pk_progress_set_status (state->progress, PK_STATUS_ENUM_COPY_FILES);
975
976 /* calculate percentage */
977 if (total_num_bytes > 0)
978 percentage = 100 * current_num_bytes / total_num_bytes;
979
980 /* save percentage */
981 pk_progress_set_percentage (state->progress, percentage);
982 }
983
984 /*
985 * pk_client_copy_downloaded_file:
986 */
987 static void
988 pk_client_copy_downloaded_file (PkClientState *state, const gchar *package_id, const gchar *source_file)
989 {
990 g_autoptr(GError) error = NULL;
991 g_autofree gchar *basename = NULL;
992 g_autofree gchar *path = NULL;
993 g_autoptr(GFile) destination = NULL;
994 g_autoptr(GFile) source = NULL;
995 g_autoptr(PkFiles) item = NULL;
996 g_auto(GStrv) files = NULL;
997
998 /* generate the destination location */
999 basename = g_path_get_basename (source_file);
1000 path = g_build_filename (state->directory, basename, NULL);
1001
1002 /* copy async */
1003 g_debug ("copy %s to %s", source_file, path);
1004 source = g_file_new_for_path (source_file);
1005 destination = g_file_new_for_path (path);
1006 if (g_file_query_exists (destination, state->cancellable)) {
1007 g_set_error (&error,
1008 PK_CLIENT_ERROR,
1009 PK_ERROR_ENUM_FILE_CONFLICTS,
1010 "file %s already exists", path);
1011 pk_client_state_finish (state, g_steal_pointer (&error));
1012 return;
1013 }
1014 g_file_copy_async (source, destination, G_FILE_COPY_OVERWRITE,
1015 G_PRIORITY_DEFAULT, state->cancellable,
1016 (GFileProgressCallback) pk_client_copy_progress_cb, state,
1017 (GAsyncReadyCallback) pk_client_copy_downloaded_finished_cb, g_object_ref (state));
1018
1019 /* Add the result (as a GStrv) to the results set */
1020 files = g_strsplit (path, ",", -1);
1021 item = pk_files_new ();
1022 g_object_set (item,
1023 "package-id", package_id,
1024 "files", files,
1025 "role", state->role,
1026 "transaction-id", state->transaction_id,
1027 NULL);
1028 pk_results_add_files (state->results, item);
1029 }
1030
1031 /*
1032 * pk_client_copy_downloaded:
1033 *
1034 * We have to copy the files from the temporary directory into the user-specified
1035 * directory. There should only be one file for each package, although this is
1036 * not encoded in the spec.
1037 *
1038 * This will eventually call pk_client_state_finish() on `state`.
1039 */
1040 static void
1041 pk_client_copy_downloaded (PkClientState *state)
1042 {
1043 guint i;
1044 guint j;
1045 guint len;
1046 PkFiles *item;
1047 g_autoptr(GPtrArray) array = NULL;
1048 unsigned int n_files_to_copy;
1049
1050 /* get data */
1051 array = pk_results_get_files_array (state->results);
1052
1053 /* get the number of files to copy */
1054 n_files_to_copy = 0;
1055 for (i = 0; i < array->len; i++) {
1056 item = g_ptr_array_index (array, i);
1057 n_files_to_copy += g_strv_length (pk_files_get_files (item));
1058 }
1059
1060 g_atomic_int_set (&state->remaining_files_to_copy, n_files_to_copy);
1061
1062 /* get a cached value, as pk_client_copy_downloaded_file() adds items */
1063 len = array->len;
1064
1065 /* save percentage */
1066 pk_progress_set_percentage (state->progress, -1);
1067
1068 /* do the copies pipelined */
1069 for (i = 0; i < len; i++) {
1070 gchar **files;
1071 item = g_ptr_array_index (array, i);
1072 files = pk_files_get_files (item);
1073 for (j = 0; files[j] != NULL; j++) {
1074 pk_client_copy_downloaded_file (state,
1075 pk_files_get_package_id (item),
1076 files[j]);
1077 }
1078 }
1079
1080 /* Were there actually any files to copy? */
1081 if (n_files_to_copy == 0) {
1082 state->ret = TRUE;
1083 pk_client_state_finish (state, NULL);
1084 }
1085 }
1086
1087 /*
1088 * pk_client_signal_finished:
1089 */
1090 static void
1091 pk_client_signal_finished (PkClientState *state,
1092 PkExitEnum exit_enum,
1093 guint runtime)
1094 {
1095 g_autoptr(GError) error = NULL;
1096 g_autoptr(PkError) error_code = NULL;
1097
1098 /* yay */
1099 pk_results_set_exit_code (state->results, exit_enum);
1100
1101 /* failed */
1102 if (exit_enum == PK_EXIT_ENUM_FAILED) {
1103
1104 /* get error code and error message */
1105 error_code = pk_results_get_error_code (state->results);
1106 if (error_code != NULL) {
1107 /* should only ever have one ErrorCode */
1108 error = g_error_new (PK_CLIENT_ERROR,
1109 0xFF + pk_error_get_code (error_code),
1110 "%s",
1111 pk_error_get_details (error_code));
1112 } else {
1113 /* fallback where the daemon didn't sent ErrorCode */
1114 error = g_error_new (PK_CLIENT_ERROR,
1115 PK_CLIENT_ERROR_FAILED,
1116 "Failed: %s",
1117 pk_exit_enum_to_string (exit_enum));
1118 }
1119 pk_client_state_finish (state, g_steal_pointer (&error));
1120 return;
1121 }
1122
1123 /* do we have to copy results? If so, this will eventually call
1124 * pk_client_state_finish() for us. */
1125 if (state->role == PK_ROLE_ENUM_DOWNLOAD_PACKAGES &&
1126 state->directory != NULL &&
1127 exit_enum != PK_EXIT_ENUM_CANCELLED) {
1128 pk_client_copy_downloaded (state);
1129 return;
1130 }
1131
1132 /* we're done */
1133 state->ret = TRUE;
1134 pk_client_state_finish (state, NULL);
1135 }
1136
1137 static void
1138 results_add_update_detail_from_variant (PkResults *results,
1139 GVariant *update_variant,
1140 PkRoleEnum role,
1141 const gchar *transaction_id)
1142 {
1143 g_autoptr(PkUpdateDetail) item = NULL;
1144 const gchar *package_id;
1145 g_autofree gchar **updates_strv = NULL;
1146 g_autofree gchar **obsoletes_strv = NULL;
1147 g_autofree gchar **vendor_urls_strv = NULL;
1148 g_autofree gchar **bugzilla_urls_strv = NULL;
1149 g_autofree gchar **cve_urls_strv = NULL;
1150 guint restart, state;
1151 const gchar *update_text, *changelog, *issued, *updated;
1152
1153 g_variant_get (update_variant,
1154 "(&s^a&s^a&s^a&s^a&s^a&su&s&su&s&s)",
1155 &package_id,
1156 &updates_strv,
1157 &obsoletes_strv,
1158 &vendor_urls_strv,
1159 &bugzilla_urls_strv,
1160 &cve_urls_strv,
1161 &restart,
1162 &update_text,
1163 &changelog,
1164 &state,
1165 &issued,
1166 &updated);
1167
1168 item = pk_update_detail_new ();
1169 g_object_set (item,
1170 "package-id", package_id,
1171 "updates", updates_strv[0] != NULL ? updates_strv : NULL,
1172 "obsoletes", obsoletes_strv[0] != NULL ? obsoletes_strv : NULL,
1173 "vendor-urls", vendor_urls_strv[0] != NULL ? vendor_urls_strv : NULL,
1174 "bugzilla-urls", bugzilla_urls_strv[0] != NULL ? bugzilla_urls_strv : NULL,
1175 "cve-urls", cve_urls_strv[0] != NULL ? cve_urls_strv : NULL,
1176 "restart", restart,
1177 "update-text", update_text,
1178 "changelog", changelog,
1179 "state", state,
1180 "issued", issued,
1181 "updated", updated,
1182 "role", role,
1183 "transaction-id", transaction_id,
1184 NULL);
1185
1186 pk_results_add_update_detail (results, item);
1187 }
1188
1189 /*
1190 * pk_client_signal_cb:
1191 **/
1192 static void
1193 pk_client_signal_cb (GDBusProxy *proxy,
1194 const gchar *sender_name,
1195 const gchar *signal_name,
1196 GVariant *parameters,
1197 gpointer user_data)
1198 {
1199 GWeakRef *weak_ref = user_data;
1200 g_autoptr(PkClientState) state = g_weak_ref_get (weak_ref);
1201 gchar *tmp_str[12];
1202 gboolean tmp_bool;
1203 guint tmp_uint;
1204 guint tmp_uint2;
1205 guint tmp_uint3;
1206
1207 if (!state)
1208 return;
1209
1210 if (g_strcmp0 (signal_name, "Finished") == 0) {
1211 if (state->waiting_for_finished) {
1212 g_variant_get (parameters,
1213 "(uu)",
1214 &tmp_uint2,
1215 &tmp_uint);
1216 /* this will call pk_client_state_finish(): */
1217 pk_client_signal_finished (state,
1218 tmp_uint2,
1219 tmp_uint);
1220 }
1221 return;
1222 }
1223 if (g_strcmp0 (signal_name, "Package") == 0) {
1224 g_variant_get (parameters,
1225 "(u&s&s)",
1226 &tmp_uint,
1227 &tmp_str[1],
1228 &tmp_str[2]);
1229 /* The 'info' and 'update-severity' are encoded in the single value */
1230 tmp_uint2 = tmp_uint & 0xFFFF;
1231 tmp_uint3 = (tmp_uint >> 16) & 0xFFFF;
1232 pk_client_signal_package (state,
1233 tmp_uint2,
1234 tmp_uint3,
1235 tmp_str[1],
1236 tmp_str[2]);
1237 return;
1238 }
1239 if (g_strcmp0 (signal_name, "Packages") == 0) {
1240 g_autoptr(GVariantIter) iter = NULL;
1241 guint flags;
1242 PkInfoEnum info, severity;
1243 const gchar *package_id, *summary;
1244
1245 g_variant_get (parameters, "(a(uss))", &iter);
1246
1247 while (g_variant_iter_loop (iter, "(u&s&s)",
1248 &flags,
1249 &package_id,
1250 &summary)) {
1251 /* The 'info' and 'update-severity' are encoded in the single value */
1252 info = flags & 0xFFFF;
1253 severity = (flags >> 16) & 0xFFFF;
1254 pk_client_signal_package (state,
1255 info,
1256 severity,
1257 package_id,
1258 summary);
1259 }
1260
1261 return;
1262 }
1263 if (g_strcmp0 (signal_name, "Details") == 0) {
1264 gchar *key;
1265 GVariantIter *dictionary;
1266 GVariant *value;
1267 g_autoptr(PkDetails) item = NULL;
1268 item = pk_details_new ();
1269
1270 if (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(a{sv})"))) {
1271 g_variant_get_child (parameters, 0, "a{sv}", &dictionary);
1272 while (g_variant_iter_loop (dictionary, "{sv}", &key, &value)) {
1273 if (g_strcmp0 (key, "group") == 0)
1274 g_object_set (item, "group", g_variant_get_uint32 (value), NULL);
1275 else if (g_strcmp0 (key, "size") == 0)
1276 g_object_set (item, "size", g_variant_get_uint64 (value), NULL);
1277 else if (g_strcmp0 (key, "download-size") == 0)
1278 g_object_set (item, "download-size", g_variant_get_uint64 (value), NULL);
1279 else
1280 g_object_set (item, key, g_variant_get_string (value, NULL), NULL);
1281 }
1282 g_variant_iter_free (dictionary);
1283 } else {
1284 guint64 tmp_uint64;
1285 g_variant_get (parameters,
1286 "(&s&su&s&st)",
1287 &tmp_str[0],
1288 &tmp_str[1],
1289 &tmp_uint,
1290 &tmp_str[3],
1291 &tmp_str[4],
1292 &tmp_uint64);
1293 g_object_set (item,
1294 "package-id", tmp_str[0],
1295 "license", tmp_str[1],
1296 "group", tmp_uint,
1297 "description", tmp_str[3],
1298 "url", tmp_str[4],
1299 "size", tmp_uint64,
1300 "role", state->role,
1301 "transaction-id", state->transaction_id,
1302 NULL);
1303 }
1304 pk_results_add_details (state->results, item);
1305 return;
1306 }
1307 if (g_strcmp0 (signal_name, "UpdateDetail") == 0) {
1308 results_add_update_detail_from_variant (state->results, parameters,
1309 state->role, state->transaction_id);
1310 return;
1311 }
1312 if (g_strcmp0 (signal_name, "UpdateDetails") == 0) {
1313 g_autoptr(GVariantIter) iter = NULL;
1314 g_autoptr(GVariant) update_detail = NULL;
1315
1316 g_variant_get (parameters, "(a(sasasasasasussuss))", &iter);
1317
1318 while ((update_detail = g_variant_iter_next_value (iter))) {
1319 results_add_update_detail_from_variant (state->results, update_detail,
1320 state->role, state->transaction_id);
1321 g_clear_pointer (&update_detail, g_variant_unref);
1322 }
1323
1324 return;
1325 }
1326 if (g_strcmp0 (signal_name, "Transaction") == 0) {
1327 g_autoptr(PkTransactionPast) item = NULL;
1328 g_variant_get (parameters,
1329 "(&o&sbuu&su&s)",
1330 &tmp_str[0],
1331 &tmp_str[1],
1332 &tmp_bool,
1333 &tmp_uint3,
1334 &tmp_uint,
1335 &tmp_str[3],
1336 &tmp_uint2,
1337 &tmp_str[4]);
1338 item = pk_transaction_past_new ();
1339 g_object_set (item,
1340 "tid", tmp_str[0],
1341 "timespec", tmp_str[1],
1342 "succeeded", tmp_bool,
1343 "role", tmp_uint3,
1344 "duration", tmp_uint,
1345 "data", tmp_str[3],
1346 "uid", tmp_uint2,
1347 "cmdline", tmp_str[4],
1348 "PkSource::role", state->role,
1349 "transaction-id", state->transaction_id,
1350 NULL);
1351 pk_results_add_transaction (state->results, item);
1352 return;
1353 }
1354 if (g_strcmp0 (signal_name, "DistroUpgrade") == 0) {
1355 g_autoptr(PkDistroUpgrade) item = NULL;
1356 g_variant_get (parameters,
1357 "(u&s&s)",
1358 &tmp_uint,
1359 &tmp_str[1],
1360 &tmp_str[2]);
1361 item = pk_distro_upgrade_new ();
1362 g_object_set (item,
1363 "state", tmp_uint,
1364 "name", tmp_str[1],
1365 "summary", tmp_str[2],
1366 "role", state->role,
1367 "transaction-id", state->transaction_id,
1368 NULL);
1369 pk_results_add_distro_upgrade (state->results, item);
1370 return;
1371 }
1372 if (g_strcmp0 (signal_name, "RequireRestart") == 0) {
1373 g_autoptr(PkRequireRestart) item = NULL;
1374 g_variant_get (parameters,
1375 "(u&s)",
1376 &tmp_uint,
1377 &tmp_str[1]);
1378 item = pk_require_restart_new ();
1379 g_object_set (item,
1380 "restart", tmp_uint,
1381 "package-id", tmp_str[1],
1382 "role", state->role,
1383 "transaction-id", state->transaction_id,
1384 NULL);
1385 pk_results_add_require_restart (state->results, item);
1386 return;
1387 }
1388 if (g_strcmp0 (signal_name, "Category") == 0) {
1389 g_autoptr(PkCategory) item = NULL;
1390 g_variant_get (parameters,
1391 "(&s&s&s&s&s)",
1392 &tmp_str[0],
1393 &tmp_str[1],
1394 &tmp_str[2],
1395 &tmp_str[3],
1396 &tmp_str[4]);
1397 item = pk_category_new ();
1398 g_object_set (item,
1399 "parent-id", tmp_str[0],
1400 "cat-id", tmp_str[1],
1401 "name", tmp_str[2],
1402 "summary", tmp_str[3],
1403 "icon", tmp_str[4],
1404 "role", state->role,
1405 "transaction-id", state->transaction_id,
1406 NULL);
1407 pk_results_add_category (state->results, item);
1408 return;
1409 }
1410 if (g_strcmp0 (signal_name, "Files") == 0) {
1411 g_autofree gchar **files = NULL;
1412 g_autoptr(PkFiles) item = NULL;
1413 g_variant_get (parameters,
1414 "(&s^a&s)",
1415 &tmp_str[0],
1416 &files);
1417 item = pk_files_new ();
1418 g_object_set (item,
1419 "package-id", tmp_str[0],
1420 "files", files,
1421 "role", state->role,
1422 "transaction-id", state->transaction_id,
1423 NULL);
1424 pk_results_add_files (state->results, item);
1425 return;
1426 }
1427 if (g_strcmp0 (signal_name, "RepoSignatureRequired") == 0) {
1428 g_autoptr(PkRepoSignatureRequired) item = NULL;
1429 g_variant_get (parameters,
1430 "(&s&s&s&s&s&s&su)",
1431 &tmp_str[0],
1432 &tmp_str[1],
1433 &tmp_str[2],
1434 &tmp_str[3],
1435 &tmp_str[4],
1436 &tmp_str[5],
1437 &tmp_str[6],
1438 &tmp_uint);
1439 item = pk_repo_signature_required_new ();
1440 g_object_set (item,
1441 "package-id", tmp_str[0],
1442 "repository-name", tmp_str[1],
1443 "key-url", tmp_str[2],
1444 "key-userid", tmp_str[3],
1445 "key-id", tmp_str[4],
1446 "key-fingerprint", tmp_str[5],
1447 "key-timestamp", tmp_str[6],
1448 "type", tmp_uint,
1449 "role", state->role,
1450 "transaction-id", state->transaction_id,
1451 NULL);
1452 pk_results_add_repo_signature_required (state->results, item);
1453 return;
1454 }
1455 if (g_strcmp0 (signal_name, "EulaRequired") == 0) {
1456 g_autoptr(PkEulaRequired) item = NULL;
1457 g_variant_get (parameters,
1458 "(&s&s&s&s)",
1459 &tmp_str[0],
1460 &tmp_str[1],
1461 &tmp_str[2],
1462 &tmp_str[3]);
1463 item = pk_eula_required_new ();
1464 g_object_set (item,
1465 "eula-id", tmp_str[0],
1466 "package-id", tmp_str[1],
1467 "vendor-name", tmp_str[2],
1468 "license-agreement", tmp_str[3],
1469 "role", state->role,
1470 "transaction-id", state->transaction_id,
1471 NULL);
1472 pk_results_add_eula_required (state->results, item);
1473 return;
1474 }
1475 if (g_strcmp0 (signal_name, "RepoDetail") == 0) {
1476 g_autoptr(PkRepoDetail) item = NULL;
1477 g_variant_get (parameters,
1478 "(&s&sb)",
1479 &tmp_str[0],
1480 &tmp_str[1],
1481 &tmp_bool);
1482 item = pk_repo_detail_new ();
1483 g_object_set (item,
1484 "repo-id", tmp_str[0],
1485 "description", tmp_str[1],
1486 "enabled", tmp_bool,
1487 "role", state->role,
1488 "transaction-id", state->transaction_id,
1489 NULL);
1490 pk_results_add_repo_detail (state->results, item);
1491 return;
1492 }
1493 if (g_strcmp0 (signal_name, "ErrorCode") == 0) {
1494 g_autoptr(PkError) item = NULL;
1495 g_variant_get (parameters,
1496 "(u&s)",
1497 &tmp_uint,
1498 &tmp_str[1]);
1499 item = pk_error_new ();
1500 g_object_set (item,
1501 "code", tmp_uint,
1502 "details", tmp_str[1],
1503 "role", state->role,
1504 "transaction-id", state->transaction_id,
1505 NULL);
1506 pk_results_set_error_code (state->results, item);
1507 return;
1508 }
1509 if (g_strcmp0 (signal_name, "MediaChangeRequired") == 0) {
1510 g_autoptr(PkMediaChangeRequired) item = NULL;
1511 g_variant_get (parameters,
1512 "(u&s&s)",
1513 &tmp_uint,
1514 &tmp_str[1],
1515 &tmp_str[2]);
1516 item = pk_media_change_required_new ();
1517 g_object_set (item,
1518 "media-type", tmp_uint,
1519 "media-id", tmp_str[1],
1520 "media-text", tmp_str[2],
1521 "role", state->role,
1522 "transaction-id", state->transaction_id,
1523 NULL);
1524 pk_results_add_media_change_required (state->results, item);
1525 return;
1526 }
1527 if (g_strcmp0 (signal_name, "ItemProgress") == 0) {
1528 g_autoptr(PkItemProgress) item = NULL;
1529 g_variant_get (parameters,
1530 "(&suu)",
1531 &tmp_str[0],
1532 &tmp_uint,
1533 &tmp_uint2);
1534 item = pk_item_progress_new ();
1535 g_object_set (item,
1536 "package-id", tmp_str[0],
1537 "status", tmp_uint,
1538 "percentage", tmp_uint2,
1539 "transaction-id", state->transaction_id,
1540 NULL);
1541 pk_progress_set_item_progress (state->progress, item);
1542 return;
1543 }
1544 if (g_strcmp0 (signal_name, "Destroy") == 0) {
1545 g_autoptr(GError) local_error = NULL;
1546
1547 if (state->waiting_for_finished) {
1548 local_error = g_error_new_literal (PK_CLIENT_ERROR, PK_CLIENT_ERROR_FAILED,
1549 "PackageKit transaction disappeared");
1550 pk_client_state_finish (state, g_steal_pointer (&local_error));
1551 }
1552 return;
1553 }
1554 }
1555
1556 static void
1557 pk_client_notify_name_owner_cb (GObject *obj,
1558 GParamSpec *pspec,
1559 gpointer user_data)
1560 {
1561 GWeakRef *weak_ref = user_data;
1562 g_autoptr(PkClientState) state = g_weak_ref_get (weak_ref);
1563
1564 if (!state)
1565 return;
1566
1567 if (state->waiting_for_finished) {
1568 g_autoptr(GError) local_error = NULL;
1569
1570 local_error = g_error_new_literal (PK_CLIENT_ERROR, PK_CLIENT_ERROR_FAILED,
1571 "PackageKit daemon disappeared");
1572 pk_client_state_finish (state, g_steal_pointer (&local_error));
1573 } else {
1574 pk_client_state_unset_proxy (state);
1575 g_cancellable_cancel (state->cancellable);
1576 }
1577 }
1578
1579 /*
1580 * pk_client_proxy_connect:
1581 **/
1582 static void
1583 pk_client_proxy_connect (PkClientState *state)
1584 {
1585 guint i;
1586 g_auto(GStrv) props = NULL;
1587
1588 /* coldplug properties */
1589 props = g_dbus_proxy_get_cached_property_names (state->proxy);
1590 for (i = 0; props != NULL && props[i] != NULL; i++) {
1591 g_autoptr(GVariant) value_tmp = NULL;
1592 value_tmp = g_dbus_proxy_get_cached_property (state->proxy,
1593 props[i]);
1594 pk_client_set_property_value (state,
1595 props[i],
1596 value_tmp);
1597 }
1598
1599 /* connect up signals */
1600 g_signal_connect_data (state->proxy, "g-properties-changed",
1601 G_CALLBACK (pk_client_properties_changed_cb),
1602 pk_client_weak_ref_new (state), pk_client_weak_ref_free_gclosure, 0);
1603 g_signal_connect_data (state->proxy, "g-signal",
1604 G_CALLBACK (pk_client_signal_cb),
1605 pk_client_weak_ref_new (state), pk_client_weak_ref_free_gclosure, 0);
1606 g_signal_connect_data (state->proxy, "notify::g-name-owner",
1607 G_CALLBACK (pk_client_notify_name_owner_cb),
1608 pk_client_weak_ref_new (state), pk_client_weak_ref_free_gclosure, 0);
1609 }
1610
1611 /*
1612 * pk_client_method_cb:
1613 **/
1614 static void
1615 pk_client_method_cb (GObject *source_object,
1616 GAsyncResult *res,
1617 gpointer user_data)
1618 {
1619 GDBusProxy *proxy = G_DBUS_PROXY (source_object);
1620 g_autoptr(PkClientState) state = PK_CLIENT_STATE (g_steal_pointer (&user_data));
1621 g_autoptr(GError) error = NULL;
1622 g_autoptr(GVariant) value = NULL;
1623
1624 /* get the result */
1625 value = g_dbus_proxy_call_finish (proxy, res, &error);
1626 if (value == NULL) {
1627 /* fix up the D-Bus error */
1628 pk_client_fixup_dbus_error (error);
1629 pk_client_state_finish (state, g_steal_pointer (&error));
1630 return;
1631 }
1632
1633 /* wait for ::Finished() or ::Destroy() or notify::g-name-owner (if the daemon disappears) */
1634 state->waiting_for_finished = TRUE;
1635 }
1636
1637 /*
1638 * pk_client_set_role:
1639 **/
1640 static void
1641 pk_client_set_role (PkClientState *state, PkRoleEnum role)
1642 {
1643 pk_progress_set_transaction_flags (state->progress,
1644 state->transaction_flags);
1645 pk_progress_set_role (state->progress, role);
1646 }
1647
1648 /*
1649 * pk_client_set_hints_cb:
1650 **/
1651 static void
1652 pk_client_set_hints_cb (GObject *source_object,
1653 GAsyncResult *res,
1654 gpointer user_data)
1655 {
1656 GDBusProxy *proxy = G_DBUS_PROXY (source_object);
1657 g_autoptr(PkClientState) state = PK_CLIENT_STATE (g_steal_pointer (&user_data));
1658 g_autoptr(GError) error = NULL;
1659 g_autoptr(GVariant) value = NULL;
1660
1661 /* get the result */
1662 value = g_dbus_proxy_call_finish (proxy, res, &error);
1663 if (value == NULL) {
1664 /* fix up the D-Bus error */
1665 pk_client_fixup_dbus_error (error);
1666 pk_client_state_finish (state, g_steal_pointer (&error));
1667 return;
1668 }
1669
1670 /* we'll have results from now on */
1671 state->results = pk_results_new ();
1672 g_object_set (state->results,
1673 "role", state->role,
1674 "progress", state->progress,
1675 "transaction-flags", state->transaction_flags,
1676 NULL);
1677
1678 /* do this async, although this should be pretty fast anyway */
1679 if (state->role == PK_ROLE_ENUM_RESOLVE) {
1680 g_dbus_proxy_call (state->proxy, "Resolve",
1681 g_variant_new ("(t^a&s)",
1682 state->filters,
1683 state->package_ids),
1684 G_DBUS_CALL_FLAGS_NONE,
1685 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1686 state->cancellable,
1687 pk_client_method_cb,
1688 g_object_ref (state));
1689 g_object_set (state->results,
1690 "inputs", g_strv_length (state->package_ids),
1691 NULL);
1692 } else if (state->role == PK_ROLE_ENUM_SEARCH_NAME) {
1693 g_dbus_proxy_call (state->proxy, "SearchNames",
1694 g_variant_new ("(t^a&s)",
1695 state->filters,
1696 state->search),
1697 G_DBUS_CALL_FLAGS_NONE,
1698 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1699 state->cancellable,
1700 pk_client_method_cb,
1701 g_object_ref (state));
1702 } else if (state->role == PK_ROLE_ENUM_SEARCH_DETAILS) {
1703 g_dbus_proxy_call (state->proxy, "SearchDetails",
1704 g_variant_new ("(t^a&s)",
1705 state->filters,
1706 state->search),
1707 G_DBUS_CALL_FLAGS_NONE,
1708 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1709 state->cancellable,
1710 pk_client_method_cb,
1711 g_object_ref (state));
1712 } else if (state->role == PK_ROLE_ENUM_SEARCH_GROUP) {
1713 g_dbus_proxy_call (state->proxy, "SearchGroups",
1714 g_variant_new ("(t^a&s)",
1715 state->filters,
1716 state->search),
1717 G_DBUS_CALL_FLAGS_NONE,
1718 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1719 state->cancellable,
1720 pk_client_method_cb,
1721 g_object_ref (state));
1722 } else if (state->role == PK_ROLE_ENUM_SEARCH_FILE) {
1723 g_dbus_proxy_call (state->proxy, "SearchFiles",
1724 g_variant_new ("(t^a&s)",
1725 state->filters,
1726 state->search),
1727 G_DBUS_CALL_FLAGS_NONE,
1728 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1729 state->cancellable,
1730 pk_client_method_cb,
1731 g_object_ref (state));
1732 } else if (state->role == PK_ROLE_ENUM_GET_DETAILS) {
1733 g_dbus_proxy_call (state->proxy, "GetDetails",
1734 g_variant_new ("(^a&s)",
1735 state->package_ids),
1736 G_DBUS_CALL_FLAGS_NONE,
1737 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1738 state->cancellable,
1739 pk_client_method_cb,
1740 g_object_ref (state));
1741 g_object_set (state->results,
1742 "inputs", g_strv_length (state->package_ids),
1743 NULL);
1744 } else if (state->role == PK_ROLE_ENUM_GET_DETAILS_LOCAL) {
1745 g_dbus_proxy_call (state->proxy, "GetDetailsLocal",
1746 g_variant_new ("(^a&s)",
1747 state->files),
1748 G_DBUS_CALL_FLAGS_NONE,
1749 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1750 state->cancellable,
1751 pk_client_method_cb,
1752 g_object_ref (state));
1753 g_object_set (state->results,
1754 "inputs", g_strv_length (state->files),
1755 NULL);
1756 } else if (state->role == PK_ROLE_ENUM_GET_FILES_LOCAL) {
1757 g_dbus_proxy_call (state->proxy, "GetFilesLocal",
1758 g_variant_new ("(^a&s)",
1759 state->files),
1760 G_DBUS_CALL_FLAGS_NONE,
1761 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1762 state->cancellable,
1763 pk_client_method_cb,
1764 g_object_ref (state));
1765 g_object_set (state->results,
1766 "inputs", g_strv_length (state->files),
1767 NULL);
1768 } else if (state->role == PK_ROLE_ENUM_GET_UPDATE_DETAIL) {
1769 g_dbus_proxy_call (state->proxy, "GetUpdateDetail",
1770 g_variant_new ("(^a&s)",
1771 state->package_ids),
1772 G_DBUS_CALL_FLAGS_NONE,
1773 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1774 state->cancellable,
1775 pk_client_method_cb,
1776 g_object_ref (state));
1777 g_object_set (state->results,
1778 "inputs", g_strv_length (state->package_ids),
1779 NULL);
1780 } else if (state->role == PK_ROLE_ENUM_GET_OLD_TRANSACTIONS) {
1781 g_dbus_proxy_call (state->proxy, "GetOldTransactions",
1782 g_variant_new ("(u)",
1783 state->number),
1784 G_DBUS_CALL_FLAGS_NONE,
1785 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1786 state->cancellable,
1787 pk_client_method_cb,
1788 g_object_ref (state));
1789 } else if (state->role == PK_ROLE_ENUM_DOWNLOAD_PACKAGES) {
1790 g_dbus_proxy_call (state->proxy, "DownloadPackages",
1791 g_variant_new ("(b^a&s)",
1792 (state->directory == NULL),
1793 state->package_ids),
1794 G_DBUS_CALL_FLAGS_NONE,
1795 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1796 state->cancellable,
1797 pk_client_method_cb,
1798 g_object_ref (state));
1799 g_object_set (state->results,
1800 "inputs", g_strv_length (state->package_ids),
1801 NULL);
1802 } else if (state->role == PK_ROLE_ENUM_GET_UPDATES) {
1803 g_dbus_proxy_call (state->proxy, "GetUpdates",
1804 g_variant_new ("(t)",
1805 state->filters),
1806 G_DBUS_CALL_FLAGS_NONE,
1807 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1808 state->cancellable,
1809 pk_client_method_cb,
1810 g_object_ref (state));
1811 } else if (state->role == PK_ROLE_ENUM_DEPENDS_ON) {
1812 g_dbus_proxy_call (state->proxy, "DependsOn",
1813 g_variant_new ("(t^a&sb)",
1814 state->filters,
1815 state->package_ids,
1816 state->recursive),
1817 G_DBUS_CALL_FLAGS_NONE,
1818 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1819 state->cancellable,
1820 pk_client_method_cb,
1821 g_object_ref (state));
1822 g_object_set (state->results,
1823 "inputs", g_strv_length (state->package_ids),
1824 NULL);
1825
1826 } else if (state->role == PK_ROLE_ENUM_REQUIRED_BY) {
1827 g_dbus_proxy_call (state->proxy, "RequiredBy",
1828 g_variant_new ("(t^a&sb)",
1829 state->filters,
1830 state->package_ids,
1831 state->recursive),
1832 G_DBUS_CALL_FLAGS_NONE,
1833 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1834 state->cancellable,
1835 pk_client_method_cb,
1836 g_object_ref (state));
1837 g_object_set (state->results,
1838 "inputs", g_strv_length (state->package_ids),
1839 NULL);
1840 } else if (state->role == PK_ROLE_ENUM_GET_PACKAGES) {
1841 g_dbus_proxy_call (state->proxy, "GetPackages",
1842 g_variant_new ("(t)",
1843 state->filters),
1844 G_DBUS_CALL_FLAGS_NONE,
1845 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1846 state->cancellable,
1847 pk_client_method_cb,
1848 g_object_ref (state));
1849 } else if (state->role == PK_ROLE_ENUM_WHAT_PROVIDES) {
1850 g_dbus_proxy_call (state->proxy, "WhatProvides",
1851 g_variant_new ("(t^a&s)",
1852 state->filters,
1853 state->search),
1854 G_DBUS_CALL_FLAGS_NONE,
1855 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1856 state->cancellable,
1857 pk_client_method_cb,
1858 g_object_ref (state));
1859 } else if (state->role == PK_ROLE_ENUM_GET_DISTRO_UPGRADES) {
1860 g_dbus_proxy_call (state->proxy, "GetDistroUpgrades",
1861 NULL,
1862 G_DBUS_CALL_FLAGS_NONE,
1863 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1864 state->cancellable,
1865 pk_client_method_cb,
1866 g_object_ref (state));
1867 } else if (state->role == PK_ROLE_ENUM_GET_FILES) {
1868 g_dbus_proxy_call (state->proxy, "GetFiles",
1869 g_variant_new ("(^a&s)",
1870 state->package_ids),
1871 G_DBUS_CALL_FLAGS_NONE,
1872 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1873 state->cancellable,
1874 pk_client_method_cb,
1875 g_object_ref (state));
1876 g_object_set (state->results,
1877 "inputs", g_strv_length (state->package_ids),
1878 NULL);
1879 } else if (state->role == PK_ROLE_ENUM_GET_CATEGORIES) {
1880 g_dbus_proxy_call (state->proxy, "GetCategories",
1881 NULL,
1882 G_DBUS_CALL_FLAGS_NONE,
1883 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1884 state->cancellable,
1885 pk_client_method_cb,
1886 g_object_ref (state));
1887 } else if (state->role == PK_ROLE_ENUM_REMOVE_PACKAGES) {
1888 g_dbus_proxy_call (state->proxy, "RemovePackages",
1889 g_variant_new ("(t^a&sbb)",
1890 state->transaction_flags,
1891 state->package_ids,
1892 state->allow_deps,
1893 state->autoremove),
1894 G_DBUS_CALL_FLAGS_NONE,
1895 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1896 state->cancellable,
1897 pk_client_method_cb,
1898 g_object_ref (state));
1899 g_object_set (state->results,
1900 "inputs", g_strv_length (state->package_ids),
1901 NULL);
1902 } else if (state->role == PK_ROLE_ENUM_REFRESH_CACHE) {
1903 g_dbus_proxy_call (state->proxy, "RefreshCache",
1904 g_variant_new ("(b)",
1905 state->force),
1906 G_DBUS_CALL_FLAGS_NONE,
1907 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1908 state->cancellable,
1909 pk_client_method_cb,
1910 g_object_ref (state));
1911 } else if (state->role == PK_ROLE_ENUM_INSTALL_PACKAGES) {
1912 g_dbus_proxy_call (state->proxy, "InstallPackages",
1913 g_variant_new ("(t^a&s)",
1914 state->transaction_flags,
1915 state->package_ids),
1916 G_DBUS_CALL_FLAGS_NONE,
1917 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1918 state->cancellable,
1919 pk_client_method_cb,
1920 g_object_ref (state));
1921 g_object_set (state->results,
1922 "inputs", g_strv_length (state->package_ids),
1923 NULL);
1924 } else if (state->role == PK_ROLE_ENUM_INSTALL_SIGNATURE) {
1925 g_dbus_proxy_call (state->proxy, "InstallSignature",
1926 g_variant_new ("(uss)",
1927 state->type,
1928 state->key_id,
1929 state->package_id),
1930 G_DBUS_CALL_FLAGS_NONE,
1931 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1932 state->cancellable,
1933 pk_client_method_cb,
1934 g_object_ref (state));
1935 } else if (state->role == PK_ROLE_ENUM_UPDATE_PACKAGES) {
1936 g_dbus_proxy_call (state->proxy, "UpdatePackages",
1937 g_variant_new ("(t^a&s)",
1938 state->transaction_flags,
1939 state->package_ids),
1940 G_DBUS_CALL_FLAGS_NONE,
1941 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1942 state->cancellable,
1943 pk_client_method_cb,
1944 g_object_ref (state));
1945 g_object_set (state->results,
1946 "inputs", g_strv_length (state->package_ids),
1947 NULL);
1948 } else if (state->role == PK_ROLE_ENUM_INSTALL_FILES) {
1949 g_dbus_proxy_call (state->proxy, "InstallFiles",
1950 g_variant_new ("(t^a&s)",
1951 state->transaction_flags,
1952 state->files),
1953 G_DBUS_CALL_FLAGS_NONE,
1954 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1955 state->cancellable,
1956 pk_client_method_cb,
1957 g_object_ref (state));
1958 g_object_set (state->results,
1959 "inputs", g_strv_length (state->files),
1960 NULL);
1961 } else if (state->role == PK_ROLE_ENUM_ACCEPT_EULA) {
1962 g_dbus_proxy_call (state->proxy, "AcceptEula",
1963 g_variant_new ("(s)",
1964 state->eula_id),
1965 G_DBUS_CALL_FLAGS_NONE,
1966 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1967 state->cancellable,
1968 pk_client_method_cb,
1969 g_object_ref (state));
1970 } else if (state->role == PK_ROLE_ENUM_GET_REPO_LIST) {
1971 g_dbus_proxy_call (state->proxy, "GetRepoList",
1972 g_variant_new ("(t)",
1973 state->filters),
1974 G_DBUS_CALL_FLAGS_NONE,
1975 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1976 state->cancellable,
1977 pk_client_method_cb,
1978 g_object_ref (state));
1979 } else if (state->role == PK_ROLE_ENUM_REPO_ENABLE) {
1980 g_dbus_proxy_call (state->proxy, "RepoEnable",
1981 g_variant_new ("(sb)",
1982 state->repo_id,
1983 state->enabled),
1984 G_DBUS_CALL_FLAGS_NONE,
1985 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1986 state->cancellable,
1987 pk_client_method_cb,
1988 g_object_ref (state));
1989 } else if (state->role == PK_ROLE_ENUM_REPO_SET_DATA) {
1990 g_dbus_proxy_call (state->proxy, "RepoSetData",
1991 g_variant_new ("(sss)",
1992 state->repo_id,
1993 state->parameter ? state->parameter : "",
1994 state->value ? state->value : ""),
1995 G_DBUS_CALL_FLAGS_NONE,
1996 PK_CLIENT_DBUS_METHOD_TIMEOUT,
1997 state->cancellable,
1998 pk_client_method_cb,
1999 g_object_ref (state));
2000 } else if (state->role == PK_ROLE_ENUM_REPO_REMOVE) {
2001 g_dbus_proxy_call (state->proxy, "RepoRemove",
2002 g_variant_new ("(tsb)",
2003 state->transaction_flags,
2004 state->repo_id,
2005 state->autoremove),
2006 G_DBUS_CALL_FLAGS_NONE,
2007 PK_CLIENT_DBUS_METHOD_TIMEOUT,
2008 state->cancellable,
2009 pk_client_method_cb,
2010 g_object_ref (state));
2011 } else if (state->role == PK_ROLE_ENUM_UPGRADE_SYSTEM) {
2012 g_dbus_proxy_call (state->proxy, "UpgradeSystem",
2013 g_variant_new ("(tsu)",
2014 state->transaction_flags,
2015 state->distro_id,
2016 state->upgrade_kind),
2017 G_DBUS_CALL_FLAGS_NONE,
2018 PK_CLIENT_DBUS_METHOD_TIMEOUT,
2019 state->cancellable,
2020 pk_client_method_cb,
2021 g_object_ref (state));
2022 } else if (state->role == PK_ROLE_ENUM_REPAIR_SYSTEM) {
2023 g_dbus_proxy_call (state->proxy, "RepairSystem",
2024 g_variant_new ("(t)",
2025 state->transaction_flags),
2026 G_DBUS_CALL_FLAGS_NONE,
2027 PK_CLIENT_DBUS_METHOD_TIMEOUT,
2028 state->cancellable,
2029 pk_client_method_cb,
2030 g_object_ref (state));
2031 } else {
2032 g_assert_not_reached ();
2033 }
2034 }
2035
2036 /*
2037 * pk_client_bool_to_string:
2038 **/
2039 static const gchar *
2040 pk_client_bool_to_string (gboolean value)
2041 {
2042 if (value)
2043 return "true";
2044 return "false";
2045 }
2046
2047 /*
2048 * pk_client_create_helper_argv_envp_test:
2049 **/
2050 static gboolean
2051 pk_client_create_helper_argv_envp_test (PkClientState *state,
2052 gchar ***argv,
2053 gchar ***envp)
2054 {
2055 gboolean ret;
2056
2057 /* check we have the right file */
2058 ret = g_file_test (TESTDATADIR "/pk-client-helper-test.py",
2059 G_FILE_TEST_EXISTS);
2060 if (!ret) {
2061 g_warning ("could not find the socket helper!");
2062 return FALSE;
2063 }
2064
2065 /* setup simple test socket */
2066 *argv = g_new0 (gchar *, 2);
2067 *argv[0] = g_build_filename (TESTDATADIR,
2068 "pk-client-helper-test.py",
2069 NULL);
2070 return TRUE;
2071 }
2072
2073 /*
2074 * pk_client_create_helper_argv_envp:
2075 **/
2076 gboolean
2077 pk_client_create_helper_argv_envp (gchar ***argv,
2078 gchar ***envp_out)
2079 {
2080 const gchar *dialog = NULL;
2081 const gchar *display;
2082 const gchar *wayland_display;
2083 const gchar *xauthority;
2084 const gchar *term;
2085 const gchar *desktop;
2086 const gchar *lang;
2087 const gchar *language;
2088 gboolean ret;
2089 guint envpi = 0;
2090 gchar **envp;
2091
2092 /* check we have the right file */
2093 ret = g_file_test ("/usr/bin/debconf-communicate",
2094 G_FILE_TEST_EXISTS);
2095 if (!ret)
2096 return FALSE;
2097
2098 /* setup simple test socket */
2099 *argv = g_new0 (gchar *, 2);
2100 *argv[0] = g_strdup ("/usr/bin/debconf-communicate");
2101
2102 *envp_out = g_new0 (gchar *, 16);
2103 envp = *envp_out;
2104 envp[envpi++] = g_strdup ("DEBCONF_DB_REPLACE=configdb");
2105 envp[envpi++] = g_strdup ("DEBCONF_DB_OVERRIDE=Pipe{infd:none outfd:none}");
2106 if (pk_debug_is_verbose ())
2107 envp[envpi++] = g_strdup ("DEBCONF_DEBUG=.");
2108
2109 /* do we have an available terminal to use */
2110 term = g_getenv ("TERM");
2111 if (term != NULL) {
2112 envp[envpi++] = g_strdup_printf ("TERM=%s", term);
2113 dialog = "dialog";
2114 }
2115
2116 /* do we have access to the display */
2117 display = g_getenv ("DISPLAY");
2118 if (display != NULL) {
2119 envp[envpi++] = g_strdup_printf ("DISPLAY=%s", display);
2120 }
2121 xauthority = g_getenv ("XAUTHORITY");
2122 if (xauthority != NULL) {
2123 envp[envpi++] = g_strdup_printf ("XAUTHORITY=%s", xauthority);
2124 }
2125 wayland_display = g_getenv ("WAYLAND_DISPLAY");
2126 if (wayland_display != NULL) {
2127 envp[envpi++] = g_strdup_printf ("WAYLAND_DISPLAY=%s", wayland_display);
2128 envp[envpi++] = g_strdup_printf ("XDG_RUNTIME_DIR=%s", g_get_user_runtime_dir ());
2129 }
2130
2131 desktop = g_getenv ("XDG_SESSION_DESKTOP");
2132 if (display != NULL || wayland_display != NULL) {
2133 if (g_strcmp0 (desktop, "KDE") == 0 ||
2134 g_strcmp0 (g_getenv ("KDE_FULL_SESSION"), "true") == 0)
2135 dialog = "kde";
2136 else
2137 dialog = "gnome";
2138 }
2139
2140 if (desktop != NULL)
2141 envp[envpi++] = g_strdup_printf ("XDG_SESSION_DESKTOP=%s", desktop);
2142
2143 /* some Qt-based helpers need a config directory */
2144 envp[envpi++] = g_strdup_printf ("XDG_CONFIG_HOME=%s/config", g_get_user_runtime_dir ());
2145
2146 /* forward locale */
2147 lang = g_getenv ("LANG");
2148 if (lang != NULL)
2149 envp[envpi++] = g_strdup_printf ("LANG=%s", lang);
2150 language = g_getenv ("LANGUAGE");;
2151 if (language != NULL)
2152 envp[envpi++] = g_strdup_printf ("LANGUAGE=%s", language);
2153
2154 /* indicate a prefered frontend */
2155 if (dialog != NULL) {
2156 envp[envpi++] = g_strdup_printf ("DEBIAN_FRONTEND=%s", dialog);
2157 g_debug ("using frontend %s", dialog);
2158 }
2159 return TRUE;
2160 }
2161
2162 /*
2163 * pk_client_create_helper_socket:
2164 **/
2165 static gchar *
2166 pk_client_create_helper_socket (PkClientState *state)
2167 {
2168 gboolean ret = FALSE;
2169 g_autoptr(GError) error = NULL;
2170 g_autofree gchar *socket_filename = NULL;
2171 g_autofree gchar *socket_id = NULL;
2172 g_auto(GStrv) argv = NULL;
2173 g_auto(GStrv) envp = NULL;
2174
2175 /* use the test socket */
2176 if (g_getenv ("PK_SELF_TEST") != NULL) {
2177 ret = pk_client_create_helper_argv_envp_test (state,
2178 &argv,
2179 &envp);
2180 }
2181
2182 /* either the self test failed, or we're not in self test */
2183 if (!ret) {
2184 ret = pk_client_create_helper_argv_envp (&argv,
2185 &envp);
2186 }
2187
2188 /* no supported frontends available */
2189 if (!ret)
2190 return NULL;
2191
2192 /* This is not a specially handled debian frontend (current terminal or
2193 * the debconf-kde stuff, use a systemd-activated helper if available)
2194 */
2195 if (envp != NULL &&
2196 !g_strv_contains ((const gchar * const *) envp, "DEBIAN_FRONTEND=kde") &&
2197 !g_strv_contains ((const gchar * const *) envp, "DEBIAN_FRONTEND=dialog")) {
2198 g_autofree gchar *existing_socket_filename = g_build_filename (g_get_user_runtime_dir (), "pk-debconf-socket", NULL);
2199 if (g_file_test (existing_socket_filename, G_FILE_TEST_EXISTS))
2200 return g_strdup_printf ("frontend-socket=%s", existing_socket_filename);
2201 }
2202
2203 /* create object */
2204 state->client_helper = pk_client_helper_new ();
2205
2206 /* create socket to read from /tmp */
2207 socket_id = g_strdup_printf ("gpk-%s.socket", &state->tid[1]);
2208 socket_filename = g_build_filename (g_get_tmp_dir (), socket_id, NULL);
2209
2210 /* start the helper process */
2211 ret = pk_client_helper_start (state->client_helper, socket_filename, argv, envp, &error);
2212 if (!ret) {
2213 g_warning ("failed to open debconf socket: %s", error->message);
2214 return NULL;
2215 }
2216
2217 /* success */
2218 return g_strdup_printf ("frontend-socket=%s", socket_filename);
2219 }
2220
2221 /*
2222 * pk_client_get_proxy_cb:
2223 **/
2224 static void
2225 pk_client_get_proxy_cb (GObject *object,
2226 GAsyncResult *res,
2227 gpointer user_data)
2228 {
2229 gchar *hint;
2230 g_autoptr(PkClientState) state = PK_CLIENT_STATE (g_steal_pointer (&user_data));
2231 g_autoptr(GError) error = NULL;
2232 g_autoptr(GPtrArray) array = NULL;
2233 PkClientPrivate *priv = pk_client_get_instance_private (state->client);
2234
2235 state->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
2236 if (state->proxy == NULL)
2237 g_error ("Cannot connect to PackageKit on %s", state->tid);
2238
2239 /* connect */
2240 pk_client_proxy_connect (state);
2241
2242 /* get hints */
2243 array = g_ptr_array_new_with_free_func (g_free);
2244
2245 /* locale */
2246 if (priv->locale != NULL) {
2247 hint = g_strdup_printf ("locale=%s", priv->locale);
2248 g_ptr_array_add (array, hint);
2249 }
2250
2251 /* background */
2252 hint = g_strdup_printf ("background=%s",
2253 pk_client_bool_to_string (priv->background));
2254 g_ptr_array_add (array, hint);
2255
2256 /* interactive */
2257 hint = g_strdup_printf ("interactive=%s",
2258 pk_client_bool_to_string (priv->interactive));
2259 g_ptr_array_add (array, hint);
2260
2261 if (priv->details_with_deps_size &&
2262 state->role == PK_ROLE_ENUM_GET_DETAILS)
2263 g_ptr_array_add (array, g_strdup ("details-with-deps-size=true"));
2264
2265 /* cache-age */
2266 if (priv->cache_age > 0) {
2267 hint = g_strdup_printf ("cache-age=%u", priv->cache_age);
2268 g_ptr_array_add (array, hint);
2269 }
2270
2271 /* Always set the supports-plural-signals hint to get higher performance signals */
2272 g_ptr_array_add (array, g_strdup ("supports-plural-signals=true"));
2273
2274 /* create socket for roles that need interaction */
2275 if (state->role == PK_ROLE_ENUM_INSTALL_FILES ||
2276 state->role == PK_ROLE_ENUM_INSTALL_PACKAGES ||
2277 state->role == PK_ROLE_ENUM_REMOVE_PACKAGES ||
2278 state->role == PK_ROLE_ENUM_UPDATE_PACKAGES) {
2279 hint = pk_client_create_helper_socket (state);
2280 if (hint != NULL)
2281 g_ptr_array_add (array, hint);
2282 }
2283
2284 /* set hints */
2285 g_ptr_array_add (array, NULL);
2286 g_dbus_proxy_call (state->proxy, "SetHints",
2287 g_variant_new ("(^a&s)",
2288 array->pdata),
2289 G_DBUS_CALL_FLAGS_NONE,
2290 PK_CLIENT_DBUS_METHOD_TIMEOUT,
2291 state->cancellable,
2292 pk_client_set_hints_cb,
2293 g_object_ref (state));
2294 }
2295
2296 /*
2297 * pk_client_get_tid_cb:
2298 **/
2299 static void
2300 pk_client_get_tid_cb (GObject *object, GAsyncResult *res, gpointer user_data)
2301 {
2302 g_autoptr(PkClientState) state = PK_CLIENT_STATE (g_steal_pointer (&user_data));
2303 PkControl *control = PK_CONTROL (object);
2304 g_autoptr(GError) error = NULL;
2305
2306 state->tid = pk_control_get_tid_finish (control, res, &error);
2307 if (state->tid == NULL) {
2308 pk_client_state_finish (state, g_steal_pointer (&error));
2309 return;
2310 }
2311
2312 pk_progress_set_transaction_id (state->progress, state->tid);
2313
2314 /* get a connection to the transaction interface */
2315 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
2316 G_DBUS_PROXY_FLAGS_NONE,
2317 NULL,
2318 PK_DBUS_SERVICE,
2319 state->tid,
2320 PK_DBUS_INTERFACE_TRANSACTION,
2321 state->cancellable,
2322 pk_client_get_proxy_cb,
2323 g_object_ref (state));
2324 }
2325
2326 /**
2327 * pk_client_generic_finish:
2328 * @client: a valid #PkClient instance
2329 * @res: the #GAsyncResult
2330 * @error: A #GError or %NULL
2331 *
2332 * Gets the result from the asynchronous function.
2333 *
2334 * Return value: (transfer full): the #PkResults, or %NULL. Free with g_object_unref()
2335 *
2336 * Since: 0.5.2
2337 **/
2338 PkResults *
2339 pk_client_generic_finish (PkClient *client, GAsyncResult *res, GError **error)
2340 {
2341 g_return_val_if_fail (PK_IS_CLIENT (client), NULL);
2342 g_return_val_if_fail (G_IS_TASK (res), NULL);
2343 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
2344
2345 return g_task_propagate_pointer (G_TASK (res), error);
2346 }
2347
2348 /**
2349 * pk_client_resolve_async: (finish-func pk_client_generic_finish):
2350 * @client: a valid #PkClient instance
2351 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
2352 * @packages: (array zero-terminated=1): an array of package names to resolve, e.g. "gnome-system-tools"
2353 * @cancellable: a #GCancellable or %NULL
2354 * @progress_callback: (scope notified): the function to run when the progress changes
2355 * @progress_user_data: data to pass to @progress_callback
2356 * @callback_ready: the function to run on completion
2357 * @user_data: the data to pass to @callback_ready
2358 *
2359 * Resolve a package name into a @package_id. This can return installed and
2360 * available packages and allows you find out if a package is installed locally
2361 * or is available in a repository.
2362 *
2363 * Since: 0.5.2
2364 **/
2365 void
2366 pk_client_resolve_async (PkClient *client, PkBitfield filters, gchar **packages, GCancellable *cancellable,
2367 PkProgressCallback progress_callback, gpointer progress_user_data,
2368 GAsyncReadyCallback callback_ready, gpointer user_data)
2369 {
2370 PkClientPrivate *priv = GET_PRIVATE(client);
2371 g_autoptr(PkClientState) state = NULL;
2372 g_autoptr(GError) error = NULL;
2373
2374 g_return_if_fail (PK_IS_CLIENT (client));
2375 g_return_if_fail (callback_ready != NULL);
2376 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2377
2378 /* save state */
2379 state = pk_client_state_new (client, callback_ready, user_data, pk_client_resolve_async, PK_ROLE_ENUM_RESOLVE, cancellable);
2380 state->filters = filters;
2381 state->package_ids = g_strdupv (packages);
2382 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2383
2384 /* check not already cancelled */
2385 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2386 pk_client_state_finish (state, g_steal_pointer (&error));
2387 return;
2388 }
2389
2390 /* identify */
2391 pk_client_set_role (state, state->role);
2392
2393 /* get tid */
2394 pk_control_get_tid_async (priv->control,
2395 cancellable,
2396 (GAsyncReadyCallback) pk_client_get_tid_cb,
2397 g_steal_pointer (&state));
2398 }
2399
2400 /**
2401 * pk_client_search_names_async: (finish-func pk_client_generic_finish):
2402 * @client: a valid #PkClient instance
2403 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
2404 * @values: (array zero-terminated=1): free text to search for, for instance, "power"
2405 * @cancellable: a #GCancellable or %NULL
2406 * @progress_callback: (scope notified): the function to run when the progress changes
2407 * @progress_user_data: data to pass to @progress_callback
2408 * @callback_ready: the function to run on completion
2409 * @user_data: the data to pass to @callback_ready
2410 *
2411 * Search all the locally installed files and remote repositories for a package
2412 * that matches a specific name.
2413 *
2414 * Since: 0.5.5
2415 **/
2416 void
2417 pk_client_search_names_async (PkClient *client, PkBitfield filters, gchar **values, GCancellable *cancellable,
2418 PkProgressCallback progress_callback, gpointer progress_user_data,
2419 GAsyncReadyCallback callback_ready, gpointer user_data)
2420 {
2421 PkClientPrivate *priv = GET_PRIVATE(client);
2422 g_autoptr(PkClientState) state = NULL;
2423 g_autoptr(GError) error = NULL;
2424
2425 g_return_if_fail (PK_IS_CLIENT (client));
2426 g_return_if_fail (callback_ready != NULL);
2427 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2428
2429 /* save state */
2430 state = pk_client_state_new (client, callback_ready, user_data, pk_client_search_names_async, PK_ROLE_ENUM_SEARCH_NAME, cancellable);
2431 state->filters = filters;
2432 state->search = g_strdupv (values);
2433 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2434
2435 /* check not already cancelled */
2436 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2437 pk_client_state_finish (state, g_steal_pointer (&error));
2438 return;
2439 }
2440
2441 /* identify */
2442 pk_client_set_role (state, state->role);
2443
2444 /* get tid */
2445 pk_control_get_tid_async (priv->control,
2446 cancellable,
2447 (GAsyncReadyCallback) pk_client_get_tid_cb,
2448 g_steal_pointer (&state));
2449 }
2450
2451 /**
2452 * pk_client_search_details_async: (finish-func pk_client_generic_finish):
2453 * @client: a valid #PkClient instance
2454 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
2455 * @values: (array zero-terminated=1): free text to search for, for instance, "power"
2456 * @cancellable: a #GCancellable or %NULL
2457 * @progress_callback: (scope notified): the function to run when the progress changes
2458 * @progress_user_data: data to pass to @progress_callback
2459 * @callback_ready: the function to run on completion
2460 * @user_data: the data to pass to @callback_ready
2461 *
2462 * Search all detailed summary information to try and find a keyword.
2463 * Think of this as pk_client_search_names(), but trying much harder and
2464 * taking longer.
2465 *
2466 * Since: 0.5.5
2467 **/
2468 void
2469 pk_client_search_details_async (PkClient *client, PkBitfield filters, gchar **values, GCancellable *cancellable,
2470 PkProgressCallback progress_callback, gpointer progress_user_data,
2471 GAsyncReadyCallback callback_ready, gpointer user_data)
2472 {
2473 PkClientPrivate *priv = GET_PRIVATE(client);
2474 g_autoptr(PkClientState) state = NULL;
2475 g_autoptr(GError) error = NULL;
2476
2477 g_return_if_fail (PK_IS_CLIENT (client));
2478 g_return_if_fail (callback_ready != NULL);
2479 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2480
2481 /* save state */
2482 state = pk_client_state_new (client, callback_ready, user_data, pk_client_search_details_async, PK_ROLE_ENUM_SEARCH_DETAILS, cancellable);
2483 state->filters = filters;
2484 state->search = g_strdupv (values);
2485 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2486
2487 /* check not already cancelled */
2488 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2489 pk_client_state_finish (state, g_steal_pointer (&error));
2490 return;
2491 }
2492
2493 /* identify */
2494 pk_client_set_role (state, state->role);
2495
2496 /* get tid */
2497 pk_control_get_tid_async (priv->control,
2498 cancellable,
2499 (GAsyncReadyCallback) pk_client_get_tid_cb,
2500 g_steal_pointer (&state));
2501 }
2502
2503 /**
2504 * pk_client_search_groups_async: (finish-func pk_client_generic_finish):
2505 * @client: a valid #PkClient instance
2506 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
2507 * @values: (array zero-terminated=1): a group enum to search for, for instance, "system-tools"
2508 * @cancellable: a #GCancellable or %NULL
2509 * @progress_callback: (scope notified): the function to run when the progress changes
2510 * @progress_user_data: data to pass to @progress_callback
2511 * @callback_ready: the function to run on completion
2512 * @user_data: the data to pass to @callback_ready
2513 *
2514 * Return all packages in a specific group.
2515 *
2516 * Since: 0.5.5
2517 **/
2518 void
2519 pk_client_search_groups_async (PkClient *client, PkBitfield filters, gchar **values, GCancellable *cancellable,
2520 PkProgressCallback progress_callback, gpointer progress_user_data,
2521 GAsyncReadyCallback callback_ready, gpointer user_data)
2522 {
2523 PkClientPrivate *priv = GET_PRIVATE(client);
2524 g_autoptr(PkClientState) state = NULL;
2525 g_autoptr(GError) error = NULL;
2526
2527 g_return_if_fail (PK_IS_CLIENT (client));
2528 g_return_if_fail (callback_ready != NULL);
2529 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2530
2531 /* save state */
2532 state = pk_client_state_new (client, callback_ready, user_data, pk_client_search_groups_async, PK_ROLE_ENUM_SEARCH_GROUP, cancellable);
2533 state->filters = filters;
2534 state->search = g_strdupv (values);
2535 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2536
2537 /* check not already cancelled */
2538 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2539 pk_client_state_finish (state, g_steal_pointer (&error));
2540 return;
2541 }
2542
2543 /* identify */
2544 pk_client_set_role (state, state->role);
2545
2546 /* get tid */
2547 pk_control_get_tid_async (priv->control,
2548 cancellable,
2549 (GAsyncReadyCallback) pk_client_get_tid_cb,
2550 g_steal_pointer (&state));
2551 }
2552
2553 /**
2554 * pk_client_search_files_async: (finish-func pk_client_generic_finish):
2555 * @client: a valid #PkClient instance
2556 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
2557 * @values: (array zero-terminated=1): file to search for, for instance, "/sbin/service"
2558 * @cancellable: a #GCancellable or %NULL
2559 * @progress_callback: (scope notified): the function to run when the progress changes
2560 * @progress_user_data: data to pass to @progress_callback
2561 * @callback_ready: the function to run on completion
2562 * @user_data: the data to pass to @callback_ready
2563 *
2564 * Search for packages that provide a specific file.
2565 *
2566 * Since: 0.5.5
2567 **/
2568 void
2569 pk_client_search_files_async (PkClient *client, PkBitfield filters, gchar **values, GCancellable *cancellable,
2570 PkProgressCallback progress_callback, gpointer progress_user_data,
2571 GAsyncReadyCallback callback_ready, gpointer user_data)
2572 {
2573 PkClientPrivate *priv = GET_PRIVATE(client);
2574 g_autoptr(PkClientState) state = NULL;
2575 g_autoptr(GError) error = NULL;
2576
2577 g_return_if_fail (PK_IS_CLIENT (client));
2578 g_return_if_fail (callback_ready != NULL);
2579 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2580
2581 /* save state */
2582 state = pk_client_state_new (client, callback_ready, user_data, pk_client_search_files_async, PK_ROLE_ENUM_SEARCH_FILE, cancellable);
2583 state->filters = filters;
2584 state->search = g_strdupv (values);
2585 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2586
2587 /* check not already cancelled */
2588 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2589 pk_client_state_finish (state, g_steal_pointer (&error));
2590 return;
2591 }
2592
2593 /* identify */
2594 pk_client_set_role (state, state->role);
2595
2596 /* get tid */
2597 pk_control_get_tid_async (priv->control,
2598 cancellable,
2599 (GAsyncReadyCallback) pk_client_get_tid_cb,
2600 g_steal_pointer (&state));
2601 }
2602
2603 /**
2604 * pk_client_get_details_async: (finish-func pk_client_generic_finish):
2605 * @client: a valid #PkClient instance
2606 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
2607 * @cancellable: a #GCancellable or %NULL
2608 * @progress_callback: (scope notified): the function to run when the progress changes
2609 * @progress_user_data: data to pass to @progress_callback
2610 * @callback_ready: the function to run on completion
2611 * @user_data: the data to pass to @callback_ready
2612 *
2613 * Get details of a package, so more information can be obtained for GUI
2614 * or command line tools.
2615 *
2616 * Since: 0.5.2
2617 **/
2618 void
2619 pk_client_get_details_async (PkClient *client, gchar **package_ids, GCancellable *cancellable,
2620 PkProgressCallback progress_callback, gpointer progress_user_data,
2621 GAsyncReadyCallback callback_ready, gpointer user_data)
2622 {
2623 PkClientPrivate *priv = GET_PRIVATE(client);
2624 g_autoptr(PkClientState) state = NULL;
2625 g_autoptr(GError) error = NULL;
2626
2627 g_return_if_fail (PK_IS_CLIENT (client));
2628 g_return_if_fail (callback_ready != NULL);
2629 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2630 g_return_if_fail (package_ids != NULL);
2631
2632 /* save state */
2633 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_details_async, PK_ROLE_ENUM_GET_DETAILS, cancellable);
2634 state->package_ids = g_strdupv (package_ids);
2635 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2636
2637 /* check not already cancelled */
2638 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2639 pk_client_state_finish (state, g_steal_pointer (&error));
2640 return;
2641 }
2642
2643 /* identify */
2644 pk_client_set_role (state, state->role);
2645
2646 /* get tid */
2647 pk_control_get_tid_async (priv->control,
2648 cancellable,
2649 (GAsyncReadyCallback) pk_client_get_tid_cb,
2650 g_steal_pointer (&state));
2651 }
2652
2653 /**
2654 * pk_client_get_details_local_async: (finish-func pk_client_generic_finish):
2655 * @client: a valid #PkClient instance
2656 * @files: (array zero-terminated=1): a null terminated array of filenames
2657 * @cancellable: a #GCancellable or %NULL
2658 * @progress_callback: (scope notified): the function to run when the progress changes
2659 * @progress_user_data: data to pass to @progress_callback
2660 * @callback_ready: the function to run on completion
2661 * @user_data: the data to pass to @callback_ready
2662 *
2663 * Get details of a package, so more information can be obtained for GUI
2664 * or command line tools.
2665 *
2666 * Since: 0.8.17
2667 **/
2668 void
2669 pk_client_get_details_local_async (PkClient *client, gchar **files, GCancellable *cancellable,
2670 PkProgressCallback progress_callback, gpointer progress_user_data,
2671 GAsyncReadyCallback callback_ready, gpointer user_data)
2672 {
2673 PkClientPrivate *priv = GET_PRIVATE(client);
2674 g_autoptr(PkClientState) state = NULL;
2675 g_autoptr(GError) error = NULL;
2676
2677 g_return_if_fail (PK_IS_CLIENT (client));
2678 g_return_if_fail (callback_ready != NULL);
2679 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2680 g_return_if_fail (files != NULL);
2681
2682 /* save state */
2683 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_details_local_async, PK_ROLE_ENUM_GET_DETAILS_LOCAL, cancellable);
2684 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2685
2686 state->files = pk_client_convert_real_paths (files, &error);
2687 if (state->files == NULL) {
2688 pk_client_state_finish (state, g_steal_pointer (&error));
2689 return;
2690 }
2691
2692 /* check not already cancelled */
2693 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2694 pk_client_state_finish (state, g_steal_pointer (&error));
2695 return;
2696 }
2697
2698 /* identify */
2699 pk_client_set_role (state, state->role);
2700
2701 /* get tid */
2702 pk_control_get_tid_async (priv->control,
2703 cancellable,
2704 (GAsyncReadyCallback) pk_client_get_tid_cb,
2705 g_steal_pointer (&state));
2706 }
2707
2708 /**
2709 * pk_client_get_files_local_async: (finish-func pk_client_generic_finish):
2710 * @client: a valid #PkClient instance
2711 * @files: (array zero-terminated=1): a null terminated array of filenames
2712 * @cancellable: a #GCancellable or %NULL
2713 * @progress_callback: (scope notified): the function to run when the progress changes
2714 * @progress_user_data: data to pass to @progress_callback
2715 * @callback_ready: the function to run on completion
2716 * @user_data: the data to pass to @callback_ready
2717 *
2718 * Get file list of a package, so more information can be obtained for GUI
2719 * or command line tools.
2720 *
2721 * Since: 0.9.1
2722 **/
2723 void
2724 pk_client_get_files_local_async (PkClient *client, gchar **files, GCancellable *cancellable,
2725 PkProgressCallback progress_callback, gpointer progress_user_data,
2726 GAsyncReadyCallback callback_ready, gpointer user_data)
2727 {
2728 PkClientPrivate *priv = GET_PRIVATE(client);
2729 g_autoptr(PkClientState) state = NULL;
2730 g_autoptr(GError) error = NULL;
2731
2732 g_return_if_fail (PK_IS_CLIENT (client));
2733 g_return_if_fail (callback_ready != NULL);
2734 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2735 g_return_if_fail (files != NULL);
2736
2737 /* save state */
2738 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_files_local_async, PK_ROLE_ENUM_GET_FILES_LOCAL, cancellable);
2739 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2740 state->files = pk_client_convert_real_paths (files, &error);
2741 if (state->files == NULL) {
2742 pk_client_state_finish (state, g_steal_pointer (&error));
2743 return;
2744 }
2745
2746 /* check not already cancelled */
2747 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2748 pk_client_state_finish (state, g_steal_pointer (&error));
2749 return;
2750 }
2751
2752 /* identify */
2753 pk_client_set_role (state, state->role);
2754
2755 /* get tid */
2756 pk_control_get_tid_async (priv->control,
2757 cancellable,
2758 (GAsyncReadyCallback) pk_client_get_tid_cb,
2759 g_steal_pointer (&state));
2760 }
2761
2762 /**
2763 * pk_client_get_update_detail_async: (finish-func pk_client_generic_finish):
2764 * @client: a valid #PkClient instance
2765 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
2766 * @cancellable: a #GCancellable or %NULL
2767 * @progress_callback: (scope notified): the function to run when the progress changes
2768 * @progress_user_data: data to pass to @progress_callback
2769 * @callback_ready: the function to run on completion
2770 * @user_data: the data to pass to @callback_ready
2771 *
2772 * Get details about the specific update, for instance any CVE urls and
2773 * severity information.
2774 *
2775 * Since: 0.5.2
2776 **/
2777 void
2778 pk_client_get_update_detail_async (PkClient *client, gchar **package_ids, GCancellable *cancellable,
2779 PkProgressCallback progress_callback, gpointer progress_user_data,
2780 GAsyncReadyCallback callback_ready, gpointer user_data)
2781 {
2782 PkClientPrivate *priv = GET_PRIVATE(client);
2783 g_autoptr(PkClientState) state = NULL;
2784 g_autoptr(GError) error = NULL;
2785
2786 g_return_if_fail (PK_IS_CLIENT (client));
2787 g_return_if_fail (callback_ready != NULL);
2788 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2789 g_return_if_fail (package_ids != NULL);
2790
2791 /* save state */
2792 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_update_detail_async, PK_ROLE_ENUM_GET_UPDATE_DETAIL, cancellable);
2793 state->package_ids = g_strdupv (package_ids);
2794 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2795
2796 /* check not already cancelled */
2797 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2798 pk_client_state_finish (state, g_steal_pointer (&error));
2799 return;
2800 }
2801
2802 /* identify */
2803 pk_client_set_role (state, state->role);
2804
2805 /* get tid */
2806 pk_control_get_tid_async (priv->control,
2807 cancellable,
2808 (GAsyncReadyCallback) pk_client_get_tid_cb,
2809 g_steal_pointer (&state));
2810 }
2811
2812 /**
2813 * pk_client_download_packages_async: (finish-func pk_client_generic_finish):
2814 * @client: a valid #PkClient instance
2815 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
2816 * @directory: the location where packages are to be downloaded
2817 * @cancellable: a #GCancellable or %NULL
2818 * @progress_callback: (scope notified): the function to run when the progress changes
2819 * @progress_user_data: data to pass to @progress_callback
2820 * @callback_ready: the function to run on completion
2821 * @user_data: the data to pass to @callback_ready
2822 *
2823 * Downloads package files to a specified location.
2824 *
2825 * Since: 0.5.2
2826 **/
2827 void
2828 pk_client_download_packages_async (PkClient *client, gchar **package_ids, const gchar *directory, GCancellable *cancellable,
2829 PkProgressCallback progress_callback, gpointer progress_user_data,
2830 GAsyncReadyCallback callback_ready, gpointer user_data)
2831 {
2832 PkClientPrivate *priv = GET_PRIVATE(client);
2833 g_autoptr(PkClientState) state = NULL;
2834 g_autoptr(GError) error = NULL;
2835
2836 g_return_if_fail (PK_IS_CLIENT (client));
2837 g_return_if_fail (callback_ready != NULL);
2838 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2839 g_return_if_fail (package_ids != NULL);
2840
2841 /* save state */
2842 state = pk_client_state_new (client, callback_ready, user_data, pk_client_download_packages_async, PK_ROLE_ENUM_DOWNLOAD_PACKAGES, cancellable);
2843 state->package_ids = g_strdupv (package_ids);
2844 state->directory = g_strdup (directory);
2845 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2846
2847 /* check not already cancelled */
2848 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2849 pk_client_state_finish (state, g_steal_pointer (&error));
2850 return;
2851 }
2852
2853 /* identify */
2854 pk_client_set_role (state, state->role);
2855
2856 /* get tid */
2857 pk_control_get_tid_async (priv->control,
2858 cancellable,
2859 (GAsyncReadyCallback) pk_client_get_tid_cb,
2860 g_steal_pointer (&state));
2861 }
2862
2863 /**
2864 * pk_client_get_updates_async: (finish-func pk_client_generic_finish):
2865 * @client: a valid #PkClient instance
2866 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_DEVELOPMENT or %PK_FILTER_ENUM_NONE
2867 * @cancellable: a #GCancellable or %NULL
2868 * @progress_callback: (scope notified): the function to run when the progress changes
2869 * @progress_user_data: data to pass to @progress_callback
2870 * @callback_ready: the function to run on completion
2871 * @user_data: the data to pass to @callback_ready
2872 *
2873 * Get a list of all the packages that can be updated for all repositories.
2874 *
2875 * Since: 0.5.2
2876 **/
2877 void
2878 pk_client_get_updates_async (PkClient *client, PkBitfield filters, GCancellable *cancellable,
2879 PkProgressCallback progress_callback, gpointer progress_user_data,
2880 GAsyncReadyCallback callback_ready, gpointer user_data)
2881 {
2882 PkClientPrivate *priv = GET_PRIVATE(client);
2883 g_autoptr(PkClientState) state = NULL;
2884 g_autoptr(GError) error = NULL;
2885
2886 g_return_if_fail (PK_IS_CLIENT (client));
2887 g_return_if_fail (callback_ready != NULL);
2888 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2889
2890 /* save state */
2891 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_updates_async, PK_ROLE_ENUM_GET_UPDATES, cancellable);
2892 state->filters = filters;
2893 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2894
2895 /* check not already cancelled */
2896 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2897 pk_client_state_finish (state, g_steal_pointer (&error));
2898 return;
2899 }
2900
2901 /* identify */
2902 pk_client_set_role (state, state->role);
2903
2904 /* get tid */
2905 pk_control_get_tid_async (priv->control,
2906 cancellable,
2907 (GAsyncReadyCallback) pk_client_get_tid_cb,
2908 g_steal_pointer (&state));
2909 }
2910
2911 /**
2912 * pk_client_get_old_transactions_async: (finish-func pk_client_generic_finish):
2913 * @client: a valid #PkClient instance
2914 * @number: the number of past transactions to return, or 0 for all
2915 * @cancellable: a #GCancellable or %NULL
2916 * @progress_callback: (scope notified): the function to run when the progress changes
2917 * @progress_user_data: data to pass to @progress_callback
2918 * @callback_ready: the function to run on completion
2919 * @user_data: the data to pass to @callback_ready
2920 *
2921 * Get the old transaction list, mainly used for the transaction viewer.
2922 *
2923 * Since: 0.5.2
2924 **/
2925 void
2926 pk_client_get_old_transactions_async (PkClient *client, guint number, GCancellable *cancellable,
2927 PkProgressCallback progress_callback, gpointer progress_user_data,
2928 GAsyncReadyCallback callback_ready, gpointer user_data)
2929 {
2930 PkClientPrivate *priv = GET_PRIVATE(client);
2931 g_autoptr(PkClientState) state = NULL;
2932 g_autoptr(GError) error = NULL;
2933
2934 g_return_if_fail (PK_IS_CLIENT (client));
2935 g_return_if_fail (callback_ready != NULL);
2936 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2937
2938 /* save state */
2939 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_old_transactions_async, PK_ROLE_ENUM_GET_OLD_TRANSACTIONS, cancellable);
2940 state->number = number;
2941 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2942
2943 /* check not already cancelled */
2944 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2945 pk_client_state_finish (state, g_steal_pointer (&error));
2946 return;
2947 }
2948
2949 /* identify */
2950 pk_client_set_role (state, state->role);
2951
2952 /* get tid */
2953 pk_control_get_tid_async (priv->control,
2954 cancellable,
2955 (GAsyncReadyCallback) pk_client_get_tid_cb,
2956 g_steal_pointer (&state));
2957 }
2958
2959 /**
2960 * pk_client_depends_on_async: (finish-func pk_client_generic_finish):
2961 * @client: a valid #PkClient instance
2962 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
2963 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
2964 * @recursive: If we should search recursively for depends
2965 * @cancellable: a #GCancellable or %NULL
2966 * @progress_callback: (scope notified): the function to run when the progress changes
2967 * @progress_user_data: data to pass to @progress_callback
2968 * @callback_ready: the function to run on completion
2969 * @user_data: the data to pass to @callback_ready
2970 *
2971 * Get the packages that depend this one, i.e. child->parent.
2972 *
2973 * Since: 0.5.2
2974 **/
2975 void
2976 pk_client_depends_on_async (PkClient *client, PkBitfield filters, gchar **package_ids, gboolean recursive, GCancellable *cancellable,
2977 PkProgressCallback progress_callback, gpointer progress_user_data,
2978 GAsyncReadyCallback callback_ready, gpointer user_data)
2979 {
2980 PkClientPrivate *priv = GET_PRIVATE(client);
2981 g_autoptr(PkClientState) state = NULL;
2982 g_autoptr(GError) error = NULL;
2983
2984 g_return_if_fail (PK_IS_CLIENT (client));
2985 g_return_if_fail (callback_ready != NULL);
2986 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
2987 g_return_if_fail (package_ids != NULL);
2988
2989 /* save state */
2990 state = pk_client_state_new (client, callback_ready, user_data, pk_client_depends_on_async, PK_ROLE_ENUM_DEPENDS_ON, cancellable);
2991 state->filters = filters;
2992 state->recursive = recursive;
2993 state->package_ids = g_strdupv (package_ids);
2994 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
2995
2996 /* check not already cancelled */
2997 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
2998 pk_client_state_finish (state, g_steal_pointer (&error));
2999 return;
3000 }
3001
3002 /* identify */
3003 pk_client_set_role (state, state->role);
3004
3005 /* get tid */
3006 pk_control_get_tid_async (priv->control,
3007 cancellable,
3008 (GAsyncReadyCallback) pk_client_get_tid_cb,
3009 g_steal_pointer (&state));
3010 }
3011
3012 /**
3013 * pk_client_get_packages_async: (finish-func pk_client_generic_finish):
3014 * @client: a valid #PkClient instance
3015 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
3016 * @cancellable: a #GCancellable or %NULL
3017 * @progress_callback: (scope notified): the function to run when the progress changes
3018 * @progress_user_data: data to pass to @progress_callback
3019 * @callback_ready: the function to run on completion
3020 * @user_data: the data to pass to @callback_ready
3021 *
3022 * Get the list of packages from the backend
3023 *
3024 * Since: 0.5.2
3025 **/
3026 void
3027 pk_client_get_packages_async (PkClient *client, PkBitfield filters, GCancellable *cancellable,
3028 PkProgressCallback progress_callback, gpointer progress_user_data,
3029 GAsyncReadyCallback callback_ready, gpointer user_data)
3030 {
3031 PkClientPrivate *priv = GET_PRIVATE(client);
3032 g_autoptr(PkClientState) state = NULL;
3033 g_autoptr(GError) error = NULL;
3034
3035 g_return_if_fail (PK_IS_CLIENT (client));
3036 g_return_if_fail (callback_ready != NULL);
3037 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3038
3039 /* save state */
3040 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_packages_async, PK_ROLE_ENUM_GET_PACKAGES, cancellable);
3041 state->filters = filters;
3042 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3043
3044 /* check not already cancelled */
3045 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3046 pk_client_state_finish (state, g_steal_pointer (&error));
3047 return;
3048 }
3049
3050 /* identify */
3051 pk_client_set_role (state, state->role);
3052
3053 /* get tid */
3054 pk_control_get_tid_async (priv->control,
3055 cancellable,
3056 (GAsyncReadyCallback) pk_client_get_tid_cb,
3057 g_steal_pointer (&state));
3058 }
3059
3060 /**
3061 * pk_client_required_by_async: (finish-func pk_client_generic_finish):
3062 * @client: a valid #PkClient instance
3063 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
3064 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
3065 * @recursive: If we should search recursively for requires
3066 * @cancellable: a #GCancellable or %NULL
3067 * @progress_callback: (scope notified): the function to run when the progress changes
3068 * @progress_user_data: data to pass to @progress_callback
3069 * @callback_ready: the function to run on completion
3070 * @user_data: the data to pass to @callback_ready
3071 *
3072 * Get the packages that require this one, i.e. parent->child.
3073 *
3074 * Since: 0.5.2
3075 **/
3076 void
3077 pk_client_required_by_async (PkClient *client, PkBitfield filters, gchar **package_ids, gboolean recursive, GCancellable *cancellable,
3078 PkProgressCallback progress_callback, gpointer progress_user_data,
3079 GAsyncReadyCallback callback_ready, gpointer user_data)
3080 {
3081 PkClientPrivate *priv = GET_PRIVATE(client);
3082 g_autoptr(PkClientState) state = NULL;
3083 g_autoptr(GError) error = NULL;
3084
3085 g_return_if_fail (PK_IS_CLIENT (client));
3086 g_return_if_fail (callback_ready != NULL);
3087 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3088 g_return_if_fail (package_ids != NULL);
3089
3090 /* save state */
3091 state = pk_client_state_new (client, callback_ready, user_data, pk_client_required_by_async, PK_ROLE_ENUM_REQUIRED_BY, cancellable);
3092 state->recursive = recursive;
3093 state->filters = filters;
3094 state->package_ids = g_strdupv (package_ids);
3095 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3096
3097 /* check not already cancelled */
3098 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3099 pk_client_state_finish (state, g_steal_pointer (&error));
3100 return;
3101 }
3102
3103 /* identify */
3104 pk_client_set_role (state, state->role);
3105
3106 /* get tid */
3107 pk_control_get_tid_async (priv->control,
3108 cancellable,
3109 (GAsyncReadyCallback) pk_client_get_tid_cb,
3110 g_steal_pointer (&state));
3111 }
3112
3113 /**
3114 * pk_client_what_provides_async: (finish-func pk_client_generic_finish):
3115 * @client: a valid #PkClient instance
3116 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_GUI | %PK_FILTER_ENUM_FREE or %PK_FILTER_ENUM_NONE
3117 * @values: (array zero-terminated=1): a search term such as "sound/mp3"
3118 * @cancellable: a #GCancellable or %NULL
3119 * @progress_callback: (scope notified): the function to run when the progress changes
3120 * @progress_user_data: data to pass to @progress_callback
3121 * @callback_ready: the function to run on completion
3122 * @user_data: the data to pass to @callback_ready
3123 *
3124 * This should return packages that provide the supplied attributes.
3125 * This method is useful for finding out what package(s) provide a modalias
3126 * or GStreamer codec string.
3127 *
3128 * Since: 0.5.2
3129 **/
3130 void
3131 pk_client_what_provides_async (PkClient *client,
3132 PkBitfield filters,
3133 gchar **values,
3134 GCancellable *cancellable,
3135 PkProgressCallback progress_callback, gpointer progress_user_data,
3136 GAsyncReadyCallback callback_ready, gpointer user_data)
3137 {
3138 PkClientPrivate *priv = GET_PRIVATE(client);
3139 g_autoptr(PkClientState) state = NULL;
3140 g_autoptr(GError) error = NULL;
3141
3142 g_return_if_fail (PK_IS_CLIENT (client));
3143 g_return_if_fail (callback_ready != NULL);
3144 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3145
3146 /* save state */
3147 state = pk_client_state_new (client, callback_ready, user_data, pk_client_what_provides_async, PK_ROLE_ENUM_WHAT_PROVIDES, cancellable);
3148 state->filters = filters;
3149 state->search = g_strdupv (values);
3150 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3151
3152 /* check not already cancelled */
3153 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3154 pk_client_state_finish (state, g_steal_pointer (&error));
3155 return;
3156 }
3157
3158 /* identify */
3159 pk_client_set_role (state, state->role);
3160
3161 /* get tid */
3162 pk_control_get_tid_async (priv->control,
3163 cancellable,
3164 (GAsyncReadyCallback) pk_client_get_tid_cb,
3165 g_steal_pointer (&state));
3166 }
3167
3168 /**
3169 * pk_client_get_distro_upgrades_async: (finish-func pk_client_generic_finish):
3170 * @client: a valid #PkClient instance
3171 * @cancellable: a #GCancellable or %NULL
3172 * @progress_callback: (scope notified): the function to run when the progress changes
3173 * @progress_user_data: data to pass to @progress_callback
3174 * @callback_ready: the function to run on completion
3175 * @user_data: the data to pass to @callback_ready
3176 *
3177 * This method should return a list of distribution upgrades that are available.
3178 * It should not return updates, only major upgrades.
3179 *
3180 * Since: 0.5.2
3181 **/
3182 void
3183 pk_client_get_distro_upgrades_async (PkClient *client, GCancellable *cancellable,
3184 PkProgressCallback progress_callback, gpointer progress_user_data,
3185 GAsyncReadyCallback callback_ready, gpointer user_data)
3186 {
3187 PkClientPrivate *priv = GET_PRIVATE(client);
3188 g_autoptr(PkClientState) state = NULL;
3189 g_autoptr(GError) error = NULL;
3190
3191 g_return_if_fail (PK_IS_CLIENT (client));
3192 g_return_if_fail (callback_ready != NULL);
3193 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3194
3195 /* save state */
3196 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_distro_upgrades_async, PK_ROLE_ENUM_GET_DISTRO_UPGRADES, cancellable);
3197 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3198
3199 /* check not already cancelled */
3200 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3201 pk_client_state_finish (state, g_steal_pointer (&error));
3202 return;
3203 }
3204
3205 /* identify */
3206 pk_client_set_role (state, state->role);
3207
3208 /* get tid */
3209 pk_control_get_tid_async (priv->control,
3210 cancellable,
3211 (GAsyncReadyCallback) pk_client_get_tid_cb,
3212 g_steal_pointer (&state));
3213 }
3214
3215 /**
3216 * pk_client_get_files_async: (finish-func pk_client_generic_finish):
3217 * @client: a valid #PkClient instance
3218 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
3219 * @cancellable: a #GCancellable or %NULL
3220 * @progress_callback: (scope notified): the function to run when the progress changes
3221 * @progress_user_data: data to pass to @progress_callback
3222 * @callback_ready: the function to run on completion
3223 * @user_data: the data to pass to @callback_ready
3224 *
3225 * Get the file list (i.e. a list of files installed) for the specified package.
3226 *
3227 * Since: 0.5.2
3228 **/
3229 void
3230 pk_client_get_files_async (PkClient *client, gchar **package_ids, GCancellable *cancellable,
3231 PkProgressCallback progress_callback, gpointer progress_user_data,
3232 GAsyncReadyCallback callback_ready, gpointer user_data)
3233 {
3234 PkClientPrivate *priv = GET_PRIVATE(client);
3235 g_autoptr(PkClientState) state = NULL;
3236 g_autoptr(GError) error = NULL;
3237
3238 g_return_if_fail (PK_IS_CLIENT (client));
3239 g_return_if_fail (callback_ready != NULL);
3240 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3241 g_return_if_fail (package_ids != NULL);
3242
3243 /* save state */
3244 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_files_async, PK_ROLE_ENUM_GET_FILES, cancellable);
3245 state->package_ids = g_strdupv (package_ids);
3246 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3247
3248 /* check not already cancelled */
3249 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3250 pk_client_state_finish (state, g_steal_pointer (&error));
3251 return;
3252 }
3253
3254 /* identify */
3255 pk_client_set_role (state, state->role);
3256
3257 /* get tid */
3258 pk_control_get_tid_async (priv->control,
3259 cancellable,
3260 (GAsyncReadyCallback) pk_client_get_tid_cb,
3261 g_steal_pointer (&state));
3262 }
3263
3264 /**
3265 * pk_client_get_categories_async: (finish-func pk_client_generic_finish):
3266 * @client: a valid #PkClient instance
3267 * @cancellable: a #GCancellable or %NULL
3268 * @progress_callback: (scope notified): the function to run when the progress changes
3269 * @progress_user_data: data to pass to @progress_callback
3270 * @callback_ready: the function to run on completion
3271 * @user_data: the data to pass to @callback_ready
3272 *
3273 * Get a list of all categories supported.
3274 *
3275 * Since: 0.5.2
3276 **/
3277 void
3278 pk_client_get_categories_async (PkClient *client, GCancellable *cancellable,
3279 PkProgressCallback progress_callback, gpointer progress_user_data,
3280 GAsyncReadyCallback callback_ready, gpointer user_data)
3281 {
3282 PkClientPrivate *priv = GET_PRIVATE(client);
3283 g_autoptr(PkClientState) state = NULL;
3284 g_autoptr(GError) error = NULL;
3285
3286 g_return_if_fail (PK_IS_CLIENT (client));
3287 g_return_if_fail (callback_ready != NULL);
3288 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3289
3290 /* save state */
3291 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_categories_async, PK_ROLE_ENUM_GET_CATEGORIES, cancellable);
3292 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3293
3294 /* check not already cancelled */
3295 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3296 pk_client_state_finish (state, g_steal_pointer (&error));
3297 return;
3298 }
3299
3300 /* identify */
3301 pk_client_set_role (state, state->role);
3302
3303 /* get tid */
3304 pk_control_get_tid_async (priv->control,
3305 cancellable,
3306 (GAsyncReadyCallback) pk_client_get_tid_cb,
3307 g_steal_pointer (&state));
3308 }
3309
3310 /**
3311 * pk_client_remove_packages_async: (finish-func pk_client_generic_finish):
3312 * @client: a valid #PkClient instance
3313 * @transaction_flags: a transaction type bitfield
3314 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
3315 * @allow_deps: if other dependent packages are allowed to be removed from the computer
3316 * @autoremove: if other packages installed at the same time should be tried to remove
3317 * @cancellable: a #GCancellable or %NULL
3318 * @progress_callback: (scope notified): the function to run when the progress changes
3319 * @progress_user_data: data to pass to @progress_callback
3320 * @callback_ready: the function to run on completion
3321 * @user_data: the data to pass to @callback_ready
3322 *
3323 * Remove a package (optionally with dependancies) from the system.
3324 * If @allow_deps is set to %FALSE, and other packages would have to be removed,
3325 * then the transaction would fail.
3326 *
3327 * Since: 0.8.1
3328 **/
3329 void
3330 pk_client_remove_packages_async (PkClient *client,
3331 PkBitfield transaction_flags,
3332 gchar **package_ids,
3333 gboolean allow_deps,
3334 gboolean autoremove,
3335 GCancellable *cancellable,
3336 PkProgressCallback progress_callback,
3337 gpointer progress_user_data,
3338 GAsyncReadyCallback callback_ready,
3339 gpointer user_data)
3340 {
3341 PkClientPrivate *priv = GET_PRIVATE(client);
3342 g_autoptr(PkClientState) state = NULL;
3343 g_autoptr(GError) error = NULL;
3344
3345 g_return_if_fail (PK_IS_CLIENT (client));
3346 g_return_if_fail (callback_ready != NULL);
3347 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3348 g_return_if_fail (package_ids != NULL);
3349
3350 /* save state */
3351 state = pk_client_state_new (client, callback_ready, user_data, pk_client_remove_packages_async, PK_ROLE_ENUM_REMOVE_PACKAGES, cancellable);
3352 state->transaction_flags = transaction_flags;
3353 state->allow_deps = allow_deps;
3354 state->autoremove = autoremove;
3355 state->package_ids = g_strdupv (package_ids);
3356 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3357
3358 /* check not already cancelled */
3359 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3360 pk_client_state_finish (state, g_steal_pointer (&error));
3361 return;
3362 }
3363
3364 /* identify */
3365 pk_client_set_role (state, state->role);
3366
3367 /* get tid */
3368 pk_control_get_tid_async (priv->control,
3369 cancellable,
3370 (GAsyncReadyCallback) pk_client_get_tid_cb,
3371 g_steal_pointer (&state));
3372 }
3373
3374 /**
3375 * pk_client_refresh_cache_async: (finish-func pk_client_generic_finish):
3376 * @client: a valid #PkClient instance
3377 * @force: if we should aggressively drop caches
3378 * @cancellable: a #GCancellable or %NULL
3379 * @progress_callback: (scope notified): the function to run when the progress changes
3380 * @progress_user_data: data to pass to @progress_callback
3381 * @callback_ready: the function to run on completion
3382 * @user_data: the data to pass to @callback_ready
3383 *
3384 * Refresh the cache, i.e. download new metadata from a remote URL so that
3385 * package lists are up to date.
3386 * This action may take a few minutes and should be done when the session and
3387 * system are idle.
3388 *
3389 * Since: 0.5.2
3390 **/
3391 void
3392 pk_client_refresh_cache_async (PkClient *client, gboolean force, GCancellable *cancellable,
3393 PkProgressCallback progress_callback, gpointer progress_user_data,
3394 GAsyncReadyCallback callback_ready, gpointer user_data)
3395 {
3396 PkClientPrivate *priv = GET_PRIVATE(client);
3397 g_autoptr(PkClientState) state = NULL;
3398 g_autoptr(GError) error = NULL;
3399
3400 g_return_if_fail (PK_IS_CLIENT (client));
3401 g_return_if_fail (callback_ready != NULL);
3402 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3403
3404 /* save state */
3405 state = pk_client_state_new (client, callback_ready, user_data, pk_client_refresh_cache_async, PK_ROLE_ENUM_REFRESH_CACHE, cancellable);
3406 state->force = force;
3407 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3408
3409 /* check not already cancelled */
3410 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3411 pk_client_state_finish (state, g_steal_pointer (&error));
3412 return;
3413 }
3414
3415 /* identify */
3416 pk_client_set_role (state, state->role);
3417
3418 /* get tid */
3419 pk_control_get_tid_async (priv->control,
3420 cancellable,
3421 (GAsyncReadyCallback) pk_client_get_tid_cb,
3422 g_steal_pointer (&state));
3423 }
3424
3425 /**
3426 * pk_client_install_packages_async: (finish-func pk_client_generic_finish):
3427 * @client: a valid #PkClient instance
3428 * @transaction_flags: a transaction type bitfield
3429 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
3430 * @cancellable: a #GCancellable or %NULL
3431 * @progress_callback: (scope notified): the function to run when the progress changes
3432 * @progress_user_data: data to pass to @progress_callback
3433 * @callback_ready: the function to run on completion
3434 * @user_data: the data to pass to @callback_ready
3435 *
3436 * Install a package of the newest and most correct version.
3437 *
3438 * Since: 0.8.1
3439 **/
3440 void
3441 pk_client_install_packages_async (PkClient *client, PkBitfield transaction_flags, gchar **package_ids, GCancellable *cancellable,
3442 PkProgressCallback progress_callback, gpointer progress_user_data,
3443 GAsyncReadyCallback callback_ready, gpointer user_data)
3444 {
3445 PkClientPrivate *priv = GET_PRIVATE(client);
3446 g_autoptr(PkClientState) state = NULL;
3447 g_autoptr(GError) error = NULL;
3448
3449 g_return_if_fail (PK_IS_CLIENT (client));
3450 g_return_if_fail (callback_ready != NULL);
3451 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3452 g_return_if_fail (package_ids != NULL);
3453
3454 /* save state */
3455 state = pk_client_state_new (client, callback_ready, user_data, pk_client_install_packages_async, PK_ROLE_ENUM_INSTALL_PACKAGES, cancellable);
3456 state->transaction_flags = transaction_flags;
3457 state->package_ids = g_strdupv (package_ids);
3458 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3459
3460 /* check not already cancelled */
3461 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3462 pk_client_state_finish (state, g_steal_pointer (&error));
3463 return;
3464 }
3465
3466 /* identify */
3467 pk_client_set_role (state, state->role);
3468
3469 /* get tid */
3470 pk_control_get_tid_async (priv->control,
3471 cancellable,
3472 (GAsyncReadyCallback) pk_client_get_tid_cb,
3473 g_steal_pointer (&state));
3474 }
3475
3476 /**
3477 * pk_client_install_signature_async: (finish-func pk_client_generic_finish):
3478 * @client: a valid #PkClient instance
3479 * @type: the signature type, e.g. %PK_SIGTYPE_ENUM_GPG
3480 * @key_id: a key ID such as "0df23df"
3481 * @package_id: a signature_id structure such as "hal;0.0.1;i386;fedora"
3482 * @cancellable: a #GCancellable or %NULL
3483 * @progress_callback: (scope notified): the function to run when the progress changes
3484 * @progress_user_data: data to pass to @progress_callback
3485 * @callback_ready: the function to run on completion
3486 * @user_data: the data to pass to @callback_ready
3487 *
3488 * Install a software repository signature of the newest and most correct version.
3489 *
3490 * Since: 0.5.2
3491 **/
3492 void
3493 pk_client_install_signature_async (PkClient *client, PkSigTypeEnum type, const gchar *key_id, const gchar *package_id, GCancellable *cancellable,
3494 PkProgressCallback progress_callback, gpointer progress_user_data,
3495 GAsyncReadyCallback callback_ready, gpointer user_data)
3496 {
3497 PkClientPrivate *priv = GET_PRIVATE(client);
3498 g_autoptr(PkClientState) state = NULL;
3499 g_autoptr(GError) error = NULL;
3500
3501 g_return_if_fail (PK_IS_CLIENT (client));
3502 g_return_if_fail (callback_ready != NULL);
3503 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3504
3505 /* save state */
3506 state = pk_client_state_new (client, callback_ready, user_data, pk_client_install_signature_async, PK_ROLE_ENUM_INSTALL_SIGNATURE, cancellable);
3507 state->type = type;
3508 state->key_id = g_strdup (key_id);
3509 state->package_id = g_strdup (package_id);
3510 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3511
3512 /* check not already cancelled */
3513 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3514 pk_client_state_finish (state, g_steal_pointer (&error));
3515 return;
3516 }
3517
3518 /* identify */
3519 pk_client_set_role (state, state->role);
3520
3521 /* get tid */
3522 pk_control_get_tid_async (priv->control,
3523 cancellable,
3524 (GAsyncReadyCallback) pk_client_get_tid_cb,
3525 g_steal_pointer (&state));
3526 }
3527
3528 /**
3529 * pk_client_update_packages_async: (finish-func pk_client_generic_finish):
3530 * @client: a valid #PkClient instance
3531 * @transaction_flags: a transaction type bitfield
3532 * @package_ids: (array zero-terminated=1): a null terminated array of package_id structures such as "hal;0.0.1;i386;fedora"
3533 * @cancellable: a #GCancellable or %NULL
3534 * @progress_callback: (scope notified): the function to run when the progress changes
3535 * @progress_user_data: data to pass to @progress_callback
3536 * @callback_ready: the function to run on completion
3537 * @user_data: the data to pass to @callback_ready
3538 *
3539 * Update specific packages to the newest available versions.
3540 *
3541 * Since: 0.8.1
3542 **/
3543 void
3544 pk_client_update_packages_async (PkClient *client,
3545 PkBitfield transaction_flags,
3546 gchar **package_ids,
3547 GCancellable *cancellable,
3548 PkProgressCallback progress_callback,
3549 gpointer progress_user_data,
3550 GAsyncReadyCallback callback_ready,
3551 gpointer user_data)
3552 {
3553 PkClientPrivate *priv = GET_PRIVATE(client);
3554 g_autoptr(PkClientState) state = NULL;
3555 g_autoptr(GError) error = NULL;
3556
3557 g_return_if_fail (PK_IS_CLIENT (client));
3558 g_return_if_fail (callback_ready != NULL);
3559 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3560 g_return_if_fail (package_ids != NULL);
3561
3562 /* save state */
3563 state = pk_client_state_new (client, callback_ready, user_data, pk_client_update_packages_async, PK_ROLE_ENUM_UPDATE_PACKAGES, cancellable);
3564 state->transaction_flags = transaction_flags;
3565 state->package_ids = g_strdupv (package_ids);
3566 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3567
3568 /* check not already cancelled */
3569 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3570 pk_client_state_finish (state, g_steal_pointer (&error));
3571 return;
3572 }
3573
3574 /* identify */
3575 pk_client_set_role (state, state->role);
3576
3577 /* get tid */
3578 pk_control_get_tid_async (priv->control,
3579 cancellable,
3580 (GAsyncReadyCallback) pk_client_get_tid_cb,
3581 g_steal_pointer (&state));
3582 }
3583
3584 /*
3585 * pk_client_copy_native_finished_cb:
3586 */
3587 static void
3588 pk_client_copy_native_finished_cb (GFile *file, GAsyncResult *res, gpointer user_data)
3589 {
3590 g_autoptr(PkClientState) state = PK_CLIENT_STATE (g_steal_pointer (&user_data));
3591 g_autoptr(GError) error = NULL;
3592
3593 /* get the result */
3594 if (!g_file_copy_finish (file, res, &error)) {
3595 pk_client_state_finish (state, g_steal_pointer (&error));
3596 return;
3597 }
3598
3599 /* no more copies pending? */
3600 if (g_atomic_int_dec_and_test (&state->remaining_files_to_copy)) {
3601 PkClientPrivate *client_priv = pk_client_get_instance_private (state->client);
3602 /* now get tid and continue on our merry way */
3603 pk_control_get_tid_async (client_priv->control,
3604 state->cancellable,
3605 (GAsyncReadyCallback) pk_client_get_tid_cb,
3606 g_object_ref (state));
3607 }
3608 }
3609
3610 /*
3611 * pk_client_copy_non_native_then_get_tid:
3612 **/
3613 static void
3614 pk_client_copy_non_native_then_get_tid (PkClientState *state)
3615 {
3616 gchar *path;
3617 gboolean ret;
3618 guint i;
3619 g_autofree gchar *user_temp = NULL;
3620 g_autoptr(GError) error = NULL;
3621
3622 /* get a temp dir accessible by the daemon */
3623 user_temp = pk_client_get_user_temp ("native-cache", &error);
3624 g_debug ("using temp dir %s", user_temp);
3625
3626 /* save percentage */
3627 ret = pk_progress_set_percentage (state->progress, -1);
3628
3629 /* copy each file that is non-native */
3630 for (i = 0; state->files[i] != NULL; i++) {
3631 ret = pk_client_is_file_native (state->files[i]);
3632 g_debug ("%s native=%i", state->files[i], ret);
3633 if (!ret) {
3634 /* generate the destination location */
3635 g_autofree gchar *basename = NULL;
3636 g_autoptr(GFile) destination = NULL;
3637 g_autoptr(GFile) source = NULL;
3638 basename = g_path_get_basename (state->files[i]);
3639 path = g_build_filename (user_temp, basename, NULL);
3640 g_debug ("copy from %s to %s", state->files[i], path);
3641 source = g_file_new_for_path (state->files[i]);
3642 destination = g_file_new_for_path (path);
3643
3644 /* copy the file async */
3645 g_file_copy_async (source, destination, G_FILE_COPY_OVERWRITE, G_PRIORITY_DEFAULT, state->cancellable,
3646 (GFileProgressCallback) pk_client_copy_progress_cb, state,
3647 (GAsyncReadyCallback) pk_client_copy_native_finished_cb, g_object_ref (state));
3648
3649 /* pass the new path to PackageKit */
3650 g_free (state->files[i]);
3651 state->files[i] = path;
3652 }
3653 }
3654 }
3655
3656 /**
3657 * pk_client_install_files_async: (finish-func pk_client_generic_finish):
3658 * @client: a valid #PkClient instance
3659 * @transaction_flags: a transaction type bitfield
3660 * @files: (array zero-terminated=1): a file such as "/home/hughsie/Desktop/hal-devel-0.10.0.rpm"
3661 * @cancellable: a #GCancellable or %NULL
3662 * @progress_callback: (scope notified): the function to run when the progress changes
3663 * @progress_user_data: data to pass to @progress_callback
3664 * @callback_ready: the function to run on completion
3665 * @user_data: the data to pass to @callback_ready
3666 *
3667 * Install a file locally, and get the deps from the repositories.
3668 * This is useful for double clicking on a .rpm or .deb file.
3669 *
3670 * Since: 0.8.1
3671 **/
3672 void
3673 pk_client_install_files_async (PkClient *client,
3674 PkBitfield transaction_flags,
3675 gchar **files,
3676 GCancellable *cancellable,
3677 PkProgressCallback progress_callback,
3678 gpointer progress_user_data,
3679 GAsyncReadyCallback callback_ready,
3680 gpointer user_data)
3681 {
3682 PkClientPrivate *priv = GET_PRIVATE(client);
3683 g_autoptr(PkClientState) state = NULL;
3684 gboolean ret;
3685 guint i;
3686 g_autoptr(GError) error = NULL;
3687
3688 g_return_if_fail (PK_IS_CLIENT (client));
3689 g_return_if_fail (callback_ready != NULL);
3690 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3691 g_return_if_fail (files != NULL);
3692
3693 /* save state */
3694 state = pk_client_state_new (client, callback_ready, user_data, pk_client_install_files_async, PK_ROLE_ENUM_INSTALL_FILES, cancellable);
3695 state->transaction_flags = transaction_flags;
3696 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3697
3698 /* check not already cancelled */
3699 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3700 pk_client_state_finish (state, g_steal_pointer (&error));
3701 return;
3702 }
3703
3704 /* identify */
3705 pk_client_set_role (state, state->role);
3706
3707 /* check files are valid */
3708 state->files = pk_client_convert_real_paths (files, &error);
3709 if (state->files == NULL) {
3710 pk_client_state_finish (state, g_steal_pointer (&error));
3711 return;
3712 }
3713
3714 /* how many non-native */
3715 for (i = 0; state->files[i] != NULL; i++) {
3716 ret = pk_client_is_file_native (state->files[i]);
3717 /* on a FUSE mount (probably created by gvfs) and not readable by packagekitd */
3718 if (!ret)
3719 g_atomic_int_inc (&state->remaining_files_to_copy);
3720 }
3721
3722 /* nothing to copy, common case */
3723 if (g_atomic_int_get (&state->remaining_files_to_copy) == 0) {
3724 /* just get tid */
3725 pk_control_get_tid_async (priv->control,
3726 cancellable,
3727 (GAsyncReadyCallback) pk_client_get_tid_cb,
3728 g_object_ref (state));
3729 return;
3730 }
3731
3732 /* copy the files first */
3733 pk_client_copy_non_native_then_get_tid (state);
3734 }
3735
3736 /**
3737 * pk_client_accept_eula_async: (finish-func pk_client_generic_finish):
3738 * @client: a valid #PkClient instance
3739 * @eula_id: the <literal>eula_id</literal> we are agreeing to
3740 * @cancellable: a #GCancellable or %NULL
3741 * @progress_callback: (scope notified): the function to run when the progress changes
3742 * @progress_user_data: data to pass to @progress_callback
3743 * @callback_ready: the function to run on completion
3744 * @user_data: the data to pass to @callback_ready
3745 *
3746 * We may want to agree to a EULA dialog if one is presented.
3747 *
3748 * Since: 0.5.2
3749 **/
3750 void
3751 pk_client_accept_eula_async (PkClient *client, const gchar *eula_id, GCancellable *cancellable,
3752 PkProgressCallback progress_callback, gpointer progress_user_data,
3753 GAsyncReadyCallback callback_ready, gpointer user_data)
3754 {
3755 PkClientPrivate *priv = GET_PRIVATE(client);
3756 g_autoptr(PkClientState) state = NULL;
3757 g_autoptr(GError) error = NULL;
3758
3759 g_return_if_fail (PK_IS_CLIENT (client));
3760 g_return_if_fail (callback_ready != NULL);
3761 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3762
3763 /* save state */
3764 state = pk_client_state_new (client, callback_ready, user_data, pk_client_accept_eula_async, PK_ROLE_ENUM_ACCEPT_EULA, cancellable);
3765 state->eula_id = g_strdup (eula_id);
3766 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3767
3768 /* check not already cancelled */
3769 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3770 pk_client_state_finish (state, g_steal_pointer (&error));
3771 return;
3772 }
3773
3774 /* identify */
3775 pk_client_set_role (state, state->role);
3776
3777 /* get tid */
3778 pk_control_get_tid_async (priv->control,
3779 cancellable,
3780 (GAsyncReadyCallback) pk_client_get_tid_cb,
3781 g_steal_pointer (&state));
3782 }
3783
3784 /**
3785 * pk_client_get_repo_list_async: (finish-func pk_client_generic_finish):
3786 * @client: a valid #PkClient instance
3787 * @filters: a #PkBitfield such as %PK_FILTER_ENUM_DEVELOPMENT or %PK_FILTER_ENUM_NONE
3788 * @cancellable: a #GCancellable or %NULL
3789 * @progress_callback: (scope notified): the function to run when the progress changes
3790 * @progress_user_data: data to pass to @progress_callback
3791 * @callback_ready: the function to run on completion
3792 * @user_data: the data to pass to @callback_ready
3793 *
3794 * Get the list of repositories installed on the system.
3795 *
3796 * Since: 0.5.2
3797 **/
3798 void
3799 pk_client_get_repo_list_async (PkClient *client, PkBitfield filters, GCancellable *cancellable,
3800 PkProgressCallback progress_callback, gpointer progress_user_data,
3801 GAsyncReadyCallback callback_ready, gpointer user_data)
3802 {
3803 PkClientPrivate *priv = GET_PRIVATE(client);
3804 g_autoptr(PkClientState) state = NULL;
3805 g_autoptr(GError) error = NULL;
3806
3807 g_return_if_fail (PK_IS_CLIENT (client));
3808 g_return_if_fail (callback_ready != NULL);
3809 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3810
3811 /* save state */
3812 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_repo_list_async, PK_ROLE_ENUM_GET_REPO_LIST, cancellable);
3813 state->filters = filters;
3814 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3815
3816 /* check not already cancelled */
3817 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3818 pk_client_state_finish (state, g_steal_pointer (&error));
3819 return;
3820 }
3821
3822 /* identify */
3823 pk_client_set_role (state, state->role);
3824
3825 /* get tid */
3826 pk_control_get_tid_async (priv->control,
3827 cancellable,
3828 (GAsyncReadyCallback) pk_client_get_tid_cb,
3829 g_steal_pointer (&state));
3830 }
3831
3832 /**
3833 * pk_client_repo_enable_async: (finish-func pk_client_generic_finish):
3834 * @client: a valid #PkClient instance
3835 * @repo_id: a repo_id structure such as "livna-devel"
3836 * @enabled: if we should enable the repository
3837 * @cancellable: a #GCancellable or %NULL
3838 * @progress_callback: (scope notified): the function to run when the progress changes
3839 * @progress_user_data: data to pass to @progress_callback
3840 * @callback_ready: the function to run on completion
3841 * @user_data: the data to pass to @callback_ready
3842 *
3843 * Enable or disable the repository.
3844 *
3845 * Since: 0.5.2
3846 **/
3847 void
3848 pk_client_repo_enable_async (PkClient *client, const gchar *repo_id, gboolean enabled, GCancellable *cancellable,
3849 PkProgressCallback progress_callback,
3850 gpointer progress_user_data, GAsyncReadyCallback callback_ready, gpointer user_data)
3851 {
3852 PkClientPrivate *priv = GET_PRIVATE(client);
3853 g_autoptr(PkClientState) state = NULL;
3854 g_autoptr(GError) error = NULL;
3855
3856 g_return_if_fail (PK_IS_CLIENT (client));
3857 g_return_if_fail (callback_ready != NULL);
3858 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3859
3860 /* save state */
3861 state = pk_client_state_new (client, callback_ready, user_data, pk_client_repo_enable_async, PK_ROLE_ENUM_REPO_ENABLE, cancellable);
3862 state->enabled = enabled;
3863 state->repo_id = g_strdup (repo_id);
3864 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3865
3866 /* check not already cancelled */
3867 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3868 pk_client_state_finish (state, g_steal_pointer (&error));
3869 return;
3870 }
3871
3872 /* identify */
3873 pk_client_set_role (state, state->role);
3874
3875 /* get tid */
3876 pk_control_get_tid_async (priv->control,
3877 cancellable,
3878 (GAsyncReadyCallback) pk_client_get_tid_cb,
3879 g_steal_pointer (&state));
3880 }
3881
3882 /**
3883 * pk_client_repo_set_data_async: (finish-func pk_client_generic_finish):
3884 * @client: a valid #PkClient instance
3885 * @repo_id: a repo_id structure such as "livna-devel"
3886 * @parameter: the parameter to change
3887 * @value: what we should change it to
3888 * @cancellable: a #GCancellable or %NULL
3889 * @progress_callback: (scope notified): the function to run when the progress changes
3890 * @progress_user_data: data to pass to @progress_callback
3891 * @callback_ready: the function to run on completion
3892 * @user_data: the data to pass to @callback_ready
3893 *
3894 * We may want to set a repository parameter.
3895 * NOTE: this is free text, and is left to the backend to define a format.
3896 *
3897 * Since: 0.5.2
3898 **/
3899 void
3900 pk_client_repo_set_data_async (PkClient *client, const gchar *repo_id, const gchar *parameter, const gchar *value, GCancellable *cancellable,
3901 PkProgressCallback progress_callback,
3902 gpointer progress_user_data, GAsyncReadyCallback callback_ready, gpointer user_data)
3903 {
3904 PkClientPrivate *priv = GET_PRIVATE(client);
3905 g_autoptr(PkClientState) state = NULL;
3906 g_autoptr(GError) error = NULL;
3907
3908 g_return_if_fail (PK_IS_CLIENT (client));
3909 g_return_if_fail (callback_ready != NULL);
3910 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3911
3912 /* save state */
3913 state = pk_client_state_new (client, callback_ready, user_data, pk_client_repo_set_data_async, PK_ROLE_ENUM_REPO_SET_DATA, cancellable);
3914 state->repo_id = g_strdup (repo_id);
3915 state->parameter = g_strdup (parameter);
3916 state->value = g_strdup (value);
3917 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3918
3919 /* check not already cancelled */
3920 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3921 pk_client_state_finish (state, g_steal_pointer (&error));
3922 return;
3923 }
3924
3925 /* identify */
3926 pk_client_set_role (state, state->role);
3927
3928 /* get tid */
3929 pk_control_get_tid_async (priv->control,
3930 cancellable,
3931 (GAsyncReadyCallback) pk_client_get_tid_cb,
3932 g_steal_pointer (&state));
3933 }
3934
3935 /**
3936 * pk_client_repo_remove_async: (finish-func pk_client_generic_finish):
3937 * @client: a valid #PkClient instance
3938 * @transaction_flags: transaction flags
3939 * @repo_id: a repo_id structure such as "livna-devel"
3940 * @autoremove: If packages should be auto-removed
3941 * @cancellable: a #GCancellable or %NULL
3942 * @progress_callback: (scope notified): the function to run when the progress changes
3943 * @progress_user_data: data to pass to @progress_callback
3944 * @callback_ready: the function to run on completion
3945 * @user_data: the data to pass to @callback_ready
3946 *
3947 * Removes a repo and optionally the packages installed from it.
3948 *
3949 * Since: 0.9.1
3950 **/
3951 void
3952 pk_client_repo_remove_async (PkClient *client,
3953 PkBitfield transaction_flags,
3954 const gchar *repo_id,
3955 gboolean autoremove,
3956 GCancellable *cancellable,
3957 PkProgressCallback progress_callback,
3958 gpointer progress_user_data,
3959 GAsyncReadyCallback callback_ready,
3960 gpointer user_data)
3961 {
3962 PkClientPrivate *priv = GET_PRIVATE(client);
3963 g_autoptr(PkClientState) state = NULL;
3964 g_autoptr(GError) error = NULL;
3965
3966 g_return_if_fail (PK_IS_CLIENT (client));
3967 g_return_if_fail (callback_ready != NULL);
3968 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
3969
3970 /* save state */
3971 state = pk_client_state_new (client, callback_ready, user_data, pk_client_repo_remove_async, PK_ROLE_ENUM_REPO_REMOVE, cancellable);
3972 state->transaction_flags = transaction_flags;
3973 state->repo_id = g_strdup (repo_id);
3974 state->autoremove = autoremove;
3975 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
3976
3977 /* check not already cancelled */
3978 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
3979 pk_client_state_finish (state, g_steal_pointer (&error));
3980 return;
3981 }
3982
3983 /* identify */
3984 pk_client_set_role (state, state->role);
3985
3986 /* get tid */
3987 pk_control_get_tid_async (priv->control,
3988 cancellable,
3989 (GAsyncReadyCallback) pk_client_get_tid_cb,
3990 g_steal_pointer (&state));
3991 }
3992
3993 /**
3994 * pk_client_upgrade_system_async: (finish-func pk_client_generic_finish):
3995 * @client: a valid #PkClient instance
3996 * @transaction_flags: a transaction type bitfield
3997 * @distro_id: a distro ID such as "fedora-14"
3998 * @upgrade_kind: a #PkUpgradeKindEnum such as %PK_UPGRADE_KIND_ENUM_COMPLETE
3999 * @cancellable: a #GCancellable or %NULL
4000 * @progress_callback: (scope notified): the function to run when the progress changes
4001 * @progress_user_data: data to pass to @progress_callback
4002 * @callback_ready: the function to run on completion
4003 * @user_data: the data to pass to @callback_ready
4004 *
4005 * This transaction will update the distro to the next version, which may
4006 * involve just downloading the installer and setting up the boot device,
4007 * or may involve doing an on-line upgrade.
4008 *
4009 * The backend will decide what is best to do.
4010 *
4011 * Since: 1.0.10
4012 **/
4013 void
4014 pk_client_upgrade_system_async (PkClient *client,
4015 PkBitfield transaction_flags,
4016 const gchar *distro_id, PkUpgradeKindEnum upgrade_kind,
4017 GCancellable *cancellable,
4018 PkProgressCallback progress_callback, gpointer progress_user_data,
4019 GAsyncReadyCallback callback_ready, gpointer user_data)
4020 {
4021 PkClientPrivate *priv = GET_PRIVATE(client);
4022 g_autoptr(PkClientState) state = NULL;
4023 g_autoptr(GError) error = NULL;
4024
4025 g_return_if_fail (PK_IS_CLIENT (client));
4026 g_return_if_fail (callback_ready != NULL);
4027 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
4028
4029 /* save state */
4030 state = pk_client_state_new (client, callback_ready, user_data, pk_client_upgrade_system_async, PK_ROLE_ENUM_UPGRADE_SYSTEM, cancellable);
4031 state->transaction_flags = transaction_flags;
4032 state->distro_id = g_strdup (distro_id);
4033 state->upgrade_kind = upgrade_kind;
4034 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
4035
4036 /* check not already cancelled */
4037 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
4038 pk_client_state_finish (state, g_steal_pointer (&error));
4039 return;
4040 }
4041
4042 /* identify */
4043 pk_client_set_role (state, state->role);
4044
4045 /* get tid */
4046 pk_control_get_tid_async (priv->control,
4047 cancellable,
4048 (GAsyncReadyCallback) pk_client_get_tid_cb,
4049 g_steal_pointer (&state));
4050 }
4051
4052 /**
4053 * pk_client_repair_system_async: (finish-func pk_client_generic_finish):
4054 * @client: a valid #PkClient instance
4055 * @transaction_flags: a transaction type bitfield
4056 * @cancellable: a #GCancellable or %NULL
4057 * @progress_callback: (scope notified): the function to run when the progress changes
4058 * @progress_user_data: data to pass to @progress_callback
4059 * @callback_ready: the function to run on completion
4060 * @user_data: the data to pass to @callback_ready
4061 *
4062 * This transaction will try to recover from a broken package management system:
4063 * e.g. the installation of a package with unsatisfied dependencies has
4064 * been forced by the user using a low level tool (rpm or dpkg) or the
4065 * system was shutdown during processing an installation.
4066 *
4067 * The backend will decide what is best to do.
4068 *
4069 * Since: 0.8.1
4070 **/
4071 void
4072 pk_client_repair_system_async (PkClient *client,
4073 PkBitfield transaction_flags,
4074 GCancellable *cancellable,
4075 PkProgressCallback progress_callback,
4076 gpointer progress_user_data,
4077 GAsyncReadyCallback callback_ready,
4078 gpointer user_data)
4079 {
4080 PkClientPrivate *priv = GET_PRIVATE(client);
4081 g_autoptr(PkClientState) state = NULL;
4082 g_autoptr(GError) error = NULL;
4083
4084 g_return_if_fail (PK_IS_CLIENT (client));
4085 g_return_if_fail (callback_ready != NULL);
4086 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
4087
4088 /* save state */
4089 state = pk_client_state_new (client, callback_ready, user_data, pk_client_repair_system_async, PK_ROLE_ENUM_REPAIR_SYSTEM, cancellable);
4090 state->transaction_flags = transaction_flags;
4091 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
4092
4093 /* check not already cancelled */
4094 if (cancellable != NULL && g_cancellable_set_error_if_cancelled (cancellable, &error)) {
4095 pk_client_state_finish (state, g_steal_pointer (&error));
4096 return;
4097 }
4098
4099 /* identify */
4100 pk_client_set_role (state, state->role);
4101
4102 /* get tid */
4103 pk_control_get_tid_async (priv->control,
4104 cancellable,
4105 (GAsyncReadyCallback) pk_client_get_tid_cb,
4106 g_steal_pointer (&state));
4107 }
4108
4109 /**********************************************************************/
4110
4111 /*
4112 * pk_client_adopt_get_proxy_cb:
4113 **/
4114 static void
4115 pk_client_adopt_get_proxy_cb (GObject *object,
4116 GAsyncResult *res,
4117 gpointer user_data)
4118 {
4119 g_autoptr(GError) error = NULL;
4120 g_autoptr(PkClientState) state = PK_CLIENT_STATE (g_steal_pointer (&user_data));
4121
4122 state->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
4123 if (state->proxy == NULL) {
4124 pk_client_state_finish (state, g_steal_pointer (&error));
4125 return;
4126 }
4127
4128 /* connect */
4129 pk_client_proxy_connect (state);
4130 }
4131
4132 /**
4133 * pk_client_adopt_async: (finish-func pk_client_generic_finish):
4134 * @client: a valid #PkClient instance
4135 * @transaction_id: a transaction ID such as "/21_ebcbdaae_data"
4136 * @cancellable: a #GCancellable or %NULL
4137 * @progress_callback: (scope notified): the function to run when the progress changes
4138 * @progress_user_data: data to pass to @progress_callback
4139 * @callback_ready: the function to run on completion
4140 * @user_data: the data to pass to @callback_ready
4141 *
4142 * Adopt a transaction which allows the caller to monitor the state or cancel it.
4143 *
4144 * Since: 0.5.2
4145 **/
4146 void
4147 pk_client_adopt_async (PkClient *client,
4148 const gchar *transaction_id,
4149 GCancellable *cancellable,
4150 PkProgressCallback progress_callback,
4151 gpointer progress_user_data,
4152 GAsyncReadyCallback callback_ready,
4153 gpointer user_data)
4154 {
4155 g_autoptr(PkClientState) state = NULL;
4156 g_autoptr(GError) error = NULL;
4157
4158 g_return_if_fail (PK_IS_CLIENT (client));
4159 g_return_if_fail (callback_ready != NULL);
4160 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
4161
4162 /* save state */
4163 state = pk_client_state_new (client, callback_ready, user_data, pk_client_adopt_async, PK_ROLE_ENUM_UNKNOWN, cancellable);
4164 state->tid = g_strdup (transaction_id);
4165 state->progress = pk_progress_new_with_callback (progress_callback, progress_user_data);
4166 state->results = pk_results_new ();
4167 g_object_set (state->results,
4168 "role", state->role,
4169 "progress", state->progress,
4170 NULL);
4171
4172 /* check not already cancelled */
4173 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
4174 pk_client_state_finish (state, g_steal_pointer (&error));
4175 return;
4176 }
4177
4178 /* identify */
4179 pk_client_set_role (state, state->role);
4180 pk_progress_set_transaction_id (state->progress, state->tid);
4181
4182 /* get a connection to the transaction interface */
4183 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
4184 G_DBUS_PROXY_FLAGS_NONE,
4185 NULL,
4186 PK_DBUS_SERVICE,
4187 state->tid,
4188 PK_DBUS_INTERFACE_TRANSACTION,
4189 state->cancellable,
4190 pk_client_adopt_get_proxy_cb,
4191 g_object_ref (state));
4192 }
4193
4194 /**********************************************************************/
4195
4196 /**
4197 * pk_client_get_progress_finish:
4198 * @client: a valid #PkClient instance
4199 * @res: the #GAsyncResult
4200 * @error: A #GError or %NULL
4201 *
4202 * Gets the result from the asynchronous function.
4203 *
4204 * Return value: (transfer full): the #PkProgress, or %NULL. Free with g_object_unref()
4205 *
4206 * Since: 0.5.2
4207 **/
4208 PkProgress *
4209 pk_client_get_progress_finish (PkClient *client, GAsyncResult *res, GError **error)
4210 {
4211 g_return_val_if_fail (PK_IS_CLIENT (client), NULL);
4212 g_return_val_if_fail (G_IS_TASK (res), NULL);
4213 g_return_val_if_fail (error == NULL || *error == NULL, NULL);
4214
4215 return g_task_propagate_pointer (G_TASK (res), error);
4216 }
4217
4218 /*
4219 * pk_client_get_progress_cb:
4220 **/
4221 static void
4222 pk_client_get_progress_cb (GObject *source_object,
4223 GAsyncResult *res,
4224 gpointer user_data)
4225 {
4226 g_autoptr(GError) error = NULL;
4227 g_autoptr(PkClientState) state = PK_CLIENT_STATE (g_steal_pointer (&user_data));
4228
4229 state->proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
4230 if (state->proxy == NULL) {
4231 pk_client_state_finish (state, g_steal_pointer (&error));
4232 return;
4233 }
4234
4235 /* connect */
4236 pk_client_proxy_connect (state);
4237
4238 state->ret = TRUE;
4239 pk_client_state_finish (state, NULL);
4240 }
4241
4242 /**
4243 * pk_client_get_progress_async:
4244 * @client: a valid #PkClient instance
4245 * @transaction_id: a transaction ID such as "/21_ebcbdaae_data"
4246 * @cancellable: a #GCancellable or %NULL
4247 * @callback_ready: the function to run on completion
4248 * @user_data: the data to pass to @callback_ready
4249 *
4250 * Find the current state of a transaction.
4251 *
4252 * Since: 0.5.2
4253 **/
4254 void
4255 pk_client_get_progress_async (PkClient *client,
4256 const gchar *transaction_id,
4257 GCancellable *cancellable,
4258 GAsyncReadyCallback callback_ready,
4259 gpointer user_data)
4260 {
4261 g_autoptr(PkClientState) state = NULL;
4262 g_autoptr(GError) error = NULL;
4263
4264 g_return_if_fail (PK_IS_CLIENT (client));
4265 g_return_if_fail (callback_ready != NULL);
4266 g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
4267
4268 /* save state */
4269 state = pk_client_state_new (client, callback_ready, user_data, pk_client_get_progress_async, PK_ROLE_ENUM_UNKNOWN, cancellable);
4270 state->tid = g_strdup (transaction_id);
4271 state->progress = pk_progress_new ();
4272 state->querying_progress = TRUE;
4273
4274 /* check not already cancelled */
4275 if (g_cancellable_set_error_if_cancelled (cancellable, &error)) {
4276 pk_client_state_finish (state, g_steal_pointer (&error));
4277 return;
4278 }
4279
4280 /* identify */
4281 pk_progress_set_transaction_id (state->progress, state->tid);
4282
4283 /* get a connection to the transaction interface */
4284 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
4285 G_DBUS_PROXY_FLAGS_NONE,
4286 NULL,
4287 PK_DBUS_SERVICE,
4288 state->tid,
4289 PK_DBUS_INTERFACE_TRANSACTION,
4290 state->cancellable,
4291 pk_client_get_progress_cb,
4292 g_object_ref (state));
4293 }
4294
4295 /**********************************************************************/
4296
4297 /*
4298 * pk_client_cancel_all_dbus_methods:
4299 **/
4300 static gboolean
4301 pk_client_cancel_all_dbus_methods (PkClient *client)
4302 {
4303 PkClientPrivate *priv = GET_PRIVATE(client);
4304 const PkClientState *state;
4305 guint i;
4306 g_autoptr(GPtrArray) array = NULL;
4307
4308 /* just cancel the call; cancelling is synchronous so this should result
4309 * in pk_client_state_remove() being called, which will modify the array,
4310 * so take a copy of the array first */
4311 array = g_ptr_array_new_from_array (priv->calls->pdata, priv->calls->len, NULL, NULL, NULL);
4312 for (i = 0; i < array->len; i++) {
4313 state = g_ptr_array_index (array, i);
4314 if (state->proxy == NULL)
4315 continue;
4316 g_debug ("cancel in flight call");
4317 g_cancellable_cancel (state->cancellable);
4318 }
4319
4320 return TRUE;
4321 }
4322
4323 /**
4324 * pk_client_set_locale:
4325 * @client: a valid #PkClient instance
4326 * @locale: the locale to set, e.g. "en_GB.UTF-8"
4327 *
4328 * Sets the locale to be used for the client. This may affect returned
4329 * results.
4330 *
4331 * Since: 0.6.10
4332 **/
4333 void
4334 pk_client_set_locale (PkClient *client, const gchar *locale)
4335 {
4336 PkClientPrivate *priv = GET_PRIVATE(client);
4337
4338 g_return_if_fail (PK_IS_CLIENT (client));
4339
4340 if (g_strcmp0 (priv->locale, locale) == 0)
4341 return;
4342
4343 g_free (priv->locale);
4344 priv->locale = g_strdup (locale);
4345 g_object_notify_by_pspec (G_OBJECT (client), obj_properties[PROP_LOCALE]);
4346 }
4347
4348 /**
4349 * pk_client_get_locale:
4350 * @client: a valid #PkClient instance
4351 *
4352 * Gets the locale used for this transaction.
4353 *
4354 * Return value: The locale.
4355 *
4356 * Since: 0.6.10
4357 **/
4358 const gchar *
4359 pk_client_get_locale (PkClient *client)
4360 {
4361 PkClientPrivate *priv = GET_PRIVATE(client);
4362
4363 g_return_val_if_fail (PK_IS_CLIENT (client), NULL);
4364
4365 return priv->locale;
4366 }
4367
4368 /**
4369 * pk_client_set_background:
4370 * @client: a valid #PkClient instance
4371 * @background: if the transaction is a background transaction
4372 *
4373 * Sets the background value for the client. A background transaction
4374 * is usually scheduled at a lower priority and is usually given less
4375 * network and disk performance.
4376 *
4377 * Since: 0.6.10
4378 **/
4379 void
4380 pk_client_set_background (PkClient *client, gboolean background)
4381 {
4382 PkClientPrivate *priv = GET_PRIVATE(client);
4383
4384 g_return_if_fail (PK_IS_CLIENT (client));
4385
4386 if (priv->background == background)
4387 return;
4388
4389 priv->background = background;
4390 g_object_notify_by_pspec (G_OBJECT (client), obj_properties[PROP_BACKGROUND]);
4391 }
4392
4393 /**
4394 * pk_client_get_background:
4395 * @client: a valid #PkClient instance
4396 *
4397 * Gets the background value.
4398 *
4399 * Return value: The background status.
4400 *
4401 * Since: 0.6.10
4402 **/
4403 gboolean
4404 pk_client_get_background (PkClient *client)
4405 {
4406 PkClientPrivate *priv = GET_PRIVATE(client);
4407
4408 g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
4409
4410 return priv->background;
4411 }
4412
4413 /**
4414 * pk_client_set_interactive:
4415 * @client: a valid #PkClient instance
4416 * @interactive: the value to set
4417 *
4418 * Sets the interactive value for the client. Interactive transactions
4419 * are usually allowed to ask the user questions.
4420 *
4421 * Since: 0.6.10
4422 **/
4423 void
4424 pk_client_set_interactive (PkClient *client, gboolean interactive)
4425 {
4426 PkClientPrivate *priv = GET_PRIVATE(client);
4427
4428 g_return_if_fail (PK_IS_CLIENT (client));
4429
4430 if (priv->interactive == interactive)
4431 return;
4432
4433 priv->interactive = interactive;
4434 g_object_notify_by_pspec (G_OBJECT (client), obj_properties[PROP_INTERACTIVE]);
4435 }
4436
4437 /**
4438 * pk_client_get_interactive:
4439 * @client: a valid #PkClient instance
4440 *
4441 * Gets the client interactive value.
4442 *
4443 * Return value: if the transaction is due to run interactivly.
4444 *
4445 * Since: 0.6.10
4446 **/
4447 gboolean
4448 pk_client_get_interactive (PkClient *client)
4449 {
4450 PkClientPrivate *priv = GET_PRIVATE(client);
4451
4452 g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
4453
4454 return priv->interactive;
4455 }
4456
4457 /**
4458 * pk_client_get_idle:
4459 * @client: a valid #PkClient instance
4460 *
4461 * Gets if the transaction client idle value.
4462 *
4463 * Return value: if this client is idle.
4464 *
4465 * Since: 0.6.10
4466 **/
4467 gboolean
4468 pk_client_get_idle (PkClient *client)
4469 {
4470 PkClientPrivate *priv = GET_PRIVATE(client);
4471
4472 g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
4473
4474 return (priv->calls->len == 0);
4475 }
4476
4477 /**
4478 * pk_client_set_cache_age:
4479 * @client: a valid #PkClient instance
4480 * @cache_age: the cache age to set in seconds, where %G_MAXUINT
4481 * means cache "never expires"
4482 *
4483 * Sets the maximum cache age value for the client.
4484 *
4485 * Since: 0.6.10
4486 **/
4487 void
4488 pk_client_set_cache_age (PkClient *client, guint cache_age)
4489 {
4490 PkClientPrivate *priv = GET_PRIVATE(client);
4491
4492 g_return_if_fail (PK_IS_CLIENT (client));
4493
4494 if (priv->cache_age == cache_age)
4495 return;
4496
4497 priv->cache_age = cache_age;
4498 g_object_notify_by_pspec (G_OBJECT (client), obj_properties[PROP_CACHE_AGE]);
4499 }
4500
4501 /**
4502 * pk_client_get_cache_age:
4503 * @client: a valid #PkClient instance
4504 *
4505 * Gets the maximum cache age value.
4506 *
4507 * Return value: The cache age in seconds
4508 *
4509 * Since: 0.6.10
4510 **/
4511 guint
4512 pk_client_get_cache_age (PkClient *client)
4513 {
4514 PkClientPrivate *priv = GET_PRIVATE(client);
4515
4516 g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
4517
4518 return priv->cache_age;
4519 }
4520
4521 /**
4522 * pk_client_set_details_with_deps_size:
4523 * @client: a valid #PkClient instance
4524 * @details_with_deps_size: the value to set
4525 *
4526 * Sets whether the pk_client_get_details_async() should include dependencies
4527 * download sizes for packages, which are not installed.
4528 *
4529 * Since: 1.2.7
4530 **/
4531 void
4532 pk_client_set_details_with_deps_size (PkClient *client, gboolean details_with_deps_size)
4533 {
4534 PkClientPrivate *priv = GET_PRIVATE(client);
4535
4536 g_return_if_fail (PK_IS_CLIENT (client));
4537
4538 if (priv->details_with_deps_size == details_with_deps_size)
4539 return;
4540
4541 priv->details_with_deps_size = details_with_deps_size;
4542 g_object_notify_by_pspec (G_OBJECT (client), obj_properties[PROP_DETAILS_WITH_DEPS_SIZE]);
4543 }
4544
4545 /**
4546 * pk_client_get_details_with_deps_size:
4547 * @client: a valid #PkClient instance
4548 *
4549 * Gets the client details-with-deps-size value.
4550 *
4551 * Returns: whether the pk_client_get_details_async() should include dependencies
4552 * download sizes for packages, which are not installed.
4553 *
4554 * Since: 1.2.7
4555 **/
4556 gboolean
4557 pk_client_get_details_with_deps_size (PkClient *client)
4558 {
4559 PkClientPrivate *priv = GET_PRIVATE(client);
4560
4561 g_return_val_if_fail (PK_IS_CLIENT (client), FALSE);
4562
4563 return priv->details_with_deps_size;
4564 }
4565
4566 /*
4567 * pk_client_class_init:
4568 **/
4569 static void
4570 pk_client_class_init (PkClientClass *klass)
4571 {
4572 GObjectClass *object_class = G_OBJECT_CLASS (klass);
4573
4574 object_class->finalize = pk_client_finalize;
4575 object_class->get_property = pk_client_get_property;
4576 object_class->set_property = pk_client_set_property;
4577
4578 /**
4579 * PkClient:locale:
4580 *
4581 * Since: 0.5.3
4582 */
4583 obj_properties[PROP_LOCALE] =
4584 g_param_spec_string ("locale", NULL, NULL,
4585 NULL,
4586 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
4587
4588 /**
4589 * PkClient:background:
4590 *
4591 * Since: 0.5.3
4592 */
4593 obj_properties[PROP_BACKGROUND] =
4594 g_param_spec_boolean ("background", NULL, NULL,
4595 FALSE,
4596 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
4597
4598 /**
4599 * PkClient:interactive:
4600 *
4601 * Since: 0.5.4
4602 */
4603 obj_properties[PROP_INTERACTIVE] =
4604 g_param_spec_boolean ("interactive", NULL, NULL,
4605 TRUE,
4606 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
4607
4608 /**
4609 * PkClient:idle:
4610 *
4611 * Whether there are transactions in progress on this client or not
4612 *
4613 * Since: 0.5.4
4614 */
4615 obj_properties[PROP_IDLE] =
4616 g_param_spec_boolean ("idle", NULL, NULL,
4617 TRUE,
4618 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
4619
4620 /**
4621 * PkClient:cache-age:
4622 *
4623 * The cache age in seconds, where %G_MAXUINT means cache
4624 * "never expires"
4625 *
4626 * Since: 0.6.10
4627 */
4628 obj_properties[PROP_CACHE_AGE] =
4629 g_param_spec_uint ("cache-age", NULL, NULL,
4630 0, G_MAXUINT, G_MAXUINT,
4631 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
4632
4633 /**
4634 * PkClient:details-with-deps-size:
4635 *
4636 * Since: 1.2.7
4637 */
4638 obj_properties[PROP_DETAILS_WITH_DEPS_SIZE] =
4639 g_param_spec_boolean ("details-with-deps-size", NULL, NULL,
4640 FALSE,
4641 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
4642
4643 g_object_class_install_properties (object_class, PROP_LAST, obj_properties);
4644 }
4645
4646 /*
4647 * pk_client_init:
4648 **/
4649 static void
4650 pk_client_init (PkClient *client)
4651 {
4652 PkClientPrivate *priv = GET_PRIVATE(client);
4653
4654 client->priv = priv;
4655 priv->calls = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
4656 priv->background = FALSE;
4657 priv->interactive = TRUE;
4658 priv->cache_age = G_MAXUINT;
4659 priv->details_with_deps_size = FALSE;
4660
4661 /* use a control object */
4662 priv->control = pk_control_new ();
4663
4664 /* cache locale */
4665 priv->locale = g_strdup (setlocale (LC_MESSAGES, NULL));
4666 }
4667
4668 /*
4669 * pk_client_finalize:
4670 **/
4671 static void
4672 pk_client_finalize (GObject *object)
4673 {
4674 PkClient *client = PK_CLIENT (object);
4675 PkClientPrivate *priv = GET_PRIVATE(client);
4676
4677 /* ensure we cancel any in-flight D-Bus calls */
4678 pk_client_cancel_all_dbus_methods (client);
4679
4680 g_clear_pointer (&priv->locale, g_free);
4681 g_clear_object (&priv->control);
4682
4683 g_assert (priv->calls->len == 0);
4684 g_clear_pointer (&priv->calls, g_ptr_array_unref);
4685
4686 G_OBJECT_CLASS (pk_client_parent_class)->finalize (object);
4687 }
4688
4689 /**
4690 * pk_client_new:
4691 *
4692 * #PkClient is a nice GObject wrapper for PackageKit and makes writing
4693 * frontends easy.
4694 *
4695 * Return value: A new #PkClient instance
4696 *
4697 * Since: 0.5.2
4698 **/
4699 PkClient *
4700 pk_client_new (void)
4701 {
4702 PkClient *client;
4703 client = g_object_new (PK_TYPE_CLIENT, NULL);
4704 return PK_CLIENT (client);
4705 }