[ekiga] Made the foe-list component a contact decorator (works in all address books, including call history!



commit d2a1dc80d606c96f6b3f1632dc1184718fe6cfbe
Author: Julien Puydt <julien puydt laposte net>
Date:   Mon Jun 23 14:52:11 2014 +0200

    Made the foe-list component a contact decorator (works in all address books, including call history!)

 lib/engine/components/foe-list/foe-list.cpp |   31 +++++++++++++++++++++++++-
 lib/engine/components/foe-list/foe-list.h   |   17 +++++++++++++-
 lib/engine/engine.cpp                       |    9 +++++--
 3 files changed, 50 insertions(+), 7 deletions(-)
---
diff --git a/lib/engine/components/foe-list/foe-list.cpp b/lib/engine/components/foe-list/foe-list.cpp
index c3799fa..eb05616 100644
--- a/lib/engine/components/foe-list/foe-list.cpp
+++ b/lib/engine/components/foe-list/foe-list.cpp
@@ -33,11 +33,14 @@
  *
  */
 
-#include "foe-list.h"
+#include <glib/gi18n.h>
 
 #include "ekiga-settings.h"
 
-Ekiga::FoeList::FoeList()
+#include "foe-list.h"
+
+Ekiga::FoeList::FoeList(boost::shared_ptr<FriendOrFoe> fof):
+  friend_or_foe(fof)
 {
 }
 
@@ -46,6 +49,30 @@ 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
diff --git a/lib/engine/components/foe-list/foe-list.h b/lib/engine/components/foe-list/foe-list.h
index 9120ae8..26e816b 100644
--- a/lib/engine/components/foe-list/foe-list.h
+++ b/lib/engine/components/foe-list/foe-list.h
@@ -36,6 +36,7 @@
 #ifndef __FOE_LIST_H__
 #define __FOE_LIST_H__
 
+#include "contact-core.h"
 #include "friend-or-foe.h"
 
 namespace Ekiga
@@ -43,10 +44,11 @@ namespace Ekiga
 
   class FoeList:
     public Service,
+    public ContactDecorator,
     public FriendOrFoe::Helper
   {
   public:
-    FoeList();
+    FoeList(boost::shared_ptr<FriendOrFoe> friend_or_foo);
 
     ~FoeList();
 
@@ -58,7 +60,13 @@ namespace Ekiga
     const std::string get_description () const
     { return "List of persons the user does not want to hear about"; }
 
-    /* FriendOrFoe::Helper api */
+    /* 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;
@@ -66,6 +74,11 @@ namespace Ekiga
     /* specific api */
 
     void add_foe (const std::string token);
+
+  private:
+
+    // beware of dependency loops!
+    boost::weak_ptr<FriendOrFoe> friend_or_foe;
   };
 };
 
diff --git a/lib/engine/engine.cpp b/lib/engine/engine.cpp
index 3b6ed20..e302429 100644
--- a/lib/engine/engine.cpp
+++ b/lib/engine/engine.cpp
@@ -101,7 +101,7 @@ engine_init (Ekiga::ServiceCorePtr service_core,
   service_core->add (notification_core);
 
   boost::shared_ptr<Ekiga::FriendOrFoe> friend_or_foe (new Ekiga::FriendOrFoe);
-  boost::shared_ptr<Ekiga::FoeList> foe_list (new Ekiga::FoeList);
+  boost::shared_ptr<Ekiga::FoeList> foe_list (new Ekiga::FoeList (friend_or_foe));
   boost::shared_ptr<Ekiga::AccountCore> account_core (new Ekiga::AccountCore);
   boost::shared_ptr<Ekiga::ContactCore> contact_core (new Ekiga::ContactCore);
   boost::shared_ptr<Ekiga::CallCore> call_core (new Ekiga::CallCore (friend_or_foe));
@@ -128,8 +128,6 @@ engine_init (Ekiga::ServiceCorePtr service_core,
   service_core->add (details);
   service_core->add (presence_core);
 
-  friend_or_foe->add_helper (foe_list);
-
   if (!videoinput_mlogo_init (*service_core, &argc, &argv)) {
     return;
   }
@@ -206,6 +204,11 @@ engine_init (Ekiga::ServiceCorePtr service_core,
   hal_core->audioinput_device_added.connect (boost::bind (&Ekiga::AudioInputCore::add_device, boost::ref 
(*audioinput_core), _1, _2, _3));
   hal_core->audioinput_device_removed.connect (boost::bind (&Ekiga::AudioInputCore::remove_device, 
boost::ref (*audioinput_core), _1, _2, _3));
 
+
+  /* FIXME: does it really belong here? */
+  friend_or_foe->add_helper (foe_list);
+  contact_core->add_contact_decorator (foe_list);
+
 #if DEBUG_STARTUP
   std::cout << "Here is what ekiga is made of for this run :" << std::endl;
   service_core->dump (std::cout);


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