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