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 <glib/gi18n.h>
35 #include <libnotify/notification.h>
37 #include <telepathy-glib/util.h>
38 #include <libmissioncontrol/mission-control.h>
40 #include <libempathy/empathy-contact-factory.h>
41 #include <libempathy/empathy-contact.h>
42 #include <libempathy/empathy-message.h>
43 #include <libempathy/empathy-dispatcher.h>
44 #include <libempathy/empathy-chatroom-manager.h>
45 #include <libempathy/empathy-utils.h>
47 #include <libempathy-gtk/empathy-images.h>
48 #include <libempathy-gtk/empathy-conf.h>
49 #include <libempathy-gtk/empathy-contact-dialogs.h>
50 #include <libempathy-gtk/empathy-log-window.h>
51 #include <libempathy-gtk/empathy-geometry.h>
52 #include <libempathy-gtk/empathy-smiley-manager.h>
53 #include <libempathy-gtk/empathy-ui-utils.h>
55 #include "empathy-chat-window.h"
56 #include "empathy-about-dialog.h"
57 #include "empathy-misc.h"
59 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
60 #include <libempathy/empathy-debug.h>
62 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChatWindow)
64 EmpathyChat *current_chat;
67 GList *chats_composing;
69 gboolean dnd_same_window;
70 guint save_geometry_id;
71 EmpathyChatroomManager *chatroom_manager;
74 NotifyNotification *notification;
77 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 EmpathyChatWindow *window;
844 chat_window_notification_closed_cb (NotifyNotification *notify,
845 NotificationData *cb_data)
847 EmpathyNotificationClosedReason reason = 0;
848 EmpathyChatWindowPriv *priv = GET_PRIV (cb_data->window);
850 #ifdef notify_notification_get_closed_reason
851 reason = notify_notification_get_closed_reason (notify);
853 if (reason == EMPATHY_NOTIFICATION_CLOSED_DISMISSED) {
854 empathy_chat_window_present_chat (cb_data->chat);
857 g_object_unref (notify);
858 priv->notification = NULL;
859 g_object_unref (cb_data->chat);
860 g_slice_free (NotificationData, cb_data);
864 chat_window_show_or_update_notification (EmpathyChatWindow *window,
865 EmpathyMessage *message,
868 EmpathyContact *sender;
869 char *header, *escaped;
872 NotificationData *cb_data;
873 EmpathyChatWindowPriv *priv = GET_PRIV (window);
876 if (!empathy_notification_is_enabled ()) {
879 empathy_conf_get_bool (empathy_conf_get (),
880 EMPATHY_PREFS_NOTIFICATIONS_FOCUS, &res);
886 cb_data = g_slice_new0 (NotificationData);
887 cb_data->chat = g_object_ref (chat);
888 cb_data->window = window;
890 sender = empathy_message_get_sender (message);
891 header = g_strdup_printf (_("New message from %s"),
892 empathy_contact_get_name (sender));
893 body = empathy_message_get_body (message);
894 escaped = g_markup_escape_text (body, -1);
896 pixbuf = empathy_misc_get_pixbuf_for_notification (sender, EMPATHY_IMAGE_NEW_MESSAGE);
898 if (priv->notification != NULL) {
899 notify_notification_update (priv->notification,
900 header, escaped, NULL);
901 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
903 priv->notification = notify_notification_new (header, escaped, NULL, NULL);
904 notify_notification_set_timeout (priv->notification, NOTIFY_EXPIRES_DEFAULT);
905 notify_notification_set_icon_from_pixbuf (priv->notification, pixbuf);
907 g_signal_connect (priv->notification, "closed",
908 G_CALLBACK (chat_window_notification_closed_cb), cb_data);
911 notify_notification_show (priv->notification, NULL);
913 g_object_unref (pixbuf);
919 chat_window_new_message_cb (EmpathyChat *chat,
920 EmpathyMessage *message,
921 EmpathyChatWindow *window)
923 EmpathyChatWindowPriv *priv;
925 gboolean needs_urgency;
926 EmpathyContact *sender;
928 priv = GET_PRIV (window);
930 has_focus = empathy_chat_window_has_focus (window);
932 /* - if we're the sender, we play the sound if it's specified in the
933 * preferences and we're not away.
934 * - if we receive a message, we play the sound if it's specified in the
935 * prefereces and the window does not have focus on the chat receiving
939 sender = empathy_message_get_sender (message);
941 if (empathy_contact_is_user (sender) != FALSE) {
942 empathy_sound_play (GTK_WIDGET (priv->dialog),
943 EMPATHY_SOUND_MESSAGE_OUTGOING);
945 if ((!has_focus || priv->current_chat != chat)) {
946 empathy_sound_play (GTK_WIDGET (priv->dialog),
947 EMPATHY_SOUND_MESSAGE_INCOMING);
952 chat_window_show_or_update_notification (window, message, chat);
955 if (has_focus && priv->current_chat == chat) {
959 if (empathy_chat_get_members_count (chat) > 2) {
960 needs_urgency = empathy_message_should_highlight (message);
962 needs_urgency = TRUE;
965 if (needs_urgency && !has_focus) {
966 chat_window_set_urgency_hint (window, TRUE);
969 if (!g_list_find (priv->chats_new_msg, chat)) {
970 priv->chats_new_msg = g_list_prepend (priv->chats_new_msg, chat);
971 chat_window_update_chat_tab (chat);
976 chat_window_detach_hook (GtkNotebook *source,
982 EmpathyChatWindowPriv *priv;
983 EmpathyChatWindow *window, *new_window;
986 chat = EMPATHY_CHAT (page);
987 window = chat_window_find_chat (chat);
989 new_window = empathy_chat_window_new ();
990 priv = GET_PRIV (new_window);
992 DEBUG ("Detach hook called");
994 empathy_chat_window_move_chat (window, new_window, chat);
996 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
997 gtk_widget_show (priv->dialog);
1003 chat_window_page_switched_cb (GtkNotebook *notebook,
1004 GtkNotebookPage *page,
1006 EmpathyChatWindow *window)
1008 EmpathyChatWindowPriv *priv;
1012 DEBUG ("Page switched");
1014 priv = GET_PRIV (window);
1016 child = gtk_notebook_get_nth_page (notebook, page_num);
1017 chat = EMPATHY_CHAT (child);
1019 if (priv->page_added) {
1020 priv->page_added = FALSE;
1021 empathy_chat_scroll_down (chat);
1023 else if (priv->current_chat == chat) {
1027 priv->current_chat = chat;
1028 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1030 chat_window_update_chat_tab (chat);
1034 chat_window_page_added_cb (GtkNotebook *notebook,
1037 EmpathyChatWindow *window)
1039 EmpathyChatWindowPriv *priv;
1042 priv = GET_PRIV (window);
1044 /* If we just received DND to the same window, we don't want
1045 * to do anything here like removing the tab and then readding
1046 * it, so we return here and in "page-added".
1048 if (priv->dnd_same_window) {
1049 DEBUG ("Page added (back to the same window)");
1050 priv->dnd_same_window = FALSE;
1054 DEBUG ("Page added");
1056 /* Get chat object */
1057 chat = EMPATHY_CHAT (child);
1059 /* Connect chat signals for this window */
1060 g_signal_connect (chat, "composing",
1061 G_CALLBACK (chat_window_composing_cb),
1063 g_signal_connect (chat, "new-message",
1064 G_CALLBACK (chat_window_new_message_cb),
1067 /* Set flag so we know to perform some special operations on
1068 * switch page due to the new page being added.
1070 priv->page_added = TRUE;
1072 /* Get list of chats up to date */
1073 priv->chats = g_list_append (priv->chats, chat);
1075 chat_window_update_chat_tab (chat);
1079 chat_window_page_removed_cb (GtkNotebook *notebook,
1082 EmpathyChatWindow *window)
1084 EmpathyChatWindowPriv *priv;
1087 priv = GET_PRIV (window);
1089 /* If we just received DND to the same window, we don't want
1090 * to do anything here like removing the tab and then readding
1091 * it, so we return here and in "page-added".
1093 if (priv->dnd_same_window) {
1094 DEBUG ("Page removed (and will be readded to same window)");
1098 DEBUG ("Page removed");
1100 /* Get chat object */
1101 chat = EMPATHY_CHAT (child);
1103 /* Disconnect all signal handlers for this chat and this window */
1104 g_signal_handlers_disconnect_by_func (chat,
1105 G_CALLBACK (chat_window_composing_cb),
1107 g_signal_handlers_disconnect_by_func (chat,
1108 G_CALLBACK (chat_window_new_message_cb),
1111 /* Keep list of chats up to date */
1112 priv->chats = g_list_remove (priv->chats, chat);
1113 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, chat);
1114 priv->chats_composing = g_list_remove (priv->chats_composing, chat);
1116 if (priv->chats == NULL) {
1117 g_object_unref (window);
1119 chat_window_update (window);
1124 chat_window_focus_in_event_cb (GtkWidget *widget,
1126 EmpathyChatWindow *window)
1128 EmpathyChatWindowPriv *priv;
1130 DEBUG ("Focus in event, updating title");
1132 priv = GET_PRIV (window);
1134 priv->chats_new_msg = g_list_remove (priv->chats_new_msg, priv->current_chat);
1136 chat_window_set_urgency_hint (window, FALSE);
1138 /* Update the title, since we now mark all unread messages as read. */
1139 chat_window_update_chat_tab (priv->current_chat);
1145 chat_window_drag_data_received (GtkWidget *widget,
1146 GdkDragContext *context,
1149 GtkSelectionData *selection,
1152 EmpathyChatWindow *window)
1154 if (info == DND_DRAG_TYPE_CONTACT_ID) {
1156 EmpathyChatWindow *old_window;
1161 id = (const gchar*) selection->data;
1163 DEBUG ("DND contact from roster with id:'%s'", id);
1165 strv = g_strsplit (id, "/", 2);
1166 account = mc_account_lookup (strv[0]);
1167 chat = empathy_chat_window_find_chat (account, strv[1]);
1170 empathy_dispatcher_chat_with_contact_id (account, strv[2], NULL, NULL);
1171 g_object_unref (account);
1175 g_object_unref (account);
1178 old_window = chat_window_find_chat (chat);
1180 if (old_window == window) {
1181 gtk_drag_finish (context, TRUE, FALSE, time);
1185 empathy_chat_window_move_chat (old_window, window, chat);
1187 empathy_chat_window_add_chat (window, chat);
1190 /* Added to take care of any outstanding chat events */
1191 empathy_chat_window_present_chat (chat);
1193 /* We should return TRUE to remove the data when doing
1194 * GDK_ACTION_MOVE, but we don't here otherwise it has
1195 * weird consequences, and we handle that internally
1196 * anyway with add_chat() and remove_chat().
1198 gtk_drag_finish (context, TRUE, FALSE, time);
1200 else if (info == DND_DRAG_TYPE_TAB) {
1202 EmpathyChatWindow *old_window = NULL;
1206 chat = (void*) selection->data;
1207 old_window = chat_window_find_chat (*chat);
1210 EmpathyChatWindowPriv *priv;
1212 priv = GET_PRIV (window);
1214 if (old_window == window) {
1215 DEBUG ("DND tab (within same window)");
1216 priv->dnd_same_window = TRUE;
1217 gtk_drag_finish (context, TRUE, FALSE, time);
1221 priv->dnd_same_window = FALSE;
1224 /* We should return TRUE to remove the data when doing
1225 * GDK_ACTION_MOVE, but we don't here otherwise it has
1226 * weird consequences, and we handle that internally
1227 * anyway with add_chat() and remove_chat().
1229 gtk_drag_finish (context, TRUE, FALSE, time);
1231 DEBUG ("DND from unknown source");
1232 gtk_drag_finish (context, FALSE, FALSE, time);
1237 chat_window_finalize (GObject *object)
1239 EmpathyChatWindow *window;
1240 EmpathyChatWindowPriv *priv;
1242 window = EMPATHY_CHAT_WINDOW (object);
1243 priv = GET_PRIV (window);
1245 DEBUG ("Finalized: %p", object);
1247 g_object_unref (priv->chatroom_manager);
1248 if (priv->save_geometry_id != 0) {
1249 g_source_remove (priv->save_geometry_id);
1252 if (priv->notification != NULL) {
1253 notify_notification_close (priv->notification, NULL);
1254 g_object_unref (priv->notification);
1255 priv->notification = NULL;
1258 chat_windows = g_list_remove (chat_windows, window);
1259 gtk_widget_destroy (priv->dialog);
1261 G_OBJECT_CLASS (empathy_chat_window_parent_class)->finalize (object);
1265 empathy_chat_window_class_init (EmpathyChatWindowClass *klass)
1267 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1269 object_class->finalize = chat_window_finalize;
1271 g_type_class_add_private (object_class, sizeof (EmpathyChatWindowPriv));
1273 /* Set up a style for the close button with no focus padding. */
1274 gtk_rc_parse_string (
1275 "style \"empathy-close-button-style\"\n"
1277 " GtkWidget::focus-padding = 0\n"
1281 "widget \"*.empathy-close-button\" style \"empathy-close-button-style\"");
1283 gtk_notebook_set_window_creation_hook (chat_window_detach_hook, NULL, NULL);
1287 empathy_chat_window_init (EmpathyChatWindow *window)
1290 GtkAccelGroup *accel_group;
1292 GtkWidget *menu_conv;
1295 GtkWidget *chat_vbox;
1297 EmpathySmileyManager *smiley_manager;
1298 EmpathyChatWindowPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (window,
1299 EMPATHY_TYPE_CHAT_WINDOW, EmpathyChatWindowPriv);
1301 window->priv = priv;
1302 filename = empathy_file_lookup ("empathy-chat-window.ui", "src");
1303 gui = empathy_builder_get_file (filename,
1304 "chat_window", &priv->dialog,
1305 "chat_vbox", &chat_vbox,
1306 "menu_conv", &menu_conv,
1307 "menu_conv_clear", &priv->menu_conv_clear,
1308 "menu_conv_insert_smiley", &priv->menu_conv_insert_smiley,
1309 "menu_conv_contact", &priv->menu_conv_contact,
1310 "menu_conv_favorite", &priv->menu_conv_favorite,
1311 "menu_conv_close", &priv->menu_conv_close,
1312 "menu_edit_cut", &priv->menu_edit_cut,
1313 "menu_edit_copy", &priv->menu_edit_copy,
1314 "menu_edit_paste", &priv->menu_edit_paste,
1315 "menu_tabs_next", &priv->menu_tabs_next,
1316 "menu_tabs_prev", &priv->menu_tabs_prev,
1317 "menu_tabs_left", &priv->menu_tabs_left,
1318 "menu_tabs_right", &priv->menu_tabs_right,
1319 "menu_tabs_detach", &priv->menu_tabs_detach,
1320 "menu_help_contents", &priv->menu_help_contents,
1321 "menu_help_about", &priv->menu_help_about,
1325 empathy_builder_connect (gui, window,
1326 "chat_window", "configure-event", chat_window_configure_event_cb,
1327 "menu_conv", "activate", chat_window_conv_activate_cb,
1328 "menu_conv_clear", "activate", chat_window_clear_activate_cb,
1329 "menu_conv_favorite", "toggled", chat_window_favorite_toggled_cb,
1330 "menu_conv_close", "activate", chat_window_close_activate_cb,
1331 "menu_edit", "activate", chat_window_edit_activate_cb,
1332 "menu_edit_cut", "activate", chat_window_cut_activate_cb,
1333 "menu_edit_copy", "activate", chat_window_copy_activate_cb,
1334 "menu_edit_paste", "activate", chat_window_paste_activate_cb,
1335 "menu_tabs_left", "activate", chat_window_tabs_left_activate_cb,
1336 "menu_tabs_right", "activate", chat_window_tabs_right_activate_cb,
1337 "menu_tabs_detach", "activate", chat_window_detach_activate_cb,
1338 "menu_help_contents", "activate", chat_window_help_contents_cb,
1339 "menu_help_about", "activate", chat_window_help_about_cb,
1342 g_object_unref (gui);
1344 priv->chatroom_manager = empathy_chatroom_manager_dup_singleton (NULL);
1346 priv->notebook = gtk_notebook_new ();
1347 gtk_notebook_set_group (GTK_NOTEBOOK (priv->notebook), "EmpathyChatWindow");
1348 gtk_box_pack_start (GTK_BOX (chat_vbox), priv->notebook, TRUE, TRUE, 0);
1349 gtk_widget_show (priv->notebook);
1352 accel_group = gtk_accel_group_new ();
1353 gtk_window_add_accel_group (GTK_WINDOW (priv->dialog), accel_group);
1355 for (i = 0; i < G_N_ELEMENTS (tab_accel_keys); i++) {
1356 closure = g_cclosure_new (G_CALLBACK (chat_window_accel_cb),
1359 gtk_accel_group_connect (accel_group,
1366 g_object_unref (accel_group);
1368 /* Set up smiley menu */
1369 smiley_manager = empathy_smiley_manager_dup_singleton ();
1370 menu = empathy_smiley_menu_new (smiley_manager,
1371 chat_window_insert_smiley_activate_cb,
1373 gtk_menu_item_set_submenu (GTK_MENU_ITEM (priv->menu_conv_insert_smiley),
1375 g_object_unref (smiley_manager);
1377 /* Set up signals we can't do with ui file since we may need to
1378 * block/unblock them at some later stage.
1381 g_signal_connect (priv->dialog,
1383 G_CALLBACK (chat_window_delete_event_cb),
1386 g_signal_connect_swapped (priv->menu_tabs_prev,
1388 G_CALLBACK (gtk_notebook_prev_page),
1390 g_signal_connect_swapped (priv->menu_tabs_next,
1392 G_CALLBACK (gtk_notebook_next_page),
1395 g_signal_connect (priv->dialog,
1397 G_CALLBACK (chat_window_focus_in_event_cb),
1399 g_signal_connect_after (priv->notebook,
1401 G_CALLBACK (chat_window_page_switched_cb),
1403 g_signal_connect (priv->notebook,
1405 G_CALLBACK (chat_window_page_added_cb),
1407 g_signal_connect (priv->notebook,
1409 G_CALLBACK (chat_window_page_removed_cb),
1412 /* Set up drag and drop */
1413 gtk_drag_dest_set (GTK_WIDGET (priv->notebook),
1414 GTK_DEST_DEFAULT_ALL,
1416 G_N_ELEMENTS (drag_types_dest),
1419 g_signal_connect (priv->notebook,
1420 "drag-data-received",
1421 G_CALLBACK (chat_window_drag_data_received),
1424 chat_windows = g_list_prepend (chat_windows, window);
1426 /* Set up private details */
1428 priv->chats_new_msg = NULL;
1429 priv->chats_composing = NULL;
1430 priv->current_chat = NULL;
1434 empathy_chat_window_new (void)
1436 return EMPATHY_CHAT_WINDOW (g_object_new (EMPATHY_TYPE_CHAT_WINDOW, NULL));
1439 /* Returns the window to open a new tab in if there is only one window
1440 * visble, otherwise, returns NULL indicating that a new window should
1444 empathy_chat_window_get_default (void)
1447 gboolean separate_windows = TRUE;
1449 empathy_conf_get_bool (empathy_conf_get (),
1450 EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
1453 if (separate_windows) {
1454 /* Always create a new window */
1458 for (l = chat_windows; l; l = l->next) {
1459 EmpathyChatWindow *chat_window;
1462 chat_window = l->data;
1464 dialog = empathy_chat_window_get_dialog (chat_window);
1465 if (empathy_window_get_is_visible (GTK_WINDOW (dialog))) {
1466 /* Found a visible window on this desktop */
1475 empathy_chat_window_get_dialog (EmpathyChatWindow *window)
1477 EmpathyChatWindowPriv *priv;
1479 g_return_val_if_fail (window != NULL, NULL);
1481 priv = GET_PRIV (window);
1483 return priv->dialog;
1487 empathy_chat_window_add_chat (EmpathyChatWindow *window,
1490 EmpathyChatWindowPriv *priv;
1495 g_return_if_fail (window != NULL);
1496 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1498 priv = GET_PRIV (window);
1500 /* Reference the chat object */
1501 g_object_ref (chat);
1503 /* If this window has just been created, position it */
1504 if (priv->chats == NULL) {
1505 empathy_geometry_load (chat_get_window_id_for_geometry (chat), &x, &y, &w, &h);
1507 if (x >= 0 && y >= 0) {
1508 /* Let the window manager position it if we don't have
1509 * good x, y coordinates.
1511 gtk_window_move (GTK_WINDOW (priv->dialog), x, y);
1514 if (w > 0 && h > 0) {
1515 /* Use the defaults from the ui file if we don't have
1516 * good w, h geometry.
1518 gtk_window_resize (GTK_WINDOW (priv->dialog), w, h);
1522 child = GTK_WIDGET (chat);
1523 label = chat_window_create_label (window, chat);
1524 gtk_widget_show (child);
1526 g_signal_connect (chat, "notify::name",
1527 G_CALLBACK (chat_window_chat_notify_cb),
1529 g_signal_connect (chat, "notify::subject",
1530 G_CALLBACK (chat_window_chat_notify_cb),
1532 g_signal_connect (chat, "notify::remote-contact",
1533 G_CALLBACK (chat_window_chat_notify_cb),
1535 chat_window_chat_notify_cb (chat);
1537 gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook), child, label);
1538 gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1539 gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (priv->notebook), child, TRUE);
1540 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK (priv->notebook), child,
1541 TRUE, TRUE, GTK_PACK_START);
1543 DEBUG ("Chat added (%d references)", G_OBJECT (chat)->ref_count);
1547 empathy_chat_window_remove_chat (EmpathyChatWindow *window,
1550 EmpathyChatWindowPriv *priv;
1552 EmpathyContact *remote_contact;
1554 g_return_if_fail (window != NULL);
1555 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1557 priv = GET_PRIV (window);
1559 g_signal_handlers_disconnect_by_func (chat,
1560 chat_window_chat_notify_cb,
1562 remote_contact = g_object_get_data (G_OBJECT (chat),
1563 "chat-window-remote-contact");
1564 if (remote_contact) {
1565 g_signal_handlers_disconnect_by_func (remote_contact,
1566 chat_window_update_chat_tab,
1570 position = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1572 gtk_notebook_remove_page (GTK_NOTEBOOK (priv->notebook), position);
1574 DEBUG ("Chat removed (%d references)", G_OBJECT (chat)->ref_count - 1);
1576 g_object_unref (chat);
1580 empathy_chat_window_move_chat (EmpathyChatWindow *old_window,
1581 EmpathyChatWindow *new_window,
1586 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (old_window));
1587 g_return_if_fail (EMPATHY_IS_CHAT_WINDOW (new_window));
1588 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1590 widget = GTK_WIDGET (chat);
1592 DEBUG ("Chat moving with widget:%p (%d references)", widget,
1593 G_OBJECT (widget)->ref_count);
1595 /* We reference here to make sure we don't loose the widget
1596 * and the EmpathyChat object during the move.
1598 g_object_ref (chat);
1599 g_object_ref (widget);
1601 empathy_chat_window_remove_chat (old_window, chat);
1602 empathy_chat_window_add_chat (new_window, chat);
1604 g_object_unref (widget);
1605 g_object_unref (chat);
1609 empathy_chat_window_switch_to_chat (EmpathyChatWindow *window,
1612 EmpathyChatWindowPriv *priv;
1615 g_return_if_fail (window != NULL);
1616 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1618 priv = GET_PRIV (window);
1620 page_num = gtk_notebook_page_num (GTK_NOTEBOOK (priv->notebook),
1622 gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
1627 empathy_chat_window_has_focus (EmpathyChatWindow *window)
1629 EmpathyChatWindowPriv *priv;
1632 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1634 priv = GET_PRIV (window);
1636 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);
1642 empathy_chat_window_find_chat (McAccount *account,
1647 g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
1648 g_return_val_if_fail (!EMP_STR_EMPTY (id), NULL);
1650 for (l = chat_windows; l; l = l->next) {
1651 EmpathyChatWindowPriv *priv;
1652 EmpathyChatWindow *window;
1656 priv = GET_PRIV (window);
1658 for (ll = priv->chats; ll; ll = ll->next) {
1663 if (empathy_account_equal (account, empathy_chat_get_account (chat)) &&
1664 !tp_strdiff (id, empathy_chat_get_id (chat))) {
1674 empathy_chat_window_present_chat (EmpathyChat *chat)
1676 EmpathyChatWindow *window;
1677 EmpathyChatWindowPriv *priv;
1679 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1681 window = chat_window_find_chat (chat);
1683 /* If the chat has no window, create one */
1684 if (window == NULL) {
1685 window = empathy_chat_window_get_default ();
1687 window = empathy_chat_window_new ();
1690 empathy_chat_window_add_chat (window, chat);
1693 priv = GET_PRIV (window);
1694 empathy_chat_window_switch_to_chat (window, chat);
1695 empathy_window_present (GTK_WINDOW (priv->dialog), TRUE);
1697 gtk_widget_grab_focus (chat->input_text_view);
1702 chat_window_should_play_sound (EmpathyChatWindow *window)
1704 EmpathyChatWindowPriv *priv = GET_PRIV (window);
1705 gboolean has_focus = FALSE;
1707 g_return_val_if_fail (EMPATHY_IS_CHAT_WINDOW (window), FALSE);
1709 g_object_get (priv->dialog, "has-toplevel-focus", &has_focus, NULL);