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-2010 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 <telepathy-logger/text-event.h>
42 #include <libempathy/empathy-contact-list.h>
43 #include <libempathy/empathy-gsettings.h>
44 #include <libempathy/empathy-keyring.h>
45 #include <libempathy/empathy-utils.h>
46 #include <libempathy/empathy-request-util.h>
47 #include <libempathy/empathy-chatroom-manager.h>
49 #include "empathy-chat.h"
50 #include "empathy-spell.h"
51 #include "empathy-contact-dialogs.h"
52 #include "empathy-contact-list-store.h"
53 #include "empathy-contact-list-view.h"
54 #include "empathy-contact-menu.h"
55 #include "empathy-input-text-view.h"
56 #include "empathy-search-bar.h"
57 #include "empathy-theme-manager.h"
58 #include "empathy-theme-adium.h"
59 #include "empathy-smiley-manager.h"
60 #include "empathy-ui-utils.h"
61 #include "empathy-string-parser.h"
62 #include "extensions/extensions.h"
64 #define DEBUG_FLAG EMPATHY_DEBUG_CHAT
65 #include <libempathy/empathy-debug.h>
67 #define IS_ENTER(v) (v == GDK_KEY_Return || v == GDK_KEY_ISO_Enter || v == GDK_KEY_KP_Enter)
68 #define COMPOSING_STOP_TIMEOUT 5
70 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat)
71 struct _EmpathyChatPriv {
72 EmpathyTpChat *tp_chat;
77 EmpathyContact *remote_contact;
78 gboolean show_contacts;
80 GSettings *gsettings_chat;
81 GSettings *gsettings_ui;
83 TplLogManager *log_manager;
84 TpAccountManager *account_manager;
86 GList *input_history_current;
88 GCompletion *completion;
89 guint composing_stop_timeout_id;
90 guint block_events_timeout_id;
91 TpHandleType handle_type;
93 gboolean has_input_vscroll;
95 /* TRUE if spell checking is enabled, FALSE otherwise.
96 * This is to keep track of the last state of spell checking
98 gboolean spell_checking_enabled;
100 /* These store the signal handler ids for the enclosed text entry. */
101 gulong insert_text_id;
102 gulong delete_range_id;
103 gulong notify_cursor_position_id;
105 /* Source func ID for update_misspelled_words () */
106 guint update_misspelled_words_id;
107 /* Source func ID for save_paned_pos_timeout () */
108 guint save_paned_pos_id;
109 /* Source func ID for chat_contacts_visible_timeout_cb () */
110 guint contacts_visible_id;
114 GtkWidget *vbox_left;
115 GtkWidget *scrolled_window_chat;
116 GtkWidget *scrolled_window_input;
117 GtkWidget *scrolled_window_contacts;
118 GtkWidget *hbox_topic;
119 GtkWidget *expander_topic;
120 GtkWidget *label_topic;
121 GtkWidget *contact_list_view;
122 GtkWidget *info_bar_vbox;
123 GtkWidget *search_bar;
125 guint unread_messages;
126 guint unread_messages_when_offline;
127 /* TRUE if the pending messages can be displayed. This is to avoid to show
128 * pending messages *before* messages from logs. (#603980) */
129 gboolean can_show_pending;
131 /* FIXME: retrieving_backlogs flag is a workaround for Bug#610994 and should
132 * be differently handled since it introduces another race condition, which
133 * is really hard to occur, but still possible.
135 * With the current workaround (which has the race above), we need to be
136 * sure to ACK any pending messages only when the retrieval of backlogs is
137 * finished, that's why using retrieving_backlogs flag.
138 * empathy_chat_messages_read () will check this variable and not ACK
139 * anything when TRUE. It will be set TRUE at chat_constructed () and set
140 * back to FALSE when the backlog has been retrieved and the pending
141 * messages actually showed to the user.
143 * Race condition introduced with this workaround:
144 * Scenario: a message is pending, the user is notified and selects the tab.
145 * the tab with a pending message is focused before the messages are properly
146 * shown (since the preparation of the window is slower AND async WRT the
147 * tab showing), which means the user won't see any new messages (rare but
148 * possible), if he/she will change tab focus before the messages are
149 * properly shown, the tab will be set as 'seen' and the user won't be
150 * notified again about the already notified pending messages when the
151 * messages in tab will be properly shown */
152 gboolean retrieving_backlogs;
153 gboolean sms_channel;
155 /* we need to know whether populate-popup happened in response to
156 * the keyboard or the mouse. We can't ask GTK for the most recent
157 * event, because it will be a notify event. Instead we track it here */
158 GdkEventType most_recent_event_type;
162 gchar *text; /* Original message that was specified
163 * upon entry creation. */
164 gchar *modified_text; /* Message that was modified by user.
165 * When no modifications were made, it is NULL */
171 PART_COMMAND_ENTERED,
185 PROP_N_MESSAGES_SENDING,
186 PROP_NB_UNREAD_MESSAGES,
189 static guint signals[LAST_SIGNAL] = { 0 };
191 G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BOX);
193 static gboolean update_misspelled_words (gpointer data);
196 chat_get_property (GObject *object,
201 EmpathyChat *chat = EMPATHY_CHAT (object);
202 EmpathyChatPriv *priv = GET_PRIV (object);
206 g_value_set_object (value, priv->tp_chat);
209 g_value_set_object (value, priv->account);
212 g_value_take_string (value, empathy_chat_dup_name (chat));
215 g_value_set_string (value, priv->id);
218 g_value_set_string (value, priv->subject);
220 case PROP_REMOTE_CONTACT:
221 g_value_set_object (value, priv->remote_contact);
223 case PROP_SHOW_CONTACTS:
224 g_value_set_boolean (value, priv->show_contacts);
226 case PROP_SMS_CHANNEL:
227 g_value_set_boolean (value, priv->sms_channel);
229 case PROP_N_MESSAGES_SENDING:
230 g_value_set_uint (value,
231 empathy_chat_get_n_messages_sending (chat));
233 case PROP_NB_UNREAD_MESSAGES:
234 g_value_set_uint (value,
235 empathy_chat_get_nb_unread_messages (chat));
238 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
244 chat_set_property (GObject *object,
249 EmpathyChat *chat = EMPATHY_CHAT (object);
253 empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
255 case PROP_SHOW_CONTACTS:
256 empathy_chat_set_show_contacts (chat, g_value_get_boolean (value));
259 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
265 account_reconnected (EmpathyChat *chat,
268 EmpathyChatPriv *priv = GET_PRIV (chat);
270 DEBUG ("Account reconnected, request a new Text channel");
272 /* FIXME: Ideally we should ask to handle ourself the channel so we can
273 * report the error if any but this is blocked by
274 * https://bugs.freedesktop.org/show_bug.cgi?id=13422 */
275 switch (priv->handle_type) {
276 case TP_HANDLE_TYPE_CONTACT:
277 if (priv->sms_channel)
278 empathy_sms_contact_id (
280 TP_USER_ACTION_TIME_NOT_USER_ACTION,
283 empathy_chat_with_contact_id (
285 TP_USER_ACTION_TIME_NOT_USER_ACTION,
288 case TP_HANDLE_TYPE_ROOM:
289 empathy_join_muc (account, priv->id,
290 TP_USER_ACTION_TIME_NOT_USER_ACTION);
292 case TP_HANDLE_TYPE_NONE:
293 case TP_HANDLE_TYPE_LIST:
294 case TP_HANDLE_TYPE_GROUP:
296 g_assert_not_reached ();
300 g_object_unref (chat);
304 chat_new_connection_cb (TpAccount *account,
308 gchar *dbus_error_name,
312 EmpathyChatPriv *priv = GET_PRIV (chat);
314 if (new_status != TP_CONNECTION_STATUS_CONNECTED)
317 if (priv->tp_chat != NULL || account != priv->account ||
318 priv->handle_type == TP_HANDLE_TYPE_NONE ||
319 EMP_STR_EMPTY (priv->id))
324 account_reconnected (chat, account);
328 chat_composing_remove_timeout (EmpathyChat *chat)
330 EmpathyChatPriv *priv;
332 priv = GET_PRIV (chat);
334 if (priv->composing_stop_timeout_id) {
335 g_source_remove (priv->composing_stop_timeout_id);
336 priv->composing_stop_timeout_id = 0;
341 set_chate_state_cb (GObject *source,
342 GAsyncResult *result,
345 GError *error = NULL;
347 if (!tp_text_channel_set_chat_state_finish (TP_TEXT_CHANNEL (source), result,
349 DEBUG ("Failed to set chat state: %s", error->message);
350 g_error_free (error);
355 set_chat_state (EmpathyChat *self,
356 TpChannelChatState state)
358 EmpathyChatPriv *priv = GET_PRIV (self);
360 if (!tp_proxy_has_interface_by_id (priv->tp_chat,
361 TP_IFACE_QUARK_CHANNEL_INTERFACE_CHAT_STATE))
364 tp_text_channel_set_chat_state_async (TP_TEXT_CHANNEL (priv->tp_chat), state,
365 set_chate_state_cb, self);
369 chat_composing_stop_timeout_cb (EmpathyChat *chat)
371 EmpathyChatPriv *priv;
373 priv = GET_PRIV (chat);
375 priv->composing_stop_timeout_id = 0;
376 set_chat_state (chat, TP_CHANNEL_CHAT_STATE_PAUSED);
382 chat_composing_start (EmpathyChat *chat)
384 EmpathyChatPriv *priv;
386 priv = GET_PRIV (chat);
388 if (priv->composing_stop_timeout_id) {
389 /* Just restart the timeout */
390 chat_composing_remove_timeout (chat);
392 set_chat_state (chat, TP_CHANNEL_CHAT_STATE_COMPOSING);
395 priv->composing_stop_timeout_id = g_timeout_add_seconds (
396 COMPOSING_STOP_TIMEOUT,
397 (GSourceFunc) chat_composing_stop_timeout_cb,
402 chat_composing_stop (EmpathyChat *chat)
404 chat_composing_remove_timeout (chat);
405 set_chat_state (chat, TP_CHANNEL_CHAT_STATE_ACTIVE);
409 chat_input_history_entry_cmp (InputHistoryEntry *entry,
412 if (!tp_strdiff (entry->text, text)) {
413 if (entry->modified_text != NULL) {
414 /* Modified entry and single string cannot be equal. */
422 static InputHistoryEntry *
423 chat_input_history_entry_new_with_text (const gchar *text)
425 InputHistoryEntry *entry;
426 entry = g_slice_new0 (InputHistoryEntry);
427 entry->text = g_strdup (text);
433 chat_input_history_entry_free (InputHistoryEntry *entry)
435 g_free (entry->text);
436 g_free (entry->modified_text);
437 g_slice_free (InputHistoryEntry, entry);
441 chat_input_history_entry_revert (InputHistoryEntry *entry)
443 g_free (entry->modified_text);
444 entry->modified_text = NULL;
448 chat_input_history_entry_update_text (InputHistoryEntry *entry,
453 if (!tp_strdiff (text, entry->text)) {
454 g_free (entry->modified_text);
455 entry->modified_text = NULL;
459 old = entry->modified_text;
460 entry->modified_text = g_strdup (text);
465 chat_input_history_entry_get_text (InputHistoryEntry *entry)
471 if (entry->modified_text != NULL) {
472 return entry->modified_text;
478 chat_input_history_remove_item (GList *list,
481 list = g_list_remove_link (list, item);
482 chat_input_history_entry_free (item->data);
483 g_list_free_1 (item);
488 chat_input_history_revert (EmpathyChat *chat)
490 EmpathyChatPriv *priv;
494 InputHistoryEntry *entry;
496 priv = GET_PRIV (chat);
497 list = priv->input_history;
500 DEBUG ("No input history");
504 /* Delete temporary entry */
505 if (priv->input_history_current != NULL) {
507 list = chat_input_history_remove_item (list, item1);
508 if (priv->input_history_current == item1) {
509 /* Removed temporary entry was current entry */
510 priv->input_history = list;
511 priv->input_history_current = NULL;
516 /* There is no entry to revert */
520 /* Restore the current history entry to original value */
521 item1 = priv->input_history_current;
523 chat_input_history_entry_revert (entry);
525 /* Remove restored entry if there is other occurance before this entry */
526 item2 = g_list_find_custom (list, chat_input_history_entry_get_text (entry),
527 (GCompareFunc) chat_input_history_entry_cmp);
528 if (item2 != item1) {
529 list = chat_input_history_remove_item (list, item1);
532 /* Remove other occurance of the restored entry */
533 item2 = g_list_find_custom (item1->next,
534 chat_input_history_entry_get_text (entry),
535 (GCompareFunc) chat_input_history_entry_cmp);
537 list = chat_input_history_remove_item (list, item2);
541 priv->input_history_current = NULL;
542 priv->input_history = list;
546 chat_input_history_add (EmpathyChat *chat,
550 EmpathyChatPriv *priv;
553 InputHistoryEntry *entry;
555 priv = GET_PRIV (chat);
557 list = priv->input_history;
559 /* Remove any other occurances of this entry, if not temporary */
561 while ((item = g_list_find_custom (list, str,
562 (GCompareFunc) chat_input_history_entry_cmp)) != NULL) {
563 list = chat_input_history_remove_item (list, item);
566 /* Trim the list to the last 10 items */
567 while (g_list_length (list) > 10) {
568 item = g_list_last (list);
570 list = chat_input_history_remove_item (list, item);
578 entry = chat_input_history_entry_new_with_text (str);
579 list = g_list_prepend (list, entry);
581 /* Set the list and the current item pointer */
582 priv->input_history = list;
584 priv->input_history_current = list;
587 priv->input_history_current = NULL;
592 chat_input_history_get_next (EmpathyChat *chat)
594 EmpathyChatPriv *priv;
598 priv = GET_PRIV (chat);
600 if (priv->input_history == NULL) {
601 DEBUG ("No input history, next entry is NULL");
604 g_assert (priv->input_history_current != NULL);
606 if ((item = g_list_next (priv->input_history_current)) == NULL)
608 item = priv->input_history_current;
611 msg = chat_input_history_entry_get_text (item->data);
613 DEBUG ("Returning next entry: '%s'", msg);
615 priv->input_history_current = item;
621 chat_input_history_get_prev (EmpathyChat *chat)
623 EmpathyChatPriv *priv;
627 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
629 priv = GET_PRIV (chat);
631 if (priv->input_history == NULL) {
632 DEBUG ("No input history, previous entry is NULL");
636 if (priv->input_history_current == NULL)
640 else if ((item = g_list_previous (priv->input_history_current)) == NULL)
642 item = priv->input_history_current;
645 msg = chat_input_history_entry_get_text (item->data);
647 DEBUG ("Returning previous entry: '%s'", msg);
649 priv->input_history_current = item;
655 chat_input_history_update (EmpathyChat *chat,
656 GtkTextBuffer *buffer)
658 EmpathyChatPriv *priv;
659 GtkTextIter start, end;
661 InputHistoryEntry *entry;
663 priv = GET_PRIV (chat);
665 gtk_text_buffer_get_bounds (buffer, &start, &end);
666 text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
668 if (priv->input_history_current == NULL) {
669 /* Add the current text temporarily to the history */
670 chat_input_history_add (chat, text, TRUE);
675 /* Save the changes in the history */
676 entry = priv->input_history_current->data;
677 if (tp_strdiff (chat_input_history_entry_get_text (entry), text)) {
678 chat_input_history_entry_update_text (entry, text);
687 } ChatCommandMsgData;
690 chat_command_msg_cb (GObject *source,
691 GAsyncResult *result,
694 ChatCommandMsgData *data = user_data;
695 GError *error = NULL;
698 channel = tp_account_channel_request_ensure_and_observe_channel_finish (
699 TP_ACCOUNT_CHANNEL_REQUEST (source), result, &error);
701 if (channel == NULL) {
702 DEBUG ("Failed to get channel: %s", error->message);
703 g_error_free (error);
705 empathy_chat_view_append_event (data->chat->view,
706 _("Failed to open private chat"));
710 if (!EMP_STR_EMPTY (data->message) && TP_IS_TEXT_CHANNEL (channel)) {
711 TpTextChannel *text = (TpTextChannel *) channel;
714 msg = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
717 tp_text_channel_send_message_async (text, msg, 0, NULL, NULL);
719 g_object_unref (msg);
722 g_object_unref (channel);
725 g_free (data->message);
726 g_slice_free (ChatCommandMsgData, data);
730 nick_command_supported (EmpathyChat *chat)
732 EmpathyChatPriv * priv = GET_PRIV (chat);
733 TpConnection *connection;
735 connection = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
736 return tp_proxy_has_interface_by_id (connection,
737 EMP_IFACE_QUARK_CONNECTION_INTERFACE_RENAMING);
741 part_command_supported (EmpathyChat *chat)
743 EmpathyChatPriv * priv = GET_PRIV (chat);
745 return tp_proxy_has_interface_by_id (priv->tp_chat,
746 TP_IFACE_QUARK_CHANNEL_INTERFACE_GROUP);
750 chat_command_clear (EmpathyChat *chat,
753 empathy_chat_view_clear (chat->view);
757 chat_command_topic (EmpathyChat *chat,
760 EmpathyChatPriv *priv = GET_PRIV (chat);
762 if (!empathy_tp_chat_supports_subject (priv->tp_chat)) {
763 empathy_chat_view_append_event (chat->view,
764 _("Topic not supported on this conversation"));
768 if (!empathy_tp_chat_can_set_subject (priv->tp_chat)) {
769 empathy_chat_view_append_event (chat->view,
770 _("You are not allowed to change the topic"));
774 empathy_tp_chat_set_subject (priv->tp_chat, strv[1]);
778 empathy_chat_join_muc (EmpathyChat *chat,
781 EmpathyChatPriv *priv = GET_PRIV (chat);
783 empathy_join_muc (priv->account, room,
784 empathy_get_current_action_time ());
788 chat_command_join (EmpathyChat *chat,
793 GStrv rooms = g_strsplit_set (strv[1], ", ", -1);
795 /* FIXME: Ideally we should ask to handle ourself the channel so we can
796 * report the error if any but this is blocked by
797 * https://bugs.freedesktop.org/show_bug.cgi?id=13422 */
798 while (rooms[i] != NULL) {
799 /* ignore empty strings */
800 if (!EMP_STR_EMPTY (rooms[i])) {
801 empathy_chat_join_muc (chat, rooms[i]);
809 chat_command_part (EmpathyChat *chat,
812 g_signal_emit (chat, signals[PART_COMMAND_ENTERED], 0, strv);
816 chat_command_msg_internal (EmpathyChat *chat,
817 const gchar *contact_id,
818 const gchar *message)
820 EmpathyChatPriv *priv = GET_PRIV (chat);
821 ChatCommandMsgData *data;
822 TpAccountChannelRequest *req;
825 request = tp_asv_new (
826 TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
827 TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
828 TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, contact_id,
831 req = tp_account_channel_request_new (priv->account, request,
832 empathy_get_current_action_time ());
834 /* FIXME: We should probably search in members alias. But this
835 * is enough for IRC */
836 data = g_slice_new (ChatCommandMsgData);
838 data->message = g_strdup (message);
840 tp_account_channel_request_ensure_and_observe_channel_async (req,
841 EMPATHY_CHAT_BUS_NAME, NULL, chat_command_msg_cb, data);
843 g_object_unref (req);
844 g_hash_table_unref (request);
848 chat_command_query (EmpathyChat *chat,
851 /* If <message> part is not defined,
852 * strv[2] will be the terminal NULL */
853 chat_command_msg_internal (chat, strv[1], strv[2]);
857 chat_command_msg (EmpathyChat *chat,
860 chat_command_msg_internal (chat, strv[1], strv[2]);
864 callback_for_request_rename (TpProxy *proxy,
867 GObject *weak_object)
870 DEBUG ("Call to RequestRename method failed: %s",error->message);
875 chat_command_nick (EmpathyChat *chat,
878 EmpathyChatPriv *priv = GET_PRIV (chat);
881 proxy = TP_PROXY (tp_account_get_connection (priv->account));
883 emp_cli_connection_interface_renaming_call_request_rename (proxy, -1,
884 strv[1], callback_for_request_rename, NULL, NULL, NULL);
888 chat_command_me (EmpathyChat *chat,
891 EmpathyChatPriv *priv = GET_PRIV (chat);
893 TpTextChannel *channel;
895 channel = (TpTextChannel *) (priv->tp_chat);
897 if (!tp_text_channel_supports_message_type (channel,
898 TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION)) {
899 /* Action message are not supported, 'simulate' the action */
900 EmpathyContact *self_contact;
903 self_contact = empathy_tp_chat_get_self_contact (priv->tp_chat);
904 /* The TpChat can't be ready if it doesn't have the self contact */
905 g_assert (self_contact != NULL);
907 tmp = g_strdup_printf ("%s %s", empathy_contact_get_alias (self_contact),
909 message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
914 message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_ACTION,
918 empathy_tp_chat_send (priv->tp_chat, message);
919 g_object_unref (message);
923 chat_command_say (EmpathyChat *chat,
926 EmpathyChatPriv *priv = GET_PRIV (chat);
929 message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
931 empathy_tp_chat_send (priv->tp_chat, message);
932 g_object_unref (message);
936 whois_got_contact_cb (TpConnection *connection,
938 TpContact * const *contacts,
939 const gchar * const *requested_ids,
940 GHashTable *failed_id_errors,
943 GObject *weak_object)
945 EmpathyChat *chat = EMPATHY_CHAT (weak_object);
947 g_return_if_fail (n_contacts <= 1);
949 if (n_contacts == 0) {
951 gpointer key = NULL, value = NULL;
955 /* tp-glib guarantees that the contacts you requested will be
956 * in failed_id_errors regardless of whether the individual
957 * contact was invalid or the whole operation failed.
959 g_hash_table_iter_init (&iter, failed_id_errors);
960 g_hash_table_iter_next (&iter, &key, &value);
964 DEBUG ("Error getting TpContact for '%s': %s %u %s",
965 id, g_quark_to_string (id_error->domain),
966 id_error->code, id_error->message);
969 /* The specific ID failed. */
970 gchar *event = g_strdup_printf (
971 _("“%s” is not a valid contact ID"), id);
972 empathy_chat_view_append_event (chat->view, event);
975 /* Otherwise we're disconnected or something; so the window
976 * will already say ‘Disconnected’, so let's not show anything.
979 EmpathyContact *empathy_contact;
982 g_return_if_fail (contacts[0] != NULL);
983 empathy_contact = empathy_contact_dup_from_tp_contact (
986 window = gtk_widget_get_toplevel (GTK_WIDGET (chat));
987 /* If we're alive and this command is running, we'd better be
989 g_return_if_fail (window != NULL);
990 g_return_if_fail (gtk_widget_is_toplevel (window));
991 empathy_contact_information_dialog_show (empathy_contact,
992 GTK_WINDOW (window));
993 g_object_unref (empathy_contact);
998 chat_command_whois (EmpathyChat *chat,
1001 EmpathyChatPriv *priv = GET_PRIV (chat);
1004 conn = tp_channel_borrow_connection ((TpChannel *) priv->tp_chat);
1005 tp_connection_get_contacts_by_id (conn,
1006 /* Element 0 of 'strv' is "whois"; element 1 is the contact ID
1007 * entered by the user (including spaces, if any). */
1008 1, (const gchar * const *) strv + 1,
1010 whois_got_contact_cb, NULL, NULL, G_OBJECT (chat));
1014 chat_command_whale (EmpathyChat *chat,
1017 EmpathyChatPriv *priv = GET_PRIV (chat);
1020 message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
1022 "•_______________•");
1023 empathy_tp_chat_send (priv->tp_chat, message);
1024 g_object_unref (message);
1028 chat_command_babywhale (EmpathyChat *chat,
1031 EmpathyChatPriv *priv = GET_PRIV (chat);
1034 message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
1037 empathy_tp_chat_send (priv->tp_chat, message);
1038 g_object_unref (message);
1042 chat_command_inspector (EmpathyChat *chat,
1045 if (EMPATHY_IS_THEME_ADIUM (chat->view)) {
1046 empathy_theme_adium_show_inspector (
1047 EMPATHY_THEME_ADIUM (chat->view));
1051 static void chat_command_help (EmpathyChat *chat, GStrv strv);
1053 typedef void (*ChatCommandFunc) (EmpathyChat *chat, GStrv strv);
1056 const gchar *prefix;
1059 ChatCommandFunc func;
1060 gboolean (*is_supported)(EmpathyChat *chat);
1064 static ChatCommandItem commands[] = {
1065 {"clear", 1, 1, chat_command_clear, NULL,
1066 N_("/clear: clear all messages from the current conversation")},
1068 {"topic", 2, 2, chat_command_topic, NULL,
1069 N_("/topic <topic>: set the topic of the current conversation")},
1071 {"join", 2, 2, chat_command_join, NULL,
1072 N_("/join <chat room ID>: join a new chat room")},
1074 {"j", 2, 2, chat_command_join, NULL,
1075 N_("/j <chat room ID>: join a new chat room")},
1077 /* FIXME: https://bugzilla.gnome.org/show_bug.cgi?id=643295 */
1078 {"part", 1, 3, chat_command_part, part_command_supported,
1079 N_("/part [<chat room ID>] [<reason>]: leave the chat room, "
1080 "by default the current one")},
1082 {"query", 2, 3, chat_command_query, NULL,
1083 N_("/query <contact ID> [<message>]: open a private chat")},
1085 {"msg", 3, 3, chat_command_msg, NULL,
1086 N_("/msg <contact ID> <message>: open a private chat")},
1088 {"nick", 2, 2, chat_command_nick, nick_command_supported,
1089 N_("/nick <nickname>: change your nickname on the current server")},
1091 {"me", 2, 2, chat_command_me, NULL,
1092 N_("/me <message>: send an ACTION message to the current conversation")},
1094 {"say", 2, 2, chat_command_say, NULL,
1095 N_("/say <message>: send <message> to the current conversation. "
1096 "This is used to send a message starting with a '/'. For example: "
1097 "\"/say /join is used to join a new chat room\"")},
1099 {"whois", 2, 2, chat_command_whois, NULL,
1100 N_("/whois <contact ID>: display information about a contact")},
1102 {"help", 1, 2, chat_command_help, NULL,
1103 N_("/help [<command>]: show all supported commands. "
1104 "If <command> is defined, show its usage.")},
1106 {"inspector", 1, 1, chat_command_inspector, NULL, NULL},
1108 {"whale", 1, 1, chat_command_whale, NULL, NULL},
1109 {"babywhale", 1, 1, chat_command_babywhale, NULL, NULL},
1113 chat_command_show_help (EmpathyChat *chat,
1114 ChatCommandItem *item)
1118 if (item->help == NULL) {
1122 str = g_strdup_printf (_("Usage: %s"), _(item->help));
1123 empathy_chat_view_append_event (chat->view, str);
1128 chat_command_help (EmpathyChat *chat,
1133 /* If <command> part is not defined,
1134 * strv[1] will be the terminal NULL */
1135 if (strv[1] == NULL) {
1136 for (i = 0; i < G_N_ELEMENTS (commands); i++) {
1137 if (commands[i].is_supported != NULL) {
1138 if (!commands[i].is_supported (chat)) {
1142 if (commands[i].help == NULL) {
1145 empathy_chat_view_append_event (chat->view,
1146 _(commands[i].help));
1151 for (i = 0; i < G_N_ELEMENTS (commands); i++) {
1152 if (g_ascii_strcasecmp (strv[1], commands[i].prefix) == 0) {
1153 if (commands[i].is_supported != NULL) {
1154 if (!commands[i].is_supported (chat)) {
1158 if (commands[i].help == NULL) {
1161 chat_command_show_help (chat, &commands[i]);
1166 empathy_chat_view_append_event (chat->view,
1167 _("Unknown command"));
1171 chat_command_parse (const gchar *text, guint max_parts)
1176 DEBUG ("Parse command, parts=%d text=\"%s\":", max_parts, text);
1178 array = g_ptr_array_sized_new (max_parts + 1);
1179 while (max_parts > 1) {
1182 /* Skip white spaces */
1183 while (g_ascii_isspace (*text)) {
1187 /* Search the end of this part, until first space. */
1188 for (end = text; *end != '\0' && !g_ascii_isspace (*end); end++)
1194 item = g_strndup (text, end - text);
1195 g_ptr_array_add (array, item);
1196 DEBUG ("\tITEM: \"%s\"", item);
1202 /* Append last part if not empty */
1203 item = g_strstrip (g_strdup (text));
1204 if (!EMP_STR_EMPTY (item)) {
1205 g_ptr_array_add (array, item);
1206 DEBUG ("\tITEM: \"%s\"", item);
1211 /* Make the array NULL-terminated */
1212 g_ptr_array_add (array, NULL);
1214 return (GStrv) g_ptr_array_free (array, FALSE);
1218 has_prefix_case (const gchar *s,
1219 const gchar *prefix)
1221 return g_ascii_strncasecmp (s, prefix, strlen (prefix)) == 0;
1225 chat_send (EmpathyChat *chat,
1228 EmpathyChatPriv *priv;
1232 if (EMP_STR_EMPTY (msg)) {
1236 priv = GET_PRIV (chat);
1238 chat_input_history_add (chat, msg, FALSE);
1240 if (msg[0] == '/') {
1241 gboolean second_slash = FALSE;
1242 const gchar *iter = msg + 1;
1244 for (i = 0; i < G_N_ELEMENTS (commands); i++) {
1249 if (!has_prefix_case (msg + 1, commands[i].prefix)) {
1252 c = *(msg + 1 + strlen (commands[i].prefix));
1253 if (c != '\0' && !g_ascii_isspace (c)) {
1256 if (commands[i].is_supported != NULL) {
1257 if (!commands[i].is_supported (chat)) {
1262 /* We can't use g_strsplit here because it does
1263 * not deal correctly if we have more than one space
1265 strv = chat_command_parse (msg + 1, commands[i].max_parts);
1267 strv_len = g_strv_length (strv);
1268 if (strv_len < commands[i].min_parts ||
1269 strv_len > commands[i].max_parts) {
1270 chat_command_show_help (chat, &commands[i]);
1275 commands[i].func (chat, strv);
1280 /* Also allow messages with two slashes before the
1281 * first space, so it is possible to send a /unix/path.
1282 * This heuristic is kind of crap. */
1283 while (*iter != '\0' && !g_ascii_isspace (*iter)) {
1285 second_slash = TRUE;
1291 if (!second_slash) {
1292 empathy_chat_view_append_event (chat->view,
1293 _("Unknown command; see /help for the available"
1299 message = tp_client_message_new_text (TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL,
1301 empathy_tp_chat_send (priv->tp_chat, message);
1302 g_object_unref (message);
1306 chat_input_text_view_send (EmpathyChat *chat)
1308 GtkTextBuffer *buffer;
1309 GtkTextIter start, end;
1312 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1314 gtk_text_buffer_get_bounds (buffer, &start, &end);
1315 msg = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
1317 /* clear the input field */
1318 gtk_text_buffer_set_text (buffer, "", -1);
1319 /* delete input history modifications */
1320 chat_input_history_revert (chat);
1322 chat_send (chat, msg);
1327 chat_state_changed_cb (EmpathyTpChat *tp_chat,
1328 EmpathyContact *contact,
1329 TpChannelChatState state,
1332 EmpathyChatPriv *priv;
1334 gboolean was_composing;
1336 priv = GET_PRIV (chat);
1338 if (empathy_contact_is_user (contact)) {
1339 /* We don't care about our own chat state */
1343 was_composing = (priv->compositors != NULL);
1345 /* Find the contact in the list. After that l is the list elem or NULL */
1346 for (l = priv->compositors; l; l = l->next) {
1347 if (contact == l->data) {
1353 case TP_CHANNEL_CHAT_STATE_GONE:
1354 case TP_CHANNEL_CHAT_STATE_INACTIVE:
1355 case TP_CHANNEL_CHAT_STATE_PAUSED:
1356 case TP_CHANNEL_CHAT_STATE_ACTIVE:
1357 /* Contact is not composing */
1359 priv->compositors = g_list_remove_link (priv->compositors, l);
1360 g_object_unref (l->data);
1364 case TP_CHANNEL_CHAT_STATE_COMPOSING:
1365 /* Contact is composing */
1367 priv->compositors = g_list_prepend (priv->compositors,
1368 g_object_ref (contact));
1372 g_assert_not_reached ();
1375 DEBUG ("Was composing: %s now composing: %s",
1376 was_composing ? "yes" : "no",
1377 priv->compositors ? "yes" : "no");
1379 if ((was_composing && !priv->compositors) ||
1380 (!was_composing && priv->compositors)) {
1381 /* Composing state changed */
1382 g_signal_emit (chat, signals[COMPOSING], 0,
1383 priv->compositors != NULL);
1388 chat_message_received (EmpathyChat *chat,
1389 EmpathyMessage *message,
1392 EmpathyChatPriv *priv = GET_PRIV (chat);
1393 EmpathyContact *sender;
1395 sender = empathy_message_get_sender (message);
1397 if (empathy_message_is_edit (message)) {
1398 DEBUG ("Editing message '%s' to '%s'",
1399 empathy_message_get_supersedes (message),
1400 empathy_message_get_body (message));
1402 empathy_chat_view_edit_message (chat->view, message);
1404 DEBUG ("Appending new message '%s' from %s (%d)",
1405 empathy_message_get_token (message),
1406 empathy_contact_get_alias (sender),
1407 empathy_contact_get_handle (sender));
1409 empathy_chat_view_append_message (chat->view, message);
1411 if (empathy_message_is_incoming (message)) {
1412 priv->unread_messages++;
1413 g_object_notify (G_OBJECT (chat), "nb-unread-messages");
1416 g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, pending);
1419 /* We received a message so the contact is no longer
1421 chat_state_changed_cb (priv->tp_chat, sender,
1422 TP_CHANNEL_CHAT_STATE_ACTIVE,
1427 chat_message_received_cb (EmpathyTpChat *tp_chat,
1428 EmpathyMessage *message,
1431 chat_message_received (chat, message, FALSE);
1435 chat_message_acknowledged_cb (EmpathyTpChat *tp_chat,
1436 EmpathyMessage *message,
1439 EmpathyChatPriv *priv = GET_PRIV (chat);
1441 empathy_chat_view_message_acknowledged (chat->view,
1444 if (!empathy_message_is_edit (message)) {
1445 priv->unread_messages--;
1446 g_object_notify (G_OBJECT (chat), "nb-unread-messages");
1451 append_balance_error (EmpathyChat *chat,
1452 const gchar *message_body)
1454 EmpathyChatPriv *priv = GET_PRIV (chat);
1455 TpConnection *conn = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
1456 const gchar *uri = tp_connection_get_balance_uri (conn);
1457 const gchar *error = _("insufficient balance to send message");
1458 gchar *str, *str_markup = NULL;
1460 if (message_body != NULL) {
1461 str = g_strdup_printf (_("Error sending message '%s': %s"), message_body, error);
1463 str = g_strdup_printf (_("Error sending message: %s"), error);
1466 if (!tp_str_empty (uri)) {
1467 /* translators: error used when user doesn't have enough credit on his
1468 * account to send the message. */
1469 gchar *markup_error = g_strdup_printf (_("insufficient balance to send message."
1470 " <a href='%s'>Top up</a>."), uri);
1472 if (message_body != NULL) {
1473 gchar *escaped_body = g_markup_escape_text (message_body, -1);
1475 str_markup = g_strdup_printf (_("Error sending message '%s': %s"),
1476 escaped_body, markup_error);
1478 g_free (escaped_body);
1480 str_markup = g_strdup_printf (_("Error sending message: %s"), markup_error);
1483 g_free (markup_error);
1486 if (str_markup != NULL)
1487 empathy_chat_view_append_event_markup (chat->view, str_markup, str);
1489 empathy_chat_view_append_event (chat->view, str);
1492 g_free (str_markup);
1496 chat_send_error_cb (EmpathyTpChat *tp_chat,
1497 const gchar *message_body,
1498 TpChannelTextSendError error_code,
1499 const gchar *dbus_error,
1502 const gchar *error = NULL;
1505 if (!tp_strdiff (dbus_error, TP_ERROR_STR_INSUFFICIENT_BALANCE)) {
1506 append_balance_error (chat, message_body);
1508 } else if (!tp_strdiff (dbus_error, TP_ERROR_STR_NOT_CAPABLE)) {
1509 error = _("not capable");
1512 if (error == NULL) {
1513 /* if we didn't find a dbus-error, try the old error */
1514 switch (error_code) {
1515 case TP_CHANNEL_TEXT_SEND_ERROR_OFFLINE:
1516 error = _("offline");
1518 case TP_CHANNEL_TEXT_SEND_ERROR_INVALID_CONTACT:
1519 error = _("invalid contact");
1521 case TP_CHANNEL_TEXT_SEND_ERROR_PERMISSION_DENIED:
1522 error = _("permission denied");
1524 case TP_CHANNEL_TEXT_SEND_ERROR_TOO_LONG:
1525 error = _("too long message");
1527 case TP_CHANNEL_TEXT_SEND_ERROR_NOT_IMPLEMENTED:
1528 error = _("not implemented");
1530 case TP_CHANNEL_TEXT_SEND_ERROR_UNKNOWN:
1532 error = _("unknown");
1537 if (message_body != NULL) {
1538 str = g_strdup_printf (_("Error sending message '%s': %s"),
1539 message_body, error);
1542 str = g_strdup_printf (_("Error sending message: %s"), error);
1545 empathy_chat_view_append_event (chat->view, str);
1550 chat_topic_label_size_allocate_cb (GtkLabel *label,
1551 GtkAllocation *allocation,
1554 EmpathyChatPriv *priv = GET_PRIV (chat);
1556 if (!gtk_label_get_line_wrap (label)) {
1557 if (pango_layout_is_ellipsized (gtk_label_get_layout (label)))
1558 gtk_widget_show (priv->expander_topic);
1560 gtk_widget_hide (priv->expander_topic);
1567 chat_topic_expander_activate_cb (GtkExpander *expander,
1568 GParamSpec *param_spec,
1571 EmpathyChatPriv *priv = GET_PRIV (chat);
1573 if (gtk_expander_get_expanded (expander)) {
1574 gtk_label_set_ellipsize (GTK_LABEL (priv->label_topic), PANGO_ELLIPSIZE_NONE);
1575 gtk_label_set_line_wrap (GTK_LABEL (priv->label_topic), TRUE);
1577 gtk_label_set_ellipsize (GTK_LABEL (priv->label_topic), PANGO_ELLIPSIZE_END);
1578 gtk_label_set_line_wrap (GTK_LABEL (priv->label_topic), FALSE);
1583 chat_subject_changed_cb (EmpathyChat *chat)
1585 EmpathyChatPriv *priv = GET_PRIV (chat);
1587 g_free (priv->subject);
1588 priv->subject = g_strdup (empathy_tp_chat_get_subject (priv->tp_chat));
1589 g_object_notify (G_OBJECT (chat), "subject");
1591 if (EMP_STR_EMPTY (priv->subject)) {
1592 gtk_widget_hide (priv->hbox_topic);
1594 gchar *markup_topic;
1597 markup_topic = empathy_add_link_markup (priv->subject);
1598 markup_text = g_strdup_printf ("<span weight=\"bold\">%s</span> %s",
1599 _("Topic:"), markup_topic);
1601 gtk_label_set_markup (GTK_LABEL (priv->label_topic), markup_text);
1602 g_free (markup_text);
1603 g_free (markup_topic);
1605 gtk_widget_show (priv->hbox_topic);
1607 if (priv->block_events_timeout_id == 0) {
1610 if (!EMP_STR_EMPTY (priv->subject)) {
1611 str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
1613 str = g_strdup (_("No topic defined"));
1615 empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
1621 chat_title_changed_cb (EmpathyChat *chat)
1623 EmpathyChatPriv *priv = GET_PRIV (chat);
1625 g_free (priv->name);
1626 priv->name = g_strdup (empathy_tp_chat_get_title (priv->tp_chat));
1627 g_object_notify (G_OBJECT (chat), "name");
1631 chat_input_text_get_word_from_iter (GtkTextIter *iter,
1635 GtkTextIter word_start = *iter;
1636 GtkTextIter word_end = *iter;
1639 if (gtk_text_iter_inside_word (&word_end) &&
1640 !gtk_text_iter_ends_word (&word_end)) {
1641 gtk_text_iter_forward_word_end (&word_end);
1646 if (gtk_text_iter_get_char (&tmp) == '\'') {
1647 gtk_text_iter_forward_char (&tmp);
1649 if (g_unichar_isalpha (gtk_text_iter_get_char (&tmp))) {
1650 gtk_text_iter_forward_word_end (&word_end);
1655 if (gtk_text_iter_inside_word (&word_start) ||
1656 gtk_text_iter_ends_word (&word_start)) {
1657 if (!gtk_text_iter_starts_word (&word_start) ||
1658 gtk_text_iter_equal (&word_start, &word_end)) {
1659 gtk_text_iter_backward_word_start (&word_start);
1663 gtk_text_iter_backward_char (&tmp);
1665 if (gtk_text_iter_get_char (&tmp) == '\'') {
1666 gtk_text_iter_backward_char (&tmp);
1668 if (g_unichar_isalpha (gtk_text_iter_get_char (&tmp))) {
1669 gtk_text_iter_backward_word_start (&word_start);
1674 *start = word_start;
1680 chat_input_text_buffer_insert_text_cb (GtkTextBuffer *buffer,
1681 GtkTextIter *location,
1686 GtkTextIter iter, pos;
1688 /* Remove all misspelled tags in the inserted text.
1689 * This happens when text is inserted within a misspelled word. */
1690 gtk_text_buffer_get_iter_at_offset (buffer, &iter,
1691 gtk_text_iter_get_offset (location) - len);
1692 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled",
1695 gtk_text_buffer_get_iter_at_mark (buffer, &pos, gtk_text_buffer_get_insert (buffer));
1698 GtkTextIter start, end;
1701 if (!chat_input_text_get_word_from_iter (&iter, &start, &end))
1704 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
1706 if (gtk_text_iter_in_range (&pos, &start, &end) ||
1707 gtk_text_iter_equal (&pos, &end) ||
1708 empathy_spell_check (str)) {
1709 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled", &start, &end);
1711 gtk_text_buffer_apply_tag_by_name (buffer, "misspelled", &start, &end);
1716 } while (gtk_text_iter_forward_word_end (&iter) &&
1717 gtk_text_iter_compare (&iter, location) <= 0);
1721 chat_input_text_buffer_delete_range_cb (GtkTextBuffer *buffer,
1726 GtkTextIter word_start, word_end;
1728 if (chat_input_text_get_word_from_iter (start, &word_start, &word_end)) {
1729 gtk_text_buffer_remove_tag_by_name (buffer, "misspelled",
1730 &word_start, &word_end);
1735 chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
1738 if (gtk_text_buffer_get_char_count (buffer) == 0) {
1739 chat_composing_stop (chat);
1741 chat_composing_start (chat);
1746 chat_input_text_buffer_notify_cursor_position_cb (GtkTextBuffer *buffer,
1751 GtkTextIter prev_pos;
1752 GtkTextIter word_start;
1753 GtkTextIter word_end;
1757 mark = gtk_text_buffer_get_mark (buffer, "previous-cursor-position");
1759 gtk_text_buffer_get_iter_at_mark (buffer, &pos,
1760 gtk_text_buffer_get_insert (buffer));
1761 gtk_text_buffer_get_iter_at_mark (buffer, &prev_pos, mark);
1763 if (!chat_input_text_get_word_from_iter (&prev_pos, &word_start, &word_end))
1766 if (!gtk_text_iter_in_range (&pos, &word_start, &word_end) &&
1767 !gtk_text_iter_equal (&pos, &word_end)) {
1768 str = gtk_text_buffer_get_text (buffer,
1769 &word_start, &word_end, FALSE);
1771 if (!empathy_spell_check (str)) {
1772 gtk_text_buffer_apply_tag_by_name (buffer,
1773 "misspelled", &word_start, &word_end);
1775 gtk_text_buffer_remove_tag_by_name (buffer,
1776 "misspelled", &word_start, &word_end);
1783 gtk_text_buffer_move_mark (buffer, mark, &pos);
1787 empathy_isspace_cb (gunichar c,
1790 return g_unichar_isspace (c);
1794 chat_input_key_press_event_cb (GtkWidget *widget,
1798 EmpathyChatPriv *priv;
1801 GtkWidget *text_view_sw;
1803 priv = GET_PRIV (chat);
1805 priv->most_recent_event_type = event->type;
1807 /* Catch ctrl+up/down so we can traverse messages we sent */
1808 if ((event->state & GDK_CONTROL_MASK) &&
1809 (event->keyval == GDK_KEY_Up ||
1810 event->keyval == GDK_KEY_Down)) {
1811 GtkTextBuffer *buffer;
1814 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
1815 chat_input_history_update (chat, buffer);
1817 if (event->keyval == GDK_KEY_Up) {
1818 str = chat_input_history_get_next (chat);
1820 str = chat_input_history_get_prev (chat);
1823 g_signal_handlers_block_by_func (buffer,
1824 chat_input_text_buffer_changed_cb,
1826 gtk_text_buffer_set_text (buffer, str ? str : "", -1);
1827 g_signal_handlers_unblock_by_func (buffer,
1828 chat_input_text_buffer_changed_cb,
1834 /* Catch enter but not ctrl/shift-enter */
1835 if (IS_ENTER (event->keyval) &&
1836 !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
1839 /* This is to make sure that kinput2 gets the enter. And if
1840 * it's handled there we shouldn't send on it. This is because
1841 * kinput2 uses Enter to commit letters. See:
1842 * http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=104299
1845 view = GTK_TEXT_VIEW (chat->input_text_view);
1846 if (gtk_text_view_im_context_filter_keypress (view, event)) {
1847 gtk_text_view_reset_im_context (view);
1851 chat_input_text_view_send (chat);
1855 text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
1857 if (IS_ENTER (event->keyval) &&
1858 (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
1859 /* Newline for shift/control-enter. */
1862 if (!(event->state & GDK_CONTROL_MASK) &&
1863 event->keyval == GDK_KEY_Page_Up) {
1864 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
1865 gtk_adjustment_set_value (adj, gtk_adjustment_get_value (adj) - gtk_adjustment_get_page_size (adj));
1868 if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
1869 event->keyval == GDK_KEY_Page_Down) {
1870 adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
1871 val = MIN (gtk_adjustment_get_value (adj) + gtk_adjustment_get_page_size (adj),
1872 gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj));
1873 gtk_adjustment_set_value (adj, val);
1876 if (event->keyval == GDK_KEY_Escape) {
1877 empathy_search_bar_hide (EMPATHY_SEARCH_BAR (priv->search_bar));
1879 if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
1880 event->keyval == GDK_KEY_Tab) {
1881 GtkTextBuffer *buffer;
1882 GtkTextIter start, current;
1883 gchar *nick, *completed;
1884 GList *list, *completed_list;
1885 gboolean is_start_of_buffer;
1887 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
1888 gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (buffer));
1890 /* Get the start of the nick to complete. */
1891 gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
1892 if (gtk_text_iter_backward_find_char (&start, &empathy_isspace_cb, NULL, NULL)) {
1893 gtk_text_iter_set_offset (&start, gtk_text_iter_get_offset (&start) + 1);
1895 is_start_of_buffer = gtk_text_iter_is_start (&start);
1897 list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
1898 g_completion_add_items (priv->completion, list);
1900 nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
1901 completed_list = g_completion_complete (priv->completion,
1910 GString *message = NULL;
1913 gtk_text_buffer_delete (buffer, &start, ¤t);
1915 len = g_list_length (completed_list);
1918 /* If we only have one hit, use that text
1919 * instead of the text in completed since the
1920 * completed text will use the typed string
1921 * which might be cased all wrong.
1924 text = empathy_contact_get_alias (completed_list->data);
1928 /* Print all hits to the scrollback view, so the
1929 * user knows what possibilities he has.
1932 message = g_string_new ("");
1933 for (l = completed_list; l != NULL; l = l->next) {
1934 g_string_append (message, empathy_contact_get_alias (l->data));
1935 g_string_append (message, " - ");
1937 empathy_chat_view_append_event (chat->view, message->str);
1938 g_string_free (message, TRUE);
1941 gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
1943 if (len == 1 && is_start_of_buffer) {
1944 gchar *complete_char;
1946 complete_char = g_settings_get_string (
1947 priv->gsettings_chat,
1948 EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR);
1950 if (complete_char != NULL) {
1951 gtk_text_buffer_insert_at_cursor (buffer,
1953 strlen (complete_char));
1954 gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
1955 g_free (complete_char);
1962 g_completion_clear_items (priv->completion);
1964 g_list_foreach (list, (GFunc) g_object_unref, NULL);
1974 chat_text_view_focus_in_event_cb (GtkWidget *widget,
1978 gtk_widget_grab_focus (chat->input_text_view);
1984 chat_input_realize_cb (GtkWidget *widget,
1987 DEBUG ("Setting focus to the input text view");
1988 if (gtk_widget_is_sensitive (widget)) {
1989 gtk_widget_grab_focus (widget);
1994 chat_input_has_focus_notify_cb (GtkWidget *widget,
1998 empathy_chat_view_focus_toggled (chat->view, gtk_widget_has_focus (widget));
2002 chat_insert_smiley_activate_cb (EmpathySmileyManager *manager,
2003 EmpathySmiley *smiley,
2006 EmpathyChat *chat = EMPATHY_CHAT (user_data);
2007 GtkTextBuffer *buffer;
2010 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
2012 gtk_text_buffer_get_end_iter (buffer, &iter);
2013 gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
2015 gtk_text_buffer_get_end_iter (buffer, &iter);
2016 gtk_text_buffer_insert (buffer, &iter, " ", -1);
2027 static EmpathyChatSpell *
2028 chat_spell_new (EmpathyChat *chat,
2033 EmpathyChatSpell *chat_spell;
2035 chat_spell = g_slice_new0 (EmpathyChatSpell);
2037 chat_spell->chat = g_object_ref (chat);
2038 chat_spell->word = g_strdup (word);
2039 chat_spell->start = start;
2040 chat_spell->end = end;
2046 chat_spell_free (EmpathyChatSpell *chat_spell)
2048 g_object_unref (chat_spell->chat);
2049 g_free (chat_spell->word);
2050 g_slice_free (EmpathyChatSpell, chat_spell);
2054 chat_spelling_menu_activate_cb (GtkMenuItem *menu_item,
2055 EmpathyChatSpell *chat_spell)
2057 empathy_chat_correct_word (chat_spell->chat,
2058 &(chat_spell->start),
2060 gtk_menu_item_get_label (menu_item));
2065 chat_spelling_build_suggestions_menu (const gchar *code,
2066 EmpathyChatSpell *chat_spell)
2068 GList *suggestions, *l;
2069 GtkWidget *menu, *menu_item;
2071 suggestions = empathy_spell_get_suggestions (code, chat_spell->word);
2072 if (suggestions == NULL)
2075 menu = gtk_menu_new ();
2076 for (l = suggestions; l; l = l->next) {
2077 menu_item = gtk_menu_item_new_with_label (l->data);
2078 g_signal_connect (G_OBJECT (menu_item), "activate",
2079 G_CALLBACK (chat_spelling_menu_activate_cb),
2081 gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
2083 empathy_spell_free_suggestions (suggestions);
2085 gtk_widget_show_all (menu);
2091 chat_spelling_build_menu (EmpathyChatSpell *chat_spell)
2093 GtkWidget *menu, *submenu, *item;
2096 codes = empathy_spell_get_enabled_language_codes ();
2097 g_assert (codes != NULL);
2099 if (g_list_length (codes) > 1) {
2100 menu = gtk_menu_new ();
2102 for (l = codes; l; l = l->next) {
2103 const gchar *code, *name;
2106 name = empathy_spell_get_language_name (code);
2110 item = gtk_image_menu_item_new_with_label (name);
2112 submenu = chat_spelling_build_suggestions_menu (
2114 if (submenu == NULL)
2115 gtk_widget_set_sensitive (item, FALSE);
2117 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item),
2119 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
2122 menu = chat_spelling_build_suggestions_menu (codes->data,
2125 menu = gtk_menu_new ();
2126 item = gtk_menu_item_new_with_label (_("(No Suggestions)"));
2127 gtk_widget_set_sensitive (item, FALSE);
2128 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2131 g_list_free (codes);
2133 gtk_widget_show_all (menu);
2144 static EmpathyChatWord *
2145 chat_word_new (EmpathyChat *chat,
2149 EmpathyChatWord *chat_word;
2151 chat_word = g_slice_new0 (EmpathyChatWord);
2153 chat_word->chat = g_object_ref (chat);
2154 chat_word->word = g_strdup (word);
2155 chat_word->code = g_strdup (code);
2161 chat_word_free (EmpathyChatWord *chat_word)
2163 g_object_unref (chat_word->chat);
2164 g_free (chat_word->word);
2165 g_free (chat_word->code);
2166 g_slice_free (EmpathyChatWord, chat_word);
2170 chat_add_to_dictionary_activate_cb (GtkMenuItem *menu_item,
2171 EmpathyChatWord *chat_word)
2173 EmpathyChatPriv *priv = GET_PRIV (chat_word->chat);
2175 empathy_spell_add_to_dictionary (chat_word->code,
2177 priv->update_misspelled_words_id =
2178 g_idle_add (update_misspelled_words, chat_word->chat);
2182 chat_spelling_build_add_to_dictionary_item (EmpathyChatSpell *chat_spell)
2184 GtkWidget *menu, *item, *lang_item, *image;
2187 const gchar *code, *name;
2188 EmpathyChatWord *chat_word;
2190 codes = empathy_spell_get_enabled_language_codes ();
2191 g_assert (codes != NULL);
2192 if (g_list_length (codes) > 1) {
2193 /* translators: %s is the selected word */
2194 label = g_strdup_printf (_("Add '%s' to Dictionary"),
2196 item = gtk_image_menu_item_new_with_mnemonic (label);
2198 image = gtk_image_new_from_icon_name (GTK_STOCK_ADD,
2199 GTK_ICON_SIZE_MENU);
2200 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),
2203 menu = gtk_menu_new ();
2205 for (l = codes; l; l = l->next) {
2207 name = empathy_spell_get_language_name (code);
2211 lang_item = gtk_image_menu_item_new_with_label (name);
2213 chat_word= chat_word_new (chat_spell->chat,
2214 chat_spell->word, code);
2215 g_object_set_data_full (G_OBJECT (lang_item),
2216 "chat-word", chat_word,
2217 (GDestroyNotify) chat_word_free);
2219 g_signal_connect (G_OBJECT (lang_item), "activate",
2220 G_CALLBACK (chat_add_to_dictionary_activate_cb),
2222 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), lang_item);
2224 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), menu);
2227 name = empathy_spell_get_language_name (code);
2228 g_assert (name != NULL);
2229 /* translators: first %s is the selected word,
2230 * second %s is the language name of the target dictionary */
2231 label = g_strdup_printf (_("Add '%s' to %s Dictionary"),
2232 chat_spell->word, name);
2233 item = gtk_image_menu_item_new_with_mnemonic (label);
2235 image = gtk_image_new_from_icon_name (GTK_STOCK_ADD,
2236 GTK_ICON_SIZE_MENU);
2237 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
2239 chat_word = chat_word_new (chat_spell->chat, chat_spell->word,
2241 g_object_set_data_full (G_OBJECT (item), "chat-word", chat_word,
2242 (GDestroyNotify) chat_word_free);
2244 g_signal_connect (G_OBJECT (item), "activate",
2245 G_CALLBACK (chat_add_to_dictionary_activate_cb),
2248 g_list_free (codes);
2250 gtk_widget_show_all (item);
2256 chat_text_send_cb (GtkMenuItem *menuitem,
2259 chat_input_text_view_send (chat);
2263 chat_input_button_press_event_cb (GtkTextView *view,
2264 GdkEventButton *event,
2267 EmpathyChatPriv *priv = GET_PRIV (chat);
2269 priv->most_recent_event_type = event->type;
2275 chat_input_populate_popup_cb (GtkTextView *view,
2279 EmpathyChatPriv *priv = GET_PRIV (chat);
2280 GtkTextBuffer *buffer;
2281 GtkTextTagTable *table;
2284 GtkTextIter iter, start, end;
2287 EmpathyChatSpell *chat_spell;
2288 GtkWidget *spell_menu;
2289 GtkWidget *spell_item;
2290 EmpathySmileyManager *smiley_manager;
2291 GtkWidget *smiley_menu;
2294 buffer = gtk_text_view_get_buffer (view);
2296 /* Add the emoticon menu. */
2297 item = gtk_separator_menu_item_new ();
2298 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
2299 gtk_widget_show (item);
2301 item = gtk_image_menu_item_new_with_mnemonic (_("Insert Smiley"));
2302 image = gtk_image_new_from_icon_name ("face-smile",
2303 GTK_ICON_SIZE_MENU);
2304 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
2305 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
2306 gtk_widget_show (item);
2308 smiley_manager = empathy_smiley_manager_dup_singleton ();
2309 smiley_menu = empathy_smiley_menu_new (smiley_manager,
2310 chat_insert_smiley_activate_cb,
2312 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), smiley_menu);
2313 g_object_unref (smiley_manager);
2315 /* Add the Send menu item. */
2316 gtk_text_buffer_get_bounds (buffer, &start, &end);
2317 str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
2318 if (!EMP_STR_EMPTY (str)) {
2319 item = gtk_menu_item_new_with_mnemonic (_("_Send"));
2320 g_signal_connect (G_OBJECT (item), "activate",
2321 G_CALLBACK (chat_text_send_cb), chat);
2322 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
2323 gtk_widget_show (item);
2327 /* Add the spell check menu item. */
2328 table = gtk_text_buffer_get_tag_table (buffer);
2329 tag = gtk_text_tag_table_lookup (table, "misspelled");
2331 switch (priv->most_recent_event_type) {
2332 case GDK_BUTTON_PRESS:
2333 /* get the location from the pointer */
2334 gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
2335 gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (view),
2336 GTK_TEXT_WINDOW_WIDGET,
2339 gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (view),
2344 g_warn_if_reached ();
2345 /* assume the KEY_PRESS case */
2348 /* get the location from the cursor */
2349 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
2350 gtk_text_buffer_get_insert (buffer));
2356 if (gtk_text_iter_backward_to_tag_toggle (&start, tag) &&
2357 gtk_text_iter_forward_to_tag_toggle (&end, tag)) {
2359 str = gtk_text_buffer_get_text (buffer,
2360 &start, &end, FALSE);
2362 if (!EMP_STR_EMPTY (str)) {
2363 chat_spell = chat_spell_new (chat, str, start, end);
2364 g_object_set_data_full (G_OBJECT (menu),
2365 "chat-spell", chat_spell,
2366 (GDestroyNotify) chat_spell_free);
2368 item = gtk_separator_menu_item_new ();
2369 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
2370 gtk_widget_show (item);
2372 /* Spelling suggestions */
2373 item = gtk_image_menu_item_new_with_mnemonic (_("_Spelling Suggestions"));
2374 image = gtk_image_new_from_icon_name (GTK_STOCK_SPELL_CHECK,
2375 GTK_ICON_SIZE_MENU);
2376 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
2378 spell_menu = chat_spelling_build_menu (chat_spell);
2379 gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), spell_menu);
2382 spell_item = gtk_separator_menu_item_new ();
2383 gtk_menu_shell_append (GTK_MENU_SHELL (spell_menu), spell_item);
2384 gtk_widget_show (spell_item);
2386 /* Add to dictionary */
2387 spell_item = chat_spelling_build_add_to_dictionary_item (chat_spell);
2389 gtk_menu_shell_append (GTK_MENU_SHELL (spell_menu), spell_item);
2390 gtk_widget_show (spell_item);
2392 gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), item);
2393 gtk_widget_show (item);
2399 chat_log_filter (TplEvent *event,
2402 EmpathyChat *chat = user_data;
2403 EmpathyMessage *message;
2404 EmpathyChatPriv *priv = GET_PRIV (chat);
2405 const GList *pending;
2407 g_return_val_if_fail (TPL_IS_EVENT (event), FALSE);
2408 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
2410 pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
2411 message = empathy_message_from_tpl_log_event (event);
2413 for (; pending; pending = g_list_next (pending)) {
2414 if (empathy_message_equal (message, pending->data)) {
2415 g_object_unref (message);
2420 g_object_unref (message);
2426 show_pending_messages (EmpathyChat *chat) {
2427 EmpathyChatPriv *priv = GET_PRIV (chat);
2428 const GList *messages, *l;
2430 g_return_if_fail (EMPATHY_IS_CHAT (chat));
2432 if (chat->view == NULL || priv->tp_chat == NULL)
2435 if (!priv->can_show_pending)
2438 messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
2440 for (l = messages; l != NULL ; l = g_list_next (l)) {
2441 EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
2442 chat_message_received (chat, message, TRUE);
2448 got_filtered_messages_cb (GObject *manager,
2449 GAsyncResult *result,
2454 EmpathyChat *chat = EMPATHY_CHAT (user_data);
2455 EmpathyChatPriv *priv = GET_PRIV (chat);
2456 GError *error = NULL;
2458 if (!tpl_log_manager_get_filtered_events_finish (TPL_LOG_MANAGER (manager),
2459 result, &messages, &error)) {
2460 DEBUG ("%s. Aborting.", error->message);
2461 empathy_chat_view_append_event (chat->view,
2462 _("Failed to retrieve recent logs"));
2463 g_error_free (error);
2467 for (l = messages; l; l = g_list_next (l)) {
2468 EmpathyMessage *message;
2470 g_assert (TPL_IS_EVENT (l->data));
2472 message = empathy_message_from_tpl_log_event (l->data);
2473 g_object_unref (l->data);
2475 if (empathy_message_is_edit (message)) {
2476 /* this is an edited message, create a synthetic event
2477 * using the supersedes token and
2478 * original-message-sent timestamp, that we can then
2480 EmpathyMessage *syn_msg = g_object_new (
2481 EMPATHY_TYPE_MESSAGE,
2483 "token", empathy_message_get_supersedes (message),
2484 "type", empathy_message_get_tptype (message),
2485 "timestamp", empathy_message_get_original_timestamp (message),
2486 "incoming", empathy_message_is_incoming (message),
2488 "receiver", empathy_message_get_receiver (message),
2489 "sender", empathy_message_get_sender (message),
2492 empathy_chat_view_append_message (chat->view, syn_msg);
2493 empathy_chat_view_edit_message (chat->view, message);
2495 g_object_unref (syn_msg);
2497 /* append the latest message */
2498 empathy_chat_view_append_message (chat->view, message);
2501 g_object_unref (message);
2503 g_list_free (messages);
2506 /* in case of TPL error, skip backlog and show pending messages */
2507 priv->can_show_pending = TRUE;
2508 show_pending_messages (chat);
2510 /* FIXME: See Bug#610994, we are forcing the ACK of the queue. See comments
2511 * about it in EmpathyChatPriv definition */
2512 priv->retrieving_backlogs = FALSE;
2513 empathy_chat_messages_read (chat);
2515 /* Turn back on scrolling */
2516 empathy_chat_view_scroll (chat->view, TRUE);
2520 chat_add_logs (EmpathyChat *chat)
2522 EmpathyChatPriv *priv = GET_PRIV (chat);
2529 /* Turn off scrolling temporarily */
2530 empathy_chat_view_scroll (chat->view, FALSE);
2532 /* Add messages from last conversation */
2533 if (priv->handle_type == TP_HANDLE_TYPE_ROOM)
2534 target = tpl_entity_new_from_room_id (priv->id);
2536 target = tpl_entity_new (priv->id, TPL_ENTITY_CONTACT, NULL, NULL);
2538 priv->retrieving_backlogs = TRUE;
2539 tpl_log_manager_get_filtered_events_async (priv->log_manager,
2542 TPL_EVENT_MASK_TEXT,
2546 got_filtered_messages_cb,
2549 g_object_unref (target);
2553 chat_contacts_completion_func (const gchar *s1,
2557 gchar *tmp, *nick1, *nick2;
2564 return s1 ? -1 : +1;
2567 tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
2568 nick1 = g_utf8_casefold (tmp, -1);
2571 tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
2572 nick2 = g_utf8_casefold (tmp, -1);
2575 ret = strncmp (nick1, nick2, n);
2584 build_part_message (guint reason,
2586 EmpathyContact *actor,
2587 const gchar *message)
2589 GString *s = g_string_new ("");
2590 const gchar *actor_name = NULL;
2592 if (actor != NULL) {
2593 actor_name = empathy_contact_get_alias (actor);
2596 /* Having an actor only really makes sense for a few actions... */
2598 case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE:
2599 g_string_append_printf (s, _("%s has disconnected"), name);
2601 case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED:
2602 if (actor_name != NULL) {
2603 /* translators: reverse the order of these arguments
2604 * if the kicked should come before the kicker in your locale.
2606 g_string_append_printf (s, _("%1$s was kicked by %2$s"),
2609 g_string_append_printf (s, _("%s was kicked"), name);
2612 case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED:
2613 if (actor_name != NULL) {
2614 /* translators: reverse the order of these arguments
2615 * if the banned should come before the banner in your locale.
2617 g_string_append_printf (s, _("%1$s was banned by %2$s"),
2620 g_string_append_printf (s, _("%s was banned"), name);
2624 g_string_append_printf (s, _("%s has left the room"), name);
2627 if (!EMP_STR_EMPTY (message)) {
2628 /* Note to translators: this string is appended to
2629 * notifications like "foo has left the room", with the message
2630 * given by the user living the room. If this poses a problem,
2631 * please let us know. :-)
2633 g_string_append_printf (s, _(" (%s)"), message);
2636 return g_string_free (s, FALSE);
2640 chat_members_changed_cb (EmpathyTpChat *tp_chat,
2641 EmpathyContact *contact,
2642 EmpathyContact *actor,
2648 EmpathyChatPriv *priv = GET_PRIV (chat);
2649 const gchar *name = empathy_contact_get_alias (contact);
2652 g_return_if_fail (TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED != reason);
2654 if (priv->block_events_timeout_id != 0)
2658 str = g_strdup_printf (_("%s has joined the room"),
2661 str = build_part_message (reason, name, actor, message);
2664 empathy_chat_view_append_event (chat->view, str);
2669 chat_member_renamed_cb (EmpathyTpChat *tp_chat,
2670 EmpathyContact *old_contact,
2671 EmpathyContact *new_contact,
2676 EmpathyChatPriv *priv = GET_PRIV (chat);
2678 g_return_if_fail (TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED == reason);
2680 if (priv->block_events_timeout_id == 0) {
2683 str = g_strdup_printf (_("%s is now known as %s"),
2684 empathy_contact_get_alias (old_contact),
2685 empathy_contact_get_alias (new_contact));
2686 empathy_chat_view_append_event (chat->view, str);
2693 chat_contacts_visible_timeout_cb (gpointer chat)
2695 EmpathyChatPriv *priv = GET_PRIV (chat);
2697 /* Relax the size request */
2698 gtk_widget_set_size_request (priv->vbox_left, -1, -1);
2700 /* Set the position of the slider. This must be done here because
2701 * GtkPaned need to know its size allocation and it will be settled only
2702 * after the gtk_window_resize () tough effect. */
2703 if (priv->contacts_width > 0) {
2704 gtk_paned_set_position (GTK_PANED (priv->hpaned),
2705 priv->contacts_width);
2708 priv->contacts_visible_id = 0;
2714 chat_update_contacts_visibility (EmpathyChat *chat,
2717 EmpathyChatPriv *priv = GET_PRIV (chat);
2719 if (!priv->scrolled_window_contacts) {
2723 if (priv->remote_contact != NULL) {
2727 if (show && priv->contact_list_view == NULL) {
2728 EmpathyContactListStore *store;
2730 GtkAllocation allocation;
2732 /* We are adding the contact list to the chat, we don't want the
2733 * chat view to become too small. If the chat view is already
2734 * smaller than 250 make sure that size won't change. If the
2735 * chat view is bigger the contact list will take some space on
2736 * it but we make sure the chat view don't become smaller than
2737 * 250. Relax the size request once the resize is done */
2738 gtk_widget_get_allocation (priv->vbox_left, &allocation);
2739 min_width = MIN (allocation.width, 250);
2740 gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
2742 /* There is no way to know when the window resize will happen
2743 * since it is WM's decision. Let's hope it won't be longer. */
2744 if (priv->contacts_visible_id != 0)
2745 g_source_remove (priv->contacts_visible_id);
2746 priv->contacts_visible_id = g_timeout_add (500,
2747 chat_contacts_visible_timeout_cb, chat);
2749 store = empathy_contact_list_store_new (
2750 EMPATHY_CONTACT_LIST (priv->tp_chat));
2751 empathy_contact_list_store_set_show_groups (
2752 EMPATHY_CONTACT_LIST_STORE (store), FALSE);
2754 priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
2755 EMPATHY_CONTACT_LIST_FEATURE_CONTACT_TOOLTIP,
2756 EMPATHY_CONTACT_FEATURE_CHAT |
2757 EMPATHY_CONTACT_FEATURE_CALL |
2758 EMPATHY_CONTACT_FEATURE_LOG |
2759 EMPATHY_CONTACT_FEATURE_INFO));
2760 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
2761 priv->contact_list_view);
2762 gtk_widget_show (priv->contact_list_view);
2763 gtk_widget_show (priv->scrolled_window_contacts);
2764 g_object_unref (store);
2766 priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
2767 gtk_widget_hide (priv->scrolled_window_contacts);
2768 if (priv->contact_list_view != NULL) {
2769 gtk_widget_destroy (priv->contact_list_view);
2770 priv->contact_list_view = NULL;
2776 empathy_chat_set_show_contacts (EmpathyChat *chat,
2779 EmpathyChatPriv *priv = GET_PRIV (chat);
2781 priv->show_contacts = show;
2783 chat_update_contacts_visibility (chat, show);
2785 g_object_notify (G_OBJECT (chat), "show-contacts");
2789 chat_remote_contact_changed_cb (EmpathyChat *chat)
2791 EmpathyChatPriv *priv = GET_PRIV (chat);
2793 if (priv->remote_contact != NULL) {
2794 g_object_unref (priv->remote_contact);
2795 priv->remote_contact = NULL;
2800 priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
2801 priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
2802 if (priv->remote_contact != NULL) {
2803 g_object_ref (priv->remote_contact);
2804 priv->handle_type = TP_HANDLE_TYPE_CONTACT;
2806 else if (priv->tp_chat != NULL) {
2807 tp_channel_get_handle ((TpChannel *) priv->tp_chat, &priv->handle_type);
2810 chat_update_contacts_visibility (chat, priv->show_contacts);
2812 g_object_notify (G_OBJECT (chat), "remote-contact");
2813 g_object_notify (G_OBJECT (chat), "id");
2817 chat_invalidated_cb (EmpathyTpChat *tp_chat,
2823 EmpathyChatPriv *priv;
2825 priv = GET_PRIV (chat);
2827 if (!priv->tp_chat) {
2831 chat_composing_remove_timeout (chat);
2832 g_object_unref (priv->tp_chat);
2833 priv->tp_chat = NULL;
2834 g_object_notify (G_OBJECT (chat), "tp-chat");
2836 empathy_chat_view_append_event (chat->view, _("Disconnected"));
2837 gtk_widget_set_sensitive (chat->input_text_view, FALSE);
2839 chat_update_contacts_visibility (chat, FALSE);
2841 priv->unread_messages_when_offline = priv->unread_messages;
2845 update_misspelled_words (gpointer data)
2847 EmpathyChat *chat = EMPATHY_CHAT (data);
2848 EmpathyChatPriv *priv = GET_PRIV (chat);
2849 GtkTextBuffer *buffer;
2853 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
2855 gtk_text_buffer_get_end_iter (buffer, &iter);
2856 length = gtk_text_iter_get_offset (&iter);
2857 chat_input_text_buffer_insert_text_cb (buffer, &iter,
2858 NULL, length, chat);
2860 priv->update_misspelled_words_id = 0;
2866 conf_spell_checking_cb (GSettings *gsettings_chat,
2870 EmpathyChat *chat = EMPATHY_CHAT (user_data);
2871 EmpathyChatPriv *priv = GET_PRIV (chat);
2872 gboolean spell_checker;
2873 GtkTextBuffer *buffer;
2875 if (strcmp (key, EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED) != 0)
2878 spell_checker = g_settings_get_boolean (gsettings_chat,
2879 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED);
2881 if (!empathy_spell_supported ()) {
2882 spell_checker = FALSE;
2885 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
2887 if (spell_checker == priv->spell_checking_enabled) {
2888 if (spell_checker) {
2889 /* Possibly changed dictionaries,
2890 * update misspelled words. Need to do so in idle
2891 * so the spell checker is updated. */
2892 priv->update_misspelled_words_id =
2893 g_idle_add (update_misspelled_words, chat);
2899 if (spell_checker) {
2902 priv->notify_cursor_position_id = tp_g_signal_connect_object (
2903 buffer, "notify::cursor-position",
2904 G_CALLBACK (chat_input_text_buffer_notify_cursor_position_cb),
2906 priv->insert_text_id = tp_g_signal_connect_object (
2907 buffer, "insert-text",
2908 G_CALLBACK (chat_input_text_buffer_insert_text_cb),
2909 chat, G_CONNECT_AFTER);
2910 priv->delete_range_id = tp_g_signal_connect_object (
2911 buffer, "delete-range",
2912 G_CALLBACK (chat_input_text_buffer_delete_range_cb),
2913 chat, G_CONNECT_AFTER);
2915 gtk_text_buffer_create_tag (buffer, "misspelled",
2916 "underline", PANGO_UNDERLINE_ERROR,
2919 gtk_text_buffer_get_iter_at_mark (buffer, &iter,
2920 gtk_text_buffer_get_insert (buffer));
2921 gtk_text_buffer_create_mark (buffer, "previous-cursor-position",
2924 /* Mark misspelled words in the existing buffer.
2925 * Need to do so in idle so the spell checker is updated. */
2926 priv->update_misspelled_words_id =
2927 g_idle_add (update_misspelled_words, chat);
2929 GtkTextTagTable *table;
2932 g_signal_handler_disconnect (buffer, priv->notify_cursor_position_id);
2933 priv->notify_cursor_position_id = 0;
2934 g_signal_handler_disconnect (buffer, priv->insert_text_id);
2935 priv->insert_text_id = 0;
2936 g_signal_handler_disconnect (buffer, priv->delete_range_id);
2937 priv->delete_range_id = 0;
2939 table = gtk_text_buffer_get_tag_table (buffer);
2940 tag = gtk_text_tag_table_lookup (table, "misspelled");
2941 gtk_text_tag_table_remove (table, tag);
2943 gtk_text_buffer_delete_mark_by_name (buffer,
2944 "previous-cursor-position");
2947 priv->spell_checking_enabled = spell_checker;
2951 save_paned_pos_timeout (gpointer data)
2953 EmpathyChat *self = data;
2956 hpaned_pos = gtk_paned_get_position (GTK_PANED (self->priv->hpaned));
2958 g_settings_set_int (self->priv->gsettings_ui,
2959 EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS,
2966 chat_hpaned_pos_changed_cb (GtkWidget* hpaned,
2970 EmpathyChat *chat = EMPATHY_CHAT (user_data);
2972 if (chat->priv->save_paned_pos_id != 0)
2973 g_source_remove (chat->priv->save_paned_pos_id);
2975 chat->priv->save_paned_pos_id = g_timeout_add_seconds (1,
2976 save_paned_pos_timeout, chat);
2982 chat_create_ui (EmpathyChat *chat)
2984 EmpathyChatPriv *priv = GET_PRIV (chat);
2988 GtkTextBuffer *buffer;
2989 EmpathyThemeManager *theme_mgr;
2991 filename = empathy_file_lookup ("empathy-chat.ui",
2993 gui = empathy_builder_get_file (filename,
2994 "chat_widget", &priv->widget,
2995 "hpaned", &priv->hpaned,
2996 "vbox_left", &priv->vbox_left,
2997 "scrolled_window_chat", &priv->scrolled_window_chat,
2998 "scrolled_window_input", &priv->scrolled_window_input,
2999 "hbox_topic", &priv->hbox_topic,
3000 "expander_topic", &priv->expander_topic,
3001 "label_topic", &priv->label_topic,
3002 "scrolled_window_contacts", &priv->scrolled_window_contacts,
3003 "info_bar_vbox", &priv->info_bar_vbox,
3006 empathy_builder_connect (gui, chat,
3007 "expander_topic", "notify::expanded", chat_topic_expander_activate_cb,
3008 "label_topic", "size-allocate", chat_topic_label_size_allocate_cb,
3013 /* Add message view. */
3014 theme_mgr = empathy_theme_manager_dup_singleton ();
3015 chat->view = empathy_theme_manager_create_view (theme_mgr);
3016 g_object_unref (theme_mgr);
3017 /* If this is a GtkTextView, it's set as a drag destination for text/plain
3018 and other types, even though it's non-editable and doesn't accept any
3019 drags. This steals drag motion for anything inside the scrollbars,
3020 making drag destinations on chat windows far less useful.
3022 gtk_drag_dest_unset (GTK_WIDGET (chat->view));
3023 g_signal_connect (chat->view, "focus_in_event",
3024 G_CALLBACK (chat_text_view_focus_in_event_cb),
3026 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
3027 GTK_WIDGET (chat->view));
3028 gtk_widget_show (GTK_WIDGET (chat->view));
3030 /* Add input GtkTextView */
3031 chat->input_text_view = empathy_input_text_view_new ();
3032 g_signal_connect (chat->input_text_view, "notify::has-focus",
3033 G_CALLBACK (chat_input_has_focus_notify_cb),
3035 g_signal_connect (chat->input_text_view, "key-press-event",
3036 G_CALLBACK (chat_input_key_press_event_cb),
3038 g_signal_connect (chat->input_text_view, "realize",
3039 G_CALLBACK (chat_input_realize_cb),
3041 g_signal_connect (chat->input_text_view, "button-press-event",
3042 G_CALLBACK (chat_input_button_press_event_cb),
3044 g_signal_connect (chat->input_text_view, "populate-popup",
3045 G_CALLBACK (chat_input_populate_popup_cb),
3047 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
3048 tp_g_signal_connect_object (buffer, "changed",
3049 G_CALLBACK (chat_input_text_buffer_changed_cb),
3051 tp_g_signal_connect_object (priv->gsettings_chat,
3052 "changed::" EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
3053 G_CALLBACK (conf_spell_checking_cb), chat, 0);
3054 conf_spell_checking_cb (priv->gsettings_chat,
3055 EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED, chat);
3056 gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
3057 chat->input_text_view);
3058 gtk_widget_show (chat->input_text_view);
3060 /* Add the (invisible) search bar */
3061 priv->search_bar = empathy_search_bar_new (chat->view);
3062 gtk_box_pack_start (GTK_BOX(priv->vbox_left),
3065 gtk_box_reorder_child (GTK_BOX(priv->vbox_left), priv->search_bar, 1);
3067 /* Initialy hide the topic, will be shown if not empty */
3068 gtk_widget_hide (priv->hbox_topic);
3070 g_signal_connect (priv->hpaned, "notify::position",
3071 G_CALLBACK (chat_hpaned_pos_changed_cb),
3074 /* Set widget focus order */
3075 list = g_list_append (NULL, priv->search_bar);
3076 list = g_list_append (list, priv->scrolled_window_input);
3077 gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
3080 list = g_list_append (NULL, priv->vbox_left);
3081 list = g_list_append (list, priv->scrolled_window_contacts);
3082 gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
3085 list = g_list_append (NULL, priv->hpaned);
3086 list = g_list_append (list, priv->hbox_topic);
3087 gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
3090 /* Add the main widget in the chat widget */
3091 gtk_box_pack_start (GTK_BOX (chat), priv->widget, TRUE, TRUE, 0);
3092 g_object_unref (gui);
3096 chat_finalize (GObject *object)
3099 EmpathyChatPriv *priv;
3101 chat = EMPATHY_CHAT (object);
3102 priv = GET_PRIV (chat);
3104 DEBUG ("Finalized: %p", object);
3106 if (priv->update_misspelled_words_id != 0)
3107 g_source_remove (priv->update_misspelled_words_id);
3109 if (priv->save_paned_pos_id != 0)
3110 g_source_remove (priv->save_paned_pos_id);
3112 if (priv->contacts_visible_id != 0)
3113 g_source_remove (priv->contacts_visible_id);
3115 g_object_unref (priv->gsettings_chat);
3116 g_object_unref (priv->gsettings_ui);
3118 g_list_foreach (priv->input_history, (GFunc) chat_input_history_entry_free, NULL);
3119 g_list_free (priv->input_history);
3121 g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
3122 g_list_free (priv->compositors);
3124 chat_composing_remove_timeout (chat);
3126 g_object_unref (priv->account_manager);
3127 g_object_unref (priv->log_manager);
3129 if (priv->tp_chat) {
3130 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3131 chat_invalidated_cb, chat);
3132 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3133 chat_message_received_cb, chat);
3134 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3135 chat_message_acknowledged_cb, chat);
3136 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3137 chat_send_error_cb, chat);
3138 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3139 chat_state_changed_cb, chat);
3140 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3141 chat_members_changed_cb, chat);
3142 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3143 chat_remote_contact_changed_cb, chat);
3144 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3145 chat_title_changed_cb, chat);
3146 g_signal_handlers_disconnect_by_func (priv->tp_chat,
3147 chat_subject_changed_cb, chat);
3148 empathy_tp_chat_leave (priv->tp_chat, "");
3149 g_object_unref (priv->tp_chat);
3151 if (priv->account) {
3152 g_object_unref (priv->account);
3154 if (priv->remote_contact) {
3155 g_object_unref (priv->remote_contact);
3158 if (priv->block_events_timeout_id) {
3159 g_source_remove (priv->block_events_timeout_id);
3163 g_free (priv->name);
3164 g_free (priv->subject);
3165 g_completion_free (priv->completion);
3167 G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
3171 chat_constructed (GObject *object)
3173 EmpathyChat *chat = EMPATHY_CHAT (object);
3174 EmpathyChatPriv *priv = GET_PRIV (chat);
3176 if (priv->handle_type != TP_HANDLE_TYPE_ROOM) {
3177 /* First display logs from the logger and then display pending messages */
3178 chat_add_logs (chat);
3181 /* Just display pending messages for rooms */
3182 priv->can_show_pending = TRUE;
3183 show_pending_messages (chat);
3188 empathy_chat_class_init (EmpathyChatClass *klass)
3190 GObjectClass *object_class = G_OBJECT_CLASS (klass);
3192 object_class->finalize = chat_finalize;
3193 object_class->get_property = chat_get_property;
3194 object_class->set_property = chat_set_property;
3195 object_class->constructed = chat_constructed;
3197 g_object_class_install_property (object_class,
3199 g_param_spec_object ("tp-chat",
3201 "The tp chat object",
3202 EMPATHY_TYPE_TP_CHAT,
3205 G_PARAM_STATIC_STRINGS));
3206 g_object_class_install_property (object_class,
3208 g_param_spec_object ("account",
3209 "Account of the chat",
3210 "The account of the chat",
3213 G_PARAM_STATIC_STRINGS));
3214 g_object_class_install_property (object_class,
3216 g_param_spec_string ("id",
3218 "The id of the chat",
3221 G_PARAM_STATIC_STRINGS));
3222 g_object_class_install_property (object_class,
3224 g_param_spec_string ("name",
3226 "The name of the chat",
3229 G_PARAM_STATIC_STRINGS));
3230 g_object_class_install_property (object_class,
3232 g_param_spec_string ("subject",
3234 "The subject or topic of the chat",
3237 G_PARAM_STATIC_STRINGS));
3238 g_object_class_install_property (object_class,
3239 PROP_REMOTE_CONTACT,
3240 g_param_spec_object ("remote-contact",
3241 "The remote contact",
3242 "The remote contact is any",
3243 EMPATHY_TYPE_CONTACT,
3245 G_PARAM_STATIC_STRINGS));
3246 g_object_class_install_property (object_class,
3248 g_param_spec_boolean ("show-contacts",
3249 "Contacts' visibility",
3250 "The visibility of the contacts' list",
3253 G_PARAM_STATIC_STRINGS));
3255 g_object_class_install_property (object_class,
3257 g_param_spec_boolean ("sms-channel",
3259 "TRUE if this channel is for sending SMSes",
3261 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
3263 g_object_class_install_property (object_class,
3264 PROP_N_MESSAGES_SENDING,
3265 g_param_spec_uint ("n-messages-sending",
3266 "Num Messages Sending",
3267 "The number of messages being sent",
3269 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
3271 g_object_class_install_property (object_class,
3272 PROP_NB_UNREAD_MESSAGES,
3273 g_param_spec_uint ("nb-unread-messages",
3274 "Num Unread Messages",
3275 "The number of unread messages",
3277 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
3279 signals[COMPOSING] =
3280 g_signal_new ("composing",
3281 G_OBJECT_CLASS_TYPE (object_class),
3285 g_cclosure_marshal_generic,
3289 signals[NEW_MESSAGE] =
3290 g_signal_new ("new-message",
3291 G_OBJECT_CLASS_TYPE (object_class),
3295 g_cclosure_marshal_generic,
3297 2, EMPATHY_TYPE_MESSAGE, G_TYPE_BOOLEAN);
3299 signals[PART_COMMAND_ENTERED] =
3300 g_signal_new ("part-command-entered",
3301 G_OBJECT_CLASS_TYPE (object_class),
3305 g_cclosure_marshal_generic,
3309 g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
3313 chat_block_events_timeout_cb (gpointer data)
3315 EmpathyChatPriv *priv = GET_PRIV (data);
3317 priv->block_events_timeout_id = 0;
3323 account_manager_prepared_cb (GObject *source_object,
3324 GAsyncResult *result,
3327 GList *accounts, *l;
3328 TpAccountManager *account_manager = TP_ACCOUNT_MANAGER (source_object);
3329 EmpathyChat *chat = user_data;
3330 GError *error = NULL;
3332 if (!tp_proxy_prepare_finish (account_manager, result, &error)) {
3333 DEBUG ("Failed to prepare the account manager: %s", error->message);
3334 g_error_free (error);
3338 accounts = tp_account_manager_get_valid_accounts (account_manager);
3340 for (l = accounts; l != NULL; l = l->next) {
3341 TpAccount *account = l->data;
3342 tp_g_signal_connect_object (account, "status-changed",
3343 G_CALLBACK (chat_new_connection_cb),
3347 g_list_free (accounts);
3351 empathy_chat_init (EmpathyChat *chat)
3353 EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
3354 EMPATHY_TYPE_CHAT, EmpathyChatPriv);
3357 priv->log_manager = tpl_log_manager_dup_singleton ();
3358 priv->gsettings_chat = g_settings_new (EMPATHY_PREFS_CHAT_SCHEMA);
3359 priv->gsettings_ui = g_settings_new (EMPATHY_PREFS_UI_SCHEMA);
3361 priv->contacts_width = g_settings_get_int (priv->gsettings_ui,
3362 EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS);
3363 priv->input_history = NULL;
3364 priv->input_history_current = NULL;
3365 priv->account_manager = tp_account_manager_dup ();
3367 tp_proxy_prepare_async (priv->account_manager, NULL,
3368 account_manager_prepared_cb, chat);
3370 priv->show_contacts = g_settings_get_boolean (priv->gsettings_chat,
3371 EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS);
3373 /* Block events for some time to avoid having "has come online" or
3374 * "joined" messages. */
3375 priv->block_events_timeout_id =
3376 g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
3378 /* Add nick name completion */
3379 priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_alias);
3380 g_completion_set_compare (priv->completion, chat_contacts_completion_func);
3382 chat_create_ui (chat);
3386 empathy_chat_new (EmpathyTpChat *tp_chat)
3388 return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
3392 empathy_chat_get_tp_chat (EmpathyChat *chat)
3394 EmpathyChatPriv *priv = GET_PRIV (chat);
3396 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3398 return priv->tp_chat;
3404 GtkWidget *info_bar;
3414 passwd_remember_button_cb (GtkButton *button,
3417 gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_OK);
3421 passwd_not_now_button_cb (GtkButton *button,
3424 gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_NO);
3428 remember_password_infobar_response_cb (GtkWidget *info_bar,
3432 EmpathyChatPriv *priv = GET_PRIV (data->self);
3434 if (response_id == GTK_RESPONSE_OK) {
3435 DEBUG ("Saving room password");
3436 empathy_keyring_set_room_password_async (priv->account,
3437 empathy_tp_chat_get_id (priv->tp_chat),
3442 gtk_widget_destroy (info_bar);
3443 g_free (data->password);
3444 g_slice_free (PasswordData, data);
3448 chat_prompt_to_save_password (EmpathyChat *self,
3451 GtkWidget *content_area;
3458 /* save the password in case it needs to be saved */
3459 data->password = g_strdup (gtk_entry_get_text (GTK_ENTRY (data->entry)));
3461 /* Remove all previous widgets */
3462 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (data->info_bar));
3463 gtk_container_forall (GTK_CONTAINER (content_area),
3464 (GtkCallback) gtk_widget_destroy, NULL);
3465 data->button = NULL;
3468 data->spinner = NULL;
3470 gtk_info_bar_set_message_type (GTK_INFO_BAR (data->info_bar),
3471 GTK_MESSAGE_QUESTION);
3473 hbox = gtk_hbox_new (FALSE, 5);
3474 gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
3477 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
3478 GTK_ICON_SIZE_DIALOG);
3479 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3482 label = gtk_label_new (_("Would you like to store this password?"));
3483 gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
3485 /* Add 'Remember' button */
3486 alig = gtk_alignment_new (0, 0.5, 1, 0);
3488 button = gtk_button_new_with_label (_("Remember"));
3489 gtk_container_add (GTK_CONTAINER (alig), button);
3490 gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
3492 g_signal_connect (button, "clicked", G_CALLBACK (passwd_remember_button_cb),
3495 /* Add 'Not now' button */
3496 alig = gtk_alignment_new (0, 0.5, 1, 0);
3498 button = gtk_button_new_with_label (_("Not now"));
3499 gtk_container_add (GTK_CONTAINER (alig), button);
3500 gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
3502 g_signal_connect (button, "clicked", G_CALLBACK (passwd_not_now_button_cb),
3506 g_signal_handler_disconnect (data->info_bar, data->response_id);
3507 g_signal_connect (data->info_bar, "response",
3508 G_CALLBACK (remember_password_infobar_response_cb), data);
3510 gtk_widget_show_all (data->info_bar);
3514 provide_password_cb (GObject *tp_chat,
3518 PasswordData *data = user_data;
3519 EmpathyChat *self = data->self;
3520 EmpathyChatPriv *priv = GET_PRIV (self);
3521 GError *error = NULL;
3523 if (!tp_channel_provide_password_finish (TP_CHANNEL (tp_chat), res,
3525 DEBUG ("error: %s", error->message);
3526 /* FIXME: what should we do if that's another error? Close the channel?
3527 * Display the raw D-Bus error to the user isn't very useful */
3528 if (g_error_matches (error, TP_ERRORS, TP_ERROR_AUTHENTICATION_FAILED)) {
3530 gtk_entry_set_text (GTK_ENTRY (data->entry), "");
3531 gtk_widget_set_sensitive (data->entry, TRUE);
3532 gtk_widget_grab_focus (data->entry);
3535 gtk_info_bar_set_message_type (
3536 GTK_INFO_BAR (data->info_bar),
3540 gtk_widget_set_sensitive (data->button, TRUE);
3541 gtk_button_set_label (GTK_BUTTON (data->button),
3545 gtk_label_set_text (GTK_LABEL (data->label),
3546 _("Wrong password; please try again:"));
3549 gtk_spinner_stop (GTK_SPINNER (data->spinner));
3550 gtk_widget_hide (data->spinner);
3552 g_error_free (error);
3556 if (empathy_keyring_is_available ()) {
3557 /* ask whether they want to save the password */
3558 chat_prompt_to_save_password (self, data);
3560 /* Get rid of the password info bar finally */
3561 gtk_widget_destroy (data->info_bar);
3562 g_slice_free (PasswordData, data);
3566 gtk_widget_set_sensitive (priv->hpaned, TRUE);
3567 gtk_widget_set_sensitive (self->input_text_view, TRUE);
3568 gtk_widget_grab_focus (self->input_text_view);
3572 password_infobar_response_cb (GtkWidget *info_bar,
3576 EmpathyChatPriv *priv = GET_PRIV (data->self);
3577 const gchar *password;
3579 if (response_id != GTK_RESPONSE_OK) {
3580 gtk_widget_destroy (info_bar);
3581 g_slice_free (PasswordData, data);
3585 password = gtk_entry_get_text (GTK_ENTRY (data->entry));
3587 tp_channel_provide_password_async (TP_CHANNEL (priv->tp_chat), password,
3588 provide_password_cb, data);
3590 gtk_widget_set_sensitive (data->button, FALSE);
3591 gtk_widget_set_sensitive (data->entry, FALSE);
3593 gtk_spinner_start (GTK_SPINNER (data->spinner));
3594 gtk_widget_show (data->spinner);
3598 password_entry_activate_cb (GtkWidget *entry,
3601 gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_OK);
3605 passwd_join_button_cb (GtkButton *button,
3608 gtk_info_bar_response (GTK_INFO_BAR (data->info_bar), GTK_RESPONSE_OK);
3612 clear_icon_released_cb (GtkEntry *entry,
3613 GtkEntryIconPosition icon_pos,
3617 gtk_entry_set_text (entry, "");
3621 password_entry_changed_cb (GtkEditable *entry,
3626 str = gtk_entry_get_text (GTK_ENTRY (entry));
3628 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
3629 GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
3633 infobar_chat_invalidated_cb (TpProxy *proxy,
3637 gpointer password_infobar)
3639 /* Destroy the password infobar whenever a channel is invalidated
3640 * so we don't have multiple infobars when the MUC is rejoined */
3641 gtk_widget_destroy (GTK_WIDGET (password_infobar));
3645 display_password_info_bar (EmpathyChat *self)
3647 EmpathyChatPriv *priv = GET_PRIV (self);
3648 GtkWidget *info_bar;
3649 GtkWidget *content_area;
3659 data = g_slice_new0 (PasswordData);
3661 info_bar = gtk_info_bar_new ();
3662 gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar),
3663 GTK_MESSAGE_QUESTION);
3665 content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
3667 hbox = gtk_hbox_new (FALSE, 5);
3668 gtk_box_pack_start (GTK_BOX (content_area), hbox, TRUE, TRUE, 0);
3671 image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
3672 GTK_ICON_SIZE_DIALOG);
3673 gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
3676 label = gtk_label_new (_("This room is protected by a password:"));
3677 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
3679 /* Add password entry */
3680 entry = gtk_entry_new ();
3681 gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
3682 gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
3684 gtk_entry_set_icon_from_stock (GTK_ENTRY (entry),
3685 GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
3686 gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
3687 GTK_ENTRY_ICON_SECONDARY, FALSE);
3689 g_signal_connect (entry, "icon-release",
3690 G_CALLBACK (clear_icon_released_cb), data);
3691 g_signal_connect (entry, "changed",
3692 G_CALLBACK (password_entry_changed_cb), data);
3694 g_signal_connect (entry, "activate",
3695 G_CALLBACK (password_entry_activate_cb), data);
3697 /* Focus the password entry once it's realized */
3698 g_signal_connect (entry, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
3700 /* Add 'Join' button */
3701 alig = gtk_alignment_new (0, 0.5, 1, 0);
3703 button = gtk_button_new_with_label (_("Join"));
3704 gtk_container_add (GTK_CONTAINER (alig), button);
3705 gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
3707 g_signal_connect (button, "clicked", G_CALLBACK (passwd_join_button_cb),
3711 spinner = gtk_spinner_new ();
3712 gtk_box_pack_end (GTK_BOX (hbox), spinner, FALSE, FALSE, 0);
3714 /* Save some data for messing around with later */
3716 data->info_bar = info_bar;
3717 data->button = button;
3718 data->label = label;
3719 data->entry = entry;
3720 data->spinner = spinner;
3722 gtk_box_pack_start (GTK_BOX (priv->info_bar_vbox), info_bar,
3724 gtk_widget_show_all (hbox);
3726 tp_g_signal_connect_object (priv->tp_chat,
3727 "invalidated", G_CALLBACK (infobar_chat_invalidated_cb),
3730 data->response_id = g_signal_connect (info_bar, "response",
3731 G_CALLBACK (password_infobar_response_cb), data);
3733 gtk_widget_show_all (info_bar);
3734 /* ... but hide the spinner */
3735 gtk_widget_hide (spinner);
3737 /* prevent the user from typing anything */
3738 gtk_widget_set_sensitive (self->input_text_view, FALSE);
3742 provide_saved_password_cb (GObject *tp_chat,
3746 EmpathyChat *self = user_data;
3747 EmpathyChatPriv *priv = GET_PRIV (self);
3748 GError *error = NULL;
3750 if (!tp_channel_provide_password_finish (TP_CHANNEL (tp_chat), res,
3752 DEBUG ("error: %s", error->message);
3753 /* FIXME: what should we do if that's another error? Close the channel?
3754 * Display the raw D-Bus error to the user isn't very useful */
3755 if (g_error_matches (error, TP_ERRORS, TP_ERROR_AUTHENTICATION_FAILED)) {
3756 display_password_info_bar (self);
3757 gtk_widget_set_sensitive (priv->hpaned, FALSE);
3759 g_error_free (error);
3764 gtk_widget_set_sensitive (priv->hpaned, TRUE);
3765 gtk_widget_grab_focus (self->input_text_view);
3769 chat_room_got_password_cb (GObject *source,
3770 GAsyncResult *result,
3773 EmpathyChat *self = user_data;
3774 EmpathyChatPriv *priv = GET_PRIV (self);
3775 const gchar *password;
3776 GError *error = NULL;
3778 password = empathy_keyring_get_room_password_finish (priv->account,
3781 if (error != NULL) {
3782 DEBUG ("Couldn't get room password: %s\n", error->message);
3783 g_clear_error (&error);
3785 display_password_info_bar (self);
3786 gtk_widget_set_sensitive (priv->hpaned, FALSE);
3790 tp_channel_provide_password_async (TP_CHANNEL (priv->tp_chat), password,
3791 provide_saved_password_cb, self);
3795 chat_password_needed_changed_cb (EmpathyChat *self)
3797 EmpathyChatPriv *priv = GET_PRIV (self);
3799 if (tp_channel_password_needed (TP_CHANNEL (priv->tp_chat))) {
3800 empathy_keyring_get_room_password_async (priv->account,
3801 empathy_tp_chat_get_id (priv->tp_chat),
3802 chat_room_got_password_cb, self);
3807 chat_sms_channel_changed_cb (EmpathyChat *self)
3809 EmpathyChatPriv *priv = GET_PRIV (self);
3811 priv->sms_channel = tp_text_channel_is_sms_channel (
3812 (TpTextChannel *) priv->tp_chat);
3813 g_object_notify (G_OBJECT (self), "sms-channel");
3817 chat_n_messages_sending_changed_cb (EmpathyChat *self)
3819 g_object_notify (G_OBJECT (self), "n-messages-sending");
3823 empathy_chat_set_tp_chat (EmpathyChat *chat,
3824 EmpathyTpChat *tp_chat)
3826 EmpathyChatPriv *priv = GET_PRIV (chat);
3828 g_return_if_fail (EMPATHY_IS_CHAT (chat));
3829 g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
3831 if (priv->tp_chat) {
3835 if (priv->account) {
3836 g_object_unref (priv->account);
3839 priv->tp_chat = g_object_ref (tp_chat);
3840 priv->account = g_object_ref (empathy_tp_chat_get_account (priv->tp_chat));
3842 g_signal_connect (tp_chat, "invalidated",
3843 G_CALLBACK (chat_invalidated_cb),
3845 g_signal_connect (tp_chat, "message-received-empathy",
3846 G_CALLBACK (chat_message_received_cb),
3848 g_signal_connect (tp_chat, "message_acknowledged",
3849 G_CALLBACK (chat_message_acknowledged_cb),
3851 g_signal_connect (tp_chat, "send-error",
3852 G_CALLBACK (chat_send_error_cb),
3854 g_signal_connect (tp_chat, "chat-state-changed-empathy",
3855 G_CALLBACK (chat_state_changed_cb),
3857 g_signal_connect (tp_chat, "members-changed",
3858 G_CALLBACK (chat_members_changed_cb),
3860 g_signal_connect (tp_chat, "member-renamed",
3861 G_CALLBACK (chat_member_renamed_cb),
3863 g_signal_connect_swapped (tp_chat, "notify::remote-contact",
3864 G_CALLBACK (chat_remote_contact_changed_cb),
3866 g_signal_connect_swapped (tp_chat, "notify::password-needed",
3867 G_CALLBACK (chat_password_needed_changed_cb),
3869 g_signal_connect_swapped (tp_chat, "notify::is-sms-channel",
3870 G_CALLBACK (chat_sms_channel_changed_cb),
3872 g_signal_connect_swapped (tp_chat, "notify::n-messages-sending",
3873 G_CALLBACK (chat_n_messages_sending_changed_cb),
3875 g_signal_connect_swapped (tp_chat, "notify::title",
3876 G_CALLBACK (chat_title_changed_cb),
3878 g_signal_connect_swapped (tp_chat, "notify::subject",
3879 G_CALLBACK (chat_subject_changed_cb),
3882 /* Get initial value of properties */
3883 chat_sms_channel_changed_cb (chat);
3884 chat_remote_contact_changed_cb (chat);
3885 chat_title_changed_cb (chat);
3886 chat_subject_changed_cb (chat);
3888 if (chat->input_text_view) {
3889 gtk_widget_set_sensitive (chat->input_text_view, TRUE);
3890 if (priv->block_events_timeout_id == 0) {
3891 empathy_chat_view_append_event (chat->view, _("Connected"));
3895 g_object_notify (G_OBJECT (chat), "tp-chat");
3896 g_object_notify (G_OBJECT (chat), "id");
3897 g_object_notify (G_OBJECT (chat), "account");
3899 /* This is a noop when tp-chat is set at object construction time and causes
3900 * the pending messages to be show when it's set on the object after it has
3902 show_pending_messages (chat);
3904 /* check if a password is needed */
3905 chat_password_needed_changed_cb (chat);
3909 empathy_chat_get_account (EmpathyChat *chat)
3911 EmpathyChatPriv *priv = GET_PRIV (chat);
3913 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3915 return priv->account;
3919 empathy_chat_get_id (EmpathyChat *chat)
3921 EmpathyChatPriv *priv = GET_PRIV (chat);
3923 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3929 empathy_chat_dup_name (EmpathyChat *chat)
3931 EmpathyChatPriv *priv = GET_PRIV (chat);
3934 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3938 if (!ret && priv->remote_contact) {
3939 ret = empathy_contact_get_alias (priv->remote_contact);
3946 ret = _("Conversation");
3948 if (priv->sms_channel)
3949 /* Translators: this string is a something like
3950 * "Escher Cat (SMS)" */
3951 return g_strdup_printf (_("%s (SMS)"), ret);
3953 return g_strdup (ret);
3957 empathy_chat_get_subject (EmpathyChat *chat)
3959 EmpathyChatPriv *priv = GET_PRIV (chat);
3961 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3963 return priv->subject;
3967 empathy_chat_get_remote_contact (EmpathyChat *chat)
3969 EmpathyChatPriv *priv = GET_PRIV (chat);
3971 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3973 return priv->remote_contact;
3977 empathy_chat_get_contact_menu (EmpathyChat *chat)
3979 EmpathyChatPriv *priv = GET_PRIV (chat);
3980 GtkWidget *menu = NULL;
3982 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
3984 if (priv->remote_contact) {
3985 menu = empathy_contact_menu_new (priv->remote_contact,
3986 EMPATHY_CONTACT_FEATURE_CALL |
3987 EMPATHY_CONTACT_FEATURE_LOG |
3988 EMPATHY_CONTACT_FEATURE_INFO |
3989 EMPATHY_CONTACT_FEATURE_BLOCK);
3996 empathy_chat_clear (EmpathyChat *chat)
3998 g_return_if_fail (EMPATHY_IS_CHAT (chat));
4000 empathy_chat_view_clear (chat->view);
4004 empathy_chat_scroll_down (EmpathyChat *chat)
4006 g_return_if_fail (EMPATHY_IS_CHAT (chat));
4008 empathy_chat_view_scroll_down (chat->view);
4012 empathy_chat_cut (EmpathyChat *chat)
4014 GtkTextBuffer *buffer;
4016 g_return_if_fail (EMPATHY_IS_CHAT (chat));
4018 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
4019 if (gtk_text_buffer_get_has_selection (buffer)) {
4020 GtkClipboard *clipboard;
4022 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4024 gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
4029 empathy_chat_copy (EmpathyChat *chat)
4031 GtkTextBuffer *buffer;
4033 g_return_if_fail (EMPATHY_IS_CHAT (chat));
4035 if (empathy_chat_view_get_has_selection (chat->view)) {
4036 empathy_chat_view_copy_clipboard (chat->view);
4040 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
4041 if (gtk_text_buffer_get_has_selection (buffer)) {
4042 GtkClipboard *clipboard;
4044 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4046 gtk_text_buffer_copy_clipboard (buffer, clipboard);
4051 EmpathyChatPriv *priv = GET_PRIV (chat);
4053 if (gtk_label_get_selection_bounds (GTK_LABEL (priv->label_topic),
4060 GtkClipboard *clipboard;
4062 topic = gtk_label_get_text (GTK_LABEL (priv->label_topic));
4063 start = g_utf8_offset_to_pointer (topic, start_offset);
4064 end = g_utf8_offset_to_pointer (topic, end_offset);
4065 selection = g_strndup (start, end - start);
4067 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4068 gtk_clipboard_set_text (clipboard, selection, -1);
4076 empathy_chat_paste (EmpathyChat *chat)
4078 GtkTextBuffer *buffer;
4079 GtkClipboard *clipboard;
4080 EmpathyChatPriv *priv;
4082 g_return_if_fail (EMPATHY_IS_CHAT (chat));
4084 priv = GET_PRIV (chat);
4086 if (gtk_widget_get_visible (priv->search_bar)) {
4087 empathy_search_bar_paste_clipboard (EMPATHY_SEARCH_BAR (priv->search_bar));
4091 if (priv->tp_chat == NULL ||
4092 !gtk_widget_is_sensitive (chat->input_text_view))
4095 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
4096 clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
4098 gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
4102 empathy_chat_find (EmpathyChat *chat)
4104 EmpathyChatPriv *priv;
4106 g_return_if_fail (EMPATHY_IS_CHAT (chat));
4108 priv = GET_PRIV (chat);
4110 empathy_search_bar_show (EMPATHY_SEARCH_BAR (priv->search_bar));
4114 empathy_chat_correct_word (EmpathyChat *chat,
4117 const gchar *new_word)
4119 GtkTextBuffer *buffer;
4121 g_return_if_fail (chat != NULL);
4122 g_return_if_fail (new_word != NULL);
4124 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
4126 gtk_text_buffer_delete (buffer, start, end);
4127 gtk_text_buffer_insert (buffer, start,
4133 empathy_chat_is_room (EmpathyChat *chat)
4135 EmpathyChatPriv *priv = GET_PRIV (chat);
4137 g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
4139 return (priv->handle_type == TP_HANDLE_TYPE_ROOM);
4143 empathy_chat_get_nb_unread_messages (EmpathyChat *self)
4145 EmpathyChatPriv *priv = GET_PRIV (self);
4147 g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
4149 return priv->unread_messages;
4152 /* called when the messages have been read by user */
4154 empathy_chat_messages_read (EmpathyChat *self)
4156 EmpathyChatPriv *priv = GET_PRIV (self);
4158 g_return_if_fail (EMPATHY_IS_CHAT (self));
4160 /* FIXME: See Bug#610994, See comments about it in EmpathyChatPriv
4161 * definition. If we are still retrieving the backlogs, do not ACK */
4162 if (priv->retrieving_backlogs)
4165 if (priv->tp_chat != NULL) {
4166 tp_text_channel_ack_all_pending_messages_async (
4167 TP_TEXT_CHANNEL (priv->tp_chat), NULL, NULL);
4170 if (priv->unread_messages_when_offline > 0) {
4171 /* We can't ack those as the connection has gone away so just consider
4173 priv->unread_messages -= priv->unread_messages_when_offline;
4174 g_object_notify (G_OBJECT (self), "nb-unread-messages");
4175 priv->unread_messages_when_offline = 0;
4179 /* Return TRUE if on of the contacts in this chat is composing */
4181 empathy_chat_is_composing (EmpathyChat *chat)
4183 return chat->priv->compositors != NULL;
4187 empathy_chat_is_sms_channel (EmpathyChat *self)
4189 EmpathyChatPriv *priv = GET_PRIV (self);
4191 g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
4193 return priv->sms_channel;
4197 empathy_chat_get_n_messages_sending (EmpathyChat *self)
4199 EmpathyChatPriv *priv;
4201 g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
4203 priv = GET_PRIV (self);
4205 if (priv->tp_chat == NULL) {
4210 g_object_get (priv->tp_chat,
4211 "n-messages-sending", &n_messages,
4219 empathy_chat_dup_text (EmpathyChat *self)
4221 GtkTextBuffer *buffer;
4222 GtkTextIter start, end;
4224 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->input_text_view));
4226 gtk_text_buffer_get_bounds (buffer, &start, &end);
4227 return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
4231 empathy_chat_set_text (EmpathyChat *self,
4234 GtkTextBuffer *buffer;
4236 buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->input_text_view));
4238 gtk_text_buffer_set_text (buffer, text, -1);