comparison pidgin/gtkblist.c @ 25313:12e258fb6f3c

Got about a third of the gtkblist.c direct struct usage, much more to go obviously, but i must sleep...
author Gary Kramlich <grim@reaperworld.com>
date Mon, 03 Nov 2008 04:48:50 +0000
parents 43aeab2bb50e
children 0e08c847517d
comparison
equal deleted inserted replaced
25312:2b8c85f74ede 25313:12e258fb6f3c
323 return FALSE; 323 return FALSE;
324 } 324 }
325 325
326 static void gtk_blist_menu_info_cb(GtkWidget *w, PurpleBuddy *b) 326 static void gtk_blist_menu_info_cb(GtkWidget *w, PurpleBuddy *b)
327 { 327 {
328 pidgin_retrieve_user_info(b->account->gc, purple_buddy_get_name(b)); 328 PurpleAccount *account = purple_buddy_get_account(b);
329
330 pidgin_retrieve_user_info(purple_account_get_connection(account),
331 purple_buddy_get_name(b));
329 } 332 }
330 333
331 static void gtk_blist_menu_im_cb(GtkWidget *w, PurpleBuddy *b) 334 static void gtk_blist_menu_im_cb(GtkWidget *w, PurpleBuddy *b)
332 { 335 {
333 pidgin_dialogs_im_with_user(b->account, b->name); 336 pidgin_dialogs_im_with_user(purple_buddy_get_account(b),
337 purple_buddy_get_name(b));
334 } 338 }
335 339
336 static void gtk_blist_menu_send_file_cb(GtkWidget *w, PurpleBuddy *b) 340 static void gtk_blist_menu_send_file_cb(GtkWidget *w, PurpleBuddy *b)
337 { 341 {
338 serv_send_file(b->account->gc, b->name, NULL); 342 PurpleAccount *account = purple_buddy_get_account(b);
343
344 serv_send_file(purple_account_get_connection(account),
345 purple_buddy_get_name(b), NULL);
339 } 346 }
340 347
341 static void gtk_blist_menu_move_to_cb(GtkWidget *w, PurpleBlistNode *node) 348 static void gtk_blist_menu_move_to_cb(GtkWidget *w, PurpleBlistNode *node)
342 { 349 {
343 PurpleGroup *group = g_object_get_data(G_OBJECT(w), "groupnode"); 350 PurpleGroup *group = g_object_get_data(G_OBJECT(w), "groupnode");
358 } 365 }
359 366
360 static PurpleConversation * 367 static PurpleConversation *
361 find_conversation_with_buddy(PurpleBuddy *buddy) 368 find_conversation_with_buddy(PurpleBuddy *buddy)
362 { 369 {
363 PidginBlistNode *ui = buddy->node.ui_data; 370 PidginBlistNode *ui = purple_blist_node_get_ui_data(PURPLE_BLIST_NODE(buddy));
364 if (ui) 371 if (ui)
365 return ui->conv.conv; 372 return ui->conv.conv;
366 return purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, 373 return purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM,
367 purple_buddy_get_name(buddy), 374 purple_buddy_get_name(buddy),
368 purple_buddy_get_account(buddy)); 375 purple_buddy_get_account(buddy));
369 } 376 }
370 377
371 static void gtk_blist_join_chat(PurpleChat *chat) 378 static void gtk_blist_join_chat(PurpleChat *chat)
372 { 379 {
380 PurpleAccount *account;
373 PurpleConversation *conv; 381 PurpleConversation *conv;
374 PurplePluginProtocolInfo *prpl_info; 382 PurplePluginProtocolInfo *prpl_info;
383 GHashTable *components;
375 const char *name; 384 const char *name;
376 char *chat_name; 385 char *chat_name;
377 386
378 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(chat->account))); 387 account = purple_chat_get_account(chat);
388 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(account)));
389
390 components = purple_chat_get_components(chat);
379 391
380 if (prpl_info && prpl_info->get_chat_name) 392 if (prpl_info && prpl_info->get_chat_name)
381 chat_name = prpl_info->get_chat_name(chat->components); 393 chat_name = prpl_info->get_chat_name(components);
382 else 394 else
383 chat_name = NULL; 395 chat_name = NULL;
384 396
385 if (chat_name) 397 if (chat_name)
386 name = chat_name; 398 name = chat_name;
387 else 399 else
388 name = purple_chat_get_name(chat); 400 name = purple_chat_get_name(chat);
389 401
390 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, name, 402 conv = purple_find_conversation_with_account(PURPLE_CONV_TYPE_CHAT, name,
391 chat->account); 403 account);
392 404
393 if (conv != NULL) { 405 if (conv != NULL) {
394 pidgin_conv_attach_to_conversation(conv); 406 pidgin_conv_attach_to_conversation(conv);
395 purple_conversation_present(conv); 407 purple_conversation_present(conv);
396 } 408 }
397 409
398 serv_join_chat(chat->account->gc, chat->components); 410 serv_join_chat(purple_account_get_connection(account), components);
399 g_free(chat_name); 411 g_free(chat_name);
400 } 412 }
401 413
402 static void gtk_blist_menu_join_cb(GtkWidget *w, PurpleChat *chat) 414 static void gtk_blist_menu_join_cb(GtkWidget *w, PurpleChat *chat)
403 { 415 {
428 gtk_tree_path_free (path); 440 gtk_tree_path_free (path);
429 val.g_type = 0; 441 val.g_type = 0;
430 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); 442 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val);
431 node = g_value_get_pointer(&val); 443 node = g_value_get_pointer(&val);
432 444
433 switch (node->type) { 445 switch (purple_blist_node_get_type(node)) {
434 case PURPLE_BLIST_CONTACT_NODE: 446 case PURPLE_BLIST_CONTACT_NODE:
435 text = purple_contact_get_alias((PurpleContact *)node); 447 text = purple_contact_get_alias(PURPLE_CONTACT(node));
436 break; 448 break;
437 case PURPLE_BLIST_BUDDY_NODE: 449 case PURPLE_BLIST_BUDDY_NODE:
438 text = purple_buddy_get_alias((PurpleBuddy *)node); 450 text = purple_buddy_get_alias(PURPLE_BUDDY(node));
439 break; 451 break;
440 case PURPLE_BLIST_GROUP_NODE: 452 case PURPLE_BLIST_GROUP_NODE:
441 text = ((PurpleGroup *)node)->name; 453 text = purple_group_get_name(PURPLE_GROUP(node));
442 break; 454 break;
443 default: 455 default:
444 g_return_if_reached(); 456 g_return_if_reached();
445 } 457 }
446 458
464 * by which contact is higher in the list 476 * by which contact is higher in the list
465 */ 477 */
466 for (tmp = merges; tmp; tmp = tmp->next) { 478 for (tmp = merges; tmp; tmp = tmp->next) {
467 PurpleBlistNode *node = tmp->data; 479 PurpleBlistNode *node = tmp->data;
468 PurpleBlistNode *b; 480 PurpleBlistNode *b;
481 PurpleBlistNodeType type;
469 int i = 0; 482 int i = 0;
470 483
471 if (node->type == PURPLE_BLIST_BUDDY_NODE) 484 type = purple_blist_node_get_type(node);
472 node = node->parent; 485
473 486 if(type == PURPLE_BLIST_BUDDY_NODE)
474 if (node->type != PURPLE_BLIST_CONTACT_NODE) 487 node = purple_blist_node_get_parent(node);
488
489 if(type == PURPLE_BLIST_CONTACT_NODE)
475 continue; 490 continue;
476 491
477 492 for (b = purple_blist_node_get_first_child(node);
478 for (b = node->child; b; b = b->next) 493 b;
494 b = purple_blist_node_get_sibling_next(b))
495 {
479 i++; 496 i++;
497 }
498
480 if (i > max) { 499 if (i > max) {
481 contact = node; 500 contact = node;
482 max = i; 501 max = i;
483 } 502 }
484 } 503 }
487 return; 506 return;
488 507
489 /* Merge all those buddies into this contact */ 508 /* Merge all those buddies into this contact */
490 for (tmp = merges; tmp; tmp = tmp->next) { 509 for (tmp = merges; tmp; tmp = tmp->next) {
491 PurpleBlistNode *node = tmp->data; 510 PurpleBlistNode *node = tmp->data;
492 if (node->type == PURPLE_BLIST_BUDDY_NODE) 511 if (purple_blist_node_get_type(node) == PURPLE_BLIST_BUDDY_NODE)
493 node = node->parent; 512 node = purple_blist_node_get_parent(node);
494 513
495 if (node == contact) 514 if (node == contact)
496 continue; 515 continue;
497 516
498 purple_blist_merge_contact((PurpleContact *)node, contact); 517 purple_blist_merge_contact((PurpleContact *)node, contact);
526 g_free(node_alias); 545 g_free(node_alias);
527 continue; 546 continue;
528 } 547 }
529 g_free(node_alias); 548 g_free(node_alias);
530 549
531 for (buddy = contact->child; buddy; buddy = buddy->next) { 550 for (buddy = purple_blist_node_get_first_child(contact);
532 if (buddy->type != PURPLE_BLIST_BUDDY_NODE) 551 buddy;
552 buddy = purple_blist_node_get_sibling_next(buddy))
553 {
554 if (purple_blist_node_get_type(buddy) != PURPLE_BLIST_BUDDY_NODE)
533 continue; 555 continue;
534 556
535 node_alias = g_utf8_casefold(purple_buddy_get_alias((PurpleBuddy *)buddy), -1); 557 node_alias = g_utf8_casefold(purple_buddy_get_alias(PURPLE_BUDDY(buddy)), -1);
536 if (node_alias && !g_utf8_collate(node_alias, a)) { 558 if (node_alias && !g_utf8_collate(node_alias, a)) {
537 merges = g_list_append(merges, buddy); 559 merges = g_list_append(merges, buddy);
538 i++; 560 i++;
539 g_free(node_alias); 561 g_free(node_alias);
540 break; 562 break;
572 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val); 594 gtk_tree_model_get_value (GTK_TREE_MODEL(gtkblist->treemodel), &iter, NODE_COLUMN, &val);
573 node = g_value_get_pointer(&val); 595 node = g_value_get_pointer(&val);
574 gtk_tree_view_set_enable_search (GTK_TREE_VIEW(gtkblist->treeview), TRUE); 596 gtk_tree_view_set_enable_search (GTK_TREE_VIEW(gtkblist->treeview), TRUE);
575 g_object_set(G_OBJECT(gtkblist->text_rend), "editable", FALSE, NULL); 597 g_object_set(G_OBJECT(gtkblist->text_rend), "editable", FALSE, NULL);
576 598
577 switch (node->type) 599 switch (purple_blist_node_get_type(node))
578 { 600 {
579 case PURPLE_BLIST_CONTACT_NODE: 601 case PURPLE_BLIST_CONTACT_NODE:
580 { 602 {
581 PurpleContact *contact = (PurpleContact *)node; 603 PurpleContact *contact = PURPLE_CONTACT(node);
582 struct _pidgin_blist_node *gtknode = (struct _pidgin_blist_node *)node->ui_data; 604 struct _pidgin_blist_node *gtknode =
583 605 (struct _pidgin_blist_node *)purple_blist_node_get_ui_data(node);
584 if (contact->alias || gtknode->contact_expanded) { 606
607 if (purple_contact_get_alias(contact) || gtknode->contact_expanded) {
585 purple_blist_alias_contact(contact, arg2); 608 purple_blist_alias_contact(contact, arg2);
586 gtk_blist_auto_personize(node->parent, arg2); 609 gtk_blist_auto_personize(purple_blist_node_get_parent(node), arg2);
587 } else { 610 } else {
588 PurpleBuddy *buddy = purple_contact_get_priority_buddy(contact); 611 PurpleBuddy *buddy = purple_contact_get_priority_buddy(contact);
589 purple_blist_alias_buddy(buddy, arg2); 612 purple_blist_alias_buddy(buddy, arg2);
590 serv_alias_buddy(buddy); 613 serv_alias_buddy(buddy);
591 gtk_blist_auto_personize(node->parent, arg2); 614 gtk_blist_auto_personize(purple_blist_node_get_parent(node), arg2);
592 } 615 }
593 } 616 }
594 break; 617 break;
595 618
596 case PURPLE_BLIST_BUDDY_NODE: 619 case PURPLE_BLIST_BUDDY_NODE:
597 purple_blist_alias_buddy((PurpleBuddy*)node, arg2); 620 {
598 serv_alias_buddy((PurpleBuddy *)node); 621 PurpleGroup *group = purple_buddy_get_group(PURPLE_BUDDY(node));
599 gtk_blist_auto_personize(node->parent->parent, arg2); 622
623 purple_blist_alias_buddy(PURPLE_BUDDY(node), arg2);
624 serv_alias_buddy(PURPLE_BUDDY(node));
625 gtk_blist_auto_personize(PURPLE_BLIST_NODE(group), arg2);
626 }
600 break; 627 break;
601 case PURPLE_BLIST_GROUP_NODE: 628 case PURPLE_BLIST_GROUP_NODE:
602 dest = purple_find_group(arg2); 629 dest = purple_find_group(arg2);
603 if (dest != NULL && strcmp(arg2, ((PurpleGroup*) node)->name)) { 630 if (dest != NULL && strcmp(arg2, purple_group_get_name(PURPLE_GROUP(node)))) {
604 pidgin_dialogs_merge_groups((PurpleGroup*) node, arg2); 631 pidgin_dialogs_merge_groups(PURPLE_GROUP(node), arg2);
605 } else 632 } else {
606 purple_blist_rename_group((PurpleGroup*)node, arg2); 633 purple_blist_rename_group(PURPLE_GROUP(node), arg2);
634 }
607 break; 635 break;
608 case PURPLE_BLIST_CHAT_NODE: 636 case PURPLE_BLIST_CHAT_NODE:
609 purple_blist_alias_chat((PurpleChat*)node, arg2); 637 purple_blist_alias_chat(PURPLE_CHAT(node), arg2);
610 break; 638 break;
611 default: 639 default:
612 break; 640 break;
613 } 641 }
614 pidgin_blist_refresh(list); 642 pidgin_blist_refresh(list);
691 GtkTreeIter iter; 719 GtkTreeIter iter;
692 GtkTreePath *path; 720 GtkTreePath *path;
693 721
694 if (!(get_iter_from_node(node, &iter))) { 722 if (!(get_iter_from_node(node, &iter))) {
695 /* This is either a bug, or the buddy is in a collapsed contact */ 723 /* This is either a bug, or the buddy is in a collapsed contact */
696 node = node->parent; 724 node = purple_blist_node_get_parent(node);
697 if (!get_iter_from_node(node, &iter)) 725 if (!get_iter_from_node(node, &iter))
698 /* Now it's definitely a bug */ 726 /* Now it's definitely a bug */
699 return; 727 return;
700 } 728 }
701 729
714 gtk_tree_path_free(path); 742 gtk_tree_path_free(path);
715 } 743 }
716 744
717 static void gtk_blist_menu_bp_cb(GtkWidget *w, PurpleBuddy *b) 745 static void gtk_blist_menu_bp_cb(GtkWidget *w, PurpleBuddy *b)
718 { 746 {
719 pidgin_pounce_editor_show(b->account, b->name, NULL); 747 pidgin_pounce_editor_show(purple_buddy_get_account(b),
748 purple_buddy_get_name(b), NULL);
720 } 749 }
721 750
722 static void gtk_blist_menu_showlog_cb(GtkWidget *w, PurpleBlistNode *node) 751 static void gtk_blist_menu_showlog_cb(GtkWidget *w, PurpleBlistNode *node)
723 { 752 {
724 PurpleLogType type; 753 PurpleLogType type;
728 pidgin_set_cursor(gtkblist->window, GDK_WATCH); 757 pidgin_set_cursor(gtkblist->window, GDK_WATCH);
729 758
730 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) { 759 if (PURPLE_BLIST_NODE_IS_BUDDY(node)) {
731 PurpleBuddy *b = (PurpleBuddy*) node; 760 PurpleBuddy *b = (PurpleBuddy*) node;
732 type = PURPLE_LOG_IM; 761 type = PURPLE_LOG_IM;
733 name = g_strdup(b->name); 762 name = g_strdup(purple_buddy_get_name(b));
734 account = b->account; 763 account = purple_buddy_get_account(b);
735 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) { 764 } else if (PURPLE_BLIST_NODE_IS_CHAT(node)) {
736 PurpleChat *c = (PurpleChat*) node; 765 PurpleChat *c = PURPLE_CHAT(node);
737 PurplePluginProtocolInfo *prpl_info = NULL; 766 PurplePluginProtocolInfo *prpl_info = NULL;
738 type = PURPLE_LOG_CHAT; 767 type = PURPLE_LOG_CHAT;
739 account = c->account; 768 account = purple_chat_get_account(c);
740 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(account))); 769 prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(purple_find_prpl(purple_account_get_protocol_id(account)));
741 if (prpl_info && prpl_info->get_chat_name) { 770 if (prpl_info && prpl_info->get_chat_name) {
742 name = prpl_info->get_chat_name(c->components); 771 name = prpl_info->get_chat_name(purple_chat_get_components(c));
743 } 772 }
744 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) { 773 } else if (PURPLE_BLIST_NODE_IS_CONTACT(node)) {
745 pidgin_log_show_contact((PurpleContact *)node); 774 pidgin_log_show_contact(PURPLE_CONTACT(node));
746 pidgin_clear_cursor(gtkblist->window); 775 pidgin_clear_cursor(gtkblist->window);
747 return; 776 return;
748 } else { 777 } else {
749 pidgin_clear_cursor(gtkblist->window); 778 pidgin_clear_cursor(gtkblist->window);
750 779
773 { 802 {
774 PurpleBlistNode *bnode; 803 PurpleBlistNode *bnode;
775 gboolean setting = !purple_blist_node_get_bool(node, "show_offline"); 804 gboolean setting = !purple_blist_node_get_bool(node, "show_offline");
776 805
777 purple_blist_node_set_bool(node, "show_offline", setting); 806 purple_blist_node_set_bool(node, "show_offline", setting);
778 for (bnode = node->child; bnode != NULL; bnode = bnode->next) { 807 for (bnode = purple_blist_node_get_first_child(node);
808 bnode != NULL;
809 bnode = purple_blist_node_get_sibling_next(bnode))
810 {
779 purple_blist_node_set_bool(bnode, "show_offline", setting); 811 purple_blist_node_set_bool(bnode, "show_offline", setting);
780 pidgin_blist_update(purple_get_blist(), bnode); 812 pidgin_blist_update(purple_get_blist(), bnode);
781 } 813 }
782 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) { 814 } else if (PURPLE_BLIST_NODE_IS_GROUP(node)) {
783 PurpleBlistNode *cnode, *bnode; 815 PurpleBlistNode *cnode, *bnode;
784 gboolean setting = !purple_blist_node_get_bool(node, "show_offline"); 816 gboolean setting = !purple_blist_node_get_bool(node, "show_offline");
785 817
786 purple_blist_node_set_bool(node, "show_offline", setting); 818 purple_blist_node_set_bool(node, "show_offline", setting);
787 for (cnode = node->child; cnode != NULL; cnode = cnode->next) { 819 for (cnode = purple_blist_node_get_first_child(node);
820 cnode != NULL;
821 cnode = purple_blist_node_get_sibling_next(cnode))
822 {
788 purple_blist_node_set_bool(cnode, "show_offline", setting); 823 purple_blist_node_set_bool(cnode, "show_offline", setting);
789 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next) { 824 for (bnode = purple_blist_node_get_first_child(cnode);
825 bnode != NULL;
826 bnode = purple_blist_node_get_sibling_next(bnode))
827 {
790 purple_blist_node_set_bool(bnode, "show_offline", setting); 828 purple_blist_node_set_bool(bnode, "show_offline", setting);
791 pidgin_blist_update(purple_get_blist(), bnode); 829 pidgin_blist_update(purple_get_blist(), bnode);
792 } 830 }
793 } 831 }
794 } 832 }
896 } 934 }
897 935
898 static void 936 static void
899 pidgin_blist_update_privacy_cb(PurpleBuddy *buddy) 937 pidgin_blist_update_privacy_cb(PurpleBuddy *buddy)
900 { 938 {
901 if (buddy->node.ui_data == NULL || ((struct _pidgin_blist_node*)buddy->node.ui_data)->row == NULL) 939 struct _pidgin_blist_node *ui_data = purple_blist_node_get_ui_data(PURPLE_BLIST_NODE(buddy));
940 if (ui_data == NULL || ui_data->row == NULL)
902 return; 941 return;
903 pidgin_blist_update_buddy(purple_get_blist(), (PurpleBlistNode*)(buddy), TRUE); 942 pidgin_blist_update_buddy(purple_get_blist(), PURPLE_BLIST_NODE(buddy), TRUE);
904 } 943 }
905 944
906 static void 945 static void
907 rebuild_joinchat_entries(PidginJoinChatData *data) 946 rebuild_joinchat_entries(PidginJoinChatData *data)
908 { 947 {
1026 GtkWidget *label; 1065 GtkWidget *label;
1027 PidginBuddyList *gtkblist; 1066 PidginBuddyList *gtkblist;
1028 GtkWidget *img = NULL; 1067 GtkWidget *img = NULL;
1029 PidginJoinChatData *data = NULL; 1068 PidginJoinChatData *data = NULL;
1030 1069
1031 gtkblist = PIDGIN_BLIST(purple_get_blist()); 1070 gtkblist = purple_blist_get_ui_data();
1032 img = gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION, 1071 img = gtk_image_new_from_stock(PIDGIN_STOCK_DIALOG_QUESTION,
1033 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE)); 1072 gtk_icon_size_from_name(PIDGIN_ICON_SIZE_TANGO_HUGE));
1034 data = g_new0(PidginJoinChatData, 1); 1073 data = g_new0(PidginJoinChatData, 1);
1035 1074
1036 data->window = gtk_dialog_new_with_buttons(_("Join a Chat"), 1075 data->window = gtk_dialog_new_with_buttons(_("Join a Chat"),