soc.2009.telepathy: 980d299f: Start adding support for AccountManager....

sttwister at soc.pidgin.im sttwister at soc.pidgin.im
Mon Jul 20 10:20:42 EDT 2009


-----------------------------------------------------------------
Revision: 980d299f564dc131f2a019b3d900baab61402203
Ancestor: 361a5c7c23ff680df716f738f54b2ed258cb7c72
Author: sttwister at soc.pidgin.im
Date: 2009-07-20T14:16:59
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/980d299f564dc131f2a019b3d900baab61402203

Added files:
        libpurple/protocols/telepathy/telepathy_account.c
        libpurple/protocols/telepathy/telepathy_account.h
Modified files:
        libpurple/protocols/telepathy/Makefile.am
        libpurple/protocols/telepathy/Makefile.mingw
        libpurple/protocols/telepathy/telepathy.c

ChangeLog: 


Start adding support for AccountManager. So far queries valid accounts and
check if they already exist in purple-land.

-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy_account.c	26de5cddec0df6100f999f63c8d1e14460816624
+++ libpurple/protocols/telepathy/telepathy_account.c	26de5cddec0df6100f999f63c8d1e14460816624
@@ -0,0 +1,154 @@
+/**
+ * purple - Telepathy Protocol Plugin
+ *
+ * Copyright (C) 2009, Felix Kerekes <sttwister at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#include "telepathy_account.h"
+
+#include <telepathy-glib/account.h>
+#include <telepathy-glib/dbus.h>
+#include <telepathy-glib/interfaces.h>
+
+#include "account.h"
+#include "debug.h"
+
+static void
+get_account_properties_cb (TpProxy *proxy,
+                           GHashTable *out_Properties,
+                           const GError *error,
+                           gpointer user_data,
+                           GObject *weak_object)
+{
+	GHashTable *parameters;
+	const gchar *display_name;
+	gchar **tokens;
+	gchar *cm, *proto, *protocol_id;
+
+	PurpleAccount *account;
+
+	if (error != NULL)
+	{
+		purple_debug_error("telepathy", "Error getting properties for account: %s\n",
+				error->message);
+		return;
+	}
+
+	purple_debug_info("telepathy", "Got account properties!\n");
+
+	parameters = g_value_get_boxed(g_hash_table_lookup(out_Properties, "Parameters"));
+
+	if (parameters == NULL)
+	{
+		purple_debug_warning("telepathy", "Account has no parameters!\n");
+		return;
+	}
+
+	display_name = g_value_get_string(g_hash_table_lookup(parameters, "account"));
+
+	/* Parse the object path to find the connection manager and the protocol.
+	 * The object path looks like "/org/freedesktop/Telepathy/Account/cm/proto/acct"
+	 */
+	tokens = g_strsplit(user_data, "/", 8);
+
+	cm = tokens[5];
+	proto = tokens[6];
+
+	protocol_id = g_strdup_printf("prpl-telepathy-%s-%s", cm, proto);
+	
+	g_strfreev(tokens);
+
+	/* Check if the account already exists in purple-land. If not, we need to manually
+	 * create it.
+	 */
+	account = purple_accounts_find(display_name, protocol_id);
+
+	g_free(protocol_id);
+
+	if (account == NULL)
+	{
+		purple_debug_info("telepathy", "Account %s does not exist in purple-land,"
+				" creating it!\n", display_name);
+	}
+	else
+	{
+		purple_debug_info("telepathy", "Account %s DOES exist in purple-land,"
+				" creating it!\n", display_name);
+	}
+}
+
+void
+get_valid_accounts_cb (TpProxy *proxy,
+                       const GValue *out_Value,
+                       const GError *error,
+                       gpointer user_data,
+                       GObject *weak_object)
+{
+	int i;
+
+	GPtrArray *accounts;
+	GError *err = NULL;
+	TpDBusDaemon *daemon;
+
+	if (error != NULL)
+	{
+		purple_debug_error("telepathy", "Error geting valid accounts: %s\n",
+				error->message);
+		return;
+	}
+
+	daemon = tp_dbus_daemon_dup(&err);
+
+	if (err != NULL)
+	{
+		purple_debug_error("telepathy", "Error dupping DBus daemon: %s\n",
+				err->message);
+		g_error_free(err);
+		return;
+	}
+
+	purple_debug_info("telepathy", "Got valid accounts!\n");
+
+	accounts = g_value_get_boxed(out_Value);
+
+	for (i = 0; i<accounts->len; ++i)
+	{
+		gchar *obj_Path = g_ptr_array_index(accounts, i);
+		TpAccount *account;
+
+		purple_debug_info("telepathy", "  %s\n", obj_Path);
+
+		/* Create a new proxy for each account */
+		account = tp_account_new(daemon, obj_Path, &err);
+
+		if (err != NULL)
+		{
+			purple_debug_error("telepathy", "Error creating TpAccount: %s\n",
+					err->message);
+			g_error_free(err);
+			continue;
+		}
+
+		/* Get all properties and sync the accounts with libpurple */
+		tp_cli_dbus_properties_call_get_all(account, -1, TP_IFACE_ACCOUNT,
+				get_account_properties_cb, g_strdup(obj_Path), g_free, NULL);
+	}
+
+	if (daemon)
+		g_object_unref(daemon);
+
+}
============================================================
--- libpurple/protocols/telepathy/telepathy_account.h	baaca98396b3cb552a1936c8cce21f744e37e610
+++ libpurple/protocols/telepathy/telepathy_account.h	baaca98396b3cb552a1936c8cce21f744e37e610
@@ -0,0 +1,34 @@
+/**
+ * purple - Telepathy Protocol Plugin
+ *
+ * Copyright (C) 2009, Felix Kerekes <sttwister at soc.pidgin.im>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
+ */
+
+#ifndef _TELEPATHY_ACCOUNT_H_
+#define _TELEPATHY_ACCOUNT_H_
+
+#include <telepathy-glib/proxy.h>
+
+void
+get_valid_accounts_cb (TpProxy *proxy,
+                       const GValue *out_Value,
+                       const GError *error,
+                       gpointer user_data,
+                       GObject *weak_object);
+
+
+#endif /* _TELEPATHY_ACCOUNT_H_ */
============================================================
--- libpurple/protocols/telepathy/Makefile.am	edcf56f9ef554e4a09fc722f263fc08735e970bb
+++ libpurple/protocols/telepathy/Makefile.am	e604229c35ab20d8df72b2d4eef3031dc6014c94
@@ -5,6 +5,7 @@ TELEPATHYSOURCES = \
 
 TELEPATHYSOURCES = \
 	telepathy.c \
+	telepathy_account.c \
 	telepathy_avatar.c \
 	telepathy_channel.c \
 	telepathy_channel_list.c \
============================================================
--- libpurple/protocols/telepathy/Makefile.mingw	1380667637d60efc3f54357b12c07a4a36a5b402
+++ libpurple/protocols/telepathy/Makefile.mingw	75db80282b7f2d462964ea35c01213124bb116f7
@@ -38,6 +38,7 @@ C_SRC =			telepathy.c \
 ##  SOURCES, OBJECTS
 ##
 C_SRC =			telepathy.c \
+			telepathy_account.c \
 			telepathy_avatar.c \
 			telepathy_channel.c \
 			telepathy_channel_list.c \
============================================================
--- libpurple/protocols/telepathy/telepathy.c	1209d2744bc24c71e5c99a5a7b13bba9b5154211
+++ libpurple/protocols/telepathy/telepathy.c	d49a4b6bc8ed08e9dd480ffd47d3aaf987a323e2
@@ -20,6 +20,7 @@
 
 #include <glib.h>
 
+#include <telepathy-glib/account-manager.h>
 #include <telepathy-glib/connection-manager.h>
 #include <telepathy-glib/channel.h>
 #include <telepathy-glib/contact.h>
@@ -39,6 +40,7 @@
 #include "util.h"
 #include "version.h"
 
+#include "telepathy_account.h"
 #include "telepathy_avatar.h"
 #include "telepathy_channel.h"
 #include "telepathy_channel_list.h"
@@ -51,6 +53,7 @@ static gchar *module_path;
 
 static void *module_handle;
 static gchar *module_path;
+static TpAccountManager *account_Manager;
 
 typedef struct
 {
@@ -1284,6 +1287,20 @@ G_MODULE_EXPORT gboolean purple_init_plu
 	/* the list of connection managers will be returned in list_connection_managers_cb */
 	tp_list_connection_managers(daemon, list_connection_managers_cb, NULL, NULL, NULL);
 	
+	/* Create an AccountManager interface */
+	account_Manager = tp_account_manager_new(daemon);
+
+	if (account_Manager == NULL)
+	{
+		purple_debug_error("telepathy", "There is no AccountManager interface!\n");
+		return FALSE;
+	}
+
+	/* Get all valid accounts from AccountManager */
+	tp_cli_dbus_properties_call_get(account_Manager, -1,
+			TP_IFACE_ACCOUNT_MANAGER, "ValidAccounts",
+			get_valid_accounts_cb, NULL, NULL, NULL);
+
 	if (daemon != NULL)
 		g_object_unref(daemon);
 


More information about the Commits mailing list