/*
* Copyright (C) 2002-2007 Imendio AB
* Copyright (C) 2007-2010 Collabora Ltd.
+ * Copyright (C) 2012 Red Hat, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* Xavier Claessens <xclaesse@gmail.com>
*/
-#include <config.h>
/* for GCompletion */
#define GLIB_DISABLE_DEPRECATION_WARNINGS 1
-#include <string.h>
-#include <stdlib.h>
+#include "config.h"
+#include "empathy-chat.h"
-#include <gdk/gdkkeysyms.h>
#include <glib/gi18n-lib.h>
-#include <gtk/gtk.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/util.h>
-#include <telepathy-logger/telepathy-logger.h>
-#include <libempathy/empathy-gsettings.h>
-#include <libempathy/empathy-keyring.h>
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-request-util.h>
-#include <libempathy/empathy-chatroom-manager.h>
-#include <libempathy/empathy-client-factory.h>
-
-#include "empathy-chat.h"
-#include "empathy-spell.h"
-#include "empathy-contact-dialogs.h"
+#include <tp-account-widgets/tpaw-keyring.h>
+#include <tp-account-widgets/tpaw-builder.h>
+#include <tp-account-widgets/tpaw-utils.h>
+#include <telepathy-glib/telepathy-glib-dbus.h>
+
+#include "empathy-client-factory.h"
+#include "empathy-gsettings.h"
+#include "empathy-individual-information-dialog.h"
#include "empathy-individual-store-channel.h"
#include "empathy-individual-view.h"
#include "empathy-input-text-view.h"
+#include "empathy-request-util.h"
#include "empathy-search-bar.h"
+#include "empathy-spell.h"
+#include "empathy-string-parser.h"
#include "empathy-theme-manager.h"
-#include "empathy-theme-adium.h"
-#include "empathy-smiley-manager.h"
#include "empathy-ui-utils.h"
-#include "empathy-string-parser.h"
-#include "extensions/extensions.h"
+#include "empathy-utils.h"
#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
#define IS_ENTER(v) (v == GDK_KEY_Return || v == GDK_KEY_ISO_Enter || v == GDK_KEY_KP_Enter)
#define COMPOSING_STOP_TIMEOUT 5
GSettings *gsettings_ui;
TplLogManager *log_manager;
+ TplLogWalker *log_walker;
+ /* Are we watching for scrolling movements? */
+ gboolean watch_scroll;
+ /* Maximum page size of the chat->view. */
+ guint max_page_size;
+ /* The offset from the lower edge of the chat->view before it
+ * expanded to fit in the newly fetched logs. This is to
+ * restore the chat->view to the page it was on before the
+ * latest batch of logs were inserted. */
+ guint scroll_offset;
+
TpAccountManager *account_manager;
GList *input_history;
GList *input_history_current;
guint unread_messages;
guint unread_messages_when_offline;
- /* 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
G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BOX);
+static gboolean chat_scrollable_connect (gpointer user_data);
static gboolean update_misspelled_words (gpointer data);
static void
if (priv->tp_chat != NULL || account != priv->account ||
priv->handle_type == TP_HANDLE_TYPE_NONE ||
- EMP_STR_EMPTY (priv->id))
+ TPAW_STR_EMPTY (priv->id))
return;
g_object_ref (chat);
DEBUG ("Failed to get channel: %s", error->message);
g_error_free (error);
- empathy_chat_view_append_event (data->chat->view,
+ empathy_theme_adium_append_event (data->chat->view,
_("Failed to open private chat"));
goto OUT;
}
- if (!EMP_STR_EMPTY (data->message) && TP_IS_TEXT_CHANNEL (channel)) {
+ if (!TPAW_STR_EMPTY (data->message) && TP_IS_TEXT_CHANNEL (channel)) {
TpTextChannel *text = (TpTextChannel *) channel;
TpMessage *msg;
EmpathyChatPriv * priv = GET_PRIV (chat);
TpConnection *connection;
- connection = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
+ connection = tp_channel_get_connection (TP_CHANNEL (priv->tp_chat));
return tp_proxy_has_interface_by_id (connection,
- EMP_IFACE_QUARK_CONNECTION_INTERFACE_RENAMING);
+ TP_IFACE_QUARK_CONNECTION_INTERFACE_RENAMING);
}
static gboolean
chat_command_clear (EmpathyChat *chat,
GStrv strv)
{
- empathy_chat_view_clear (chat->view);
+ empathy_theme_adium_clear (chat->view);
}
static void
EmpathyChatPriv *priv = GET_PRIV (chat);
if (!empathy_tp_chat_supports_subject (priv->tp_chat)) {
- empathy_chat_view_append_event (chat->view,
+ empathy_theme_adium_append_event (chat->view,
_("Topic not supported on this conversation"));
return;
}
if (!empathy_tp_chat_can_set_subject (priv->tp_chat)) {
- empathy_chat_view_append_event (chat->view,
+ empathy_theme_adium_append_event (chat->view,
_("You are not allowed to change the topic"));
return;
}
* https://bugs.freedesktop.org/show_bug.cgi?id=13422 */
while (rooms[i] != NULL) {
/* ignore empty strings */
- if (!EMP_STR_EMPTY (rooms[i])) {
+ if (!TPAW_STR_EMPTY (rooms[i])) {
empathy_chat_join_muc (chat, rooms[i]);
}
i++;
EmpathyChatPriv *priv = GET_PRIV (chat);
ChatCommandMsgData *data;
TpAccountChannelRequest *req;
- GHashTable *request;
- request = tp_asv_new (
- TP_PROP_CHANNEL_CHANNEL_TYPE, G_TYPE_STRING, TP_IFACE_CHANNEL_TYPE_TEXT,
- TP_PROP_CHANNEL_TARGET_HANDLE_TYPE, G_TYPE_UINT, TP_HANDLE_TYPE_CONTACT,
- TP_PROP_CHANNEL_TARGET_ID, G_TYPE_STRING, contact_id,
- NULL);
-
- req = tp_account_channel_request_new (priv->account, request,
+ req = tp_account_channel_request_new_text (priv->account,
empathy_get_current_action_time ());
+ tp_account_channel_request_set_target_id (req, TP_HANDLE_TYPE_CONTACT,
+ contact_id);
+
/* FIXME: We should probably search in members alias. But this
* is enough for IRC */
data = g_slice_new (ChatCommandMsgData);
data->message = g_strdup (message);
tp_account_channel_request_ensure_and_observe_channel_async (req,
- EMPATHY_CHAT_BUS_NAME, NULL, chat_command_msg_cb, data);
+ EMPATHY_CHAT_TP_BUS_NAME, NULL, chat_command_msg_cb, data);
g_object_unref (req);
- g_hash_table_unref (request);
}
static void
}
static void
-callback_for_request_rename (TpProxy *proxy,
+callback_for_request_rename (TpConnection *conn,
const GError *error,
gpointer user_data,
GObject *weak_object)
GStrv strv)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- TpProxy *proxy;
+ TpConnection *conn;
- proxy = TP_PROXY (tp_account_get_connection (priv->account));
+ conn = tp_account_get_connection (priv->account);
- emp_cli_connection_interface_renaming_call_request_rename (proxy, -1,
+ tp_cli_connection_interface_renaming_call_request_rename (conn, -1,
strv[1], callback_for_request_rename, NULL, NULL, NULL);
}
{
EmpathyChat *chat = user_data;
EmpathyContact *contact;
- GtkWidget *window;
+ FolksIndividual *individual;
contact = empathy_client_factory_dup_contact_by_id_finish (
EMPATHY_CLIENT_FACTORY (source), result, NULL);
if (contact == NULL) {
- empathy_chat_view_append_event (chat->view, _("Invalid contact ID"));
+ empathy_theme_adium_append_event (chat->view, _("Invalid contact ID"));
goto out;
}
- window = gtk_widget_get_toplevel (GTK_WIDGET (chat));
- g_return_if_fail (window != NULL);
- g_return_if_fail (gtk_widget_is_toplevel (window));
- empathy_contact_information_dialog_show (contact,
- GTK_WINDOW (window));
+ individual = empathy_ensure_individual_from_tp_contact (
+ empathy_contact_get_tp_contact (contact));
+ empathy_display_individual_info (individual);
+ g_object_unref (individual);
g_object_unref (contact);
out:
TpConnection *conn;
EmpathyClientFactory *factory;
- conn = tp_channel_borrow_connection ((TpChannel *) priv->tp_chat);
+ conn = tp_channel_get_connection ((TpChannel *) priv->tp_chat);
factory = empathy_client_factory_dup ();
/* Element 0 of 'strv' is "whois"; element 1 is the contact ID
}
str = g_strdup_printf (_("Usage: %s"), _(item->help));
- empathy_chat_view_append_event (chat->view, str);
+ empathy_theme_adium_append_event (chat->view, str);
g_free (str);
}
if (commands[i].help == NULL) {
continue;
}
- empathy_chat_view_append_event (chat->view,
+ empathy_theme_adium_append_event (chat->view,
_(commands[i].help));
}
return;
}
}
- empathy_chat_view_append_event (chat->view,
+ empathy_theme_adium_append_event (chat->view,
_("Unknown command"));
}
/* Append last part if not empty */
item = g_strstrip (g_strdup (text));
- if (!EMP_STR_EMPTY (item)) {
+ if (!TPAW_STR_EMPTY (item)) {
g_ptr_array_add (array, item);
DEBUG ("\tITEM: \"%s\"", item);
} else {
TpMessage *message;
guint i;
- if (EMP_STR_EMPTY (msg)) {
+ if (TPAW_STR_EMPTY (msg)) {
return;
}
}
if (!second_slash) {
- empathy_chat_view_append_event (chat->view,
+ empathy_theme_adium_append_event (chat->view,
_("Unknown command; see /help for the available"
" commands"));
return;
{
EmpathyChatPriv *priv = GET_PRIV (chat);
const gchar *msg;
- TpChannelTextMessageFlags flags;
g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
return FALSE;
}
- flags = empathy_message_get_flags (message);
- if (flags & TP_CHANNEL_TEXT_MESSAGE_FLAG_SCROLLBACK) {
+ if (empathy_message_is_backlog (message)) {
/* FIXME: Ideally we shouldn't highlight scrollback messages only if they
* have already been received by the user before (and so are in the logs) */
return FALSE;
empathy_message_get_supersedes (message),
empathy_message_get_body (message));
- empathy_chat_view_edit_message (chat->view, message);
+ empathy_theme_adium_edit_message (chat->view, message);
} else {
gboolean should_highlight = chat_should_highlight (chat, message);
empathy_contact_get_alias (sender),
empathy_contact_get_handle (sender));
- empathy_chat_view_append_message (chat->view, message, should_highlight);
+ empathy_theme_adium_append_message (chat->view, message, should_highlight);
if (empathy_message_is_incoming (message)) {
priv->unread_messages++;
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- empathy_chat_view_message_acknowledged (chat->view,
+ empathy_theme_adium_message_acknowledged (chat->view,
message);
if (!empathy_message_is_edit (message)) {
const gchar *message_body)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- TpConnection *conn = tp_channel_borrow_connection (TP_CHANNEL (priv->tp_chat));
+ TpConnection *conn = tp_channel_get_connection (TP_CHANNEL (priv->tp_chat));
const gchar *uri = tp_connection_get_balance_uri (conn);
const gchar *error = _("insufficient balance to send message");
gchar *str, *str_markup = NULL;
}
if (str_markup != NULL)
- empathy_chat_view_append_event_markup (chat->view, str_markup, str);
+ empathy_theme_adium_append_event_markup (chat->view, str_markup, str);
else
- empathy_chat_view_append_event (chat->view, str);
+ empathy_theme_adium_append_event (chat->view, str);
g_free (str);
g_free (str_markup);
str = g_strdup_printf (_("Error sending message: %s"), error);
}
- empathy_chat_view_append_event (chat->view, str);
+ empathy_theme_adium_append_event (chat->view, str);
g_free (str);
}
priv->subject = g_strdup (empathy_tp_chat_get_subject (priv->tp_chat));
g_object_notify (G_OBJECT (chat), "subject");
- if (EMP_STR_EMPTY (priv->subject)) {
+ if (TPAW_STR_EMPTY (priv->subject)) {
gtk_widget_hide (priv->hbox_topic);
} else {
gchar *markup_topic;
gchar *markup_text;
- markup_topic = empathy_add_link_markup (priv->subject);
+ markup_topic = tpaw_add_link_markup (priv->subject);
markup_text = g_strdup_printf ("<span weight=\"bold\">%s</span> %s",
_("Topic:"), markup_topic);
if (priv->block_events_timeout_id == 0) {
gchar *str = NULL;
- if (!EMP_STR_EMPTY (priv->subject)) {
+ if (!TPAW_STR_EMPTY (priv->subject)) {
const gchar *actor = empathy_tp_chat_get_subject_actor (priv->tp_chat);
if (tp_str_empty (actor)) {
}
if (str != NULL) {
- empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
+ empathy_theme_adium_append_event (EMPATHY_CHAT (chat)->view, str);
g_free (str);
}
}
g_string_append (message, empathy_contact_get_alias (l->data));
g_string_append (message, " - ");
}
- empathy_chat_view_append_event (chat->view, message->str);
+ empathy_theme_adium_append_event (chat->view, message->str);
g_string_free (message, TRUE);
}
GParamSpec *pspec,
EmpathyChat *chat)
{
- empathy_chat_view_focus_toggled (chat->view, gtk_widget_has_focus (widget));
+ empathy_theme_adium_focus_toggled (chat->view, gtk_widget_has_focus (widget));
+}
+
+void
+empathy_chat_insert_smiley (GtkTextBuffer *buffer,
+ EmpathySmiley *smiley)
+{
+ gtk_text_buffer_insert_at_cursor (buffer, smiley->str, -1);
}
static void
{
EmpathyChat *chat = EMPATHY_CHAT (user_data);
GtkTextBuffer *buffer;
- GtkTextIter iter;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
- gtk_text_buffer_get_end_iter (buffer, &iter);
- gtk_text_buffer_insert (buffer, &iter, smiley->str, -1);
-
- gtk_text_buffer_get_end_iter (buffer, &iter);
- gtk_text_buffer_insert (buffer, &iter, " ", -1);
+ empathy_chat_insert_smiley (buffer, smiley);
}
typedef struct {
/* Add the Send menu item. */
gtk_text_buffer_get_bounds (buffer, &start, &end);
str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
- if (!EMP_STR_EMPTY (str)) {
+ if (!TPAW_STR_EMPTY (str)) {
item = gtk_menu_item_new_with_mnemonic (_("_Send"));
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (chat_text_send_cb), chat);
str = gtk_text_buffer_get_text (buffer,
&start, &end, FALSE);
}
- if (!EMP_STR_EMPTY (str)) {
+ if (!TPAW_STR_EMPTY (str)) {
chat_spell = chat_spell_new (chat, str, start, end);
g_object_set_data_full (G_OBJECT (menu),
"chat-spell", chat_spell,
chat_log_filter (TplEvent *event,
gpointer user_data)
{
- TpWeakRef *wr = user_data;
- EmpathyChat *chat = tp_weak_ref_dup_object (wr);
+ EmpathyChat *chat = EMPATHY_CHAT (user_data);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
EmpathyMessage *message;
- EmpathyChatPriv *priv;
const GList *pending;
bool retval = FALSE;
- if (chat == NULL)
- return FALSE;
-
g_return_val_if_fail (TPL_IS_EVENT (event), FALSE);
g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
- priv = GET_PRIV (chat);
-
pending = empathy_tp_chat_get_pending_messages (priv->tp_chat);
message = empathy_message_from_tpl_log_event (event);
out:
g_object_unref (message);
- g_object_unref (chat);
return retval;
}
-
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;
+ g_return_if_fail (chat->view != NULL);
+ g_return_if_fail (priv->tp_chat != NULL);
messages = empathy_tp_chat_get_pending_messages (priv->tp_chat);
}
}
+static gboolean
+chat_scrollable_set_value (gpointer user_data)
+{
+ EmpathyChat *chat = EMPATHY_CHAT (user_data);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ GtkAdjustment *adjustment;
+ guint upper;
+
+ adjustment = gtk_scrollable_get_vadjustment (
+ GTK_SCROLLABLE (chat->view));
+
+ /* Set the chat->view's adjustment back to the value it had
+ * before it grew as a result of new logs being inserted.
+ */
+ upper = (guint) gtk_adjustment_get_upper (adjustment);
+ gtk_adjustment_set_value (adjustment, upper - priv->scroll_offset);
+
+ return G_SOURCE_REMOVE;
+}
static void
-got_filtered_messages_cb (GObject *manager,
+got_filtered_messages_cb (GObject *walker,
GAsyncResult *result,
gpointer user_data)
{
GList *l;
GList *messages;
- TpWeakRef *wr = user_data;
- EmpathyChat *chat = tp_weak_ref_dup_object (wr);
- EmpathyChatPriv *priv;
+ EmpathyChat *chat = EMPATHY_CHAT (user_data);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
GError *error = NULL;
- if (chat == NULL) {
- tp_weak_ref_destroy (wr);
- return;
- }
-
- priv = GET_PRIV (chat);
-
- if (!tpl_log_manager_get_filtered_events_finish (TPL_LOG_MANAGER (manager),
+ if (!tpl_log_walker_get_events_finish (TPL_LOG_WALKER (walker),
result, &messages, &error)) {
DEBUG ("%s. Aborting.", error->message);
- empathy_chat_view_append_event (chat->view,
+ empathy_theme_adium_append_event (chat->view,
_("Failed to retrieve recent logs"));
g_error_free (error);
goto out;
}
- for (l = messages; l; l = g_list_next (l)) {
+ for (l = g_list_last (messages); l; l = g_list_previous (l)) {
EmpathyMessage *message;
g_assert (TPL_IS_EVENT (l->data));
"sender", empathy_message_get_sender (message),
NULL);
- empathy_chat_view_append_message (chat->view, syn_msg,
+ empathy_theme_adium_prepend_message (chat->view, syn_msg,
chat_should_highlight (chat, syn_msg));
- empathy_chat_view_edit_message (chat->view, message);
+ empathy_theme_adium_edit_message (chat->view, message);
g_object_unref (syn_msg);
} else {
/* append the latest message */
- empathy_chat_view_append_message (chat->view, message,
+ empathy_theme_adium_prepend_message (chat->view, message,
chat_should_highlight (chat, 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);
+ empathy_theme_adium_scroll (chat->view, TRUE);
+
+ /* We start watching the scrolling movements only after the first
+ * batch of logs have been fetched. Otherwise, if the
+ * chat->view's page size is too small the scrollbar might hit
+ * the upper edge and trigger another batch of logs to be
+ * fetched.
+ */
+ if (G_UNLIKELY (!priv->watch_scroll &&
+ !tpl_log_walker_is_end (priv->log_walker))) {
+ priv->watch_scroll = TRUE;
+ g_idle_add_full (G_PRIORITY_LOW, chat_scrollable_connect,
+ g_object_ref (chat), g_object_unref);
+ }
+ else {
+ GtkAdjustment *adjustment;
+ guint upper;
+ guint value;
+
+ /* The chat->view's adjustment won't change unless we
+ * return to the main loop. Save the current offset
+ * from the lower edge (or the upper value of the
+ * adjustment) so that we can restore it later once the
+ * adjustment grows.
+ */
+ adjustment = gtk_scrollable_get_vadjustment (
+ GTK_SCROLLABLE (chat->view));
+ upper = (guint) gtk_adjustment_get_upper (adjustment);
+ value = (guint) gtk_adjustment_get_value (adjustment);
+ priv->scroll_offset = upper - value;
+
+ g_idle_add_full (G_PRIORITY_LOW, chat_scrollable_set_value,
+ g_object_ref (chat), g_object_unref);
+ }
g_object_unref (chat);
- tp_weak_ref_destroy (wr);
}
-static void
+static gboolean
chat_add_logs (EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- TplEntity *target;
- TpWeakRef *wr;
if (!priv->id) {
- return;
+ return G_SOURCE_REMOVE;
}
/* Turn off scrolling temporarily */
- empathy_chat_view_scroll (chat->view, FALSE);
+ empathy_theme_adium_scroll (chat->view, FALSE);
- /* Add messages from last conversation */
- if (priv->handle_type == TP_HANDLE_TYPE_ROOM)
- target = tpl_entity_new_from_room_id (priv->id);
- else
- target = tpl_entity_new (priv->id, TPL_ENTITY_CONTACT, NULL, NULL);
+ tpl_log_walker_get_events_async (priv->log_walker, 5,
+ got_filtered_messages_cb, g_object_ref (chat));
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+chat_schedule_logs (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ if (priv->retrieving_backlogs)
+ return;
priv->retrieving_backlogs = TRUE;
- wr = tp_weak_ref_new (chat, NULL, NULL);
- tpl_log_manager_get_filtered_events_async (priv->log_manager,
- priv->account,
- target,
- TPL_EVENT_MASK_TEXT,
- 5,
- chat_log_filter,
- wr,
- got_filtered_messages_cb,
- wr);
+ g_timeout_add_full (G_PRIORITY_LOW, 500, /* ms */
+ (GSourceFunc) chat_add_logs, g_object_ref (chat), g_object_unref);
+}
- g_object_unref (target);
+static void
+chat_view_adjustment_changed_cb (GtkAdjustment *adjustment,
+ gpointer user_data)
+{
+ EmpathyChat *chat = EMPATHY_CHAT (user_data);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ guint page_size;
+
+ if (tpl_log_walker_is_end (priv->log_walker)) {
+ g_signal_handlers_disconnect_by_func (adjustment,
+ chat_view_adjustment_changed_cb, user_data);
+ return;
+ }
+
+ page_size = (guint) gtk_adjustment_get_page_size (adjustment);
+ if (page_size <= priv->max_page_size)
+ return;
+
+ /* We need to fetch more logs if the page size of the view
+ * increases, so that there is no empty space at the top.
+ */
+ if (G_LIKELY (priv->max_page_size != 0))
+ chat_schedule_logs (chat);
+
+ priv->max_page_size = page_size;
+}
+
+static void
+chat_view_adjustment_value_changed_cb (GtkAdjustment *adjustment,
+ gpointer user_data)
+{
+ EmpathyChat *chat = EMPATHY_CHAT (user_data);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ guint lower;
+ guint value;
+
+ if (tpl_log_walker_is_end (priv->log_walker)) {
+ g_signal_handlers_disconnect_by_func (adjustment,
+ chat_view_adjustment_value_changed_cb, user_data);
+ return;
+ }
+
+ lower = (guint) gtk_adjustment_get_lower (adjustment);
+ value = (guint) gtk_adjustment_get_value (adjustment);
+ if (value != lower)
+ return;
+
+ /* Request for more logs to be fetched if the user hit the
+ * upper edge of the chat->view.
+ */
+ chat_schedule_logs (chat);
+}
+
+static gboolean
+chat_scrollable_connect (gpointer user_data)
+{
+ EmpathyChat *chat = EMPATHY_CHAT (user_data);
+ GtkAdjustment *adjustment;
+
+ adjustment = gtk_scrollable_get_vadjustment (
+ GTK_SCROLLABLE (chat->view));
+
+ g_signal_connect (adjustment, "changed",
+ G_CALLBACK (chat_view_adjustment_changed_cb), chat);
+ g_signal_connect (adjustment, "value-changed",
+ G_CALLBACK (chat_view_adjustment_value_changed_cb), chat);
+
+ return G_SOURCE_REMOVE;
}
static gint
g_string_append_printf (s, _("%s has left the room"), name);
}
- if (!EMP_STR_EMPTY (message)) {
+ if (!TPAW_STR_EMPTY (message)) {
/* Note to translators: this string is appended to
* notifications like "foo has left the room", with the message
* given by the user living the room. If this poses a problem,
str = build_part_message (reason, name, actor, message);
}
- empathy_chat_view_append_event (chat->view, str);
+ empathy_theme_adium_append_event (chat->view, str);
g_free (str);
}
str = g_strdup_printf (_("%s is now known as %s"),
empathy_contact_get_alias (old_contact),
empathy_contact_get_alias (new_contact));
- empathy_chat_view_append_event (chat->view, str);
+ empathy_theme_adium_append_event (chat->view, str);
g_free (str);
}
priv->tp_chat = NULL;
g_object_notify (G_OBJECT (chat), "tp-chat");
- empathy_chat_view_append_event (chat->view, _("Disconnected"));
+ empathy_theme_adium_append_event (chat->view, _("Disconnected"));
gtk_widget_set_sensitive (chat->input_text_view, FALSE);
chat_update_contacts_visibility (chat, FALSE);
filename = empathy_file_lookup ("empathy-chat.ui",
"libempathy-gtk");
- gui = empathy_builder_get_file (filename,
+ gui = tpaw_builder_get_file (filename,
"chat_widget", &priv->widget,
"hpaned", &priv->hpaned,
"vbox_left", &priv->vbox_left,
"info_bar_vbox", &priv->info_bar_vbox,
NULL);
- empathy_builder_connect (gui, chat,
+ tpaw_builder_connect (gui, chat,
"expander_topic", "notify::expanded", chat_topic_expander_activate_cb,
"label_topic", "size-allocate", chat_topic_label_size_allocate_cb,
NULL);
g_object_unref (priv->account_manager);
g_object_unref (priv->log_manager);
+ g_object_unref (priv->log_walker);
if (priv->tp_chat) {
g_signal_handlers_disconnect_by_func (priv->tp_chat,
{
EmpathyChat *chat = EMPATHY_CHAT (object);
EmpathyChatPriv *priv = GET_PRIV (chat);
+ TplEntity *target;
+
+ if (priv->tp_chat != NULL) {
+ TpChannel *channel = TP_CHANNEL (priv->tp_chat);
+ TpConnection *conn = tp_channel_get_connection (channel);
+ gboolean supports_avatars =
+ tp_proxy_has_interface_by_id (conn,
+ TP_IFACE_QUARK_CONNECTION_INTERFACE_AVATARS);
+
+ empathy_theme_adium_set_show_avatars (chat->view,
+ supports_avatars);
+ }
+
+ /* Add messages from last conversations. Backlog messages are always
+ * prepended and pending messages are appended, so we can do both
+ * independently. Hacks like we previously had for bug #603980 are no
+ * longer needed. Pending messages are handled within
+ * empathy_chat_set_tp_chat() so we don't have to care about them here.
+ */
+ if (priv->handle_type == TP_HANDLE_TYPE_ROOM)
+ target = tpl_entity_new_from_room_id (priv->id);
+ else
+ target = tpl_entity_new (priv->id, TPL_ENTITY_CONTACT, NULL, NULL);
+
+ priv->log_walker = tpl_log_manager_walk_filtered_events (priv->log_manager, priv->account, target,
+ TPL_EVENT_MASK_TEXT, chat_log_filter, chat);
+ g_object_unref (target);
if (priv->handle_type != TP_HANDLE_TYPE_ROOM) {
- /* First display logs from the logger and then display pending messages */
chat_add_logs (chat);
}
- else {
- /* Just display pending messages for rooms */
- priv->can_show_pending = TRUE;
- show_pending_messages (chat);
- }
}
static void
return;
}
- accounts = tp_account_manager_get_valid_accounts (account_manager);
+ accounts = tp_account_manager_dup_valid_accounts (account_manager);
for (l = accounts; l != NULL; l = l->next) {
TpAccount *account = l->data;
chat, 0);
}
- g_list_free (accounts);
+ g_list_free_full (accounts, g_object_unref);
}
static void
priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_alias);
g_completion_set_compare (priv->completion, chat_contacts_completion_func);
+ /* Create UI early so by the time empathy_chat_set_tp_chat() is called
+ * (construct property) the view will already exists to receive pending
+ * messages. */
chat_create_ui (chat);
}
if (response_id == GTK_RESPONSE_OK) {
DEBUG ("Saving room password");
- empathy_keyring_set_room_password_async (priv->account,
+ tpaw_keyring_set_room_password_async (priv->account,
empathy_tp_chat_get_id (priv->tp_chat),
data->password,
NULL, NULL);
return;
}
- if (empathy_keyring_is_available ()) {
- /* ask whether they want to save the password */
- chat_prompt_to_save_password (self, data);
- } else {
- /* Get rid of the password info bar finally */
- gtk_widget_destroy (data->info_bar);
- g_slice_free (PasswordData, data);
- }
+ /* ask whether they want to save the password */
+ chat_prompt_to_save_password (self, data);
/* Room joined */
gtk_widget_set_sensitive (priv->hpaned, TRUE);
str = gtk_entry_get_text (GTK_ENTRY (entry));
gtk_entry_set_icon_sensitive (GTK_ENTRY (entry),
- GTK_ENTRY_ICON_SECONDARY, !EMP_STR_EMPTY (str));
+ GTK_ENTRY_ICON_SECONDARY, !TPAW_STR_EMPTY (str));
}
static void
const gchar *password;
GError *error = NULL;
- password = empathy_keyring_get_room_password_finish (priv->account,
+ password = tpaw_keyring_get_room_password_finish (priv->account,
result, &error);
if (error != NULL) {
EmpathyChatPriv *priv = GET_PRIV (self);
if (tp_channel_password_needed (TP_CHANNEL (priv->tp_chat))) {
- empathy_keyring_get_room_password_async (priv->account,
+ tpaw_keyring_get_room_password_async (priv->account,
empathy_tp_chat_get_id (priv->tp_chat),
chat_room_got_password_cb, self);
}
if (chat->input_text_view) {
gtk_widget_set_sensitive (chat->input_text_view, TRUE);
if (priv->block_events_timeout_id == 0) {
- empathy_chat_view_append_event (chat->view, _("Connected"));
+ empathy_theme_adium_append_event (chat->view, _("Connected"));
}
}
g_object_notify (G_OBJECT (chat), "id");
g_object_notify (G_OBJECT (chat), "account");
- /* This is a noop when tp-chat is set at object construction time and causes
- * 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 */
if (individual == NULL)
return NULL;
- menu = empathy_individual_menu_new (individual,
+ menu = empathy_individual_menu_new (individual, NULL,
EMPATHY_INDIVIDUAL_FEATURE_CALL |
EMPATHY_INDIVIDUAL_FEATURE_LOG |
EMPATHY_INDIVIDUAL_FEATURE_INFO |
{
g_return_if_fail (EMPATHY_IS_CHAT (chat));
- empathy_chat_view_clear (chat->view);
+ empathy_theme_adium_clear (chat->view);
}
void
{
g_return_if_fail (EMPATHY_IS_CHAT (chat));
- empathy_chat_view_scroll_down (chat->view);
+ empathy_theme_adium_scroll_down (chat->view);
}
void
}
}
-void
-empathy_chat_copy (EmpathyChat *chat)
+static gboolean
+copy_from_chat_view (EmpathyChat *chat)
+{
+ if (!empathy_theme_adium_get_has_selection (chat->view))
+ return FALSE;
+
+ empathy_theme_adium_copy_clipboard (chat->view);
+ return TRUE;
+}
+
+static gboolean
+copy_from_input (EmpathyChat *chat)
{
GtkTextBuffer *buffer;
+ GtkClipboard *clipboard;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
+ if (!gtk_text_buffer_get_has_selection (buffer))
+ return FALSE;
+
+ clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ gtk_text_buffer_copy_clipboard (buffer, clipboard);
+ return TRUE;
+}
+
+static gboolean
+copy_from_topic (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ gint start_offset;
+ gint end_offset;
+ gchar *start;
+ gchar *end;
+ gchar *selection;
+ const gchar *topic;
+ GtkClipboard *clipboard;
+
+ if (!gtk_label_get_selection_bounds (GTK_LABEL (priv->label_topic),
+ &start_offset,
+ &end_offset))
+ return FALSE;
+ topic = gtk_label_get_text (GTK_LABEL (priv->label_topic));
+ start = g_utf8_offset_to_pointer (topic, start_offset);
+ end = g_utf8_offset_to_pointer (topic, end_offset);
+ selection = g_strndup (start, end - start);
+
+ clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ gtk_clipboard_set_text (clipboard, selection, -1);
+
+ g_free (selection);
+ return TRUE;
+}
+
+void
+empathy_chat_copy (EmpathyChat *chat)
+{
g_return_if_fail (EMPATHY_IS_CHAT (chat));
- if (empathy_chat_view_get_has_selection (chat->view)) {
- empathy_chat_view_copy_clipboard (chat->view);
+ if (copy_from_chat_view (chat))
return;
- }
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
- if (gtk_text_buffer_get_has_selection (buffer)) {
- GtkClipboard *clipboard;
-
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+ if (copy_from_input (chat))
+ return;
- gtk_text_buffer_copy_clipboard (buffer, clipboard);
- }
- else {
- gint start_offset;
- gint end_offset;
- EmpathyChatPriv *priv = GET_PRIV (chat);
-
- if (gtk_label_get_selection_bounds (GTK_LABEL (priv->label_topic),
- &start_offset,
- &end_offset)) {
- gchar *start;
- gchar *end;
- gchar *selection;
- const gchar *topic;
- GtkClipboard *clipboard;
-
- topic = gtk_label_get_text (GTK_LABEL (priv->label_topic));
- start = g_utf8_offset_to_pointer (topic, start_offset);
- end = g_utf8_offset_to_pointer (topic, end_offset);
- selection = g_strndup (start, end - start);
-
- clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
- gtk_clipboard_set_text (clipboard, selection, -1);
-
- g_free (selection);
- }
- }
+ copy_from_topic (chat);
}
void