[ekiga] Made the ConversationPage manage its title itself and cleaned the code



commit ff838542d74ab295f05174ef4dda7d7cb77d3a73
Author: Julien Puydt <jpuydt free fr>
Date:   Thu Feb 27 21:54:46 2014 +0100

    Made the ConversationPage manage its title itself and cleaned the code

 lib/engine/gui/gtk-frontend/conversation-page.cpp |   34 ++++++++++++++++----
 lib/engine/gui/gtk-frontend/conversation-page.h   |    8 ++--
 2 files changed, 31 insertions(+), 11 deletions(-)
---
diff --git a/lib/engine/gui/gtk-frontend/conversation-page.cpp 
b/lib/engine/gui/gtk-frontend/conversation-page.cpp
index 2db0bee..b2e53f5 100644
--- a/lib/engine/gui/gtk-frontend/conversation-page.cpp
+++ b/lib/engine/gui/gtk-frontend/conversation-page.cpp
@@ -47,6 +47,7 @@ struct _ConversationPagePrivate {
   Ekiga::scoped_connections connections;
   GtkWidget* area;
   GtkWidget* heapview;
+  gchar* title;
 };
 
 enum {
@@ -58,7 +59,6 @@ static guint signals[LAST_SIGNAL] = {0,};
 
 G_DEFINE_TYPE (ConversationPage, conversation_page, GTK_TYPE_BOX);
 
-
 static void
 on_conversation_updated (ConversationPage* self)
 {
@@ -75,10 +75,28 @@ on_page_grab_focus (GtkWidget* widget,
 }
 
 static void
+conversation_page_update_title (ConversationPage* self)
+{
+  g_free (self->priv->title);
+  guint unread_count = self->priv->conversation->get_unread_messages_count ();
+  if (unread_count > 0) {
+
+    self->priv->title = g_strdup_printf ("[%d] %s",
+                                        unread_count,
+                                        self->priv->conversation->get_title ().c_str ());
+  } else {
+
+    self->priv->title = g_strdup_printf ("%s",
+                                        self->priv->conversation->get_title ().c_str ());
+  }
+}
+
+static void
 conversation_page_finalize (GObject* obj)
 {
   ConversationPage* self = (ConversationPage*)obj;
 
+  g_free (self->priv->title);
   delete self->priv;
 
   G_OBJECT_CLASS (conversation_page_parent_class)->finalize (obj);
@@ -121,6 +139,8 @@ conversation_page_new (Ekiga::ConversationPtr conversation)
   result = (ConversationPage*)g_object_new (TYPE_CONVERSATION_PAGE, NULL);
 
   result->priv->conversation = conversation;
+  result->priv->title = NULL;
+  conversation_page_update_title (result);
 
   result->priv->connections.add (conversation->updated.connect (boost::bind (&on_conversation_updated, 
result)));
 
@@ -141,17 +161,17 @@ conversation_page_new (Ekiga::ConversationPtr conversation)
 }
 
 const gchar*
-conversation_page_get_title (GtkWidget* widget)
+conversation_page_get_title (ConversationPage* page)
 {
-  g_return_val_if_fail (IS_CONVERSATION_PAGE (widget), NULL);
+  g_return_val_if_fail (IS_CONVERSATION_PAGE (page), NULL);
 
-  return ((ConversationPage*)widget)->priv->conversation->get_title().c_str();
+  return page->priv->title;
 }
 
 guint
-conversation_page_get_unread_count (GtkWidget* widget)
+conversation_page_get_unread_count (ConversationPage* page)
 {
-  g_return_val_if_fail (IS_CONVERSATION_PAGE (widget), 0);
+  g_return_val_if_fail (IS_CONVERSATION_PAGE (page), 0);
 
-  return ((ConversationPage*)widget)->priv->conversation->get_unread_messages_count ();
+  return page->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 f498b48..8334460 100644
--- a/lib/engine/gui/gtk-frontend/conversation-page.h
+++ b/lib/engine/gui/gtk-frontend/conversation-page.h
@@ -44,16 +44,16 @@
 G_BEGIN_DECLS
 
 /* public api */
+typedef struct _ConversationPage ConversationPage;
 
 GtkWidget* conversation_page_new (Ekiga::ConversationPtr conversation);
 
-const gchar* conversation_page_get_title (GtkWidget* page);
+const gchar* conversation_page_get_title (ConversationPage* page);
 
-guint conversation_page_get_unread_count (GtkWidget* page);
+guint conversation_page_get_unread_count (ConversationPage* page);
 
 /* GObject boilerplate */
 
-typedef struct _ConversationPage ConversationPage;
 typedef struct _ConversationPagePrivate ConversationPagePrivate;
 typedef struct _ConversationPageClass ConversationPageClass;
 
@@ -77,7 +77,7 @@ struct _ConversationPageClass {
 #define IS_CONVERSATION_PAGE_CLASS(klass)  (G_TYPE_CHECK_CLASS_TYPE((klass),TYPE_CONVERSATION_PAGE))
 #define CONVERSATION_PAGE_GET_CLASS(obj)   
(G_TYPE_INSTANCE_GET_CLASS((obj),TYPE_CONVERSATION_PAGE,ConversationPageClass))
 
-GType multiple_chat_page_get_type () G_GNUC_CONST;
+GType conversation_page_get_type () G_GNUC_CONST;
 
 G_END_DECLS
 


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