Mercurial > pidgin-audacious
annotate pidgin-audacious.c @ 3:e7f2d7bb0381
update prototype of botch_utf()
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Fri, 29 Feb 2008 02:36:09 +0900 |
parents | f1dc959e4706 |
children | 76f3cd9915c5 feb13e877029 |
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 | |
3
e7f2d7bb0381
update prototype of botch_utf()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2
diff
changeset
|
34 extern gchar *botch_utf(const gchar *msg, size_t len, size_t *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 #if 0 | |
82 if (audacious_remote_is_running(session)) { | |
83 return session; | |
84 } | |
85 else { | |
86 return NULL; | |
87 } | |
88 #endif | |
89 } | |
90 | |
91 static gboolean | |
92 watchdog_func(void) | |
93 { | |
94 gint playpos = 0; | |
95 gchar *song = NULL, *tmp = NULL; | |
96 // DBusGProxy *session = get_dbus_proxy(); | |
97 | |
98 gboolean rv = TRUE; | |
99 size_t dummy; | |
100 | |
101 aud_debug("session = %p\n", session); | |
102 | |
103 aud_debug("is_playing = %d\n", audacious_remote_is_playing(session)); | |
104 | |
105 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ | |
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) { | |
113 if(botch_utf) // function exists | |
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; | |
124 return rv; | |
125 } | |
126 | |
127 static void | |
128 aud_process_status(PurpleConnection *gc, gchar *aud_info) | |
129 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
130 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
|
131 const gchar *current, *seed, *pushed, *proto; |
0 | 132 PurpleAccount *account; |
133 PurplePresence *presence; | |
134 PurplePlugin *prpl; | |
135 PurplePluginProtocolInfo *prpl_info; | |
136 PurpleStatus *status; | |
137 | |
138 account = purple_connection_get_account(gc); | |
139 presence = purple_account_get_presence(account); | |
140 | |
141 proto = purple_account_get_protocol_id(account); | |
142 prpl = purple_find_prpl(proto); | |
143 g_return_if_fail(prpl != NULL); | |
144 | |
145 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
146 g_return_if_fail(prpl_info != NULL && prpl_info->set_status != NULL); | |
147 | |
148 status = purple_presence_get_active_status(presence); | |
149 g_return_if_fail(status != NULL); | |
150 | |
151 /* generate key for hash table */ | |
152 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
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 */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
155 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
|
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. */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
159 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
|
160 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
|
161 g_free(key); |
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 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
168 /* 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
|
169 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
|
170 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
|
171 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); |
0 | 172 } |
173 | |
174 /* 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
|
175 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
|
176 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
|
177 aud_debug("status seed = %s\n", seed); |
0 | 178 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
179 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
|
180 if(aud_info){ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
181 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
|
182 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
183 else { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
184 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
|
185 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
186 } |
0 | 187 g_return_if_fail(new != NULL); |
188 | |
189 /* 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
|
190 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
|
191 aud_debug("status pushed = %s\n", pushed); |
0 | 192 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
193 if (!pushed || g_ascii_strcasecmp(pushed, new)) { |
0 | 194 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new)); |
195 purple_status_set_attr_string(status, "message", new); | |
196 prpl_info->set_status(account, status); | |
197 } | |
198 g_free(key); | |
199 g_free(new); | |
200 } | |
201 | |
202 | |
203 static void | |
204 aud_process_userinfo(PurpleConnection *gc, gchar *aud_info) | |
205 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
206 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
|
207 const gchar *current, *seed, *pushed, *proto; |
0 | 208 PurpleAccount *account; |
209 PurplePlugin *prpl; | |
210 PurplePluginProtocolInfo *prpl_info; | |
211 | |
212 account = purple_connection_get_account(gc); | |
213 | |
214 proto = purple_account_get_protocol_id(account); | |
215 prpl = purple_find_prpl(proto); | |
216 g_return_if_fail(prpl != NULL); | |
217 | |
218 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
219 g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL); | |
220 | |
221 /* generate key for hash table*/ | |
222 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
223 | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
224 /* retrieve current user info */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
225 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
|
226 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
|
227 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
228 /* 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
|
229 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
|
230 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
|
231 g_free(key); |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
232 return; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
233 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
234 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
235 /* pop pushed_userinfo */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
236 pushed = g_hash_table_lookup(pushed_userinfo, key); |
0 | 237 |
238 /* 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
|
239 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
|
240 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
|
241 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(current)); |
0 | 242 } |
243 | |
244 /* 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
|
245 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
|
246 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
|
247 aud_debug("userinfo seed = %s\n", seed); |
0 | 248 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
249 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
|
250 if(aud_info){ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
251 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
|
252 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
253 else { |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
254 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
|
255 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
256 } |
0 | 257 g_return_if_fail(new != NULL); |
258 | |
259 /* 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
|
260 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
|
261 aud_debug("userinfo pushed = %s\n", pushed); |
0 | 262 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
263 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
0 | 264 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(new)); |
265 prpl_info->set_info(gc, new); | |
266 } | |
267 g_free(key); | |
268 g_free(new); | |
269 } | |
270 | |
271 static void | |
272 aud_process_alias(PurpleConnection *gc, gchar *aud_info) | |
273 { | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
274 gchar *new = NULL, *key = NULL; |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
275 const gchar *current, *seed, *pushed, *proto; |
0 | 276 PurpleAccount *account; |
277 PurplePlugin *prpl; | |
278 PurplePluginProtocolInfo *prpl_info; | |
279 | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
280 glong bytes; |
0 | 281 |
282 account = purple_connection_get_account(gc); | |
283 | |
284 proto = purple_account_get_protocol_id(account); | |
285 prpl = purple_find_prpl(proto); | |
286 g_return_if_fail(prpl != NULL); | |
287 | |
288 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
289 g_return_if_fail(prpl_info != NULL); | |
290 | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
291 /* generate key for hash table*/ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
292 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
|
293 |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
294 /* retrieve current alias */ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
295 // current = purple_url_decode(purple_account_get_alias(account)); |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
296 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
|
297 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
|
298 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
|
299 g_free(key); |
0 | 300 return; |
301 } | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
302 aud_debug("current alias = %s\n", current); |
0 | 303 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
304 /* pop pushed_alias */ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
305 pushed = g_hash_table_lookup(pushed_alias, key); |
0 | 306 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
307 /* 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
|
308 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
|
309 g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current)); |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
310 // g_hash_table_replace(pushed_alias, g_strdup(key), g_strdup(current)); //XXX should do? |
0 | 311 } |
312 | |
313 /* construct new status message */ | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
314 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
|
315 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
|
316 aud_debug("alias: seed = %s\n", (gchar *)seed); |
0 | 317 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
318 bytes = strlen(seed); |
0 | 319 bytes -= strlen(SONG_TOKEN); |
320 aud_debug("alias: bytes = %ld", bytes); | |
321 | |
322 if(aud_info){ | |
323 gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN); | |
324 glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1); | |
325 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
|
326 new = purple_strreplace(seed, SONG_TOKEN, tmp); |
0 | 327 g_free(tmp); |
328 } | |
329 else { | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
330 new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE); |
0 | 331 } |
332 g_return_if_fail(new != NULL); | |
333 | |
334 /* 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
|
335 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
|
336 aud_debug("alias pushed = %s\n", (gchar *)pushed); |
0 | 337 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
338 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
0 | 339 gboolean ok = FALSE; |
340 PurplePlugin *msn_plugin = NULL; | |
341 msn_plugin = purple_plugins_find_with_id("prpl-msn"); | |
342 aud_debug("msn_plugin = %p\n", msn_plugin); | |
343 | |
344 g_hash_table_replace(pushed_alias, g_strdup(key), g_strdup(new)); | |
345 purple_plugin_ipc_call(msn_plugin, "msn_set_friendly_name", &ok, gc, new); | |
346 aud_debug("ipc %d\n", ok); | |
347 } | |
348 g_free(key); | |
349 g_free(new); | |
350 } | |
351 | |
352 static void | |
353 aud_process(gchar *aud_info) | |
354 { | |
355 GList *l; | |
356 PurpleConnection *gc; | |
357 | |
358 for (l = purple_connections_get_all(); l != NULL; l = l->next) { | |
359 gc = (PurpleConnection *) l->data; | |
360 | |
361 /* make sure we're connected */ | |
362 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) { | |
363 continue; | |
364 } | |
365 | |
366 if (purple_prefs_get_bool(OPT_PROCESS_USERINFO)) { | |
367 aud_process_userinfo(gc, aud_info); | |
368 } | |
369 | |
370 if (purple_prefs_get_bool(OPT_PROCESS_STATUS)) { | |
371 aud_process_status(gc, aud_info); | |
372 } | |
373 | |
374 if (purple_prefs_get_bool(OPT_PROCESS_ALIAS)) { | |
375 aud_process_alias(gc, aud_info); | |
376 } | |
377 | |
378 } | |
379 } | |
380 static void | |
381 removekey(gpointer data) | |
382 { | |
383 g_free(data); | |
384 } | |
385 | |
386 static void | |
387 removeval(gpointer data) | |
388 { | |
389 g_free(data); | |
390 } | |
391 | |
392 static gboolean | |
393 restore_alias(PurpleConnection *gc, gpointer data) | |
394 { | |
395 PurpleAccount *account; | |
396 gpointer val = NULL; | |
397 gchar *key = NULL; | |
398 | |
399 aud_debug("********** restore_alias called **********\n"); | |
400 account = purple_connection_get_account(gc); | |
401 | |
402 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
|
403 val = g_hash_table_lookup(seed_alias, key); |
0 | 404 g_return_val_if_fail(val != NULL, FALSE); |
405 | |
406 aud_debug("write back alias %s\n", val); | |
407 purple_account_set_alias(account, val); //oct16 | |
408 | |
409 g_free(key); | |
410 | |
411 return TRUE; | |
412 } | |
413 | |
414 | |
415 static gboolean | |
416 load_plugin(PurplePlugin *plugin) | |
417 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
418 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
|
419 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
|
420 seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); |
0 | 421 |
422 pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
423 pushed_alias = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
424 pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
425 | |
426 timeout_tag = g_timeout_add(15*1000, (gpointer)watchdog_func, NULL); | |
427 | |
428 /* connect to signing-off signal */ | |
429 purple_signal_connect(purple_connections_get_handle(), "signing-off", plugin, | |
430 PURPLE_CALLBACK(restore_alias), NULL); | |
431 | |
432 | |
433 return TRUE; | |
434 } | |
435 | |
436 static gboolean | |
437 unload_plugin(PurplePlugin *plugin) | |
438 { | |
439 aud_debug("pidgin-audacious unload called\n"); | |
440 | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
441 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
|
442 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
|
443 g_hash_table_destroy(seed_userinfo); |
0 | 444 |
445 g_hash_table_destroy(pushed_status); | |
446 g_hash_table_destroy(pushed_alias); | |
447 g_hash_table_destroy(pushed_userinfo); | |
448 | |
449 return TRUE; | |
450 } | |
451 | |
452 static PurplePluginPrefFrame * | |
453 get_plugin_pref_frame(PurplePlugin *plugin) | |
454 { | |
455 PurplePluginPref *pref; | |
456 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new(); | |
457 | |
458 /* create gtk elements for the plugin preferences */ | |
459 pref = purple_plugin_pref_new_with_label("Pidgin-Audacious Configuration"); | |
460 purple_plugin_pref_frame_add(frame, pref); | |
461 | |
462 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_STATUS, | |
463 "Expand " SONG_TOKEN " to song info in the status message"); | |
464 purple_plugin_pref_frame_add(frame, pref); | |
465 | |
466 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_USERINFO, | |
467 "Expand " SONG_TOKEN " to song info in the user info"); | |
468 purple_plugin_pref_frame_add(frame, pref); | |
469 | |
470 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_ALIAS, | |
471 "Expand " SONG_TOKEN " to song info in the alias"); | |
472 purple_plugin_pref_frame_add(frame, pref); | |
473 | |
474 return frame; | |
475 } | |
476 | |
477 static PurplePluginUiInfo pref_info = | |
478 { | |
479 get_plugin_pref_frame | |
480 }; | |
481 | |
482 static PurplePluginInfo info = | |
483 { | |
484 PURPLE_PLUGIN_MAGIC, | |
485 PURPLE_MAJOR_VERSION, | |
486 PURPLE_MINOR_VERSION, | |
487 PURPLE_PLUGIN_STANDARD, /**< type */ | |
488 NULL, /**< ui_req */ | |
489 0, /**< flags */ | |
490 NULL, /**< deps */ | |
491 PURPLE_PRIORITY_DEFAULT, /**< priority */ | |
492 PIDGINAUD_PLUGIN_ID, /**< id */ | |
493 "Pidgin-Audacious", /**< name */ | |
494 "2.0.0d4", /**< version */ | |
495 "Automatically updates your Pidgin status info with the currently " | |
496 "playing music in Audacious.", /** summary */ | |
497 "Automatically updates your Pidgin status info with the currently " | |
498 "playing music in Audacious.", /** desc */ | |
499 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ | |
500 "http://www.honeyplanet.jp", /**< homepage */ | |
501 load_plugin, /**< load */ | |
502 unload_plugin, /**< unload */ | |
503 NULL, /**< destroy */ | |
504 NULL, /**< ui_info */ | |
505 NULL, /**< extra_info */ | |
506 &pref_info, /**< pref info */ | |
507 NULL | |
508 }; | |
509 | |
510 static void | |
511 init_plugin(PurplePlugin *plugin) | |
512 { | |
513 g_type_init(); | |
514 | |
515 /* add plugin preferences */ | |
516 purple_prefs_add_none(OPT_PIDGINAUD); | |
517 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); | |
518 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); | |
519 purple_prefs_add_bool(OPT_PROCESS_ALIAS, TRUE); | |
520 | |
521 session = get_dbus_proxy(); | |
522 } | |
523 | |
524 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) |