#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 *hbox_topic;
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,
EmpathyChatPriv *priv = GET_PRIV (chat);
TpConnection *connection;
- connection = tp_account_get_connection (account);
+ if (new_status != TP_CONNECTION_STATUS_CONNECTED)
+ return;
- if (!priv->tp_chat && account == priv->account &&
- priv->handle_type != TP_HANDLE_TYPE_NONE &&
- !EMP_STR_EMPTY (priv->id)) {
+ connection = tp_account_get_connection (account);
- 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
chat_command_msg_internal (chat, strv[1], strv[2]);
}
+static void
+chat_command_nick (EmpathyChat *chat,
+ GStrv strv)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ TpConnection *connection;
+ GHashTable *new_alias;
+ TpHandle handle;
+
+ connection = tp_account_get_connection (priv->account);
+ handle = tp_connection_get_self_handle (connection);
+ new_alias = g_hash_table_new (g_direct_hash, g_direct_equal);
+ g_hash_table_insert (new_alias, GUINT_TO_POINTER (handle), strv[1]);
+
+ tp_cli_connection_interface_aliasing_call_set_aliases (connection, -1,
+ new_alias, NULL, NULL, NULL, NULL);
+
+ g_hash_table_destroy (new_alias);
+}
+
static void
chat_command_me (EmpathyChat *chat,
GStrv strv)
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 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;
}
TP_CHANNEL_CHAT_STATE_ACTIVE,
chat);
+ priv->unread_messages++;
g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
}
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
const gchar *name = empathy_contact_get_name (contact);
gchar *str;
+ g_return_if_fail (TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED != reason);
+
if (priv->block_events_timeout_id != 0)
return;
g_free (str);
}
+static void
+chat_member_renamed_cb (EmpathyTpChat *tp_chat,
+ EmpathyContact *old_contact,
+ EmpathyContact *new_contact,
+ guint reason,
+ gchar *message,
+ EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ g_return_if_fail (TP_CHANNEL_GROUP_CHANGE_REASON_RENAMED == reason);
+
+ if (priv->block_events_timeout_id == 0) {
+ gchar *str;
+
+ str = g_strdup_printf (_("%s is now known as %s"),
+ empathy_contact_get_name (old_contact),
+ empathy_contact_get_name (new_contact));
+ empathy_chat_view_append_event (chat->view, str);
+ g_free (str);
+ }
+
+}
+
static gboolean
chat_reset_size_request (gpointer widget)
{
}
static void
-chat_update_contacts_visibility (EmpathyChat *chat)
+chat_update_contacts_visibility (EmpathyChat *chat,
+ gboolean show)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- gboolean show;
-
- show = priv->remote_contact == NULL && priv->show_contacts;
+ GtkAllocation allocation;
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;
* chat view is bigger the contact list will take some space on
* it but we make sure the chat view don't become smaller than
* 250. Relax the size request once the resize is done */
- min_width = MIN (priv->vbox_left->allocation.width, 250);
+ gtk_widget_get_allocation (priv->vbox_left, &allocation);
+ min_width = MIN (allocation.width, 250);
gtk_widget_set_size_request (priv->vbox_left, min_width, -1);
g_idle_add (chat_reset_size_request, priv->vbox_left);
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");
"hbox_topic", &priv->hbox_topic,
"label_topic", &priv->label_topic,
"scrolled_window_contacts", &priv->scrolled_window_contacts,
+ "info_bar_vbox", &priv->info_bar_vbox,
NULL);
g_free (filename);
/* Add message view. */
chat->view = empathy_theme_manager_create_view (empathy_theme_manager_get ());
+ /* If this is a GtkTextView, it's set as a drag destination for text/plain
+ and other types, even though it's non-editable and doesn't accept any
+ drags. This steals drag motion for anything inside the scrollbars,
+ making drag destinations on chat windows far less useful.
+ */
+ gtk_drag_dest_unset (GTK_WIDGET (chat->view));
g_signal_connect (chat->view, "focus_in_event",
G_CALLBACK (chat_text_view_focus_in_event_cb),
chat);
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);
child = gtk_bin_get_child (bin);
- if (child && GTK_WIDGET_VISIBLE (child))
+ if (child && gtk_widget_get_visible (child))
{
GtkRequisition child_requisition;
GtkAllocation child_allocation;
GtkWidget *child;
- widget->allocation = *allocation;
+ gtk_widget_set_allocation (widget, allocation);
child = gtk_bin_get_child (bin);
- if (child && GTK_WIDGET_VISIBLE (child))
+ if (child && gtk_widget_get_visible (child))
{
child_allocation.x = allocation->x + gtk_container_get_border_width (GTK_CONTAINER (widget));
child_allocation.y = allocation->y + gtk_container_get_border_width (GTK_CONTAINER (widget));
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) {
chat_constructed (GObject *object)
{
EmpathyChat *chat = EMPATHY_CHAT (object);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
- chat_add_logs (chat);
+ 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;
return priv->tp_chat;
}
+static void display_password_info_bar (EmpathyChat *self,
+ gboolean retry);
+
+static void
+provide_password_cb (GObject *tp_chat,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ EmpathyChat *self = EMPATHY_CHAT (user_data);
+ EmpathyChatPriv *priv = GET_PRIV (self);
+ GError *error = NULL;
+
+ if (!empathy_tp_chat_provide_password_finish (EMPATHY_TP_CHAT (tp_chat), res,
+ &error)) {
+ DEBUG ("error: %s", error->message);
+ /* FIXME: what should we do if that's another error? Close the channel?
+ * Display the raw D-Bus error to the user isn't very useful */
+ if (g_error_matches (error, TP_ERRORS, TP_ERROR_AUTHENTICATION_FAILED))
+ display_password_info_bar (self, TRUE);
+ g_error_free (error);
+ return;
+ }
+
+ /* Room joined */
+ gtk_widget_set_sensitive (priv->hpaned, TRUE);
+ gtk_widget_grab_focus (self->input_text_view);
+}
+
+static void
+password_infobar_response_cb (GtkWidget *info_bar,
+ gint response_id,
+ EmpathyChat *self)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+ GtkWidget *entry;
+ const gchar *password;
+
+ if (response_id != GTK_RESPONSE_OK)
+ goto out;
+
+ entry = g_object_get_data (G_OBJECT (info_bar), "password-entry");
+ g_assert (entry != NULL);
+
+ password = gtk_entry_get_text (GTK_ENTRY (entry));
+
+ empathy_tp_chat_provide_password_async (priv->tp_chat, password,
+ provide_password_cb, self);
+
+ out:
+ gtk_widget_destroy (info_bar);
+}
+
+static void
+password_entry_activate_cb (GtkWidget *entry,
+ GtkWidget *info_bar)
+{
+ gtk_info_bar_response (GTK_INFO_BAR (info_bar), GTK_RESPONSE_OK);
+}
+
+static void
+passwd_join_button_cb (GtkButton *button,
+ GtkWidget *info_bar)
+{
+ gtk_info_bar_response (GTK_INFO_BAR (info_bar), GTK_RESPONSE_OK);
+}
+
+static void
+display_password_info_bar (EmpathyChat *self,
+ gboolean retry)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+ GtkWidget *info_bar;
+ GtkWidget *content_area;
+ GtkWidget *hbox;
+ GtkWidget *image;
+ GtkWidget *label;
+ GtkWidget *entry;
+ GtkWidget *alig;
+ GtkWidget *button;
+ GtkMessageType type;
+ const gchar *msg, *button_label;
+
+ if (retry) {
+ /* Previous password was wrong */
+ type = GTK_MESSAGE_ERROR;
+ msg = _("Wrong password; please try again:");
+ button_label = _("Retry");
+ }
+ else {
+ /* First time we're trying to join */
+ type = GTK_MESSAGE_QUESTION;
+ msg = _("This room is protected by a password:");
+ button_label = _("Join");
+ }
+
+ info_bar = gtk_info_bar_new ();
+ gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), type);
+
+ content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (info_bar));
+
+ hbox = gtk_hbox_new (FALSE, 3);
+ gtk_container_add (GTK_CONTAINER (content_area), hbox);
+
+ /* Add image */
+ image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION,
+ GTK_ICON_SIZE_DIALOG);
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+
+ /* Add message */
+ label = gtk_label_new (msg);
+ gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+ /* Add password entry */
+ entry = gtk_entry_new ();
+ gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE);
+ gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+
+ g_signal_connect (entry, "activate",
+ G_CALLBACK (password_entry_activate_cb), info_bar);
+
+ /* Focus the password entry once it's realized */
+ g_signal_connect (entry, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
+
+ /* Add 'Join' button */
+ alig = gtk_alignment_new (0, 0.5, 0, 0);
+
+ button = gtk_button_new_with_label (button_label);
+ gtk_container_add (GTK_CONTAINER (alig), button);
+ gtk_box_pack_start (GTK_BOX (hbox), alig, FALSE, FALSE, 0);
+
+ g_signal_connect (button, "clicked", G_CALLBACK (passwd_join_button_cb),
+ info_bar);
+
+ g_object_set_data (G_OBJECT (info_bar), "password-entry", entry);
+
+ gtk_box_pack_start (GTK_BOX (priv->info_bar_vbox), info_bar,
+ FALSE, FALSE, 3);
+ gtk_widget_show_all (hbox);
+
+ g_signal_connect (info_bar, "response",
+ G_CALLBACK (password_infobar_response_cb), self);
+
+ gtk_widget_show_all (info_bar);
+}
+
+static void
+chat_password_needed_changed_cb (EmpathyChat *self)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+
+ if (empathy_tp_chat_password_needed (priv->tp_chat)) {
+ display_password_info_bar (self, FALSE);
+ gtk_widget_set_sensitive (priv->hpaned, FALSE);
+ }
+}
+
void
empathy_chat_set_tp_chat (EmpathyChat *chat,
EmpathyTpChat *tp_chat)
g_signal_connect (tp_chat, "members-changed",
G_CALLBACK (chat_members_changed_cb),
chat);
+ g_signal_connect (tp_chat, "member-renamed",
+ G_CALLBACK (chat_member_renamed_cb),
+ chat);
g_signal_connect_swapped (tp_chat, "notify::remote-contact",
G_CALLBACK (chat_remote_contact_changed_cb),
chat);
+ g_signal_connect_swapped (tp_chat, "notify::password-needed",
+ G_CALLBACK (chat_password_needed_changed_cb),
+ chat);
/* Get initial value of properties */
properties = empathy_tp_chat_get_properties (priv->tp_chat);
* the pending messages to be show when it's set on the object after it has
* been created */
show_pending_messages (chat);
+
+ /* check if a password is needed */
+ chat_password_needed_changed_cb (chat);
}
TpAccount *
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,
return (priv->handle_type == TP_HANDLE_TYPE_ROOM);
}
+guint
+empathy_chat_get_nb_unread_messages (EmpathyChat *self)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (self), 0);
+
+ return priv->unread_messages;
+}
+
+/* called when the messages have been read by user */
+void
+empathy_chat_messages_read (EmpathyChat *self)
+{
+ EmpathyChatPriv *priv = GET_PRIV (self);
+
+ 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;
+}