1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2003-2007 Imendio AB
4 * Copyright (C) 2007-2008 Collabora Ltd.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Mikael Hallendal <micke@imendio.com>
22 * Richard Hult <richard@imendio.com>
23 * Martyn Russell <martyn@imendio.com>
24 * Geert-Jan Van den Bogaerde <geertjan@gnome.org>
25 * Xavier Claessens <xclaesse@gmail.com>
33 #include <gdk/gdkkeysyms.h>
34 #include <glib/gi18n.h>
35 #include <libnotify/notification.h>
37 #include <telepathy-glib/util.h>
38 #include <libmissioncontrol/mission-control.h>
40 #include <libempathy/empathy-contact.h>
41 #include <libempathy/empathy-message.h>
42 #include <libempathy/empathy-dispatcher.h>
43 #include <libempathy/empathy-chatroom-manager.h>
44 #include <libempathy/empathy-account-manager.h>
45 #include <libempathy/empathy-utils.h>
47 #include <libempathy-gtk/empathy-images.h>
48 #include <libempathy-gtk/empathy-conf.h>
49 #include <libempathy-gtk/empathy-contact-dialogs.h>
50 #include <libempathy-gtk/empathy-log-window.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-smiley-manager.h>
53 #include <libempathy-gtk/empathy-ui-utils.h>
55 #include "empathy-chat-window.h"
56 #include "empathy-about-dialog.h"
57 #include "empathy-misc.h"
59 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
60 #include <libempathy/empathy-debug.h>
62 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChatWindow)
64 EmpathyChat *current_chat;
67 GList *chats_composing;
69 gboolean dnd_same_window;
70 guint save_geometry_id;
71 EmpathyChatroomManager *chatroom_manager;
74 NotifyNotification *notification;
77 GtkUIManager *ui_manager;
78 GtkAction *menu_conv_insert_smiley;
79 GtkAction *menu_conv_favorite;
81 GtkAction *menu_edit_cut;
82 GtkAction *menu_edit_copy;
83 GtkAction *menu_edit_paste;
85 GtkAction *menu_tabs_next;
86 GtkAction *menu_tabs_prev;
87 GtkAction *menu_tabs_left;
88 GtkAction *menu_tabs_right;
89 GtkAction *menu_tabs_detach;
90 } EmpathyChatWindowPriv;
92 static GList *chat_windows = NULL;
94 static const guint tab_accel_keys[] = {
95 GDK_1, GDK_2, GDK_3, GDK_4, GDK_5,
96 GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
100 DND_DRAG_TYPE_CONTACT_ID,
104 static const GtkTargetEntry drag_types_dest[] = {
105 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
106 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, DND_DRAG_TYPE_TAB },
109 G_DEFINE_TYPE (EmpathyChatWindow, empathy_chat_window, G_TYPE_OBJECT);
112 chat_window_accel_cb (GtkAccelGroup *accelgroup,
116 EmpathyChatWindow *window)
118 EmpathyChatWindowPriv *priv;
122 priv = GET_PRIV (window);
124 for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
125 if (tab_accel_keys[i] == key) {
132 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), num);
136 static EmpathyChatWindow *
137 chat_window_find_chat (EmpathyChat *chat)
139 EmpathyChatWindowPriv *priv;
142 for (l = chat_windows; l; l = l->next) {
143 priv = GET_PRIV (l->data);
144 ll = g_list_find (priv->chats, chat);
154 chat_window_close_clicked_cb (GtkAction *action,
157 EmpathyChatWindow *window;
159 window = chat_window_find_chat (chat);
160 empathy_chat_window_remove_chat (window, chat);
164 chat_window_close_button_style_set_cb (GtkWidget *button,
165 GtkStyle *previous_style,
170 gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
171 GTK_ICON_SIZE_MENU, &w, &h);
173 gtk_widget_set_size_request (button, w, h);
177 chat_window_create_label (EmpathyChatWindow *window,
180 EmpathyChatWindowPriv *priv;
182 GtkWidget *name_label;
183 GtkWidget *status_image;
184 GtkWidget *close_button;
185 GtkWidget *close_image;
186 GtkWidget *event_box;
187 GtkWidget *event_box_hbox;
188 PangoAttrList *attr_list;
189 PangoAttribute *attr;
191 priv = GET_PRIV (window);
193 /* The spacing between the button and the label. */
194 hbox = gtk_hbox_new (FALSE, 0);
196 event_box = gtk_event_box_new ();
197 gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
199 name_label = gtk_label_new (NULL);
200 gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
202 attr_list = pango_attr_list_new ();
203 attr = pango_attr_scale_new (1/1.2);
204 attr->start_index = 0;
205 attr->end_index = -1;
206 pango_attr_list_insert (attr_list, attr);
207 gtk_label_set_attributes (GTK_LABEL (name_label), attr_list);
208 pango_attr_list_unref (attr_list);
210 gtk_misc_set_padding (GTK_MISC (name_label), 2, 0);
211 gtk_misc_set_alignment (GTK_MISC (name_label), 0.0, 0.5);
212 g_object_set_data (G_OBJECT (chat), "chat-window-tab-label", name_label);
214 status_image = gtk_image_new ();
216 /* Spacing between the icon and label. */
217 event_box_hbox = gtk_hbox_new (FALSE, 0);
219 gtk_box_pack_start (GTK_BOX (event_box_hbox), status_image, FALSE, FALSE, 0);
220 gtk_box_pack_start (GTK_BOX (event_box_hbox), name_label, TRUE, TRUE, 0);
222 g_object_set_data (G_OBJECT (chat), "chat-window-tab-image", status_image);
223 g_object_set_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget", event_box);
225 close_button = gtk_button_new ();
226 gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
227 g_object_set_data (G_OBJECT (chat), "chat-window-tab-close-button", close_button);
229 /* We don't want focus/keynav for the button to avoid clutter, and
230 * Ctrl-W works anyway.
232 GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_FOCUS);
233 GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_DEFAULT);
235 /* Set the name to make the special rc style match. */
236 gtk_widget_set_name (close_button, "empathy-close-button");
238 close_image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
240 gtk_container_add (GTK_CONTAINER (close_button), close_image);
242 gtk_container_add (GTK_CONTAINER (event_box), event_box_hbox);
243 gtk_box_pack_start (GTK_BOX (hbox), event_box, TRUE, TRUE, 0);
244 gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
246 /* React to theme changes and also used to setup the initial size
249 g_signal_connect (close_button,
251 G_CALLBACK (chat_window_close_button_style_set_cb),
254 g_signal_connect (close_button,
256 G_CALLBACK (chat_window_close_clicked_cb),
259 gtk_widget_show_all (hbox);
265 chat_window_update (EmpathyChatWindow *window)
267 EmpathyChatWindowPriv *priv = GET_PRIV (window);
270 gboolean is_connected;
277 EmpathyContact *remote_contact;
278 gboolean avatar_in_icon;
280 GtkWidget *chat_close_button;
284 /* Get information */
285 page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
286 num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
287 first_page = (page_num == 0);
288 last_page = (page_num == (num_pages - 1));
289 is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
290 name = empathy_chat_get_name (priv->current_chat);
291 n_chats = g_list_length (priv->chats);
293 DEBUG ("Update window");
296 gtk_action_set_sensitive (priv->menu_tabs_next, !last_page);
297 gtk_action_set_sensitive (priv->menu_tabs_prev, !first_page);
298 gtk_action_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
299 gtk_action_set_sensitive (priv->menu_tabs_left, !first_page);
300 gtk_action_set_sensitive (priv->menu_tabs_right, !last_page);
301 gtk_action_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
303 /* Update Contact menu */
304 menu = gtk_ui_manager_get_widget (priv->ui_manager,
305 "/chats_menubar/menu_contact");
306 submenu = empathy_chat_get_contact_menu (priv->current_chat);
307 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu);
308 gtk_widget_show (menu);
310 /* Update window title */
312 gtk_window_set_title (GTK_WINDOW (priv->dialog), name);
316 title = g_strdup_printf (_("Conversations (%d)"), n_chats);
317 gtk_window_set_title (GTK_WINDOW (priv->dialog), title);
321 /* Update window icon */
322 if (priv->chats_new_msg) {
323 gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
324 EMPATHY_IMAGE_MESSAGE);
326 empathy_conf_get_bool (empathy_conf_get (),
327 EMPATHY_PREFS_CHAT_AVATAR_IN_ICON,
330 if (n_chats == 1 && avatar_in_icon) {
331 remote_contact = empathy_chat_get_remote_contact (priv->current_chat);
332 icon = empathy_pixbuf_avatar_from_contact_scaled (remote_contact, 0, 0);
333 gtk_window_set_icon (GTK_WINDOW (priv->dialog), icon);
336 g_object_unref (icon);
339 gtk_window_set_icon_name (GTK_WINDOW (priv->dialog), NULL);
343 if (num_pages == 1) {
344 chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 0);
345 chat_close_button = g_object_get_data (G_OBJECT (chat),
346 "chat-window-tab-close-button");
347 gtk_widget_hide (chat_close_button);
349 for (i=0; i<num_pages; i++) {
350 chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), i);
351 chat_close_button = g_object_get_data (G_OBJECT (chat),
352 "chat-window-tab-close-button");
353 gtk_widget_show (chat_close_button);
359 chat_window_update_chat_tab (EmpathyChat *chat)
361 EmpathyChatWindow *window;
362 EmpathyChatWindowPriv *priv;
363 EmpathyContact *remote_contact;
366 const gchar *subject;
370 const gchar *icon_name;
372 window = chat_window_find_chat (chat);
376 priv = GET_PRIV (window);
378 /* Get information */
379 name = empathy_chat_get_name (chat);
380 account = empathy_chat_get_account (chat);
381 subject = empathy_chat_get_subject (chat);
382 remote_contact = empathy_chat_get_remote_contact (chat);
384 DEBUG ("Updating chat tab, name=%s, account=%s, subject=%s, remote_contact=%p",
385 name, mc_account_get_unique_name (account), subject, remote_contact);
387 /* Update tab image */
388 if (g_list_find (priv->chats_new_msg, chat)) {
389 icon_name = EMPATHY_IMAGE_MESSAGE;
391 else if (g_list_find (priv->chats_composing, chat)) {
392 icon_name = EMPATHY_IMAGE_TYPING;
394 else if (remote_contact) {
395 icon_name = empathy_icon_name_for_contact (remote_contact);
397 icon_name = EMPATHY_IMAGE_GROUP_MESSAGE;
399 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-image");
400 gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_MENU);
402 /* Update tab tooltip */
403 tooltip = g_string_new (NULL);
405 if (remote_contact) {
406 markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>\n%s",
407 empathy_contact_get_id (remote_contact),
408 mc_account_get_display_name (account),
409 empathy_contact_get_status (remote_contact));
410 g_string_append (tooltip, markup);
414 markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>", name,
415 mc_account_get_display_name (account));
416 g_string_append (tooltip, markup);
421 markup = g_markup_printf_escaped ("\n<b>%s</b> %s", _("Topic:"), subject);
422 g_string_append (tooltip, markup);
425 if (g_list_find (priv->chats_composing, chat)) {
426 markup = g_markup_printf_escaped ("\n%s", _("Typing a message."));
427 g_string_append (tooltip, markup);
431 markup = g_string_free (tooltip, FALSE);
432 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget");
433 gtk_widget_set_tooltip_markup (widget, markup);
436 /* Update tab label */
437 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
438 gtk_label_set_text (GTK_LABEL (widget), name);
440 /* Update the window if it's the current chat */
441 if (priv->current_chat == chat) {
442 chat_window_update (window);
447 chat_window_chat_notify_cb (EmpathyChat *chat)
449 EmpathyContact *old_remote_contact;
450 EmpathyContact *remote_contact = NULL;
452 old_remote_contact = g_object_get_data (G_OBJECT (chat), "chat-window-remote-contact");
453 remote_contact = empathy_chat_get_remote_contact (chat);
455 if (old_remote_contact != remote_contact) {
456 /* The remote-contact associated with the chat changed, we need
457 * to keep track of any change of that contact and update the
458 * window each time. */
459 if (remote_contact) {
460 g_signal_connect_swapped (remote_contact, "notify",
461 G_CALLBACK (chat_window_update_chat_tab),
464 if (old_remote_contact) {
465 g_signal_handlers_disconnect_by_func (old_remote_contact,
466 chat_window_update_chat_tab,
470 g_object_set_data (G_OBJECT (chat), "chat-window-remote-contact",
474 chat_window_update_chat_tab (chat);
478 chat_window_insert_smiley_activate_cb (EmpathySmileyManager *manager,
479 EmpathySmiley *smiley,
482 EmpathyChatWindowPriv *priv = GET_PRIV (window);
484 GtkTextBuffer *buffer;
487 chat = priv->current_chat;
489 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
490 gtk_text_buffer_get_end_iter (buffer, &iter);
491 gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
495 chat_window_conv_activate_cb (GtkAction *action,
496 EmpathyChatWindow *window)
498 EmpathyChatWindowPriv *priv = GET_PRIV (window);
501 /* Favorite room menu */
502 is_room = empathy_chat_is_room (priv->current_chat);
508 room = empathy_chat_get_id (priv->current_chat);
509 account = empathy_chat_get_account (priv->current_chat);
510 found = empathy_chatroom_manager_find (priv->chatroom_manager,
511 account, room) != NULL;
513 DEBUG ("This room %s favorite", found ? "is" : "is not");
514 gtk_toggle_action_set_active (
515 GTK_TOGGLE_ACTION (priv->menu_conv_favorite), found);
517 gtk_action_set_visible (priv->menu_conv_favorite, is_room);
521 chat_window_clear_activate_cb (GtkAction *action,
522 EmpathyChatWindow *window)
524 EmpathyChatWindowPriv *priv = GET_PRIV (window);
526 empathy_chat_clear (priv->current_chat);
530 chat_window_favorite_toggled_cb (GtkToggleAction *toggle_action,
531 EmpathyChatWindow *window)
533 EmpathyChatWindowPriv *priv = GET_PRIV (window);
537 EmpathyChatroom *chatroom;
539 active = gtk_toggle_action_get_active (toggle_action);
540 account = empathy_chat_get_account (priv->current_chat);
541 room = empathy_chat_get_id (priv->current_chat);
543 chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
546 if (active && !chatroom) {
549 name = empathy_chat_get_name (priv->current_chat);
550 chatroom = empathy_chatroom_new_full (account, room, name, FALSE);
551 empathy_chatroom_manager_add (priv->chatroom_manager, chatroom);
552 g_object_unref (chatroom);
556 if (!active && chatroom) {
557 empathy_chatroom_manager_remove (priv->chatroom_manager, chatroom);
562 chat_get_window_id_for_geometry (EmpathyChat *chat)
564 const gchar *res = NULL;
565 gboolean separate_windows;
567 empathy_conf_get_bool (empathy_conf_get (),
568 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
571 if (separate_windows) {
572 res = empathy_chat_get_id (chat);
575 return res ? res : "chat-window";
579 chat_window_save_geometry_timeout_cb (EmpathyChatWindow *window)
581 EmpathyChatWindowPriv *priv;
584 priv = GET_PRIV (window);
586 gtk_window_get_size (GTK_WINDOW (priv->dialog), &w, &h);
587 gtk_window_get_position (GTK_WINDOW (priv->dialog), &x, &y);
589 empathy_geometry_save (chat_get_window_id_for_geometry (priv->current_chat),
592 priv->save_geometry_id = 0;
598 chat_window_configure_event_cb (GtkWidget *widget,
599 GdkEventConfigure *event,
600 EmpathyChatWindow *window)
602 EmpathyChatWindowPriv *priv;
604 priv = GET_PRIV (window);
606 if (priv->save_geometry_id != 0) {
607 g_source_remove (priv->save_geometry_id);
610 priv->save_geometry_id =
611 g_timeout_add_seconds (1,
612 (GSourceFunc) chat_window_save_geometry_timeout_cb,
619 chat_window_close_activate_cb (GtkAction *action,
620 EmpathyChatWindow *window)
622 EmpathyChatWindowPriv *priv;
624 priv = GET_PRIV (window);
626 g_return_if_fail (priv->current_chat != NULL);
628 empathy_chat_window_remove_chat (window, priv->current_chat);
632 chat_window_edit_activate_cb (GtkAction *action,
633 EmpathyChatWindow *window)
635 EmpathyChatWindowPriv *priv;
636 GtkClipboard *clipboard;
637 GtkTextBuffer *buffer;
638 gboolean text_available;
640 priv = GET_PRIV (window);
642 g_return_if_fail (priv->current_chat != NULL);
644 if (!empathy_chat_get_tp_chat (priv->current_chat)) {
645 gtk_action_set_sensitive (priv->menu_edit_copy, FALSE);
646 gtk_action_set_sensitive (priv->menu_edit_cut, FALSE);
647 gtk_action_set_sensitive (priv->menu_edit_paste, FALSE);
651 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->current_chat->input_text_view));
652 if (gtk_text_buffer_get_has_selection (buffer)) {
653 gtk_action_set_sensitive (priv->menu_edit_copy, TRUE);
654 gtk_action_set_sensitive (priv->menu_edit_cut, TRUE);
658 selection = empathy_chat_view_get_has_selection (priv->current_chat->view);
660 gtk_action_set_sensitive (priv->menu_edit_cut, FALSE);
661 gtk_action_set_sensitive (priv->menu_edit_copy, selection);
664 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
665 text_available = gtk_clipboard_wait_is_text_available (clipboard);
666 gtk_action_set_sensitive (priv->menu_edit_paste, text_available);
670 chat_window_cut_activate_cb (GtkAction *action,
671 EmpathyChatWindow *window)
673 EmpathyChatWindowPriv *priv;
675 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
677 priv = GET_PRIV (window);
679 empathy_chat_cut (priv->current_chat);
683 chat_window_copy_activate_cb (GtkAction *action,
684 EmpathyChatWindow *window)
686 EmpathyChatWindowPriv *priv;
688 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
690 priv = GET_PRIV (window);
692 empathy_chat_copy (priv->current_chat);
696 chat_window_paste_activate_cb (GtkAction *action,
697 EmpathyChatWindow *window)
699 EmpathyChatWindowPriv *priv;
701 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
703 priv = GET_PRIV (window);
705 empathy_chat_paste (priv->current_chat);
709 chat_window_tabs_left_activate_cb (GtkAction *action,
710 EmpathyChatWindow *window)
712 EmpathyChatWindowPriv *priv;
716 priv = GET_PRIV (window);
718 chat = priv->current_chat;
719 index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
724 gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
730 chat_window_tabs_right_activate_cb (GtkAction *action,
731 EmpathyChatWindow *window)
733 EmpathyChatWindowPriv *priv;
737 priv = GET_PRIV (window);
739 chat = priv->current_chat;
740 index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
742 gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
748 chat_window_detach_activate_cb (GtkAction *action,
749 EmpathyChatWindow *window)
751 EmpathyChatWindowPriv *priv;
752 EmpathyChatWindow *new_window;
755 priv = GET_PRIV (window);
757 chat = priv->current_chat;
758 new_window = empathy_chat_window_new ();
760 empathy_chat_window_move_chat (window, new_window, chat);
762 priv = GET_PRIV (new_window);
763 gtk_widget_show (priv->dialog);
767 chat_window_help_contents_activate_cb (GtkAction *action,
768 EmpathyChatWindow *window)
770 EmpathyChatWindowPriv *priv = GET_PRIV (window);
772 empathy_url_show (priv->dialog, "ghelp:empathy?chat");
776 chat_window_help_about_activate_cb (GtkAction *action,
777 EmpathyChatWindow *window)
779 EmpathyChatWindowPriv *priv = GET_PRIV (window);
781 empathy_about_dialog_new (GTK_WINDOW (priv->dialog));
785 chat_window_delete_event_cb (GtkWidget *dialog,
787 EmpathyChatWindow *window)
789 EmpathyChatWindowPriv *priv = GET_PRIV (window);
791 DEBUG ("Delete event received");
793 g_object_ref (window);
794 while (priv->chats) {
795 empathy_chat_window_remove_chat (window, priv->chats->data);
797 g_object_unref (window);
803 chat_window_composing_cb (EmpathyChat *chat,
804 gboolean is_composing,
805 EmpathyChatWindow *window)
807 EmpathyChatWindowPriv *priv;
809 priv = GET_PRIV (window);
811 if (is_composing && !g_list_find (priv->chats_composing, chat)) {
812 priv->chats_composing = g_list_prepend (priv->chats_composing, chat);
814 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
817 chat_window_update_chat_tab (chat);
821 chat_window_set_urgency_hint (EmpathyChatWindow *window,
824 EmpathyChatWindowPriv *priv;
826 priv = GET_PRIV (window);
828 DEBUG ("Turning %s urgency hint", urgent ? "on" : "off");
829 gtk_window_set_urgency_hint (GTK_WINDOW (priv->dialog), urgent);
833 EmpathyChatWindow *window;
838 chat_window_notification_closed_cb (NotifyNotification *notify,
839 NotificationData *cb_data)
841 EmpathyNotificationClosedReason reason = 0;
842 EmpathyChatWindowPriv *priv = GET_PRIV (cb_data->window);
844 #ifdef notify_notification_get_closed_reason
845 reason = notify_notification_get_closed_reason (notify);
847 if (reason == EMPATHY_NOTIFICATION_CLOSED_DISMISSED) {
848 empathy_chat_window_present_chat (cb_data->chat);
851 g_object_unref (notify);
852 priv->notification = NULL;
853 g_object_unref (cb_data->chat);
854 g_slice_free (NotificationData, cb_data);
858 chat_window_show_or_update_notification (EmpathyChatWindow *window,
859 EmpathyMessage *message,
862 EmpathyContact *sender;
863 char *header, *escaped;
866 NotificationData *cb_data;
867 EmpathyChatWindowPriv *priv = GET_PRIV (window);
870 if (!empathy_notification_is_enabled ()) {
873 empathy_conf_get_bool (empathy_conf_get (),
874 EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
880 cb_data = g_slice_new0 (NotificationData);
881 cb_data->chat = g_object_ref (chat);
882 cb_data->window = window;
884 sender = empathy_message_get_sender (message);
885 header = g_strdup_printf (_("New message from %s"),
886 empathy_contact_get_name (sender));
887 body = empathy_message_get_body (message);
888 escaped = g_markup_escape_text (body, -1);
890 pixbuf = empathy_misc_get_pixbuf_for_notification (sender, EMPATHY_IMAGE_NEW_MESSAGE);
892 if (priv->notification != NULL) {
893 notify_notification_update (priv->notification,
894 header, escaped, NULL);
895 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
897 priv->notification = notify_notification_new (header, escaped, NULL, NULL);
898 notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
899 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
901 g_signal_connect (priv->notification, "closed",
902 G_CALLBACK (chat_window_notification_closed_cb), cb_data);
905 notify_notification_show (priv->notification, NULL);
907 g_object_unref (pixbuf);
913 chat_window_new_message_cb (EmpathyChat *chat,
914 EmpathyMessage *message,
915 EmpathyChatWindow *window)
917 EmpathyChatWindowPriv *priv;
919 gboolean needs_urgency;
920 EmpathyContact *sender;
922 priv = GET_PRIV (window);
924 has_focus = empathy_chat_window_has_focus (window);
926 /* - if we're the sender, we play the sound if it's specified in the
927 * preferences and we're not away.
928 * - if we receive a message, we play the sound if it's specified in the
929 * preferences and the window does not have focus on the chat receiving
933 sender = empathy_message_get_sender (message);
935 if (empathy_contact_is_user (sender)) {
936 empathy_sound_play (GTK_WIDGET (priv->dialog),
937 EMPATHY_SOUND_MESSAGE_OUTGOING);
940 if (has_focus && priv->current_chat == chat) {
944 /* If empathy_chat_is_room () returns TRUE, that means it's a named MUC.
945 * If empathy_chat_get_remote_contact () returns NULL, that means it's
946 * an unamed MUC (msn-like).
947 * In case of a MUC, we set urgency only if the message contains our
949 if (empathy_chat_is_room (chat) ||
950 empathy_chat_get_remote_contact (chat) == NULL) {
951 needs_urgency = empathy_message_should_highlight (message);
953 needs_urgency = TRUE;
958 chat_window_set_urgency_hint (window, TRUE);
960 empathy_sound_play (GTK_WIDGET (priv->dialog),
961 EMPATHY_SOUND_MESSAGE_INCOMING);
962 chat_window_show_or_update_notification (window, message, chat);
965 if (!g_list_find (priv->chats_new_msg, chat)) {
966 priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
967 chat_window_update_chat_tab (chat);
972 chat_window_detach_hook (GtkNotebook *source,
978 EmpathyChatWindowPriv *priv;
979 EmpathyChatWindow *window, *new_window;
982 chat = EMPATHY_CHAT (page);
983 window = chat_window_find_chat (chat);
985 new_window = empathy_chat_window_new ();
986 priv = GET_PRIV (new_window);
988 DEBUG ("Detach hook called");
990 empathy_chat_window_move_chat (window, new_window, chat);
992 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
993 gtk_widget_show (priv->dialog);
999 chat_window_page_switched_cb (GtkNotebook *notebook,
1000 GtkNotebookPage *page,
1002 EmpathyChatWindow *window)
1004 EmpathyChatWindowPriv *priv;
1008 DEBUG ("Page switched");
1010 priv = GET_PRIV (window);
1012 child = gtk_notebook_get_nth_page (notebook, page_num);
1013 chat = EMPATHY_CHAT (child);
1015 if (priv->page_added) {
1016 priv->page_added = FALSE;
1017 empathy_chat_scroll_down (chat);
1019 else if (priv->current_chat == chat) {
1023 priv->current_chat = chat;
1024 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1026 chat_window_update_chat_tab (chat);
1030 chat_window_page_added_cb (GtkNotebook *notebook,
1033 EmpathyChatWindow *window)
1035 EmpathyChatWindowPriv *priv;
1038 priv = GET_PRIV (window);
1040 /* If we just received DND to the same window, we don't want
1041 * to do anything here like removing the tab and then readding
1042 * it, so we return here and in "page-added".
1044 if (priv->dnd_same_window) {
1045 DEBUG ("Page added (back to the same window)");
1046 priv->dnd_same_window = FALSE;
1050 DEBUG ("Page added");
1052 /* Get chat object */
1053 chat = EMPATHY_CHAT (child);
1055 /* Connect chat signals for this window */
1056 g_signal_connect (chat, "composing",
1057 G_CALLBACK (chat_window_composing_cb),
1059 g_signal_connect (chat, "new-message",
1060 G_CALLBACK (chat_window_new_message_cb),
1063 /* Set flag so we know to perform some special operations on
1064 * switch page due to the new page being added.
1066 priv->page_added = TRUE;
1068 /* Get list of chats up to date */
1069 priv->chats = g_list_append (priv->chats, chat);
1071 chat_window_update_chat_tab (chat);
1075 chat_window_page_removed_cb (GtkNotebook *notebook,
1078 EmpathyChatWindow *window)
1080 EmpathyChatWindowPriv *priv;
1083 priv = GET_PRIV (window);
1085 /* If we just received DND to the same window, we don't want
1086 * to do anything here like removing the tab and then readding
1087 * it, so we return here and in "page-added".
1089 if (priv->dnd_same_window) {
1090 DEBUG ("Page removed (and will be readded to same window)");
1094 DEBUG ("Page removed");
1096 /* Get chat object */
1097 chat = EMPATHY_CHAT (child);
1099 /* Disconnect all signal handlers for this chat and this window */
1100 g_signal_handlers_disconnect_by_func (chat,
1101 G_CALLBACK (chat_window_composing_cb),
1103 g_signal_handlers_disconnect_by_func (chat,
1104 G_CALLBACK (chat_window_new_message_cb),
1107 /* Keep list of chats up to date */
1108 priv->chats = g_list_remove (priv->chats, chat);
1109 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1110 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
1112 if (priv->chats == NULL) {
1113 g_object_unref (window);
1115 chat_window_update (window);
1120 chat_window_focus_in_event_cb (GtkWidget *widget,
1122 EmpathyChatWindow *window)
1124 EmpathyChatWindowPriv *priv;
1126 DEBUG ("Focus in event, updating title");
1128 priv = GET_PRIV (window);
1130 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
1132 chat_window_set_urgency_hint (window, FALSE);
1134 /* Update the title, since we now mark all unread messages as read. */
1135 chat_window_update_chat_tab (priv->current_chat);
1141 chat_window_drag_data_received (GtkWidget *widget,
1142 GdkDragContext *context,
1145 GtkSelectionData *selection,
1148 EmpathyChatWindow *window)
1150 if (info == DND_DRAG_TYPE_CONTACT_ID) {
1152 EmpathyChatWindow *old_window;
1156 const gchar *account_id;
1157 const gchar *contact_id;
1159 id = (const gchar*) selection->data;
1161 DEBUG ("DND contact from roster with id:'%s'", id);
1163 strv = g_strsplit (id, "/", 2);
1164 account_id = strv[0];
1165 contact_id = strv[1];
1166 account = mc_account_lookup (account_id);
1167 chat = empathy_chat_window_find_chat (account, contact_id);
1170 EmpathyAccountManager *account_manager;
1171 TpConnection *connection;
1173 account_manager = empathy_account_manager_dup_singleton ();
1174 connection = empathy_account_manager_get_connection (
1175 account_manager, account);
1178 empathy_dispatcher_chat_with_contact_id (
1179 connection, contact_id, NULL, NULL);
1182 g_object_unref (account_manager);
1183 g_object_unref (account);
1187 g_object_unref (account);
1190 old_window = chat_window_find_chat (chat);
1192 if (old_window == window) {
1193 gtk_drag_finish (context, TRUE, FALSE, time);
1197 empathy_chat_window_move_chat (old_window, window, chat);
1199 empathy_chat_window_add_chat (window, chat);
1202 /* Added to take care of any outstanding chat events */
1203 empathy_chat_window_present_chat (chat);
1205 /* We should return TRUE to remove the data when doing
1206 * GDK_ACTION_MOVE, but we don't here otherwise it has
1207 * weird consequences, and we handle that internally
1208 * anyway with add_chat () and remove_chat ().
1210 gtk_drag_finish (context, TRUE, FALSE, time);
1212 else if (info == DND_DRAG_TYPE_TAB) {
1214 EmpathyChatWindow *old_window = NULL;
1218 chat = (void *) selection->data;
1219 old_window = chat_window_find_chat (*chat);
1222 EmpathyChatWindowPriv *priv;
1224 priv = GET_PRIV (window);
1226 if (old_window == window) {
1227 DEBUG ("DND tab (within same window)");
1228 priv->dnd_same_window = TRUE;
1229 gtk_drag_finish (context, TRUE, FALSE, time);
1233 priv->dnd_same_window = FALSE;
1236 /* We should return TRUE to remove the data when doing
1237 * GDK_ACTION_MOVE, but we don't here otherwise it has
1238 * weird consequences, and we handle that internally
1239 * anyway with add_chat () and remove_chat ().
1241 gtk_drag_finish (context, TRUE, FALSE, time);
1243 DEBUG ("DND from unknown source");
1244 gtk_drag_finish (context, FALSE, FALSE, time);
1249 chat_window_finalize (GObject *object)
1251 EmpathyChatWindow *window;
1252 EmpathyChatWindowPriv *priv;
1254 window = EMPATHY_CHAT_WINDOW (object);
1255 priv = GET_PRIV (window);
1257 DEBUG ("Finalized: %p", object);
1259 g_object_unref (priv->ui_manager);
1260 g_object_unref (priv->chatroom_manager);
1261 if (priv->save_geometry_id != 0) {
1262 g_source_remove (priv->save_geometry_id);
1265 if (priv->notification != NULL) {
1266 notify_notification_close (priv->notification, NULL);
1267 g_object_unref (priv->notification);
1268 priv->notification = NULL;
1271 chat_windows = g_list_remove (chat_windows, window);
1272 gtk_widget_destroy (priv->dialog);
1274 G_OBJECT_CLASS (empathy_chat_window_parent_class)->finalize (object);
1278 empathy_chat_window_class_init (EmpathyChatWindowClass *klass)
1280 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1282 object_class->finalize = chat_window_finalize;
1284 g_type_class_add_private (object_class, sizeof (EmpathyChatWindowPriv));
1286 /* Set up a style for the close button with no focus padding. */
1287 gtk_rc_parse_string (
1288 "style \"empathy-close-button-style\"\n"
1290 " GtkWidget::focus-padding = 0\n"
1294 "widget \"*.empathy-close-button\" style \"empathy-close-button-style\"");
1296 gtk_notebook_set_window_creation_hook (chat_window_detach_hook, NULL, NULL);
1300 empathy_chat_window_init (EmpathyChatWindow *window)
1303 GtkAccelGroup *accel_group;
1308 GtkWidget *chat_vbox;
1310 EmpathySmileyManager *smiley_manager;
1311 EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1312 EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);
1314 window->priv = priv;
1315 filename = empathy_file_lookup ("empathy-chat-window.ui", "src");
1316 gui = empathy_builder_get_file (filename,
1317 "chat_window", &priv->dialog,
1318 "chat_vbox", &chat_vbox,
1319 "ui_manager", &priv->ui_manager,
1320 "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
1321 "menu_conv_favorite", &priv->menu_conv_favorite,
1322 "menu_edit_cut", &priv->menu_edit_cut,
1323 "menu_edit_copy", &priv->menu_edit_copy,
1324 "menu_edit_paste", &priv->menu_edit_paste,
1325 "menu_tabs_next", &priv->menu_tabs_next,
1326 "menu_tabs_prev", &priv->menu_tabs_prev,
1327 "menu_tabs_left", &priv->menu_tabs_left,
1328 "menu_tabs_right", &priv->menu_tabs_right,
1329 "menu_tabs_detach", &priv->menu_tabs_detach,
1333 empathy_builder_connect (gui, window,
1334 "chat_window", "configure-event", chat_window_configure_event_cb,
1335 "menu_conv", "activate", chat_window_conv_activate_cb,
1336 "menu_conv_clear", "activate", chat_window_clear_activate_cb,
1337 "menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb,
1338 "menu_conv_close", "activate", chat_window_close_activate_cb,
1339 "menu_edit", "activate", chat_window_edit_activate_cb,
1340 "menu_edit_cut", "activate", chat_window_cut_activate_cb,
1341 "menu_edit_copy", "activate", chat_window_copy_activate_cb,
1342 "menu_edit_paste", "activate", chat_window_paste_activate_cb,
1343 "menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
1344 "menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
1345 "menu_tabs_detach", "activate", chat_window_detach_activate_cb,
1346 "menu_help_contents", "activate", chat_window_help_contents_activate_cb,
1347 "menu_help_about", "activate", chat_window_help_about_activate_cb,
1350 g_object_ref (priv->ui_manager);
1351 g_object_unref (gui);
1353 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1355 priv->notebook = gtk_notebook_new ();
1356 gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow");
1357 gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0);
1358 gtk_widget_show (priv->notebook);
1361 accel_group = gtk_accel_group_new ();
1362 gtk_window_add_accel_group (GTK_WINDOW (priv->dialog), accel_group);
1364 for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
1365 closure = g_cclosure_new (G_CALLBACK (chat_window_accel_cb),
1368 gtk_accel_group_connect (accel_group,
1375 g_object_unref (accel_group);
1377 /* Set up smiley menu */
1378 smiley_manager = empathy_smiley_manager_dup_singleton ();
1379 submenu = empathy_smiley_menu_new (smiley_manager,
1380 chat_window_insert_smiley_activate_cb,
1382 menu = gtk_ui_manager_get_widget (priv->ui_manager,
1383 "/chats_menubar/menu_conv/menu_conv_insert_smiley");
1384 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu);
1385 g_object_unref (smiley_manager);
1387 /* Set up signals we can't do with ui file since we may need to
1388 * block/unblock them at some later stage.
1391 g_signal_connect (priv->dialog,
1393 G_CALLBACK (chat_window_delete_event_cb),
1396 g_signal_connect_swapped (priv->menu_tabs_prev,
1398 G_CALLBACK (gtk_notebook_prev_page),
1400 g_signal_connect_swapped (priv->menu_tabs_next,
1402 G_CALLBACK (gtk_notebook_next_page),
1405 g_signal_connect (priv->dialog,
1407 G_CALLBACK (chat_window_focus_in_event_cb),
1409 g_signal_connect_after (priv->notebook,
1411 G_CALLBACK (chat_window_page_switched_cb),
1413 g_signal_connect (priv->notebook,
1415 G_CALLBACK (chat_window_page_added_cb),
1417 g_signal_connect (priv->notebook,
1419 G_CALLBACK (chat_window_page_removed_cb),
1422 /* Set up drag and drop */
1423 gtk_drag_dest_set (GTK_WIDGET (priv->notebook),
1424 GTK_DEST_DEFAULT_ALL,
1426 G_N_ELEMENTS (drag_types_dest),
1429 g_signal_connect (priv->notebook,
1430 "drag-data-received",
1431 G_CALLBACK (chat_window_drag_data_received),
1434 chat_windows = g_list_prepend (chat_windows, window);
1436 /* Set up private details */
1438 priv->chats_new_msg = NULL;
1439 priv->chats_composing = NULL;
1440 priv->current_chat = NULL;
1444 empathy_chat_window_new (void)
1446 return EMPATHY_CHAT_WINDOW (g_object_new (EMPATHY_TYPE_CHAT_WINDOW, NULL));
1449 /* Returns the window to open a new tab in if there is only one window
1450 * visble, otherwise, returns NULL indicating that a new window should
1454 empathy_chat_window_get_default (void)
1457 gboolean separate_windows = TRUE;
1459 empathy_conf_get_bool (empathy_conf_get (),
1460 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
1463 if (separate_windows) {
1464 /* Always create a new window */
1468 for (l = chat_windows; l; l = l->next) {
1469 EmpathyChatWindow *chat_window;
1472 chat_window = l->data;
1474 dialog = empathy_chat_window_get_dialog (chat_window);
1475 if (empathy_window_get_is_visible (GTK_WINDOW (dialog))) {
1476 /* Found a visible window on this desktop */
1485 empathy_chat_window_get_dialog (EmpathyChatWindow *window)
1487 EmpathyChatWindowPriv *priv;
1489 g_return_val_if_fail (window != NULL, NULL);
1491 priv = GET_PRIV (window);
1493 return priv->dialog;
1497 empathy_chat_window_add_chat (EmpathyChatWindow *window,
1500 EmpathyChatWindowPriv *priv;
1505 g_return_if_fail (window != NULL);
1506 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1508 priv = GET_PRIV (window);
1510 /* Reference the chat object */
1511 g_object_ref (chat);
1513 /* If this window has just been created, position it */
1514 if (priv->chats == NULL) {
1515 empathy_geometry_load (chat_get_window_id_for_geometry (chat), &x, &y, &w, &h);
1517 if (x >= 0 && y >= 0) {
1518 /* Let the window manager position it if we don't have
1519 * good x, y coordinates.
1521 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
1524 if (w > 0 && h > 0) {
1525 /* Use the defaults from the ui file if we don't have
1526 * good w, h geometry.
1528 gtk_window_resize (GTK_WINDOW (priv->dialog), w, h);
1532 child = GTK_WIDGET (chat);
1533 label = chat_window_create_label (window, chat);
1534 gtk_widget_show (child);
1536 g_signal_connect (chat, "notify::name",
1537 G_CALLBACK (chat_window_chat_notify_cb),
1539 g_signal_connect (chat, "notify::subject",
1540 G_CALLBACK (chat_window_chat_notify_cb),
1542 g_signal_connect (chat, "notify::remote-contact",
1543 G_CALLBACK (chat_window_chat_notify_cb),
1545 chat_window_chat_notify_cb (chat);
1547 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
1548 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1549 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1550 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
1551 TRUE, TRUE, GTK_PACK_START);
1553 DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
1557 empathy_chat_window_remove_chat (EmpathyChatWindow *window,
1560 EmpathyChatWindowPriv *priv;
1562 EmpathyContact *remote_contact;
1564 g_return_if_fail (window != NULL);
1565 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1567 priv = GET_PRIV (window);
1569 g_signal_handlers_disconnect_by_func (chat,
1570 chat_window_chat_notify_cb,
1572 remote_contact = g_object_get_data (G_OBJECT (chat),
1573 "chat-window-remote-contact");
1574 if (remote_contact) {
1575 g_signal_handlers_disconnect_by_func (remote_contact,
1576 chat_window_update_chat_tab,
1580 position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1582 gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
1584 DEBUG ("Chat removed (%d references)", G_OBJECT (chat)->ref_count - 1);
1586 g_object_unref (chat);
1590 empathy_chat_window_move_chat (EmpathyChatWindow *old_window,
1591 EmpathyChatWindow *new_window,
1596 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (old_window));
1597 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (new_window));
1598 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1600 widget = GTK_WIDGET (chat);
1602 DEBUG ("Chat moving with widget:%p (%d references)", widget,
1603 G_OBJECT (widget)->ref_count);
1605 /* We reference here to make sure we don't loose the widget
1606 * and the EmpathyChat object during the move.
1608 g_object_ref (chat);
1609 g_object_ref (widget);
1611 empathy_chat_window_remove_chat (old_window, chat);
1612 empathy_chat_window_add_chat (new_window, chat);
1614 g_object_unref (widget);
1615 g_object_unref (chat);
1619 empathy_chat_window_switch_to_chat (EmpathyChatWindow *window,
1622 EmpathyChatWindowPriv *priv;
1625 g_return_if_fail (window != NULL);
1626 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1628 priv = GET_PRIV (window);
1630 page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1632 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1637 empathy_chat_window_has_focus (EmpathyChatWindow *window)
1639 EmpathyChatWindowPriv *priv;
1642 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1644 priv = GET_PRIV (window);
1646 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);
1652 empathy_chat_window_find_chat (McAccount *account,
1657 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
1658 g_return_val_if_fail (!EMP_STR_EMPTY (id), NULL);
1660 for (l = chat_windows; l; l = l->next) {
1661 EmpathyChatWindowPriv *priv;
1662 EmpathyChatWindow *window;
1666 priv = GET_PRIV (window);
1668 for (ll = priv->chats; ll; ll = ll->next) {
1673 if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
1674 !tp_strdiff (id, empathy_chat_get_id (chat))) {
1684 empathy_chat_window_present_chat (EmpathyChat *chat)
1686 EmpathyChatWindow *window;
1687 EmpathyChatWindowPriv *priv;
1689 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1691 window = chat_window_find_chat (chat);
1693 /* If the chat has no window, create one */
1694 if (window == NULL) {
1695 window = empathy_chat_window_get_default ();
1697 window = empathy_chat_window_new ();
1700 empathy_chat_window_add_chat (window, chat);
1703 priv = GET_PRIV (window);
1704 empathy_chat_window_switch_to_chat (window, chat);
1705 empathy_window_present (GTK_WINDOW (priv->dialog), TRUE);
1707 gtk_widget_grab_focus (chat->input_text_view);