forked from AuroraMiddleware/gtk
open-with: add a PackageKit module for online lookup of applications
It's implemented with a GIOExtensionPoint, which has two implementations: - a dummy one, which just errors out - a PackageKit one, which looks up for the specified content type using the PK DBus API and GDBus. The PK module is optional, and can be compiled out at configure time. TODO: a Win32 implementation of the module.
This commit is contained in:
parent
86a8f99806
commit
d4e1dd9734
19
configure.ac
19
configure.ac
@ -1488,6 +1488,25 @@ GLIB_GSETTINGS
|
||||
|
||||
GOBJECT_INTROSPECTION_CHECK([0.9.3])
|
||||
|
||||
##################################################
|
||||
# Packagekit module
|
||||
#################################################
|
||||
|
||||
AC_ARG_ENABLE(packagekit,
|
||||
AC_HELP_STRING([--disable-packagekit],
|
||||
[build packagekit open with module]))
|
||||
|
||||
ENABLE_PACKAGEKIT=
|
||||
if test "os_win32" != "yes"; then
|
||||
if test "x$enable_packagekit" != "xno"; then
|
||||
ENABLE_PACKAGEKIT=1
|
||||
AC_DEFINE(ENABLE_PACKAGEKIT, 1, [define to enable packagekit])
|
||||
fi
|
||||
fi
|
||||
|
||||
AC_SUBST(ENABLE_PACKAGEKIT)
|
||||
AM_CONDITIONAL(ENABLE_PACKAGEKIT, test "x$ENABLE_PACKAGEKIT" = "x1")
|
||||
|
||||
##################################################
|
||||
# Checks for gtk-doc and docbook-tools
|
||||
##################################################
|
||||
|
@ -249,6 +249,7 @@ gtk_public_h_sources = \
|
||||
gtkopenwith.h \
|
||||
gtkopenwithdialog.h \
|
||||
gtkopenwithwidget.h \
|
||||
gtkopenwithonline.h \
|
||||
gtkorientable.h \
|
||||
gtkpagesetup.h \
|
||||
gtkpaned.h \
|
||||
@ -352,6 +353,18 @@ endif
|
||||
gtk_semi_private_h_sources = \
|
||||
gtktextlayout.h
|
||||
|
||||
if ENABLE_PACKAGEKIT
|
||||
gtk_openwith_impl_h_sources = \
|
||||
gtkopenwithonlinepk.h \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
if ENABLE_PACKAGEKIT
|
||||
gtk_openwith_impl_c_sources = \
|
||||
gtkopenwithonlinepk.c \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
# GTK+ header files that don't get installed
|
||||
gtk_private_h_sources = \
|
||||
gtkbuttonprivate.h \
|
||||
@ -377,6 +390,8 @@ gtk_private_h_sources = \
|
||||
gtkmnemonichash.h \
|
||||
gtkmountoperationprivate.h \
|
||||
gtkopenwithprivate.h \
|
||||
gtkopenwithmodule.h \
|
||||
gtkopenwithonlinedummy.h \
|
||||
gtkpango.h \
|
||||
gtkpathbar.h \
|
||||
gtkplugprivate.h \
|
||||
@ -404,7 +419,8 @@ gtk_private_h_sources = \
|
||||
gtktreeprivate.h \
|
||||
gtkwindow-decorate.h \
|
||||
gtkwidgetprivate.h \
|
||||
$(gtk_clipboard_dnd_h_sources)
|
||||
$(gtk_clipboard_dnd_h_sources) \
|
||||
$(gtk_openwith_impl_h_sources)
|
||||
|
||||
# GTK+ C sources to build the library from
|
||||
gtk_base_c_sources = \
|
||||
@ -523,6 +539,9 @@ gtk_base_c_sources = \
|
||||
gtkopenwith.c \
|
||||
gtkopenwithwidget.c \
|
||||
gtkopenwithdialog.c \
|
||||
gtkopenwithmodule.c \
|
||||
gtkopenwithonline.c \
|
||||
gtkopenwithonlinedummy.c \
|
||||
gtkorientable.c \
|
||||
gtkpagesetup.c \
|
||||
gtkpaned.c \
|
||||
@ -627,7 +646,8 @@ gtk_base_c_sources = \
|
||||
gtkwidget.c \
|
||||
gtkwindow-decorate.c \
|
||||
gtkwindow.c \
|
||||
$(gtk_clipboard_dnd_c_sources)
|
||||
$(gtk_clipboard_dnd_c_sources) \
|
||||
$(gtk_openwith_impl_c_sources)
|
||||
|
||||
gtk_c_sources = $(gtk_base_c_sources)
|
||||
gtk_all_c_sources = $(gtk_base_c_sources)
|
||||
|
62
gtk/gtkopenwithmodule.c
Normal file
62
gtk/gtkopenwithmodule.c
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* gtkopenwithmodule.c: an extension point for online integration
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "gtkopenwithmodule.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#include "gtkopenwithonline.h"
|
||||
#include "gtkopenwithonlinedummy.h"
|
||||
|
||||
#ifdef ENABLE_PACKAGEKIT
|
||||
#include "gtkopenwithonlinepk.h"
|
||||
#endif
|
||||
|
||||
G_LOCK_DEFINE_STATIC (registered_ep);
|
||||
|
||||
void
|
||||
_gtk_open_with_module_ensure (void)
|
||||
{
|
||||
static gboolean registered_ep = FALSE;
|
||||
GIOExtensionPoint *ep;
|
||||
|
||||
G_LOCK (registered_ep);
|
||||
|
||||
if (!registered_ep)
|
||||
{
|
||||
registered_ep = TRUE;
|
||||
|
||||
ep = g_io_extension_point_register ("gtkopenwith-online");
|
||||
g_io_extension_point_set_required_type (ep, GTK_TYPE_OPEN_WITH_ONLINE);
|
||||
|
||||
_gtk_open_with_online_dummy_get_type ();
|
||||
|
||||
#ifdef ENABLE_PACKAGEKIT
|
||||
_gtk_open_with_online_pk_get_type ();
|
||||
#endif
|
||||
}
|
||||
|
||||
G_UNLOCK (registered_ep);
|
||||
}
|
35
gtk/gtkopenwithmodule.h
Normal file
35
gtk/gtkopenwithmodule.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* gtkopenwithmodule.h: an extension point for PackageKit integration
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_OPEN_WITH_MODULE_H__
|
||||
#define __GTK_OPEN_WITH_MODULE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
void _gtk_open_with_module_ensure (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_OPEN_WITH_MODULE_H__ */
|
98
gtk/gtkopenwithonline.c
Normal file
98
gtk/gtkopenwithonline.c
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* gtkopenwithonline.h: an extension point for online integration
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "gtkopenwithonline.h"
|
||||
|
||||
#include "gtkopenwithonlinedummy.h"
|
||||
#include "gtkopenwithmodule.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_DEFINE_INTERFACE (GtkOpenWithOnline, gtk_open_with_online, G_TYPE_OBJECT);
|
||||
|
||||
static void
|
||||
gtk_open_with_online_default_init (GtkOpenWithOnlineInterface *iface)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
GtkOpenWithOnline *
|
||||
gtk_open_with_online_get_default (void)
|
||||
{
|
||||
GIOExtensionPoint *ep;
|
||||
GIOExtension *extension;
|
||||
GList *extensions;
|
||||
GtkOpenWithOnline *retval;
|
||||
|
||||
_gtk_open_with_module_ensure ();
|
||||
|
||||
ep = g_io_extension_point_lookup ("gtkopenwith-online");
|
||||
extensions = g_io_extension_point_get_extensions (ep);
|
||||
|
||||
if (extensions != NULL)
|
||||
{
|
||||
/* pick the first */
|
||||
extension = extensions->data;
|
||||
retval = g_object_new (g_io_extension_get_type (extension),
|
||||
NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
retval = g_object_new (GTK_TYPE_OPEN_WITH_ONLINE_DUMMY,
|
||||
NULL);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
gtk_open_with_online_search_for_mimetype_async (GtkOpenWithOnline *self,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkOpenWithOnlineInterface *iface;
|
||||
|
||||
g_return_if_fail (GTK_IS_OPEN_WITH_ONLINE (self));
|
||||
|
||||
iface = GTK_OPEN_WITH_ONLINE_GET_IFACE (self);
|
||||
|
||||
(* iface->search_for_mimetype_async) (self, content_type, parent, callback, user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gtk_open_with_online_search_for_mimetype_finish (GtkOpenWithOnline *self,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
GtkOpenWithOnlineInterface *iface;
|
||||
|
||||
g_return_val_if_fail (GTK_IS_OPEN_WITH_ONLINE (self), FALSE);
|
||||
|
||||
iface = GTK_OPEN_WITH_ONLINE_GET_IFACE (self);
|
||||
|
||||
return ((* iface->search_for_mimetype_finish) (self, res, error));
|
||||
}
|
73
gtk/gtkopenwithonline.h
Normal file
73
gtk/gtkopenwithonline.h
Normal file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* gtkopenwithonline.h: an extension point for online integration
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_OPEN_WITH_ONLINE_H__
|
||||
#define __GTK_OPEN_WITH_ONLINE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <gtk/gtkwindow.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GTK_TYPE_OPEN_WITH_ONLINE\
|
||||
(gtk_open_with_online_get_type ())
|
||||
#define GTK_OPEN_WITH_ONLINE(o)\
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_OPEN_WITH_ONLINE, GtkOpenWithOnline))
|
||||
#define GTK_IS_OPEN_WITH_ONLINE(o)\
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_OPEN_WITH_ONLINE))
|
||||
#define GTK_OPEN_WITH_ONLINE_GET_IFACE(obj)\
|
||||
(G_TYPE_INSTANCE_GET_INTERFACE ((obj), GTK_TYPE_OPEN_WITH_ONLINE, GtkOpenWithOnlineInterface))
|
||||
|
||||
typedef struct _GtkOpenWithOnline GtkOpenWithOnline;
|
||||
typedef struct _GtkOpenWithOnlineInterface GtkOpenWithOnlineInterface;
|
||||
|
||||
struct _GtkOpenWithOnlineInterface {
|
||||
GTypeInterface g_iface;
|
||||
|
||||
/* Methods */
|
||||
void (*search_for_mimetype_async) (GtkOpenWithOnline *self,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean (*search_for_mimetype_finish) (GtkOpenWithOnline *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
};
|
||||
|
||||
GType gtk_open_with_online_get_type (void) G_GNUC_CONST;
|
||||
void gtk_open_with_online_search_for_mimetype_async (GtkOpenWithOnline *self,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data);
|
||||
gboolean gtk_open_with_online_search_for_mimetype_finish (GtkOpenWithOnline *self,
|
||||
GAsyncResult *res,
|
||||
GError **error);
|
||||
|
||||
GtkOpenWithOnline * gtk_open_with_online_get_default (void);
|
||||
|
||||
#endif /* __GTK_OPEN_WITH_ONLINE_H__ */
|
86
gtk/gtkopenwithonlinedummy.c
Normal file
86
gtk/gtkopenwithonlinedummy.c
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* gtkopenwithonlinedummy.c: an extension point for online integration
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "gtkopenwithonlinedummy.h"
|
||||
|
||||
#include "gtkintl.h"
|
||||
#include "gtkopenwithonline.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define gtk_open_with_online_dummy_get_type _gtk_open_with_online_dummy_get_type
|
||||
static void open_with_online_iface_init (GtkOpenWithOnlineInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkOpenWithOnlineDummy, gtk_open_with_online_dummy,
|
||||
G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_OPEN_WITH_ONLINE,
|
||||
open_with_online_iface_init)
|
||||
g_io_extension_point_implement ("gtkopenwith-online",
|
||||
g_define_type_id,
|
||||
"dummy", 0));
|
||||
|
||||
static void
|
||||
gtk_open_with_online_dummy_class_init (GtkOpenWithOnlineDummyClass *klass)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_open_with_online_dummy_init (GtkOpenWithOnlineDummy *self)
|
||||
{
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
static gboolean
|
||||
dummy_search_mime_finish (GtkOpenWithOnline *obj,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
||||
|
||||
return !g_simple_async_result_propagate_error (simple, error);
|
||||
}
|
||||
|
||||
static void
|
||||
dummy_search_mime_async (GtkOpenWithOnline *obj,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
g_simple_async_report_error_in_idle (G_OBJECT (obj),
|
||||
callback, user_data,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_FAILED,
|
||||
"%s",
|
||||
_("Operation not supported"));
|
||||
}
|
||||
|
||||
static void
|
||||
open_with_online_iface_init (GtkOpenWithOnlineInterface *iface)
|
||||
{
|
||||
iface->search_for_mimetype_async = dummy_search_mime_async;
|
||||
iface->search_for_mimetype_finish = dummy_search_mime_finish;
|
||||
}
|
59
gtk/gtkopenwithonlinedummy.h
Normal file
59
gtk/gtkopenwithonlinedummy.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* gtkopenwithonlinedummy.h: an extension point for online integration
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_OPEN_WITH_ONLINE_DUMMY_H__
|
||||
#define __GTK_OPEN_WITH_ONLINE_DUMMY_H__
|
||||
|
||||
#include <gtk/gtkopenwithonline.h>
|
||||
#include <glib.h>
|
||||
|
||||
#define GTK_TYPE_OPEN_WITH_ONLINE_DUMMY\
|
||||
(_gtk_open_with_online_dummy_get_type ())
|
||||
#define GTK_OPEN_WITH_ONLINE_DUMMY(obj)\
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_OPEN_WITH_ONLINE_DUMMY, GtkOpenWithOnlineDummy))
|
||||
#define GTK_OPEN_WITH_ONLINE_DUMMY_CLASS(klass)\
|
||||
(G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_OPEN_WITH_ONLINE_DUMMY, GtkOpenWithOnlineDummyClass))
|
||||
#define GTK_IS_OPEN_WITH_ONLINE_DUMMY(obj)\
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_OPEN_WITH_ONLINE_DUMMY))
|
||||
#define GTK_IS_OPEN_WITH_ONLINE_DUMMY_CLASS(klass)\
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OPEN_WITH_ONLINE_DUMMY))
|
||||
#define GTK_OPEN_WITH_ONLINE_DUMMY_GET_CLASS(obj)\
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_OPEN_WITH_ONLINE_DUMMY, GtkOpenWithOnlineDummyClass))
|
||||
|
||||
typedef struct _GtkOpenWithOnlineDummy GtkOpenWithOnlineDummy;
|
||||
typedef struct _GtkOpenWithOnlineDummyClass GtkOpenWithOnlineDummyClass;
|
||||
typedef struct _GtkOpenWithOnlineDummyPrivate GtkOpenWithOnlineDummyPrivate;
|
||||
|
||||
struct _GtkOpenWithOnlineDummy {
|
||||
GObject parent;
|
||||
};
|
||||
|
||||
struct _GtkOpenWithOnlineDummyClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
GtkOpenWithOnlineDummy *priv;
|
||||
};
|
||||
|
||||
GType _gtk_open_with_online_dummy_get_type (void);
|
||||
|
||||
#endif /* __GTK_OPEN_WITH_ONLINE_DUMMY_H__ */
|
181
gtk/gtkopenwithonlinepk.c
Normal file
181
gtk/gtkopenwithonlinepk.c
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* gtkopenwithonlinepk.c: packagekit module for open with
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "gtkopenwithonlinepk.h"
|
||||
|
||||
#include "gtkopenwithonline.h"
|
||||
#include "x11/gdkx.h"
|
||||
|
||||
#include <gio/gio.h>
|
||||
|
||||
#define gtk_open_with_online_pk_get_type _gtk_open_with_online_pk_get_type
|
||||
static void open_with_online_iface_init (GtkOpenWithOnlineInterface *iface);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkOpenWithOnlinePk, gtk_open_with_online_pk,
|
||||
G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_OPEN_WITH_ONLINE,
|
||||
open_with_online_iface_init)
|
||||
g_io_extension_point_implement ("gtkopenwith-online",
|
||||
g_define_type_id,
|
||||
"packagekit", 10));
|
||||
|
||||
struct _GtkOpenWithOnlinePkPrivate {
|
||||
GSimpleAsyncResult *result;
|
||||
GtkWindow *parent;
|
||||
gchar *content_type;
|
||||
};
|
||||
|
||||
static void
|
||||
gtk_open_with_online_pk_finalize (GObject *obj)
|
||||
{
|
||||
GtkOpenWithOnlinePk *self = GTK_OPEN_WITH_ONLINE_PK (obj);
|
||||
|
||||
g_free (self->priv->content_type);
|
||||
g_clear_object (&self->priv->result);
|
||||
|
||||
G_OBJECT_CLASS (gtk_open_with_online_pk_parent_class)->finalize (obj);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_open_with_online_pk_class_init (GtkOpenWithOnlinePkClass *klass)
|
||||
{
|
||||
GObjectClass *oclass = G_OBJECT_CLASS (klass);
|
||||
|
||||
oclass->finalize = gtk_open_with_online_pk_finalize;
|
||||
|
||||
g_type_class_add_private (klass, sizeof (GtkOpenWithOnlinePkPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_open_with_online_pk_init (GtkOpenWithOnlinePk *self)
|
||||
{
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_OPEN_WITH_ONLINE_PK,
|
||||
GtkOpenWithOnlinePkPrivate);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pk_search_mime_finish (GtkOpenWithOnline *obj,
|
||||
GAsyncResult *res,
|
||||
GError **error)
|
||||
{
|
||||
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
|
||||
|
||||
return !g_simple_async_result_propagate_error (simple, error);
|
||||
}
|
||||
|
||||
static void
|
||||
install_mime_types_ready_cb (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkOpenWithOnlinePk *self = user_data;
|
||||
GDBusProxy *proxy = G_DBUS_PROXY (source);
|
||||
GError *error = NULL;
|
||||
GVariant *variant;
|
||||
|
||||
variant = g_dbus_proxy_call_finish (proxy, res, &error);
|
||||
|
||||
if (variant == NULL) {
|
||||
g_simple_async_result_set_from_error (self->priv->result, error);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
g_simple_async_result_complete (self->priv->result);
|
||||
}
|
||||
|
||||
static void
|
||||
pk_proxy_appeared_cb (GObject *source,
|
||||
GAsyncResult *res,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkOpenWithOnlinePk *self = user_data;
|
||||
GDBusProxy *proxy;
|
||||
GError *error = NULL;
|
||||
guint xid = 0;
|
||||
GdkWindow *window;
|
||||
const gchar *mime_types[2];
|
||||
|
||||
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
|
||||
|
||||
if (error != NULL) {
|
||||
g_simple_async_result_set_from_error (self->priv->result, error);
|
||||
g_error_free (error);
|
||||
|
||||
g_simple_async_result_complete (self->priv->result);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
window = gtk_widget_get_window (GTK_WIDGET (self->priv->parent));
|
||||
xid = GDK_WINDOW_XID (window);
|
||||
|
||||
mime_types[0] = self->priv->content_type;
|
||||
mime_types[1] = NULL;
|
||||
|
||||
g_dbus_proxy_call (proxy,
|
||||
"InstallMimeTypes",
|
||||
g_variant_new ("(u^ass)",
|
||||
xid,
|
||||
mime_types,
|
||||
"hide-confirm-search"),
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
G_MAXINT, /* no timeout */
|
||||
NULL,
|
||||
install_mime_types_ready_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
pk_search_mime_async (GtkOpenWithOnline *obj,
|
||||
const gchar *content_type,
|
||||
GtkWindow *parent,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkOpenWithOnlinePk *self = GTK_OPEN_WITH_ONLINE_PK (obj);
|
||||
|
||||
self->priv->result = g_simple_async_result_new (G_OBJECT (self),
|
||||
callback, user_data,
|
||||
gtk_open_with_online_search_for_mimetype_async);
|
||||
self->priv->parent = parent;
|
||||
self->priv->content_type = g_strdup (content_type);
|
||||
|
||||
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
|
||||
G_DBUS_PROXY_FLAGS_NONE,
|
||||
NULL,
|
||||
"org.freedesktop.PackageKit",
|
||||
"/org/freedesktop/PackageKit",
|
||||
"org.freedesktop.PackageKit.Modify",
|
||||
NULL,
|
||||
pk_proxy_appeared_cb,
|
||||
self);
|
||||
}
|
||||
|
||||
static void
|
||||
open_with_online_iface_init (GtkOpenWithOnlineInterface *iface)
|
||||
{
|
||||
iface->search_for_mimetype_async = pk_search_mime_async;
|
||||
iface->search_for_mimetype_finish = pk_search_mime_finish;
|
||||
}
|
59
gtk/gtkopenwithonlinepk.h
Normal file
59
gtk/gtkopenwithonlinepk.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* gtkopenwithonlinepk.h: an extension point for online integration
|
||||
*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
#ifndef __GTK_OPEN_WITH_ONLINE_PK_H__
|
||||
#define __GTK_OPEN_WITH_ONLINE_PK_H__
|
||||
|
||||
#include <gtk/gtkopenwithonline.h>
|
||||
#include <glib.h>
|
||||
|
||||
#define GTK_TYPE_OPEN_WITH_ONLINE_PK\
|
||||
(_gtk_open_with_online_pk_get_type ())
|
||||
#define GTK_OPEN_WITH_ONLINE_PK(obj)\
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_OPEN_WITH_ONLINE_PK, GtkOpenWithOnlinePk))
|
||||
#define GTK_OPEN_WITH_ONLINE_PK_CLASS(klass)\
|
||||
(G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_OPEN_WITH_ONLINE_PK, GtkOpenWithOnlinePkClass))
|
||||
#define GTK_IS_OPEN_WITH_ONLINE_PK(obj)\
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_OPEN_WITH_ONLINE_PK))
|
||||
#define GTK_IS_OPEN_WITH_ONLINE_PK_CLASS(klass)\
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OPEN_WITH_ONLINE_PK))
|
||||
#define GTK_OPEN_WITH_ONLINE_PK_GET_CLASS(obj)\
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_OPEN_WITH_ONLINE_PK, GtkOpenWithOnlinePkClass))
|
||||
|
||||
typedef struct _GtkOpenWithOnlinePk GtkOpenWithOnlinePk;
|
||||
typedef struct _GtkOpenWithOnlinePkClass GtkOpenWithOnlinePkClass;
|
||||
typedef struct _GtkOpenWithOnlinePkPrivate GtkOpenWithOnlinePkPrivate;
|
||||
|
||||
struct _GtkOpenWithOnlinePk {
|
||||
GObject parent;
|
||||
|
||||
GtkOpenWithOnlinePkPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GtkOpenWithOnlinePkClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
GType _gtk_open_with_online_pk_get_type (void);
|
||||
|
||||
#endif /* __GTK_OPEN_WITH_ONLINE_PK_H__ */
|
Loading…
Reference in New Issue
Block a user