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 <telepathy-glib/util.h>
39 #include <libempathy/empathy-account-manager.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-theme-manager.h"
52 #include "empathy-smiley-manager.h"
53 #include "empathy-ui-utils.h"
55 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
56 #include <libempathy/empathy-debug.h>
58 #define CHAT_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
59 #define CHAT_FILE_CREATE_MODE (S_IRUSR | S_IWUSR)
60 #define IS_ENTER(v) (v == GDK_Return || v == GDK_ISO_Enter || v == GDK_KP_Enter)
61 #define MAX_INPUT_HEIGHT 150
62 #define COMPOSING_STOP_TIMEOUT 5
64 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat)
66 EmpathyTpChat *tp_chat;
71 EmpathyContact *remote_contact;
73 EmpathyLogManager *log_manager;
74 EmpathyAccountManager *account_manager;
75 GSList *sent_messages;
76 gint sent_messages_index;
78 GCompletion *completion;
79 guint composing_stop_timeout_id;
80 guint block_events_timeout_id;
81 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 EmpathyChat *chat = EMPATHY_CHAT (object);
123 EmpathyChatPriv *priv = GET_PRIV (object);
127 g_value_set_object (value, priv->tp_chat);
130 g_value_set_object (value, priv->account);
133 g_value_set_string (value, empathy_chat_get_name (chat));
136 g_value_set_string (value, priv->id);
139 g_value_set_string (value, priv->subject);
141 case PROP_REMOTE_CONTACT:
142 g_value_set_object (value, priv->remote_contact);
145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
151 chat_set_property (GObject *object,
156 EmpathyChat *chat = EMPATHY_CHAT (object);
160 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
169 chat_connection_changed_cb (EmpathyAccountManager *manager,
171 TpConnectionStatusReason reason,
172 TpConnectionStatus current,
173 TpConnectionStatus previous,
176 EmpathyChatPriv *priv = GET_PRIV (chat);
178 if (current == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
179 empathy_account_equal (account, priv->account) &&
180 priv->handle_type != TP_HANDLE_TYPE_NONE) {
181 TpConnection *connection;
184 DEBUG ("Account reconnected, request a new Text channel");
186 mc = empathy_mission_control_new ();
187 connection = mission_control_get_tpconnection (mc, account, NULL);
188 tp_connection_run_until_ready (connection, FALSE, NULL, NULL);
189 empathy_connection_request_channel (connection, -1,
190 TP_IFACE_CHANNEL_TYPE_TEXT,
193 NULL, NULL, NULL, NULL);
194 g_object_unref (connection);
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 (EmpathySmileyManager *manager,
871 EmpathySmiley *smiley,
874 EmpathyChat *chat = EMPATHY_CHAT (user_data);
875 GtkTextBuffer *buffer;
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->str, -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 EmpathySmileyManager *smiley_manager;
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_manager = empathy_smiley_manager_dup_singleton ();
972 smiley_menu = empathy_smiley_menu_new (smiley_manager,
973 chat_insert_smiley_activate_cb,
975 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
976 g_object_unref (smiley_manager);
978 /* Add the Send menu item. */
979 gtk_text_buffer_get_bounds (buffer, &start, &end);
980 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
981 if (!G_STR_EMPTY (str)) {
982 item = gtk_menu_item_new_with_mnemonic (_("_Send"));
983 g_signal_connect (G_OBJECT (item), "activate",
984 G_CALLBACK (chat_text_send_cb), chat);
985 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
986 gtk_widget_show (item);
990 /* Add the spell check menu item. */
991 table = gtk_text_buffer_get_tag_table (buffer);
992 tag = gtk_text_tag_table_lookup (table, "misspelled");
993 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
994 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
995 GTK_TEXT_WINDOW_WIDGET,
998 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
1000 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
1001 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1003 str = gtk_text_buffer_get_text (buffer,
1004 &start, &end, FALSE);
1006 if (!G_STR_EMPTY (str)) {
1007 chat_spell = chat_spell_new (chat, str, start, end);
1008 g_object_set_data_full (G_OBJECT (menu),
1009 "chat_spell", chat_spell,
1010 (GDestroyNotify) chat_spell_free);
1012 item = gtk_separator_menu_item_new ();
1013 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1014 gtk_widget_show (item);
1016 item = gtk_image_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
1017 image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK,
1018 GTK_ICON_SIZE_MENU);
1019 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1020 g_signal_connect (item,
1022 G_CALLBACK (chat_text_check_word_spelling_cb),
1024 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1025 gtk_widget_show (item);
1030 chat_add_logs (EmpathyChat *chat)
1032 EmpathyChatPriv *priv = GET_PRIV (chat);
1033 gboolean is_chatroom;
1034 GList *messages, *l;
1042 /* Turn off scrolling temporarily */
1043 empathy_chat_view_scroll (chat->view, FALSE);
1045 /* Add messages from last conversation */
1046 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
1047 messages = empathy_log_manager_get_last_messages (priv->log_manager,
1051 num_messages = g_list_length (messages);
1053 /* Only keep the 10 last messages */
1054 for (i = 0; num_messages - i > 10; i++) {
1055 EmpathyMessage *message;
1057 message = messages->data;
1058 messages = g_list_remove (messages, message);
1059 g_object_unref (message);
1062 for (l = messages; l; l = l->next) {
1063 empathy_chat_view_append_message (chat->view, l->data);
1064 g_object_unref (l->data);
1066 g_list_free (messages);
1068 /* Turn back on scrolling */
1069 empathy_chat_view_scroll (chat->view, TRUE);
1073 chat_contacts_completion_func (const gchar *s1,
1077 gchar *tmp, *nick1, *nick2;
1084 return s1 ? -1 : +1;
1087 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
1088 nick1 = g_utf8_casefold (tmp, -1);
1091 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
1092 nick2 = g_utf8_casefold (tmp, -1);
1095 ret = strncmp (nick1, nick2, n);
1104 chat_members_changed_cb (EmpathyTpChat *tp_chat,
1105 EmpathyContact *contact,
1106 EmpathyContact *actor,
1112 EmpathyChatPriv *priv = GET_PRIV (chat);
1114 if (priv->block_events_timeout_id == 0) {
1117 empathy_contact_run_until_ready (contact,
1118 EMPATHY_CONTACT_READY_NAME,
1122 str = g_strdup_printf (_("%s has joined the room"),
1123 empathy_contact_get_name (contact));
1125 str = g_strdup_printf (_("%s has left the room"),
1126 empathy_contact_get_name (contact));
1128 empathy_chat_view_append_event (chat->view, str);
1134 chat_reset_size_request (gpointer widget)
1136 gtk_widget_set_size_request (widget, -1, -1);
1142 chat_set_show_contacts (EmpathyChat *chat, gboolean show)
1144 EmpathyChatPriv *priv = GET_PRIV (chat);
1146 if (!priv->scrolled_window_contacts) {
1151 EmpathyContactListStore *store;
1154 /* We are adding the contact list to the chat, we don't want the
1155 * chat view to become too small. If the chat view is already
1156 * smaller than 250 make sure that size won't change. If the
1157 * chat view is bigger the contact list will take some space on
1158 * it but we make sure the chat view don't become smaller than
1159 * 250. Relax the size request once the resize is done */
1160 min_width = MIN (priv->vbox_left->allocation.width, 250);
1161 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
1162 g_idle_add (chat_reset_size_request, priv->vbox_left);
1164 if (priv->contacts_width > 0) {
1165 gtk_paned_set_position (GTK_PANED (priv->hpaned),
1166 priv->contacts_width);
1169 store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
1170 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
1171 EMPATHY_CONTACT_LIST_FEATURE_NONE,
1172 EMPATHY_CONTACT_FEATURE_CHAT |
1173 EMPATHY_CONTACT_FEATURE_CALL |
1174 EMPATHY_CONTACT_FEATURE_LOG |
1175 EMPATHY_CONTACT_FEATURE_INFO));
1176 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
1177 priv->contact_list_view);
1178 gtk_widget_show (priv->contact_list_view);
1179 gtk_widget_show (priv->scrolled_window_contacts);
1180 g_object_unref (store);
1182 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
1183 gtk_widget_hide (priv->scrolled_window_contacts);
1184 if (priv->contact_list_view) {
1185 gtk_widget_destroy (priv->contact_list_view);
1186 priv->contact_list_view = NULL;
1192 chat_remote_contact_changed_cb (EmpathyChat *chat)
1194 EmpathyChatPriv *priv = GET_PRIV (chat);
1196 if (priv->remote_contact) {
1197 g_object_unref (priv->remote_contact);
1198 priv->remote_contact = NULL;
1201 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
1202 if (priv->remote_contact) {
1203 g_object_ref (priv->remote_contact);
1204 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
1206 priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
1208 else if (priv->tp_chat) {
1211 channel = empathy_tp_chat_get_channel (priv->tp_chat);
1212 g_object_get (channel, "handle-type", &priv->handle_type, NULL);
1214 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
1217 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1219 g_object_notify (G_OBJECT (chat), "remote-contact");
1220 g_object_notify (G_OBJECT (chat), "id");
1224 chat_destroy_cb (EmpathyTpChat *tp_chat,
1227 EmpathyChatPriv *priv;
1229 priv = GET_PRIV (chat);
1231 if (!priv->tp_chat) {
1235 g_object_unref (priv->tp_chat);
1236 priv->tp_chat = NULL;
1237 g_object_notify (G_OBJECT (chat), "tp-chat");
1239 empathy_chat_view_append_event (chat->view, _("Disconnected"));
1240 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
1241 chat_set_show_contacts (chat, FALSE);
1245 chat_create_ui (EmpathyChat *chat)
1247 EmpathyChatPriv *priv = GET_PRIV (chat);
1251 GtkTextBuffer *buffer;
1253 filename = empathy_file_lookup ("empathy-chat.glade",
1255 glade = empathy_glade_get_file (filename,
1258 "chat_widget", &priv->widget,
1259 "hpaned", &priv->hpaned,
1260 "vbox_left", &priv->vbox_left,
1261 "scrolled_window_chat", &priv->scrolled_window_chat,
1262 "scrolled_window_input", &priv->scrolled_window_input,
1263 "hbox_topic", &priv->hbox_topic,
1264 "label_topic", &priv->label_topic,
1265 "scrolled_window_contacts", &priv->scrolled_window_contacts,
1268 g_object_unref (glade);
1270 /* Add message view. */
1271 chat->view = empathy_theme_manager_create_view (empathy_theme_manager_get ());
1272 g_signal_connect (chat->view, "focus_in_event",
1273 G_CALLBACK (chat_text_view_focus_in_event_cb),
1275 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
1276 GTK_WIDGET (chat->view));
1277 gtk_widget_show (GTK_WIDGET (chat->view));
1279 /* Add input GtkTextView */
1280 chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
1281 "pixels-above-lines", 2,
1282 "pixels-below-lines", 2,
1283 "pixels-inside-wrap", 1,
1286 "wrap-mode", GTK_WRAP_WORD_CHAR,
1288 g_signal_connect (chat->input_text_view, "key-press-event",
1289 G_CALLBACK (chat_input_key_press_event_cb),
1291 g_signal_connect (chat->input_text_view, "size-request",
1292 G_CALLBACK (chat_input_size_request_cb),
1294 g_signal_connect (chat->input_text_view, "realize",
1295 G_CALLBACK (chat_input_realize_cb),
1297 g_signal_connect (chat->input_text_view, "populate-popup",
1298 G_CALLBACK (chat_input_populate_popup_cb),
1300 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1301 g_signal_connect (buffer, "changed",
1302 G_CALLBACK (chat_input_text_buffer_changed_cb),
1304 gtk_text_buffer_create_tag (buffer, "misspelled",
1305 "underline", PANGO_UNDERLINE_ERROR,
1307 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
1308 chat->input_text_view);
1309 gtk_widget_show (chat->input_text_view);
1311 /* Create contact list */
1312 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1314 /* Initialy hide the topic, will be shown if not empty */
1315 gtk_widget_hide (priv->hbox_topic);
1317 /* Set widget focus order */
1318 list = g_list_append (NULL, priv->scrolled_window_input);
1319 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
1322 list = g_list_append (NULL, priv->vbox_left);
1323 list = g_list_append (list, priv->scrolled_window_contacts);
1324 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
1327 list = g_list_append (NULL, priv->hpaned);
1328 list = g_list_append (list, priv->hbox_topic);
1329 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
1332 /* Add the main widget in the chat widget */
1333 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
1337 chat_size_request (GtkWidget *widget,
1338 GtkRequisition *requisition)
1340 GtkBin *bin = GTK_BIN (widget);
1342 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
1343 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
1345 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1347 GtkRequisition child_requisition;
1349 gtk_widget_size_request (bin->child, &child_requisition);
1351 requisition->width += child_requisition.width;
1352 requisition->height += child_requisition.height;
1357 chat_size_allocate (GtkWidget *widget,
1358 GtkAllocation *allocation)
1360 GtkBin *bin = GTK_BIN (widget);
1361 GtkAllocation child_allocation;
1363 widget->allocation = *allocation;
1365 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1367 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1368 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
1369 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
1370 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
1372 gtk_widget_size_allocate (bin->child, &child_allocation);
1377 chat_finalize (GObject *object)
1380 EmpathyChatPriv *priv;
1382 chat = EMPATHY_CHAT (object);
1383 priv = GET_PRIV (chat);
1385 DEBUG ("Finalized: %p", object);
1387 g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
1388 g_slist_free (priv->sent_messages);
1390 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
1391 g_list_free (priv->compositors);
1393 chat_composing_remove_timeout (chat);
1395 g_signal_handlers_disconnect_by_func (priv->account_manager,
1396 chat_connection_changed_cb, object);
1398 g_object_unref (priv->account_manager);
1399 g_object_unref (priv->log_manager);
1401 if (priv->tp_chat) {
1402 g_object_unref (priv->tp_chat);
1404 if (priv->account) {
1405 g_object_unref (priv->account);
1407 if (priv->remote_contact) {
1408 g_object_unref (priv->remote_contact);
1411 if (priv->block_events_timeout_id) {
1412 g_source_remove (priv->block_events_timeout_id);
1416 g_free (priv->name);
1417 g_free (priv->subject);
1419 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
1423 chat_constructed (GObject *object)
1425 EmpathyChat *chat = EMPATHY_CHAT (object);
1427 chat_create_ui (chat);
1428 chat_add_logs (chat);
1432 empathy_chat_class_init (EmpathyChatClass *klass)
1434 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
1435 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1437 object_class->finalize = chat_finalize;
1438 object_class->get_property = chat_get_property;
1439 object_class->set_property = chat_set_property;
1440 object_class->constructed = chat_constructed;
1442 widget_class->size_request = chat_size_request;
1443 widget_class->size_allocate = chat_size_allocate;
1445 g_object_class_install_property (object_class,
1447 g_param_spec_object ("tp-chat",
1449 "The tp chat object",
1450 EMPATHY_TYPE_TP_CHAT,
1452 G_PARAM_READWRITE));
1453 g_object_class_install_property (object_class,
1455 g_param_spec_object ("account",
1456 "Account of the chat",
1457 "The account of the chat",
1460 g_object_class_install_property (object_class,
1462 g_param_spec_string ("id",
1464 "The id of the chat",
1467 g_object_class_install_property (object_class,
1469 g_param_spec_string ("name",
1471 "The name of the chat",
1474 g_object_class_install_property (object_class,
1476 g_param_spec_string ("subject",
1478 "The subject or topic of the chat",
1481 g_object_class_install_property (object_class,
1482 PROP_REMOTE_CONTACT,
1483 g_param_spec_object ("remote-contact",
1484 "The remote contact",
1485 "The remote contact is any",
1486 EMPATHY_TYPE_CONTACT,
1489 signals[COMPOSING] =
1490 g_signal_new ("composing",
1491 G_OBJECT_CLASS_TYPE (object_class),
1495 g_cclosure_marshal_VOID__BOOLEAN,
1499 signals[NEW_MESSAGE] =
1500 g_signal_new ("new-message",
1501 G_OBJECT_CLASS_TYPE (object_class),
1505 g_cclosure_marshal_VOID__OBJECT,
1507 1, EMPATHY_TYPE_MESSAGE);
1509 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
1513 chat_block_events_timeout_cb (gpointer data)
1515 EmpathyChatPriv *priv = GET_PRIV (data);
1517 priv->block_events_timeout_id = 0;
1523 empathy_chat_init (EmpathyChat *chat)
1525 EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
1526 EMPATHY_TYPE_CHAT, EmpathyChatPriv);
1529 priv->log_manager = empathy_log_manager_dup_singleton ();
1530 priv->contacts_width = -1;
1531 priv->sent_messages = NULL;
1532 priv->sent_messages_index = -1;
1533 priv->account_manager = empathy_account_manager_dup_singleton ();
1535 g_signal_connect (priv->account_manager,
1536 "account-connection-changed",
1537 G_CALLBACK (chat_connection_changed_cb),
1540 /* Block events for some time to avoid having "has come online" or
1541 * "joined" messages. */
1542 priv->block_events_timeout_id =
1543 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
1545 /* Add nick name completion */
1546 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
1547 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
1551 empathy_chat_new (EmpathyTpChat *tp_chat)
1553 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
1557 empathy_chat_get_tp_chat (EmpathyChat *chat)
1559 EmpathyChatPriv *priv = GET_PRIV (chat);
1561 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1563 return priv->tp_chat;
1567 empathy_chat_set_tp_chat (EmpathyChat *chat,
1568 EmpathyTpChat *tp_chat)
1570 EmpathyChatPriv *priv = GET_PRIV (chat);
1572 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1573 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
1574 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
1576 if (priv->tp_chat) {
1580 if (priv->account) {
1581 g_object_unref (priv->account);
1584 priv->tp_chat = g_object_ref (tp_chat);
1585 priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
1587 g_signal_connect (tp_chat, "message-received",
1588 G_CALLBACK (chat_message_received_cb),
1590 g_signal_connect (tp_chat, "send-error",
1591 G_CALLBACK (chat_send_error_cb),
1593 g_signal_connect (tp_chat, "chat-state-changed",
1594 G_CALLBACK (chat_state_changed_cb),
1596 g_signal_connect (tp_chat, "property-changed",
1597 G_CALLBACK (chat_property_changed_cb),
1599 g_signal_connect (tp_chat, "members-changed",
1600 G_CALLBACK (chat_members_changed_cb),
1602 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
1603 G_CALLBACK (chat_remote_contact_changed_cb),
1605 g_signal_connect (tp_chat, "destroy",
1606 G_CALLBACK (chat_destroy_cb),
1609 chat_remote_contact_changed_cb (chat);
1611 if (chat->input_text_view) {
1612 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
1613 if (priv->block_events_timeout_id == 0) {
1614 empathy_chat_view_append_event (chat->view, _("Connected"));
1618 empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
1619 empathy_tp_chat_emit_pendings (priv->tp_chat);
1621 g_object_notify (G_OBJECT (chat), "tp-chat");
1622 g_object_notify (G_OBJECT (chat), "id");
1623 g_object_notify (G_OBJECT (chat), "account");
1627 empathy_chat_get_account (EmpathyChat *chat)
1629 EmpathyChatPriv *priv = GET_PRIV (chat);
1631 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1633 return priv->account;
1637 empathy_chat_get_id (EmpathyChat *chat)
1639 EmpathyChatPriv *priv = GET_PRIV (chat);
1641 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1647 empathy_chat_get_name (EmpathyChat *chat)
1649 EmpathyChatPriv *priv = GET_PRIV (chat);
1652 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1655 if (!ret && priv->remote_contact) {
1656 ret = empathy_contact_get_name (priv->remote_contact);
1662 return ret ? ret : _("Conversation");
1666 empathy_chat_get_subject (EmpathyChat *chat)
1668 EmpathyChatPriv *priv = GET_PRIV (chat);
1670 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1672 return priv->subject;
1676 empathy_chat_get_remote_contact (EmpathyChat *chat)
1678 EmpathyChatPriv *priv = GET_PRIV (chat);
1680 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1682 return priv->remote_contact;
1686 empathy_chat_get_members_count (EmpathyChat *chat)
1688 EmpathyChatPriv *priv = GET_PRIV (chat);
1690 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
1692 if (priv->tp_chat) {
1693 return empathy_tp_chat_get_members_count (priv->tp_chat);
1700 empathy_chat_get_contact_menu (EmpathyChat *chat)
1702 EmpathyChatPriv *priv = GET_PRIV (chat);
1703 GtkWidget *menu = NULL;
1705 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1707 if (priv->remote_contact) {
1708 menu = empathy_contact_menu_new (priv->remote_contact,
1709 EMPATHY_CONTACT_FEATURE_CALL |
1710 EMPATHY_CONTACT_FEATURE_LOG |
1711 EMPATHY_CONTACT_FEATURE_INFO);
1713 else if (priv->contact_list_view) {
1714 EmpathyContactListView *view;
1716 view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
1717 menu = empathy_contact_list_view_get_contact_menu (view);
1724 empathy_chat_clear (EmpathyChat *chat)
1726 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1728 empathy_chat_view_clear (chat->view);
1732 empathy_chat_scroll_down (EmpathyChat *chat)
1734 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1736 empathy_chat_view_scroll_down (chat->view);
1740 empathy_chat_cut (EmpathyChat *chat)
1742 GtkTextBuffer *buffer;
1744 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1746 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1747 if (gtk_text_buffer_get_has_selection (buffer)) {
1748 GtkClipboard *clipboard;
1750 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1752 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1757 empathy_chat_copy (EmpathyChat *chat)
1759 GtkTextBuffer *buffer;
1761 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1763 if (empathy_chat_view_get_has_selection (chat->view)) {
1764 empathy_chat_view_copy_clipboard (chat->view);
1768 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1769 if (gtk_text_buffer_get_has_selection (buffer)) {
1770 GtkClipboard *clipboard;
1772 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1774 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1779 empathy_chat_paste (EmpathyChat *chat)
1781 GtkTextBuffer *buffer;
1782 GtkClipboard *clipboard;
1784 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1786 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1787 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1789 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1793 empathy_chat_correct_word (EmpathyChat *chat,
1796 const gchar *new_word)
1798 GtkTextBuffer *buffer;
1800 g_return_if_fail (chat != NULL);
1801 g_return_if_fail (new_word != NULL);
1803 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1805 gtk_text_buffer_delete (buffer, start, end);
1806 gtk_text_buffer_insert (buffer, start,
1812 empathy_chat_is_room (EmpathyChat *chat)
1814 EmpathyChatPriv *priv = GET_PRIV (chat);
1816 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
1818 return (priv->handle_type == TP_HANDLE_TYPE_ROOM);