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