comparison pidgin-twitter.c @ 44:4f456c7150ed

cleanups
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Tue, 13 May 2008 03:42:45 +0900
parents caa42301f520
children 746ff3b54c10
comparison
equal deleted inserted replaced
43:caa42301f520 44:4f456c7150ed
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 EXCESS_MARKUP 4 38 #define EXCESS_MARKUP 4
39 #define FONT_MARKUP 5 39 #define FONT_MARKUP 5
40 #define ATMARK_AFTER_A 6 40 #define ATMARK_AFTER_A 6
41 41
42 #define PLUGIN_ID "gtk-honeyplanet-pidgin_twitter" 42 #define PLUGIN_ID "gtk-honeyplanet-pidgin_twitter"
43 #define PLUGIN_NAME "pidgin-twitter" 43 #define PLUGIN_NAME "pidgin-twitter"
44 44
45 #define OPT_PIDGINTWITTER "/plugins/pidgin_twitter" 45 #define OPT_PIDGINTWITTER "/plugins/pidgin_twitter"
89 static gboolean unload_plugin(PurplePlugin *plugin); 89 static gboolean unload_plugin(PurplePlugin *plugin);
90 static void counter_prefs_cb(const char *name, PurplePrefType type, gconstpointer val, gpointer data); 90 static void counter_prefs_cb(const char *name, PurplePrefType type, gconstpointer val, gpointer data);
91 static PurplePluginPrefFrame *get_plugin_pref_frame(PurplePlugin *plugin); 91 static PurplePluginPrefFrame *get_plugin_pref_frame(PurplePlugin *plugin);
92 static void init_plugin(PurplePlugin *plugin); 92 static void init_plugin(PurplePlugin *plugin);
93 93
94
94 /* implementation */ 95 /* implementation */
95 static void 96 static void
96 strip_excess_markup(gchar **str) 97 strip_excess_markup(gchar **str)
97 { 98 {
98 gchar *newstr = NULL; 99 gchar *newstr = NULL;
99 100
100 /* strip font */ 101 /* strip font tag */
101 newstr = g_regex_replace(regp[FONT_MARKUP], *str, -1, 0, "\\1", 0, NULL); 102 newstr = g_regex_replace(regp[FONT_MARKUP], *str, -1, 0, "\\1", 0, NULL);
102 twitter_debug("*str = %s newstr = %s\n", *str, newstr); 103 twitter_debug("*str = %s newstr = %s\n", *str, newstr);
103 g_free(*str); 104 g_free(*str);
104 *str = newstr; 105 *str = newstr;
105 106
106 /* change from atmark after a to atmark before a */ 107 /* move @ prior to anchor tag */
107 newstr = g_regex_replace(regp[ATMARK_AFTER_A], *str, -1, 0, "@\\1", 0, NULL); 108 newstr = g_regex_replace(regp[ATMARK_AFTER_A], *str, -1, 0, "@\\1", 0, NULL);
108 twitter_debug("*str = %s newstr = %s\n", *str, newstr); 109 twitter_debug("*str = %s newstr = %s\n", *str, newstr);
109 g_free(*str); 110 g_free(*str);
110 *str = newstr; 111 *str = newstr;
111 112
167 static gboolean 168 static gboolean
168 sending_im_cb(PurpleAccount *account, char *recipient, char **buffer, 169 sending_im_cb(PurpleAccount *account, char *recipient, char **buffer,
169 void *data) 170 void *data)
170 { 171 {
171 /* check if the message is from twitter */ 172 /* check if the message is from twitter */
172 if(is_twitter_account(account, recipient)) { 173 if(!is_twitter_account(account, recipient))
173 /* strip excess markup */ 174 return FALSE;
174 strip_excess_markup(buffer); 175
175 176 /* strip excess markup */
176 /* escape pseudo command */ 177 strip_excess_markup(buffer);
177 if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) { 178
178 escape(buffer); 179 /* escape pseudo command */
179 } 180 if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) {
180 181 escape(buffer);
181 /* try to suppress oops message */ 182 }
182 gint utflen = g_utf8_strlen(*buffer, -1); 183
183 gint bytes = strlen(*buffer); 184 /* try to suppress oops message */
184 twitter_debug("utflen = %d bytes = %d\n", utflen, bytes); 185 gint utflen = g_utf8_strlen(*buffer, -1);
185 if(bytes > 140 && utflen <= 140) 186 gint bytes = strlen(*buffer);
186 suppress_oops = TRUE; 187 twitter_debug("utflen = %d bytes = %d\n", utflen, bytes);
187 } 188 if(bytes > 140 && utflen <= 140)
189 suppress_oops = TRUE;
188 190
189 return FALSE; 191 return FALSE;
190 } 192 }
191 193
192 static gboolean 194 static gboolean
269 static gboolean 271 static gboolean
270 writing_im_cb(PurpleAccount *account, char *sender, char **buffer, 272 writing_im_cb(PurpleAccount *account, char *sender, char **buffer,
271 PurpleConversation *conv, int *flags, void *data) 273 PurpleConversation *conv, int *flags, void *data)
272 { 274 {
273 /* check if the message is from twitter */ 275 /* check if the message is from twitter */
274 if(is_twitter_account(account, sender)) { 276 if(!is_twitter_account(account, sender))
275 /* playsound */ 277 return FALSE;
276 if(purple_prefs_get_bool(OPT_PLAYSOUND_SENDER)) { 278
277 playsound(buffer, SENDER); 279
278 } 280 /* playsound */
279 if(purple_prefs_get_bool(OPT_PLAYSOUND_RECIPIENT)) { 281 if(purple_prefs_get_bool(OPT_PLAYSOUND_SENDER)) {
280 playsound(buffer, RECIPIENT); 282 playsound(buffer, SENDER);
281 } 283 }
282 284 if(purple_prefs_get_bool(OPT_PLAYSOUND_RECIPIENT)) {
283 /* strip excess markup */ 285 playsound(buffer, RECIPIENT);
284 strip_excess_markup(buffer); 286 }
285 287
286 /* translate */ 288 /* strip excess markup */
287 if(purple_prefs_get_bool(OPT_TRANSLATE_SENDER)) { 289 strip_excess_markup(buffer);
288 translate(buffer, SENDER); 290
289 } 291 /* translate */
290 if(purple_prefs_get_bool(OPT_TRANSLATE_RECIPIENT)) { 292 if(purple_prefs_get_bool(OPT_TRANSLATE_SENDER)) {
291 translate(buffer, RECIPIENT); 293 translate(buffer, SENDER);
292 } 294 }
293 295 if(purple_prefs_get_bool(OPT_TRANSLATE_RECIPIENT)) {
294 /* escape pseudo command */ 296 translate(buffer, RECIPIENT);
295 if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) { 297 }
296 escape(buffer); 298
297 } 299 /* escape pseudo command */
298 } 300 if(purple_prefs_get_bool(OPT_ESCAPE_PSEUDO)) {
301 escape(buffer);
302 }
303
299 return FALSE; 304 return FALSE;
300 } 305 }
301 306
302 static void 307 static void
303 insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position, 308 insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position,
520 525
521 /* compile regex */ 526 /* compile regex */
522 regp[RECIPIENT] = g_regex_new("@([A-Za-z0-9_]+)", 0, 0, NULL); 527 regp[RECIPIENT] = g_regex_new("@([A-Za-z0-9_]+)", 0, 0, NULL);
523 regp[SENDER] = g_regex_new("<body>([A-Za-z0-9_]+): ", 0, 0, NULL); 528 regp[SENDER] = g_regex_new("<body>([A-Za-z0-9_]+): ", 0, 0, NULL);
524 regp[COMMAND] = 529 regp[COMMAND] =
525 // g_regex_new("^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+\\Z)",
526 g_regex_new("^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+)(?:\\s*\\Z)", 530 g_regex_new("^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+)(?:\\s*\\Z)",
527 G_REGEX_RAW, 0, NULL); 531 G_REGEX_RAW, 0, NULL);
528 regp[PSEUDO] = 532 regp[PSEUDO] =
529 g_regex_new 533 g_regex_new
530 ("^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)", 534 ("^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)",