changeset 17:14de631fa929

drop outdated alias support
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Thu, 02 Oct 2008 18:36:39 +0900
parents 9e37b72309d4
children dc3aa0bf24c0
files pidgin-audacious.c
diffstat 1 files changed, 2 insertions(+), 136 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-audacious.c	Thu Oct 02 18:26:21 2008 +0900
+++ b/pidgin-audacious.c	Thu Oct 02 18:36:39 2008 +0900
@@ -38,14 +38,11 @@
 #define OPT_PIDGINAUD           "/plugins/pidgin_audacious"
 #define OPT_PROCESS_STATUS      OPT_PIDGINAUD "/process_status"
 #define OPT_PROCESS_USERINFO    OPT_PIDGINAUD "/process_userinfo"
-#define OPT_PROCESS_ALIAS       OPT_PIDGINAUD "/process_alias"
 #define OPT_PASTE_TEMPLATE      OPT_PIDGINAUD "/paste_template"
 
 #define SONG_TOKEN              "%song"
 #define NO_SONG_MESSAGE         "No song being played."
 
-#define BUDDY_ALIAS_MAXLEN 387
-
 #define aud_debug(fmt, ...)     purple_debug(PURPLE_DEBUG_INFO, \
                                              "Pidgin-Audacious", \
                                              fmt, ## __VA_ARGS__);
@@ -57,11 +54,9 @@
 
 GHashTable *seed_status;
 GHashTable *seed_userinfo;
-GHashTable *seed_alias;
 
 GHashTable *pushed_status;
 GHashTable *pushed_userinfo;
-GHashTable *pushed_alias;
 
 DBusGConnection *connection = NULL;
 DBusGProxy *session = NULL;
@@ -260,8 +255,8 @@
     /* pop pushed_userinfo */
     pushed = g_hash_table_lookup(pushed_userinfo, key);
 
-    /* if current alias differs from pushed_alias or contains token,
-       replace seed with this. */
+    /* if current userinfo differs from pushed_userinfo or contains
+       token, replace seed with this. */
     if((pushed && g_ascii_strcasecmp(current, pushed)) ||
        strstr(current, SONG_TOKEN)) {
         g_hash_table_replace(seed_userinfo, g_strdup(key),
@@ -305,90 +300,6 @@
     g_free(new);
 }
 
-static void
-aud_process_alias(PurpleConnection *gc, gchar *aud_info)
-{
-    gchar *new = NULL, *key = NULL;
-    const gchar *current, *seed, *pushed, *proto;
-    PurpleAccount *account;
-    PurplePlugin *prpl;
-    PurplePluginProtocolInfo *prpl_info;
-
-    glong bytes;
-
-    account = purple_connection_get_account(gc);
-
-    proto = purple_account_get_protocol_id(account);
-    prpl = purple_find_prpl(proto);
-    g_return_if_fail(prpl != NULL);
-
-    prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
-    g_return_if_fail(prpl_info != NULL);
-
-    /* generate key for hash table*/
-    key = g_strdup_printf("%s %s", account->username, account->protocol_id);
-
-    /* retrieve current alias */
-    current = purple_account_get_alias(account);
-    if(current == NULL || strlen(current) == 0) {
-        aud_error("couldn't get current alias\n");
-        g_free(key);
-        return;
-    }
-    aud_debug("current alias = %s\n", current);
-
-    /* pop pushed_alias */
-    pushed = g_hash_table_lookup(pushed_alias, key);
-
-    /* if current alias differs from pushed_alias or contains token, replace seed with current. */
-    if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) {
-        g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current));
-    }
-
-    /* construct new status message */
-    seed = g_hash_table_lookup(seed_alias, key);
-    if(!seed) {
-        g_free(key);
-        return;
-    }
-    aud_debug("alias: seed = %s\n", (gchar *)seed);
-
-    bytes = strlen(seed);
-    bytes -= strlen(SONG_TOKEN);
-    aud_debug("alias: bytes = %ld", bytes);
-
-    if(aud_info){
-        gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN);
-        glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1);
-        g_utf8_strncpy(tmp, aud_info, utflen);
-        new = purple_strreplace(seed, SONG_TOKEN, tmp);
-        g_free(tmp);
-    }
-    else {
-        new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE);
-    }
-    if(!new) {
-        g_free(key);
-        return;
-    }
-
-    /* set user info only if text has been changed */
-    pushed = g_hash_table_lookup(pushed_alias, key);
-    aud_debug("alias pushed = %s\n", (gchar *)pushed);
-
-    if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) {
-        gboolean ok = FALSE;
-        PurplePlugin *msn_plugin = NULL;
-        msn_plugin = purple_plugins_find_with_id("prpl-msn");
-        aud_debug("msn_plugin = %p\n", msn_plugin);
-
-        g_hash_table_replace(pushed_alias, g_strdup(key), g_strdup(new));
-        purple_plugin_ipc_call(msn_plugin, "msn_set_friendly_name", &ok, gc, new);
-        aud_debug("ipc %d\n", ok);
-    }
-    g_free(key);
-    g_free(new);
-}
 
 static void
 aud_process(gchar *aud_info)
@@ -412,10 +323,6 @@
             aud_process_status(gc, aud_info);
         }
 
-        if (purple_prefs_get_bool(OPT_PROCESS_ALIAS)) {
-            aud_process_alias(gc, aud_info);
-        }
-
     }
 }
 static void
@@ -430,31 +337,6 @@
     g_free(data);
 }
 
-static gboolean
-restore_alias(PurpleConnection *gc, gpointer data)
-{
-    PurpleAccount *account;
-    gpointer val = NULL;
-    gchar *key = NULL;
-
-    aud_debug("********** restore_alias called **********\n");
-    account = purple_connection_get_account(gc);
-
-    key = g_strdup_printf("%s %s", account->username, account->protocol_id);
-    val = g_hash_table_lookup(seed_alias, key);
-    if(!val) {
-        g_free(key);
-        return FALSE;
-    }
-
-    aud_debug("write back alias %s\n", (char *)val);
-    purple_account_set_alias(account, val); //oct16
-
-    g_free(key);
-
-    return TRUE;
-}
-
 static PurpleCmdRet
 paste_current_song(PurpleConversation *conv, const gchar *cmd,
                    gchar **args, gchar **error, void *data)
@@ -514,24 +396,16 @@
 {
     seed_status = g_hash_table_new_full(g_str_hash, g_str_equal,
                                         removekey, removeval);
-    seed_alias = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                       removekey, removeval);
     seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal,
                                           removekey, removeval);
 
     pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal,
                                           removekey, removeval);
-    pushed_alias = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                         removekey, removeval);
     pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal,
                                             removekey, removeval);
 
     timeout_tag = g_timeout_add(15*1000, (gpointer)watchdog_func, NULL);
 
-    /* connect to signing-off signal */
-    purple_signal_connect(purple_connections_get_handle(), "signing-off",
-                          plugin, PURPLE_CALLBACK(restore_alias), NULL);
-
     cmdid_paste_current_song =
         purple_cmd_register("song", "", PURPLE_CMD_P_DEFAULT,
                             PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT,
@@ -549,11 +423,9 @@
     g_source_remove(timeout_tag);
 
     g_hash_table_destroy(seed_status);
-    g_hash_table_destroy(seed_alias);
     g_hash_table_destroy(seed_userinfo);
 
     g_hash_table_destroy(pushed_status);
-    g_hash_table_destroy(pushed_alias);
     g_hash_table_destroy(pushed_userinfo);
 
     purple_cmd_unregister(cmdid_paste_current_song);
@@ -590,11 +462,6 @@
         "Expand " SONG_TOKEN " to song info in the user info");
     purple_plugin_pref_frame_add(frame, pref);
 
-    pref = purple_plugin_pref_new_with_name_and_label(
-        OPT_PROCESS_ALIAS,
-        "Expand " SONG_TOKEN " to song info in the alias");
-    purple_plugin_pref_frame_add(frame, pref);
-
     /* paste template */
     pref = purple_plugin_pref_new_with_name_and_label(
         OPT_PASTE_TEMPLATE,
@@ -646,7 +513,6 @@
     purple_prefs_add_none(OPT_PIDGINAUD);
     purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE);
     purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE);
-    purple_prefs_add_bool(OPT_PROCESS_ALIAS, TRUE);
     purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN);
 
 }