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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 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 #undef G_DISABLE_DEPRECATED /* for GCompletion */
34 #include <gdk/gdkkeysyms.h>
35 #include <glib/gi18n-lib.h>
38 #include <telepathy-glib/account-manager.h>
39 #include <telepathy-glib/util.h>
40 #include <telepathy-logger/log-manager.h>
41 #include <libempathy/empathy-contact-list.h>
42 #include <libempathy/empathy-gsettings.h>
43 #include <libempathy/empathy-utils.h>
44 #include <libempathy/empathy-dispatcher.h>
46 #include "empathy-chat.h"
47 #include "empathy-spell.h"
48 #include "empathy-contact-list-store.h"
49 #include "empathy-contact-list-view.h"
50 #include "empathy-contact-menu.h"
51 #include "empathy-input-text-view.h"
52 #include "empathy-search-bar.h"
53 #include "empathy-theme-manager.h"
54 #include "empathy-smiley-manager.h"
55 #include "empathy-ui-utils.h"
56 #include "empathy-string-parser.h"
58 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
59 #include <libempathy/empathy-debug.h>
61 #define CHAT_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
62 #define CHAT_FILE_CREATE_MODE (S_IRUSR | S_IWUSR)
63 #define IS_ENTER(v) (v == GDK_KEY_Return || v == GDK_KEY_ISO_Enter || v == GDK_KEY_KP_Enter)
64 #define MAX_INPUT_HEIGHT 150
65 #define COMPOSING_STOP_TIMEOUT 5
67 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat)
68 struct _EmpathyChatPriv {
69 EmpathyTpChat *tp_chat;
74 EmpathyContact *remote_contact;
75 gboolean show_contacts;
77 GSettings *gsettings_chat;
78 GSettings *gsettings_ui;
80 TplLogManager *log_manager;
81 TpAccountManager *account_manager;
83 GList *input_history_current;
85 GCompletion *completion;
86 guint composing_stop_timeout_id;
87 guint block_events_timeout_id;
88 TpHandleType handle_type;
90 gboolean has_input_vscroll;
92 /* TRUE if spell checking is enabled, FALSE otherwise.
93 * This is to keep track of the last state of spell checking
95 gboolean spell_checking_enabled;
97 /* These store the signal handler ids for the enclosed text entry. */
98 gulong insert_text_id;
99 gulong delete_range_id;
100 gulong notify_cursor_position_id;
102 /* Source func ID for update_misspelled_words () */
103 guint update_misspelled_words_id;
107 GtkWidget *vbox_left;
108 GtkWidget *scrolled_window_chat;
109 GtkWidget *scrolled_window_input;
110 GtkWidget *scrolled_window_contacts;
111 GtkWidget *hbox_topic;
112 GtkWidget *expander_topic;
113 GtkWidget *label_topic;
114 GtkWidget *contact_list_view;
115 GtkWidget *info_bar_vbox;
116 GtkWidget *search_bar;
118 guint unread_messages;
119 /* TRUE if the pending messages can be displayed. This is to avoid to show
120 * pending messages *before* messages from logs. (#603980) */
121 gboolean can_show_pending;
123 /* FIXME: retrieving_backlogs flag is a workaround for Bug#610994 and should
124 * be differently handled since it introduces another race condition, which
125 * is really hard to occur, but still possible.
127 * With the current workaround (which has the race above), we need to be
128 * sure to ACK any pending messages only when the retrieval of backlogs is
129 * finished, that's why using retrieving_backlogs flag.
130 * empathy_chat_messages_read () will check this variable and not ACK
131 * anything when TRUE. It will be set TRUE at chat_constructed () and set
132 * back to FALSE when the backlog has been retrieved and the pending
133 * messages actually showed to the user.
135 * Race condition introduced with this workaround:
136 * Scenario: a message is pending, the user is notified and selects the tab.
137 * the tab with a pending message is focused before the messages are properly
138 * shown (since the preparation of the window is slower AND async WRT the
139 * tab showing), which means the user won't see any new messages (rare but
140 * possible), if he/she will change tab focus before the messages are
141 * properly shown, the tab will be set as 'seen' and the user won't be
142 * notified again about the already notified pending messages when the
143 * messages in tab will be properly shown */
144 gboolean retrieving_backlogs;
148 gchar *text; /* Original message that was specified
149 * upon entry creation. */
150 gchar *modified_text; /* Message that was modified by user.
151 * When no modifications were made, it is NULL */
171 static guint signals[LAST_SIGNAL] = { 0 };
173 G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
175 static gboolean update_misspelled_words (gpointer data);
178 chat_get_property (GObject *object,
183 EmpathyChat *chat = EMPATHY_CHAT (object);
184 EmpathyChatPriv *priv = GET_PRIV (object);
188 g_value_set_object (value, priv->tp_chat);
191 g_value_set_object (value, priv->account);
194 g_value_set_string (value, empathy_chat_get_name (chat));
197 g_value_set_string (value, priv->id);
200 g_value_set_string (value, priv->subject);
202 case PROP_REMOTE_CONTACT:
203 g_value_set_object (value, priv->remote_contact);
205 case PROP_SHOW_CONTACTS:
206 g_value_set_boolean (value, priv->show_contacts);
209 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
215 chat_set_property (GObject *object,
220 EmpathyChat *chat = EMPATHY_CHAT (object);
224 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
226 case PROP_SHOW_CONTACTS:
227 empathy_chat_set_show_contacts (chat, g_value_get_boolean (value));
230 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
236 account_reconnected (EmpathyChat *chat,
239 EmpathyChatPriv *priv = GET_PRIV (chat);
241 DEBUG ("Account reconnected, request a new Text channel");
243 /* FIXME: Ideally we should ask to handle ourself the channel so we can
244 * report the error if any but this is blocked by
245 * https://bugs.freedesktop.org/show_bug.cgi?id=13422 */
246 switch (priv->handle_type) {
247 case TP_HANDLE_TYPE_CONTACT:
248 empathy_dispatcher_chat_with_contact_id (
249 account, priv->id, TP_USER_ACTION_TIME_NOT_USER_ACTION);
251 case TP_HANDLE_TYPE_ROOM:
252 empathy_dispatcher_join_muc (account, priv->id,
253 TP_USER_ACTION_TIME_NOT_USER_ACTION);
255 case TP_HANDLE_TYPE_NONE:
256 case TP_HANDLE_TYPE_LIST:
257 case TP_HANDLE_TYPE_GROUP:
259 g_assert_not_reached ();
263 g_object_unref (chat);
267 chat_new_connection_cb (TpAccount *account,
271 gchar *dbus_error_name,
275 EmpathyChatPriv *priv = GET_PRIV (chat);
276 TpConnection *connection;
278 if (new_status != TP_CONNECTION_STATUS_CONNECTED)
281 connection = tp_account_get_connection (account);
283 if (priv->tp_chat != NULL || account != priv->account ||
284 priv->handle_type == TP_HANDLE_TYPE_NONE ||
285 EMP_STR_EMPTY (priv->id))
290 account_reconnected (chat, account);
294 chat_composing_remove_timeout (EmpathyChat *chat)
296 EmpathyChatPriv *priv;
298 priv = GET_PRIV (chat);
300 if (priv->composing_stop_timeout_id) {
301 g_source_remove (priv->composing_stop_timeout_id);
302 priv->composing_stop_timeout_id = 0;
307 chat_composing_stop_timeout_cb (EmpathyChat *chat)
309 EmpathyChatPriv *priv;
311 priv = GET_PRIV (chat);
313 priv->composing_stop_timeout_id = 0;
314 empathy_tp_chat_set_state (priv->tp_chat,
315 TP_CHANNEL_CHAT_STATE_PAUSED);
321 chat_composing_start (EmpathyChat *chat)
323 EmpathyChatPriv *priv;
325 priv = GET_PRIV (chat);
327 if (priv->composing_stop_timeout_id) {
328 /* Just restart the timeout */
329 chat_composing_remove_timeout (chat);
331 empathy_tp_chat_set_state (priv->tp_chat,
332 TP_CHANNEL_CHAT_STATE_COMPOSING);
335 priv->composing_stop_timeout_id = g_timeout_add_seconds (
336 COMPOSING_STOP_TIMEOUT,
337 (GSourceFunc) chat_composing_stop_timeout_cb,
342 chat_composing_stop (EmpathyChat *chat)
344 EmpathyChatPriv *priv;
346 priv = GET_PRIV (chat);
348 chat_composing_remove_timeout (chat);
349 empathy_tp_chat_set_state (priv->tp_chat,
350 TP_CHANNEL_CHAT_STATE_ACTIVE);
354 chat_input_history_entry_cmp (InputHistoryEntry *entry,
357 if (!tp_strdiff (entry->text, text)) {
358 if (entry->modified_text != NULL) {
359 /* Modified entry and single string cannot be equal. */
367 static InputHistoryEntry *
368 chat_input_history_entry_new_with_text (const gchar *text)
370 InputHistoryEntry *entry;
371 entry = g_slice_new0 (InputHistoryEntry);
372 entry->text = g_strdup (text);
378 chat_input_history_entry_free (InputHistoryEntry *entry)
380 g_free (entry->text);
381 g_free (entry->modified_text);
382 g_slice_free (InputHistoryEntry, entry);
386 chat_input_history_entry_revert (InputHistoryEntry *entry)
388 g_free (entry->modified_text);
389 entry->modified_text = NULL;
393 chat_input_history_entry_update_text (InputHistoryEntry *entry,
398 if (!tp_strdiff (text, entry->text)) {
399 g_free (entry->modified_text);
400 entry->modified_text = NULL;
404 old = entry->modified_text;
405 entry->modified_text = g_strdup (text);
410 chat_input_history_entry_get_text (InputHistoryEntry *entry)
416 if (entry->modified_text != NULL) {
417 return entry->modified_text;
423 chat_input_history_remove_item (GList *list,
426 list = g_list_remove_link (list, item);
427 chat_input_history_entry_free (item->data);
428 g_list_free_1 (item);
433 chat_input_history_revert (EmpathyChat *chat)
435 EmpathyChatPriv *priv;
439 InputHistoryEntry *entry;
441 priv = GET_PRIV (chat);
442 list = priv->input_history;
445 DEBUG ("No input history");
449 /* Delete temporary entry */
450 if (priv->input_history_current != NULL) {
452 list = chat_input_history_remove_item (list, item1);
453 if (priv->input_history_current == item1) {
454 /* Removed temporary entry was current entry */
455 priv->input_history = list;
456 priv->input_history_current = NULL;
461 /* There is no entry to revert */
465 /* Restore the current history entry to original value */
466 item1 = priv->input_history_current;
468 chat_input_history_entry_revert (entry);
470 /* Remove restored entry if there is other occurance before this entry */
471 item2 = g_list_find_custom (list, chat_input_history_entry_get_text (entry),
472 (GCompareFunc) chat_input_history_entry_cmp);
473 if (item2 != item1) {
474 list = chat_input_history_remove_item (list, item1);
477 /* Remove other occurance of the restored entry */
478 item2 = g_list_find_custom (item1->next,
479 chat_input_history_entry_get_text (entry),
480 (GCompareFunc) chat_input_history_entry_cmp);
482 list = chat_input_history_remove_item (list, item2);
486 priv->input_history_current = NULL;
487 priv->input_history = list;
491 chat_input_history_add (EmpathyChat *chat,
495 EmpathyChatPriv *priv;
498 InputHistoryEntry *entry;
500 priv = GET_PRIV (chat);
502 list = priv->input_history;
504 /* Remove any other occurances of this entry, if not temporary */
506 while ((item = g_list_find_custom (list, str,
507 (GCompareFunc) chat_input_history_entry_cmp)) != NULL) {
508 list = chat_input_history_remove_item (list, item);
511 /* Trim the list to the last 10 items */
512 while (g_list_length (list) > 10) {
513 item = g_list_last (list);
515 list = chat_input_history_remove_item (list, item);
523 entry = chat_input_history_entry_new_with_text (str);
524 list = g_list_prepend (list, entry);
526 /* Set the list and the current item pointer */
527 priv->input_history = list;
529 priv->input_history_current = list;
532 priv->input_history_current = NULL;
537 chat_input_history_get_next (EmpathyChat *chat)
539 EmpathyChatPriv *priv;
543 priv = GET_PRIV (chat);
545 if (priv->input_history == NULL) {
546 DEBUG ("No input history, next entry is NULL");
549 g_assert (priv->input_history_current != NULL);
551 if ((item = g_list_next (priv->input_history_current)) == NULL)
553 item = priv->input_history_current;
556 msg = chat_input_history_entry_get_text (item->data);
558 DEBUG ("Returning next entry: '%s'", msg);
560 priv->input_history_current = item;
566 chat_input_history_get_prev (EmpathyChat *chat)
568 EmpathyChatPriv *priv;
572 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
574 priv = GET_PRIV (chat);
576 if (priv->input_history == NULL) {
577 DEBUG ("No input history, previous entry is NULL");
581 if (priv->input_history_current == NULL)
585 else if ((item = g_list_previous (priv->input_history_current)) == NULL)
587 item = priv->input_history_current;
590 msg = chat_input_history_entry_get_text (item->data);
592 DEBUG ("Returning previous entry: '%s'", msg);
594 priv->input_history_current = item;
600 chat_input_history_update (EmpathyChat *chat,
601 GtkTextBuffer *buffer)
603 EmpathyChatPriv *priv;
604 GtkTextIter start, end;
606 InputHistoryEntry *entry;
608 priv = GET_PRIV (chat);
610 gtk_text_buffer_get_bounds (buffer, &start, &end);
611 text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
613 if (priv->input_history_current == NULL) {
614 /* Add the current text temporarily to the history */
615 chat_input_history_add (chat, text, TRUE);
620 /* Save the changes in the history */
621 entry = priv->input_history_current->data;
622 if (tp_strdiff (chat_input_history_entry_get_text (entry), text)) {
623 chat_input_history_entry_update_text (entry, text);
632 } ChatCommandMsgData;
636 chat_command_msg_cb (EmpathyDispatchOperation *dispatch,
640 ChatCommandMsgData *data = user_data;
643 empathy_chat_view_append_event (data->chat->view,
644 _("Failed to open private chat"));
648 if (!EMP_STR_EMPTY (data->message)) {
649 EmpathyTpChat *tpchat;
650 EmpathyMessage *message;
652 tpchat = EMPATHY_TP_CHAT (
653 empathy_dispatch_operation_get_channel_wrapper (dispatch));
655 message = empathy_message_new (data->message);
656 empathy_tp_chat_send (tpchat, message);
657 g_object_unref (message);
661 g_free (data->message);
662 g_slice_free (ChatCommandMsgData, data);
667 chat_command_clear (EmpathyChat *chat,
670 empathy_chat_view_clear (chat->view);
674 chat_command_topic (EmpathyChat *chat,
677 EmpathyChatPriv *priv = GET_PRIV (chat);
678 EmpathyTpChatProperty *property;
679 GValue value = {0, };
681 property = empathy_tp_chat_get_property (priv->tp_chat, "subject");
682 if (property == NULL) {
683 empathy_chat_view_append_event (chat->view,
684 _("Topic not supported on this conversation"));
688 if (!(property->flags & TP_PROPERTY_FLAG_WRITE)) {
689 empathy_chat_view_append_event (chat->view,
690 _("You are not allowed to change the topic"));
694 g_value_init (&value, G_TYPE_STRING);
695 g_value_set_string (&value, strv[1]);
696 empathy_tp_chat_set_property (priv->tp_chat, "subject", &value);
697 g_value_unset (&value);
701 chat_command_join (EmpathyChat *chat,
705 EmpathyChatPriv *priv = GET_PRIV (chat);
707 GStrv rooms = g_strsplit_set (strv[1], ", ", -1);
709 /* FIXME: Ideally we should ask to handle ourself the channel so we can
710 * report the error if any but this is blocked by
711 * https://bugs.freedesktop.org/show_bug.cgi?id=13422 */
712 while (rooms[i] != NULL) {
713 /* ignore empty strings */
714 if (!EMP_STR_EMPTY (rooms[i])) {
715 TpConnection *connection;
717 connection = empathy_tp_chat_get_connection (priv->tp_chat);
718 empathy_dispatcher_join_muc (priv->account, rooms[i],
719 gtk_get_current_event_time ());
728 chat_command_msg_internal (EmpathyChat *chat,
729 const gchar *contact_id,
730 const gchar *message)
732 EmpathyChatPriv *priv = GET_PRIV (chat);
733 TpConnection *connection;
734 ChatCommandMsgData *data;
736 /* FIXME: We should probably search in members alias. But this
737 * is enough for IRC */
738 data = g_slice_new (ChatCommandMsgData);
740 data->message = g_strdup (message);
741 connection = empathy_tp_chat_get_connection (priv->tp_chat);
742 empathy_dispatcher_chat_with_contact_id (connection, contact_id,
743 gtk_get_current_event_time (),
749 chat_command_query (EmpathyChat *chat,
752 /* If <message> part is not defined,
753 * strv[2] will be the terminal NULL */
754 chat_command_msg_internal (chat, strv[1], strv[2]);
758 chat_command_msg (EmpathyChat *chat,
761 chat_command_msg_internal (chat, strv[1], strv[2]);
766 chat_command_nick (EmpathyChat *chat,
769 EmpathyChatPriv *priv = GET_PRIV (chat);
770 TpConnection *connection;
771 GHashTable *new_alias;
774 connection = tp_account_get_connection (priv->account);
775 handle = tp_connection_get_self_handle (connection);
776 new_alias = g_hash_table_new (g_direct_hash, g_direct_equal);
777 g_hash_table_insert (new_alias, GUINT_TO_POINTER (handle), strv[1]);
779 tp_cli_connection_interface_aliasing_call_set_aliases (connection, -1,
780 new_alias, NULL, NULL, NULL, NULL);
782 g_hash_table_destroy (new_alias);
786 chat_command_me (EmpathyChat *chat,
789 EmpathyChatPriv *priv = GET_PRIV (chat);
790 EmpathyMessage *message;
792 message = empathy_message_new (strv[1]);
793 empathy_message_set_tptype (message, TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION);
794 empathy_tp_chat_send (priv->tp_chat, message);
795 g_object_unref (message);
799 chat_command_say (EmpathyChat *chat,
802 EmpathyChatPriv *priv = GET_PRIV (chat);
803 EmpathyMessage *message;
805 message = empathy_message_new (strv[1]);
806 empathy_tp_chat_send (priv->tp_chat, message);
807 g_object_unref (message);
810 static void chat_command_help (EmpathyChat *chat, GStrv strv);
812 typedef void (*ChatCommandFunc) (EmpathyChat *chat, GStrv strv);
818 ChatCommandFunc func;
822 static ChatCommandItem commands[] = {
823 {"clear", 1, 1, chat_command_clear,
824 N_("/clear: clear all messages from the current conversation")},
826 {"topic", 2, 2, chat_command_topic,
827 N_("/topic <topic>: set the topic of the current conversation")},
829 {"join", 2, 2, chat_command_join,
830 N_("/join <chat room ID>: join a new chat room")},
832 {"j", 2, 2, chat_command_join,
833 N_("/j <chat room ID>: join a new chat room")},
836 /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=623682 */
837 {"query", 2, 3, chat_command_query,
838 N_("/query <contact ID> [<message>]: open a private chat")},
840 {"msg", 3, 3, chat_command_msg,
841 N_("/msg <contact ID> <message>: open a private chat")},
844 {"nick", 2, 2, chat_command_nick,
845 N_("/nick <nickname>: change your nickname on the current server")},
847 {"me", 2, 2, chat_command_me,
848 N_("/me <message>: send an ACTION message to the current conversation")},
850 {"say", 2, 2, chat_command_say,
851 N_("/say <message>: send <message> to the current conversation. "
852 "This is used to send a message starting with a '/'. For example: "
853 "\"/say /join is used to join a new chat room\"")},
855 {"help", 1, 2, chat_command_help,
856 N_("/help [<command>]: show all supported commands. "
857 "If <command> is defined, show its usage.")},
861 chat_command_show_help (EmpathyChat *chat,
862 ChatCommandItem *item)
866 str = g_strdup_printf (_("Usage: %s"), _(item->help));
867 empathy_chat_view_append_event (chat->view, str);
872 chat_command_help (EmpathyChat *chat,
877 /* If <command> part is not defined,
878 * strv[1] will be the terminal NULL */
879 if (strv[1] == NULL) {
880 for (i = 0; i < G_N_ELEMENTS (commands); i++) {
881 empathy_chat_view_append_event (chat->view,
882 _(commands[i].help));
887 for (i = 0; i < G_N_ELEMENTS (commands); i++) {
888 if (g_ascii_strcasecmp (strv[1], commands[i].prefix) == 0) {
889 chat_command_show_help (chat, &commands[i]);
894 empathy_chat_view_append_event (chat->view,
895 _("Unknown command"));
899 chat_command_parse (const gchar *text, guint max_parts)
904 DEBUG ("Parse command, parts=%d text=\"%s\":", max_parts, text);
906 array = g_ptr_array_sized_new (max_parts + 1);
907 while (max_parts > 1) {
910 /* Skip white spaces */
911 while (g_ascii_isspace (*text)) {
915 /* Search the end of this part, until first space. */
916 for (end = text; *end != '\0' && !g_ascii_isspace (*end); end++)
922 item = g_strndup (text, end - text);
923 g_ptr_array_add (array, item);
924 DEBUG ("\tITEM: \"%s\"", item);
930 /* Append last part if not empty */
931 item = g_strstrip (g_strdup (text));
932 if (!EMP_STR_EMPTY (item)) {
933 g_ptr_array_add (array, item);
934 DEBUG ("\tITEM: \"%s\"", item);
939 /* Make the array NULL-terminated */
940 g_ptr_array_add (array, NULL);
942 return (GStrv) g_ptr_array_free (array, FALSE);
946 has_prefix_case (const gchar *s,
949 return g_ascii_strncasecmp (s, prefix, strlen (prefix)) == 0;
953 chat_send (EmpathyChat *chat,
956 EmpathyChatPriv *priv;
957 EmpathyMessage *message;
960 if (EMP_STR_EMPTY (msg)) {
964 priv = GET_PRIV (chat);
966 chat_input_history_add (chat, msg, FALSE);
969 gboolean second_slash = FALSE;
970 const gchar *iter = msg + 1;
972 for (i = 0; i < G_N_ELEMENTS (commands); i++) {
977 if (!has_prefix_case (msg + 1, commands[i].prefix)) {
980 c = *(msg + 1 + strlen (commands[i].prefix));
981 if (c != '\0' && !g_ascii_isspace (c)) {
985 /* We can't use g_strsplit here because it does
986 * not deal correctly if we have more than one space
988 strv = chat_command_parse (msg + 1, commands[i].max_parts);
990 strv_len = g_strv_length (strv);
991 if (strv_len < commands[i].min_parts ||
992 strv_len > commands[i].max_parts) {
993 chat_command_show_help (chat, &commands[i]);
998 commands[i].func (chat, strv);
1003 /* Also allow messages with two slashes before the
1004 * first space, so it is possible to send a /unix/path.
1005 * This heuristic is kind of crap. */
1006 while (*iter != '\0' && !g_ascii_isspace (*iter)) {
1008 second_slash = TRUE;
1014 if (!second_slash) {
1015 empathy_chat_view_append_event (chat->view,
1016 _("Unknown command; see /help for the available"
1022 message = empathy_message_new (msg);
1023 empathy_tp_chat_send (priv->tp_chat, message);
1024 g_object_unref (message);
1028 chat_input_text_view_send (EmpathyChat *chat)
1030 EmpathyChatPriv *priv;
1031 GtkTextBuffer *buffer;
1032 GtkTextIter start, end;
1035 priv = GET_PRIV (chat);
1037 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1039 gtk_text_buffer_get_bounds (buffer, &start, &end);
1040 msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
1042 /* clear the input field */
1043 gtk_text_buffer_set_text (buffer, "", -1);
1044 /* delete input history modifications */
1045 chat_input_history_revert (chat);
1047 chat_send (chat, msg);
1052 chat_state_changed_cb (EmpathyTpChat *tp_chat,
1053 EmpathyContact *contact,
1054 TpChannelChatState state,
1057 EmpathyChatPriv *priv;
1059 gboolean was_composing;
1061 priv = GET_PRIV (chat);
1063 if (empathy_contact_is_user (contact)) {
1064 /* We don't care about our own chat state */
1068 was_composing = (priv->compositors != NULL);
1070 /* Find the contact in the list. After that l is the list elem or NULL */
1071 for (l = priv->compositors; l; l = l->next) {
1072 if (contact == l->data) {
1078 case TP_CHANNEL_CHAT_STATE_GONE:
1079 case TP_CHANNEL_CHAT_STATE_INACTIVE:
1080 case TP_CHANNEL_CHAT_STATE_PAUSED:
1081 case TP_CHANNEL_CHAT_STATE_ACTIVE:
1082 /* Contact is not composing */
1084 priv->compositors = g_list_remove_link (priv->compositors, l);
1085 g_object_unref (l->data);
1089 case TP_CHANNEL_CHAT_STATE_COMPOSING:
1090 /* Contact is composing */
1092 priv->compositors = g_list_prepend (priv->compositors,
1093 g_object_ref (contact));
1097 g_assert_not_reached ();
1100 DEBUG ("Was composing: %s now composing: %s",
1101 was_composing ? "yes" : "no",
1102 priv->compositors ? "yes" : "no");
1104 if ((was_composing && !priv->compositors) ||
1105 (!was_composing && priv->compositors)) {
1106 /* Composing state changed */
1107 g_signal_emit (chat, signals[COMPOSING], 0,
1108 priv->compositors != NULL);
1113 chat_message_received (EmpathyChat *chat, EmpathyMessage *message)
1115 EmpathyChatPriv *priv = GET_PRIV (chat);
1116 EmpathyContact *sender;
1118 sender = empathy_message_get_sender (message);
1120 DEBUG ("Appending new message from %s (%d)",
1121 empathy_contact_get_alias (sender),
1122 empathy_contact_get_handle (sender));
1124 empathy_chat_view_append_message (chat->view, message);
1126 /* We received a message so the contact is no longer composing */
1127 chat_state_changed_cb (priv->tp_chat, sender,
1128 TP_CHANNEL_CHAT_STATE_ACTIVE,
1131 priv->unread_messages++;
1132 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
1136 chat_message_received_cb (EmpathyTpChat *tp_chat,
1137 EmpathyMessage *message,
1140 chat_message_received (chat, message);
1144 chat_send_error_cb (EmpathyTpChat *tp_chat,
1145 const gchar *message_body,
1146 TpChannelTextSendError error_code,
1152 switch (error_code) {
1153 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
1154 error = _("offline");
1156 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
1157 error = _("invalid contact");
1159 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
1160 error = _("permission denied");
1162 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
1163 error = _("too long message");
1165 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
1166 error = _("not implemented");
1168 case TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN:
1170 error = _("unknown");
1174 str = g_strdup_printf (_("Error sending message '%s': %s"),
1177 empathy_chat_view_append_event (chat->view, str);
1182 chat_topic_label_size_allocate_cb (GtkLabel *label,
1183 GtkAllocation *allocation,
1186 EmpathyChatPriv *priv = GET_PRIV (chat);
1188 if (!gtk_label_get_line_wrap (label)) {
1189 if (pango_layout_is_ellipsized (gtk_label_get_layout (label)))
1190 gtk_widget_show (priv->expander_topic);
1192 gtk_widget_hide (priv->expander_topic);
1199 chat_topic_expander_activate_cb (GtkExpander *expander,
1200 GParamSpec *param_spec,
1203 EmpathyChatPriv *priv = GET_PRIV (chat);
1205 if (gtk_expander_get_expanded (expander)) {
1206 gtk_label_set_ellipsize (GTK_LABEL (priv->label_topic), PANGO_ELLIPSIZE_NONE);
1207 gtk_label_set_line_wrap (GTK_LABEL (priv->label_topic), TRUE);
1209 gtk_label_set_ellipsize (GTK_LABEL (priv->label_topic), PANGO_ELLIPSIZE_END);
1210 gtk_label_set_line_wrap (GTK_LABEL (priv->label_topic), FALSE);
1215 chat_property_changed_cb (EmpathyTpChat *tp_chat,
1220 EmpathyChatPriv *priv = GET_PRIV (chat);
1222 if (!tp_strdiff (name, "subject")) {
1223 g_free (priv->subject);
1224 priv->subject = g_value_dup_string (value);
1225 g_object_notify (G_OBJECT (chat), "subject");
1227 if (EMP_STR_EMPTY (priv->subject)) {
1228 gtk_widget_hide (priv->hbox_topic);
1230 gchar *markup_topic;
1233 markup_topic = empathy_add_link_markup (priv->subject);
1234 markup_text = g_strdup_printf ("<span weight=\"bold\">%s</span> %s",
1235 _("Topic:"), markup_topic);
1237 gtk_label_set_markup (GTK_LABEL (priv->label_topic), markup_text);
1238 g_free (markup_text);
1239 g_free (markup_topic);
1241 gtk_widget_show (priv->hbox_topic);
1243 if (priv->block_events_timeout_id == 0) {
1246 if (!EMP_STR_EMPTY (priv->subject)) {
1247 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
1249 str = g_strdup (_("No topic defined"));
1251 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
1255 else if (!tp_strdiff (name, "name")) {
1256 g_free (priv->name);
1257 priv->name = g_value_dup_string (value);
1258 g_object_notify (G_OBJECT (chat), "name");
1263 chat_input_text_get_word_from_iter (GtkTextIter *iter,
1267 GtkTextIter word_start = *iter;
1268 GtkTextIter word_end = *iter;
1271 if (gtk_text_iter_inside_word (&word_end) &&
1272 !gtk_text_iter_ends_word (&word_end)) {
1273 gtk_text_iter_forward_word_end (&word_end);
1278 if (gtk_text_iter_get_char (&tmp) == '\'') {
1279 gtk_text_iter_forward_char (&tmp);
1281 if (g_unichar_isalpha (gtk_text_iter_get_char (&tmp))) {
1282 gtk_text_iter_forward_word_end (&word_end);
1287 if (gtk_text_iter_inside_word (&word_start) ||
1288 gtk_text_iter_ends_word (&word_start)) {
1289 if (!gtk_text_iter_starts_word (&word_start) ||
1290 gtk_text_iter_equal (&word_start, &word_end)) {
1291 gtk_text_iter_backward_word_start (&word_start);
1295 gtk_text_iter_backward_char (&tmp);
1297 if (gtk_text_iter_get_char (&tmp) == '\'') {
1298 gtk_text_iter_backward_char (&tmp);
1300 if (g_unichar_isalpha (gtk_text_iter_get_char (&tmp))) {
1301 gtk_text_iter_backward_word_start (&word_start);
1306 *start = word_start;
1312 chat_input_text_buffer_insert_text_cb (GtkTextBuffer *buffer,
1313 GtkTextIter *location,
1318 GtkTextIter iter, pos;
1320 /* Remove all misspelled tags in the inserted text.
1321 * This happens when text is inserted within a misspelled word. */
1322 gtk_text_buffer_get_iter_at_offset (buffer, &iter,
1323 gtk_text_iter_get_offset (location) - len);
1324 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled",
1327 gtk_text_buffer_get_iter_at_mark (buffer, &pos, gtk_text_buffer_get_insert (buffer));
1330 GtkTextIter start, end;
1333 if (!chat_input_text_get_word_from_iter (&iter, &start, &end))
1336 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
1338 if (gtk_text_iter_in_range (&pos, &start, &end) ||
1339 gtk_text_iter_equal (&pos, &end) ||
1340 empathy_spell_check (str)) {
1341 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
1343 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
1348 } while (gtk_text_iter_forward_word_end (&iter) &&
1349 gtk_text_iter_compare (&iter, location) <= 0);
1353 chat_input_text_buffer_delete_range_cb (GtkTextBuffer *buffer,
1358 GtkTextIter word_start, word_end;
1360 if (chat_input_text_get_word_from_iter (start, &word_start, &word_end)) {
1361 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled",
1362 &word_start, &word_end);
1367 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
1370 if (gtk_text_buffer_get_char_count (buffer) == 0) {
1371 chat_composing_stop (chat);
1373 chat_composing_start (chat);
1378 chat_input_text_buffer_notify_cursor_position_cb (GtkTextBuffer *buffer,
1383 GtkTextIter prev_pos;
1384 GtkTextIter word_start;
1385 GtkTextIter word_end;
1389 mark = gtk_text_buffer_get_mark (buffer, "previous-cursor-position");
1391 gtk_text_buffer_get_iter_at_mark (buffer, &pos,
1392 gtk_text_buffer_get_insert (buffer));
1393 gtk_text_buffer_get_iter_at_mark (buffer, &prev_pos, mark);
1395 if (!chat_input_text_get_word_from_iter (&prev_pos, &word_start, &word_end))
1398 if (!gtk_text_iter_in_range (&pos, &word_start, &word_end) &&
1399 !gtk_text_iter_equal (&pos, &word_end)) {
1400 str = gtk_text_buffer_get_text (buffer,
1401 &word_start, &word_end, FALSE);
1403 if (!empathy_spell_check (str)) {
1404 gtk_text_buffer_apply_tag_by_name (buffer,
1405 "misspelled", &word_start, &word_end);
1407 gtk_text_buffer_remove_tag_by_name (buffer,
1408 "misspelled", &word_start, &word_end);
1415 gtk_text_buffer_move_mark (buffer, mark, &pos);
1419 empathy_isspace_cb (gunichar c,
1422 return g_unichar_isspace (c);
1426 chat_input_key_press_event_cb (GtkWidget *widget,
1430 EmpathyChatPriv *priv;
1433 GtkWidget *text_view_sw;
1435 priv = GET_PRIV (chat);
1437 /* Catch ctrl+up/down so we can traverse messages we sent */
1438 if ((event->state & GDK_CONTROL_MASK) &&
1439 (event->keyval == GDK_KEY_Up ||
1440 event->keyval == GDK_KEY_Down)) {
1441 GtkTextBuffer *buffer;
1444 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1445 chat_input_history_update (chat, buffer);
1447 if (event->keyval == GDK_KEY_Up) {
1448 str = chat_input_history_get_next (chat);
1450 str = chat_input_history_get_prev (chat);
1453 g_signal_handlers_block_by_func (buffer,
1454 chat_input_text_buffer_changed_cb,
1456 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
1457 g_signal_handlers_unblock_by_func (buffer,
1458 chat_input_text_buffer_changed_cb,
1464 /* Catch enter but not ctrl/shift-enter */
1465 if (IS_ENTER (event->keyval) &&
1466 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
1469 /* This is to make sure that kinput2 gets the enter. And if
1470 * it's handled there we shouldn't send on it. This is because
1471 * kinput2 uses Enter to commit letters. See:
1472 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
1475 view = GTK_TEXT_VIEW (chat->input_text_view);
1476 if (gtk_text_view_im_context_filter_keypress (view, event)) {
1477 gtk_text_view_reset_im_context (view);
1481 chat_input_text_view_send (chat);
1485 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
1487 if (IS_ENTER (event->keyval) &&
1488 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
1489 /* Newline for shift/control-enter. */
1492 if (!(event->state & GDK_CONTROL_MASK) &&
1493 event->keyval == GDK_KEY_Page_Up) {
1494 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
1495 gtk_adjustment_set_value (adj, gtk_adjustment_get_value (adj) - gtk_adjustment_get_page_size (adj));
1498 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
1499 event->keyval == GDK_KEY_Page_Down) {
1500 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
1501 val = MIN (gtk_adjustment_get_value (adj) + gtk_adjustment_get_page_size (adj),
1502 gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj));
1503 gtk_adjustment_set_value (adj, val);
1506 if (event->keyval == GDK_KEY_Escape) {
1507 empathy_search_bar_hide (EMPATHY_SEARCH_BAR (priv->search_bar));
1509 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
1510 event->keyval == GDK_KEY_Tab) {
1511 GtkTextBuffer *buffer;
1512 GtkTextIter start, current;
1513 gchar *nick, *completed;
1514 GList *list, *completed_list;
1515 gboolean is_start_of_buffer;
1517 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
1518 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
1520 /* Get the start of the nick to complete. */
1521 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
1522 if (gtk_text_iter_backward_find_char (&start, &empathy_isspace_cb, NULL, NULL)) {
1523 gtk_text_iter_set_offset (&start, gtk_text_iter_get_offset (&start) + 1);
1525 is_start_of_buffer = gtk_text_iter_is_start (&start);
1527 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
1528 g_completion_add_items (priv->completion, list);
1530 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
1531 completed_list = g_completion_complete (priv->completion,
1540 GString *message = NULL;
1543 gtk_text_buffer_delete (buffer, &start, ¤t);
1545 len = g_list_length (completed_list);
1548 /* If we only have one hit, use that text
1549 * instead of the text in completed since the
1550 * completed text will use the typed string
1551 * which might be cased all wrong.
1554 text = empathy_contact_get_alias (completed_list->data);
1558 /* Print all hits to the scrollback view, so the
1559 * user knows what possibilities he has.
1562 message = g_string_new ("");
1563 for (l = completed_list; l != NULL; l = l->next) {
1564 g_string_append (message, empathy_contact_get_alias (l->data));
1565 g_string_append (message, " - ");
1567 empathy_chat_view_append_event (chat->view, message->str);
1568 g_string_free (message, TRUE);
1571 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
1573 if (len == 1 && is_start_of_buffer) {
1574 gchar *complete_char;
1576 complete_char = g_settings_get_string (
1577 priv->gsettings_chat,
1578 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR);
1580 if (complete_char != NULL) {
1581 gtk_text_buffer_insert_at_cursor (buffer,
1583 strlen (complete_char));
1584 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
1585 g_free (complete_char);
1592 g_completion_clear_items (priv->completion);
1594 g_list_foreach (list, (GFunc) g_object_unref, NULL);
1604 chat_text_view_focus_in_event_cb (GtkWidget *widget,
1608 gtk_widget_grab_focus (chat->input_text_view);
1614 chat_input_set_size_request_idle (gpointer sw)
1616 gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT);
1622 chat_input_size_request_cb (GtkWidget *widget,
1623 GtkRequisition *requisition,
1626 EmpathyChatPriv *priv = GET_PRIV (chat);
1629 sw = gtk_widget_get_parent (widget);
1630 if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) {
1631 g_idle_add (chat_input_set_size_request_idle, sw);
1632 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
1635 priv->has_input_vscroll = TRUE;
1638 if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) {
1639 gtk_widget_set_size_request (sw, -1, -1);
1640 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
1643 priv->has_input_vscroll = FALSE;
1648 chat_input_realize_cb (GtkWidget *widget,
1651 DEBUG ("Setting focus to the input text view");
1652 if (gtk_widget_is_sensitive (widget)) {
1653 gtk_widget_grab_focus (widget);
1658 chat_insert_smiley_activate_cb (EmpathySmileyManager *manager,
1659 EmpathySmiley *smiley,
1662 EmpathyChat *chat = EMPATHY_CHAT (user_data);
1663 GtkTextBuffer *buffer;
1666 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1668 gtk_text_buffer_get_end_iter (buffer, &iter);
1669 gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
1671 gtk_text_buffer_get_end_iter (buffer, &iter);
1672 gtk_text_buffer_insert (buffer, &iter, " ", -1);
1683 static EmpathyChatSpell *
1684 chat_spell_new (EmpathyChat *chat,
1689 EmpathyChatSpell *chat_spell;
1691 chat_spell = g_slice_new0 (EmpathyChatSpell);
1693 chat_spell->chat = g_object_ref (chat);
1694 chat_spell->word = g_strdup (word);
1695 chat_spell->start = start;
1696 chat_spell->end = end;
1702 chat_spell_free (EmpathyChatSpell *chat_spell)
1704 g_object_unref (chat_spell->chat);
1705 g_free (chat_spell->word);
1706 g_slice_free (EmpathyChatSpell, chat_spell);
1710 chat_spelling_menu_activate_cb (GtkMenuItem *menu_item,
1711 EmpathyChatSpell *chat_spell)
1713 empathy_chat_correct_word (chat_spell->chat,
1714 &(chat_spell->start),
1716 gtk_menu_item_get_label (menu_item));
1721 chat_spelling_build_suggestions_menu (const gchar *code,
1722 EmpathyChatSpell *chat_spell)
1724 GList *suggestions, *l;
1725 GtkWidget *menu, *menu_item;
1727 suggestions = empathy_spell_get_suggestions (code, chat_spell->word);
1728 if (suggestions == NULL)
1731 menu = gtk_menu_new ();
1732 for (l = suggestions; l; l = l->next) {
1733 menu_item = gtk_menu_item_new_with_label (l->data);
1734 g_signal_connect (G_OBJECT (menu_item), "activate",
1735 G_CALLBACK (chat_spelling_menu_activate_cb),
1737 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
1739 empathy_spell_free_suggestions (suggestions);
1741 gtk_widget_show_all (menu);
1747 chat_spelling_build_menu (EmpathyChatSpell *chat_spell)
1749 GtkWidget *menu, *submenu, *item;
1752 codes = empathy_spell_get_enabled_language_codes ();
1753 g_assert (codes != NULL);
1755 if (g_list_length (codes) > 1) {
1756 menu = gtk_menu_new ();
1758 for (l = codes; l; l = l->next) {
1759 const gchar *code, *name;
1762 name = empathy_spell_get_language_name (code);
1766 item = gtk_image_menu_item_new_with_label (name);
1768 submenu = chat_spelling_build_suggestions_menu (
1770 if (submenu == NULL)
1771 gtk_widget_set_sensitive (item, FALSE);
1773 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item),
1775 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1778 menu = chat_spelling_build_suggestions_menu (codes->data,
1781 menu = gtk_menu_new ();
1782 item = gtk_menu_item_new_with_label (_("(No Suggestions)"));
1783 gtk_widget_set_sensitive (item, FALSE);
1784 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
1787 g_list_free (codes);
1789 gtk_widget_show_all (menu);
1800 static EmpathyChatWord *
1801 chat_word_new (EmpathyChat *chat,
1805 EmpathyChatWord *chat_word;
1807 chat_word = g_slice_new0 (EmpathyChatWord);
1809 chat_word->chat = g_object_ref (chat);
1810 chat_word->word = g_strdup (word);
1811 chat_word->code = g_strdup (code);
1817 chat_word_free (EmpathyChatWord *chat_word)
1819 g_object_unref (chat_word->chat);
1820 g_free (chat_word->word);
1821 g_free (chat_word->code);
1822 g_slice_free (EmpathyChatWord, chat_word);
1826 chat_add_to_dictionary_activate_cb (GtkMenuItem *menu_item,
1827 EmpathyChatWord *chat_word)
1829 EmpathyChatPriv *priv = GET_PRIV (chat_word->chat);
1831 empathy_spell_add_to_dictionary (chat_word->code,
1833 priv->update_misspelled_words_id =
1834 g_idle_add (update_misspelled_words, chat_word->chat);
1838 chat_spelling_build_add_to_dictionary_item (EmpathyChatSpell *chat_spell)
1840 GtkWidget *menu, *item, *lang_item, *image;
1843 const gchar *code, *name;
1844 EmpathyChatWord *chat_word;
1846 codes = empathy_spell_get_enabled_language_codes ();
1847 g_assert (codes != NULL);
1848 if (g_list_length (codes) > 1) {
1849 /* translators: %s is the selected word */
1850 label = g_strdup_printf (_("Add '%s' to Dictionary"),
1852 item = gtk_image_menu_item_new_with_mnemonic (label);
1854 image = gtk_image_new_from_icon_name (GTK_STOCK_ADD,
1855 GTK_ICON_SIZE_MENU);
1856 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
1859 menu = gtk_menu_new ();
1861 for (l = codes; l; l = l->next) {
1863 name = empathy_spell_get_language_name (code);
1867 lang_item = gtk_image_menu_item_new_with_label (name);
1869 chat_word= chat_word_new (chat_spell->chat,
1870 chat_spell->word, code);
1871 g_object_set_data_full (G_OBJECT (lang_item),
1872 "chat-word", chat_word,
1873 (GDestroyNotify) chat_word_free);
1875 g_signal_connect (G_OBJECT (lang_item), "activate",
1876 G_CALLBACK (chat_add_to_dictionary_activate_cb),
1878 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), lang_item);
1880 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
1883 name = empathy_spell_get_language_name (code);
1884 g_assert (name != NULL);
1885 /* translators: first %s is the selected word,
1886 * second %s is the language name of the target dictionary */
1887 label = g_strdup_printf (_("Add '%s' to %s Dictionary"),
1888 chat_spell->word, name);
1889 item = gtk_image_menu_item_new_with_mnemonic (label);
1891 image = gtk_image_new_from_icon_name (GTK_STOCK_ADD,
1892 GTK_ICON_SIZE_MENU);
1893 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1895 chat_word = chat_word_new (chat_spell->chat, chat_spell->word,
1897 g_object_set_data_full (G_OBJECT (item), "chat-word", chat_word,
1898 (GDestroyNotify) chat_word_free);
1900 g_signal_connect (G_OBJECT (item), "activate",
1901 G_CALLBACK (chat_add_to_dictionary_activate_cb),
1904 g_list_free (codes);
1906 gtk_widget_show_all (item);
1912 chat_text_send_cb (GtkMenuItem *menuitem,
1915 chat_input_text_view_send (chat);
1919 chat_input_populate_popup_cb (GtkTextView *view,
1923 EmpathyChatPriv *priv;
1924 GtkTextBuffer *buffer;
1925 GtkTextTagTable *table;
1928 GtkTextIter iter, start, end;
1931 EmpathyChatSpell *chat_spell;
1932 GtkWidget *spell_menu;
1933 GtkWidget *spell_item;
1934 EmpathySmileyManager *smiley_manager;
1935 GtkWidget *smiley_menu;
1938 priv = GET_PRIV (chat);
1939 buffer = gtk_text_view_get_buffer (view);
1941 /* Add the emoticon menu. */
1942 item = gtk_separator_menu_item_new ();
1943 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1944 gtk_widget_show (item);
1946 item = gtk_image_menu_item_new_with_mnemonic (_("Insert Smiley"));
1947 image = gtk_image_new_from_icon_name ("face-smile",
1948 GTK_ICON_SIZE_MENU);
1949 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
1950 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1951 gtk_widget_show (item);
1953 smiley_manager = empathy_smiley_manager_dup_singleton ();
1954 smiley_menu = empathy_smiley_menu_new (smiley_manager,
1955 chat_insert_smiley_activate_cb,
1957 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
1958 g_object_unref (smiley_manager);
1960 /* Add the Send menu item. */
1961 gtk_text_buffer_get_bounds (buffer, &start, &end);
1962 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
1963 if (!EMP_STR_EMPTY (str)) {
1964 item = gtk_menu_item_new_with_mnemonic (_("_Send"));
1965 g_signal_connect (G_OBJECT (item), "activate",
1966 G_CALLBACK (chat_text_send_cb), chat);
1967 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1968 gtk_widget_show (item);
1972 /* Add the spell check menu item. */
1973 table = gtk_text_buffer_get_tag_table (buffer);
1974 tag = gtk_text_tag_table_lookup (table, "misspelled");
1975 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
1976 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
1977 GTK_TEXT_WINDOW_WIDGET,
1980 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view), &iter, x, y);
1982 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
1983 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
1985 str = gtk_text_buffer_get_text (buffer,
1986 &start, &end, FALSE);
1988 if (!EMP_STR_EMPTY (str)) {
1989 chat_spell = chat_spell_new (chat, str, start, end);
1990 g_object_set_data_full (G_OBJECT (menu),
1991 "chat-spell", chat_spell,
1992 (GDestroyNotify) chat_spell_free);
1994 item = gtk_separator_menu_item_new ();
1995 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
1996 gtk_widget_show (item);
1998 /* Spelling suggestions */
1999 item = gtk_image_menu_item_new_with_mnemonic (_("_Spelling Suggestions"));
2000 image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK,
2001 GTK_ICON_SIZE_MENU);
2002 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
2004 spell_menu = chat_spelling_build_menu (chat_spell);
2005 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), spell_menu);
2008 spell_item = gtk_separator_menu_item_new ();
2009 gtk_menu_shell_append (GTK_MENU_SHELL (spell_menu), spell_item);
2010 gtk_widget_show (spell_item);
2012 /* Add to dictionary */
2013 spell_item = chat_spelling_build_add_to_dictionary_item (chat_spell);
2015 gtk_menu_shell_append (GTK_MENU_SHELL (spell_menu), spell_item);
2016 gtk_widget_show (spell_item);
2018 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
2019 gtk_widget_show (item);
2025 chat_log_filter (TplEntry *log,
2028 EmpathyChat *chat = user_data;
2029 EmpathyMessage *message;
2030 EmpathyChatPriv *priv = GET_PRIV (chat);
2031 const GList *pending;
2033 g_return_val_if_fail (TPL_IS_ENTRY (log), FALSE);
2034 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
2036 pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
2037 message = empathy_message_from_tpl_log_entry (log);
2039 for (; pending; pending = g_list_next (pending)) {
2040 if (empathy_message_equal (message, pending->data)) {
2045 g_object_unref (message);
2051 show_pending_messages (EmpathyChat *chat) {
2052 EmpathyChatPriv *priv = GET_PRIV (chat);
2053 const GList *messages, *l;
2055 g_return_if_fail (EMPATHY_IS_CHAT (chat));
2057 if (chat->view == NULL || priv->tp_chat == NULL)
2060 if (!priv->can_show_pending)
2063 messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
2065 for (l = messages; l != NULL ; l = g_list_next (l)) {
2066 EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
2067 chat_message_received (chat, message);
2073 got_filtered_messages_cb (GObject *manager,
2074 GAsyncResult *result,
2079 EmpathyChat *chat = EMPATHY_CHAT (user_data);
2080 EmpathyChatPriv *priv = GET_PRIV (chat);
2081 GError *error = NULL;
2083 if (!tpl_log_manager_get_filtered_messages_finish (TPL_LOG_MANAGER (manager),
2084 result, &messages, &error)) {
2085 DEBUG ("%s. Aborting.", error->message);
2086 empathy_chat_view_append_event (chat->view,
2087 _("Failed to retrieve recent logs"));
2088 g_error_free (error);
2092 for (l = messages; l; l = g_list_next (l)) {
2093 EmpathyMessage *message;
2094 g_assert (TPL_IS_ENTRY (l->data));
2096 message = empathy_message_from_tpl_log_entry (l->data);
2097 g_object_unref (l->data);
2099 empathy_chat_view_append_message (chat->view, message);
2100 g_object_unref (message);
2102 g_list_free (messages);
2105 /* in case of TPL error, skip backlog and show pending messages */
2106 priv->can_show_pending = TRUE;
2107 show_pending_messages (chat);
2109 /* FIXME: See Bug#610994, we are forcing the ACK of the queue. See comments
2110 * about it in EmpathyChatPriv definition */
2111 priv->retrieving_backlogs = FALSE;
2112 empathy_chat_messages_read (chat);
2114 /* Turn back on scrolling */
2115 empathy_chat_view_scroll (chat->view, TRUE);
2119 chat_add_logs (EmpathyChat *chat)
2121 EmpathyChatPriv *priv = GET_PRIV (chat);
2122 gboolean is_chatroom;
2128 /* Turn off scrolling temporarily */
2129 empathy_chat_view_scroll (chat->view, FALSE);
2131 /* Add messages from last conversation */
2132 is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
2134 priv->retrieving_backlogs = TRUE;
2135 tpl_log_manager_get_filtered_messages_async (priv->log_manager,
2142 got_filtered_messages_cb,
2147 chat_contacts_completion_func (const gchar *s1,
2151 gchar *tmp, *nick1, *nick2;
2158 return s1 ? -1 : +1;
2161 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
2162 nick1 = g_utf8_casefold (tmp, -1);
2165 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
2166 nick2 = g_utf8_casefold (tmp, -1);
2169 ret = strncmp (nick1, nick2, n);
2178 build_part_message (guint reason,
2180 EmpathyContact *actor,
2181 const gchar *message)
2183 GString *s = g_string_new ("");
2184 const gchar *actor_name = NULL;
2186 if (actor != NULL) {
2187 actor_name = empathy_contact_get_alias (actor);
2190 /* Having an actor only really makes sense for a few actions... */
2192 case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE:
2193 g_string_append_printf (s, _("%s has disconnected"), name);
2195 case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED:
2196 if (actor_name != NULL) {
2197 /* translators: reverse the order of these arguments
2198 * if the kicked should come before the kicker in your locale.
2200 g_string_append_printf (s, _("%1$s was kicked by %2$s"),
2203 g_string_append_printf (s, _("%s was kicked"), name);
2206 case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED:
2207 if (actor_name != NULL) {
2208 /* translators: reverse the order of these arguments
2209 * if the banned should come before the banner in your locale.
2211 g_string_append_printf (s, _("%1$s was banned by %2$s"),
2214 g_string_append_printf (s, _("%s was banned"), name);
2218 g_string_append_printf (s, _("%s has left the room"), name);
2221 if (!EMP_STR_EMPTY (message)) {
2222 /* Note to translators: this string is appended to
2223 * notifications like "foo has left the room", with the message
2224 * given by the user living the room. If this poses a problem,
2225 * please let us know. :-)
2227 g_string_append_printf (s, _(" (%s)"), message);
2230 return g_string_free (s, FALSE);
2234 chat_members_changed_cb (EmpathyTpChat *tp_chat,
2235 EmpathyContact *contact,
2236 EmpathyContact *actor,
2242 EmpathyChatPriv *priv = GET_PRIV (chat);
2243 const gchar *name = empathy_contact_get_alias (contact);
2246 g_return_if_fail (TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED != reason);
2248 if (priv->block_events_timeout_id != 0)
2252 str = g_strdup_printf (_("%s has joined the room"),
2255 str = build_part_message (reason, name, actor, message);
2258 empathy_chat_view_append_event (chat->view, str);
2263 chat_member_renamed_cb (EmpathyTpChat *tp_chat,
2264 EmpathyContact *old_contact,
2265 EmpathyContact *new_contact,
2270 EmpathyChatPriv *priv = GET_PRIV (chat);
2272 g_return_if_fail (TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED == reason);
2274 if (priv->block_events_timeout_id == 0) {
2277 str = g_strdup_printf (_("%s is now known as %s"),
2278 empathy_contact_get_alias (old_contact),
2279 empathy_contact_get_alias (new_contact));
2280 empathy_chat_view_append_event (chat->view, str);
2287 chat_reset_size_request (gpointer widget)
2289 gtk_widget_set_size_request (widget, -1, -1);
2295 chat_update_contacts_visibility (EmpathyChat *chat,
2298 EmpathyChatPriv *priv = GET_PRIV (chat);
2299 GtkAllocation allocation;
2301 if (!priv->scrolled_window_contacts) {
2305 if (priv->remote_contact != NULL) {
2309 if (show && priv->contact_list_view == NULL) {
2310 EmpathyContactListStore *store;
2313 /* We are adding the contact list to the chat, we don't want the
2314 * chat view to become too small. If the chat view is already
2315 * smaller than 250 make sure that size won't change. If the
2316 * chat view is bigger the contact list will take some space on
2317 * it but we make sure the chat view don't become smaller than
2318 * 250. Relax the size request once the resize is done */
2319 gtk_widget_get_allocation (priv->vbox_left, &allocation);
2320 min_width = MIN (allocation.width, 250);
2321 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
2322 g_idle_add (chat_reset_size_request, priv->vbox_left);
2324 if (priv->contacts_width > 0) {
2325 gtk_paned_set_position (GTK_PANED (priv->hpaned),
2326 priv->contacts_width);
2329 store = empathy_contact_list_store_new (
2330 EMPATHY_CONTACT_LIST (priv->tp_chat));
2331 empathy_contact_list_store_set_show_groups (
2332 EMPATHY_CONTACT_LIST_STORE (store), FALSE);
2334 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
2335 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_TOOLTIP,
2336 EMPATHY_CONTACT_FEATURE_CHAT |
2337 EMPATHY_CONTACT_FEATURE_CALL |
2338 EMPATHY_CONTACT_FEATURE_LOG |
2339 EMPATHY_CONTACT_FEATURE_INFO));
2340 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
2341 priv->contact_list_view);
2342 gtk_widget_show (priv->contact_list_view);
2343 gtk_widget_show (priv->scrolled_window_contacts);
2344 g_object_unref (store);
2346 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
2347 gtk_widget_hide (priv->scrolled_window_contacts);
2348 if (priv->contact_list_view != NULL) {
2349 gtk_widget_destroy (priv->contact_list_view);
2350 priv->contact_list_view = NULL;
2356 empathy_chat_set_show_contacts (EmpathyChat *chat,
2359 EmpathyChatPriv *priv = GET_PRIV (chat);
2361 priv->show_contacts = show;
2363 chat_update_contacts_visibility (chat, show);
2365 g_object_notify (G_OBJECT (chat), "show-contacts");
2369 chat_remote_contact_changed_cb (EmpathyChat *chat)
2371 EmpathyChatPriv *priv = GET_PRIV (chat);
2373 if (priv->remote_contact != NULL) {
2374 g_object_unref (priv->remote_contact);
2375 priv->remote_contact = NULL;
2380 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
2381 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
2382 if (priv->remote_contact != NULL) {
2383 g_object_ref (priv->remote_contact);
2384 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
2386 else if (priv->tp_chat != NULL) {
2389 channel = empathy_tp_chat_get_channel (priv->tp_chat);
2390 g_object_get (channel, "handle-type", &priv->handle_type, NULL);
2393 chat_update_contacts_visibility (chat, priv->show_contacts);
2395 g_object_notify (G_OBJECT (chat), "remote-contact");
2396 g_object_notify (G_OBJECT (chat), "id");
2400 chat_destroy_cb (EmpathyTpChat *tp_chat,
2403 EmpathyChatPriv *priv;
2405 priv = GET_PRIV (chat);
2407 if (!priv->tp_chat) {
2411 chat_composing_remove_timeout (chat);
2412 g_object_unref (priv->tp_chat);
2413 priv->tp_chat = NULL;
2414 g_object_notify (G_OBJECT (chat), "tp-chat");
2416 empathy_chat_view_append_event (chat->view, _("Disconnected"));
2417 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
2419 chat_update_contacts_visibility (chat, FALSE);
2423 update_misspelled_words (gpointer data)
2425 EmpathyChat *chat = EMPATHY_CHAT (data);
2426 EmpathyChatPriv *priv = GET_PRIV (chat);
2427 GtkTextBuffer *buffer;
2431 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
2433 gtk_text_buffer_get_end_iter (buffer, &iter);
2434 length = gtk_text_iter_get_offset (&iter);
2435 chat_input_text_buffer_insert_text_cb (buffer, &iter,
2436 NULL, length, chat);
2438 priv->update_misspelled_words_id = 0;
2444 conf_spell_checking_cb (GSettings *gsettings_chat,
2448 EmpathyChat *chat = EMPATHY_CHAT (user_data);
2449 EmpathyChatPriv *priv = GET_PRIV (chat);
2450 gboolean spell_checker;
2451 GtkTextBuffer *buffer;
2453 if (strcmp (key, EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED) != 0)
2456 spell_checker = g_settings_get_boolean (gsettings_chat,
2457 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED);
2459 if (!empathy_spell_supported ()) {
2460 spell_checker = FALSE;
2463 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
2465 if (spell_checker == priv->spell_checking_enabled) {
2466 if (spell_checker) {
2467 /* Possibly changed dictionaries,
2468 * update misspelled words. Need to do so in idle
2469 * so the spell checker is updated. */
2470 priv->update_misspelled_words_id =
2471 g_idle_add (update_misspelled_words, chat);
2477 if (spell_checker) {
2480 priv->notify_cursor_position_id = tp_g_signal_connect_object (
2481 buffer, "notify::cursor-position",
2482 G_CALLBACK (chat_input_text_buffer_notify_cursor_position_cb),
2484 priv->insert_text_id = tp_g_signal_connect_object (
2485 buffer, "insert-text",
2486 G_CALLBACK (chat_input_text_buffer_insert_text_cb),
2487 chat, G_CONNECT_AFTER);
2488 priv->delete_range_id = tp_g_signal_connect_object (
2489 buffer, "delete-range",
2490 G_CALLBACK (chat_input_text_buffer_delete_range_cb),
2491 chat, G_CONNECT_AFTER);
2493 gtk_text_buffer_create_tag (buffer, "misspelled",
2494 "underline", PANGO_UNDERLINE_ERROR,
2497 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
2498 gtk_text_buffer_get_insert (buffer));
2499 gtk_text_buffer_create_mark (buffer, "previous-cursor-position",
2502 /* Mark misspelled words in the existing buffer.
2503 * Need to do so in idle so the spell checker is updated. */
2504 priv->update_misspelled_words_id =
2505 g_idle_add (update_misspelled_words, chat);
2507 GtkTextTagTable *table;
2510 g_signal_handler_disconnect (buffer, priv->notify_cursor_position_id);
2511 priv->notify_cursor_position_id = 0;
2512 g_signal_handler_disconnect (buffer, priv->insert_text_id);
2513 priv->insert_text_id = 0;
2514 g_signal_handler_disconnect (buffer, priv->delete_range_id);
2515 priv->delete_range_id = 0;
2517 table = gtk_text_buffer_get_tag_table (buffer);
2518 tag = gtk_text_tag_table_lookup (table, "misspelled");
2519 gtk_text_tag_table_remove (table, tag);
2521 gtk_text_buffer_delete_mark_by_name (buffer,
2522 "previous-cursor-position");
2525 priv->spell_checking_enabled = spell_checker;
2529 chat_hpaned_pos_changed_cb (GtkWidget* hpaned,
2533 EmpathyChat *chat = EMPATHY_CHAT (user_data);
2536 hpaned_pos = gtk_paned_get_position (GTK_PANED(hpaned));
2537 g_settings_set_int (chat->priv->gsettings_ui,
2538 EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS,
2545 chat_create_ui (EmpathyChat *chat)
2547 EmpathyChatPriv *priv = GET_PRIV (chat);
2551 GtkTextBuffer *buffer;
2554 filename = empathy_file_lookup ("empathy-chat.ui",
2556 gui = empathy_builder_get_file (filename,
2557 "chat_widget", &priv->widget,
2558 "hpaned", &priv->hpaned,
2559 "vbox_left", &priv->vbox_left,
2560 "scrolled_window_chat", &priv->scrolled_window_chat,
2561 "scrolled_window_input", &priv->scrolled_window_input,
2562 "hbox_topic", &priv->hbox_topic,
2563 "expander_topic", &priv->expander_topic,
2564 "label_topic", &priv->label_topic,
2565 "scrolled_window_contacts", &priv->scrolled_window_contacts,
2566 "info_bar_vbox", &priv->info_bar_vbox,
2569 empathy_builder_connect (gui, chat,
2570 "expander_topic", "notify::expanded", chat_topic_expander_activate_cb,
2571 "label_topic", "size-allocate", chat_topic_label_size_allocate_cb,
2576 /* Add message view. */
2577 chat->view = empathy_theme_manager_create_view (empathy_theme_manager_get ());
2578 /* If this is a GtkTextView, it's set as a drag destination for text/plain
2579 and other types, even though it's non-editable and doesn't accept any
2580 drags. This steals drag motion for anything inside the scrollbars,
2581 making drag destinations on chat windows far less useful.
2583 gtk_drag_dest_unset (GTK_WIDGET (chat->view));
2584 g_signal_connect (chat->view, "focus_in_event",
2585 G_CALLBACK (chat_text_view_focus_in_event_cb),
2587 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
2588 GTK_WIDGET (chat->view));
2589 gtk_widget_show (GTK_WIDGET (chat->view));
2591 /* Add input GtkTextView */
2592 chat->input_text_view = empathy_input_text_view_new ();
2594 g_signal_connect (chat->input_text_view, "key-press-event",
2595 G_CALLBACK (chat_input_key_press_event_cb),
2597 g_signal_connect (chat->input_text_view, "size-request",
2598 G_CALLBACK (chat_input_size_request_cb),
2600 g_signal_connect (chat->input_text_view, "realize",
2601 G_CALLBACK (chat_input_realize_cb),
2603 g_signal_connect (chat->input_text_view, "populate-popup",
2604 G_CALLBACK (chat_input_populate_popup_cb),
2606 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
2607 tp_g_signal_connect_object (buffer, "changed",
2608 G_CALLBACK (chat_input_text_buffer_changed_cb),
2610 tp_g_signal_connect_object (priv->gsettings_chat,
2611 "changed::" EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
2612 G_CALLBACK (conf_spell_checking_cb), chat, 0);
2613 conf_spell_checking_cb (priv->gsettings_chat,
2614 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED, chat);
2615 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
2616 chat->input_text_view);
2617 gtk_widget_show (chat->input_text_view);
2619 /* Add the (invisible) search bar */
2620 priv->search_bar = empathy_search_bar_new (chat->view);
2621 gtk_box_pack_start (GTK_BOX(priv->vbox_left),
2624 gtk_box_reorder_child (GTK_BOX(priv->vbox_left), priv->search_bar, 1);
2626 /* Initialy hide the topic, will be shown if not empty */
2627 gtk_widget_hide (priv->hbox_topic);
2629 g_signal_connect (priv->hpaned, "notify::position",
2630 G_CALLBACK (chat_hpaned_pos_changed_cb),
2633 /* Load the paned position */
2634 paned_pos = g_settings_get_int (priv->gsettings_ui,
2635 EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS);
2637 gtk_paned_set_position (GTK_PANED(priv->hpaned), paned_pos);
2639 /* Set widget focus order */
2640 list = g_list_append (NULL, priv->search_bar);
2641 list = g_list_append (list, priv->scrolled_window_input);
2642 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
2645 list = g_list_append (NULL, priv->vbox_left);
2646 list = g_list_append (list, priv->scrolled_window_contacts);
2647 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
2650 list = g_list_append (NULL, priv->hpaned);
2651 list = g_list_append (list, priv->hbox_topic);
2652 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
2655 /* Add the main widget in the chat widget */
2656 gtk_container_add (GTK_CONTAINER (chat), priv->widget);
2657 g_object_unref (gui);
2661 chat_size_allocate (GtkWidget *widget,
2662 GtkAllocation *allocation)
2664 GtkBin *bin = GTK_BIN (widget);
2665 GtkAllocation child_allocation;
2668 gtk_widget_set_allocation (widget, allocation);
2670 child = gtk_bin_get_child (bin);
2672 if (child && gtk_widget_get_visible (child))
2674 child_allocation.x = allocation->x + gtk_container_get_border_width (GTK_CONTAINER (widget));
2675 child_allocation.y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (widget));
2676 child_allocation.width = MAX (allocation->width - gtk_container_get_border_width (GTK_CONTAINER (widget)) * 2, 0);
2677 child_allocation.height = MAX (allocation->height - gtk_container_get_border_width (GTK_CONTAINER (widget)) * 2, 0);
2679 gtk_widget_size_allocate (child, &child_allocation);
2684 chat_finalize (GObject *object)
2687 EmpathyChatPriv *priv;
2689 chat = EMPATHY_CHAT (object);
2690 priv = GET_PRIV (chat);
2692 DEBUG ("Finalized: %p", object);
2694 if (priv->update_misspelled_words_id != 0)
2695 g_source_remove (priv->update_misspelled_words_id);
2697 g_object_unref (priv->gsettings_chat);
2698 g_object_unref (priv->gsettings_ui);
2700 g_list_foreach (priv->input_history, (GFunc) chat_input_history_entry_free, NULL);
2701 g_list_free (priv->input_history);
2703 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
2704 g_list_free (priv->compositors);
2706 chat_composing_remove_timeout (chat);
2708 g_object_unref (priv->account_manager);
2709 g_object_unref (priv->log_manager);
2711 if (priv->tp_chat) {
2712 g_signal_handlers_disconnect_by_func (priv->tp_chat,
2713 chat_destroy_cb, chat);
2714 g_signal_handlers_disconnect_by_func (priv->tp_chat,
2715 chat_message_received_cb, chat);
2716 g_signal_handlers_disconnect_by_func (priv->tp_chat,
2717 chat_send_error_cb, chat);
2718 g_signal_handlers_disconnect_by_func (priv->tp_chat,
2719 chat_state_changed_cb, chat);
2720 g_signal_handlers_disconnect_by_func (priv->tp_chat,
2721 chat_property_changed_cb, chat);
2722 g_signal_handlers_disconnect_by_func (priv->tp_chat,
2723 chat_members_changed_cb, chat);
2724 g_signal_handlers_disconnect_by_func (priv->tp_chat,
2725 chat_remote_contact_changed_cb, chat);
2726 empathy_tp_chat_leave (priv->tp_chat);
2727 g_object_unref (priv->tp_chat);
2729 if (priv->account) {
2730 g_object_unref (priv->account);
2732 if (priv->remote_contact) {
2733 g_object_unref (priv->remote_contact);
2736 if (priv->block_events_timeout_id) {
2737 g_source_remove (priv->block_events_timeout_id);
2741 g_free (priv->name);
2742 g_free (priv->subject);
2743 g_completion_free (priv->completion);
2745 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
2749 chat_constructed (GObject *object)
2751 EmpathyChat *chat = EMPATHY_CHAT (object);
2752 EmpathyChatPriv *priv = GET_PRIV (chat);
2754 if (priv->handle_type != TP_HANDLE_TYPE_ROOM) {
2755 /* First display logs from the logger and then display pending messages */
2756 chat_add_logs (chat);
2759 /* Just display pending messages for rooms */
2760 priv->can_show_pending = TRUE;
2761 show_pending_messages (chat);
2766 empathy_chat_class_init (EmpathyChatClass *klass)
2768 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
2769 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2771 object_class->finalize = chat_finalize;
2772 object_class->get_property = chat_get_property;
2773 object_class->set_property = chat_set_property;
2774 object_class->constructed = chat_constructed;
2776 widget_class->size_allocate = chat_size_allocate;
2778 g_object_class_install_property (object_class,
2780 g_param_spec_object ("tp-chat",
2782 "The tp chat object",
2783 EMPATHY_TYPE_TP_CHAT,
2786 G_PARAM_STATIC_STRINGS));
2787 g_object_class_install_property (object_class,
2789 g_param_spec_object ("account",
2790 "Account of the chat",
2791 "The account of the chat",
2794 G_PARAM_STATIC_STRINGS));
2795 g_object_class_install_property (object_class,
2797 g_param_spec_string ("id",
2799 "The id of the chat",
2802 G_PARAM_STATIC_STRINGS));
2803 g_object_class_install_property (object_class,
2805 g_param_spec_string ("name",
2807 "The name of the chat",
2810 G_PARAM_STATIC_STRINGS));
2811 g_object_class_install_property (object_class,
2813 g_param_spec_string ("subject",
2815 "The subject or topic of the chat",
2818 G_PARAM_STATIC_STRINGS));
2819 g_object_class_install_property (object_class,
2820 PROP_REMOTE_CONTACT,
2821 g_param_spec_object ("remote-contact",
2822 "The remote contact",
2823 "The remote contact is any",
2824 EMPATHY_TYPE_CONTACT,
2826 G_PARAM_STATIC_STRINGS));
2827 g_object_class_install_property (object_class,
2829 g_param_spec_boolean ("show-contacts",
2830 "Contacts' visibility",
2831 "The visibility of the contacts' list",
2834 G_PARAM_STATIC_STRINGS));
2836 signals[COMPOSING] =
2837 g_signal_new ("composing",
2838 G_OBJECT_CLASS_TYPE (object_class),
2842 g_cclosure_marshal_VOID__BOOLEAN,
2846 signals[NEW_MESSAGE] =
2847 g_signal_new ("new-message",
2848 G_OBJECT_CLASS_TYPE (object_class),
2852 g_cclosure_marshal_VOID__OBJECT,
2854 1, EMPATHY_TYPE_MESSAGE);
2856 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
2860 chat_block_events_timeout_cb (gpointer data)
2862 EmpathyChatPriv *priv = GET_PRIV (data);
2864 priv->block_events_timeout_id = 0;
2870 account_manager_prepared_cb (GObject *source_object,
2871 GAsyncResult *result,
2874 GList *accounts, *l;
2875 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
2876 EmpathyChat *chat = user_data;
2877 GError *error = NULL;
2879 if (!tp_account_manager_prepare_finish (account_manager, result, &error)) {
2880 DEBUG ("Failed to prepare the account manager: %s", error->message);
2881 g_error_free (error);
2885 accounts = tp_account_manager_get_valid_accounts (account_manager);
2887 for (l = accounts; l != NULL; l = l->next) {
2888 TpAccount *account = l->data;
2889 tp_g_signal_connect_object (account, "status-changed",
2890 G_CALLBACK (chat_new_connection_cb),
2894 g_list_free (accounts);
2898 empathy_chat_init (EmpathyChat *chat)
2900 EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
2901 EMPATHY_TYPE_CHAT, EmpathyChatPriv);
2904 priv->log_manager = tpl_log_manager_dup_singleton ();
2905 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
2906 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
2908 priv->contacts_width = -1;
2909 priv->input_history = NULL;
2910 priv->input_history_current = NULL;
2911 priv->account_manager = tp_account_manager_dup ();
2913 tp_account_manager_prepare_async (priv->account_manager, NULL,
2914 account_manager_prepared_cb, chat);
2916 priv->show_contacts = g_settings_get_boolean (priv->gsettings_chat,
2917 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS);
2919 /* Block events for some time to avoid having "has come online" or
2920 * "joined" messages. */
2921 priv->block_events_timeout_id =
2922 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
2924 /* Add nick name completion */
2925 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_alias);
2926 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
2928 chat_create_ui (chat);
2932 empathy_chat_new (EmpathyTpChat *tp_chat)
2934 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
2938 empathy_chat_get_tp_chat (EmpathyChat *chat)
2940 EmpathyChatPriv *priv = GET_PRIV (chat);
2942 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
2944 return priv->tp_chat;
2947 static void display_password_info_bar (EmpathyChat *self,
2951 provide_password_cb (GObject *tp_chat,
2955 EmpathyChat *self = EMPATHY_CHAT (user_data);
2956 EmpathyChatPriv *priv = GET_PRIV (self);
2957 GError *error = NULL;
2959 if (!empathy_tp_chat_provide_password_finish (EMPATHY_TP_CHAT (tp_chat), res,
2961 DEBUG ("error: %s", error->message);
2962 /* FIXME: what should we do if that's another error? Close the channel?
2963 * Display the raw D-Bus error to the user isn't very useful */
2964 if (g_error_matches (error, TP_ERRORS, TP_ERROR_AUTHENTICATION_FAILED))
2965 display_password_info_bar (self, TRUE);
2966 g_error_free (error);
2971 gtk_widget_set_sensitive (priv->hpaned, TRUE);
2972 gtk_widget_grab_focus (self->input_text_view);
2976 password_infobar_response_cb (GtkWidget *info_bar,
2980 EmpathyChatPriv *priv = GET_PRIV (self);
2982 const gchar *password;
2984 if (response_id != GTK_RESPONSE_OK)
2987 entry = g_object_get_data (G_OBJECT (info_bar), "password-entry");
2988 g_assert (entry != NULL);
2990 password = gtk_entry_get_text (GTK_ENTRY (entry));
2992 empathy_tp_chat_provide_password_async (priv->tp_chat, password,
2993 provide_password_cb, self);
2996 gtk_widget_destroy (info_bar);
3000 password_entry_activate_cb (GtkWidget *entry,
3001 GtkWidget *info_bar)
3003 gtk_info_bar_response (GTK_INFO_BAR (info_bar), GTK_RESPONSE_OK);
3007 passwd_join_button_cb (GtkButton *button,
3008 GtkWidget *info_bar)
3010 gtk_info_bar_response (GTK_INFO_BAR (info_bar), GTK_RESPONSE_OK);
3014 display_password_info_bar (EmpathyChat *self,
3017 EmpathyChatPriv *priv = GET_PRIV (self);
3018 GtkWidget *info_bar;
3019 GtkWidget *content_area;
3026 GtkMessageType type;
3027 const gchar *msg, *button_label;
3030 /* Previous password was wrong */
3031 type = GTK_MESSAGE_ERROR;
3032 msg = _("Wrong password; please try again:");
3033 button_label = _("Retry");
3036 /* First time we're trying to join */
3037 type = GTK_MESSAGE_QUESTION;
3038 msg = _("This room is protected by a password:");
3039 button_label = _("Join");
3042 info_bar = gtk_info_bar_new ();
3043 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), type);
3045 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3047 hbox = gtk_hbox_new (FALSE, 3);
3048 gtk_container_add (GTK_CONTAINER (content_area), hbox);
3051 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
3052 GTK_ICON_SIZE_DIALOG);
3053 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3056 label = gtk_label_new (msg);
3057 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
3059 /* Add password entry */
3060 entry = gtk_entry_new ();
3061 gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
3062 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
3064 g_signal_connect (entry, "activate",
3065 G_CALLBACK (password_entry_activate_cb), info_bar);
3067 /* Focus the password entry once it's realized */
3068 g_signal_connect (entry, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
3070 /* Add 'Join' button */
3071 alig = gtk_alignment_new (0, 0.5, 0, 0);
3073 button = gtk_button_new_with_label (button_label);
3074 gtk_container_add (GTK_CONTAINER (alig), button);
3075 gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
3077 g_signal_connect (button, "clicked", G_CALLBACK (passwd_join_button_cb),
3080 g_object_set_data (G_OBJECT (info_bar), "password-entry", entry);
3082 gtk_box_pack_start (GTK_BOX (priv->info_bar_vbox), info_bar,
3084 gtk_widget_show_all (hbox);
3086 g_signal_connect (info_bar, "response",
3087 G_CALLBACK (password_infobar_response_cb), self);
3089 gtk_widget_show_all (info_bar);
3093 chat_password_needed_changed_cb (EmpathyChat *self)
3095 EmpathyChatPriv *priv = GET_PRIV (self);
3097 if (empathy_tp_chat_password_needed (priv->tp_chat)) {
3098 display_password_info_bar (self, FALSE);
3099 gtk_widget_set_sensitive (priv->hpaned, FALSE);
3104 empathy_chat_set_tp_chat (EmpathyChat *chat,
3105 EmpathyTpChat *tp_chat)
3107 EmpathyChatPriv *priv = GET_PRIV (chat);
3108 TpConnection *connection;
3109 GPtrArray *properties;
3111 g_return_if_fail (EMPATHY_IS_CHAT (chat));
3112 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
3113 g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
3115 if (priv->tp_chat) {
3119 if (priv->account) {
3120 g_object_unref (priv->account);
3123 priv->tp_chat = g_object_ref (tp_chat);
3124 connection = empathy_tp_chat_get_connection (priv->tp_chat);
3125 priv->account = g_object_ref (empathy_tp_chat_get_account (priv->tp_chat));
3127 g_signal_connect (tp_chat, "destroy",
3128 G_CALLBACK (chat_destroy_cb),
3130 g_signal_connect (tp_chat, "message-received",
3131 G_CALLBACK (chat_message_received_cb),
3133 g_signal_connect (tp_chat, "send-error",
3134 G_CALLBACK (chat_send_error_cb),
3136 g_signal_connect (tp_chat, "chat-state-changed",
3137 G_CALLBACK (chat_state_changed_cb),
3139 g_signal_connect (tp_chat, "property-changed",
3140 G_CALLBACK (chat_property_changed_cb),
3142 g_signal_connect (tp_chat, "members-changed",
3143 G_CALLBACK (chat_members_changed_cb),
3145 g_signal_connect (tp_chat, "member-renamed",
3146 G_CALLBACK (chat_member_renamed_cb),
3148 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
3149 G_CALLBACK (chat_remote_contact_changed_cb),
3151 g_signal_connect_swapped (tp_chat, "notify::password-needed",
3152 G_CALLBACK (chat_password_needed_changed_cb),
3155 /* Get initial value of properties */
3156 properties = empathy_tp_chat_get_properties (priv->tp_chat);
3157 if (properties != NULL) {
3160 for (i = 0; i < properties->len; i++) {
3161 EmpathyTpChatProperty *property;
3163 property = g_ptr_array_index (properties, i);
3164 if (property->value == NULL)
3167 chat_property_changed_cb (priv->tp_chat,
3174 chat_remote_contact_changed_cb (chat);
3176 if (chat->input_text_view) {
3177 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
3178 if (priv->block_events_timeout_id == 0) {
3179 empathy_chat_view_append_event (chat->view, _("Connected"));
3183 g_object_notify (G_OBJECT (chat), "tp-chat");
3184 g_object_notify (G_OBJECT (chat), "id");
3185 g_object_notify (G_OBJECT (chat), "account");
3187 /* This is a noop when tp-chat is set at object construction time and causes
3188 * the pending messages to be show when it's set on the object after it has
3190 show_pending_messages (chat);
3192 /* check if a password is needed */
3193 chat_password_needed_changed_cb (chat);
3197 empathy_chat_get_account (EmpathyChat *chat)
3199 EmpathyChatPriv *priv = GET_PRIV (chat);
3201 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3203 return priv->account;
3207 empathy_chat_get_id (EmpathyChat *chat)
3209 EmpathyChatPriv *priv = GET_PRIV (chat);
3211 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3217 empathy_chat_get_name (EmpathyChat *chat)
3219 EmpathyChatPriv *priv = GET_PRIV (chat);
3222 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3225 if (!ret && priv->remote_contact) {
3226 ret = empathy_contact_get_alias (priv->remote_contact);
3232 return ret ? ret : _("Conversation");
3236 empathy_chat_get_subject (EmpathyChat *chat)
3238 EmpathyChatPriv *priv = GET_PRIV (chat);
3240 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3242 return priv->subject;
3246 empathy_chat_get_remote_contact (EmpathyChat *chat)
3248 EmpathyChatPriv *priv = GET_PRIV (chat);
3250 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3252 return priv->remote_contact;
3256 empathy_chat_get_contact_menu (EmpathyChat *chat)
3258 EmpathyChatPriv *priv = GET_PRIV (chat);
3259 GtkWidget *menu = NULL;
3261 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3263 if (priv->remote_contact) {
3264 menu = empathy_contact_menu_new (priv->remote_contact,
3265 EMPATHY_CONTACT_FEATURE_CALL |
3266 EMPATHY_CONTACT_FEATURE_LOG |
3267 EMPATHY_CONTACT_FEATURE_INFO);
3269 else if (priv->contact_list_view) {
3270 EmpathyContactListView *view;
3272 view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
3273 menu = empathy_contact_list_view_get_contact_menu (view);
3280 empathy_chat_clear (EmpathyChat *chat)
3282 g_return_if_fail (EMPATHY_IS_CHAT (chat));
3284 empathy_chat_view_clear (chat->view);
3288 empathy_chat_scroll_down (EmpathyChat *chat)
3290 g_return_if_fail (EMPATHY_IS_CHAT (chat));
3292 empathy_chat_view_scroll_down (chat->view);
3296 empathy_chat_cut (EmpathyChat *chat)
3298 GtkTextBuffer *buffer;
3300 g_return_if_fail (EMPATHY_IS_CHAT (chat));
3302 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
3303 if (gtk_text_buffer_get_has_selection (buffer)) {
3304 GtkClipboard *clipboard;
3306 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3308 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
3313 empathy_chat_copy (EmpathyChat *chat)
3315 GtkTextBuffer *buffer;
3317 g_return_if_fail (EMPATHY_IS_CHAT (chat));
3319 if (empathy_chat_view_get_has_selection (chat->view)) {
3320 empathy_chat_view_copy_clipboard (chat->view);
3324 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
3325 if (gtk_text_buffer_get_has_selection (buffer)) {
3326 GtkClipboard *clipboard;
3328 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3330 gtk_text_buffer_copy_clipboard (buffer, clipboard);
3335 EmpathyChatPriv *priv = GET_PRIV (chat);
3337 if (gtk_label_get_selection_bounds (GTK_LABEL (priv->label_topic),
3344 GtkClipboard *clipboard;
3346 topic = gtk_label_get_text (GTK_LABEL (priv->label_topic));
3347 start = g_utf8_offset_to_pointer (topic, start_offset);
3348 end = g_utf8_offset_to_pointer (topic, end_offset);
3349 selection = g_strndup (start, end - start);
3351 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3352 gtk_clipboard_set_text (clipboard, selection, -1);
3360 empathy_chat_paste (EmpathyChat *chat)
3362 GtkTextBuffer *buffer;
3363 GtkClipboard *clipboard;
3364 EmpathyChatPriv *priv;
3366 g_return_if_fail (EMPATHY_IS_CHAT (chat));
3368 priv = GET_PRIV (chat);
3370 if (gtk_widget_get_visible (priv->search_bar)) {
3371 empathy_search_bar_paste_clipboard (EMPATHY_SEARCH_BAR (priv->search_bar));
3375 if (priv->tp_chat == NULL ||
3376 !gtk_widget_is_sensitive (chat->input_text_view))
3379 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
3380 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
3382 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
3386 empathy_chat_find (EmpathyChat *chat)
3388 EmpathyChatPriv *priv;
3390 g_return_if_fail (EMPATHY_IS_CHAT (chat));
3392 priv = GET_PRIV (chat);
3394 empathy_search_bar_show (EMPATHY_SEARCH_BAR (priv->search_bar));
3398 empathy_chat_correct_word (EmpathyChat *chat,
3401 const gchar *new_word)
3403 GtkTextBuffer *buffer;
3405 g_return_if_fail (chat != NULL);
3406 g_return_if_fail (new_word != NULL);
3408 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
3410 gtk_text_buffer_delete (buffer, start, end);
3411 gtk_text_buffer_insert (buffer, start,
3417 empathy_chat_is_room (EmpathyChat *chat)
3419 EmpathyChatPriv *priv = GET_PRIV (chat);
3421 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
3423 return (priv->handle_type == TP_HANDLE_TYPE_ROOM);
3427 empathy_chat_get_nb_unread_messages (EmpathyChat *self)
3429 EmpathyChatPriv *priv = GET_PRIV (self);
3431 g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
3433 return priv->unread_messages;
3436 /* called when the messages have been read by user */
3438 empathy_chat_messages_read (EmpathyChat *self)
3440 EmpathyChatPriv *priv = GET_PRIV (self);
3442 g_return_if_fail (EMPATHY_IS_CHAT (self));
3444 /* FIXME: See Bug#610994, See comments about it in EmpathyChatPriv
3445 * definition. If we are still retrieving the backlogs, do not ACK */
3446 if (priv->retrieving_backlogs)
3449 if (priv->tp_chat != NULL ) {
3450 empathy_tp_chat_acknowledge_all_messages (priv->tp_chat);
3452 priv->unread_messages = 0;