[ekiga] Made the conversation page widget richer



commit d0eb0ddbbdaedfd416d0d042394c0db98ebf868d
Author: Julien Puydt <jpuydt free fr>
Date:   Wed Feb 26 10:25:48 2014 +0100

    Made the conversation page widget richer
    
    It shouldn't leak anymore, as it now properly manages
    its private structure.
    
    It has a richer api, with an "updated" signal which will allow
    the chat window to follow changes of title or in the number
    of unread messages.

 lib/engine/gui/gtk-frontend/conversation-page.cpp |   75 ++++++++++++++++++---
 lib/engine/gui/gtk-frontend/conversation-page.h   |    7 ++
 2 files changed, 72 insertions(+), 10 deletions(-)
---
diff --git a/lib/engine/gui/gtk-frontend/conversation-page.cpp 
b/lib/engine/gui/gtk-frontend/conversation-page.cpp
index 748fe2a..2db0bee 100644
--- a/lib/engine/gui/gtk-frontend/conversation-page.cpp
+++ b/lib/engine/gui/gtk-frontend/conversation-page.cpp
@@ -39,39 +39,74 @@
 #include "chat-area.h"
 #include "heap-view.h"
 
+#include "scoped-connections.h"
+
 struct _ConversationPagePrivate {
+
+  Ekiga::ConversationPtr conversation;
+  Ekiga::scoped_connections connections;
   GtkWidget* area;
   GtkWidget* heapview;
 };
 
+enum {
+  UPDATED_SIGNAL,
+  LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = {0,};
+
 G_DEFINE_TYPE (ConversationPage, conversation_page, GTK_TYPE_BOX);
 
-static void on_page_grab_focus (GtkWidget*,
-                               gpointer);
 
-static void on_page_grab_focus (GtkWidget* widget,
-                               G_GNUC_UNUSED gpointer data)
+static void
+on_conversation_updated (ConversationPage* self)
 {
-  ConversationPage* self = NULL;
+  g_signal_emit (self, signals[UPDATED_SIGNAL], 0);
+}
 
-  self = (ConversationPage*)widget;
+static void
+on_page_grab_focus (GtkWidget* widget,
+                   G_GNUC_UNUSED gpointer data)
+{
+  ConversationPage* self = (ConversationPage*)widget;
 
-  if (self->priv->area)
-    gtk_widget_grab_focus (self->priv->area);
+  gtk_widget_grab_focus (self->priv->area);
+}
+
+static void
+conversation_page_finalize (GObject* obj)
+{
+  ConversationPage* self = (ConversationPage*)obj;
+
+  delete self->priv;
+
+  G_OBJECT_CLASS (conversation_page_parent_class)->finalize (obj);
 }
 
 static void
 conversation_page_init (ConversationPage* self)
 {
-  self->priv = g_new0 (ConversationPagePrivate, 1);
+  self->priv = new ConversationPagePrivate;
 
   g_signal_connect (self, "grab-focus",
                     G_CALLBACK (on_page_grab_focus), NULL);
 }
 
 static void
-conversation_page_class_init (G_GNUC_UNUSED ConversationPageClass* klass)
+conversation_page_class_init (ConversationPageClass* klass)
 {
+  GObjectClass* gobject_class = G_OBJECT_CLASS (klass);
+
+  gobject_class->finalize = conversation_page_finalize;
+
+  signals[UPDATED_SIGNAL] =
+    g_signal_new ("updated", G_OBJECT_CLASS_TYPE (gobject_class),
+                 G_SIGNAL_RUN_LAST,
+                 G_STRUCT_OFFSET (ConversationPageClass, updated),
+                 NULL, NULL,
+                 g_cclosure_marshal_VOID__VOID,
+                 G_TYPE_NONE, 0);
 }
 
 /* implementation of the public api */
@@ -85,6 +120,10 @@ conversation_page_new (Ekiga::ConversationPtr conversation)
 
   result = (ConversationPage*)g_object_new (TYPE_CONVERSATION_PAGE, NULL);
 
+  result->priv->conversation = conversation;
+
+  result->priv->connections.add (conversation->updated.connect (boost::bind (&on_conversation_updated, 
result)));
+
   area = chat_area_new (conversation);
   result->priv->area = area;
   gtk_box_pack_start (GTK_BOX (result), area,
@@ -100,3 +139,19 @@ conversation_page_new (Ekiga::ConversationPtr conversation)
 
   return GTK_WIDGET (result);
 }
+
+const gchar*
+conversation_page_get_title (GtkWidget* widget)
+{
+  g_return_val_if_fail (IS_CONVERSATION_PAGE (widget), NULL);
+
+  return ((ConversationPage*)widget)->priv->conversation->get_title().c_str();
+}
+
+guint
+conversation_page_get_unread_count (GtkWidget* widget)
+{
+  g_return_val_if_fail (IS_CONVERSATION_PAGE (widget), 0);
+
+  return ((ConversationPage*)widget)->priv->conversation->get_unread_messages_count ();
+}
diff --git a/lib/engine/gui/gtk-frontend/conversation-page.h b/lib/engine/gui/gtk-frontend/conversation-page.h
index 0073f2f..f498b48 100644
--- a/lib/engine/gui/gtk-frontend/conversation-page.h
+++ b/lib/engine/gui/gtk-frontend/conversation-page.h
@@ -47,6 +47,10 @@ G_BEGIN_DECLS
 
 GtkWidget* conversation_page_new (Ekiga::ConversationPtr conversation);
 
+const gchar* conversation_page_get_title (GtkWidget* page);
+
+guint conversation_page_get_unread_count (GtkWidget* page);
+
 /* GObject boilerplate */
 
 typedef struct _ConversationPage ConversationPage;
@@ -61,6 +65,9 @@ struct _ConversationPage {
 
 struct _ConversationPageClass {
   GtkBoxClass parent_class;
+
+  /* signals */
+  void (*updated) (ConversationPage* self); // allows tracking unread counts
 };
 
 #define TYPE_CONVERSATION_PAGE             (conversation_page_get_type())


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]