* Xavier Claessens <xclaesse@gmail.com>
*/
-#include "config.h"
+#include <config.h>
#include <string.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <libmissioncontrol/mission-control.h>
-
#include <telepathy-glib/util.h>
-#include <libempathy/empathy-contact-manager.h>
#include <libempathy/empathy-log-manager.h>
-#include <libempathy/empathy-debug.h>
+#include <libempathy/empathy-contact-list.h>
#include <libempathy/empathy-utils.h>
#include "empathy-chat.h"
-#include "empathy-geometry.h"
#include "empathy-conf.h"
#include "empathy-spell.h"
#include "empathy-spell-dialog.h"
+#include "empathy-contact-list-store.h"
+#include "empathy-contact-list-view.h"
+#include "empathy-contact-menu.h"
#include "empathy-ui-utils.h"
-#include "empathy-gtk-marshal.h"
-#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CHAT, EmpathyChatPriv))
+#define DEBUG_FLAG EMPATHY_DEBUG_CHAT
+#include <libempathy/empathy-debug.h>
-#define DEBUG_DOMAIN "Chat"
+#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CHAT, EmpathyChatPriv))
#define CHAT_DIR_CREATE_MODE (S_IRUSR | S_IWUSR | S_IXUSR)
#define CHAT_FILE_CREATE_MODE (S_IRUSR | S_IWUSR)
-
#define IS_ENTER(v) (v == GDK_Return || v == GDK_ISO_Enter || v == GDK_KP_Enter)
-
#define MAX_INPUT_HEIGHT 150
-
#define COMPOSING_STOP_TIMEOUT 5
struct _EmpathyChatPriv {
- EmpathyLogManager *log_manager;
- EmpathyTpChat *tp_chat;
- McAccount *account;
- MissionControl *mc;
- GtkWidget *widget;
- guint composing_stop_timeout_id;
- gboolean sensitive;
- gchar *id;
- GSList *sent_messages;
- gint sent_messages_index;
- GList *compositors;
- guint scroll_idle_id;
- gboolean first_tp_chat;
- GList *backlog_messages;
- gboolean is_first_char;
- guint block_events_timeout_id;
- TpHandleType handle_type;
- gchar *name;
- gchar *tooltip;
- const gchar *icon_name;
- /* Used to automatically shrink a window that has temporarily
- * grown due to long input.
- */
- gint padding_height;
- gint default_window_height;
- gint last_input_height;
- gboolean vscroll_visible;
+ EmpathyTpChat *tp_chat;
+ McAccount *account;
+ gchar *id;
+ gchar *name;
+ gchar *subject;
+ EmpathyContact *remote_contact;
+
+ EmpathyLogManager *log_manager;
+ MissionControl *mc;
+ GSList *sent_messages;
+ gint sent_messages_index;
+ GList *compositors;
+ GList *backlog_messages;
+ GCompletion *completion;
+ guint composing_stop_timeout_id;
+ guint block_events_timeout_id;
+ TpHandleType handle_type;
+ gpointer token;
+ gint contacts_width;
+ gboolean has_input_vscroll;
+
+ GtkWidget *widget;
+ GtkWidget *hpaned;
+ GtkWidget *vbox_left;
+ GtkWidget *scrolled_window_chat;
+ GtkWidget *scrolled_window_input;
+ GtkWidget *scrolled_window_contacts;
+ GtkWidget *hbox_topic;
+ GtkWidget *label_topic;
+ GtkWidget *contact_list_view;
};
static void empathy_chat_class_init (EmpathyChatClass *klass);
enum {
PROP_0,
PROP_TP_CHAT,
+ PROP_ACCOUNT,
+ PROP_ID,
PROP_NAME,
- PROP_TOOLTIP,
- PROP_ICON_NAME,
- PROP_WIDGET
+ PROP_SUBJECT,
+ PROP_REMOTE_CONTACT,
};
static guint signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE (EmpathyChat, empathy_chat, G_TYPE_OBJECT);
+G_DEFINE_TYPE (EmpathyChat, empathy_chat, GTK_TYPE_BIN);
static void
chat_get_property (GObject *object,
case PROP_TP_CHAT:
g_value_set_object (value, priv->tp_chat);
break;
+ case PROP_ACCOUNT:
+ g_value_set_object (value, priv->account);
+ break;
case PROP_NAME:
g_value_set_string (value, priv->name);
break;
- case PROP_TOOLTIP:
- g_value_set_string (value, priv->tooltip);
+ case PROP_ID:
+ g_value_set_string (value, priv->id);
break;
- case PROP_ICON_NAME:
- g_value_set_string (value, priv->icon_name);
+ case PROP_SUBJECT:
+ g_value_set_string (value, priv->subject);
break;
- case PROP_WIDGET:
- g_value_set_object (value, priv->widget);
+ case PROP_REMOTE_CONTACT:
+ g_value_set_object (value, priv->remote_contact);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
switch (param_id) {
case PROP_TP_CHAT:
- empathy_chat_set_tp_chat (chat,
- EMPATHY_TP_CHAT (g_value_get_object (value)));
+ empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
if (status == TP_CONNECTION_STATUS_CONNECTED && !priv->tp_chat &&
empathy_account_equal (account, priv->account) &&
- priv->handle_type != 0) {
- empathy_debug (DEBUG_DOMAIN,
- "Account reconnected, request a new Text channel");
+ priv->handle_type != TP_HANDLE_TYPE_NONE) {
+ DEBUG ("Account reconnected, request a new Text channel");
mission_control_request_channel_with_string_handle (mc,
priv->account,
TP_IFACE_CHANNEL_TYPE_TEXT,
TP_CHANNEL_CHAT_STATE_ACTIVE);
}
-static void
-chat_finalize (GObject *object)
-{
- EmpathyChat *chat;
- EmpathyChatPriv *priv;
-
- chat = EMPATHY_CHAT (object);
- priv = GET_PRIV (chat);
-
- empathy_debug (DEBUG_DOMAIN, "Finalized: %p", object);
-
- g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
- g_slist_free (priv->sent_messages);
-
- g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
- g_list_free (priv->compositors);
-
- chat_composing_remove_timeout (chat);
- g_object_unref (priv->log_manager);
-
- dbus_g_proxy_disconnect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged",
- G_CALLBACK (chat_status_changed_cb),
- chat);
- g_object_unref (priv->mc);
-
-
- if (priv->tp_chat) {
- g_object_unref (priv->tp_chat);
- }
-
- if (priv->account) {
- g_object_unref (priv->account);
- }
-
- if (priv->scroll_idle_id) {
- g_source_remove (priv->scroll_idle_id);
- }
-
- if (priv->block_events_timeout_id) {
- g_source_remove (priv->block_events_timeout_id);
- }
-
- g_free (priv->id);
- g_free (priv->name);
- g_free (priv->tooltip);
-
- G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
-}
-
-static void
-chat_destroy_cb (EmpathyTpChat *tp_chat,
- EmpathyChat *chat)
-{
- EmpathyChatPriv *priv;
-
- priv = GET_PRIV (chat);
-
- if (priv->tp_chat) {
- g_object_unref (priv->tp_chat);
- priv->tp_chat = NULL;
- }
- priv->sensitive = FALSE;
-
- empathy_chat_view_append_event (chat->view, _("Disconnected"));
- gtk_widget_set_sensitive (chat->input_text_view, FALSE);
-
- if (priv->block_events_timeout_id != 0) {
- g_source_remove (priv->block_events_timeout_id);
- }
-}
-
static void
chat_sent_message_add (EmpathyChat *chat,
const gchar *str)
priv = GET_PRIV (chat);
if (!priv->sent_messages) {
- empathy_debug (DEBUG_DOMAIN,
- "No sent messages, next message is NULL");
+ DEBUG ("No sent messages, next message is NULL");
return NULL;
}
priv->sent_messages_index++;
}
- empathy_debug (DEBUG_DOMAIN,
- "Returning next message index:%d",
- priv->sent_messages_index);
+ DEBUG ("Returning next message index:%d", priv->sent_messages_index);
return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
}
priv = GET_PRIV (chat);
if (!priv->sent_messages) {
- empathy_debug (DEBUG_DOMAIN,
- "No sent messages, last message is NULL");
+ DEBUG ("No sent messages, last message is NULL");
return NULL;
}
priv->sent_messages_index--;
}
- empathy_debug (DEBUG_DOMAIN,
- "Returning last message index:%d",
- priv->sent_messages_index);
+ DEBUG ("Returning last message index:%d", priv->sent_messages_index);
return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
}
gtk_text_buffer_set_text (buffer, "", -1);
chat_send (chat, msg);
-
g_free (msg);
-
- priv->is_first_char = TRUE;
}
static void
g_assert_not_reached ();
}
- empathy_debug (DEBUG_DOMAIN, "Was composing: %s now composing: %s",
- was_composing ? "yes" : "no",
- priv->compositors ? "yes" : "no");
+ DEBUG ("Was composing: %s now composing: %s",
+ was_composing ? "yes" : "no",
+ priv->compositors ? "yes" : "no");
if ((was_composing && !priv->compositors) ||
(!was_composing && priv->compositors)) {
/* The message we received is already displayed because
* some jabber chatrooms sends us back logs and we
* already displayed it from localy logged messages. */
- empathy_debug (DEBUG_DOMAIN, "Skipping message because "
- "it is already displayed from logged "
- "messages");
+ DEBUG ("Skipping message because it is already "
+ "displayed from logged messages");
g_object_unref (log_message);
return;
}
g_object_unref (log_message);
}
- empathy_debug (DEBUG_DOMAIN, "Appending new message from %s (%d)",
- empathy_contact_get_name (sender),
- empathy_contact_get_handle (sender));
-
- empathy_log_manager_add_message (priv->log_manager,
- empathy_chat_get_id (chat),
- FALSE,
- message);
+ DEBUG ("Appending new message from %s (%d)",
+ empathy_contact_get_name (sender),
+ empathy_contact_get_handle (sender));
- empathy_chat_view_append_message (chat->view, message);
+ if (priv->id) {
+ gboolean is_chatroom;
- if (empathy_chat_should_play_sound (chat)) {
- // FIXME: empathy_sound_play (EMPATHY_SOUND_CHAT);
+ is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
+ empathy_log_manager_add_message (priv->log_manager,
+ priv->id, is_chatroom,
+ message);
}
+ empathy_chat_view_append_message (chat->view, message);
+
/* We received a message so the contact is no more composing */
chat_state_changed_cb (tp_chat, sender,
TP_CHANNEL_CHAT_STATE_ACTIVE,
chat);
- g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, FALSE);
+ g_signal_emit (chat, signals[NEW_MESSAGE], 0, message);
}
static void
g_free (str);
}
+static void
+chat_property_changed_cb (EmpathyTpChat *tp_chat,
+ const gchar *name,
+ GValue *value,
+ EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ if (!tp_strdiff (name, "subject")) {
+ g_free (priv->subject);
+ priv->subject = g_value_dup_string (value);
+ g_object_notify (G_OBJECT (chat), "subject");
+
+ if (G_STR_EMPTY (priv->subject)) {
+ gtk_widget_hide (priv->hbox_topic);
+ } else {
+ gtk_label_set_text (GTK_LABEL (priv->label_topic), priv->subject);
+ gtk_widget_show (priv->hbox_topic);
+ }
+ if (priv->block_events_timeout_id == 0) {
+ gchar *str;
+
+ if (!G_STR_EMPTY (priv->subject)) {
+ str = g_strdup_printf (_("Topic set to: %s"), priv->subject);
+ } else {
+ str = g_strdup (_("No topic defined"));
+ }
+ empathy_chat_view_append_event (EMPATHY_CHAT (chat)->view, str);
+ g_free (str);
+ }
+ }
+ else if (!tp_strdiff (name, "name")) {
+ g_free (priv->name);
+ priv->name = g_value_dup_string (value);
+ g_object_notify (G_OBJECT (chat), "name");
+ }
+}
+
+static gboolean
+chat_get_is_command (const gchar *str)
+{
+ g_return_val_if_fail (str != NULL, FALSE);
+
+ if (str[0] != '/') {
+ return FALSE;
+ }
+
+ if (g_str_has_prefix (str, "/me")) {
+ return TRUE;
+ }
+ else if (g_str_has_prefix (str, "/nick")) {
+ return TRUE;
+ }
+ else if (g_str_has_prefix (str, "/topic")) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static void
chat_input_text_buffer_changed_cb (GtkTextBuffer *buffer,
EmpathyChat *chat)
EMPATHY_PREFS_CHAT_SPELL_CHECKER_ENABLED,
&spell_checker);
- if (priv->is_first_char) {
- GtkRequisition req;
- gint window_height;
- GtkWindow *dialog;
- GtkAllocation *allocation;
-
- /* Save the window's size */
- dialog = empathy_get_toplevel_window (priv->widget);
- if (dialog) {
- gtk_window_get_size (GTK_WINDOW (dialog), NULL, &window_height);
- gtk_widget_size_request (chat->input_text_view, &req);
- allocation = >K_WIDGET (chat->view)->allocation;
-
- priv->default_window_height = window_height;
- priv->last_input_height = req.height;
- priv->padding_height = window_height - req.height - allocation->height;
- }
-
- priv->is_first_char = FALSE;
- }
-
gtk_text_buffer_get_start_iter (buffer, &start);
if (!spell_checker) {
str = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
/* spell check string */
- if (!empathy_chat_get_is_command (str)) {
+ if (!chat_get_is_command (str)) {
correct = empathy_spell_check (str);
} else {
correct = TRUE;
/* Newline for shift/control-enter. */
return FALSE;
}
- else if (!(event->state & GDK_CONTROL_MASK) &&
- event->keyval == GDK_Page_Up) {
+ if (!(event->state & GDK_CONTROL_MASK) &&
+ event->keyval == GDK_Page_Up) {
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
gtk_adjustment_set_value (adj, adj->value - adj->page_size);
-
return TRUE;
}
- else if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
- event->keyval == GDK_Page_Down) {
+ if ((event->state & GDK_CONTROL_MASK) != GDK_CONTROL_MASK &&
+ event->keyval == GDK_Page_Down) {
adj = gtk_scrolled_window_get_vadjustment (GTK_SCROLLED_WINDOW (text_view_sw));
val = MIN (adj->value + adj->page_size, adj->upper - adj->page_size);
gtk_adjustment_set_value (adj, val);
+ return TRUE;
+ }
+ if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
+ event->keyval == GDK_Tab) {
+ GtkTextBuffer *buffer;
+ GtkTextIter start, current;
+ gchar *nick, *completed;
+ GList *list, *completed_list;
+ gboolean is_start_of_buffer;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
+ gtk_text_buffer_get_iter_at_mark (buffer, ¤t, gtk_text_buffer_get_insert (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);
+ is_start_of_buffer = gtk_text_iter_is_start (&start);
+
+ list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
+ g_completion_add_items (priv->completion, list);
+
+ nick = gtk_text_buffer_get_text (buffer, &start, ¤t, FALSE);
+ completed_list = g_completion_complete (priv->completion,
+ nick,
+ &completed);
+
+ g_free (nick);
+
+ if (completed) {
+ guint len;
+ const gchar *text;
+ gchar *complete_char = NULL;
+
+ gtk_text_buffer_delete (buffer, &start, ¤t);
+
+ len = g_list_length (completed_list);
+
+ if (len == 1) {
+ /* If we only have one hit, use that text
+ * instead of the text in completed since the
+ * completed text will use the typed string
+ * which might be cased all wrong.
+ * Fixes #120876
+ * */
+ text = empathy_contact_get_name (completed_list->data);
+ } else {
+ text = completed;
+ }
+
+ gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
+
+ if (len == 1 && is_start_of_buffer &&
+ empathy_conf_get_string (empathy_conf_get (),
+ EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
+ &complete_char) &&
+ complete_char != NULL) {
+ gtk_text_buffer_insert_at_cursor (buffer,
+ complete_char,
+ strlen (complete_char));
+ gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
+ g_free (complete_char);
+ }
+
+ g_free (completed);
+ }
+
+ g_completion_clear_items (priv->completion);
+
+ g_list_foreach (list, (GFunc) g_object_unref, NULL);
+ g_list_free (list);
return TRUE;
}
return TRUE;
}
-typedef struct {
- GtkWindow *window;
- gint width;
- gint height;
-} ChangeSizeData;
-
static gboolean
-chat_change_size_in_idle_cb (ChangeSizeData *data)
+chat_input_set_size_request_idle (gpointer sw)
{
- gtk_window_resize (data->window, data->width, data->height);
+ gtk_widget_set_size_request (sw, -1, MAX_INPUT_HEIGHT);
return FALSE;
}
static void
-chat_text_view_scroll_hide_cb (GtkWidget *widget,
- EmpathyChat *chat)
-{
- EmpathyChatPriv *priv;
- GtkWidget *sw;
-
- priv = GET_PRIV (chat);
-
- priv->vscroll_visible = FALSE;
- g_signal_handlers_disconnect_by_func (widget, chat_text_view_scroll_hide_cb, chat);
-
- sw = gtk_widget_get_parent (chat->input_text_view);
- gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
- GTK_POLICY_NEVER,
- GTK_POLICY_NEVER);
- g_object_set (sw, "height-request", -1, NULL);
-}
-
-static void
-chat_text_view_size_allocate_cb (GtkWidget *widget,
- GtkAllocation *allocation,
- EmpathyChat *chat)
+chat_input_size_request_cb (GtkWidget *widget,
+ GtkRequisition *requisition,
+ EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
- gint width;
- GtkWindow *dialog;
- ChangeSizeData *data;
- gint window_height;
- gint new_height;
- GtkAllocation *view_allocation;
- gint current_height;
- gint diff;
- GtkWidget *sw;
-
- priv = GET_PRIV (chat);
-
- if (priv->default_window_height <= 0) {
- return;
- }
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ GtkWidget *sw;
sw = gtk_widget_get_parent (widget);
- if (sw->allocation.height >= MAX_INPUT_HEIGHT && !priv->vscroll_visible) {
- GtkWidget *vscroll;
-
- priv->vscroll_visible = TRUE;
- gtk_widget_set_size_request (sw, sw->allocation.width, MAX_INPUT_HEIGHT);
+ if (requisition->height >= MAX_INPUT_HEIGHT && !priv->has_input_vscroll) {
+ g_idle_add (chat_input_set_size_request_idle, sw);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_NEVER,
- GTK_POLICY_AUTOMATIC);
- vscroll = gtk_scrolled_window_get_vscrollbar (GTK_SCROLLED_WINDOW (sw));
- g_signal_connect (vscroll, "hide",
- G_CALLBACK (chat_text_view_scroll_hide_cb),
- chat);
- }
-
- if (priv->last_input_height <= allocation->height) {
- priv->last_input_height = allocation->height;
- return;
- }
-
- diff = priv->last_input_height - allocation->height;
- priv->last_input_height = allocation->height;
-
- view_allocation = >K_WIDGET (chat->view)->allocation;
-
- dialog = empathy_get_toplevel_window (priv->widget);
- gtk_window_get_size (dialog, NULL, ¤t_height);
-
- new_height = view_allocation->height + priv->padding_height + allocation->height - diff;
-
- if (new_height <= priv->default_window_height) {
- window_height = priv->default_window_height;
- } else {
- window_height = new_height;
+ GTK_POLICY_ALWAYS);
+ priv->has_input_vscroll = TRUE;
}
- if (current_height <= window_height) {
- return;
+ if (requisition->height < MAX_INPUT_HEIGHT && priv->has_input_vscroll) {
+ gtk_widget_set_size_request (sw, -1, -1);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_NEVER,
+ GTK_POLICY_NEVER);
+ priv->has_input_vscroll = FALSE;
}
-
- /* Restore the window's size */
- gtk_window_get_size (dialog, &width, NULL);
-
- data = g_new0 (ChangeSizeData, 1);
- data->window = dialog;
- data->width = width;
- data->height = window_height;
-
- g_idle_add_full (G_PRIORITY_DEFAULT_IDLE,
- (GSourceFunc) chat_change_size_in_idle_cb,
- data, g_free);
}
static void
-chat_text_view_realize_cb (GtkWidget *widget,
- EmpathyChat *chat)
+chat_input_realize_cb (GtkWidget *widget,
+ EmpathyChat *chat)
{
- empathy_debug (DEBUG_DOMAIN, "Setting focus to the input text view");
+ DEBUG ("Setting focus to the input text view");
gtk_widget_grab_focus (widget);
}
EmpathyChatSpell *chat_spell)
{
empathy_spell_dialog_show (chat_spell->chat,
- chat_spell->start,
- chat_spell->end,
+ &chat_spell->start,
+ &chat_spell->end,
chat_spell->word);
}
static void
-chat_text_populate_popup_cb (GtkTextView *view,
- GtkMenu *menu,
- EmpathyChat *chat)
+chat_input_populate_popup_cb (GtkTextView *view,
+ GtkMenu *menu,
+ EmpathyChat *chat)
{
EmpathyChatPriv *priv;
GtkTextBuffer *buffer;
gtk_widget_show (item);
}
-static gboolean
-chat_scroll_down_idle_func (EmpathyChat *chat)
-{
- EmpathyChatPriv *priv;
-
- priv = GET_PRIV (chat);
-
- empathy_chat_scroll_down (chat);
- g_object_unref (chat);
-
- priv->scroll_idle_id = 0;
-
- return FALSE;
-}
-
static void
chat_add_logs (EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
- GList *messages, *l;
- guint num_messages;
- guint i;
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ gboolean is_chatroom;
+ GList *messages, *l;
+ guint num_messages;
+ guint i;
- priv = GET_PRIV (chat);
+ if (!priv->id) {
+ return;
+ }
/* Turn off scrolling temporarily */
empathy_chat_view_scroll (chat->view, FALSE);
/* Add messages from last conversation */
+ is_chatroom = priv->handle_type == TP_HANDLE_TYPE_ROOM;
messages = empathy_log_manager_get_last_messages (priv->log_manager,
priv->account,
- empathy_chat_get_id (chat),
- FALSE);
+ priv->id,
+ is_chatroom);
num_messages = g_list_length (messages);
/* Only keep the 10 last messages */
/* Turn back on scrolling */
empathy_chat_view_scroll (chat->view, TRUE);
-
- /* Scroll to the most recent messages, we reference the chat
- * for the duration of the scroll func.
- */
- priv->scroll_idle_id = g_idle_add ((GSourceFunc) chat_scroll_down_idle_func,
- g_object_ref (chat));
}
-static void
-empathy_chat_class_init (EmpathyChatClass *klass)
+static gint
+chat_contacts_completion_func (const gchar *s1,
+ const gchar *s2,
+ gsize n)
{
- GObjectClass *object_class;
+ gchar *tmp, *nick1, *nick2;
+ gint ret;
- object_class = G_OBJECT_CLASS (klass);
+ if (s1 == s2) {
+ return 0;
+ }
+ if (!s1 || !s2) {
+ return s1 ? -1 : +1;
+ }
- object_class->finalize = chat_finalize;
- object_class->get_property = chat_get_property;
- object_class->set_property = chat_set_property;
+ tmp = g_utf8_normalize (s1, -1, G_NORMALIZE_DEFAULT);
+ nick1 = g_utf8_casefold (tmp, -1);
+ g_free (tmp);
- g_object_class_install_property (object_class,
- PROP_TP_CHAT,
- g_param_spec_object ("tp-chat",
- "Empathy tp chat",
- "The tp chat object",
- EMPATHY_TYPE_TP_CHAT,
- G_PARAM_CONSTRUCT |
- G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_NAME,
- g_param_spec_string ("name",
- "Chat's name",
- "The name of the chat",
- NULL,
- G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_TOOLTIP,
- g_param_spec_string ("tooltip",
- "Chat's tooltip",
- "The tooltip of the chat",
- NULL,
- G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_ICON_NAME,
- g_param_spec_string ("icon-name",
- "Chat's icon name",
- "The icon name of the chat",
- NULL,
- G_PARAM_READABLE));
- g_object_class_install_property (object_class,
- PROP_WIDGET,
- g_param_spec_object ("widget",
- "Chat's widget",
- "The widget of the chat",
- GTK_TYPE_WIDGET,
- G_PARAM_READABLE));
+ tmp = g_utf8_normalize (s2, -1, G_NORMALIZE_DEFAULT);
+ nick2 = g_utf8_casefold (tmp, -1);
+ g_free (tmp);
- signals[COMPOSING] =
- g_signal_new ("composing",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- g_cclosure_marshal_VOID__BOOLEAN,
- G_TYPE_NONE,
- 1, G_TYPE_BOOLEAN);
+ ret = strncmp (nick1, nick2, n);
- signals[NEW_MESSAGE] =
- g_signal_new ("new-message",
- G_OBJECT_CLASS_TYPE (object_class),
- G_SIGNAL_RUN_LAST,
- 0,
- NULL, NULL,
- _empathy_gtk_marshal_VOID__OBJECT_BOOLEAN,
- G_TYPE_NONE,
- 2, EMPATHY_TYPE_MESSAGE, G_TYPE_BOOLEAN);
+ g_free (nick1);
+ g_free (nick2);
- g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
+ return ret;
}
static void
-empathy_chat_init (EmpathyChat *chat)
+chat_members_changed_cb (EmpathyTpChat *tp_chat,
+ EmpathyContact *contact,
+ EmpathyContact *actor,
+ guint reason,
+ gchar *message,
+ gboolean is_member,
+ EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- GtkTextBuffer *buffer;
- chat->view = empathy_chat_view_new ();
- chat->input_text_view = gtk_text_view_new ();
+ if (priv->block_events_timeout_id == 0) {
+ gchar *str;
- priv->is_first_char = TRUE;
+ empathy_contact_run_until_ready (contact,
+ EMPATHY_CONTACT_READY_NAME,
+ NULL);
- g_object_set (chat->input_text_view,
- "pixels-above-lines", 2,
- "pixels-below-lines", 2,
- "pixels-inside-wrap", 1,
- "right-margin", 2,
- "left-margin", 2,
- "wrap-mode", GTK_WRAP_WORD_CHAR,
- NULL);
+ if (is_member) {
+ str = g_strdup_printf (_("%s has joined the room"),
+ empathy_contact_get_name (contact));
+ } else {
+ str = g_strdup_printf (_("%s has left the room"),
+ empathy_contact_get_name (contact));
+ }
+ empathy_chat_view_append_event (chat->view, str);
+ g_free (str);
+ }
+}
- priv->log_manager = empathy_log_manager_new ();
- priv->default_window_height = -1;
- priv->vscroll_visible = FALSE;
- priv->sensitive = TRUE;
- priv->sent_messages = NULL;
- priv->sent_messages_index = -1;
- priv->first_tp_chat = TRUE;
- priv->mc = empathy_mission_control_new ();
+static gboolean
+chat_reset_size_request (gpointer widget)
+{
+ gtk_widget_set_size_request (widget, -1, -1);
- dbus_g_proxy_connect_signal (DBUS_G_PROXY (priv->mc), "AccountStatusChanged",
- G_CALLBACK (chat_status_changed_cb),
- chat, NULL);
+ return FALSE;
+}
- g_signal_connect (chat->input_text_view,
- "key_press_event",
- G_CALLBACK (chat_input_key_press_event_cb),
- chat);
+static void
+chat_set_show_contacts (EmpathyChat *chat, gboolean show)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
- g_signal_connect (buffer,
- "changed",
- G_CALLBACK (chat_input_text_buffer_changed_cb),
- chat);
- g_signal_connect (chat->view,
- "focus_in_event",
- G_CALLBACK (chat_text_view_focus_in_event_cb),
- chat);
+ if (!priv->scrolled_window_contacts) {
+ return;
+ }
- g_signal_connect (chat->input_text_view,
- "size_allocate",
- G_CALLBACK (chat_text_view_size_allocate_cb),
- chat);
+ if (show) {
+ EmpathyContactListStore *store;
+ gint min_width;
- g_signal_connect (chat->input_text_view,
- "realize",
- G_CALLBACK (chat_text_view_realize_cb),
- chat);
+ /* We are adding the contact list to the chat, we don't want the
+ * chat view to become too small. If the chat view is already
+ * smaller than 250 make sure that size won't change. If the
+ * 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_set_size_request (priv->vbox_left, min_width, -1);
+ g_idle_add (chat_reset_size_request, priv->vbox_left);
- g_signal_connect (GTK_TEXT_VIEW (chat->input_text_view),
- "populate_popup",
- G_CALLBACK (chat_text_populate_popup_cb),
- chat);
-
- /* create misspelt words identification tag */
- gtk_text_buffer_create_tag (buffer,
- "misspelled",
- "underline", PANGO_UNDERLINE_ERROR,
- NULL);
-}
+ if (priv->contacts_width > 0) {
+ gtk_paned_set_position (GTK_PANED (priv->hpaned),
+ priv->contacts_width);
+ }
-EmpathyChat *
-empathy_chat_new (EmpathyTpChat *tp_chat)
-{
- return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
+ store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
+ priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
+ EMPATHY_CONTACT_LIST_FEATURE_NONE,
+ EMPATHY_CONTACT_FEATURE_CHAT |
+ EMPATHY_CONTACT_FEATURE_CALL |
+ EMPATHY_CONTACT_FEATURE_LOG |
+ EMPATHY_CONTACT_FEATURE_INFO));
+ gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
+ priv->contact_list_view);
+ gtk_widget_show (priv->contact_list_view);
+ gtk_widget_show (priv->scrolled_window_contacts);
+ g_object_unref (store);
+ } else {
+ priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
+ gtk_widget_hide (priv->scrolled_window_contacts);
+ if (priv->contact_list_view) {
+ gtk_widget_destroy (priv->contact_list_view);
+ priv->contact_list_view = NULL;
+ }
+ }
}
-gboolean
-empathy_chat_get_is_command (const gchar *str)
+static void
+chat_remote_contact_changed_cb (EmpathyChat *chat)
{
- g_return_val_if_fail (str != NULL, FALSE);
+ EmpathyChatPriv *priv = GET_PRIV (chat);
- if (str[0] != '/') {
- return FALSE;
+ if (priv->remote_contact) {
+ g_object_unref (priv->remote_contact);
+ priv->remote_contact = NULL;
}
- if (g_str_has_prefix (str, "/me")) {
- return TRUE;
- }
- else if (g_str_has_prefix (str, "/nick")) {
- return TRUE;
+ priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
+ if (priv->remote_contact) {
+ g_object_ref (priv->remote_contact);
+ priv->handle_type = TP_HANDLE_TYPE_CONTACT;
+ g_free (priv->id);
+ priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
}
- else if (g_str_has_prefix (str, "/topic")) {
- return TRUE;
+ else if (priv->tp_chat) {
+ TpChannel *channel;
+
+ channel = empathy_tp_chat_get_channel (priv->tp_chat);
+ g_object_get (channel, "handle-type", &priv->handle_type, NULL);
+ g_free (priv->id);
+ priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
}
- return FALSE;
+ chat_set_show_contacts (chat, priv->remote_contact == NULL);
+
+ g_object_notify (G_OBJECT (chat), "remote-contact");
+ g_object_notify (G_OBJECT (chat), "id");
}
-void
-empathy_chat_correct_word (EmpathyChat *chat,
- GtkTextIter start,
- GtkTextIter end,
- const gchar *new_word)
+static void
+chat_destroy_cb (EmpathyTpChat *tp_chat,
+ EmpathyChat *chat)
{
- GtkTextBuffer *buffer;
+ EmpathyChatPriv *priv;
- g_return_if_fail (chat != NULL);
- g_return_if_fail (new_word != NULL);
+ priv = GET_PRIV (chat);
- buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
+ if (!priv->tp_chat) {
+ return;
+ }
- gtk_text_buffer_delete (buffer, &start, &end);
- gtk_text_buffer_insert (buffer, &start,
- new_word,
- -1);
+ g_object_unref (priv->tp_chat);
+ priv->tp_chat = NULL;
+ g_object_notify (G_OBJECT (chat), "tp-chat");
+
+ empathy_chat_view_append_event (chat->view, _("Disconnected"));
+ gtk_widget_set_sensitive (chat->input_text_view, FALSE);
+ chat_set_show_contacts (chat, FALSE);
}
-const gchar *
-empathy_chat_get_name (EmpathyChat *chat)
+static void
+chat_create_ui (EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
+ GladeXML *glade;
+ GList *list = NULL;
+ gchar *filename;
+ GtkTextBuffer *buffer;
- g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+ filename = empathy_file_lookup ("empathy-chat.glade",
+ "libempathy-gtk");
+ glade = empathy_glade_get_file (filename,
+ "chat_widget",
+ NULL,
+ "chat_widget", &priv->widget,
+ "hpaned", &priv->hpaned,
+ "vbox_left", &priv->vbox_left,
+ "scrolled_window_chat", &priv->scrolled_window_chat,
+ "scrolled_window_input", &priv->scrolled_window_input,
+ "hbox_topic", &priv->hbox_topic,
+ "label_topic", &priv->label_topic,
+ "scrolled_window_contacts", &priv->scrolled_window_contacts,
+ NULL);
+ g_free (filename);
+ g_object_unref (glade);
+
+ /* Add message GtkTextView. */
+ chat->view = empathy_chat_view_new ();
+ g_signal_connect (chat->view, "focus_in_event",
+ G_CALLBACK (chat_text_view_focus_in_event_cb),
+ chat);
+ gtk_container_add (GTK_CONTAINER (priv->scrolled_window_chat),
+ GTK_WIDGET (chat->view));
+ gtk_widget_show (GTK_WIDGET (chat->view));
+
+ /* Add input GtkTextView */
+ chat->input_text_view = g_object_new (GTK_TYPE_TEXT_VIEW,
+ "pixels-above-lines", 2,
+ "pixels-below-lines", 2,
+ "pixels-inside-wrap", 1,
+ "right-margin", 2,
+ "left-margin", 2,
+ "wrap-mode", GTK_WRAP_WORD_CHAR,
+ NULL);
+ g_signal_connect (chat->input_text_view, "key-press-event",
+ G_CALLBACK (chat_input_key_press_event_cb),
+ chat);
+ g_signal_connect (chat->input_text_view, "size-request",
+ G_CALLBACK (chat_input_size_request_cb),
+ chat);
+ g_signal_connect (chat->input_text_view, "realize",
+ G_CALLBACK (chat_input_realize_cb),
+ chat);
+ g_signal_connect (chat->input_text_view, "populate-popup",
+ G_CALLBACK (chat_input_populate_popup_cb),
+ chat);
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
+ g_signal_connect (buffer, "changed",
+ G_CALLBACK (chat_input_text_buffer_changed_cb),
+ chat);
+ gtk_text_buffer_create_tag (buffer, "misspelled",
+ "underline", PANGO_UNDERLINE_ERROR,
+ NULL);
+ gtk_container_add (GTK_CONTAINER (priv->scrolled_window_input),
+ chat->input_text_view);
+ gtk_widget_show (chat->input_text_view);
- return priv->name;
-}
+ /* Create contact list */
+ chat_set_show_contacts (chat, priv->remote_contact == NULL);
-const gchar *
-empathy_chat_get_tooltip (EmpathyChat *chat)
-{
- EmpathyChatPriv *priv = GET_PRIV (chat);
+ /* Initialy hide the topic, will be shown if not empty */
+ gtk_widget_hide (priv->hbox_topic);
- g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+ /* Set widget focus order */
+ list = g_list_append (NULL, priv->scrolled_window_input);
+ gtk_container_set_focus_chain (GTK_CONTAINER (priv->vbox_left), list);
+ g_list_free (list);
+
+ list = g_list_append (NULL, priv->vbox_left);
+ list = g_list_append (list, priv->scrolled_window_contacts);
+ gtk_container_set_focus_chain (GTK_CONTAINER (priv->hpaned), list);
+ g_list_free (list);
+
+ list = g_list_append (NULL, priv->hpaned);
+ list = g_list_append (list, priv->hbox_topic);
+ gtk_container_set_focus_chain (GTK_CONTAINER (priv->widget), list);
+ g_list_free (list);
- return priv->tooltip;
+ /* Add the main widget in the chat widget */
+ gtk_container_add (GTK_CONTAINER (chat), priv->widget);
}
-const gchar *
-empathy_chat_get_status_icon_name (EmpathyChat *chat)
+static void
+chat_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
{
- EmpathyChatPriv *priv = GET_PRIV (chat);
+ GtkBin *bin = GTK_BIN (widget);
- g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+ requisition->width = GTK_CONTAINER (widget)->border_width * 2;
+ requisition->height = GTK_CONTAINER (widget)->border_width * 2;
+
+ if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+ {
+ GtkRequisition child_requisition;
+
+ gtk_widget_size_request (bin->child, &child_requisition);
- return priv->icon_name;
+ requisition->width += child_requisition.width;
+ requisition->height += child_requisition.height;
+ }
}
-GtkWidget *
-empathy_chat_get_widget (EmpathyChat *chat)
+static void
+chat_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
{
- EmpathyChatPriv *priv = GET_PRIV (chat);
-
- g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
-
- return priv->widget;
+ GtkBin *bin = GTK_BIN (widget);
+ GtkAllocation child_allocation;
+
+ widget->allocation = *allocation;
+
+ if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
+ {
+ child_allocation.x = allocation->x + GTK_CONTAINER (widget)->border_width;
+ child_allocation.y = allocation->y + GTK_CONTAINER (widget)->border_width;
+ child_allocation.width = MAX (allocation->width - GTK_CONTAINER (widget)->border_width * 2, 0);
+ child_allocation.height = MAX (allocation->height - GTK_CONTAINER (widget)->border_width * 2, 0);
+
+ gtk_widget_size_allocate (bin->child, &child_allocation);
+ }
}
-gboolean
-empathy_chat_is_connected (EmpathyChat *chat)
+static void
+chat_finalize (GObject *object)
{
+ EmpathyChat *chat;
EmpathyChatPriv *priv;
- g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
-
+ chat = EMPATHY_CHAT (object);
priv = GET_PRIV (chat);
- return (priv->tp_chat != NULL);
-}
+ DEBUG ("Finalized: %p", object);
-static const gchar *
-chat_get_window_id_for_geometry (EmpathyChat *chat)
-{
- gboolean separate_windows;
+ g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
+ g_slist_free (priv->sent_messages);
- empathy_conf_get_bool (empathy_conf_get (),
- EMPATHY_PREFS_UI_SEPARATE_CHAT_WINDOWS,
- &separate_windows);
+ g_list_foreach (priv->compositors, (GFunc) g_object_unref, NULL);
+ g_list_free (priv->compositors);
- if (separate_windows) {
- return empathy_chat_get_id (chat);
- } else {
- return "chat-window";
+ g_list_foreach (priv->backlog_messages, (GFunc) g_object_unref, NULL);
+ g_list_free (priv->backlog_messages);
+
+ chat_composing_remove_timeout (chat);
+
+ empathy_disconnect_account_status_changed (priv->token);
+ g_object_unref (priv->mc);
+ g_object_unref (priv->log_manager);
+
+ if (priv->tp_chat) {
+ g_object_unref (priv->tp_chat);
+ }
+ if (priv->account) {
+ g_object_unref (priv->account);
+ }
+ if (priv->remote_contact) {
+ g_object_unref (priv->remote_contact);
+ }
+
+ if (priv->block_events_timeout_id) {
+ g_source_remove (priv->block_events_timeout_id);
}
+
+ g_free (priv->id);
+ g_free (priv->name);
+ g_free (priv->subject);
+
+ G_OBJECT_CLASS (empathy_chat_parent_class)->finalize (object);
}
-void
-empathy_chat_save_geometry (EmpathyChat *chat,
- gint x,
- gint y,
- gint w,
- gint h)
+static void
+chat_constructed (GObject *object)
{
- empathy_geometry_save (chat_get_window_id_for_geometry (chat), x, y, w, h);
+ EmpathyChat *chat = EMPATHY_CHAT (object);
+
+ chat_create_ui (chat);
+ chat_add_logs (chat);
}
-void
-empathy_chat_load_geometry (EmpathyChat *chat,
- gint *x,
- gint *y,
- gint *w,
- gint *h)
+static void
+empathy_chat_class_init (EmpathyChatClass *klass)
{
- empathy_geometry_load (chat_get_window_id_for_geometry (chat), x, y, w, h);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = chat_finalize;
+ object_class->get_property = chat_get_property;
+ object_class->set_property = chat_set_property;
+ object_class->constructed = chat_constructed;
+
+ widget_class->size_request = chat_size_request;
+ widget_class->size_allocate = chat_size_allocate;
+
+ g_object_class_install_property (object_class,
+ PROP_TP_CHAT,
+ g_param_spec_object ("tp-chat",
+ "Empathy tp chat",
+ "The tp chat object",
+ EMPATHY_TYPE_TP_CHAT,
+ G_PARAM_CONSTRUCT |
+ G_PARAM_READWRITE));
+ g_object_class_install_property (object_class,
+ PROP_ACCOUNT,
+ g_param_spec_object ("account",
+ "Account of the chat",
+ "The account of the chat",
+ MC_TYPE_ACCOUNT,
+ G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_ID,
+ g_param_spec_string ("id",
+ "Chat's id",
+ "The id of the chat",
+ NULL,
+ G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_string ("name",
+ "Chat's name",
+ "The name of the chat",
+ NULL,
+ G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_SUBJECT,
+ g_param_spec_string ("subject",
+ "Chat's subject",
+ "The subject or topic of the chat",
+ NULL,
+ G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_REMOTE_CONTACT,
+ g_param_spec_object ("remote-contact",
+ "The remote contact",
+ "The remote contact is any",
+ EMPATHY_TYPE_CONTACT,
+ G_PARAM_READABLE));
+
+ signals[COMPOSING] =
+ g_signal_new ("composing",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE,
+ 1, G_TYPE_BOOLEAN);
+
+ signals[NEW_MESSAGE] =
+ g_signal_new ("new-message",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1, EMPATHY_TYPE_MESSAGE);
+
+ g_type_class_add_private (object_class, sizeof (EmpathyChatPriv));
}
static gboolean
chat_block_events_timeout_cb (gpointer data)
{
- EmpathyChat *chat = EMPATHY_CHAT (data);
- EmpathyChatPriv *priv = GET_PRIV (chat);
+ EmpathyChatPriv *priv = GET_PRIV (data);
- chat->block_events = FALSE;
priv->block_events_timeout_id = 0;
return FALSE;
}
-void
-empathy_chat_set_tp_chat (EmpathyChat *chat,
- EmpathyTpChat *tp_chat)
+static void
+empathy_chat_init (EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
- TpChan *tp_chan;
-
- g_return_if_fail (EMPATHY_IS_CHAT (chat));
- g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
+ EmpathyChatPriv *priv = GET_PRIV (chat);
- priv = GET_PRIV (chat);
+ priv->log_manager = empathy_log_manager_new ();
+ priv->contacts_width = -1;
+ priv->sent_messages = NULL;
+ priv->sent_messages_index = -1;
+ priv->mc = empathy_mission_control_new ();
- if (tp_chat == priv->tp_chat) {
- return;
- }
+ priv->token = empathy_connect_to_account_status_changed (priv->mc,
+ G_CALLBACK (chat_status_changed_cb),
+ chat, NULL);
/* Block events for some time to avoid having "has come online" or
* "joined" messages. */
- chat->block_events = TRUE;
- if (priv->block_events_timeout_id != 0) {
- g_source_remove (priv->block_events_timeout_id);
- }
priv->block_events_timeout_id =
g_timeout_add_seconds (1, chat_block_events_timeout_cb, chat);
+ /* Add nick name completion */
+ priv->completion = g_completion_new ((GCompletionFunc) empathy_contact_get_name);
+ g_completion_set_compare (priv->completion, chat_contacts_completion_func);
+}
+
+EmpathyChat *
+empathy_chat_new (EmpathyTpChat *tp_chat)
+{
+ return g_object_new (EMPATHY_TYPE_CHAT, "tp-chat", tp_chat, NULL);
+}
+
+EmpathyTpChat *
+empathy_chat_get_tp_chat (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+ return priv->tp_chat;
+}
+
+void
+empathy_chat_set_tp_chat (EmpathyChat *chat,
+ EmpathyTpChat *tp_chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ g_return_if_fail (EMPATHY_IS_CHAT (chat));
+ g_return_if_fail (EMPATHY_IS_TP_CHAT (tp_chat));
+ g_return_if_fail (empathy_tp_chat_is_ready (tp_chat));
+
if (priv->tp_chat) {
- g_signal_handlers_disconnect_by_func (priv->tp_chat,
- chat_message_received_cb,
- chat);
- g_signal_handlers_disconnect_by_func (priv->tp_chat,
- chat_send_error_cb,
- chat);
- g_signal_handlers_disconnect_by_func (priv->tp_chat,
- chat_destroy_cb,
- chat);
- g_object_unref (priv->tp_chat);
+ return;
}
+
if (priv->account) {
g_object_unref (priv->account);
}
- g_free (priv->id);
priv->tp_chat = g_object_ref (tp_chat);
- priv->id = g_strdup (empathy_tp_chat_get_id (tp_chat));
priv->account = g_object_ref (empathy_tp_chat_get_account (tp_chat));
- tp_chan = empathy_tp_chat_get_channel (tp_chat);
- priv->handle_type = tp_chan->handle_type;
-
- if (priv->first_tp_chat) {
- chat_add_logs (chat);
- priv->first_tp_chat = FALSE;
- }
g_signal_connect (tp_chat, "message-received",
G_CALLBACK (chat_message_received_cb),
g_signal_connect (tp_chat, "chat-state-changed",
G_CALLBACK (chat_state_changed_cb),
chat);
+ g_signal_connect (tp_chat, "property-changed",
+ G_CALLBACK (chat_property_changed_cb),
+ chat);
+ g_signal_connect (tp_chat, "members-changed",
+ G_CALLBACK (chat_members_changed_cb),
+ chat);
+ g_signal_connect_swapped (tp_chat, "notify::remote-contact",
+ G_CALLBACK (chat_remote_contact_changed_cb),
+ chat);
g_signal_connect (tp_chat, "destroy",
G_CALLBACK (chat_destroy_cb),
chat);
- if (!priv->sensitive) {
+ chat_remote_contact_changed_cb (chat);
+
+ if (chat->input_text_view) {
gtk_widget_set_sensitive (chat->input_text_view, TRUE);
- empathy_chat_view_append_event (chat->view, _("Connected"));
- priv->sensitive = TRUE;
+ if (priv->block_events_timeout_id == 0) {
+ empathy_chat_view_append_event (chat->view, _("Connected"));
+ }
}
+ empathy_tp_chat_set_acknowledge (priv->tp_chat, TRUE);
+ empathy_tp_chat_emit_pendings (priv->tp_chat);
+
g_object_notify (G_OBJECT (chat), "tp-chat");
+ g_object_notify (G_OBJECT (chat), "id");
+ g_object_notify (G_OBJECT (chat), "account");
+}
+
+McAccount *
+empathy_chat_get_account (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+ return priv->account;
}
const gchar *
empathy_chat_get_id (EmpathyChat *chat)
{
- EmpathyChatPriv *priv;
+ EmpathyChatPriv *priv = GET_PRIV (chat);
- priv = GET_PRIV (chat);
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
return priv->id;
}
-McAccount *
-empathy_chat_get_account (EmpathyChat *chat)
+const gchar *
+empathy_chat_get_name (EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
- return priv->account;
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+ return priv->name;
+}
+
+const gchar *
+empathy_chat_get_subject (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+ return priv->subject;
+}
+
+EmpathyContact *
+empathy_chat_get_remote_contact (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+ return priv->remote_contact;
+}
+
+guint
+empathy_chat_get_members_count (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), 0);
+
+ if (priv->tp_chat) {
+ return empathy_tp_chat_get_members_count (priv->tp_chat);
+ }
+
+ return 0;
+}
+
+GtkWidget *
+empathy_chat_get_contact_menu (EmpathyChat *chat)
+{
+ EmpathyChatPriv *priv = GET_PRIV (chat);
+ GtkWidget *menu = NULL;
+
+ g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
+
+ if (priv->remote_contact) {
+ menu = empathy_contact_menu_new (priv->remote_contact,
+ EMPATHY_CONTACT_FEATURE_CALL |
+ EMPATHY_CONTACT_FEATURE_LOG |
+ EMPATHY_CONTACT_FEATURE_INFO);
+ }
+ else if (priv->contact_list_view) {
+ EmpathyContactListView *view;
+
+ view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
+ menu = empathy_contact_list_view_get_contact_menu (view);
+ }
+
+ return menu;
}
void
gtk_text_buffer_paste_clipboard (buffer, clipboard, NULL, TRUE);
}
-gboolean
-empathy_chat_should_play_sound (EmpathyChat *chat)
-{
- EmpathyChatPriv *priv = GET_PRIV (chat);
- GtkWindow *window;
- gboolean has_focus = FALSE;
-
- g_return_val_if_fail (EMPATHY_IS_CHAT (chat), FALSE);
-
- window = empathy_get_toplevel_window (priv->widget);
- if (window) {
- g_object_get (window, "has-toplevel-focus", &has_focus, NULL);
- }
-
- return !has_focus;
-}
-
-gboolean
-empathy_chat_should_highlight_nick (EmpathyMessage *message)
+void
+empathy_chat_correct_word (EmpathyChat *chat,
+ GtkTextIter *start,
+ GtkTextIter *end,
+ const gchar *new_word)
{
- EmpathyContact *contact;
- const gchar *msg, *to;
- gchar *cf_msg, *cf_to;
- gchar *ch;
- gboolean ret_val;
-
- g_return_val_if_fail (EMPATHY_IS_MESSAGE (message), FALSE);
-
- empathy_debug (DEBUG_DOMAIN, "Highlighting nickname");
-
- ret_val = FALSE;
-
- msg = empathy_message_get_body (message);
- if (!msg) {
- return FALSE;
- }
-
- contact = empathy_message_get_receiver (message);
- if (!contact || !empathy_contact_is_user (contact)) {
- return FALSE;
- }
-
- to = empathy_contact_get_name (contact);
- if (!to) {
- return FALSE;
- }
-
- cf_msg = g_utf8_casefold (msg, -1);
- cf_to = g_utf8_casefold (to, -1);
-
- ch = strstr (cf_msg, cf_to);
- if (ch == NULL) {
- goto finished;
- }
-
- if (ch != cf_msg) {
- /* Not first in the message */
- if ((*(ch - 1) != ' ') &&
- (*(ch - 1) != ',') &&
- (*(ch - 1) != '.')) {
- goto finished;
- }
- }
-
- ch = ch + strlen (cf_to);
- if (ch >= cf_msg + strlen (cf_msg)) {
- ret_val = TRUE;
- goto finished;
- }
+ GtkTextBuffer *buffer;
- if ((*ch == ' ') ||
- (*ch == ',') ||
- (*ch == '.') ||
- (*ch == ':')) {
- ret_val = TRUE;
- goto finished;
- }
+ g_return_if_fail (chat != NULL);
+ g_return_if_fail (new_word != NULL);
-finished:
- g_free (cf_msg);
- g_free (cf_to);
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
- return ret_val;
+ gtk_text_buffer_delete (buffer, start, end);
+ gtk_text_buffer_insert (buffer, start,
+ new_word,
+ -1);
}