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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, 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 <glade/glade.h>
35 #include <glib/gi18n.h>
36 #include <libnotify/notification.h>
38 #include <telepathy-glib/util.h>
39 #include <libmissioncontrol/mission-control.h>
41 #include <libempathy/empathy-contact-factory.h>
42 #include <libempathy/empathy-contact.h>
43 #include <libempathy/empathy-message.h>
44 #include <libempathy/empathy-dispatcher.h>
45 #include <libempathy/empathy-chatroom-manager.h>
46 #include <libempathy/empathy-utils.h>
48 #include <libempathy-gtk/empathy-images.h>
49 #include <libempathy-gtk/empathy-conf.h>
50 #include <libempathy-gtk/empathy-contact-dialogs.h>
51 #include <libempathy-gtk/empathy-log-window.h>
52 #include <libempathy-gtk/empathy-geometry.h>
53 #include <libempathy-gtk/empathy-smiley-manager.h>
54 #include <libempathy-gtk/empathy-ui-utils.h>
56 #include "empathy-chat-window.h"
57 #include "empathy-about-dialog.h"
58 #include "empathy-misc.h"
60 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
61 #include <libempathy/empathy-debug.h>
63 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChatWindow)
65 EmpathyChat *current_chat;
68 GList *chats_composing;
70 gboolean dnd_same_window;
71 guint save_geometry_id;
72 EmpathyChatroomManager *chatroom_manager;
75 NotifyNotification *notification;
78 GtkWidget *menu_conv_clear;
79 GtkWidget *menu_conv_insert_smiley;
80 GtkWidget *menu_conv_contact;
81 GtkWidget *menu_conv_favorite;
82 GtkWidget *menu_conv_close;
84 GtkWidget *menu_edit_cut;
85 GtkWidget *menu_edit_copy;
86 GtkWidget *menu_edit_paste;
88 GtkWidget *menu_tabs_next;
89 GtkWidget *menu_tabs_prev;
90 GtkWidget *menu_tabs_left;
91 GtkWidget *menu_tabs_right;
92 GtkWidget *menu_tabs_detach;
94 GtkWidget *menu_help_contents;
95 GtkWidget *menu_help_about;
96 } EmpathyChatWindowPriv;
98 static GList *chat_windows = NULL;
100 static const guint tab_accel_keys[] = {
101 GDK_1, GDK_2, GDK_3, GDK_4, GDK_5,
102 GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
106 DND_DRAG_TYPE_CONTACT_ID,
110 static const GtkTargetEntry drag_types_dest[] = {
111 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
112 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, DND_DRAG_TYPE_TAB },
115 G_DEFINE_TYPE (EmpathyChatWindow, empathy_chat_window, G_TYPE_OBJECT);
118 chat_window_accel_cb (GtkAccelGroup *accelgroup,
122 EmpathyChatWindow *window)
124 EmpathyChatWindowPriv *priv;
128 priv = GET_PRIV (window);
130 for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
131 if (tab_accel_keys[i] == key) {
138 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), num);
142 static EmpathyChatWindow *
143 chat_window_find_chat (EmpathyChat *chat)
145 EmpathyChatWindowPriv *priv;
148 for (l = chat_windows; l; l = l->next) {
149 priv = GET_PRIV (l->data);
150 ll = g_list_find (priv->chats, chat);
160 chat_window_close_clicked_cb (GtkWidget *button,
163 EmpathyChatWindow *window;
165 window = chat_window_find_chat (chat);
166 empathy_chat_window_remove_chat (window, chat);
170 chat_window_close_button_style_set_cb (GtkWidget *button,
171 GtkStyle *previous_style,
176 gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
177 GTK_ICON_SIZE_MENU, &w, &h);
179 gtk_widget_set_size_request (button, w, h);
183 chat_window_create_label (EmpathyChatWindow *window,
186 EmpathyChatWindowPriv *priv;
188 GtkWidget *name_label;
189 GtkWidget *status_image;
190 GtkWidget *close_button;
191 GtkWidget *close_image;
192 GtkWidget *event_box;
193 GtkWidget *event_box_hbox;
194 PangoAttrList *attr_list;
195 PangoAttribute *attr;
197 priv = GET_PRIV (window);
199 /* The spacing between the button and the label. */
200 hbox = gtk_hbox_new (FALSE, 0);
202 event_box = gtk_event_box_new ();
203 gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
205 name_label = gtk_label_new (NULL);
206 gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
208 attr_list = pango_attr_list_new ();
209 attr = pango_attr_scale_new (1/1.2);
210 attr->start_index = 0;
211 attr->end_index = -1;
212 pango_attr_list_insert (attr_list, attr);
213 gtk_label_set_attributes (GTK_LABEL (name_label), attr_list);
214 pango_attr_list_unref (attr_list);
216 gtk_misc_set_padding (GTK_MISC (name_label), 2, 0);
217 gtk_misc_set_alignment (GTK_MISC (name_label), 0.0, 0.5);
218 g_object_set_data (G_OBJECT (chat), "chat-window-tab-label", name_label);
220 status_image = gtk_image_new ();
222 /* Spacing between the icon and label. */
223 event_box_hbox = gtk_hbox_new (FALSE, 0);
225 gtk_box_pack_start (GTK_BOX (event_box_hbox), status_image, FALSE, FALSE, 0);
226 gtk_box_pack_start (GTK_BOX (event_box_hbox), name_label, TRUE, TRUE, 0);
228 g_object_set_data (G_OBJECT (chat), "chat-window-tab-image", status_image);
229 g_object_set_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget", event_box);
231 close_button = gtk_button_new ();
232 gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
233 g_object_set_data (G_OBJECT (chat), "chat-window-tab-close-button", close_button);
235 /* We don't want focus/keynav for the button to avoid clutter, and
236 * Ctrl-W works anyway.
238 GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_FOCUS);
239 GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_DEFAULT);
241 /* Set the name to make the special rc style match. */
242 gtk_widget_set_name (close_button, "empathy-close-button");
244 close_image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
246 gtk_container_add (GTK_CONTAINER (close_button), close_image);
248 gtk_container_add (GTK_CONTAINER (event_box), event_box_hbox);
249 gtk_box_pack_start (GTK_BOX (hbox), event_box, TRUE, TRUE, 0);
250 gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
252 /* React to theme changes and also used to setup the initial size
255 g_signal_connect (close_button,
257 G_CALLBACK (chat_window_close_button_style_set_cb),
260 g_signal_connect (close_button,
262 G_CALLBACK (chat_window_close_clicked_cb),
265 gtk_widget_show_all (hbox);
271 chat_window_update (EmpathyChatWindow *window)
273 EmpathyChatWindowPriv *priv = GET_PRIV (window);
276 gboolean is_connected;
283 EmpathyContact *remote_contact;
284 gboolean avatar_in_icon;
286 GtkWidget *chat_close_button;
288 /* Get information */
289 page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
290 num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
291 first_page = (page_num == 0);
292 last_page = (page_num == (num_pages - 1));
293 is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
294 name = empathy_chat_get_name (priv->current_chat);
295 n_chats = g_list_length (priv->chats);
297 DEBUG ("Update window");
300 gtk_widget_set_sensitive (priv->menu_tabs_next, !last_page);
301 gtk_widget_set_sensitive (priv->menu_tabs_prev, !first_page);
302 gtk_widget_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
303 gtk_widget_set_sensitive (priv->menu_tabs_left, !first_page);
304 gtk_widget_set_sensitive (priv->menu_tabs_right, !last_page);
305 gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
307 /* Update window title */
309 gtk_window_set_title (GTK_WINDOW (priv->dialog), name);
313 title = g_strdup_printf (_("Conversations (%d)"), n_chats);
314 gtk_window_set_title (GTK_WINDOW (priv->dialog), title);
318 /* Update window icon */
319 if (priv->chats_new_msg) {
320 gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
321 EMPATHY_IMAGE_MESSAGE);
323 empathy_conf_get_bool (empathy_conf_get (),
324 EMPATHY_PREFS_CHAT_AVATAR_IN_ICON,
327 if (n_chats == 1 && avatar_in_icon) {
328 remote_contact = empathy_chat_get_remote_contact (priv->current_chat);
329 icon = empathy_pixbuf_avatar_from_contact_scaled (remote_contact, 0, 0);
330 gtk_window_set_icon (GTK_WINDOW (priv->dialog), icon);
333 g_object_unref (icon);
336 gtk_window_set_icon_name (GTK_WINDOW (priv->dialog), NULL);
340 if (num_pages == 1) {
341 chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 0);
342 chat_close_button = g_object_get_data (G_OBJECT (chat),
343 "chat-window-tab-close-button");
344 gtk_widget_hide (chat_close_button);
346 for (i=0; i<num_pages; i++) {
347 chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), i);
348 chat_close_button = g_object_get_data (G_OBJECT (chat),
349 "chat-window-tab-close-button");
350 gtk_widget_show (chat_close_button);
356 chat_window_update_chat_tab (EmpathyChat *chat)
358 EmpathyChatWindow *window;
359 EmpathyChatWindowPriv *priv;
360 EmpathyContact *remote_contact;
363 const gchar *subject;
367 const gchar *icon_name;
369 window = chat_window_find_chat (chat);
373 priv = GET_PRIV (window);
375 /* Get information */
376 name = empathy_chat_get_name (chat);
377 account = empathy_chat_get_account (chat);
378 subject = empathy_chat_get_subject (chat);
379 remote_contact = empathy_chat_get_remote_contact (chat);
381 DEBUG ("Updating chat tab, name=%s, account=%s, subject=%s, remote_contact=%p",
382 name, mc_account_get_unique_name (account), subject, remote_contact);
384 /* Update tab image */
385 if (g_list_find (priv->chats_new_msg, chat)) {
386 icon_name = EMPATHY_IMAGE_MESSAGE;
388 else if (g_list_find (priv->chats_composing, chat)) {
389 icon_name = EMPATHY_IMAGE_TYPING;
391 else if (remote_contact) {
392 icon_name = empathy_icon_name_for_contact (remote_contact);
394 icon_name = EMPATHY_IMAGE_GROUP_MESSAGE;
396 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-image");
397 gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_MENU);
399 /* Update tab tooltip */
400 tooltip = g_string_new (NULL);
402 if (remote_contact) {
403 markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>\n%s",
404 empathy_contact_get_id (remote_contact),
405 mc_account_get_display_name (account),
406 empathy_contact_get_status (remote_contact));
407 g_string_append (tooltip, markup);
411 markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>", name,
412 mc_account_get_display_name (account));
413 g_string_append (tooltip, markup);
418 markup = g_markup_printf_escaped ("\n<b>%s</b> %s", _("Topic:"), subject);
419 g_string_append (tooltip, markup);
422 if (g_list_find (priv->chats_composing, chat)) {
423 markup = g_markup_printf_escaped ("\n%s", _("Typing a message."));
424 g_string_append (tooltip, markup);
428 markup = g_string_free (tooltip, FALSE);
429 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget");
430 gtk_widget_set_tooltip_markup (widget, markup);
433 /* Update tab label */
434 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
435 gtk_label_set_text (GTK_LABEL (widget), name);
437 /* Update the window if it's the current chat */
438 if (priv->current_chat == chat) {
439 chat_window_update (window);
444 chat_window_chat_notify_cb (EmpathyChat *chat)
446 EmpathyContact *old_remote_contact;
447 EmpathyContact *remote_contact = NULL;
449 old_remote_contact = g_object_get_data (G_OBJECT (chat), "chat-window-remote-contact");
450 remote_contact = empathy_chat_get_remote_contact (chat);
452 if (old_remote_contact != remote_contact) {
453 /* The remote-contact associated with the chat changed, we need
454 * to keep track of any change of that contact and update the
455 * window each time. */
456 if (remote_contact) {
457 g_signal_connect_swapped (remote_contact, "notify",
458 G_CALLBACK (chat_window_update_chat_tab),
461 if (old_remote_contact) {
462 g_signal_handlers_disconnect_by_func (old_remote_contact,
463 chat_window_update_chat_tab,
467 g_object_set_data (G_OBJECT (chat), "chat-window-remote-contact",
471 chat_window_update_chat_tab (chat);
475 chat_window_insert_smiley_activate_cb (EmpathySmileyManager *manager,
476 EmpathySmiley *smiley,
479 EmpathyChatWindowPriv *priv = GET_PRIV (window);
481 GtkTextBuffer *buffer;
484 chat = priv->current_chat;
486 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
487 gtk_text_buffer_get_end_iter (buffer, &iter);
488 gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
492 chat_window_conv_activate_cb (GtkWidget *menuitem,
493 EmpathyChatWindow *window)
495 EmpathyChatWindowPriv *priv = GET_PRIV (window);
496 GtkWidget *submenu = NULL;
498 /* Contact submenu */
499 submenu = empathy_chat_get_contact_menu (priv->current_chat);
501 gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_contact),
503 gtk_widget_show (priv->menu_conv_contact);
504 gtk_widget_show (submenu);
506 gtk_widget_hide (priv->menu_conv_contact);
509 /* Favorite room menu */
510 if (empathy_chat_is_room (priv->current_chat)) {
515 room = empathy_chat_get_id (priv->current_chat);
516 account = empathy_chat_get_account (priv->current_chat);
517 found = empathy_chatroom_manager_find (priv->chatroom_manager,
518 account, room) != NULL;
520 DEBUG ("This room %s favorite", found ? "is" : "is not");
521 gtk_check_menu_item_set_active (
522 GTK_CHECK_MENU_ITEM (priv->menu_conv_favorite), found);
523 gtk_widget_show (priv->menu_conv_favorite);
525 gtk_widget_hide (priv->menu_conv_favorite);
530 chat_window_clear_activate_cb (GtkWidget *menuitem,
531 EmpathyChatWindow *window)
533 EmpathyChatWindowPriv *priv = GET_PRIV (window);
535 empathy_chat_clear (priv->current_chat);
539 chat_window_favorite_toggled_cb (GtkCheckMenuItem *menuitem,
540 EmpathyChatWindow *window)
542 EmpathyChatWindowPriv *priv = GET_PRIV (window);
546 EmpathyChatroom *chatroom;
548 active = gtk_check_menu_item_get_active (menuitem);
549 account = empathy_chat_get_account (priv->current_chat);
550 room = empathy_chat_get_id (priv->current_chat);
552 chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
555 if (active && !chatroom) {
558 name = empathy_chat_get_name (priv->current_chat);
559 chatroom = empathy_chatroom_new_full (account, room, name, FALSE);
560 empathy_chatroom_manager_add (priv->chatroom_manager, chatroom);
561 g_object_unref (chatroom);
565 if (!active && chatroom) {
566 empathy_chatroom_manager_remove (priv->chatroom_manager, chatroom);
571 chat_get_window_id_for_geometry (EmpathyChat *chat)
573 const gchar *res = NULL;
574 gboolean separate_windows;
576 empathy_conf_get_bool (empathy_conf_get (),
577 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
580 if (separate_windows) {
581 res = empathy_chat_get_id (chat);
584 return res ? res : "chat-window";
588 chat_window_save_geometry_timeout_cb (EmpathyChatWindow *window)
590 EmpathyChatWindowPriv *priv;
593 priv = GET_PRIV (window);
595 gtk_window_get_size (GTK_WINDOW (priv->dialog), &w, &h);
596 gtk_window_get_position (GTK_WINDOW (priv->dialog), &x, &y);
598 empathy_geometry_save (chat_get_window_id_for_geometry (priv->current_chat),
601 priv->save_geometry_id = 0;
607 chat_window_configure_event_cb (GtkWidget *widget,
608 GdkEventConfigure *event,
609 EmpathyChatWindow *window)
611 EmpathyChatWindowPriv *priv;
613 priv = GET_PRIV (window);
615 if (priv->save_geometry_id != 0) {
616 g_source_remove (priv->save_geometry_id);
619 priv->save_geometry_id =
620 g_timeout_add_seconds (1,
621 (GSourceFunc) chat_window_save_geometry_timeout_cb,
628 chat_window_close_activate_cb (GtkWidget *menuitem,
629 EmpathyChatWindow *window)
631 EmpathyChatWindowPriv *priv;
633 priv = GET_PRIV (window);
635 g_return_if_fail (priv->current_chat != NULL);
637 empathy_chat_window_remove_chat (window, priv->current_chat);
641 chat_window_edit_activate_cb (GtkWidget *menuitem,
642 EmpathyChatWindow *window)
644 EmpathyChatWindowPriv *priv;
645 GtkClipboard *clipboard;
646 GtkTextBuffer *buffer;
647 gboolean text_available;
649 priv = GET_PRIV (window);
651 g_return_if_fail (priv->current_chat != NULL);
653 if (!empathy_chat_get_tp_chat (priv->current_chat)) {
654 gtk_widget_set_sensitive (priv->menu_edit_copy, FALSE);
655 gtk_widget_set_sensitive (priv->menu_edit_cut, FALSE);
656 gtk_widget_set_sensitive (priv->menu_edit_paste, FALSE);
660 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->current_chat->input_text_view));
661 if (gtk_text_buffer_get_has_selection (buffer)) {
662 gtk_widget_set_sensitive (priv->menu_edit_copy, TRUE);
663 gtk_widget_set_sensitive (priv->menu_edit_cut, TRUE);
667 selection = empathy_chat_view_get_has_selection (priv->current_chat->view);
669 gtk_widget_set_sensitive (priv->menu_edit_cut, FALSE);
670 gtk_widget_set_sensitive (priv->menu_edit_copy, selection);
673 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
674 text_available = gtk_clipboard_wait_is_text_available (clipboard);
675 gtk_widget_set_sensitive (priv->menu_edit_paste, text_available);
679 chat_window_cut_activate_cb (GtkWidget *menuitem,
680 EmpathyChatWindow *window)
682 EmpathyChatWindowPriv *priv;
684 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
686 priv = GET_PRIV (window);
688 empathy_chat_cut (priv->current_chat);
692 chat_window_copy_activate_cb (GtkWidget *menuitem,
693 EmpathyChatWindow *window)
695 EmpathyChatWindowPriv *priv;
697 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
699 priv = GET_PRIV (window);
701 empathy_chat_copy (priv->current_chat);
705 chat_window_paste_activate_cb (GtkWidget *menuitem,
706 EmpathyChatWindow *window)
708 EmpathyChatWindowPriv *priv;
710 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
712 priv = GET_PRIV (window);
714 empathy_chat_paste (priv->current_chat);
718 chat_window_tabs_left_activate_cb (GtkWidget *menuitem,
719 EmpathyChatWindow *window)
721 EmpathyChatWindowPriv *priv;
725 priv = GET_PRIV (window);
727 chat = priv->current_chat;
728 index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
733 gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
739 chat_window_tabs_right_activate_cb (GtkWidget *menuitem,
740 EmpathyChatWindow *window)
742 EmpathyChatWindowPriv *priv;
746 priv = GET_PRIV (window);
748 chat = priv->current_chat;
749 index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
751 gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
757 chat_window_detach_activate_cb (GtkWidget *menuitem,
758 EmpathyChatWindow *window)
760 EmpathyChatWindowPriv *priv;
761 EmpathyChatWindow *new_window;
764 priv = GET_PRIV (window);
766 chat = priv->current_chat;
767 new_window = empathy_chat_window_new ();
769 empathy_chat_window_move_chat (window, new_window, chat);
771 priv = GET_PRIV (new_window);
772 gtk_widget_show (priv->dialog);
776 chat_window_help_contents_cb (GtkWidget *menuitem,
777 EmpathyChatWindow *window)
779 empathy_url_show (menuitem, "ghelp:empathy?chat");
783 chat_window_help_about_cb (GtkWidget *menuitem,
784 EmpathyChatWindow *window)
786 EmpathyChatWindowPriv *priv = GET_PRIV (window);
788 empathy_about_dialog_new (GTK_WINDOW (priv->dialog));
792 chat_window_delete_event_cb (GtkWidget *dialog,
794 EmpathyChatWindow *window)
796 EmpathyChatWindowPriv *priv = GET_PRIV (window);
798 DEBUG ("Delete event received");
800 g_object_ref (window);
801 while (priv->chats) {
802 empathy_chat_window_remove_chat (window, priv->chats->data);
804 g_object_unref (window);
810 chat_window_composing_cb (EmpathyChat *chat,
811 gboolean is_composing,
812 EmpathyChatWindow *window)
814 EmpathyChatWindowPriv *priv;
816 priv = GET_PRIV (window);
818 if (is_composing && !g_list_find (priv->chats_composing, chat)) {
819 priv->chats_composing = g_list_prepend (priv->chats_composing, chat);
821 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
824 chat_window_update_chat_tab (chat);
828 chat_window_set_urgency_hint (EmpathyChatWindow *window,
831 EmpathyChatWindowPriv *priv;
833 priv = GET_PRIV (window);
835 DEBUG ("Turning %s urgency hint", urgent ? "on" : "off");
836 gtk_window_set_urgency_hint (GTK_WINDOW (priv->dialog), urgent);
840 EmpathyChatWindow *window;
845 chat_window_notification_closed_cb (NotifyNotification *notify,
846 NotificationData *cb_data)
848 EmpathyNotificationClosedReason reason = 0;
849 EmpathyChatWindowPriv *priv = GET_PRIV (cb_data->window);
851 #ifdef notify_notification_get_closed_reason
852 reason = notify_notification_get_closed_reason (notify);
854 if (reason == EMPATHY_NOTIFICATION_CLOSED_DISMISSED) {
855 empathy_chat_window_present_chat (cb_data->chat);
858 g_object_unref (notify);
859 priv->notification = NULL;
860 g_object_unref (cb_data->chat);
861 g_slice_free (NotificationData, cb_data);
865 chat_window_show_or_update_notification (EmpathyChatWindow *window,
866 EmpathyMessage *message,
869 EmpathyContact *sender;
870 char *header, *escaped;
873 NotificationData *cb_data;
874 EmpathyChatWindowPriv *priv = GET_PRIV (window);
877 if (!empathy_notification_is_enabled ()) {
880 empathy_conf_get_bool (empathy_conf_get (),
881 EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
887 cb_data = g_slice_new0 (NotificationData);
888 cb_data->chat = g_object_ref (chat);
889 cb_data->window = window;
891 sender = empathy_message_get_sender (message);
892 header = g_strdup_printf (_("New message from %s"),
893 empathy_contact_get_name (sender));
894 body = empathy_message_get_body (message);
895 escaped = g_markup_escape_text (body, -1);
897 pixbuf = empathy_misc_get_pixbuf_for_notification (sender, EMPATHY_IMAGE_NEW_MESSAGE);
899 if (priv->notification != NULL) {
900 notify_notification_update (priv->notification,
901 header, escaped, NULL);
902 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
904 priv->notification = notify_notification_new (header, escaped, NULL, NULL);
905 notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
906 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
908 g_signal_connect (priv->notification, "closed",
909 G_CALLBACK (chat_window_notification_closed_cb), cb_data);
912 notify_notification_show (priv->notification, NULL);
914 g_object_unref (pixbuf);
920 chat_window_new_message_cb (EmpathyChat *chat,
921 EmpathyMessage *message,
922 EmpathyChatWindow *window)
924 EmpathyChatWindowPriv *priv;
926 gboolean needs_urgency;
927 EmpathyContact *sender;
929 priv = GET_PRIV (window);
931 has_focus = empathy_chat_window_has_focus (window);
933 /* - if we're the sender, we play the sound if it's specified in the
934 * preferences and we're not away.
935 * - if we receive a message, we play the sound if it's specified in the
936 * prefereces and the window does not have focus on the chat receiving
940 sender = empathy_message_get_sender (message);
942 if (empathy_contact_is_user (sender) != FALSE) {
943 empathy_sound_play (GTK_WIDGET (priv->dialog),
944 EMPATHY_SOUND_MESSAGE_OUTGOING);
946 if ((!has_focus || priv->current_chat != chat)) {
947 empathy_sound_play (GTK_WIDGET (priv->dialog),
948 EMPATHY_SOUND_MESSAGE_INCOMING);
953 chat_window_show_or_update_notification (window, message, chat);
956 if (has_focus && priv->current_chat == chat) {
960 if (empathy_chat_get_members_count (chat) > 2) {
961 needs_urgency = empathy_message_should_highlight (message);
963 needs_urgency = TRUE;
966 if (needs_urgency && !has_focus) {
967 chat_window_set_urgency_hint (window, TRUE);
970 if (!g_list_find (priv->chats_new_msg, chat)) {
971 priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
972 chat_window_update_chat_tab (chat);
977 chat_window_detach_hook (GtkNotebook *source,
983 EmpathyChatWindowPriv *priv;
984 EmpathyChatWindow *window, *new_window;
987 chat = EMPATHY_CHAT (page);
988 window = chat_window_find_chat (chat);
990 new_window = empathy_chat_window_new ();
991 priv = GET_PRIV (new_window);
993 DEBUG ("Detach hook called");
995 empathy_chat_window_move_chat (window, new_window, chat);
997 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
998 gtk_widget_show (priv->dialog);
1004 chat_window_page_switched_cb (GtkNotebook *notebook,
1005 GtkNotebookPage *page,
1007 EmpathyChatWindow *window)
1009 EmpathyChatWindowPriv *priv;
1013 DEBUG ("Page switched");
1015 priv = GET_PRIV (window);
1017 child = gtk_notebook_get_nth_page (notebook, page_num);
1018 chat = EMPATHY_CHAT (child);
1020 if (priv->page_added) {
1021 priv->page_added = FALSE;
1022 empathy_chat_scroll_down (chat);
1024 else if (priv->current_chat == chat) {
1028 priv->current_chat = chat;
1029 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1031 chat_window_update_chat_tab (chat);
1035 chat_window_page_added_cb (GtkNotebook *notebook,
1038 EmpathyChatWindow *window)
1040 EmpathyChatWindowPriv *priv;
1043 priv = GET_PRIV (window);
1045 /* If we just received DND to the same window, we don't want
1046 * to do anything here like removing the tab and then readding
1047 * it, so we return here and in "page-added".
1049 if (priv->dnd_same_window) {
1050 DEBUG ("Page added (back to the same window)");
1051 priv->dnd_same_window = FALSE;
1055 DEBUG ("Page added");
1057 /* Get chat object */
1058 chat = EMPATHY_CHAT (child);
1060 /* Connect chat signals for this window */
1061 g_signal_connect (chat, "composing",
1062 G_CALLBACK (chat_window_composing_cb),
1064 g_signal_connect (chat, "new-message",
1065 G_CALLBACK (chat_window_new_message_cb),
1068 /* Set flag so we know to perform some special operations on
1069 * switch page due to the new page being added.
1071 priv->page_added = TRUE;
1073 /* Get list of chats up to date */
1074 priv->chats = g_list_append (priv->chats, chat);
1076 chat_window_update_chat_tab (chat);
1080 chat_window_page_removed_cb (GtkNotebook *notebook,
1083 EmpathyChatWindow *window)
1085 EmpathyChatWindowPriv *priv;
1088 priv = GET_PRIV (window);
1090 /* If we just received DND to the same window, we don't want
1091 * to do anything here like removing the tab and then readding
1092 * it, so we return here and in "page-added".
1094 if (priv->dnd_same_window) {
1095 DEBUG ("Page removed (and will be readded to same window)");
1099 DEBUG ("Page removed");
1101 /* Get chat object */
1102 chat = EMPATHY_CHAT (child);
1104 /* Disconnect all signal handlers for this chat and this window */
1105 g_signal_handlers_disconnect_by_func (chat,
1106 G_CALLBACK (chat_window_composing_cb),
1108 g_signal_handlers_disconnect_by_func (chat,
1109 G_CALLBACK (chat_window_new_message_cb),
1112 /* Keep list of chats up to date */
1113 priv->chats = g_list_remove (priv->chats, chat);
1114 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1115 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
1117 if (priv->chats == NULL) {
1118 g_object_unref (window);
1120 chat_window_update (window);
1125 chat_window_focus_in_event_cb (GtkWidget *widget,
1127 EmpathyChatWindow *window)
1129 EmpathyChatWindowPriv *priv;
1131 DEBUG ("Focus in event, updating title");
1133 priv = GET_PRIV (window);
1135 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
1137 chat_window_set_urgency_hint (window, FALSE);
1139 /* Update the title, since we now mark all unread messages as read. */
1140 chat_window_update_chat_tab (priv->current_chat);
1146 chat_window_drag_data_received (GtkWidget *widget,
1147 GdkDragContext *context,
1150 GtkSelectionData *selection,
1153 EmpathyChatWindow *window)
1155 if (info == DND_DRAG_TYPE_CONTACT_ID) {
1157 EmpathyChatWindow *old_window;
1162 id = (const gchar*) selection->data;
1164 DEBUG ("DND contact from roster with id:'%s'", id);
1166 strv = g_strsplit (id, "/", 2);
1167 account = mc_account_lookup (strv[0]);
1168 chat = empathy_chat_window_find_chat (account, strv[1]);
1171 empathy_dispatcher_chat_with_contact_id (account, strv[2], NULL, NULL);
1172 g_object_unref (account);
1176 g_object_unref (account);
1179 old_window = chat_window_find_chat (chat);
1181 if (old_window == window) {
1182 gtk_drag_finish (context, TRUE, FALSE, time);
1186 empathy_chat_window_move_chat (old_window, window, chat);
1188 empathy_chat_window_add_chat (window, chat);
1191 /* Added to take care of any outstanding chat events */
1192 empathy_chat_window_present_chat (chat);
1194 /* We should return TRUE to remove the data when doing
1195 * GDK_ACTION_MOVE, but we don't here otherwise it has
1196 * weird consequences, and we handle that internally
1197 * anyway with add_chat() and remove_chat().
1199 gtk_drag_finish (context, TRUE, FALSE, time);
1201 else if (info == DND_DRAG_TYPE_TAB) {
1203 EmpathyChatWindow *old_window = NULL;
1207 chat = (void*) selection->data;
1208 old_window = chat_window_find_chat (*chat);
1211 EmpathyChatWindowPriv *priv;
1213 priv = GET_PRIV (window);
1215 if (old_window == window) {
1216 DEBUG ("DND tab (within same window)");
1217 priv->dnd_same_window = TRUE;
1218 gtk_drag_finish (context, TRUE, FALSE, time);
1222 priv->dnd_same_window = FALSE;
1225 /* We should return TRUE to remove the data when doing
1226 * GDK_ACTION_MOVE, but we don't here otherwise it has
1227 * weird consequences, and we handle that internally
1228 * anyway with add_chat() and remove_chat().
1230 gtk_drag_finish (context, TRUE, FALSE, time);
1232 DEBUG ("DND from unknown source");
1233 gtk_drag_finish (context, FALSE, FALSE, time);
1238 chat_window_finalize (GObject *object)
1240 EmpathyChatWindow *window;
1241 EmpathyChatWindowPriv *priv;
1243 window = EMPATHY_CHAT_WINDOW (object);
1244 priv = GET_PRIV (window);
1246 DEBUG ("Finalized: %p", object);
1248 g_object_unref (priv->chatroom_manager);
1249 if (priv->save_geometry_id != 0) {
1250 g_source_remove (priv->save_geometry_id);
1253 if (priv->notification != NULL) {
1254 notify_notification_close (priv->notification, NULL);
1255 g_object_unref (priv->notification);
1256 priv->notification = NULL;
1259 chat_windows = g_list_remove (chat_windows, window);
1260 gtk_widget_destroy (priv->dialog);
1262 G_OBJECT_CLASS (empathy_chat_window_parent_class)->finalize (object);
1266 empathy_chat_window_class_init (EmpathyChatWindowClass *klass)
1268 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1270 object_class->finalize = chat_window_finalize;
1272 g_type_class_add_private (object_class, sizeof (EmpathyChatWindowPriv));
1274 /* Set up a style for the close button with no focus padding. */
1275 gtk_rc_parse_string (
1276 "style \"empathy-close-button-style\"\n"
1278 " GtkWidget::focus-padding = 0\n"
1282 "widget \"*.empathy-close-button\" style \"empathy-close-button-style\"");
1284 gtk_notebook_set_window_creation_hook (chat_window_detach_hook, NULL, NULL);
1288 empathy_chat_window_init (EmpathyChatWindow *window)
1291 GtkAccelGroup *accel_group;
1293 GtkWidget *menu_conv;
1296 GtkWidget *chat_vbox;
1298 EmpathySmileyManager *smiley_manager;
1299 EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1300 EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);
1302 window->priv = priv;
1303 filename = empathy_file_lookup ("empathy-chat-window.glade", "src");
1304 glade = empathy_glade_get_file (filename,
1307 "chat_window", &priv->dialog,
1308 "chat_vbox", &chat_vbox,
1309 "menu_conv", &menu_conv,
1310 "menu_conv_clear", &priv->menu_conv_clear,
1311 "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
1312 "menu_conv_contact", &priv->menu_conv_contact,
1313 "menu_conv_favorite", &priv->menu_conv_favorite,
1314 "menu_conv_close", &priv->menu_conv_close,
1315 "menu_edit_cut", &priv->menu_edit_cut,
1316 "menu_edit_copy", &priv->menu_edit_copy,
1317 "menu_edit_paste", &priv->menu_edit_paste,
1318 "menu_tabs_next", &priv->menu_tabs_next,
1319 "menu_tabs_prev", &priv->menu_tabs_prev,
1320 "menu_tabs_left", &priv->menu_tabs_left,
1321 "menu_tabs_right", &priv->menu_tabs_right,
1322 "menu_tabs_detach", &priv->menu_tabs_detach,
1323 "menu_help_contents", &priv->menu_help_contents,
1324 "menu_help_about", &priv->menu_help_about,
1328 empathy_glade_connect (glade,
1330 "chat_window", "configure-event", chat_window_configure_event_cb,
1331 "menu_conv", "activate", chat_window_conv_activate_cb,
1332 "menu_conv_clear", "activate", chat_window_clear_activate_cb,
1333 "menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb,
1334 "menu_conv_close", "activate", chat_window_close_activate_cb,
1335 "menu_edit", "activate", chat_window_edit_activate_cb,
1336 "menu_edit_cut", "activate", chat_window_cut_activate_cb,
1337 "menu_edit_copy", "activate", chat_window_copy_activate_cb,
1338 "menu_edit_paste", "activate", chat_window_paste_activate_cb,
1339 "menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
1340 "menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
1341 "menu_tabs_detach", "activate", chat_window_detach_activate_cb,
1342 "menu_help_contents", "activate", chat_window_help_contents_cb,
1343 "menu_help_about", "activate", chat_window_help_about_cb,
1346 g_object_unref (glade);
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 menu = empathy_smiley_menu_new (smiley_manager,
1375 chat_window_insert_smiley_activate_cb,
1377 gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_insert_smiley),
1379 g_object_unref (smiley_manager);
1381 /* Set up signals we can't do with glade since we may need to
1382 * block/unblock them at some later stage.
1385 g_signal_connect (priv->dialog,
1387 G_CALLBACK (chat_window_delete_event_cb),
1390 g_signal_connect_swapped (priv->menu_tabs_prev,
1392 G_CALLBACK (gtk_notebook_prev_page),
1394 g_signal_connect_swapped (priv->menu_tabs_next,
1396 G_CALLBACK (gtk_notebook_next_page),
1399 g_signal_connect (priv->dialog,
1401 G_CALLBACK (chat_window_focus_in_event_cb),
1403 g_signal_connect_after (priv->notebook,
1405 G_CALLBACK (chat_window_page_switched_cb),
1407 g_signal_connect (priv->notebook,
1409 G_CALLBACK (chat_window_page_added_cb),
1411 g_signal_connect (priv->notebook,
1413 G_CALLBACK (chat_window_page_removed_cb),
1416 /* Set up drag and drop */
1417 gtk_drag_dest_set (GTK_WIDGET (priv->notebook),
1418 GTK_DEST_DEFAULT_ALL,
1420 G_N_ELEMENTS (drag_types_dest),
1423 g_signal_connect (priv->notebook,
1424 "drag-data-received",
1425 G_CALLBACK (chat_window_drag_data_received),
1428 chat_windows = g_list_prepend (chat_windows, window);
1430 /* Set up private details */
1432 priv->chats_new_msg = NULL;
1433 priv->chats_composing = NULL;
1434 priv->current_chat = NULL;
1438 empathy_chat_window_new (void)
1440 return EMPATHY_CHAT_WINDOW (g_object_new (EMPATHY_TYPE_CHAT_WINDOW, NULL));
1443 /* Returns the window to open a new tab in if there is only one window
1444 * visble, otherwise, returns NULL indicating that a new window should
1448 empathy_chat_window_get_default (void)
1451 gboolean separate_windows = TRUE;
1453 empathy_conf_get_bool (empathy_conf_get (),
1454 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
1457 if (separate_windows) {
1458 /* Always create a new window */
1462 for (l = chat_windows; l; l = l->next) {
1463 EmpathyChatWindow *chat_window;
1466 chat_window = l->data;
1468 dialog = empathy_chat_window_get_dialog (chat_window);
1469 if (empathy_window_get_is_visible (GTK_WINDOW (dialog))) {
1470 /* Found a visible window on this desktop */
1479 empathy_chat_window_get_dialog (EmpathyChatWindow *window)
1481 EmpathyChatWindowPriv *priv;
1483 g_return_val_if_fail (window != NULL, NULL);
1485 priv = GET_PRIV (window);
1487 return priv->dialog;
1491 empathy_chat_window_add_chat (EmpathyChatWindow *window,
1494 EmpathyChatWindowPriv *priv;
1499 g_return_if_fail (window != NULL);
1500 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1502 priv = GET_PRIV (window);
1504 /* Reference the chat object */
1505 g_object_ref (chat);
1507 /* If this window has just been created, position it */
1508 if (priv->chats == NULL) {
1509 empathy_geometry_load (chat_get_window_id_for_geometry (chat), &x, &y, &w, &h);
1511 if (x >= 0 && y >= 0) {
1512 /* Let the window manager position it if we don't have
1513 * good x, y coordinates.
1515 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
1518 if (w > 0 && h > 0) {
1519 /* Use the defaults from the glade file if we don't have
1520 * good w, h geometry.
1522 gtk_window_resize (GTK_WINDOW (priv->dialog), w, h);
1526 child = GTK_WIDGET (chat);
1527 label = chat_window_create_label (window, chat);
1528 gtk_widget_show (child);
1530 g_signal_connect (chat, "notify::name",
1531 G_CALLBACK (chat_window_chat_notify_cb),
1533 g_signal_connect (chat, "notify::subject",
1534 G_CALLBACK (chat_window_chat_notify_cb),
1536 g_signal_connect (chat, "notify::remote-contact",
1537 G_CALLBACK (chat_window_chat_notify_cb),
1539 chat_window_chat_notify_cb (chat);
1541 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
1542 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1543 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1544 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
1545 TRUE, TRUE, GTK_PACK_START);
1547 DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
1551 empathy_chat_window_remove_chat (EmpathyChatWindow *window,
1554 EmpathyChatWindowPriv *priv;
1556 EmpathyContact *remote_contact;
1558 g_return_if_fail (window != NULL);
1559 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1561 priv = GET_PRIV (window);
1563 g_signal_handlers_disconnect_by_func (chat,
1564 chat_window_chat_notify_cb,
1566 remote_contact = g_object_get_data (G_OBJECT (chat),
1567 "chat-window-remote-contact");
1568 if (remote_contact) {
1569 g_signal_handlers_disconnect_by_func (remote_contact,
1570 chat_window_update_chat_tab,
1574 position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1576 gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
1578 DEBUG ("Chat removed (%d references)", G_OBJECT (chat)->ref_count - 1);
1580 g_object_unref (chat);
1584 empathy_chat_window_move_chat (EmpathyChatWindow *old_window,
1585 EmpathyChatWindow *new_window,
1590 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (old_window));
1591 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (new_window));
1592 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1594 widget = GTK_WIDGET (chat);
1596 DEBUG ("Chat moving with widget:%p (%d references)", widget,
1597 G_OBJECT (widget)->ref_count);
1599 /* We reference here to make sure we don't loose the widget
1600 * and the EmpathyChat object during the move.
1602 g_object_ref (chat);
1603 g_object_ref (widget);
1605 empathy_chat_window_remove_chat (old_window, chat);
1606 empathy_chat_window_add_chat (new_window, chat);
1608 g_object_unref (widget);
1609 g_object_unref (chat);
1613 empathy_chat_window_switch_to_chat (EmpathyChatWindow *window,
1616 EmpathyChatWindowPriv *priv;
1619 g_return_if_fail (window != NULL);
1620 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1622 priv = GET_PRIV (window);
1624 page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1626 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1631 empathy_chat_window_has_focus (EmpathyChatWindow *window)
1633 EmpathyChatWindowPriv *priv;
1636 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1638 priv = GET_PRIV (window);
1640 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);
1646 empathy_chat_window_find_chat (McAccount *account,
1651 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
1652 g_return_val_if_fail (!EMP_STR_EMPTY (id), NULL);
1654 for (l = chat_windows; l; l = l->next) {
1655 EmpathyChatWindowPriv *priv;
1656 EmpathyChatWindow *window;
1660 priv = GET_PRIV (window);
1662 for (ll = priv->chats; ll; ll = ll->next) {
1667 if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
1668 !tp_strdiff (id, empathy_chat_get_id (chat))) {
1678 empathy_chat_window_present_chat (EmpathyChat *chat)
1680 EmpathyChatWindow *window;
1681 EmpathyChatWindowPriv *priv;
1683 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1685 window = chat_window_find_chat (chat);
1687 /* If the chat has no window, create one */
1688 if (window == NULL) {
1689 window = empathy_chat_window_get_default ();
1691 window = empathy_chat_window_new ();
1694 empathy_chat_window_add_chat (window, chat);
1697 priv = GET_PRIV (window);
1698 empathy_chat_window_switch_to_chat (window, chat);
1699 empathy_window_present (GTK_WINDOW (priv->dialog), TRUE);
1701 gtk_widget_grab_focus (chat->input_text_view);
1706 chat_window_should_play_sound (EmpathyChatWindow *window)
1708 EmpathyChatWindowPriv *priv = GET_PRIV (window);
1709 gboolean has_focus = FALSE;
1711 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1713 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);