/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
* Copyright (C) 2002-2007 Imendio AB
+ * Copyright (C) 2007 Collabora Ltd.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* Richard Hult <richard@imendio.com>
* Martyn Russell <martyn@imendio.com>
* Geert-Jan Van den Bogaerde <geertjan@gnome.org>
+ * Xavier Claessens <xclaesse@gmail.com>
*/
#include "config.h"
#include "gossip-chat.h"
#include "gossip-chat-window.h"
-//#include "gossip-geometry.h"
+#include "gossip-geometry.h"
#include "gossip-preferences.h"
#include "gossip-spell.h"
//#include "gossip-spell-dialog.h"
GtkTooltips *tooltips;
guint composing_stop_timeout_id;
gboolean sensitive;
+ gchar *id;
+ GSList *sent_messages;
+ gint sent_messages_index;
/* Used to automatically shrink a window that has temporarily
* grown due to long input.
*/
static void chat_message_received_cb (EmpathyTpChat *tp_chat,
GossipMessage *message,
GossipChat *chat);
+void chat_sent_message_add (GossipChat *chat,
+ const gchar *str);
+const gchar * chat_sent_message_get_next (GossipChat *chat);
+const gchar * chat_sent_message_get_last (GossipChat *chat);
static gboolean chat_input_key_press_event_cb (GtkWidget *widget,
GdkEventKey *event,
GossipChat *chat);
priv->default_window_height = -1;
priv->vscroll_visible = FALSE;
priv->sensitive = TRUE;
+ priv->sent_messages = NULL;
+ priv->sent_messages_index = -1;
g_signal_connect (chat->input_text_view,
"key_press_event",
gossip_debug (DEBUG_DOMAIN, "Finalized: %p", object);
+ g_slist_foreach (priv->sent_messages, (GFunc) g_free, NULL);
+ g_slist_free (priv->sent_messages);
+
chat_composing_remove_timeout (chat);
g_object_unref (GOSSIP_CHAT (object)->account);
g_object_unref (priv->tp_chat);
}
+ g_free (priv->id);
+
G_OBJECT_CLASS (gossip_chat_parent_class)->finalize (object);
}
priv = GET_PRIV (chat);
- if (msg == NULL || msg[0] == '\0') {
+ if (G_STR_EMPTY (msg)) {
return;
}
+ chat_sent_message_add (chat, msg);
+
if (g_str_has_prefix (msg, "/clear")) {
gossip_chat_view_clear (chat->view);
return;
g_signal_emit_by_name (chat, "new-message", message);
}
+void
+chat_sent_message_add (GossipChat *chat,
+ const gchar *str)
+{
+ GossipChatPriv *priv;
+ GSList *list;
+ GSList *item;
+
+ priv = GET_PRIV (chat);
+
+ /* Save the sent message in our repeat buffer */
+ list = priv->sent_messages;
+
+ /* Remove any other occurances of this msg */
+ while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) {
+ list = g_slist_remove_link (list, item);
+ g_free (item->data);
+ g_slist_free1 (item);
+ }
+
+ /* Trim the list to the last 10 items */
+ while (g_slist_length (list) > 10) {
+ item = g_slist_last (list);
+ if (item) {
+ list = g_slist_remove_link (list, item);
+ g_free (item->data);
+ g_slist_free1 (item);
+ }
+ }
+
+ /* Add new message */
+ list = g_slist_prepend (list, g_strdup (str));
+
+ /* Set list and reset the index */
+ priv->sent_messages = list;
+ priv->sent_messages_index = -1;
+}
+
+const gchar *
+chat_sent_message_get_next (GossipChat *chat)
+{
+ GossipChatPriv *priv;
+ gint max;
+
+ priv = GET_PRIV (chat);
+
+ if (!priv->sent_messages) {
+ gossip_debug (DEBUG_DOMAIN,
+ "No sent messages, next message is NULL");
+ return NULL;
+ }
+
+ max = g_slist_length (priv->sent_messages) - 1;
+
+ if (priv->sent_messages_index < max) {
+ priv->sent_messages_index++;
+ }
+
+ gossip_debug (DEBUG_DOMAIN,
+ "Returning next message index:%d",
+ priv->sent_messages_index);
+
+ return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
+}
+
+const gchar *
+chat_sent_message_get_last (GossipChat *chat)
+{
+ GossipChatPriv *priv;
+
+ g_return_val_if_fail (GOSSIP_IS_CHAT (chat), NULL);
+
+ priv = GET_PRIV (chat);
+
+ if (!priv->sent_messages) {
+ gossip_debug (DEBUG_DOMAIN,
+ "No sent messages, last message is NULL");
+ return NULL;
+ }
+
+ if (priv->sent_messages_index >= 0) {
+ priv->sent_messages_index--;
+ }
+
+ gossip_debug (DEBUG_DOMAIN,
+ "Returning last message index:%d",
+ priv->sent_messages_index);
+
+ return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
+}
+
static gboolean
chat_input_key_press_event_cb (GtkWidget *widget,
GdkEventKey *event,
return TRUE;
}
+ /* Catch ctrl+up/down so we can traverse messages we sent */
+ if ((event->state & GDK_CONTROL_MASK) &&
+ (event->keyval == GDK_Up ||
+ event->keyval == GDK_Down)) {
+ GtkTextBuffer *buffer;
+ const gchar *str;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (chat->input_text_view));
+
+ if (event->keyval == GDK_Up) {
+ str = chat_sent_message_get_next (chat);
+ } else {
+ str = chat_sent_message_get_last (chat);
+ }
+
+ g_signal_handlers_block_by_func (buffer,
+ chat_input_text_buffer_changed_cb,
+ chat);
+ gtk_text_buffer_set_text (buffer, str ? str : "", -1);
+ g_signal_handlers_unblock_by_func (buffer,
+ chat_input_text_buffer_changed_cb,
+ chat);
+
+ return TRUE;
+ }
+
/* Catch enter but not ctrl/shift-enter */
if (IS_ENTER (event->keyval) && !(event->state & GDK_SHIFT_MASK)) {
GtkTextView *view;
}
text_view_sw = gtk_widget_get_parent (GTK_WIDGET (chat->view));
+
if (IS_ENTER (event->keyval) && (event->state & GDK_SHIFT_MASK)) {
/* Newline for shift-enter. */
return FALSE;
gint w,
gint h)
{
- //FIXME: gossip_geometry_save_for_chat (chat, x, y, w, h);
+ gossip_geometry_save (gossip_chat_get_id (chat), x, y, w, h);
}
void
gint *w,
gint *h)
{
- //FIXME: gossip_geometry_load_for_chat (chat, x, y, w, h);
+ gossip_geometry_load (gossip_chat_get_id (chat), x, y, w, h);
}
void
g_object_unref (priv->tp_chat);
}
+ g_free (priv->id);
priv->tp_chat = g_object_ref (tp_chat);
+ priv->id = g_strdup (empathy_tp_chat_get_id (tp_chat));
g_signal_connect (tp_chat, "message-received",
G_CALLBACK (chat_message_received_cb),
}
}
+const gchar *
+gossip_chat_get_id (GossipChat *chat)
+{
+ GossipChatPriv *priv;
+
+ priv = GET_PRIV (chat);
+
+ return priv->id;
+}
+
void
gossip_chat_clear (GossipChat *chat)
{