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 CHAT_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
57 #define CHAT_FILE_CREATE_MODE (S_IRUSR | S_IWUSR)
58 #define IS_ENTER(v) (v == GDK_Return || v == GDK_ISO_Enter || v == GDK_KP_Enter)
59 #define MAX_INPUT_HEIGHT 150
60 #define COMPOSING_STOP_TIMEOUT 5
62 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat)
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;
83 gboolean has_input_vscroll;
88 GtkWidget *scrolled_window_chat;
89 GtkWidget *scrolled_window_input;
90 GtkWidget *scrolled_window_contacts;
91 GtkWidget *hbox_topic;
92 GtkWidget *label_topic;
93 GtkWidget *contact_list_view;
112 static guint signals[LAST_SIGNAL] = { 0 };
114 G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
117 chat_get_property (GObject *object,
122 EmpathyChatPriv *priv = GET_PRIV (object);
126 g_value_set_object (value, priv->tp_chat);
129 g_value_set_object (value, priv->account);
132 g_value_set_string (value, priv->name);
135 g_value_set_string (value, priv->id);
138 g_value_set_string (value, priv->subject);
140 case PROP_REMOTE_CONTACT:
141 g_value_set_object (value, priv->remote_contact);
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
150 chat_set_property (GObject *object,
155 EmpathyChat *chat = EMPATHY_CHAT (object);
159 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
168 chat_status_changed_cb (MissionControl *mc,
169 TpConnectionStatus status,
171 TpConnectionStatusReason reason,
172 const gchar *unique_name,
175 EmpathyChatPriv *priv = GET_PRIV (chat);
178 account = mc_account_lookup (unique_name);
180 if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
181 empathy_account_equal (account, priv->account) &&
182 priv->handle_type != TP_HANDLE_TYPE_NONE) {
183 DEBUG ("Account reconnected, request a new Text channel");
184 mission_control_request_channel_with_string_handle (mc,
186 TP_IFACE_CHANNEL_TYPE_TEXT,
192 g_object_unref (account);
196 chat_composing_remove_timeout (EmpathyChat *chat)
198 EmpathyChatPriv *priv;
200 priv = GET_PRIV (chat);
202 if (priv->composing_stop_timeout_id) {
203 g_source_remove (priv->composing_stop_timeout_id);
204 priv->composing_stop_timeout_id = 0;
209 chat_composing_stop_timeout_cb (EmpathyChat *chat)
211 EmpathyChatPriv *priv;
213 priv = GET_PRIV (chat);
215 priv->composing_stop_timeout_id = 0;
216 empathy_tp_chat_set_state (priv->tp_chat,
217 TP_CHANNEL_CHAT_STATE_PAUSED);
223 chat_composing_start (EmpathyChat *chat)
225 EmpathyChatPriv *priv;
227 priv = GET_PRIV (chat);
229 if (priv->composing_stop_timeout_id) {
230 /* Just restart the timeout */
231 chat_composing_remove_timeout (chat);
233 empathy_tp_chat_set_state (priv->tp_chat,
234 TP_CHANNEL_CHAT_STATE_COMPOSING);
237 priv->composing_stop_timeout_id = g_timeout_add_seconds (
238 COMPOSING_STOP_TIMEOUT,
239 (GSourceFunc) chat_composing_stop_timeout_cb,
244 chat_composing_stop (EmpathyChat *chat)
246 EmpathyChatPriv *priv;
248 priv = GET_PRIV (chat);
250 chat_composing_remove_timeout (chat);
251 empathy_tp_chat_set_state (priv->tp_chat,
252 TP_CHANNEL_CHAT_STATE_ACTIVE);
256 chat_sent_message_add (EmpathyChat *chat,
259 EmpathyChatPriv *priv;
263 priv = GET_PRIV (chat);
265 /* Save the sent message in our repeat buffer */
266 list = priv->sent_messages;
268 /* Remove any other occurances of this msg */
269 while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) {
270 list = g_slist_remove_link (list, item);
272 g_slist_free1 (item);
275 /* Trim the list to the last 10 items */
276 while (g_slist_length (list) > 10) {
277 item = g_slist_last (list);
279 list = g_slist_remove_link (list, item);
281 g_slist_free1 (item);
285 /* Add new message */
286 list = g_slist_prepend (list, g_strdup (str));
288 /* Set list and reset the index */
289 priv->sent_messages = list;
290 priv->sent_messages_index = -1;
294 chat_sent_message_get_next (EmpathyChat *chat)
296 EmpathyChatPriv *priv;
299 priv = GET_PRIV (chat);
301 if (!priv->sent_messages) {
302 DEBUG ("No sent messages, next message is NULL");
306 max = g_slist_length (priv->sent_messages) - 1;
308 if (priv->sent_messages_index < max) {
309 priv->sent_messages_index++;
312 DEBUG ("Returning next message index:%d", priv->sent_messages_index);
314 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
318 chat_sent_message_get_last (EmpathyChat *chat)
320 EmpathyChatPriv *priv;
322 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
324 priv = GET_PRIV (chat);
326 if (!priv->sent_messages) {
327 DEBUG ("No sent messages, last message is NULL");
331 if (priv->sent_messages_index >= 0) {
332 priv->sent_messages_index--;
335 DEBUG ("Returning last message index:%d", priv->sent_messages_index);
337 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
341 chat_send (EmpathyChat *chat,
344 EmpathyChatPriv *priv;
345 EmpathyMessage *message;
347 priv = GET_PRIV (chat);
349 if (G_STR_EMPTY (msg)) {
353 chat_sent_message_add (chat, msg);
355 if (g_str_has_prefix (msg, "/clear")) {
356 empathy_chat_view_clear (chat->view);
360 message = empathy_message_new (msg);
362 empathy_tp_chat_send (priv->tp_chat, message);
364 g_object_unref (message);
368 chat_input_text_view_send (EmpathyChat *chat)
370 EmpathyChatPriv *priv;
371 GtkTextBuffer *buffer;
372 GtkTextIter start, end;
375 priv = GET_PRIV (chat);
377 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
379 gtk_text_buffer_get_bounds (buffer, &start, &end);
380 msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
382 /* clear the input field */
383 gtk_text_buffer_set_text (buffer, "", -1);
385 chat_send (chat, msg);
390 chat_state_changed_cb (EmpathyTpChat *tp_chat,
391 EmpathyContact *contact,
392 TpChannelChatState state,
395 EmpathyChatPriv *priv;
397 gboolean was_composing;
399 priv = GET_PRIV (chat);
401 if (empathy_contact_is_user (contact)) {
402 /* We don't care about our own chat state */
406 was_composing = (priv->compositors != NULL);
408 /* Find the contact in the list. After that l is the list elem or NULL */
409 for (l = priv->compositors; l; l = l->next) {
410 if (contact == l->data) {
416 case TP_CHANNEL_CHAT_STATE_GONE:
417 case TP_CHANNEL_CHAT_STATE_INACTIVE:
418 case TP_CHANNEL_CHAT_STATE_PAUSED:
419 case TP_CHANNEL_CHAT_STATE_ACTIVE:
420 /* Contact is not composing */
422 priv->compositors = g_list_remove_link (priv->compositors, l);
423 g_object_unref (l->data);
427 case TP_CHANNEL_CHAT_STATE_COMPOSING:
428 /* Contact is composing */
430 priv->compositors = g_list_prepend (priv->compositors,
431 g_object_ref (contact));
435 g_assert_not_reached ();
438 DEBUG ("Was composing: %s now composing: %s",
439 was_composing ? "yes" : "no",
440 priv->compositors ? "yes" : "no");
442 if ((was_composing && !priv->compositors) ||
443 (!was_composing && priv->compositors)) {
444 /* Composing state changed */
445 g_signal_emit (chat, signals[COMPOSING], 0,
446 priv->compositors != NULL);
451 chat_message_received_cb (EmpathyTpChat *tp_chat,
452 EmpathyMessage *message,
455 EmpathyChatPriv *priv;
456 EmpathyContact *sender;
459 priv = GET_PRIV (chat);
461 sender = empathy_message_get_sender (message);
462 body = empathy_message_get_body (message);
463 while (priv->backlog_messages) {
464 EmpathyMessage *log_message;
465 EmpathyContact *log_sender;
466 const gchar *log_body;
468 log_message = priv->backlog_messages->data;
469 log_sender = empathy_message_get_sender (log_message);
470 log_body = empathy_message_get_body (log_message);
472 priv->backlog_messages = g_list_remove (priv->backlog_messages,
475 if (empathy_contact_equal (sender, log_sender) &&
476 !tp_strdiff (body, log_body)) {
477 /* The message we received is already displayed because
478 * some jabber chatrooms sends us back logs and we
479 * already displayed it from localy logged messages. */
480 DEBUG ("Skipping message because it is already "
481 "displayed from logged messages");
482 g_object_unref (log_message);
485 g_object_unref (log_message);
488 DEBUG ("Appending new message from %s (%d)",
489 empathy_contact_get_name (sender),
490 empathy_contact_get_handle (sender));
493 gboolean is_chatroom;
495 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
496 empathy_log_manager_add_message (priv->log_manager,
497 priv->id, is_chatroom,
501 empathy_chat_view_append_message (chat->view, message);
503 /* We received a message so the contact is no more composing */
504 chat_state_changed_cb (tp_chat, sender,
505 TP_CHANNEL_CHAT_STATE_ACTIVE,
508 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
512 chat_send_error_cb (EmpathyTpChat *tp_chat,
513 EmpathyMessage *message,
514 TpChannelTextSendError error_code,
520 switch (error_code) {
521 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
522 error = _("offline");
524 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
525 error = _("invalid contact");
527 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
528 error = _("permission denied");
530 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
531 error = _("too long message");
533 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
534 error = _("not implemented");
537 error = _("unknown");
541 str = g_strdup_printf (_("Error sending message '%s': %s"),
542 empathy_message_get_body (message),
544 empathy_chat_view_append_event (chat->view, str);
549 chat_property_changed_cb (EmpathyTpChat *tp_chat,
554 EmpathyChatPriv *priv = GET_PRIV (chat);
556 if (!tp_strdiff (name, "subject")) {
557 g_free (priv->subject);
558 priv->subject = g_value_dup_string (value);
559 g_object_notify (G_OBJECT (chat), "subject");
561 if (G_STR_EMPTY (priv->subject)) {
562 gtk_widget_hide (priv->hbox_topic);
564 gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
565 gtk_widget_show (priv->hbox_topic);
567 if (priv->block_events_timeout_id == 0) {
570 if (!G_STR_EMPTY (priv->subject)) {
571 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
573 str = g_strdup (_("No topic defined"));
575 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
579 else if (!tp_strdiff (name, "name")) {
581 priv->name = g_value_dup_string (value);
582 g_object_notify (G_OBJECT (chat), "name");
587 chat_get_is_command (const gchar *str)
589 g_return_val_if_fail (str != NULL, FALSE);
595 if (g_str_has_prefix (str, "/me")) {
598 else if (g_str_has_prefix (str, "/nick")) {
601 else if (g_str_has_prefix (str, "/topic")) {
609 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
612 EmpathyChatPriv *priv;
613 GtkTextIter start, end;
615 gboolean spell_checker = FALSE;
617 priv = GET_PRIV (chat);
619 if (gtk_text_buffer_get_char_count (buffer) == 0) {
620 chat_composing_stop (chat);
622 chat_composing_start (chat);
625 empathy_conf_get_bool (empathy_conf_get (),
626 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
629 gtk_text_buffer_get_start_iter (buffer, &start);
631 if (!spell_checker) {
632 gtk_text_buffer_get_end_iter (buffer, &end);
633 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
637 if (!empathy_spell_supported ()) {
641 /* NOTE: this is really inefficient, we shouldn't have to
642 reiterate the whole buffer each time and check each work
645 gboolean correct = FALSE;
648 if (gtk_text_iter_is_start (&start)) {
651 if (!gtk_text_iter_forward_word_end (&end)) {
652 /* no whole word yet */
656 if (!gtk_text_iter_forward_word_end (&end)) {
657 /* must be the end of the buffer */
662 gtk_text_iter_backward_word_start (&start);
665 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
667 /* spell check string */
668 if (!chat_get_is_command (str)) {
669 correct = empathy_spell_check (str);
675 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
677 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
682 /* set start iter to the end iters position */
688 chat_input_key_press_event_cb (GtkWidget *widget,
692 EmpathyChatPriv *priv;
695 GtkWidget *text_view_sw;
697 priv = GET_PRIV (chat);
699 /* Catch ctrl+up/down so we can traverse messages we sent */
700 if ((event->state & GDK_CONTROL_MASK) &&
701 (event->keyval == GDK_Up ||
702 event->keyval == GDK_Down)) {
703 GtkTextBuffer *buffer;
706 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
708 if (event->keyval == GDK_Up) {
709 str = chat_sent_message_get_next (chat);
711 str = chat_sent_message_get_last (chat);
714 g_signal_handlers_block_by_func (buffer,
715 chat_input_text_buffer_changed_cb,
717 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
718 g_signal_handlers_unblock_by_func (buffer,
719 chat_input_text_buffer_changed_cb,
725 /* Catch enter but not ctrl/shift-enter */
726 if (IS_ENTER (event->keyval) &&
727 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
730 /* This is to make sure that kinput2 gets the enter. And if
731 * it's handled there we shouldn't send on it. This is because
732 * kinput2 uses Enter to commit letters. See:
733 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
736 view = GTK_TEXT_VIEW (chat->input_text_view);
737 if (gtk_im_context_filter_keypress (view->im_context, event)) {
738 GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
742 chat_input_text_view_send (chat);
746 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
748 if (IS_ENTER (event->keyval) &&
749 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
750 /* Newline for shift/control-enter. */
753 if (!(event->state & GDK_CONTROL_MASK) &&
754 event->keyval == GDK_Page_Up) {
755 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
756 gtk_adjustment_set_value (adj, adj->value - adj->page_size);
759 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
760 event->keyval == GDK_Page_Down) {
761 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
762 val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
763 gtk_adjustment_set_value (adj, val);
766 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
767 event->keyval == GDK_Tab) {
768 GtkTextBuffer *buffer;
769 GtkTextIter start, current;
770 gchar *nick, *completed;
771 GList *list, *completed_list;
772 gboolean is_start_of_buffer;
774 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
775 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
777 /* Get the start of the nick to complete. */
778 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
779 gtk_text_iter_backward_word_start (&start);
780 is_start_of_buffer = gtk_text_iter_is_start (&start);
782 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
783 g_completion_add_items (priv->completion, list);
785 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
786 completed_list = g_completion_complete (priv->completion,
795 gchar *complete_char = NULL;
797 gtk_text_buffer_delete (buffer, &start, ¤t);
799 len = g_list_length (completed_list);
802 /* If we only have one hit, use that text
803 * instead of the text in completed since the
804 * completed text will use the typed string
805 * which might be cased all wrong.
808 text = empathy_contact_get_name (completed_list->data);
813 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
815 if (len == 1 && is_start_of_buffer &&
816 empathy_conf_get_string (empathy_conf_get (),
817 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
819 complete_char != NULL) {
820 gtk_text_buffer_insert_at_cursor (buffer,
822 strlen (complete_char));
823 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
824 g_free (complete_char);
830 g_completion_clear_items (priv->completion);
832 g_list_foreach (list, (GFunc) g_object_unref, NULL);
842 chat_text_view_focus_in_event_cb (GtkWidget *widget,
846 gtk_widget_grab_focus (chat->input_text_view);
852 chat_input_set_size_request_idle (gpointer sw)
854 gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT);
860 chat_input_size_request_cb (GtkWidget *widget,
861 GtkRequisition *requisition,
864 EmpathyChatPriv *priv = GET_PRIV (chat);
867 sw = gtk_widget_get_parent (widget);
868 if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) {
869 g_idle_add (chat_input_set_size_request_idle, sw);
870 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
873 priv->has_input_vscroll = TRUE;
876 if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) {
877 gtk_widget_set_size_request (sw, -1, -1);
878 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
881 priv->has_input_vscroll = FALSE;
886 chat_input_realize_cb (GtkWidget *widget,
889 DEBUG ("Setting focus to the input text view");
890 gtk_widget_grab_focus (widget);
894 chat_insert_smiley_activate_cb (GtkWidget *menuitem,
897 GtkTextBuffer *buffer;
901 smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
903 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
905 gtk_text_buffer_get_end_iter (buffer, &iter);
906 gtk_text_buffer_insert (buffer, &iter, smiley, -1);
908 gtk_text_buffer_get_end_iter (buffer, &iter);
909 gtk_text_buffer_insert (buffer, &iter, " ", -1);
920 static EmpathyChatSpell *
921 chat_spell_new (EmpathyChat *chat,
926 EmpathyChatSpell *chat_spell;
928 chat_spell = g_slice_new0 (EmpathyChatSpell);
930 chat_spell->chat = g_object_ref (chat);
931 chat_spell->word = g_strdup (word);
932 chat_spell->start = start;
933 chat_spell->end = end;
939 chat_spell_free (EmpathyChatSpell *chat_spell)
941 g_object_unref (chat_spell->chat);
942 g_free (chat_spell->word);
943 g_slice_free (EmpathyChatSpell, chat_spell);
947 chat_text_check_word_spelling_cb (GtkMenuItem *menuitem,
948 EmpathyChatSpell *chat_spell)
950 empathy_spell_dialog_show (chat_spell->chat,
957 chat_input_populate_popup_cb (GtkTextView *view,
961 EmpathyChatPriv *priv;
962 GtkTextBuffer *buffer;
963 GtkTextTagTable *table;
966 GtkTextIter iter, start, end;
969 EmpathyChatSpell *chat_spell;
970 GtkWidget *smiley_menu;
972 priv = GET_PRIV (chat);
974 /* Add the emoticon menu. */
975 item = gtk_separator_menu_item_new ();
976 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
977 gtk_widget_show (item);
979 item = gtk_menu_item_new_with_mnemonic (_("Insert Smiley"));
980 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
981 gtk_widget_show (item);
983 smiley_menu = empathy_chat_view_get_smiley_menu (
984 G_CALLBACK (chat_insert_smiley_activate_cb),
986 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
988 /* Add the spell check menu item. */
989 buffer = gtk_text_view_get_buffer (view);
990 table = gtk_text_buffer_get_tag_table (buffer);
992 tag = gtk_text_tag_table_lookup (table, "misspelled");
994 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
996 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
997 GTK_TEXT_WINDOW_WIDGET,
1001 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
1005 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
1006 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1008 str = gtk_text_buffer_get_text (buffer,
1009 &start, &end, FALSE);
1012 if (G_STR_EMPTY (str)) {
1016 chat_spell = chat_spell_new (chat, str, start, end);
1018 g_object_set_data_full (G_OBJECT (menu),
1019 "chat_spell", chat_spell,
1020 (GDestroyNotify) chat_spell_free);
1022 item = gtk_separator_menu_item_new ();
1023 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1024 gtk_widget_show (item);
1026 item = gtk_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
1027 g_signal_connect (item,
1029 G_CALLBACK (chat_text_check_word_spelling_cb),
1031 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1032 gtk_widget_show (item);
1036 chat_add_logs (EmpathyChat *chat)
1038 EmpathyChatPriv *priv = GET_PRIV (chat);
1039 gboolean is_chatroom;
1040 GList *messages, *l;
1048 /* Turn off scrolling temporarily */
1049 empathy_chat_view_scroll (chat->view, FALSE);
1051 /* Add messages from last conversation */
1052 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
1053 messages = empathy_log_manager_get_last_messages (priv->log_manager,
1057 num_messages = g_list_length (messages);
1059 /* Only keep the 10 last messages */
1060 for (i = 0; num_messages - i > 10; i++) {
1061 EmpathyMessage *message;
1063 message = messages->data;
1064 messages = g_list_remove (messages, message);
1065 g_object_unref (message);
1068 for (l = messages; l; l = l->next) {
1069 empathy_chat_view_append_message (chat->view, l->data);
1071 priv->backlog_messages = messages;
1073 /* Turn back on scrolling */
1074 empathy_chat_view_scroll (chat->view, TRUE);
1078 chat_contacts_completion_func (const gchar *s1,
1082 gchar *tmp, *nick1, *nick2;
1089 return s1 ? -1 : +1;
1092 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
1093 nick1 = g_utf8_casefold (tmp, -1);
1096 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
1097 nick2 = g_utf8_casefold (tmp, -1);
1100 ret = strncmp (nick1, nick2, n);
1109 chat_members_changed_cb (EmpathyTpChat *tp_chat,
1110 EmpathyContact *contact,
1111 EmpathyContact *actor,
1117 EmpathyChatPriv *priv = GET_PRIV (chat);
1119 if (priv->block_events_timeout_id == 0) {
1122 empathy_contact_run_until_ready (contact,
1123 EMPATHY_CONTACT_READY_NAME,
1127 str = g_strdup_printf (_("%s has joined the room"),
1128 empathy_contact_get_name (contact));
1130 str = g_strdup_printf (_("%s has left the room"),
1131 empathy_contact_get_name (contact));
1133 empathy_chat_view_append_event (chat->view, str);
1139 chat_reset_size_request (gpointer widget)
1141 gtk_widget_set_size_request (widget, -1, -1);
1147 chat_set_show_contacts (EmpathyChat *chat, gboolean show)
1149 EmpathyChatPriv *priv = GET_PRIV (chat);
1151 if (!priv->scrolled_window_contacts) {
1156 EmpathyContactListStore *store;
1159 /* We are adding the contact list to the chat, we don't want the
1160 * chat view to become too small. If the chat view is already
1161 * smaller than 250 make sure that size won't change. If the
1162 * chat view is bigger the contact list will take some space on
1163 * it but we make sure the chat view don't become smaller than
1164 * 250. Relax the size request once the resize is done */
1165 min_width = MIN (priv->vbox_left->allocation.width, 250);
1166 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
1167 g_idle_add (chat_reset_size_request, priv->vbox_left);
1169 if (priv->contacts_width > 0) {
1170 gtk_paned_set_position (GTK_PANED (priv->hpaned),
1171 priv->contacts_width);
1174 store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
1175 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
1176 EMPATHY_CONTACT_LIST_FEATURE_NONE,
1177 EMPATHY_CONTACT_FEATURE_CHAT |
1178 EMPATHY_CONTACT_FEATURE_CALL |
1179 EMPATHY_CONTACT_FEATURE_LOG |
1180 EMPATHY_CONTACT_FEATURE_INFO));
1181 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
1182 priv->contact_list_view);
1183 gtk_widget_show (priv->contact_list_view);
1184 gtk_widget_show (priv->scrolled_window_contacts);
1185 g_object_unref (store);
1187 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
1188 gtk_widget_hide (priv->scrolled_window_contacts);
1189 if (priv->contact_list_view) {
1190 gtk_widget_destroy (priv->contact_list_view);
1191 priv->contact_list_view = NULL;
1197 chat_remote_contact_changed_cb (EmpathyChat *chat)
1199 EmpathyChatPriv *priv = GET_PRIV (chat);
1201 if (priv->remote_contact) {
1202 g_object_unref (priv->remote_contact);
1203 priv->remote_contact = NULL;
1206 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
1207 if (priv->remote_contact) {
1208 g_object_ref (priv->remote_contact);
1209 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
1211 priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
1213 else if (priv->tp_chat) {
1216 channel = empathy_tp_chat_get_channel (priv->tp_chat);
1217 g_object_get (channel, "handle-type", &priv->handle_type, NULL);
1219 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
1222 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1224 g_object_notify (G_OBJECT (chat), "remote-contact");
1225 g_object_notify (G_OBJECT (chat), "id");
1229 chat_destroy_cb (EmpathyTpChat *tp_chat,
1232 EmpathyChatPriv *priv;
1234 priv = GET_PRIV (chat);
1236 if (!priv->tp_chat) {
1240 g_object_unref (priv->tp_chat);
1241 priv->tp_chat = NULL;
1242 g_object_notify (G_OBJECT (chat), "tp-chat");
1244 empathy_chat_view_append_event (chat->view, _("Disconnected"));
1245 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
1246 chat_set_show_contacts (chat, FALSE);
1250 chat_create_ui (EmpathyChat *chat)
1252 EmpathyChatPriv *priv = GET_PRIV (chat);
1256 GtkTextBuffer *buffer;
1258 filename = empathy_file_lookup ("empathy-chat.glade",
1260 glade = empathy_glade_get_file (filename,
1263 "chat_widget", &priv->widget,
1264 "hpaned", &priv->hpaned,
1265 "vbox_left", &priv->vbox_left,
1266 "scrolled_window_chat", &priv->scrolled_window_chat,
1267 "scrolled_window_input", &priv->scrolled_window_input,
1268 "hbox_topic", &priv->hbox_topic,
1269 "label_topic", &priv->label_topic,
1270 "scrolled_window_contacts", &priv->scrolled_window_contacts,
1273 g_object_unref (glade);
1275 /* Add message GtkTextView. */
1276 chat->view = empathy_chat_view_new ();
1277 g_signal_connect (chat->view, "focus_in_event",
1278 G_CALLBACK (chat_text_view_focus_in_event_cb),
1280 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
1281 GTK_WIDGET (chat->view));
1282 gtk_widget_show (GTK_WIDGET (chat->view));
1284 /* Add input GtkTextView */
1285 chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
1286 "pixels-above-lines", 2,
1287 "pixels-below-lines", 2,
1288 "pixels-inside-wrap", 1,
1291 "wrap-mode", GTK_WRAP_WORD_CHAR,
1293 g_signal_connect (chat->input_text_view, "key-press-event",
1294 G_CALLBACK (chat_input_key_press_event_cb),
1296 g_signal_connect (chat->input_text_view, "size-request",
1297 G_CALLBACK (chat_input_size_request_cb),
1299 g_signal_connect (chat->input_text_view, "realize",
1300 G_CALLBACK (chat_input_realize_cb),
1302 g_signal_connect (chat->input_text_view, "populate-popup",
1303 G_CALLBACK (chat_input_populate_popup_cb),
1305 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1306 g_signal_connect (buffer, "changed",
1307 G_CALLBACK (chat_input_text_buffer_changed_cb),
1309 gtk_text_buffer_create_tag (buffer, "misspelled",
1310 "underline", PANGO_UNDERLINE_ERROR,
1312 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
1313 chat->input_text_view);
1314 gtk_widget_show (chat->input_text_view);
1316 /* Create contact list */
1317 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1319 /* Initialy hide the topic, will be shown if not empty */
1320 gtk_widget_hide (priv->hbox_topic);
1322 /* Set widget focus order */
1323 list = g_list_append (NULL, priv->scrolled_window_input);
1324 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
1327 list = g_list_append (NULL, priv->vbox_left);
1328 list = g_list_append (list, priv->scrolled_window_contacts);
1329 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
1332 list = g_list_append (NULL, priv->hpaned);
1333 list = g_list_append (list, priv->hbox_topic);
1334 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
1337 /* Add the main widget in the chat widget */
1338 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
1342 chat_size_request (GtkWidget *widget,
1343 GtkRequisition *requisition)
1345 GtkBin *bin = GTK_BIN (widget);
1347 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
1348 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
1350 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1352 GtkRequisition child_requisition;
1354 gtk_widget_size_request (bin->child, &child_requisition);
1356 requisition->width += child_requisition.width;
1357 requisition->height += child_requisition.height;
1362 chat_size_allocate (GtkWidget *widget,
1363 GtkAllocation *allocation)
1365 GtkBin *bin = GTK_BIN (widget);
1366 GtkAllocation child_allocation;
1368 widget->allocation = *allocation;
1370 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1372 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1373 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
1374 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
1375 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
1377 gtk_widget_size_allocate (bin->child, &child_allocation);
1382 chat_finalize (GObject *object)
1385 EmpathyChatPriv *priv;
1387 chat = EMPATHY_CHAT (object);
1388 priv = GET_PRIV (chat);
1390 DEBUG ("Finalized: %p", object);
1392 g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
1393 g_slist_free (priv->sent_messages);
1395 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
1396 g_list_free (priv->compositors);
1398 g_list_foreach (priv->backlog_messages, (GFunc) g_object_unref, NULL);
1399 g_list_free (priv->backlog_messages);
1401 chat_composing_remove_timeout (chat);
1403 empathy_disconnect_account_status_changed (priv->token);
1404 g_object_unref (priv->mc);
1405 g_object_unref (priv->log_manager);
1407 if (priv->tp_chat) {
1408 g_object_unref (priv->tp_chat);
1410 if (priv->account) {
1411 g_object_unref (priv->account);
1413 if (priv->remote_contact) {
1414 g_object_unref (priv->remote_contact);
1417 if (priv->block_events_timeout_id) {
1418 g_source_remove (priv->block_events_timeout_id);
1422 g_free (priv->name);
1423 g_free (priv->subject);
1425 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
1429 chat_constructed (GObject *object)
1431 EmpathyChat *chat = EMPATHY_CHAT (object);
1433 chat_create_ui (chat);
1434 chat_add_logs (chat);
1438 empathy_chat_class_init (EmpathyChatClass *klass)
1440 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1441 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1443 object_class->finalize = chat_finalize;
1444 object_class->get_property = chat_get_property;
1445 object_class->set_property = chat_set_property;
1446 object_class->constructed = chat_constructed;
1448 widget_class->size_request = chat_size_request;
1449 widget_class->size_allocate = chat_size_allocate;
1451 g_object_class_install_property (object_class,
1453 g_param_spec_object ("tp-chat",
1455 "The tp chat object",
1456 EMPATHY_TYPE_TP_CHAT,
1458 G_PARAM_READWRITE));
1459 g_object_class_install_property (object_class,
1461 g_param_spec_object ("account",
1462 "Account of the chat",
1463 "The account of the chat",
1466 g_object_class_install_property (object_class,
1468 g_param_spec_string ("id",
1470 "The id of the chat",
1473 g_object_class_install_property (object_class,
1475 g_param_spec_string ("name",
1477 "The name of the chat",
1480 g_object_class_install_property (object_class,
1482 g_param_spec_string ("subject",
1484 "The subject or topic of the chat",
1487 g_object_class_install_property (object_class,
1488 PROP_REMOTE_CONTACT,
1489 g_param_spec_object ("remote-contact",
1490 "The remote contact",
1491 "The remote contact is any",
1492 EMPATHY_TYPE_CONTACT,
1495 signals[COMPOSING] =
1496 g_signal_new ("composing",
1497 G_OBJECT_CLASS_TYPE (object_class),
1501 g_cclosure_marshal_VOID__BOOLEAN,
1505 signals[NEW_MESSAGE] =
1506 g_signal_new ("new-message",
1507 G_OBJECT_CLASS_TYPE (object_class),
1511 g_cclosure_marshal_VOID__OBJECT,
1513 1, EMPATHY_TYPE_MESSAGE);
1515 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
1519 chat_block_events_timeout_cb (gpointer data)
1521 EmpathyChatPriv *priv = GET_PRIV (data);
1523 priv->block_events_timeout_id = 0;
1529 empathy_chat_init (EmpathyChat *chat)
1531 EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1532 EMPATHY_TYPE_CHAT, EmpathyChatPriv);
1535 priv->log_manager = empathy_log_manager_new ();
1536 priv->contacts_width = -1;
1537 priv->sent_messages = NULL;
1538 priv->sent_messages_index = -1;
1539 priv->mc = empathy_mission_control_new ();
1541 priv->token = empathy_connect_to_account_status_changed (priv->mc,
1542 G_CALLBACK (chat_status_changed_cb),
1545 /* Block events for some time to avoid having "has come online" or
1546 * "joined" messages. */
1547 priv->block_events_timeout_id =
1548 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
1550 /* Add nick name completion */
1551 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
1552 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
1556 empathy_chat_new (EmpathyTpChat *tp_chat)
1558 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
1562 empathy_chat_get_tp_chat (EmpathyChat *chat)
1564 EmpathyChatPriv *priv = GET_PRIV (chat);
1566 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1568 return priv->tp_chat;
1572 empathy_chat_set_tp_chat (EmpathyChat *chat,
1573 EmpathyTpChat *tp_chat)
1575 EmpathyChatPriv *priv = GET_PRIV (chat);
1577 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1578 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
1579 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
1581 if (priv->tp_chat) {
1585 if (priv->account) {
1586 g_object_unref (priv->account);
1589 priv->tp_chat = g_object_ref (tp_chat);
1590 priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
1592 g_signal_connect (tp_chat, "message-received",
1593 G_CALLBACK (chat_message_received_cb),
1595 g_signal_connect (tp_chat, "send-error",
1596 G_CALLBACK (chat_send_error_cb),
1598 g_signal_connect (tp_chat, "chat-state-changed",
1599 G_CALLBACK (chat_state_changed_cb),
1601 g_signal_connect (tp_chat, "property-changed",
1602 G_CALLBACK (chat_property_changed_cb),
1604 g_signal_connect (tp_chat, "members-changed",
1605 G_CALLBACK (chat_members_changed_cb),
1607 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
1608 G_CALLBACK (chat_remote_contact_changed_cb),
1610 g_signal_connect (tp_chat, "destroy",
1611 G_CALLBACK (chat_destroy_cb),
1614 chat_remote_contact_changed_cb (chat);
1616 if (chat->input_text_view) {
1617 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
1618 if (priv->block_events_timeout_id == 0) {
1619 empathy_chat_view_append_event (chat->view, _("Connected"));
1623 empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
1624 empathy_tp_chat_emit_pendings (priv->tp_chat);
1626 g_object_notify (G_OBJECT (chat), "tp-chat");
1627 g_object_notify (G_OBJECT (chat), "id");
1628 g_object_notify (G_OBJECT (chat), "account");
1632 empathy_chat_get_account (EmpathyChat *chat)
1634 EmpathyChatPriv *priv = GET_PRIV (chat);
1636 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1638 return priv->account;
1642 empathy_chat_get_id (EmpathyChat *chat)
1644 EmpathyChatPriv *priv = GET_PRIV (chat);
1646 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1652 empathy_chat_get_name (EmpathyChat *chat)
1654 EmpathyChatPriv *priv = GET_PRIV (chat);
1656 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1662 empathy_chat_get_subject (EmpathyChat *chat)
1664 EmpathyChatPriv *priv = GET_PRIV (chat);
1666 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1668 return priv->subject;
1672 empathy_chat_get_remote_contact (EmpathyChat *chat)
1674 EmpathyChatPriv *priv = GET_PRIV (chat);
1676 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1678 return priv->remote_contact;
1682 empathy_chat_get_members_count (EmpathyChat *chat)
1684 EmpathyChatPriv *priv = GET_PRIV (chat);
1686 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
1688 if (priv->tp_chat) {
1689 return empathy_tp_chat_get_members_count (priv->tp_chat);
1696 empathy_chat_get_contact_menu (EmpathyChat *chat)
1698 EmpathyChatPriv *priv = GET_PRIV (chat);
1699 GtkWidget *menu = NULL;
1701 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1703 if (priv->remote_contact) {
1704 menu = empathy_contact_menu_new (priv->remote_contact,
1705 EMPATHY_CONTACT_FEATURE_CALL |
1706 EMPATHY_CONTACT_FEATURE_LOG |
1707 EMPATHY_CONTACT_FEATURE_INFO);
1709 else if (priv->contact_list_view) {
1710 EmpathyContactListView *view;
1712 view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
1713 menu = empathy_contact_list_view_get_contact_menu (view);
1720 empathy_chat_clear (EmpathyChat *chat)
1722 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1724 empathy_chat_view_clear (chat->view);
1728 empathy_chat_scroll_down (EmpathyChat *chat)
1730 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1732 empathy_chat_view_scroll_down (chat->view);
1736 empathy_chat_cut (EmpathyChat *chat)
1738 GtkTextBuffer *buffer;
1740 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1742 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1743 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1744 GtkClipboard *clipboard;
1746 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1748 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1753 empathy_chat_copy (EmpathyChat *chat)
1755 GtkTextBuffer *buffer;
1757 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1759 if (empathy_chat_view_get_selection_bounds (chat->view, NULL, NULL)) {
1760 empathy_chat_view_copy_clipboard (chat->view);
1764 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1765 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1766 GtkClipboard *clipboard;
1768 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1770 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1775 empathy_chat_paste (EmpathyChat *chat)
1777 GtkTextBuffer *buffer;
1778 GtkClipboard *clipboard;
1780 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1782 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1783 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1785 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1789 empathy_chat_correct_word (EmpathyChat *chat,
1792 const gchar *new_word)
1794 GtkTextBuffer *buffer;
1796 g_return_if_fail (chat != NULL);
1797 g_return_if_fail (new_word != NULL);
1799 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1801 gtk_text_buffer_delete (buffer, start, end);
1802 gtk_text_buffer_insert (buffer, start,