[ekiga/ds-gtk-application] LocalCluster: Migrated to Actor/ContactActor API.



commit 6878db2532a686c743b8431e1c90c0bf434cfa61
Author: Damien Sandras <dsandras beip be>
Date:   Sun Mar 30 19:46:31 2014 +0200

    LocalCluster: Migrated to Actor/ContactActor API.
    
    This allows us getting rid of the Roster bridget.

 lib/Makefile.am                                    |    4 +-
 .../components/local-roster/local-cluster.cpp      |   44 +++---
 lib/engine/components/local-roster/local-cluster.h |   18 ++--
 lib/engine/components/local-roster/local-heap.cpp  |   24 ++-
 lib/engine/components/local-roster/local-heap.h    |   11 +-
 .../local-roster/local-roster-bridge.cpp           |  145 --------------------
 .../components/local-roster/local-roster-bridge.h  |   53 -------
 .../components/local-roster/local-roster-main.cpp  |   10 +-
 lib/engine/engine.cpp                              |    3 -
 9 files changed, 62 insertions(+), 250 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 9711c39..30d4f11 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -535,9 +535,7 @@ libekiga_la_SOURCES += \
        engine/components/local-roster/local-cluster.h \
        engine/components/local-roster/local-cluster.cpp \
        engine/components/local-roster/local-roster-main.h \
-       engine/components/local-roster/local-roster-main.cpp \
-       engine/components/local-roster/local-roster-bridge.h \
-       engine/components/local-roster/local-roster-bridge.cpp
+       engine/components/local-roster/local-roster-main.cpp
 
 ##
 # Sources of the moving logo component
diff --git a/lib/engine/components/local-roster/local-cluster.cpp 
b/lib/engine/components/local-roster/local-cluster.cpp
index 188d236..106c681 100644
--- a/lib/engine/components/local-roster/local-cluster.cpp
+++ b/lib/engine/components/local-roster/local-cluster.cpp
@@ -34,6 +34,7 @@
  */
 
 #include "local-cluster.h"
+#include "action.h"
 
 #include <glib/gi18n.h>
 
@@ -47,7 +48,7 @@ Local::Cluster::~Cluster ()
 }
 
 bool
-Local::Cluster::is_supported_uri (const std::string uri) const
+Local::Cluster::is_supported_uri (const std::string & uri) const
 {
   boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
 
@@ -57,30 +58,15 @@ Local::Cluster::is_supported_uri (const std::string uri) const
     return false;
 }
 
-void
-Local::Cluster::pull ()
-{
-  heap->new_presentity ("", "");
-}
-
 const std::set<std::string>
 Local::Cluster::existing_groups () const
 {
   return heap->existing_groups ();
 }
 
-bool
-Local::Cluster::populate_menu (Ekiga::MenuBuilder& builder)
-{
-  builder.add_action ("add", _("A_dd Contact"),
-                     boost::bind (&Local::Cluster::on_new_presentity, this));
-
-  return true;
-}
-
 void
 Local::Cluster::set_heap (HeapPtr _heap)
-{ 
+{
   heap = _heap;
   add_heap (heap);
   boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
@@ -92,12 +78,6 @@ Local::Cluster::set_heap (HeapPtr _heap)
 }
 
 void
-Local::Cluster::on_new_presentity ()
-{
-  heap->new_presentity ("", "");
-}
-
-void
 Local::Cluster::on_presence_received (std::string uri,
                                      std::string presence)
 {
@@ -109,3 +89,21 @@ void Local::Cluster::on_status_received (std::string uri,
 {
   heap->push_status (uri, status);
 }
+
+void Local::Cluster::register_actions (boost::shared_ptr<Ekiga::ContactCore> contact_core)
+{
+  Ekiga::TesterList testers;
+  testers.push_back (boost::bind (&Local::Cluster::is_supported_uri, this, _2));
+  testers.push_back (boost::bind (&Local::Heap::has_no_presentity_with_uri, heap, _2));
+  Ekiga::ActionPtr add (new Ekiga::ContactAction ("local-cluster-add", _("Add to Contact List"),
+                                                  boost::bind (static_cast<void (Local::Heap::*)(const 
Ekiga::ContactPtr&, const std::string&)>(&Local::Heap::new_presentity), heap, _1, _2),
+                                                  testers));
+  contact_core->add_action (add);
+}
+
+void Local::Cluster::register_actions ()
+{
+  /* Add Actor actions */
+  add_action (Ekiga::ActionPtr (new Ekiga::Action ("local-cluster-new", _("New Contact"),
+                                                   boost::bind (static_cast<void (Local::Heap::*)(const 
std::string&, const std::string&)>(&Local::Heap::new_presentity), heap, "", ""))));
+}
diff --git a/lib/engine/components/local-roster/local-cluster.h 
b/lib/engine/components/local-roster/local-cluster.h
index 18bf2bd..67beb8c 100644
--- a/lib/engine/components/local-roster/local-cluster.h
+++ b/lib/engine/components/local-roster/local-cluster.h
@@ -37,8 +37,8 @@
 #define __LOCAL_CLUSTER_H__
 
 #include "cluster-impl.h"
-#include "trigger.h"
 #include "local-heap.h"
+#include "contact-core.h"
 
 namespace Local
 {
@@ -50,7 +50,8 @@ namespace Local
 
   class Cluster :
     public Ekiga::ClusterImpl<Heap>,
-    public Ekiga::Trigger,
+    public Ekiga::Service,
+    public Ekiga::Actor,
     public boost::signals2::trackable
   {
   public:
@@ -59,9 +60,7 @@ namespace Local
 
     ~Cluster ();
 
-    bool populate_menu (Ekiga::MenuBuilder &);
-
-    bool is_supported_uri (const std::string uri) const;
+    bool is_supported_uri (const std::string & uri) const;
 
     const std::string get_name () const
     { return "local-cluster"; }
@@ -69,8 +68,6 @@ namespace Local
     const std::string get_description () const
     { return "\tProvides the internal roster"; }
 
-    void pull ();
-
     const std::set<std::string> existing_groups () const;
 
     HeapPtr get_heap () const
@@ -79,13 +76,16 @@ namespace Local
     // used by the local roster main code
     void set_heap (HeapPtr _heap);
 
+    /*** Actor stuff ***/
+    void register_actions (boost::shared_ptr<Ekiga::ContactCore> contact_core);
+    void register_actions ();
+
+
   private:
 
     boost::weak_ptr<Ekiga::PresenceCore> presence_core;
     HeapPtr heap;
 
-    void on_new_presentity ();
-
     void on_presence_received (std::string uri,
                               std::string presence);
 
diff --git a/lib/engine/components/local-roster/local-heap.cpp 
b/lib/engine/components/local-roster/local-heap.cpp
index 5f2d1de..7755754 100644
--- a/lib/engine/components/local-roster/local-heap.cpp
+++ b/lib/engine/components/local-roster/local-heap.cpp
@@ -112,8 +112,10 @@ Local::Heap::get_name () const
 bool
 Local::Heap::populate_menu (Ekiga::MenuBuilder &builder)
 {
-  builder.add_action ("add", _("A_dd Contact"),
-                     boost::bind (&Local::Heap::new_presentity, this, "", ""));
+  std::cout << "FIXME" << std::endl << std::flush;
+  //FIXME
+//  builder.add_action ("add", _("A_dd Contact"),
+//                   boost::bind (&Local::Heap::new_presentity, this, "", ""));
   return true;
 }
 
@@ -150,13 +152,13 @@ struct has_presentity_with_uri_helper
 };
 
 bool
-Local::Heap::has_presentity_with_uri (const std::string uri)
+Local::Heap::has_no_presentity_with_uri (const std::string & uri)
 {
   has_presentity_with_uri_helper helper(uri);
 
   visit_presentities (boost::ref (helper));
 
-  return helper.found;
+  return !helper.found;
 }
 
 struct existing_groups_helper
@@ -216,12 +218,18 @@ Local::Heap::existing_groups ()
   return result;
 }
 
+void
+Local::Heap::new_presentity (const Ekiga::ContactPtr & contact,
+                            const std::string & uri)
+{
+  new_presentity (contact->get_name (), uri);
+}
 
 void
-Local::Heap::new_presentity (const std::string name,
-                            const std::string uri)
+Local::Heap::new_presentity (const std::string & name,
+                            const std::string & uri)
 {
-  if (!has_presentity_with_uri (uri)) {
+  if (has_no_presentity_with_uri (uri)) {
 
     boost::shared_ptr<Ekiga::PresenceCore> pcore = presence_core.lock ();
     if (!pcore)
@@ -405,7 +413,7 @@ Local::Heap::new_presentity_form_submitted (bool submitted,
   uri = canonize_uri (uri);
 
   if (pcore->is_supported_uri (uri)
-      && !has_presentity_with_uri (uri)) {
+      && has_no_presentity_with_uri (uri)) {
 
     add (name, uri, groups);
     save ();
diff --git a/lib/engine/components/local-roster/local-heap.h b/lib/engine/components/local-roster/local-heap.h
index c94e9b0..1c4236c 100644
--- a/lib/engine/components/local-roster/local-heap.h
+++ b/lib/engine/components/local-roster/local-heap.h
@@ -40,6 +40,7 @@
 #include "heap-impl.h"
 #include "friend-or-foe.h"
 #include "local-presentity.h"
+#include "contact.h"
 
 #include "ekiga-settings.h"
 
@@ -109,9 +110,9 @@ namespace Local
 
     /** Determines if the given uri is already present in the Heap.
      * @param: A string representing an uri.
-     * @return: TRUE if that uri is already present in the Heap.
+     * @return: FALSE if that uri is already present in the Heap.
      */
-    bool has_presentity_with_uri (const std::string uri);
+    bool has_no_presentity_with_uri (const std::string & uri);
 
 
     /** Returns the list of all groups already in used in the Heap.
@@ -130,8 +131,10 @@ namespace Local
      * @param: The name and uri of the presentity.
      * @return: TRUE if that uri is already present in the Heap.
      */
-    void new_presentity (const std::string name,
-                        const std::string uri);
+    void new_presentity (const Ekiga::ContactPtr & contact,
+                         const std::string & uri);
+    void new_presentity (const std::string & name = "",
+                        const std::string & uri = "");
 
 
     /**
diff --git a/lib/engine/components/local-roster/local-roster-main.cpp 
b/lib/engine/components/local-roster/local-roster-main.cpp
index 7e6ff96..97d9a83 100644
--- a/lib/engine/components/local-roster/local-roster-main.cpp
+++ b/lib/engine/components/local-roster/local-roster-main.cpp
@@ -37,6 +37,7 @@
 
 #include "local-roster-main.h"
 #include "presence-core.h"
+#include "contact-core.h"
 #include "friend-or-foe.h"
 #include "local-cluster.h"
 
@@ -49,8 +50,12 @@ struct LOCALROSTERSpark: public Ekiga::Spark
                            int* /*argc*/,
                            char** /*argv*/[])
   {
-    boost::shared_ptr<Ekiga::PresenceCore> presence_core = core.get<Ekiga::PresenceCore> ("presence-core");
-    boost::shared_ptr<Ekiga::FriendOrFoe> iff = core.get<Ekiga::FriendOrFoe> ("friend-or-foe");
+    boost::shared_ptr<Ekiga::PresenceCore> presence_core =
+      core.get<Ekiga::PresenceCore> ("presence-core");
+    boost::shared_ptr<Ekiga::ContactCore> contact_core =
+      core.get<Ekiga::ContactCore> ("contact-core");
+    boost::shared_ptr<Ekiga::FriendOrFoe> iff =
+      core.get<Ekiga::FriendOrFoe> ("friend-or-foe");
 
     if (presence_core && iff) {
 
@@ -61,6 +66,7 @@ struct LOCALROSTERSpark: public Ekiga::Spark
        iff->add_helper (heap);
        cluster->set_heap (heap);
        presence_core->add_cluster (cluster);
+        cluster->register_actions (contact_core);
        result = true;
       }
     }
diff --git a/lib/engine/engine.cpp b/lib/engine/engine.cpp
index 632fd41..3340cf4 100644
--- a/lib/engine/engine.cpp
+++ b/lib/engine/engine.cpp
@@ -57,7 +57,6 @@
 #include "hal-core.h"
 #include "history-main.h"
 #include "local-roster-main.h"
-#include "local-roster-bridge.h"
 #include "gtk-core-main.h"
 #include "gmconf-personal-details.h"
 
@@ -159,8 +158,6 @@ engine_init (Ekiga::ServiceCorePtr service_core,
 
   local_roster_init (kickstart);
 
-  local_roster_bridge_init (kickstart);
-
   plugin_init (kickstart);
 
   // FIXME: Some parts in the kickstart need the gui.  The gui needs


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