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 EmpathyContactListView *view;
93 EmpathyContactListStore *store;
95 /* Used to automatically shrink a window that has temporarily
96 * grown due to long input.
99 gint default_window_height;
100 gint last_input_height;
101 gboolean vscroll_visible;
102 gboolean is_first_char;
105 static void empathy_chat_class_init (EmpathyChatClass *klass);
106 static void empathy_chat_init (EmpathyChat *chat);
124 static guint signals[LAST_SIGNAL] = { 0 };
126 G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
129 chat_get_property (GObject *object,
134 EmpathyChatPriv *priv = GET_PRIV (object);
138 g_value_set_object (value, priv->tp_chat);
141 g_value_set_object (value, priv->account);
144 g_value_set_string (value, priv->name);
147 g_value_set_string (value, priv->id);
150 g_value_set_string (value, priv->subject);
152 case PROP_REMOTE_CONTACT:
153 g_value_set_object (value, priv->remote_contact);
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
162 chat_set_property (GObject *object,
167 EmpathyChat *chat = EMPATHY_CHAT (object);
171 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
174 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
180 chat_status_changed_cb (MissionControl *mc,
181 TpConnectionStatus status,
183 TpConnectionStatusReason reason,
184 const gchar *unique_name,
187 EmpathyChatPriv *priv = GET_PRIV (chat);
190 account = mc_account_lookup (unique_name);
192 if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
193 empathy_account_equal (account, priv->account) &&
194 priv->handle_type != 0) {
195 empathy_debug (DEBUG_DOMAIN,
196 "Account reconnected, request a new Text channel");
197 mission_control_request_channel_with_string_handle (mc,
199 TP_IFACE_CHANNEL_TYPE_TEXT,
205 g_object_unref (account);
209 chat_composing_remove_timeout (EmpathyChat *chat)
211 EmpathyChatPriv *priv;
213 priv = GET_PRIV (chat);
215 if (priv->composing_stop_timeout_id) {
216 g_source_remove (priv->composing_stop_timeout_id);
217 priv->composing_stop_timeout_id = 0;
222 chat_composing_stop_timeout_cb (EmpathyChat *chat)
224 EmpathyChatPriv *priv;
226 priv = GET_PRIV (chat);
228 priv->composing_stop_timeout_id = 0;
229 empathy_tp_chat_set_state (priv->tp_chat,
230 TP_CHANNEL_CHAT_STATE_PAUSED);
236 chat_composing_start (EmpathyChat *chat)
238 EmpathyChatPriv *priv;
240 priv = GET_PRIV (chat);
242 if (priv->composing_stop_timeout_id) {
243 /* Just restart the timeout */
244 chat_composing_remove_timeout (chat);
246 empathy_tp_chat_set_state (priv->tp_chat,
247 TP_CHANNEL_CHAT_STATE_COMPOSING);
250 priv->composing_stop_timeout_id = g_timeout_add_seconds (
251 COMPOSING_STOP_TIMEOUT,
252 (GSourceFunc) chat_composing_stop_timeout_cb,
257 chat_composing_stop (EmpathyChat *chat)
259 EmpathyChatPriv *priv;
261 priv = GET_PRIV (chat);
263 chat_composing_remove_timeout (chat);
264 empathy_tp_chat_set_state (priv->tp_chat,
265 TP_CHANNEL_CHAT_STATE_ACTIVE);
269 chat_destroy_cb (EmpathyTpChat *tp_chat,
272 EmpathyChatPriv *priv;
274 priv = GET_PRIV (chat);
277 g_object_unref (priv->tp_chat);
278 priv->tp_chat = NULL;
279 g_object_notify (G_OBJECT (chat), "tp-chat");
282 empathy_chat_view_append_event (chat->view, _("Disconnected"));
283 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
287 chat_sent_message_add (EmpathyChat *chat,
290 EmpathyChatPriv *priv;
294 priv = GET_PRIV (chat);
296 /* Save the sent message in our repeat buffer */
297 list = priv->sent_messages;
299 /* Remove any other occurances of this msg */
300 while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) {
301 list = g_slist_remove_link (list, item);
303 g_slist_free1 (item);
306 /* Trim the list to the last 10 items */
307 while (g_slist_length (list) > 10) {
308 item = g_slist_last (list);
310 list = g_slist_remove_link (list, item);
312 g_slist_free1 (item);
316 /* Add new message */
317 list = g_slist_prepend (list, g_strdup (str));
319 /* Set list and reset the index */
320 priv->sent_messages = list;
321 priv->sent_messages_index = -1;
325 chat_sent_message_get_next (EmpathyChat *chat)
327 EmpathyChatPriv *priv;
330 priv = GET_PRIV (chat);
332 if (!priv->sent_messages) {
333 empathy_debug (DEBUG_DOMAIN,
334 "No sent messages, next message is NULL");
338 max = g_slist_length (priv->sent_messages) - 1;
340 if (priv->sent_messages_index < max) {
341 priv->sent_messages_index++;
344 empathy_debug (DEBUG_DOMAIN,
345 "Returning next message index:%d",
346 priv->sent_messages_index);
348 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
352 chat_sent_message_get_last (EmpathyChat *chat)
354 EmpathyChatPriv *priv;
356 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
358 priv = GET_PRIV (chat);
360 if (!priv->sent_messages) {
361 empathy_debug (DEBUG_DOMAIN,
362 "No sent messages, last message is NULL");
366 if (priv->sent_messages_index >= 0) {
367 priv->sent_messages_index--;
370 empathy_debug (DEBUG_DOMAIN,
371 "Returning last message index:%d",
372 priv->sent_messages_index);
374 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
378 chat_send (EmpathyChat *chat,
381 EmpathyChatPriv *priv;
382 EmpathyMessage *message;
384 priv = GET_PRIV (chat);
386 if (G_STR_EMPTY (msg)) {
390 chat_sent_message_add (chat, msg);
392 if (g_str_has_prefix (msg, "/clear")) {
393 empathy_chat_view_clear (chat->view);
397 message = empathy_message_new (msg);
399 empathy_tp_chat_send (priv->tp_chat, message);
401 g_object_unref (message);
405 chat_input_text_view_send (EmpathyChat *chat)
407 EmpathyChatPriv *priv;
408 GtkTextBuffer *buffer;
409 GtkTextIter start, end;
412 priv = GET_PRIV (chat);
414 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
416 gtk_text_buffer_get_bounds (buffer, &start, &end);
417 msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
419 /* clear the input field */
420 gtk_text_buffer_set_text (buffer, "", -1);
422 chat_send (chat, msg);
425 priv->is_first_char = TRUE;
429 chat_state_changed_cb (EmpathyTpChat *tp_chat,
430 EmpathyContact *contact,
431 TpChannelChatState state,
434 EmpathyChatPriv *priv;
436 gboolean was_composing;
438 priv = GET_PRIV (chat);
440 if (empathy_contact_is_user (contact)) {
441 /* We don't care about our own chat state */
445 was_composing = (priv->compositors != NULL);
447 /* Find the contact in the list. After that l is the list elem or NULL */
448 for (l = priv->compositors; l; l = l->next) {
449 if (contact == l->data) {
455 case TP_CHANNEL_CHAT_STATE_GONE:
456 case TP_CHANNEL_CHAT_STATE_INACTIVE:
457 case TP_CHANNEL_CHAT_STATE_PAUSED:
458 case TP_CHANNEL_CHAT_STATE_ACTIVE:
459 /* Contact is not composing */
461 priv->compositors = g_list_remove_link (priv->compositors, l);
462 g_object_unref (l->data);
466 case TP_CHANNEL_CHAT_STATE_COMPOSING:
467 /* Contact is composing */
469 priv->compositors = g_list_prepend (priv->compositors,
470 g_object_ref (contact));
474 g_assert_not_reached ();
477 empathy_debug (DEBUG_DOMAIN, "Was composing: %s now composing: %s",
478 was_composing ? "yes" : "no",
479 priv->compositors ? "yes" : "no");
481 if ((was_composing && !priv->compositors) ||
482 (!was_composing && priv->compositors)) {
483 /* Composing state changed */
484 g_signal_emit (chat, signals[COMPOSING], 0,
485 priv->compositors != NULL);
490 chat_message_received_cb (EmpathyTpChat *tp_chat,
491 EmpathyMessage *message,
494 EmpathyChatPriv *priv;
495 EmpathyContact *sender;
498 priv = GET_PRIV (chat);
500 sender = empathy_message_get_sender (message);
501 body = empathy_message_get_body (message);
502 while (priv->backlog_messages) {
503 EmpathyMessage *log_message;
504 EmpathyContact *log_sender;
505 const gchar *log_body;
507 log_message = priv->backlog_messages->data;
508 log_sender = empathy_message_get_sender (log_message);
509 log_body = empathy_message_get_body (log_message);
511 priv->backlog_messages = g_list_remove (priv->backlog_messages,
514 if (empathy_contact_equal (sender, log_sender) &&
515 !tp_strdiff (body, log_body)) {
516 /* The message we received is already displayed because
517 * some jabber chatrooms sends us back logs and we
518 * already displayed it from localy logged messages. */
519 empathy_debug (DEBUG_DOMAIN, "Skipping message because "
520 "it is already displayed from logged "
522 g_object_unref (log_message);
525 g_object_unref (log_message);
528 empathy_debug (DEBUG_DOMAIN, "Appending new message from %s (%d)",
529 empathy_contact_get_name (sender),
530 empathy_contact_get_handle (sender));
532 empathy_log_manager_add_message (priv->log_manager,
533 empathy_chat_get_id (chat),
537 empathy_chat_view_append_message (chat->view, message);
539 /* We received a message so the contact is no more composing */
540 chat_state_changed_cb (tp_chat, sender,
541 TP_CHANNEL_CHAT_STATE_ACTIVE,
544 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
548 chat_send_error_cb (EmpathyTpChat *tp_chat,
549 EmpathyMessage *message,
550 TpChannelTextSendError error_code,
556 switch (error_code) {
557 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
558 error = _("offline");
560 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
561 error = _("invalid contact");
563 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
564 error = _("permission denied");
566 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
567 error = _("too long message");
569 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
570 error = _("not implemented");
573 error = _("unknown");
577 str = g_strdup_printf (_("Error sending message '%s': %s"),
578 empathy_message_get_body (message),
580 empathy_chat_view_append_event (chat->view, str);
585 chat_property_changed_cb (EmpathyTpChat *tp_chat,
590 EmpathyChatPriv *priv = GET_PRIV (chat);
592 if (!tp_strdiff (name, "subject")) {
593 g_free (priv->subject);
594 priv->subject = g_value_dup_string (value);
595 g_object_notify (G_OBJECT (chat), "subject");
597 if (G_STR_EMPTY (priv->subject)) {
598 gtk_widget_hide (priv->hbox_topic);
600 gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
601 gtk_widget_show (priv->hbox_topic);
603 if (priv->block_events_timeout_id == 0) {
606 if (!G_STR_EMPTY (priv->subject)) {
607 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
609 str = g_strdup (_("No topic defined"));
611 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
615 else if (!tp_strdiff (name, "name")) {
617 priv->name = g_value_dup_string (value);
618 g_object_notify (G_OBJECT (chat), "name");
623 chat_get_is_command (const gchar *str)
625 g_return_val_if_fail (str != NULL, FALSE);
631 if (g_str_has_prefix (str, "/me")) {
634 else if (g_str_has_prefix (str, "/nick")) {
637 else if (g_str_has_prefix (str, "/topic")) {
645 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
648 EmpathyChatPriv *priv;
649 GtkTextIter start, end;
651 gboolean spell_checker = FALSE;
653 priv = GET_PRIV (chat);
655 if (gtk_text_buffer_get_char_count (buffer) == 0) {
656 chat_composing_stop (chat);
658 chat_composing_start (chat);
661 empathy_conf_get_bool (empathy_conf_get (),
662 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
665 if (priv->is_first_char) {
669 GtkAllocation *allocation;
671 /* Save the window's size */
672 dialog = empathy_get_toplevel_window (GTK_WIDGET (chat));
674 gtk_window_get_size (GTK_WINDOW (dialog), NULL, &window_height);
675 gtk_widget_size_request (chat->input_text_view, &req);
676 allocation = >K_WIDGET (chat->view)->allocation;
678 priv->default_window_height = window_height;
679 priv->last_input_height = req.height;
680 priv->padding_height = window_height - req.height - allocation->height;
683 priv->is_first_char = FALSE;
686 gtk_text_buffer_get_start_iter (buffer, &start);
688 if (!spell_checker) {
689 gtk_text_buffer_get_end_iter (buffer, &end);
690 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
694 if (!empathy_spell_supported ()) {
698 /* NOTE: this is really inefficient, we shouldn't have to
699 reiterate the whole buffer each time and check each work
702 gboolean correct = FALSE;
705 if (gtk_text_iter_is_start (&start)) {
708 if (!gtk_text_iter_forward_word_end (&end)) {
709 /* no whole word yet */
713 if (!gtk_text_iter_forward_word_end (&end)) {
714 /* must be the end of the buffer */
719 gtk_text_iter_backward_word_start (&start);
722 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
724 /* spell check string */
725 if (!chat_get_is_command (str)) {
726 correct = empathy_spell_check (str);
732 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
734 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
739 /* set start iter to the end iters position */
745 chat_input_key_press_event_cb (GtkWidget *widget,
749 EmpathyChatPriv *priv;
752 GtkWidget *text_view_sw;
754 priv = GET_PRIV (chat);
756 /* Catch ctrl+up/down so we can traverse messages we sent */
757 if ((event->state & GDK_CONTROL_MASK) &&
758 (event->keyval == GDK_Up ||
759 event->keyval == GDK_Down)) {
760 GtkTextBuffer *buffer;
763 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
765 if (event->keyval == GDK_Up) {
766 str = chat_sent_message_get_next (chat);
768 str = chat_sent_message_get_last (chat);
771 g_signal_handlers_block_by_func (buffer,
772 chat_input_text_buffer_changed_cb,
774 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
775 g_signal_handlers_unblock_by_func (buffer,
776 chat_input_text_buffer_changed_cb,
782 /* Catch enter but not ctrl/shift-enter */
783 if (IS_ENTER (event->keyval) &&
784 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
787 /* This is to make sure that kinput2 gets the enter. And if
788 * it's handled there we shouldn't send on it. This is because
789 * kinput2 uses Enter to commit letters. See:
790 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
793 view = GTK_TEXT_VIEW (chat->input_text_view);
794 if (gtk_im_context_filter_keypress (view->im_context, event)) {
795 GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
799 chat_input_text_view_send (chat);
803 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
805 if (IS_ENTER (event->keyval) &&
806 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
807 /* Newline for shift/control-enter. */
810 if (!(event->state & GDK_CONTROL_MASK) &&
811 event->keyval == GDK_Page_Up) {
812 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
813 gtk_adjustment_set_value (adj, adj->value - adj->page_size);
816 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
817 event->keyval == GDK_Page_Down) {
818 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
819 val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
820 gtk_adjustment_set_value (adj, val);
823 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
824 event->keyval == GDK_Tab) {
825 GtkTextBuffer *buffer;
826 GtkTextIter start, current;
827 gchar *nick, *completed;
828 GList *list, *completed_list;
829 gboolean is_start_of_buffer;
831 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
832 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
834 /* Get the start of the nick to complete. */
835 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
836 gtk_text_iter_backward_word_start (&start);
837 is_start_of_buffer = gtk_text_iter_is_start (&start);
839 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
840 g_completion_add_items (priv->completion, list);
842 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
843 completed_list = g_completion_complete (priv->completion,
852 gchar *complete_char = NULL;
854 gtk_text_buffer_delete (buffer, &start, ¤t);
856 len = g_list_length (completed_list);
859 /* If we only have one hit, use that text
860 * instead of the text in completed since the
861 * completed text will use the typed string
862 * which might be cased all wrong.
865 text = empathy_contact_get_name (completed_list->data);
870 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
872 if (len == 1 && is_start_of_buffer &&
873 empathy_conf_get_string (empathy_conf_get (),
874 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
876 complete_char != NULL) {
877 gtk_text_buffer_insert_at_cursor (buffer,
879 strlen (complete_char));
880 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
881 g_free (complete_char);
887 g_completion_clear_items (priv->completion);
889 g_list_foreach (list, (GFunc) g_object_unref, NULL);
899 chat_text_view_focus_in_event_cb (GtkWidget *widget,
903 gtk_widget_grab_focus (chat->input_text_view);
915 chat_change_size_in_idle_cb (ChangeSizeData *data)
917 gtk_window_resize (data->window, data->width, data->height);
923 chat_text_view_scroll_hide_cb (GtkWidget *widget,
926 EmpathyChatPriv *priv;
929 priv = GET_PRIV (chat);
931 priv->vscroll_visible = FALSE;
932 g_signal_handlers_disconnect_by_func (widget,
933 chat_text_view_scroll_hide_cb,
936 sw = gtk_widget_get_parent (chat->input_text_view);
937 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
940 g_object_set (sw, "height-request", -1, NULL);
944 chat_text_view_size_allocate_cb (GtkWidget *widget,
945 GtkAllocation *allocation,
948 EmpathyChatPriv *priv;
951 ChangeSizeData *data;
954 GtkAllocation *view_allocation;
959 priv = GET_PRIV (chat);
961 if (priv->default_window_height <= 0) {
965 sw = gtk_widget_get_parent (widget);
966 if (sw->allocation.height >= MAX_INPUT_HEIGHT && !priv->vscroll_visible) {
969 priv->vscroll_visible = TRUE;
970 gtk_widget_set_size_request (sw, sw->allocation.width, MAX_INPUT_HEIGHT);
971 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
973 GTK_POLICY_AUTOMATIC);
974 vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (sw));
975 g_signal_connect (vscroll, "hide",
976 G_CALLBACK (chat_text_view_scroll_hide_cb),
980 if (priv->last_input_height <= allocation->height) {
981 priv->last_input_height = allocation->height;
985 diff = priv->last_input_height - allocation->height;
986 priv->last_input_height = allocation->height;
988 view_allocation = >K_WIDGET (chat->view)->allocation;
990 dialog = empathy_get_toplevel_window (GTK_WIDGET (widget));
991 gtk_window_get_size (dialog, NULL, ¤t_height);
993 new_height = view_allocation->height + priv->padding_height + allocation->height - diff;
995 if (new_height <= priv->default_window_height) {
996 window_height = priv->default_window_height;
998 window_height = new_height;
1001 if (current_height <= window_height) {
1005 /* Restore the window's size */
1006 gtk_window_get_size (dialog, &width, NULL);
1008 data = g_new0 (ChangeSizeData, 1);
1009 data->window = dialog;
1010 data->width = width;
1011 data->height = window_height;
1013 g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
1014 (GSourceFunc) chat_change_size_in_idle_cb,
1019 chat_text_view_realize_cb (GtkWidget *widget,
1022 empathy_debug (DEBUG_DOMAIN, "Setting focus to the input text view");
1023 gtk_widget_grab_focus (widget);
1027 chat_insert_smiley_activate_cb (GtkWidget *menuitem,
1030 GtkTextBuffer *buffer;
1032 const gchar *smiley;
1034 smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
1036 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1038 gtk_text_buffer_get_end_iter (buffer, &iter);
1039 gtk_text_buffer_insert (buffer, &iter, smiley, -1);
1041 gtk_text_buffer_get_end_iter (buffer, &iter);
1042 gtk_text_buffer_insert (buffer, &iter, " ", -1);
1053 static EmpathyChatSpell *
1054 chat_spell_new (EmpathyChat *chat,
1059 EmpathyChatSpell *chat_spell;
1061 chat_spell = g_slice_new0 (EmpathyChatSpell);
1063 chat_spell->chat = g_object_ref (chat);
1064 chat_spell->word = g_strdup (word);
1065 chat_spell->start = start;
1066 chat_spell->end = end;
1072 chat_spell_free (EmpathyChatSpell *chat_spell)
1074 g_object_unref (chat_spell->chat);
1075 g_free (chat_spell->word);
1076 g_slice_free (EmpathyChatSpell, chat_spell);
1080 chat_text_check_word_spelling_cb (GtkMenuItem *menuitem,
1081 EmpathyChatSpell *chat_spell)
1083 empathy_spell_dialog_show (chat_spell->chat,
1090 chat_text_populate_popup_cb (GtkTextView *view,
1094 EmpathyChatPriv *priv;
1095 GtkTextBuffer *buffer;
1096 GtkTextTagTable *table;
1099 GtkTextIter iter, start, end;
1102 EmpathyChatSpell *chat_spell;
1103 GtkWidget *smiley_menu;
1105 priv = GET_PRIV (chat);
1107 /* Add the emoticon menu. */
1108 item = gtk_separator_menu_item_new ();
1109 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1110 gtk_widget_show (item);
1112 item = gtk_menu_item_new_with_mnemonic (_("Insert Smiley"));
1113 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1114 gtk_widget_show (item);
1116 smiley_menu = empathy_chat_view_get_smiley_menu (
1117 G_CALLBACK (chat_insert_smiley_activate_cb),
1119 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
1121 /* Add the spell check menu item. */
1122 buffer = gtk_text_view_get_buffer (view);
1123 table = gtk_text_buffer_get_tag_table (buffer);
1125 tag = gtk_text_tag_table_lookup (table, "misspelled");
1127 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
1129 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
1130 GTK_TEXT_WINDOW_WIDGET,
1134 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
1138 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
1139 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1141 str = gtk_text_buffer_get_text (buffer,
1142 &start, &end, FALSE);
1145 if (G_STR_EMPTY (str)) {
1149 chat_spell = chat_spell_new (chat, str, start, end);
1151 g_object_set_data_full (G_OBJECT (menu),
1152 "chat_spell", chat_spell,
1153 (GDestroyNotify) chat_spell_free);
1155 item = gtk_separator_menu_item_new ();
1156 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1157 gtk_widget_show (item);
1159 item = gtk_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
1160 g_signal_connect (item,
1162 G_CALLBACK (chat_text_check_word_spelling_cb),
1164 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1165 gtk_widget_show (item);
1169 chat_add_logs (EmpathyChat *chat)
1171 EmpathyChatPriv *priv;
1172 GList *messages, *l;
1176 priv = GET_PRIV (chat);
1178 /* Turn off scrolling temporarily */
1179 empathy_chat_view_scroll (chat->view, FALSE);
1181 /* Add messages from last conversation */
1182 messages = empathy_log_manager_get_last_messages (priv->log_manager,
1184 empathy_chat_get_id (chat),
1186 num_messages = g_list_length (messages);
1188 /* Only keep the 10 last messages */
1189 for (i = 0; num_messages - i > 10; i++) {
1190 EmpathyMessage *message;
1192 message = messages->data;
1193 messages = g_list_remove (messages, message);
1194 g_object_unref (message);
1197 for (l = messages; l; l = l->next) {
1198 empathy_chat_view_append_message (chat->view, l->data);
1200 priv->backlog_messages = messages;
1202 /* Turn back on scrolling */
1203 empathy_chat_view_scroll (chat->view, TRUE);
1207 chat_contacts_completion_func (const gchar *s1,
1211 gchar *tmp, *nick1, *nick2;
1218 return s1 ? -1 : +1;
1221 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
1222 nick1 = g_utf8_casefold (tmp, -1);
1225 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
1226 nick2 = g_utf8_casefold (tmp, -1);
1229 ret = strncmp (nick1, nick2, n);
1238 chat_members_changed_cb (EmpathyTpChat *tp_chat,
1239 EmpathyContact *contact,
1240 EmpathyContact *actor,
1246 EmpathyChatPriv *priv = GET_PRIV (chat);
1248 if (priv->block_events_timeout_id == 0) {
1251 empathy_contact_run_until_ready (contact,
1252 EMPATHY_CONTACT_READY_NAME,
1256 str = g_strdup_printf (_("%s has joined the room"),
1257 empathy_contact_get_name (contact));
1259 str = g_strdup_printf (_("%s has left the room"),
1260 empathy_contact_get_name (contact));
1262 empathy_chat_view_append_event (chat->view, str);
1268 chat_reset_size_request (gpointer widget)
1270 gtk_widget_set_size_request (widget, -1, -1);
1276 chat_set_show_contacts (EmpathyChat *chat, gboolean show)
1278 EmpathyChatPriv *priv = GET_PRIV (chat);
1280 if (!priv->scrolled_window_contacts ||
1281 GTK_WIDGET_VISIBLE (priv->scrolled_window_contacts) == show) {
1286 if (priv->contacts_width <= 0) {
1287 /* It's the first time we show the contact list, make
1288 * sure the chat view don't get resized. Relax the
1289 * size request once it's done. */
1290 gtk_widget_set_size_request (priv->vbox_left,
1291 priv->vbox_left->allocation.width,
1293 g_idle_add (chat_reset_size_request, priv->vbox_left);
1295 gtk_paned_set_position (GTK_PANED (priv->hpaned),
1296 priv->contacts_width);
1298 gtk_widget_show (priv->scrolled_window_contacts);
1300 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
1301 gtk_widget_hide (priv->scrolled_window_contacts);
1306 chat_remote_contact_changed_cb (EmpathyChat *chat)
1308 EmpathyChatPriv *priv = GET_PRIV (chat);
1310 if (priv->remote_contact) {
1311 g_object_unref (priv->remote_contact);
1312 priv->remote_contact = NULL;
1315 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
1316 if (priv->remote_contact) {
1317 g_object_ref (priv->remote_contact);
1320 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1322 g_object_notify (G_OBJECT (chat), "remote-contact");
1326 chat_create_ui (EmpathyChat *chat)
1328 EmpathyChatPriv *priv = GET_PRIV (chat);
1332 GtkTextBuffer *buffer;
1334 filename = empathy_file_lookup ("empathy-chat.glade",
1336 glade = empathy_glade_get_file (filename,
1339 "chat_widget", &priv->widget,
1340 "hpaned", &priv->hpaned,
1341 "vbox_left", &priv->vbox_left,
1342 "scrolled_window_chat", &priv->scrolled_window_chat,
1343 "scrolled_window_input", &priv->scrolled_window_input,
1344 "hbox_topic", &priv->hbox_topic,
1345 "label_topic", &priv->label_topic,
1346 "scrolled_window_contacts", &priv->scrolled_window_contacts,
1349 g_object_unref (glade);
1351 /* Add message GtkTextView. */
1352 chat->view = empathy_chat_view_new ();
1353 g_signal_connect (chat->view, "focus_in_event",
1354 G_CALLBACK (chat_text_view_focus_in_event_cb),
1356 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
1357 GTK_WIDGET (chat->view));
1358 gtk_widget_show (GTK_WIDGET (chat->view));
1360 /* Add input GtkTextView */
1361 chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
1362 "pixels-above-lines", 2,
1363 "pixels-below-lines", 2,
1364 "pixels-inside-wrap", 1,
1367 "wrap-mode", GTK_WRAP_WORD_CHAR,
1369 g_signal_connect (chat->input_text_view, "key_press_event",
1370 G_CALLBACK (chat_input_key_press_event_cb),
1372 g_signal_connect (chat->input_text_view, "size_allocate",
1373 G_CALLBACK (chat_text_view_size_allocate_cb),
1375 g_signal_connect (chat->input_text_view, "realize",
1376 G_CALLBACK (chat_text_view_realize_cb),
1378 g_signal_connect (chat->input_text_view, "populate_popup",
1379 G_CALLBACK (chat_text_populate_popup_cb),
1381 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1382 g_signal_connect (buffer, "changed",
1383 G_CALLBACK (chat_input_text_buffer_changed_cb),
1385 gtk_text_buffer_create_tag (buffer, "misspelled",
1386 "underline", PANGO_UNDERLINE_ERROR,
1388 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
1389 chat->input_text_view);
1390 gtk_widget_show (chat->input_text_view);
1392 /* Create contact list */
1393 priv->store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
1394 priv->view = empathy_contact_list_view_new (priv->store,
1395 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT |
1396 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL |
1397 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG |
1398 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT |
1399 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE |
1400 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO);
1401 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
1402 GTK_WIDGET (priv->view));
1403 gtk_widget_show (GTK_WIDGET (priv->view));
1404 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1406 /* Initialy hide the topic, will be shown if not empty */
1407 gtk_widget_hide (priv->hbox_topic);
1409 /* Set widget focus order */
1410 list = g_list_append (NULL, priv->scrolled_window_input);
1411 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
1414 list = g_list_append (NULL, priv->vbox_left);
1415 list = g_list_append (list, priv->scrolled_window_contacts);
1416 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
1419 list = g_list_append (NULL, priv->hpaned);
1420 list = g_list_append (list, priv->hbox_topic);
1421 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
1424 /* Add the main widget in the chat widget */
1425 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
1429 chat_size_request (GtkWidget *widget,
1430 GtkRequisition *requisition)
1432 GtkBin *bin = GTK_BIN (widget);
1434 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
1435 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
1437 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1439 GtkRequisition child_requisition;
1441 gtk_widget_size_request (bin->child, &child_requisition);
1443 requisition->width += child_requisition.width;
1444 requisition->height += child_requisition.height;
1449 chat_size_allocate (GtkWidget *widget,
1450 GtkAllocation *allocation)
1452 GtkBin *bin = GTK_BIN (widget);
1453 GtkAllocation child_allocation;
1455 widget->allocation = *allocation;
1457 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1459 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1460 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
1461 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
1462 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
1464 gtk_widget_size_allocate (bin->child, &child_allocation);
1469 chat_finalize (GObject *object)
1472 EmpathyChatPriv *priv;
1474 chat = EMPATHY_CHAT (object);
1475 priv = GET_PRIV (chat);
1477 empathy_debug (DEBUG_DOMAIN, "Finalized: %p", object);
1479 g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
1480 g_slist_free (priv->sent_messages);
1482 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
1483 g_list_free (priv->compositors);
1485 g_list_foreach (priv->backlog_messages, (GFunc) g_object_unref, NULL);
1486 g_list_free (priv->backlog_messages);
1488 chat_composing_remove_timeout (chat);
1490 empathy_disconnect_account_status_changed (priv->token);
1491 g_object_unref (priv->mc);
1492 g_object_unref (priv->log_manager);
1493 g_object_unref (priv->store);
1495 if (priv->tp_chat) {
1496 g_object_unref (priv->tp_chat);
1498 if (priv->account) {
1499 g_object_unref (priv->account);
1501 if (priv->remote_contact) {
1502 g_object_unref (priv->remote_contact);
1505 if (priv->block_events_timeout_id) {
1506 g_source_remove (priv->block_events_timeout_id);
1510 g_free (priv->name);
1511 g_free (priv->subject);
1513 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
1517 chat_constructed (GObject *object)
1519 EmpathyChat *chat = EMPATHY_CHAT (object);
1521 chat_create_ui (chat);
1522 chat_add_logs (chat);
1526 empathy_chat_class_init (EmpathyChatClass *klass)
1528 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1529 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1531 object_class->finalize = chat_finalize;
1532 object_class->get_property = chat_get_property;
1533 object_class->set_property = chat_set_property;
1534 object_class->constructed = chat_constructed;
1536 widget_class->size_request = chat_size_request;
1537 widget_class->size_allocate = chat_size_allocate;
1539 g_object_class_install_property (object_class,
1541 g_param_spec_object ("tp-chat",
1543 "The tp chat object",
1544 EMPATHY_TYPE_TP_CHAT,
1546 G_PARAM_READWRITE));
1547 g_object_class_install_property (object_class,
1549 g_param_spec_object ("account",
1550 "Account of the chat",
1551 "The account of the chat",
1554 g_object_class_install_property (object_class,
1556 g_param_spec_string ("id",
1558 "The id of the chat",
1561 g_object_class_install_property (object_class,
1563 g_param_spec_string ("name",
1565 "The name of the chat",
1568 g_object_class_install_property (object_class,
1570 g_param_spec_string ("subject",
1572 "The subject or topic of the chat",
1575 g_object_class_install_property (object_class,
1576 PROP_REMOTE_CONTACT,
1577 g_param_spec_object ("remote-contact",
1578 "The remote contact",
1579 "The remote contact is any",
1580 EMPATHY_TYPE_CONTACT,
1583 signals[COMPOSING] =
1584 g_signal_new ("composing",
1585 G_OBJECT_CLASS_TYPE (object_class),
1589 g_cclosure_marshal_VOID__BOOLEAN,
1593 signals[NEW_MESSAGE] =
1594 g_signal_new ("new-message",
1595 G_OBJECT_CLASS_TYPE (object_class),
1599 g_cclosure_marshal_VOID__OBJECT,
1601 1, EMPATHY_TYPE_MESSAGE);
1603 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
1607 chat_block_events_timeout_cb (gpointer data)
1609 EmpathyChatPriv *priv = GET_PRIV (data);
1611 priv->block_events_timeout_id = 0;
1617 empathy_chat_init (EmpathyChat *chat)
1619 EmpathyChatPriv *priv = GET_PRIV (chat);
1621 priv->is_first_char = TRUE;
1622 priv->log_manager = empathy_log_manager_new ();
1623 priv->default_window_height = -1;
1624 priv->contacts_width = -1;
1625 priv->vscroll_visible = FALSE;
1626 priv->sent_messages = NULL;
1627 priv->sent_messages_index = -1;
1628 priv->mc = empathy_mission_control_new ();
1630 priv->token = empathy_connect_to_account_status_changed (priv->mc,
1631 G_CALLBACK (chat_status_changed_cb),
1634 /* Block events for some time to avoid having "has come online" or
1635 * "joined" messages. */
1636 priv->block_events_timeout_id =
1637 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
1639 /* Add nick name completion */
1640 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
1641 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
1645 empathy_chat_new (EmpathyTpChat *tp_chat)
1647 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
1651 empathy_chat_get_tp_chat (EmpathyChat *chat)
1653 EmpathyChatPriv *priv = GET_PRIV (chat);
1655 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1657 return priv->tp_chat;
1661 empathy_chat_set_tp_chat (EmpathyChat *chat,
1662 EmpathyTpChat *tp_chat)
1664 EmpathyChatPriv *priv = GET_PRIV (chat);
1666 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1667 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
1668 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
1670 if (priv->tp_chat) {
1674 if (priv->account) {
1675 g_object_unref (priv->account);
1679 priv->tp_chat = g_object_ref (tp_chat);
1680 priv->id = g_strdup (empathy_tp_chat_get_id (tp_chat));
1681 priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
1683 g_signal_connect (tp_chat, "message-received",
1684 G_CALLBACK (chat_message_received_cb),
1686 g_signal_connect (tp_chat, "send-error",
1687 G_CALLBACK (chat_send_error_cb),
1689 g_signal_connect (tp_chat, "chat-state-changed",
1690 G_CALLBACK (chat_state_changed_cb),
1692 g_signal_connect (tp_chat, "property-changed",
1693 G_CALLBACK (chat_property_changed_cb),
1695 g_signal_connect (tp_chat, "members-changed",
1696 G_CALLBACK (chat_members_changed_cb),
1698 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
1699 G_CALLBACK (chat_remote_contact_changed_cb),
1701 g_signal_connect (tp_chat, "destroy",
1702 G_CALLBACK (chat_destroy_cb),
1705 chat_remote_contact_changed_cb (chat);
1707 if (chat->input_text_view) {
1708 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
1709 if (priv->block_events_timeout_id == 0) {
1710 empathy_chat_view_append_event (chat->view, _("Connected"));
1714 empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
1715 empathy_tp_chat_emit_pendings (priv->tp_chat);
1717 g_object_notify (G_OBJECT (chat), "tp-chat");
1718 g_object_notify (G_OBJECT (chat), "id");
1719 g_object_notify (G_OBJECT (chat), "account");
1723 empathy_chat_get_account (EmpathyChat *chat)
1725 EmpathyChatPriv *priv = GET_PRIV (chat);
1727 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1729 return priv->account;
1733 empathy_chat_get_id (EmpathyChat *chat)
1735 EmpathyChatPriv *priv = GET_PRIV (chat);
1737 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1743 empathy_chat_get_name (EmpathyChat *chat)
1745 EmpathyChatPriv *priv = GET_PRIV (chat);
1747 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1753 empathy_chat_get_subject (EmpathyChat *chat)
1755 EmpathyChatPriv *priv = GET_PRIV (chat);
1757 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1759 return priv->subject;
1763 empathy_chat_get_remote_contact (EmpathyChat *chat)
1765 EmpathyChatPriv *priv = GET_PRIV (chat);
1767 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1769 return priv->remote_contact;
1773 empathy_chat_get_members_count (EmpathyChat *chat)
1775 EmpathyChatPriv *priv = GET_PRIV (chat);
1777 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
1779 if (priv->tp_chat) {
1780 return empathy_tp_chat_get_members_count (priv->tp_chat);
1787 empathy_chat_clear (EmpathyChat *chat)
1789 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1791 empathy_chat_view_clear (chat->view);
1795 empathy_chat_scroll_down (EmpathyChat *chat)
1797 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1799 empathy_chat_view_scroll_down (chat->view);
1803 empathy_chat_cut (EmpathyChat *chat)
1805 GtkTextBuffer *buffer;
1807 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1809 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1810 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1811 GtkClipboard *clipboard;
1813 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1815 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1820 empathy_chat_copy (EmpathyChat *chat)
1822 GtkTextBuffer *buffer;
1824 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1826 if (empathy_chat_view_get_selection_bounds (chat->view, NULL, NULL)) {
1827 empathy_chat_view_copy_clipboard (chat->view);
1831 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1832 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1833 GtkClipboard *clipboard;
1835 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1837 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1842 empathy_chat_paste (EmpathyChat *chat)
1844 GtkTextBuffer *buffer;
1845 GtkClipboard *clipboard;
1847 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1849 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1850 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1852 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1856 empathy_chat_correct_word (EmpathyChat *chat,
1859 const gchar *new_word)
1861 GtkTextBuffer *buffer;
1863 g_return_if_fail (chat != NULL);
1864 g_return_if_fail (new_word != NULL);
1866 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1868 gtk_text_buffer_delete (buffer, &start, &end);
1869 gtk_text_buffer_insert (buffer, &start,