]> Pileus Git - ~andy/gtk/blob - gtk/gtkappchooseronline.c
Merge branch 'master' into open-with-dialog
[~andy/gtk] / gtk / gtkappchooseronline.c
1 /*
2  * gtkappchooseronline.h: an extension point for online integration
3  *
4  * Copyright (C) 2010 Red Hat, Inc.
5  *
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.
10  *
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.
15  *
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.
20  *
21  * Authors: Cosimo Cecchi <ccecchi@redhat.com>
22  */
23
24 #include "config.h"
25
26 #include "gtkappchooseronline.h"
27
28 #include "gtkappchoosermodule.h"
29 #include "gtkintl.h"
30
31 #include <gio/gio.h>
32
33 #define gtk_app_chooser_online_get_type _gtk_app_chooser_online_get_type
34 static void gtk_app_chooser_online_default_init (GtkAppChooserOnlineInterface *iface);
35 G_DEFINE_INTERFACE_WITH_CODE (GtkAppChooserOnline, gtk_app_chooser_online, G_TYPE_OBJECT,
36                               g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_ASYNC_INITABLE);)
37
38 static void
39 gtk_app_chooser_online_default_init (GtkAppChooserOnlineInterface *iface)
40 {
41   /* do nothing */
42 }
43
44 GtkAppChooserOnline *
45 gtk_app_chooser_online_get_default_finish (GObject *source,
46                                            GAsyncResult *result)
47 {
48   GtkAppChooserOnline *retval;
49
50   retval = GTK_APP_CHOOSER_ONLINE (g_async_initable_new_finish (G_ASYNC_INITABLE (source),
51                                                                 result, NULL));
52
53   return retval;
54 }  
55
56 void
57 gtk_app_chooser_online_get_default_async (GAsyncReadyCallback callback,
58                                           gpointer user_data)
59 {
60   GIOExtensionPoint *ep;
61   GIOExtension *extension;
62   GList *extensions;
63
64   _gtk_app_chooser_module_ensure ();
65
66   ep = g_io_extension_point_lookup ("gtkappchooser-online");
67   extensions = g_io_extension_point_get_extensions (ep);
68
69   if (extensions != NULL)
70     {
71       /* pick the first */
72       extension = extensions->data;
73       g_async_initable_new_async (g_io_extension_get_type (extension), G_PRIORITY_DEFAULT,
74                                   NULL, callback, user_data, NULL);
75     }
76 }
77
78 void
79 gtk_app_chooser_online_search_for_mimetype_async (GtkAppChooserOnline *self,
80                                                   const gchar         *content_type,
81                                                   GtkWindow           *parent,
82                                                   GAsyncReadyCallback  callback,
83                                                   gpointer             user_data)
84 {
85   GtkAppChooserOnlineInterface *iface;
86
87   g_return_if_fail (GTK_IS_APP_CHOOSER_ONLINE (self));
88
89   iface = GTK_APP_CHOOSER_ONLINE_GET_IFACE (self);
90
91   (* iface->search_for_mimetype_async) (self, content_type, parent, callback, user_data);
92 }
93
94 gboolean
95 gtk_app_chooser_online_search_for_mimetype_finish (GtkAppChooserOnline  *self,
96                                                    GAsyncResult         *res,
97                                                    GError              **error)
98 {
99   GtkAppChooserOnlineInterface *iface;
100
101   g_return_val_if_fail (GTK_IS_APP_CHOOSER_ONLINE (self), FALSE);
102
103   iface = GTK_APP_CHOOSER_ONLINE_GET_IFACE (self);
104
105   return ((* iface->search_for_mimetype_finish) (self, res, error));
106 }