1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2002-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>
37 #include <libmissioncontrol/mission-control.h>
38 #include <telepathy-glib/util.h>
40 #include <libempathy/empathy-log-manager.h>
41 #include <libempathy/empathy-contact-list.h>
42 #include <libempathy/empathy-debug.h>
43 #include <libempathy/empathy-utils.h>
45 #include "empathy-chat.h"
46 #include "empathy-conf.h"
47 #include "empathy-spell.h"
48 #include "empathy-spell-dialog.h"
49 #include "empathy-contact-list-store.h"
50 #include "empathy-contact-list-view.h"
51 #include "empathy-ui-utils.h"
53 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CHAT, EmpathyChatPriv))
55 #define DEBUG_DOMAIN "Chat"
57 #define CHAT_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
58 #define CHAT_FILE_CREATE_MODE (S_IRUSR | S_IWUSR)
59 #define IS_ENTER(v) (v == GDK_Return || v == GDK_ISO_Enter || v == GDK_KP_Enter)
60 #define MAX_INPUT_HEIGHT 150
61 #define COMPOSING_STOP_TIMEOUT 5
63 struct _EmpathyChatPriv {
64 EmpathyTpChat *tp_chat;
69 EmpathyContact *remote_contact;
71 EmpathyLogManager *log_manager;
73 GSList *sent_messages;
74 gint sent_messages_index;
76 GList *backlog_messages;
77 GCompletion *completion;
78 guint composing_stop_timeout_id;
79 guint block_events_timeout_id;
80 TpHandleType handle_type;
87 GtkWidget *scrolled_window_chat;
88 GtkWidget *scrolled_window_input;
89 GtkWidget *scrolled_window_contacts;
90 GtkWidget *hbox_topic;
91 GtkWidget *label_topic;
92 GtkWidget *contact_list_view;
94 /* Used to automatically shrink a window that has temporarily
95 * grown due to long input.
98 gint default_window_height;
99 gint last_input_height;
100 gboolean vscroll_visible;
101 gboolean is_first_char;
104 static void empathy_chat_class_init (EmpathyChatClass *klass);
105 static void empathy_chat_init (EmpathyChat *chat);
123 static guint signals[LAST_SIGNAL] = { 0 };
125 G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
128 chat_get_property (GObject *object,
133 EmpathyChatPriv *priv = GET_PRIV (object);
137 g_value_set_object (value, priv->tp_chat);
140 g_value_set_object (value, priv->account);
143 g_value_set_string (value, priv->name);
146 g_value_set_string (value, priv->id);
149 g_value_set_string (value, priv->subject);
151 case PROP_REMOTE_CONTACT:
152 g_value_set_object (value, priv->remote_contact);
155 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
161 chat_set_property (GObject *object,
166 EmpathyChat *chat = EMPATHY_CHAT (object);
170 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
173 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
179 chat_status_changed_cb (MissionControl *mc,
180 TpConnectionStatus status,
182 TpConnectionStatusReason reason,
183 const gchar *unique_name,
186 EmpathyChatPriv *priv = GET_PRIV (chat);
189 account = mc_account_lookup (unique_name);
191 if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
192 empathy_account_equal (account, priv->account) &&
193 priv->handle_type != TP_HANDLE_TYPE_NONE) {
194 empathy_debug (DEBUG_DOMAIN,
195 "Account reconnected, request a new Text channel");
196 mission_control_request_channel_with_string_handle (mc,
198 TP_IFACE_CHANNEL_TYPE_TEXT,
204 g_object_unref (account);
208 chat_composing_remove_timeout (EmpathyChat *chat)
210 EmpathyChatPriv *priv;
212 priv = GET_PRIV (chat);
214 if (priv->composing_stop_timeout_id) {
215 g_source_remove (priv->composing_stop_timeout_id);
216 priv->composing_stop_timeout_id = 0;
221 chat_composing_stop_timeout_cb (EmpathyChat *chat)
223 EmpathyChatPriv *priv;
225 priv = GET_PRIV (chat);
227 priv->composing_stop_timeout_id = 0;
228 empathy_tp_chat_set_state (priv->tp_chat,
229 TP_CHANNEL_CHAT_STATE_PAUSED);
235 chat_composing_start (EmpathyChat *chat)
237 EmpathyChatPriv *priv;
239 priv = GET_PRIV (chat);
241 if (priv->composing_stop_timeout_id) {
242 /* Just restart the timeout */
243 chat_composing_remove_timeout (chat);
245 empathy_tp_chat_set_state (priv->tp_chat,
246 TP_CHANNEL_CHAT_STATE_COMPOSING);
249 priv->composing_stop_timeout_id = g_timeout_add_seconds (
250 COMPOSING_STOP_TIMEOUT,
251 (GSourceFunc) chat_composing_stop_timeout_cb,
256 chat_composing_stop (EmpathyChat *chat)
258 EmpathyChatPriv *priv;
260 priv = GET_PRIV (chat);
262 chat_composing_remove_timeout (chat);
263 empathy_tp_chat_set_state (priv->tp_chat,
264 TP_CHANNEL_CHAT_STATE_ACTIVE);
268 chat_destroy_cb (EmpathyTpChat *tp_chat,
271 EmpathyChatPriv *priv;
273 priv = GET_PRIV (chat);
276 g_object_unref (priv->tp_chat);
277 priv->tp_chat = NULL;
278 g_object_notify (G_OBJECT (chat), "tp-chat");
281 empathy_chat_view_append_event (chat->view, _("Disconnected"));
282 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
286 chat_sent_message_add (EmpathyChat *chat,
289 EmpathyChatPriv *priv;
293 priv = GET_PRIV (chat);
295 /* Save the sent message in our repeat buffer */
296 list = priv->sent_messages;
298 /* Remove any other occurances of this msg */
299 while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) {
300 list = g_slist_remove_link (list, item);
302 g_slist_free1 (item);
305 /* Trim the list to the last 10 items */
306 while (g_slist_length (list) > 10) {
307 item = g_slist_last (list);
309 list = g_slist_remove_link (list, item);
311 g_slist_free1 (item);
315 /* Add new message */
316 list = g_slist_prepend (list, g_strdup (str));
318 /* Set list and reset the index */
319 priv->sent_messages = list;
320 priv->sent_messages_index = -1;
324 chat_sent_message_get_next (EmpathyChat *chat)
326 EmpathyChatPriv *priv;
329 priv = GET_PRIV (chat);
331 if (!priv->sent_messages) {
332 empathy_debug (DEBUG_DOMAIN,
333 "No sent messages, next message is NULL");
337 max = g_slist_length (priv->sent_messages) - 1;
339 if (priv->sent_messages_index < max) {
340 priv->sent_messages_index++;
343 empathy_debug (DEBUG_DOMAIN,
344 "Returning next message index:%d",
345 priv->sent_messages_index);
347 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
351 chat_sent_message_get_last (EmpathyChat *chat)
353 EmpathyChatPriv *priv;
355 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
357 priv = GET_PRIV (chat);
359 if (!priv->sent_messages) {
360 empathy_debug (DEBUG_DOMAIN,
361 "No sent messages, last message is NULL");
365 if (priv->sent_messages_index >= 0) {
366 priv->sent_messages_index--;
369 empathy_debug (DEBUG_DOMAIN,
370 "Returning last message index:%d",
371 priv->sent_messages_index);
373 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
377 chat_send (EmpathyChat *chat,
380 EmpathyChatPriv *priv;
381 EmpathyMessage *message;
383 priv = GET_PRIV (chat);
385 if (G_STR_EMPTY (msg)) {
389 chat_sent_message_add (chat, msg);
391 if (g_str_has_prefix (msg, "/clear")) {
392 empathy_chat_view_clear (chat->view);
396 message = empathy_message_new (msg);
398 empathy_tp_chat_send (priv->tp_chat, message);
400 g_object_unref (message);
404 chat_input_text_view_send (EmpathyChat *chat)
406 EmpathyChatPriv *priv;
407 GtkTextBuffer *buffer;
408 GtkTextIter start, end;
411 priv = GET_PRIV (chat);
413 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
415 gtk_text_buffer_get_bounds (buffer, &start, &end);
416 msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
418 /* clear the input field */
419 gtk_text_buffer_set_text (buffer, "", -1);
421 chat_send (chat, msg);
424 priv->is_first_char = TRUE;
428 chat_state_changed_cb (EmpathyTpChat *tp_chat,
429 EmpathyContact *contact,
430 TpChannelChatState state,
433 EmpathyChatPriv *priv;
435 gboolean was_composing;
437 priv = GET_PRIV (chat);
439 if (empathy_contact_is_user (contact)) {
440 /* We don't care about our own chat state */
444 was_composing = (priv->compositors != NULL);
446 /* Find the contact in the list. After that l is the list elem or NULL */
447 for (l = priv->compositors; l; l = l->next) {
448 if (contact == l->data) {
454 case TP_CHANNEL_CHAT_STATE_GONE:
455 case TP_CHANNEL_CHAT_STATE_INACTIVE:
456 case TP_CHANNEL_CHAT_STATE_PAUSED:
457 case TP_CHANNEL_CHAT_STATE_ACTIVE:
458 /* Contact is not composing */
460 priv->compositors = g_list_remove_link (priv->compositors, l);
461 g_object_unref (l->data);
465 case TP_CHANNEL_CHAT_STATE_COMPOSING:
466 /* Contact is composing */
468 priv->compositors = g_list_prepend (priv->compositors,
469 g_object_ref (contact));
473 g_assert_not_reached ();
476 empathy_debug (DEBUG_DOMAIN, "Was composing: %s now composing: %s",
477 was_composing ? "yes" : "no",
478 priv->compositors ? "yes" : "no");
480 if ((was_composing && !priv->compositors) ||
481 (!was_composing && priv->compositors)) {
482 /* Composing state changed */
483 g_signal_emit (chat, signals[COMPOSING], 0,
484 priv->compositors != NULL);
489 chat_message_received_cb (EmpathyTpChat *tp_chat,
490 EmpathyMessage *message,
493 EmpathyChatPriv *priv;
494 EmpathyContact *sender;
497 priv = GET_PRIV (chat);
499 sender = empathy_message_get_sender (message);
500 body = empathy_message_get_body (message);
501 while (priv->backlog_messages) {
502 EmpathyMessage *log_message;
503 EmpathyContact *log_sender;
504 const gchar *log_body;
506 log_message = priv->backlog_messages->data;
507 log_sender = empathy_message_get_sender (log_message);
508 log_body = empathy_message_get_body (log_message);
510 priv->backlog_messages = g_list_remove (priv->backlog_messages,
513 if (empathy_contact_equal (sender, log_sender) &&
514 !tp_strdiff (body, log_body)) {
515 /* The message we received is already displayed because
516 * some jabber chatrooms sends us back logs and we
517 * already displayed it from localy logged messages. */
518 empathy_debug (DEBUG_DOMAIN, "Skipping message because "
519 "it is already displayed from logged "
521 g_object_unref (log_message);
524 g_object_unref (log_message);
527 empathy_debug (DEBUG_DOMAIN, "Appending new message from %s (%d)",
528 empathy_contact_get_name (sender),
529 empathy_contact_get_handle (sender));
532 gboolean is_chatroom;
534 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
535 empathy_log_manager_add_message (priv->log_manager,
536 priv->id, is_chatroom,
540 empathy_chat_view_append_message (chat->view, message);
542 /* We received a message so the contact is no more composing */
543 chat_state_changed_cb (tp_chat, sender,
544 TP_CHANNEL_CHAT_STATE_ACTIVE,
547 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
551 chat_send_error_cb (EmpathyTpChat *tp_chat,
552 EmpathyMessage *message,
553 TpChannelTextSendError error_code,
559 switch (error_code) {
560 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
561 error = _("offline");
563 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
564 error = _("invalid contact");
566 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
567 error = _("permission denied");
569 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
570 error = _("too long message");
572 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
573 error = _("not implemented");
576 error = _("unknown");
580 str = g_strdup_printf (_("Error sending message '%s': %s"),
581 empathy_message_get_body (message),
583 empathy_chat_view_append_event (chat->view, str);
588 chat_property_changed_cb (EmpathyTpChat *tp_chat,
593 EmpathyChatPriv *priv = GET_PRIV (chat);
595 if (!tp_strdiff (name, "subject")) {
596 g_free (priv->subject);
597 priv->subject = g_value_dup_string (value);
598 g_object_notify (G_OBJECT (chat), "subject");
600 if (G_STR_EMPTY (priv->subject)) {
601 gtk_widget_hide (priv->hbox_topic);
603 gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
604 gtk_widget_show (priv->hbox_topic);
606 if (priv->block_events_timeout_id == 0) {
609 if (!G_STR_EMPTY (priv->subject)) {
610 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
612 str = g_strdup (_("No topic defined"));
614 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
618 else if (!tp_strdiff (name, "name")) {
620 priv->name = g_value_dup_string (value);
621 g_object_notify (G_OBJECT (chat), "name");
626 chat_get_is_command (const gchar *str)
628 g_return_val_if_fail (str != NULL, FALSE);
634 if (g_str_has_prefix (str, "/me")) {
637 else if (g_str_has_prefix (str, "/nick")) {
640 else if (g_str_has_prefix (str, "/topic")) {
648 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
651 EmpathyChatPriv *priv;
652 GtkTextIter start, end;
654 gboolean spell_checker = FALSE;
656 priv = GET_PRIV (chat);
658 if (gtk_text_buffer_get_char_count (buffer) == 0) {
659 chat_composing_stop (chat);
661 chat_composing_start (chat);
664 empathy_conf_get_bool (empathy_conf_get (),
665 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
668 if (priv->is_first_char) {
672 GtkAllocation *allocation;
674 /* Save the window's size */
675 dialog = empathy_get_toplevel_window (GTK_WIDGET (chat));
677 gtk_window_get_size (GTK_WINDOW (dialog), NULL, &window_height);
678 gtk_widget_size_request (chat->input_text_view, &req);
679 allocation = >K_WIDGET (chat->view)->allocation;
681 priv->default_window_height = window_height;
682 priv->last_input_height = req.height;
683 priv->padding_height = window_height - req.height - allocation->height;
686 priv->is_first_char = FALSE;
689 gtk_text_buffer_get_start_iter (buffer, &start);
691 if (!spell_checker) {
692 gtk_text_buffer_get_end_iter (buffer, &end);
693 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
697 if (!empathy_spell_supported ()) {
701 /* NOTE: this is really inefficient, we shouldn't have to
702 reiterate the whole buffer each time and check each work
705 gboolean correct = FALSE;
708 if (gtk_text_iter_is_start (&start)) {
711 if (!gtk_text_iter_forward_word_end (&end)) {
712 /* no whole word yet */
716 if (!gtk_text_iter_forward_word_end (&end)) {
717 /* must be the end of the buffer */
722 gtk_text_iter_backward_word_start (&start);
725 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
727 /* spell check string */
728 if (!chat_get_is_command (str)) {
729 correct = empathy_spell_check (str);
735 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
737 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
742 /* set start iter to the end iters position */
748 chat_input_key_press_event_cb (GtkWidget *widget,
752 EmpathyChatPriv *priv;
755 GtkWidget *text_view_sw;
757 priv = GET_PRIV (chat);
759 /* Catch ctrl+up/down so we can traverse messages we sent */
760 if ((event->state & GDK_CONTROL_MASK) &&
761 (event->keyval == GDK_Up ||
762 event->keyval == GDK_Down)) {
763 GtkTextBuffer *buffer;
766 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
768 if (event->keyval == GDK_Up) {
769 str = chat_sent_message_get_next (chat);
771 str = chat_sent_message_get_last (chat);
774 g_signal_handlers_block_by_func (buffer,
775 chat_input_text_buffer_changed_cb,
777 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
778 g_signal_handlers_unblock_by_func (buffer,
779 chat_input_text_buffer_changed_cb,
785 /* Catch enter but not ctrl/shift-enter */
786 if (IS_ENTER (event->keyval) &&
787 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
790 /* This is to make sure that kinput2 gets the enter. And if
791 * it's handled there we shouldn't send on it. This is because
792 * kinput2 uses Enter to commit letters. See:
793 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
796 view = GTK_TEXT_VIEW (chat->input_text_view);
797 if (gtk_im_context_filter_keypress (view->im_context, event)) {
798 GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
802 chat_input_text_view_send (chat);
806 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
808 if (IS_ENTER (event->keyval) &&
809 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
810 /* Newline for shift/control-enter. */
813 if (!(event->state & GDK_CONTROL_MASK) &&
814 event->keyval == GDK_Page_Up) {
815 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
816 gtk_adjustment_set_value (adj, adj->value - adj->page_size);
819 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
820 event->keyval == GDK_Page_Down) {
821 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
822 val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
823 gtk_adjustment_set_value (adj, val);
826 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
827 event->keyval == GDK_Tab) {
828 GtkTextBuffer *buffer;
829 GtkTextIter start, current;
830 gchar *nick, *completed;
831 GList *list, *completed_list;
832 gboolean is_start_of_buffer;
834 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
835 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
837 /* Get the start of the nick to complete. */
838 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
839 gtk_text_iter_backward_word_start (&start);
840 is_start_of_buffer = gtk_text_iter_is_start (&start);
842 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
843 g_completion_add_items (priv->completion, list);
845 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
846 completed_list = g_completion_complete (priv->completion,
855 gchar *complete_char = NULL;
857 gtk_text_buffer_delete (buffer, &start, ¤t);
859 len = g_list_length (completed_list);
862 /* If we only have one hit, use that text
863 * instead of the text in completed since the
864 * completed text will use the typed string
865 * which might be cased all wrong.
868 text = empathy_contact_get_name (completed_list->data);
873 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
875 if (len == 1 && is_start_of_buffer &&
876 empathy_conf_get_string (empathy_conf_get (),
877 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
879 complete_char != NULL) {
880 gtk_text_buffer_insert_at_cursor (buffer,
882 strlen (complete_char));
883 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
884 g_free (complete_char);
890 g_completion_clear_items (priv->completion);
892 g_list_foreach (list, (GFunc) g_object_unref, NULL);
902 chat_text_view_focus_in_event_cb (GtkWidget *widget,
906 gtk_widget_grab_focus (chat->input_text_view);
918 chat_change_size_in_idle_cb (ChangeSizeData *data)
920 gtk_window_resize (data->window, data->width, data->height);
926 chat_text_view_scroll_hide_cb (GtkWidget *widget,
929 EmpathyChatPriv *priv;
932 priv = GET_PRIV (chat);
934 priv->vscroll_visible = FALSE;
935 g_signal_handlers_disconnect_by_func (widget,
936 chat_text_view_scroll_hide_cb,
939 sw = gtk_widget_get_parent (chat->input_text_view);
940 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
943 g_object_set (sw, "height-request", -1, NULL);
947 chat_text_view_size_allocate_cb (GtkWidget *widget,
948 GtkAllocation *allocation,
951 EmpathyChatPriv *priv;
954 ChangeSizeData *data;
957 GtkAllocation *view_allocation;
962 priv = GET_PRIV (chat);
964 if (priv->default_window_height <= 0) {
968 sw = gtk_widget_get_parent (widget);
969 if (sw->allocation.height >= MAX_INPUT_HEIGHT && !priv->vscroll_visible) {
972 priv->vscroll_visible = TRUE;
973 gtk_widget_set_size_request (sw, sw->allocation.width, MAX_INPUT_HEIGHT);
974 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
976 GTK_POLICY_AUTOMATIC);
977 vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (sw));
978 g_signal_connect (vscroll, "hide",
979 G_CALLBACK (chat_text_view_scroll_hide_cb),
983 if (priv->last_input_height <= allocation->height) {
984 priv->last_input_height = allocation->height;
988 diff = priv->last_input_height - allocation->height;
989 priv->last_input_height = allocation->height;
991 view_allocation = >K_WIDGET (chat->view)->allocation;
993 dialog = empathy_get_toplevel_window (GTK_WIDGET (widget));
994 gtk_window_get_size (dialog, NULL, ¤t_height);
996 new_height = view_allocation->height + priv->padding_height + allocation->height - diff;
998 if (new_height <= priv->default_window_height) {
999 window_height = priv->default_window_height;
1001 window_height = new_height;
1004 if (current_height <= window_height) {
1008 /* Restore the window's size */
1009 gtk_window_get_size (dialog, &width, NULL);
1011 data = g_new0 (ChangeSizeData, 1);
1012 data->window = dialog;
1013 data->width = width;
1014 data->height = window_height;
1016 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
1017 (GSourceFunc) chat_change_size_in_idle_cb,
1022 chat_text_view_realize_cb (GtkWidget *widget,
1025 empathy_debug (DEBUG_DOMAIN, "Setting focus to the input text view");
1026 gtk_widget_grab_focus (widget);
1030 chat_insert_smiley_activate_cb (GtkWidget *menuitem,
1033 GtkTextBuffer *buffer;
1035 const gchar *smiley;
1037 smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
1039 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1041 gtk_text_buffer_get_end_iter (buffer, &iter);
1042 gtk_text_buffer_insert (buffer, &iter, smiley, -1);
1044 gtk_text_buffer_get_end_iter (buffer, &iter);
1045 gtk_text_buffer_insert (buffer, &iter, " ", -1);
1056 static EmpathyChatSpell *
1057 chat_spell_new (EmpathyChat *chat,
1062 EmpathyChatSpell *chat_spell;
1064 chat_spell = g_slice_new0 (EmpathyChatSpell);
1066 chat_spell->chat = g_object_ref (chat);
1067 chat_spell->word = g_strdup (word);
1068 chat_spell->start = start;
1069 chat_spell->end = end;
1075 chat_spell_free (EmpathyChatSpell *chat_spell)
1077 g_object_unref (chat_spell->chat);
1078 g_free (chat_spell->word);
1079 g_slice_free (EmpathyChatSpell, chat_spell);
1083 chat_text_check_word_spelling_cb (GtkMenuItem *menuitem,
1084 EmpathyChatSpell *chat_spell)
1086 empathy_spell_dialog_show (chat_spell->chat,
1093 chat_text_populate_popup_cb (GtkTextView *view,
1097 EmpathyChatPriv *priv;
1098 GtkTextBuffer *buffer;
1099 GtkTextTagTable *table;
1102 GtkTextIter iter, start, end;
1105 EmpathyChatSpell *chat_spell;
1106 GtkWidget *smiley_menu;
1108 priv = GET_PRIV (chat);
1110 /* Add the emoticon menu. */
1111 item = gtk_separator_menu_item_new ();
1112 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1113 gtk_widget_show (item);
1115 item = gtk_menu_item_new_with_mnemonic (_("Insert Smiley"));
1116 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1117 gtk_widget_show (item);
1119 smiley_menu = empathy_chat_view_get_smiley_menu (
1120 G_CALLBACK (chat_insert_smiley_activate_cb),
1122 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
1124 /* Add the spell check menu item. */
1125 buffer = gtk_text_view_get_buffer (view);
1126 table = gtk_text_buffer_get_tag_table (buffer);
1128 tag = gtk_text_tag_table_lookup (table, "misspelled");
1130 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
1132 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
1133 GTK_TEXT_WINDOW_WIDGET,
1137 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
1141 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
1142 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1144 str = gtk_text_buffer_get_text (buffer,
1145 &start, &end, FALSE);
1148 if (G_STR_EMPTY (str)) {
1152 chat_spell = chat_spell_new (chat, str, start, end);
1154 g_object_set_data_full (G_OBJECT (menu),
1155 "chat_spell", chat_spell,
1156 (GDestroyNotify) chat_spell_free);
1158 item = gtk_separator_menu_item_new ();
1159 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1160 gtk_widget_show (item);
1162 item = gtk_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
1163 g_signal_connect (item,
1165 G_CALLBACK (chat_text_check_word_spelling_cb),
1167 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1168 gtk_widget_show (item);
1172 chat_add_logs (EmpathyChat *chat)
1174 EmpathyChatPriv *priv = GET_PRIV (chat);
1175 gboolean is_chatroom;
1176 GList *messages, *l;
1184 /* Turn off scrolling temporarily */
1185 empathy_chat_view_scroll (chat->view, FALSE);
1187 /* Add messages from last conversation */
1188 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
1189 messages = empathy_log_manager_get_last_messages (priv->log_manager,
1193 num_messages = g_list_length (messages);
1195 /* Only keep the 10 last messages */
1196 for (i = 0; num_messages - i > 10; i++) {
1197 EmpathyMessage *message;
1199 message = messages->data;
1200 messages = g_list_remove (messages, message);
1201 g_object_unref (message);
1204 for (l = messages; l; l = l->next) {
1205 empathy_chat_view_append_message (chat->view, l->data);
1207 priv->backlog_messages = messages;
1209 /* Turn back on scrolling */
1210 empathy_chat_view_scroll (chat->view, TRUE);
1214 chat_contacts_completion_func (const gchar *s1,
1218 gchar *tmp, *nick1, *nick2;
1225 return s1 ? -1 : +1;
1228 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
1229 nick1 = g_utf8_casefold (tmp, -1);
1232 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
1233 nick2 = g_utf8_casefold (tmp, -1);
1236 ret = strncmp (nick1, nick2, n);
1245 chat_members_changed_cb (EmpathyTpChat *tp_chat,
1246 EmpathyContact *contact,
1247 EmpathyContact *actor,
1253 EmpathyChatPriv *priv = GET_PRIV (chat);
1255 if (priv->block_events_timeout_id == 0) {
1258 empathy_contact_run_until_ready (contact,
1259 EMPATHY_CONTACT_READY_NAME,
1263 str = g_strdup_printf (_("%s has joined the room"),
1264 empathy_contact_get_name (contact));
1266 str = g_strdup_printf (_("%s has left the room"),
1267 empathy_contact_get_name (contact));
1269 empathy_chat_view_append_event (chat->view, str);
1275 chat_reset_size_request (gpointer widget)
1277 gtk_widget_set_size_request (widget, -1, -1);
1283 chat_set_show_contacts (EmpathyChat *chat, gboolean show)
1285 EmpathyChatPriv *priv = GET_PRIV (chat);
1287 if (!priv->scrolled_window_contacts) {
1292 EmpathyContactListStore *store;
1295 /* We are adding the contact list to the chat, we don't want the
1296 * chat view to become too small. If the chat view is already
1297 * smaller than 250 make sure that size won't change. If the
1298 * chat view is bigger the contact list will take some space on
1299 * it but we make sure the chat view don't become smaller than
1300 * 250. Relax the size request once the resize is done */
1301 min_width = MIN (priv->vbox_left->allocation.width, 250);
1302 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
1303 g_idle_add (chat_reset_size_request, priv->vbox_left);
1305 if (priv->contacts_width > 0) {
1306 gtk_paned_set_position (GTK_PANED (priv->hpaned),
1307 priv->contacts_width);
1310 store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
1311 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
1312 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT |
1313 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL |
1314 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG |
1315 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT |
1316 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE |
1317 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO));
1318 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
1319 priv->contact_list_view);
1320 gtk_widget_show (priv->contact_list_view);
1321 gtk_widget_show (priv->scrolled_window_contacts);
1322 g_object_unref (store);
1324 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
1325 gtk_widget_hide (priv->scrolled_window_contacts);
1326 if (priv->contact_list_view) {
1327 gtk_widget_destroy (priv->contact_list_view);
1328 priv->contact_list_view = NULL;
1334 chat_remote_contact_changed_cb (EmpathyChat *chat)
1336 EmpathyChatPriv *priv = GET_PRIV (chat);
1338 if (priv->remote_contact) {
1339 g_object_unref (priv->remote_contact);
1340 priv->remote_contact = NULL;
1343 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
1344 if (priv->remote_contact) {
1345 g_object_ref (priv->remote_contact);
1346 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
1348 priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
1350 else if (priv->tp_chat) {
1353 channel = empathy_tp_chat_get_channel (priv->tp_chat);
1354 g_object_get (channel, "handle-type", &priv->handle_type, NULL);
1356 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
1359 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1361 g_object_notify (G_OBJECT (chat), "remote-contact");
1362 g_object_notify (G_OBJECT (chat), "id");
1366 chat_create_ui (EmpathyChat *chat)
1368 EmpathyChatPriv *priv = GET_PRIV (chat);
1372 GtkTextBuffer *buffer;
1374 filename = empathy_file_lookup ("empathy-chat.glade",
1376 glade = empathy_glade_get_file (filename,
1379 "chat_widget", &priv->widget,
1380 "hpaned", &priv->hpaned,
1381 "vbox_left", &priv->vbox_left,
1382 "scrolled_window_chat", &priv->scrolled_window_chat,
1383 "scrolled_window_input", &priv->scrolled_window_input,
1384 "hbox_topic", &priv->hbox_topic,
1385 "label_topic", &priv->label_topic,
1386 "scrolled_window_contacts", &priv->scrolled_window_contacts,
1389 g_object_unref (glade);
1391 /* Add message GtkTextView. */
1392 chat->view = empathy_chat_view_new ();
1393 g_signal_connect (chat->view, "focus_in_event",
1394 G_CALLBACK (chat_text_view_focus_in_event_cb),
1396 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
1397 GTK_WIDGET (chat->view));
1398 gtk_widget_show (GTK_WIDGET (chat->view));
1400 /* Add input GtkTextView */
1401 chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
1402 "pixels-above-lines", 2,
1403 "pixels-below-lines", 2,
1404 "pixels-inside-wrap", 1,
1407 "wrap-mode", GTK_WRAP_WORD_CHAR,
1409 g_signal_connect (chat->input_text_view, "key_press_event",
1410 G_CALLBACK (chat_input_key_press_event_cb),
1412 g_signal_connect (chat->input_text_view, "size_allocate",
1413 G_CALLBACK (chat_text_view_size_allocate_cb),
1415 g_signal_connect (chat->input_text_view, "realize",
1416 G_CALLBACK (chat_text_view_realize_cb),
1418 g_signal_connect (chat->input_text_view, "populate_popup",
1419 G_CALLBACK (chat_text_populate_popup_cb),
1421 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1422 g_signal_connect (buffer, "changed",
1423 G_CALLBACK (chat_input_text_buffer_changed_cb),
1425 gtk_text_buffer_create_tag (buffer, "misspelled",
1426 "underline", PANGO_UNDERLINE_ERROR,
1428 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
1429 chat->input_text_view);
1430 gtk_widget_show (chat->input_text_view);
1432 /* Create contact list */
1433 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1435 /* Initialy hide the topic, will be shown if not empty */
1436 gtk_widget_hide (priv->hbox_topic);
1438 /* Set widget focus order */
1439 list = g_list_append (NULL, priv->scrolled_window_input);
1440 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
1443 list = g_list_append (NULL, priv->vbox_left);
1444 list = g_list_append (list, priv->scrolled_window_contacts);
1445 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
1448 list = g_list_append (NULL, priv->hpaned);
1449 list = g_list_append (list, priv->hbox_topic);
1450 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
1453 /* Add the main widget in the chat widget */
1454 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
1458 chat_size_request (GtkWidget *widget,
1459 GtkRequisition *requisition)
1461 GtkBin *bin = GTK_BIN (widget);
1463 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
1464 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
1466 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1468 GtkRequisition child_requisition;
1470 gtk_widget_size_request (bin->child, &child_requisition);
1472 requisition->width += child_requisition.width;
1473 requisition->height += child_requisition.height;
1478 chat_size_allocate (GtkWidget *widget,
1479 GtkAllocation *allocation)
1481 GtkBin *bin = GTK_BIN (widget);
1482 GtkAllocation child_allocation;
1484 widget->allocation = *allocation;
1486 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1488 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1489 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
1490 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
1491 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
1493 gtk_widget_size_allocate (bin->child, &child_allocation);
1498 chat_finalize (GObject *object)
1501 EmpathyChatPriv *priv;
1503 chat = EMPATHY_CHAT (object);
1504 priv = GET_PRIV (chat);
1506 empathy_debug (DEBUG_DOMAIN, "Finalized: %p", object);
1508 g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
1509 g_slist_free (priv->sent_messages);
1511 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
1512 g_list_free (priv->compositors);
1514 g_list_foreach (priv->backlog_messages, (GFunc) g_object_unref, NULL);
1515 g_list_free (priv->backlog_messages);
1517 chat_composing_remove_timeout (chat);
1519 empathy_disconnect_account_status_changed (priv->token);
1520 g_object_unref (priv->mc);
1521 g_object_unref (priv->log_manager);
1523 if (priv->tp_chat) {
1524 g_object_unref (priv->tp_chat);
1526 if (priv->account) {
1527 g_object_unref (priv->account);
1529 if (priv->remote_contact) {
1530 g_object_unref (priv->remote_contact);
1533 if (priv->block_events_timeout_id) {
1534 g_source_remove (priv->block_events_timeout_id);
1538 g_free (priv->name);
1539 g_free (priv->subject);
1541 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
1545 chat_constructed (GObject *object)
1547 EmpathyChat *chat = EMPATHY_CHAT (object);
1549 chat_create_ui (chat);
1550 chat_add_logs (chat);
1554 empathy_chat_class_init (EmpathyChatClass *klass)
1556 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1557 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1559 object_class->finalize = chat_finalize;
1560 object_class->get_property = chat_get_property;
1561 object_class->set_property = chat_set_property;
1562 object_class->constructed = chat_constructed;
1564 widget_class->size_request = chat_size_request;
1565 widget_class->size_allocate = chat_size_allocate;
1567 g_object_class_install_property (object_class,
1569 g_param_spec_object ("tp-chat",
1571 "The tp chat object",
1572 EMPATHY_TYPE_TP_CHAT,
1574 G_PARAM_READWRITE));
1575 g_object_class_install_property (object_class,
1577 g_param_spec_object ("account",
1578 "Account of the chat",
1579 "The account of the chat",
1582 g_object_class_install_property (object_class,
1584 g_param_spec_string ("id",
1586 "The id of the chat",
1589 g_object_class_install_property (object_class,
1591 g_param_spec_string ("name",
1593 "The name of the chat",
1596 g_object_class_install_property (object_class,
1598 g_param_spec_string ("subject",
1600 "The subject or topic of the chat",
1603 g_object_class_install_property (object_class,
1604 PROP_REMOTE_CONTACT,
1605 g_param_spec_object ("remote-contact",
1606 "The remote contact",
1607 "The remote contact is any",
1608 EMPATHY_TYPE_CONTACT,
1611 signals[COMPOSING] =
1612 g_signal_new ("composing",
1613 G_OBJECT_CLASS_TYPE (object_class),
1617 g_cclosure_marshal_VOID__BOOLEAN,
1621 signals[NEW_MESSAGE] =
1622 g_signal_new ("new-message",
1623 G_OBJECT_CLASS_TYPE (object_class),
1627 g_cclosure_marshal_VOID__OBJECT,
1629 1, EMPATHY_TYPE_MESSAGE);
1631 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
1635 chat_block_events_timeout_cb (gpointer data)
1637 EmpathyChatPriv *priv = GET_PRIV (data);
1639 priv->block_events_timeout_id = 0;
1645 empathy_chat_init (EmpathyChat *chat)
1647 EmpathyChatPriv *priv = GET_PRIV (chat);
1649 priv->is_first_char = TRUE;
1650 priv->log_manager = empathy_log_manager_new ();
1651 priv->default_window_height = -1;
1652 priv->contacts_width = -1;
1653 priv->vscroll_visible = FALSE;
1654 priv->sent_messages = NULL;
1655 priv->sent_messages_index = -1;
1656 priv->mc = empathy_mission_control_new ();
1658 priv->token = empathy_connect_to_account_status_changed (priv->mc,
1659 G_CALLBACK (chat_status_changed_cb),
1662 /* Block events for some time to avoid having "has come online" or
1663 * "joined" messages. */
1664 priv->block_events_timeout_id =
1665 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
1667 /* Add nick name completion */
1668 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
1669 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
1673 empathy_chat_new (EmpathyTpChat *tp_chat)
1675 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
1679 empathy_chat_get_tp_chat (EmpathyChat *chat)
1681 EmpathyChatPriv *priv = GET_PRIV (chat);
1683 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1685 return priv->tp_chat;
1689 empathy_chat_set_tp_chat (EmpathyChat *chat,
1690 EmpathyTpChat *tp_chat)
1692 EmpathyChatPriv *priv = GET_PRIV (chat);
1694 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1695 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
1696 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
1698 if (priv->tp_chat) {
1702 if (priv->account) {
1703 g_object_unref (priv->account);
1706 priv->tp_chat = g_object_ref (tp_chat);
1707 priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
1709 g_signal_connect (tp_chat, "message-received",
1710 G_CALLBACK (chat_message_received_cb),
1712 g_signal_connect (tp_chat, "send-error",
1713 G_CALLBACK (chat_send_error_cb),
1715 g_signal_connect (tp_chat, "chat-state-changed",
1716 G_CALLBACK (chat_state_changed_cb),
1718 g_signal_connect (tp_chat, "property-changed",
1719 G_CALLBACK (chat_property_changed_cb),
1721 g_signal_connect (tp_chat, "members-changed",
1722 G_CALLBACK (chat_members_changed_cb),
1724 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
1725 G_CALLBACK (chat_remote_contact_changed_cb),
1727 g_signal_connect (tp_chat, "destroy",
1728 G_CALLBACK (chat_destroy_cb),
1731 chat_remote_contact_changed_cb (chat);
1733 if (chat->input_text_view) {
1734 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
1735 if (priv->block_events_timeout_id == 0) {
1736 empathy_chat_view_append_event (chat->view, _("Connected"));
1740 empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
1741 empathy_tp_chat_emit_pendings (priv->tp_chat);
1743 g_object_notify (G_OBJECT (chat), "tp-chat");
1744 g_object_notify (G_OBJECT (chat), "id");
1745 g_object_notify (G_OBJECT (chat), "account");
1749 empathy_chat_get_account (EmpathyChat *chat)
1751 EmpathyChatPriv *priv = GET_PRIV (chat);
1753 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1755 return priv->account;
1759 empathy_chat_get_id (EmpathyChat *chat)
1761 EmpathyChatPriv *priv = GET_PRIV (chat);
1763 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1769 empathy_chat_get_name (EmpathyChat *chat)
1771 EmpathyChatPriv *priv = GET_PRIV (chat);
1773 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1779 empathy_chat_get_subject (EmpathyChat *chat)
1781 EmpathyChatPriv *priv = GET_PRIV (chat);
1783 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1785 return priv->subject;
1789 empathy_chat_get_remote_contact (EmpathyChat *chat)
1791 EmpathyChatPriv *priv = GET_PRIV (chat);
1793 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1795 return priv->remote_contact;
1799 empathy_chat_get_members_count (EmpathyChat *chat)
1801 EmpathyChatPriv *priv = GET_PRIV (chat);
1803 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
1805 if (priv->tp_chat) {
1806 return empathy_tp_chat_get_members_count (priv->tp_chat);
1813 empathy_chat_clear (EmpathyChat *chat)
1815 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1817 empathy_chat_view_clear (chat->view);
1821 empathy_chat_scroll_down (EmpathyChat *chat)
1823 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1825 empathy_chat_view_scroll_down (chat->view);
1829 empathy_chat_cut (EmpathyChat *chat)
1831 GtkTextBuffer *buffer;
1833 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1835 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1836 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1837 GtkClipboard *clipboard;
1839 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1841 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1846 empathy_chat_copy (EmpathyChat *chat)
1848 GtkTextBuffer *buffer;
1850 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1852 if (empathy_chat_view_get_selection_bounds (chat->view, NULL, NULL)) {
1853 empathy_chat_view_copy_clipboard (chat->view);
1857 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1858 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1859 GtkClipboard *clipboard;
1861 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1863 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1868 empathy_chat_paste (EmpathyChat *chat)
1870 GtkTextBuffer *buffer;
1871 GtkClipboard *clipboard;
1873 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1875 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1876 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1878 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1882 empathy_chat_correct_word (EmpathyChat *chat,
1885 const gchar *new_word)
1887 GtkTextBuffer *buffer;
1889 g_return_if_fail (chat != NULL);
1890 g_return_if_fail (new_word != NULL);
1892 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1894 gtk_text_buffer_delete (buffer, &start, &end);
1895 gtk_text_buffer_insert (buffer, &start,