2 * gtkappchooseronlinepk.c: packagekit module for app-chooser
4 * Copyright (C) 2010 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with the Gnome Library; see the file COPYING.LIB. If not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
21 * Authors: Cosimo Cecchi <ccecchi@redhat.com>
26 #include "gtkappchooseronlinepk.h"
28 #include "gtkappchooseronline.h"
29 #ifdef GDK_WINDOWING_X11
35 #define gtk_app_chooser_online_pk_get_type _gtk_app_chooser_online_pk_get_type
36 static void app_chooser_online_iface_init (GtkAppChooserOnlineInterface *iface);
37 static void app_chooser_online_pk_async_initable_init (GAsyncInitableIface *iface);
39 G_DEFINE_TYPE_WITH_CODE (GtkAppChooserOnlinePk, gtk_app_chooser_online_pk,
41 G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
42 app_chooser_online_pk_async_initable_init)
43 G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER_ONLINE,
44 app_chooser_online_iface_init)
45 g_io_extension_point_implement ("gtkappchooser-online",
49 struct _GtkAppChooserOnlinePkPrivate {
50 GSimpleAsyncResult *init_result;
54 GSimpleAsyncResult *result;
59 gtk_app_chooser_online_pk_dispose (GObject *obj)
61 GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (obj);
63 g_clear_object (&self->priv->result);
64 g_clear_object (&self->priv->proxy);
66 G_OBJECT_CLASS (gtk_app_chooser_online_pk_parent_class)->dispose (obj);
70 gtk_app_chooser_online_pk_class_init (GtkAppChooserOnlinePkClass *klass)
72 GObjectClass *oclass = G_OBJECT_CLASS (klass);
74 oclass->dispose = gtk_app_chooser_online_pk_dispose;
76 g_type_class_add_private (klass, sizeof (GtkAppChooserOnlinePkPrivate));
80 gtk_app_chooser_online_pk_init (GtkAppChooserOnlinePk *self)
82 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_ONLINE_PK,
83 GtkAppChooserOnlinePkPrivate);
87 pk_search_mime_finish (GtkAppChooserOnline *obj,
91 GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
93 return !g_simple_async_result_propagate_error (simple, error);
97 install_mime_types_ready_cb (GObject *source,
101 GtkAppChooserOnlinePk *self = user_data;
102 GDBusProxy *proxy = G_DBUS_PROXY (source);
103 GError *error = NULL;
106 variant = g_dbus_proxy_call_finish (proxy, res, &error);
110 /* don't show errors if the user cancelled the installation explicitely
111 * or if PK wasn't able to find any apps
113 if (g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.Cancelled") != 0 &&
114 g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.NoPackagesFound") != 0)
115 g_simple_async_result_set_from_error (self->priv->result, error);
117 g_error_free (error);
120 g_simple_async_result_complete (self->priv->result);
124 pk_search_mime_async (GtkAppChooserOnline *obj,
125 const gchar *content_type,
127 GAsyncReadyCallback callback,
130 GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (obj);
133 const gchar *mime_types[2];
135 self->priv->result = g_simple_async_result_new (G_OBJECT (self),
137 _gtk_app_chooser_online_search_for_mimetype_async);
139 #ifdef GDK_WINDOWING_X11
140 window = gtk_widget_get_window (GTK_WIDGET (parent));
141 xid = GDK_WINDOW_XID (window);
144 mime_types[0] = content_type;
145 mime_types[1] = NULL;
147 g_dbus_proxy_call (self->priv->proxy,
149 g_variant_new ("(u^ass)",
152 "hide-confirm-search"),
153 G_DBUS_CALL_FLAGS_NONE,
154 G_MAXINT, /* no timeout */
156 install_mime_types_ready_cb,
161 app_chooser_online_iface_init (GtkAppChooserOnlineInterface *iface)
163 iface->search_for_mimetype_async = pk_search_mime_async;
164 iface->search_for_mimetype_finish = pk_search_mime_finish;
168 pk_proxy_created_cb (GObject *source,
169 GAsyncResult *result,
172 GtkAppChooserOnlinePk *self = user_data;
175 proxy = g_dbus_proxy_new_finish (result, NULL);
179 g_simple_async_result_set_op_res_gboolean (self->priv->init_result, FALSE);
183 g_simple_async_result_set_op_res_gboolean (self->priv->init_result, TRUE);
184 self->priv->proxy = proxy;
187 g_simple_async_result_complete (self->priv->init_result);
188 g_clear_object (&self->priv->init_result);
192 pk_appeared_cb (GDBusConnection *conn,
197 GtkAppChooserOnlinePk *self = user_data;
199 /* create the proxy */
200 g_dbus_proxy_new (conn, 0, NULL,
201 "org.freedesktop.PackageKit",
202 "/org/freedesktop/PackageKit",
203 "org.freedesktop.PackageKit.Modify",
208 g_bus_unwatch_name (self->priv->watch_id);
212 pk_vanished_cb (GDBusConnection *conn,
216 GtkAppChooserOnlinePk *self = user_data;
219 g_simple_async_result_set_op_res_gboolean (self->priv->init_result, FALSE);
220 g_simple_async_result_complete (self->priv->init_result);
222 g_bus_unwatch_name (self->priv->watch_id);
224 g_clear_object (&self->priv->init_result);
228 app_chooser_online_pk_init_finish (GAsyncInitable *init,
232 return g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res));
236 app_chooser_online_pk_init_async (GAsyncInitable *init,
238 GCancellable *cancellable,
239 GAsyncReadyCallback callback,
242 GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (init);
244 self->priv->init_result = g_simple_async_result_new (G_OBJECT (self),
246 _gtk_app_chooser_online_get_default_async);
248 self->priv->watch_id =
249 g_bus_watch_name (G_BUS_TYPE_SESSION,
250 "org.freedesktop.PackageKit",
251 G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
259 app_chooser_online_pk_async_initable_init (GAsyncInitableIface *iface)
261 iface->init_async = app_chooser_online_pk_init_async;
262 iface->init_finish = app_chooser_online_pk_init_finish;