[gnome-online-accounts] tplinker: add a stub for GoaTpAccountLinker



commit 2af01f61d3c75c67a850f935b38e966eb03b5468
Author: Marco Barisione <marco barisione collabora co uk>
Date:   Mon Jul 8 15:38:34 2013 +0100

    tplinker: add a stub for GoaTpAccountLinker
    
    https://bugzilla.gnome.org/show_bug.cgi?id=696267

 configure.ac                    |    2 +
 src/daemon/Makefile.am          |    3 +
 src/daemon/goatpaccountlinker.c |  151 +++++++++++++++++++++++++++++++++++++++
 src/daemon/goatpaccountlinker.h |   58 +++++++++++++++
 4 files changed, 214 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 48b6f1d..906e8e6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -300,6 +300,8 @@ if test "$enable_exchange" != "no"; then
   AC_DEFINE(GOA_TELEPATHY_ENABLED, 1, [Enable Telepathy data provider])
 fi
 
+PKG_CHECK_MODULES(TP, telepathy-glib)
+
 # Kerberos
 AC_ARG_ENABLE([kerberos],
               [AS_HELP_STRING([--enable-kerberos],
diff --git a/src/daemon/Makefile.am b/src/daemon/Makefile.am
index 72dde8a..9b9cd79 100644
--- a/src/daemon/Makefile.am
+++ b/src/daemon/Makefile.am
@@ -27,6 +27,7 @@ goa_daemon_SOURCES =                                          \
                                main.c                          \
        goadaemontypes.h                                        \
        goadaemon.h             goadaemon.c                     \
+       goatpaccountlinker.h    goatpaccountlinker.c            \
        $(NULL)
 
 goa_daemon_CPPFLAGS =                                          \
@@ -38,6 +39,7 @@ goa_daemon_CFLAGS =                                           \
        $(GLIB_CFLAGS)                                          \
        $(GTK_CFLAGS)                                           \
        $(REST_CFLAGS)                                          \
+       $(TP_CFLAGS)                                            \
        $(NULL)
 
 goa_daemon_LDADD =                                             \
@@ -46,6 +48,7 @@ goa_daemon_LDADD =                                            \
        $(top_builddir)/src/goabackend/libgoa-backend-1.0.la    \
        $(GTK_LIBS)                                             \
        $(REST_LIBS)                                            \
+       $(TP_LIBS)                                              \
        $(NULL)
 
 if BUILD_KERBEROS
diff --git a/src/daemon/goatpaccountlinker.c b/src/daemon/goatpaccountlinker.c
new file mode 100644
index 0000000..23e128e
--- /dev/null
+++ b/src/daemon/goatpaccountlinker.c
@@ -0,0 +1,151 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2010-2013 Collabora Ltd.
+ * 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>
+ */
+
+/* This class makes sure we have a GOA account for each Telepathy account
+ * configured in the system.
+ * Note that this handles only plain Telepathy accounts; the ones with
+ * multiple capabilities (e.g. Facebook) are handled differently. */
+
+#include "config.h"
+
+#include <gio/gio.h>
+#include <telepathy-glib/telepathy-glib.h>
+
+#include "goatpaccountlinker.h"
+#include "goa/goa.h"
+#include "goabackend/goalogging.h"
+
+#define GOA_TP_ACCOUNT_LINKER_GET_PRIVATE(obj) \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOA_TYPE_TP_ACCOUNT_LINKER, \
+                                GoaTpAccountLinkerPrivate))
+
+G_DEFINE_TYPE (GoaTpAccountLinker, goa_tp_account_linker, G_TYPE_OBJECT)
+
+struct _GoaTpAccountLinkerPrivate
+{
+  TpAccountManager *account_manager;
+  GoaClient *goa_client;
+};
+
+static void
+start_if_ready (GoaTpAccountLinker *self)
+{
+  GoaTpAccountLinkerPrivate *priv = self->priv;
+
+  if (priv->goa_client == NULL ||
+      priv->account_manager == NULL ||
+      !tp_proxy_is_prepared (priv->account_manager,
+        TP_ACCOUNT_MANAGER_FEATURE_CORE))
+    {
+      /* Not everything is ready yet */
+      return;
+    }
+
+  goa_debug ("Both GOA and Tp are ready, starting tracking of accounts");
+}
+
+static void
+account_manager_prepared_cb (GObject      *object,
+                             GAsyncResult *res,
+                             gpointer      user_data)
+{
+  GoaTpAccountLinker *self = user_data;
+  GError *error = NULL;
+
+  if (!tp_proxy_prepare_finish (object, res, &error))
+    {
+      goa_error ("Error preparing AM: %s", error->message);
+      g_clear_error (&error);
+      return;
+    }
+
+  goa_debug("Telepathy account manager prepared");
+  start_if_ready (self);
+}
+
+static void
+goa_client_new_cb (GObject      *object,
+                   GAsyncResult *result,
+                   gpointer      user_data)
+{
+  GoaTpAccountLinker *self = user_data;
+  GoaTpAccountLinkerPrivate *priv = self->priv;
+  GError *error = NULL;
+
+  priv->goa_client = goa_client_new_finish (result, &error);
+  if (priv->goa_client == NULL)
+    {
+      goa_error ("Error connecting to GOA: %s", error->message);
+      g_clear_error (&error);
+      return;
+    }
+
+  goa_debug("GOA client ready");
+  start_if_ready (self);
+}
+
+static void
+goa_tp_account_linker_dispose (GObject *object)
+{
+  GoaTpAccountLinker *self = GOA_TP_ACCOUNT_LINKER (object);
+  GoaTpAccountLinkerPrivate *priv = self->priv;
+
+  g_clear_object (&priv->account_manager);
+  g_clear_object (&priv->goa_client);
+
+  G_OBJECT_CLASS (goa_tp_account_linker_parent_class)->dispose (object);
+}
+
+static void
+goa_tp_account_linker_init (GoaTpAccountLinker *self)
+{
+  GoaTpAccountLinkerPrivate *priv;
+
+  goa_debug ("Starting GOA <-> Telepathy account linker");
+
+  self->priv = GOA_TP_ACCOUNT_LINKER_GET_PRIVATE (self);
+  priv = self->priv;
+
+  priv->account_manager = tp_account_manager_dup ();
+  tp_proxy_prepare_async (priv->account_manager, NULL,
+      account_manager_prepared_cb, self);
+
+  goa_client_new (NULL, goa_client_new_cb, self);
+}
+
+static void
+goa_tp_account_linker_class_init (GoaTpAccountLinkerClass *klass)
+{
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+  g_type_class_add_private (gobject_class,
+      sizeof (GoaTpAccountLinkerPrivate));
+
+  gobject_class->dispose = goa_tp_account_linker_dispose;
+}
+
+GoaTpAccountLinker *
+goa_tp_account_linker_new (void)
+{
+  return g_object_new (GOA_TYPE_TP_ACCOUNT_LINKER, NULL);
+}
diff --git a/src/daemon/goatpaccountlinker.h b/src/daemon/goatpaccountlinker.h
new file mode 100644
index 0000000..287e6f1
--- /dev/null
+++ b/src/daemon/goatpaccountlinker.h
@@ -0,0 +1,58 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/*
+ * Copyright (C) 2010-2013 Collabora Ltd.
+ * 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>
+ */
+
+#ifndef __GOA_TP_ACCOUNT_LINKER_H__
+#define __GOA_TP_ACCOUNT_LINKER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GOA_TYPE_TP_ACCOUNT_LINKER           (goa_tp_account_linker_get_type ())
+#define GOA_TP_ACCOUNT_LINKER(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOA_TYPE_TP_ACCOUNT_LINKER, 
GoaTpAccountLinker))
+#define GOA_TP_ACCOUNT_LINKER_CLASS(obj)     (G_TYPE_CHECK_CLASS_CAST ((obj), GOA_TYPE_TP_ACCOUNT_LINKER, 
GoaTpAccountLinkerClass))
+#define GOA_IS_TP_ACCOUNT_LINKER(obj)        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOA_TYPE_TP_ACCOUNT_LINKER))
+#define GOA_IS_TP_ACCOUNT_LINKER_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE ((obj), GOA_TYPE_TP_ACCOUNT_LINKER))
+#define GOA_TP_ACCOUNT_LINKER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOA_TYPE_TP_ACCOUNT_LINKER, 
GoaTpAccountLinkerClass))
+
+typedef struct _GoaTpAccountLinker        GoaTpAccountLinker;
+typedef struct _GoaTpAccountLinkerClass   GoaTpAccountLinkerClass;
+typedef struct _GoaTpAccountLinkerPrivate GoaTpAccountLinkerPrivate;
+
+struct _GoaTpAccountLinker
+{
+  GObject parent_instance;
+  GoaTpAccountLinkerPrivate *priv;
+};
+
+struct _GoaTpAccountLinkerClass
+{
+  GObjectClass parent_class;
+};
+
+GType               goa_tp_account_linker_get_type      (void) G_GNUC_CONST;
+GoaTpAccountLinker *goa_tp_account_linker_new           (void);
+
+G_END_DECLS
+
+#endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]