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-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;
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;
84 gboolean has_input_vscroll;
89 GtkWidget *scrolled_window_chat;
90 GtkWidget *scrolled_window_input;
91 GtkWidget *scrolled_window_contacts;
92 GtkWidget *hbox_topic;
93 GtkWidget *label_topic;
94 GtkWidget *contact_list_view;
113 static guint signals[LAST_SIGNAL] = { 0 };
115 G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
118 chat_get_property (GObject *object,
123 EmpathyChat *chat = EMPATHY_CHAT (object);
124 EmpathyChatPriv *priv = GET_PRIV (object);
128 g_value_set_object (value, priv->tp_chat);
131 g_value_set_object (value, priv->account);
134 g_value_set_string (value, empathy_chat_get_name (chat));
137 g_value_set_string (value, priv->id);
140 g_value_set_string (value, priv->subject);
142 case PROP_REMOTE_CONTACT:
143 g_value_set_object (value, priv->remote_contact);
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
152 chat_set_property (GObject *object,
157 EmpathyChat *chat = EMPATHY_CHAT (object);
161 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
164 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
170 chat_status_changed_cb (MissionControl *mc,
171 TpConnectionStatus status,
173 TpConnectionStatusReason reason,
174 const gchar *unique_name,
177 EmpathyChatPriv *priv = GET_PRIV (chat);
180 account = mc_account_lookup (unique_name);
182 if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
183 empathy_account_equal (account, priv->account) &&
184 priv->handle_type != TP_HANDLE_TYPE_NONE) {
185 TpConnection *connection;
187 DEBUG ("Account reconnected, request a new Text channel");
188 connection = mission_control_get_tpconnection (mc, account, NULL);
189 tp_connection_run_until_ready (connection, FALSE, NULL, NULL);
190 empathy_connection_request_channel (connection, -1,
191 TP_IFACE_CHANNEL_TYPE_TEXT,
194 NULL, NULL, NULL, NULL);
195 g_object_unref (connection);
198 g_object_unref (account);
202 chat_composing_remove_timeout (EmpathyChat *chat)
204 EmpathyChatPriv *priv;
206 priv = GET_PRIV (chat);
208 if (priv->composing_stop_timeout_id) {
209 g_source_remove (priv->composing_stop_timeout_id);
210 priv->composing_stop_timeout_id = 0;
215 chat_composing_stop_timeout_cb (EmpathyChat *chat)
217 EmpathyChatPriv *priv;
219 priv = GET_PRIV (chat);
221 priv->composing_stop_timeout_id = 0;
222 empathy_tp_chat_set_state (priv->tp_chat,
223 TP_CHANNEL_CHAT_STATE_PAUSED);
229 chat_composing_start (EmpathyChat *chat)
231 EmpathyChatPriv *priv;
233 priv = GET_PRIV (chat);
235 if (priv->composing_stop_timeout_id) {
236 /* Just restart the timeout */
237 chat_composing_remove_timeout (chat);
239 empathy_tp_chat_set_state (priv->tp_chat,
240 TP_CHANNEL_CHAT_STATE_COMPOSING);
243 priv->composing_stop_timeout_id = g_timeout_add_seconds (
244 COMPOSING_STOP_TIMEOUT,
245 (GSourceFunc) chat_composing_stop_timeout_cb,
250 chat_composing_stop (EmpathyChat *chat)
252 EmpathyChatPriv *priv;
254 priv = GET_PRIV (chat);
256 chat_composing_remove_timeout (chat);
257 empathy_tp_chat_set_state (priv->tp_chat,
258 TP_CHANNEL_CHAT_STATE_ACTIVE);
262 chat_sent_message_add (EmpathyChat *chat,
265 EmpathyChatPriv *priv;
269 priv = GET_PRIV (chat);
271 /* Save the sent message in our repeat buffer */
272 list = priv->sent_messages;
274 /* Remove any other occurances of this msg */
275 while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) {
276 list = g_slist_remove_link (list, item);
278 g_slist_free1 (item);
281 /* Trim the list to the last 10 items */
282 while (g_slist_length (list) > 10) {
283 item = g_slist_last (list);
285 list = g_slist_remove_link (list, item);
287 g_slist_free1 (item);
291 /* Add new message */
292 list = g_slist_prepend (list, g_strdup (str));
294 /* Set list and reset the index */
295 priv->sent_messages = list;
296 priv->sent_messages_index = -1;
300 chat_sent_message_get_next (EmpathyChat *chat)
302 EmpathyChatPriv *priv;
305 priv = GET_PRIV (chat);
307 if (!priv->sent_messages) {
308 DEBUG ("No sent messages, next message is NULL");
312 max = g_slist_length (priv->sent_messages) - 1;
314 if (priv->sent_messages_index < max) {
315 priv->sent_messages_index++;
318 DEBUG ("Returning next message index:%d", priv->sent_messages_index);
320 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
324 chat_sent_message_get_last (EmpathyChat *chat)
326 EmpathyChatPriv *priv;
328 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
330 priv = GET_PRIV (chat);
332 if (!priv->sent_messages) {
333 DEBUG ("No sent messages, last message is NULL");
337 if (priv->sent_messages_index >= 0) {
338 priv->sent_messages_index--;
341 DEBUG ("Returning last message index:%d", priv->sent_messages_index);
343 return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
347 chat_send (EmpathyChat *chat,
350 EmpathyChatPriv *priv;
351 EmpathyMessage *message;
353 priv = GET_PRIV (chat);
355 if (G_STR_EMPTY (msg)) {
359 chat_sent_message_add (chat, msg);
361 if (g_str_has_prefix (msg, "/clear")) {
362 empathy_chat_view_clear (chat->view);
366 message = empathy_message_new (msg);
368 empathy_tp_chat_send (priv->tp_chat, message);
370 g_object_unref (message);
374 chat_input_text_view_send (EmpathyChat *chat)
376 EmpathyChatPriv *priv;
377 GtkTextBuffer *buffer;
378 GtkTextIter start, end;
381 priv = GET_PRIV (chat);
383 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
385 gtk_text_buffer_get_bounds (buffer, &start, &end);
386 msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
388 /* clear the input field */
389 gtk_text_buffer_set_text (buffer, "", -1);
391 chat_send (chat, msg);
396 chat_state_changed_cb (EmpathyTpChat *tp_chat,
397 EmpathyContact *contact,
398 TpChannelChatState state,
401 EmpathyChatPriv *priv;
403 gboolean was_composing;
405 priv = GET_PRIV (chat);
407 if (empathy_contact_is_user (contact)) {
408 /* We don't care about our own chat state */
412 was_composing = (priv->compositors != NULL);
414 /* Find the contact in the list. After that l is the list elem or NULL */
415 for (l = priv->compositors; l; l = l->next) {
416 if (contact == l->data) {
422 case TP_CHANNEL_CHAT_STATE_GONE:
423 case TP_CHANNEL_CHAT_STATE_INACTIVE:
424 case TP_CHANNEL_CHAT_STATE_PAUSED:
425 case TP_CHANNEL_CHAT_STATE_ACTIVE:
426 /* Contact is not composing */
428 priv->compositors = g_list_remove_link (priv->compositors, l);
429 g_object_unref (l->data);
433 case TP_CHANNEL_CHAT_STATE_COMPOSING:
434 /* Contact is composing */
436 priv->compositors = g_list_prepend (priv->compositors,
437 g_object_ref (contact));
441 g_assert_not_reached ();
444 DEBUG ("Was composing: %s now composing: %s",
445 was_composing ? "yes" : "no",
446 priv->compositors ? "yes" : "no");
448 if ((was_composing && !priv->compositors) ||
449 (!was_composing && priv->compositors)) {
450 /* Composing state changed */
451 g_signal_emit (chat, signals[COMPOSING], 0,
452 priv->compositors != NULL);
457 chat_message_received_cb (EmpathyTpChat *tp_chat,
458 EmpathyMessage *message,
461 EmpathyChatPriv *priv = GET_PRIV (chat);
462 EmpathyContact *sender;
464 sender = empathy_message_get_sender (message);
466 DEBUG ("Appending new message from %s (%d)",
467 empathy_contact_get_name (sender),
468 empathy_contact_get_handle (sender));
471 gboolean is_chatroom;
473 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
474 empathy_log_manager_add_message (priv->log_manager,
475 priv->id, is_chatroom,
479 empathy_chat_view_append_message (chat->view, message);
481 /* We received a message so the contact is no more composing */
482 chat_state_changed_cb (tp_chat, sender,
483 TP_CHANNEL_CHAT_STATE_ACTIVE,
486 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
490 chat_send_error_cb (EmpathyTpChat *tp_chat,
491 EmpathyMessage *message,
492 TpChannelTextSendError error_code,
498 switch (error_code) {
499 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
500 error = _("offline");
502 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
503 error = _("invalid contact");
505 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
506 error = _("permission denied");
508 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
509 error = _("too long message");
511 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
512 error = _("not implemented");
515 error = _("unknown");
519 str = g_strdup_printf (_("Error sending message '%s': %s"),
520 empathy_message_get_body (message),
522 empathy_chat_view_append_event (chat->view, str);
527 chat_property_changed_cb (EmpathyTpChat *tp_chat,
532 EmpathyChatPriv *priv = GET_PRIV (chat);
534 if (!tp_strdiff (name, "subject")) {
535 g_free (priv->subject);
536 priv->subject = g_value_dup_string (value);
537 g_object_notify (G_OBJECT (chat), "subject");
539 if (G_STR_EMPTY (priv->subject)) {
540 gtk_widget_hide (priv->hbox_topic);
542 gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
543 gtk_widget_show (priv->hbox_topic);
545 if (priv->block_events_timeout_id == 0) {
548 if (!G_STR_EMPTY (priv->subject)) {
549 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
551 str = g_strdup (_("No topic defined"));
553 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
557 else if (!tp_strdiff (name, "name")) {
559 priv->name = g_value_dup_string (value);
560 g_object_notify (G_OBJECT (chat), "name");
565 chat_get_is_command (const gchar *str)
567 g_return_val_if_fail (str != NULL, FALSE);
573 if (g_str_has_prefix (str, "/me")) {
576 else if (g_str_has_prefix (str, "/nick")) {
579 else if (g_str_has_prefix (str, "/topic")) {
587 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
590 EmpathyChatPriv *priv;
591 GtkTextIter start, end;
593 gboolean spell_checker = FALSE;
595 priv = GET_PRIV (chat);
597 if (gtk_text_buffer_get_char_count (buffer) == 0) {
598 chat_composing_stop (chat);
600 chat_composing_start (chat);
603 empathy_conf_get_bool (empathy_conf_get (),
604 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
607 gtk_text_buffer_get_start_iter (buffer, &start);
609 if (!spell_checker) {
610 gtk_text_buffer_get_end_iter (buffer, &end);
611 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
615 if (!empathy_spell_supported ()) {
619 /* NOTE: this is really inefficient, we shouldn't have to
620 reiterate the whole buffer each time and check each work
623 gboolean correct = FALSE;
626 if (gtk_text_iter_is_start (&start)) {
629 if (!gtk_text_iter_forward_word_end (&end)) {
630 /* no whole word yet */
634 if (!gtk_text_iter_forward_word_end (&end)) {
635 /* must be the end of the buffer */
640 gtk_text_iter_backward_word_start (&start);
643 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
645 /* spell check string */
646 if (!chat_get_is_command (str)) {
647 correct = empathy_spell_check (str);
653 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
655 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
660 /* set start iter to the end iters position */
666 chat_input_key_press_event_cb (GtkWidget *widget,
670 EmpathyChatPriv *priv;
673 GtkWidget *text_view_sw;
675 priv = GET_PRIV (chat);
677 /* Catch ctrl+up/down so we can traverse messages we sent */
678 if ((event->state & GDK_CONTROL_MASK) &&
679 (event->keyval == GDK_Up ||
680 event->keyval == GDK_Down)) {
681 GtkTextBuffer *buffer;
684 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
686 if (event->keyval == GDK_Up) {
687 str = chat_sent_message_get_next (chat);
689 str = chat_sent_message_get_last (chat);
692 g_signal_handlers_block_by_func (buffer,
693 chat_input_text_buffer_changed_cb,
695 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
696 g_signal_handlers_unblock_by_func (buffer,
697 chat_input_text_buffer_changed_cb,
703 /* Catch enter but not ctrl/shift-enter */
704 if (IS_ENTER (event->keyval) &&
705 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
708 /* This is to make sure that kinput2 gets the enter. And if
709 * it's handled there we shouldn't send on it. This is because
710 * kinput2 uses Enter to commit letters. See:
711 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
714 view = GTK_TEXT_VIEW (chat->input_text_view);
715 if (gtk_im_context_filter_keypress (view->im_context, event)) {
716 GTK_TEXT_VIEW (chat->input_text_view)->need_im_reset = TRUE;
720 chat_input_text_view_send (chat);
724 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
726 if (IS_ENTER (event->keyval) &&
727 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
728 /* Newline for shift/control-enter. */
731 if (!(event->state & GDK_CONTROL_MASK) &&
732 event->keyval == GDK_Page_Up) {
733 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
734 gtk_adjustment_set_value (adj, adj->value - adj->page_size);
737 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
738 event->keyval == GDK_Page_Down) {
739 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
740 val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
741 gtk_adjustment_set_value (adj, val);
744 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
745 event->keyval == GDK_Tab) {
746 GtkTextBuffer *buffer;
747 GtkTextIter start, current;
748 gchar *nick, *completed;
749 GList *list, *completed_list;
750 gboolean is_start_of_buffer;
752 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
753 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
755 /* Get the start of the nick to complete. */
756 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
757 gtk_text_iter_backward_word_start (&start);
758 is_start_of_buffer = gtk_text_iter_is_start (&start);
760 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
761 g_completion_add_items (priv->completion, list);
763 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
764 completed_list = g_completion_complete (priv->completion,
773 gchar *complete_char = NULL;
775 gtk_text_buffer_delete (buffer, &start, ¤t);
777 len = g_list_length (completed_list);
780 /* If we only have one hit, use that text
781 * instead of the text in completed since the
782 * completed text will use the typed string
783 * which might be cased all wrong.
786 text = empathy_contact_get_name (completed_list->data);
791 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
793 if (len == 1 && is_start_of_buffer &&
794 empathy_conf_get_string (empathy_conf_get (),
795 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
797 complete_char != NULL) {
798 gtk_text_buffer_insert_at_cursor (buffer,
800 strlen (complete_char));
801 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
802 g_free (complete_char);
808 g_completion_clear_items (priv->completion);
810 g_list_foreach (list, (GFunc) g_object_unref, NULL);
820 chat_text_view_focus_in_event_cb (GtkWidget *widget,
824 gtk_widget_grab_focus (chat->input_text_view);
830 chat_input_set_size_request_idle (gpointer sw)
832 gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT);
838 chat_input_size_request_cb (GtkWidget *widget,
839 GtkRequisition *requisition,
842 EmpathyChatPriv *priv = GET_PRIV (chat);
845 sw = gtk_widget_get_parent (widget);
846 if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) {
847 g_idle_add (chat_input_set_size_request_idle, sw);
848 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
851 priv->has_input_vscroll = TRUE;
854 if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) {
855 gtk_widget_set_size_request (sw, -1, -1);
856 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
859 priv->has_input_vscroll = FALSE;
864 chat_input_realize_cb (GtkWidget *widget,
867 DEBUG ("Setting focus to the input text view");
868 gtk_widget_grab_focus (widget);
872 chat_insert_smiley_activate_cb (EmpathySmileyManager *manager,
873 EmpathySmiley *smiley,
876 EmpathyChat *chat = EMPATHY_CHAT (user_data);
877 GtkTextBuffer *buffer;
880 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
882 gtk_text_buffer_get_end_iter (buffer, &iter);
883 gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
885 gtk_text_buffer_get_end_iter (buffer, &iter);
886 gtk_text_buffer_insert (buffer, &iter, " ", -1);
897 static EmpathyChatSpell *
898 chat_spell_new (EmpathyChat *chat,
903 EmpathyChatSpell *chat_spell;
905 chat_spell = g_slice_new0 (EmpathyChatSpell);
907 chat_spell->chat = g_object_ref (chat);
908 chat_spell->word = g_strdup (word);
909 chat_spell->start = start;
910 chat_spell->end = end;
916 chat_spell_free (EmpathyChatSpell *chat_spell)
918 g_object_unref (chat_spell->chat);
919 g_free (chat_spell->word);
920 g_slice_free (EmpathyChatSpell, chat_spell);
924 chat_text_check_word_spelling_cb (GtkMenuItem *menuitem,
925 EmpathyChatSpell *chat_spell)
927 empathy_spell_dialog_show (chat_spell->chat,
934 chat_text_send_cb (GtkMenuItem *menuitem,
937 chat_input_text_view_send (chat);
941 chat_input_populate_popup_cb (GtkTextView *view,
945 EmpathyChatPriv *priv;
946 GtkTextBuffer *buffer;
947 GtkTextTagTable *table;
950 GtkTextIter iter, start, end;
953 EmpathyChatSpell *chat_spell;
954 EmpathySmileyManager *smiley_manager;
955 GtkWidget *smiley_menu;
958 priv = GET_PRIV (chat);
959 buffer = gtk_text_view_get_buffer (view);
961 /* Add the emoticon menu. */
962 item = gtk_separator_menu_item_new ();
963 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
964 gtk_widget_show (item);
966 item = gtk_image_menu_item_new_with_mnemonic (_("Insert Smiley"));
967 image = gtk_image_new_from_icon_name ("face-smile",
969 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
970 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
971 gtk_widget_show (item);
973 smiley_manager = empathy_smiley_manager_new ();
974 smiley_menu = empathy_smiley_menu_new (smiley_manager,
975 chat_insert_smiley_activate_cb,
977 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
978 g_object_unref (smiley_manager);
980 /* Add the Send menu item. */
981 gtk_text_buffer_get_bounds (buffer, &start, &end);
982 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
983 if (!G_STR_EMPTY (str)) {
984 item = gtk_menu_item_new_with_mnemonic (_("_Send"));
985 g_signal_connect (G_OBJECT (item), "activate",
986 G_CALLBACK (chat_text_send_cb), chat);
987 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
988 gtk_widget_show (item);
992 /* Add the spell check menu item. */
993 table = gtk_text_buffer_get_tag_table (buffer);
994 tag = gtk_text_tag_table_lookup (table, "misspelled");
995 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
996 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
997 GTK_TEXT_WINDOW_WIDGET,
1000 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
1002 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
1003 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1005 str = gtk_text_buffer_get_text (buffer,
1006 &start, &end, FALSE);
1008 if (!G_STR_EMPTY (str)) {
1009 chat_spell = chat_spell_new (chat, str, start, end);
1010 g_object_set_data_full (G_OBJECT (menu),
1011 "chat_spell", chat_spell,
1012 (GDestroyNotify) chat_spell_free);
1014 item = gtk_separator_menu_item_new ();
1015 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1016 gtk_widget_show (item);
1018 item = gtk_image_menu_item_new_with_mnemonic (_("_Check Word Spelling..."));
1019 image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK,
1020 GTK_ICON_SIZE_MENU);
1021 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1022 g_signal_connect (item,
1024 G_CALLBACK (chat_text_check_word_spelling_cb),
1026 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1027 gtk_widget_show (item);
1032 chat_add_logs (EmpathyChat *chat)
1034 EmpathyChatPriv *priv = GET_PRIV (chat);
1035 gboolean is_chatroom;
1036 GList *messages, *l;
1044 /* Turn off scrolling temporarily */
1045 empathy_chat_view_scroll (chat->view, FALSE);
1047 /* Add messages from last conversation */
1048 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
1049 messages = empathy_log_manager_get_last_messages (priv->log_manager,
1053 num_messages = g_list_length (messages);
1055 /* Only keep the 10 last messages */
1056 for (i = 0; num_messages - i > 10; i++) {
1057 EmpathyMessage *message;
1059 message = messages->data;
1060 messages = g_list_remove (messages, message);
1061 g_object_unref (message);
1064 for (l = messages; l; l = l->next) {
1065 empathy_chat_view_append_message (chat->view, l->data);
1066 g_object_unref (l->data);
1068 g_list_free (messages);
1070 /* Turn back on scrolling */
1071 empathy_chat_view_scroll (chat->view, TRUE);
1075 chat_contacts_completion_func (const gchar *s1,
1079 gchar *tmp, *nick1, *nick2;
1086 return s1 ? -1 : +1;
1089 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
1090 nick1 = g_utf8_casefold (tmp, -1);
1093 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
1094 nick2 = g_utf8_casefold (tmp, -1);
1097 ret = strncmp (nick1, nick2, n);
1106 chat_members_changed_cb (EmpathyTpChat *tp_chat,
1107 EmpathyContact *contact,
1108 EmpathyContact *actor,
1114 EmpathyChatPriv *priv = GET_PRIV (chat);
1116 if (priv->block_events_timeout_id == 0) {
1119 empathy_contact_run_until_ready (contact,
1120 EMPATHY_CONTACT_READY_NAME,
1124 str = g_strdup_printf (_("%s has joined the room"),
1125 empathy_contact_get_name (contact));
1127 str = g_strdup_printf (_("%s has left the room"),
1128 empathy_contact_get_name (contact));
1130 empathy_chat_view_append_event (chat->view, str);
1136 chat_reset_size_request (gpointer widget)
1138 gtk_widget_set_size_request (widget, -1, -1);
1144 chat_set_show_contacts (EmpathyChat *chat, gboolean show)
1146 EmpathyChatPriv *priv = GET_PRIV (chat);
1148 if (!priv->scrolled_window_contacts) {
1153 EmpathyContactListStore *store;
1156 /* We are adding the contact list to the chat, we don't want the
1157 * chat view to become too small. If the chat view is already
1158 * smaller than 250 make sure that size won't change. If the
1159 * chat view is bigger the contact list will take some space on
1160 * it but we make sure the chat view don't become smaller than
1161 * 250. Relax the size request once the resize is done */
1162 min_width = MIN (priv->vbox_left->allocation.width, 250);
1163 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
1164 g_idle_add (chat_reset_size_request, priv->vbox_left);
1166 if (priv->contacts_width > 0) {
1167 gtk_paned_set_position (GTK_PANED (priv->hpaned),
1168 priv->contacts_width);
1171 store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
1172 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
1173 EMPATHY_CONTACT_LIST_FEATURE_NONE,
1174 EMPATHY_CONTACT_FEATURE_CHAT |
1175 EMPATHY_CONTACT_FEATURE_CALL |
1176 EMPATHY_CONTACT_FEATURE_LOG |
1177 EMPATHY_CONTACT_FEATURE_INFO));
1178 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
1179 priv->contact_list_view);
1180 gtk_widget_show (priv->contact_list_view);
1181 gtk_widget_show (priv->scrolled_window_contacts);
1182 g_object_unref (store);
1184 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
1185 gtk_widget_hide (priv->scrolled_window_contacts);
1186 if (priv->contact_list_view) {
1187 gtk_widget_destroy (priv->contact_list_view);
1188 priv->contact_list_view = NULL;
1194 chat_remote_contact_changed_cb (EmpathyChat *chat)
1196 EmpathyChatPriv *priv = GET_PRIV (chat);
1198 if (priv->remote_contact) {
1199 g_object_unref (priv->remote_contact);
1200 priv->remote_contact = NULL;
1203 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
1204 if (priv->remote_contact) {
1205 g_object_ref (priv->remote_contact);
1206 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
1208 priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
1210 else if (priv->tp_chat) {
1213 channel = empathy_tp_chat_get_channel (priv->tp_chat);
1214 g_object_get (channel, "handle-type", &priv->handle_type, NULL);
1216 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
1219 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1221 g_object_notify (G_OBJECT (chat), "remote-contact");
1222 g_object_notify (G_OBJECT (chat), "id");
1226 chat_destroy_cb (EmpathyTpChat *tp_chat,
1229 EmpathyChatPriv *priv;
1231 priv = GET_PRIV (chat);
1233 if (!priv->tp_chat) {
1237 g_object_unref (priv->tp_chat);
1238 priv->tp_chat = NULL;
1239 g_object_notify (G_OBJECT (chat), "tp-chat");
1241 empathy_chat_view_append_event (chat->view, _("Disconnected"));
1242 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
1243 chat_set_show_contacts (chat, FALSE);
1247 chat_create_ui (EmpathyChat *chat)
1249 EmpathyChatPriv *priv = GET_PRIV (chat);
1253 GtkTextBuffer *buffer;
1255 filename = empathy_file_lookup ("empathy-chat.glade",
1257 glade = empathy_glade_get_file (filename,
1260 "chat_widget", &priv->widget,
1261 "hpaned", &priv->hpaned,
1262 "vbox_left", &priv->vbox_left,
1263 "scrolled_window_chat", &priv->scrolled_window_chat,
1264 "scrolled_window_input", &priv->scrolled_window_input,
1265 "hbox_topic", &priv->hbox_topic,
1266 "label_topic", &priv->label_topic,
1267 "scrolled_window_contacts", &priv->scrolled_window_contacts,
1270 g_object_unref (glade);
1272 /* Add message view. */
1273 chat->view = empathy_theme_manager_create_view (empathy_theme_manager_get ());
1274 g_signal_connect (chat->view, "focus_in_event",
1275 G_CALLBACK (chat_text_view_focus_in_event_cb),
1277 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
1278 GTK_WIDGET (chat->view));
1279 gtk_widget_show (GTK_WIDGET (chat->view));
1281 /* Add input GtkTextView */
1282 chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
1283 "pixels-above-lines", 2,
1284 "pixels-below-lines", 2,
1285 "pixels-inside-wrap", 1,
1288 "wrap-mode", GTK_WRAP_WORD_CHAR,
1290 g_signal_connect (chat->input_text_view, "key-press-event",
1291 G_CALLBACK (chat_input_key_press_event_cb),
1293 g_signal_connect (chat->input_text_view, "size-request",
1294 G_CALLBACK (chat_input_size_request_cb),
1296 g_signal_connect (chat->input_text_view, "realize",
1297 G_CALLBACK (chat_input_realize_cb),
1299 g_signal_connect (chat->input_text_view, "populate-popup",
1300 G_CALLBACK (chat_input_populate_popup_cb),
1302 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1303 g_signal_connect (buffer, "changed",
1304 G_CALLBACK (chat_input_text_buffer_changed_cb),
1306 gtk_text_buffer_create_tag (buffer, "misspelled",
1307 "underline", PANGO_UNDERLINE_ERROR,
1309 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
1310 chat->input_text_view);
1311 gtk_widget_show (chat->input_text_view);
1313 /* Create contact list */
1314 chat_set_show_contacts (chat, priv->remote_contact == NULL);
1316 /* Initialy hide the topic, will be shown if not empty */
1317 gtk_widget_hide (priv->hbox_topic);
1319 /* Set widget focus order */
1320 list = g_list_append (NULL, priv->scrolled_window_input);
1321 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
1324 list = g_list_append (NULL, priv->vbox_left);
1325 list = g_list_append (list, priv->scrolled_window_contacts);
1326 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
1329 list = g_list_append (NULL, priv->hpaned);
1330 list = g_list_append (list, priv->hbox_topic);
1331 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
1334 /* Add the main widget in the chat widget */
1335 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
1339 chat_size_request (GtkWidget *widget,
1340 GtkRequisition *requisition)
1342 GtkBin *bin = GTK_BIN (widget);
1344 requisition->width = GTK_CONTAINER (widget)->border_width * 2;
1345 requisition->height = GTK_CONTAINER (widget)->border_width * 2;
1347 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1349 GtkRequisition child_requisition;
1351 gtk_widget_size_request (bin->child, &child_requisition);
1353 requisition->width += child_requisition.width;
1354 requisition->height += child_requisition.height;
1359 chat_size_allocate (GtkWidget *widget,
1360 GtkAllocation *allocation)
1362 GtkBin *bin = GTK_BIN (widget);
1363 GtkAllocation child_allocation;
1365 widget->allocation = *allocation;
1367 if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
1369 child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
1370 child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
1371 child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
1372 child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
1374 gtk_widget_size_allocate (bin->child, &child_allocation);
1379 chat_finalize (GObject *object)
1382 EmpathyChatPriv *priv;
1384 chat = EMPATHY_CHAT (object);
1385 priv = GET_PRIV (chat);
1387 DEBUG ("Finalized: %p", object);
1389 g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
1390 g_slist_free (priv->sent_messages);
1392 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
1393 g_list_free (priv->compositors);
1395 chat_composing_remove_timeout (chat);
1397 empathy_disconnect_account_status_changed (priv->token);
1398 g_object_unref (priv->mc);
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_new ();
1530 priv->contacts_width = -1;
1531 priv->sent_messages = NULL;
1532 priv->sent_messages_index = -1;
1533 priv->mc = empathy_mission_control_new ();
1535 priv->token = empathy_connect_to_account_status_changed (priv->mc,
1536 G_CALLBACK (chat_status_changed_cb),
1539 /* Block events for some time to avoid having "has come online" or
1540 * "joined" messages. */
1541 priv->block_events_timeout_id =
1542 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
1544 /* Add nick name completion */
1545 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
1546 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
1550 empathy_chat_new (EmpathyTpChat *tp_chat)
1552 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
1556 empathy_chat_get_tp_chat (EmpathyChat *chat)
1558 EmpathyChatPriv *priv = GET_PRIV (chat);
1560 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1562 return priv->tp_chat;
1566 empathy_chat_set_tp_chat (EmpathyChat *chat,
1567 EmpathyTpChat *tp_chat)
1569 EmpathyChatPriv *priv = GET_PRIV (chat);
1571 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1572 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
1573 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
1575 if (priv->tp_chat) {
1579 if (priv->account) {
1580 g_object_unref (priv->account);
1583 priv->tp_chat = g_object_ref (tp_chat);
1584 priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
1586 g_signal_connect (tp_chat, "message-received",
1587 G_CALLBACK (chat_message_received_cb),
1589 g_signal_connect (tp_chat, "send-error",
1590 G_CALLBACK (chat_send_error_cb),
1592 g_signal_connect (tp_chat, "chat-state-changed",
1593 G_CALLBACK (chat_state_changed_cb),
1595 g_signal_connect (tp_chat, "property-changed",
1596 G_CALLBACK (chat_property_changed_cb),
1598 g_signal_connect (tp_chat, "members-changed",
1599 G_CALLBACK (chat_members_changed_cb),
1601 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
1602 G_CALLBACK (chat_remote_contact_changed_cb),
1604 g_signal_connect (tp_chat, "destroy",
1605 G_CALLBACK (chat_destroy_cb),
1608 chat_remote_contact_changed_cb (chat);
1610 if (chat->input_text_view) {
1611 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
1612 if (priv->block_events_timeout_id == 0) {
1613 empathy_chat_view_append_event (chat->view, _("Connected"));
1617 empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
1618 empathy_tp_chat_emit_pendings (priv->tp_chat);
1620 g_object_notify (G_OBJECT (chat), "tp-chat");
1621 g_object_notify (G_OBJECT (chat), "id");
1622 g_object_notify (G_OBJECT (chat), "account");
1626 empathy_chat_get_account (EmpathyChat *chat)
1628 EmpathyChatPriv *priv = GET_PRIV (chat);
1630 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1632 return priv->account;
1636 empathy_chat_get_id (EmpathyChat *chat)
1638 EmpathyChatPriv *priv = GET_PRIV (chat);
1640 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1646 empathy_chat_get_name (EmpathyChat *chat)
1648 EmpathyChatPriv *priv = GET_PRIV (chat);
1651 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1654 if (!ret && priv->remote_contact) {
1655 ret = empathy_contact_get_name (priv->remote_contact);
1661 return ret ? ret : _("Conversation");
1665 empathy_chat_get_subject (EmpathyChat *chat)
1667 EmpathyChatPriv *priv = GET_PRIV (chat);
1669 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1671 return priv->subject;
1675 empathy_chat_get_remote_contact (EmpathyChat *chat)
1677 EmpathyChatPriv *priv = GET_PRIV (chat);
1679 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1681 return priv->remote_contact;
1685 empathy_chat_get_members_count (EmpathyChat *chat)
1687 EmpathyChatPriv *priv = GET_PRIV (chat);
1689 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
1691 if (priv->tp_chat) {
1692 return empathy_tp_chat_get_members_count (priv->tp_chat);
1699 empathy_chat_get_contact_menu (EmpathyChat *chat)
1701 EmpathyChatPriv *priv = GET_PRIV (chat);
1702 GtkWidget *menu = NULL;
1704 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
1706 if (priv->remote_contact) {
1707 menu = empathy_contact_menu_new (priv->remote_contact,
1708 EMPATHY_CONTACT_FEATURE_CALL |
1709 EMPATHY_CONTACT_FEATURE_LOG |
1710 EMPATHY_CONTACT_FEATURE_INFO);
1712 else if (priv->contact_list_view) {
1713 EmpathyContactListView *view;
1715 view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
1716 menu = empathy_contact_list_view_get_contact_menu (view);
1723 empathy_chat_clear (EmpathyChat *chat)
1725 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1727 empathy_chat_view_clear (chat->view);
1731 empathy_chat_scroll_down (EmpathyChat *chat)
1733 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1735 empathy_chat_view_scroll_down (chat->view);
1739 empathy_chat_cut (EmpathyChat *chat)
1741 GtkTextBuffer *buffer;
1743 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1745 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1746 if (gtk_text_buffer_get_has_selection (buffer)) {
1747 GtkClipboard *clipboard;
1749 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1751 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
1756 empathy_chat_copy (EmpathyChat *chat)
1758 GtkTextBuffer *buffer;
1760 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1762 if (empathy_chat_view_get_has_selection (chat->view)) {
1763 empathy_chat_view_copy_clipboard (chat->view);
1767 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1768 if (gtk_text_buffer_get_has_selection (buffer)) {
1769 GtkClipboard *clipboard;
1771 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1773 gtk_text_buffer_copy_clipboard (buffer, clipboard);
1778 empathy_chat_paste (EmpathyChat *chat)
1780 GtkTextBuffer *buffer;
1781 GtkClipboard *clipboard;
1783 g_return_if_fail (EMPATHY_IS_CHAT (chat));
1785 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1786 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
1788 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
1792 empathy_chat_correct_word (EmpathyChat *chat,
1795 const gchar *new_word)
1797 GtkTextBuffer *buffer;
1799 g_return_if_fail (chat != NULL);
1800 g_return_if_fail (new_word != NULL);
1802 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1804 gtk_text_buffer_delete (buffer, start, end);
1805 gtk_text_buffer_insert (buffer, start,
1811 empathy_chat_is_room (EmpathyChat *chat)
1813 EmpathyChatPriv *priv = GET_PRIV (chat);
1815 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
1817 return (priv->handle_type == TP_HANDLE_TYPE_ROOM);