Mercurial > pidgin-audacious
annotate pidgin-audacious.c @ 15:b88a5f934224
preliminary support for purple_util_set_current_song()
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Thu, 02 Oct 2008 17:12:04 +0900 |
parents | 89bd98990fff |
children | 9e37b72309d4 |
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 |
14
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
98 if(!session) { |
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
99 session = get_dbus_proxy(); |
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
100 } |
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
101 |
0 | 102 aud_debug("session = %p\n", session); |
103 aud_debug("is_playing = %d\n", audacious_remote_is_playing(session)); | |
104 | |
13 | 105 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ |
0 | 106 aud_process(NULL); |
107 return rv; | |
108 } | |
109 | |
110 playpos = audacious_remote_get_playlist_pos(session); | |
111 tmp = audacious_remote_get_playlist_title(session, playpos); | |
112 if(tmp) { | |
13 | 113 if(botch_utf) /* if function exists */ |
0 | 114 song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy); |
115 else | |
116 song = g_strdup(tmp); | |
117 } | |
118 g_free(tmp); | |
119 tmp = NULL; | |
120 | |
121 aud_process(song); | |
122 g_free(song); | |
123 song = NULL; | |
15
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
124 |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
125 /* preliminary support for purple_util_set_current_song() */ |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
126 gchar *artist = NULL, *title = NULL, *album = NULL; |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
127 |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
128 artist = audacious_get_tuple_field_data(session, "artist", playpos); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
129 title = audacious_get_tuple_field_data(session, "title", playpos); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
130 album = audacious_get_tuple_field_data(session, "album", playpos); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
131 |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
132 purple_util_set_current_song(title ? title : "", |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
133 artist ? artist : "", |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
134 album ? album : ""); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
135 |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
136 g_free(artist); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
137 g_free(title); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
138 g_free(album); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
139 |
13 | 140 return rv; |
0 | 141 } |
142 | |
143 static void | |
144 aud_process_status(PurpleConnection *gc, gchar *aud_info) | |
145 { | |
13 | 146 gchar *new = NULL, *key = NULL; |
147 const gchar *current, *seed, *pushed, *proto; | |
148 PurpleAccount *account; | |
149 PurplePresence *presence; | |
150 PurplePlugin *prpl; | |
151 PurplePluginProtocolInfo *prpl_info; | |
152 PurpleStatus *status; | |
0 | 153 |
13 | 154 account = purple_connection_get_account(gc); |
155 presence = purple_account_get_presence(account); | |
0 | 156 |
13 | 157 proto = purple_account_get_protocol_id(account); |
158 prpl = purple_find_prpl(proto); | |
159 g_return_if_fail(prpl != NULL); | |
0 | 160 |
13 | 161 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
162 g_return_if_fail(prpl_info != NULL && prpl_info->set_status != NULL); | |
0 | 163 |
13 | 164 status = purple_presence_get_active_status(presence); |
165 g_return_if_fail(status != NULL); | |
0 | 166 |
13 | 167 /* generate key for hash table */ |
168 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
0 | 169 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
170 /* retrieve current user status */ |
13 | 171 current = purple_status_get_attr_string(status, "message"); |
172 aud_debug("status current = %s\n", current); | |
0 | 173 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
174 /* invalidate pushded status on auto away etc. */ |
13 | 175 if(current == NULL || strlen(current) == 0) { |
176 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); | |
177 g_free(key); | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
178 return; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
179 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
180 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
181 /* pop pushed_status */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
182 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
|
183 |
13 | 184 /* if current status differs from pushed_status or |
185 contains token, replace hashes with current. */ | |
186 if((pushed && g_ascii_strcasecmp(current, pushed)) || | |
187 strstr(current, SONG_TOKEN)) { | |
188 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
|
189 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); |
0 | 190 } |
191 | |
13 | 192 /* construct new status message */ |
193 seed = (gchar *)g_hash_table_lookup(seed_status, key); | |
194 if(!seed) { | |
195 g_free(key); | |
196 return; | |
197 } | |
198 aud_debug("status seed = %s\n", seed); | |
0 | 199 |
13 | 200 if(strstr(seed, SONG_TOKEN)) { |
201 if(aud_info){ | |
202 new = purple_strreplace(seed, SONG_TOKEN, aud_info); | |
203 } | |
204 else { | |
205 new = g_strdup(NO_SONG_MESSAGE); | |
206 } | |
207 } | |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
208 |
13 | 209 if(!new) { |
210 g_free(key); | |
211 return; | |
212 } | |
0 | 213 |
13 | 214 /* set status message only if text has been changed */ |
215 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); | |
216 aud_debug("status pushed = %s\n", pushed); | |
0 | 217 |
13 | 218 if (!pushed || g_ascii_strcasecmp(pushed, new)) { |
219 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new)); | |
220 purple_status_set_attr_string(status, "message", new); | |
221 prpl_info->set_status(account, status); | |
222 } | |
223 g_free(key); | |
224 g_free(new); | |
0 | 225 } |
226 | |
227 | |
228 static void | |
229 aud_process_userinfo(PurpleConnection *gc, gchar *aud_info) | |
230 { | |
13 | 231 gchar *new = NULL, *key = NULL; |
232 const gchar *current, *seed, *pushed, *proto; | |
233 PurpleAccount *account; | |
234 PurplePlugin *prpl; | |
235 PurplePluginProtocolInfo *prpl_info; | |
0 | 236 |
13 | 237 account = purple_connection_get_account(gc); |
0 | 238 |
13 | 239 proto = purple_account_get_protocol_id(account); |
240 prpl = purple_find_prpl(proto); | |
241 g_return_if_fail(prpl != NULL); | |
0 | 242 |
13 | 243 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
244 g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL); | |
0 | 245 |
13 | 246 /* generate key for hash table*/ |
247 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
0 | 248 |
13 | 249 /* retrieve current user info */ |
250 current = purple_account_get_user_info(account); /* from account.xml */ | |
251 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
|
252 |
13 | 253 /* invalidate pushded status on auto away etc. */ |
254 if(current == NULL || strlen(current) == 0) { | |
255 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); | |
256 g_free(key); | |
257 return; | |
258 } | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
259 |
13 | 260 /* pop pushed_userinfo */ |
261 pushed = g_hash_table_lookup(pushed_userinfo, key); | |
0 | 262 |
13 | 263 /* if current alias differs from pushed_alias or contains token, |
264 replace seed with this. */ | |
265 if((pushed && g_ascii_strcasecmp(current, pushed)) || | |
266 strstr(current, SONG_TOKEN)) { | |
267 g_hash_table_replace(seed_userinfo, g_strdup(key), | |
268 g_strdup(current)); | |
269 g_hash_table_replace(pushed_userinfo, g_strdup(key), | |
270 g_strdup(current)); | |
271 } | |
0 | 272 |
13 | 273 /* construct new status message */ |
274 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); | |
275 if(!seed) { | |
276 g_free(key); | |
277 return; | |
278 } | |
279 aud_debug("userinfo seed = %s\n", seed); | |
0 | 280 |
13 | 281 if(strstr(seed, SONG_TOKEN)) { |
282 if(aud_info){ | |
283 new = purple_strreplace(seed, SONG_TOKEN, aud_info); | |
284 } | |
285 else { | |
286 new = g_strdup(NO_SONG_MESSAGE); | |
287 } | |
288 } | |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
289 |
13 | 290 if(!new) { |
291 g_free(key); | |
292 return; | |
293 } | |
0 | 294 |
13 | 295 /* set user info only if text has been changed */ |
296 pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key); | |
297 aud_debug("userinfo pushed = %s\n", pushed); | |
0 | 298 |
13 | 299 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
300 g_hash_table_replace(pushed_userinfo, g_strdup(key), | |
301 g_strdup(new)); | |
302 prpl_info->set_info(gc, new); | |
303 } | |
304 g_free(key); | |
305 g_free(new); | |
0 | 306 } |
307 | |
308 static void | |
309 aud_process_alias(PurpleConnection *gc, gchar *aud_info) | |
310 { | |
13 | 311 gchar *new = NULL, *key = NULL; |
312 const gchar *current, *seed, *pushed, *proto; | |
313 PurpleAccount *account; | |
314 PurplePlugin *prpl; | |
315 PurplePluginProtocolInfo *prpl_info; | |
0 | 316 |
13 | 317 glong bytes; |
0 | 318 |
13 | 319 account = purple_connection_get_account(gc); |
0 | 320 |
13 | 321 proto = purple_account_get_protocol_id(account); |
322 prpl = purple_find_prpl(proto); | |
323 g_return_if_fail(prpl != NULL); | |
0 | 324 |
13 | 325 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
326 g_return_if_fail(prpl_info != NULL); | |
0 | 327 |
13 | 328 /* generate key for hash table*/ |
329 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
|
330 |
13 | 331 /* retrieve current alias */ |
332 current = purple_account_get_alias(account); | |
333 if(current == NULL || strlen(current) == 0) { | |
334 aud_error("couldn't get current alias\n"); | |
335 g_free(key); | |
336 return; | |
337 } | |
338 aud_debug("current alias = %s\n", current); | |
0 | 339 |
13 | 340 /* pop pushed_alias */ |
341 pushed = g_hash_table_lookup(pushed_alias, key); | |
0 | 342 |
13 | 343 /* if current alias differs from pushed_alias or contains token, replace seed with current. */ |
344 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { | |
345 g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current)); | |
346 } | |
0 | 347 |
13 | 348 /* construct new status message */ |
349 seed = g_hash_table_lookup(seed_alias, key); | |
350 if(!seed) { | |
351 g_free(key); | |
352 return; | |
353 } | |
354 aud_debug("alias: seed = %s\n", (gchar *)seed); | |
0 | 355 |
13 | 356 bytes = strlen(seed); |
357 bytes -= strlen(SONG_TOKEN); | |
358 aud_debug("alias: bytes = %ld", bytes); | |
0 | 359 |
13 | 360 if(aud_info){ |
0 | 361 gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN); |
362 glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1); | |
363 g_utf8_strncpy(tmp, aud_info, utflen); | |
13 | 364 new = purple_strreplace(seed, SONG_TOKEN, tmp); |
0 | 365 g_free(tmp); |
13 | 366 } |
367 else { | |
368 new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE); | |
369 } | |
370 if(!new) { | |
371 g_free(key); | |
372 return; | |
373 } | |
0 | 374 |
13 | 375 /* set user info only if text has been changed */ |
376 pushed = g_hash_table_lookup(pushed_alias, key); | |
377 aud_debug("alias pushed = %s\n", (gchar *)pushed); | |
0 | 378 |
13 | 379 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
0 | 380 gboolean ok = FALSE; |
381 PurplePlugin *msn_plugin = NULL; | |
382 msn_plugin = purple_plugins_find_with_id("prpl-msn"); | |
383 aud_debug("msn_plugin = %p\n", msn_plugin); | |
384 | |
13 | 385 g_hash_table_replace(pushed_alias, g_strdup(key), g_strdup(new)); |
0 | 386 purple_plugin_ipc_call(msn_plugin, "msn_set_friendly_name", &ok, gc, new); |
387 aud_debug("ipc %d\n", ok); | |
13 | 388 } |
389 g_free(key); | |
390 g_free(new); | |
0 | 391 } |
392 | |
393 static void | |
394 aud_process(gchar *aud_info) | |
395 { | |
13 | 396 GList *l; |
397 PurpleConnection *gc; | |
0 | 398 |
13 | 399 for (l = purple_connections_get_all(); l != NULL; l = l->next) { |
400 gc = (PurpleConnection *) l->data; | |
0 | 401 |
13 | 402 /* make sure we're connected */ |
403 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) { | |
404 continue; | |
405 } | |
0 | 406 |
13 | 407 if (purple_prefs_get_bool(OPT_PROCESS_USERINFO)) { |
408 aud_process_userinfo(gc, aud_info); | |
409 } | |
0 | 410 |
13 | 411 if (purple_prefs_get_bool(OPT_PROCESS_STATUS)) { |
412 aud_process_status(gc, aud_info); | |
413 } | |
0 | 414 |
13 | 415 if (purple_prefs_get_bool(OPT_PROCESS_ALIAS)) { |
416 aud_process_alias(gc, aud_info); | |
417 } | |
0 | 418 |
13 | 419 } |
0 | 420 } |
421 static void | |
422 removekey(gpointer data) | |
423 { | |
13 | 424 g_free(data); |
0 | 425 } |
426 | |
427 static void | |
428 removeval(gpointer data) | |
429 { | |
13 | 430 g_free(data); |
0 | 431 } |
432 | |
433 static gboolean | |
434 restore_alias(PurpleConnection *gc, gpointer data) | |
435 { | |
13 | 436 PurpleAccount *account; |
437 gpointer val = NULL; | |
438 gchar *key = NULL; | |
0 | 439 |
13 | 440 aud_debug("********** restore_alias called **********\n"); |
441 account = purple_connection_get_account(gc); | |
0 | 442 |
13 | 443 key = g_strdup_printf("%s %s", account->username, account->protocol_id); |
444 val = g_hash_table_lookup(seed_alias, key); | |
445 if(!val) { | |
446 g_free(key); | |
447 return FALSE; | |
448 } | |
0 | 449 |
13 | 450 aud_debug("write back alias %s\n", (char *)val); |
451 purple_account_set_alias(account, val); //oct16 | |
0 | 452 |
13 | 453 g_free(key); |
0 | 454 |
13 | 455 return TRUE; |
0 | 456 } |
457 | |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
458 static PurpleCmdRet |
13 | 459 paste_current_song(PurpleConversation *conv, const gchar *cmd, |
460 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
|
461 { |
13 | 462 gint playpos = 0; |
463 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
|
464 PurpleConversationType type = purple_conversation_get_type(conv); |
13 | 465 size_t dummy; |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
466 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
|
467 |
13 | 468 /* audacious isn't playing */ |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
469 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
|
470 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
|
471 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
472 |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
473 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
|
474 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
|
475 |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
476 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
|
477 |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
478 if(template && strstr(template, SONG_TOKEN)) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
479 tmp2 = purple_strreplace(template, SONG_TOKEN, tmp); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
480 g_free(tmp); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
481 tmp = NULL; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
482 } |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
483 else { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
484 tmp2 = tmp; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
485 } |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
486 |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
487 if(tmp2) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
488 if(botch_utf) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
489 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
|
490 g_free(tmp2); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
491 tmp2 = NULL; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
492 } |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
493 else |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
494 song = tmp2; |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
495 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
496 |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
497 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
|
498 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
|
499 if (chat && song) |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
500 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
|
501 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
502 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
|
503 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
|
504 if(im && song) |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
505 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
|
506 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
507 |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
508 g_free(song); |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
509 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
|
510 } |
0 | 511 |
512 static gboolean | |
513 load_plugin(PurplePlugin *plugin) | |
514 { | |
13 | 515 seed_status = g_hash_table_new_full(g_str_hash, g_str_equal, |
516 removekey, removeval); | |
517 seed_alias = g_hash_table_new_full(g_str_hash, g_str_equal, | |
518 removekey, removeval); | |
519 seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, | |
520 removekey, removeval); | |
0 | 521 |
13 | 522 pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal, |
523 removekey, removeval); | |
524 pushed_alias = g_hash_table_new_full(g_str_hash, g_str_equal, | |
525 removekey, removeval); | |
526 pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, | |
527 removekey, removeval); | |
0 | 528 |
13 | 529 timeout_tag = g_timeout_add(15*1000, (gpointer)watchdog_func, NULL); |
0 | 530 |
13 | 531 /* connect to signing-off signal */ |
532 purple_signal_connect(purple_connections_get_handle(), "signing-off", | |
533 plugin, PURPLE_CALLBACK(restore_alias), NULL); | |
0 | 534 |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
535 cmdid_paste_current_song = |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
536 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
|
537 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
|
538 NULL, paste_current_song, |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
539 "song: Paste currently plaing song", NULL); |
0 | 540 |
13 | 541 return TRUE; |
0 | 542 } |
543 | |
544 static gboolean | |
545 unload_plugin(PurplePlugin *plugin) | |
546 { | |
13 | 547 aud_debug("pidgin-audacious unload called\n"); |
0 | 548 |
13 | 549 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
|
550 |
13 | 551 g_hash_table_destroy(seed_status); |
552 g_hash_table_destroy(seed_alias); | |
553 g_hash_table_destroy(seed_userinfo); | |
0 | 554 |
13 | 555 g_hash_table_destroy(pushed_status); |
556 g_hash_table_destroy(pushed_alias); | |
557 g_hash_table_destroy(pushed_userinfo); | |
0 | 558 |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
559 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
|
560 |
14
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
561 g_object_unref(session); |
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
562 session = NULL; |
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
563 |
13 | 564 return TRUE; |
0 | 565 } |
566 | |
567 static PurplePluginPrefFrame * | |
568 get_plugin_pref_frame(PurplePlugin *plugin) | |
569 { | |
13 | 570 PurplePluginPref *pref; |
571 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new(); | |
0 | 572 |
13 | 573 /* create gtk elements for the plugin preferences */ |
574 pref = purple_plugin_pref_new_with_label( | |
575 "Pidgin-Audacious Configuration"); | |
576 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
|
577 |
13 | 578 pref = purple_plugin_pref_new_with_name_and_label( |
579 OPT_PROCESS_STATUS, | |
580 "Expand " SONG_TOKEN " to song info in the status message"); | |
581 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
|
582 |
13 | 583 pref = purple_plugin_pref_new_with_name_and_label( |
584 OPT_PROCESS_USERINFO, | |
585 "Expand " SONG_TOKEN " to song info in the user info"); | |
586 purple_plugin_pref_frame_add(frame, pref); | |
0 | 587 |
13 | 588 pref = purple_plugin_pref_new_with_name_and_label( |
589 OPT_PROCESS_ALIAS, | |
590 "Expand " SONG_TOKEN " to song info in the alias"); | |
591 purple_plugin_pref_frame_add(frame, pref); | |
0 | 592 |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
593 /* paste template */ |
13 | 594 pref = purple_plugin_pref_new_with_name_and_label( |
595 OPT_PASTE_TEMPLATE, | |
596 "Paste template"); | |
597 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
|
598 |
13 | 599 return frame; |
0 | 600 } |
601 | |
602 static PurplePluginUiInfo pref_info = | |
603 { | |
13 | 604 get_plugin_pref_frame |
0 | 605 }; |
606 | |
607 static PurplePluginInfo info = | |
608 { | |
13 | 609 PURPLE_PLUGIN_MAGIC, |
610 PURPLE_MAJOR_VERSION, | |
611 PURPLE_MINOR_VERSION, | |
612 PURPLE_PLUGIN_STANDARD, /**< type */ | |
613 NULL, /**< ui_req */ | |
614 0, /**< flags */ | |
615 NULL, /**< deps */ | |
616 PURPLE_PRIORITY_DEFAULT, /**< priority */ | |
617 PIDGINAUD_PLUGIN_ID, /**< id */ | |
618 "Pidgin-Audacious", /**< name */ | |
619 "2.1.0d2", /**< version */ | |
620 "Automatically updates your Pidgin status info with the currently " | |
621 "playing music in Audacious.", /** summary */ | |
622 "Automatically updates your Pidgin status info with the currently " | |
623 "playing music in Audacious.", /** desc */ | |
624 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ | |
625 "http://www.honeyplanet.jp", /**< homepage */ | |
626 load_plugin, /**< load */ | |
627 unload_plugin, /**< unload */ | |
628 NULL, /**< destroy */ | |
629 NULL, /**< ui_info */ | |
630 NULL, /**< extra_info */ | |
631 &pref_info, /**< pref info */ | |
632 NULL | |
0 | 633 }; |
634 | |
635 static void | |
636 init_plugin(PurplePlugin *plugin) | |
637 { | |
13 | 638 g_type_init(); |
0 | 639 |
13 | 640 /* add plugin preferences */ |
641 purple_prefs_add_none(OPT_PIDGINAUD); | |
642 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); | |
643 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); | |
644 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
|
645 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN); |
0 | 646 |
647 } | |
648 | |
649 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) |