comparison pidgin-twitter.c @ 7:44a66c52b190

- userlist no longer uses string list. now ' ,:;' separated string is used instead. - minor fixes.
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Wed, 30 Apr 2008 18:49:49 +0900
parents ca8f95431962
children 2c7c9eb4cdda
comparison
equal deleted inserted replaced
6:ca8f95431962 7:44a66c52b190
37 #define OPT_PIDGINTWITTER "/plugins/pidgin_twitter" 37 #define OPT_PIDGINTWITTER "/plugins/pidgin_twitter"
38 #define OPT_TRANSLATE OPT_PIDGINTWITTER "/translate" 38 #define OPT_TRANSLATE OPT_PIDGINTWITTER "/translate"
39 #define OPT_PLAYSOUND OPT_PIDGINTWITTER "/playsound" 39 #define OPT_PLAYSOUND OPT_PIDGINTWITTER "/playsound"
40 #define OPT_USERLIST OPT_PIDGINTWITTER "/userlist" 40 #define OPT_USERLIST OPT_PIDGINTWITTER "/userlist"
41 #define TWITTER_FORMAT "@<a href='http://twitter.com/%s'>%s</a>" 41 #define TWITTER_FORMAT "@<a href='http://twitter.com/%s'>%s</a>"
42 #define DEFAULT_LIST "(list of users: separated with ' ,:;')"
42 43
43 #define twitter_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, PIDGINTWITTER_PLUGIN_ID, \ 44 #define twitter_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, PIDGINTWITTER_PLUGIN_ID, \
44 fmt, ## __VA_ARGS__); 45 fmt, ## __VA_ARGS__);
45 #define twitter_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, PIDGINTWITTER_PLUGIN_ID, \ 46 #define twitter_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, PIDGINTWITTER_PLUGIN_ID, \
46 fmt, ## __VA_ARGS__); 47 fmt, ## __VA_ARGS__);
85 } 86 }
86 87
87 static void playsound(gchar **str) 88 static void playsound(gchar **str)
88 { 89 {
89 GMatchInfo *match_info; 90 GMatchInfo *match_info;
90 GList *list, *lp; 91 const gchar *list;
91 92 gchar **candidates = NULL, **candidate = NULL;
92 list = purple_prefs_get_string_list(OPT_USERLIST); 93
94 list = purple_prefs_get_string(OPT_USERLIST);
93 g_return_if_fail(list != NULL); 95 g_return_if_fail(list != NULL);
96 if(!strcmp(list, DEFAULT_LIST))
97 return;
98
99 candidates = g_strsplit_set(list, " ,:;", 0);
100 if(!candidates)
101 return;
94 102
95 g_regex_match(preg, *str, 0, &match_info); 103 g_regex_match(preg, *str, 0, &match_info);
96 while(g_match_info_matches(match_info)) { 104 while(g_match_info_matches(match_info)) {
97 gchar *user = g_match_info_fetch(match_info, 0); 105 gchar *user = g_match_info_fetch(match_info, 0);
98 twitter_debug("user = %s\n", user); 106 twitter_debug("user = %s\n", user);
99 107
100 for(lp = list; lp; lp = g_list_next(lp)) { 108 for(candidate = candidates; *candidate ; candidate++) {
101 twitter_debug("lp->data = %s\n", (char *)lp->data); 109 if(!strcmp(*candidate, ""))
102 if(!strcmp(user, lp->data) || !strcmp(user + 1, lp->data)) { 110 continue;
111 twitter_debug("candidate = %s\n", *candidate);
112 if(!strcmp(user, *candidate) ||
113 !strcmp(user + 1, *candidate)) {
103 twitter_debug("match. play sound\n"); 114 twitter_debug("match. play sound\n");
104 purple_sound_play_event(PURPLE_SOUND_POUNCE_DEFAULT, NULL); 115 purple_sound_play_event(PURPLE_SOUND_POUNCE_DEFAULT, NULL);
116 break;
105 } 117 }
106 } 118 }
107
108 g_free(user); 119 g_free(user);
109 g_match_info_next(match_info, NULL); 120 g_match_info_next(match_info, NULL);
110 } 121 }
111 122 g_strfreev(candidates);
112 g_match_info_free(match_info); 123 g_match_info_free(match_info);
113 } 124 }
114 125
115 126
116 static gboolean 127 static gboolean
162 173
163 /* create gtk elements for the plugin preferences */ 174 /* create gtk elements for the plugin preferences */
164 pref = purple_plugin_pref_new_with_label("Pidgin-Twitter Configuration"); 175 pref = purple_plugin_pref_new_with_label("Pidgin-Twitter Configuration");
165 purple_plugin_pref_frame_add(frame, pref); 176 purple_plugin_pref_frame_add(frame, pref);
166 177
167 pref = purple_plugin_pref_new_with_name_and_label(OPT_TRANSLATE, 178 pref = purple_plugin_pref_new_with_name_and_label(
168 "Translate @username to the link to the user"); 179 OPT_TRANSLATE,
169 purple_plugin_pref_frame_add(frame, pref); 180 "Translate @username to the link to the user");
170 181 purple_plugin_pref_frame_add(frame, pref);
171 pref = purple_plugin_pref_new_with_name_and_label(OPT_PLAYSOUND, 182
172 "Play sound if a reply to listed users arrives"); 183 pref = purple_plugin_pref_new_with_name_and_label(
173 purple_plugin_pref_frame_add(frame, pref); 184 OPT_PLAYSOUND,
174 185 "Play a sound on a reply to the user in the Userlist");
175 // xxx add pref field for OPT_USERLIST (gtk packing is needed) --yaz 186 purple_plugin_pref_frame_add(frame, pref);
187
188 pref = purple_plugin_pref_new_with_name_and_label(
189 OPT_USERLIST,
190 "Userlist");
191 purple_plugin_pref_frame_add(frame, pref);
176 192
177 return frame; 193 return frame;
178 } 194 }
179 195
180 static PurplePluginUiInfo pref_info = { 196 static PurplePluginUiInfo pref_info = {
212 228
213 /* add plugin preferences */ 229 /* add plugin preferences */
214 purple_prefs_add_none(OPT_PIDGINTWITTER); 230 purple_prefs_add_none(OPT_PIDGINTWITTER);
215 purple_prefs_add_bool(OPT_TRANSLATE, TRUE); 231 purple_prefs_add_bool(OPT_TRANSLATE, TRUE);
216 purple_prefs_add_bool(OPT_PLAYSOUND, TRUE); 232 purple_prefs_add_bool(OPT_PLAYSOUND, TRUE);
217 purple_prefs_add_string_list(OPT_USERLIST, NULL); 233 purple_prefs_add_string(OPT_USERLIST, DEFAULT_LIST);
218 234
219 /* compile regex */ 235 /* compile regex */
220 preg = g_regex_new("@[A-Za-z0-9_]+", 0, 0, NULL); 236 preg = g_regex_new("@[A-Za-z0-9_]+", 0, 0, NULL);
221 } 237 }
222 238