[gnome-chat] embed: Show the conversations with each contact
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chat] embed: Show the conversations with each contact
- Date: Tue, 10 Sep 2013 17:03:04 +0000 (UTC)
commit cf65f56560052e9aaf12de0de84280d8a972da3f
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Sep 10 18:53:53 2013 +0200
embed: Show the conversations with each contact
src/chat-embed.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++++++
src/chat-embed.ui | 7 +++
2 files changed, 135 insertions(+), 0 deletions(-)
---
diff --git a/src/chat-embed.c b/src/chat-embed.c
index e615300..dcee903 100644
--- a/src/chat-embed.c
+++ b/src/chat-embed.c
@@ -21,7 +21,11 @@
#include "config.h"
+#include <telepathy-glib/telepathy-glib.h>
+#include <telepathy-logger/telepathy-logger.h>
+
#include "chat-application.h"
+#include "chat-conversation-view.h"
#include "chat-conversations-list.h"
#include "chat-embed.h"
#include "chat-main-toolbar.h"
@@ -30,9 +34,14 @@
struct _ChatEmbedPrivate
{
+ GHashTable *conversations;
GtkSizeGroup *size_group_left;
+ GtkWidget *conversations_list;
+ GtkWidget *current_view;
+ GtkWidget *conversations_stack;
GtkWidget *sidebar_frame;
GtkWidget *toolbar;
+ TplLogManager *lm;
};
static void chat_embed_buildable_init (GtkBuildableIface *iface);
@@ -45,6 +54,110 @@ G_DEFINE_TYPE_WITH_CODE (ChatEmbed, chat_embed, GTK_TYPE_BOX,
static void
+chat_embed_ensure_new_line (ChatEmbed *self)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
+ gint offset;
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self->priv->current_view));
+ gtk_text_buffer_get_end_iter (buffer, &iter);
+ offset = gtk_text_iter_get_line_offset (&iter);
+ if (offset != 0)
+ gtk_text_buffer_insert (buffer, &iter, "\n", -1);
+}
+
+
+static void
+chat_embed_get_filtered_events (GObject *source_object, GAsyncResult *res, gpointer user_data)
+{
+ ChatEmbed *self = CHAT_EMBED (user_data);
+ ChatEmbedPrivate *priv = self->priv;
+ GError *error;
+ GList *events;
+ GList *l;
+ GtkTextBuffer *buffer;
+
+ gtk_widget_set_sensitive (priv->conversations_list, TRUE);
+
+ error = NULL;
+ if (!tpl_log_manager_get_filtered_events_finish (priv->lm, res, &events, &error))
+ {
+ g_warning ("Unable to get events: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->current_view));
+
+ for (l = events; l != NULL; l = l->next)
+ {
+ TplEvent *event = TPL_EVENT (l->data);
+ GtkTextIter iter;
+ const gchar *message;
+
+ chat_embed_ensure_new_line (self);
+ gtk_text_buffer_get_end_iter (buffer, &iter);
+ message = tpl_text_event_get_message (TPL_TEXT_EVENT (event));
+ gtk_text_buffer_insert (buffer, &iter, message, -1);
+ }
+
+ out:
+ g_object_unref (self);
+}
+
+
+static void
+chat_embed_row_activated (ChatEmbed *self, GtkListBoxRow *row)
+{
+ ChatEmbedPrivate *priv = self->priv;
+ GtkWidget *sw;
+ TpAccount *account;
+ TpContact *contact;
+ TplEntity *entity;
+ const gchar *identifier;
+
+ contact = g_object_get_data (G_OBJECT (row), "chat-conversations-list-contact");
+
+ identifier = tp_contact_get_identifier (contact);
+ priv->current_view = g_hash_table_lookup (priv->conversations, identifier);
+ if (priv->current_view != NULL)
+ goto out;
+
+ gtk_widget_set_sensitive (priv->conversations_list, FALSE);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+ gtk_stack_add_named (GTK_STACK (priv->conversations_stack), sw, identifier);
+ gtk_widget_show (sw);
+
+ priv->current_view = chat_conversation_view_new ();
+ gtk_container_add (GTK_CONTAINER (sw), priv->current_view);
+ g_hash_table_insert (priv->conversations, g_strdup (identifier), g_object_ref (priv->current_view));
+
+ account = tp_contact_get_account (contact);
+ entity = tpl_entity_new_from_tp_contact (contact, TPL_ENTITY_CONTACT);
+ if (tpl_log_manager_exists (priv->lm, account, entity, TPL_EVENT_MASK_TEXT))
+ {
+ tpl_log_manager_get_filtered_events_async (priv->lm,
+ account,
+ entity,
+ TPL_EVENT_MASK_TEXT,
+ 20,
+ NULL,
+ NULL,
+ chat_embed_get_filtered_events,
+ g_object_ref (self));
+ }
+
+ g_object_unref (entity);
+
+ out:
+ gtk_stack_set_visible_child_name (GTK_STACK (priv->conversations_stack), identifier);
+}
+
+
+static void
chat_embed_window_added (ChatEmbed *self, GtkWindow *window)
{
gtk_window_set_titlebar (window, self->priv->toolbar);
@@ -57,7 +170,14 @@ chat_embed_dispose (GObject *object)
ChatEmbed *self = CHAT_EMBED (object);
ChatEmbedPrivate *priv = self->priv;
+ if (priv->conversations != NULL)
+ {
+ g_hash_table_unref (priv->conversations);
+ priv->conversations = NULL;
+ }
+
g_clear_object (&priv->size_group_left);
+ g_clear_object (&priv->lm);
G_OBJECT_CLASS (chat_embed_parent_class)->dispose (object);
}
@@ -75,6 +195,10 @@ chat_embed_init (ChatEmbed *self)
gtk_widget_init_template (GTK_WIDGET (self));
+ priv->conversations = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
+
+ priv->lm = tpl_log_manager_dup_singleton ();
+
app = chat_application_new ();
g_signal_connect_swapped (app, "window-added", G_CALLBACK (chat_embed_window_added), self);
g_object_unref (app);
@@ -85,6 +209,8 @@ chat_embed_init (ChatEmbed *self)
priv->size_group_left = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_size_group_add_widget (priv->size_group_left, priv->sidebar_frame);
gtk_size_group_add_widget (priv->size_group_left, toolbar_left);
+
+ g_signal_connect_swapped (priv->conversations_list, "row-activated", G_CALLBACK
(chat_embed_row_activated), self);
}
@@ -99,6 +225,8 @@ chat_embed_class_init (ChatEmbedClass *class)
g_type_ensure (CHAT_TYPE_CONVERSATIONS_LIST);
g_type_ensure (POLARI_TYPE_FIXED_SIZE_FRAME);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/chat/embed.ui");
+ gtk_widget_class_bind_template_child_private (widget_class, ChatEmbed, conversations_list);
+ gtk_widget_class_bind_template_child_private (widget_class, ChatEmbed, conversations_stack);
gtk_widget_class_bind_template_child_private (widget_class, ChatEmbed, sidebar_frame);
}
diff --git a/src/chat-embed.ui b/src/chat-embed.ui
index 662cd53..974fff2 100644
--- a/src/chat-embed.ui
+++ b/src/chat-embed.ui
@@ -60,6 +60,13 @@
<property name="hexpand">True</property>
<property name="orientation">vertical</property>
<property name="visible">True</property>
+ <child>
+ <object class="GtkStack" id="conversations_stack">
+ <property name="can_focus">False</property>
+ <property name="transition_type">crossfade</property>
+ <property name="visible">True</property>
+ </object>
+ </child>
</object>
<packing>
<property name="expand">True</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]