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"
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 GtkWidget *menu_conv_clear;
78 GtkWidget *menu_conv_insert_smiley;
79 GtkWidget *menu_conv_contact;
80 GtkWidget *menu_conv_favorite;
81 GtkWidget *menu_conv_close;
83 GtkWidget *menu_edit_cut;
84 GtkWidget *menu_edit_copy;
85 GtkWidget *menu_edit_paste;
87 GtkWidget *menu_tabs_next;
88 GtkWidget *menu_tabs_prev;
89 GtkWidget *menu_tabs_left;
90 GtkWidget *menu_tabs_right;
91 GtkWidget *menu_tabs_detach;
93 GtkWidget *menu_help_contents;
94 GtkWidget *menu_help_about;
95 } EmpathyChatWindowPriv;
97 static GList *chat_windows = NULL;
99 static const guint tab_accel_keys[] = {
100 GDK_1, GDK_2, GDK_3, GDK_4, GDK_5,
101 GDK_6, GDK_7, GDK_8, GDK_9, GDK_0
105 DND_DRAG_TYPE_CONTACT_ID,
109 static const GtkTargetEntry drag_types_dest[] = {
110 { "text/contact-id", 0, DND_DRAG_TYPE_CONTACT_ID },
111 { "GTK_NOTEBOOK_TAB", GTK_TARGET_SAME_APP, DND_DRAG_TYPE_TAB },
114 G_DEFINE_TYPE (EmpathyChatWindow, empathy_chat_window, G_TYPE_OBJECT);
117 chat_window_accel_cb (GtkAccelGroup *accelgroup,
121 EmpathyChatWindow *window)
123 EmpathyChatWindowPriv *priv;
127 priv = GET_PRIV (window);
129 for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
130 if (tab_accel_keys[i] == key) {
137 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), num);
141 static EmpathyChatWindow *
142 chat_window_find_chat (EmpathyChat *chat)
144 EmpathyChatWindowPriv *priv;
147 for (l = chat_windows; l; l = l->next) {
148 priv = GET_PRIV (l->data);
149 ll = g_list_find (priv->chats, chat);
159 chat_window_close_clicked_cb (GtkWidget *button,
162 EmpathyChatWindow *window;
164 window = chat_window_find_chat (chat);
165 empathy_chat_window_remove_chat (window, chat);
169 chat_window_close_button_style_set_cb (GtkWidget *button,
170 GtkStyle *previous_style,
175 gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
176 GTK_ICON_SIZE_MENU, &w, &h);
178 gtk_widget_set_size_request (button, w, h);
182 chat_window_create_label (EmpathyChatWindow *window,
185 EmpathyChatWindowPriv *priv;
187 GtkWidget *name_label;
188 GtkWidget *status_image;
189 GtkWidget *close_button;
190 GtkWidget *close_image;
191 GtkWidget *event_box;
192 GtkWidget *event_box_hbox;
193 PangoAttrList *attr_list;
194 PangoAttribute *attr;
196 priv = GET_PRIV (window);
198 /* The spacing between the button and the label. */
199 hbox = gtk_hbox_new (FALSE, 0);
201 event_box = gtk_event_box_new ();
202 gtk_event_box_set_visible_window (GTK_EVENT_BOX (event_box), FALSE);
204 name_label = gtk_label_new (NULL);
205 gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
207 attr_list = pango_attr_list_new ();
208 attr = pango_attr_scale_new (1/1.2);
209 attr->start_index = 0;
210 attr->end_index = -1;
211 pango_attr_list_insert (attr_list, attr);
212 gtk_label_set_attributes (GTK_LABEL (name_label), attr_list);
213 pango_attr_list_unref (attr_list);
215 gtk_misc_set_padding (GTK_MISC (name_label), 2, 0);
216 gtk_misc_set_alignment (GTK_MISC (name_label), 0.0, 0.5);
217 g_object_set_data (G_OBJECT (chat), "chat-window-tab-label", name_label);
219 status_image = gtk_image_new ();
221 /* Spacing between the icon and label. */
222 event_box_hbox = gtk_hbox_new (FALSE, 0);
224 gtk_box_pack_start (GTK_BOX (event_box_hbox), status_image, FALSE, FALSE, 0);
225 gtk_box_pack_start (GTK_BOX (event_box_hbox), name_label, TRUE, TRUE, 0);
227 g_object_set_data (G_OBJECT (chat), "chat-window-tab-image", status_image);
228 g_object_set_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget", event_box);
230 close_button = gtk_button_new ();
231 gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
232 g_object_set_data (G_OBJECT (chat), "chat-window-tab-close-button", close_button);
234 /* We don't want focus/keynav for the button to avoid clutter, and
235 * Ctrl-W works anyway.
237 GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_FOCUS);
238 GTK_WIDGET_UNSET_FLAGS (close_button, GTK_CAN_DEFAULT);
240 /* Set the name to make the special rc style match. */
241 gtk_widget_set_name (close_button, "empathy-close-button");
243 close_image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
245 gtk_container_add (GTK_CONTAINER (close_button), close_image);
247 gtk_container_add (GTK_CONTAINER (event_box), event_box_hbox);
248 gtk_box_pack_start (GTK_BOX (hbox), event_box, TRUE, TRUE, 0);
249 gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
251 /* React to theme changes and also used to setup the initial size
254 g_signal_connect (close_button,
256 G_CALLBACK (chat_window_close_button_style_set_cb),
259 g_signal_connect (close_button,
261 G_CALLBACK (chat_window_close_clicked_cb),
264 gtk_widget_show_all (hbox);
270 chat_window_update (EmpathyChatWindow *window)
272 EmpathyChatWindowPriv *priv = GET_PRIV (window);
275 gboolean is_connected;
282 EmpathyContact *remote_contact;
283 gboolean avatar_in_icon;
285 GtkWidget *chat_close_button;
287 /* Get information */
288 page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
289 num_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (priv->notebook));
290 first_page = (page_num == 0);
291 last_page = (page_num == (num_pages - 1));
292 is_connected = empathy_chat_get_tp_chat (priv->current_chat) != NULL;
293 name = empathy_chat_get_name (priv->current_chat);
294 n_chats = g_list_length (priv->chats);
296 DEBUG ("Update window");
299 gtk_widget_set_sensitive (priv->menu_tabs_next, !last_page);
300 gtk_widget_set_sensitive (priv->menu_tabs_prev, !first_page);
301 gtk_widget_set_sensitive (priv->menu_tabs_detach, num_pages > 1);
302 gtk_widget_set_sensitive (priv->menu_tabs_left, !first_page);
303 gtk_widget_set_sensitive (priv->menu_tabs_right, !last_page);
304 gtk_widget_set_sensitive (priv->menu_conv_insert_smiley, is_connected);
306 /* Update window title */
308 gtk_window_set_title (GTK_WINDOW (priv->dialog), name);
312 title = g_strdup_printf (_("Conversations (%d)"), n_chats);
313 gtk_window_set_title (GTK_WINDOW (priv->dialog), title);
317 /* Update window icon */
318 if (priv->chats_new_msg) {
319 gtk_window_set_icon_name (GTK_WINDOW (priv->dialog),
320 EMPATHY_IMAGE_MESSAGE);
322 empathy_conf_get_bool (empathy_conf_get (),
323 EMPATHY_PREFS_CHAT_AVATAR_IN_ICON,
326 if (n_chats == 1 && avatar_in_icon) {
327 remote_contact = empathy_chat_get_remote_contact (priv->current_chat);
328 icon = empathy_pixbuf_avatar_from_contact_scaled (remote_contact, 0, 0);
329 gtk_window_set_icon (GTK_WINDOW (priv->dialog), icon);
332 g_object_unref (icon);
335 gtk_window_set_icon_name (GTK_WINDOW (priv->dialog), NULL);
339 if (num_pages == 1) {
340 chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), 0);
341 chat_close_button = g_object_get_data (G_OBJECT (chat),
342 "chat-window-tab-close-button");
343 gtk_widget_hide (chat_close_button);
345 for (i=0; i<num_pages; i++) {
346 chat = gtk_notebook_get_nth_page (GTK_NOTEBOOK (priv->notebook), i);
347 chat_close_button = g_object_get_data (G_OBJECT (chat),
348 "chat-window-tab-close-button");
349 gtk_widget_show (chat_close_button);
355 chat_window_update_chat_tab (EmpathyChat *chat)
357 EmpathyChatWindow *window;
358 EmpathyChatWindowPriv *priv;
359 EmpathyContact *remote_contact;
362 const gchar *subject;
366 const gchar *icon_name;
368 window = chat_window_find_chat (chat);
372 priv = GET_PRIV (window);
374 /* Get information */
375 name = empathy_chat_get_name (chat);
376 account = empathy_chat_get_account (chat);
377 subject = empathy_chat_get_subject (chat);
378 remote_contact = empathy_chat_get_remote_contact (chat);
380 DEBUG ("Updating chat tab, name=%s, account=%s, subject=%s, remote_contact=%p",
381 name, mc_account_get_unique_name (account), subject, remote_contact);
383 /* Update tab image */
384 if (g_list_find (priv->chats_new_msg, chat)) {
385 icon_name = EMPATHY_IMAGE_MESSAGE;
387 else if (g_list_find (priv->chats_composing, chat)) {
388 icon_name = EMPATHY_IMAGE_TYPING;
390 else if (remote_contact) {
391 icon_name = empathy_icon_name_for_contact (remote_contact);
393 icon_name = EMPATHY_IMAGE_GROUP_MESSAGE;
395 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-image");
396 gtk_image_set_from_icon_name (GTK_IMAGE (widget), icon_name, GTK_ICON_SIZE_MENU);
398 /* Update tab tooltip */
399 tooltip = g_string_new (NULL);
401 if (remote_contact) {
402 markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>\n%s",
403 empathy_contact_get_id (remote_contact),
404 mc_account_get_display_name (account),
405 empathy_contact_get_status (remote_contact));
406 g_string_append (tooltip, markup);
410 markup = g_markup_printf_escaped ("<b>%s</b><small> (%s)</small>", name,
411 mc_account_get_display_name (account));
412 g_string_append (tooltip, markup);
417 markup = g_markup_printf_escaped ("\n<b>%s</b> %s", _("Topic:"), subject);
418 g_string_append (tooltip, markup);
421 if (g_list_find (priv->chats_composing, chat)) {
422 markup = g_markup_printf_escaped ("\n%s", _("Typing a message."));
423 g_string_append (tooltip, markup);
427 markup = g_string_free (tooltip, FALSE);
428 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-tooltip-widget");
429 gtk_widget_set_tooltip_markup (widget, markup);
432 /* Update tab label */
433 widget = g_object_get_data (G_OBJECT (chat), "chat-window-tab-label");
434 gtk_label_set_text (GTK_LABEL (widget), name);
436 /* Update the window if it's the current chat */
437 if (priv->current_chat == chat) {
438 chat_window_update (window);
443 chat_window_chat_notify_cb (EmpathyChat *chat)
445 EmpathyContact *old_remote_contact;
446 EmpathyContact *remote_contact = NULL;
448 old_remote_contact = g_object_get_data (G_OBJECT (chat), "chat-window-remote-contact");
449 remote_contact = empathy_chat_get_remote_contact (chat);
451 if (old_remote_contact != remote_contact) {
452 /* The remote-contact associated with the chat changed, we need
453 * to keep track of any change of that contact and update the
454 * window each time. */
455 if (remote_contact) {
456 g_signal_connect_swapped (remote_contact, "notify",
457 G_CALLBACK (chat_window_update_chat_tab),
460 if (old_remote_contact) {
461 g_signal_handlers_disconnect_by_func (old_remote_contact,
462 chat_window_update_chat_tab,
466 g_object_set_data (G_OBJECT (chat), "chat-window-remote-contact",
470 chat_window_update_chat_tab (chat);
474 chat_window_insert_smiley_activate_cb (EmpathySmileyManager *manager,
475 EmpathySmiley *smiley,
478 EmpathyChatWindowPriv *priv = GET_PRIV (window);
480 GtkTextBuffer *buffer;
483 chat = priv->current_chat;
485 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
486 gtk_text_buffer_get_end_iter (buffer, &iter);
487 gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
491 chat_window_conv_activate_cb (GtkWidget *menuitem,
492 EmpathyChatWindow *window)
494 EmpathyChatWindowPriv *priv = GET_PRIV (window);
495 GtkWidget *submenu = NULL;
497 /* Contact submenu */
498 submenu = empathy_chat_get_contact_menu (priv->current_chat);
500 gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_contact),
502 gtk_widget_show (priv->menu_conv_contact);
503 gtk_widget_show (submenu);
505 gtk_widget_hide (priv->menu_conv_contact);
508 /* Favorite room menu */
509 if (empathy_chat_is_room (priv->current_chat)) {
514 room = empathy_chat_get_id (priv->current_chat);
515 account = empathy_chat_get_account (priv->current_chat);
516 found = empathy_chatroom_manager_find (priv->chatroom_manager,
517 account, room) != NULL;
519 DEBUG ("This room %s favorite", found ? "is" : "is not");
520 gtk_check_menu_item_set_active (
521 GTK_CHECK_MENU_ITEM (priv->menu_conv_favorite), found);
522 gtk_widget_show (priv->menu_conv_favorite);
524 gtk_widget_hide (priv->menu_conv_favorite);
529 chat_window_clear_activate_cb (GtkWidget *menuitem,
530 EmpathyChatWindow *window)
532 EmpathyChatWindowPriv *priv = GET_PRIV (window);
534 empathy_chat_clear (priv->current_chat);
538 chat_window_favorite_toggled_cb (GtkCheckMenuItem *menuitem,
539 EmpathyChatWindow *window)
541 EmpathyChatWindowPriv *priv = GET_PRIV (window);
545 EmpathyChatroom *chatroom;
547 active = gtk_check_menu_item_get_active (menuitem);
548 account = empathy_chat_get_account (priv->current_chat);
549 room = empathy_chat_get_id (priv->current_chat);
551 chatroom = empathy_chatroom_manager_find (priv->chatroom_manager,
554 if (active && !chatroom) {
557 name = empathy_chat_get_name (priv->current_chat);
558 chatroom = empathy_chatroom_new_full (account, room, name, FALSE);
559 empathy_chatroom_manager_add (priv->chatroom_manager, chatroom);
560 g_object_unref (chatroom);
564 if (!active && chatroom) {
565 empathy_chatroom_manager_remove (priv->chatroom_manager, chatroom);
570 chat_get_window_id_for_geometry (EmpathyChat *chat)
572 const gchar *res = NULL;
573 gboolean separate_windows;
575 empathy_conf_get_bool (empathy_conf_get (),
576 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
579 if (separate_windows) {
580 res = empathy_chat_get_id (chat);
583 return res ? res : "chat-window";
587 chat_window_save_geometry_timeout_cb (EmpathyChatWindow *window)
589 EmpathyChatWindowPriv *priv;
592 priv = GET_PRIV (window);
594 gtk_window_get_size (GTK_WINDOW (priv->dialog), &w, &h);
595 gtk_window_get_position (GTK_WINDOW (priv->dialog), &x, &y);
597 empathy_geometry_save (chat_get_window_id_for_geometry (priv->current_chat),
600 priv->save_geometry_id = 0;
606 chat_window_configure_event_cb (GtkWidget *widget,
607 GdkEventConfigure *event,
608 EmpathyChatWindow *window)
610 EmpathyChatWindowPriv *priv;
612 priv = GET_PRIV (window);
614 if (priv->save_geometry_id != 0) {
615 g_source_remove (priv->save_geometry_id);
618 priv->save_geometry_id =
619 g_timeout_add_seconds (1,
620 (GSourceFunc) chat_window_save_geometry_timeout_cb,
627 chat_window_close_activate_cb (GtkWidget *menuitem,
628 EmpathyChatWindow *window)
630 EmpathyChatWindowPriv *priv;
632 priv = GET_PRIV (window);
634 g_return_if_fail (priv->current_chat != NULL);
636 empathy_chat_window_remove_chat (window, priv->current_chat);
640 chat_window_edit_activate_cb (GtkWidget *menuitem,
641 EmpathyChatWindow *window)
643 EmpathyChatWindowPriv *priv;
644 GtkClipboard *clipboard;
645 GtkTextBuffer *buffer;
646 gboolean text_available;
648 priv = GET_PRIV (window);
650 g_return_if_fail (priv->current_chat != NULL);
652 if (!empathy_chat_get_tp_chat (priv->current_chat)) {
653 gtk_widget_set_sensitive (priv->menu_edit_copy, FALSE);
654 gtk_widget_set_sensitive (priv->menu_edit_cut, FALSE);
655 gtk_widget_set_sensitive (priv->menu_edit_paste, FALSE);
659 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->current_chat->input_text_view));
660 if (gtk_text_buffer_get_has_selection (buffer)) {
661 gtk_widget_set_sensitive (priv->menu_edit_copy, TRUE);
662 gtk_widget_set_sensitive (priv->menu_edit_cut, TRUE);
666 selection = empathy_chat_view_get_has_selection (priv->current_chat->view);
668 gtk_widget_set_sensitive (priv->menu_edit_cut, FALSE);
669 gtk_widget_set_sensitive (priv->menu_edit_copy, selection);
672 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
673 text_available = gtk_clipboard_wait_is_text_available (clipboard);
674 gtk_widget_set_sensitive (priv->menu_edit_paste, text_available);
678 chat_window_cut_activate_cb (GtkWidget *menuitem,
679 EmpathyChatWindow *window)
681 EmpathyChatWindowPriv *priv;
683 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
685 priv = GET_PRIV (window);
687 empathy_chat_cut (priv->current_chat);
691 chat_window_copy_activate_cb (GtkWidget *menuitem,
692 EmpathyChatWindow *window)
694 EmpathyChatWindowPriv *priv;
696 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
698 priv = GET_PRIV (window);
700 empathy_chat_copy (priv->current_chat);
704 chat_window_paste_activate_cb (GtkWidget *menuitem,
705 EmpathyChatWindow *window)
707 EmpathyChatWindowPriv *priv;
709 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (window));
711 priv = GET_PRIV (window);
713 empathy_chat_paste (priv->current_chat);
717 chat_window_tabs_left_activate_cb (GtkWidget *menuitem,
718 EmpathyChatWindow *window)
720 EmpathyChatWindowPriv *priv;
724 priv = GET_PRIV (window);
726 chat = priv->current_chat;
727 index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
732 gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
738 chat_window_tabs_right_activate_cb (GtkWidget *menuitem,
739 EmpathyChatWindow *window)
741 EmpathyChatWindowPriv *priv;
745 priv = GET_PRIV (window);
747 chat = priv->current_chat;
748 index = gtk_notebook_get_current_page (GTK_NOTEBOOK (priv->notebook));
750 gtk_notebook_reorder_child (GTK_NOTEBOOK (priv->notebook),
756 chat_window_detach_activate_cb (GtkWidget *menuitem,
757 EmpathyChatWindow *window)
759 EmpathyChatWindowPriv *priv;
760 EmpathyChatWindow *new_window;
763 priv = GET_PRIV (window);
765 chat = priv->current_chat;
766 new_window = empathy_chat_window_new ();
768 empathy_chat_window_move_chat (window, new_window, chat);
770 priv = GET_PRIV (new_window);
771 gtk_widget_show (priv->dialog);
775 chat_window_help_contents_cb (GtkWidget *menuitem,
776 EmpathyChatWindow *window)
778 empathy_url_show (menuitem, "ghelp:empathy?chat");
782 chat_window_help_about_cb (GtkWidget *menuitem,
783 EmpathyChatWindow *window)
785 EmpathyChatWindowPriv *priv = GET_PRIV (window);
787 empathy_about_dialog_new (GTK_WINDOW (priv->dialog));
791 chat_window_delete_event_cb (GtkWidget *dialog,
793 EmpathyChatWindow *window)
795 EmpathyChatWindowPriv *priv = GET_PRIV (window);
797 DEBUG ("Delete event received");
799 g_object_ref (window);
800 while (priv->chats) {
801 empathy_chat_window_remove_chat (window, priv->chats->data);
803 g_object_unref (window);
809 chat_window_composing_cb (EmpathyChat *chat,
810 gboolean is_composing,
811 EmpathyChatWindow *window)
813 EmpathyChatWindowPriv *priv;
815 priv = GET_PRIV (window);
817 if (is_composing && !g_list_find (priv->chats_composing, chat)) {
818 priv->chats_composing = g_list_prepend (priv->chats_composing, chat);
820 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
823 chat_window_update_chat_tab (chat);
827 chat_window_set_urgency_hint (EmpathyChatWindow *window,
830 EmpathyChatWindowPriv *priv;
832 priv = GET_PRIV (window);
834 DEBUG ("Turning %s urgency hint", urgent ? "on" : "off");
835 gtk_window_set_urgency_hint (GTK_WINDOW (priv->dialog), urgent);
839 notification_closed_idle_cb (EmpathyChat *chat)
841 empathy_chat_window_present_chat (chat);
847 chat_window_notification_closed_cb (NotifyNotification *notify,
852 reason = notify_notification_get_closed_reason (notify);
855 empathy_chat_window_present_chat (chat);
860 chat_window_show_or_update_notification (EmpathyMessage *message,
861 EmpathyChatWindow *window,
864 EmpathyContact *sender;
868 EmpathyChatWindowPriv *priv = GET_PRIV (window);
870 if (!empathy_notification_should_show (TRUE)) {
874 sender = empathy_message_get_sender (message);
875 header = g_strdup_printf (_("New message from %s"),
876 empathy_contact_get_name (sender));
877 body = empathy_message_get_body (message);
878 pixbuf = empathy_pixbuf_avatar_from_contact_scaled (sender, 48, 48);
879 if (pixbuf == NULL) {
880 /* we use INVALID here so we fall pack to 48px */
881 pixbuf = empathy_pixbuf_from_icon_name (EMPATHY_IMAGE_NEW_MESSAGE,
882 GTK_ICON_SIZE_INVALID);
885 if (priv->notification != NULL) {
886 notify_notification_update (priv->notification,
888 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
890 priv->notification = notify_notification_new (header, body, NULL, NULL);
891 notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
892 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
894 g_signal_connect (priv->notification, "closed",
895 G_CALLBACK (chat_window_notification_closed_cb), chat);
898 notify_notification_show (priv->notification, NULL);
900 g_object_unref (pixbuf);
905 chat_window_new_message_cb (EmpathyChat *chat,
906 EmpathyMessage *message,
907 EmpathyChatWindow *window)
909 EmpathyChatWindowPriv *priv;
911 gboolean needs_urgency;
912 EmpathyContact *sender;
914 priv = GET_PRIV (window);
916 has_focus = empathy_chat_window_has_focus (window);
918 /* - if we're the sender, we play the sound if it's specified in the
919 * preferences and we're not away.
920 * - if we receive a message, we play the sound if it's specified in the
921 * prefereces and the window does not have focus on the chat receiving
925 sender = empathy_message_get_sender (message);
927 if (empathy_contact_is_user (sender) != FALSE) {
928 empathy_sound_play (GTK_WIDGET (priv->dialog),
929 EMPATHY_SOUND_MESSAGE_OUTGOING);
931 if ((!has_focus || priv->current_chat != chat)) {
932 empathy_sound_play (GTK_WIDGET (priv->dialog),
933 EMPATHY_SOUND_MESSAGE_INCOMING);
938 chat_window_show_or_update_notification (message, window, chat);
941 if (has_focus && priv->current_chat == chat) {
945 if (empathy_chat_get_members_count (chat) > 2) {
946 needs_urgency = empathy_message_should_highlight (message);
948 needs_urgency = TRUE;
951 if (needs_urgency && !has_focus) {
952 chat_window_set_urgency_hint (window, TRUE);
955 if (!g_list_find (priv->chats_new_msg, chat)) {
956 priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
957 chat_window_update_chat_tab (chat);
962 chat_window_detach_hook (GtkNotebook *source,
968 EmpathyChatWindowPriv *priv;
969 EmpathyChatWindow *window, *new_window;
972 chat = EMPATHY_CHAT (page);
973 window = chat_window_find_chat (chat);
975 new_window = empathy_chat_window_new ();
976 priv = GET_PRIV (new_window);
978 DEBUG ("Detach hook called");
980 empathy_chat_window_move_chat (window, new_window, chat);
982 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
983 gtk_widget_show (priv->dialog);
989 chat_window_page_switched_cb (GtkNotebook *notebook,
990 GtkNotebookPage *page,
992 EmpathyChatWindow *window)
994 EmpathyChatWindowPriv *priv;
998 DEBUG ("Page switched");
1000 priv = GET_PRIV (window);
1002 child = gtk_notebook_get_nth_page (notebook, page_num);
1003 chat = EMPATHY_CHAT (child);
1005 if (priv->page_added) {
1006 priv->page_added = FALSE;
1007 empathy_chat_scroll_down (chat);
1009 else if (priv->current_chat == chat) {
1013 priv->current_chat = chat;
1014 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1016 chat_window_update_chat_tab (chat);
1020 chat_window_page_added_cb (GtkNotebook *notebook,
1023 EmpathyChatWindow *window)
1025 EmpathyChatWindowPriv *priv;
1028 priv = GET_PRIV (window);
1030 /* If we just received DND to the same window, we don't want
1031 * to do anything here like removing the tab and then readding
1032 * it, so we return here and in "page-added".
1034 if (priv->dnd_same_window) {
1035 DEBUG ("Page added (back to the same window)");
1036 priv->dnd_same_window = FALSE;
1040 DEBUG ("Page added");
1042 /* Get chat object */
1043 chat = EMPATHY_CHAT (child);
1045 /* Connect chat signals for this window */
1046 g_signal_connect (chat, "composing",
1047 G_CALLBACK (chat_window_composing_cb),
1049 g_signal_connect (chat, "new-message",
1050 G_CALLBACK (chat_window_new_message_cb),
1053 /* Set flag so we know to perform some special operations on
1054 * switch page due to the new page being added.
1056 priv->page_added = TRUE;
1058 /* Get list of chats up to date */
1059 priv->chats = g_list_append (priv->chats, chat);
1061 chat_window_update_chat_tab (chat);
1065 chat_window_page_removed_cb (GtkNotebook *notebook,
1068 EmpathyChatWindow *window)
1070 EmpathyChatWindowPriv *priv;
1073 priv = GET_PRIV (window);
1075 /* If we just received DND to the same window, we don't want
1076 * to do anything here like removing the tab and then readding
1077 * it, so we return here and in "page-added".
1079 if (priv->dnd_same_window) {
1080 DEBUG ("Page removed (and will be readded to same window)");
1084 DEBUG ("Page removed");
1086 /* Get chat object */
1087 chat = EMPATHY_CHAT (child);
1089 /* Disconnect all signal handlers for this chat and this window */
1090 g_signal_handlers_disconnect_by_func (chat,
1091 G_CALLBACK (chat_window_composing_cb),
1093 g_signal_handlers_disconnect_by_func (chat,
1094 G_CALLBACK (chat_window_new_message_cb),
1097 /* Keep list of chats up to date */
1098 priv->chats = g_list_remove (priv->chats, chat);
1099 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1100 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
1102 if (priv->chats == NULL) {
1103 g_object_unref (window);
1105 chat_window_update (window);
1110 chat_window_focus_in_event_cb (GtkWidget *widget,
1112 EmpathyChatWindow *window)
1114 EmpathyChatWindowPriv *priv;
1116 DEBUG ("Focus in event, updating title");
1118 priv = GET_PRIV (window);
1120 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
1122 chat_window_set_urgency_hint (window, FALSE);
1124 /* Update the title, since we now mark all unread messages as read. */
1125 chat_window_update_chat_tab (priv->current_chat);
1131 chat_window_drag_data_received (GtkWidget *widget,
1132 GdkDragContext *context,
1135 GtkSelectionData *selection,
1138 EmpathyChatWindow *window)
1140 if (info == DND_DRAG_TYPE_CONTACT_ID) {
1142 EmpathyChatWindow *old_window;
1147 id = (const gchar*) selection->data;
1149 DEBUG ("DND contact from roster with id:'%s'", id);
1151 strv = g_strsplit (id, "/", 2);
1152 account = mc_account_lookup (strv[0]);
1153 chat = empathy_chat_window_find_chat (account, strv[1]);
1156 empathy_dispatcher_chat_with_contact_id (account, strv[2], NULL, NULL);
1157 g_object_unref (account);
1161 g_object_unref (account);
1164 old_window = chat_window_find_chat (chat);
1166 if (old_window == window) {
1167 gtk_drag_finish (context, TRUE, FALSE, time);
1171 empathy_chat_window_move_chat (old_window, window, chat);
1173 empathy_chat_window_add_chat (window, chat);
1176 /* Added to take care of any outstanding chat events */
1177 empathy_chat_window_present_chat (chat);
1179 /* We should return TRUE to remove the data when doing
1180 * GDK_ACTION_MOVE, but we don't here otherwise it has
1181 * weird consequences, and we handle that internally
1182 * anyway with add_chat() and remove_chat().
1184 gtk_drag_finish (context, TRUE, FALSE, time);
1186 else if (info == DND_DRAG_TYPE_TAB) {
1188 EmpathyChatWindow *old_window = NULL;
1192 chat = (void*) selection->data;
1193 old_window = chat_window_find_chat (*chat);
1196 EmpathyChatWindowPriv *priv;
1198 priv = GET_PRIV (window);
1200 if (old_window == window) {
1201 DEBUG ("DND tab (within same window)");
1202 priv->dnd_same_window = TRUE;
1203 gtk_drag_finish (context, TRUE, FALSE, time);
1207 priv->dnd_same_window = FALSE;
1210 /* We should return TRUE to remove the data when doing
1211 * GDK_ACTION_MOVE, but we don't here otherwise it has
1212 * weird consequences, and we handle that internally
1213 * anyway with add_chat() and remove_chat().
1215 gtk_drag_finish (context, TRUE, FALSE, time);
1217 DEBUG ("DND from unknown source");
1218 gtk_drag_finish (context, FALSE, FALSE, time);
1223 chat_window_finalize (GObject *object)
1225 EmpathyChatWindow *window;
1226 EmpathyChatWindowPriv *priv;
1228 window = EMPATHY_CHAT_WINDOW (object);
1229 priv = GET_PRIV (window);
1231 DEBUG ("Finalized: %p", object);
1233 g_object_unref (priv->chatroom_manager);
1234 if (priv->save_geometry_id != 0) {
1235 g_source_remove (priv->save_geometry_id);
1238 if (priv->notification != NULL) {
1239 notify_notification_close (priv->notification, NULL);
1240 g_object_unref (priv->notification);
1241 priv->notification = NULL;
1244 chat_windows = g_list_remove (chat_windows, window);
1245 gtk_widget_destroy (priv->dialog);
1247 G_OBJECT_CLASS (empathy_chat_window_parent_class)->finalize (object);
1251 empathy_chat_window_class_init (EmpathyChatWindowClass *klass)
1253 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1255 object_class->finalize = chat_window_finalize;
1257 g_type_class_add_private (object_class, sizeof (EmpathyChatWindowPriv));
1259 /* Set up a style for the close button with no focus padding. */
1260 gtk_rc_parse_string (
1261 "style \"empathy-close-button-style\"\n"
1263 " GtkWidget::focus-padding = 0\n"
1267 "widget \"*.empathy-close-button\" style \"empathy-close-button-style\"");
1269 gtk_notebook_set_window_creation_hook (chat_window_detach_hook, NULL, NULL);
1273 empathy_chat_window_init (EmpathyChatWindow *window)
1276 GtkAccelGroup *accel_group;
1278 GtkWidget *menu_conv;
1281 GtkWidget *chat_vbox;
1283 EmpathySmileyManager *smiley_manager;
1284 EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1285 EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);
1287 window->priv = priv;
1288 filename = empathy_file_lookup ("empathy-chat-window.glade", "src");
1289 glade = empathy_glade_get_file (filename,
1292 "chat_window", &priv->dialog,
1293 "chat_vbox", &chat_vbox,
1294 "menu_conv", &menu_conv,
1295 "menu_conv_clear", &priv->menu_conv_clear,
1296 "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
1297 "menu_conv_contact", &priv->menu_conv_contact,
1298 "menu_conv_favorite", &priv->menu_conv_favorite,
1299 "menu_conv_close", &priv->menu_conv_close,
1300 "menu_edit_cut", &priv->menu_edit_cut,
1301 "menu_edit_copy", &priv->menu_edit_copy,
1302 "menu_edit_paste", &priv->menu_edit_paste,
1303 "menu_tabs_next", &priv->menu_tabs_next,
1304 "menu_tabs_prev", &priv->menu_tabs_prev,
1305 "menu_tabs_left", &priv->menu_tabs_left,
1306 "menu_tabs_right", &priv->menu_tabs_right,
1307 "menu_tabs_detach", &priv->menu_tabs_detach,
1308 "menu_help_contents", &priv->menu_help_contents,
1309 "menu_help_about", &priv->menu_help_about,
1313 empathy_glade_connect (glade,
1315 "chat_window", "configure-event", chat_window_configure_event_cb,
1316 "menu_conv", "activate", chat_window_conv_activate_cb,
1317 "menu_conv_clear", "activate", chat_window_clear_activate_cb,
1318 "menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb,
1319 "menu_conv_close", "activate", chat_window_close_activate_cb,
1320 "menu_edit", "activate", chat_window_edit_activate_cb,
1321 "menu_edit_cut", "activate", chat_window_cut_activate_cb,
1322 "menu_edit_copy", "activate", chat_window_copy_activate_cb,
1323 "menu_edit_paste", "activate", chat_window_paste_activate_cb,
1324 "menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
1325 "menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
1326 "menu_tabs_detach", "activate", chat_window_detach_activate_cb,
1327 "menu_help_contents", "activate", chat_window_help_contents_cb,
1328 "menu_help_about", "activate", chat_window_help_about_cb,
1331 g_object_unref (glade);
1333 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1335 priv->notebook = gtk_notebook_new ();
1336 gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow");
1337 gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0);
1338 gtk_widget_show (priv->notebook);
1341 accel_group = gtk_accel_group_new ();
1342 gtk_window_add_accel_group (GTK_WINDOW (priv->dialog), accel_group);
1344 for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
1345 closure = g_cclosure_new (G_CALLBACK (chat_window_accel_cb),
1348 gtk_accel_group_connect (accel_group,
1355 g_object_unref (accel_group);
1357 /* Set up smiley menu */
1358 smiley_manager = empathy_smiley_manager_dup_singleton ();
1359 menu = empathy_smiley_menu_new (smiley_manager,
1360 chat_window_insert_smiley_activate_cb,
1362 gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_insert_smiley),
1364 g_object_unref (smiley_manager);
1366 /* Set up signals we can't do with glade since we may need to
1367 * block/unblock them at some later stage.
1370 g_signal_connect (priv->dialog,
1372 G_CALLBACK (chat_window_delete_event_cb),
1375 g_signal_connect_swapped (priv->menu_tabs_prev,
1377 G_CALLBACK (gtk_notebook_prev_page),
1379 g_signal_connect_swapped (priv->menu_tabs_next,
1381 G_CALLBACK (gtk_notebook_next_page),
1384 g_signal_connect (priv->dialog,
1386 G_CALLBACK (chat_window_focus_in_event_cb),
1388 g_signal_connect_after (priv->notebook,
1390 G_CALLBACK (chat_window_page_switched_cb),
1392 g_signal_connect (priv->notebook,
1394 G_CALLBACK (chat_window_page_added_cb),
1396 g_signal_connect (priv->notebook,
1398 G_CALLBACK (chat_window_page_removed_cb),
1401 /* Set up drag and drop */
1402 gtk_drag_dest_set (GTK_WIDGET (priv->notebook),
1403 GTK_DEST_DEFAULT_ALL,
1405 G_N_ELEMENTS (drag_types_dest),
1408 g_signal_connect (priv->notebook,
1409 "drag-data-received",
1410 G_CALLBACK (chat_window_drag_data_received),
1413 chat_windows = g_list_prepend (chat_windows, window);
1415 /* Set up private details */
1417 priv->chats_new_msg = NULL;
1418 priv->chats_composing = NULL;
1419 priv->current_chat = NULL;
1423 empathy_chat_window_new (void)
1425 return EMPATHY_CHAT_WINDOW (g_object_new (EMPATHY_TYPE_CHAT_WINDOW, NULL));
1428 /* Returns the window to open a new tab in if there is only one window
1429 * visble, otherwise, returns NULL indicating that a new window should
1433 empathy_chat_window_get_default (void)
1436 gboolean separate_windows = TRUE;
1438 empathy_conf_get_bool (empathy_conf_get (),
1439 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
1442 if (separate_windows) {
1443 /* Always create a new window */
1447 for (l = chat_windows; l; l = l->next) {
1448 EmpathyChatWindow *chat_window;
1451 chat_window = l->data;
1453 dialog = empathy_chat_window_get_dialog (chat_window);
1454 if (empathy_window_get_is_visible (GTK_WINDOW (dialog))) {
1455 /* Found a visible window on this desktop */
1464 empathy_chat_window_get_dialog (EmpathyChatWindow *window)
1466 EmpathyChatWindowPriv *priv;
1468 g_return_val_if_fail (window != NULL, NULL);
1470 priv = GET_PRIV (window);
1472 return priv->dialog;
1476 empathy_chat_window_add_chat (EmpathyChatWindow *window,
1479 EmpathyChatWindowPriv *priv;
1484 g_return_if_fail (window != NULL);
1485 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1487 priv = GET_PRIV (window);
1489 /* Reference the chat object */
1490 g_object_ref (chat);
1492 /* If this window has just been created, position it */
1493 if (priv->chats == NULL) {
1494 empathy_geometry_load (chat_get_window_id_for_geometry (chat), &x, &y, &w, &h);
1496 if (x >= 0 && y >= 0) {
1497 /* Let the window manager position it if we don't have
1498 * good x, y coordinates.
1500 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
1503 if (w > 0 && h > 0) {
1504 /* Use the defaults from the glade file if we don't have
1505 * good w, h geometry.
1507 gtk_window_resize (GTK_WINDOW (priv->dialog), w, h);
1511 child = GTK_WIDGET (chat);
1512 label = chat_window_create_label (window, chat);
1513 gtk_widget_show (child);
1515 g_signal_connect (chat, "notify::name",
1516 G_CALLBACK (chat_window_chat_notify_cb),
1518 g_signal_connect (chat, "notify::subject",
1519 G_CALLBACK (chat_window_chat_notify_cb),
1521 g_signal_connect (chat, "notify::remote-contact",
1522 G_CALLBACK (chat_window_chat_notify_cb),
1524 chat_window_chat_notify_cb (chat);
1526 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
1527 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1528 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1529 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
1530 TRUE, TRUE, GTK_PACK_START);
1532 DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
1536 empathy_chat_window_remove_chat (EmpathyChatWindow *window,
1539 EmpathyChatWindowPriv *priv;
1541 EmpathyContact *remote_contact;
1543 g_return_if_fail (window != NULL);
1544 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1546 priv = GET_PRIV (window);
1548 g_signal_handlers_disconnect_by_func (chat,
1549 chat_window_chat_notify_cb,
1551 remote_contact = g_object_get_data (G_OBJECT (chat),
1552 "chat-window-remote-contact");
1553 if (remote_contact) {
1554 g_signal_handlers_disconnect_by_func (remote_contact,
1555 chat_window_update_chat_tab,
1559 position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1561 gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
1563 DEBUG ("Chat removed (%d references)", G_OBJECT (chat)->ref_count - 1);
1565 g_object_unref (chat);
1569 empathy_chat_window_move_chat (EmpathyChatWindow *old_window,
1570 EmpathyChatWindow *new_window,
1575 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (old_window));
1576 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (new_window));
1577 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1579 widget = GTK_WIDGET (chat);
1581 DEBUG ("Chat moving with widget:%p (%d references)", widget,
1582 G_OBJECT (widget)->ref_count);
1584 /* We reference here to make sure we don't loose the widget
1585 * and the EmpathyChat object during the move.
1587 g_object_ref (chat);
1588 g_object_ref (widget);
1590 empathy_chat_window_remove_chat (old_window, chat);
1591 empathy_chat_window_add_chat (new_window, chat);
1593 g_object_unref (widget);
1594 g_object_unref (chat);
1598 empathy_chat_window_switch_to_chat (EmpathyChatWindow *window,
1601 EmpathyChatWindowPriv *priv;
1604 g_return_if_fail (window != NULL);
1605 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1607 priv = GET_PRIV (window);
1609 page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1611 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1616 empathy_chat_window_has_focus (EmpathyChatWindow *window)
1618 EmpathyChatWindowPriv *priv;
1621 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1623 priv = GET_PRIV (window);
1625 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);
1631 empathy_chat_window_find_chat (McAccount *account,
1636 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
1637 g_return_val_if_fail (!EMP_STR_EMPTY (id), NULL);
1639 for (l = chat_windows; l; l = l->next) {
1640 EmpathyChatWindowPriv *priv;
1641 EmpathyChatWindow *window;
1645 priv = GET_PRIV (window);
1647 for (ll = priv->chats; ll; ll = ll->next) {
1652 if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
1653 !tp_strdiff (id, empathy_chat_get_id (chat))) {
1663 empathy_chat_window_present_chat (EmpathyChat *chat)
1665 EmpathyChatWindow *window;
1666 EmpathyChatWindowPriv *priv;
1668 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1670 window = chat_window_find_chat (chat);
1672 /* If the chat has no window, create one */
1673 if (window == NULL) {
1674 window = empathy_chat_window_get_default ();
1676 window = empathy_chat_window_new ();
1679 empathy_chat_window_add_chat (window, chat);
1682 priv = GET_PRIV (window);
1683 empathy_chat_window_switch_to_chat (window, chat);
1684 empathy_window_present (GTK_WINDOW (priv->dialog), TRUE);
1686 gtk_widget_grab_focus (chat->input_text_view);
1691 chat_window_should_play_sound (EmpathyChatWindow *window)
1693 EmpathyChatWindowPriv *priv = GET_PRIV (window);
1694 gboolean has_focus = FALSE;
1696 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1698 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);