[ekiga/ds-gtk-application] ContactAction: Allow ContactAction to be validated with several testers.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga/ds-gtk-application] ContactAction: Allow ContactAction to be validated with several testers.
- Date: Sun, 30 Mar 2014 17:50:08 +0000 (UTC)
commit 667350b8897a1bdb78025d683a52d13a98127118
Author: Damien Sandras <dsandras beip be>
Date: Sun Mar 30 19:41:39 2014 +0200
ContactAction: Allow ContactAction to be validated with several testers.
Also added typedefs for better code clarity.
lib/engine/addressbook/contact-action.cpp | 30 +++++++++++++++++++++++---
lib/engine/addressbook/contact-action.h | 32 +++++++++++++++++++++++++---
2 files changed, 54 insertions(+), 8 deletions(-)
---
diff --git a/lib/engine/addressbook/contact-action.cpp b/lib/engine/addressbook/contact-action.cpp
index 400b839..6621993 100644
--- a/lib/engine/addressbook/contact-action.cpp
+++ b/lib/engine/addressbook/contact-action.cpp
@@ -42,18 +42,31 @@ using namespace Ekiga;
ContactAction::ContactAction (const std::string & _name,
const std::string & _description,
- boost::function2<void, ContactPtr, std::string> _callback,
- boost::function2<bool, ContactPtr, std::string> _tester) :
+ Callback _callback,
+ Tester _tester) :
Action (_name, _description)
{
callback = _callback;
- tester = _tester;
+ testers.push_back (_tester);
/* ContactAction objects should be disabled until data is set */
set_data ();
}
+ContactAction::ContactAction (const std::string & _name,
+ const std::string & _description,
+ Callback _callback,
+ const TesterList & _testers) :
+ Action (_name, _description)
+{
+ callback = _callback;
+ testers = _testers;
+
+ /* ContactAction objects should be disabled until data is set */
+ set_data ();
+}
+
void
ContactAction::set_data (ContactPtr _contact,
const std::string & _uri)
@@ -80,5 +93,14 @@ bool
ContactAction::can_run_with_data (ContactPtr _contact,
const std::string & _uri)
{
- return (tester (_contact, _uri));
+ if (!testers.empty ()) {
+ for (TesterList::const_iterator it = testers.begin ();
+ it != testers.end ();
+ ++it) {
+ if (!(*it) (_contact, _uri))
+ return false;
+ }
+ return true;
+ }
+ return false;
}
diff --git a/lib/engine/addressbook/contact-action.h b/lib/engine/addressbook/contact-action.h
index f79aa3e..7b46580 100644
--- a/lib/engine/addressbook/contact-action.h
+++ b/lib/engine/addressbook/contact-action.h
@@ -41,8 +41,14 @@
#include "contact.h"
#include "action.h"
+#include <list>
+
namespace Ekiga {
+ typedef boost::function2<void, ContactPtr, const std::string &> Callback;
+ typedef boost::function2<bool, ContactPtr, const std::string &> Tester;
+ typedef std::list<Tester> TesterList;
+
/**
* @defgroup contacts Address Book
* @{
@@ -71,8 +77,25 @@ namespace Ekiga {
*/
ContactAction (const std::string & _name,
const std::string & _description,
- boost::function2<void, ContactPtr, std::string> _callback,
- boost::function2<bool, ContactPtr, std::string> _tester);
+ Callback _callback,
+ Tester _tester);
+
+
+ /** Create an Action given a name, a description, a callback and
+ * a validity tester.
+ * @param the Action name (please read 'CONVENTION' in action.h).
+ * @param the Action description. Can be used as description in menus
+ * implementing Actions.
+ * @param the callback to executed when the ContactAction is activated by
+ * the user (from a menu or from the code itself) for the
+ * given Contact and uri.
+ * @param a list of testers to check if the ContactAction can be executed for
+ * the given tuple.
+ */
+ ContactAction (const std::string & _name,
+ const std::string & _description,
+ Callback _callback,
+ const TesterList & _testers);
/** Set the (Contact, uri) tuple on which the ContactAction should be run.
@@ -99,8 +122,9 @@ namespace Ekiga {
void on_activated ();
- boost::function2<void, ContactPtr, std::string> callback;
- boost::function2<bool, ContactPtr, std::string> tester;
+ Callback callback;
+ TesterList testers;
+
ContactPtr contact;
std::string uri;
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]