finch/gntblist.c

changeset 39698
43d46d468694
parent 39696
2ed6dd895984
child 39759
ea1401483849
equal deleted inserted replaced
39697:cf34101b6910 39698:43d46d468694
372 372
373 return color; 373 return color;
374 } 374 }
375 375
376 static GntTextFormatFlags 376 static GntTextFormatFlags
377 get_blist_node_flag(PurpleBlistNode *node) 377 get_blist_node_flag(FinchBuddyList *ggblist, PurpleBlistNode *node)
378 { 378 {
379 GntTextFormatFlags flag = 0; 379 GntTextFormatFlags flag = 0;
380 FinchBlistNode *fnode = purple_blist_node_get_ui_data(node); 380 FinchBlistNode *fnode = purple_blist_node_get_ui_data(node);
381 381
382 if (ggblist->tagged && g_list_find(ggblist->tagged, node)) 382 if (ggblist->tagged && g_list_find(ggblist->tagged, node))
393 393
394 return flag; 394 return flag;
395 } 395 }
396 396
397 static void 397 static void
398 blist_update_row_flags(PurpleBlistNode *node) 398 blist_update_row_flags(FinchBuddyList *ggblist, PurpleBlistNode *node)
399 { 399 {
400 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), node, get_blist_node_flag(node)); 400 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), node,
401 get_blist_node_flag(ggblist, node));
401 gnt_tree_set_row_color(GNT_TREE(ggblist->tree), node, get_display_color(node)); 402 gnt_tree_set_row_color(GNT_TREE(ggblist->tree), node, get_display_color(node));
402 } 403 }
403 404
404 static void 405 static void
405 new_node(PurpleBuddyList *list, PurpleBlistNode *node) 406 new_node(PurpleBuddyList *list, PurpleBlistNode *node)
474 } 475 }
475 476
476 static void 477 static void
477 node_update(PurpleBuddyList *list, PurpleBlistNode *node) 478 node_update(PurpleBuddyList *list, PurpleBlistNode *node)
478 { 479 {
480 FinchBuddyList *ggblist;
481
479 g_return_if_fail(FINCH_IS_BUDDY_LIST(list)); 482 g_return_if_fail(FINCH_IS_BUDDY_LIST(list));
480 /* It really looks like this should never happen ... but it does. 483 /* It really looks like this should never happen ... but it does.
481 This will at least emit a warning to the log when it 484 This will at least emit a warning to the log when it
482 happens, so maybe someone will figure it out. */ 485 happens, so maybe someone will figure it out. */
483 g_return_if_fail(node != NULL); 486 g_return_if_fail(node != NULL);
484 487
488 ggblist = FINCH_BUDDY_LIST(list);
485 if (ggblist->window == NULL) 489 if (ggblist->window == NULL)
486 return; 490 return;
487 491
488 if (purple_blist_node_get_ui_data(node)!= NULL) { 492 if (purple_blist_node_get_ui_data(node)!= NULL) {
489 gnt_tree_change_text(GNT_TREE(ggblist->tree), node, 493 gnt_tree_change_text(GNT_TREE(ggblist->tree), node,
490 0, get_display_name(node)); 494 0, get_display_name(node));
491 gnt_tree_sort_row(GNT_TREE(ggblist->tree), node); 495 gnt_tree_sort_row(GNT_TREE(ggblist->tree), node);
492 blist_update_row_flags(node); 496 blist_update_row_flags(ggblist, node);
493 if (gnt_tree_get_parent_key(GNT_TREE(ggblist->tree), node) != 497 if (gnt_tree_get_parent_key(GNT_TREE(ggblist->tree), node) !=
494 ggblist->manager->find_parent(node)) 498 ggblist->manager->find_parent(node))
495 node_remove(list, node); 499 node_remove(list, node);
496 } 500 }
497 501
520 524
521 static gboolean 525 static gboolean
522 remove_new_empty_group(gpointer data) 526 remove_new_empty_group(gpointer data)
523 { 527 {
524 PurpleBuddyList *list; 528 PurpleBuddyList *list;
525 529 FinchBuddyList *ggblist;
526 if (!ggblist)
527 return FALSE;
528 530
529 list = purple_blist_get_default(); 531 list = purple_blist_get_default();
530 g_return_val_if_fail(list, FALSE); 532 g_return_val_if_fail(list, FALSE);
533 ggblist = FINCH_BUDDY_LIST(list);
531 534
532 ggblist->new_group_timeout = 0; 535 ggblist->new_group_timeout = 0;
533 while (ggblist->new_group) { 536 while (ggblist->new_group) {
534 PurpleBlistNode *group = ggblist->new_group->data; 537 PurpleBlistNode *group = ggblist->new_group->data;
535 ggblist->new_group = g_list_delete_link(ggblist->new_group, ggblist->new_group); 538 ggblist->new_group = g_list_delete_link(ggblist->new_group, ggblist->new_group);
721 fields, _("Add"), G_CALLBACK(add_chat_cb), _("Cancel"), NULL, 724 fields, _("Add"), G_CALLBACK(add_chat_cb), _("Cancel"), NULL,
722 NULL, NULL); 725 NULL, NULL);
723 } 726 }
724 727
725 static void 728 static void
726 add_group_cb(gpointer null, const char *group) 729 add_group_cb(FinchBuddyList *ggblist, const char *group)
727 { 730 {
728 PurpleGroup *grp; 731 PurpleGroup *grp;
729 732
730 if (!group || !*group) { 733 if (!group || !*group) {
731 purple_notify_error(NULL, _("Error"), _("Error adding group"), 734 purple_notify_error(NULL, _("Error"), _("Error adding group"),
732 _("You must give a name for the group to add."), NULL); 735 _("You must give a name for the group to add."), NULL);
736 g_object_unref(ggblist);
733 return; 737 return;
734 } 738 }
735 739
736 grp = purple_blist_find_group(group); 740 grp = purple_blist_find_group(group);
737 if (!grp) { 741 if (!grp) {
738 grp = purple_group_new(group); 742 grp = purple_group_new(group);
739 purple_blist_add_group(grp, NULL); 743 purple_blist_add_group(grp, NULL);
740 } 744 }
741
742 if (!ggblist)
743 return;
744 745
745 /* Treat the group as a new group even if it had existed before. This should 746 /* Treat the group as a new group even if it had existed before. This should
746 * make things easier to add buddies to empty groups (new or old) without having 747 * make things easier to add buddies to empty groups (new or old) without having
747 * to turn on 'show empty groups' setting */ 748 * to turn on 'show empty groups' setting */
748 ggblist->new_group = g_list_prepend(ggblist->new_group, grp); 749 ggblist->new_group = g_list_prepend(ggblist->new_group, grp);
756 FinchBlistNode *fnode = purple_blist_node_get_ui_data((PurpleBlistNode*)grp); 757 FinchBlistNode *fnode = purple_blist_node_get_ui_data((PurpleBlistNode*)grp);
757 if (!fnode) 758 if (!fnode)
758 add_node((PurpleBlistNode*)grp, ggblist); 759 add_node((PurpleBlistNode*)grp, ggblist);
759 gnt_tree_set_selected(GNT_TREE(ggblist->tree), grp); 760 gnt_tree_set_selected(GNT_TREE(ggblist->tree), grp);
760 } 761 }
762
763 g_object_unref(ggblist);
761 } 764 }
762 765
763 static void 766 static void
764 finch_request_add_group(PurpleBuddyList *list) 767 finch_request_add_group(PurpleBuddyList *list)
765 { 768 {
766 purple_request_input(NULL, _("Add Group"), NULL, _("Enter the name of the group"), 769 purple_request_input(NULL, _("Add Group"), NULL,
767 NULL, FALSE, FALSE, NULL, 770 _("Enter the name of the group"), NULL, FALSE,
768 _("Add"), G_CALLBACK(add_group_cb), _("Cancel"), NULL, 771 FALSE, NULL, _("Add"), G_CALLBACK(add_group_cb),
769 NULL, NULL); 772 _("Cancel"), G_CALLBACK(g_object_unref), NULL,
773 g_object_ref(list));
770 } 774 }
771 775
772 static gpointer 776 static gpointer
773 finch_blist_get_handle(void) 777 finch_blist_get_handle(void)
774 { 778 {
905 909
906 create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy, 910 create_finch_blist_node(node, gnt_tree_add_row_after(GNT_TREE(ggblist->tree), buddy,
907 gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)), 911 gnt_tree_create_row(GNT_TREE(ggblist->tree), get_display_name(node)),
908 parent, NULL)); 912 parent, NULL));
909 913
910 blist_update_row_flags((PurpleBlistNode*)buddy); 914 blist_update_row_flags(ggblist, (PurpleBlistNode *)buddy);
911 if (buddy == purple_contact_get_priority_buddy(contact)) 915 if (buddy == purple_contact_get_priority_buddy(contact)) {
912 blist_update_row_flags((PurpleBlistNode*)contact); 916 blist_update_row_flags(ggblist, (PurpleBlistNode *)contact);
917 }
913 } 918 }
914 919
915 static void 920 static void
916 selection_activate(GntWidget *widget, FinchBuddyList *ggblist) 921 selection_activate(GntWidget *widget, FinchBuddyList *ggblist)
917 { 922 {
1799 } 1804 }
1800 1805
1801 static void 1806 static void
1802 update_node_display(PurpleBlistNode *node, FinchBuddyList *ggblist) 1807 update_node_display(PurpleBlistNode *node, FinchBuddyList *ggblist)
1803 { 1808 {
1804 GntTextFormatFlags flag = get_blist_node_flag(node); 1809 GntTextFormatFlags flag = get_blist_node_flag(ggblist, node);
1805 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), node, flag); 1810 gnt_tree_set_row_flags(GNT_TREE(ggblist->tree), node, flag);
1806 } 1811 }
1807 1812
1808 static void 1813 static void
1809 update_buddy_display(PurpleBuddy *buddy, FinchBuddyList *ggblist) 1814 update_buddy_display(PurpleBuddy *buddy, FinchBuddyList *ggblist)
1813 contact = purple_buddy_get_contact(buddy); 1818 contact = purple_buddy_get_contact(buddy);
1814 1819
1815 gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, 0, get_display_name((PurpleBlistNode*)buddy)); 1820 gnt_tree_change_text(GNT_TREE(ggblist->tree), buddy, 0, get_display_name((PurpleBlistNode*)buddy));
1816 gnt_tree_change_text(GNT_TREE(ggblist->tree), contact, 0, get_display_name((PurpleBlistNode*)contact)); 1821 gnt_tree_change_text(GNT_TREE(ggblist->tree), contact, 0, get_display_name((PurpleBlistNode*)contact));
1817 1822
1818 blist_update_row_flags((PurpleBlistNode *)buddy); 1823 blist_update_row_flags(ggblist, (PurpleBlistNode *)buddy);
1819 if (buddy == purple_contact_get_priority_buddy(contact)) 1824 if (buddy == purple_contact_get_priority_buddy(contact))
1820 blist_update_row_flags((PurpleBlistNode *)contact); 1825 blist_update_row_flags(ggblist, (PurpleBlistNode *)contact);
1821 1826
1822 if (ggblist->tnode == (PurpleBlistNode*)buddy) 1827 if (ggblist->tnode == (PurpleBlistNode *)buddy) {
1823 draw_tooltip(ggblist); 1828 draw_tooltip(ggblist);
1829 }
1824 } 1830 }
1825 1831
1826 static void 1832 static void
1827 buddy_status_changed(PurpleBuddy *buddy, PurpleStatus *old, PurpleStatus *now, 1833 buddy_status_changed(PurpleBuddy *buddy, PurpleStatus *old, PurpleStatus *now,
1828 FinchBuddyList *ggblist) 1834 FinchBuddyList *ggblist)

mercurial