2 * Copyright (C) 2012 Collabora Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Guillaume Desmottes <guillaume.desmottes@collabora.com>
23 #include "empathy-pkg-kit.h"
31 GSimpleAsyncResult *result;
32 GCancellable *cancellable;
36 install_ctx_new (guint xid,
37 const gchar **packages,
39 GSimpleAsyncResult *result,
40 GCancellable *cancellable)
42 InstallCtx *ctx = g_slice_new (InstallCtx);
45 ctx->packages = g_strdupv ((gchar **) packages);
46 ctx->options = g_strdup (options);
47 ctx->result = g_object_ref (result);
48 ctx->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
53 install_ctx_free (InstallCtx *ctx)
55 g_free (ctx->packages);
56 g_free (ctx->options);
57 g_object_unref (ctx->result);
58 g_slice_free (InstallCtx, ctx);
62 install_ctx_complete (InstallCtx *ctx)
64 g_simple_async_result_complete (ctx->result);
65 install_ctx_free (ctx);
69 install_ctx_failed (InstallCtx *ctx,
72 g_simple_async_result_take_error (ctx->result, error);
73 install_ctx_complete (ctx);
77 install_package_names_cb (GObject *source,
81 InstallCtx *ctx = user_data;
85 res = g_dbus_proxy_call_finish (G_DBUS_PROXY (source), result, &error);
88 install_ctx_failed (ctx, error);
92 install_ctx_complete (ctx);
94 g_variant_unref (res);
98 pkg_kit_proxy_new_cb (GObject *source,
102 InstallCtx *ctx = user_data;
103 GError *error = NULL;
106 proxy = g_dbus_proxy_new_for_bus_finish (result, &error);
109 install_ctx_failed (ctx, error);
113 g_dbus_proxy_call (proxy, "InstallPackageNames",
114 g_variant_new ("(u^a&ss)", ctx->xid, ctx->packages, ctx->options),
115 G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, install_package_names_cb, ctx);
117 g_object_unref (proxy);
120 /* Ideally this should live in PackageKit (fdo #45741) */
122 empathy_pkg_kit_install_packages_async (
124 const gchar **packages,
125 const gchar *options,
126 GCancellable *cancellable,
127 GAsyncReadyCallback callback,
131 GSimpleAsyncResult *result;
133 result = g_simple_async_result_new (NULL, callback, user_data,
134 empathy_pkg_kit_install_packages_async);
136 ctx = install_ctx_new (xid, packages, options != NULL ? options : "",
137 result, cancellable);
139 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
140 G_DBUS_PROXY_FLAGS_NONE, NULL,
141 "org.freedesktop.PackageKit",
142 "/org/freedesktop/PackageKit",
143 "org.freedesktop.PackageKit.Modify",
144 NULL, pkg_kit_proxy_new_cb, ctx);
146 g_object_unref (result);
150 empathy_pkg_kit_install_packages_finish (GAsyncResult *result,
153 g_return_val_if_fail (g_simple_async_result_is_valid (result, NULL,
154 empathy_pkg_kit_install_packages_async), FALSE);
156 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result),