[ekiga/chat_opal_v314] Full rewrite of the chat part of the opal component



commit bc76ff333dea86c66cdd1b442f2e9885d6b01b13
Author: Julien Puydt <julien puydt laposte net>
Date:   Sat Aug 23 20:01:34 2014 +0200

    Full rewrite of the chat part of the opal component

 lib/Makefile.am                                    |   12 +-
 lib/engine/components/opal/opal-call-manager.cpp   |   16 ++-
 lib/engine/components/opal/opal-call-manager.h     |    7 +
 lib/engine/components/opal/opal-conversation.cpp   |  139 +++++++++++++++++
 lib/engine/components/opal/opal-conversation.h     |  105 +++++++++++++
 lib/engine/components/opal/opal-dialect.cpp        |  159 ++++++++++++++++++++
 .../opal/{sip-dialect.h => opal-dialect.h}         |   65 ++++++---
 .../opal/{sip-heap.cpp => opal-heap.cpp}           |   16 +-
 .../components/opal/{sip-heap.h => opal-heap.h}    |   13 +-
 lib/engine/components/opal/opal-main.cpp           |    2 +-
 lib/engine/components/opal/sip-conversation.cpp    |   89 -----------
 lib/engine/components/opal/sip-conversation.h      |   98 ------------
 lib/engine/components/opal/sip-dialect.cpp         |  107 -------------
 lib/engine/components/opal/sip-endpoint.cpp        |  112 +--------------
 lib/engine/components/opal/sip-endpoint.h          |   17 +--
 15 files changed, 493 insertions(+), 464 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 5c7a7a9..c4c42b4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -429,6 +429,12 @@ libekiga_la_SOURCES += \
        engine/components/opal/opal-videooutput.cpp \
        engine/components/opal/opal-plugins-hook.h \
        engine/components/opal/opal-plugins-hook.cpp \
+       engine/components/opal/opal-dialect.h \
+       engine/components/opal/opal-dialect.cpp \
+       engine/components/opal/opal-conversation.h \
+       engine/components/opal/opal-conversation.cpp \
+       engine/components/opal/opal-heap.h \
+       engine/components/opal/opal-heap.cpp \
        engine/components/opal/opal-presentity.h \
        engine/components/opal/opal-presentity.cpp
 
@@ -439,12 +445,6 @@ libekiga_la_SOURCES += \
 endif
 
 libekiga_la_SOURCES += \
-       engine/components/opal/sip-heap.h \
-       engine/components/opal/sip-heap.cpp \
-       engine/components/opal/sip-conversation.h \
-       engine/components/opal/sip-conversation.cpp \
-       engine/components/opal/sip-dialect.h \
-       engine/components/opal/sip-dialect.cpp \
        engine/components/opal/sip-endpoint.h \
        engine/components/opal/sip-endpoint.cpp
 
diff --git a/lib/engine/components/opal/opal-call-manager.cpp 
b/lib/engine/components/opal/opal-call-manager.cpp
index 1ed7ebc..f619fb3 100644
--- a/lib/engine/components/opal/opal-call-manager.cpp
+++ b/lib/engine/components/opal/opal-call-manager.cpp
@@ -43,6 +43,8 @@
 #include "pcss-endpoint.h"
 
 #include "call-core.h"
+#include "presence-core.h"
+
 #include "opal-codec-description.h"
 #include "videoinput-info.h"
 
@@ -117,6 +119,8 @@ CallManager::CallManager (Ekiga::ServiceCore& core)
 {
   call_core = core.get<Ekiga::CallCore> ("call-core");
   notification_core = core.get<Ekiga::NotificationCore> ("notification-core");
+  chat_core = core.get<Ekiga::ChatCore> ("chat-core");
+  boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
 
   stun_thread = 0;
 
@@ -163,6 +167,14 @@ CallManager::CallManager (Ekiga::ServiceCore& core)
   pcssEP->SetSoundChannelPlayDevice("EKIGA");
   pcssEP->SetSoundChannelRecordDevice("EKIGA");
 
+  boost::shared_ptr<Ekiga::ChatCore> chat = chat_core.lock ();
+  if (chat) {
+
+    imEP = new OpalIMEndPoint (*this);
+    dialect = boost::shared_ptr<Opal::Dialect> (new Opal::Dialect (imEP, presence_core));
+    chat->add_dialect (dialect);
+  }
+
   // Media formats
   SetMediaFormatOrder (PStringArray ());
   SetMediaFormatMask (PStringArray ());
@@ -244,9 +256,11 @@ CallManager::populate_menu (const std::string fullname,
 
 #ifdef HAVE_H323
   if (uri.find ("h323:") == 0)
-    result = h323_endpoint->populate_menu (fullname, complete_uri, builder);
+    result = h323_endpoint->populate_menu (fullname, complete_uri, builder) || result;
 #endif
 
+  result = dialect->populate_menu (fullname, complete_uri, builder) || result;
+
   return result;
 }
 
diff --git a/lib/engine/components/opal/opal-call-manager.h b/lib/engine/components/opal/opal-call-manager.h
index 698152e..9777dc4 100644
--- a/lib/engine/components/opal/opal-call-manager.h
+++ b/lib/engine/components/opal/opal-call-manager.h
@@ -45,11 +45,15 @@
 
 #include <h323/h323.h>
 #include <sip/sip.h>
+#include <im/im_ep.h>
 
 #include "menu-builder.h"
 
+#include "chat-core.h"
+
 #include "call-manager.h"
 #include "opal-call.h"
+#include "opal-dialect.h"
 
 #include "ekiga-settings.h"
 
@@ -179,6 +183,8 @@ public:
 private:
     boost::weak_ptr<Ekiga::CallCore> call_core;
     boost::shared_ptr<Ekiga::NotificationCore> notification_core;
+    boost::weak_ptr<Ekiga::ChatCore> chat_core;
+    boost::shared_ptr<Opal::Dialect> dialect;
 
     void create_call_in_main (Opal::Call* call);
     OpalCall *CreateCall (void *uri);
@@ -204,6 +210,7 @@ private:
 
     /* The various related endpoints */
     GMPCSSEndpoint *pcssEP;
+    OpalIMEndPoint* imEP;
 
     /* Various mutexes to ensure thread safeness around internal
        variables */
diff --git a/lib/engine/components/opal/opal-conversation.cpp 
b/lib/engine/components/opal/opal-conversation.cpp
new file mode 100644
index 0000000..12bbfe0
--- /dev/null
+++ b/lib/engine/components/opal/opal-conversation.cpp
@@ -0,0 +1,139 @@
+
+/* 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.
+ */
+
+
+/*
+ *                         opal-conversation.h  -  description
+ *                         --------------------------------
+ *   begin                : written in august 2014 by Julien Puydt
+ *   copyright            : (C) 2014 by Julien Puydt
+ *   description          : Interface of an opal conversation
+ *
+ */
+
+#include <glib/gi18n.h>
+
+#include "opal-conversation.h"
+
+#include "runtime.h"
+#include "uri-presentity.h"
+
+Opal::Conversation::Conversation (boost::shared_ptr<Ekiga::PresenceCore> presence_core_,
+                                 OpalIMContext& context_):
+  presence_core(presence_core_),
+  context(context_),
+  heap(new Heap)
+{
+  context.SetMessageDispositionNotifier (PCREATE_MessageDispositionNotifier (OnMessageDisposition));
+  context.SetMessageReceivedNotifier (PCREATE_MessageReceivedNotifier (OnMessageReceived));
+
+  boost::shared_ptr<Ekiga::URIPresentity> presentity (new Ekiga::URIPresentity (presence_core_,
+                                                                               context.GetRemoteName (),
+                                                                               context.GetRemoteURL 
().AsString (),
+                                                                               std::set<std::string>()));
+  heap->add_presentity (boost::dynamic_pointer_cast<Ekiga::Presentity> (presentity));
+}
+
+void
+Opal::Conversation::visit_messages (boost::function1<bool, const Ekiga::Message&> visitor) const
+{
+  for (std::list<Ekiga::Message>::const_iterator iter = messages.begin();
+       iter != messages.end ();
+       ++iter) {
+
+    if (!visitor(*iter))
+      break;
+  }
+}
+
+bool
+Opal::Conversation::send_message (const Ekiga::Message::payload_type& payload)
+{
+  bool result = false;
+
+  // FIXME: here we are supposed to check which kind of payload we're dealing with!
+  Ekiga::Message::payload_type::const_iterator iter = payload.find ("text/plain");
+  if (iter != payload.end ()) {
+
+    OpalIM* im = new OpalIM;
+    im->m_bodies.SetAt(PMIMEInfo::TextPlain(), iter->second);
+    context.Send (im);
+    result = true;
+  }
+
+  return result;
+}
+
+void
+Opal::Conversation::reset_unread_messages_count ()
+{
+  unreads = 0;
+  updated ();
+}
+
+bool
+Opal::Conversation::populate_menu (Ekiga::MenuBuilder& /*builder*/)
+{
+  return false; // FIXME?
+}
+
+void
+Opal::Conversation::on_message_received (const std::string txt)
+{
+  const std::string display_name(context.GetRemoteName ().operator std::string ());
+
+  Ekiga::Message::payload_type payload;
+  // FIXME: we push as 'text/plain' without really knowing
+  payload.insert (std::make_pair ("text/plain", txt));
+
+  GTimeVal current;
+  g_get_current_time (&current);
+  gchar* time = g_time_val_to_iso8601 (&current);
+
+  Ekiga::Message msg = {time, display_name, payload };
+  g_free (time);
+
+  messages.push_back (msg);
+  message_received (msg);
+  unreads++;
+  updated ();
+}
+
+void
+Opal::Conversation::OnMessageReceived (OpalIMContext& /*context*/,
+                                      OpalIM im)
+{
+  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Conversation::on_message_received, this,
+                                           im.m_bodies (PMIMEInfo::TextPlain())));
+}
+
+void
+Opal::Conversation::OnMessageDisposition (OpalIMContext& /*context*/,
+                                         OpalIMContext::DispositionInfo /*info*/)
+{
+  // FIXME: what should be done here?
+}
diff --git a/lib/engine/components/opal/opal-conversation.h b/lib/engine/components/opal/opal-conversation.h
new file mode 100644
index 0000000..149f683
--- /dev/null
+++ b/lib/engine/components/opal/opal-conversation.h
@@ -0,0 +1,105 @@
+
+/* 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.
+ */
+
+
+/*
+ *                         opal-conversation.h  -  description
+ *                         --------------------------------
+ *   begin                : written in august 2014 by Julien Puydt
+ *   copyright            : (C) 2014 by Julien Puydt
+ *   description          : Interface of an opal conversation
+ *
+ */
+
+#ifndef __OPAL_CONVERSATION_H__
+#define __OPAL_CONVERSATION_H__
+
+#include <ptlib.h>
+#include <ptlib/notifier_ext.h>
+#include <im/im.h>
+
+#include "conversation.h"
+#include "presence-core.h"
+
+#include "opal-heap.h"
+
+namespace Opal {
+
+  class Conversation:
+    public Ekiga::Conversation,
+    public PAsyncNotifierTarget
+  {
+  public:
+
+    Conversation (boost::shared_ptr<Ekiga::PresenceCore> presence_core_,
+                 OpalIMContext& context_);
+
+    // generic Ekiga::Conversation api:
+
+    Ekiga::HeapPtr get_heap () const
+    { return boost::dynamic_pointer_cast<Ekiga::Heap>(heap); }
+
+    const std::string get_title () const
+    { return title; }
+
+    const std::string get_status () const
+    { return status; }
+
+    void visit_messages (boost::function1<bool, const Ekiga::Message&> visitor) const;
+
+    bool send_message (const Ekiga::Message::payload_type& payload);
+
+    int get_unread_messages_count () const
+    { return unreads; }
+
+    void reset_unread_messages_count ();
+
+    bool populate_menu (Ekiga::MenuBuilder& /*builder*/);
+
+  private:
+
+    boost::weak_ptr<Ekiga::PresenceCore> presence_core;
+    OpalIMContext& context;
+
+    std::string title;
+    std::string status;
+    boost::shared_ptr<Opal::Heap> heap;
+    int unreads;
+    std::list<Ekiga::Message> messages;
+
+
+    void on_message_received (const std::string txt);
+
+    PDECLARE_ASYNC_MessageReceivedNotifier(Conversation, OnMessageReceived);
+    PDECLARE_ASYNC_MessageDispositionNotifier(Conversation, OnMessageDisposition);
+
+  };
+
+  typedef typename boost::shared_ptr<Conversation> ConversationPtr;
+};
+
+#endif
diff --git a/lib/engine/components/opal/opal-dialect.cpp b/lib/engine/components/opal/opal-dialect.cpp
new file mode 100644
index 0000000..5dfbd6d
--- /dev/null
+++ b/lib/engine/components/opal/opal-dialect.cpp
@@ -0,0 +1,159 @@
+
+/* 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.
+ */
+
+
+/*
+ *                         opal-dialect.cpp  -  description
+ *                         --------------------------------
+ *   begin                : written in august 2014 by Julien Puydt
+ *   copyright            : (C) 2014 by Julien Puydt
+ *   description          : Implementation of the opal dialect
+ *
+ */
+
+#include "opal-dialect.h"
+
+#include <glib/gi18n.h>
+
+#include "runtime.h"
+
+Opal::Dialect::Dialect (OpalIMEndPoint* im_endpoint_,
+                       boost::shared_ptr<Ekiga::PresenceCore> presence_core_):
+  im_endpoint(im_endpoint_),
+  presence_core(presence_core_)
+{
+  im_endpoint->AddNotifier (PCREATE_ConversationNotifier(OnConversation), "*");
+}
+
+Opal::Dialect::~Dialect ()
+{
+}
+
+bool
+Opal::Dialect::populate_menu (Ekiga::MenuBuilder& /*builder*/)
+{
+  return false;
+}
+
+bool
+Opal::Dialect::populate_menu (const std::string name,
+                             const std::string uri,
+                             Ekiga::MenuBuilder& builder)
+{
+  builder.add_action ("im-message-new", _("Message"),
+                     boost::bind (&Opal::Dialect::start_chat_with, this, uri, name));
+  return true;
+}
+
+int
+Opal::Dialect::get_unread_messages_count () const
+{
+  int result = 0;
+
+  for (conversations_type::const_iterator iter = conversations.begin ();
+       iter != conversations.end (); ++iter) {
+
+    result += iter->second->get_unread_messages_count ();
+  }
+
+  return result;
+}
+
+void
+Opal::Dialect::visit_conversations (boost::function1<bool, Ekiga::ConversationPtr> visitor) const
+{
+  bool go_on = true;
+  for (conversations_type::const_iterator iter = conversations.begin ();
+       iter != conversations.end () && go_on; ++iter) {
+
+    go_on = visitor (iter->second);
+  }
+}
+
+void
+Opal::Dialect::start_chat_with (const std::string uri,
+                               const std::string /*name*/)
+{
+  // FIXME? Made sip the default...
+  const char* scheme;
+  if (uri.find("h323:") == 0)
+    scheme = "h323";
+  else
+    scheme = "sip";
+
+  PURL local("local", scheme); // FIXME? local url?
+  PURL remote(uri, scheme);
+  if (im_endpoint->CreateContext (local, remote) == 0) {
+
+   g_print ("%s -- failed to start chat\n", __PRETTY_FUNCTION__);   // FIXME: here we should notify the user 
that it wasn't possible
+  }
+}
+
+void
+Opal::Dialect::add_chat (const std::string id,
+                        OpalIMContext& context,
+                        bool user_requested)
+{
+  boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock (); // FIXME: check?
+  ConversationPtr chat = ConversationPtr(new Conversation(pcore, context));
+
+  conversations[id] = chat;
+  connections[id] = boost::shared_ptr<Ekiga::scoped_connections> (new Ekiga::scoped_connections);
+  connections[id]->add (chat->updated.connect (boost::bind (boost::ref (conversation_updated), chat)));
+  connections[id]->add (chat->updated.connect (boost::ref (updated)));
+  connections[id]->add (chat->removed.connect (boost::bind (&Opal::Dialect::remove_chat, this, id)));
+  conversation_added (chat);
+  updated ();
+
+  if (user_requested)
+    chat->user_requested ();
+}
+
+void
+Opal::Dialect::remove_chat (const std::string id)
+{
+  ConversationPtr chat = conversations[id];
+  connections.erase (id);
+  conversations.erase (id);
+  conversation_removed (chat);
+}
+
+void
+Opal::Dialect::OnConversation (OpalIMContext& /*context*/,
+                              OpalIMContext::ConversationInfo info)
+{
+  if (info.m_opening) {
+
+    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Dialect::add_chat, this,
+                                             info.m_conversationId, *info.m_context,
+                                             !info.m_byRemote));
+  } else {
+
+    Ekiga::Runtime::run_in_main (boost::bind (&Opal::Dialect::remove_chat,  this,
+                                             info.m_conversationId));
+  }
+}
diff --git a/lib/engine/components/opal/sip-dialect.h b/lib/engine/components/opal/opal-dialect.h
similarity index 51%
rename from lib/engine/components/opal/sip-dialect.h
rename to lib/engine/components/opal/opal-dialect.h
index b016303..0773890 100644
--- a/lib/engine/components/opal/sip-dialect.h
+++ b/lib/engine/components/opal/opal-dialect.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
@@ -27,47 +27,68 @@
 
 
 /*
- *                         sip-dialect.h  -  description
+ *                         opal-dialect.h  -  description
  *                         --------------------------------
- *   begin                : written in july 2008 by Julien Puydt
- *   copyright            : (C) 2008 by Julien Puydt
- *   description          : Interface of the SIP dialect
+ *   begin                : written in august 2014 by Julien Puydt
+ *   copyright            : (C) 2014 by Julien Puydt
+ *   description          : Interface of the opal dialect
  *
  */
 
-#ifndef __SIP_DIALECT_H__
-#define __SIP_DIALECT_H__
+#ifndef __OPAL_DIALECT_H__
+#define __OPAL_DIALECT_H__
 
-#include "dialect-impl.h"
+#include <im/im_ep.h>
+
+#include "dialect.h"
+#include "scoped-connections.h"
 
 #include "presence-core.h"
-#include "sip-conversation.h"
+#include "opal-conversation.h"
 
-namespace SIP
+namespace Opal
 {
-  class Dialect: public Ekiga::DialectImpl<Conversation>
+  class Dialect:
+    public Ekiga::Dialect,
+    public PAsyncNotifierTarget
   {
   public:
-    Dialect (boost::shared_ptr<Ekiga::PresenceCore> core_,
-            boost::function2<bool, std::string, Ekiga::Message::payload_type> sender_);
 
-    ~Dialect ();
+    Dialect (OpalIMEndPoint* im_endpoint_,
+            boost::shared_ptr<Ekiga::PresenceCore> presence_core);
 
-    void push_message (const std::string uri,
-                      const Ekiga::Message& msg);
+    ~Dialect ();
 
     bool populate_menu (Ekiga::MenuBuilder& builder);
 
-    void start_chat_with (std::string uri,
-                         std::string name);
+    int get_unread_messages_count () const;
+
+    void visit_conversations (boost::function1<bool, Ekiga::ConversationPtr> visitor) const;
+
+    bool populate_menu (const std::string name,
+                       const std::string uri,
+                       Ekiga::MenuBuilder& builder);
 
   private:
+    OpalIMEndPoint* im_endpoint;
     boost::weak_ptr<Ekiga::PresenceCore> presence_core;
-    boost::function2<bool, std::string, Ekiga::Message::payload_type> sender;
 
-    ConversationPtr open_chat_with (std::string uri,
-                                   std::string name,
-                                   bool user_request);
+    void start_chat_with (const std::string uri,
+                         const std::string name);
+
+    void add_chat (const std::string id,
+                  OpalIMContext& context,
+                  bool user_requested);
+
+    void remove_chat (const std::string id);
+
+    PDECLARE_ASYNC_ConversationNotifier(Dialect, OnConversation);
+
+    typedef std::map<std::string, ConversationPtr> conversations_type;
+    conversations_type conversations;
+
+    typedef std::map<std::string, boost::shared_ptr<Ekiga::scoped_connections> > connections_type;
+    connections_type connections;
   };
 
   typedef boost::shared_ptr<Dialect> DialectPtr;
diff --git a/lib/engine/components/opal/sip-heap.cpp b/lib/engine/components/opal/opal-heap.cpp
similarity index 85%
rename from lib/engine/components/opal/sip-heap.cpp
rename to lib/engine/components/opal/opal-heap.cpp
index 7a8e0e9..60b8977 100644
--- a/lib/engine/components/opal/sip-heap.cpp
+++ b/lib/engine/components/opal/opal-heap.cpp
@@ -25,38 +25,38 @@
 
 
 /*
- *                         sip-heap.cpp -  description
+ *                         opal-heap.cpp -  description
  *                         ------------------------------------------
  *   begin                : written in 2014 by Julien Puydt
  *   copyright            : (c) 2014 by Julien Puydt
- *   description          : implementation of an Ekiga::Heap implementation for a SIP::Conversation
+ *   description          : implementation of an Ekiga::Heap implementation for an Opal::Conversation
  *
  */
 
-#include "sip-heap.h"
+#include "opal-heap.h"
 #include "uri-presentity.h"
 
 bool
-SIP::Heap::populate_menu (Ekiga::MenuBuilder& /*builder*/)
+Opal::Heap::populate_menu (Ekiga::MenuBuilder& /*builder*/)
 {
   return false;
 }
 
 const std::string
-SIP::Heap::get_name () const
+Opal::Heap::get_name () const
 {
   return ""; // FIXME?
 }
 
 bool
-SIP::Heap::populate_menu_for_group (const std::string /*name*/,
-                                   Ekiga::MenuBuilder& /*builder*/)
+Opal::Heap::populate_menu_for_group (const std::string /*name*/,
+                                    Ekiga::MenuBuilder& /*builder*/)
 {
   return false;
 }
 
 const std::string
-SIP::Heap::get_name (const std::string uri) const
+Opal::Heap::get_name (const std::string uri) const
 {
   bool found = false;
   std::string result = uri; // sensible default
diff --git a/lib/engine/components/opal/sip-heap.h b/lib/engine/components/opal/opal-heap.h
similarity index 90%
rename from lib/engine/components/opal/sip-heap.h
rename to lib/engine/components/opal/opal-heap.h
index 70e7811..df21425 100644
--- a/lib/engine/components/opal/sip-heap.h
+++ b/lib/engine/components/opal/opal-heap.h
@@ -25,25 +25,26 @@
 
 
 /*
- *                         sip-heap.h -  description
+ *                         opal-heap.h -  description
  *                         ------------------------------------------
  *   begin                : written in 2014 by Julien Puydt
  *   copyright            : (c) 2014 by Julien Puydt
- *   description          : declaration of an Ekiga::Heap implementation for a SIP::Conversation
+ *   description          : declaration of an Ekiga::Heap implementation for an Opal::Conversation
  *
  */
 
-#ifndef __SIP_HEAP_H__
-#define __SIP_HEAP_H__
+#ifndef __OPAL_HEAP_H__
+#define __OPAL_HEAP_H__
 
 #include "heap-impl.h"
 
-namespace SIP
+namespace Opal
 {
   class Heap: public Ekiga::HeapImpl<Ekiga::Presentity>
   {
   public:
-    // let's put everything in public so SIP::Conversation can control us fully!
+
+    // let's put everything in public so Opal::Conversation can control us fully!
     using Ekiga::HeapImpl<Ekiga::Presentity>::add_presentity;
     using Ekiga::HeapImpl<Ekiga::Presentity>::remove_presentity;
     using Ekiga::HeapImpl<Ekiga::Presentity>::add_connection;
diff --git a/lib/engine/components/opal/opal-main.cpp b/lib/engine/components/opal/opal-main.cpp
index a2d00ba..5ba47da 100644
--- a/lib/engine/components/opal/opal-main.cpp
+++ b/lib/engine/components/opal/opal-main.cpp
@@ -112,7 +112,7 @@ struct OPALSpark: public Ekiga::Spark
       boost::shared_ptr<CallManager> call_manager (new CallManager (core));
       core.add (call_manager);
 
-      boost::shared_ptr<Sip::EndPoint> sip_manager (new Sip::EndPoint (*call_manager, core), null_deleter 
());
+      boost::shared_ptr<Sip::EndPoint> sip_manager (new Sip::EndPoint (*call_manager), null_deleter ());
       std::cout << "FIXME: where is H323" << std::endl << std::flush;
       sip_manager->setup ();
       call_manager->set_sip_endpoint (sip_manager);
diff --git a/lib/engine/components/opal/sip-endpoint.cpp b/lib/engine/components/opal/sip-endpoint.cpp
index 36bfa6e..161c789 100644
--- a/lib/engine/components/opal/sip-endpoint.cpp
+++ b/lib/engine/components/opal/sip-endpoint.cpp
@@ -112,20 +112,13 @@ namespace Opal {
 
 
 /* The class */
-Opal::Sip::EndPoint::EndPoint (Opal::CallManager & _manager,
-                               Ekiga::ServiceCore& core):
+Opal::Sip::EndPoint::EndPoint (Opal::CallManager & _manager):
   SIPEndPoint (_manager),
   manager (_manager)
 {
-  boost::shared_ptr<Ekiga::ChatCore> chat_core = core.get<Ekiga::ChatCore> ("chat-core");
-  boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
-
   protocol_name = "sip";
   uri_prefix = "sip:";
 
-  dialect = boost::shared_ptr<SIP::Dialect>(new SIP::Dialect (presence_core, boost::bind 
(&Opal::Sip::EndPoint::send_message, this, _1, _2)));
-  chat_core->add_dialect (dialect);
-
   /* Timeouts */
   SetAckTimeout (PTimeInterval (0, 32));
   SetPduCleanUpTimeout (PTimeInterval (0, 1));
@@ -178,7 +171,7 @@ Opal::Sip::EndPoint::setup (std::string setting)
 
 
 bool
-Opal::Sip::EndPoint::populate_menu (const std::string& fullname,
+Opal::Sip::EndPoint::populate_menu (const std::string& /*fullname*/,
                                    const std::string& uri,
                                    Ekiga::MenuBuilder& builder)
 {
@@ -188,32 +181,12 @@ Opal::Sip::EndPoint::populate_menu (const std::string& fullname,
   else
     builder.add_action ("mail-forward", _("Transfer"),
                        boost::bind (&Opal::Sip::EndPoint::on_transfer, this, uri));
-  builder.add_action ("im-message-new", _("Message"),
-                     boost::bind (&Opal::Sip::EndPoint::on_message, this, uri, fullname));
 
   return true;
 }
 
 
 bool
-Opal::Sip::EndPoint::send_message (const std::string & _uri,
-                                  const Ekiga::Message::payload_type payload)
-{
-  // FIXME: here we should check which kind of payload we have
-  Ekiga::Message::payload_type::const_iterator iter = payload.find("text/plain");
-  if (!_uri.empty () && (_uri.find ("sip:") == 0 || _uri.find (':') == string::npos) && iter != payload.end 
()) {
-    OpalIM im;
-    im.m_to = PURL (_uri);
-    im.m_bodies.SetAt (PMIMEInfo::TextPlain(), iter->second);
-    Message (im);
-    return true;
-  }
-
-  return false;
-}
-
-
-bool
 Opal::Sip::EndPoint::dial (const std::string & uri)
 {
   std::stringstream ustr;
@@ -805,73 +778,6 @@ Opal::Sip::EndPoint::OnIncomingConnection (OpalConnection &connection,
 }
 
 
-bool
-Opal::Sip::EndPoint::OnReceivedMESSAGE (SIP_PDU & pdu)
-{
-  if (pdu.GetMIME().GetContentType(false) != "text/plain")
-    return false; // Ignore what we do not handle.
-
-  PString from = pdu.GetMIME().GetFrom();
-  PINDEX j = from.Find (';');
-  if (j != P_MAX_INDEX)
-    from = from.Left(j); // Remove all parameters
-  j = from.Find ('<');
-  if (j != P_MAX_INDEX && from.Find ('>') == P_MAX_INDEX)
-    from += '>';
-
-  SIPURL uri = from;
-  uri.Sanitise (SIPURL::RequestURI);
-  std::string display_name = (const char *) uri.GetDisplayName ();
-  std::string message_uri = (const char *) uri.AsString ();
-  std::string _message = (const char *) pdu.GetEntityBody ();
-  Ekiga::Message::payload_type payload;
-  // FIXME: we push as 'text/plain' without really knowing
-  payload.insert (std::make_pair ("text/plain", _message));
-  GTimeVal current;
-  g_get_current_time (&current);
-  gchar* time = g_time_val_to_iso8601 (&current);
-  Ekiga::Message msg = {time, display_name, payload };
-  g_free (time);
-
-  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::push_message_in_main, this, message_uri, 
msg));
-
-  return SIPEndPoint::OnReceivedMESSAGE (pdu);
-}
-
-
-void
-Opal::Sip::EndPoint::OnMESSAGECompleted (const SIPMessage::Params & params,
-                                         SIP_PDU::StatusCodes reason)
-{
-  PTRACE (4, "IM sending completed, reason: " << reason);
-
-  // after TemporarilyUnavailable, RequestTimeout appears too, hence do not process it too
-  if (reason == SIP_PDU::Successful_OK || reason == SIP_PDU::Failure_RequestTimeout)
-    return;
-
-  SIPURL to = params.m_remoteAddress;
-  to.Sanitise (SIPURL::ToURI);
-  std::string uri = (const char*) to.AsString ();
-  std::string display_name = (const char*) to.GetDisplayName ();
-
-  std::string reason_shown = _("Could not send message: ");
-  if (reason == SIP_PDU::Failure_TemporarilyUnavailable)
-    reason_shown += _("user offline");
-  else
-    reason_shown += SIP_PDU::GetStatusCodeDescription (reason).operator std::string ();  // too many to 
translate them with _()...
-  Ekiga::Message::payload_type payload;
-  // FIXME: we push as 'text/plain' without really knowing...
-  payload.insert (std::make_pair ("text/plain", reason_shown));
-  GTimeVal current;
-  g_get_current_time (&current);
-  gchar* time = g_time_val_to_iso8601 (&current);
-  Ekiga::Message msg = {time, "" /* it's a notice */, payload };
-  g_free (time);
-
-  Ekiga::Runtime::run_in_main (boost::bind (&Opal::Sip::EndPoint::push_message_in_main, this, uri, msg));
-}
-
-
 SIPURL
 Opal::Sip::EndPoint::GetRegisteredPartyName (const SIPURL & aor,
                                             const OpalTransport & transport)
@@ -933,13 +839,6 @@ void Opal::Sip::EndPoint::on_dial (std::string uri)
 }
 
 
-void Opal::Sip::EndPoint::on_message (std::string uri,
-                                      std::string name)
-{
-  dialect->start_chat_with (uri, name);
-}
-
-
 void Opal::Sip::EndPoint::on_transfer (std::string uri)
 {
   /* FIXME : we don't handle several calls here */
@@ -949,13 +848,6 @@ void Opal::Sip::EndPoint::on_transfer (std::string uri)
 }
 
 void
-Opal::Sip::EndPoint::push_message_in_main (const std::string uri,
-                                          const Ekiga::Message msg)
-{
-  dialect->push_message (uri, msg);
-}
-
-void
 Opal::Sip::EndPoint::update_aor_map (std::map<std::string, std::string> _accounts)
 {
   PWaitAndSignal m(aorMutex);
diff --git a/lib/engine/components/opal/sip-endpoint.h b/lib/engine/components/opal/sip-endpoint.h
index a25745b..642273e 100644
--- a/lib/engine/components/opal/sip-endpoint.h
+++ b/lib/engine/components/opal/sip-endpoint.h
@@ -41,11 +41,9 @@
 
 #include <opal/opal.h>
 
-#include "presence-core.h"
 #include "call-manager.h"
 #include "call-protocol-manager.h"
 #include "opal-bank.h"
-#include "sip-dialect.h"
 #include "call-core.h"
 #include "contact-core.h"
 #include "services.h"
@@ -69,8 +67,7 @@ namespace Opal {
       typedef std::list<std::string> domain_list;
       typedef std::list<std::string>::iterator domain_list_iterator;
 
-      EndPoint (CallManager& ep,
-               Ekiga::ServiceCore& core);
+      EndPoint (CallManager& ep);
 
       ~EndPoint ();
 
@@ -157,11 +154,6 @@ namespace Opal {
 
       void OnDialogInfoReceived (const SIPDialogNotification & info);
 
-      bool OnReceivedMESSAGE (SIP_PDU & pdu);
-
-      void OnMESSAGECompleted (const SIPMessage::Params & params,
-                               SIP_PDU::StatusCodes reason);
-
       SIPURL GetRegisteredPartyName (const SIPURL & host,
                                     const OpalTransport & transport);
 
@@ -169,13 +161,8 @@ namespace Opal {
       /* Callbacks */
     private:
       void on_dial (std::string uri);
-      void on_message (std::string uri,
-                      std::string name);
       void on_transfer (std::string uri);
 
-      void push_message_in_main (const std::string uri,
-                                const Ekiga::Message msg);
-
       PMutex aorMutex;
       std::map<std::string, std::string> accounts;
 
@@ -192,8 +179,6 @@ namespace Opal {
       std::string forward_uri;
       std::string outbound_proxy;
 
-      boost::shared_ptr<SIP::Dialect> dialect;
-
       boost::shared_ptr<Ekiga::Settings> settings;
     };
   };


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