[ekiga] FriendOrFoe: Use ActionProvider.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga] FriendOrFoe: Use ActionProvider.
- Date: Thu, 12 Nov 2015 18:36:48 +0000 (UTC)
commit dff1f70590263c116fe68977dfca5b0360d93002
Author: Damien Sandras <dsandras seconix com>
Date: Sun Oct 11 11:43:31 2015 +0200
FriendOrFoe: Use ActionProvider.
lib/engine/components/foe-list/foe-list.cpp | 26 +++++++++++++++-----------
lib/engine/components/foe-list/foe-list.h | 8 +++++++-
lib/engine/friend-or-foe/friend-or-foe.cpp | 5 ++++-
lib/engine/friend-or-foe/friend-or-foe.h | 27 ++++++++++-----------------
4 files changed, 36 insertions(+), 30 deletions(-)
---
diff --git a/lib/engine/components/foe-list/foe-list.cpp b/lib/engine/components/foe-list/foe-list.cpp
index 8e72057..40e5b62 100644
--- a/lib/engine/components/foe-list/foe-list.cpp
+++ b/lib/engine/components/foe-list/foe-list.cpp
@@ -49,9 +49,10 @@ Ekiga::FoeList::~FoeList()
{
}
+
Ekiga::FriendOrFoe::Identification
Ekiga::FoeList::decide (const std::string /*domain*/,
- const std::string uri) const
+ const std::string uri)
{
boost::scoped_ptr<Ekiga::Settings> settings(new Ekiga::Settings (CONTACTS_SCHEMA));
std::list<std::string> foes = settings->get_string_list ("foe-list");
@@ -60,18 +61,10 @@ Ekiga::FoeList::decide (const std::string /*domain*/,
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;
}
+
void
Ekiga::FoeList::add_foe (const std::string token)
{
@@ -82,5 +75,16 @@ Ekiga::FoeList::add_foe (const std::string token)
boost::shared_ptr<FriendOrFoe> fof = friend_or_foe.lock ();
if (fof)
- fof->remove_helper_action ("blacklist");
+ remove_action (*fof, "blacklist");
+}
+
+
+void
+Ekiga::FoeList::pull_actions (Actor & actor,
+ G_GNUC_UNUSED const std::string & display_name,
+ const std::string & uri)
+{
+ if (decide (std::string (), uri) != Ekiga::FriendOrFoe::Foe)
+ add_action (actor, Ekiga::ActionPtr (new Ekiga::Action ("blacklist", _("_Blacklist"),
+ boost::bind (&Ekiga::FoeList::add_foe, this,
uri))));
}
diff --git a/lib/engine/components/foe-list/foe-list.h b/lib/engine/components/foe-list/foe-list.h
index cfdf8a3..d47abc5 100644
--- a/lib/engine/components/foe-list/foe-list.h
+++ b/lib/engine/components/foe-list/foe-list.h
@@ -45,6 +45,7 @@ namespace Ekiga
public Service,
public FriendOrFoe::Helper
{
+
public:
FoeList(boost::shared_ptr<FriendOrFoe> friend_or_foo);
@@ -61,12 +62,17 @@ namespace Ekiga
/* Ekiga::FriendOrFoe::Helper api */
FriendOrFoe::Identification decide (const std::string domain,
- const std::string token) const;
+ const std::string token);
/* specific api */
void add_foe (const std::string token);
private:
+ /* ActionProvider api */
+ void pull_actions (Actor & actor,
+ const std::string & display_name,
+ const std::string & uri);
+
// beware of dependency loops!
boost::weak_ptr<FriendOrFoe> friend_or_foe;
diff --git a/lib/engine/friend-or-foe/friend-or-foe.cpp b/lib/engine/friend-or-foe/friend-or-foe.cpp
index d797dea..0ae4aaa 100644
--- a/lib/engine/friend-or-foe/friend-or-foe.cpp
+++ b/lib/engine/friend-or-foe/friend-or-foe.cpp
@@ -36,16 +36,19 @@
Ekiga::FriendOrFoe::Identification
Ekiga::FriendOrFoe::decide (const std::string domain,
- const std::string token) const
+ const std::string token)
{
Identification answer = Unknown;
Identification iter_answer;
+ remove_actions ();
+
for (helpers_type::const_iterator iter = helpers.begin ();
iter != helpers.end ();
++iter) {
iter_answer = (*iter)->decide (domain, token);
+ (*iter)->pull_actions (*this, std::string (), token);
if (answer < iter_answer)
answer = iter_answer;
}
diff --git a/lib/engine/friend-or-foe/friend-or-foe.h b/lib/engine/friend-or-foe/friend-or-foe.h
index ade1837..9054648 100644
--- a/lib/engine/friend-or-foe/friend-or-foe.h
+++ b/lib/engine/friend-or-foe/friend-or-foe.h
@@ -53,6 +53,7 @@
#include "services.h"
#include "actor.h"
+#include "action-provider.h"
namespace Ekiga
{
@@ -65,35 +66,27 @@ namespace Ekiga
/* beware of the order : we prefer erring on the side of safety */
typedef enum { Unknown, Foe, Neutral, Friend } Identification;
- class Helper
+ class Helper : public URIActionProvider
{
+ friend class FriendOrFoe;
public:
virtual ~Helper ()
{}
virtual Identification decide (const std::string domain,
- const std::string token) const = 0;
+ const std::string token) = 0;
+
+ protected:
+ virtual void pull_actions (Actor & actor,
+ const std::string & display_name,
+ const std::string & uri) = 0;
};
Identification decide (const std::string domain,
- const std::string token) const;
+ const std::string token);
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]