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-lib.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 EmpathyChat *chat = EMPATHY_CHAT (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, empathy_chat_get_name (chat));
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 TpConnection *connection;
185 DEBUG ("Account reconnected, request a new Text channel");
186 connection = mission_control_get_tpconnection (mc, account, NULL);
187 tp_connection_run_until_ready (connection, FALSE, NULL, NULL);
188 empathy_connection_request_channel (connection, -1,
189 TP_IFACE_CHANNEL_TYPE_TEXT,
192 NULL, NULL, NULL, NULL);
193 g_object_unref (connection);
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 = GET_PRIV (chat);
460 EmpathyContact *sender;
462 sender = empathy_message_get_sender (message);
464 DEBUG ("Appending new message from %s (%d)",
465 empathy_contact_get_name (sender),
466 empathy_contact_get_handle (sender));
469 gboolean is_chatroom;
471 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
472 empathy_log_manager_add_message (priv->log_manager,
473 priv->id, is_chatroom,
477 empathy_chat_view_append_message (chat->view, message);
479 /* We received a message so the contact is no more composing */
480 chat_state_changed_cb (tp_chat, sender,
481 TP_CHANNEL_CHAT_STATE_ACTIVE,
484 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
488 chat_send_error_cb (EmpathyTpChat *tp_chat,
489 EmpathyMessage *message,
490 TpChannelTextSendError error_code,
496 switch (error_code) {
497 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
498 error = _("offline");
500 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
501 error = _("invalid contact");
503 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
504 error = _("permission denied");
506 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
507 error = _("too long message");
509 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
510 error = _("not implemented");
513 error = _("unknown");
517 str = g_strdup_printf (_("Error sending message '%s': %s"),
518 empathy_message_get_body (message),
520 empathy_chat_view_append_event (chat->view, str);
525 chat_property_changed_cb (EmpathyTpChat *tp_chat,
530 EmpathyChatPriv *priv = GET_PRIV (chat);
532 if (!tp_strdiff (name, "subject")) {
533 g_free (priv->subject);
534 priv->subject = g_value_dup_string (value);
535 g_object_notify (G_OBJECT (chat), "subject");
537 if (G_STR_EMPTY (priv->subject)) {
538 gtk_widget_hide (priv->hbox_topic);
540 gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
541 gtk_widget_show (priv->hbox_topic);
543 if (priv->block_events_timeout_id == 0) {
546 if (!G_STR_EMPTY (priv->subject)) {
547 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
549 str = g_strdup (_("No topic defined"));
551 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
555 else if (!tp_strdiff (name, "name")) {
557 priv->name = g_value_dup_string (value);
558 g_object_notify (G_OBJECT (chat), "name");
563 chat_get_is_command (const gchar *str)
565 g_return_val_if_fail (str != NULL, FALSE);
571 if (g_str_has_prefix (str, "/me")) {
574 else if (g_str_has_prefix (str, "/nick")) {
577 else if (g_str_has_prefix (str, "/topic")) {
585 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
588 EmpathyChatPriv *priv;
589 GtkTextIter start, end;
591 gboolean spell_checker = FALSE;
593 priv = GET_PRIV (chat);
595 if (gtk_text_buffer_get_char_count (buffer) == 0) {
596 chat_composing_stop (chat);
598 chat_composing_start (chat);
601 empathy_conf_get_bool (empathy_conf_get (),
602 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
605 gtk_text_buffer_get_start_iter (buffer, &start);
607 if (!spell_checker) {
608 gtk_text_buffer_get_end_iter (buffer, &end);
609 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
613 if (!empathy_spell_supported ()) {
617 /* NOTE: this is really inefficient, we shouldn't have to
618 reiterate the whole buffer each time and check each work
621 gboolean correct = FALSE;
624 if (gtk_text_iter_is_start (&start)) {
627 if (!gtk_text_iter_forward_word_end (&end)) {
628 /* no whole word yet */
632 if (!gtk_text_iter_forward_word_end (&end)) {
633 /* must be the end of the buffer */
638 gtk_text_iter_backward_word_start (&start);
641 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
643 /* spell check string */
644 if (!chat_get_is_command (str)) {
645 correct = empathy_spell_check (str);
651 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
653 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
658 /* set start iter to the end iters position */
664 chat_input_key_press_event_cb (GtkWidget *widget,
668 EmpathyChatPriv *priv;
671 GtkWidget *text_view_sw;
673 priv = GET_PRIV (chat);
675 /* Catch ctrl+up/down so we can traverse messages we sent */
676 if ((event->state & GDK_CONTROL_MASK) &&
677 (event->keyval == GDK_Up ||
678 event->keyval == GDK_Down)) {
679 GtkTextBuffer *buffer;
682 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
684 if (event->keyval == GDK_Up) {
685 str = chat_sent_message_get_next (chat);
687 str = chat_sent_message_get_last (chat);
690 g_signal_handlers_block_by_func (buffer,
691 chat_input_text_buffer_changed_cb,
693 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
694 g_signal_handlers_unblock_by_func (buffer,
695 chat_input_text_buffer_changed_cb,
701 /* Catch enter but not ctrl/shift-enter */
702 if (IS_ENTER (event->keyval) &&
703 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
706 /* This is to make sure that kinput2 gets the enter. And if
707 * it's handled there we shouldn't send on it. This is because
708 * kinput2 uses Enter to commit letters. See:
709 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
712 view = GTK_TEXT_VIEW (chat->input_text_view);
713 if (gtk_im_context_filter_keypress (view->im_context, event)) {
714 GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
718 chat_input_text_view_send (chat);
722 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
724 if (IS_ENTER (event->keyval) &&
725 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
726 /* Newline for shift/control-enter. */
729 if (!(event->state & GDK_CONTROL_MASK) &&
730 event->keyval == GDK_Page_Up) {
731 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
732 gtk_adjustment_set_value (adj, adj->value - adj->page_size);
735 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
736 event->keyval == GDK_Page_Down) {
737 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
738 val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
739 gtk_adjustment_set_value (adj, val);
742 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
743 event->keyval == GDK_Tab) {
744 GtkTextBuffer *buffer;
745 GtkTextIter start, current;
746 gchar *nick, *completed;
747 GList *list, *completed_list;
748 gboolean is_start_of_buffer;
750 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
751 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
753 /* Get the start of the nick to complete. */
754 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
755 gtk_text_iter_backward_word_start (&start);
756 is_start_of_buffer = gtk_text_iter_is_start (&start);
758 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
759 g_completion_add_items (priv->completion, list);
761 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
762 completed_list = g_completion_complete (priv->completion,
771 gchar *complete_char = NULL;
773 gtk_text_buffer_delete (buffer, &start, ¤t);
775 len = g_list_length (completed_list);
778 /* If we only have one hit, use that text
779 * instead of the text in completed since the
780 * completed text will use the typed string
781 * which might be cased all wrong.
784 text = empathy_contact_get_name (completed_list->data);
789 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
791 if (len == 1 && is_start_of_buffer &&
792 empathy_conf_get_string (empathy_conf_get (),
793 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
795 complete_char != NULL) {
796 gtk_text_buffer_insert_at_cursor (buffer,
798 strlen (complete_char));
799 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
800 g_free (complete_char);
806 g_completion_clear_items (priv->completion);
808 g_list_foreach (list, (GFunc) g_object_unref, NULL);
818 chat_text_view_focus_in_event_cb (GtkWidget *widget,
822 gtk_widget_grab_focus (chat->input_text_view);
828 chat_input_set_size_request_idle (gpointer sw)
830 gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT);
836 chat_input_size_request_cb (GtkWidget *widget,
837 GtkRequisition *requisition,
840 EmpathyChatPriv *priv = GET_PRIV (chat);
843 sw = gtk_widget_get_parent (widget);
844 if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) {
845 g_idle_add (chat_input_set_size_request_idle, sw);
846 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
849 priv->has_input_vscroll = TRUE;
852 if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) {
853 gtk_widget_set_size_request (sw, -1, -1);
854 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
857 priv->has_input_vscroll = FALSE;
862 chat_input_realize_cb (GtkWidget *widget,
865 DEBUG ("Setting focus to the input text view");
866 gtk_widget_grab_focus (widget);
870 chat_insert_smiley_activate_cb (GtkWidget *menuitem,
873 GtkTextBuffer *buffer;
877 smiley = g_object_get_data (G_OBJECT (menuitem), "smiley_text");
879 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
881 gtk_text_buffer_get_end_iter (buffer, &iter);
882 gtk_text_buffer_insert (buffer, &iter, smiley, -1);
884 gtk_text_buffer_get_end_iter (buffer, &iter);
885 gtk_text_buffer_insert (buffer, &iter, " ", -1);
896 static EmpathyChatSpell *
897 chat_spell_new (EmpathyChat *chat,
902 EmpathyChatSpell *chat_spell;
904 chat_spell = g_slice_new0 (EmpathyChatSpell);
906 chat_spell->chat = g_object_ref (chat);
907 chat_spell->word = g_strdup (word);
908 chat_spell->start = start;
909 chat_spell->end = end;
915 chat_spell_free (EmpathyChatSpell *chat_spell)
917 g_object_unref (chat_spell->chat);
918 g_free (chat_spell->word);
919 g_slice_free (EmpathyChatSpell, chat_spell);
923 chat_text_check_word_spelling_cb (GtkMenuItem *menuitem,
924 EmpathyChatSpell *chat_spell)
926 empathy_spell_dialog_show (chat_spell->chat,
933 chat_text_send_cb (GtkMenuItem *menuitem,
936 chat_input_text_view_send (chat);
940 chat_input_populate_popup_cb (GtkTextView *view,
944 EmpathyChatPriv *priv;
945 GtkTextBuffer *buffer;
946 GtkTextTagTable *table;
949 GtkTextIter iter, start, end;
952 EmpathyChatSpell *chat_spell;
953 GtkWidget *smiley_menu;
956 priv = GET_PRIV (chat);
957 buffer = gtk_text_view_get_buffer (view);
959 /* Add the emoticon menu. */
960 item = gtk_separator_menu_item_new ();
961 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
962 gtk_widget_show (item);
964 item = gtk_image_menu_item_new_with_mnemonic (_("Insert Smiley"));
965 image = gtk_image_new_from_icon_name ("face-smile",
967 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
968 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
969 gtk_widget_show (item);
971 smiley_menu = empathy_chat_view_get_smiley_menu (
972 G_CALLBACK (chat_insert_smiley_activate_cb),
974 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
976 /* Add the Send menu item. */
977 gtk_text_buffer_get_bounds (buffer, &start, &end);
978 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
979 if (!G_STR_EMPTY (str)) {
980 item = gtk_menu_item_new_with_mnemonic (_("_Send"));
981 g_signal_connect (G_OBJECT (item), "activate",
982 G_CALLBACK (chat_text_send_cb), chat);
983 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
984 gtk_widget_show (item);
988 /* Add the spell check menu item. */
989 table = gtk_text_buffer_get_tag_table (buffer);
990 tag = gtk_text_tag_table_lookup (table, "misspelled");
991 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
992 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
993 GTK_TEXT_WINDOW_WIDGET,
996 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
998 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
999 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1001 str = gtk_text_buffer_get_text (buffer,
1002 &start, &end, FALSE);
1004 if (!G_STR_EMPTY (str)) {
1005 chat_spell = chat_spell_new (chat, str, start, end);
1006 g_object_set_data_full (G_OBJECT (menu),
1007 "chat_spell", chat_spell,
1008 (GDestroyNotify) chat_spell_free);
1010 item = gtk_separator_menu_item_new ();
1011 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1012 gtk_widget_show (item);
1014 item = gtk_image_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
1015 image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK,
1016 GTK_ICON_SIZE_MENU);
1017 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1018 g_signal_connect (item,
1020 G_CALLBACK (chat_text_check_word_spelling_cb),
1022 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1023 gtk_widget_show (item);
1028 chat_add_logs (EmpathyChat *chat)
1030 EmpathyChatPriv *priv = GET_PRIV (chat);
1031 gboolean is_chatroom;
1032 GList *messages, *l;
1040 /* Turn off scrolling temporarily */
1041 empathy_chat_view_scroll (chat->view, FALSE);
1043 /* Add messages from last conversation */
1044 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
1045 messages = empathy_log_manager_get_last_messages (priv->log_manager,
1049 num_messages = g_list_length (messages);
1051 /* Only keep the 10 last messages */
1052 for (i = 0; num_messages - i > 10; i++) {
1053 EmpathyMessage *message;
1055 message = messages->data;
1056 messages = g_list_remove (messages, message);
1057 g_object_unref (message);
1060 for (l = messages; l; l = l->next) {
1061 empathy_chat_view_append_message (chat->view, l->data);
1062 g_object_unref (l->data);
1064 g_list_free (messages);
1066 /* Turn back on scrolling */
1067 empathy_chat_view_scroll (chat->view, TRUE);
1071 chat_contacts_completion_func (const gchar *s1,
1075 gchar *tmp, *nick1, *nick2;
1082 return s1 ? -1 : +1;
1085 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
1086 nick1 = g_utf8_casefold (tmp, -1);
1089 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
1090 nick2 = g_utf8_casefold (tmp, -1);
1093 ret = strncmp (nick1, nick2, n);
1102 chat_members_changed_cb (EmpathyTpChat *tp_chat,
1103 EmpathyContact *contact,
1104 EmpathyContact *actor,
1110 EmpathyChatPriv *priv = GET_PRIV (chat);
1112 if (priv->block_events_timeout_id == 0) {
1115 empathy_contact_run_until_ready (contact,
1116 EMPATHY_CONTACT_READY_NAME,
1120 str = g_strdup_printf (_("%s has joined the room"),
1121 empathy_contact_get_name (contact));
1123 str = g_strdup_printf (_("%s has left the room"),
1124 empathy_contact_get_name (contact));
1126 empathy_chat_view_append_event (chat->view, str);
1132 chat_reset_size_request (gpointer widget)
1134 gtk_widget_set_size_request (widget, -1, -1);
1140 chat_set_show_contacts (EmpathyChat *chat, gboolean show)
1142 EmpathyChatPriv *priv = GET_PRIV (chat);
1144 if (!priv->scrolled_window_contacts) {
1149 EmpathyContactListStore *store;
1152 /* We are adding the contact list to the chat, we don't want the
1153 * chat view to become too small. If the chat view is already
1154 * smaller than 250 make sure that size won't change. If the
1155 * chat view is bigger the contact list will take some space on
1156 * it but we make sure the chat view don't become smaller than
1157 * 250. Relax the size request once the resize is done */
1158 min_width = MIN (priv->vbox_left->allocation.width, 250);
1159 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
1160 g_idle_add (chat_reset_size_request, priv->vbox_left);
1162 if (priv->contacts_width > 0) {
1163 gtk_paned_set_position (GTK_PANED (priv->hpaned),
1164 priv->contacts_width);
1167 store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
1168 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
1169 EMPATHY_CONTACT_LIST_FEATURE_NONE,
1170 EMPATHY_CONTACT_FEATURE_CHAT |
1171 EMPATHY_CONTACT_FEATURE_CALL |
1172 EMPATHY_CONTACT_FEATURE_LOG |
1173 EMPATHY_CONTACT_FEATURE_INFO));
1174 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
1175 priv->contact_list_view);
1176 gtk_widget_show (priv->contact_list_view);
1177 gtk_widget_show (priv->scrolled_window_contacts);
1178 g_object_unref (store);
1180 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
1181 gtk_widget_hide (priv->scrolled_window_contacts);
1182 if (priv->contact_list_view) {
1183 gtk_widget_destroy (priv->contact_list_view);
1184 priv->contact_list_view = NULL;
1190 chat_remote_contact_changed_cb (EmpathyChat *chat)
1192 EmpathyChatPriv *priv = GET_PRIV (chat);
1194 if (priv->remote_contact) {
1195 g_object_unref (priv->remote_contact);
1196 priv->remote_contact = NULL;
1199 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
1200 if (priv->remote_contact) {
1201 g_object_ref (priv->remote_contact);
1202 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
1204 priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
1206 else if (priv->tp_chat) {
1209 channel = empathy_tp_chat_get_channel (priv->tp_chat);
1210 g_object_get (channel, "handle-type", &priv->handle_type, NULL);
1212 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
1215 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1217 g_object_notify (G_OBJECT (chat), "remote-contact");
1218 g_object_notify (G_OBJECT (chat), "id");
1222 chat_destroy_cb (EmpathyTpChat *tp_chat,
1225 EmpathyChatPriv *priv;
1227 priv = GET_PRIV (chat);
1229 if (!priv->tp_chat) {
1233 g_object_unref (priv->tp_chat);
1234 priv->tp_chat = NULL;
1235 g_object_notify (G_OBJECT (chat), "tp-chat");
1237 empathy_chat_view_append_event (chat->view, _("Disconnected"));
1238 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
1239 chat_set_show_contacts (chat, FALSE);
1243 chat_create_ui (EmpathyChat *chat)
1245 EmpathyChatPriv *priv = GET_PRIV (chat);
1249 GtkTextBuffer *buffer;
1251 filename = empathy_file_lookup ("empathy-chat.glade",
1253 glade = empathy_glade_get_file (filename,
1256 "chat_widget", &priv->widget,
1257 "hpaned", &priv->hpaned,
1258 "vbox_left", &priv->vbox_left,
1259 "scrolled_window_chat", &priv->scrolled_window_chat,
1260 "scrolled_window_input", &priv->scrolled_window_input,
1261 "hbox_topic", &priv->hbox_topic,
1262 "label_topic", &priv->label_topic,
1263 "scrolled_window_contacts", &priv->scrolled_window_contacts,
1266 g_object_unref (glade);
1268 /* Add message GtkTextView. */
1269 chat->view = empathy_chat_view_new ();
1270 g_signal_connect (chat->view, "focus_in_event",
1271 G_CALLBACK (chat_text_view_focus_in_event_cb),
1273 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
1274 GTK_WIDGET (chat->view));
1275 gtk_widget_show (GTK_WIDGET (chat->view));
1277 /* Add input GtkTextView */
1278 chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
1279 "pixels-above-lines", 2,
1280 "pixels-below-lines", 2,
1281 "pixels-inside-wrap", 1,
1284 "wrap-mode", GTK_WRAP_WORD_CHAR,
1286 g_signal_connect (chat->input_text_view, "key-press-event",
1287 G_CALLBACK (chat_input_key_press_event_cb),
1289 g_signal_connect (chat->input_text_view, "size-request",
1290 G_CALLBACK (chat_input_size_request_cb),
1292 g_signal_connect (chat->input_text_view, "realize",
1293 G_CALLBACK (chat_input_realize_cb),
1295 g_signal_connect (chat->input_text_view, "populate-popup",
1296 G_CALLBACK (chat_input_populate_popup_cb),
1298 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1299 g_signal_connect (buffer, "changed",
1300 G_CALLBACK (chat_input_text_buffer_changed_cb),
1302 gtk_text_buffer_create_tag (buffer, "misspelled",
1303 "underline", PANGO_UNDERLINE_ERROR,
1305 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
1306 chat->input_text_view);
1307 gtk_widget_show (chat->input_text_view);
1309 /* Create contact list */
1310 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1312 /* Initialy hide the topic, will be shown if not empty */
1313 gtk_widget_hide (priv->hbox_topic);
1315 /* Set widget focus order */
1316 list = g_list_append (NULL, priv->scrolled_window_input);
1317 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
1320 list = g_list_append (NULL, priv->vbox_left);
1321 list = g_list_append (list, priv->scrolled_window_contacts);
1322 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
1325 list = g_list_append (NULL, priv->hpaned);
1326 list = g_list_append (list, priv->hbox_topic);
1327 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
1330 /* Add the main widget in the chat widget */
1331 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
1335 chat_size_request (GtkWidget *widget,
1336 GtkRequisition *requisition)
1338 GtkBin *bin = GTK_BIN (widget);
1340 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
1341 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
1343 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1345 GtkRequisition child_requisition;
1347 gtk_widget_size_request (bin->child, &child_requisition);
1349 requisition->width += child_requisition.width;
1350 requisition->height += child_requisition.height;
1355 chat_size_allocate (GtkWidget *widget,
1356 GtkAllocation *allocation)
1358 GtkBin *bin = GTK_BIN (widget);
1359 GtkAllocation child_allocation;
1361 widget->allocation = *allocation;
1363 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1365 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1366 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
1367 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
1368 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
1370 gtk_widget_size_allocate (bin->child, &child_allocation);
1375 chat_finalize (GObject *object)
1378 EmpathyChatPriv *priv;
1380 chat = EMPATHY_CHAT (object);
1381 priv = GET_PRIV (chat);
1383 DEBUG ("Finalized: %p", object);
1385 g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
1386 g_slist_free (priv->sent_messages);
1388 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
1389 g_list_free (priv->compositors);
1391 chat_composing_remove_timeout (chat);
1393 empathy_disconnect_account_status_changed (priv->token);
1394 g_object_unref (priv->mc);
1395 g_object_unref (priv->log_manager);
1397 if (priv->tp_chat) {
1398 g_object_unref (priv->tp_chat);
1400 if (priv->account) {
1401 g_object_unref (priv->account);
1403 if (priv->remote_contact) {
1404 g_object_unref (priv->remote_contact);
1407 if (priv->block_events_timeout_id) {
1408 g_source_remove (priv->block_events_timeout_id);
1412 g_free (priv->name);
1413 g_free (priv->subject);
1415 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
1419 chat_constructed (GObject *object)
1421 EmpathyChat *chat = EMPATHY_CHAT (object);
1423 chat_create_ui (chat);
1424 chat_add_logs (chat);
1428 empathy_chat_class_init (EmpathyChatClass *klass)
1430 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1431 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1433 object_class->finalize = chat_finalize;
1434 object_class->get_property = chat_get_property;
1435 object_class->set_property = chat_set_property;
1436 object_class->constructed = chat_constructed;
1438 widget_class->size_request = chat_size_request;
1439 widget_class->size_allocate = chat_size_allocate;
1441 g_object_class_install_property (object_class,
1443 g_param_spec_object ("tp-chat",
1445 "The tp chat object",
1446 EMPATHY_TYPE_TP_CHAT,
1448 G_PARAM_READWRITE));
1449 g_object_class_install_property (object_class,
1451 g_param_spec_object ("account",
1452 "Account of the chat",
1453 "The account of the chat",
1456 g_object_class_install_property (object_class,
1458 g_param_spec_string ("id",
1460 "The id of the chat",
1463 g_object_class_install_property (object_class,
1465 g_param_spec_string ("name",
1467 "The name of the chat",
1470 g_object_class_install_property (object_class,
1472 g_param_spec_string ("subject",
1474 "The subject or topic of the chat",
1477 g_object_class_install_property (object_class,
1478 PROP_REMOTE_CONTACT,
1479 g_param_spec_object ("remote-contact",
1480 "The remote contact",
1481 "The remote contact is any",
1482 EMPATHY_TYPE_CONTACT,
1485 signals[COMPOSING] =
1486 g_signal_new ("composing",
1487 G_OBJECT_CLASS_TYPE (object_class),
1491 g_cclosure_marshal_VOID__BOOLEAN,
1495 signals[NEW_MESSAGE] =
1496 g_signal_new ("new-message",
1497 G_OBJECT_CLASS_TYPE (object_class),
1501 g_cclosure_marshal_VOID__OBJECT,
1503 1, EMPATHY_TYPE_MESSAGE);
1505 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
1509 chat_block_events_timeout_cb (gpointer data)
1511 EmpathyChatPriv *priv = GET_PRIV (data);
1513 priv->block_events_timeout_id = 0;
1519 empathy_chat_init (EmpathyChat *chat)
1521 EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1522 EMPATHY_TYPE_CHAT, EmpathyChatPriv);
1525 priv->log_manager = empathy_log_manager_new ();
1526 priv->contacts_width = -1;
1527 priv->sent_messages = NULL;
1528 priv->sent_messages_index = -1;
1529 priv->mc = empathy_mission_control_new ();
1531 priv->token = empathy_connect_to_account_status_changed (priv->mc,
1532 G_CALLBACK (chat_status_changed_cb),
1535 /* Block events for some time to avoid having "has come online" or
1536 * "joined" messages. */
1537 priv->block_events_timeout_id =
1538 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
1540 /* Add nick name completion */
1541 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
1542 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
1546 empathy_chat_new (EmpathyTpChat *tp_chat)
1548 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
1552 empathy_chat_get_tp_chat (EmpathyChat *chat)
1554 EmpathyChatPriv *priv = GET_PRIV (chat);
1556 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1558 return priv->tp_chat;
1562 empathy_chat_set_tp_chat (EmpathyChat *chat,
1563 EmpathyTpChat *tp_chat)
1565 EmpathyChatPriv *priv = GET_PRIV (chat);
1567 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1568 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
1569 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
1571 if (priv->tp_chat) {
1575 if (priv->account) {
1576 g_object_unref (priv->account);
1579 priv->tp_chat = g_object_ref (tp_chat);
1580 priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
1582 g_signal_connect (tp_chat, "message-received",
1583 G_CALLBACK (chat_message_received_cb),
1585 g_signal_connect (tp_chat, "send-error",
1586 G_CALLBACK (chat_send_error_cb),
1588 g_signal_connect (tp_chat, "chat-state-changed",
1589 G_CALLBACK (chat_state_changed_cb),
1591 g_signal_connect (tp_chat, "property-changed",
1592 G_CALLBACK (chat_property_changed_cb),
1594 g_signal_connect (tp_chat, "members-changed",
1595 G_CALLBACK (chat_members_changed_cb),
1597 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
1598 G_CALLBACK (chat_remote_contact_changed_cb),
1600 g_signal_connect (tp_chat, "destroy",
1601 G_CALLBACK (chat_destroy_cb),
1604 chat_remote_contact_changed_cb (chat);
1606 if (chat->input_text_view) {
1607 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
1608 if (priv->block_events_timeout_id == 0) {
1609 empathy_chat_view_append_event (chat->view, _("Connected"));
1613 empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
1614 empathy_tp_chat_emit_pendings (priv->tp_chat);
1616 g_object_notify (G_OBJECT (chat), "tp-chat");
1617 g_object_notify (G_OBJECT (chat), "id");
1618 g_object_notify (G_OBJECT (chat), "account");
1622 empathy_chat_get_account (EmpathyChat *chat)
1624 EmpathyChatPriv *priv = GET_PRIV (chat);
1626 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1628 return priv->account;
1632 empathy_chat_get_id (EmpathyChat *chat)
1634 EmpathyChatPriv *priv = GET_PRIV (chat);
1636 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1642 empathy_chat_get_name (EmpathyChat *chat)
1644 EmpathyChatPriv *priv = GET_PRIV (chat);
1647 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1650 if (!ret && priv->remote_contact) {
1651 ret = empathy_contact_get_name (priv->remote_contact);
1657 return ret ? ret : _("Conversation");
1661 empathy_chat_get_subject (EmpathyChat *chat)
1663 EmpathyChatPriv *priv = GET_PRIV (chat);
1665 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1667 return priv->subject;
1671 empathy_chat_get_remote_contact (EmpathyChat *chat)
1673 EmpathyChatPriv *priv = GET_PRIV (chat);
1675 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1677 return priv->remote_contact;
1681 empathy_chat_get_members_count (EmpathyChat *chat)
1683 EmpathyChatPriv *priv = GET_PRIV (chat);
1685 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
1687 if (priv->tp_chat) {
1688 return empathy_tp_chat_get_members_count (priv->tp_chat);
1695 empathy_chat_get_contact_menu (EmpathyChat *chat)
1697 EmpathyChatPriv *priv = GET_PRIV (chat);
1698 GtkWidget *menu = NULL;
1700 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1702 if (priv->remote_contact) {
1703 menu = empathy_contact_menu_new (priv->remote_contact,
1704 EMPATHY_CONTACT_FEATURE_CALL |
1705 EMPATHY_CONTACT_FEATURE_LOG |
1706 EMPATHY_CONTACT_FEATURE_INFO);
1708 else if (priv->contact_list_view) {
1709 EmpathyContactListView *view;
1711 view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
1712 menu = empathy_contact_list_view_get_contact_menu (view);
1719 empathy_chat_clear (EmpathyChat *chat)
1721 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1723 empathy_chat_view_clear (chat->view);
1727 empathy_chat_scroll_down (EmpathyChat *chat)
1729 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1731 empathy_chat_view_scroll_down (chat->view);
1735 empathy_chat_cut (EmpathyChat *chat)
1737 GtkTextBuffer *buffer;
1739 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1741 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1742 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1743 GtkClipboard *clipboard;
1745 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1747 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1752 empathy_chat_copy (EmpathyChat *chat)
1754 GtkTextBuffer *buffer;
1756 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1758 if (empathy_chat_view_get_selection_bounds (chat->view, NULL, NULL)) {
1759 empathy_chat_view_copy_clipboard (chat->view);
1763 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1764 if (gtk_text_buffer_get_selection_bounds (buffer, NULL, NULL)) {
1765 GtkClipboard *clipboard;
1767 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1769 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1774 empathy_chat_paste (EmpathyChat *chat)
1776 GtkTextBuffer *buffer;
1777 GtkClipboard *clipboard;
1779 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1781 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1782 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1784 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1788 empathy_chat_correct_word (EmpathyChat *chat,
1791 const gchar *new_word)
1793 GtkTextBuffer *buffer;
1795 g_return_if_fail (chat != NULL);
1796 g_return_if_fail (new_word != NULL);
1798 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1800 gtk_text_buffer_delete (buffer, start, end);
1801 gtk_text_buffer_insert (buffer, start,
1807 empathy_chat_is_room (EmpathyChat *chat)
1809 EmpathyChatPriv *priv = GET_PRIV (chat);
1811 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
1813 return (priv->handle_type == TP_HANDLE_TYPE_ROOM);