2010-11-19 17:00:55 +00:00
|
|
|
/*
|
2010-11-23 16:23:37 +00:00
|
|
|
* gtkappchooseronlinepk.c: packagekit module for app-chooser
|
2010-11-19 17:00:55 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with the Gnome Library; see the file COPYING.LIB. If not,
|
|
|
|
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
|
|
|
|
*/
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
#include "config.h"
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
#include "gtkappchooseronlinepk.h"
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
#include "gtkappchooseronline.h"
|
2010-11-24 23:32:05 +00:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
2010-11-19 17:00:55 +00:00
|
|
|
#include "x11/gdkx.h"
|
2010-11-24 23:32:05 +00:00
|
|
|
#endif
|
2010-11-19 17:00:55 +00:00
|
|
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
#define gtk_app_chooser_online_pk_get_type _gtk_app_chooser_online_pk_get_type
|
|
|
|
static void app_chooser_online_iface_init (GtkAppChooserOnlineInterface *iface);
|
2010-11-29 17:10:06 +00:00
|
|
|
static void app_chooser_online_pk_async_initable_init (GAsyncInitableIface *iface);
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkAppChooserOnlinePk, gtk_app_chooser_online_pk,
|
2010-11-24 23:32:05 +00:00
|
|
|
G_TYPE_OBJECT,
|
2010-11-29 17:10:06 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE,
|
|
|
|
app_chooser_online_pk_async_initable_init)
|
2010-11-24 23:32:05 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_APP_CHOOSER_ONLINE,
|
|
|
|
app_chooser_online_iface_init)
|
|
|
|
g_io_extension_point_implement ("gtkappchooser-online",
|
|
|
|
g_define_type_id,
|
|
|
|
"packagekit", 10));
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
struct _GtkAppChooserOnlinePkPrivate {
|
2010-11-29 17:10:06 +00:00
|
|
|
GSimpleAsyncResult *init_result;
|
|
|
|
guint watch_id;
|
|
|
|
|
|
|
|
GDBusProxy *proxy;
|
2010-11-19 17:00:55 +00:00
|
|
|
GSimpleAsyncResult *result;
|
|
|
|
GtkWindow *parent;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2010-11-29 17:10:06 +00:00
|
|
|
gtk_app_chooser_online_pk_dispose (GObject *obj)
|
2010-11-19 17:00:55 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (obj);
|
2010-11-19 17:00:55 +00:00
|
|
|
|
|
|
|
g_clear_object (&self->priv->result);
|
2010-11-29 17:10:06 +00:00
|
|
|
g_clear_object (&self->priv->proxy);
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
G_OBJECT_CLASS (gtk_app_chooser_online_pk_parent_class)->dispose (obj);
|
2010-11-19 17:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_online_pk_class_init (GtkAppChooserOnlinePkClass *klass)
|
2010-11-19 17:00:55 +00:00
|
|
|
{
|
|
|
|
GObjectClass *oclass = G_OBJECT_CLASS (klass);
|
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
oclass->dispose = gtk_app_chooser_online_pk_dispose;
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-23 16:23:37 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GtkAppChooserOnlinePkPrivate));
|
2010-11-19 17:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-23 16:23:37 +00:00
|
|
|
gtk_app_chooser_online_pk_init (GtkAppChooserOnlinePk *self)
|
2010-11-19 17:00:55 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_APP_CHOOSER_ONLINE_PK,
|
2010-11-24 23:32:05 +00:00
|
|
|
GtkAppChooserOnlinePkPrivate);
|
2010-11-19 17:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-11-23 16:23:37 +00:00
|
|
|
pk_search_mime_finish (GtkAppChooserOnline *obj,
|
2010-11-24 23:32:05 +00:00
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
2010-11-19 17:00:55 +00:00
|
|
|
{
|
|
|
|
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
|
|
|
|
|
|
|
return !g_simple_async_result_propagate_error (simple, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-24 23:32:05 +00:00
|
|
|
install_mime_types_ready_cb (GObject *source,
|
|
|
|
GAsyncResult *res,
|
|
|
|
gpointer user_data)
|
2010-11-19 17:00:55 +00:00
|
|
|
{
|
2010-11-23 16:23:37 +00:00
|
|
|
GtkAppChooserOnlinePk *self = user_data;
|
2010-11-19 17:00:55 +00:00
|
|
|
GDBusProxy *proxy = G_DBUS_PROXY (source);
|
|
|
|
GError *error = NULL;
|
|
|
|
GVariant *variant;
|
|
|
|
|
|
|
|
variant = g_dbus_proxy_call_finish (proxy, res, &error);
|
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
if (variant == NULL)
|
|
|
|
{
|
|
|
|
/* don't show errors if the user cancelled the installation explicitely
|
|
|
|
* or if PK wasn't able to find any apps
|
|
|
|
*/
|
|
|
|
if (g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.Cancelled") != 0 &&
|
|
|
|
g_strcmp0 (g_dbus_error_get_remote_error (error), "org.freedesktop.PackageKit.Modify.NoPackagesFound") != 0)
|
|
|
|
g_simple_async_result_set_from_error (self->priv->result, error);
|
2010-11-19 17:33:05 +00:00
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
g_error_free (error);
|
|
|
|
}
|
2010-11-19 17:00:55 +00:00
|
|
|
|
|
|
|
g_simple_async_result_complete (self->priv->result);
|
2012-02-01 18:19:52 +00:00
|
|
|
g_clear_object (&self->priv->result);
|
2010-11-19 17:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 17:10:06 +00:00
|
|
|
pk_search_mime_async (GtkAppChooserOnline *obj,
|
|
|
|
const gchar *content_type,
|
|
|
|
GtkWindow *parent,
|
2011-10-03 15:47:09 +00:00
|
|
|
GCancellable *cancellable,
|
2010-11-29 17:10:06 +00:00
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
2010-11-19 17:00:55 +00:00
|
|
|
{
|
2010-11-29 17:10:06 +00:00
|
|
|
GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (obj);
|
2010-11-19 17:00:55 +00:00
|
|
|
guint xid = 0;
|
|
|
|
GdkWindow *window;
|
|
|
|
const gchar *mime_types[2];
|
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
self->priv->result = g_simple_async_result_new (G_OBJECT (self),
|
|
|
|
callback, user_data,
|
2010-12-05 17:18:30 +00:00
|
|
|
_gtk_app_chooser_online_search_for_mimetype_async);
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-24 23:32:05 +00:00
|
|
|
#ifdef GDK_WINDOWING_X11
|
2010-11-29 17:10:06 +00:00
|
|
|
window = gtk_widget_get_window (GTK_WIDGET (parent));
|
2010-11-19 17:00:55 +00:00
|
|
|
xid = GDK_WINDOW_XID (window);
|
2010-11-24 23:32:05 +00:00
|
|
|
#endif
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
mime_types[0] = content_type;
|
2010-11-19 17:00:55 +00:00
|
|
|
mime_types[1] = NULL;
|
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
g_dbus_proxy_call (self->priv->proxy,
|
2010-11-24 23:32:05 +00:00
|
|
|
"InstallMimeTypes",
|
|
|
|
g_variant_new ("(u^ass)",
|
|
|
|
xid,
|
|
|
|
mime_types,
|
|
|
|
"hide-confirm-search"),
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
G_MAXINT, /* no timeout */
|
2011-10-03 15:47:09 +00:00
|
|
|
cancellable,
|
2010-11-24 23:32:05 +00:00
|
|
|
install_mime_types_ready_cb,
|
|
|
|
self);
|
2010-11-19 17:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 17:10:06 +00:00
|
|
|
app_chooser_online_iface_init (GtkAppChooserOnlineInterface *iface)
|
2010-11-19 17:00:55 +00:00
|
|
|
{
|
2010-11-29 17:10:06 +00:00
|
|
|
iface->search_for_mimetype_async = pk_search_mime_async;
|
|
|
|
iface->search_for_mimetype_finish = pk_search_mime_finish;
|
|
|
|
}
|
2010-11-19 17:00:55 +00:00
|
|
|
|
2010-11-29 17:10:06 +00:00
|
|
|
static void
|
|
|
|
pk_proxy_created_cb (GObject *source,
|
|
|
|
GAsyncResult *result,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkAppChooserOnlinePk *self = user_data;
|
|
|
|
GDBusProxy *proxy;
|
|
|
|
|
|
|
|
proxy = g_dbus_proxy_new_finish (result, NULL);
|
|
|
|
|
|
|
|
if (proxy == NULL)
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_op_res_gboolean (self->priv->init_result, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_simple_async_result_set_op_res_gboolean (self->priv->init_result, TRUE);
|
|
|
|
self->priv->proxy = proxy;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_simple_async_result_complete (self->priv->init_result);
|
|
|
|
g_clear_object (&self->priv->init_result);
|
2010-11-19 17:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-29 17:10:06 +00:00
|
|
|
pk_appeared_cb (GDBusConnection *conn,
|
|
|
|
const gchar *name,
|
|
|
|
const gchar *owner,
|
|
|
|
gpointer user_data)
|
2010-11-19 17:00:55 +00:00
|
|
|
{
|
2010-11-29 17:10:06 +00:00
|
|
|
GtkAppChooserOnlinePk *self = user_data;
|
|
|
|
|
|
|
|
/* create the proxy */
|
|
|
|
g_dbus_proxy_new (conn, 0, NULL,
|
|
|
|
"org.freedesktop.PackageKit",
|
|
|
|
"/org/freedesktop/PackageKit",
|
|
|
|
"org.freedesktop.PackageKit.Modify",
|
|
|
|
NULL,
|
|
|
|
pk_proxy_created_cb,
|
|
|
|
self);
|
|
|
|
|
|
|
|
g_bus_unwatch_name (self->priv->watch_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pk_vanished_cb (GDBusConnection *conn,
|
|
|
|
const gchar *name,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkAppChooserOnlinePk *self = user_data;
|
|
|
|
|
|
|
|
/* just return */
|
|
|
|
g_simple_async_result_set_op_res_gboolean (self->priv->init_result, FALSE);
|
|
|
|
g_simple_async_result_complete (self->priv->init_result);
|
|
|
|
|
|
|
|
g_bus_unwatch_name (self->priv->watch_id);
|
|
|
|
|
|
|
|
g_clear_object (&self->priv->init_result);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
app_chooser_online_pk_init_finish (GAsyncInitable *init,
|
|
|
|
GAsyncResult *res,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
return g_simple_async_result_get_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (res));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
app_chooser_online_pk_init_async (GAsyncInitable *init,
|
|
|
|
int io_priority,
|
|
|
|
GCancellable *cancellable,
|
|
|
|
GAsyncReadyCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkAppChooserOnlinePk *self = GTK_APP_CHOOSER_ONLINE_PK (init);
|
|
|
|
|
|
|
|
self->priv->init_result = g_simple_async_result_new (G_OBJECT (self),
|
|
|
|
callback, user_data,
|
2010-12-05 17:18:30 +00:00
|
|
|
_gtk_app_chooser_online_get_default_async);
|
2010-11-29 17:10:06 +00:00
|
|
|
|
|
|
|
self->priv->watch_id =
|
|
|
|
g_bus_watch_name (G_BUS_TYPE_SESSION,
|
|
|
|
"org.freedesktop.PackageKit",
|
|
|
|
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
|
|
|
pk_appeared_cb,
|
|
|
|
pk_vanished_cb,
|
|
|
|
self,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
app_chooser_online_pk_async_initable_init (GAsyncInitableIface *iface)
|
|
|
|
{
|
|
|
|
iface->init_async = app_chooser_online_pk_init_async;
|
|
|
|
iface->init_finish = app_chooser_online_pk_init_finish;
|
2010-11-19 17:00:55 +00:00
|
|
|
}
|