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>
22 #include "empathy-pkg-kit.h"
30 GSimpleAsyncResult
*result
;
31 GCancellable
*cancellable
;
35 install_ctx_new (guint xid
,
36 const gchar
**packages
,
38 GSimpleAsyncResult
*result
,
39 GCancellable
*cancellable
)
41 InstallCtx
*ctx
= g_slice_new (InstallCtx
);
44 ctx
->packages
= g_strdupv ((gchar
**) packages
);
45 ctx
->options
= g_strdup (options
);
46 ctx
->result
= g_object_ref (result
);
47 ctx
->cancellable
= cancellable
!= NULL
? g_object_ref (cancellable
) : NULL
;
52 install_ctx_free (InstallCtx
*ctx
)
54 g_free (ctx
->packages
);
55 g_free (ctx
->options
);
56 g_object_unref (ctx
->result
);
57 g_slice_free (InstallCtx
, ctx
);
61 install_ctx_complete (InstallCtx
*ctx
)
63 g_simple_async_result_complete (ctx
->result
);
64 install_ctx_free (ctx
);
68 install_ctx_failed (InstallCtx
*ctx
,
71 g_simple_async_result_take_error (ctx
->result
, error
);
72 install_ctx_complete (ctx
);
76 install_package_names_cb (GObject
*source
,
80 InstallCtx
*ctx
= user_data
;
84 res
= g_dbus_proxy_call_finish (G_DBUS_PROXY (source
), result
, &error
);
87 install_ctx_failed (ctx
, error
);
91 install_ctx_complete (ctx
);
93 g_variant_unref (res
);
97 pkg_kit_proxy_new_cb (GObject
*source
,
101 InstallCtx
*ctx
= user_data
;
102 GError
*error
= NULL
;
105 proxy
= g_dbus_proxy_new_for_bus_finish (result
, &error
);
108 install_ctx_failed (ctx
, error
);
112 g_dbus_proxy_call (proxy
, "InstallPackageNames",
113 g_variant_new ("(u^a&ss)", ctx
->xid
, ctx
->packages
, ctx
->options
),
114 G_DBUS_CALL_FLAGS_NONE
, G_MAXINT
, NULL
, install_package_names_cb
, ctx
);
116 g_object_unref (proxy
);
119 /* Ideally this should live in PackageKit (fdo #45741) */
121 empathy_pkg_kit_install_packages_async (
123 const gchar
**packages
,
124 const gchar
*options
,
125 GCancellable
*cancellable
,
126 GAsyncReadyCallback callback
,
130 GSimpleAsyncResult
*result
;
132 result
= g_simple_async_result_new (NULL
, callback
, user_data
,
133 empathy_pkg_kit_install_packages_async
);
135 ctx
= install_ctx_new (xid
, packages
, options
!= NULL
? options
: "",
136 result
, cancellable
);
138 g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION
,
139 G_DBUS_PROXY_FLAGS_NONE
, NULL
,
140 "org.freedesktop.PackageKit",
141 "/org/freedesktop/PackageKit",
142 "org.freedesktop.PackageKit.Modify",
143 NULL
, pkg_kit_proxy_new_cb
, ctx
);
145 g_object_unref (result
);
149 empathy_pkg_kit_install_packages_finish (GAsyncResult
*result
,
152 g_return_val_if_fail (g_simple_async_result_is_valid (result
, NULL
,
153 empathy_pkg_kit_install_packages_async
), FALSE
);
155 if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result
),