changeset 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
files pidgin-twitter.c
diffstat 1 files changed, 29 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-twitter.c	Wed Apr 30 17:06:58 2008 +0900
+++ b/pidgin-twitter.c	Wed Apr 30 18:49:49 2008 +0900
@@ -39,6 +39,7 @@
 #define OPT_PLAYSOUND	OPT_PIDGINTWITTER "/playsound"
 #define OPT_USERLIST	OPT_PIDGINTWITTER "/userlist"
 #define TWITTER_FORMAT  "@<a href='http://twitter.com/%s'>%s</a>"
+#define DEFAULT_LIST    "(list of users: separated with ' ,:;')"
 
 #define twitter_debug(fmt, ...)	purple_debug(PURPLE_DEBUG_INFO, PIDGINTWITTER_PLUGIN_ID, \
                                              fmt, ## __VA_ARGS__);
@@ -87,28 +88,38 @@
 static void playsound(gchar **str)
 {
     GMatchInfo *match_info;
-    GList *list, *lp;
+    const gchar *list;
+    gchar **candidates = NULL, **candidate = NULL;
 
-    list = purple_prefs_get_string_list(OPT_USERLIST);
+    list = purple_prefs_get_string(OPT_USERLIST);
     g_return_if_fail(list != NULL);
+    if(!strcmp(list, DEFAULT_LIST))
+        return;
+
+    candidates = g_strsplit_set(list, " ,:;", 0);
+    if(!candidates)
+        return;
 
     g_regex_match(preg, *str, 0, &match_info);
     while(g_match_info_matches(match_info)) {
         gchar *user = g_match_info_fetch(match_info, 0);
         twitter_debug("user = %s\n", user);
 
-        for(lp = list; lp; lp = g_list_next(lp)) {
-            twitter_debug("lp->data = %s\n", (char *)lp->data);
-            if(!strcmp(user, lp->data) || !strcmp(user + 1, lp->data)) {
+        for(candidate = candidates; *candidate ; candidate++) {
+            if(!strcmp(*candidate, ""))
+                continue;
+            twitter_debug("candidate = %s\n", *candidate);
+            if(!strcmp(user, *candidate) ||
+               !strcmp(user + 1, *candidate)) {
                 twitter_debug("match. play sound\n");
                 purple_sound_play_event(PURPLE_SOUND_POUNCE_DEFAULT, NULL);
+                break;
             }
         }
-
         g_free(user);
         g_match_info_next(match_info, NULL);
     }
-
+    g_strfreev(candidates);
     g_match_info_free(match_info);
 }
 
@@ -164,15 +175,20 @@
     pref = purple_plugin_pref_new_with_label("Pidgin-Twitter Configuration");
     purple_plugin_pref_frame_add(frame, pref);
 
-    pref = purple_plugin_pref_new_with_name_and_label(OPT_TRANSLATE,
-                                                      "Translate @username to the link to the user");
+    pref = purple_plugin_pref_new_with_name_and_label(
+        OPT_TRANSLATE,
+        "Translate @username to the link to the user");
     purple_plugin_pref_frame_add(frame, pref);
 
-    pref = purple_plugin_pref_new_with_name_and_label(OPT_PLAYSOUND,
-                                                      "Play sound if a reply to listed users arrives");
+    pref = purple_plugin_pref_new_with_name_and_label(
+        OPT_PLAYSOUND,
+        "Play a sound on a reply to the user in the Userlist");
     purple_plugin_pref_frame_add(frame, pref);
 
-    // xxx add pref field for OPT_USERLIST (gtk packing is needed) --yaz
+    pref = purple_plugin_pref_new_with_name_and_label(
+        OPT_USERLIST,
+        "Userlist");
+    purple_plugin_pref_frame_add(frame, pref);
 
     return frame;
 }
@@ -214,7 +230,7 @@
     purple_prefs_add_none(OPT_PIDGINTWITTER);
     purple_prefs_add_bool(OPT_TRANSLATE, TRUE);
     purple_prefs_add_bool(OPT_PLAYSOUND, TRUE);
-    purple_prefs_add_string_list(OPT_USERLIST, NULL);
+    purple_prefs_add_string(OPT_USERLIST, DEFAULT_LIST);
 
     /* compile regex */
     preg = g_regex_new("@[A-Za-z0-9_]+", 0, 0, NULL);