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 GCompletion *completion;
77 guint composing_stop_timeout_id;
78 guint block_events_timeout_id;
79 TpHandleType handle_type;
82 gboolean has_input_vscroll;
87 GtkWidget *scrolled_window_chat;
88 GtkWidget *scrolled_window_input;
89 GtkWidget *scrolled_window_contacts;
90 GtkWidget *hbox_topic;
91 GtkWidget *label_topic;
92 GtkWidget *contact_list_view;
111 static guint signals[LAST_SIGNAL] = { 0 };
113 G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
116 chat_get_property (GObject *object,
121 EmpathyChatPriv *priv = GET_PRIV (object);
125 g_value_set_object (value, priv->tp_chat);
128 g_value_set_object (value, priv->account);
131 g_value_set_string (value, priv->name);
134 g_value_set_string (value, priv->id);
137 g_value_set_string (value, priv->subject);
139 case PROP_REMOTE_CONTACT:
140 g_value_set_object (value, priv->remote_contact);
143 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
149 chat_set_property (GObject *object,
154 EmpathyChat *chat = EMPATHY_CHAT (object);
158 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
161 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
167 chat_status_changed_cb (MissionControl *mc,
168 TpConnectionStatus status,
170 TpConnectionStatusReason reason,
171 const gchar *unique_name,
174 EmpathyChatPriv *priv = GET_PRIV (chat);
177 account = mc_account_lookup (unique_name);
179 if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
180 empathy_account_equal (account, priv->account) &&
181 priv->handle_type != TP_HANDLE_TYPE_NONE) {
182 TpConnection *connection;
184 DEBUG ("Account reconnected, request a new Text channel");
185 connection = mission_control_get_tpconnection (mc, account, NULL);
186 tp_connection_run_until_ready (connection, FALSE, NULL, NULL);
187 empathy_connection_request_channel (connection, -1,
188 TP_IFACE_CHANNEL_TYPE_TEXT,
191 NULL, NULL, NULL, NULL);
192 g_object_unref (connection);
195 g_object_unref (account);
199 chat_composing_remove_timeout (EmpathyChat *chat)
201 EmpathyChatPriv *priv;
203 priv = GET_PRIV (chat);
205 if (priv->composing_stop_timeout_id) {
206 g_source_remove (priv->composing_stop_timeout_id);
207 priv->composing_stop_timeout_id = 0;
212 chat_composing_stop_timeout_cb (EmpathyChat *chat)
214 EmpathyChatPriv *priv;
216 priv = GET_PRIV (chat);
218 priv->composing_stop_timeout_id = 0;
219 empathy_tp_chat_set_state (priv->tp_chat,
220 TP_CHANNEL_CHAT_STATE_PAUSED);
226 chat_composing_start (EmpathyChat *chat)
228 EmpathyChatPriv *priv;
230 priv = GET_PRIV (chat);
232 if (priv->composing_stop_timeout_id) {
233 /* Just restart the timeout */
234 chat_composing_remove_timeout (chat);
236 empathy_tp_chat_set_state (priv->tp_chat,
237 TP_CHANNEL_CHAT_STATE_COMPOSING);
240 priv->composing_stop_timeout_id = g_timeout_add_seconds (
241 COMPOSING_STOP_TIMEOUT,
242 (GSourceFunc) chat_composing_stop_timeout_cb,
247 chat_composing_stop (EmpathyChat *chat)
249 EmpathyChatPriv *priv;
251 priv = GET_PRIV (chat);
253 chat_composing_remove_timeout (chat);
254 empathy_tp_chat_set_state (priv->tp_chat,
255 TP_CHANNEL_CHAT_STATE_ACTIVE);
259 chat_sent_message_add (EmpathyChat *chat,
262 EmpathyChatPriv *priv;
266 priv = GET_PRIV (chat);
268 /* Save the sent message in our repeat buffer */
269 list = priv->sent_messages;
271 /* Remove any other occurances of this msg */
272 while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) {
273 list = g_slist_remove_link (list, item);
275 g_slist_free1 (item);
278 /* Trim the list to the last 10 items */
279 while (g_slist_length (list) > 10) {
280 item = g_slist_last (list);
282 list = g_slist_remove_link (list, item);
284 g_slist_free1 (item);
288 /* Add new message */
289 list = g_slist_prepend (list, g_strdup (str));
291 /* Set list and reset the index */
292 priv->sent_messages = list;
293 priv->sent_messages_index = -1;
297 chat_sent_message_get_next (EmpathyChat *chat)
299 EmpathyChatPriv *priv;
302 priv = GET_PRIV (chat);
304 if (!priv->sent_messages) {
305 DEBUG ("No sent messages, next message is NULL");
309 max = g_slist_length (priv->sent_messages) - 1;
311 if (priv->sent_messages_index < max) {
312 priv->sent_messages_index++;
315 DEBUG ("Returning next message index:%d", priv->sent_messages_index);
317 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
321 chat_sent_message_get_last (EmpathyChat *chat)
323 EmpathyChatPriv *priv;
325 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
327 priv = GET_PRIV (chat);
329 if (!priv->sent_messages) {
330 DEBUG ("No sent messages, last message is NULL");
334 if (priv->sent_messages_index >= 0) {
335 priv->sent_messages_index--;
338 DEBUG ("Returning last message index:%d", priv->sent_messages_index);
340 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
344 chat_send (EmpathyChat *chat,
347 EmpathyChatPriv *priv;
348 EmpathyMessage *message;
350 priv = GET_PRIV (chat);
352 if (G_STR_EMPTY (msg)) {
356 chat_sent_message_add (chat, msg);
358 if (g_str_has_prefix (msg, "/clear")) {
359 empathy_chat_view_clear (chat->view);
363 message = empathy_message_new (msg);
365 empathy_tp_chat_send (priv->tp_chat, message);
367 g_object_unref (message);
371 chat_input_text_view_send (EmpathyChat *chat)
373 EmpathyChatPriv *priv;
374 GtkTextBuffer *buffer;
375 GtkTextIter start, end;
378 priv = GET_PRIV (chat);
380 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
382 gtk_text_buffer_get_bounds (buffer, &start, &end);
383 msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
385 /* clear the input field */
386 gtk_text_buffer_set_text (buffer, "", -1);
388 chat_send (chat, msg);
393 chat_state_changed_cb (EmpathyTpChat *tp_chat,
394 EmpathyContact *contact,
395 TpChannelChatState state,
398 EmpathyChatPriv *priv;
400 gboolean was_composing;
402 priv = GET_PRIV (chat);
404 if (empathy_contact_is_user (contact)) {
405 /* We don't care about our own chat state */
409 was_composing = (priv->compositors != NULL);
411 /* Find the contact in the list. After that l is the list elem or NULL */
412 for (l = priv->compositors; l; l = l->next) {
413 if (contact == l->data) {
419 case TP_CHANNEL_CHAT_STATE_GONE:
420 case TP_CHANNEL_CHAT_STATE_INACTIVE:
421 case TP_CHANNEL_CHAT_STATE_PAUSED:
422 case TP_CHANNEL_CHAT_STATE_ACTIVE:
423 /* Contact is not composing */
425 priv->compositors = g_list_remove_link (priv->compositors, l);
426 g_object_unref (l->data);
430 case TP_CHANNEL_CHAT_STATE_COMPOSING:
431 /* Contact is composing */
433 priv->compositors = g_list_prepend (priv->compositors,
434 g_object_ref (contact));
438 g_assert_not_reached ();
441 DEBUG ("Was composing: %s now composing: %s",
442 was_composing ? "yes" : "no",
443 priv->compositors ? "yes" : "no");
445 if ((was_composing && !priv->compositors) ||
446 (!was_composing && priv->compositors)) {
447 /* Composing state changed */
448 g_signal_emit (chat, signals[COMPOSING], 0,
449 priv->compositors != NULL);
454 chat_message_received_cb (EmpathyTpChat *tp_chat,
455 EmpathyMessage *message,
458 EmpathyChatPriv *priv = GET_PRIV (chat);
459 EmpathyContact *sender;
461 sender = empathy_message_get_sender (message);
463 DEBUG ("Appending new message from %s (%d)",
464 empathy_contact_get_name (sender),
465 empathy_contact_get_handle (sender));
468 gboolean is_chatroom;
470 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
471 empathy_log_manager_add_message (priv->log_manager,
472 priv->id, is_chatroom,
476 empathy_chat_view_append_message (chat->view, message);
478 /* We received a message so the contact is no more composing */
479 chat_state_changed_cb (tp_chat, sender,
480 TP_CHANNEL_CHAT_STATE_ACTIVE,
483 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
487 chat_send_error_cb (EmpathyTpChat *tp_chat,
488 EmpathyMessage *message,
489 TpChannelTextSendError error_code,
495 switch (error_code) {
496 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
497 error = _("offline");
499 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
500 error = _("invalid contact");
502 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
503 error = _("permission denied");
505 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
506 error = _("too long message");
508 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
509 error = _("not implemented");
512 error = _("unknown");
516 str = g_strdup_printf (_("Error sending message '%s': %s"),
517 empathy_message_get_body (message),
519 empathy_chat_view_append_event (chat->view, str);
524 chat_property_changed_cb (EmpathyTpChat *tp_chat,
529 EmpathyChatPriv *priv = GET_PRIV (chat);
531 if (!tp_strdiff (name, "subject")) {
532 g_free (priv->subject);
533 priv->subject = g_value_dup_string (value);
534 g_object_notify (G_OBJECT (chat), "subject");
536 if (G_STR_EMPTY (priv->subject)) {
537 gtk_widget_hide (priv->hbox_topic);
539 gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
540 gtk_widget_show (priv->hbox_topic);
542 if (priv->block_events_timeout_id == 0) {
545 if (!G_STR_EMPTY (priv->subject)) {
546 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
548 str = g_strdup (_("No topic defined"));
550 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
554 else if (!tp_strdiff (name, "name")) {
556 priv->name = g_value_dup_string (value);
557 g_object_notify (G_OBJECT (chat), "name");
562 chat_get_is_command (const gchar *str)
564 g_return_val_if_fail (str != NULL, FALSE);
570 if (g_str_has_prefix (str, "/me")) {
573 else if (g_str_has_prefix (str, "/nick")) {
576 else if (g_str_has_prefix (str, "/topic")) {
584 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
587 EmpathyChatPriv *priv;
588 GtkTextIter start, end;
590 gboolean spell_checker = FALSE;
592 priv = GET_PRIV (chat);
594 if (gtk_text_buffer_get_char_count (buffer) == 0) {
595 chat_composing_stop (chat);
597 chat_composing_start (chat);
600 empathy_conf_get_bool (empathy_conf_get (),
601 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
604 gtk_text_buffer_get_start_iter (buffer, &start);
606 if (!spell_checker) {
607 gtk_text_buffer_get_end_iter (buffer, &end);
608 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
612 if (!empathy_spell_supported ()) {
616 /* NOTE: this is really inefficient, we shouldn't have to
617 reiterate the whole buffer each time and check each work
620 gboolean correct = FALSE;
623 if (gtk_text_iter_is_start (&start)) {
626 if (!gtk_text_iter_forward_word_end (&end)) {
627 /* no whole word yet */
631 if (!gtk_text_iter_forward_word_end (&end)) {
632 /* must be the end of the buffer */
637 gtk_text_iter_backward_word_start (&start);
640 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
642 /* spell check string */
643 if (!chat_get_is_command (str)) {
644 correct = empathy_spell_check (str);
650 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
652 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
657 /* set start iter to the end iters position */
663 chat_input_key_press_event_cb (GtkWidget *widget,
667 EmpathyChatPriv *priv;
670 GtkWidget *text_view_sw;
672 priv = GET_PRIV (chat);
674 /* Catch ctrl+up/down so we can traverse messages we sent */
675 if ((event->state & GDK_CONTROL_MASK) &&
676 (event->keyval == GDK_Up ||
677 event->keyval == GDK_Down)) {
678 GtkTextBuffer *buffer;
681 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
683 if (event->keyval == GDK_Up) {
684 str = chat_sent_message_get_next (chat);
686 str = chat_sent_message_get_last (chat);
689 g_signal_handlers_block_by_func (buffer,
690 chat_input_text_buffer_changed_cb,
692 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
693 g_signal_handlers_unblock_by_func (buffer,
694 chat_input_text_buffer_changed_cb,
700 /* Catch enter but not ctrl/shift-enter */
701 if (IS_ENTER (event->keyval) &&
702 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
705 /* This is to make sure that kinput2 gets the enter. And if
706 * it's handled there we shouldn't send on it. This is because
707 * kinput2 uses Enter to commit letters. See:
708 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
711 view = GTK_TEXT_VIEW (chat->input_text_view);
712 if (gtk_im_context_filter_keypress (view->im_context, event)) {
713 GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
717 chat_input_text_view_send (chat);
721 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
723 if (IS_ENTER (event->keyval) &&
724 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
725 /* Newline for shift/control-enter. */
728 if (!(event->state & GDK_CONTROL_MASK) &&
729 event->keyval == GDK_Page_Up) {
730 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
731 gtk_adjustment_set_value (adj, adj->value - adj->page_size);
734 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
735 event->keyval == GDK_Page_Down) {
736 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
737 val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
738 gtk_adjustment_set_value (adj, val);
741 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
742 event->keyval == GDK_Tab) {
743 GtkTextBuffer *buffer;
744 GtkTextIter start, current;
745 gchar *nick, *completed;
746 GList *list, *completed_list;
747 gboolean is_start_of_buffer;
749 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
750 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
752 /* Get the start of the nick to complete. */
753 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
754 gtk_text_iter_backward_word_start (&start);
755 is_start_of_buffer = gtk_text_iter_is_start (&start);
757 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
758 g_completion_add_items (priv->completion, list);
760 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
761 completed_list = g_completion_complete (priv->completion,
770 gchar *complete_char = NULL;
772 gtk_text_buffer_delete (buffer, &start, ¤t);
774 len = g_list_length (completed_list);
777 /* If we only have one hit, use that text
778 * instead of the text in completed since the
779 * completed text will use the typed string
780 * which might be cased all wrong.
783 text = empathy_contact_get_name (completed_list->data);
788 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
790 if (len == 1 && is_start_of_buffer &&
791 empathy_conf_get_string (empathy_conf_get (),
792 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
794 complete_char != NULL) {
795 gtk_text_buffer_insert_at_cursor (buffer,
797 strlen (complete_char));
798 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
799 g_free (complete_char);
805 g_completion_clear_items (priv->completion);
807 g_list_foreach (list, (GFunc) g_object_unref, NULL);
817 chat_text_view_focus_in_event_cb (GtkWidget *widget,
821 gtk_widget_grab_focus (chat->input_text_view);
827 chat_input_set_size_request_idle (gpointer sw)
829 gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT);
835 chat_input_size_request_cb (GtkWidget *widget,
836 GtkRequisition *requisition,
839 EmpathyChatPriv *priv = GET_PRIV (chat);
842 sw = gtk_widget_get_parent (widget);
843 if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) {
844 g_idle_add (chat_input_set_size_request_idle, sw);
845 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
848 priv->has_input_vscroll = TRUE;
851 if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) {
852 gtk_widget_set_size_request (sw, -1, -1);
853 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
856 priv->has_input_vscroll = FALSE;
861 chat_input_realize_cb (GtkWidget *widget,
864 DEBUG ("Setting focus to the input text view");
865 gtk_widget_grab_focus (widget);
869 chat_insert_smiley_activate_cb (GtkWidget *menuitem,
872 GtkTextBuffer *buffer;
876 smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
878 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
880 gtk_text_buffer_get_end_iter (buffer, &iter);
881 gtk_text_buffer_insert (buffer, &iter, smiley, -1);
883 gtk_text_buffer_get_end_iter (buffer, &iter);
884 gtk_text_buffer_insert (buffer, &iter, " ", -1);
895 static EmpathyChatSpell *
896 chat_spell_new (EmpathyChat *chat,
901 EmpathyChatSpell *chat_spell;
903 chat_spell = g_slice_new0 (EmpathyChatSpell);
905 chat_spell->chat = g_object_ref (chat);
906 chat_spell->word = g_strdup (word);
907 chat_spell->start = start;
908 chat_spell->end = end;
914 chat_spell_free (EmpathyChatSpell *chat_spell)
916 g_object_unref (chat_spell->chat);
917 g_free (chat_spell->word);
918 g_slice_free (EmpathyChatSpell, chat_spell);
922 chat_text_check_word_spelling_cb (GtkMenuItem *menuitem,
923 EmpathyChatSpell *chat_spell)
925 empathy_spell_dialog_show (chat_spell->chat,
932 chat_text_send_cb (GtkMenuItem *menuitem,
935 chat_input_text_view_send (chat);
939 chat_input_populate_popup_cb (GtkTextView *view,
943 EmpathyChatPriv *priv;
944 GtkTextBuffer *buffer;
945 GtkTextTagTable *table;
948 GtkTextIter iter, start, end;
951 EmpathyChatSpell *chat_spell;
952 GtkWidget *smiley_menu;
955 priv = GET_PRIV (chat);
956 buffer = gtk_text_view_get_buffer (view);
958 /* Add the emoticon menu. */
959 item = gtk_separator_menu_item_new ();
960 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
961 gtk_widget_show (item);
963 item = gtk_image_menu_item_new_with_mnemonic (_("Insert Smiley"));
964 image = gtk_image_new_from_icon_name ("face-smile",
966 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
967 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
968 gtk_widget_show (item);
970 smiley_menu = empathy_chat_view_get_smiley_menu (
971 G_CALLBACK (chat_insert_smiley_activate_cb),
973 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
975 /* Add the Send menu item. */
976 gtk_text_buffer_get_bounds (buffer, &start, &end);
977 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
978 if (!G_STR_EMPTY (str)) {
979 item = gtk_menu_item_new_with_mnemonic (_("_Send"));
980 g_signal_connect (G_OBJECT (item), "activate",
981 G_CALLBACK (chat_text_send_cb), chat);
982 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
983 gtk_widget_show (item);
987 /* Add the spell check menu item. */
988 table = gtk_text_buffer_get_tag_table (buffer);
989 tag = gtk_text_tag_table_lookup (table, "misspelled");
990 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
991 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
992 GTK_TEXT_WINDOW_WIDGET,
995 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
997 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
998 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1000 str = gtk_text_buffer_get_text (buffer,
1001 &start, &end, FALSE);
1003 if (!G_STR_EMPTY (str)) {
1004 chat_spell = chat_spell_new (chat, str, start, end);
1005 g_object_set_data_full (G_OBJECT (menu),
1006 "chat_spell", chat_spell,
1007 (GDestroyNotify) chat_spell_free);
1009 item = gtk_separator_menu_item_new ();
1010 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1011 gtk_widget_show (item);
1013 item = gtk_image_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
1014 image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK,
1015 GTK_ICON_SIZE_MENU);
1016 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1017 g_signal_connect (item,
1019 G_CALLBACK (chat_text_check_word_spelling_cb),
1021 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1022 gtk_widget_show (item);
1027 chat_add_logs (EmpathyChat *chat)
1029 EmpathyChatPriv *priv = GET_PRIV (chat);
1030 gboolean is_chatroom;
1031 GList *messages, *l;
1039 /* Turn off scrolling temporarily */
1040 empathy_chat_view_scroll (chat->view, FALSE);
1042 /* Add messages from last conversation */
1043 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
1044 messages = empathy_log_manager_get_last_messages (priv->log_manager,
1048 num_messages = g_list_length (messages);
1050 /* Only keep the 10 last messages */
1051 for (i = 0; num_messages - i > 10; i++) {
1052 EmpathyMessage *message;
1054 message = messages->data;
1055 messages = g_list_remove (messages, message);
1056 g_object_unref (message);
1059 for (l = messages; l; l = l->next) {
1060 empathy_chat_view_append_message (chat->view, l->data);
1061 g_object_unref (l->data);
1063 g_list_free (messages);
1065 /* Turn back on scrolling */
1066 empathy_chat_view_scroll (chat->view, TRUE);
1070 chat_contacts_completion_func (const gchar *s1,
1074 gchar *tmp, *nick1, *nick2;
1081 return s1 ? -1 : +1;
1084 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
1085 nick1 = g_utf8_casefold (tmp, -1);
1088 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
1089 nick2 = g_utf8_casefold (tmp, -1);
1092 ret = strncmp (nick1, nick2, n);
1101 chat_members_changed_cb (EmpathyTpChat *tp_chat,
1102 EmpathyContact *contact,
1103 EmpathyContact *actor,
1109 EmpathyChatPriv *priv = GET_PRIV (chat);
1111 if (priv->block_events_timeout_id == 0) {
1114 empathy_contact_run_until_ready (contact,
1115 EMPATHY_CONTACT_READY_NAME,
1119 str = g_strdup_printf (_("%s has joined the room"),
1120 empathy_contact_get_name (contact));
1122 str = g_strdup_printf (_("%s has left the room"),
1123 empathy_contact_get_name (contact));
1125 empathy_chat_view_append_event (chat->view, str);
1131 chat_reset_size_request (gpointer widget)
1133 gtk_widget_set_size_request (widget, -1, -1);
1139 chat_set_show_contacts (EmpathyChat *chat, gboolean show)
1141 EmpathyChatPriv *priv = GET_PRIV (chat);
1143 if (!priv->scrolled_window_contacts) {
1148 EmpathyContactListStore *store;
1151 /* We are adding the contact list to the chat, we don't want the
1152 * chat view to become too small. If the chat view is already
1153 * smaller than 250 make sure that size won't change. If the
1154 * chat view is bigger the contact list will take some space on
1155 * it but we make sure the chat view don't become smaller than
1156 * 250. Relax the size request once the resize is done */
1157 min_width = MIN (priv->vbox_left->allocation.width, 250);
1158 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
1159 g_idle_add (chat_reset_size_request, priv->vbox_left);
1161 if (priv->contacts_width > 0) {
1162 gtk_paned_set_position (GTK_PANED (priv->hpaned),
1163 priv->contacts_width);
1166 store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
1167 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
1168 EMPATHY_CONTACT_LIST_FEATURE_NONE,
1169 EMPATHY_CONTACT_FEATURE_CHAT |
1170 EMPATHY_CONTACT_FEATURE_CALL |
1171 EMPATHY_CONTACT_FEATURE_LOG |
1172 EMPATHY_CONTACT_FEATURE_INFO));
1173 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
1174 priv->contact_list_view);
1175 gtk_widget_show (priv->contact_list_view);
1176 gtk_widget_show (priv->scrolled_window_contacts);
1177 g_object_unref (store);
1179 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
1180 gtk_widget_hide (priv->scrolled_window_contacts);
1181 if (priv->contact_list_view) {
1182 gtk_widget_destroy (priv->contact_list_view);
1183 priv->contact_list_view = NULL;
1189 chat_remote_contact_changed_cb (EmpathyChat *chat)
1191 EmpathyChatPriv *priv = GET_PRIV (chat);
1193 if (priv->remote_contact) {
1194 g_object_unref (priv->remote_contact);
1195 priv->remote_contact = NULL;
1198 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
1199 if (priv->remote_contact) {
1200 g_object_ref (priv->remote_contact);
1201 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
1203 priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
1205 else if (priv->tp_chat) {
1208 channel = empathy_tp_chat_get_channel (priv->tp_chat);
1209 g_object_get (channel, "handle-type", &priv->handle_type, NULL);
1211 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
1214 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1216 g_object_notify (G_OBJECT (chat), "remote-contact");
1217 g_object_notify (G_OBJECT (chat), "id");
1221 chat_destroy_cb (EmpathyTpChat *tp_chat,
1224 EmpathyChatPriv *priv;
1226 priv = GET_PRIV (chat);
1228 if (!priv->tp_chat) {
1232 g_object_unref (priv->tp_chat);
1233 priv->tp_chat = NULL;
1234 g_object_notify (G_OBJECT (chat), "tp-chat");
1236 empathy_chat_view_append_event (chat->view, _("Disconnected"));
1237 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
1238 chat_set_show_contacts (chat, FALSE);
1242 chat_create_ui (EmpathyChat *chat)
1244 EmpathyChatPriv *priv = GET_PRIV (chat);
1248 GtkTextBuffer *buffer;
1250 filename = empathy_file_lookup ("empathy-chat.glade",
1252 glade = empathy_glade_get_file (filename,
1255 "chat_widget", &priv->widget,
1256 "hpaned", &priv->hpaned,
1257 "vbox_left", &priv->vbox_left,
1258 "scrolled_window_chat", &priv->scrolled_window_chat,
1259 "scrolled_window_input", &priv->scrolled_window_input,
1260 "hbox_topic", &priv->hbox_topic,
1261 "label_topic", &priv->label_topic,
1262 "scrolled_window_contacts", &priv->scrolled_window_contacts,
1265 g_object_unref (glade);
1267 /* Add message GtkTextView. */
1268 chat->view = empathy_chat_view_new ();
1269 g_signal_connect (chat->view, "focus_in_event",
1270 G_CALLBACK (chat_text_view_focus_in_event_cb),
1272 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
1273 GTK_WIDGET (chat->view));
1274 gtk_widget_show (GTK_WIDGET (chat->view));
1276 /* Add input GtkTextView */
1277 chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
1278 "pixels-above-lines", 2,
1279 "pixels-below-lines", 2,
1280 "pixels-inside-wrap", 1,
1283 "wrap-mode", GTK_WRAP_WORD_CHAR,
1285 g_signal_connect (chat->input_text_view, "key-press-event",
1286 G_CALLBACK (chat_input_key_press_event_cb),
1288 g_signal_connect (chat->input_text_view, "size-request",
1289 G_CALLBACK (chat_input_size_request_cb),
1291 g_signal_connect (chat->input_text_view, "realize",
1292 G_CALLBACK (chat_input_realize_cb),
1294 g_signal_connect (chat->input_text_view, "populate-popup",
1295 G_CALLBACK (chat_input_populate_popup_cb),
1297 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1298 g_signal_connect (buffer, "changed",
1299 G_CALLBACK (chat_input_text_buffer_changed_cb),
1301 gtk_text_buffer_create_tag (buffer, "misspelled",
1302 "underline", PANGO_UNDERLINE_ERROR,
1304 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
1305 chat->input_text_view);
1306 gtk_widget_show (chat->input_text_view);
1308 /* Create contact list */
1309 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1311 /* Initialy hide the topic, will be shown if not empty */
1312 gtk_widget_hide (priv->hbox_topic);
1314 /* Set widget focus order */
1315 list = g_list_append (NULL, priv->scrolled_window_input);
1316 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
1319 list = g_list_append (NULL, priv->vbox_left);
1320 list = g_list_append (list, priv->scrolled_window_contacts);
1321 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
1324 list = g_list_append (NULL, priv->hpaned);
1325 list = g_list_append (list, priv->hbox_topic);
1326 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
1329 /* Add the main widget in the chat widget */
1330 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
1334 chat_size_request (GtkWidget *widget,
1335 GtkRequisition *requisition)
1337 GtkBin *bin = GTK_BIN (widget);
1339 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
1340 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
1342 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1344 GtkRequisition child_requisition;
1346 gtk_widget_size_request (bin->child, &child_requisition);
1348 requisition->width += child_requisition.width;
1349 requisition->height += child_requisition.height;
1354 chat_size_allocate (GtkWidget *widget,
1355 GtkAllocation *allocation)
1357 GtkBin *bin = GTK_BIN (widget);
1358 GtkAllocation child_allocation;
1360 widget->allocation = *allocation;
1362 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1364 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1365 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
1366 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
1367 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
1369 gtk_widget_size_allocate (bin->child, &child_allocation);
1374 chat_finalize (GObject *object)
1377 EmpathyChatPriv *priv;
1379 chat = EMPATHY_CHAT (object);
1380 priv = GET_PRIV (chat);
1382 DEBUG ("Finalized: %p", object);
1384 g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
1385 g_slist_free (priv->sent_messages);
1387 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
1388 g_list_free (priv->compositors);
1390 chat_composing_remove_timeout (chat);
1392 empathy_disconnect_account_status_changed (priv->token);
1393 g_object_unref (priv->mc);
1394 g_object_unref (priv->log_manager);
1396 if (priv->tp_chat) {
1397 g_object_unref (priv->tp_chat);
1399 if (priv->account) {
1400 g_object_unref (priv->account);
1402 if (priv->remote_contact) {
1403 g_object_unref (priv->remote_contact);
1406 if (priv->block_events_timeout_id) {
1407 g_source_remove (priv->block_events_timeout_id);
1411 g_free (priv->name);
1412 g_free (priv->subject);
1414 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
1418 chat_constructed (GObject *object)
1420 EmpathyChat *chat = EMPATHY_CHAT (object);
1422 chat_create_ui (chat);
1423 chat_add_logs (chat);
1427 empathy_chat_class_init (EmpathyChatClass *klass)
1429 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1430 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1432 object_class->finalize = chat_finalize;
1433 object_class->get_property = chat_get_property;
1434 object_class->set_property = chat_set_property;
1435 object_class->constructed = chat_constructed;
1437 widget_class->size_request = chat_size_request;
1438 widget_class->size_allocate = chat_size_allocate;
1440 g_object_class_install_property (object_class,
1442 g_param_spec_object ("tp-chat",
1444 "The tp chat object",
1445 EMPATHY_TYPE_TP_CHAT,
1447 G_PARAM_READWRITE));
1448 g_object_class_install_property (object_class,
1450 g_param_spec_object ("account",
1451 "Account of the chat",
1452 "The account of the chat",
1455 g_object_class_install_property (object_class,
1457 g_param_spec_string ("id",
1459 "The id of the chat",
1462 g_object_class_install_property (object_class,
1464 g_param_spec_string ("name",
1466 "The name of the chat",
1469 g_object_class_install_property (object_class,
1471 g_param_spec_string ("subject",
1473 "The subject or topic of the chat",
1476 g_object_class_install_property (object_class,
1477 PROP_REMOTE_CONTACT,
1478 g_param_spec_object ("remote-contact",
1479 "The remote contact",
1480 "The remote contact is any",
1481 EMPATHY_TYPE_CONTACT,
1484 signals[COMPOSING] =
1485 g_signal_new ("composing",
1486 G_OBJECT_CLASS_TYPE (object_class),
1490 g_cclosure_marshal_VOID__BOOLEAN,
1494 signals[NEW_MESSAGE] =
1495 g_signal_new ("new-message",
1496 G_OBJECT_CLASS_TYPE (object_class),
1500 g_cclosure_marshal_VOID__OBJECT,
1502 1, EMPATHY_TYPE_MESSAGE);
1504 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
1508 chat_block_events_timeout_cb (gpointer data)
1510 EmpathyChatPriv *priv = GET_PRIV (data);
1512 priv->block_events_timeout_id = 0;
1518 empathy_chat_init (EmpathyChat *chat)
1520 EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1521 EMPATHY_TYPE_CHAT, EmpathyChatPriv);
1524 priv->log_manager = empathy_log_manager_new ();
1525 priv->contacts_width = -1;
1526 priv->sent_messages = NULL;
1527 priv->sent_messages_index = -1;
1528 priv->mc = empathy_mission_control_new ();
1530 priv->token = empathy_connect_to_account_status_changed (priv->mc,
1531 G_CALLBACK (chat_status_changed_cb),
1534 /* Block events for some time to avoid having "has come online" or
1535 * "joined" messages. */
1536 priv->block_events_timeout_id =
1537 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
1539 /* Add nick name completion */
1540 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
1541 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
1545 empathy_chat_new (EmpathyTpChat *tp_chat)
1547 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
1551 empathy_chat_get_tp_chat (EmpathyChat *chat)
1553 EmpathyChatPriv *priv = GET_PRIV (chat);
1555 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1557 return priv->tp_chat;
1561 empathy_chat_set_tp_chat (EmpathyChat *chat,
1562 EmpathyTpChat *tp_chat)
1564 EmpathyChatPriv *priv = GET_PRIV (chat);
1566 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1567 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
1568 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
1570 if (priv->tp_chat) {
1574 if (priv->account) {
1575 g_object_unref (priv->account);
1578 priv->tp_chat = g_object_ref (tp_chat);
1579 priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
1581 g_signal_connect (tp_chat, "message-received",
1582 G_CALLBACK (chat_message_received_cb),
1584 g_signal_connect (tp_chat, "send-error",
1585 G_CALLBACK (chat_send_error_cb),
1587 g_signal_connect (tp_chat, "chat-state-changed",
1588 G_CALLBACK (chat_state_changed_cb),
1590 g_signal_connect (tp_chat, "property-changed",
1591 G_CALLBACK (chat_property_changed_cb),
1593 g_signal_connect (tp_chat, "members-changed",
1594 G_CALLBACK (chat_members_changed_cb),
1596 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
1597 G_CALLBACK (chat_remote_contact_changed_cb),
1599 g_signal_connect (tp_chat, "destroy",
1600 G_CALLBACK (chat_destroy_cb),
1603 chat_remote_contact_changed_cb (chat);
1605 if (chat->input_text_view) {
1606 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
1607 if (priv->block_events_timeout_id == 0) {
1608 empathy_chat_view_append_event (chat->view, _("Connected"));
1612 empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
1613 empathy_tp_chat_emit_pendings (priv->tp_chat);
1615 g_object_notify (G_OBJECT (chat), "tp-chat");
1616 g_object_notify (G_OBJECT (chat), "id");
1617 g_object_notify (G_OBJECT (chat), "account");
1621 empathy_chat_get_account (EmpathyChat *chat)
1623 EmpathyChatPriv *priv = GET_PRIV (chat);
1625 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1627 return priv->account;
1631 empathy_chat_get_id (EmpathyChat *chat)
1633 EmpathyChatPriv *priv = GET_PRIV (chat);
1635 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1641 empathy_chat_get_name (EmpathyChat *chat)
1643 EmpathyChatPriv *priv = GET_PRIV (chat);
1645 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1651 empathy_chat_get_subject (EmpathyChat *chat)
1653 EmpathyChatPriv *priv = GET_PRIV (chat);
1655 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1657 return priv->subject;
1661 empathy_chat_get_remote_contact (EmpathyChat *chat)
1663 EmpathyChatPriv *priv = GET_PRIV (chat);
1665 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1667 return priv->remote_contact;
1671 empathy_chat_get_members_count (EmpathyChat *chat)
1673 EmpathyChatPriv *priv = GET_PRIV (chat);
1675 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
1677 if (priv->tp_chat) {
1678 return empathy_tp_chat_get_members_count (priv->tp_chat);
1685 empathy_chat_get_contact_menu (EmpathyChat *chat)
1687 EmpathyChatPriv *priv = GET_PRIV (chat);
1688 GtkWidget *menu = NULL;
1690 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1692 if (priv->remote_contact) {
1693 menu = empathy_contact_menu_new (priv->remote_contact,
1694 EMPATHY_CONTACT_FEATURE_CALL |
1695 EMPATHY_CONTACT_FEATURE_LOG |
1696 EMPATHY_CONTACT_FEATURE_INFO);
1698 else if (priv->contact_list_view) {
1699 EmpathyContactListView *view;
1701 view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
1702 menu = empathy_contact_list_view_get_contact_menu (view);
1709 empathy_chat_clear (EmpathyChat *chat)
1711 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1713 empathy_chat_view_clear (chat->view);
1717 empathy_chat_scroll_down (EmpathyChat *chat)
1719 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1721 empathy_chat_view_scroll_down (chat->view);
1725 empathy_chat_cut (EmpathyChat *chat)
1727 GtkTextBuffer *buffer;
1729 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1731 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1732 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1733 GtkClipboard *clipboard;
1735 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1737 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1742 empathy_chat_copy (EmpathyChat *chat)
1744 GtkTextBuffer *buffer;
1746 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1748 if (empathy_chat_view_get_selection_bounds (chat->view, NULL, NULL)) {
1749 empathy_chat_view_copy_clipboard (chat->view);
1753 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1754 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1755 GtkClipboard *clipboard;
1757 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1759 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1764 empathy_chat_paste (EmpathyChat *chat)
1766 GtkTextBuffer *buffer;
1767 GtkClipboard *clipboard;
1769 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1771 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1772 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1774 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1778 empathy_chat_correct_word (EmpathyChat *chat,
1781 const gchar *new_word)
1783 GtkTextBuffer *buffer;
1785 g_return_if_fail (chat != NULL);
1786 g_return_if_fail (new_word != NULL);
1788 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1790 gtk_text_buffer_delete (buffer, start, end);
1791 gtk_text_buffer_insert (buffer, start,