Mercurial > pidgin-twitter
comparison pidgin-twitter.c @ 34:44ffbd056f33
added patch to strip excessive hyper link on @username when it copied and pasted from message window. patch by mikanbako (maoutwo@gmail.com).
author | Yoshiki Yazawa <yaz@cc.rim.or.jp> |
---|---|
date | Sat, 10 May 2008 20:18:20 +0900 |
parents | 92715b489de6 |
children | 7d07fcb9c616 |
comparison
equal
deleted
inserted
replaced
33:abe31282e2de | 34:44ffbd056f33 |
---|---|
33 | 33 |
34 #define RECIPIENT 0 | 34 #define RECIPIENT 0 |
35 #define SENDER 1 | 35 #define SENDER 1 |
36 #define COMMAND 2 | 36 #define COMMAND 2 |
37 #define PSEUDO 3 | 37 #define PSEUDO 3 |
38 #define SENDER_WITH_LINK 4 | |
38 | 39 |
39 #define PLUGIN_ID "gtk-honeyplanet-pidgin_twitter" | 40 #define PLUGIN_ID "gtk-honeyplanet-pidgin_twitter" |
40 #define PLUGIN_NAME "pidgin-twitter" | 41 #define PLUGIN_NAME "pidgin-twitter" |
41 | 42 |
42 #define OPT_PIDGINTWITTER "/plugins/pidgin_twitter" | 43 #define OPT_PIDGINTWITTER "/plugins/pidgin_twitter" |
59 #define twitter_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, \ | 60 #define twitter_debug(fmt, ...) purple_debug(PURPLE_DEBUG_INFO, PLUGIN_NAME, \ |
60 fmt, ## __VA_ARGS__); | 61 fmt, ## __VA_ARGS__); |
61 #define twitter_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, \ | 62 #define twitter_error(fmt, ...) purple_debug(PURPLE_DEBUG_ERROR, PLUGIN_NAME, \ |
62 | 63 |
63 /* globals */ | 64 /* globals */ |
64 static GRegex *regp[4]; | 65 static GRegex *regp[5]; |
66 | |
67 static void | |
68 delete_sender_with_link(gchar **str) | |
69 { | |
70 gchar *newstr = NULL; | |
71 | |
72 /* replace senders with link */ | |
73 newstr = g_regex_replace(regp[SENDER_WITH_LINK], *str, -1, 0, "@\\1", 0, NULL); | |
74 twitter_debug("*str = %s\n", *str); | |
75 twitter_debug("rnewstr = %s\n", newstr); | |
76 | |
77 g_free(*str); | |
78 *str = newstr; | |
79 } | |
65 | 80 |
66 /* prototypes */ | 81 /* prototypes */ |
67 static gboolean is_twitter_conv(PurpleConversation *conv); | 82 static gboolean is_twitter_conv(PurpleConversation *conv); |
68 static void attach_to_gtkconv(PidginConversation *gtkconv, gpointer null); | 83 static void attach_to_gtkconv(PidginConversation *gtkconv, gpointer null); |
69 static void detach_from_gtkconv(PidginConversation *gtkconv, gpointer null); | 84 static void detach_from_gtkconv(PidginConversation *gtkconv, gpointer null); |
132 !strcmp(recipient, "twitter@twitter.com")) { | 147 !strcmp(recipient, "twitter@twitter.com")) { |
133 /* escape */ | 148 /* escape */ |
134 if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) { | 149 if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) { |
135 escape(buffer); | 150 escape(buffer); |
136 } | 151 } |
152 delete_sender_with_link(buffer); | |
137 } | 153 } |
138 return FALSE; | 154 return FALSE; |
139 } | 155 } |
140 | 156 |
141 static gboolean | 157 static gboolean |
458 "^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+\\Z)", | 474 "^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+\\Z)", |
459 G_REGEX_RAW, 0, NULL); | 475 G_REGEX_RAW, 0, NULL); |
460 regp[PSEUDO] = g_regex_new( | 476 regp[PSEUDO] = g_regex_new( |
461 "^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)", | 477 "^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)", |
462 G_REGEX_RAW, 0, NULL); | 478 G_REGEX_RAW, 0, NULL); |
479 regp[SENDER_WITH_LINK] = g_regex_new("@<a href=.+?>([A-Za-z0-9_]+?)</a>", 0, 0, NULL); | |
463 | 480 |
464 /* attach counter to the existing twitter window*/ | 481 /* attach counter to the existing twitter window*/ |
465 gboolean enabled = purple_prefs_get_bool(OPT_COUNTER); | 482 gboolean enabled = purple_prefs_get_bool(OPT_COUNTER); |
466 if(enabled) { | 483 if(enabled) { |
467 attach_to_window(); | 484 attach_to_window(); |
489 /* unreference regp */ | 506 /* unreference regp */ |
490 g_regex_unref(regp[RECIPIENT]); | 507 g_regex_unref(regp[RECIPIENT]); |
491 g_regex_unref(regp[SENDER]); | 508 g_regex_unref(regp[SENDER]); |
492 g_regex_unref(regp[COMMAND]); | 509 g_regex_unref(regp[COMMAND]); |
493 g_regex_unref(regp[PSEUDO]); | 510 g_regex_unref(regp[PSEUDO]); |
511 g_regex_unref(regp[SENDER_WITH_LINK]); | |
494 | 512 |
495 /* detach from twitter window */ | 513 /* detach from twitter window */ |
496 detach_from_window(); | 514 detach_from_window(); |
497 | 515 |
498 return TRUE; | 516 return TRUE; |