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-utils.h>
44 #include "empathy-chat.h"
45 #include "empathy-conf.h"
46 #include "empathy-spell.h"
47 #include "empathy-spell-dialog.h"
48 #include "empathy-contact-list-store.h"
49 #include "empathy-contact-list-view.h"
50 #include "empathy-contact-menu.h"
51 #include "empathy-ui-utils.h"
53 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
54 #include <libempathy/empathy-debug.h>
56 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CHAT, EmpathyChatPriv))
58 #define CHAT_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
59 #define CHAT_FILE_CREATE_MODE (S_IRUSR | S_IWUSR)
60 #define IS_ENTER(v) (v == GDK_Return || v == GDK_ISO_Enter || v == GDK_KP_Enter)
61 #define MAX_INPUT_HEIGHT 150
62 #define COMPOSING_STOP_TIMEOUT 5
64 struct _EmpathyChatPriv {
65 EmpathyTpChat *tp_chat;
70 EmpathyContact *remote_contact;
72 EmpathyLogManager *log_manager;
74 GSList *sent_messages;
75 gint sent_messages_index;
77 GList *backlog_messages;
78 GCompletion *completion;
79 guint composing_stop_timeout_id;
80 guint block_events_timeout_id;
81 TpHandleType handle_type;
84 gboolean has_input_vscroll;
89 GtkWidget *scrolled_window_chat;
90 GtkWidget *scrolled_window_input;
91 GtkWidget *scrolled_window_contacts;
92 GtkWidget *hbox_topic;
93 GtkWidget *label_topic;
94 GtkWidget *contact_list_view;
97 static void empathy_chat_class_init (EmpathyChatClass *klass);
98 static void empathy_chat_init (EmpathyChat *chat);
116 static guint signals[LAST_SIGNAL] = { 0 };
118 G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
121 chat_get_property (GObject *object,
126 EmpathyChatPriv *priv = GET_PRIV (object);
130 g_value_set_object (value, priv->tp_chat);
133 g_value_set_object (value, priv->account);
136 g_value_set_string (value, priv->name);
139 g_value_set_string (value, priv->id);
142 g_value_set_string (value, priv->subject);
144 case PROP_REMOTE_CONTACT:
145 g_value_set_object (value, priv->remote_contact);
148 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
154 chat_set_property (GObject *object,
159 EmpathyChat *chat = EMPATHY_CHAT (object);
163 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
166 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
172 chat_status_changed_cb (MissionControl *mc,
173 TpConnectionStatus status,
175 TpConnectionStatusReason reason,
176 const gchar *unique_name,
179 EmpathyChatPriv *priv = GET_PRIV (chat);
182 account = mc_account_lookup (unique_name);
184 if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
185 empathy_account_equal (account, priv->account) &&
186 priv->handle_type != TP_HANDLE_TYPE_NONE) {
187 DEBUG ("Account reconnected, request a new Text channel");
188 mission_control_request_channel_with_string_handle (mc,
190 TP_IFACE_CHANNEL_TYPE_TEXT,
196 g_object_unref (account);
200 chat_composing_remove_timeout (EmpathyChat *chat)
202 EmpathyChatPriv *priv;
204 priv = GET_PRIV (chat);
206 if (priv->composing_stop_timeout_id) {
207 g_source_remove (priv->composing_stop_timeout_id);
208 priv->composing_stop_timeout_id = 0;
213 chat_composing_stop_timeout_cb (EmpathyChat *chat)
215 EmpathyChatPriv *priv;
217 priv = GET_PRIV (chat);
219 priv->composing_stop_timeout_id = 0;
220 empathy_tp_chat_set_state (priv->tp_chat,
221 TP_CHANNEL_CHAT_STATE_PAUSED);
227 chat_composing_start (EmpathyChat *chat)
229 EmpathyChatPriv *priv;
231 priv = GET_PRIV (chat);
233 if (priv->composing_stop_timeout_id) {
234 /* Just restart the timeout */
235 chat_composing_remove_timeout (chat);
237 empathy_tp_chat_set_state (priv->tp_chat,
238 TP_CHANNEL_CHAT_STATE_COMPOSING);
241 priv->composing_stop_timeout_id = g_timeout_add_seconds (
242 COMPOSING_STOP_TIMEOUT,
243 (GSourceFunc) chat_composing_stop_timeout_cb,
248 chat_composing_stop (EmpathyChat *chat)
250 EmpathyChatPriv *priv;
252 priv = GET_PRIV (chat);
254 chat_composing_remove_timeout (chat);
255 empathy_tp_chat_set_state (priv->tp_chat,
256 TP_CHANNEL_CHAT_STATE_ACTIVE);
260 chat_sent_message_add (EmpathyChat *chat,
263 EmpathyChatPriv *priv;
267 priv = GET_PRIV (chat);
269 /* Save the sent message in our repeat buffer */
270 list = priv->sent_messages;
272 /* Remove any other occurances of this msg */
273 while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) {
274 list = g_slist_remove_link (list, item);
276 g_slist_free1 (item);
279 /* Trim the list to the last 10 items */
280 while (g_slist_length (list) > 10) {
281 item = g_slist_last (list);
283 list = g_slist_remove_link (list, item);
285 g_slist_free1 (item);
289 /* Add new message */
290 list = g_slist_prepend (list, g_strdup (str));
292 /* Set list and reset the index */
293 priv->sent_messages = list;
294 priv->sent_messages_index = -1;
298 chat_sent_message_get_next (EmpathyChat *chat)
300 EmpathyChatPriv *priv;
303 priv = GET_PRIV (chat);
305 if (!priv->sent_messages) {
306 DEBUG ("No sent messages, next message is NULL");
310 max = g_slist_length (priv->sent_messages) - 1;
312 if (priv->sent_messages_index < max) {
313 priv->sent_messages_index++;
316 DEBUG ("Returning next message index:%d", priv->sent_messages_index);
318 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
322 chat_sent_message_get_last (EmpathyChat *chat)
324 EmpathyChatPriv *priv;
326 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
328 priv = GET_PRIV (chat);
330 if (!priv->sent_messages) {
331 DEBUG ("No sent messages, last message is NULL");
335 if (priv->sent_messages_index >= 0) {
336 priv->sent_messages_index--;
339 DEBUG ("Returning last message index:%d", priv->sent_messages_index);
341 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
345 chat_send (EmpathyChat *chat,
348 EmpathyChatPriv *priv;
349 EmpathyMessage *message;
351 priv = GET_PRIV (chat);
353 if (G_STR_EMPTY (msg)) {
357 chat_sent_message_add (chat, msg);
359 if (g_str_has_prefix (msg, "/clear")) {
360 empathy_chat_view_clear (chat->view);
364 message = empathy_message_new (msg);
366 empathy_tp_chat_send (priv->tp_chat, message);
368 g_object_unref (message);
372 chat_input_text_view_send (EmpathyChat *chat)
374 EmpathyChatPriv *priv;
375 GtkTextBuffer *buffer;
376 GtkTextIter start, end;
379 priv = GET_PRIV (chat);
381 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
383 gtk_text_buffer_get_bounds (buffer, &start, &end);
384 msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
386 /* clear the input field */
387 gtk_text_buffer_set_text (buffer, "", -1);
389 chat_send (chat, msg);
394 chat_state_changed_cb (EmpathyTpChat *tp_chat,
395 EmpathyContact *contact,
396 TpChannelChatState state,
399 EmpathyChatPriv *priv;
401 gboolean was_composing;
403 priv = GET_PRIV (chat);
405 if (empathy_contact_is_user (contact)) {
406 /* We don't care about our own chat state */
410 was_composing = (priv->compositors != NULL);
412 /* Find the contact in the list. After that l is the list elem or NULL */
413 for (l = priv->compositors; l; l = l->next) {
414 if (contact == l->data) {
420 case TP_CHANNEL_CHAT_STATE_GONE:
421 case TP_CHANNEL_CHAT_STATE_INACTIVE:
422 case TP_CHANNEL_CHAT_STATE_PAUSED:
423 case TP_CHANNEL_CHAT_STATE_ACTIVE:
424 /* Contact is not composing */
426 priv->compositors = g_list_remove_link (priv->compositors, l);
427 g_object_unref (l->data);
431 case TP_CHANNEL_CHAT_STATE_COMPOSING:
432 /* Contact is composing */
434 priv->compositors = g_list_prepend (priv->compositors,
435 g_object_ref (contact));
439 g_assert_not_reached ();
442 DEBUG ("Was composing: %s now composing: %s",
443 was_composing ? "yes" : "no",
444 priv->compositors ? "yes" : "no");
446 if ((was_composing && !priv->compositors) ||
447 (!was_composing && priv->compositors)) {
448 /* Composing state changed */
449 g_signal_emit (chat, signals[COMPOSING], 0,
450 priv->compositors != NULL);
455 chat_message_received_cb (EmpathyTpChat *tp_chat,
456 EmpathyMessage *message,
459 EmpathyChatPriv *priv;
460 EmpathyContact *sender;
463 priv = GET_PRIV (chat);
465 sender = empathy_message_get_sender (message);
466 body = empathy_message_get_body (message);
467 while (priv->backlog_messages) {
468 EmpathyMessage *log_message;
469 EmpathyContact *log_sender;
470 const gchar *log_body;
472 log_message = priv->backlog_messages->data;
473 log_sender = empathy_message_get_sender (log_message);
474 log_body = empathy_message_get_body (log_message);
476 priv->backlog_messages = g_list_remove (priv->backlog_messages,
479 if (empathy_contact_equal (sender, log_sender) &&
480 !tp_strdiff (body, log_body)) {
481 /* The message we received is already displayed because
482 * some jabber chatrooms sends us back logs and we
483 * already displayed it from localy logged messages. */
484 DEBUG ("Skipping message because it is already "
485 "displayed from logged messages");
486 g_object_unref (log_message);
489 g_object_unref (log_message);
492 DEBUG ("Appending new message from %s (%d)",
493 empathy_contact_get_name (sender),
494 empathy_contact_get_handle (sender));
497 gboolean is_chatroom;
499 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
500 empathy_log_manager_add_message (priv->log_manager,
501 priv->id, is_chatroom,
505 empathy_chat_view_append_message (chat->view, message);
507 /* We received a message so the contact is no more composing */
508 chat_state_changed_cb (tp_chat, sender,
509 TP_CHANNEL_CHAT_STATE_ACTIVE,
512 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
516 chat_send_error_cb (EmpathyTpChat *tp_chat,
517 EmpathyMessage *message,
518 TpChannelTextSendError error_code,
524 switch (error_code) {
525 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
526 error = _("offline");
528 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
529 error = _("invalid contact");
531 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
532 error = _("permission denied");
534 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
535 error = _("too long message");
537 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
538 error = _("not implemented");
541 error = _("unknown");
545 str = g_strdup_printf (_("Error sending message '%s': %s"),
546 empathy_message_get_body (message),
548 empathy_chat_view_append_event (chat->view, str);
553 chat_property_changed_cb (EmpathyTpChat *tp_chat,
558 EmpathyChatPriv *priv = GET_PRIV (chat);
560 if (!tp_strdiff (name, "subject")) {
561 g_free (priv->subject);
562 priv->subject = g_value_dup_string (value);
563 g_object_notify (G_OBJECT (chat), "subject");
565 if (G_STR_EMPTY (priv->subject)) {
566 gtk_widget_hide (priv->hbox_topic);
568 gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
569 gtk_widget_show (priv->hbox_topic);
571 if (priv->block_events_timeout_id == 0) {
574 if (!G_STR_EMPTY (priv->subject)) {
575 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
577 str = g_strdup (_("No topic defined"));
579 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
583 else if (!tp_strdiff (name, "name")) {
585 priv->name = g_value_dup_string (value);
586 g_object_notify (G_OBJECT (chat), "name");
591 chat_get_is_command (const gchar *str)
593 g_return_val_if_fail (str != NULL, FALSE);
599 if (g_str_has_prefix (str, "/me")) {
602 else if (g_str_has_prefix (str, "/nick")) {
605 else if (g_str_has_prefix (str, "/topic")) {
613 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
616 EmpathyChatPriv *priv;
617 GtkTextIter start, end;
619 gboolean spell_checker = FALSE;
621 priv = GET_PRIV (chat);
623 if (gtk_text_buffer_get_char_count (buffer) == 0) {
624 chat_composing_stop (chat);
626 chat_composing_start (chat);
629 empathy_conf_get_bool (empathy_conf_get (),
630 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
633 gtk_text_buffer_get_start_iter (buffer, &start);
635 if (!spell_checker) {
636 gtk_text_buffer_get_end_iter (buffer, &end);
637 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
641 if (!empathy_spell_supported ()) {
645 /* NOTE: this is really inefficient, we shouldn't have to
646 reiterate the whole buffer each time and check each work
649 gboolean correct = FALSE;
652 if (gtk_text_iter_is_start (&start)) {
655 if (!gtk_text_iter_forward_word_end (&end)) {
656 /* no whole word yet */
660 if (!gtk_text_iter_forward_word_end (&end)) {
661 /* must be the end of the buffer */
666 gtk_text_iter_backward_word_start (&start);
669 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
671 /* spell check string */
672 if (!chat_get_is_command (str)) {
673 correct = empathy_spell_check (str);
679 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
681 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
686 /* set start iter to the end iters position */
692 chat_input_key_press_event_cb (GtkWidget *widget,
696 EmpathyChatPriv *priv;
699 GtkWidget *text_view_sw;
701 priv = GET_PRIV (chat);
703 /* Catch ctrl+up/down so we can traverse messages we sent */
704 if ((event->state & GDK_CONTROL_MASK) &&
705 (event->keyval == GDK_Up ||
706 event->keyval == GDK_Down)) {
707 GtkTextBuffer *buffer;
710 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
712 if (event->keyval == GDK_Up) {
713 str = chat_sent_message_get_next (chat);
715 str = chat_sent_message_get_last (chat);
718 g_signal_handlers_block_by_func (buffer,
719 chat_input_text_buffer_changed_cb,
721 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
722 g_signal_handlers_unblock_by_func (buffer,
723 chat_input_text_buffer_changed_cb,
729 /* Catch enter but not ctrl/shift-enter */
730 if (IS_ENTER (event->keyval) &&
731 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
734 /* This is to make sure that kinput2 gets the enter. And if
735 * it's handled there we shouldn't send on it. This is because
736 * kinput2 uses Enter to commit letters. See:
737 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
740 view = GTK_TEXT_VIEW (chat->input_text_view);
741 if (gtk_im_context_filter_keypress (view->im_context, event)) {
742 GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
746 chat_input_text_view_send (chat);
750 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
752 if (IS_ENTER (event->keyval) &&
753 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
754 /* Newline for shift/control-enter. */
757 if (!(event->state & GDK_CONTROL_MASK) &&
758 event->keyval == GDK_Page_Up) {
759 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
760 gtk_adjustment_set_value (adj, adj->value - adj->page_size);
763 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
764 event->keyval == GDK_Page_Down) {
765 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
766 val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
767 gtk_adjustment_set_value (adj, val);
770 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
771 event->keyval == GDK_Tab) {
772 GtkTextBuffer *buffer;
773 GtkTextIter start, current;
774 gchar *nick, *completed;
775 GList *list, *completed_list;
776 gboolean is_start_of_buffer;
778 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
779 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
781 /* Get the start of the nick to complete. */
782 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
783 gtk_text_iter_backward_word_start (&start);
784 is_start_of_buffer = gtk_text_iter_is_start (&start);
786 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
787 g_completion_add_items (priv->completion, list);
789 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
790 completed_list = g_completion_complete (priv->completion,
799 gchar *complete_char = NULL;
801 gtk_text_buffer_delete (buffer, &start, ¤t);
803 len = g_list_length (completed_list);
806 /* If we only have one hit, use that text
807 * instead of the text in completed since the
808 * completed text will use the typed string
809 * which might be cased all wrong.
812 text = empathy_contact_get_name (completed_list->data);
817 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
819 if (len == 1 && is_start_of_buffer &&
820 empathy_conf_get_string (empathy_conf_get (),
821 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
823 complete_char != NULL) {
824 gtk_text_buffer_insert_at_cursor (buffer,
826 strlen (complete_char));
827 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
828 g_free (complete_char);
834 g_completion_clear_items (priv->completion);
836 g_list_foreach (list, (GFunc) g_object_unref, NULL);
846 chat_text_view_focus_in_event_cb (GtkWidget *widget,
850 gtk_widget_grab_focus (chat->input_text_view);
856 chat_input_set_size_request_idle (gpointer sw)
858 gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT);
864 chat_input_size_request_cb (GtkWidget *widget,
865 GtkRequisition *requisition,
868 EmpathyChatPriv *priv = GET_PRIV (chat);
871 sw = gtk_widget_get_parent (widget);
872 if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) {
873 g_idle_add (chat_input_set_size_request_idle, sw);
874 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
877 priv->has_input_vscroll = TRUE;
880 if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) {
881 gtk_widget_set_size_request (sw, -1, -1);
882 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
885 priv->has_input_vscroll = FALSE;
890 chat_input_realize_cb (GtkWidget *widget,
893 DEBUG ("Setting focus to the input text view");
894 gtk_widget_grab_focus (widget);
898 chat_insert_smiley_activate_cb (GtkWidget *menuitem,
901 GtkTextBuffer *buffer;
905 smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
907 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
909 gtk_text_buffer_get_end_iter (buffer, &iter);
910 gtk_text_buffer_insert (buffer, &iter, smiley, -1);
912 gtk_text_buffer_get_end_iter (buffer, &iter);
913 gtk_text_buffer_insert (buffer, &iter, " ", -1);
924 static EmpathyChatSpell *
925 chat_spell_new (EmpathyChat *chat,
930 EmpathyChatSpell *chat_spell;
932 chat_spell = g_slice_new0 (EmpathyChatSpell);
934 chat_spell->chat = g_object_ref (chat);
935 chat_spell->word = g_strdup (word);
936 chat_spell->start = start;
937 chat_spell->end = end;
943 chat_spell_free (EmpathyChatSpell *chat_spell)
945 g_object_unref (chat_spell->chat);
946 g_free (chat_spell->word);
947 g_slice_free (EmpathyChatSpell, chat_spell);
951 chat_text_check_word_spelling_cb (GtkMenuItem *menuitem,
952 EmpathyChatSpell *chat_spell)
954 empathy_spell_dialog_show (chat_spell->chat,
961 chat_input_populate_popup_cb (GtkTextView *view,
965 EmpathyChatPriv *priv;
966 GtkTextBuffer *buffer;
967 GtkTextTagTable *table;
970 GtkTextIter iter, start, end;
973 EmpathyChatSpell *chat_spell;
974 GtkWidget *smiley_menu;
976 priv = GET_PRIV (chat);
978 /* Add the emoticon menu. */
979 item = gtk_separator_menu_item_new ();
980 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
981 gtk_widget_show (item);
983 item = gtk_menu_item_new_with_mnemonic (_("Insert Smiley"));
984 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
985 gtk_widget_show (item);
987 smiley_menu = empathy_chat_view_get_smiley_menu (
988 G_CALLBACK (chat_insert_smiley_activate_cb),
990 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
992 /* Add the spell check menu item. */
993 buffer = gtk_text_view_get_buffer (view);
994 table = gtk_text_buffer_get_tag_table (buffer);
996 tag = gtk_text_tag_table_lookup (table, "misspelled");
998 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
1000 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
1001 GTK_TEXT_WINDOW_WIDGET,
1005 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
1009 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
1010 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1012 str = gtk_text_buffer_get_text (buffer,
1013 &start, &end, FALSE);
1016 if (G_STR_EMPTY (str)) {
1020 chat_spell = chat_spell_new (chat, str, start, end);
1022 g_object_set_data_full (G_OBJECT (menu),
1023 "chat_spell", chat_spell,
1024 (GDestroyNotify) chat_spell_free);
1026 item = gtk_separator_menu_item_new ();
1027 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1028 gtk_widget_show (item);
1030 item = gtk_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
1031 g_signal_connect (item,
1033 G_CALLBACK (chat_text_check_word_spelling_cb),
1035 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1036 gtk_widget_show (item);
1040 chat_add_logs (EmpathyChat *chat)
1042 EmpathyChatPriv *priv = GET_PRIV (chat);
1043 gboolean is_chatroom;
1044 GList *messages, *l;
1052 /* Turn off scrolling temporarily */
1053 empathy_chat_view_scroll (chat->view, FALSE);
1055 /* Add messages from last conversation */
1056 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
1057 messages = empathy_log_manager_get_last_messages (priv->log_manager,
1061 num_messages = g_list_length (messages);
1063 /* Only keep the 10 last messages */
1064 for (i = 0; num_messages - i > 10; i++) {
1065 EmpathyMessage *message;
1067 message = messages->data;
1068 messages = g_list_remove (messages, message);
1069 g_object_unref (message);
1072 for (l = messages; l; l = l->next) {
1073 empathy_chat_view_append_message (chat->view, l->data);
1075 priv->backlog_messages = messages;
1077 /* Turn back on scrolling */
1078 empathy_chat_view_scroll (chat->view, TRUE);
1082 chat_contacts_completion_func (const gchar *s1,
1086 gchar *tmp, *nick1, *nick2;
1093 return s1 ? -1 : +1;
1096 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
1097 nick1 = g_utf8_casefold (tmp, -1);
1100 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
1101 nick2 = g_utf8_casefold (tmp, -1);
1104 ret = strncmp (nick1, nick2, n);
1113 chat_members_changed_cb (EmpathyTpChat *tp_chat,
1114 EmpathyContact *contact,
1115 EmpathyContact *actor,
1121 EmpathyChatPriv *priv = GET_PRIV (chat);
1123 if (priv->block_events_timeout_id == 0) {
1126 empathy_contact_run_until_ready (contact,
1127 EMPATHY_CONTACT_READY_NAME,
1131 str = g_strdup_printf (_("%s has joined the room"),
1132 empathy_contact_get_name (contact));
1134 str = g_strdup_printf (_("%s has left the room"),
1135 empathy_contact_get_name (contact));
1137 empathy_chat_view_append_event (chat->view, str);
1143 chat_reset_size_request (gpointer widget)
1145 gtk_widget_set_size_request (widget, -1, -1);
1151 chat_set_show_contacts (EmpathyChat *chat, gboolean show)
1153 EmpathyChatPriv *priv = GET_PRIV (chat);
1155 if (!priv->scrolled_window_contacts) {
1160 EmpathyContactListStore *store;
1163 /* We are adding the contact list to the chat, we don't want the
1164 * chat view to become too small. If the chat view is already
1165 * smaller than 250 make sure that size won't change. If the
1166 * chat view is bigger the contact list will take some space on
1167 * it but we make sure the chat view don't become smaller than
1168 * 250. Relax the size request once the resize is done */
1169 min_width = MIN (priv->vbox_left->allocation.width, 250);
1170 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
1171 g_idle_add (chat_reset_size_request, priv->vbox_left);
1173 if (priv->contacts_width > 0) {
1174 gtk_paned_set_position (GTK_PANED (priv->hpaned),
1175 priv->contacts_width);
1178 store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
1179 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
1180 EMPATHY_CONTACT_LIST_FEATURE_NONE,
1181 EMPATHY_CONTACT_FEATURE_CHAT |
1182 EMPATHY_CONTACT_FEATURE_CALL |
1183 EMPATHY_CONTACT_FEATURE_LOG |
1184 EMPATHY_CONTACT_FEATURE_INFO));
1185 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
1186 priv->contact_list_view);
1187 gtk_widget_show (priv->contact_list_view);
1188 gtk_widget_show (priv->scrolled_window_contacts);
1189 g_object_unref (store);
1191 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
1192 gtk_widget_hide (priv->scrolled_window_contacts);
1193 if (priv->contact_list_view) {
1194 gtk_widget_destroy (priv->contact_list_view);
1195 priv->contact_list_view = NULL;
1201 chat_remote_contact_changed_cb (EmpathyChat *chat)
1203 EmpathyChatPriv *priv = GET_PRIV (chat);
1205 if (priv->remote_contact) {
1206 g_object_unref (priv->remote_contact);
1207 priv->remote_contact = NULL;
1210 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
1211 if (priv->remote_contact) {
1212 g_object_ref (priv->remote_contact);
1213 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
1215 priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
1217 else if (priv->tp_chat) {
1220 channel = empathy_tp_chat_get_channel (priv->tp_chat);
1221 g_object_get (channel, "handle-type", &priv->handle_type, NULL);
1223 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
1226 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1228 g_object_notify (G_OBJECT (chat), "remote-contact");
1229 g_object_notify (G_OBJECT (chat), "id");
1233 chat_destroy_cb (EmpathyTpChat *tp_chat,
1236 EmpathyChatPriv *priv;
1238 priv = GET_PRIV (chat);
1240 if (!priv->tp_chat) {
1244 g_object_unref (priv->tp_chat);
1245 priv->tp_chat = NULL;
1246 g_object_notify (G_OBJECT (chat), "tp-chat");
1248 empathy_chat_view_append_event (chat->view, _("Disconnected"));
1249 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
1250 chat_set_show_contacts (chat, FALSE);
1254 chat_create_ui (EmpathyChat *chat)
1256 EmpathyChatPriv *priv = GET_PRIV (chat);
1260 GtkTextBuffer *buffer;
1262 filename = empathy_file_lookup ("empathy-chat.glade",
1264 glade = empathy_glade_get_file (filename,
1267 "chat_widget", &priv->widget,
1268 "hpaned", &priv->hpaned,
1269 "vbox_left", &priv->vbox_left,
1270 "scrolled_window_chat", &priv->scrolled_window_chat,
1271 "scrolled_window_input", &priv->scrolled_window_input,
1272 "hbox_topic", &priv->hbox_topic,
1273 "label_topic", &priv->label_topic,
1274 "scrolled_window_contacts", &priv->scrolled_window_contacts,
1277 g_object_unref (glade);
1279 /* Add message GtkTextView. */
1280 chat->view = empathy_chat_view_new ();
1281 g_signal_connect (chat->view, "focus_in_event",
1282 G_CALLBACK (chat_text_view_focus_in_event_cb),
1284 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
1285 GTK_WIDGET (chat->view));
1286 gtk_widget_show (GTK_WIDGET (chat->view));
1288 /* Add input GtkTextView */
1289 chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
1290 "pixels-above-lines", 2,
1291 "pixels-below-lines", 2,
1292 "pixels-inside-wrap", 1,
1295 "wrap-mode", GTK_WRAP_WORD_CHAR,
1297 g_signal_connect (chat->input_text_view, "key-press-event",
1298 G_CALLBACK (chat_input_key_press_event_cb),
1300 g_signal_connect (chat->input_text_view, "size-request",
1301 G_CALLBACK (chat_input_size_request_cb),
1303 g_signal_connect (chat->input_text_view, "realize",
1304 G_CALLBACK (chat_input_realize_cb),
1306 g_signal_connect (chat->input_text_view, "populate-popup",
1307 G_CALLBACK (chat_input_populate_popup_cb),
1309 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1310 g_signal_connect (buffer, "changed",
1311 G_CALLBACK (chat_input_text_buffer_changed_cb),
1313 gtk_text_buffer_create_tag (buffer, "misspelled",
1314 "underline", PANGO_UNDERLINE_ERROR,
1316 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
1317 chat->input_text_view);
1318 gtk_widget_show (chat->input_text_view);
1320 /* Create contact list */
1321 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1323 /* Initialy hide the topic, will be shown if not empty */
1324 gtk_widget_hide (priv->hbox_topic);
1326 /* Set widget focus order */
1327 list = g_list_append (NULL, priv->scrolled_window_input);
1328 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
1331 list = g_list_append (NULL, priv->vbox_left);
1332 list = g_list_append (list, priv->scrolled_window_contacts);
1333 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
1336 list = g_list_append (NULL, priv->hpaned);
1337 list = g_list_append (list, priv->hbox_topic);
1338 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
1341 /* Add the main widget in the chat widget */
1342 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
1346 chat_size_request (GtkWidget *widget,
1347 GtkRequisition *requisition)
1349 GtkBin *bin = GTK_BIN (widget);
1351 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
1352 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
1354 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1356 GtkRequisition child_requisition;
1358 gtk_widget_size_request (bin->child, &child_requisition);
1360 requisition->width += child_requisition.width;
1361 requisition->height += child_requisition.height;
1366 chat_size_allocate (GtkWidget *widget,
1367 GtkAllocation *allocation)
1369 GtkBin *bin = GTK_BIN (widget);
1370 GtkAllocation child_allocation;
1372 widget->allocation = *allocation;
1374 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1376 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1377 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
1378 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
1379 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
1381 gtk_widget_size_allocate (bin->child, &child_allocation);
1386 chat_finalize (GObject *object)
1389 EmpathyChatPriv *priv;
1391 chat = EMPATHY_CHAT (object);
1392 priv = GET_PRIV (chat);
1394 DEBUG ("Finalized: %p", object);
1396 g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
1397 g_slist_free (priv->sent_messages);
1399 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
1400 g_list_free (priv->compositors);
1402 g_list_foreach (priv->backlog_messages, (GFunc) g_object_unref, NULL);
1403 g_list_free (priv->backlog_messages);
1405 chat_composing_remove_timeout (chat);
1407 empathy_disconnect_account_status_changed (priv->token);
1408 g_object_unref (priv->mc);
1409 g_object_unref (priv->log_manager);
1411 if (priv->tp_chat) {
1412 g_object_unref (priv->tp_chat);
1414 if (priv->account) {
1415 g_object_unref (priv->account);
1417 if (priv->remote_contact) {
1418 g_object_unref (priv->remote_contact);
1421 if (priv->block_events_timeout_id) {
1422 g_source_remove (priv->block_events_timeout_id);
1426 g_free (priv->name);
1427 g_free (priv->subject);
1429 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
1433 chat_constructed (GObject *object)
1435 EmpathyChat *chat = EMPATHY_CHAT (object);
1437 chat_create_ui (chat);
1438 chat_add_logs (chat);
1442 empathy_chat_class_init (EmpathyChatClass *klass)
1444 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1445 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1447 object_class->finalize = chat_finalize;
1448 object_class->get_property = chat_get_property;
1449 object_class->set_property = chat_set_property;
1450 object_class->constructed = chat_constructed;
1452 widget_class->size_request = chat_size_request;
1453 widget_class->size_allocate = chat_size_allocate;
1455 g_object_class_install_property (object_class,
1457 g_param_spec_object ("tp-chat",
1459 "The tp chat object",
1460 EMPATHY_TYPE_TP_CHAT,
1462 G_PARAM_READWRITE));
1463 g_object_class_install_property (object_class,
1465 g_param_spec_object ("account",
1466 "Account of the chat",
1467 "The account of the chat",
1470 g_object_class_install_property (object_class,
1472 g_param_spec_string ("id",
1474 "The id of the chat",
1477 g_object_class_install_property (object_class,
1479 g_param_spec_string ("name",
1481 "The name of the chat",
1484 g_object_class_install_property (object_class,
1486 g_param_spec_string ("subject",
1488 "The subject or topic of the chat",
1491 g_object_class_install_property (object_class,
1492 PROP_REMOTE_CONTACT,
1493 g_param_spec_object ("remote-contact",
1494 "The remote contact",
1495 "The remote contact is any",
1496 EMPATHY_TYPE_CONTACT,
1499 signals[COMPOSING] =
1500 g_signal_new ("composing",
1501 G_OBJECT_CLASS_TYPE (object_class),
1505 g_cclosure_marshal_VOID__BOOLEAN,
1509 signals[NEW_MESSAGE] =
1510 g_signal_new ("new-message",
1511 G_OBJECT_CLASS_TYPE (object_class),
1515 g_cclosure_marshal_VOID__OBJECT,
1517 1, EMPATHY_TYPE_MESSAGE);
1519 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
1523 chat_block_events_timeout_cb (gpointer data)
1525 EmpathyChatPriv *priv = GET_PRIV (data);
1527 priv->block_events_timeout_id = 0;
1533 empathy_chat_init (EmpathyChat *chat)
1535 EmpathyChatPriv *priv = GET_PRIV (chat);
1537 priv->log_manager = empathy_log_manager_new ();
1538 priv->contacts_width = -1;
1539 priv->sent_messages = NULL;
1540 priv->sent_messages_index = -1;
1541 priv->mc = empathy_mission_control_new ();
1543 priv->token = empathy_connect_to_account_status_changed (priv->mc,
1544 G_CALLBACK (chat_status_changed_cb),
1547 /* Block events for some time to avoid having "has come online" or
1548 * "joined" messages. */
1549 priv->block_events_timeout_id =
1550 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
1552 /* Add nick name completion */
1553 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
1554 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
1558 empathy_chat_new (EmpathyTpChat *tp_chat)
1560 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
1564 empathy_chat_get_tp_chat (EmpathyChat *chat)
1566 EmpathyChatPriv *priv = GET_PRIV (chat);
1568 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1570 return priv->tp_chat;
1574 empathy_chat_set_tp_chat (EmpathyChat *chat,
1575 EmpathyTpChat *tp_chat)
1577 EmpathyChatPriv *priv = GET_PRIV (chat);
1579 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1580 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
1581 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
1583 if (priv->tp_chat) {
1587 if (priv->account) {
1588 g_object_unref (priv->account);
1591 priv->tp_chat = g_object_ref (tp_chat);
1592 priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
1594 g_signal_connect (tp_chat, "message-received",
1595 G_CALLBACK (chat_message_received_cb),
1597 g_signal_connect (tp_chat, "send-error",
1598 G_CALLBACK (chat_send_error_cb),
1600 g_signal_connect (tp_chat, "chat-state-changed",
1601 G_CALLBACK (chat_state_changed_cb),
1603 g_signal_connect (tp_chat, "property-changed",
1604 G_CALLBACK (chat_property_changed_cb),
1606 g_signal_connect (tp_chat, "members-changed",
1607 G_CALLBACK (chat_members_changed_cb),
1609 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
1610 G_CALLBACK (chat_remote_contact_changed_cb),
1612 g_signal_connect (tp_chat, "destroy",
1613 G_CALLBACK (chat_destroy_cb),
1616 chat_remote_contact_changed_cb (chat);
1618 if (chat->input_text_view) {
1619 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
1620 if (priv->block_events_timeout_id == 0) {
1621 empathy_chat_view_append_event (chat->view, _("Connected"));
1625 empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
1626 empathy_tp_chat_emit_pendings (priv->tp_chat);
1628 g_object_notify (G_OBJECT (chat), "tp-chat");
1629 g_object_notify (G_OBJECT (chat), "id");
1630 g_object_notify (G_OBJECT (chat), "account");
1634 empathy_chat_get_account (EmpathyChat *chat)
1636 EmpathyChatPriv *priv = GET_PRIV (chat);
1638 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1640 return priv->account;
1644 empathy_chat_get_id (EmpathyChat *chat)
1646 EmpathyChatPriv *priv = GET_PRIV (chat);
1648 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1654 empathy_chat_get_name (EmpathyChat *chat)
1656 EmpathyChatPriv *priv = GET_PRIV (chat);
1658 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1664 empathy_chat_get_subject (EmpathyChat *chat)
1666 EmpathyChatPriv *priv = GET_PRIV (chat);
1668 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1670 return priv->subject;
1674 empathy_chat_get_remote_contact (EmpathyChat *chat)
1676 EmpathyChatPriv *priv = GET_PRIV (chat);
1678 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1680 return priv->remote_contact;
1684 empathy_chat_get_members_count (EmpathyChat *chat)
1686 EmpathyChatPriv *priv = GET_PRIV (chat);
1688 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
1690 if (priv->tp_chat) {
1691 return empathy_tp_chat_get_members_count (priv->tp_chat);
1698 empathy_chat_get_contact_menu (EmpathyChat *chat)
1700 EmpathyChatPriv *priv = GET_PRIV (chat);
1701 GtkWidget *menu = NULL;
1703 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1705 if (priv->remote_contact) {
1706 menu = empathy_contact_menu_new (priv->remote_contact,
1707 EMPATHY_CONTACT_FEATURE_CALL |
1708 EMPATHY_CONTACT_FEATURE_LOG |
1709 EMPATHY_CONTACT_FEATURE_INFO);
1711 else if (priv->contact_list_view) {
1712 EmpathyContactListView *view;
1714 view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
1715 menu = empathy_contact_list_view_get_contact_menu (view);
1722 empathy_chat_clear (EmpathyChat *chat)
1724 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1726 empathy_chat_view_clear (chat->view);
1730 empathy_chat_scroll_down (EmpathyChat *chat)
1732 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1734 empathy_chat_view_scroll_down (chat->view);
1738 empathy_chat_cut (EmpathyChat *chat)
1740 GtkTextBuffer *buffer;
1742 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1744 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1745 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1746 GtkClipboard *clipboard;
1748 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1750 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1755 empathy_chat_copy (EmpathyChat *chat)
1757 GtkTextBuffer *buffer;
1759 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1761 if (empathy_chat_view_get_selection_bounds (chat->view, NULL, NULL)) {
1762 empathy_chat_view_copy_clipboard (chat->view);
1766 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1767 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1768 GtkClipboard *clipboard;
1770 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1772 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1777 empathy_chat_paste (EmpathyChat *chat)
1779 GtkTextBuffer *buffer;
1780 GtkClipboard *clipboard;
1782 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1784 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1785 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1787 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1791 empathy_chat_correct_word (EmpathyChat *chat,
1794 const gchar *new_word)
1796 GtkTextBuffer *buffer;
1798 g_return_if_fail (chat != NULL);
1799 g_return_if_fail (new_word != NULL);
1801 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1803 gtk_text_buffer_delete (buffer, start, end);
1804 gtk_text_buffer_insert (buffer, start,