[gnome-online-accounts] telepathyfactory: add GoaProviderFactory for dynamic Telepathy providers
- From: Marco Barisione <mbari src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-accounts] telepathyfactory: add GoaProviderFactory for dynamic Telepathy providers
- Date: Thu, 22 Aug 2013 14:18:59 +0000 (UTC)
commit ffe28d85ea4b1a06d73bde7ed60730b0938bc420
Author: Marco Barisione <marco barisione collabora co uk>
Date: Wed Jul 24 17:46:59 2013 +0100
telepathyfactory: add GoaProviderFactory for dynamic Telepathy providers
https://bugzilla.gnome.org/show_bug.cgi?id=696267
src/goabackend/Makefile.am | 1 +
src/goabackend/goatelepathyfactory.c | 129 ++++++++++++++++++++++++++++++++++
src/goabackend/goatelepathyfactory.h | 59 +++++++++++++++
3 files changed, 189 insertions(+), 0 deletions(-)
---
diff --git a/src/goabackend/Makefile.am b/src/goabackend/Makefile.am
index 8368bf7..9b17f09 100644
--- a/src/goabackend/Makefile.am
+++ b/src/goabackend/Makefile.am
@@ -78,6 +78,7 @@ libgoa_backend_1_0_la_SOURCES = \
goatwitterprovider.h goatwitterprovider.c \
goaflickrprovider.h goaflickrprovider.c \
goawindowsliveprovider.h goawindowsliveprovider.c \
+ goatelepathyfactory.h goatelepathyfactory.c \
goatelepathyprovider.h goatelepathyprovider.c \
goautils.h goautils.c \
goaspinnerbutton.h goaspinnerbutton.c \
diff --git a/src/goabackend/goatelepathyfactory.c b/src/goabackend/goatelepathyfactory.c
new file mode 100644
index 0000000..a41c1ef
--- /dev/null
+++ b/src/goabackend/goatelepathyfactory.c
@@ -0,0 +1,129 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Marco Barisione <marco barisione collabora co uk>
+ */
+
+#include "config.h"
+
+#include <tp-account-widgets/tpaw-protocol.h>
+
+#include "goatelepathyfactory.h"
+#include "goaprovider-priv.h"
+#include "goatelepathyprovider.h"
+
+/**
+ * SECTION:goatelepathyfactory
+ * @title: GoaTelepathyFactory
+ * @short_description: Factory for #GoaTelepathyProvider instances
+ *
+ * #GoaTelepathyFactory dynamically creates instances of #GoaTelepathyProvider
+ * based on the protocols available through Telepathy.
+ */
+
+G_DEFINE_TYPE_WITH_CODE (GoaTelepathyFactory, goa_telepathy_factory, GOA_TYPE_PROVIDER_FACTORY,
+ goa_provider_ensure_extension_points_registered ();
+ g_io_extension_point_implement (GOA_PROVIDER_FACTORY_EXTENSION_POINT_NAME,
+ g_define_type_id,
+ GOA_TELEPATHY_PROVIDER_BASE_TYPE,
+ 0));
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static GoaProvider *
+get_provider (GoaProviderFactory *factory,
+ const gchar *provider_name)
+{
+ g_return_if_fail (GOA_IS_TELEPATHY_FACTORY (factory));
+
+ return GOA_PROVIDER (goa_telepathy_provider_new_from_protocol_name (provider_name));
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+free_list_and_unref (gpointer data)
+{
+ g_list_free_full (data, g_object_unref);
+}
+
+static void
+get_protocols_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *outer_result = user_data;
+ GList *protocols = NULL;
+ GList *ret;
+ GList *l;
+ GError *error = NULL;
+
+ if (!tpaw_protocol_get_all_finish (&protocols, res, &error))
+ {
+ g_simple_async_result_take_error (outer_result, error);
+ g_simple_async_result_complete_in_idle (outer_result);
+ g_object_unref (outer_result);
+ return;
+ }
+
+ ret = NULL;
+ for (l = protocols; l != NULL; l = l->next)
+ {
+ GoaTelepathyProvider *provider = goa_telepathy_provider_new_from_protocol (l->data);
+ ret = g_list_prepend (ret, provider);
+ }
+ ret = g_list_reverse (ret);
+ g_list_free_full (protocols, g_object_unref);
+
+ g_simple_async_result_set_op_res_gpointer (outer_result, ret, free_list_and_unref);
+ g_simple_async_result_complete_in_idle (outer_result);
+
+ g_object_unref (outer_result);
+}
+
+static void
+get_providers (GoaProviderFactory *factory,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ GSimpleAsyncResult *result;
+
+ g_return_if_fail (GOA_IS_TELEPATHY_FACTORY (factory));
+
+ result = g_simple_async_result_new (G_OBJECT (factory), callback, user_data,
+ get_providers);
+ tpaw_protocol_get_all_async (get_protocols_cb, result);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+goa_telepathy_factory_init (GoaTelepathyFactory *provider)
+{
+}
+
+static void
+goa_telepathy_factory_class_init (GoaTelepathyFactoryClass *klass)
+{
+ GoaProviderFactoryClass *factory_class;
+
+ factory_class = GOA_PROVIDER_FACTORY_CLASS (klass);
+ factory_class->get_provider = get_provider;
+ factory_class->get_providers = get_providers;
+}
diff --git a/src/goabackend/goatelepathyfactory.h b/src/goabackend/goatelepathyfactory.h
new file mode 100644
index 0000000..576466d
--- /dev/null
+++ b/src/goabackend/goatelepathyfactory.h
@@ -0,0 +1,59 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Marco Barisione <marco barisione collabora co uk>
+ */
+
+#if !defined (__GOA_BACKEND_INSIDE_GOA_BACKEND_H__) && !defined (GOA_BACKEND_COMPILATION)
+#error "Only <goabackend/goabackend.h> can be included directly."
+#endif
+
+#ifndef __GOA_TELEPATHY_FACTORY_H__
+#define __GOA_TELEPATHY_FACTORY_H__
+
+#include "goaproviderfactory.h"
+
+G_BEGIN_DECLS
+
+#define GOA_TYPE_TELEPATHY_FACTORY (goa_telepathy_factory_get_type ())
+#define GOA_TELEPATHY_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GOA_TYPE_TELEPATHY_FACTORY,
GoaTelepathyFactory))
+#define GOA_TELEPATHY_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GOA_TYPE_TELEPATHY_FACTORY,
GoaTelepathyFactoryClass))
+#define GOA_TELEPATHY_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GOA_TYPE_TELEPATHY_FACTORY,
GoaTelepathyFactoryClass))
+#define GOA_IS_TELEPATHY_FACTORY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GOA_TYPE_TELEPATHY_FACTORY))
+#define GOA_IS_TELEPATHY_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GOA_TYPE_TELEPATHY_FACTORY))
+
+typedef struct _GoaTelepathyFactory GoaTelepathyFactory;
+typedef struct _GoaTelepathyFactoryClass GoaTelepathyFactoryClass;
+
+struct _GoaTelepathyFactory
+{
+ /*< private >*/
+ GoaProviderFactory parent_instance;
+};
+
+struct _GoaTelepathyFactoryClass
+{
+ GoaProviderFactoryClass parent_class;
+};
+
+GType goa_telepathy_factory_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __GOA_TELEPATHY_FACTORY_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]