comparison src/buddy_chat.c @ 2956:b68c648618a3

[gaim-migrate @ 2969] I Love Rock & Roll.... committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Sun, 17 Feb 2002 18:08:12 +0000
parents 019d7462337b
children 4f2f12bf4408
comparison
equal deleted inserted replaced
2955:8b03506b8c1e 2956:b68c648618a3
806 ignore_callback(obj, b); 806 ignore_callback(obj, b);
807 } 807 }
808 808
809 static void chat_press_info(GtkObject *obj, struct conversation *b) 809 static void chat_press_info(GtkObject *obj, struct conversation *b)
810 { 810 {
811 if (b->gc) 811 if (b->gc) {
812 b->gc->prpl->get_info(b->gc, gtk_object_get_user_data(obj)); 812 /*
813 * If there are special needs for getting info on users in
814 * buddy chat "rooms"...
815 */
816 if(b->gc->prpl->get_cb_info != NULL) {
817 b->gc->prpl->get_cb_info(b->gc, b->id, gtk_object_get_user_data(obj));
818 } else {
819 b->gc->prpl->get_info(b->gc, gtk_object_get_user_data(obj));
820 }
821 }
822 }
823
824
825 static void chat_press_away(GtkObject *obj, struct conversation *b)
826 {
827 if (b->gc) {
828 /*
829 * May want to expand this to work similarly to chat_press_info?
830 */
831 if(b->gc->prpl->get_cb_away != NULL) {
832 b->gc->prpl->get_cb_away(b->gc, b->id, gtk_object_get_user_data(obj));
833 }
834 }
813 } 835 }
814 836
815 static gint right_click_chat(GtkObject *obj, GdkEventButton *event, struct conversation *b) 837 static gint right_click_chat(GtkObject *obj, GdkEventButton *event, struct conversation *b)
816 { 838 {
817 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) { 839 if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) {
847 gtk_object_set_user_data(GTK_OBJECT(button), gtk_object_get_user_data(obj)); 869 gtk_object_set_user_data(GTK_OBJECT(button), gtk_object_get_user_data(obj));
848 gtk_menu_append(GTK_MENU(menu), button); 870 gtk_menu_append(GTK_MENU(menu), button);
849 gtk_widget_show(button); 871 gtk_widget_show(button);
850 } 872 }
851 873
874 if (b->gc && b->gc->prpl->get_cb_away) {
875 button = gtk_menu_item_new_with_label(_("Get Away Msg"));
876 gtk_signal_connect(GTK_OBJECT(button), "activate",
877 GTK_SIGNAL_FUNC(chat_press_away), b);
878 gtk_object_set_user_data(GTK_OBJECT(button), gtk_object_get_user_data(obj));
879 gtk_menu_append(GTK_MENU(menu), button);
880 gtk_widget_show(button);
881 }
882
852 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); 883 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time);
853 return TRUE; 884 return TRUE;
854 } 885 }
855 return TRUE; 886 return TRUE;
856 } 887 }
857 888
889 /*
890 * Common code for adding a chat buddy to the list
891 */
892 static void add_chat_buddy_common(struct conversation *b, char *name, int pos)
893 {
894 char tmp[BUF_LONG];
895 GtkWidget *list_item;
896
897 if (ignored(b, name)) {
898 g_snprintf(tmp, sizeof(tmp), "X %s", name);
899 list_item = gtk_list_item_new_with_label(tmp);
900 } else
901 list_item = gtk_list_item_new_with_label(name);
902
903 gtk_object_set_user_data(GTK_OBJECT(list_item), name);
904 gtk_signal_connect(GTK_OBJECT(list_item), "button_press_event",
905 GTK_SIGNAL_FUNC(right_click_chat), b);
906 gtk_list_insert_items(GTK_LIST(b->list), g_list_append(NULL, list_item), pos);
907 gtk_widget_show(list_item);
908 }
909
858 void add_chat_buddy(struct conversation *b, char *buddy) 910 void add_chat_buddy(struct conversation *b, char *buddy)
859 { 911 {
860 char *name = g_strdup(buddy); 912 char *name = g_strdup(buddy);
861 char tmp[BUF_LONG]; 913 char tmp[BUF_LONG];
862 GtkWidget *list_item;
863 int pos; 914 int pos;
864 915
865 plugin_event(event_chat_buddy_join, b->gc, (void *)b->id, name, 0); 916 plugin_event(event_chat_buddy_join, b->gc, (void *)b->id, name, 0);
866 b->in_room = g_list_insert_sorted(b->in_room, name, insertname); 917 b->in_room = g_list_insert_sorted(b->in_room, name, insertname);
867 pos = g_list_index(b->in_room, name); 918 pos = g_list_index(b->in_room, name);
868 919
869 if (ignored(b, buddy)) { 920 add_chat_buddy_common(b, name, pos);
870 g_snprintf(tmp, sizeof(tmp), "X %s", name);
871 list_item = gtk_list_item_new_with_label(tmp);
872 } else
873 list_item = gtk_list_item_new_with_label(name);
874
875 gtk_object_set_user_data(GTK_OBJECT(list_item), name);
876 gtk_signal_connect(GTK_OBJECT(list_item), "button_press_event",
877 GTK_SIGNAL_FUNC(right_click_chat), b);
878 gtk_list_insert_items(GTK_LIST(b->list), g_list_append(NULL, list_item), pos);
879 gtk_widget_show(list_item);
880 921
881 g_snprintf(tmp, sizeof(tmp), _("%d %s in room"), g_list_length(b->in_room), 922 g_snprintf(tmp, sizeof(tmp), _("%d %s in room"), g_list_length(b->in_room),
882 g_list_length(b->in_room) == 1 ? "person" : "people"); 923 g_list_length(b->in_room) == 1 ? "person" : "people");
883 gtk_label_set_text(GTK_LABEL(b->count), tmp); 924 gtk_label_set_text(GTK_LABEL(b->count), tmp);
884 925
896 { 937 {
897 GList *names = b->in_room; 938 GList *names = b->in_room;
898 GList *items = GTK_LIST(b->list)->children; 939 GList *items = GTK_LIST(b->list)->children;
899 940
900 char *name = g_strdup(new); 941 char *name = g_strdup(new);
901 GtkWidget *list_item;
902 char *ign; 942 char *ign;
903 int pos; 943 int pos;
904 944
905 char tmp[BUF_LONG]; 945 char tmp[BUF_LONG];
906 946
938 978
939 /* we haven't added them yet. if we find them, don't add them again */ 979 /* we haven't added them yet. if we find them, don't add them again */
940 if (!ignored(b, new)) 980 if (!ignored(b, new))
941 b->ignored = g_list_append(b->ignored, g_strdup(name)); 981 b->ignored = g_list_append(b->ignored, g_strdup(name));
942 982
943 g_snprintf(tmp, sizeof(tmp), "X %s", name);
944 list_item = gtk_list_item_new_with_label(tmp);
945 } else { 983 } else {
946 if ((ign = ignored(b, new)) != NULL) { 984 if ((ign = ignored(b, new)) != NULL) {
947 /* if they weren't ignored and change to someone who is ignored, 985 /* if they weren't ignored and change to someone who is ignored,
948 * assume it's someone else. that may seem a little backwards but 986 * assume it's someone else. that may seem a little backwards but
949 * it's better when it *is* actually someone else. Sorry Sean. */ 987 * it's better when it *is* actually someone else. Sorry Sean. */
950 g_free(ign); 988 g_free(ign);
951 b->ignored = g_list_remove(b->ignored, ign); 989 b->ignored = g_list_remove(b->ignored, ign);
952 } 990 }
953 list_item = gtk_list_item_new_with_label(name); 991 }
954 } 992
955 993 add_chat_buddy_common(b, name, pos);
956 gtk_object_set_user_data(GTK_OBJECT(list_item), name);
957 gtk_signal_connect(GTK_OBJECT(list_item), "button_press_event",
958 GTK_SIGNAL_FUNC(right_click_chat), b);
959 gtk_list_insert_items(GTK_LIST(b->list), g_list_append(NULL, list_item), pos);
960 gtk_widget_show(list_item);
961 994
962 if (chat_options & OPT_CHAT_LOGON) { 995 if (chat_options & OPT_CHAT_LOGON) {
963 g_snprintf(tmp, sizeof(tmp), _("%s is now known as %s"), old, new); 996 g_snprintf(tmp, sizeof(tmp), _("%s is now known as %s"), old, new);
964 write_to_conv(b, tmp, WFLAG_SYSTEM, NULL, time(NULL), -1); 997 write_to_conv(b, tmp, WFLAG_SYSTEM, NULL, time(NULL), -1);
965 } 998 }
1048 { 1081 {
1049 char *name; 1082 char *name;
1050 GList *i; 1083 GList *i;
1051 char *ign; 1084 char *ign;
1052 int pos; 1085 int pos;
1053 GtkWidget *list_item;
1054 char tmp[80];
1055 1086
1056 i = GTK_LIST(b->list)->selection; 1087 i = GTK_LIST(b->list)->selection;
1057 if (i) { 1088 if (i) {
1058 name = (char *)gtk_object_get_user_data(GTK_OBJECT(i->data)); 1089 name = (char *)gtk_object_get_user_data(GTK_OBJECT(i->data));
1059 } else { 1090 } else {
1065 ign = ignored(b, name); 1096 ign = ignored(b, name);
1066 1097
1067 if (ign) { 1098 if (ign) {
1068 g_free(ign); 1099 g_free(ign);
1069 b->ignored = g_list_remove(b->ignored, ign); 1100 b->ignored = g_list_remove(b->ignored, ign);
1070 g_snprintf(tmp, sizeof tmp, "%s", name);
1071 } else { 1101 } else {
1072 b->ignored = g_list_append(b->ignored, g_strdup(name)); 1102 b->ignored = g_list_append(b->ignored, g_strdup(name));
1073 g_snprintf(tmp, sizeof tmp, "X %s", name); 1103 }
1074 } 1104
1075
1076 list_item = gtk_list_item_new_with_label(tmp);
1077 gtk_object_set_user_data(GTK_OBJECT(list_item), name);
1078 gtk_list_insert_items(GTK_LIST(b->list), g_list_append(NULL, list_item), pos);
1079 gtk_widget_destroy(i->data); 1105 gtk_widget_destroy(i->data);
1080 gtk_widget_show(list_item); 1106 add_chat_buddy_common(b, name, pos);
1081 gtk_signal_connect(GTK_OBJECT(list_item), "button_press_event",
1082 GTK_SIGNAL_FUNC(right_click_chat), b);
1083 } 1107 }
1084 1108
1085 void show_new_buddy_chat(struct conversation *b) 1109 void show_new_buddy_chat(struct conversation *b)
1086 { 1110 {
1087 GtkWidget *win; 1111 GtkWidget *win;
1474 g_list_length(c->in_room) == 1 ? "person" : "people"); 1498 g_list_length(c->in_room) == 1 ? "person" : "people");
1475 gtk_label_set_text(GTK_LABEL(c->count), tmp); 1499 gtk_label_set_text(GTK_LABEL(c->count), tmp);
1476 1500
1477 while (r) { 1501 while (r) {
1478 char *name = r->data; 1502 char *name = r->data;
1479 GtkWidget *list_item; 1503
1480 char tmp[BUF_LONG]; 1504 add_chat_buddy_common(c, name, pos);
1481
1482 if (ignored(c, name)) {
1483 g_snprintf(tmp, sizeof(tmp), "X %s", name);
1484 list_item = gtk_list_item_new_with_label(tmp);
1485 } else
1486 list_item = gtk_list_item_new_with_label(name);
1487
1488 gtk_object_set_user_data(GTK_OBJECT(list_item), name);
1489 gtk_signal_connect(GTK_OBJECT(list_item), "button_press_event",
1490 GTK_SIGNAL_FUNC(right_click_chat), c);
1491 gtk_list_insert_items(GTK_LIST(c->list),
1492 g_list_append(NULL, list_item), pos);
1493 gtk_widget_show(list_item);
1494 1505
1495 r = r->next; 1506 r = r->next;
1496 pos++; 1507 pos++;
1497 } 1508 }
1498 1509
1520 g_list_length(c->in_room) == 1 ? "person" : "people"); 1531 g_list_length(c->in_room) == 1 ? "person" : "people");
1521 gtk_label_set_text(GTK_LABEL(c->count), tmp); 1532 gtk_label_set_text(GTK_LABEL(c->count), tmp);
1522 1533
1523 while (r) { 1534 while (r) {
1524 char *name = r->data; 1535 char *name = r->data;
1525 GtkWidget *list_item; 1536
1526 char tmp[BUF_LONG]; 1537 add_chat_buddy_common(c, name, pos);
1527
1528 if (ignored(c, name)) {
1529 g_snprintf(tmp, sizeof(tmp), "X %s", name);
1530 list_item = gtk_list_item_new_with_label(tmp);
1531 } else
1532 list_item = gtk_list_item_new_with_label(name);
1533
1534 gtk_object_set_user_data(GTK_OBJECT(list_item), name);
1535 gtk_signal_connect(GTK_OBJECT(list_item), "button_press_event",
1536 GTK_SIGNAL_FUNC(right_click_chat), c);
1537 gtk_list_insert_items(GTK_LIST(c->list),
1538 g_list_append(NULL, list_item), pos);
1539 gtk_widget_show(list_item);
1540 1538
1541 r = r->next; 1539 r = r->next;
1542 pos++; 1540 pos++;
1543 } 1541 }
1544 1542