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;
282 /* Get information */
283 page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
284 num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
285 first_page = (page_num == 0);
286 last_page = (page_num == (num_pages - 1));
287 is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
288 name = empathy_chat_get_name (priv->current_chat);
289 n_chats = g_list_length (priv->chats);
291 DEBUG ("Update window");
294 gtk_action_set_sensitive (priv->menu_tabs_next, !last_page);
295 gtk_action_set_sensitive (priv->menu_tabs_prev, !first_page);
296 gtk_action_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
297 gtk_action_set_sensitive (priv->menu_tabs_left, !first_page);
298 gtk_action_set_sensitive (priv->menu_tabs_right, !last_page);
299 gtk_action_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
301 /* Update window title */
303 gtk_window_set_title (GTK_WINDOW (priv->dialog), name);
307 title = g_strdup_printf (_("Conversations (%d)"), n_chats);
308 gtk_window_set_title (GTK_WINDOW (priv->dialog), title);
312 /* Update window icon */
313 if (priv->chats_new_msg) {
314 gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
315 EMPATHY_IMAGE_MESSAGE);
317 empathy_conf_get_bool (empathy_conf_get (),
318 EMPATHY_PREFS_CHAT_AVATAR_IN_ICON,
321 if (n_chats == 1 && avatar_in_icon) {
322 remote_contact = empathy_chat_get_remote_contact (priv->current_chat);
323 icon = empathy_pixbuf_avatar_from_contact_scaled (remote_contact, 0, 0);
324 gtk_window_set_icon (GTK_WINDOW (priv->dialog), icon);
327 g_object_unref (icon);
330 gtk_window_set_icon_name (GTK_WINDOW (priv->dialog), NULL);
334 if (num_pages == 1) {
335 chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 0);
336 chat_close_button = g_object_get_data (G_OBJECT (chat),
337 "chat-window-tab-close-button");
338 gtk_widget_hide (chat_close_button);
340 for (i=0; i<num_pages; i++) {
341 chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), i);
342 chat_close_button = g_object_get_data (G_OBJECT (chat),
343 "chat-window-tab-close-button");
344 gtk_widget_show (chat_close_button);
350 chat_window_update_chat_tab (EmpathyChat *chat)
352 EmpathyChatWindow *window;
353 EmpathyChatWindowPriv *priv;
354 EmpathyContact *remote_contact;
357 const gchar *subject;
361 const gchar *icon_name;
363 window = chat_window_find_chat (chat);
367 priv = GET_PRIV (window);
369 /* Get information */
370 name = empathy_chat_get_name (chat);
371 account = empathy_chat_get_account (chat);
372 subject = empathy_chat_get_subject (chat);
373 remote_contact = empathy_chat_get_remote_contact (chat);
375 DEBUG ("Updating chat tab, name=%s, account=%s, subject=%s, remote_contact=%p",
376 name, mc_account_get_unique_name (account), subject, remote_contact);
378 /* Update tab image */
379 if (g_list_find (priv->chats_new_msg, chat)) {
380 icon_name = EMPATHY_IMAGE_MESSAGE;
382 else if (g_list_find (priv->chats_composing, chat)) {
383 icon_name = EMPATHY_IMAGE_TYPING;
385 else if (remote_contact) {
386 icon_name = empathy_icon_name_for_contact (remote_contact);
388 icon_name = EMPATHY_IMAGE_GROUP_MESSAGE;
390 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-image");
391 gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_MENU);
393 /* Update tab tooltip */
394 tooltip = g_string_new (NULL);
396 if (remote_contact) {
397 markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>\n%s",
398 empathy_contact_get_id (remote_contact),
399 mc_account_get_display_name (account),
400 empathy_contact_get_status (remote_contact));
401 g_string_append (tooltip, markup);
405 markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>", name,
406 mc_account_get_display_name (account));
407 g_string_append (tooltip, markup);
412 markup = g_markup_printf_escaped ("\n<b>%s</b> %s", _("Topic:"), subject);
413 g_string_append (tooltip, markup);
416 if (g_list_find (priv->chats_composing, chat)) {
417 markup = g_markup_printf_escaped ("\n%s", _("Typing a message."));
418 g_string_append (tooltip, markup);
422 markup = g_string_free (tooltip, FALSE);
423 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget");
424 gtk_widget_set_tooltip_markup (widget, markup);
427 /* Update tab label */
428 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
429 gtk_label_set_text (GTK_LABEL (widget), name);
431 /* Update the window if it's the current chat */
432 if (priv->current_chat == chat) {
433 chat_window_update (window);
438 chat_window_chat_notify_cb (EmpathyChat *chat)
440 EmpathyContact *old_remote_contact;
441 EmpathyContact *remote_contact = NULL;
443 old_remote_contact = g_object_get_data (G_OBJECT (chat), "chat-window-remote-contact");
444 remote_contact = empathy_chat_get_remote_contact (chat);
446 if (old_remote_contact != remote_contact) {
447 /* The remote-contact associated with the chat changed, we need
448 * to keep track of any change of that contact and update the
449 * window each time. */
450 if (remote_contact) {
451 g_signal_connect_swapped (remote_contact, "notify",
452 G_CALLBACK (chat_window_update_chat_tab),
455 if (old_remote_contact) {
456 g_signal_handlers_disconnect_by_func (old_remote_contact,
457 chat_window_update_chat_tab,
461 g_object_set_data (G_OBJECT (chat), "chat-window-remote-contact",
465 chat_window_update_chat_tab (chat);
469 chat_window_insert_smiley_activate_cb (EmpathySmileyManager *manager,
470 EmpathySmiley *smiley,
473 EmpathyChatWindowPriv *priv = GET_PRIV (window);
475 GtkTextBuffer *buffer;
478 chat = priv->current_chat;
480 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
481 gtk_text_buffer_get_end_iter (buffer, &iter);
482 gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
486 chat_window_conv_activate_cb (GtkAction *action,
487 EmpathyChatWindow *window)
489 EmpathyChatWindowPriv *priv = GET_PRIV (window);
492 /* Favorite room menu */
493 is_room = empathy_chat_is_room (priv->current_chat);
499 room = empathy_chat_get_id (priv->current_chat);
500 account = empathy_chat_get_account (priv->current_chat);
501 found = empathy_chatroom_manager_find (priv->chatroom_manager,
502 account, room) != NULL;
504 DEBUG ("This room %s favorite", found ? "is" : "is not");
505 gtk_toggle_action_set_active (
506 GTK_TOGGLE_ACTION (priv->menu_conv_favorite), found);
508 gtk_action_set_visible (priv->menu_conv_favorite, is_room);
512 chat_window_clear_activate_cb (GtkAction *action,
513 EmpathyChatWindow *window)
515 EmpathyChatWindowPriv *priv = GET_PRIV (window);
517 empathy_chat_clear (priv->current_chat);
521 chat_window_favorite_toggled_cb (GtkToggleAction *toggle_action,
522 EmpathyChatWindow *window)
524 EmpathyChatWindowPriv *priv = GET_PRIV (window);
528 EmpathyChatroom *chatroom;
530 active = gtk_toggle_action_get_active (toggle_action);
531 account = empathy_chat_get_account (priv->current_chat);
532 room = empathy_chat_get_id (priv->current_chat);
534 chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
537 if (active && !chatroom) {
540 name = empathy_chat_get_name (priv->current_chat);
541 chatroom = empathy_chatroom_new_full (account, room, name, FALSE);
542 empathy_chatroom_manager_add (priv->chatroom_manager, chatroom);
543 g_object_unref (chatroom);
547 if (!active && chatroom) {
548 empathy_chatroom_manager_remove (priv->chatroom_manager, chatroom);
553 chat_get_window_id_for_geometry (EmpathyChat *chat)
555 const gchar *res = NULL;
556 gboolean separate_windows;
558 empathy_conf_get_bool (empathy_conf_get (),
559 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
562 if (separate_windows) {
563 res = empathy_chat_get_id (chat);
566 return res ? res : "chat-window";
570 chat_window_save_geometry_timeout_cb (EmpathyChatWindow *window)
572 EmpathyChatWindowPriv *priv;
575 priv = GET_PRIV (window);
577 gtk_window_get_size (GTK_WINDOW (priv->dialog), &w, &h);
578 gtk_window_get_position (GTK_WINDOW (priv->dialog), &x, &y);
580 empathy_geometry_save (chat_get_window_id_for_geometry (priv->current_chat),
583 priv->save_geometry_id = 0;
589 chat_window_configure_event_cb (GtkWidget *widget,
590 GdkEventConfigure *event,
591 EmpathyChatWindow *window)
593 EmpathyChatWindowPriv *priv;
595 priv = GET_PRIV (window);
597 if (priv->save_geometry_id != 0) {
598 g_source_remove (priv->save_geometry_id);
601 priv->save_geometry_id =
602 g_timeout_add_seconds (1,
603 (GSourceFunc) chat_window_save_geometry_timeout_cb,
610 chat_window_close_activate_cb (GtkAction *action,
611 EmpathyChatWindow *window)
613 EmpathyChatWindowPriv *priv;
615 priv = GET_PRIV (window);
617 g_return_if_fail (priv->current_chat != NULL);
619 empathy_chat_window_remove_chat (window, priv->current_chat);
623 chat_window_edit_activate_cb (GtkAction *action,
624 EmpathyChatWindow *window)
626 EmpathyChatWindowPriv *priv;
627 GtkClipboard *clipboard;
628 GtkTextBuffer *buffer;
629 gboolean text_available;
631 priv = GET_PRIV (window);
633 g_return_if_fail (priv->current_chat != NULL);
635 if (!empathy_chat_get_tp_chat (priv->current_chat)) {
636 gtk_action_set_sensitive (priv->menu_edit_copy, FALSE);
637 gtk_action_set_sensitive (priv->menu_edit_cut, FALSE);
638 gtk_action_set_sensitive (priv->menu_edit_paste, FALSE);
642 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->current_chat->input_text_view));
643 if (gtk_text_buffer_get_has_selection (buffer)) {
644 gtk_action_set_sensitive (priv->menu_edit_copy, TRUE);
645 gtk_action_set_sensitive (priv->menu_edit_cut, TRUE);
649 selection = empathy_chat_view_get_has_selection (priv->current_chat->view);
651 gtk_action_set_sensitive (priv->menu_edit_cut, FALSE);
652 gtk_action_set_sensitive (priv->menu_edit_copy, selection);
655 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
656 text_available = gtk_clipboard_wait_is_text_available (clipboard);
657 gtk_action_set_sensitive (priv->menu_edit_paste, text_available);
661 chat_window_cut_activate_cb (GtkAction *action,
662 EmpathyChatWindow *window)
664 EmpathyChatWindowPriv *priv;
666 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
668 priv = GET_PRIV (window);
670 empathy_chat_cut (priv->current_chat);
674 chat_window_copy_activate_cb (GtkAction *action,
675 EmpathyChatWindow *window)
677 EmpathyChatWindowPriv *priv;
679 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
681 priv = GET_PRIV (window);
683 empathy_chat_copy (priv->current_chat);
687 chat_window_paste_activate_cb (GtkAction *action,
688 EmpathyChatWindow *window)
690 EmpathyChatWindowPriv *priv;
692 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
694 priv = GET_PRIV (window);
696 empathy_chat_paste (priv->current_chat);
700 chat_window_tabs_left_activate_cb (GtkAction *action,
701 EmpathyChatWindow *window)
703 EmpathyChatWindowPriv *priv;
707 priv = GET_PRIV (window);
709 chat = priv->current_chat;
710 index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
715 gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
721 chat_window_tabs_right_activate_cb (GtkAction *action,
722 EmpathyChatWindow *window)
724 EmpathyChatWindowPriv *priv;
728 priv = GET_PRIV (window);
730 chat = priv->current_chat;
731 index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
733 gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
739 chat_window_detach_activate_cb (GtkAction *action,
740 EmpathyChatWindow *window)
742 EmpathyChatWindowPriv *priv;
743 EmpathyChatWindow *new_window;
746 priv = GET_PRIV (window);
748 chat = priv->current_chat;
749 new_window = empathy_chat_window_new ();
751 empathy_chat_window_move_chat (window, new_window, chat);
753 priv = GET_PRIV (new_window);
754 gtk_widget_show (priv->dialog);
758 chat_window_help_contents_activate_cb (GtkAction *action,
759 EmpathyChatWindow *window)
761 EmpathyChatWindowPriv *priv = GET_PRIV (window);
763 empathy_url_show (priv->dialog, "ghelp:empathy?chat");
767 chat_window_help_about_activate_cb (GtkAction *action,
768 EmpathyChatWindow *window)
770 EmpathyChatWindowPriv *priv = GET_PRIV (window);
772 empathy_about_dialog_new (GTK_WINDOW (priv->dialog));
776 chat_window_delete_event_cb (GtkWidget *dialog,
778 EmpathyChatWindow *window)
780 EmpathyChatWindowPriv *priv = GET_PRIV (window);
782 DEBUG ("Delete event received");
784 g_object_ref (window);
785 while (priv->chats) {
786 empathy_chat_window_remove_chat (window, priv->chats->data);
788 g_object_unref (window);
794 chat_window_composing_cb (EmpathyChat *chat,
795 gboolean is_composing,
796 EmpathyChatWindow *window)
798 EmpathyChatWindowPriv *priv;
800 priv = GET_PRIV (window);
802 if (is_composing && !g_list_find (priv->chats_composing, chat)) {
803 priv->chats_composing = g_list_prepend (priv->chats_composing, chat);
805 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
808 chat_window_update_chat_tab (chat);
812 chat_window_set_urgency_hint (EmpathyChatWindow *window,
815 EmpathyChatWindowPriv *priv;
817 priv = GET_PRIV (window);
819 DEBUG ("Turning %s urgency hint", urgent ? "on" : "off");
820 gtk_window_set_urgency_hint (GTK_WINDOW (priv->dialog), urgent);
824 EmpathyChatWindow *window;
829 chat_window_notification_closed_cb (NotifyNotification *notify,
830 NotificationData *cb_data)
832 EmpathyNotificationClosedReason reason = 0;
833 EmpathyChatWindowPriv *priv = GET_PRIV (cb_data->window);
835 #ifdef notify_notification_get_closed_reason
836 reason = notify_notification_get_closed_reason (notify);
838 if (reason == EMPATHY_NOTIFICATION_CLOSED_DISMISSED) {
839 empathy_chat_window_present_chat (cb_data->chat);
842 g_object_unref (notify);
843 priv->notification = NULL;
844 g_object_unref (cb_data->chat);
845 g_slice_free (NotificationData, cb_data);
849 chat_window_show_or_update_notification (EmpathyChatWindow *window,
850 EmpathyMessage *message,
853 EmpathyContact *sender;
854 char *header, *escaped;
857 NotificationData *cb_data;
858 EmpathyChatWindowPriv *priv = GET_PRIV (window);
861 if (!empathy_notification_is_enabled ()) {
864 empathy_conf_get_bool (empathy_conf_get (),
865 EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
871 cb_data = g_slice_new0 (NotificationData);
872 cb_data->chat = g_object_ref (chat);
873 cb_data->window = window;
875 sender = empathy_message_get_sender (message);
876 header = g_strdup_printf (_("New message from %s"),
877 empathy_contact_get_name (sender));
878 body = empathy_message_get_body (message);
879 escaped = g_markup_escape_text (body, -1);
881 pixbuf = empathy_misc_get_pixbuf_for_notification (sender, EMPATHY_IMAGE_NEW_MESSAGE);
883 if (priv->notification != NULL) {
884 notify_notification_update (priv->notification,
885 header, escaped, NULL);
886 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
888 priv->notification = notify_notification_new (header, escaped, NULL, NULL);
889 notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
890 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
892 g_signal_connect (priv->notification, "closed",
893 G_CALLBACK (chat_window_notification_closed_cb), cb_data);
896 notify_notification_show (priv->notification, NULL);
898 g_object_unref (pixbuf);
904 chat_window_new_message_cb (EmpathyChat *chat,
905 EmpathyMessage *message,
906 EmpathyChatWindow *window)
908 EmpathyChatWindowPriv *priv;
910 gboolean needs_urgency;
911 EmpathyContact *sender;
913 priv = GET_PRIV (window);
915 has_focus = empathy_chat_window_has_focus (window);
917 /* - if we're the sender, we play the sound if it's specified in the
918 * preferences and we're not away.
919 * - if we receive a message, we play the sound if it's specified in the
920 * prefereces and the window does not have focus on the chat receiving
924 sender = empathy_message_get_sender (message);
926 if (empathy_contact_is_user (sender) != FALSE) {
927 empathy_sound_play (GTK_WIDGET (priv->dialog),
928 EMPATHY_SOUND_MESSAGE_OUTGOING);
930 if ((!has_focus || priv->current_chat != chat)) {
931 empathy_sound_play (GTK_WIDGET (priv->dialog),
932 EMPATHY_SOUND_MESSAGE_INCOMING);
937 chat_window_show_or_update_notification (window, message, chat);
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;
956 if (needs_urgency && !has_focus) {
957 chat_window_set_urgency_hint (window, TRUE);
960 if (!g_list_find (priv->chats_new_msg, chat)) {
961 priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
962 chat_window_update_chat_tab (chat);
967 chat_window_detach_hook (GtkNotebook *source,
973 EmpathyChatWindowPriv *priv;
974 EmpathyChatWindow *window, *new_window;
977 chat = EMPATHY_CHAT (page);
978 window = chat_window_find_chat (chat);
980 new_window = empathy_chat_window_new ();
981 priv = GET_PRIV (new_window);
983 DEBUG ("Detach hook called");
985 empathy_chat_window_move_chat (window, new_window, chat);
987 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
988 gtk_widget_show (priv->dialog);
994 chat_window_page_switched_cb (GtkNotebook *notebook,
995 GtkNotebookPage *page,
997 EmpathyChatWindow *window)
999 EmpathyChatWindowPriv *priv;
1003 DEBUG ("Page switched");
1005 priv = GET_PRIV (window);
1007 child = gtk_notebook_get_nth_page (notebook, page_num);
1008 chat = EMPATHY_CHAT (child);
1010 if (priv->page_added) {
1011 priv->page_added = FALSE;
1012 empathy_chat_scroll_down (chat);
1014 else if (priv->current_chat == chat) {
1018 priv->current_chat = chat;
1019 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1021 chat_window_update_chat_tab (chat);
1025 chat_window_page_added_cb (GtkNotebook *notebook,
1028 EmpathyChatWindow *window)
1030 EmpathyChatWindowPriv *priv;
1033 priv = GET_PRIV (window);
1035 /* If we just received DND to the same window, we don't want
1036 * to do anything here like removing the tab and then readding
1037 * it, so we return here and in "page-added".
1039 if (priv->dnd_same_window) {
1040 DEBUG ("Page added (back to the same window)");
1041 priv->dnd_same_window = FALSE;
1045 DEBUG ("Page added");
1047 /* Get chat object */
1048 chat = EMPATHY_CHAT (child);
1050 /* Connect chat signals for this window */
1051 g_signal_connect (chat, "composing",
1052 G_CALLBACK (chat_window_composing_cb),
1054 g_signal_connect (chat, "new-message",
1055 G_CALLBACK (chat_window_new_message_cb),
1058 /* Set flag so we know to perform some special operations on
1059 * switch page due to the new page being added.
1061 priv->page_added = TRUE;
1063 /* Get list of chats up to date */
1064 priv->chats = g_list_append (priv->chats, chat);
1066 chat_window_update_chat_tab (chat);
1070 chat_window_page_removed_cb (GtkNotebook *notebook,
1073 EmpathyChatWindow *window)
1075 EmpathyChatWindowPriv *priv;
1078 priv = GET_PRIV (window);
1080 /* If we just received DND to the same window, we don't want
1081 * to do anything here like removing the tab and then readding
1082 * it, so we return here and in "page-added".
1084 if (priv->dnd_same_window) {
1085 DEBUG ("Page removed (and will be readded to same window)");
1089 DEBUG ("Page removed");
1091 /* Get chat object */
1092 chat = EMPATHY_CHAT (child);
1094 /* Disconnect all signal handlers for this chat and this window */
1095 g_signal_handlers_disconnect_by_func (chat,
1096 G_CALLBACK (chat_window_composing_cb),
1098 g_signal_handlers_disconnect_by_func (chat,
1099 G_CALLBACK (chat_window_new_message_cb),
1102 /* Keep list of chats up to date */
1103 priv->chats = g_list_remove (priv->chats, chat);
1104 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1105 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
1107 if (priv->chats == NULL) {
1108 g_object_unref (window);
1110 chat_window_update (window);
1115 chat_window_focus_in_event_cb (GtkWidget *widget,
1117 EmpathyChatWindow *window)
1119 EmpathyChatWindowPriv *priv;
1121 DEBUG ("Focus in event, updating title");
1123 priv = GET_PRIV (window);
1125 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
1127 chat_window_set_urgency_hint (window, FALSE);
1129 /* Update the title, since we now mark all unread messages as read. */
1130 chat_window_update_chat_tab (priv->current_chat);
1136 chat_window_drag_data_received (GtkWidget *widget,
1137 GdkDragContext *context,
1140 GtkSelectionData *selection,
1143 EmpathyChatWindow *window)
1145 if (info == DND_DRAG_TYPE_CONTACT_ID) {
1147 EmpathyChatWindow *old_window;
1151 const gchar *account_id;
1152 const gchar *contact_id;
1154 id = (const gchar*) selection->data;
1156 DEBUG ("DND contact from roster with id:'%s'", id);
1158 strv = g_strsplit (id, "/", 2);
1159 account_id = strv[0];
1160 contact_id = strv[1];
1161 account = mc_account_lookup (account_id);
1162 chat = empathy_chat_window_find_chat (account, contact_id);
1165 EmpathyAccountManager *account_manager;
1166 TpConnection *connection;
1168 account_manager = empathy_account_manager_dup_singleton ();
1169 connection = empathy_account_manager_get_connection (
1170 account_manager, account);
1173 empathy_dispatcher_chat_with_contact_id (
1174 connection, contact_id, NULL, NULL);
1177 g_object_unref (account_manager);
1178 g_object_unref (account);
1182 g_object_unref (account);
1185 old_window = chat_window_find_chat (chat);
1187 if (old_window == window) {
1188 gtk_drag_finish (context, TRUE, FALSE, time);
1192 empathy_chat_window_move_chat (old_window, window, chat);
1194 empathy_chat_window_add_chat (window, chat);
1197 /* Added to take care of any outstanding chat events */
1198 empathy_chat_window_present_chat (chat);
1200 /* We should return TRUE to remove the data when doing
1201 * GDK_ACTION_MOVE, but we don't here otherwise it has
1202 * weird consequences, and we handle that internally
1203 * anyway with add_chat () and remove_chat ().
1205 gtk_drag_finish (context, TRUE, FALSE, time);
1207 else if (info == DND_DRAG_TYPE_TAB) {
1209 EmpathyChatWindow *old_window = NULL;
1213 chat = (void *) selection->data;
1214 old_window = chat_window_find_chat (*chat);
1217 EmpathyChatWindowPriv *priv;
1219 priv = GET_PRIV (window);
1221 if (old_window == window) {
1222 DEBUG ("DND tab (within same window)");
1223 priv->dnd_same_window = TRUE;
1224 gtk_drag_finish (context, TRUE, FALSE, time);
1228 priv->dnd_same_window = FALSE;
1231 /* We should return TRUE to remove the data when doing
1232 * GDK_ACTION_MOVE, but we don't here otherwise it has
1233 * weird consequences, and we handle that internally
1234 * anyway with add_chat () and remove_chat ().
1236 gtk_drag_finish (context, TRUE, FALSE, time);
1238 DEBUG ("DND from unknown source");
1239 gtk_drag_finish (context, FALSE, FALSE, time);
1244 chat_window_finalize (GObject *object)
1246 EmpathyChatWindow *window;
1247 EmpathyChatWindowPriv *priv;
1249 window = EMPATHY_CHAT_WINDOW (object);
1250 priv = GET_PRIV (window);
1252 DEBUG ("Finalized: %p", object);
1254 g_object_unref (priv->ui_manager);
1255 g_object_unref (priv->chatroom_manager);
1256 if (priv->save_geometry_id != 0) {
1257 g_source_remove (priv->save_geometry_id);
1260 if (priv->notification != NULL) {
1261 notify_notification_close (priv->notification, NULL);
1262 g_object_unref (priv->notification);
1263 priv->notification = NULL;
1266 chat_windows = g_list_remove (chat_windows, window);
1267 gtk_widget_destroy (priv->dialog);
1269 G_OBJECT_CLASS (empathy_chat_window_parent_class)->finalize (object);
1273 empathy_chat_window_class_init (EmpathyChatWindowClass *klass)
1275 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1277 object_class->finalize = chat_window_finalize;
1279 g_type_class_add_private (object_class, sizeof (EmpathyChatWindowPriv));
1281 /* Set up a style for the close button with no focus padding. */
1282 gtk_rc_parse_string (
1283 "style \"empathy-close-button-style\"\n"
1285 " GtkWidget::focus-padding = 0\n"
1289 "widget \"*.empathy-close-button\" style \"empathy-close-button-style\"");
1291 gtk_notebook_set_window_creation_hook (chat_window_detach_hook, NULL, NULL);
1295 empathy_chat_window_init (EmpathyChatWindow *window)
1298 GtkAccelGroup *accel_group;
1303 GtkWidget *chat_vbox;
1305 EmpathySmileyManager *smiley_manager;
1306 EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1307 EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);
1309 window->priv = priv;
1310 filename = empathy_file_lookup ("empathy-chat-window.ui", "src");
1311 gui = empathy_builder_get_file (filename,
1312 "chat_window", &priv->dialog,
1313 "chat_vbox", &chat_vbox,
1314 "ui_manager", &priv->ui_manager,
1315 "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
1316 "menu_conv_favorite", &priv->menu_conv_favorite,
1317 "menu_edit_cut", &priv->menu_edit_cut,
1318 "menu_edit_copy", &priv->menu_edit_copy,
1319 "menu_edit_paste", &priv->menu_edit_paste,
1320 "menu_tabs_next", &priv->menu_tabs_next,
1321 "menu_tabs_prev", &priv->menu_tabs_prev,
1322 "menu_tabs_left", &priv->menu_tabs_left,
1323 "menu_tabs_right", &priv->menu_tabs_right,
1324 "menu_tabs_detach", &priv->menu_tabs_detach,
1328 empathy_builder_connect (gui, window,
1329 "chat_window", "configure-event", chat_window_configure_event_cb,
1330 "menu_conv", "activate", chat_window_conv_activate_cb,
1331 "menu_conv_clear", "activate", chat_window_clear_activate_cb,
1332 "menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb,
1333 "menu_conv_close", "activate", chat_window_close_activate_cb,
1334 "menu_edit", "activate", chat_window_edit_activate_cb,
1335 "menu_edit_cut", "activate", chat_window_cut_activate_cb,
1336 "menu_edit_copy", "activate", chat_window_copy_activate_cb,
1337 "menu_edit_paste", "activate", chat_window_paste_activate_cb,
1338 "menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
1339 "menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
1340 "menu_tabs_detach", "activate", chat_window_detach_activate_cb,
1341 "menu_help_contents", "activate", chat_window_help_contents_activate_cb,
1342 "menu_help_about", "activate", chat_window_help_about_activate_cb,
1345 g_object_ref (priv->ui_manager);
1346 g_object_unref (gui);
1348 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1350 priv->notebook = gtk_notebook_new ();
1351 gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow");
1352 gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0);
1353 gtk_widget_show (priv->notebook);
1356 accel_group = gtk_accel_group_new ();
1357 gtk_window_add_accel_group (GTK_WINDOW (priv->dialog), accel_group);
1359 for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
1360 closure = g_cclosure_new (G_CALLBACK (chat_window_accel_cb),
1363 gtk_accel_group_connect (accel_group,
1370 g_object_unref (accel_group);
1372 /* Set up smiley menu */
1373 smiley_manager = empathy_smiley_manager_dup_singleton ();
1374 submenu = empathy_smiley_menu_new (smiley_manager,
1375 chat_window_insert_smiley_activate_cb,
1377 menu = gtk_ui_manager_get_widget (priv->ui_manager,
1378 "/chats_menubar/menu_conv/menu_conv_insert_smiley");
1379 gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), submenu);
1380 g_object_unref (smiley_manager);
1382 /* Set up signals we can't do with ui file since we may need to
1383 * block/unblock them at some later stage.
1386 g_signal_connect (priv->dialog,
1388 G_CALLBACK (chat_window_delete_event_cb),
1391 g_signal_connect_swapped (priv->menu_tabs_prev,
1393 G_CALLBACK (gtk_notebook_prev_page),
1395 g_signal_connect_swapped (priv->menu_tabs_next,
1397 G_CALLBACK (gtk_notebook_next_page),
1400 g_signal_connect (priv->dialog,
1402 G_CALLBACK (chat_window_focus_in_event_cb),
1404 g_signal_connect_after (priv->notebook,
1406 G_CALLBACK (chat_window_page_switched_cb),
1408 g_signal_connect (priv->notebook,
1410 G_CALLBACK (chat_window_page_added_cb),
1412 g_signal_connect (priv->notebook,
1414 G_CALLBACK (chat_window_page_removed_cb),
1417 /* Set up drag and drop */
1418 gtk_drag_dest_set (GTK_WIDGET (priv->notebook),
1419 GTK_DEST_DEFAULT_ALL,
1421 G_N_ELEMENTS (drag_types_dest),
1424 g_signal_connect (priv->notebook,
1425 "drag-data-received",
1426 G_CALLBACK (chat_window_drag_data_received),
1429 chat_windows = g_list_prepend (chat_windows, window);
1431 /* Set up private details */
1433 priv->chats_new_msg = NULL;
1434 priv->chats_composing = NULL;
1435 priv->current_chat = NULL;
1439 empathy_chat_window_new (void)
1441 return EMPATHY_CHAT_WINDOW (g_object_new (EMPATHY_TYPE_CHAT_WINDOW, NULL));
1444 /* Returns the window to open a new tab in if there is only one window
1445 * visble, otherwise, returns NULL indicating that a new window should
1449 empathy_chat_window_get_default (void)
1452 gboolean separate_windows = TRUE;
1454 empathy_conf_get_bool (empathy_conf_get (),
1455 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
1458 if (separate_windows) {
1459 /* Always create a new window */
1463 for (l = chat_windows; l; l = l->next) {
1464 EmpathyChatWindow *chat_window;
1467 chat_window = l->data;
1469 dialog = empathy_chat_window_get_dialog (chat_window);
1470 if (empathy_window_get_is_visible (GTK_WINDOW (dialog))) {
1471 /* Found a visible window on this desktop */
1480 empathy_chat_window_get_dialog (EmpathyChatWindow *window)
1482 EmpathyChatWindowPriv *priv;
1484 g_return_val_if_fail (window != NULL, NULL);
1486 priv = GET_PRIV (window);
1488 return priv->dialog;
1492 empathy_chat_window_add_chat (EmpathyChatWindow *window,
1495 EmpathyChatWindowPriv *priv;
1500 g_return_if_fail (window != NULL);
1501 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1503 priv = GET_PRIV (window);
1505 /* Reference the chat object */
1506 g_object_ref (chat);
1508 /* If this window has just been created, position it */
1509 if (priv->chats == NULL) {
1510 empathy_geometry_load (chat_get_window_id_for_geometry (chat), &x, &y, &w, &h);
1512 if (x >= 0 && y >= 0) {
1513 /* Let the window manager position it if we don't have
1514 * good x, y coordinates.
1516 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
1519 if (w > 0 && h > 0) {
1520 /* Use the defaults from the ui file if we don't have
1521 * good w, h geometry.
1523 gtk_window_resize (GTK_WINDOW (priv->dialog), w, h);
1527 child = GTK_WIDGET (chat);
1528 label = chat_window_create_label (window, chat);
1529 gtk_widget_show (child);
1531 g_signal_connect (chat, "notify::name",
1532 G_CALLBACK (chat_window_chat_notify_cb),
1534 g_signal_connect (chat, "notify::subject",
1535 G_CALLBACK (chat_window_chat_notify_cb),
1537 g_signal_connect (chat, "notify::remote-contact",
1538 G_CALLBACK (chat_window_chat_notify_cb),
1540 chat_window_chat_notify_cb (chat);
1542 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
1543 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1544 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1545 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
1546 TRUE, TRUE, GTK_PACK_START);
1548 DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
1552 empathy_chat_window_remove_chat (EmpathyChatWindow *window,
1555 EmpathyChatWindowPriv *priv;
1557 EmpathyContact *remote_contact;
1559 g_return_if_fail (window != NULL);
1560 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1562 priv = GET_PRIV (window);
1564 g_signal_handlers_disconnect_by_func (chat,
1565 chat_window_chat_notify_cb,
1567 remote_contact = g_object_get_data (G_OBJECT (chat),
1568 "chat-window-remote-contact");
1569 if (remote_contact) {
1570 g_signal_handlers_disconnect_by_func (remote_contact,
1571 chat_window_update_chat_tab,
1575 position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1577 gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
1579 DEBUG ("Chat removed (%d references)", G_OBJECT (chat)->ref_count - 1);
1581 g_object_unref (chat);
1585 empathy_chat_window_move_chat (EmpathyChatWindow *old_window,
1586 EmpathyChatWindow *new_window,
1591 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (old_window));
1592 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (new_window));
1593 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1595 widget = GTK_WIDGET (chat);
1597 DEBUG ("Chat moving with widget:%p (%d references)", widget,
1598 G_OBJECT (widget)->ref_count);
1600 /* We reference here to make sure we don't loose the widget
1601 * and the EmpathyChat object during the move.
1603 g_object_ref (chat);
1604 g_object_ref (widget);
1606 empathy_chat_window_remove_chat (old_window, chat);
1607 empathy_chat_window_add_chat (new_window, chat);
1609 g_object_unref (widget);
1610 g_object_unref (chat);
1614 empathy_chat_window_switch_to_chat (EmpathyChatWindow *window,
1617 EmpathyChatWindowPriv *priv;
1620 g_return_if_fail (window != NULL);
1621 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1623 priv = GET_PRIV (window);
1625 page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1627 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1632 empathy_chat_window_has_focus (EmpathyChatWindow *window)
1634 EmpathyChatWindowPriv *priv;
1637 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1639 priv = GET_PRIV (window);
1641 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);
1647 empathy_chat_window_find_chat (McAccount *account,
1652 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
1653 g_return_val_if_fail (!EMP_STR_EMPTY (id), NULL);
1655 for (l = chat_windows; l; l = l->next) {
1656 EmpathyChatWindowPriv *priv;
1657 EmpathyChatWindow *window;
1661 priv = GET_PRIV (window);
1663 for (ll = priv->chats; ll; ll = ll->next) {
1668 if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
1669 !tp_strdiff (id, empathy_chat_get_id (chat))) {
1679 empathy_chat_window_present_chat (EmpathyChat *chat)
1681 EmpathyChatWindow *window;
1682 EmpathyChatWindowPriv *priv;
1684 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1686 window = chat_window_find_chat (chat);
1688 /* If the chat has no window, create one */
1689 if (window == NULL) {
1690 window = empathy_chat_window_get_default ();
1692 window = empathy_chat_window_new ();
1695 empathy_chat_window_add_chat (window, chat);
1698 priv = GET_PRIV (window);
1699 empathy_chat_window_switch_to_chat (window, chat);
1700 empathy_window_present (GTK_WINDOW (priv->dialog), TRUE);
1702 gtk_widget_grab_focus (chat->input_text_view);