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