gtkappchooseronline.c 3.46 KB
Newer Older
1
/*
2
 * gtkappchooseronline.h: an extension point for online integration
3 4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
Javier Jardon's avatar
Javier Jardon committed
17
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 19 20 21
 *
 * Authors: Cosimo Cecchi <ccecchi@redhat.com>
 */

Matthias Clasen's avatar
Matthias Clasen committed
22
#include "config.h"
23

24
#include "gtkappchooseronline.h"
25

26
#include "gtkappchoosermodule.h"
27
#include "gtkintl.h"
28 29 30

#include <gio/gio.h>

31
G_DEFINE_INTERFACE_WITH_CODE (GtkAppChooserOnline, _gtk_app_chooser_online, G_TYPE_OBJECT,
32
                              g_type_interface_add_prerequisite (g_define_type_id, G_TYPE_ASYNC_INITABLE);)
33 34

static void
35
_gtk_app_chooser_online_default_init (GtkAppChooserOnlineInterface *iface)
36 37 38 39
{
  /* do nothing */
}

40
GtkAppChooserOnline *
41 42
_gtk_app_chooser_online_get_default_finish (GObject      *source,
                                            GAsyncResult *result)
43 44 45 46 47 48 49
{
  GtkAppChooserOnline *retval;

  retval = GTK_APP_CHOOSER_ONLINE (g_async_initable_new_finish (G_ASYNC_INITABLE (source),
                                                                result, NULL));

  return retval;
50
}
51 52

void
53 54
_gtk_app_chooser_online_get_default_async (GAsyncReadyCallback callback,
                                           gpointer            user_data)
55 56 57 58 59
{
  GIOExtensionPoint *ep;
  GIOExtension *extension;
  GList *extensions;

60
  _gtk_app_chooser_module_ensure ();
61

62
  ep = g_io_extension_point_lookup ("gtkappchooser-online");
63 64 65 66 67 68
  extensions = g_io_extension_point_get_extensions (ep);

  if (extensions != NULL)
    {
      /* pick the first */
      extension = extensions->data;
69 70
      g_async_initable_new_async (g_io_extension_get_type (extension), G_PRIORITY_DEFAULT,
                                  NULL, callback, user_data, NULL);
71 72 73 74
    }
}

void
75 76 77
_gtk_app_chooser_online_search_for_mimetype_async (GtkAppChooserOnline *self,
                                                   const gchar         *content_type,
                                                   GtkWindow           *parent,
78
                                                   GCancellable        *cancellable,
79 80
                                                   GAsyncReadyCallback  callback,
                                                   gpointer             user_data)
81
{
82
  GtkAppChooserOnlineInterface *iface;
83

84
  g_return_if_fail (GTK_IS_APP_CHOOSER_ONLINE (self));
85

86
  iface = GTK_APP_CHOOSER_ONLINE_GET_IFACE (self);
87

88
  (* iface->search_for_mimetype_async) (self, content_type, parent, cancellable, callback, user_data);
89 90 91
}

gboolean
92 93 94
_gtk_app_chooser_online_search_for_mimetype_finish (GtkAppChooserOnline  *self,
                                                    GAsyncResult         *res,
                                                    GError              **error)
95
{
96
  GtkAppChooserOnlineInterface *iface;
97

98
  g_return_val_if_fail (GTK_IS_APP_CHOOSER_ONLINE (self), FALSE);
99

100
  iface = GTK_APP_CHOOSER_ONLINE_GET_IFACE (self);
101 102 103

  return ((* iface->search_for_mimetype_finish) (self, res, error));
}