comparison src/conversation.c @ 10827:53e7884c549a

[gaim-migrate @ 12492] this should fix some problems with contact aware conversations, while possibly introducing new problems, and breaking some plugins. Someone needs to just remove GaimConvWindows all together. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Fri, 15 Apr 2005 22:32:00 +0000
parents 8d52201620d0
children c203cd637f95
comparison
equal deleted inserted replaced
10826:2a5fe8e67195 10827:53e7884c549a
258 258
259 g_free(displayed); 259 g_free(displayed);
260 g_free(sent); 260 g_free(sent);
261 } 261 }
262 262
263 static void
264 update_conv_indexes(GaimConvWindow *win)
265 {
266 GList *l;
267 int i;
268
269 for (l = gaim_conv_window_get_conversations(win), i = 0;
270 l != NULL;
271 l = l->next, i++) {
272
273 GaimConversation *conv = (GaimConversation *)l->data;
274
275 conv->conversation_pos = i;
276 }
277 }
278
279 GaimConvWindow * 263 GaimConvWindow *
280 gaim_conv_window_new(void) 264 gaim_conv_window_new(void)
281 { 265 {
282 GaimConvWindow *win; 266 GaimConvWindow *win;
283 267
474 ops = gaim_conv_window_get_ui_ops(win); 458 ops = gaim_conv_window_get_ui_ops(win);
475 459
476 win->conversations = g_list_append(win->conversations, conv); 460 win->conversations = g_list_append(win->conversations, conv);
477 win->conversation_count++; 461 win->conversation_count++;
478 462
479 conv->conversation_pos = win->conversation_count - 1;
480
481 if (ops != NULL) { 463 if (ops != NULL) {
482 conv->window = win; 464 conv->window = win;
483 465
484 if (ops->get_conversation_ui_ops != NULL) 466 if (ops->get_conversation_ui_ops != NULL)
485 gaim_conversation_set_ui_ops(conv, ops->get_conversation_ui_ops()); 467 gaim_conversation_set_ui_ops(conv, ops->get_conversation_ui_ops());
518 500
519 conv->window = NULL; 501 conv->window = NULL;
520 502
521 if (gaim_conv_window_get_conversation_count(win) == 0) 503 if (gaim_conv_window_get_conversation_count(win) == 0)
522 gaim_conv_window_destroy(win); 504 gaim_conv_window_destroy(win);
523 else {
524 /* Change all the indexes. */
525 update_conv_indexes(win);
526 }
527 505
528 return conv; 506 return conv;
529 }
530
531 void
532 gaim_conv_window_move_conversation(GaimConvWindow *win, unsigned int index,
533 unsigned int new_index)
534 {
535 GaimConvWindowUiOps *ops;
536 GaimConversation *conv;
537 GList *l;
538
539 g_return_if_fail(win != NULL);
540 g_return_if_fail(index < gaim_conv_window_get_conversation_count(win));
541 g_return_if_fail(index != new_index);
542
543 /* We can't move this past the last index. */
544 if (new_index > gaim_conv_window_get_conversation_count(win))
545 new_index = gaim_conv_window_get_conversation_count(win);
546
547 /* Get the list item for this conversation at its current index. */
548 l = g_list_nth(gaim_conv_window_get_conversations(win), index);
549
550 if (l == NULL) {
551 /* Should never happen. */
552 gaim_debug(GAIM_DEBUG_ERROR, "conversation",
553 "Misordered conversations list in window %p\n", win);
554
555 return;
556 }
557
558 conv = (GaimConversation *)l->data;
559
560 /* Update the UI part of this. */
561 ops = gaim_conv_window_get_ui_ops(win);
562
563 if (ops != NULL && ops->move_conversation != NULL)
564 ops->move_conversation(win, conv, new_index);
565
566 if (new_index > index)
567 new_index--;
568
569 /* Remove the old one. */
570 win->conversations = g_list_delete_link(win->conversations, l);
571
572 /* Insert it where it should go. */
573 win->conversations = g_list_insert(win->conversations, conv, new_index);
574
575 update_conv_indexes(win);
576 }
577
578 GaimConversation *
579 gaim_conv_window_get_conversation_at(const GaimConvWindow *win, unsigned int index)
580 {
581 g_return_val_if_fail(win != NULL, NULL);
582 g_return_val_if_fail(index >= 0 &&
583 index < gaim_conv_window_get_conversation_count(win),
584 NULL);
585
586 return (GaimConversation *)g_list_nth_data(
587 gaim_conv_window_get_conversations(win), index);
588 } 507 }
589 508
590 size_t 509 size_t
591 gaim_conv_window_get_conversation_count(const GaimConvWindow *win) 510 gaim_conv_window_get_conversation_count(const GaimConvWindow *win)
592 { 511 {
594 513
595 return win->conversation_count; 514 return win->conversation_count;
596 } 515 }
597 516
598 void 517 void
599 gaim_conv_window_switch_conversation(GaimConvWindow *win, unsigned int index) 518 gaim_conv_window_switch_conversation(GaimConvWindow *win, GaimConversation *conv)
600 { 519 {
601 GaimConvWindowUiOps *ops; 520 GaimConvWindowUiOps *ops;
602 GaimConversation *old_conv, *conv; 521 GaimConversation *old_conv;
603 522
604 g_return_if_fail(win != NULL); 523 g_return_if_fail(win != NULL);
605 g_return_if_fail(index >= 0 && 524 g_return_if_fail(conv != NULL);
606 index < gaim_conv_window_get_conversation_count(win));
607 525
608 old_conv = gaim_conv_window_get_active_conversation(win); 526 old_conv = gaim_conv_window_get_active_conversation(win);
609 conv = gaim_conv_window_get_conversation_at(win, index);
610 527
611 gaim_signal_emit(gaim_conversations_get_handle(), 528 gaim_signal_emit(gaim_conversations_get_handle(),
612 "conversation-switching", old_conv, conv); 529 "conversation-switching", old_conv, conv);
613 530
614 ops = gaim_conv_window_get_ui_ops(win); 531 ops = gaim_conv_window_get_ui_ops(win);
615 532
616 if (ops != NULL && ops->switch_conversation != NULL) 533 if (ops != NULL && ops->switch_conversation != NULL)
617 ops->switch_conversation(win, index); 534 ops->switch_conversation(win, conv);
618 535
619 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); 536 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE);
620 537
621 gaim_signal_emit(gaim_conversations_get_handle(), 538 gaim_signal_emit(gaim_conversations_get_handle(),
622 "conversation-switched", old_conv, conv); 539 "conversation-switched", old_conv, conv);
632 if (gaim_conv_window_get_conversation_count(win) == 0) 549 if (gaim_conv_window_get_conversation_count(win) == 0)
633 return NULL; 550 return NULL;
634 551
635 ops = gaim_conv_window_get_ui_ops(win); 552 ops = gaim_conv_window_get_ui_ops(win);
636 553
637 if (ops != NULL && ops->get_active_index != NULL) 554 if (ops != NULL && ops->get_active_conversation != NULL)
638 return gaim_conv_window_get_conversation_at(win, ops->get_active_index(win)); 555 return ops->get_active_conversation(win);
639 556
640 return NULL; 557 return NULL;
641 } 558 }
642 559
643 GList * 560 GList *
1177 text = name; 1094 text = name;
1178 1095
1179 gaim_conversation_set_title(conv, text); 1096 gaim_conversation_set_title(conv, text);
1180 } 1097 }
1181 1098
1182 int
1183 gaim_conversation_get_index(const GaimConversation *conv)
1184 {
1185 g_return_val_if_fail(conv != NULL, 0);
1186
1187 return conv->conversation_pos;
1188 }
1189
1190 void 1099 void
1191 gaim_conversation_set_unseen(GaimConversation *conv, GaimUnseenState state) 1100 gaim_conversation_set_unseen(GaimConversation *conv, GaimUnseenState state)
1192 { 1101 {
1193 g_return_if_fail(conv != NULL); 1102 g_return_if_fail(conv != NULL);
1194 1103
1732 /* 1641 /*
1733 * Change the active conversation to this conversation unless the 1642 * Change the active conversation to this conversation unless the
1734 * user is already using this window. 1643 * user is already using this window.
1735 */ 1644 */
1736 if (!gaim_conv_window_has_focus(window)) 1645 if (!gaim_conv_window_has_focus(window))
1737 gaim_conv_window_switch_conversation(window, gaim_conversation_get_index(conv)); 1646 gaim_conv_window_switch_conversation(window, conv);
1738 1647
1739 gaim_conv_window_raise(window); 1648 gaim_conv_window_raise(window);
1740 1649
1741 return TRUE; 1650 return TRUE;
1742 } 1651 }