* 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) \
#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"
static void account_storage_iface_init (McpAccountStorageIface *iface);
gboolean ready;
GoaClient *client;
- GHashTable *accounts; /* alloc'ed string -> ref'ed GoaAccount */
+ GHashTable *accounts; /* alloc'ed string -> ref'ed GoaObject */
+
+ GKeyFile *store;
+ gchar *filename;
};
{
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);
G_OBJECT_CLASS (mcp_account_manager_goa_parent_class)->finalize (self);
}
sizeof (McpAccountManagerGoaPrivate));
}
-
-// static void
-// _enable_chat_toggled (GConfClient *client,
-// guint cnxn_id,
-// GConfEntry *entry,
-// gpointer user_data)
-// {
-// McpAccountStorage *self = MCP_ACCOUNT_STORAGE (user_data);
-// McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
-// gboolean enabled = gconf_value_get_bool (gconf_entry_get_value (entry));
-//
-// DEBUG ("%s: %s", G_STRFUNC, enabled ? "enabled" : "disabled");
-//
-// if (priv->ready && priv->facebook_available)
-// {
-// DEBUG ("Emitting toggled signal");
-//
-// g_signal_emit_by_name (self, "toggled", FACEBOOK_ACCOUNT_NAME, enabled);
-// }
-// }
-
-
static GHashTable *
get_tp_parameters (GoaAccount *account)
{
#define PARAM(key, value) g_hash_table_insert (params, key, g_strdup (value));
- // { "param-account", "chat.facebook.com" },
- // { "param-server", "chat.facebook.com" },
-
if (!tp_strdiff (type, "google"))
{
PARAM ("manager", "gabble");
PARAM ("param-account", goa_account_get_identity (account));
PARAM ("param-server", "talk.google.com");
+ PARAM ("param-fallback-servers",
+ "talkx.l.google.com;"
+ "talkx.l.google.com:443,oldssl;"
+ "talkx.l.google.com:80");
+ 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;
}
/* generic properties */
PARAM ("DisplayName", goa_account_get_presentation_identity (account));
- PARAM ("ConnectAutomatically", "true");
#undef PARAM
(char *) g_hash_table_lookup (params, "protocol"),
type, id);
- g_hash_table_destroy (params);
+ g_hash_table_unref (params);
return name;
}
+static void
+object_chat_changed_cb (GoaObject *object,
+ GParamSpec *spec,
+ McpAccountManagerGoa *self)
+{
+ GoaAccount *account = goa_object_peek_account (object);
+ char *name = get_tp_account_name (account);
+ gboolean enabled;
+
+ enabled = (goa_object_peek_chat (object) != NULL);
+
+ DEBUG ("%s %s", name, enabled ? "enabled" : "disabled");
+
+ if (self->priv->ready)
+ g_signal_emit_by_name (self, "toggled", name, enabled);
+}
static void
_new_account (McpAccountManagerGoa *self,
- GoaAccount *account)
+ GoaObject *object)
{
+ GoaAccount *account = goa_object_peek_account (object);
char *account_name = get_tp_account_name (account);
if (account_name == NULL)
/* @account_name now is owned by the hash table */
g_hash_table_insert (self->priv->accounts, account_name,
- g_object_ref (account));
+ g_object_ref (object));
if (self->priv->ready)
g_signal_emit_by_name (self, "created", account_name);
+
+ tp_g_signal_connect_object (object, "notify::chat",
+ G_CALLBACK (object_chat_changed_cb), self, 0);
}
DECLARE_GASYNC_CALLBACK (_goa_client_new_cb);
+static void
+load_store (McpAccountManagerGoa *self)
+{
+ GError *error = NULL;
+
+ if (!g_key_file_load_from_file (self->priv->store, self->priv->filename,
+ G_KEY_FILE_KEEP_COMMENTS, &error))
+ {
+ gchar *dir;
+
+ DEBUG ("Failed to load keyfile, creating a new one: %s", error->message);
+
+ dir = g_path_get_dirname (self->priv->filename);
+
+ g_mkdir_with_parents (dir, 0700);
+ g_free (dir);
+
+ g_key_file_set_comment (self->priv->store, NULL, NULL, INITIAL_COMMENT,
+ NULL);
+
+ g_error_free (error);
+ }
+}
+
static void
mcp_account_manager_goa_init (McpAccountManagerGoa *self)
{
g_free, g_object_unref);
goa_client_new (NULL, _goa_client_new_cb, self);
+
+ /* key file store */
+ self->priv->store = g_key_file_new ();
+ self->priv->filename = g_build_filename (g_get_user_data_dir (), "telepathy",
+ "mission-control", "accounts-goa.cfg", NULL);
+
+ load_store (self);
}
GoaObject *object,
McpAccountManagerGoa *self)
{
- GoaAccount *account = goa_object_peek_account (object);
-
- _new_account (self, account);
+ _new_account (self, object);
}
g_free (name);
}
-
static void
_goa_client_new_cb (GObject *obj,
GAsyncResult *result,
gpointer user_data)
{
McpAccountManagerGoa *self = user_data;
- GoaClient *client;
GList *accounts, *ptr;
GError *error = NULL;
for (ptr = accounts; ptr != NULL; ptr = ptr->next)
{
- GoaAccount *account = goa_object_peek_account (ptr->data);
-
- _new_account (self, account);
+ _new_account (self, ptr->data);
}
g_list_free_full (accounts, g_object_unref);
G_CALLBACK (_account_added_cb), self);
g_signal_connect (self->priv->client, "account-removed",
G_CALLBACK (_account_removed_cb), self);
- /* FIXME: do we need to support account-changed ? */
}
static void
get_enabled (const McpAccountStorage *self,
const McpAccountManager *am,
- const gchar *acct)
+ const gchar *acc,
+ GoaAccount *account)
{
- // McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
- // GError *error = NULL;
- // gboolean enabled;
- // const char *value;
-
- // enabled = gconf_client_get_bool (priv->gconf,
- // BISHO_FB_GCONF_ENABLE_CHAT_KEY, &error);
- // if (error != NULL)
- // {
- // g_warning ("Unabled to get value for %s/Enabled from GConf: %s",
- // acct, error->message);
- // g_clear_error (&error);
- // }
-
- // value = enabled ? "true" : "false";
-
- // DEBUG ("Facebook Chat enabled = %s", value);
-
- mcp_account_manager_set_value (am, acct, "Enabled", "true");
+ 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);
- account = g_hash_table_lookup (priv->accounts, acct);
+ object = g_hash_table_lookup (priv->accounts, acc);
+
+ if (object == NULL)
+ return FALSE;
+
+ account = goa_object_peek_account (object);
if (account == NULL)
return FALSE;
/* load all keys */
GHashTable *params = get_tp_parameters (account);
GHashTableIter iter;
- gpointer key, value;
+ gpointer k, value;
+ GStrv keys;
+ guint i;
+ 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_unref (params);
+
+ /* Stored properties */
+ keys = g_key_file_get_keys (priv->store, acc, &nkeys, NULL);
- g_hash_table_destroy (params);
+ for (i = 0; i < nkeys; i++)
+ {
+ gchar *v = g_key_file_get_value (priv->store, acc, keys[i], NULL);
- get_enabled (self, am, acct);
+ if (v != NULL)
+ {
+ mcp_account_manager_set_value (am, acc, keys[i], v);
+ g_free (v);
+ }
+ }
+
+ g_strfreev (keys);
+
+ /* Enabled */
+ get_enabled (self, am, acc, account);
}
else if (!tp_strdiff (key, "Enabled"))
{
- get_enabled (self, am, acct);
+ get_enabled (self, am, acc, account);
}
else
{
/* get a specific key */
GHashTable *params = get_tp_parameters (account);
+ gchar *value;
+
+ value = g_hash_table_lookup (params, key);
- mcp_account_manager_set_value (am, acct, key,
- g_hash_table_lookup (params, key));
+ if (value == NULL)
+ value = g_key_file_get_value (priv->store, acc, key, NULL);
+ else
+ value = g_strdup (value);
- g_hash_table_destroy (params);
+ mcp_account_manager_set_value (am, acc, key, value);
+
+ 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,
const McpAccountManager *am,
- const gchar *acct,
+ const gchar *account,
const gchar *key,
const gchar *val)
{
- GError *error = NULL;
+ McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
+
+ 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;
- DEBUG ("%s: (%s, %s, %s)", G_STRFUNC, acct, key, val);
-
- // if (!tp_strdiff (acct, FACEBOOK_ACCOUNT_NAME))
- // {
- // if (!tp_strdiff (key, "Enabled"))
- // {
- // gboolean enabled = !tp_strdiff (val, "true");
-
- // DEBUG ("set Enabled to %s", enabled ? "enabled" : "disabled");
-
- // gconf_client_set_bool (priv->gconf, BISHO_FB_GCONF_ENABLE_CHAT_KEY,
- // enabled, &error);
- // if (error != NULL)
- // {
- // g_warning ("Unable to save %s/Enable state in GConf: %s",
- // acct, error->message);
- // g_clear_error (&error);
- // }
-
- // return TRUE;
- // }
- // else
- // /* pretend we saved everything else */
- // return TRUE;
- // }
- // else
- // {
- // return FALSE;
- // }
+ 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;
}
static gboolean
mcp_account_manager_goa_delete (const McpAccountStorage *self,
const McpAccountManager *am,
- const gchar *acct,
+ const gchar *account,
const gchar *key)
{
- DEBUG ("%s: (%s, %s)", G_STRFUNC, acct, key);
-
-// if (!tp_strdiff (acct, FACEBOOK_ACCOUNT_NAME))
-// {
-// if (!tp_strdiff (key, "Enabled"))
-// return TRUE;
-// else
-// /* pretend we deleted everything else */
-// return TRUE;
-// }
-// else
-// {
-// return FALSE;
-// }
+ 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)
+ {
+ g_key_file_remove_group (priv->store, account, NULL);
+ }
+ else
+ {
+ g_key_file_remove_key (priv->store, account, key, NULL);
+ }
+
+ /* Pretend we deleted everything */
+ return TRUE;
}
mcp_account_manager_goa_commit (const McpAccountStorage *self,
const McpAccountManager *am)
{
- DEBUG ("%s", G_STRFUNC);
+ McpAccountManagerGoaPrivate *priv = GET_PRIVATE (self);
+ gchar *data;
+ gsize len;
+ GError *error = NULL;
+
+ DEBUG ("Save config to %s", priv->filename);
+
+ data = g_key_file_to_data (priv->store, &len, &error);
+ if (data == NULL)
+ {
+ DEBUG ("Failed to get data from store: %s", error->message);
+
+ g_error_free (error);
+ return FALSE;
+ }
+
+ if (!g_file_set_contents (priv->filename, data, len, &error))
+ {
+ DEBUG ("Failed to write file: %s", error->message);
+
+ g_free (data);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ g_free (data);
return TRUE;
}
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;
- account = 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);
g_return_if_fail (account != NULL);
g_value_init (identifier, G_TYPE_STRING);
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);