Mercurial > pidgin-audacious
annotate pidgin-audacious.c @ 12:79f081cdfb19
- fixed potential memory leaks.
- fixed indentation.
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sat, 27 Sep 2008 00:50:45 +0900 |
parents | 43cb653de212 |
children | 44568f7ef51d |
rev | line source |
---|---|
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
1 /* -*- indent-tabs-mode:t; tab-width:8; -*- |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
2 * |
0 | 3 * Pidgin-Audacious plugin. |
4 * | |
5 * This program is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU General Public License as | |
7 * published by the Free Software Foundation; either version 2 of the | |
8 * License, or (at your option) any later version. | |
9 * | |
10 * This program is distributed in the hope that it will be useful, but | |
11 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU General Public License | |
16 * along with this program; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
18 * 02111-1307, USA. | |
19 */ | |
20 #define PURPLE_PLUGINS 1 | |
21 | |
22 #include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
25 #include <glib.h> | |
26 | |
27 #include "gtkplugin.h" | |
28 #include "util.h" | |
29 #include "debug.h" | |
30 #include "connection.h" | |
31 #include "version.h" | |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
32 #include "cmds.h" |
0 | 33 #include <audacious/audctrl.h> |
34 #include <audacious/dbus.h> | |
35 | |
7
feb13e877029
follow the change of botch_utf()
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3
diff
changeset
|
36 extern gchar *botch_utf(const gchar *msg, gsize len, gsize *newlen) __attribute__ ((weak)); |
0 | 37 |
38 #define PIDGINAUD_PLUGIN_ID "pidgin_audacious" | |
39 | |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
40 #define OPT_PIDGINAUD "/plugins/pidgin_audacious" |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
41 #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
|
42 #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
|
43 #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
|
44 #define OPT_PASTE_TEMPLATE OPT_PIDGINAUD "/paste_template" |
0 | 45 |
46 #define SONG_TOKEN "%song" | |
47 #define NO_SONG_MESSAGE "No song being played." | |
48 | |
49 #define BUDDY_ALIAS_MAXLEN 387 | |
50 | |
51 #define aud_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, "Pidgin-Audacious", \ | |
52 fmt, ## __VA_ARGS__); | |
53 #define aud_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, "Pidgin-Audacious", \ | |
54 fmt, ## __VA_ARGS__); | |
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 { | |
92 gint playpos = 0; | |
93 gchar *song = NULL, *tmp = NULL; | |
94 | |
95 gboolean rv = TRUE; | |
96 size_t dummy; | |
97 | |
98 aud_debug("session = %p\n", session); | |
99 | |
100 aud_debug("is_playing = %d\n", audacious_remote_is_playing(session)); | |
101 | |
102 if(!audacious_remote_is_playing(session)) { /* audacious isn't playing */ | |
103 aud_process(NULL); | |
104 return rv; | |
105 } | |
106 | |
107 playpos = audacious_remote_get_playlist_pos(session); | |
108 tmp = audacious_remote_get_playlist_title(session, playpos); | |
109 if(tmp) { | |
110 if(botch_utf) // function exists | |
111 song = (gchar *) botch_utf(tmp, strlen(tmp), &dummy); | |
112 else | |
113 song = g_strdup(tmp); | |
114 } | |
115 g_free(tmp); | |
116 tmp = NULL; | |
117 | |
118 aud_process(song); | |
119 g_free(song); | |
120 song = NULL; | |
121 return rv; | |
122 } | |
123 | |
124 static void | |
125 aud_process_status(PurpleConnection *gc, gchar *aud_info) | |
126 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
127 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
|
128 const gchar *current, *seed, *pushed, *proto; |
0 | 129 PurpleAccount *account; |
130 PurplePresence *presence; | |
131 PurplePlugin *prpl; | |
132 PurplePluginProtocolInfo *prpl_info; | |
133 PurpleStatus *status; | |
134 | |
135 account = purple_connection_get_account(gc); | |
136 presence = purple_account_get_presence(account); | |
137 | |
138 proto = purple_account_get_protocol_id(account); | |
139 prpl = purple_find_prpl(proto); | |
140 g_return_if_fail(prpl != NULL); | |
141 | |
142 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
143 g_return_if_fail(prpl_info != NULL && prpl_info->set_status != NULL); | |
144 | |
145 status = purple_presence_get_active_status(presence); | |
146 g_return_if_fail(status != NULL); | |
147 | |
148 /* generate key for hash table */ | |
149 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
150 | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
151 /* retrieve current user status */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
152 current = purple_status_get_attr_string(status, "message"); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
153 aud_debug("status current = %s\n", current); |
0 | 154 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
155 /* 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
|
156 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
|
157 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup("")); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
158 g_free(key); |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
159 return; |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
160 } |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
161 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
162 /* pop pushed_status */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
163 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
|
164 |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
165 /* 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
|
166 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
|
167 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
|
168 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(current)); |
0 | 169 } |
170 | |
171 /* 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
|
172 seed = (gchar *)g_hash_table_lookup(seed_status, key); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
173 if(!seed) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
174 g_free(key); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
175 return; |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
176 } |
1
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 |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
179 if(strstr(seed, SONG_TOKEN)) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
180 if(aud_info){ |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
181 new = purple_strreplace(seed, SONG_TOKEN, aud_info); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
182 } |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
183 else { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
184 new = g_strdup(NO_SONG_MESSAGE); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
185 } |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
186 } |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
187 |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
188 if(!new) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
189 g_free(key); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
190 return; |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
191 } |
0 | 192 |
193 /* 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
|
194 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
|
195 aud_debug("status pushed = %s\n", pushed); |
0 | 196 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
197 if (!pushed || g_ascii_strcasecmp(pushed, new)) { |
0 | 198 g_hash_table_replace(pushed_status, g_strdup(key), g_strdup(new)); |
199 purple_status_set_attr_string(status, "message", new); | |
200 prpl_info->set_status(account, status); | |
201 } | |
202 g_free(key); | |
203 g_free(new); | |
204 } | |
205 | |
206 | |
207 static void | |
208 aud_process_userinfo(PurpleConnection *gc, gchar *aud_info) | |
209 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
210 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
|
211 const gchar *current, *seed, *pushed, *proto; |
0 | 212 PurpleAccount *account; |
213 PurplePlugin *prpl; | |
214 PurplePluginProtocolInfo *prpl_info; | |
215 | |
216 account = purple_connection_get_account(gc); | |
217 | |
218 proto = purple_account_get_protocol_id(account); | |
219 prpl = purple_find_prpl(proto); | |
220 g_return_if_fail(prpl != NULL); | |
221 | |
222 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
223 g_return_if_fail(prpl_info != NULL && prpl_info->set_info != NULL); | |
224 | |
225 /* generate key for hash table*/ | |
226 key = g_strdup_printf("%s %s", account->username, account->protocol_id); | |
227 | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
228 /* retrieve current user info */ |
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
229 current = purple_account_get_user_info(account); /* it's always from account.xml! */ |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
230 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
|
231 |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
232 /* invalidate pushded status on auto away etc. */ |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
233 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
|
234 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup("")); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
235 g_free(key); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
236 return; |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
237 } |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
238 |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
239 /* pop pushed_userinfo */ |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
240 pushed = g_hash_table_lookup(pushed_userinfo, key); |
0 | 241 |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
242 /* if current alias differs from pushed_alias or contains token, replace seed with this. */ |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
243 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
244 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
|
245 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(current)); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
246 } |
0 | 247 |
248 /* 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
|
249 seed = (gchar *)g_hash_table_lookup(seed_userinfo, key); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
250 if(!seed) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
251 g_free(key); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
252 return; |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
253 } |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
254 aud_debug("userinfo seed = %s\n", seed); |
0 | 255 |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
256 if(strstr(seed, SONG_TOKEN)) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
257 if(aud_info){ |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
258 new = purple_strreplace(seed, SONG_TOKEN, aud_info); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
259 } |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
260 else { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
261 new = g_strdup(NO_SONG_MESSAGE); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
262 } |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
263 } |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
264 |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
265 if(!new) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
266 g_free(key); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
267 return; |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
268 } |
0 | 269 |
270 /* 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
|
271 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
|
272 aud_debug("userinfo pushed = %s\n", pushed); |
0 | 273 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
274 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
0 | 275 g_hash_table_replace(pushed_userinfo, g_strdup(key), g_strdup(new)); |
276 prpl_info->set_info(gc, new); | |
277 } | |
278 g_free(key); | |
279 g_free(new); | |
280 } | |
281 | |
282 static void | |
283 aud_process_alias(PurpleConnection *gc, gchar *aud_info) | |
284 { | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
285 gchar *new = NULL, *key = NULL; |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
286 const gchar *current, *seed, *pushed, *proto; |
0 | 287 PurpleAccount *account; |
288 PurplePlugin *prpl; | |
289 PurplePluginProtocolInfo *prpl_info; | |
290 | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
291 glong bytes; |
0 | 292 |
293 account = purple_connection_get_account(gc); | |
294 | |
295 proto = purple_account_get_protocol_id(account); | |
296 prpl = purple_find_prpl(proto); | |
297 g_return_if_fail(prpl != NULL); | |
298 | |
299 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl); | |
300 g_return_if_fail(prpl_info != NULL); | |
301 | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
302 /* generate key for hash table*/ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
303 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
|
304 |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
305 /* retrieve current alias */ |
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
306 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
|
307 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
|
308 aud_error("couldn't get current alias\n"); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
309 g_free(key); |
0 | 310 return; |
311 } | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
312 aud_debug("current alias = %s\n", current); |
0 | 313 |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
314 /* pop pushed_alias */ |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
315 pushed = g_hash_table_lookup(pushed_alias, key); |
0 | 316 |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
317 /* if current alias differs from pushed_alias or contains token, replace seed with current. */ |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
318 if( (pushed && g_ascii_strcasecmp(current, pushed)) || strstr(current, SONG_TOKEN) ) { |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
319 g_hash_table_replace(seed_alias, g_strdup(key), g_strdup(current)); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
320 } |
0 | 321 |
322 /* construct new status message */ | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
323 seed = g_hash_table_lookup(seed_alias, key); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
324 if(!seed) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
325 g_free(key); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
326 return; |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
327 } |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
328 aud_debug("alias: seed = %s\n", (gchar *)seed); |
0 | 329 |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
330 bytes = strlen(seed); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
331 bytes -= strlen(SONG_TOKEN); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
332 aud_debug("alias: bytes = %ld", bytes); |
0 | 333 |
334 if(aud_info){ | |
335 gchar *tmp = g_malloc0(BUDDY_ALIAS_MAXLEN); | |
336 glong utflen = g_utf8_strlen(aud_info, BUDDY_ALIAS_MAXLEN/3 - bytes - 1); | |
337 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
|
338 new = purple_strreplace(seed, SONG_TOKEN, tmp); |
0 | 339 g_free(tmp); |
340 } | |
341 else { | |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
342 new = purple_strreplace(seed, SONG_TOKEN, NO_SONG_MESSAGE); |
0 | 343 } |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
344 if(!new) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
345 g_free(key); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
346 return; |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
347 } |
0 | 348 |
349 /* 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
|
350 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
|
351 aud_debug("alias pushed = %s\n", (gchar *)pushed); |
0 | 352 |
2
f1dc959e4706
modify process_alias to follow recent changes.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
1
diff
changeset
|
353 if (!pushed || g_ascii_strcasecmp(pushed, new) != 0) { |
0 | 354 gboolean ok = FALSE; |
355 PurplePlugin *msn_plugin = NULL; | |
356 msn_plugin = purple_plugins_find_with_id("prpl-msn"); | |
357 aud_debug("msn_plugin = %p\n", msn_plugin); | |
358 | |
359 g_hash_table_replace(pushed_alias, g_strdup(key), g_strdup(new)); | |
360 purple_plugin_ipc_call(msn_plugin, "msn_set_friendly_name", &ok, gc, new); | |
361 aud_debug("ipc %d\n", ok); | |
362 } | |
363 g_free(key); | |
364 g_free(new); | |
365 } | |
366 | |
367 static void | |
368 aud_process(gchar *aud_info) | |
369 { | |
370 GList *l; | |
371 PurpleConnection *gc; | |
372 | |
373 for (l = purple_connections_get_all(); l != NULL; l = l->next) { | |
374 gc = (PurpleConnection *) l->data; | |
375 | |
376 /* make sure we're connected */ | |
377 if (purple_connection_get_state(gc) != PURPLE_CONNECTED) { | |
378 continue; | |
379 } | |
380 | |
381 if (purple_prefs_get_bool(OPT_PROCESS_USERINFO)) { | |
382 aud_process_userinfo(gc, aud_info); | |
383 } | |
384 | |
385 if (purple_prefs_get_bool(OPT_PROCESS_STATUS)) { | |
386 aud_process_status(gc, aud_info); | |
387 } | |
388 | |
389 if (purple_prefs_get_bool(OPT_PROCESS_ALIAS)) { | |
390 aud_process_alias(gc, aud_info); | |
391 } | |
392 | |
393 } | |
394 } | |
395 static void | |
396 removekey(gpointer data) | |
397 { | |
398 g_free(data); | |
399 } | |
400 | |
401 static void | |
402 removeval(gpointer data) | |
403 { | |
404 g_free(data); | |
405 } | |
406 | |
407 static gboolean | |
408 restore_alias(PurpleConnection *gc, gpointer data) | |
409 { | |
410 PurpleAccount *account; | |
411 gpointer val = NULL; | |
412 gchar *key = NULL; | |
413 | |
414 aud_debug("********** restore_alias called **********\n"); | |
415 account = purple_connection_get_account(gc); | |
416 | |
417 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
|
418 val = g_hash_table_lookup(seed_alias, key); |
12
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
419 if(!val) { |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
420 g_free(key); |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
421 return FALSE; |
79f081cdfb19
- fixed potential memory leaks.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
11
diff
changeset
|
422 } |
0 | 423 |
9
d5702f04b19c
Fixed a bug that disabling this plugin while watch dog function has been hooked causes crash.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
8
diff
changeset
|
424 aud_debug("write back alias %s\n", (char *)val); |
0 | 425 purple_account_set_alias(account, val); //oct16 |
426 | |
427 g_free(key); | |
428 | |
429 return TRUE; | |
430 } | |
431 | |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
432 static PurpleCmdRet |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
433 paste_current_song(PurpleConversation *conv, const gchar *cmd, gchar **args, gchar **error, void *data) |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
434 { |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
435 gint playpos = 0; |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
436 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
|
437 PurpleConversationType type = purple_conversation_get_type(conv); |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
438 size_t dummy; |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
439 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
|
440 |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
441 /* audacious isn't playing */ |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
442 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
|
443 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
|
444 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
445 |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
446 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
|
447 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
|
448 |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
449 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
|
450 |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
451 if(template && strstr(template, SONG_TOKEN)) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
452 tmp2 = purple_strreplace(template, SONG_TOKEN, tmp); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
453 g_free(tmp); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
454 tmp = NULL; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
455 } |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
456 else { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
457 tmp2 = tmp; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
458 } |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
459 |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
460 if(tmp2) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
461 if(botch_utf) { |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
462 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
|
463 g_free(tmp2); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
464 tmp2 = NULL; |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
465 } |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
466 else |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
467 song = tmp2; |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
468 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
469 |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
470 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
|
471 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
|
472 if (chat && song) |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
473 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
|
474 } |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
475 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
|
476 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
|
477 if(im && song) |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
478 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
|
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 g_free(song); |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
482 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
|
483 } |
0 | 484 |
485 static gboolean | |
486 load_plugin(PurplePlugin *plugin) | |
487 { | |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
488 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
|
489 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
|
490 seed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); |
0 | 491 |
492 pushed_status = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
493 pushed_alias = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
494 pushed_userinfo = g_hash_table_new_full(g_str_hash, g_str_equal, removekey, removeval); | |
495 | |
496 timeout_tag = g_timeout_add(15*1000, (gpointer)watchdog_func, NULL); | |
497 | |
498 /* connect to signing-off signal */ | |
499 purple_signal_connect(purple_connections_get_handle(), "signing-off", plugin, | |
500 PURPLE_CALLBACK(restore_alias), NULL); | |
501 | |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
502 cmdid_paste_current_song = |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
503 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
|
504 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
|
505 NULL, paste_current_song, |
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
506 "song: Paste currently plaing song", NULL); |
0 | 507 |
508 return TRUE; | |
509 } | |
510 | |
511 static gboolean | |
512 unload_plugin(PurplePlugin *plugin) | |
513 { | |
514 aud_debug("pidgin-audacious unload called\n"); | |
515 | |
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
|
516 g_source_remove(timeout_tag); |
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
|
517 |
1
46071692f191
implement new replace logic to status and userinfo.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
0
diff
changeset
|
518 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
|
519 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
|
520 g_hash_table_destroy(seed_userinfo); |
0 | 521 |
522 g_hash_table_destroy(pushed_status); | |
523 g_hash_table_destroy(pushed_alias); | |
524 g_hash_table_destroy(pushed_userinfo); | |
525 | |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
526 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
|
527 |
0 | 528 return TRUE; |
529 } | |
530 | |
531 static PurplePluginPrefFrame * | |
532 get_plugin_pref_frame(PurplePlugin *plugin) | |
533 { | |
534 PurplePluginPref *pref; | |
535 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new(); | |
536 | |
537 /* create gtk elements for the plugin preferences */ | |
538 pref = purple_plugin_pref_new_with_label("Pidgin-Audacious Configuration"); | |
539 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
|
540 |
0 | 541 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_STATUS, |
542 "Expand " SONG_TOKEN " to song info in the status message"); | |
543 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
|
544 |
0 | 545 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_USERINFO, |
546 "Expand " SONG_TOKEN " to song info in the user info"); | |
547 purple_plugin_pref_frame_add(frame, pref); | |
548 | |
549 pref = purple_plugin_pref_new_with_name_and_label(OPT_PROCESS_ALIAS, | |
550 "Expand " SONG_TOKEN " to song info in the alias"); | |
551 purple_plugin_pref_frame_add(frame, pref); | |
552 | |
11
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
553 /* paste template */ |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
554 pref = purple_plugin_pref_new_with_name_and_label(OPT_PASTE_TEMPLATE, |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
555 "Paste template"); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
556 purple_plugin_pref_frame_add(frame, pref); |
43cb653de212
paste template has been implemented.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
10
diff
changeset
|
557 |
0 | 558 return frame; |
559 } | |
560 | |
561 static PurplePluginUiInfo pref_info = | |
562 { | |
563 get_plugin_pref_frame | |
564 }; | |
565 | |
566 static PurplePluginInfo info = | |
567 { | |
568 PURPLE_PLUGIN_MAGIC, | |
569 PURPLE_MAJOR_VERSION, | |
570 PURPLE_MINOR_VERSION, | |
571 PURPLE_PLUGIN_STANDARD, /**< type */ | |
572 NULL, /**< ui_req */ | |
573 0, /**< flags */ | |
574 NULL, /**< deps */ | |
575 PURPLE_PRIORITY_DEFAULT, /**< priority */ | |
576 PIDGINAUD_PLUGIN_ID, /**< id */ | |
577 "Pidgin-Audacious", /**< name */ | |
10
7c9624c8a109
added /song command which sends name of currently playing song.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
9
diff
changeset
|
578 "2.1.0d1", /**< version */ |
0 | 579 "Automatically updates your Pidgin status info with the currently " |
580 "playing music in Audacious.", /** summary */ | |
581 "Automatically updates your Pidgin status info with the currently " | |
582 "playing music in Audacious.", /** desc */ | |
583 "Yoshiki Yazawa (yaz@honeyplanet.jp)", /**< author */ | |
584 "http://www.honeyplanet.jp", /**< homepage */ | |
585 load_plugin, /**< load */ | |
586 unload_plugin, /**< unload */ | |
587 NULL, /**< destroy */ | |
588 NULL, /**< ui_info */ | |
589 NULL, /**< extra_info */ | |
590 &pref_info, /**< pref info */ | |
591 NULL | |
592 }; | |
593 | |
594 static void | |
595 init_plugin(PurplePlugin *plugin) | |
596 { | |
597 g_type_init(); | |
598 | |
599 /* add plugin preferences */ | |
600 purple_prefs_add_none(OPT_PIDGINAUD); | |
601 purple_prefs_add_bool(OPT_PROCESS_STATUS, TRUE); | |
602 purple_prefs_add_bool(OPT_PROCESS_USERINFO, TRUE); | |
603 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
|
604 purple_prefs_add_string(OPT_PASTE_TEMPLATE, SONG_TOKEN); |
0 | 605 |
606 session = get_dbus_proxy(); | |
607 } | |
608 | |
609 PURPLE_INIT_PLUGIN(pidgin_audacious, init_plugin, info) |