[ekiga/ds-gtk-application] Engine: Added first implementation of Actions and Actors.



commit 3aec83ef76a4027d7847235a0daa48cbd711b19e
Author: Damien Sandras <dsandras beip be>
Date:   Mon Mar 3 20:25:24 2014 +0100

    Engine: Added first implementation of Actions and Actors.
    
    Glib now requires a separation between menus and their actions. Actions
    can be accessible globally or locally and reused in menus, toobars, ...
    and basically everywhere depending on their context, ie their UI window.
    
    The current engine principle was relying on actions between exposed in
    real time when the appropriate object representation in the UI was
    selected.
    
    We are now introducing a new concepts where objects (derived objects or
    parent classes or ServiceCores) can expose Actions through Actors.
    
    We have two implementation of Actions:
    - The base class, simple
    - A derived objects dedicated to ContactActions

 lib/Makefile.am                           |    8 ++
 lib/engine/addressbook/contact-action.cpp |   76 ++++++++++++++
 lib/engine/addressbook/contact-action.h   |  111 +++++++++++++++++++++
 lib/engine/addressbook/contact-core.h     |    3 +
 lib/engine/framework/action.cpp           |   92 +++++++++++++++++
 lib/engine/framework/action.h             |  154 +++++++++++++++++++++++++++++
 lib/engine/framework/actor.cpp            |   54 ++++++++++
 lib/engine/framework/actor.h              |   88 ++++++++++++++++
 8 files changed, 586 insertions(+), 0 deletions(-)
---
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 1482701..be4571d 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -163,6 +163,10 @@ libekiga_la_SOURCES += \
 ##
 
 libekiga_la_SOURCES += \
+       engine/framework/action.h \
+       engine/framework/action.cpp \
+       engine/framework/actor.h \
+       engine/framework/actor.cpp \
        engine/framework/boost-exceptions.cpp \
        engine/framework/services.h \
        engine/framework/map-key-iterator.h \
@@ -231,6 +235,8 @@ libekiga_la_SOURCES += \
        engine/addressbook/book-impl.h \
        engine/addressbook/source.h \
        engine/addressbook/source-impl.h \
+       engine/addressbook/contact-action.h \
+       engine/addressbook/contact-action.cpp \
        engine/addressbook/contact-core.h \
        engine/addressbook/contact-core.cpp
 
@@ -354,6 +360,8 @@ libekiga_la_SOURCES += \
        engine/gui/gtk-core/menu-builder-gtk.cpp \
        engine/gui/gtk-core/form-dialog-gtk.h \
        engine/gui/gtk-core/form-dialog-gtk.cpp \
+       engine/gui/gtk-core/live-object-menu.h \
+       engine/gui/gtk-core/live-object-menu.cpp \
        engine/gui/gtk-core/optional-buttons-gtk.h \
        engine/gui/gtk-core/optional-buttons-gtk.cpp \
        engine/gui/gtk-core/codecsbox.cpp \
diff --git a/lib/engine/addressbook/contact-action.cpp b/lib/engine/addressbook/contact-action.cpp
new file mode 100644
index 0000000..3e36702
--- /dev/null
+++ b/lib/engine/addressbook/contact-action.cpp
@@ -0,0 +1,76 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         contact-action.cpp  -  description
+ *                         ----------------------------------
+ *   begin                : written in February 2014 by Damien Sandras
+ *   copyright            : (c) 2014 by Damien Sandras
+ *   description          : An engine action.
+ *
+ */
+
+#include "contact-action.h"
+
+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) :
+    Action (_name, _description)
+{
+  callback = _callback;
+  tester = _tester;
+}
+
+
+void
+ContactAction::set_data (ContactPtr _contact,
+                         const std::string & _uri)
+{
+  contact = _contact;
+  uri = _uri;
+}
+
+
+void
+ContactAction::on_activated ()
+{
+  if (can_run_with_data (contact, uri))
+    callback (contact, uri);
+}
+
+
+bool
+ContactAction::can_run_with_data (ContactPtr _contact,
+                                  const std::string & _uri)
+{
+  return (tester (_contact, _uri));
+}
diff --git a/lib/engine/addressbook/contact-action.h b/lib/engine/addressbook/contact-action.h
new file mode 100644
index 0000000..18f85e8
--- /dev/null
+++ b/lib/engine/addressbook/contact-action.h
@@ -0,0 +1,111 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         contact-action.h  -  description
+ *                         --------------------------------
+ *   begin                : written in February 2014 by Damien Sandras
+ *   copyright            : (c) 2014 by Damien Sandras
+ *   description          : An engine action.
+ *
+ */
+
+#ifndef __CONTACT_ACTION_H__
+#define __CONTACT_ACTION_H__
+
+#include "contact.h"
+#include "action.h"
+
+namespace Ekiga {
+
+  /**
+   * @defgroup contacts Address Book
+   * @{
+   */
+
+  /* A ContactAction is an action related to a Contact supporting URIs.
+   *
+   * The main difference between an Action and a ContactAction is the fact
+   * that a ContactAction is executed for a given (Contact, uri) tuple
+   * iff the (Contact, uri) tuple is valid for the given action.
+   */
+  class ContactAction : public Action
+  {
+
+  public:
+    /** 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 the tester checking if the ContactAction can be executed for
+     *        the given tuple.
+     */
+    ContactAction (const std::string & _name,
+                   const std::string & _description,
+                   boost::function2<void, ContactPtr, std::string> _callback,
+                   boost::function2<bool, ContactPtr, std::string> _tester);
+
+
+    /** Set the (Contact, uri) tuple on which the ContactAction should be run.
+     * They must stay valid until the ContactAction is activated.
+     * @param the contact part of the tuple.
+     * @param the uri part of the tuple.
+     */
+    void set_data (ContactPtr _contact,
+                   const std::string & _uri);
+
+
+    /** Checks if the ContactAction can be run on the (Contact, uri) tuple given
+     * as argument.
+     * @param the contact part of the tuple.
+     * @param the uri part of the tuple.
+     * @return true of the action can be run, false otherwise.
+     */
+    bool can_run_with_data (ContactPtr _contact,
+                            const std::string & _uri);
+
+
+  private:
+
+    void on_activated ();
+
+    boost::function2<void, ContactPtr, std::string> callback;
+    boost::function2<bool, ContactPtr, std::string> tester;
+    ContactPtr contact;
+    std::string uri;
+  };
+
+  /**
+   * @}
+   */
+};
+#endif
diff --git a/lib/engine/addressbook/contact-core.h b/lib/engine/addressbook/contact-core.h
index 6bbc8c4..7de0115 100644
--- a/lib/engine/addressbook/contact-core.h
+++ b/lib/engine/addressbook/contact-core.h
@@ -37,6 +37,7 @@
 #define __CONTACT_CORE_H__
 
 #include "services.h"
+#include "actor.h"
 #include "source.h"
 #include "scoped-connections.h"
 
@@ -68,6 +69,7 @@ namespace Ekiga
    */
   class ContactCore:
     public virtual LiveObject,
+    public Actor,
     public Service
   {
   public:
@@ -96,6 +98,7 @@ namespace Ekiga
     /*** LiveObject implementation ***/
     bool populate_menu (MenuBuilder& builder);
 
+
     /*** Public API ***/
 
     /** Adds a source to the ContactCore service.
diff --git a/lib/engine/framework/action.cpp b/lib/engine/framework/action.cpp
new file mode 100644
index 0000000..ba4d083
--- /dev/null
+++ b/lib/engine/framework/action.cpp
@@ -0,0 +1,92 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         action.cpp  -  description
+ *                         --------------------------
+ *   begin                : written in February 2014 by Damien Sandras
+ *   copyright            : (c) 2014 by Damien Sandras
+ *   description          : An engine action.
+ *
+ */
+
+#include "action.h"
+
+using namespace Ekiga;
+
+
+Action::Action (const std::string & _name,
+                const std::string & _description)
+{
+  name = _name;
+  description = _description;
+
+  activated.connect (boost::bind (&Action::on_activated, this));
+}
+
+
+Action::Action (const std::string & _name,
+                const std::string & _description,
+                boost::function0<void> _callback)
+{
+  name = _name;
+  description = _description;
+  callback = _callback;
+
+  activated.connect (boost::bind (&Action::on_activated, this));
+}
+
+
+const std::string &
+Action::get_name ()
+{
+  return name;
+}
+
+
+
+const std::string &
+Action::get_description ()
+{
+  return description;
+}
+
+
+
+void
+Action::activate ()
+{
+  activated ();
+}
+
+
+void
+Action::on_activated ()
+{
+  callback ();
+}
diff --git a/lib/engine/framework/action.h b/lib/engine/framework/action.h
new file mode 100644
index 0000000..1a476d6
--- /dev/null
+++ b/lib/engine/framework/action.h
@@ -0,0 +1,154 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         action.h  -  description
+ *                         ------------------------
+ *   begin                : written in February 2014 by Damien Sandras
+ *   copyright            : (c) 2014 by Damien Sandras
+ *   description          : An engine action.
+ *
+ */
+
+#ifndef __ACTION_H__
+#define __ACTION_H__
+
+#include <boost/signals2.hpp>
+#include <boost/function.hpp>
+#include <boost/smart_ptr.hpp>
+#include <map>
+
+namespace Ekiga {
+
+  /**
+   * @defgroup actions Action
+   * @{
+   */
+
+
+  /* An action is a way for Actor objects to expose functionnality to the UI
+   * or to other elements.
+   *
+   * Actions are usually exposed through the object API.
+   *
+   * Global actions are exposed through the parent class API. However, derived
+   * objects might allow processing more actions than the parent object.
+   *
+   * The Action object interface allows such derived objects to expose their
+   * own specific actions to be globally in such a way that they are usable
+   * through the user interface without requiring dynamic casts in the UI code
+   * to be able to use the full derived object API.
+   *
+   * CONVENTION:
+   * -----------
+   *
+   * Usually, specific actions implemented by some specialized derived objects
+   * will be defined in the derived object itself. However, generic actions -
+   * which are supposed to be implemented by all components - will be defined
+   * in the parent class. For example, the "dial" action will be defined
+   * in the CallCore itself, but the "make coffee" action will be defined in
+   * the CoffeeMachine object implementation.
+   *
+   * Generic actions are supposed to be named globally: e.g. "call".
+   * Specific actions are supposed to be named according the object name:
+   * e.g. "coffee-machine-do-coffee".
+   */
+  class Action
+  {
+  public:
+
+    /** Create an Action given a name and a description.
+     * @param the Action name (please read 'CONVENTION').
+     * @param the Action description. Can be used as description in menus
+     *        implementing Actions.
+     */
+    Action (const std::string & _name,
+            const std::string & _description);
+
+
+    /** Create an Action given a name, a description and a callback.
+     * @param the Action name (please read 'CONVENTION').
+     * @param the Action description. Can be used as description in menus
+     *        implementing Actions.
+     * @param the callback to executed when the Action is activated by
+     *        the user (from a menu or from the code itself).
+     */
+    Action (const std::string & _name,
+            const std::string & _description,
+            boost::function0<void> _callback);
+
+
+    /** Return the Action name.
+     * @return the Action name (please read 'CONVENTION').
+     */
+    const std::string & get_name ();
+
+
+    /** Return the Action description.
+     * @return the Action description.
+     */
+    const std::string & get_description ();
+
+
+    /** Activate the Action.
+     * This will emit the "activated" signal and trigger the callback
+     * execution.
+     */
+    void activate ();
+
+
+  protected:
+
+    std::string name;
+    std::string description;
+    boost::function0<void> callback;
+
+
+  private:
+
+    /** Internal callback executed when the Action activated signal is emitted.
+     * It basically calls the callback.
+     */
+    virtual void on_activated ();
+
+
+    /** This signal is emitted when the Action is activated. This triggers
+     * the signal execution.
+     */
+    boost::signals2::signal<void(void)> activated;
+  };
+
+  typedef boost::shared_ptr<Action> ActionPtr;
+  typedef std::map< std::string, ActionPtr > ActionMap;
+
+  /**
+   * @}
+   */
+}
+
+#endif
diff --git a/lib/engine/framework/actor.cpp b/lib/engine/framework/actor.cpp
new file mode 100644
index 0000000..4cf90a7
--- /dev/null
+++ b/lib/engine/framework/actor.cpp
@@ -0,0 +1,54 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         actor.cpp  -  description
+ *                         -------------------------
+ *   begin                : written in February 2014 by Damien Sandras
+ *   copyright            : (c) 2014 by Damien Sandras
+ *   description          : An engine actor.
+ *
+ */
+
+#include "actor.h"
+
+using namespace Ekiga;
+
+
+void
+Actor::add_action (ActionPtr action)
+{
+  actions.insert (std::make_pair (action->get_name (), action));
+}
+
+
+void
+Actor::register_actions ()
+{
+  // Nothing to do here yet.
+}
diff --git a/lib/engine/framework/actor.h b/lib/engine/framework/actor.h
new file mode 100644
index 0000000..de9e186
--- /dev/null
+++ b/lib/engine/framework/actor.h
@@ -0,0 +1,88 @@
+
+/* Ekiga -- A VoIP and Video-Conferencing application
+ * Copyright (C) 2000-2014 Damien Sandras <dsandras seconix com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ *
+ * Ekiga is licensed under the GPL license and as a special exception,
+ * you have permission to link or otherwise combine this program with the
+ * programs OPAL, OpenH323 and PWLIB, and distribute the combination,
+ * without applying the requirements of the GNU GPL to the OPAL, OpenH323
+ * and PWLIB programs, as long as you do follow the requirements of the
+ * GNU GPL for all the rest of the software thus combined.
+ */
+
+
+/*
+ *                         actor.h  -  description
+ *                         -----------------------
+ *   begin                : written in February 2014 by Damien Sandras
+ *   copyright            : (c) 2014 by Damien Sandras
+ *   description          : An engine actor.
+ *
+ */
+
+#ifndef __ACTOR_H__
+#define __ACTOR_H__
+
+#include "action.h"
+
+namespace Ekiga {
+
+  /**
+   * @defgroup actions Actor
+   * @{
+   */
+
+
+  /* An actor is an object able to execute Actions.
+   *
+   * Actor can register actions through the add_action method.
+   * acting.
+   */
+  class Actor
+  {
+    friend class ActorMenu;
+    friend class ContactActorMenu;
+
+  public:
+
+    /** Register an action on the given Actor.
+     *
+     * Actions that are not "added" using this method will not be usable
+     * from menus.
+     *
+     * @param An Action.
+     */
+    void add_action (ActionPtr action);
+
+
+  protected:
+
+    /** This method must be called by each Actor to register Actions.
+     */
+    virtual void register_actions ();
+
+    ActionMap actions;
+  };
+
+  /**
+   * @}
+   */
+}
+
+#endif
+


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