]> git.0d.be Git - empathy.git/blobdiff - goa-mc-plugin/mcp-account-manager-goa.c
Clean up #include directives in source files
[empathy.git] / goa-mc-plugin / mcp-account-manager-goa.c
index 7319f8cfc29036cadb5adb684d3bdff1e78d1173..dc9e036ee6db02aaa47d6b26a36f681e60f8807f 100644 (file)
  *    Danielle Madeley <danielle.madeley@collabora.co.uk>
  */
 
-#include <glib/gi18n.h>
-
-#include <telepathy-glib/util.h>
+#include "config.h"
+#include "mcp-account-manager-goa.h"
 
 #define GOA_API_IS_SUBJECT_TO_CHANGE /* awesome! */
 #include <goa/goa.h>
 
-#include "mcp-account-manager-goa.h"
-
 #define DEBUG g_debug
 #define GET_PRIVATE(self) (((McpAccountManagerGoa *) self)->priv)
 #define DECLARE_GASYNC_CALLBACK(name) \
@@ -40,7 +37,7 @@
 #define PLUGIN_NAME "goa"
 #define PLUGIN_PRIORITY (MCP_ACCOUNT_STORAGE_PLUGIN_PRIO_KEYRING + 10)
 #define PLUGIN_DESCRIPTION "Provide Telepathy Accounts from GOA"
-#define PLUGIN_PROVIDER "org.gnome.OnlineAccounts"
+#define PLUGIN_PROVIDER EMPATHY_GOA_PROVIDER
 
 #define INITIAL_COMMENT "Parameters of GOA Telepathy accounts"
 
@@ -80,7 +77,7 @@ mcp_account_manager_goa_finalize (GObject *self)
 {
   McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
 
-  g_hash_table_destroy (priv->accounts);
+  g_hash_table_unref (priv->accounts);
   g_key_file_free (priv->store);
   g_free (priv->filename);
 
@@ -125,18 +122,41 @@ get_tp_parameters (GoaAccount *account)
       PARAM ("param-extra-certificate-identities", "talk.google.com");
       PARAM ("param-require-encryption", "true");
     }
+  else if (!tp_strdiff (type, "facebook"))
+    {
+      PARAM ("manager", "gabble");
+      PARAM ("protocol", "jabber");
+      PARAM ("Icon", "im-facebook");
+      PARAM ("Service", "facebook");
+
+      PARAM ("param-account", "chat.facebook.com");
+      PARAM ("param-server", "chat.facebook.com");
+      PARAM ("param-require-encryption", "true");
+      PARAM ("param-fallback-servers",
+          "chat.facebook.com:443");
+    }
+  else if (!tp_strdiff (type, "windows_live"))
+    {
+      PARAM ("manager", "gabble");
+      PARAM ("protocol", "jabber");
+      PARAM ("Icon", "im-msn");
+      PARAM ("Service", "windows-live");
+
+      PARAM ("param-account", "messenger.live.com");
+      PARAM ("param-require-encryption", "true");
+      PARAM ("param-fallback-servers", "xmpp.messenger.live.com");
+      PARAM ("param-extra-certificate-identities",
+          "*.gateway.messenger.live.com");
+    }
   else
     {
-      /* unknown account type */
-      g_hash_table_destroy (params);
+      DEBUG ("Unknown account type %s", type);
+      g_hash_table_unref (params);
       return NULL;
     }
 
-  /* TODO: add Facebook support */
-
   /* generic properties */
   PARAM ("DisplayName", goa_account_get_presentation_identity (account));
-  PARAM ("ConnectAutomatically", "true");
 
 #undef PARAM
 
@@ -160,7 +180,7 @@ get_tp_account_name (GoaAccount *account)
       (char *) g_hash_table_lookup (params, "protocol"),
       type, id);
 
-  g_hash_table_destroy (params);
+  g_hash_table_unref (params);
 
   return name;
 }
@@ -233,8 +253,6 @@ load_store (McpAccountManagerGoa *self)
 static void
 mcp_account_manager_goa_init (McpAccountManagerGoa *self)
 {
-  gchar *path;
-
   DEBUG ("GOA MC plugin initialised");
 
   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
@@ -285,7 +303,6 @@ _goa_client_new_cb (GObject *obj,
     gpointer user_data)
 {
   McpAccountManagerGoa *self = user_data;
-  GoaClient *client;
   GList *accounts, *ptr;
   GError *error = NULL;
 
@@ -335,27 +352,27 @@ mcp_account_manager_goa_list (const McpAccountStorage *self,
 static void
 get_enabled (const McpAccountStorage *self,
     const McpAccountManager *am,
-    const gchar *acct,
-    GoaObject *object)
+    const gchar *acc,
+    GoaAccount *account)
 {
-  mcp_account_manager_set_value (am, acct, "Enabled",
-      goa_object_peek_chat (object) != NULL ? "true" : "false");
+  mcp_account_manager_set_value (am, acc, "Enabled",
+      goa_account_get_chat_disabled (account) == FALSE ? "true" : "false");
 }
 
 
 static gboolean
 mcp_account_manager_goa_get (const McpAccountStorage *self,
     const McpAccountManager *am,
-    const gchar *acct,
+    const gchar *acc,
     const gchar *key)
 {
   McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
   GoaObject *object;
   GoaAccount *account;
 
-  DEBUG ("%s: %s, %s", G_STRFUNC, acct, key);
+  DEBUG ("%s: %s, %s", G_STRFUNC, acc, key);
 
-  object = g_hash_table_lookup (priv->accounts, acct);
+  object = g_hash_table_lookup (priv->accounts, acc);
 
   if (object == NULL)
     return FALSE;
@@ -370,41 +387,40 @@ mcp_account_manager_goa_get (const McpAccountStorage *self,
       /* load all keys */
       GHashTable *params = get_tp_parameters (account);
       GHashTableIter iter;
-      gpointer key, value;
+      gpointer k, value;
       GStrv keys;
       guint i;
-      gssize n;
+      gsize nkeys = 0;
 
       /* Properties from GOA */
       g_hash_table_iter_init (&iter, params);
-      while (g_hash_table_iter_next (&iter, &key, &value))
-        mcp_account_manager_set_value (am, acct, key, value);
+      while (g_hash_table_iter_next (&iter, &k, &value))
+        mcp_account_manager_set_value (am, acc, k, value);
 
-      g_hash_table_destroy (params);
+      g_hash_table_unref (params);
 
       /* Stored properties */
-      keys = g_key_file_get_keys (priv->store, acct, &n, NULL);
-
-      if (keys == NULL)
-        n = 0;
+      keys = g_key_file_get_keys (priv->store, acc, &nkeys, NULL);
 
-      for (i = 0; i < n; i++)
+      for (i = 0; i < nkeys; i++)
         {
-          gchar *v = g_key_file_get_value (priv->store, acct, keys[i], NULL);
+          gchar *v = g_key_file_get_value (priv->store, acc, keys[i], NULL);
 
           if (v != NULL)
             {
-              mcp_account_manager_set_value (am, acct, keys[i], v);
+              mcp_account_manager_set_value (am, acc, keys[i], v);
               g_free (v);
             }
         }
 
+      g_strfreev (keys);
+
       /* Enabled */
-      get_enabled (self, am, acct, object);
+      get_enabled (self, am, acc, account);
     }
   else if (!tp_strdiff (key, "Enabled"))
     {
-      get_enabled (self, am, acct, object);
+      get_enabled (self, am, acc, account);
     }
   else
     {
@@ -415,19 +431,27 @@ mcp_account_manager_goa_get (const McpAccountStorage *self,
       value = g_hash_table_lookup (params, key);
 
       if (value == NULL)
-        value = g_key_file_get_value (priv->store, acct, key, NULL);
+        value = g_key_file_get_value (priv->store, acc, key, NULL);
       else
         value = g_strdup (value);
 
-      mcp_account_manager_set_value (am, acct, key, value);
+      mcp_account_manager_set_value (am, acc, key, value);
 
-      g_hash_table_destroy (params);
+      g_hash_table_unref (params);
       g_free (value);
     }
 
   return TRUE;
 }
 
+static gboolean
+account_is_in_goa (const McpAccountStorage *self,
+    const gchar *account)
+{
+  McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
+
+  return (g_hash_table_lookup (priv->accounts, account) != NULL);
+}
 
 static gboolean
 mcp_account_manager_goa_set (const McpAccountStorage *self,
@@ -437,20 +461,37 @@ mcp_account_manager_goa_set (const McpAccountStorage *self,
     const gchar *val)
 {
   McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
-  GError *error = NULL;
 
-  /* No need to save Enabled, it's up to the GOA configuration if the account
-   * is configured or not. */
-  if (!tp_strdiff (key, "Enabled"))
-    return TRUE;
+  if (!account_is_in_goa (self, account))
+    return FALSE;
 
   DEBUG ("%s: (%s, %s, %s)", G_STRFUNC, account, key, val);
 
+  if (!tp_strdiff (key, "Enabled"))
+    {
+      GoaObject *object;
+      GoaAccount *acc;
+
+      object = g_hash_table_lookup (priv->accounts, account);
+
+      if (object == NULL)
+        return FALSE;
+
+      acc = goa_object_peek_account (object);
+
+      if (acc == NULL)
+        return FALSE;
+
+      goa_account_set_chat_disabled (acc, tp_strdiff (val, "true"));
+      goto out;
+    }
+
   if (val != NULL)
     g_key_file_set_value (priv->store, account, key, val);
   else
     g_key_file_remove_key (priv->store, account, key, NULL);
 
+ out:
   /* Pretend we save everything so MC won't save this in accounts.cfg */
   return TRUE;
 }
@@ -464,6 +505,9 @@ mcp_account_manager_goa_delete (const McpAccountStorage *self,
 {
   McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
 
+  if (!account_is_in_goa (self, account))
+    return FALSE;
+
   DEBUG ("%s: (%s, %s)", G_STRFUNC, account, key);
 
   if (key == NULL)
@@ -530,21 +574,20 @@ mcp_account_manager_goa_get_restrictions (const McpAccountStorage *self,
     const gchar *account)
 {
   return TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_PARAMETERS |
-         TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_SERVICE |
-         TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_ENABLED;
+         TP_STORAGE_RESTRICTION_FLAG_CANNOT_SET_SERVICE;
 }
 
 
 static void
 mcp_account_manager_goa_get_identifier (const McpAccountStorage *self,
-    const gchar *acct,
+    const gchar *acc,
     GValue *identifier)
 {
   McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
   GoaObject *object;
   GoaAccount *account;
 
-  object = g_hash_table_lookup (priv->accounts, acct);
+  object = g_hash_table_lookup (priv->accounts, acc);
   g_return_if_fail (object != NULL);
 
   account = goa_object_peek_account (object);
@@ -558,13 +601,12 @@ mcp_account_manager_goa_get_identifier (const McpAccountStorage *self,
 static void
 account_storage_iface_init (McpAccountStorageIface *iface)
 {
-  mcp_account_storage_iface_set_name (iface, PLUGIN_NAME);
-  mcp_account_storage_iface_set_desc (iface, PLUGIN_DESCRIPTION);
-  mcp_account_storage_iface_set_priority (iface, PLUGIN_PRIORITY);
-  mcp_account_storage_iface_set_provider (iface, PLUGIN_PROVIDER);
+  iface->name = PLUGIN_NAME;
+  iface->desc = PLUGIN_DESCRIPTION;
+  iface->priority = PLUGIN_PRIORITY;
+  iface->provider = PLUGIN_PROVIDER;
 
-#define IMPLEMENT(x) mcp_account_storage_iface_implement_##x(iface, \
-    mcp_account_manager_goa_##x)
+#define IMPLEMENT(x) iface->x = mcp_account_manager_goa_##x
   IMPLEMENT (get);
   IMPLEMENT (list);
   IMPLEMENT (set);