[ekiga] Moved the chat gui to the new organisation



commit 24cc6a1daf8d4f8f1c92c5bb78398e28290b9381
Author: Julien Puydt <jpuydt free fr>
Date:   Sun Feb 16 08:46:32 2014 +0100

    Moved the chat gui to the new organisation
    
    It's ugly!

 lib/Makefile.am                                   |    6 +-
 lib/engine/gui/gtk-frontend/chat-area.cpp         |   97 ++++++++++++---------
 lib/engine/gui/gtk-frontend/chat-area.h           |   12 ++--
 lib/engine/gui/gtk-frontend/chat-window.cpp       |   81 +++--------------
 lib/engine/gui/gtk-frontend/conversation-page.cpp |   92 +++++++++++++++++++
 lib/engine/gui/gtk-frontend/conversation-page.h   |   77 ++++++++++++++++
 6 files changed, 246 insertions(+), 119 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 0651739..63329be 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -365,10 +365,8 @@ libekiga_la_SOURCES += \
        engine/gui/gtk-frontend/heap-view.cpp \
        engine/gui/gtk-frontend/chat-area.h \
        engine/gui/gtk-frontend/chat-area.cpp \
-       engine/gui/gtk-frontend/simple-chat-page.h \
-       engine/gui/gtk-frontend/simple-chat-page.cpp \
-       engine/gui/gtk-frontend/multiple-chat-page.h \
-       engine/gui/gtk-frontend/multiple-chat-page.cpp \
+       engine/gui/gtk-frontend/conversation-page.h \
+       engine/gui/gtk-frontend/conversation-page.cpp \
        engine/gui/gtk-frontend/preferences-window.cpp \
        engine/gui/gtk-frontend/preferences-window.h \
        engine/gui/gtk-frontend/statusicon.cpp \
diff --git a/lib/engine/gui/gtk-frontend/chat-area.cpp b/lib/engine/gui/gtk-frontend/chat-area.cpp
index 2cb5165..194a77b 100644
--- a/lib/engine/gui/gtk-frontend/chat-area.cpp
+++ b/lib/engine/gui/gtk-frontend/chat-area.cpp
@@ -1,6 +1,6 @@
 
 /* Ekiga -- A VoIP and Video-Conferencing application
- * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,7 +30,7 @@
  *                        chat-area.cpp  -  description
  *                         --------------------------------
  *   begin                : written in july 2008 by Julien Puydt
- *   copyright            : (C) 2008 by Julien Puydt
+ *   copyright            : (C) 2008-2014 by Julien Puydt
  *                          (C) 2008 by Jan Schampera
  *   description          : Implementation of a Chat area (view and control)
  *
@@ -38,6 +38,9 @@
 
 
 #include "chat-area.h"
+
+#include "scoped-connections.h"
+
 #include "gm-text-buffer-enhancer.h"
 #include "gm-text-anchored-tag.h"
 #include "gm-text-smiley.h"
@@ -52,13 +55,10 @@
 #include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
 
-class ChatAreaHelper;
-
 struct _ChatAreaPrivate
 {
-  boost::shared_ptr<Ekiga::Chat> chat;
-  boost::signals2::scoped_connection connection;
-  boost::shared_ptr<ChatAreaHelper> helper;
+  Ekiga::ConversationPtr conversation;
+  Ekiga::scoped_connections connections;
   GmTextBufferEnhancer* enhancer;
 
   /* we contain those, so no need to unref them */
@@ -85,27 +85,6 @@ static void chat_area_add_message (ChatArea* self,
                                   const gchar* from,
                                   const gchar* txt);
 
-/* declaration of the helping observer */
-class ChatAreaHelper: public Ekiga::ChatObserver
-{
-public:
-  ChatAreaHelper (ChatArea* area_): area(area_)
-  {}
-
-  ~ChatAreaHelper ()
-  {}
-
-  void message (const std::string from,
-               const std::string msg)
-  { chat_area_add_message (area, from.c_str (), msg.c_str ()); }
-
-  void notice (const std::string msg)
-  { chat_area_add_notice (area, msg.c_str ()); }
-
-private:
-  ChatArea* area;
-};
-
 /* a helper to shorten tag definitions
  * FIXME when C99 finally is supported everywhere, this
  * can be a variadic macro
@@ -148,7 +127,13 @@ static gboolean message_activated_cb (GtkWidget *w,
                                       GdkEventKey *key,
                                       gpointer data);
 
-static void on_chat_removed (ChatArea* self);
+static bool visit_messages (ChatArea* self,
+                           const Ekiga::Message& message);
+
+static void on_message_received (ChatArea* self,
+                                const Ekiga::Message& message);
+
+static void on_conversation_removed (ChatArea* self);
 
 static void on_chat_area_grab_focus (GtkWidget*,
                                     gpointer);
@@ -552,7 +537,6 @@ message_activated_cb (G_GNUC_UNUSED GtkWidget *w,
   GtkTextIter start_iter, end_iter;
   GtkTextBuffer *buffer = NULL;
   gchar *body = NULL;
-  std::string message;
 
   g_return_val_if_fail (data != NULL, false);
 
@@ -572,7 +556,10 @@ message_activated_cb (G_GNUC_UNUSED GtkWidget *w,
 
     body = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (buffer), &start_iter, &end_iter, TRUE);
 
-    if (self->priv->chat->send_message (body))
+    Ekiga::Message::payload_type message;
+    // FIXME: perhaps we have more than bare!
+    message.insert(std::make_pair("bare", body));
+    if (self->priv->conversation->send_message (message))
       gtk_text_buffer_delete (GTK_TEXT_BUFFER (buffer), &start_iter, &end_iter);
 
     return TRUE;
@@ -581,10 +568,38 @@ message_activated_cb (G_GNUC_UNUSED GtkWidget *w,
   return FALSE;
 }
 
+static bool
+visit_messages (ChatArea* self,
+               const Ekiga::Message& message)
+{
+  on_message_received (self, message);
+  return true;
+}
+
+static void
+on_message_received (ChatArea* self,
+                    const Ekiga::Message& message)
+{
+  if (message.name == "") {
+
+
+    Ekiga::Message::payload_type::const_iterator iter = message.payload.find ("bare");
+    if (iter != message.payload.end ())
+      chat_area_add_notice (self, iter->second.c_str ());
+  } else {
+
+    Ekiga::Message::payload_type::const_iterator iter = message.payload.find ("bare");
+    if (iter != message.payload.end ())
+      chat_area_add_message (self, message.name.c_str (), iter->second.c_str ());
+  }
+}
+
 static void
-on_chat_removed (ChatArea* self)
+on_conversation_removed (ChatArea* self)
 {
   gtk_widget_hide (self->priv->message);
+  self->priv->connections.clear ();
+  self->priv->conversation.reset ();
 }
 
 static void
@@ -621,11 +636,7 @@ chat_area_dispose (GObject* obj)
 
   self = (ChatArea*)obj;
 
-  if (self->priv->helper) {
-
-    self->priv->chat->disconnect (self->priv->helper);
-    self->priv->helper.reset ();
-  }
+  self->priv->connections.clear ();
 
   if (self->priv->enhancer != NULL) {
 
@@ -904,15 +915,15 @@ chat_area_init (ChatArea* self)
 /* public api */
 
 GtkWidget*
-chat_area_new (boost::shared_ptr<Ekiga::Chat> chat)
+chat_area_new (Ekiga::ConversationPtr conversation)
 {
   ChatArea* self = NULL;
 
   self = (ChatArea*)g_object_new (TYPE_CHAT_AREA, NULL);
-  self->priv->chat = chat;
-  self->priv->connection = self->priv->chat->removed.connect (boost::bind (&on_chat_removed, self));
-  self->priv->helper = boost::shared_ptr<ChatAreaHelper>(new ChatAreaHelper (self));
-  self->priv->chat->connect (self->priv->helper);
+  self->priv->conversation = conversation;
+  self->priv->connections.add (conversation->removed.connect (boost::bind (&on_conversation_removed, self)));
+  self->priv->connections.add (conversation->message_received.connect (boost::bind (&on_message_received, 
self, _1)));
+  conversation->visit_messages (boost::bind (&visit_messages, self, _1));
 
   return (GtkWidget*)self;
 }
@@ -920,5 +931,5 @@ chat_area_new (boost::shared_ptr<Ekiga::Chat> chat)
 const std::string
 chat_area_get_title (ChatArea* area)
 {
-  return area->priv->chat->get_title ();
+  return area->priv->conversation->get_title ();
 }
diff --git a/lib/engine/gui/gtk-frontend/chat-area.h b/lib/engine/gui/gtk-frontend/chat-area.h
index 7cbe920..7900e0e 100644
--- a/lib/engine/gui/gtk-frontend/chat-area.h
+++ b/lib/engine/gui/gtk-frontend/chat-area.h
@@ -1,6 +1,6 @@
 
 /* Ekiga -- A VoIP and Video-Conferencing application
- * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,8 +30,8 @@
  *                        chat-area.h  -  description
  *                         --------------------------------
  *   begin                : written in july 2008 by Julien Puydt
- *   copyright            : (C) 2008 by Julien Puydt
- *   description          : Declaration of a Chat area (both view and control)
+ *   copyright            : (C) 2008-2014 by Julien Puydt
+ *   description          : Declaration of a chat area (both view and control)
  *
  */
 
@@ -40,7 +40,7 @@
 
 #include <gtk/gtk.h>
 
-#include "chat.h"
+#include "conversation.h"
 
 G_BEGIN_DECLS
 
@@ -65,9 +65,9 @@ struct _ChatAreaClass
 
 /* public api */
 
-GtkWidget *chat_area_new (boost::shared_ptr<Ekiga::Chat> chat);
+GtkWidget *chat_area_new (Ekiga::ConversationPtr conversation);
 
-const std::string chat_area_get_title (ChatArea* chat);
+const std::string chat_area_get_title (ChatArea* area);
 
 /* GObject thingies */
 
diff --git a/lib/engine/gui/gtk-frontend/chat-window.cpp b/lib/engine/gui/gtk-frontend/chat-window.cpp
index ad71225..fc6e806 100644
--- a/lib/engine/gui/gtk-frontend/chat-window.cpp
+++ b/lib/engine/gui/gtk-frontend/chat-window.cpp
@@ -45,8 +45,8 @@
 #include "scoped-connections.h"
 
 #include "chat-window.h"
-#include "simple-chat-page.h"
-#include "multiple-chat-page.h"
+
+#include "conversation-page.h"
 
 struct _ChatWindowPrivate
 {
@@ -95,12 +95,10 @@ static void on_message_notice_event (GtkWidget* page,
 
 static bool on_dialect_added (ChatWindow* self,
                              Ekiga::DialectPtr dialect);
-static bool on_simple_chat_added (ChatWindow* self,
-                                 Ekiga::SimpleChatPtr chat);
-static bool on_multiple_chat_added (ChatWindow* self,
-                                   Ekiga::MultipleChatPtr chat);
-static void on_some_chat_user_requested (ChatWindow* self,
-                                        GtkWidget* page);
+static bool on_conversation_added (ChatWindow* self,
+                                  Ekiga::ConversationPtr conversation);
+static void on_some_conversation_user_requested (ChatWindow* self,
+                                                GtkWidget* page);
 
 static void show_chat_window_cb (ChatWindow *self);
 
@@ -296,84 +294,35 @@ static bool
 on_dialect_added (ChatWindow* self,
                  Ekiga::DialectPtr dialect)
 {
-  self->priv->connections.add (dialect->simple_chat_added.connect (boost::bind (&on_simple_chat_added, self, 
_1)));
-  self->priv->connections.add (dialect->multiple_chat_added.connect (boost::bind (&on_multiple_chat_added, 
self, _1)));
-
-  dialect->visit_simple_chats (boost::bind (&on_simple_chat_added, self, _1));
-  dialect->visit_multiple_chats (boost::bind (&on_multiple_chat_added, self, _1));
-
-  return true;
-}
-
-static bool
-on_simple_chat_added (ChatWindow* self,
-                     Ekiga::SimpleChatPtr chat)
-{
-  GtkWidget* page = NULL;
-  GtkWidget* hbox = NULL;
-  GtkWidget* label = NULL;
-  GtkWidget* close_button = NULL;
-  GtkWidget* close_image = NULL;
-
-  page = simple_chat_page_new (chat);
-  hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
-
-  label = gtk_label_new (chat->get_title ().c_str ());
-  g_object_set_data_full (G_OBJECT (label), "base-title",
-                         g_strdup (chat->get_title ().c_str ()),
-                         g_free);
-
-  close_button = gtk_button_new ();
-  gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
-  gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
-  close_image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU);
-  gtk_widget_set_size_request (GTK_WIDGET (close_image), 12, 12);
-  gtk_widget_set_size_request (GTK_WIDGET (close_button), 16, 16);
-  gtk_container_add (GTK_CONTAINER (close_button), close_image);
-  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);
-
-  gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 2);
-  g_object_set_data (G_OBJECT (hbox), "label-widget", label);
-  gtk_box_pack_end (GTK_BOX (hbox), close_button, FALSE, FALSE, 2);
-  g_object_set_data (G_OBJECT (hbox), "close-button-widget", close_button);
-  gtk_widget_show_all (hbox);
-
-  gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook),
-                           page, hbox);
-  gtk_widget_show (page);
-  g_signal_connect (page, "message-notice-event",
-                   G_CALLBACK (on_message_notice_event), self);
+  self->priv->connections.add (dialect->conversation_added.connect (boost::bind(&on_conversation_added, 
self, _1)));
 
-  self->priv->connections.add (chat->user_requested.connect (boost::bind (&on_some_chat_user_requested, 
self, page)));
+  dialect->visit_conversations (boost::bind (&on_conversation_added, self, _1));
 
   return true;
 }
 
 static bool
-on_multiple_chat_added (ChatWindow* self,
-                       Ekiga::MultipleChatPtr chat)
+on_conversation_added (ChatWindow* self,
+                      Ekiga::ConversationPtr conversation)
 {
   GtkWidget* page = NULL;
   GtkWidget* label = NULL;
 
-  page = multiple_chat_page_new (chat);
-  label = gtk_label_new (chat->get_title ().c_str ());
+  page = conversation_page_new (conversation);
+  label = gtk_label_new (conversation->get_title ().c_str ());
 
   gtk_notebook_append_page (GTK_NOTEBOOK (self->priv->notebook),
                            page, label);
   gtk_widget_show_all (page);
 
-  self->priv->connections.add (chat->user_requested.connect (boost::bind (&on_some_chat_user_requested, 
self, page)));
+  self->priv->connections.add (conversation->user_requested.connect (boost::bind 
(&on_some_conversation_user_requested, self, page)));
 
   return true;
 }
 
 static void
-on_some_chat_user_requested (ChatWindow* self,
-                            GtkWidget* page)
+on_some_conversation_user_requested (ChatWindow* self,
+                                    GtkWidget* page)
 {
   gint num;
 
diff --git a/lib/engine/gui/gtk-frontend/conversation-page.cpp 
b/lib/engine/gui/gtk-frontend/conversation-page.cpp
new file mode 100644
index 0000000..e75f9ef
--- /dev/null
+++ b/lib/engine/gui/gtk-frontend/conversation-page.cpp
@@ -0,0 +1,92 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2009 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                        multiple-chat-page.cpp  -  description
+ *                         --------------------------------
+ *   begin                : written in july 2008 by Julien Puydt
+ *   copyright            : (C) 2008 by Julien Puydt
+ *   description          : Declaration of a page displaying a Conversation
+ *
+ */
+
+#include "conversation-page.h"
+#include "chat-area.h"
+
+struct _ConversationPagePrivate {
+  GtkWidget* area;
+};
+
+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)
+{
+  ConversationPage* self = NULL;
+
+  self = (ConversationPage*)widget;
+
+  if (self->priv->area)
+    gtk_widget_grab_focus (self->priv->area);
+}
+
+static void
+conversation_page_init (ConversationPage* self)
+{
+  self->priv = g_new0 (ConversationPagePrivate, 1);
+
+  g_signal_connect (self, "grab-focus",
+                    G_CALLBACK (on_page_grab_focus), NULL);
+}
+
+static void
+conversation_page_class_init (G_GNUC_UNUSED ConversationPageClass* klass)
+{
+}
+
+/* implementation of the public api */
+
+GtkWidget*
+conversation_page_new (Ekiga::ConversationPtr conversation)
+{
+  ConversationPage* result = NULL;
+  GtkWidget* area = NULL;
+
+  result = (ConversationPage*)g_object_new (TYPE_CONVERSATION_PAGE, NULL);
+
+  area = chat_area_new (conversation);
+  result->priv->area = area;
+  gtk_box_pack_start (GTK_BOX (result), area,
+                     TRUE,TRUE, 2);
+  gtk_widget_show (area);
+
+  return GTK_WIDGET (result);
+}
diff --git a/lib/engine/gui/gtk-frontend/conversation-page.h b/lib/engine/gui/gtk-frontend/conversation-page.h
new file mode 100644
index 0000000..08f2806
--- /dev/null
+++ b/lib/engine/gui/gtk-frontend/conversation-page.h
@@ -0,0 +1,77 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                        conversation-page.h  -  description
+ *                         --------------------------------
+ *   begin                : written in 2014 by Julien Puydt
+ *   copyright            : (C) 2014 by Julien Puydt
+ *   description          : Declaration of a page displaying a Conversation
+ *
+ */
+
+#ifndef __CONVERSATION_PAGE_H__
+#define __CONVERSATION_PAGE_H__
+
+#include <gtk/gtk.h>
+#include "conversation.h"
+
+G_BEGIN_DECLS
+
+/* public api */
+
+GtkWidget* conversation_page_new (Ekiga::ConversationPtr conversation);
+
+/* GObject boilerplate */
+
+typedef struct _ConversationPage ConversationPage;
+typedef struct _ConversationPagePrivate ConversationPagePrivate;
+typedef struct _ConversationPageClass ConversationPageClass;
+
+struct _ConversationPage {
+  GtkBox parent;
+
+  ConversationPagePrivate* priv;
+};
+
+struct _ConversationPageClass {
+  GtkBoxClass parent_class;
+};
+
+#define TYPE_CONVERSATION_PAGE             (conversation_page_get_type())
+#define CONVERSATION_PAGE(obj)             
(G_TYPE_CHECK_INSTANCE_CAST((obj),TYPE_CONVERSATION_PAGE,ConversationPage))
+#define CONVERSATION_PAGE_CLASS(klass)     (G_TYPE_CHECK_CLASS_CAST((klass),TYPE_CONVERSATION_PAGE,GtkVBox))
+#define IS_CONVERSATION_PAGE(obj)          (G_TYPE_CHECK_INSTANCE_TYPE((obj),TYPE_CONVERSATION_PAGE))
+#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;
+
+G_END_DECLS
+
+#endif /* __CONVERSATION_PAGE_H__ */


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