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 notification_closed_idle_cb (EmpathyChat *chat)
842 empathy_chat_window_present_chat (chat);
848 chat_window_notification_closed_cb (NotifyNotification *notify,
853 #ifdef notify_notification_get_closed_reason
854 reason = notify_notification_get_closed_reason (notify);
858 g_idle_add ((GSourceFunc) notification_closed_idle_cb, chat);
863 chat_window_show_or_update_notification (EmpathyMessage *message,
864 EmpathyChatWindow *window,
867 EmpathyContact *sender;
871 EmpathyChatWindowPriv *priv = GET_PRIV (window);
874 if (!empathy_notification_is_enabled ()) {
877 empathy_conf_get_bool (empathy_conf_get (),
878 EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
884 sender = empathy_message_get_sender (message);
885 header = g_strdup_printf (_("New message from %s"),
886 empathy_contact_get_name (sender));
887 body = empathy_message_get_body (message);
888 pixbuf = empathy_pixbuf_avatar_from_contact_scaled (sender, 48, 48);
889 if (pixbuf == NULL) {
890 pixbuf = empathy_pixbuf_from_icon_name_sized
891 (EMPATHY_IMAGE_NEW_MESSAGE, 48);
894 if (priv->notification != NULL) {
895 notify_notification_update (priv->notification,
897 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
899 priv->notification = notify_notification_new (header, body, NULL, NULL);
900 notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
901 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
903 g_signal_connect (priv->notification, "closed",
904 G_CALLBACK (chat_window_notification_closed_cb), chat);
907 notify_notification_show (priv->notification, NULL);
909 g_object_unref (pixbuf);
914 chat_window_new_message_cb (EmpathyChat *chat,
915 EmpathyMessage *message,
916 EmpathyChatWindow *window)
918 EmpathyChatWindowPriv *priv;
920 gboolean needs_urgency;
921 EmpathyContact *sender;
923 priv = GET_PRIV (window);
925 has_focus = empathy_chat_window_has_focus (window);
927 /* - if we're the sender, we play the sound if it's specified in the
928 * preferences and we're not away.
929 * - if we receive a message, we play the sound if it's specified in the
930 * prefereces and the window does not have focus on the chat receiving
934 sender = empathy_message_get_sender (message);
936 if (empathy_contact_is_user (sender) != FALSE) {
937 empathy_sound_play (GTK_WIDGET (priv->dialog),
938 EMPATHY_SOUND_MESSAGE_OUTGOING);
940 if ((!has_focus || priv->current_chat != chat)) {
941 empathy_sound_play (GTK_WIDGET (priv->dialog),
942 EMPATHY_SOUND_MESSAGE_INCOMING);
947 chat_window_show_or_update_notification (message, window, chat);
950 if (has_focus && priv->current_chat == chat) {
954 if (empathy_chat_get_members_count (chat) > 2) {
955 needs_urgency = empathy_message_should_highlight (message);
957 needs_urgency = TRUE;
960 if (needs_urgency && !has_focus) {
961 chat_window_set_urgency_hint (window, TRUE);
964 if (!g_list_find (priv->chats_new_msg, chat)) {
965 priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
966 chat_window_update_chat_tab (chat);
971 chat_window_detach_hook (GtkNotebook *source,
977 EmpathyChatWindowPriv *priv;
978 EmpathyChatWindow *window, *new_window;
981 chat = EMPATHY_CHAT (page);
982 window = chat_window_find_chat (chat);
984 new_window = empathy_chat_window_new ();
985 priv = GET_PRIV (new_window);
987 DEBUG ("Detach hook called");
989 empathy_chat_window_move_chat (window, new_window, chat);
991 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
992 gtk_widget_show (priv->dialog);
998 chat_window_page_switched_cb (GtkNotebook *notebook,
999 GtkNotebookPage *page,
1001 EmpathyChatWindow *window)
1003 EmpathyChatWindowPriv *priv;
1007 DEBUG ("Page switched");
1009 priv = GET_PRIV (window);
1011 child = gtk_notebook_get_nth_page (notebook, page_num);
1012 chat = EMPATHY_CHAT (child);
1014 if (priv->page_added) {
1015 priv->page_added = FALSE;
1016 empathy_chat_scroll_down (chat);
1018 else if (priv->current_chat == chat) {
1022 priv->current_chat = chat;
1023 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1025 chat_window_update_chat_tab (chat);
1029 chat_window_page_added_cb (GtkNotebook *notebook,
1032 EmpathyChatWindow *window)
1034 EmpathyChatWindowPriv *priv;
1037 priv = GET_PRIV (window);
1039 /* If we just received DND to the same window, we don't want
1040 * to do anything here like removing the tab and then readding
1041 * it, so we return here and in "page-added".
1043 if (priv->dnd_same_window) {
1044 DEBUG ("Page added (back to the same window)");
1045 priv->dnd_same_window = FALSE;
1049 DEBUG ("Page added");
1051 /* Get chat object */
1052 chat = EMPATHY_CHAT (child);
1054 /* Connect chat signals for this window */
1055 g_signal_connect (chat, "composing",
1056 G_CALLBACK (chat_window_composing_cb),
1058 g_signal_connect (chat, "new-message",
1059 G_CALLBACK (chat_window_new_message_cb),
1062 /* Set flag so we know to perform some special operations on
1063 * switch page due to the new page being added.
1065 priv->page_added = TRUE;
1067 /* Get list of chats up to date */
1068 priv->chats = g_list_append (priv->chats, chat);
1070 chat_window_update_chat_tab (chat);
1074 chat_window_page_removed_cb (GtkNotebook *notebook,
1077 EmpathyChatWindow *window)
1079 EmpathyChatWindowPriv *priv;
1082 priv = GET_PRIV (window);
1084 /* If we just received DND to the same window, we don't want
1085 * to do anything here like removing the tab and then readding
1086 * it, so we return here and in "page-added".
1088 if (priv->dnd_same_window) {
1089 DEBUG ("Page removed (and will be readded to same window)");
1093 DEBUG ("Page removed");
1095 /* Get chat object */
1096 chat = EMPATHY_CHAT (child);
1098 /* Disconnect all signal handlers for this chat and this window */
1099 g_signal_handlers_disconnect_by_func (chat,
1100 G_CALLBACK (chat_window_composing_cb),
1102 g_signal_handlers_disconnect_by_func (chat,
1103 G_CALLBACK (chat_window_new_message_cb),
1106 /* Keep list of chats up to date */
1107 priv->chats = g_list_remove (priv->chats, chat);
1108 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1109 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
1111 if (priv->chats == NULL) {
1112 g_object_unref (window);
1114 chat_window_update (window);
1119 chat_window_focus_in_event_cb (GtkWidget *widget,
1121 EmpathyChatWindow *window)
1123 EmpathyChatWindowPriv *priv;
1125 DEBUG ("Focus in event, updating title");
1127 priv = GET_PRIV (window);
1129 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
1131 chat_window_set_urgency_hint (window, FALSE);
1133 /* Update the title, since we now mark all unread messages as read. */
1134 chat_window_update_chat_tab (priv->current_chat);
1140 chat_window_drag_data_received (GtkWidget *widget,
1141 GdkDragContext *context,
1144 GtkSelectionData *selection,
1147 EmpathyChatWindow *window)
1149 if (info == DND_DRAG_TYPE_CONTACT_ID) {
1151 EmpathyChatWindow *old_window;
1156 id = (const gchar*) selection->data;
1158 DEBUG ("DND contact from roster with id:'%s'", id);
1160 strv = g_strsplit (id, "/", 2);
1161 account = mc_account_lookup (strv[0]);
1162 chat = empathy_chat_window_find_chat (account, strv[1]);
1165 empathy_dispatcher_chat_with_contact_id (account, strv[2], NULL, NULL);
1166 g_object_unref (account);
1170 g_object_unref (account);
1173 old_window = chat_window_find_chat (chat);
1175 if (old_window == window) {
1176 gtk_drag_finish (context, TRUE, FALSE, time);
1180 empathy_chat_window_move_chat (old_window, window, chat);
1182 empathy_chat_window_add_chat (window, chat);
1185 /* Added to take care of any outstanding chat events */
1186 empathy_chat_window_present_chat (chat);
1188 /* We should return TRUE to remove the data when doing
1189 * GDK_ACTION_MOVE, but we don't here otherwise it has
1190 * weird consequences, and we handle that internally
1191 * anyway with add_chat() and remove_chat().
1193 gtk_drag_finish (context, TRUE, FALSE, time);
1195 else if (info == DND_DRAG_TYPE_TAB) {
1197 EmpathyChatWindow *old_window = NULL;
1201 chat = (void*) selection->data;
1202 old_window = chat_window_find_chat (*chat);
1205 EmpathyChatWindowPriv *priv;
1207 priv = GET_PRIV (window);
1209 if (old_window == window) {
1210 DEBUG ("DND tab (within same window)");
1211 priv->dnd_same_window = TRUE;
1212 gtk_drag_finish (context, TRUE, FALSE, time);
1216 priv->dnd_same_window = FALSE;
1219 /* We should return TRUE to remove the data when doing
1220 * GDK_ACTION_MOVE, but we don't here otherwise it has
1221 * weird consequences, and we handle that internally
1222 * anyway with add_chat() and remove_chat().
1224 gtk_drag_finish (context, TRUE, FALSE, time);
1226 DEBUG ("DND from unknown source");
1227 gtk_drag_finish (context, FALSE, FALSE, time);
1232 chat_window_finalize (GObject *object)
1234 EmpathyChatWindow *window;
1235 EmpathyChatWindowPriv *priv;
1237 window = EMPATHY_CHAT_WINDOW (object);
1238 priv = GET_PRIV (window);
1240 DEBUG ("Finalized: %p", object);
1242 g_object_unref (priv->chatroom_manager);
1243 if (priv->save_geometry_id != 0) {
1244 g_source_remove (priv->save_geometry_id);
1247 if (priv->notification != NULL) {
1248 notify_notification_close (priv->notification, NULL);
1249 g_object_unref (priv->notification);
1250 priv->notification = NULL;
1253 chat_windows = g_list_remove (chat_windows, window);
1254 gtk_widget_destroy (priv->dialog);
1256 G_OBJECT_CLASS (empathy_chat_window_parent_class)->finalize (object);
1260 empathy_chat_window_class_init (EmpathyChatWindowClass *klass)
1262 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1264 object_class->finalize = chat_window_finalize;
1266 g_type_class_add_private (object_class, sizeof (EmpathyChatWindowPriv));
1268 /* Set up a style for the close button with no focus padding. */
1269 gtk_rc_parse_string (
1270 "style \"empathy-close-button-style\"\n"
1272 " GtkWidget::focus-padding = 0\n"
1276 "widget \"*.empathy-close-button\" style \"empathy-close-button-style\"");
1278 gtk_notebook_set_window_creation_hook (chat_window_detach_hook, NULL, NULL);
1282 empathy_chat_window_init (EmpathyChatWindow *window)
1285 GtkAccelGroup *accel_group;
1287 GtkWidget *menu_conv;
1290 GtkWidget *chat_vbox;
1292 EmpathySmileyManager *smiley_manager;
1293 EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1294 EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);
1296 window->priv = priv;
1297 filename = empathy_file_lookup ("empathy-chat-window.glade", "src");
1298 glade = empathy_glade_get_file (filename,
1301 "chat_window", &priv->dialog,
1302 "chat_vbox", &chat_vbox,
1303 "menu_conv", &menu_conv,
1304 "menu_conv_clear", &priv->menu_conv_clear,
1305 "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
1306 "menu_conv_contact", &priv->menu_conv_contact,
1307 "menu_conv_favorite", &priv->menu_conv_favorite,
1308 "menu_conv_close", &priv->menu_conv_close,
1309 "menu_edit_cut", &priv->menu_edit_cut,
1310 "menu_edit_copy", &priv->menu_edit_copy,
1311 "menu_edit_paste", &priv->menu_edit_paste,
1312 "menu_tabs_next", &priv->menu_tabs_next,
1313 "menu_tabs_prev", &priv->menu_tabs_prev,
1314 "menu_tabs_left", &priv->menu_tabs_left,
1315 "menu_tabs_right", &priv->menu_tabs_right,
1316 "menu_tabs_detach", &priv->menu_tabs_detach,
1317 "menu_help_contents", &priv->menu_help_contents,
1318 "menu_help_about", &priv->menu_help_about,
1322 empathy_glade_connect (glade,
1324 "chat_window", "configure-event", chat_window_configure_event_cb,
1325 "menu_conv", "activate", chat_window_conv_activate_cb,
1326 "menu_conv_clear", "activate", chat_window_clear_activate_cb,
1327 "menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb,
1328 "menu_conv_close", "activate", chat_window_close_activate_cb,
1329 "menu_edit", "activate", chat_window_edit_activate_cb,
1330 "menu_edit_cut", "activate", chat_window_cut_activate_cb,
1331 "menu_edit_copy", "activate", chat_window_copy_activate_cb,
1332 "menu_edit_paste", "activate", chat_window_paste_activate_cb,
1333 "menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
1334 "menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
1335 "menu_tabs_detach", "activate", chat_window_detach_activate_cb,
1336 "menu_help_contents", "activate", chat_window_help_contents_cb,
1337 "menu_help_about", "activate", chat_window_help_about_cb,
1340 g_object_unref (glade);
1342 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1344 priv->notebook = gtk_notebook_new ();
1345 gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow");
1346 gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0);
1347 gtk_widget_show (priv->notebook);
1350 accel_group = gtk_accel_group_new ();
1351 gtk_window_add_accel_group (GTK_WINDOW (priv->dialog), accel_group);
1353 for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
1354 closure = g_cclosure_new (G_CALLBACK (chat_window_accel_cb),
1357 gtk_accel_group_connect (accel_group,
1364 g_object_unref (accel_group);
1366 /* Set up smiley menu */
1367 smiley_manager = empathy_smiley_manager_dup_singleton ();
1368 menu = empathy_smiley_menu_new (smiley_manager,
1369 chat_window_insert_smiley_activate_cb,
1371 gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_insert_smiley),
1373 g_object_unref (smiley_manager);
1375 /* Set up signals we can't do with glade since we may need to
1376 * block/unblock them at some later stage.
1379 g_signal_connect (priv->dialog,
1381 G_CALLBACK (chat_window_delete_event_cb),
1384 g_signal_connect_swapped (priv->menu_tabs_prev,
1386 G_CALLBACK (gtk_notebook_prev_page),
1388 g_signal_connect_swapped (priv->menu_tabs_next,
1390 G_CALLBACK (gtk_notebook_next_page),
1393 g_signal_connect (priv->dialog,
1395 G_CALLBACK (chat_window_focus_in_event_cb),
1397 g_signal_connect_after (priv->notebook,
1399 G_CALLBACK (chat_window_page_switched_cb),
1401 g_signal_connect (priv->notebook,
1403 G_CALLBACK (chat_window_page_added_cb),
1405 g_signal_connect (priv->notebook,
1407 G_CALLBACK (chat_window_page_removed_cb),
1410 /* Set up drag and drop */
1411 gtk_drag_dest_set (GTK_WIDGET (priv->notebook),
1412 GTK_DEST_DEFAULT_ALL,
1414 G_N_ELEMENTS (drag_types_dest),
1417 g_signal_connect (priv->notebook,
1418 "drag-data-received",
1419 G_CALLBACK (chat_window_drag_data_received),
1422 chat_windows = g_list_prepend (chat_windows, window);
1424 /* Set up private details */
1426 priv->chats_new_msg = NULL;
1427 priv->chats_composing = NULL;
1428 priv->current_chat = NULL;
1432 empathy_chat_window_new (void)
1434 return EMPATHY_CHAT_WINDOW (g_object_new (EMPATHY_TYPE_CHAT_WINDOW, NULL));
1437 /* Returns the window to open a new tab in if there is only one window
1438 * visble, otherwise, returns NULL indicating that a new window should
1442 empathy_chat_window_get_default (void)
1445 gboolean separate_windows = TRUE;
1447 empathy_conf_get_bool (empathy_conf_get (),
1448 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
1451 if (separate_windows) {
1452 /* Always create a new window */
1456 for (l = chat_windows; l; l = l->next) {
1457 EmpathyChatWindow *chat_window;
1460 chat_window = l->data;
1462 dialog = empathy_chat_window_get_dialog (chat_window);
1463 if (empathy_window_get_is_visible (GTK_WINDOW (dialog))) {
1464 /* Found a visible window on this desktop */
1473 empathy_chat_window_get_dialog (EmpathyChatWindow *window)
1475 EmpathyChatWindowPriv *priv;
1477 g_return_val_if_fail (window != NULL, NULL);
1479 priv = GET_PRIV (window);
1481 return priv->dialog;
1485 empathy_chat_window_add_chat (EmpathyChatWindow *window,
1488 EmpathyChatWindowPriv *priv;
1493 g_return_if_fail (window != NULL);
1494 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1496 priv = GET_PRIV (window);
1498 /* Reference the chat object */
1499 g_object_ref (chat);
1501 /* If this window has just been created, position it */
1502 if (priv->chats == NULL) {
1503 empathy_geometry_load (chat_get_window_id_for_geometry (chat), &x, &y, &w, &h);
1505 if (x >= 0 && y >= 0) {
1506 /* Let the window manager position it if we don't have
1507 * good x, y coordinates.
1509 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
1512 if (w > 0 && h > 0) {
1513 /* Use the defaults from the glade file if we don't have
1514 * good w, h geometry.
1516 gtk_window_resize (GTK_WINDOW (priv->dialog), w, h);
1520 child = GTK_WIDGET (chat);
1521 label = chat_window_create_label (window, chat);
1522 gtk_widget_show (child);
1524 g_signal_connect (chat, "notify::name",
1525 G_CALLBACK (chat_window_chat_notify_cb),
1527 g_signal_connect (chat, "notify::subject",
1528 G_CALLBACK (chat_window_chat_notify_cb),
1530 g_signal_connect (chat, "notify::remote-contact",
1531 G_CALLBACK (chat_window_chat_notify_cb),
1533 chat_window_chat_notify_cb (chat);
1535 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
1536 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1537 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1538 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
1539 TRUE, TRUE, GTK_PACK_START);
1541 DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
1545 empathy_chat_window_remove_chat (EmpathyChatWindow *window,
1548 EmpathyChatWindowPriv *priv;
1550 EmpathyContact *remote_contact;
1552 g_return_if_fail (window != NULL);
1553 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1555 priv = GET_PRIV (window);
1557 g_signal_handlers_disconnect_by_func (chat,
1558 chat_window_chat_notify_cb,
1560 remote_contact = g_object_get_data (G_OBJECT (chat),
1561 "chat-window-remote-contact");
1562 if (remote_contact) {
1563 g_signal_handlers_disconnect_by_func (remote_contact,
1564 chat_window_update_chat_tab,
1568 position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1570 gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
1572 DEBUG ("Chat removed (%d references)", G_OBJECT (chat)->ref_count - 1);
1574 g_object_unref (chat);
1578 empathy_chat_window_move_chat (EmpathyChatWindow *old_window,
1579 EmpathyChatWindow *new_window,
1584 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (old_window));
1585 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (new_window));
1586 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1588 widget = GTK_WIDGET (chat);
1590 DEBUG ("Chat moving with widget:%p (%d references)", widget,
1591 G_OBJECT (widget)->ref_count);
1593 /* We reference here to make sure we don't loose the widget
1594 * and the EmpathyChat object during the move.
1596 g_object_ref (chat);
1597 g_object_ref (widget);
1599 empathy_chat_window_remove_chat (old_window, chat);
1600 empathy_chat_window_add_chat (new_window, chat);
1602 g_object_unref (widget);
1603 g_object_unref (chat);
1607 empathy_chat_window_switch_to_chat (EmpathyChatWindow *window,
1610 EmpathyChatWindowPriv *priv;
1613 g_return_if_fail (window != NULL);
1614 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1616 priv = GET_PRIV (window);
1618 page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1620 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1625 empathy_chat_window_has_focus (EmpathyChatWindow *window)
1627 EmpathyChatWindowPriv *priv;
1630 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1632 priv = GET_PRIV (window);
1634 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);
1640 empathy_chat_window_find_chat (McAccount *account,
1645 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
1646 g_return_val_if_fail (!EMP_STR_EMPTY (id), NULL);
1648 for (l = chat_windows; l; l = l->next) {
1649 EmpathyChatWindowPriv *priv;
1650 EmpathyChatWindow *window;
1654 priv = GET_PRIV (window);
1656 for (ll = priv->chats; ll; ll = ll->next) {
1661 if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
1662 !tp_strdiff (id, empathy_chat_get_id (chat))) {
1672 empathy_chat_window_present_chat (EmpathyChat *chat)
1674 EmpathyChatWindow *window;
1675 EmpathyChatWindowPriv *priv;
1677 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1679 window = chat_window_find_chat (chat);
1681 /* If the chat has no window, create one */
1682 if (window == NULL) {
1683 window = empathy_chat_window_get_default ();
1685 window = empathy_chat_window_new ();
1688 empathy_chat_window_add_chat (window, chat);
1691 priv = GET_PRIV (window);
1692 empathy_chat_window_switch_to_chat (window, chat);
1693 empathy_window_present (GTK_WINDOW (priv->dialog), TRUE);
1695 gtk_widget_grab_focus (chat->input_text_view);
1700 chat_window_should_play_sound (EmpathyChatWindow *window)
1702 EmpathyChatWindowPriv *priv = GET_PRIV (window);
1703 gboolean has_focus = FALSE;
1705 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1707 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);