Mercurial > pidgin-audacious
annotate pidgin-audacious.c @ 17:14de631fa929
drop outdated alias support
author | Yoshiki Yazawa <yaz@honeyplanet.jp> |
---|---|
date | Thu, 02 Oct 2008 18:36:39 +0900 |
parents | 9e37b72309d4 |
children | dc3aa0bf24c0 |
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_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template" |
0 | 42 |
13 | 43 #define SONG_TOKEN "%song" |
44 #define NO_SONG_MESSAGE "No song being played." | |
0 | 45 |
13 | 46 #define aud_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, \ |
47 "Pidgin-Audacious", \ | |
48 fmt, ## __VA_ARGS__); | |
49 #define aud_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, \ | |
50 "Pidgin-Audacious", \ | |
51 fmt, ## __VA_ARGS__); | |
0 | 52 |
53 static gint timeout_tag = 0; | |
54 | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
55 GHashTable *seed_status; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
56 GHashTable *seed_userinfo; |
0 | 57 |
58 GHashTable *pushed_status; | |
59 GHashTable *pushed_userinfo; | |
60 | |
16
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
61 DBusGConnection *connection = NULL; |
0 | 62 DBusGProxy *session = NULL; |
63 | |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
64 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
|
65 |
0 | 66 static void aud_process(gchar *aud_info); |
67 | |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
68 static DBusGProxy * |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
69 get_dbus_proxy(void) |
0 | 70 { |
71 GError *error = NULL; | |
72 connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); | |
73 g_clear_error(&error); | |
74 | |
75 session = dbus_g_proxy_new_for_name(connection, AUDACIOUS_DBUS_SERVICE, | |
76 AUDACIOUS_DBUS_PATH, | |
77 AUDACIOUS_DBUS_INTERFACE); | |
78 | |
79 g_clear_error(&error); | |
80 return session; | |
81 } | |
82 | |
83 static gboolean | |
84 watchdog_func(void) | |
85 { | |
13 | 86 gint playpos = 0; |
87 gchar *song = NULL, *tmp = NULL; | |
0 | 88 |
13 | 89 gboolean rv = TRUE; |
90 size_t dummy; | |
0 | 91 |
14
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
92 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
|
93 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
|
94 } |
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
95 |
0 | 96 aud_debug("session = %p\n", session); |
97 aud_debug("is_playing = %d\n", audacious_remote_is_playing(session)); | |
98 | |
13 | 99 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ |
0 | 100 aud_process(NULL); |
16
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
101 purple_util_set_current_song(NULL, NULL, NULL); |
0 | 102 return rv; |
103 } | |
104 | |
105 playpos = audacious_remote_get_playlist_pos(session); | |
106 tmp = audacious_remote_get_playlist_title(session, playpos); | |
107 if(tmp) { | |
13 | 108 if(botch_utf) /* if function exists */ |
0 | 109 song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy); |
110 else | |
111 song = g_strdup(tmp); | |
112 } | |
113 g_free(tmp); | |
114 tmp = NULL; | |
115 | |
116 aud_process(song); | |
117 g_free(song); | |
118 song = NULL; | |
15
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
119 |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
120 /* 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
|
121 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
|
122 |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
123 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
|
124 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
|
125 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
|
126 |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
127 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
|
128 artist ? artist : "", |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
129 album ? album : ""); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
130 |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
131 g_free(artist); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
132 g_free(title); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
133 g_free(album); |
b88a5f934224
preliminary support for purple_util_set_current_song()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
14
diff
changeset
|
134 |
13 | 135 return rv; |
0 | 136 } |
137 | |
138 static void | |
139 aud_process_status(PurpleConnection *gc, gchar *aud_info) | |
140 { | |
13 | 141 gchar *new = NULL, *key = NULL; |
142 const gchar *current, *seed, *pushed, *proto; | |
143 PurpleAccount *account; | |
144 PurplePresence *presence; | |
145 PurplePlugin *prpl; | |
146 PurplePluginProtocolInfo *prpl_info; | |
147 PurpleStatus *status; | |
0 | 148 |
13 | 149 account = purple_connection_get_account(gc); |
150 presence = purple_account_get_presence(account); | |
0 | 151 |
13 | 152 proto = purple_account_get_protocol_id(account); |
153 prpl = purple_find_prpl(proto); | |
154 g_return_if_fail(prpl != NULL); | |
0 | 155 |
13 | 156 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
157 g_return_if_fail(prpl_info != NULL && prpl_info->set_status != NULL); | |
0 | 158 |
13 | 159 status = purple_presence_get_active_status(presence); |
160 g_return_if_fail(status != NULL); | |
0 | 161 |
13 | 162 /* generate key for hash table */ |
163 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
0 | 164 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
165 /* retrieve current user status */ |
13 | 166 current = purple_status_get_attr_string(status, "message"); |
167 aud_debug("status current = %s\n", current); | |
0 | 168 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
169 /* invalidate pushded status on auto away etc. */ |
13 | 170 if(current == NULL || strlen(current) == 0) { |
171 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); | |
172 g_free(key); | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
173 return; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
174 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
175 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
176 /* pop pushed_status */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
177 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
|
178 |
13 | 179 /* if current status differs from pushed_status or |
180 contains token, replace hashes with current. */ | |
181 if((pushed && g_ascii_strcasecmp(current, pushed)) || | |
182 strstr(current, SONG_TOKEN)) { | |
183 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
|
184 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); |
0 | 185 } |
186 | |
13 | 187 /* construct new status message */ |
188 seed = (gchar *)g_hash_table_lookup(seed_status, key); | |
189 if(!seed) { | |
190 g_free(key); | |
191 return; | |
192 } | |
193 aud_debug("status seed = %s\n", seed); | |
0 | 194 |
13 | 195 if(strstr(seed, SONG_TOKEN)) { |
196 if(aud_info){ | |
197 new = purple_strreplace(seed, SONG_TOKEN, aud_info); | |
198 } | |
199 else { | |
200 new = g_strdup(NO_SONG_MESSAGE); | |
201 } | |
202 } | |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
203 |
13 | 204 if(!new) { |
205 g_free(key); | |
206 return; | |
207 } | |
0 | 208 |
13 | 209 /* set status message only if text has been changed */ |
210 pushed = (gchar *)g_hash_table_lookup(pushed_status, key); | |
211 aud_debug("status pushed = %s\n", pushed); | |
0 | 212 |
13 | 213 if (!pushed || g_ascii_strcasecmp(pushed, new)) { |
214 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new)); | |
215 purple_status_set_attr_string(status, "message", new); | |
216 prpl_info->set_status(account, status); | |
217 } | |
218 g_free(key); | |
219 g_free(new); | |
0 | 220 } |
221 | |
222 | |
223 static void | |
224 aud_process_userinfo(PurpleConnection *gc, gchar *aud_info) | |
225 { | |
13 | 226 gchar *new = NULL, *key = NULL; |
227 const gchar *current, *seed, *pushed, *proto; | |
228 PurpleAccount *account; | |
229 PurplePlugin *prpl; | |
230 PurplePluginProtocolInfo *prpl_info; | |
0 | 231 |
13 | 232 account = purple_connection_get_account(gc); |
0 | 233 |
13 | 234 proto = purple_account_get_protocol_id(account); |
235 prpl = purple_find_prpl(proto); | |
236 g_return_if_fail(prpl != NULL); | |
0 | 237 |
13 | 238 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); |
239 g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL); | |
0 | 240 |
13 | 241 /* generate key for hash table*/ |
242 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
0 | 243 |
13 | 244 /* retrieve current user info */ |
245 current = purple_account_get_user_info(account); /* from account.xml */ | |
246 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
|
247 |
13 | 248 /* invalidate pushded status on auto away etc. */ |
249 if(current == NULL || strlen(current) == 0) { | |
250 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); | |
251 g_free(key); | |
252 return; | |
253 } | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
254 |
13 | 255 /* pop pushed_userinfo */ |
256 pushed = g_hash_table_lookup(pushed_userinfo, key); | |
0 | 257 |
17
14de631fa929
drop outdated alias support
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
16
diff
changeset
|
258 /* if current userinfo differs from pushed_userinfo or contains |
14de631fa929
drop outdated alias support
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
16
diff
changeset
|
259 token, replace seed with this. */ |
13 | 260 if((pushed && g_ascii_strcasecmp(current, pushed)) || |
261 strstr(current, SONG_TOKEN)) { | |
262 g_hash_table_replace(seed_userinfo, g_strdup(key), | |
263 g_strdup(current)); | |
264 g_hash_table_replace(pushed_userinfo, g_strdup(key), | |
265 g_strdup(current)); | |
266 } | |
0 | 267 |
13 | 268 /* construct new status message */ |
269 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); | |
270 if(!seed) { | |
271 g_free(key); | |
272 return; | |
273 } | |
274 aud_debug("userinfo seed = %s\n", seed); | |
0 | 275 |
13 | 276 if(strstr(seed, SONG_TOKEN)) { |
277 if(aud_info){ | |
278 new = purple_strreplace(seed, SONG_TOKEN, aud_info); | |
279 } | |
280 else { | |
281 new = g_strdup(NO_SONG_MESSAGE); | |
282 } | |
283 } | |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
284 |
13 | 285 if(!new) { |
286 g_free(key); | |
287 return; | |
288 } | |
0 | 289 |
13 | 290 /* set user info only if text has been changed */ |
291 pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key); | |
292 aud_debug("userinfo pushed = %s\n", pushed); | |
0 | 293 |
13 | 294 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
295 g_hash_table_replace(pushed_userinfo, g_strdup(key), | |
296 g_strdup(new)); | |
297 prpl_info->set_info(gc, new); | |
298 } | |
299 g_free(key); | |
300 g_free(new); | |
0 | 301 } |
302 | |
303 | |
304 static void | |
305 aud_process(gchar *aud_info) | |
306 { | |
13 | 307 GList *l; |
308 PurpleConnection *gc; | |
0 | 309 |
13 | 310 for (l = purple_connections_get_all(); l != NULL; l = l->next) { |
311 gc = (PurpleConnection *) l->data; | |
0 | 312 |
13 | 313 /* make sure we're connected */ |
314 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) { | |
315 continue; | |
316 } | |
0 | 317 |
13 | 318 if (purple_prefs_get_bool(OPT_PROCESS_USERINFO)) { |
319 aud_process_userinfo(gc, aud_info); | |
320 } | |
0 | 321 |
13 | 322 if (purple_prefs_get_bool(OPT_PROCESS_STATUS)) { |
323 aud_process_status(gc, aud_info); | |
324 } | |
0 | 325 |
13 | 326 } |
0 | 327 } |
328 static void | |
329 removekey(gpointer data) | |
330 { | |
13 | 331 g_free(data); |
0 | 332 } |
333 | |
334 static void | |
335 removeval(gpointer data) | |
336 { | |
13 | 337 g_free(data); |
0 | 338 } |
339 | |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
340 static PurpleCmdRet |
13 | 341 paste_current_song(PurpleConversation *conv, const gchar *cmd, |
342 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
|
343 { |
13 | 344 gint playpos = 0; |
345 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
|
346 PurpleConversationType type = purple_conversation_get_type(conv); |
13 | 347 size_t dummy; |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
348 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
|
349 |
13 | 350 /* audacious isn't playing */ |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
351 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
|
352 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
|
353 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
354 |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
355 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
|
356 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
|
357 |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
358 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
|
359 |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
360 if(template && strstr(template, SONG_TOKEN)) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
361 tmp2 = purple_strreplace(template, SONG_TOKEN, tmp); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
362 g_free(tmp); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
363 tmp = NULL; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
364 } |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
365 else { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
366 tmp2 = tmp; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
367 } |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
368 |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
369 if(tmp2) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
370 if(botch_utf) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
371 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
|
372 g_free(tmp2); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
373 tmp2 = NULL; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
374 } |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
375 else |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
376 song = tmp2; |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
377 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
378 |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
379 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
|
380 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
|
381 if (chat && song) |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
382 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
|
383 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
384 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
|
385 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
|
386 if(im && song) |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
387 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
|
388 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
389 |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
390 g_free(song); |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
391 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
|
392 } |
0 | 393 |
394 static gboolean | |
395 load_plugin(PurplePlugin *plugin) | |
396 { | |
13 | 397 seed_status = g_hash_table_new_full(g_str_hash, g_str_equal, |
398 removekey, removeval); | |
399 seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, | |
400 removekey, removeval); | |
0 | 401 |
13 | 402 pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal, |
403 removekey, removeval); | |
404 pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, | |
405 removekey, removeval); | |
0 | 406 |
13 | 407 timeout_tag = g_timeout_add(15*1000, (gpointer)watchdog_func, NULL); |
0 | 408 |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
409 cmdid_paste_current_song = |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
410 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
|
411 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
|
412 NULL, paste_current_song, |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
413 "song: Paste currently plaing song", NULL); |
0 | 414 |
13 | 415 return TRUE; |
0 | 416 } |
417 | |
418 static gboolean | |
419 unload_plugin(PurplePlugin *plugin) | |
420 { | |
13 | 421 aud_debug("pidgin-audacious unload called\n"); |
0 | 422 |
13 | 423 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
|
424 |
13 | 425 g_hash_table_destroy(seed_status); |
426 g_hash_table_destroy(seed_userinfo); | |
0 | 427 |
13 | 428 g_hash_table_destroy(pushed_status); |
429 g_hash_table_destroy(pushed_userinfo); | |
0 | 430 |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
431 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
|
432 |
14
89bd98990fff
now it tries to get dbus proxy if session is NULL.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
13
diff
changeset
|
433 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
|
434 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
|
435 |
16
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
436 if(connection) { |
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
437 dbus_g_connection_unref(connection); |
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
438 connection = NULL; |
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
439 } |
9e37b72309d4
- clear current song if audacious is not playing.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
15
diff
changeset
|
440 |
13 | 441 return TRUE; |
0 | 442 } |
443 | |
444 static PurplePluginPrefFrame * | |
445 get_plugin_pref_frame(PurplePlugin *plugin) | |
446 { | |
13 | 447 PurplePluginPref *pref; |
448 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new(); | |
0 | 449 |
13 | 450 /* create gtk elements for the plugin preferences */ |
451 pref = purple_plugin_pref_new_with_label( | |
452 "Pidgin-Audacious Configuration"); | |
453 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
|
454 |
13 | 455 pref = purple_plugin_pref_new_with_name_and_label( |
456 OPT_PROCESS_STATUS, | |
457 "Expand " SONG_TOKEN " to song info in the status message"); | |
458 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
|
459 |
13 | 460 pref = purple_plugin_pref_new_with_name_and_label( |
461 OPT_PROCESS_USERINFO, | |
462 "Expand " SONG_TOKEN " to song info in the user info"); | |
463 purple_plugin_pref_frame_add(frame, pref); | |
0 | 464 |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
465 /* paste template */ |
13 | 466 pref = purple_plugin_pref_new_with_name_and_label( |
467 OPT_PASTE_TEMPLATE, | |
468 "Paste template"); | |
469 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
|
470 |
13 | 471 return frame; |
0 | 472 } |
473 | |
474 static PurplePluginUiInfo pref_info = | |
475 { | |
13 | 476 get_plugin_pref_frame |
0 | 477 }; |
478 | |
479 static PurplePluginInfo info = | |
480 { | |
13 | 481 PURPLE_PLUGIN_MAGIC, |
482 PURPLE_MAJOR_VERSION, | |
483 PURPLE_MINOR_VERSION, | |
484 PURPLE_PLUGIN_STANDARD, /**< type */ | |
485 NULL, /**< ui_req */ | |
486 0, /**< flags */ | |
487 NULL, /**< deps */ | |
488 PURPLE_PRIORITY_DEFAULT, /**< priority */ | |
489 PIDGINAUD_PLUGIN_ID, /**< id */ | |
490 "Pidgin-Audacious", /**< name */ | |
491 "2.1.0d2", /**< version */ | |
492 "Automatically updates your Pidgin status info with the currently " | |
493 "playing music in Audacious.", /** summary */ | |
494 "Automatically updates your Pidgin status info with the currently " | |
495 "playing music in Audacious.", /** desc */ | |
496 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ | |
497 "http://www.honeyplanet.jp", /**< homepage */ | |
498 load_plugin, /**< load */ | |
499 unload_plugin, /**< unload */ | |
500 NULL, /**< destroy */ | |
501 NULL, /**< ui_info */ | |
502 NULL, /**< extra_info */ | |
503 &pref_info, /**< pref info */ | |
504 NULL | |
0 | 505 }; |
506 | |
507 static void | |
508 init_plugin(PurplePlugin *plugin) | |
509 { | |
13 | 510 g_type_init(); |
0 | 511 |
13 | 512 /* add plugin preferences */ |
513 purple_prefs_add_none(OPT_PIDGINAUD); | |
514 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); | |
515 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); | |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
516 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN); |
0 | 517 |
518 } | |
519 | |
520 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) |