comparison pidgin-audacious.c @ 13:44568f7ef51d

fixed indentation
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Sat, 27 Sep 2008 01:07:06 +0900
parents 79f081cdfb19
children 89bd98990fff
comparison
equal deleted inserted replaced
12:79f081cdfb19 13:44568f7ef51d
1 /* -*- indent-tabs-mode:t; tab-width:8; -*- 1 /* Pidgin-Audacious plugin.
2 *
3 * Pidgin-Audacious plugin.
4 * 2 *
5 * This program is free software; you can redistribute it and/or 3 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as 4 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the 5 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version. 6 * License, or (at your option) any later version.
33 #include <audacious/audctrl.h> 31 #include <audacious/audctrl.h>
34 #include <audacious/dbus.h> 32 #include <audacious/dbus.h>
35 33
36 extern gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) __attribute__ ((weak)); 34 extern gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) __attribute__ ((weak));
37 35
38 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious" 36 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious"
39 37
40 #define OPT_PIDGINAUD "/plugins/pidgin_audacious" 38 #define OPT_PIDGINAUD "/plugins/pidgin_audacious"
41 #define OPT_PROCESS_STATUS OPT_PIDGINAUD "/process_status" 39 #define OPT_PROCESS_STATUS OPT_PIDGINAUD "/process_status"
42 #define OPT_PROCESS_USERINFO OPT_PIDGINAUD "/process_userinfo" 40 #define OPT_PROCESS_USERINFO OPT_PIDGINAUD "/process_userinfo"
43 #define OPT_PROCESS_ALIAS OPT_PIDGINAUD "/process_alias" 41 #define OPT_PROCESS_ALIAS OPT_PIDGINAUD "/process_alias"
44 #define OPT_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template" 42 #define OPT_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template"
45 43
46 #define SONG_TOKEN "%song" 44 #define SONG_TOKEN "%song"
47 #define NO_SONG_MESSAGE "No song being played." 45 #define NO_SONG_MESSAGE "No song being played."
48 46
49 #define BUDDY_ALIAS_MAXLEN 387 47 #define BUDDY_ALIAS_MAXLEN 387
50 48
51 #define aud_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, "Pidgin-Audacious", \ 49 #define aud_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, \
52 fmt, ## __VA_ARGS__); 50 "Pidgin-Audacious", \
53 #define aud_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, "Pidgin-Audacious", \ 51 fmt, ## __VA_ARGS__);
54 fmt, ## __VA_ARGS__); 52 #define aud_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, \
53 "Pidgin-Audacious", \
54 fmt, ## __VA_ARGS__);
55 55
56 static gint timeout_tag = 0; 56 static gint timeout_tag = 0;
57 57
58 GHashTable *seed_status; 58 GHashTable *seed_status;
59 GHashTable *seed_userinfo; 59 GHashTable *seed_userinfo;
87 } 87 }
88 88
89 static gboolean 89 static gboolean
90 watchdog_func(void) 90 watchdog_func(void)
91 { 91 {
92 gint playpos = 0; 92 gint playpos = 0;
93 gchar *song = NULL, *tmp = NULL; 93 gchar *song = NULL, *tmp = NULL;
94 94
95 gboolean rv = TRUE; 95 gboolean rv = TRUE;
96 size_t dummy; 96 size_t dummy;
97 97
98 aud_debug("session = %p\n", session); 98 aud_debug("session = %p\n", session);
99 99
100 aud_debug("is_playing = %d\n", audacious_remote_is_playing(session)); 100 aud_debug("is_playing = %d\n", audacious_remote_is_playing(session));
101 101
102 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ 102 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */
103 aud_process(NULL); 103 aud_process(NULL);
104 return rv; 104 return rv;
105 } 105 }
106 106
107 playpos = audacious_remote_get_playlist_pos(session); 107 playpos = audacious_remote_get_playlist_pos(session);
108 tmp = audacious_remote_get_playlist_title(session, playpos); 108 tmp = audacious_remote_get_playlist_title(session, playpos);
109 if(tmp) { 109 if(tmp) {
110 if(botch_utf) // function exists 110 if(botch_utf) /* if function exists */
111 song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy); 111 song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy);
112 else 112 else
113 song = g_strdup(tmp); 113 song = g_strdup(tmp);
114 } 114 }
115 g_free(tmp); 115 g_free(tmp);
116 tmp = NULL; 116 tmp = NULL;
117 117
118 aud_process(song); 118 aud_process(song);
119 g_free(song); 119 g_free(song);
120 song = NULL; 120 song = NULL;
121 return rv; 121 return rv;
122 } 122 }
123 123
124 static void 124 static void
125 aud_process_status(PurpleConnection *gc, gchar *aud_info) 125 aud_process_status(PurpleConnection *gc, gchar *aud_info)
126 { 126 {
127 gchar *new = NULL, *key = NULL; 127 gchar *new = NULL, *key = NULL;
128 const gchar *current, *seed, *pushed, *proto; 128 const gchar *current, *seed, *pushed, *proto;
129 PurpleAccount *account; 129 PurpleAccount *account;
130 PurplePresence *presence; 130 PurplePresence *presence;
131 PurplePlugin *prpl; 131 PurplePlugin *prpl;
132 PurplePluginProtocolInfo *prpl_info; 132 PurplePluginProtocolInfo *prpl_info;
133 PurpleStatus *status; 133 PurpleStatus *status;
134 134
135 account = purple_connection_get_account(gc); 135 account = purple_connection_get_account(gc);
136 presence = purple_account_get_presence(account); 136 presence = purple_account_get_presence(account);
137 137
138 proto = purple_account_get_protocol_id(account); 138 proto = purple_account_get_protocol_id(account);
139 prpl = purple_find_prpl(proto); 139 prpl = purple_find_prpl(proto);
140 g_return_if_fail(prpl != NULL); 140 g_return_if_fail(prpl != NULL);
141 141
142 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); 142 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
143 g_return_if_fail(prpl_info != NULL && prpl_info->set_status != NULL); 143 g_return_if_fail(prpl_info != NULL && prpl_info->set_status != NULL);
144 144
145 status = purple_presence_get_active_status(presence); 145 status = purple_presence_get_active_status(presence);
146 g_return_if_fail(status != NULL); 146 g_return_if_fail(status != NULL);
147 147
148 /* generate key for hash table */ 148 /* generate key for hash table */
149 key = g_strdup_printf("%s %s", account->username, account->protocol_id); 149 key = g_strdup_printf("%s %s", account->username, account->protocol_id);
150 150
151 /* retrieve current user status */ 151 /* retrieve current user status */
152 current = purple_status_get_attr_string(status, "message"); 152 current = purple_status_get_attr_string(status, "message");
153 aud_debug("status current = %s\n", current); 153 aud_debug("status current = %s\n", current);
154 154
155 /* invalidate pushded status on auto away etc. */ 155 /* invalidate pushded status on auto away etc. */
156 if(current == NULL || strlen(current) == 0) { 156 if(current == NULL || strlen(current) == 0) {
157 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); 157 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(""));
158 g_free(key); 158 g_free(key);
159 return; 159 return;
160 } 160 }
161 161
162 /* pop pushed_status */ 162 /* pop pushed_status */
163 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); 163 pushed = (gchar *)g_hash_table_lookup(pushed_status, key);
164 164
165 /* if current status differs from pushed_status or contains token, replace hashes with current. */ 165 /* if current status differs from pushed_status or
166 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { 166 contains token, replace hashes with current. */
167 g_hash_table_replace(seed_status, g_strdup(key), g_strdup(current)); 167 if((pushed && g_ascii_strcasecmp(current, pushed)) ||
168 strstr(current, SONG_TOKEN)) {
169 g_hash_table_replace(seed_status, g_strdup(key), g_strdup(current));
168 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); 170 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current));
169 } 171 }
170 172
171 /* construct new status message */ 173 /* construct new status message */
172 seed = (gchar *)g_hash_table_lookup(seed_status, key); 174 seed = (gchar *)g_hash_table_lookup(seed_status, key);
173 if(!seed) { 175 if(!seed) {
174 g_free(key); 176 g_free(key);
175 return; 177 return;
176 } 178 }
177 aud_debug("status seed = %s\n", seed); 179 aud_debug("status seed = %s\n", seed);
178 180
179 if(strstr(seed, SONG_TOKEN)) { 181 if(strstr(seed, SONG_TOKEN)) {
180 if(aud_info){ 182 if(aud_info){
181 new = purple_strreplace(seed, SONG_TOKEN, aud_info); 183 new = purple_strreplace(seed, SONG_TOKEN, aud_info);
182 } 184 }
183 else { 185 else {
184 new = g_strdup(NO_SONG_MESSAGE); 186 new = g_strdup(NO_SONG_MESSAGE);
185 } 187 }
186 } 188 }
187 189
188 if(!new) { 190 if(!new) {
189 g_free(key); 191 g_free(key);
190 return; 192 return;
191 } 193 }
192 194
193 /* set status message only if text has been changed */ 195 /* set status message only if text has been changed */
194 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); 196 pushed = (gchar *)g_hash_table_lookup(pushed_status, key);
195 aud_debug("status pushed = %s\n", pushed); 197 aud_debug("status pushed = %s\n", pushed);
196 198
197 if (!pushed || g_ascii_strcasecmp(pushed, new)) { 199 if (!pushed || g_ascii_strcasecmp(pushed, new)) {
198 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new)); 200 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new));
199 purple_status_set_attr_string(status, "message", new); 201 purple_status_set_attr_string(status, "message", new);
200 prpl_info->set_status(account, status); 202 prpl_info->set_status(account, status);
201 } 203 }
202 g_free(key); 204 g_free(key);
203 g_free(new); 205 g_free(new);
204 } 206 }
205 207
206 208
207 static void 209 static void
208 aud_process_userinfo(PurpleConnection *gc, gchar *aud_info) 210 aud_process_userinfo(PurpleConnection *gc, gchar *aud_info)
209 { 211 {
210 gchar *new = NULL, *key = NULL; 212 gchar *new = NULL, *key = NULL;
211 const gchar *current, *seed, *pushed, *proto; 213 const gchar *current, *seed, *pushed, *proto;
212 PurpleAccount *account; 214 PurpleAccount *account;
213 PurplePlugin *prpl; 215 PurplePlugin *prpl;
214 PurplePluginProtocolInfo *prpl_info; 216 PurplePluginProtocolInfo *prpl_info;
215 217
216 account = purple_connection_get_account(gc); 218 account = purple_connection_get_account(gc);
217 219
218 proto = purple_account_get_protocol_id(account); 220 proto = purple_account_get_protocol_id(account);
219 prpl = purple_find_prpl(proto); 221 prpl = purple_find_prpl(proto);
220 g_return_if_fail(prpl != NULL); 222 g_return_if_fail(prpl != NULL);
221 223
222 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); 224 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
223 g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL); 225 g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL);
224 226
225 /* generate key for hash table*/ 227 /* generate key for hash table*/
226 key = g_strdup_printf("%s %s", account->username, account->protocol_id); 228 key = g_strdup_printf("%s %s", account->username, account->protocol_id);
227 229
228 /* retrieve current user info */ 230 /* retrieve current user info */
229 current = purple_account_get_user_info(account); /* it's always from account.xml! */ 231 current = purple_account_get_user_info(account); /* from account.xml */
230 aud_debug("userinfo current = %s\n", current); 232 aud_debug("userinfo current = %s\n", current);
231 233
232 /* invalidate pushded status on auto away etc. */ 234 /* invalidate pushded status on auto away etc. */
233 if(current == NULL || strlen(current) == 0) { 235 if(current == NULL || strlen(current) == 0) {
234 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); 236 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(""));
235 g_free(key); 237 g_free(key);
236 return; 238 return;
237 } 239 }
238 240
239 /* pop pushed_userinfo */ 241 /* pop pushed_userinfo */
240 pushed = g_hash_table_lookup(pushed_userinfo, key); 242 pushed = g_hash_table_lookup(pushed_userinfo, key);
241 243
242 /* if current alias differs from pushed_alias or contains token, replace seed with this. */ 244 /* if current alias differs from pushed_alias or contains token,
243 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { 245 replace seed with this. */
244 g_hash_table_replace(seed_userinfo, g_strdup(key), g_strdup(current)); 246 if((pushed && g_ascii_strcasecmp(current, pushed)) ||
245 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(current)); 247 strstr(current, SONG_TOKEN)) {
246 } 248 g_hash_table_replace(seed_userinfo, g_strdup(key),
247 249 g_strdup(current));
248 /* construct new status message */ 250 g_hash_table_replace(pushed_userinfo, g_strdup(key),
249 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); 251 g_strdup(current));
250 if(!seed) { 252 }
251 g_free(key); 253
252 return; 254 /* construct new status message */
253 } 255 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key);
254 aud_debug("userinfo seed = %s\n", seed); 256 if(!seed) {
255 257 g_free(key);
256 if(strstr(seed, SONG_TOKEN)) { 258 return;
257 if(aud_info){ 259 }
258 new = purple_strreplace(seed, SONG_TOKEN, aud_info); 260 aud_debug("userinfo seed = %s\n", seed);
259 } 261
260 else { 262 if(strstr(seed, SONG_TOKEN)) {
261 new = g_strdup(NO_SONG_MESSAGE); 263 if(aud_info){
262 } 264 new = purple_strreplace(seed, SONG_TOKEN, aud_info);
263 } 265 }
264 266 else {
265 if(!new) { 267 new = g_strdup(NO_SONG_MESSAGE);
266 g_free(key); 268 }
267 return; 269 }
268 } 270
269 271 if(!new) {
270 /* set user info only if text has been changed */ 272 g_free(key);
271 pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key); 273 return;
272 aud_debug("userinfo pushed = %s\n", pushed); 274 }
273 275
274 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { 276 /* set user info only if text has been changed */
275 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(new)); 277 pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key);
276 prpl_info->set_info(gc, new); 278 aud_debug("userinfo pushed = %s\n", pushed);
277 } 279
278 g_free(key); 280 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) {
279 g_free(new); 281 g_hash_table_replace(pushed_userinfo, g_strdup(key),
282 g_strdup(new));
283 prpl_info->set_info(gc, new);
284 }
285 g_free(key);
286 g_free(new);
280 } 287 }
281 288
282 static void 289 static void
283 aud_process_alias(PurpleConnection *gc, gchar *aud_info) 290 aud_process_alias(PurpleConnection *gc, gchar *aud_info)
284 { 291 {
285 gchar *new = NULL, *key = NULL; 292 gchar *new = NULL, *key = NULL;
286 const gchar *current, *seed, *pushed, *proto; 293 const gchar *current, *seed, *pushed, *proto;
287 PurpleAccount *account; 294 PurpleAccount *account;
288 PurplePlugin *prpl; 295 PurplePlugin *prpl;
289 PurplePluginProtocolInfo *prpl_info; 296 PurplePluginProtocolInfo *prpl_info;
290 297
291 glong bytes; 298 glong bytes;
292 299
293 account = purple_connection_get_account(gc); 300 account = purple_connection_get_account(gc);
294 301
295 proto = purple_account_get_protocol_id(account); 302 proto = purple_account_get_protocol_id(account);
296 prpl = purple_find_prpl(proto); 303 prpl = purple_find_prpl(proto);
297 g_return_if_fail(prpl != NULL); 304 g_return_if_fail(prpl != NULL);
298 305
299 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); 306 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
300 g_return_if_fail(prpl_info != NULL); 307 g_return_if_fail(prpl_info != NULL);
301 308
302 /* generate key for hash table*/ 309 /* generate key for hash table*/
303 key = g_strdup_printf("%s %s", account->username, account->protocol_id); 310 key = g_strdup_printf("%s %s", account->username, account->protocol_id);
304 311
305 /* retrieve current alias */ 312 /* retrieve current alias */
306 current = purple_account_get_alias(account); 313 current = purple_account_get_alias(account);
307 if(current == NULL || strlen(current) == 0) { 314 if(current == NULL || strlen(current) == 0) {
308 aud_error("couldn't get current alias\n"); 315 aud_error("couldn't get current alias\n");
309 g_free(key); 316 g_free(key);
310 return; 317 return;
311 } 318 }
312 aud_debug("current alias = %s\n", current); 319 aud_debug("current alias = %s\n", current);
313 320
314 /* pop pushed_alias */ 321 /* pop pushed_alias */
315 pushed = g_hash_table_lookup(pushed_alias, key); 322 pushed = g_hash_table_lookup(pushed_alias, key);
316 323
317 /* if current alias differs from pushed_alias or contains token, replace seed with current. */ 324 /* if current alias differs from pushed_alias or contains token, replace seed with current. */
318 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { 325 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) {
319 g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current)); 326 g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current));
320 } 327 }
321 328
322 /* construct new status message */ 329 /* construct new status message */
323 seed = g_hash_table_lookup(seed_alias, key); 330 seed = g_hash_table_lookup(seed_alias, key);
324 if(!seed) { 331 if(!seed) {
325 g_free(key); 332 g_free(key);
326 return; 333 return;
327 } 334 }
328 aud_debug("alias: seed = %s\n", (gchar *)seed); 335 aud_debug("alias: seed = %s\n", (gchar *)seed);
329 336
330 bytes = strlen(seed); 337 bytes = strlen(seed);
331 bytes -= strlen(SONG_TOKEN); 338 bytes -= strlen(SONG_TOKEN);
332 aud_debug("alias: bytes = %ld", bytes); 339 aud_debug("alias: bytes = %ld", bytes);
333 340
334 if(aud_info){ 341 if(aud_info){
335 gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN); 342 gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN);
336 glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1); 343 glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1);
337 g_utf8_strncpy(tmp, aud_info, utflen); 344 g_utf8_strncpy(tmp, aud_info, utflen);
338 new = purple_strreplace(seed, SONG_TOKEN, tmp); 345 new = purple_strreplace(seed, SONG_TOKEN, tmp);
339 g_free(tmp); 346 g_free(tmp);
340 } 347 }
341 else { 348 else {
342 new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE); 349 new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE);
343 } 350 }
344 if(!new) { 351 if(!new) {
345 g_free(key); 352 g_free(key);
346 return; 353 return;
347 } 354 }
348 355
349 /* set user info only if text has been changed */ 356 /* set user info only if text has been changed */
350 pushed = g_hash_table_lookup(pushed_alias, key); 357 pushed = g_hash_table_lookup(pushed_alias, key);
351 aud_debug("alias pushed = %s\n", (gchar *)pushed); 358 aud_debug("alias pushed = %s\n", (gchar *)pushed);
352 359
353 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { 360 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) {
354 gboolean ok = FALSE; 361 gboolean ok = FALSE;
355 PurplePlugin *msn_plugin = NULL; 362 PurplePlugin *msn_plugin = NULL;
356 msn_plugin = purple_plugins_find_with_id("prpl-msn"); 363 msn_plugin = purple_plugins_find_with_id("prpl-msn");
357 aud_debug("msn_plugin = %p\n", msn_plugin); 364 aud_debug("msn_plugin = %p\n", msn_plugin);
358 365
359 g_hash_table_replace(pushed_alias, g_strdup(key), g_strdup(new)); 366 g_hash_table_replace(pushed_alias, g_strdup(key), g_strdup(new));
360 purple_plugin_ipc_call(msn_plugin, "msn_set_friendly_name", &ok, gc, new); 367 purple_plugin_ipc_call(msn_plugin, "msn_set_friendly_name", &ok, gc, new);
361 aud_debug("ipc %d\n", ok); 368 aud_debug("ipc %d\n", ok);
362 } 369 }
363 g_free(key); 370 g_free(key);
364 g_free(new); 371 g_free(new);
365 } 372 }
366 373
367 static void 374 static void
368 aud_process(gchar *aud_info) 375 aud_process(gchar *aud_info)
369 { 376 {
370 GList *l; 377 GList *l;
371 PurpleConnection *gc; 378 PurpleConnection *gc;
372 379
373 for (l = purple_connections_get_all(); l != NULL; l = l->next) { 380 for (l = purple_connections_get_all(); l != NULL; l = l->next) {
374 gc = (PurpleConnection *) l->data; 381 gc = (PurpleConnection *) l->data;
375 382
376 /* make sure we're connected */ 383 /* make sure we're connected */
377 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) { 384 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) {
378 continue; 385 continue;
379 } 386 }
380 387
381 if (purple_prefs_get_bool(OPT_PROCESS_USERINFO)) { 388 if (purple_prefs_get_bool(OPT_PROCESS_USERINFO)) {
382 aud_process_userinfo(gc, aud_info); 389 aud_process_userinfo(gc, aud_info);
383 } 390 }
384 391
385 if (purple_prefs_get_bool(OPT_PROCESS_STATUS)) { 392 if (purple_prefs_get_bool(OPT_PROCESS_STATUS)) {
386 aud_process_status(gc, aud_info); 393 aud_process_status(gc, aud_info);
387 } 394 }
388 395
389 if (purple_prefs_get_bool(OPT_PROCESS_ALIAS)) { 396 if (purple_prefs_get_bool(OPT_PROCESS_ALIAS)) {
390 aud_process_alias(gc, aud_info); 397 aud_process_alias(gc, aud_info);
391 } 398 }
392 399
393 } 400 }
394 } 401 }
395 static void 402 static void
396 removekey(gpointer data) 403 removekey(gpointer data)
397 { 404 {
398 g_free(data); 405 g_free(data);
399 } 406 }
400 407
401 static void 408 static void
402 removeval(gpointer data) 409 removeval(gpointer data)
403 { 410 {
404 g_free(data); 411 g_free(data);
405 } 412 }
406 413
407 static gboolean 414 static gboolean
408 restore_alias(PurpleConnection *gc, gpointer data) 415 restore_alias(PurpleConnection *gc, gpointer data)
409 { 416 {
410 PurpleAccount *account; 417 PurpleAccount *account;
411 gpointer val = NULL; 418 gpointer val = NULL;
412 gchar *key = NULL; 419 gchar *key = NULL;
413 420
414 aud_debug("********** restore_alias called **********\n"); 421 aud_debug("********** restore_alias called **********\n");
415 account = purple_connection_get_account(gc); 422 account = purple_connection_get_account(gc);
416 423
417 key = g_strdup_printf("%s %s", account->username, account->protocol_id); 424 key = g_strdup_printf("%s %s", account->username, account->protocol_id);
418 val = g_hash_table_lookup(seed_alias, key); 425 val = g_hash_table_lookup(seed_alias, key);
419 if(!val) { 426 if(!val) {
420 g_free(key); 427 g_free(key);
421 return FALSE; 428 return FALSE;
422 } 429 }
423 430
424 aud_debug("write back alias %s\n", (char *)val); 431 aud_debug("write back alias %s\n", (char *)val);
425 purple_account_set_alias(account, val); //oct16 432 purple_account_set_alias(account, val); //oct16
426 433
427 g_free(key); 434 g_free(key);
428 435
429 return TRUE; 436 return TRUE;
430 } 437 }
431 438
432 static PurpleCmdRet 439 static PurpleCmdRet
433 paste_current_song(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) 440 paste_current_song(PurpleConversation *conv, const gchar *cmd,
434 { 441 gchar **args, gchar **error, void *data)
435 gint playpos = 0; 442 {
436 gchar *song = NULL, *tmp = NULL, *tmp2 = NULL; 443 gint playpos = 0;
444 gchar *song = NULL, *tmp = NULL, *tmp2 = NULL;
437 PurpleConversationType type = purple_conversation_get_type(conv); 445 PurpleConversationType type = purple_conversation_get_type(conv);
438 size_t dummy; 446 size_t dummy;
439 const gchar *template = NULL; 447 const gchar *template = NULL;
440 448
441 /* audacious isn't playing */ 449 /* audacious isn't playing */
442 if(!audacious_remote_is_playing(session)) { 450 if(!audacious_remote_is_playing(session)) {
443 return PURPLE_CMD_RET_OK; 451 return PURPLE_CMD_RET_OK;
444 } 452 }
445 453
446 playpos = audacious_remote_get_playlist_pos(session); 454 playpos = audacious_remote_get_playlist_pos(session);
483 } 491 }
484 492
485 static gboolean 493 static gboolean
486 load_plugin(PurplePlugin *plugin) 494 load_plugin(PurplePlugin *plugin)
487 { 495 {
488 seed_status = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); 496 seed_status = g_hash_table_new_full(g_str_hash, g_str_equal,
489 seed_alias = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); 497 removekey, removeval);
490 seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); 498 seed_alias = g_hash_table_new_full(g_str_hash, g_str_equal,
491 499 removekey, removeval);
492 pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); 500 seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal,
493 pushed_alias = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); 501 removekey, removeval);
494 pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); 502
495 503 pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal,
496 timeout_tag = g_timeout_add(15*1000, (gpointer)watchdog_func, NULL); 504 removekey, removeval);
497 505 pushed_alias = g_hash_table_new_full(g_str_hash, g_str_equal,
498 /* connect to signing-off signal */ 506 removekey, removeval);
499 purple_signal_connect(purple_connections_get_handle(), "signing-off", plugin, 507 pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal,
500 PURPLE_CALLBACK(restore_alias), NULL); 508 removekey, removeval);
509
510 timeout_tag = g_timeout_add(15*1000, (gpointer)watchdog_func, NULL);
511
512 /* connect to signing-off signal */
513 purple_signal_connect(purple_connections_get_handle(), "signing-off",
514 plugin, PURPLE_CALLBACK(restore_alias), NULL);
501 515
502 cmdid_paste_current_song = 516 cmdid_paste_current_song =
503 purple_cmd_register("song", "", PURPLE_CMD_P_DEFAULT, 517 purple_cmd_register("song", "", PURPLE_CMD_P_DEFAULT,
504 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT, 518 PURPLE_CMD_FLAG_IM | PURPLE_CMD_FLAG_CHAT,
505 NULL, paste_current_song, 519 NULL, paste_current_song,
506 "song: Paste currently plaing song", NULL); 520 "song: Paste currently plaing song", NULL);
507 521
508 return TRUE; 522 return TRUE;
509 } 523 }
510 524
511 static gboolean 525 static gboolean
512 unload_plugin(PurplePlugin *plugin) 526 unload_plugin(PurplePlugin *plugin)
513 { 527 {
514 aud_debug("pidgin-audacious unload called\n"); 528 aud_debug("pidgin-audacious unload called\n");
515 529
516 g_source_remove(timeout_tag); 530 g_source_remove(timeout_tag);
517 531
518 g_hash_table_destroy(seed_status); 532 g_hash_table_destroy(seed_status);
519 g_hash_table_destroy(seed_alias); 533 g_hash_table_destroy(seed_alias);
520 g_hash_table_destroy(seed_userinfo); 534 g_hash_table_destroy(seed_userinfo);
521 535
522 g_hash_table_destroy(pushed_status); 536 g_hash_table_destroy(pushed_status);
523 g_hash_table_destroy(pushed_alias); 537 g_hash_table_destroy(pushed_alias);
524 g_hash_table_destroy(pushed_userinfo); 538 g_hash_table_destroy(pushed_userinfo);
525 539
526 purple_cmd_unregister(cmdid_paste_current_song); 540 purple_cmd_unregister(cmdid_paste_current_song);
527 541
528 return TRUE; 542 return TRUE;
529 } 543 }
530 544
531 static PurplePluginPrefFrame * 545 static PurplePluginPrefFrame *
532 get_plugin_pref_frame(PurplePlugin *plugin) 546 get_plugin_pref_frame(PurplePlugin *plugin)
533 { 547 {
534 PurplePluginPref *pref; 548 PurplePluginPref *pref;
535 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new(); 549 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new();
536 550
537 /* create gtk elements for the plugin preferences */ 551 /* create gtk elements for the plugin preferences */
538 pref = purple_plugin_pref_new_with_label("Pidgin-Audacious Configuration"); 552 pref = purple_plugin_pref_new_with_label(
539 purple_plugin_pref_frame_add(frame, pref); 553 "Pidgin-Audacious Configuration");
540 554 purple_plugin_pref_frame_add(frame, pref);
541 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_STATUS, 555
542 "Expand " SONG_TOKEN " to song info in the status message"); 556 pref = purple_plugin_pref_new_with_name_and_label(
543 purple_plugin_pref_frame_add(frame, pref); 557 OPT_PROCESS_STATUS,
544 558 "Expand " SONG_TOKEN " to song info in the status message");
545 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_USERINFO, 559 purple_plugin_pref_frame_add(frame, pref);
546 "Expand " SONG_TOKEN " to song info in the user info"); 560
547 purple_plugin_pref_frame_add(frame, pref); 561 pref = purple_plugin_pref_new_with_name_and_label(
548 562 OPT_PROCESS_USERINFO,
549 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_ALIAS, 563 "Expand " SONG_TOKEN " to song info in the user info");
550 "Expand " SONG_TOKEN " to song info in the alias"); 564 purple_plugin_pref_frame_add(frame, pref);
551 purple_plugin_pref_frame_add(frame, pref); 565
566 pref = purple_plugin_pref_new_with_name_and_label(
567 OPT_PROCESS_ALIAS,
568 "Expand " SONG_TOKEN " to song info in the alias");
569 purple_plugin_pref_frame_add(frame, pref);
552 570
553 /* paste template */ 571 /* paste template */
554 pref = purple_plugin_pref_new_with_name_and_label(OPT_PASTE_TEMPLATE, 572 pref = purple_plugin_pref_new_with_name_and_label(
555 "Paste template"); 573 OPT_PASTE_TEMPLATE,
556 purple_plugin_pref_frame_add(frame, pref); 574 "Paste template");
557 575 purple_plugin_pref_frame_add(frame, pref);
558 return frame; 576
577 return frame;
559 } 578 }
560 579
561 static PurplePluginUiInfo pref_info = 580 static PurplePluginUiInfo pref_info =
562 { 581 {
563 get_plugin_pref_frame 582 get_plugin_pref_frame
564 }; 583 };
565 584
566 static PurplePluginInfo info = 585 static PurplePluginInfo info =
567 { 586 {
568 PURPLE_PLUGIN_MAGIC, 587 PURPLE_PLUGIN_MAGIC,
569 PURPLE_MAJOR_VERSION, 588 PURPLE_MAJOR_VERSION,
570 PURPLE_MINOR_VERSION, 589 PURPLE_MINOR_VERSION,
571 PURPLE_PLUGIN_STANDARD, /**< type */ 590 PURPLE_PLUGIN_STANDARD, /**< type */
572 NULL, /**< ui_req */ 591 NULL, /**< ui_req */
573 0, /**< flags */ 592 0, /**< flags */
574 NULL, /**< deps */ 593 NULL, /**< deps */
575 PURPLE_PRIORITY_DEFAULT, /**< priority */ 594 PURPLE_PRIORITY_DEFAULT, /**< priority */
576 PIDGINAUD_PLUGIN_ID, /**< id */ 595 PIDGINAUD_PLUGIN_ID, /**< id */
577 "Pidgin-Audacious", /**< name */ 596 "Pidgin-Audacious", /**< name */
578 "2.1.0d1", /**< version */ 597 "2.1.0d2", /**< version */
579 "Automatically updates your Pidgin status info with the currently " 598 "Automatically updates your Pidgin status info with the currently "
580 "playing music in Audacious.", /** summary */ 599 "playing music in Audacious.", /** summary */
581 "Automatically updates your Pidgin status info with the currently " 600 "Automatically updates your Pidgin status info with the currently "
582 "playing music in Audacious.", /** desc */ 601 "playing music in Audacious.", /** desc */
583 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ 602 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */
584 "http://www.honeyplanet.jp", /**< homepage */ 603 "http://www.honeyplanet.jp", /**< homepage */
585 load_plugin, /**< load */ 604 load_plugin, /**< load */
586 unload_plugin, /**< unload */ 605 unload_plugin, /**< unload */
587 NULL, /**< destroy */ 606 NULL, /**< destroy */
588 NULL, /**< ui_info */ 607 NULL, /**< ui_info */
589 NULL, /**< extra_info */ 608 NULL, /**< extra_info */
590 &pref_info, /**< pref info */ 609 &pref_info, /**< pref info */
591 NULL 610 NULL
592 }; 611 };
593 612
594 static void 613 static void
595 init_plugin(PurplePlugin *plugin) 614 init_plugin(PurplePlugin *plugin)
596 { 615 {
597 g_type_init(); 616 g_type_init();
598 617
599 /* add plugin preferences */ 618 /* add plugin preferences */
600 purple_prefs_add_none(OPT_PIDGINAUD); 619 purple_prefs_add_none(OPT_PIDGINAUD);
601 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); 620 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE);
602 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); 621 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE);
603 purple_prefs_add_bool(OPT_PROCESS_ALIAS, TRUE); 622 purple_prefs_add_bool(OPT_PROCESS_ALIAS, TRUE);
604 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN); 623 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN);
605 624
606 session = get_dbus_proxy(); 625 session = get_dbus_proxy();
607 } 626 }
608 627