[ekiga] FriendOrFoe: Ported to use Actions.



commit 2723d366086dbc98bf5da267ccd1bf9f9e5311ec
Author: Damien Sandras <dsandras seconix com>
Date:   Sat Oct 10 17:38:30 2015 +0200

    FriendOrFoe: Ported to use Actions.

 lib/engine/components/foe-list/foe-list.cpp |   42 ++++++++++----------------
 lib/engine/components/foe-list/foe-list.h   |    8 -----
 lib/engine/friend-or-foe/friend-or-foe.h    |   19 +++++++++++-
 3 files changed, 34 insertions(+), 35 deletions(-)
---
diff --git a/lib/engine/components/foe-list/foe-list.cpp b/lib/engine/components/foe-list/foe-list.cpp
index ce93b5c..8e72057 100644
--- a/lib/engine/components/foe-list/foe-list.cpp
+++ b/lib/engine/components/foe-list/foe-list.cpp
@@ -37,6 +37,7 @@
 #include "ekiga-settings.h"
 
 #include "foe-list.h"
+#include <iostream>
 
 Ekiga::FoeList::FoeList(boost::shared_ptr<FriendOrFoe> fof):
   friend_or_foe(fof)
@@ -48,41 +49,26 @@ Ekiga::FoeList::~FoeList()
 {
 }
 
-bool
-Ekiga::FoeList::populate_menu (ContactPtr /*contact*/,
-                              const std::string uri,
-                              MenuBuilder& builder)
-{
-  bool result = false;
-  boost::shared_ptr<FriendOrFoe> fof = friend_or_foe.lock ();
-
-  if (fof) {
-
-    Ekiga::FriendOrFoe::Identification current = fof->decide ("" /* FIXME */,
-                                                             uri);
-
-    if (current == Ekiga::FriendOrFoe::Unknown) {
-
-      builder.add_action ("blacklist", _("Add to blacklist"),
-                         boost::bind(&Ekiga::FoeList::add_foe, this, uri));
-      result = true;
-    }
-  }
-
-  return result;
-}
-
 Ekiga::FriendOrFoe::Identification
 Ekiga::FoeList::decide (const std::string /*domain*/,
-                       const std::string token) const
+                       const std::string uri) const
 {
   boost::scoped_ptr<Ekiga::Settings> settings(new Ekiga::Settings (CONTACTS_SCHEMA));
   std::list<std::string> foes = settings->get_string_list ("foe-list");
   Ekiga::FriendOrFoe::Identification result = Ekiga::FriendOrFoe::Unknown;
 
-  if (std::find (foes.begin (), foes.end (), token) != foes.end ())
+  if (std::find (foes.begin (), foes.end (), uri) != foes.end ())
     result = Ekiga::FriendOrFoe::Foe;
 
+  boost::shared_ptr<FriendOrFoe> fof = friend_or_foe.lock ();
+  if (fof) {
+    if (result != Ekiga::FriendOrFoe::Foe)
+      fof->add_helper_action (Ekiga::ActionPtr (new Ekiga::Action ("blacklist", _("_Blacklist"),
+                                                                   boost::bind (&Ekiga::FoeList::add_foe, 
(Ekiga::FoeList *) this, uri))));
+    else
+      fof->remove_helper_action ("blacklist");
+  }
+
   return result;
 }
 
@@ -93,4 +79,8 @@ Ekiga::FoeList::add_foe (const std::string token)
   std::list<std::string> foes = settings->get_string_list ("foe-list");
   foes.push_back (token);
   settings->set_string_list ("foe-list", foes);
+
+  boost::shared_ptr<FriendOrFoe> fof = friend_or_foe.lock ();
+  if (fof)
+    fof->remove_helper_action ("blacklist");
 }
diff --git a/lib/engine/components/foe-list/foe-list.h b/lib/engine/components/foe-list/foe-list.h
index 85f9b7c..cfdf8a3 100644
--- a/lib/engine/components/foe-list/foe-list.h
+++ b/lib/engine/components/foe-list/foe-list.h
@@ -37,7 +37,6 @@
 
 #include "contact-core.h"
 #include "friend-or-foe.h"
-#include "menu-builder.h"
 
 namespace Ekiga
 {
@@ -59,19 +58,12 @@ namespace Ekiga
     const std::string get_description () const
     { return "List of persons the user does not want to hear about"; }
 
-    /* Ekiga::ContactDecorator api */
-
-    bool populate_menu (ContactPtr contact,
-                       const std::string uri,
-                       MenuBuilder& builder);
 
     /* Ekiga::FriendOrFoe::Helper api */
-
     FriendOrFoe::Identification decide (const std::string domain,
                                        const std::string token) const;
 
     /* specific api */
-
     void add_foe (const std::string token);
 
   private:
diff --git a/lib/engine/friend-or-foe/friend-or-foe.h b/lib/engine/friend-or-foe/friend-or-foe.h
index a495575..ade1837 100644
--- a/lib/engine/friend-or-foe/friend-or-foe.h
+++ b/lib/engine/friend-or-foe/friend-or-foe.h
@@ -52,10 +52,13 @@
  */
 
 #include "services.h"
+#include "actor.h"
 
 namespace Ekiga
 {
-  class FriendOrFoe: public Ekiga::Service
+  class FriendOrFoe:
+      public Ekiga::Service,
+      public virtual Actor
   {
   public:
 
@@ -77,6 +80,20 @@ namespace Ekiga
 
     void add_helper (boost::shared_ptr<Helper> helper);
 
+    /* Allow our helpers to add actions */
+    // FIXME: It is not clean. Perhaps we should use an ActionProvider.
+    // But I am not sure that having a FoeList as a component and
+    // a FriendOrFoe engine class is the way to go.
+    void add_helper_action (ActionPtr action)
+    {
+      add_action (action);
+    }
+
+    void remove_helper_action (const std::string & action)
+    {
+      remove_action (action);
+    }
+
     /* this turns us into a service */
     const std::string get_name () const
     { return "friend-or-foe"; }


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