soc.2009.telepathy: 0c7eaf54: Copy parameters from AccountManager to P...
sttwister at soc.pidgin.im
sttwister at soc.pidgin.im
Mon Jul 20 12:30:27 EDT 2009
-----------------------------------------------------------------
Revision: 0c7eaf54b16010da40a7bdad96e7268718cf0f6b
Ancestor: 980d299f564dc131f2a019b3d900baab61402203
Author: sttwister at soc.pidgin.im
Date: 2009-07-20T16:27:06
Branch: im.pidgin.soc.2009.telepathy
URL: http://d.pidgin.im/viewmtn/revision/info/0c7eaf54b16010da40a7bdad96e7268718cf0f6b
Added files:
libpurple/protocols/telepathy/telepathy_utils.c
libpurple/protocols/telepathy/telepathy_utils.h
Modified files:
libpurple/protocols/telepathy/Makefile.am
libpurple/protocols/telepathy/Makefile.mingw
libpurple/protocols/telepathy/telepathy.c
libpurple/protocols/telepathy/telepathy_account.c
ChangeLog:
Copy parameters from AccountManager to PurpleAccount on initialisation
-------------- next part --------------
============================================================
--- libpurple/protocols/telepathy/telepathy_utils.c defd73a448af2c5281a8dee74e2c3b39a521c4cd
+++ libpurple/protocols/telepathy/telepathy_utils.c defd73a448af2c5281a8dee74e2c3b39a521c4cd
@@ -0,0 +1,54 @@
+/**
+ * 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_utils.h"
+
+#include "internal.h"
+
+/* transform a telepathy parameter name into a user-friendly one */
+gchar*
+telepathy_transform_param_name(const gchar* param)
+{
+ gchar *name;
+ int i,len;
+
+ g_return_val_if_fail(param != NULL, NULL);
+
+ name = g_strdup(param);
+
+ /* capitalize first letter */
+ name[0] = g_ascii_toupper(name[0]);
+
+ len = strlen(name);
+ for (i = 0; i<len; ++i)
+ {
+ if (name[i] == '-')
+ {
+ name[i] = ' ';
+ if (i+1 < len)
+ {
+ /* capitalize first letter of each word */
+ name[i+1] = g_ascii_toupper(name[i+1]);
+ }
+ }
+ }
+ return name;
+}
+
============================================================
--- libpurple/protocols/telepathy/telepathy_utils.h e1261c63457926242df522730e260bb28e708e97
+++ libpurple/protocols/telepathy/telepathy_utils.h e1261c63457926242df522730e260bb28e708e97
@@ -0,0 +1,76 @@
+/**
+ * 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_UTILS_H_
+#define _TELEPATHY_UTILS_H_
+
+#include <glib.h>
+
+#include "internal.h"
+
+#include "status.h"
+
+#define TELEPATHY_ID "prpl-telepathy"
+#define TELEPATHY_DISPLAY_VERSION "1.0"
+
+typedef struct
+{
+ const gchar *telepathy_name;
+ const gchar *dbus_type;
+ const gchar *human_name;
+} OptionMapping;
+
+static const OptionMapping options[] = {
+ { "server", "s", N_("Server")},
+ { "port", "q", N_("Port")},
+ { "require-encryption", "b", N_("Require Encryption")},
+ { "ident", "s", N_("Ident")},
+ { "fullname", "s", N_("Full Name")},
+ { "stun-server", "s", N_("STUN Server")},
+ { "stun-port", "q", N_("STUN Port")},
+ { NULL, NULL, NULL}
+};
+
+typedef struct
+{
+ const guint status_primitive;
+ const gchar* id;
+ const gchar* description;
+} StatusMapping;
+
+static const StatusMapping statuses[] =
+{
+ { PURPLE_STATUS_AVAILABLE, "available", "Available" },
+ { PURPLE_STATUS_AWAY, "away", N_("Away") },
+ { PURPLE_STATUS_AWAY, "brb", N_("Be right back") },
+ { PURPLE_STATUS_UNAVAILABLE, "dnd", N_("Do not disturb") },
+ { PURPLE_STATUS_UNAVAILABLE, "busy", N_("Busy") },
+ { PURPLE_STATUS_EXTENDED_AWAY, "xa", N_("Extended away") },
+ { PURPLE_STATUS_INVISIBLE, "hidden", NULL },
+ { PURPLE_STATUS_OFFLINE, "offline", NULL },
+ { PURPLE_STATUS_UNSET, "unknown", NULL },
+ { PURPLE_STATUS_UNSET, "error", NULL },
+ { 0, NULL, NULL}
+};
+
+gchar*
+telepathy_transform_param_name(const gchar* param);
+
+#endif /* _TELEPATHY_UTILS_H_ */
============================================================
--- libpurple/protocols/telepathy/Makefile.am e604229c35ab20d8df72b2d4eef3031dc6014c94
+++ libpurple/protocols/telepathy/Makefile.am fd45c471ee56ab2c18488c9d2147adc4873edca6
@@ -11,7 +11,8 @@ TELEPATHYSOURCES = \
telepathy_channel_list.c \
telepathy_channel_text.c \
telepathy_connection.c \
- telepathy_contact.c
+ telepathy_contact.c \
+ telepathy_utils.c
AM_CFLAGS = $(st)
============================================================
--- libpurple/protocols/telepathy/Makefile.mingw 75db80282b7f2d462964ea35c01213124bb116f7
+++ libpurple/protocols/telepathy/Makefile.mingw 98589fb7482feec7331e350452a4903b8a88e9e8
@@ -44,7 +44,8 @@ C_SRC = telepathy.c \
telepathy_channel_list.c \
telepathy_channel_text.c \
telepathy_connection.c \
- telepathy_contact.c
+ telepathy_contact.c \
+ telepathy_utils.c
OBJECTS = $(C_SRC:%.c=%.o)
============================================================
--- libpurple/protocols/telepathy/telepathy.c d49a4b6bc8ed08e9dd480ffd47d3aaf987a323e2
+++ libpurple/protocols/telepathy/telepathy.c 35409b192423a2371870081158b779f5df0bd5c4
@@ -47,10 +47,8 @@
#include "telepathy_channel_text.h"
#include "telepathy_connection.h"
#include "telepathy_contact.h"
+#include "telepathy_utils.h"
-#define TELEPATHY_ID "prpl-telepathy"
-#define TELEPATHY_DISPLAY_VERSION "1.0"
-
static void *module_handle;
static gchar *module_path;
static TpAccountManager *account_Manager;
@@ -63,46 +61,6 @@ typedef struct
} telepathy_data;
-typedef struct
-{
- const gchar *telepathy_name;
- const gchar *dbus_type;
- const gchar *human_name;
-} OptionMapping;
-
-static const OptionMapping options[] = {
- { "server", "s", N_("Server")},
- { "port", "q", N_("Port")},
- { "require-encryption", "b", N_("Require Encryption")},
- { "ident", "s", N_("Ident")},
- { "fullname", "s", N_("Full Name")},
- { "stun-server", "s", N_("STUN Server")},
- { "stun-port", "q", N_("STUN Port")},
- { NULL, NULL, NULL}
-};
-
-typedef struct
-{
- const guint status_primitive;
- const gchar* id;
- const gchar* description;
-} StatusMapping;
-
-static const StatusMapping statuses[] =
-{
- { PURPLE_STATUS_AVAILABLE, "available", "Available" },
- { PURPLE_STATUS_AWAY, "away", N_("Away") },
- { PURPLE_STATUS_AWAY, "brb", N_("Be right back") },
- { PURPLE_STATUS_UNAVAILABLE, "dnd", N_("Do not disturb") },
- { PURPLE_STATUS_UNAVAILABLE, "busy", N_("Busy") },
- { PURPLE_STATUS_EXTENDED_AWAY, "xa", N_("Extended away") },
- { PURPLE_STATUS_INVISIBLE, "hidden", NULL },
- { PURPLE_STATUS_OFFLINE, "offline", NULL },
- { PURPLE_STATUS_UNSET, "unknown", NULL },
- { PURPLE_STATUS_UNSET, "error", NULL },
- { 0, NULL, NULL}
-};
-
static gboolean
telepathy_plugin_load(PurplePlugin *plugin)
{
@@ -247,6 +205,8 @@ telepathy_login(PurpleAccount *acct)
static void
telepathy_login(PurpleAccount *acct)
{
+ purple_debug_info("telepathy", "Object path: %s\n",
+ purple_account_get_string(acct, "objpath", NULL));
PurpleConnection *gc = purple_account_get_connection(acct);
PurplePlugin* plugin = gc->prpl;
@@ -987,36 +947,6 @@ static PurplePluginInfo telepathy_info =
NULL
};
-/* transform a telepathy parameter name into a user-friendly one */
-static gchar*
-telepathy_transform_param_name(const gchar* param)
-{
- gchar *name;
- int i,len;
-
- g_return_val_if_fail(param != NULL, NULL);
-
- name = g_strdup(param);
-
- /* capitalize first letter */
- name[0] = g_ascii_toupper(name[0]);
-
- len = strlen(name);
- for (i = 0; i<len; ++i)
- {
- if (name[i] == '-')
- {
- name[i] = ' ';
- if (i+1 < len)
- {
- /* capitalize first letter of each word */
- name[i+1] = g_ascii_toupper(name[i+1]);
- }
- }
- }
- return name;
-}
-
/* TODO: Handle "as" types */
static gchar *
get_human_name(const gchar *telepathy_name,
============================================================
--- libpurple/protocols/telepathy/telepathy_account.c 26de5cddec0df6100f999f63c8d1e14460816624
+++ libpurple/protocols/telepathy/telepathy_account.c 19d119018cffc8dc50eb0f2694b9a6066f9dec83
@@ -20,6 +20,8 @@
#include "telepathy_account.h"
+#include "telepathy_utils.h"
+
#include <telepathy-glib/account.h>
#include <telepathy-glib/dbus.h>
#include <telepathy-glib/interfaces.h>
@@ -28,12 +30,65 @@ static void
#include "debug.h"
static void
+set_account_parameters (PurpleAccount *account,
+ GHashTable *parameters)
+{
+ GHashTableIter iter;
+ gpointer key, value;
+
+ /* Loop over all parameters */
+ g_hash_table_iter_init (&iter, parameters);
+ while (g_hash_table_iter_next (&iter, &key, &value))
+ {
+ gchar *name = key;
+ GValue *val = value;
+
+ /* Username and password are special properties */
+ if (g_strcmp0(name, "account") == 0)
+ {
+ purple_account_set_username(account, g_value_get_string(val));
+ }
+ else if (g_strcmp0(name, "password") == 0)
+ {
+ purple_account_set_password(account, g_value_get_string(val));
+ }
+ else
+ {
+ /* Save the parameters in the account */
+ if (G_VALUE_HOLDS_BOOLEAN(val))
+ {
+ purple_account_set_bool(account, name, g_value_get_boolean(val));
+ }
+ else if (G_VALUE_HOLDS_INT(val))
+ {
+ purple_account_set_int(account, name, g_value_get_int(val));
+ }
+ else if (G_VALUE_HOLDS_UINT(val))
+ {
+ purple_account_set_int(account, name, g_value_get_uint(val));
+ }
+ else if (G_VALUE_HOLDS_STRING(val))
+ {
+ purple_account_set_string(account, name, g_value_get_string(val));
+ }
+ else
+ {
+ purple_debug_warning("telepathy", "Unknown value type for %s\n",
+ name);
+ }
+ }
+ }
+}
+
+static void
get_account_properties_cb (TpProxy *proxy,
GHashTable *out_Properties,
const GError *error,
gpointer user_data,
GObject *weak_object)
{
+ gchar *obj_Path = user_data;
+
GHashTable *parameters;
const gchar *display_name;
gchar **tokens;
@@ -58,17 +113,17 @@ get_account_properties_cb (TpProxy *prox
return;
}
- display_name = g_value_get_string(g_hash_table_lookup(parameters, "account"));
+ display_name = tp_asv_get_string(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);
+ tokens = g_strsplit(obj_Path, "/", 8);
cm = tokens[5];
proto = tokens[6];
- protocol_id = g_strdup_printf("prpl-telepathy-%s-%s", cm, proto);
+ protocol_id = g_strdup_printf("%s-%s-%s", TELEPATHY_ID, cm, proto);
g_strfreev(tokens);
@@ -83,12 +138,19 @@ get_account_properties_cb (TpProxy *prox
{
purple_debug_info("telepathy", "Account %s does not exist in purple-land,"
" creating it!\n", display_name);
+
+ account = purple_account_new(display_name, protocol_id);
}
else
{
- purple_debug_info("telepathy", "Account %s DOES exist in purple-land,"
- " creating it!\n", display_name);
+ purple_debug_info("telepathy", "Account %s DOES exist in purple-land\n",
+ display_name);
}
+
+ purple_account_set_string(account, "objpath", obj_Path);
+
+ /* Sync the parameters with PurpleAccount's parameters */
+ set_account_parameters(account, parameters);
}
void
More information about the Commits
mailing list