#include <telepathy-glib/account-manager.h>
#include <telepathy-glib/util.h>
+#ifdef ENABLE_TPL
+#include <telepathy-logger/log-manager.h>
+#else
#include <libempathy/empathy-log-manager.h>
+#endif /* ENABLE_TPL */
#include <libempathy/empathy-contact-list.h>
#include <libempathy/empathy-utils.h>
#include <libempathy/empathy-dispatcher.h>
#include "empathy-contact-list-store.h"
#include "empathy-contact-list-view.h"
#include "empathy-contact-menu.h"
+#include "empathy-search-bar.h"
#include "empathy-theme-manager.h"
#include "empathy-smiley-manager.h"
#include "empathy-ui-utils.h"
+#include "empathy-string-parser.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
#include <libempathy/empathy-debug.h>
EmpathyContact *remote_contact;
gboolean show_contacts;
+#ifdef ENABLE_TPL
+ TplLogManager *log_manager;
+#else
EmpathyLogManager *log_manager;
+#endif /* ENABLE_TPL */
TpAccountManager *account_manager;
GList *input_history;
GList *input_history_current;
GtkWidget *label_topic;
GtkWidget *contact_list_view;
GtkWidget *info_bar_vbox;
+ GtkWidget *search_bar;
guint unread_messages;
+ /* TRUE if the pending messages can be displayed. This is to avoid to show
+ * pending messages *before* messages from logs. (#603980) */
+ gboolean can_show_pending;
+
+ /* FIXME: retrieving_backlogs flag is a workaround for Bug#610994 and should
+ * be differently handled since it introduces another race condition, which
+ * is really hard to occur, but still possible.
+ *
+ * With the current workaround (which has the race above), we need to be
+ * sure to ACK any pending messages only when the retrieval of backlogs is
+ * finished, that's why using retrieving_backlogs flag.
+ * empathy_chat_messages_read () will check this variable and not ACK
+ * anything when TRUE. It will be set TRUE at chat_constructed () and set
+ * back to FALSE when the backlog has been retrieved and the pending
+ * messages actually showed to the user.
+ *
+ * Race condition introduced with this workaround:
+ * Scenario: a message is pending, the user is notified and selects the tab.
+ * the tab with a pending message is focused before the messages are properly
+ * shown (since the preparation of the window is slower AND async WRT the
+ * tab showing), which means the user won't see any new messages (rare but
+ * possible), if he/she will change tab focus before the messages are
+ * properly shown, the tab will be set as 'seen' and the user won't be
+ * notified again about the already notified pending messages when the
+ * messages in tab will be properly shown */
+ gboolean retrieving_backlogs;
} EmpathyChatPriv;
typedef struct {
}
}
+static void
+reconnected_connection_ready_cb (TpConnection *connection,
+ const GError *error,
+ gpointer user_data)
+{
+ EmpathyChat *chat = user_data;
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ if (error != NULL) {
+ DEBUG ("connection is not ready: %s", error->message);
+ goto out;
+ }
+
+ DEBUG ("Account reconnected, request a new Text channel");
+
+ switch (priv->handle_type) {
+ case TP_HANDLE_TYPE_CONTACT:
+ empathy_dispatcher_chat_with_contact_id (
+ connection, priv->id,
+ chat_connect_channel_reconnected,
+ chat);
+ break;
+ case TP_HANDLE_TYPE_ROOM:
+ empathy_dispatcher_join_muc (connection,
+ priv->id,
+ chat_connect_channel_reconnected,
+ chat);
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+out:
+ g_object_unref (chat);
+}
+
static void
chat_new_connection_cb (TpAccount *account,
guint old_status,
connection = tp_account_get_connection (account);
- if (!priv->tp_chat && account == priv->account &&
- priv->handle_type != TP_HANDLE_TYPE_NONE &&
- !EMP_STR_EMPTY (priv->id)) {
-
- DEBUG ("Account reconnected, request a new Text channel");
+ if (priv->tp_chat != NULL || account != priv->account ||
+ priv->handle_type == TP_HANDLE_TYPE_NONE ||
+ EMP_STR_EMPTY (priv->id))
+ return;
- switch (priv->handle_type) {
- case TP_HANDLE_TYPE_CONTACT:
- empathy_dispatcher_chat_with_contact_id (
- connection, priv->id,
- chat_connect_channel_reconnected,
- chat);
- break;
- case TP_HANDLE_TYPE_ROOM:
- empathy_dispatcher_join_muc (connection,
- priv->id,
- chat_connect_channel_reconnected,
- chat);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- }
+ g_object_ref (chat);
+ tp_connection_call_when_ready (connection, reconnected_connection_ready_cb,
+ chat);
}
static void
if (error != NULL) {
DEBUG ("Error: %s", error->message);
empathy_chat_view_append_event (chat->view,
- _("Failed to join chatroom"));
+ _("Failed to join chat room"));
}
}
chat_command_join (EmpathyChat *chat,
GStrv strv)
{
+ guint i = 0;
EmpathyChatPriv *priv = GET_PRIV (chat);
- TpConnection *connection;
- connection = empathy_tp_chat_get_connection (priv->tp_chat);
- empathy_dispatcher_join_muc (connection, strv[1],
- chat_command_join_cb,
- chat);
+ GStrv rooms = g_strsplit_set (strv[1], ", ", -1);
+
+ while (rooms[i] != NULL) {
+ /* ignore empty strings */
+ if (!EMP_STR_EMPTY (rooms[i])) {
+ TpConnection *connection;
+
+ connection = empathy_tp_chat_get_connection (priv->tp_chat);
+ empathy_dispatcher_join_muc (connection, rooms[i],
+ chat_command_join_cb,
+ chat);
+ }
+ i++;
+ }
+ g_strfreev (rooms);
}
static void
static ChatCommandItem commands[] = {
{"clear", 1, 1, chat_command_clear,
- N_("/clear, clear all messages from the current conversation")},
+ N_("/clear: clear all messages from the current conversation")},
{"topic", 2, 2, chat_command_topic,
- N_("/topic <topic>, set the topic of the current conversation")},
+ N_("/topic <topic>: set the topic of the current conversation")},
{"join", 2, 2, chat_command_join,
- N_("/join <chatroom id>, join a new chatroom")},
+ N_("/join <chat room ID>: join a new chat room")},
{"j", 2, 2, chat_command_join,
- N_("/j <chatroom id>, join a new chatroom")},
+ N_("/j <chat room ID>: join a new chat room")},
{"query", 2, 3, chat_command_query,
- N_("/query <contact id> [<message>], open a private chat")},
+ N_("/query <contact ID> [<message>]: open a private chat")},
{"msg", 3, 3, chat_command_msg,
- N_("/msg <contact id> <message>, open a private chat")},
+ N_("/msg <contact ID> <message>: open a private chat")},
{"nick", 2, 2, chat_command_nick,
- N_("/nick <nickname>, change your nickname on current server")},
+ N_("/nick <nickname>: change your nickname on the current server")},
{"me", 2, 2, chat_command_me,
- N_("/me <message>, send an ACTION message to the current conversation")},
+ N_("/me <message>: send an ACTION message to the current conversation")},
{"say", 2, 2, chat_command_say,
- N_("/say <message>, send <message> to the current conversation. "
+ N_("/say <message>: send <message> to the current conversation. "
"This is used to send a message starting with a '/'. For example: "
- "\"/say /join is used to join a new chatroom\"")},
+ "\"/say /join is used to join a new chat room\"")},
{"help", 1, 2, chat_command_help,
- N_("/help [<command>], show all supported commands. "
+ N_("/help [<command>]: show all supported commands. "
"If <command> is defined, show its usage.")},
};
if (!second_slash) {
empathy_chat_view_append_event (chat->view,
- _("Unknown command, see /help for the available"
+ _("Unknown command; see /help for the available"
" commands"));
return;
}
EmpathyChat *chat)
{
chat_message_received (chat, message);
- empathy_tp_chat_acknowledge_message (tp_chat, message);
}
static void
if (EMP_STR_EMPTY (priv->subject)) {
gtk_widget_hide (priv->hbox_topic);
} else {
- gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
+ gchar *markup_text;
+
+ markup_text = empathy_add_link_markup (priv->subject);
+ gtk_label_set_markup (GTK_LABEL (priv->label_topic), markup_text);
+ g_free (markup_text);
+
gtk_widget_show (priv->hbox_topic);
}
if (priv->block_events_timeout_id == 0) {
}
}
+static gboolean
+empathy_isspace_cb (gunichar c,
+ gpointer data)
+{
+ return g_unichar_isspace (c);
+}
+
static gboolean
chat_input_key_press_event_cb (GtkWidget *widget,
GdkEventKey *event,
gtk_adjustment_set_value (adj, val);
return TRUE;
}
+ if (event->keyval == GDK_Escape) {
+ empathy_search_bar_hide (EMPATHY_SEARCH_BAR (priv->search_bar));
+ }
if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
event->keyval == GDK_Tab) {
GtkTextBuffer *buffer;
/* Get the start of the nick to complete. */
gtk_text_buffer_get_iter_at_mark (buffer, &start, gtk_text_buffer_get_insert (buffer));
- gtk_text_iter_backward_word_start (&start);
+ if (gtk_text_iter_backward_find_char (&start, &empathy_isspace_cb, NULL, NULL)) {
+ gtk_text_iter_set_offset (&start, gtk_text_iter_get_offset (&start) + 1);
+ }
is_start_of_buffer = gtk_text_iter_is_start (&start);
list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
guint len;
const gchar *text;
gchar *complete_char = NULL;
+ GString *message = NULL;
+ GList *l;
gtk_text_buffer_delete (buffer, &start, ¤t);
text = empathy_contact_get_name (completed_list->data);
} else {
text = completed;
+
+ /* Print all hits to the scrollback view, so the
+ * user knows what possibilities he has.
+ * Fixes #599779
+ * */
+ message = g_string_new ("");
+ for (l = completed_list; l != NULL; l = l->next) {
+ g_string_append (message, empathy_contact_get_name (l->data));
+ g_string_append (message, " - ");
+ }
+ empathy_chat_view_append_event (chat->view, message->str);
+ g_string_free (message, TRUE);
}
gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
}
}
+
+#ifdef ENABLE_TPL
+static gboolean
+chat_log_filter (TplLogEntry *log,
+ gpointer user_data)
+#else
static gboolean
chat_log_filter (EmpathyMessage *message,
gpointer user_data)
+#endif /* ENABLE_TPL */
{
- EmpathyChat *chat = (EmpathyChat *) user_data;
+ EmpathyChat *chat = user_data;
+#ifdef ENABLE_TPL
+ EmpathyMessage *message;
+#endif /* ENABLE_TPL */
EmpathyChatPriv *priv = GET_PRIV (chat);
const GList *pending;
+#ifdef ENABLE_TPL
+ g_return_val_if_fail (TPL_IS_LOG_ENTRY (log), FALSE);
+#else
+ g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
+#endif /* ENABLE_TPL */
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
+
pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
+#ifdef ENABLE_TPL
+ message = empathy_message_from_tpl_log_entry (log);
+#endif /* ENABLE_TPL */
for (; pending; pending = g_list_next (pending)) {
if (empathy_message_equal (message, pending->data)) {
return FALSE;
}
}
-
+#ifdef ENABLE_TPL
+ g_object_unref (message);
+#endif
return TRUE;
}
+
+static void
+show_pending_messages (EmpathyChat *chat) {
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ const GList *messages, *l;
+
+ g_return_if_fail (EMPATHY_IS_CHAT (chat));
+
+ if (chat->view == NULL || priv->tp_chat == NULL)
+ return;
+
+ if (!priv->can_show_pending)
+ return;
+
+ messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
+
+ for (l = messages; l != NULL ; l = g_list_next (l)) {
+ EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
+ chat_message_received (chat, message);
+ }
+}
+
+
+#ifdef ENABLE_TPL
+static void
+got_filtered_messages_cb (GObject *manager,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ GList *l;
+ GList *messages;
+ EmpathyChat *chat = EMPATHY_CHAT (user_data);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ GError *error = NULL;
+
+ messages = tpl_log_manager_get_filtered_messages_async_finish (result, &error);
+
+ if (error != NULL) {
+ DEBUG ("%s. Aborting.", error->message);
+ empathy_chat_view_append_event (chat->view,
+ _("Failed to retrieve recent logs"));
+ g_error_free (error);
+ goto out;
+ }
+
+ for (l = messages; l; l = g_list_next (l)) {
+ EmpathyMessage *message;
+ g_assert (TPL_IS_LOG_ENTRY (l->data));
+
+ message = empathy_message_from_tpl_log_entry (l->data);
+ g_object_unref (l->data);
+
+ empathy_chat_view_append_message (chat->view, message);
+ g_object_unref (message);
+ }
+ g_list_free (messages);
+
+out:
+ /* in case of TPL error, skip backlog and show pending messages */
+ priv->can_show_pending = TRUE;
+ show_pending_messages (chat);
+
+ /* FIXME: See Bug#610994, we are forcing the ACK of the queue. See comments
+ * about it in EmpathyChatPriv definition */
+ priv->retrieving_backlogs = FALSE;
+ empathy_chat_messages_read (chat);
+
+ /* Turn back on scrolling */
+ empathy_chat_view_scroll (chat->view, TRUE);
+}
+#endif /* ENABLE_TPL */
+
+
static void
chat_add_logs (EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
gboolean is_chatroom;
+#ifndef ENABLE_TPL
GList *messages, *l;
+#endif /* ENABLE_TPL */
if (!priv->id) {
return;
/* Add messages from last conversation */
is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
+#ifndef ENABLE_TPL
messages = empathy_log_manager_get_filtered_messages (priv->log_manager,
priv->account,
priv->id,
/* Turn back on scrolling */
empathy_chat_view_scroll (chat->view, TRUE);
+#else
+ priv->retrieving_backlogs = TRUE;
+ tpl_log_manager_get_filtered_messages_async (priv->log_manager,
+ priv->account,
+ priv->id,
+ is_chatroom,
+ 5,
+ chat_log_filter,
+ chat,
+ got_filtered_messages_cb,
+ (gpointer) chat);
+#endif /* ENABLE_TPL */
}
static gint
}
static void
-chat_update_contacts_visibility (EmpathyChat *chat)
+chat_update_contacts_visibility (EmpathyChat *chat,
+ gboolean show)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- gboolean show;
GtkAllocation allocation;
- show = priv->remote_contact == NULL && priv->show_contacts;
-
if (!priv->scrolled_window_contacts) {
return;
}
+ if (priv->remote_contact != NULL) {
+ show = FALSE;
+ }
+
if (show && priv->contact_list_view == NULL) {
EmpathyContactListStore *store;
gint min_width;
priv->show_contacts = show;
- chat_update_contacts_visibility (chat);
+ chat_update_contacts_visibility (chat, show);
g_object_notify (G_OBJECT (chat), "show-contacts");
}
g_object_get (channel, "handle-type", &priv->handle_type, NULL);
}
- chat_update_contacts_visibility (chat);
+ chat_update_contacts_visibility (chat, priv->show_contacts);
g_object_notify (G_OBJECT (chat), "remote-contact");
g_object_notify (G_OBJECT (chat), "id");
empathy_chat_view_append_event (chat->view, _("Disconnected"));
gtk_widget_set_sensitive (chat->input_text_view, FALSE);
- empathy_chat_set_show_contacts (chat, FALSE);
-}
-
-static void
-show_pending_messages (EmpathyChat *chat) {
- EmpathyChatPriv *priv = GET_PRIV (chat);
- const GList *messages, *l;
-
- if (chat->view == NULL || priv->tp_chat == NULL)
- return;
- messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
+ chat_update_contacts_visibility (chat, FALSE);
+}
- for (l = messages; l != NULL ; l = g_list_next (l)) {
- EmpathyMessage *message = EMPATHY_MESSAGE (l->data);
- chat_message_received (chat, message);
- }
- empathy_tp_chat_acknowledge_messages (priv->tp_chat, messages);
+static gboolean
+chat_hpaned_pos_changed_cb (GtkWidget* hpaned, gpointer user_data)
+{
+ gint hpaned_pos;
+ hpaned_pos = gtk_paned_get_position (GTK_PANED(hpaned));
+ empathy_conf_set_int (empathy_conf_get (),
+ EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS,
+ hpaned_pos);
+ return TRUE;
}
static void
GList *list = NULL;
gchar *filename;
GtkTextBuffer *buffer;
+ gint paned_pos;
filename = empathy_file_lookup ("empathy-chat.ui",
"libempathy-gtk");
chat->input_text_view);
gtk_widget_show (chat->input_text_view);
+ /* Add the (invisible) search bar */
+ priv->search_bar = empathy_search_bar_new (chat->view);
+ gtk_box_pack_start (GTK_BOX(priv->vbox_left),
+ priv->search_bar,
+ FALSE, FALSE, 0);
+ gtk_box_reorder_child (GTK_BOX(priv->vbox_left), priv->search_bar, 1);
+
/* Initialy hide the topic, will be shown if not empty */
gtk_widget_hide (priv->hbox_topic);
+ g_signal_connect (priv->hpaned, "notify::position",
+ G_CALLBACK (chat_hpaned_pos_changed_cb),
+ NULL);
+
+ /* Load the paned position */
+ if (empathy_conf_get_int (empathy_conf_get (),
+ EMPATHY_PREFS_UI_CHAT_WINDOW_PANED_POS,
+ &paned_pos)
+ && paned_pos)
+ gtk_paned_set_position (GTK_PANED(priv->hpaned), paned_pos);
+
/* Set widget focus order */
- list = g_list_append (NULL, priv->scrolled_window_input);
+ list = g_list_append (NULL, priv->search_bar);
+ list = g_list_append (list, priv->scrolled_window_input);
gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
g_list_free (list);
chat_members_changed_cb, chat);
g_signal_handlers_disconnect_by_func (priv->tp_chat,
chat_remote_contact_changed_cb, chat);
- empathy_tp_chat_close (priv->tp_chat);
+ empathy_tp_chat_leave (priv->tp_chat);
g_object_unref (priv->tp_chat);
}
if (priv->account) {
if (priv->handle_type != TP_HANDLE_TYPE_ROOM)
chat_add_logs (chat);
+#ifndef ENABLE_TPL
+ /* When async API are involved, pending message are shown at the end of the
+ * callbacks' chain fired by chat_add_logs */
+ priv->can_show_pending = TRUE;
show_pending_messages (chat);
+#endif /* ENABLE_TPL */
}
static void
EMPATHY_TYPE_CHAT, EmpathyChatPriv);
chat->priv = priv;
+#ifndef ENABLE_TPL
priv->log_manager = empathy_log_manager_dup_singleton ();
+#else
+ priv->log_manager = tpl_log_manager_dup_singleton ();
+#endif /* ENABLE_TPL */
priv->contacts_width = -1;
priv->input_history = NULL;
priv->input_history_current = NULL;
gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
}
+void
+empathy_chat_find (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv;
+
+ g_return_if_fail (EMPATHY_IS_CHAT (chat));
+
+ priv = GET_PRIV (chat);
+
+ empathy_search_bar_show (EMPATHY_SEARCH_BAR (priv->search_bar));
+}
+
void
empathy_chat_correct_word (EmpathyChat *chat,
GtkTextIter *start,
{
EmpathyChatPriv *priv = GET_PRIV (self);
- g_return_val_if_fail (EMPATHY_IS_CHAT (self), FALSE);
+ g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
return priv->unread_messages;
}
g_return_if_fail (EMPATHY_IS_CHAT (self));
+ /* FIXME: See Bug#610994, See comments about it in EmpathyChatPriv
+ * definition. If we are still retrieving the backlogs, do not ACK */
+ if (priv->retrieving_backlogs)
+ return;
+
+ if (priv->tp_chat != NULL ) {
+ empathy_tp_chat_acknowledge_all_messages (priv->tp_chat);
+ }
priv->unread_messages = 0;
}