comparison src/gtkconv.c @ 11604:6be663877350

[gaim-migrate @ 13875] This should fix some bugs, and make the tab update better when using the send to menu. committer: Tailor Script <tailor@pidgin.im>
author Tim Ringenbach <marv@pidgin.im>
date Tue, 04 Oct 2005 01:40:23 +0000
parents b97545f21b4c
children 311a743df5ca
comparison
equal deleted inserted replaced
11603:b97545f21b4c 11604:6be663877350
119 119
120 120
121 121
122 /* Prototypes. <-- because Paco-Paco hates this comment. */ 122 /* Prototypes. <-- because Paco-Paco hates this comment. */
123 static void got_typing_keypress(GaimGtkConversation *gtkconv, gboolean first); 123 static void got_typing_keypress(GaimGtkConversation *gtkconv, gboolean first);
124 static void gray_stuff_out(GaimGtkConversation *gtkconv);
124 static GList *generate_invite_user_names(GaimConnection *gc); 125 static GList *generate_invite_user_names(GaimConnection *gc);
125 static void add_chat_buddy_common(GaimConversation *conv, const char *name, 126 static void add_chat_buddy_common(GaimConversation *conv, const char *name,
126 const char *alias, const char *old_name); 127 const char *alias, const char *old_name);
127 static gboolean tab_complete(GaimConversation *conv); 128 static gboolean tab_complete(GaimConversation *conv);
129 static void gaim_gtkconv_updated(GaimConversation *conv, GaimConvUpdateType type);
128 static void update_typing_icon(GaimGtkConversation *gtkconv); 130 static void update_typing_icon(GaimGtkConversation *gtkconv);
129 static char *item_factory_translate_func (const char *path, gpointer func_data); 131 static char *item_factory_translate_func (const char *path, gpointer func_data);
130 132
131 static GdkColor *get_nick_color(GaimGtkConversation *gtkconv, const char *name) { 133 static GdkColor *get_nick_color(GaimGtkConversation *gtkconv, const char *name) {
132 static GdkColor col; 134 static GdkColor col;
1894 1896
1895 return TRUE; 1897 return TRUE;
1896 } 1898 }
1897 1899
1898 static void 1900 static void
1901 gaim_gtkconv_switch_active_conversation(GaimConversation *conv)
1902 {
1903 GaimGtkConversation *gtkconv;
1904
1905 g_return_if_fail(conv != NULL);
1906
1907 gtkconv = GAIM_GTK_CONVERSATION(conv);
1908
1909 gtkconv->active_conv = conv;
1910
1911 gray_stuff_out(gtkconv);
1912 update_typing_icon(gtkconv);
1913
1914 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(gtkconv->win->menu.logging),
1915 gaim_conversation_is_logging(conv));
1916
1917 gtk_window_set_title(GTK_WINDOW(gtkconv->win->window),
1918 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
1919
1920 gaim_gtkconv_updated(conv, GAIM_CONV_UPDATE_ACCOUNT);
1921 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry),
1922 gaim_account_get_protocol_name(conv->account));
1923 }
1924
1925 static void
1899 menu_conv_sel_send_cb(GObject *m, gpointer data) 1926 menu_conv_sel_send_cb(GObject *m, gpointer data)
1900 { 1927 {
1901 GaimAccount *account = g_object_get_data(m, "gaim_account"); 1928 GaimAccount *account = g_object_get_data(m, "gaim_account");
1902 gchar *name = g_object_get_data(m, "gaim_buddy_name"); 1929 gchar *name = g_object_get_data(m, "gaim_buddy_name");
1903 GaimConversation *conv; 1930 GaimConversation *conv;
1904 GaimGtkConversation *gtkconv;
1905 1931
1906 if (gtk_check_menu_item_get_active((GtkCheckMenuItem*) m) == FALSE) 1932 if (gtk_check_menu_item_get_active((GtkCheckMenuItem*) m) == FALSE)
1907 return; 1933 return;
1908 1934
1909 /* I'm about 99.99% sure we're leaking a conversation here... */
1910 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, name); 1935 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, name);
1911 gtkconv = GAIM_GTK_CONVERSATION(conv); 1936 gaim_gtkconv_switch_active_conversation(conv);
1912
1913 gtkconv->active_conv = conv;
1914
1915 gtk_imhtml_set_protocol_name(GTK_IMHTML(gtkconv->entry),
1916 gaim_account_get_protocol_name(conv->account));
1917 } 1937 }
1918 1938
1919 static void 1939 static void
1920 insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position, 1940 insert_text_cb(GtkTextBuffer *textbuffer, GtkTextIter *position,
1921 gchar *new_text, gint new_text_length, gpointer user_data) 1941 gchar *new_text, gint new_text_length, gpointer user_data)
2678 2698
2679 g_return_if_fail(win != NULL); 2699 g_return_if_fail(win != NULL);
2680 2700
2681 gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win); 2701 gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win);
2682 2702
2703 g_return_if_fail(gtkconv != NULL);
2704
2683 if (win->menu.send_to != NULL) 2705 if (win->menu.send_to != NULL)
2684 gtk_widget_destroy(win->menu.send_to); 2706 gtk_widget_destroy(win->menu.send_to);
2685 2707
2686 2708
2687 /* Build the Send As menu */ 2709 /* Build the Send As menu */
2693 win->menu.send_to, 2); 2715 win->menu.send_to, 2);
2694 gtk_menu_item_set_submenu(GTK_MENU_ITEM(win->menu.send_to), menu); 2716 gtk_menu_item_set_submenu(GTK_MENU_ITEM(win->menu.send_to), menu);
2695 2717
2696 gtk_widget_show(menu); 2718 gtk_widget_show(menu);
2697 2719
2698 buds = gaim_find_buddies(gtkconv->active_conv->account, gtkconv->active_conv->name); 2720 if (gtkconv->active_conv->type == GAIM_CONV_TYPE_IM) {
2699 for (l = buds; l != NULL; l = l->next) { 2721 buds = gaim_find_buddies(gtkconv->active_conv->account, gtkconv->active_conv->name);
2700 GaimBuddy *b; 2722 for (l = buds; l != NULL; l = l->next) {
2701 GaimBlistNode *node; 2723 GaimBuddy *b;
2702 2724 GaimBlistNode *node;
2703 b = l->data; 2725
2704 node = (GaimBlistNode *) gaim_buddy_get_contact(b); 2726 b = l->data;
2705 2727 node = (GaimBlistNode *) gaim_buddy_get_contact(b);
2706 for (node = node->child; node != NULL; node = node->next) 2728
2707 if (GAIM_BLIST_NODE_IS_BUDDY(node) && gaim_account_is_connected(((GaimBuddy *)node)->account)) 2729 for (node = node->child; node != NULL; node = node->next)
2708 create_sendto_item(menu, sg, &group, (GaimBuddy *) node); 2730 if (GAIM_BLIST_NODE_IS_BUDDY(node) && gaim_account_is_connected(((GaimBuddy *)node)->account))
2709 } 2731 create_sendto_item(menu, sg, &group, (GaimBuddy *) node);
2710 2732 }
2711 g_slist_free(buds); 2733
2734 g_slist_free(buds);
2735 }
2712 2736
2713 g_object_unref(sg); 2737 g_object_unref(sg);
2714 2738
2715 gtk_widget_show(win->menu.send_to); 2739 gtk_widget_show(win->menu.send_to);
2716 if (!group) 2740 if (!group)
3749 GtkWidget *pane = NULL; 3773 GtkWidget *pane = NULL;
3750 GtkWidget *tab_cont; 3774 GtkWidget *tab_cont;
3751 3775
3752 if (conv_type == GAIM_CONV_TYPE_IM && (gtkconv = gaim_gtk_conv_find_gtkconv(conv))) { 3776 if (conv_type == GAIM_CONV_TYPE_IM && (gtkconv = gaim_gtk_conv_find_gtkconv(conv))) {
3753 conv->ui_data = gtkconv; 3777 conv->ui_data = gtkconv;
3754 gtkconv->active_conv = conv;
3755 if (!g_list_find(gtkconv->convs, conv)) 3778 if (!g_list_find(gtkconv->convs, conv))
3756 gtkconv->convs = g_list_prepend(gtkconv->convs, conv); 3779 gtkconv->convs = g_list_prepend(gtkconv->convs, conv);
3780 gaim_gtkconv_switch_active_conversation(conv);
3757 return; 3781 return;
3758 } 3782 }
3759 3783
3760 gtkconv = g_new0(GaimGtkConversation, 1); 3784 gtkconv = g_new0(GaimGtkConversation, 1);
3761 conv->ui_data = gtkconv; 3785 conv->ui_data = gtkconv;
5650 gaim_gtk_conv_window_destroy(win); 5674 gaim_gtk_conv_window_destroy(win);
5651 5675
5652 return TRUE; 5676 return TRUE;
5653 } 5677 }
5654 5678
5679 static void
5680 gtkconv_set_unseen(GaimGtkConversation *gtkconv, GaimUnseenState state)
5681 {
5682 GList *l;
5683
5684 for (l = gtkconv->convs; l != NULL; l = l->next)
5685 gaim_conversation_set_unseen(l->data, state);
5686 }
5655 /* 5687 /*
5656 * When a conversation window is focused, we know the user 5688 * When a conversation window is focused, we know the user
5657 * has looked at it so we know there are no longer unseen 5689 * has looked at it so we know there are no longer unseen
5658 * messages. 5690 * messages.
5659 */ 5691 */
5660 static gint 5692 static gint
5661 focus_win_cb(GtkWidget *w, GdkEventFocus *e, gpointer d) 5693 focus_win_cb(GtkWidget *w, GdkEventFocus *e, gpointer d)
5662 { 5694 {
5663 GaimGtkWindow *win = d; 5695 GaimGtkWindow *win = d;
5664 GaimConversation *conv = gaim_gtk_conv_window_get_active_conversation(win); 5696 GaimGtkConversation *gtkconv = gaim_gtk_conv_window_get_active_gtkconv(win);
5665 5697
5666 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); 5698 gtkconv_set_unseen(gtkconv, GAIM_UNSEEN_NONE);
5667 5699
5668 return FALSE; 5700 return FALSE;
5669 } 5701 }
5670 5702
5671 /* Courtesy of Galeon! */ 5703 /* Courtesy of Galeon! */
6040 6072
6041 /* 6073 /*
6042 * Only set "unseen" to "none" if the window has focus 6074 * Only set "unseen" to "none" if the window has focus
6043 */ 6075 */
6044 if (gaim_gtk_conv_window_has_focus(win)) 6076 if (gaim_gtk_conv_window_has_focus(win))
6045 gaim_conversation_set_unseen(conv, GAIM_UNSEEN_NONE); 6077 gtkconv_set_unseen(gtkconv, GAIM_UNSEEN_NONE);
6046 6078
6047 /* Update the menubar */ 6079 /* Update the menubar */
6048 gray_stuff_out(gtkconv);
6049 6080
6050 generate_send_to_items(win); 6081 generate_send_to_items(win);
6051 6082
6052 update_typing_icon(gtkconv); 6083 gaim_gtkconv_switch_active_conversation(conv);
6053
6054 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.logging),
6055 gaim_conversation_is_logging(conv));
6056 6084
6057 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.sounds), 6085 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.sounds),
6058 gtkconv->make_sound); 6086 gtkconv->make_sound);
6059 6087
6060 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_formatting_toolbar), 6088 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_formatting_toolbar),
6064 gtkconv->show_timestamps); 6092 gtkconv->show_timestamps);
6065 6093
6066 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) 6094 if (gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM)
6067 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_icon), 6095 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(win->menu.show_icon),
6068 gtkconv->u.im->show_icon); 6096 gtkconv->u.im->show_icon);
6097
6069 /* 6098 /*
6070 * We pause icons when they are not visible. If this icon should 6099 * We pause icons when they are not visible. If this icon should
6071 * be animated then start it back up again. 6100 * be animated then start it back up again.
6072 */ 6101 */
6073 if ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) && 6102 if ((gaim_conversation_get_type(conv) == GAIM_CONV_TYPE_IM) &&
6074 (gtkconv->u.im->animate)) 6103 (gtkconv->u.im->animate))
6075 start_anim(NULL, gtkconv); 6104 start_anim(NULL, gtkconv);
6076
6077 gtk_window_set_title(GTK_WINDOW(win->window),
6078 gtk_label_get_text(GTK_LABEL(gtkconv->tab_label)));
6079 } 6105 }
6080 6106
6081 /************************************************************************** 6107 /**************************************************************************
6082 * GTK+ window ops 6108 * GTK+ window ops
6083 **************************************************************************/ 6109 **************************************************************************/
6352 GtkWidget *tab_cont; 6378 GtkWidget *tab_cont;
6353 6379
6354 if (index == -1) 6380 if (index == -1)
6355 index = 0; 6381 index = 0;
6356 tab_cont = gtk_notebook_get_nth_page(GTK_NOTEBOOK(win->notebook), index); 6382 tab_cont = gtk_notebook_get_nth_page(GTK_NOTEBOOK(win->notebook), index);
6357 return g_object_get_data(G_OBJECT(tab_cont), "GaimGtkConversation"); 6383 return tab_cont ? g_object_get_data(G_OBJECT(tab_cont), "GaimGtkConversation") : NULL;
6358 } 6384 }
6359 6385
6360 GaimGtkConversation * 6386 GaimGtkConversation *
6361 gaim_gtk_conv_window_get_active_gtkconv(const GaimGtkWindow *win) 6387 gaim_gtk_conv_window_get_active_gtkconv(const GaimGtkWindow *win)
6362 { 6388 {