EmpathyContactManager *manager;
EmpathyTpChat *tp_chat;
GossipChatWindow *window;
-
GtkTooltips *tooltips;
guint composing_stop_timeout_id;
gboolean sensitive;
gchar *id;
GSList *sent_messages;
gint sent_messages_index;
+ GList *compositors;
+ guint scroll_idle_id;
/* Used to automatically shrink a window that has temporarily
* grown due to long input.
*/
GossipContact *contact,
TelepathyChannelChatState state,
GossipChat *chat);
+static gboolean chat_scroll_down_idle_func (GossipChat *chat);
enum {
COMPOSING,
LAST_SIGNAL
};
-static guint chat_signals[LAST_SIGNAL] = { 0 };
+static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GossipChat, gossip_chat, G_TYPE_OBJECT);
object_class->finalize = chat_finalize;
- chat_signals[COMPOSING] =
+ signals[COMPOSING] =
g_signal_new ("composing",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_TYPE_NONE,
1, G_TYPE_BOOLEAN);
- chat_signals[NEW_MESSAGE] =
+ signals[NEW_MESSAGE] =
g_signal_new ("new-message",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_TYPE_NONE,
2, GOSSIP_TYPE_MESSAGE, G_TYPE_BOOLEAN);
- chat_signals[NAME_CHANGED] =
+ signals[NAME_CHANGED] =
g_signal_new ("name-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
G_TYPE_NONE,
1, G_TYPE_POINTER);
- chat_signals[STATUS_CHANGED] =
+ signals[STATUS_CHANGED] =
g_signal_new ("status-changed",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_LAST,
priv = GET_PRIV (chat);
priv->manager = empathy_contact_manager_new ();
- priv->tooltips = gtk_tooltips_new ();
+ priv->tooltips = g_object_ref_sink (gtk_tooltips_new ());
priv->default_window_height = -1;
priv->vscroll_visible = FALSE;
priv->sensitive = TRUE;
"misspelled",
"underline", PANGO_UNDERLINE_ERROR,
NULL);
+
+
+
+ /* Turn off scrolling temporarily */
+ gossip_chat_view_scroll (chat->view, FALSE);
+#if 0
+FIXME:
+ /* Add messages from last conversation */
+ log_manager = gossip_session_get_log_manager (gossip_app_get_session ());
+ messages = gossip_log_get_last_for_contact (log_manager, priv->contact);
+ num_messages = g_list_length (messages);
+
+ for (l = messages, i = 0; l; l = l->next, i++) {
+ message = l->data;
+
+ if (num_messages - i > 10) {
+ continue;
+ }
+
+ sender = gossip_message_get_sender (message);
+ if (gossip_contact_equal (priv->own_contact, sender)) {
+ gossip_chat_view_append_message_from_self (view,
+ message,
+ priv->own_contact,
+ priv->own_avatar);
+ } else {
+ gossip_chat_view_append_message_from_other (view,
+ message,
+ sender,
+ priv->other_avatar);
+ }
+ }
+
+ g_list_foreach (messages, (GFunc) g_object_unref, NULL);
+ g_list_free (messages);
+#endif
+ /* Turn back on scrolling */
+ gossip_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
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 (chat->account);
g_object_unref (priv->manager);
+ g_object_unref (priv->tooltips);
if (priv->tp_chat) {
g_object_unref (priv->tp_chat);
}
+ if (priv->scroll_idle_id) {
+ g_source_remove (priv->scroll_idle_id);
+ }
+
g_free (priv->id);
G_OBJECT_CLASS (gossip_chat_parent_class)->finalize (object);
return;
}
+ /* FIXME: add here something to let group/privrate chat handle
+ * some special messages */
+
/* FIXME: gossip_app_set_not_away ();*/
- own_contact = gossip_chat_get_own_contact (chat);
+ own_contact = empathy_contact_manager_get_user (priv->manager, chat->account);
message = gossip_message_new (msg);
gossip_message_set_sender (message, own_contact);
// FIXME: gossip_sound_play (GOSSIP_SOUND_CHAT);
}
- g_signal_emit_by_name (chat, "new-message", message, FALSE);
+ g_signal_emit (chat, signals[NEW_MESSAGE], 0, message, FALSE);
}
void
}
/* Catch enter but not ctrl/shift-enter */
- if (IS_ENTER (event->keyval) && !(event->state & GDK_SHIFT_MASK)) {
+ if (IS_ENTER (event->keyval) && !(event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
GtkTextView *view;
/* This is to make sure that kinput2 gets the enter. And if
text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
- if (IS_ENTER (event->keyval) && (event->state & GDK_SHIFT_MASK)) {
+ if (IS_ENTER (event->keyval) && (event->state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))) {
/* Newline for shift-enter. */
return FALSE;
}
TelepathyChannelChatState state,
GossipChat *chat)
{
- /* FIXME: not yet implemented */
+ GossipChatPriv *priv;
+ GossipContact *own_contact;
+ GList *l;
+ gboolean was_composing;
+
+ priv = GET_PRIV (chat);
+
+ own_contact = gossip_contact_get_user (contact);
+ if (gossip_contact_equal (own_contact, contact)) {
+ /* We don't care about our own chat state */
+ return;
+ }
+
+ was_composing = (priv->compositors != NULL);
+
+ /* Find the contact in the list. After that l is the list elem or NULL */
+ for (l = priv->compositors; l; l = l->next) {
+ if (gossip_contact_equal (contact, l->data)) {
+ break;
+ }
+ }
+
+ switch (state) {
+ case TP_CHANNEL_CHAT_STATE_GONE:
+ case TP_CHANNEL_CHAT_STATE_INACTIVE:
+ case TP_CHANNEL_CHAT_STATE_ACTIVE:
+ /* Contact is not composing */
+ if (l) {
+ priv->compositors = g_list_remove_link (priv->compositors, l);
+ g_object_unref (l->data);
+ g_list_free1 (l);
+ }
+ break;
+ case TP_CHANNEL_CHAT_STATE_PAUSED:
+ case TP_CHANNEL_CHAT_STATE_COMPOSING:
+ /* Contact is composing */
+ if (!l) {
+ priv->compositors = g_list_prepend (priv->compositors,
+ g_object_ref (contact));
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+
+ gossip_debug (DEBUG_DOMAIN, "Was composing: %s now composing: %s",
+ was_composing ? "yes" : "no",
+ priv->compositors ? "yes" : "no");
+
+ if ((was_composing && !priv->compositors) ||
+ (!was_composing && priv->compositors)) {
+ /* Composing state changed */
+ g_signal_emit (chat, signals[COMPOSING], 0,
+ (gboolean) priv->compositors);
+ }
+}
+
+/* Scroll down after the back-log has been received. */
+static gboolean
+chat_scroll_down_idle_func (GossipChat *chat)
+{
+ GossipChatPriv *priv;
+
+ priv = GET_PRIV (chat);
+
+ gossip_chat_scroll_down (chat);
+ g_object_unref (chat);
+
+ priv->scroll_idle_id = 0;
+
+ return FALSE;
}
gboolean
return NULL;
}
-GossipContact *
-gossip_chat_get_contact (GossipChat *chat)
-{
- g_return_val_if_fail (GOSSIP_IS_CHAT (chat), NULL);
-
- if (GOSSIP_CHAT_GET_CLASS (chat)->get_contact) {
- return GOSSIP_CHAT_GET_CLASS (chat)->get_contact (chat);
- }
-
- return NULL;
-}
-GossipContact *
-gossip_chat_get_own_contact (GossipChat *chat)
-{
- GossipChatPriv *priv;
-
- g_return_val_if_fail (GOSSIP_IS_CHAT (chat), NULL);
-
- priv = GET_PRIV (chat);
-
- return empathy_contact_manager_get_own (priv->manager, chat->account);
-}
-
GtkWidget *
gossip_chat_get_widget (GossipChat *chat)
{
return (priv->tp_chat != NULL);
}
-gboolean
-gossip_chat_get_show_contacts (GossipChat *chat)
-{
- g_return_val_if_fail (GOSSIP_IS_CHAT (chat), FALSE);
-
- if (GOSSIP_CHAT_GET_CLASS (chat)->get_show_contacts) {
- return GOSSIP_CHAT_GET_CLASS (chat)->get_show_contacts (chat);
- }
-
- return FALSE;
-}
-
-void
-gossip_chat_set_show_contacts (GossipChat *chat,
- gboolean show)
-{
- g_return_if_fail (GOSSIP_IS_CHAT (chat));
-
- if (GOSSIP_CHAT_GET_CLASS (chat)->set_show_contacts) {
- GOSSIP_CHAT_GET_CLASS (chat)->set_show_contacts (chat, show);
- }
-}
-
void
gossip_chat_save_geometry (GossipChat *chat,
gint x,
return FALSE;
}
- my_contact = gossip_get_own_contact_from_contact (gossip_message_get_sender (message));
+ my_contact = gossip_contact_get_user (gossip_message_get_sender (message));
to = gossip_contact_get_name (my_contact);
if (!to) {
return FALSE;