comparison src/conversation.c @ 6485:70d5122bc3ff

[gaim-migrate @ 6999] Removed the old event system and replaced it with a much better signal system. There will most likely be some bugs in this, but it seems to be working for now. Plugins can now generate their own signals, and other plugins can find those plugins and connect to them. This could give plugins a form of IPC. It's also useful for other things. It's rather flexible, except for the damn marshalling, but there's no way around that that I or the glib people can see. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Mon, 18 Aug 2003 01:03:43 +0000
parents 338147ea6896
children e0c80bec996a
comparison
equal deleted inserted replaced
6484:5ced8e111473 6485:70d5122bc3ff
1 /* 1 /*
2 * gaim 2 * gaim
3 * 3 *
4 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org> 4 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org>
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
10 * 10 *
23 #include "conversation.h" 23 #include "conversation.h"
24 #include "debug.h" 24 #include "debug.h"
25 #include "notify.h" 25 #include "notify.h"
26 #include "prefs.h" 26 #include "prefs.h"
27 #include "prpl.h" 27 #include "prpl.h"
28 #include "signals.h"
28 #include "util.h" 29 #include "util.h"
29 30
30 /* XXX CORE/UI */ 31 /* XXX CORE/UI */
31 #include "gtkinternal.h" 32 #include "gtkinternal.h"
32 #include "ui.h" 33 #include "ui.h"
224 buffy = linkify_text(buf); 225 buffy = linkify_text(buf);
225 } 226 }
226 else 227 else
227 buffy = g_strdup(buf); 228 buffy = g_strdup(buf);
228 229
229 plugin_return = gaim_event_broadcast( 230 plugin_return =
230 (type == GAIM_CONV_IM ? event_im_send : event_chat_send), 231 GPOINTER_TO_INT(gaim_signal_emit_return_1(
231 gc, 232 gaim_conversations_get_handle(),
232 (type == GAIM_CONV_IM 233 (type == GAIM_CONV_IM
233 ? gaim_conversation_get_name(conv) 234 ? "displaying-im-msg" : "displaying-chat-msg"),
234 : GINT_TO_POINTER(gaim_chat_get_id(GAIM_CHAT(conv)))), 235 conv, &buffy));
235 &buffy);
236 236
237 if (buffy == NULL) { 237 if (buffy == NULL) {
238 g_free(buf2); 238 g_free(buf2);
239 g_free(buf); 239 g_free(buf);
240 return; 240 return;
248 } 248 }
249 249
250 strncpy(buf, buffy, limit); 250 strncpy(buf, buffy, limit);
251 g_free(buffy); 251 g_free(buffy);
252 252
253 gaim_signal_emit(gaim_conversations_get_handle(),
254 (type == GAIM_CONV_IM ? "displayed-im-msg" : "displayed-chat-msg"),
255 conv, buffy);
256
253 if (type == GAIM_CONV_IM) { 257 if (type == GAIM_CONV_IM) {
254 GaimIm *im = GAIM_IM(conv); 258 GaimIm *im = GAIM_IM(conv);
255 259
256 buffy = g_strdup(buf); 260 buffy = g_strdup(buf);
257 gaim_event_broadcast(event_im_displayed_sent, gc, 261 gaim_signal_emit(gaim_conversations_get_handle(), "sending-im-msg",
258 gaim_conversation_get_name(conv), &buffy); 262 conv, &buffy);
259 263
260 if (buffy != NULL) { 264 if (buffy != NULL) {
261 int imflags = 0; 265 int imflags = 0;
262 266
263 if (conv->u.im->images != NULL) { 267 if (conv->u.im->images != NULL) {
385 389
386 if (err > 0) 390 if (err > 0)
387 gaim_im_write(im, NULL, buf, -1, WFLAG_SEND, time(NULL)); 391 gaim_im_write(im, NULL, buf, -1, WFLAG_SEND, time(NULL));
388 } 392 }
389 393
394 gaim_signal_emit(gaim_conversations_get_handle(), "sent-im-msg",
395 conv, buffy);
396
390 g_free(buffy); 397 g_free(buffy);
391 } 398 }
392 } 399 }
393 else { 400 else {
394 err = serv_chat_send(gc, gaim_chat_get_id(GAIM_CHAT(conv)), buf); 401 buffy = g_strdup(buf);
402
403 gaim_signal_emit(gaim_conversations_get_handle(), "sending-chat-msg",
404 conv, &buffy);
405
406 if (buffy != NULL) {
407 err = serv_chat_send(gc, gaim_chat_get_id(GAIM_CHAT(conv)), buffy);
408
409 gaim_signal_emit(gaim_conversations_get_handle(), "sent-chat-msg",
410 conv, buf);
411
412 g_free(buffy);
413 }
395 } 414 }
396 415
397 g_free(buf2); 416 g_free(buf2);
398 g_free(buf); 417 g_free(buf);
399 418
745 764
746 void 765 void
747 gaim_window_switch_conversation(GaimWindow *win, unsigned int index) 766 gaim_window_switch_conversation(GaimWindow *win, unsigned int index)
748 { 767 {
749 GaimWindowUiOps *ops; 768 GaimWindowUiOps *ops;
750 GaimConversation *conv; 769 GaimConversation *old_conv, *conv;
751 770
752 g_return_if_fail(win != NULL); 771 g_return_if_fail(win != NULL);
753 g_return_if_fail(index >= 0 && 772 g_return_if_fail(index >= 0 &&
754 index < gaim_window_get_conversation_count(win)); 773 index < gaim_window_get_conversation_count(win));
755 774
775 old_conv = gaim_window_get_active_conversation(win);
776 conv = gaim_window_get_conversation_at(win, index);
777
778 gaim_signal_emit(gaim_conversations_get_handle(),
779 "conversation-switching", old_conv, conv);
780
756 ops = gaim_window_get_ui_ops(win); 781 ops = gaim_window_get_ui_ops(win);
757 782
758 if (ops != NULL && ops->switch_conversation != NULL) 783 if (ops != NULL && ops->switch_conversation != NULL)
759 ops->switch_conversation(win, index); 784 ops->switch_conversation(win, index);
760 785
761 conv = gaim_window_get_conversation_at(win, index);
762 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); 786 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE);
763 gaim_event_broadcast(event_conversation_switch, conv); 787
764 788 gaim_signal_emit(gaim_conversations_get_handle(),
789 "conversation-switched", old_conv, conv);
765 } 790 }
766 791
767 GaimConversation * 792 GaimConversation *
768 gaim_window_get_active_conversation(const GaimWindow *win) 793 gaim_window_get_active_conversation(const GaimWindow *win)
769 { 794 {
922 else { 947 else {
923 if (place_conv == NULL) 948 if (place_conv == NULL)
924 gaim_prefs_set_string("/core/conversations/placement", "last"); 949 gaim_prefs_set_string("/core/conversations/placement", "last");
925 950
926 if (!place_conv) 951 if (!place_conv)
927 gaim_debug(GAIM_DEBUG_ERROR, "conversation", "This is about to suck.\n"); 952 gaim_debug(GAIM_DEBUG_ERROR, "conversation",
953 "This is about to suck.\n");
928 954
929 place_conv(conv); 955 place_conv(conv);
930 } 956 }
931 957
932 gaim_event_broadcast(event_new_conversation, name); 958 gaim_signal_emit(gaim_conversations_get_handle(),
959 "conversation-created", conv);
933 960
934 return conv; 961 return conv;
935 } 962 }
936 963
937 void 964 void
987 return; 1014 return;
988 } 1015 }
989 } 1016 }
990 } 1017 }
991 1018
992 gaim_event_broadcast(event_del_conversation, conv); 1019 gaim_signal_emit(gaim_conversations_get_handle(),
1020 "deleting-conversation", conv);
993 1021
994 if (conv->name != NULL) g_free(conv->name); 1022 if (conv->name != NULL) g_free(conv->name);
995 if (conv->title != NULL) g_free(conv->title); 1023 if (conv->title != NULL) g_free(conv->title);
996 1024
997 for (node = g_list_first(conv->send_history); 1025 for (node = g_list_first(conv->send_history);
1906 g_return_if_fail(user != NULL); 1934 g_return_if_fail(user != NULL);
1907 1935
1908 conv = gaim_chat_get_conversation(chat); 1936 conv = gaim_chat_get_conversation(chat);
1909 ops = gaim_conversation_get_ui_ops(conv); 1937 ops = gaim_conversation_get_ui_ops(conv);
1910 1938
1939 gaim_signal_emit(gaim_conversations_get_handle(),
1940 "chat-buddy-joining", conv, user);
1941
1911 gaim_chat_set_users(chat, 1942 gaim_chat_set_users(chat,
1912 g_list_insert_sorted(gaim_chat_get_users(chat), g_strdup(user), 1943 g_list_insert_sorted(gaim_chat_get_users(chat), g_strdup(user),
1913 insertname_compare)); 1944 insertname_compare));
1914
1915 gaim_event_broadcast(event_chat_buddy_join,
1916 gaim_conversation_get_gc(conv), gaim_chat_get_id(chat),
1917 user);
1918 1945
1919 if (ops != NULL && ops->chat_add_user != NULL) 1946 if (ops != NULL && ops->chat_add_user != NULL)
1920 ops->chat_add_user(conv, user); 1947 ops->chat_add_user(conv, user);
1921 1948
1922 if (gaim_prefs_get_bool("/core/conversations/chat/show_join")) { 1949 if (gaim_prefs_get_bool("/core/conversations/chat/show_join")) {
1927 _("%s [<I>%s</I>] entered the room."), 1954 _("%s [<I>%s</I>] entered the room."),
1928 user, extra_msg); 1955 user, extra_msg);
1929 1956
1930 gaim_conversation_write(conv, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL)); 1957 gaim_conversation_write(conv, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL));
1931 } 1958 }
1959
1960 gaim_signal_emit(gaim_conversations_get_handle(),
1961 "chat-buddy-joined", conv, user);
1932 } 1962 }
1933 1963
1934 void 1964 void
1935 gaim_chat_add_users(GaimChat *chat, GList *users) 1965 gaim_chat_add_users(GaimChat *chat, GList *users)
1936 { 1966 {
1943 1973
1944 conv = gaim_chat_get_conversation(chat); 1974 conv = gaim_chat_get_conversation(chat);
1945 ops = gaim_conversation_get_ui_ops(conv); 1975 ops = gaim_conversation_get_ui_ops(conv);
1946 1976
1947 for (l = users; l != NULL; l = l->next) { 1977 for (l = users; l != NULL; l = l->next) {
1978 const char *user = (const char *)l->data;
1979
1980 gaim_signal_emit(gaim_conversations_get_handle(),
1981 "chat-buddy-joining", conv, user);
1982
1948 gaim_chat_set_users(chat, 1983 gaim_chat_set_users(chat,
1949 g_list_insert_sorted(gaim_chat_get_users(chat), 1984 g_list_insert_sorted(gaim_chat_get_users(chat),
1950 g_strdup((char *)l->data), 1985 g_strdup((char *)l->data),
1951 insertname_compare)); 1986 insertname_compare));
1952 1987
1953 gaim_event_broadcast(event_chat_buddy_join, 1988 gaim_signal_emit(gaim_conversations_get_handle(),
1954 gaim_conversation_get_gc(conv), gaim_chat_get_id(chat), 1989 "chat-buddy-joined", conv, user);
1955 (char *)l->data);
1956 } 1990 }
1957 1991
1958 if (ops != NULL && ops->chat_add_users != NULL) 1992 if (ops != NULL && ops->chat_add_users != NULL)
1959 ops->chat_add_users(conv, users); 1993 ops->chat_add_users(conv, users);
1960 } 1994 }
2020 g_return_if_fail(user != NULL); 2054 g_return_if_fail(user != NULL);
2021 2055
2022 conv = gaim_chat_get_conversation(chat); 2056 conv = gaim_chat_get_conversation(chat);
2023 ops = gaim_conversation_get_ui_ops(conv); 2057 ops = gaim_conversation_get_ui_ops(conv);
2024 2058
2025 gaim_event_broadcast(event_chat_buddy_leave, gaim_conversation_get_gc(conv), 2059 gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-leaving",
2026 gaim_chat_get_id(chat), user); 2060 conv, user, reason);
2027 2061
2028 if (ops != NULL && ops->chat_remove_user != NULL) 2062 if (ops != NULL && ops->chat_remove_user != NULL)
2029 ops->chat_remove_user(conv, user); 2063 ops->chat_remove_user(conv, user);
2030 2064
2031 for (names = gaim_chat_get_users(chat); 2065 for (names = gaim_chat_get_users(chat);
2048 else 2082 else
2049 g_snprintf(tmp, sizeof(tmp), _("%s left the room."), user); 2083 g_snprintf(tmp, sizeof(tmp), _("%s left the room."), user);
2050 2084
2051 gaim_conversation_write(conv, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL)); 2085 gaim_conversation_write(conv, NULL, tmp, -1, WFLAG_SYSTEM, time(NULL));
2052 } 2086 }
2087
2088 gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left",
2089 conv, user, reason);
2053 } 2090 }
2054 2091
2055 void 2092 void
2056 gaim_chat_remove_users(GaimChat *chat, GList *users, const char *reason) 2093 gaim_chat_remove_users(GaimChat *chat, GList *users, const char *reason)
2057 { 2094 {
2065 2102
2066 conv = gaim_chat_get_conversation(chat); 2103 conv = gaim_chat_get_conversation(chat);
2067 ops = gaim_conversation_get_ui_ops(conv); 2104 ops = gaim_conversation_get_ui_ops(conv);
2068 2105
2069 for (l = users; l != NULL; l = l->next) { 2106 for (l = users; l != NULL; l = l->next) {
2070 gaim_event_broadcast(event_chat_buddy_leave, 2107 const char *user = (const char *)l->data;
2071 gaim_conversation_get_gc(conv), 2108
2072 gaim_chat_get_id(chat), l->data); 2109 gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-leaving",
2110 conv, user, reason);
2073 } 2111 }
2074 2112
2075 if (ops != NULL && ops->chat_remove_users != NULL) 2113 if (ops != NULL && ops->chat_remove_users != NULL)
2076 ops->chat_remove_users(conv, users); 2114 ops->chat_remove_users(conv, users);
2077 2115
2078 for (l = users; l != NULL; l = l->next) { 2116 for (l = users; l != NULL; l = l->next) {
2117 const char *user = (const char *)l->data;
2118
2079 for (names = gaim_chat_get_users(chat); 2119 for (names = gaim_chat_get_users(chat);
2080 names != NULL; 2120 names != NULL;
2081 names = names->next) { 2121 names = names->next) {
2082 2122
2083 if (!gaim_utf8_strcasecmp((char *)names->data, (char *)l->data)) { 2123 if (!gaim_utf8_strcasecmp((char *)names->data, user))
2124 {
2084 gaim_chat_set_users(chat, 2125 gaim_chat_set_users(chat,
2085 g_list_remove(gaim_chat_get_users(chat), names->data)); 2126 g_list_remove(gaim_chat_get_users(chat), names->data));
2086 2127
2087 break; 2128 break;
2088 } 2129 }
2089 } 2130 }
2131
2132 gaim_signal_emit(gaim_conversations_get_handle(), "chat-buddy-left",
2133 conv, user, reason);
2090 } 2134 }
2091 2135
2092 /* NOTE: Don't remove them from ignored in case they re-enter. */ 2136 /* NOTE: Don't remove them from ignored in case they re-enter. */
2093 2137
2094 if (gaim_prefs_get_bool("/core/conversations/chat/show_leave")) { 2138 if (gaim_prefs_get_bool("/core/conversations/chat/show_leave")) {
2140 { 2184 {
2141 char *user = (char *)l->data; 2185 char *user = (char *)l->data;
2142 2186
2143 l_next = l->next; 2187 l_next = l->next;
2144 2188
2145 gaim_event_broadcast(event_chat_buddy_leave, 2189 gaim_signal_emit(gaim_conversations_get_handle(),
2146 gaim_conversation_get_gc(conv), 2190 "chat-buddy-leaving", conv, user, NULL);
2147 gaim_chat_get_id(chat), user); 2191 gaim_signal_emit(gaim_conversations_get_handle(),
2192 "chat-buddy-left", conv, user, NULL);
2148 2193
2149 g_free(user); 2194 g_free(user);
2150 } 2195 }
2151 2196
2152 g_list_free(users); 2197 g_list_free(users);
2523 gaim_get_win_ui_ops(void) 2568 gaim_get_win_ui_ops(void)
2524 { 2569 {
2525 return win_ui_ops; 2570 return win_ui_ops;
2526 } 2571 }
2527 2572
2528 void 2573 void *
2529 gaim_conversation_init(void) 2574 gaim_conversations_get_handle(void)
2530 { 2575 {
2576 static int handle;
2577
2578 return &handle;
2579 }
2580
2581 void
2582 gaim_conversations_init(void)
2583 {
2584 void *handle = gaim_conversations_get_handle();
2585
2586 /* Register preferences */
2587
2531 /* Conversations */ 2588 /* Conversations */
2532 gaim_prefs_add_none("/core/conversations"); 2589 gaim_prefs_add_none("/core/conversations");
2533 gaim_prefs_add_bool("/core/conversations/send_urls_as_links", TRUE); 2590 gaim_prefs_add_bool("/core/conversations/send_urls_as_links", TRUE);
2534 gaim_prefs_add_bool("/core/conversations/away_back_on_send", TRUE); 2591 gaim_prefs_add_bool("/core/conversations/away_back_on_send", TRUE);
2535 gaim_prefs_add_bool("/core/conversations/use_alias_for_title", TRUE); 2592 gaim_prefs_add_bool("/core/conversations/use_alias_for_title", TRUE);
2552 gaim_prefs_trigger_callback("/core/conversations/placement"); 2609 gaim_prefs_trigger_callback("/core/conversations/placement");
2553 gaim_prefs_connect_callback("/core/conversations/use_alias_for_title", 2610 gaim_prefs_connect_callback("/core/conversations/use_alias_for_title",
2554 update_titles_pref_cb, NULL); 2611 update_titles_pref_cb, NULL);
2555 gaim_prefs_connect_callback("/core/buddies/use_server_alias", 2612 gaim_prefs_connect_callback("/core/buddies/use_server_alias",
2556 update_titles_pref_cb, NULL); 2613 update_titles_pref_cb, NULL);
2557 } 2614
2615
2616 /* Register signals */
2617 gaim_signal_register(handle, "displaying-im-msg",
2618 gaim_marshal_BOOLEAN__POINTER_POINTER);
2619 gaim_signal_register(handle, "displayed-im-msg",
2620 gaim_marshal_VOID__POINTER_POINTER);
2621 gaim_signal_register(handle, "sending-im-msg",
2622 gaim_marshal_VOID__POINTER_POINTER);
2623 gaim_signal_register(handle, "sent-im-msg",
2624 gaim_marshal_VOID__POINTER_POINTER);
2625 gaim_signal_register(handle, "received-im-msg",
2626 gaim_marshal_BOOLEAN__POINTER_POINTER_POINTER_POINTER_POINTER);
2627
2628 gaim_signal_register(handle, "displaying-chat-msg",
2629 gaim_marshal_BOOLEAN__POINTER_POINTER);
2630 gaim_signal_register(handle, "displayed-chat-msg",
2631 gaim_marshal_VOID__POINTER_POINTER);
2632 gaim_signal_register(handle, "sending-chat-msg",
2633 gaim_marshal_VOID__POINTER_POINTER);
2634 gaim_signal_register(handle, "sent-chat-msg",
2635 gaim_marshal_VOID__POINTER_POINTER);
2636 gaim_signal_register(handle, "received-chat-msg",
2637 gaim_marshal_VOID__POINTER_POINTER_POINTER_POINTER);
2638
2639 gaim_signal_register(handle, "conversation-switching",
2640 gaim_marshal_VOID__POINTER_POINTER);
2641 gaim_signal_register(handle, "conversation-switched",
2642 gaim_marshal_VOID__POINTER_POINTER);
2643
2644 gaim_signal_register(handle, "conversation-created",
2645 gaim_marshal_VOID__POINTER);
2646 gaim_signal_register(handle, "deleting-conversation",
2647 gaim_marshal_VOID__POINTER);
2648
2649 gaim_signal_register(handle, "buddy-typing",
2650 gaim_marshal_VOID__POINTER);
2651
2652 gaim_signal_register(handle, "chat-buddy-joining",
2653 gaim_marshal_VOID__POINTER_POINTER);
2654 gaim_signal_register(handle, "chat-buddy-joined",
2655 gaim_marshal_VOID__POINTER_POINTER);
2656
2657 gaim_signal_register(handle, "chat-buddy-leaving",
2658 gaim_marshal_VOID__POINTER_POINTER_POINTER);
2659 gaim_signal_register(handle, "chat-buddy-left",
2660 gaim_marshal_VOID__POINTER_POINTER_POINTER);
2661
2662 gaim_signal_register(handle, "chat-inviting-user",
2663 gaim_marshal_VOID__POINTER_POINTER_POINTER);
2664 gaim_signal_register(handle, "chat-invited-user",
2665 gaim_marshal_VOID__POINTER_POINTER_POINTER);
2666
2667 gaim_signal_register(handle, "chat-invited",
2668 gaim_marshal_VOID__POINTER_POINTER_POINTER_POINTER);
2669 gaim_signal_register(handle, "chat-joined",
2670 gaim_marshal_VOID__POINTER);
2671 gaim_signal_register(handle, "chat-left",
2672 gaim_marshal_VOID__POINTER);
2673 }
2674
2675 void
2676 gaim_conversations_uninit(void)
2677 {
2678 gaim_signals_unregister_by_instance(gaim_conversations_get_handle());
2679 }