[ekiga] Switched the chat window from using GtkNotebook to GtkStack



commit b85ca8fec1409e8bfcff60d6cf10ce1118019522
Author: Julien Puydt <jpuydt free fr>
Date:   Thu Feb 27 21:55:08 2014 +0100

    Switched the chat window from using GtkNotebook to GtkStack

 lib/engine/gui/gtk-frontend/chat-window.cpp |  160 ++++----------------------
 1 files changed, 25 insertions(+), 135 deletions(-)
---
diff --git a/lib/engine/gui/gtk-frontend/chat-window.cpp b/lib/engine/gui/gtk-frontend/chat-window.cpp
index 8231904..5547186 100644
--- a/lib/engine/gui/gtk-frontend/chat-window.cpp
+++ b/lib/engine/gui/gtk-frontend/chat-window.cpp
@@ -35,6 +35,8 @@
  *
  */
 
+#include <sstream>
+
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
 
@@ -53,7 +55,7 @@ struct _ChatWindowPrivate
   boost::shared_ptr<Ekiga::NotificationCore> notification_core;
   Ekiga::scoped_connections connections;
 
-  GtkWidget* notebook;
+  GtkWidget* stack;
 };
 
 enum {
@@ -71,58 +73,37 @@ G_DEFINE_TYPE (ChatWindow, chat_window, GM_TYPE_WINDOW);
 static bool on_handle_questions (ChatWindow* self,
                                 Ekiga::FormRequestPtr request);
 
-static void on_close_button_clicked (GtkButton* button,
-                                    gpointer data);
-
-static void on_escaped (GtkWidget *widget,
-                        gpointer data);
-
-static void on_switch_page (GtkNotebook* notebook,
-                           gpointer page_,
-                           guint num,
-                           gpointer data);
-
 static bool on_dialect_added (ChatWindow* self,
                              Ekiga::DialectPtr dialect);
 static bool on_conversation_added (ChatWindow* self,
                                   Ekiga::ConversationPtr conversation);
 static void on_some_conversation_user_requested (ChatWindow* self,
-                                                GtkWidget* page);
+                                                const std::string name);
 
 static void show_chat_window_cb (ChatWindow *self);
 
 /* helper (implementation) */
 
 static void
-on_updated (G_GNUC_UNUSED ConversationPage* page_,
+on_updated (ConversationPage* page,
            gpointer data)
 {
   ChatWindow* self = (ChatWindow*)data;
   guint unread_count = 0;
 
-  for (gint ii = 0;
-       ii < gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->priv->notebook)) ;
-       ii++) {
-
-    GtkWidget* page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (self->priv->notebook), ii);
-    guint page_unread_count = conversation_page_get_unread_count (page);
-    GtkWidget* hbox = gtk_notebook_get_tab_label (GTK_NOTEBOOK (self->priv->notebook), page);
-    GtkWidget* label = GTK_WIDGET (g_object_get_data (G_OBJECT (hbox), "label-widget"));
-    const gchar* base_title = conversation_page_get_title (page);
+  gtk_container_child_set (GTK_CONTAINER (self->priv->stack), GTK_WIDGET (page),
+                          "title", conversation_page_get_title (page),
+                          NULL);
 
-    unread_count = unread_count + page_unread_count;
+  GList* pages = gtk_container_get_children (GTK_CONTAINER (self->priv->stack));
 
-    if (page_unread_count > 0) {
+  for (GList* ptr = pages; ptr != NULL; ptr = ptr->next) {
 
-      gchar* title = g_strdup_printf ("[%d] %s", page_unread_count, base_title);
-      gtk_label_set_text (GTK_LABEL (label), title);
-      g_free (title);
-    } else {
-
-      gtk_label_set_text (GTK_LABEL (label), base_title);
-    }
+    unread_count += conversation_page_get_unread_count ((ConversationPage*)ptr->data);
   }
 
+  g_list_free (pages);
+
   g_signal_emit (self, signals[UNREAD_COUNT], 0, unread_count);
   g_signal_emit (self, signals[UNREAD_ALERT], 0, NULL);
 
@@ -149,60 +130,6 @@ static bool on_handle_questions (ChatWindow* self,
   return true;
 }
 
-static void
-on_close_button_clicked (GtkButton* button,
-                        gpointer data)
-{
-  ChatWindow* self = (ChatWindow*)data;
-  GtkWidget* page = NULL;
-  gint num = 0;
-
-  page = (GtkWidget*)g_object_get_data (G_OBJECT (button), "page-widget");
-  num = gtk_notebook_page_num (GTK_NOTEBOOK (self->priv->notebook), page);
-
-  /* FIXME: we add a page when the conversation is added ; ok. But if
-   * we get rid of the page here, then if the same conversation is
-   * still alive and kicking, we have no way to add a corresponding
-   * page again. So there's something lacking in our API: how does one
-   * close an Ekiga::Conversation?
-   *
-   */
-  g_print ("FIXME %s\n", __PRETTY_FUNCTION__);
-  num = num + 1; // FIXME: just to stop a warning
-  //  gtk_notebook_remove_page (GTK_NOTEBOOK (self->priv->notebook), num);
-
-  if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->priv->notebook)) == 0)
-    gtk_widget_hide (GTK_WIDGET (self));
-}
-
-static void
-on_escaped (GtkWidget */*widget*/,
-            gpointer data)
-{
-  ChatWindow* self = (ChatWindow*)data;
-  gint num = 0;
-
-  num = gtk_notebook_get_current_page (GTK_NOTEBOOK (self->priv->notebook));
-  gtk_notebook_remove_page (GTK_NOTEBOOK (self->priv->notebook), num);
-
-  if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (self->priv->notebook)) == 0)
-    gtk_widget_hide (GTK_WIDGET (self));
-}
-
-static void
-on_switch_page (G_GNUC_UNUSED GtkNotebook* notebook,
-               G_GNUC_UNUSED gpointer page_,
-               guint num,
-               gpointer data)
-{
-  ChatWindow* self = (ChatWindow*)data;
-  GtkWidget* page = NULL;
-
-  page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (self->priv->notebook), num);
-
-  gtk_widget_grab_focus (page);
-}
-
 static bool
 on_dialect_added (ChatWindow* self,
                  Ekiga::DialectPtr dialect)
@@ -219,56 +146,29 @@ on_conversation_added (ChatWindow* self,
                       Ekiga::ConversationPtr conversation)
 {
   GtkWidget* page = NULL;
-  GtkWidget* hbox = NULL;
-  GtkWidget* label = NULL;
-  GtkWidget* close_button = NULL;
-  GtkWidget* close_image = NULL;
-  const std::string title = conversation->get_title ();
+  std::stringstream strstr;
+  strstr << static_cast<void*>(conversation.get ());
+  std::string name = strstr.str ();
 
   page = conversation_page_new (conversation);
   g_signal_connect (page, "updated",
                    G_CALLBACK (on_updated), self);
 
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
-
-  label = gtk_label_new (title.c_str ());
-  g_object_set_data (G_OBJECT (hbox), "label-widget", label);
-
-  close_button = gtk_button_new ();
-  gtk_widget_set_size_request (close_button, 16, 16); // FIXME: hardcoded!?
-  gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
-  gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
-  gtk_container_set_border_width (GTK_CONTAINER (close_button), 0);
-  g_object_set_data (G_OBJECT (close_button), "page-widget", page);
-  g_signal_connect (close_button, "clicked",
-                   G_CALLBACK (on_close_button_clicked), self);
-
-  close_image = gtk_image_new_from_icon_name ("gtk-close",
-                                             GTK_ICON_SIZE_MENU);
-  gtk_widget_set_size_request (close_image, 12, 12); // FIXME hardcoded!?
-  gtk_container_add (GTK_CONTAINER (close_button), close_image);
-
-  gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 2);
-  gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 2);
-  gtk_widget_show_all (hbox);
-
-  gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook),
-                           page, hbox);
+  gtk_stack_add_titled (GTK_STACK (self->priv->stack),
+                       page, name.c_str (),
+                       conversation_page_get_title (CONVERSATION_PAGE (page)));
   gtk_widget_show_all (page);
 
-  self->priv->connections.add (conversation->user_requested.connect (boost::bind 
(&on_some_conversation_user_requested, self, page)));
+  self->priv->connections.add (conversation->user_requested.connect (boost::bind 
(&on_some_conversation_user_requested, self, name)));
 
   return true;
 }
 
 static void
 on_some_conversation_user_requested (ChatWindow* self,
-                                    GtkWidget* page)
+                                    const std::string name)
 {
-  gint num;
-
-  num = gtk_notebook_page_num (GTK_NOTEBOOK (self->priv->notebook), page);
-  gtk_notebook_set_current_page (GTK_NOTEBOOK (self->priv->notebook), num);
+  gtk_stack_set_visible_child_name (GTK_STACK (self->priv->stack), name.c_str ());
   gtk_widget_show (GTK_WIDGET (self));
   gtk_window_present (GTK_WINDOW (self));
 }
@@ -337,7 +237,6 @@ chat_window_new (Ekiga::ServiceCore& core,
                 const char* key)
 {
   ChatWindow* self = NULL;
-  GtkAccelGroup *accel = NULL;
 
   self = (ChatWindow*)g_object_new (CHAT_WINDOW_TYPE,
                                    "key", key,
@@ -349,18 +248,9 @@ chat_window_new (Ekiga::ServiceCore& core,
   self->priv->notification_core =
     core.get<Ekiga::NotificationCore>("notification-core");
 
-  self->priv->notebook = gtk_notebook_new ();
-  gtk_container_add (GTK_CONTAINER (self), self->priv->notebook);
-  gtk_widget_show (self->priv->notebook);
-
-  accel = gtk_accel_group_new ();
-  gtk_window_add_accel_group (GTK_WINDOW (self), accel);
-  gtk_accel_group_connect (accel, GDK_KEY_Escape, (GdkModifierType) 0, GTK_ACCEL_LOCKED,
-                           g_cclosure_new_swap (G_CALLBACK (on_escaped), (gpointer) self, NULL));
-  g_object_unref (accel);
-
-  g_signal_connect (self->priv->notebook, "switch-page",
-                   G_CALLBACK (on_switch_page), self);
+  self->priv->stack = gtk_stack_new ();
+  gtk_container_add (GTK_CONTAINER (self), self->priv->stack);
+  gtk_widget_show (self->priv->stack);
 
   boost::shared_ptr<Ekiga::ChatCore> chat_core =
     core.get<Ekiga::ChatCore> ("chat-core");


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