Mercurial > pidgin-audacious
changeset 1:46071692f191
implement new replace logic to status and userinfo.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 28 Jun 2007 21:36:17 +0900 |
parents | 8d4d17a528ef |
children | f1dc959e4706 |
files | pidgin-audacious.c |
diffstat | 1 files changed, 77 insertions(+), 71 deletions(-) [+] |
line wrap: on
line diff
--- a/pidgin-audacious.c Thu Jun 28 19:48:21 2007 +0900 +++ b/pidgin-audacious.c Thu Jun 28 21:36:17 2007 +0900 @@ -52,9 +52,9 @@ static gint timeout_tag = 0; -GHashTable *stored_status; -GHashTable *stored_userinfo; -GHashTable *stored_alias; +GHashTable *seed_status; +GHashTable *seed_userinfo; +GHashTable *seed_alias; GHashTable *pushed_status; GHashTable *pushed_userinfo; @@ -127,17 +127,14 @@ static void aud_process_status(PurpleConnection *gc, gchar *aud_info) { - gchar *new; - const gchar *old, *proto; + gchar *new = NULL, *key = NULL; + const gchar *current, *seed, *pushed, *proto; PurpleAccount *account; PurplePresence *presence; PurplePlugin *prpl; PurplePluginProtocolInfo *prpl_info; PurpleStatus *status; - gpointer val; // for hash - gchar *key; - account = purple_connection_get_account(gc); presence = purple_account_get_presence(account); @@ -151,45 +148,49 @@ status = purple_presence_get_active_status(presence); g_return_if_fail(status != NULL); - old = purple_status_get_attr_string(status, "message"); - aud_debug("status current = %s\n", old); - if(old == NULL || strlen(old) == 0) { // auto away etc. - /* invalidate pushded status */ - /* generate key for hash table */ - key = g_strdup_printf("%s %s", account->username, account->protocol_id); - g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); - return; - } - /* generate key for hash table */ key = g_strdup_printf("%s %s", account->username, account->protocol_id); - val = g_hash_table_lookup(pushed_status, key); + /* retrieve current user status */ + current = purple_status_get_attr_string(status, "message"); + aud_debug("status current = %s\n", current); - /* if current alias differs from pushed_alias or contains token, replace seed with this. */ - if( (val && g_ascii_strcasecmp(old, val)) || strstr(old, SONG_TOKEN) ) { - g_hash_table_replace(stored_status, g_strdup(key), g_strdup(old)); + /* invalidate pushded status on auto away etc. */ + if(current == NULL || strlen(current) == 0) { + g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); + g_free(key); + return; + } + + /* pop pushed_status */ + pushed = (gchar *)g_hash_table_lookup(pushed_status, key); + + /* if current status differs from pushed_status or contains token, replace hashes with current. */ + if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { + g_hash_table_replace(seed_status, g_strdup(key), g_strdup(current)); + g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); } /* construct new status message */ - val = g_hash_table_lookup(stored_status, key); - g_return_if_fail(val != NULL); - aud_debug("status stored = %s\n", (gchar *)val); + seed = (gchar *)g_hash_table_lookup(seed_status, key); + g_return_if_fail(seed != NULL); + aud_debug("status seed = %s\n", seed); - if(aud_info){ - new = purple_strreplace(val, SONG_TOKEN, aud_info); - } - else { - new = g_strdup(NO_SONG_MESSAGE); - } - + if(strstr(seed, SONG_TOKEN)) { + if(aud_info){ + new = purple_strreplace(seed, SONG_TOKEN, aud_info); + } + else { + new = g_strdup(NO_SONG_MESSAGE); + } + } g_return_if_fail(new != NULL); /* set status message only if text has been changed */ - val = g_hash_table_lookup(pushed_status, key); - aud_debug("status pushed = %s\n", (gchar *)val); + pushed = (gchar *)g_hash_table_lookup(pushed_status, key); + aud_debug("status pushed = %s\n", pushed); - if (!val || g_ascii_strcasecmp(val, new) != 0) { + if (!pushed || g_ascii_strcasecmp(pushed, new)) { g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new)); purple_status_set_attr_string(status, "message", new); prpl_info->set_status(account, status); @@ -202,15 +203,12 @@ static void aud_process_userinfo(PurpleConnection *gc, gchar *aud_info) { - gchar *new; - const gchar *old, *proto; + gchar *new = NULL, *key = NULL; + const gchar *current, *seed, *pushed, *proto; PurpleAccount *account; PurplePlugin *prpl; PurplePluginProtocolInfo *prpl_info; - gpointer val; // for hash - gchar *key; - account = purple_connection_get_account(gc); proto = purple_account_get_protocol_id(account); @@ -220,41 +218,49 @@ prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL); - /* retrieve the old user info */ - old = purple_account_get_user_info(account); /* it's always from account.xml! */ - if(old == NULL || strlen(old) == 0) - return; - /* generate key for hash table*/ key = g_strdup_printf("%s %s", account->username, account->protocol_id); - val = g_hash_table_lookup(pushed_userinfo, key); + /* retrieve current user info */ + current = purple_account_get_user_info(account); /* it's always from account.xml! */ + aud_debug("userinfo current = %s\n", current); + + /* invalidate pushded status on auto away etc. */ + if(current == NULL || strlen(current) == 0) { + g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); + g_free(key); + return; + } + + /* 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( (val && g_ascii_strcasecmp(old, val)) || strstr(old, SONG_TOKEN) ) { - g_hash_table_replace(stored_userinfo, g_strdup(key), g_strdup(old)); + if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { + g_hash_table_replace(seed_userinfo, g_strdup(key), g_strdup(current)); + g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(current)); } /* construct new status message */ - val = g_hash_table_lookup(stored_userinfo, key); - g_return_if_fail(val != NULL); - - aud_debug("userinfo stored = %s\n", (gchar *)val); + seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); + g_return_if_fail(seed != NULL); + aud_debug("userinfo seed = %s\n", seed); - if(aud_info){ - new = purple_strreplace(val, SONG_TOKEN, aud_info); - } - else { - new = g_strdup(NO_SONG_MESSAGE); - } - + if(strstr(seed, SONG_TOKEN)) { + if(aud_info){ + new = purple_strreplace(seed, SONG_TOKEN, aud_info); + } + else { + new = g_strdup(NO_SONG_MESSAGE); + } + } g_return_if_fail(new != NULL); /* set user info only if text has been changed */ - val = g_hash_table_lookup(pushed_userinfo, key); - aud_debug("userinfo pushed = %s\n", (gchar *)val); + pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key); + aud_debug("userinfo pushed = %s\n", pushed); - if (!val || g_ascii_strcasecmp(val, new) != 0) { + if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(new)); prpl_info->set_info(gc, new); } @@ -301,11 +307,11 @@ /* if current alias differs from pushed_alias or contains token, replace seed with this. */ if( (val && g_ascii_strcasecmp(old, val)) || strstr(old, SONG_TOKEN) ) { - g_hash_table_replace(stored_alias, g_strdup(key), g_strdup(old)); + g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(old)); } /* construct new status message */ - val = g_hash_table_lookup(stored_alias, key); + val = g_hash_table_lookup(seed_alias, key); g_return_if_fail(val != NULL); bytes = strlen(val); @@ -399,7 +405,7 @@ account = purple_connection_get_account(gc); key = g_strdup_printf("%s %s", account->username, account->protocol_id); - val = g_hash_table_lookup(stored_alias, key); + val = g_hash_table_lookup(seed_alias, key); g_return_val_if_fail(val != NULL, FALSE); aud_debug("write back alias %s\n", val); @@ -414,9 +420,9 @@ static gboolean load_plugin(PurplePlugin *plugin) { - stored_status = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); - stored_alias = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); - stored_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); + 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); @@ -437,9 +443,9 @@ { aud_debug("pidgin-audacious unload called\n"); - g_hash_table_destroy(stored_status); - g_hash_table_destroy(stored_alias); - g_hash_table_destroy(stored_userinfo); + 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);