pidgin/gtkconv.c

changeset 21352
e10c4ea18f7c
parent 21175
c6d76b49c206
parent 21351
4c83d3121e8b
child 21630
591a79c1b295
equal deleted inserted replaced
21175:c6d76b49c206 21352:e10c4ea18f7c
6517 PurplePresence *p = NULL; 6517 PurplePresence *p = NULL;
6518 char *markup = NULL; 6518 char *markup = NULL;
6519 AtkObject *accessibility_obj; 6519 AtkObject *accessibility_obj;
6520 /* I think this is a little longer than it needs to be but I'm lazy. */ 6520 /* I think this is a little longer than it needs to be but I'm lazy. */
6521 char *style; 6521 char *style;
6522 gboolean bold = FALSE;
6522 6523
6523 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM) 6524 if (purple_conversation_get_type(conv) == PURPLE_CONV_TYPE_IM)
6524 im = PURPLE_CONV_IM(conv); 6525 im = PURPLE_CONV_IM(conv);
6525 6526
6526 if ((account == NULL) || 6527 if ((account == NULL) ||
6550 g_free(esc); 6551 g_free(esc);
6551 } 6552 }
6552 gtk_list_store_set(gtkconv->infopane_model, &(gtkconv->infopane_iter), 6553 gtk_list_store_set(gtkconv->infopane_model, &(gtkconv->infopane_iter),
6553 CONV_TEXT_COLUMN, markup, -1); 6554 CONV_TEXT_COLUMN, markup, -1);
6554 /* XXX seanegan Why do I have to do this? */ 6555 /* XXX seanegan Why do I have to do this? */
6555 gtk_widget_queue_draw(gtkconv->infopane); 6556 gtk_widget_queue_draw(gtkconv->infopane);
6556 6557
6557 if (title != markup) 6558 if (title != markup)
6558 g_free(markup); 6559 g_free(markup);
6559 6560
6560 if (!GTK_WIDGET_REALIZED(gtkconv->tab_label)) 6561 if (!GTK_WIDGET_REALIZED(gtkconv->tab_label))
6569 purple_conv_im_get_typing_state(im) == PURPLE_TYPED) { 6570 purple_conv_im_get_typing_state(im) == PURPLE_TYPED) {
6570 atk_object_set_description(accessibility_obj, _("Stopped Typing")); 6571 atk_object_set_description(accessibility_obj, _("Stopped Typing"));
6571 style = "color=\"#c4a000\""; 6572 style = "color=\"#c4a000\"";
6572 } else if (gtkconv->unseen_state == PIDGIN_UNSEEN_NICK) { 6573 } else if (gtkconv->unseen_state == PIDGIN_UNSEEN_NICK) {
6573 atk_object_set_description(accessibility_obj, _("Nick Said")); 6574 atk_object_set_description(accessibility_obj, _("Nick Said"));
6574 style = "color=\"#204a87\" weight=\"bold\""; 6575 style = "color=\"#cc0000\"";
6575 } else if (gtkconv->unseen_state == PIDGIN_UNSEEN_TEXT) { 6576 } else if (gtkconv->unseen_state == PIDGIN_UNSEEN_TEXT) {
6576 atk_object_set_description(accessibility_obj, _("Unread Messages")); 6577 atk_object_set_description(accessibility_obj, _("Unread Messages"));
6577 style = "color=\"#cc0000\" weight=\"bold\""; 6578 if (gtkconv->active_conv->type == PURPLE_CONV_TYPE_CHAT)
6579 style = "color=\"#204a87\" weight=\"bold\"";
6580 else
6581 style = "color=\"#cc0000\" weight=\"bold\"";
6578 } else if (gtkconv->unseen_state == PIDGIN_UNSEEN_EVENT) { 6582 } else if (gtkconv->unseen_state == PIDGIN_UNSEEN_EVENT) {
6579 atk_object_set_description(accessibility_obj, _("New Event")); 6583 atk_object_set_description(accessibility_obj, _("New Event"));
6580 style = "color=\"#888a85\" weight=\"bold\""; 6584 style = "color=\"#888a85\"";
6581 } else { 6585 } else {
6582 style = ""; 6586 style = NULL;
6583 } 6587 }
6588
6589 if (gtkconv->unseen_state == PIDGIN_UNSEEN_TEXT ||
6590 gtkconv->unseen_state == PIDGIN_UNSEEN_NICK ||
6591 gtkconv->unseen_state == PIDGIN_UNSEEN_EVENT)
6592 bold = TRUE;
6584 6593
6585 if (*style != '\0') 6594 if (style || bold)
6586 { 6595 {
6587 char *html_title,*label; 6596 char *html_title,*label;
6588 6597
6589 html_title = g_markup_escape_text(title, -1); 6598 html_title = g_markup_escape_text(title, -1);
6590 label = g_strdup_printf("<span %s>%s</span>", 6599 label = g_strdup_printf("<span %s %s>%s</span>",
6591 style, html_title); 6600 style ? style : "",
6601 bold ? "weight=\"bold\"" : "",
6602 html_title);
6592 g_free(html_title); 6603 g_free(html_title);
6593 gtk_label_set_markup(GTK_LABEL(gtkconv->tab_label), label); 6604 gtk_label_set_markup(GTK_LABEL(gtkconv->tab_label), label);
6594 g_free(label); 6605 g_free(label);
6595 } 6606 }
6596 else 6607 else
6597 gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title); 6608 gtk_label_set_text(GTK_LABEL(gtkconv->tab_label), title);
6598 6609
6599 if (pidgin_conv_window_is_active_conversation(conv)) 6610 if (pidgin_conv_window_is_active_conversation(conv))
6600 update_typing_icon(gtkconv); 6611 update_typing_icon(gtkconv);
6601 6612
6602 gtk_label_set_text(GTK_LABEL(gtkconv->menu_label), title); 6613 gtk_label_set_text(GTK_LABEL(gtkconv->menu_label), title);
6603 if (pidgin_conv_window_is_active_conversation(conv)) 6614 if (pidgin_conv_window_is_active_conversation(conv))
7395 update_chat_topic(PurpleConversation *conv, const char *old, const char *new) 7406 update_chat_topic(PurpleConversation *conv, const char *old, const char *new)
7396 { 7407 {
7397 pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC); 7408 pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC);
7398 } 7409 }
7399 7410
7411 /* Message history stuff */
7412
7413 /* Compare two PurpleConvMessage's, according to time in ascending order. */
7414 static int
7415 message_compare(gconstpointer p1, gconstpointer p2)
7416 {
7417 const PurpleConvMessage *m1 = p1, *m2 = p2;
7418 return (m1->when > m2->when);
7419 }
7420
7421 /* Adds some message history to the gtkconv. This happens in a idle-callback. */
7400 static gboolean 7422 static gboolean
7401 add_message_history_to_gtkconv(gpointer data) 7423 add_message_history_to_gtkconv(gpointer data)
7402 { 7424 {
7403 PidginConversation *gtkconv = data; 7425 PidginConversation *gtkconv = data;
7404 int count = 0; 7426 int count = 0;
7405 int timer = gtkconv->attach.timer; 7427 int timer = gtkconv->attach.timer;
7406 time_t when = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtkconv->entry), "attach-start-time")); 7428 time_t when = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtkconv->entry), "attach-start-time"));
7429 gboolean im = (gtkconv->active_conv->type == PURPLE_CONV_TYPE_IM);
7407 7430
7408 gtkconv->attach.timer = 0; 7431 gtkconv->attach.timer = 0;
7409 while (gtkconv->attach.current && count < 100) { /* XXX: 100 is a random value here */ 7432 while (gtkconv->attach.current && count < 100) { /* XXX: 100 is a random value here */
7410 PurpleConvMessage *msg = gtkconv->attach.current->data; 7433 PurpleConvMessage *msg = gtkconv->attach.current->data;
7411 if (when && when < msg->when) { 7434 if (!im && when && when < msg->when) {
7412 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR><HR>", 0); 7435 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR><HR>", 0);
7413 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL); 7436 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL);
7414 } 7437 }
7415 pidgin_conv_write_conv(gtkconv->active_conv, msg->who, msg->who, msg->what, msg->flags, msg->when); 7438 pidgin_conv_write_conv(msg->conv, msg->who, msg->who, msg->what, msg->flags, msg->when);
7416 gtkconv->attach.current = gtkconv->attach.current->prev; 7439 if (im) {
7440 gtkconv->attach.current = g_list_delete_link(gtkconv->attach.current, gtkconv->attach.current);
7441 } else {
7442 gtkconv->attach.current = gtkconv->attach.current->prev;
7443 }
7417 count++; 7444 count++;
7418 } 7445 }
7419 gtkconv->attach.timer = timer; 7446 gtkconv->attach.timer = timer;
7420 if (gtkconv->attach.current) 7447 if (gtkconv->attach.current)
7421 return TRUE; 7448 return TRUE;
7422 7449
7450 g_source_remove(gtkconv->attach.timer);
7451 gtkconv->attach.timer = 0;
7452 if (im) {
7453 /* Print any message that was sent while the old history was being added back. */
7454 GList *msgs = NULL;
7455 GList *iter = gtkconv->convs;
7456 for (; iter; iter = iter->next) {
7457 PurpleConversation *conv = iter->data;
7458 GList *history = purple_conversation_get_message_history(conv);
7459 for (; history; history = history->next) {
7460 PurpleConvMessage *msg = history->data;
7461 if (msg->when > when)
7462 msgs = g_list_prepend(msgs, msg);
7463 }
7464 }
7465 msgs = g_list_sort(msgs, message_compare);
7466 for (; msgs; msgs = g_list_delete_link(msgs, msgs)) {
7467 PurpleConvMessage *msg = msgs->data;
7468 pidgin_conv_write_conv(msg->conv, msg->who, msg->who, msg->what, msg->flags, msg->when);
7469 }
7470 gtk_imhtml_append_text(GTK_IMHTML(gtkconv->imhtml), "<BR><HR>", 0);
7471 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL);
7472 }
7473
7423 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL); 7474 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", NULL);
7424 purple_signal_emit(pidgin_conversations_get_handle(), 7475 purple_signal_emit(pidgin_conversations_get_handle(),
7425 "conversation-displayed", gtkconv); 7476 "conversation-displayed", gtkconv);
7426 g_source_remove(gtkconv->attach.timer);
7427 gtkconv->attach.timer = 0;
7428 return FALSE; 7477 return FALSE;
7429 } 7478 }
7430 7479
7431 gboolean pidgin_conv_attach_to_conversation(PurpleConversation *conv) 7480 static void
7432 { 7481 pidgin_conv_attach(PurpleConversation *conv)
7433 GList *list; 7482 {
7434 PidginConversation *gtkconv;
7435 int timer; 7483 int timer;
7436
7437 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv))
7438 return FALSE;
7439
7440 purple_conversation_set_data(conv, "unseen-count", NULL); 7484 purple_conversation_set_data(conv, "unseen-count", NULL);
7441 purple_conversation_set_ui_ops(conv, pidgin_conversations_get_conv_ui_ops()); 7485 purple_conversation_set_ui_ops(conv, pidgin_conversations_get_conv_ui_ops());
7442 private_gtkconv_new(conv, FALSE); 7486 private_gtkconv_new(conv, FALSE);
7487 timer = GPOINTER_TO_INT(purple_conversation_get_data(conv, "close-timer"));
7488 if (timer)
7489 purple_timeout_remove(timer);
7490 }
7491
7492 gboolean pidgin_conv_attach_to_conversation(PurpleConversation *conv)
7493 {
7494 GList *list;
7495 PidginConversation *gtkconv;
7496
7497 if (PIDGIN_IS_PIDGIN_CONVERSATION(conv))
7498 return FALSE;
7499
7500 pidgin_conv_attach(conv);
7443 gtkconv = PIDGIN_CONVERSATION(conv); 7501 gtkconv = PIDGIN_CONVERSATION(conv);
7444 7502
7445 list = purple_conversation_get_message_history(conv); 7503 list = purple_conversation_get_message_history(conv);
7446 if (list) { 7504 if (list) {
7505 switch (purple_conversation_get_type(conv)) {
7506 case PURPLE_CONV_TYPE_IM:
7507 {
7508 GList *convs;
7509 list = g_list_copy(list);
7510 for (convs = purple_get_ims(); convs; convs = convs->next)
7511 if (convs->data != conv &&
7512 pidgin_conv_find_gtkconv(convs->data) == gtkconv) {
7513 pidgin_conv_attach(convs->data);
7514 list = g_list_concat(list, g_list_copy(purple_conversation_get_message_history(convs->data)));
7515 }
7516 list = g_list_sort(list, message_compare);
7517 gtkconv->attach.current = list;
7518 list = g_list_last(list);
7519 break;
7520 }
7521 case PURPLE_CONV_TYPE_CHAT:
7522 gtkconv->attach.current = g_list_last(list);
7523 break;
7524 default:
7525 g_return_val_if_reached(TRUE);
7526 }
7447 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time", 7527 g_object_set_data(G_OBJECT(gtkconv->entry), "attach-start-time",
7448 GINT_TO_POINTER(((PurpleConvMessage*)(list->data))->when)); 7528 GINT_TO_POINTER(((PurpleConvMessage*)(list->data))->when));
7449 gtkconv->attach.current = g_list_last(list);
7450 gtkconv->attach.timer = g_idle_add(add_message_history_to_gtkconv, gtkconv); 7529 gtkconv->attach.timer = g_idle_add(add_message_history_to_gtkconv, gtkconv);
7451 } else { 7530 } else {
7452 purple_signal_emit(pidgin_conversations_get_handle(), 7531 purple_signal_emit(pidgin_conversations_get_handle(),
7453 "conversation-displayed", gtkconv); 7532 "conversation-displayed", gtkconv);
7454 } 7533 }
7456 if (conv->type == PURPLE_CONV_TYPE_CHAT) { 7535 if (conv->type == PURPLE_CONV_TYPE_CHAT) {
7457 pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC); 7536 pidgin_conv_update_fields(conv, PIDGIN_CONV_TOPIC);
7458 pidgin_conv_chat_add_users(conv, PURPLE_CONV_CHAT(conv)->in_room, TRUE); 7537 pidgin_conv_chat_add_users(conv, PURPLE_CONV_CHAT(conv)->in_room, TRUE);
7459 } 7538 }
7460 7539
7461 timer = GPOINTER_TO_INT(purple_conversation_get_data(conv, "close-timer"));
7462 if (timer)
7463 purple_timeout_remove(timer);
7464 return TRUE; 7540 return TRUE;
7465 } 7541 }
7466 7542
7467 void * 7543 void *
7468 pidgin_conversations_get_handle(void) 7544 pidgin_conversations_get_handle(void)
9789 } 9865 }
9790 9866
9791 return colors; 9867 return colors;
9792 } 9868 }
9793 9869
9870

mercurial