comparison pidgin-twitter.c @ 38:625e385036c3

applied indent to fix indentations
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Mon, 12 May 2008 19:46:10 +0900
parents bafe2abf2d3b
children 2ac81c0afb53
comparison
equal deleted inserted replaced
37:bafe2abf2d3b 38:625e385036c3
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 #define SENDER_WITH_LINK 4
39 39
40 #define PLUGIN_ID "gtk-honeyplanet-pidgin_twitter" 40 #define PLUGIN_ID "gtk-honeyplanet-pidgin_twitter"
41 #define PLUGIN_NAME "pidgin-twitter" 41 #define PLUGIN_NAME "pidgin-twitter"
42 42
43 #define OPT_PIDGINTWITTER "/plugins/pidgin_twitter" 43 #define OPT_PIDGINTWITTER "/plugins/pidgin_twitter"
75 delete_sender_with_link(gchar **str) 75 delete_sender_with_link(gchar **str)
76 { 76 {
77 gchar *newstr = NULL; 77 gchar *newstr = NULL;
78 78
79 /* replace senders with link */ 79 /* replace senders with link */
80 newstr = g_regex_replace(regp[SENDER_WITH_LINK], *str, -1, 0, "@\\1", 0, NULL); 80 newstr =
81 g_regex_replace(regp[SENDER_WITH_LINK], *str, -1, 0, "@\\1", 0, NULL);
81 twitter_debug("*str = %s\n", *str); 82 twitter_debug("*str = %s\n", *str);
82 twitter_debug("rnewstr = %s\n", newstr); 83 twitter_debug("rnewstr = %s\n", newstr);
83 84
84 g_free(*str); 85 g_free(*str);
85 *str = newstr; 86 *str = newstr;
130 *str = newstr; 131 *str = newstr;
131 } 132 }
132 } 133 }
133 134
134 static gboolean 135 static gboolean
135 sending_im_cb(PurpleAccount * account, char *recipient, char **buffer, 136 sending_im_cb(PurpleAccount *account, char *recipient, char **buffer,
136 void *data) 137 void *data)
137 { 138 {
138 const gchar *proto; 139 const gchar *proto;
139 140
140 /* check if the message is from twitter */ 141 /* check if the message is from twitter */
152 /* strip excessive link from @username */ 153 /* strip excessive link from @username */
153 delete_sender_with_link(buffer); 154 delete_sender_with_link(buffer);
154 155
155 /* try to suppress Oops message */ 156 /* try to suppress Oops message */
156 gint utflen = g_utf8_strlen(*buffer, -1); 157 gint utflen = g_utf8_strlen(*buffer, -1);
157 gint bytes = strlen(*buffer); 158 gint bytes = strlen(*buffer);
158 twitter_debug("utflen = %d bytes = %d\n", utflen, bytes); 159 twitter_debug("utflen = %d bytes = %d\n", utflen, bytes);
159 if(bytes > 140 && utflen <= 140) 160 if(bytes > 140 && utflen <= 140)
160 suppress_oops = TRUE; 161 suppress_oops = TRUE;
161 } 162 }
162 return FALSE; 163 return FALSE;
163 } 164 }
164 165
165 static gboolean 166 static gboolean
166 eval(const GMatchInfo * match_info, GString * result, gpointer user_data) 167 eval(const GMatchInfo *match_info, GString *result, gpointer user_data)
167 { 168 {
168 gchar sub[128]; 169 gchar sub[128];
169 gchar *match = g_match_info_fetch(match_info, 1); 170 gchar *match = g_match_info_fetch(match_info, 1);
170 171
171 int which = *(int *)user_data; 172 int which = *(int *)user_data;
184 gchar *newstr; 185 gchar *newstr;
185 186
186 twitter_debug("*str = %s\n", *str); 187 twitter_debug("*str = %s\n", *str);
187 188
188 newstr = g_regex_replace_eval(regp[which], // compiled regex 189 newstr = g_regex_replace_eval(regp[which], // compiled regex
189 *str, // subject string 190 *str, // subject string
190 -1, // length of the subject string 191 -1, // length of the subject string
191 0, // start position 192 0, // start position
192 0, // match options 193 0, // match options
193 eval, // function to be called for each match 194 eval, // function to be called for each match
194 &which, // user data 195 &which, // user data
195 NULL); // error handler 196 NULL); // error handler
196 197
197 twitter_debug("newstr = %s\n", newstr); 198 twitter_debug("newstr = %s\n", newstr);
198 199
219 g_regex_match(regp[which], *str, 0, &match_info); 220 g_regex_match(regp[which], *str, 0, &match_info);
220 while(g_match_info_matches(match_info)) { 221 while(g_match_info_matches(match_info)) {
221 gchar *user = g_match_info_fetch(match_info, 1); 222 gchar *user = g_match_info_fetch(match_info, 1);
222 twitter_debug("user = %s\n", user); 223 twitter_debug("user = %s\n", user);
223 224
224 for(candidate = candidates; *candidate ; candidate++) { 225 for(candidate = candidates; *candidate; candidate++) {
225 if(!strcmp(*candidate, "")) 226 if(!strcmp(*candidate, ""))
226 continue; 227 continue;
227 twitter_debug("candidate = %s\n", *candidate); 228 twitter_debug("candidate = %s\n", *candidate);
228 if(!strcmp(user, *candidate)) { 229 if(!strcmp(user, *candidate)) {
229 twitter_debug("match. play sound\n"); 230 twitter_debug("match. play sound\n");
230 purple_sound_play_event( 231 purple_sound_play_event(purple_prefs_get_int
231 purple_prefs_get_int(which ? OPT_SOUNDID_SENDER : OPT_SOUNDID_RECIPIENT), NULL); 232 (which ? OPT_SOUNDID_SENDER :
233 OPT_SOUNDID_RECIPIENT), NULL);
232 break; 234 break;
233 } 235 }
234 } 236 }
235 g_free(user); 237 g_free(user);
236 g_match_info_next(match_info, NULL); 238 g_match_info_next(match_info, NULL);
238 g_strfreev(candidates); 240 g_strfreev(candidates);
239 g_match_info_free(match_info); 241 g_match_info_free(match_info);
240 } 242 }
241 243
242 static gboolean 244 static gboolean
243 writing_im_cb(PurpleAccount * account, char *sender, char **buffer, 245 writing_im_cb(PurpleAccount *account, char *sender, char **buffer,
244 PurpleConversation * conv, int *flags, void *data) 246 PurpleConversation *conv, int *flags, void *data)
245 { 247 {
246 const gchar *proto; 248 const gchar *proto;
247 249
248 /* check if the message is from twitter */ 250 /* check if the message is from twitter */
249 proto = purple_account_get_protocol_id(account); 251 proto = purple_account_get_protocol_id(account);
250 twitter_debug("writing_im_cb\n"); 252 twitter_debug("writing_im_cb\n");
251 twitter_debug("proto = %s\n", proto); 253 twitter_debug("proto = %s\n", proto);
252 twitter_debug("sender = %s\n", sender); 254 twitter_debug("sender = %s\n", sender);
253 255
254 if(!strcmp(sender, "twitter@twitter.com") && 256 if(!strcmp(sender, "twitter@twitter.com") && !strcmp(proto, "prpl-jabber")) {
255 !strcmp(proto, "prpl-jabber")) {
256 /* playsound */ 257 /* playsound */
257 if(purple_prefs_get_bool(OPT_PLAYSOUND_SENDER)) { 258 if(purple_prefs_get_bool(OPT_PLAYSOUND_SENDER)) {
258 playsound(buffer, SENDER); 259 playsound(buffer, SENDER);
259 } 260 }
260 if(purple_prefs_get_bool(OPT_PLAYSOUND_RECIPIENT)) { 261 if(purple_prefs_get_bool(OPT_PLAYSOUND_RECIPIENT)) {
279 280
280 static void 281 static void
281 insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position, 282 insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position,
282 gchar *new_text, gint new_text_length, gpointer user_data) 283 gchar *new_text, gint new_text_length, gpointer user_data)
283 { 284 {
284 PidginConversation *gtkconv = (PidginConversation *)user_data; 285 PidginConversation *gtkconv = (PidginConversation *)user_data;
285 GtkWidget *box, *counter = NULL; 286 GtkWidget *box, *counter = NULL;
286 gchar *markup = NULL; 287 gchar *markup = NULL;
287 288
288 g_return_if_fail(gtkconv != NULL); 289 g_return_if_fail(gtkconv != NULL);
289 290
290 guint count = gtk_text_buffer_get_char_count(textbuffer) + 291 guint count = gtk_text_buffer_get_char_count(textbuffer) +
291 (unsigned int)g_utf8_strlen(new_text, -1); 292 (unsigned int)g_utf8_strlen(new_text, -1);
292 293
293 // twitter_debug("new_text = %s utf8_strlen = %ld new_text_length = %d\n", 294 // twitter_debug("new_text = %s utf8_strlen = %ld new_text_length = %d\n",
294 // new_text, g_utf8_strlen(new_text, -1), new_text_length); 295 // new_text, g_utf8_strlen(new_text, -1), new_text_length);
295 296
296 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", 297 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>",
297 count <= 140 ? "black" : "red", 298 count <= 140 ? "black" : "red", count);
298 count); 299
299 300 box = gtkconv->toolbar;
300 box = gtkconv->toolbar; 301 counter = g_object_get_data(G_OBJECT(box), PLUGIN_ID "-counter");
301 counter = g_object_get_data(G_OBJECT(box), 302 if(counter)
302 PLUGIN_ID "-counter");
303 if (counter)
304 gtk_label_set_markup(GTK_LABEL(counter), markup); 303 gtk_label_set_markup(GTK_LABEL(counter), markup);
305 304
306 g_free(markup); 305 g_free(markup);
307 } 306 }
308 307
309 static void 308 static void
310 delete_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *start_pos, 309 delete_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *start_pos,
311 GtkTextIter *end_pos, gpointer user_data) 310 GtkTextIter *end_pos, gpointer user_data)
312 { 311 {
313 PidginConversation *gtkconv = (PidginConversation *)user_data; 312 PidginConversation *gtkconv = (PidginConversation *)user_data;
314 GtkWidget *box, *counter = NULL; 313 GtkWidget *box, *counter = NULL;
315 gchar *markup = NULL; 314 gchar *markup = NULL;
316 315
317 g_return_if_fail(gtkconv != NULL); 316 g_return_if_fail(gtkconv != NULL);
318 317
319 guint count = gtk_text_buffer_get_char_count(textbuffer) - 318 guint count = gtk_text_buffer_get_char_count(textbuffer) -
320 (gtk_text_iter_get_offset(end_pos) - 319 (gtk_text_iter_get_offset(end_pos) -
321 gtk_text_iter_get_offset(start_pos)); 320 gtk_text_iter_get_offset(start_pos));
322 321
323 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>", 322 markup = g_markup_printf_escaped("<span color=\"%s\">%u</span>",
324 count <= 140 ? "black" : "red", 323 count <= 140 ? "black" : "red", count);
325 count); 324
326 325 box = gtkconv->toolbar;
327 box = gtkconv->toolbar; 326 counter = g_object_get_data(G_OBJECT(box), PLUGIN_ID "-counter");
328 counter = g_object_get_data(G_OBJECT(box), 327 if(counter)
329 PLUGIN_ID "-counter");
330 if (counter)
331 gtk_label_set_markup(GTK_LABEL(counter), markup); 328 gtk_label_set_markup(GTK_LABEL(counter), markup);
332 329
333 g_free(markup); 330 g_free(markup);
334 } 331 }
335 332
337 static void 334 static void
338 detach_from_window(void) 335 detach_from_window(void)
339 { 336 {
340 GList *list; 337 GList *list;
341 338
342 for (list = pidgin_conv_windows_get_list(); list; list = list->next) { 339 for(list = pidgin_conv_windows_get_list(); list; list = list->next) {
343 PidginWindow *win = list->data; 340 PidginWindow *win = list->data;
344 PurpleConversation *conv = pidgin_conv_window_get_active_conversation(win); 341 PurpleConversation *conv =
342 pidgin_conv_window_get_active_conversation(win);
345 if(is_twitter_conv(conv)) 343 if(is_twitter_conv(conv))
346 detach_from_gtkconv(PIDGIN_CONVERSATION(conv), NULL); 344 detach_from_gtkconv(PIDGIN_CONVERSATION(conv), NULL);
347 } 345 }
348 } 346 }
349 347
350 static void 348 static void
351 detach_from_gtkconv(PidginConversation *gtkconv, gpointer null) 349 detach_from_gtkconv(PidginConversation *gtkconv, gpointer null)
352 { 350 {
353 GtkWidget *box, *counter = NULL, *sep = NULL; 351 GtkWidget *box, *counter = NULL, *sep = NULL;
354 352
355 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry_buffer), 353 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry_buffer),
356 (GFunc)insert_text_cb, gtkconv); 354 (GFunc) insert_text_cb, gtkconv);
357 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry_buffer), 355 g_signal_handlers_disconnect_by_func(G_OBJECT(gtkconv->entry_buffer),
358 (GFunc)delete_text_cb, gtkconv); 356 (GFunc) delete_text_cb, gtkconv);
359 357
360 box = gtkconv->toolbar; 358 box = gtkconv->toolbar;
361 359
362 /* remove counter */ 360 /* remove counter */
363 counter = g_object_get_data(G_OBJECT(box), 361 counter = g_object_get_data(G_OBJECT(box), PLUGIN_ID "-counter");
364 PLUGIN_ID "-counter"); 362 if(counter) {
365 if (counter) { 363 gtk_container_remove(GTK_CONTAINER(box), counter);
366 gtk_container_remove(GTK_CONTAINER(box), counter);
367 g_object_unref(counter); 364 g_object_unref(counter);
368 g_object_set_data(G_OBJECT(box), 365 g_object_set_data(G_OBJECT(box), PLUGIN_ID "-counter", NULL);
369 PLUGIN_ID "-counter", NULL);
370 } 366 }
371 367
372 /* remove separator */ 368 /* remove separator */
373 sep = g_object_get_data(G_OBJECT(box), PLUGIN_ID "-sep"); 369 sep = g_object_get_data(G_OBJECT(box), PLUGIN_ID "-sep");
374 if (sep) { 370 if(sep) {
375 gtk_container_remove(GTK_CONTAINER(box), sep); 371 gtk_container_remove(GTK_CONTAINER(box), sep);
376 g_object_unref(sep); 372 g_object_unref(sep);
377 g_object_set_data(G_OBJECT(box), 373 g_object_set_data(G_OBJECT(box), PLUGIN_ID "-sep", NULL);
378 PLUGIN_ID "-sep", NULL); 374 }
379 } 375
380 376 gtk_widget_queue_draw(pidgin_conv_get_window(gtkconv)->window);
381 gtk_widget_queue_draw(pidgin_conv_get_window(gtkconv)->window);
382 } 377 }
383 378
384 static void 379 static void
385 attach_to_window(void) 380 attach_to_window(void)
386 { 381 {
387 GList *list; 382 GList *list;
388 383
389 for (list = pidgin_conv_windows_get_list(); list; list = list->next) { 384 for(list = pidgin_conv_windows_get_list(); list; list = list->next) {
390 PidginWindow *win = list->data; 385 PidginWindow *win = list->data;
391 PurpleConversation *conv = pidgin_conv_window_get_active_conversation(win); 386 PurpleConversation *conv =
387 pidgin_conv_window_get_active_conversation(win);
392 if(is_twitter_conv(conv)) 388 if(is_twitter_conv(conv))
393 attach_to_gtkconv(PIDGIN_CONVERSATION(conv), NULL); 389 attach_to_gtkconv(PIDGIN_CONVERSATION(conv), NULL);
394 } 390 }
395 } 391 }
396 392
397 static void 393 static void
398 attach_to_gtkconv(PidginConversation *gtkconv, gpointer null) 394 attach_to_gtkconv(PidginConversation *gtkconv, gpointer null)
399 { 395 {
400 GtkWidget *box, *sep, *counter; 396 GtkWidget *box, *sep, *counter;
401 397
402 box = gtkconv->toolbar; 398 box = gtkconv->toolbar;
403 counter = g_object_get_data(G_OBJECT(box), 399 counter = g_object_get_data(G_OBJECT(box), PLUGIN_ID "-counter");
404 PLUGIN_ID "-counter"); 400 g_return_if_fail(counter == NULL);
405 g_return_if_fail(counter == NULL);
406 401
407 /* make counter object */ 402 /* make counter object */
408 counter = gtk_label_new(NULL); 403 counter = gtk_label_new(NULL);
409 gtk_widget_set_name(counter, "counter_label"); 404 gtk_widget_set_name(counter, "counter_label");
410 gtk_label_set_text(GTK_LABEL(counter), "0"); 405 gtk_label_set_text(GTK_LABEL(counter), "0");
411 gtk_box_pack_end(GTK_BOX(box), counter, FALSE, FALSE, 0); 406 gtk_box_pack_end(GTK_BOX(box), counter, FALSE, FALSE, 0);
412 gtk_widget_show_all(counter); 407 gtk_widget_show_all(counter);
413 g_object_set_data(G_OBJECT(box), 408 g_object_set_data(G_OBJECT(box), PLUGIN_ID "-counter", counter);
414 PLUGIN_ID "-counter", counter);
415 409
416 /* make separator object */ 410 /* make separator object */
417 sep = gtk_vseparator_new(); 411 sep = gtk_vseparator_new();
418 gtk_box_pack_end(GTK_BOX(box), sep, FALSE, FALSE, 0); 412 gtk_box_pack_end(GTK_BOX(box), sep, FALSE, FALSE, 0);
419 gtk_widget_show_all(sep); 413 gtk_widget_show_all(sep);
420 g_object_set_data(G_OBJECT(box), 414 g_object_set_data(G_OBJECT(box), PLUGIN_ID "-sep", sep);
421 PLUGIN_ID "-sep", sep); 415
422 416 /* connect signals, etc. */
423 /* connect signals, etc. */ 417 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "insert_text",
424 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "insert_text", 418 G_CALLBACK(insert_text_cb), gtkconv);
425 G_CALLBACK(insert_text_cb), gtkconv); 419 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "delete_range",
426 g_signal_connect(G_OBJECT(gtkconv->entry_buffer), "delete_range", 420 G_CALLBACK(delete_text_cb), gtkconv);
427 G_CALLBACK(delete_text_cb), gtkconv);
428 421
429 /* redraw window */ 422 /* redraw window */
430 gtk_widget_queue_draw(pidgin_conv_get_window(gtkconv)->window); 423 gtk_widget_queue_draw(pidgin_conv_get_window(gtkconv)->window);
431 } 424 }
432 425
433 static gboolean 426 static gboolean
434 is_twitter_conv(PurpleConversation *conv) 427 is_twitter_conv(PurpleConversation *conv)
435 { 428 {
439 432
440 twitter_debug("is_twitter_conv\n"); 433 twitter_debug("is_twitter_conv\n");
441 twitter_debug("name = %s\n", name); 434 twitter_debug("name = %s\n", name);
442 twitter_debug("proto = %s\n", proto); 435 twitter_debug("proto = %s\n", proto);
443 436
444 if(!strcmp(name, "twitter@twitter.com") && 437 if(!strcmp(name, "twitter@twitter.com") && !strcmp(proto, "prpl-jabber")) {
445 !strcmp(proto, "prpl-jabber")) {
446 return TRUE; 438 return TRUE;
447 } 439 }
448 440
449 return FALSE; 441 return FALSE;
450 } 442 }
451 443
452 static void 444 static void
453 conv_created_cb(PurpleConversation *conv, gpointer null) 445 conv_created_cb(PurpleConversation *conv, gpointer null)
454 { 446 {
455 PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv); 447 PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv);
456 g_return_if_fail(gtkconv != NULL); 448 g_return_if_fail(gtkconv != NULL);
457 449
458 /* only attach to twitter conversation window */ 450 /* only attach to twitter conversation window */
459 if(is_twitter_conv(conv)) { 451 if(is_twitter_conv(conv)) {
460 gboolean enabled = purple_prefs_get_bool(OPT_COUNTER); 452 gboolean enabled = purple_prefs_get_bool(OPT_COUNTER);
461 if(enabled) { 453 if(enabled) {
474 if(!suppress_oops || !purple_prefs_get_bool(OPT_SUPPRESS_OOPS)) 466 if(!suppress_oops || !purple_prefs_get_bool(OPT_SUPPRESS_OOPS))
475 return FALSE; 467 return FALSE;
476 468
477 if(strstr(*buffer, OOPS_MESSAGE)) { 469 if(strstr(*buffer, OOPS_MESSAGE)) {
478 twitter_debug("receiving_im_cb: clearing sender and buffer\n"); 470 twitter_debug("receiving_im_cb: clearing sender and buffer\n");
479 g_free(*sender); *sender = NULL; 471 g_free(*sender);
480 g_free(*buffer); *buffer = NULL; 472 *sender = NULL;
473 g_free(*buffer);
474 *buffer = NULL;
481 suppress_oops = FALSE; 475 suppress_oops = FALSE;
482 } 476 }
483 return FALSE; 477 return FALSE;
484 } 478 }
485 479
486 static gboolean 480 static gboolean
487 load_plugin(PurplePlugin * plugin) 481 load_plugin(PurplePlugin *plugin)
488 { 482 {
489 /* connect to signal */ 483 /* connect to signal */
490 purple_signal_connect(purple_conversations_get_handle(), "writing-im-msg", 484 purple_signal_connect(purple_conversations_get_handle(), "writing-im-msg",
491 plugin, PURPLE_CALLBACK(writing_im_cb), NULL); 485 plugin, PURPLE_CALLBACK(writing_im_cb), NULL);
492 purple_signal_connect(purple_conversations_get_handle(), "sending-im-msg", 486 purple_signal_connect(purple_conversations_get_handle(), "sending-im-msg",
493 plugin, PURPLE_CALLBACK(sending_im_cb), NULL); 487 plugin, PURPLE_CALLBACK(sending_im_cb), NULL);
494 purple_signal_connect(purple_conversations_get_handle(), 488 purple_signal_connect(purple_conversations_get_handle(),
495 "conversation-created", 489 "conversation-created",
496 plugin, PURPLE_CALLBACK(conv_created_cb), NULL); 490 plugin, PURPLE_CALLBACK(conv_created_cb), NULL);
497 purple_signal_connect(purple_conversations_get_handle(), "receiving-im-msg", 491 purple_signal_connect(purple_conversations_get_handle(), "receiving-im-msg",
498 plugin, PURPLE_CALLBACK(receiving_im_cb), NULL); 492 plugin, PURPLE_CALLBACK(receiving_im_cb), NULL);
499 493
500 /* compile regex */ 494 /* compile regex */
501 regp[RECIPIENT] = g_regex_new("@([A-Za-z0-9_]+)", 0, 0, NULL); 495 regp[RECIPIENT] = g_regex_new("@([A-Za-z0-9_]+)", 0, 0, NULL);
502 regp[SENDER] = g_regex_new("<body>([A-Za-z0-9_]+): ", 0, 0, NULL); 496 regp[SENDER] = g_regex_new("<body>([A-Za-z0-9_]+): ", 0, 0, NULL);
503 regp[COMMAND] = g_regex_new( 497 regp[COMMAND] =
504 "^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+\\Z)", 498 g_regex_new("^(?:\\s*)([dDfFgGlLmMnNtTwW]{1}\\s+[A-Za-z0-9_]+\\Z)",
505 G_REGEX_RAW, 0, NULL); 499 G_REGEX_RAW, 0, NULL);
506 regp[PSEUDO] = g_regex_new( 500 regp[PSEUDO] =
507 "^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)", 501 g_regex_new
508 G_REGEX_RAW, 0, NULL); 502 ("^\\s*(?:[\"#$%&'()*+,\\-./:;<=>?\\[\\\\\\]_`{|}~]|[^\\s\\x21-\\x7E])*([dDfFgGlLmMnNtTwW]{1})(?:\\Z|\\s+|[^\\x21-\\x7E]+\\Z)",
509 regp[SENDER_WITH_LINK] = g_regex_new( 503 G_REGEX_RAW, 0, NULL);
510 "@(?:<font .+?>)?<a href=.+?>([A-Za-z0-9_]+?)</a>(?:</font>)?", 0, 0, NULL); 504 regp[SENDER_WITH_LINK] =
505 g_regex_new
506 ("@(?:<font .+?>)?<a href=.+?>([A-Za-z0-9_]+?)</a>(?:</font>)?", 0, 0,
507 NULL);
511 508
512 /* attach counter to the existing twitter window */ 509 /* attach counter to the existing twitter window */
513 gboolean enabled = purple_prefs_get_bool(OPT_COUNTER); 510 gboolean enabled = purple_prefs_get_bool(OPT_COUNTER);
514 if(enabled) { 511 if(enabled) {
515 attach_to_window(); 512 attach_to_window();
517 514
518 return TRUE; 515 return TRUE;
519 } 516 }
520 517
521 static gboolean 518 static gboolean
522 unload_plugin(PurplePlugin * plugin) 519 unload_plugin(PurplePlugin *plugin)
523 { 520 {
524 twitter_debug("pidgin-twitter unload called\n"); 521 twitter_debug("pidgin-twitter unload called\n");
525 522
526 /* disconnect from signal */ 523 /* disconnect from signal */
527 purple_signal_disconnect(purple_conversations_get_handle(), 524 purple_signal_disconnect(purple_conversations_get_handle(),
528 "writing-im-msg", 525 "writing-im-msg",
529 plugin, PURPLE_CALLBACK(writing_im_cb)); 526 plugin, PURPLE_CALLBACK(writing_im_cb));
530 purple_signal_disconnect(purple_conversations_get_handle(), 527 purple_signal_disconnect(purple_conversations_get_handle(),
531 "sending-im-msg", 528 "sending-im-msg",
532 plugin, PURPLE_CALLBACK(sending_im_cb)); 529 plugin, PURPLE_CALLBACK(sending_im_cb));
533 purple_signal_disconnect(purple_conversations_get_handle(), 530 purple_signal_disconnect(purple_conversations_get_handle(),
534 "conversation-created", 531 "conversation-created",
535 plugin, PURPLE_CALLBACK(conv_created_cb)); 532 plugin, PURPLE_CALLBACK(conv_created_cb));
536 purple_signal_disconnect(purple_conversations_get_handle(), 533 purple_signal_disconnect(purple_conversations_get_handle(),
537 "receiving-im-msg", 534 "receiving-im-msg",
538 plugin, PURPLE_CALLBACK(receiving_im_cb)); 535 plugin, PURPLE_CALLBACK(receiving_im_cb));
550 return TRUE; 547 return TRUE;
551 } 548 }
552 549
553 static void 550 static void
554 counter_prefs_cb(const char *name, PurplePrefType type, 551 counter_prefs_cb(const char *name, PurplePrefType type,
555 gconstpointer val, gpointer data) 552 gconstpointer val, gpointer data)
556 { 553 {
557 gboolean enabled = purple_prefs_get_bool(OPT_COUNTER); 554 gboolean enabled = purple_prefs_get_bool(OPT_COUNTER);
558 if(enabled) { 555 if(enabled) {
559 attach_to_window(); //xxx should check whether already attached or not? 556 attach_to_window(); //xxx should check whether already attached or not?
560 } 557 }
561 else { 558 else {
562 detach_from_window(); 559 detach_from_window();
563 } 560 }
564 } 561 }
565 562
566 static PurplePluginPrefFrame * 563 static PurplePluginPrefFrame *
567 get_plugin_pref_frame(PurplePlugin * plugin) 564 get_plugin_pref_frame(PurplePlugin *plugin)
568 { 565 {
569 /* create gtk elements for the plugin preferences */ 566 /* create gtk elements for the plugin preferences */
570 PurplePluginPref *pref; 567 PurplePluginPref *pref;
571 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new(); 568 PurplePluginPrefFrame *frame = purple_plugin_pref_frame_new();
572 569
575 /************************/ 572 /************************/
576 pref = purple_plugin_pref_new_with_label("Translation Configurations"); 573 pref = purple_plugin_pref_new_with_label("Translation Configurations");
577 purple_plugin_pref_frame_add(frame, pref); 574 purple_plugin_pref_frame_add(frame, pref);
578 575
579 /* translation settings */ 576 /* translation settings */
580 pref = purple_plugin_pref_new_with_name_and_label( 577 pref = purple_plugin_pref_new_with_name_and_label(OPT_TRANSLATE_RECIPIENT,
581 OPT_TRANSLATE_RECIPIENT, 578 "Translate @username to link");
582 "Translate @username to link"); 579 purple_plugin_pref_frame_add(frame, pref);
583 purple_plugin_pref_frame_add(frame, pref); 580
584 581 pref = purple_plugin_pref_new_with_name_and_label(OPT_TRANSLATE_SENDER,
585 pref = purple_plugin_pref_new_with_name_and_label( 582 "Translate sender name to link");
586 OPT_TRANSLATE_SENDER,
587 "Translate sender name to link");
588 purple_plugin_pref_frame_add(frame, pref); 583 purple_plugin_pref_frame_add(frame, pref);
589 584
590 585
591 /*************************/ 586 /*************************/
592 /* miscellaneous heading */ 587 /* miscellaneous heading */
593 /*************************/ 588 /*************************/
594 pref = purple_plugin_pref_new_with_label("Miscellaneous Configurations"); 589 pref = purple_plugin_pref_new_with_label("Miscellaneous Configurations");
595 purple_plugin_pref_frame_add(frame, pref); 590 purple_plugin_pref_frame_add(frame, pref);
596 591
597 /* escape pseudo command setting */ 592 /* escape pseudo command setting */
598 pref = purple_plugin_pref_new_with_name_and_label( 593 pref = purple_plugin_pref_new_with_name_and_label(OPT_ESCAPE_PSEUDO,
599 OPT_ESCAPE_PSEUDO, 594 "Escape pseudo command string");
600 "Escape pseudo command string");
601 purple_plugin_pref_frame_add(frame, pref); 595 purple_plugin_pref_frame_add(frame, pref);
602 596
603 /* show text counter */ 597 /* show text counter */
604 pref = purple_plugin_pref_new_with_name_and_label( 598 pref = purple_plugin_pref_new_with_name_and_label(OPT_COUNTER,
605 OPT_COUNTER, 599 "Show text counter");
606 "Show text counter"); 600 purple_plugin_pref_frame_add(frame, pref);
607 purple_plugin_pref_frame_add(frame, pref); 601
608 602 purple_prefs_connect_callback(plugin, OPT_COUNTER, counter_prefs_cb, NULL);
609 purple_prefs_connect_callback(plugin, OPT_COUNTER,
610 counter_prefs_cb, NULL);
611 603
612 /* suppress oops message */ 604 /* suppress oops message */
613 pref = purple_plugin_pref_new_with_name_and_label( 605 pref = purple_plugin_pref_new_with_name_and_label(OPT_SUPPRESS_OOPS,
614 OPT_SUPPRESS_OOPS, 606 "Suppress oops message");
615 "Suppress oops message");
616 purple_plugin_pref_frame_add(frame, pref); 607 purple_plugin_pref_frame_add(frame, pref);
617 608
618 609
619 /*****************/ 610 /*****************/
620 /* sound heading */ 611 /* sound heading */
621 /*****************/ 612 /*****************/
622 pref = purple_plugin_pref_new_with_label("Sound Configurations"); 613 pref = purple_plugin_pref_new_with_label("Sound Configurations");
623 purple_plugin_pref_frame_add(frame, pref); 614 purple_plugin_pref_frame_add(frame, pref);
624 615
625 /* sound settings for recipient */ 616 /* sound settings for recipient */
626 pref = purple_plugin_pref_new_with_name_and_label( 617 pref = purple_plugin_pref_new_with_name_and_label(OPT_PLAYSOUND_RECIPIENT,
627 OPT_PLAYSOUND_RECIPIENT, 618 "Play sound on a reply to the user in the recipient list");
628 "Play sound on a reply to the user in the recipient list");
629 purple_plugin_pref_frame_add(frame, pref); 619 purple_plugin_pref_frame_add(frame, pref);
630 620
631 /* recipient list */ 621 /* recipient list */
632 pref = purple_plugin_pref_new_with_name_and_label( 622 pref = purple_plugin_pref_new_with_name_and_label(OPT_USERLIST_RECIPIENT,
633 OPT_USERLIST_RECIPIENT, 623 "Recipient List");
634 "Recipient List");
635 purple_plugin_pref_frame_add(frame, pref); 624 purple_plugin_pref_frame_add(frame, pref);
636 625
637 /* sound id selector */ 626 /* sound id selector */
638 pref = purple_plugin_pref_new_with_name_and_label(OPT_SOUNDID_RECIPIENT, "Recipient Sound"); 627 pref =
639 628 purple_plugin_pref_new_with_name_and_label(OPT_SOUNDID_RECIPIENT,
640 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE); 629 "Recipient Sound");
641 purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0)); 630
642 purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1)); 631 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE);
643 purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2)); 632 purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0));
644 purple_plugin_pref_add_choice(pref, "Fist Receive", GINT_TO_POINTER(3)); 633 purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1));
645 purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4)); 634 purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2));
646 purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5)); 635 purple_plugin_pref_add_choice(pref, "Fist Receive", GINT_TO_POINTER(3));
647 purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6)); 636 purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4));
648 purple_plugin_pref_add_choice(pref, "Chat You Say", GINT_TO_POINTER(7)); 637 purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5));
649 purple_plugin_pref_add_choice(pref, "Chat Someone Say", GINT_TO_POINTER(8)); 638 purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6));
650 purple_plugin_pref_add_choice(pref, "Pounce Default", GINT_TO_POINTER(9)); 639 purple_plugin_pref_add_choice(pref, "Chat You Say", GINT_TO_POINTER(7));
651 purple_plugin_pref_add_choice(pref, "Chat Nick Said", GINT_TO_POINTER(10)); 640 purple_plugin_pref_add_choice(pref, "Chat Someone Say", GINT_TO_POINTER(8));
652 641 purple_plugin_pref_add_choice(pref, "Pounce Default", GINT_TO_POINTER(9));
653 purple_plugin_pref_frame_add(frame, pref); 642 purple_plugin_pref_add_choice(pref, "Chat Nick Said", GINT_TO_POINTER(10));
643
644 purple_plugin_pref_frame_add(frame, pref);
654 645
655 /* sound setting for sender */ 646 /* sound setting for sender */
656 pref = purple_plugin_pref_new_with_name_and_label( 647 pref = purple_plugin_pref_new_with_name_and_label(OPT_PLAYSOUND_SENDER,
657 OPT_PLAYSOUND_SENDER, 648 "Play sound if sender of a message is in the sender list");
658 "Play sound if sender of a message is in the sender list");
659 purple_plugin_pref_frame_add(frame, pref); 649 purple_plugin_pref_frame_add(frame, pref);
660 650
661 /* sender list */ 651 /* sender list */
662 pref = purple_plugin_pref_new_with_name_and_label( 652 pref = purple_plugin_pref_new_with_name_and_label(OPT_USERLIST_SENDER,
663 OPT_USERLIST_SENDER, 653 "Sender List");
664 "Sender List");
665 purple_plugin_pref_frame_add(frame, pref); 654 purple_plugin_pref_frame_add(frame, pref);
666 655
667 /* sound id selector */ 656 /* sound id selector */
668 pref = purple_plugin_pref_new_with_name_and_label(OPT_SOUNDID_SENDER, "Sender Sound"); 657 pref =
669 658 purple_plugin_pref_new_with_name_and_label(OPT_SOUNDID_SENDER,
670 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE); 659 "Sender Sound");
671 purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0)); 660
672 purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1)); 661 purple_plugin_pref_set_type(pref, PURPLE_PLUGIN_PREF_CHOICE);
673 purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2)); 662 purple_plugin_pref_add_choice(pref, "Arrive", GINT_TO_POINTER(0));
674 purple_plugin_pref_add_choice(pref, "Fist Receive", GINT_TO_POINTER(3)); 663 purple_plugin_pref_add_choice(pref, "Leave", GINT_TO_POINTER(1));
675 purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4)); 664 purple_plugin_pref_add_choice(pref, "Receive", GINT_TO_POINTER(2));
676 purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5)); 665 purple_plugin_pref_add_choice(pref, "Fist Receive", GINT_TO_POINTER(3));
677 purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6)); 666 purple_plugin_pref_add_choice(pref, "Send", GINT_TO_POINTER(4));
678 purple_plugin_pref_add_choice(pref, "Chat You Say", GINT_TO_POINTER(7)); 667 purple_plugin_pref_add_choice(pref, "Chat Join", GINT_TO_POINTER(5));
679 purple_plugin_pref_add_choice(pref, "Chat Someone Say", GINT_TO_POINTER(8)); 668 purple_plugin_pref_add_choice(pref, "Chat Leave", GINT_TO_POINTER(6));
680 purple_plugin_pref_add_choice(pref, "Pounce Default", GINT_TO_POINTER(9)); 669 purple_plugin_pref_add_choice(pref, "Chat You Say", GINT_TO_POINTER(7));
681 purple_plugin_pref_add_choice(pref, "Chat Nick Said", GINT_TO_POINTER(10)); 670 purple_plugin_pref_add_choice(pref, "Chat Someone Say", GINT_TO_POINTER(8));
682 671 purple_plugin_pref_add_choice(pref, "Pounce Default", GINT_TO_POINTER(9));
683 purple_plugin_pref_frame_add(frame, pref); 672 purple_plugin_pref_add_choice(pref, "Chat Nick Said", GINT_TO_POINTER(10));
673
674 purple_plugin_pref_frame_add(frame, pref);
684 675
685 return frame; 676 return frame;
686 } 677 }
687 678
688 static PurplePluginUiInfo pref_info = { 679 static PurplePluginUiInfo pref_info = {
713 &pref_info, /**< pref info */ 704 &pref_info, /**< pref info */
714 NULL 705 NULL
715 }; 706 };
716 707
717 static void 708 static void
718 init_plugin(PurplePlugin * plugin) 709 init_plugin(PurplePlugin *plugin)
719 { 710 {
720 g_type_init(); 711 g_type_init();
721 712
722 /* add plugin preferences */ 713 /* add plugin preferences */
723 purple_prefs_add_none(OPT_PIDGINTWITTER); 714 purple_prefs_add_none(OPT_PIDGINTWITTER);