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 GCancellable *cancellable,
128 GAsyncReadyCallback callback,
131 GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (obj);
134 const gchar *mime_types[2];
136 self->priv->result = g_simple_async_result_new (G_OBJECT (self),
138 _gtk_app_chooser_online_search_for_mimetype_async);
140 #ifdef GDK_WINDOWING_X11
141 window = gtk_widget_get_window (GTK_WIDGET (parent));
142 xid = GDK_WINDOW_XID (window);
145 mime_types[0] = content_type;
146 mime_types[1] = NULL;
148 g_dbus_proxy_call (self->priv->proxy,
150 g_variant_new ("(u^ass)",
153 "hide-confirm-search"),
154 G_DBUS_CALL_FLAGS_NONE,
155 G_MAXINT, /* no timeout */
157 install_mime_types_ready_cb,
162 app_chooser_online_iface_init (GtkAppChooserOnlineInterface *iface)
164 iface->search_for_mimetype_async = pk_search_mime_async;
165 iface->search_for_mimetype_finish = pk_search_mime_finish;
169 pk_proxy_created_cb (GObject *source,
170 GAsyncResult *result,
173 GtkAppChooserOnlinePk *self = user_data;
176 proxy = g_dbus_proxy_new_finish (result, NULL);
180 g_simple_async_result_set_op_res_gboolean (self->priv->init_result, FALSE);
184 g_simple_async_result_set_op_res_gboolean (self->priv->init_result, TRUE);
185 self->priv->proxy = proxy;
188 g_simple_async_result_complete (self->priv->init_result);
189 g_clear_object (&self->priv->init_result);
193 pk_appeared_cb (GDBusConnection *conn,
198 GtkAppChooserOnlinePk *self = user_data;
200 /* create the proxy */
201 g_dbus_proxy_new (conn, 0, NULL,
202 "org.freedesktop.PackageKit",
203 "/org/freedesktop/PackageKit",
204 "org.freedesktop.PackageKit.Modify",
209 g_bus_unwatch_name (self->priv->watch_id);
213 pk_vanished_cb (GDBusConnection *conn,
217 GtkAppChooserOnlinePk *self = user_data;
220 g_simple_async_result_set_op_res_gboolean (self->priv->init_result, FALSE);
221 g_simple_async_result_complete (self->priv->init_result);
223 g_bus_unwatch_name (self->priv->watch_id);
225 g_clear_object (&self->priv->init_result);
229 app_chooser_online_pk_init_finish (GAsyncInitable *init,
233 return g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res));
237 app_chooser_online_pk_init_async (GAsyncInitable *init,
239 GCancellable *cancellable,
240 GAsyncReadyCallback callback,
243 GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (init);
245 self->priv->init_result = g_simple_async_result_new (G_OBJECT (self),
247 _gtk_app_chooser_online_get_default_async);
249 self->priv->watch_id =
250 g_bus_watch_name (G_BUS_TYPE_SESSION,
251 "org.freedesktop.PackageKit",
252 G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
260 app_chooser_online_pk_async_initable_init (GAsyncInitableIface *iface)
262 iface->init_async = app_chooser_online_pk_init_async;
263 iface->init_finish = app_chooser_online_pk_init_finish;