Mercurial > pidgin-audacious
annotate pidgin-audacious.c @ 8:8af1f090ba9a
branch merge
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sat, 01 Mar 2008 03:18:22 +0900 |
parents | feb13e877029 76f3cd9915c5 |
children | d5702f04b19c |
rev | line source |
---|---|
0 | 1 /* |
2 * Pidgin-Audacious plugin. | |
3 * | |
4 * This program is free software; you can redistribute it and/or | |
5 * modify it under the terms of the GNU General Public License as | |
6 * published by the Free Software Foundation; either version 2 of the | |
7 * License, or (at your option) any later version. | |
8 * | |
9 * This program is distributed in the hope that it will be useful, but | |
10 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 * General Public License for more details. | |
13 * | |
14 * You should have received a copy of the GNU General Public License | |
15 * along with this program; if not, write to the Free Software | |
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
17 * 02111-1307, USA. | |
18 */ | |
19 #define PURPLE_PLUGINS 1 | |
20 | |
21 #include <stdio.h> | |
22 #include <stdlib.h> | |
23 #include <string.h> | |
24 #include <glib.h> | |
25 | |
26 #include "gtkplugin.h" | |
27 #include "util.h" | |
28 #include "debug.h" | |
29 #include "connection.h" | |
30 #include "version.h" | |
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 |
36 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious" | |
37 | |
38 #define OPT_PIDGINAUD "/plugins/pidgin_audacious" | |
39 #define OPT_PROCESS_STATUS OPT_PIDGINAUD "/process_status" | |
40 #define OPT_PROCESS_USERINFO OPT_PIDGINAUD "/process_userinfo" | |
41 #define OPT_PROCESS_ALIAS OPT_PIDGINAUD "/process_alias" | |
42 | |
43 #define SONG_TOKEN "%song" | |
44 #define NO_SONG_MESSAGE "No song being played." | |
45 | |
46 #define BUDDY_ALIAS_MAXLEN 387 | |
47 | |
48 #define aud_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, "Pidgin-Audacious", \ | |
49 fmt, ## __VA_ARGS__); | |
50 #define aud_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, "Pidgin-Audacious", \ | |
51 fmt, ## __VA_ARGS__); | |
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; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
57 GHashTable *seed_alias; |
0 | 58 |
59 GHashTable *pushed_status; | |
60 GHashTable *pushed_userinfo; | |
61 GHashTable *pushed_alias; | |
62 | |
63 DBusGProxy *session = NULL; | |
64 | |
65 static void aud_process(gchar *aud_info); | |
66 | |
67 static DBusGProxy *get_dbus_proxy(void) | |
68 { | |
69 DBusGConnection *connection = NULL; | |
70 DBusGProxy *session = NULL; | |
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 { | |
86 gint playpos = 0; | |
87 gchar *song = NULL, *tmp = NULL; | |
88 | |
89 gboolean rv = TRUE; | |
90 size_t dummy; | |
91 | |
92 aud_debug("session = %p\n", session); | |
93 | |
94 aud_debug("is_playing = %d\n", audacious_remote_is_playing(session)); | |
95 | |
96 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ | |
97 aud_process(NULL); | |
98 return rv; | |
99 } | |
100 | |
101 playpos = audacious_remote_get_playlist_pos(session); | |
102 tmp = audacious_remote_get_playlist_title(session, playpos); | |
103 if(tmp) { | |
104 if(botch_utf) // function exists | |
105 song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy); | |
106 else | |
107 song = g_strdup(tmp); | |
108 } | |
109 g_free(tmp); | |
110 tmp = NULL; | |
111 | |
112 aud_process(song); | |
113 g_free(song); | |
114 song = NULL; | |
115 return rv; | |
116 } | |
117 | |
118 static void | |
119 aud_process_status(PurpleConnection *gc, gchar *aud_info) | |
120 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
121 gchar *new = NULL, *key = NULL; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
122 const gchar *current, *seed, *pushed, *proto; |
0 | 123 PurpleAccount *account; |
124 PurplePresence *presence; | |
125 PurplePlugin *prpl; | |
126 PurplePluginProtocolInfo *prpl_info; | |
127 PurpleStatus *status; | |
128 | |
129 account = purple_connection_get_account(gc); | |
130 presence = purple_account_get_presence(account); | |
131 | |
132 proto = purple_account_get_protocol_id(account); | |
133 prpl = purple_find_prpl(proto); | |
134 g_return_if_fail(prpl != NULL); | |
135 | |
136 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
137 g_return_if_fail(prpl_info != NULL && prpl_info->set_status != NULL); | |
138 | |
139 status = purple_presence_get_active_status(presence); | |
140 g_return_if_fail(status != NULL); | |
141 | |
142 /* generate key for hash table */ | |
143 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
144 | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
145 /* retrieve current user status */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
146 current = purple_status_get_attr_string(status, "message"); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
147 aud_debug("status current = %s\n", current); |
0 | 148 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
149 /* invalidate pushded status on auto away etc. */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
150 if(current == NULL || strlen(current) == 0) { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
151 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
152 g_free(key); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
153 return; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
154 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
155 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
156 /* pop pushed_status */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
157 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
|
158 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
159 /* if current status differs from pushed_status or contains token, replace hashes with current. */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
160 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
161 g_hash_table_replace(seed_status, g_strdup(key), g_strdup(current)); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
162 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); |
0 | 163 } |
164 | |
165 /* construct new status message */ | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
166 seed = (gchar *)g_hash_table_lookup(seed_status, key); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
167 g_return_if_fail(seed != NULL); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
168 aud_debug("status seed = %s\n", seed); |
0 | 169 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
170 if(strstr(seed, SONG_TOKEN)) { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
171 if(aud_info){ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
172 new = purple_strreplace(seed, SONG_TOKEN, aud_info); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
173 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
174 else { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
175 new = g_strdup(NO_SONG_MESSAGE); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
176 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
177 } |
0 | 178 g_return_if_fail(new != NULL); |
179 | |
180 /* set status message only if text has been changed */ | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
181 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
|
182 aud_debug("status pushed = %s\n", pushed); |
0 | 183 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
184 if (!pushed || g_ascii_strcasecmp(pushed, new)) { |
0 | 185 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new)); |
186 purple_status_set_attr_string(status, "message", new); | |
187 prpl_info->set_status(account, status); | |
188 } | |
189 g_free(key); | |
190 g_free(new); | |
191 } | |
192 | |
193 | |
194 static void | |
195 aud_process_userinfo(PurpleConnection *gc, gchar *aud_info) | |
196 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
197 gchar *new = NULL, *key = NULL; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
198 const gchar *current, *seed, *pushed, *proto; |
0 | 199 PurpleAccount *account; |
200 PurplePlugin *prpl; | |
201 PurplePluginProtocolInfo *prpl_info; | |
202 | |
203 account = purple_connection_get_account(gc); | |
204 | |
205 proto = purple_account_get_protocol_id(account); | |
206 prpl = purple_find_prpl(proto); | |
207 g_return_if_fail(prpl != NULL); | |
208 | |
209 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
210 g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL); | |
211 | |
212 /* generate key for hash table*/ | |
213 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
214 | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
215 /* retrieve current user info */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
216 current = purple_account_get_user_info(account); /* it's always from account.xml! */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
217 aud_debug("userinfo current = %s\n", current); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
218 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
219 /* invalidate pushded status on auto away etc. */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
220 if(current == NULL || strlen(current) == 0) { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
221 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
222 g_free(key); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
223 return; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
224 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
225 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
226 /* pop pushed_userinfo */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
227 pushed = g_hash_table_lookup(pushed_userinfo, key); |
0 | 228 |
229 /* if current alias differs from pushed_alias or contains token, replace seed with this. */ | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
230 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
231 g_hash_table_replace(seed_userinfo, g_strdup(key), g_strdup(current)); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
232 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(current)); |
0 | 233 } |
234 | |
235 /* construct new status message */ | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
236 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
237 g_return_if_fail(seed != NULL); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
238 aud_debug("userinfo seed = %s\n", seed); |
0 | 239 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
240 if(strstr(seed, SONG_TOKEN)) { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
241 if(aud_info){ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
242 new = purple_strreplace(seed, SONG_TOKEN, aud_info); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
243 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
244 else { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
245 new = g_strdup(NO_SONG_MESSAGE); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
246 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
247 } |
0 | 248 g_return_if_fail(new != NULL); |
249 | |
250 /* set user info only if text has been changed */ | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
251 pushed = (gchar *)g_hash_table_lookup(pushed_userinfo, key); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
252 aud_debug("userinfo pushed = %s\n", pushed); |
0 | 253 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
254 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
0 | 255 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(new)); |
256 prpl_info->set_info(gc, new); | |
257 } | |
258 g_free(key); | |
259 g_free(new); | |
260 } | |
261 | |
262 static void | |
263 aud_process_alias(PurpleConnection *gc, gchar *aud_info) | |
264 { | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
265 gchar *new = NULL, *key = NULL; |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
266 const gchar *current, *seed, *pushed, *proto; |
0 | 267 PurpleAccount *account; |
268 PurplePlugin *prpl; | |
269 PurplePluginProtocolInfo *prpl_info; | |
270 | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
271 glong bytes; |
0 | 272 |
273 account = purple_connection_get_account(gc); | |
274 | |
275 proto = purple_account_get_protocol_id(account); | |
276 prpl = purple_find_prpl(proto); | |
277 g_return_if_fail(prpl != NULL); | |
278 | |
279 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
280 g_return_if_fail(prpl_info != NULL); | |
281 | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
282 /* generate key for hash table*/ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
283 key = g_strdup_printf("%s %s", account->username, account->protocol_id); |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
284 |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
285 /* retrieve current alias */ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
286 current = purple_account_get_alias(account); |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
287 if(current == NULL || strlen(current) == 0) { |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
288 aud_error("couldn't get current alias\n"); |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
289 g_free(key); |
0 | 290 return; |
291 } | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
292 aud_debug("current alias = %s\n", current); |
0 | 293 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
294 /* pop pushed_alias */ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
295 pushed = g_hash_table_lookup(pushed_alias, key); |
0 | 296 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
297 /* if current alias differs from pushed_alias or contains token, replace seed with current. */ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
298 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
299 g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current)); |
0 | 300 } |
301 | |
302 /* construct new status message */ | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
303 seed = g_hash_table_lookup(seed_alias, key); |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
304 g_return_if_fail(seed != NULL); |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
305 aud_debug("alias: seed = %s\n", (gchar *)seed); |
0 | 306 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
307 bytes = strlen(seed); |
0 | 308 bytes -= strlen(SONG_TOKEN); |
309 aud_debug("alias: bytes = %ld", bytes); | |
310 | |
311 if(aud_info){ | |
312 gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN); | |
313 glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1); | |
314 g_utf8_strncpy(tmp, aud_info, utflen); | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
315 new = purple_strreplace(seed, SONG_TOKEN, tmp); |
0 | 316 g_free(tmp); |
317 } | |
318 else { | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
319 new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE); |
0 | 320 } |
321 g_return_if_fail(new != NULL); | |
322 | |
323 /* set user info only if text has been changed */ | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
324 pushed = g_hash_table_lookup(pushed_alias, key); |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
325 aud_debug("alias pushed = %s\n", (gchar *)pushed); |
0 | 326 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
327 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
0 | 328 gboolean ok = FALSE; |
329 PurplePlugin *msn_plugin = NULL; | |
330 msn_plugin = purple_plugins_find_with_id("prpl-msn"); | |
331 aud_debug("msn_plugin = %p\n", msn_plugin); | |
332 | |
333 g_hash_table_replace(pushed_alias, g_strdup(key), g_strdup(new)); | |
334 purple_plugin_ipc_call(msn_plugin, "msn_set_friendly_name", &ok, gc, new); | |
335 aud_debug("ipc %d\n", ok); | |
336 } | |
337 g_free(key); | |
338 g_free(new); | |
339 } | |
340 | |
341 static void | |
342 aud_process(gchar *aud_info) | |
343 { | |
344 GList *l; | |
345 PurpleConnection *gc; | |
346 | |
347 for (l = purple_connections_get_all(); l != NULL; l = l->next) { | |
348 gc = (PurpleConnection *) l->data; | |
349 | |
350 /* make sure we're connected */ | |
351 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) { | |
352 continue; | |
353 } | |
354 | |
355 if (purple_prefs_get_bool(OPT_PROCESS_USERINFO)) { | |
356 aud_process_userinfo(gc, aud_info); | |
357 } | |
358 | |
359 if (purple_prefs_get_bool(OPT_PROCESS_STATUS)) { | |
360 aud_process_status(gc, aud_info); | |
361 } | |
362 | |
363 if (purple_prefs_get_bool(OPT_PROCESS_ALIAS)) { | |
364 aud_process_alias(gc, aud_info); | |
365 } | |
366 | |
367 } | |
368 } | |
369 static void | |
370 removekey(gpointer data) | |
371 { | |
372 g_free(data); | |
373 } | |
374 | |
375 static void | |
376 removeval(gpointer data) | |
377 { | |
378 g_free(data); | |
379 } | |
380 | |
381 static gboolean | |
382 restore_alias(PurpleConnection *gc, gpointer data) | |
383 { | |
384 PurpleAccount *account; | |
385 gpointer val = NULL; | |
386 gchar *key = NULL; | |
387 | |
388 aud_debug("********** restore_alias called **********\n"); | |
389 account = purple_connection_get_account(gc); | |
390 | |
391 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
392 val = g_hash_table_lookup(seed_alias, key); |
0 | 393 g_return_val_if_fail(val != NULL, FALSE); |
394 | |
395 aud_debug("write back alias %s\n", val); | |
396 purple_account_set_alias(account, val); //oct16 | |
397 | |
398 g_free(key); | |
399 | |
400 return TRUE; | |
401 } | |
402 | |
403 | |
404 static gboolean | |
405 load_plugin(PurplePlugin *plugin) | |
406 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
407 seed_status = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
408 seed_alias = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
409 seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); |
0 | 410 |
411 pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
412 pushed_alias = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
413 pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
414 | |
415 timeout_tag = g_timeout_add(15*1000, (gpointer)watchdog_func, NULL); | |
416 | |
417 /* connect to signing-off signal */ | |
418 purple_signal_connect(purple_connections_get_handle(), "signing-off", plugin, | |
419 PURPLE_CALLBACK(restore_alias), NULL); | |
420 | |
421 | |
422 return TRUE; | |
423 } | |
424 | |
425 static gboolean | |
426 unload_plugin(PurplePlugin *plugin) | |
427 { | |
428 aud_debug("pidgin-audacious unload called\n"); | |
429 | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
430 g_hash_table_destroy(seed_status); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
431 g_hash_table_destroy(seed_alias); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
432 g_hash_table_destroy(seed_userinfo); |
0 | 433 |
434 g_hash_table_destroy(pushed_status); | |
435 g_hash_table_destroy(pushed_alias); | |
436 g_hash_table_destroy(pushed_userinfo); | |
437 | |
438 return TRUE; | |
439 } | |
440 | |
441 static PurplePluginPrefFrame * | |
442 get_plugin_pref_frame(PurplePlugin *plugin) | |
443 { | |
444 PurplePluginPref *pref; | |
445 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new(); | |
446 | |
447 /* create gtk elements for the plugin preferences */ | |
448 pref = purple_plugin_pref_new_with_label("Pidgin-Audacious Configuration"); | |
449 purple_plugin_pref_frame_add(frame, pref); | |
450 | |
451 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_STATUS, | |
452 "Expand " SONG_TOKEN " to song info in the status message"); | |
453 purple_plugin_pref_frame_add(frame, pref); | |
454 | |
455 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_USERINFO, | |
456 "Expand " SONG_TOKEN " to song info in the user info"); | |
457 purple_plugin_pref_frame_add(frame, pref); | |
458 | |
459 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_ALIAS, | |
460 "Expand " SONG_TOKEN " to song info in the alias"); | |
461 purple_plugin_pref_frame_add(frame, pref); | |
462 | |
463 return frame; | |
464 } | |
465 | |
466 static PurplePluginUiInfo pref_info = | |
467 { | |
468 get_plugin_pref_frame | |
469 }; | |
470 | |
471 static PurplePluginInfo info = | |
472 { | |
473 PURPLE_PLUGIN_MAGIC, | |
474 PURPLE_MAJOR_VERSION, | |
475 PURPLE_MINOR_VERSION, | |
476 PURPLE_PLUGIN_STANDARD, /**< type */ | |
477 NULL, /**< ui_req */ | |
478 0, /**< flags */ | |
479 NULL, /**< deps */ | |
480 PURPLE_PRIORITY_DEFAULT, /**< priority */ | |
481 PIDGINAUD_PLUGIN_ID, /**< id */ | |
482 "Pidgin-Audacious", /**< name */ | |
4
19782faf1f00
- add a msn alias patch to the repository.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2
diff
changeset
|
483 "2.0.0", /**< version */ |
0 | 484 "Automatically updates your Pidgin status info with the currently " |
485 "playing music in Audacious.", /** summary */ | |
486 "Automatically updates your Pidgin status info with the currently " | |
487 "playing music in Audacious.", /** desc */ | |
488 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ | |
489 "http://www.honeyplanet.jp", /**< homepage */ | |
490 load_plugin, /**< load */ | |
491 unload_plugin, /**< unload */ | |
492 NULL, /**< destroy */ | |
493 NULL, /**< ui_info */ | |
494 NULL, /**< extra_info */ | |
495 &pref_info, /**< pref info */ | |
496 NULL | |
497 }; | |
498 | |
499 static void | |
500 init_plugin(PurplePlugin *plugin) | |
501 { | |
502 g_type_init(); | |
503 | |
504 /* add plugin preferences */ | |
505 purple_prefs_add_none(OPT_PIDGINAUD); | |
506 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); | |
507 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); | |
508 purple_prefs_add_bool(OPT_PROCESS_ALIAS, TRUE); | |
509 | |
510 session = get_dbus_proxy(); | |
511 } | |
512 | |
513 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) |