[ekiga/ds-gtk-application] ActorMenu: Fixed menu creation and actions handling.



commit 6c3135ed76183e92ad1ac2688c929b66c2b5047f
Author: Damien Sandras <dsandras beip be>
Date:   Tue Mar 4 20:23:40 2014 +0100

    ActorMenu: Fixed menu creation and actions handling.
    
    add_gio_actions methods were added to both ActorMenus objects.
    
    They allow adding Actions at the global GIO level.
    
    ActorMenus and ContactActorMenus add GIO actions at the application
    level. Window specific actions are typical of the user interface, while
    it is logical to have engine actions accessible globally.
    
    ContactActorMenus should only expose actions when the (Contact,uri) tuple
    given as data is valid for the given action. Having two different
    add_gio_actions implementations that are called from the constructor
    required the creation of a static C++ class method in order to create the
    object, then initialize it with the proper add_gio_actions method.

 lib/engine/gui/gtk-core/actor-menu.cpp |  100 ++++++++++++++++++++++++++------
 lib/engine/gui/gtk-core/actor-menu.h   |   21 +++++--
 2 files changed, 96 insertions(+), 25 deletions(-)
---
diff --git a/lib/engine/gui/gtk-core/actor-menu.cpp b/lib/engine/gui/gtk-core/actor-menu.cpp
index 205ab23..7cb28bf 100644
--- a/lib/engine/gui/gtk-core/actor-menu.cpp
+++ b/lib/engine/gui/gtk-core/actor-menu.cpp
@@ -40,7 +40,7 @@
 
 #include "action.h"
 #include "contact-core.h"
-#include "live-object-menu.h"
+#include "actor-menu.h"
 
 
 static void
@@ -56,8 +56,25 @@ action_activated (GSimpleAction *a,
 }
 
 
+
 Ekiga::ActorMenu::ActorMenu (const Ekiga::Actor & _obj) : obj (_obj)
 {
+}
+
+
+Ekiga::ActorMenu::~ActorMenu ()
+{
+  ActionMap::const_iterator it;
+
+  for (it = obj.actions.begin(); it != obj.actions.end(); ++it)
+    g_action_map_remove_action (G_ACTION_MAP (g_application_get_default ()),
+                                it->first.c_str ());
+}
+
+
+void
+Ekiga::ActorMenu::add_gio_actions ()
+{
   GSimpleAction *action = NULL;
   ActionMap::const_iterator it;
 
@@ -74,23 +91,11 @@ Ekiga::ActorMenu::ActorMenu (const Ekiga::Actor & _obj) : obj (_obj)
                         G_CALLBACK (action_activated),
                         (gpointer) this);
       g_object_unref (action);
-
-      std::cout << "Added action " << it->first << std::endl << std::flush;
     }
   }
 }
 
 
-Ekiga::ActorMenu::~ActorMenu ()
-{
-  ActionMap::const_iterator it;
-
-  for (it = obj.actions.begin(); it != obj.actions.end(); ++it)
-    g_action_map_remove_action (G_ACTION_MAP (g_application_get_default ()),
-                                it->first.c_str ());
-}
-
-
 const std::string
 Ekiga::ActorMenu::get_xml_menu (const std::string & id,
                                 const std::string & content,
@@ -105,6 +110,16 @@ Ekiga::ActorMenu::get_xml_menu (const std::string & id,
 }
 
 
+Ekiga::ActorMenu *
+Ekiga::ActorMenu::create (const Ekiga::Actor & obj)
+{
+  Ekiga::ActorMenu *m = new Ekiga::ActorMenu (obj);
+  m->add_gio_actions ();
+
+  return m;
+}
+
+
 void
 Ekiga::ActorMenu::activate (Ekiga::Action *action)
 {
@@ -113,12 +128,15 @@ Ekiga::ActorMenu::activate (Ekiga::Action *action)
 
 
 const std::string
-Ekiga::ActorMenu::as_xml ()
+Ekiga::ActorMenu::as_xml (const std::string & id)
 {
   ActionMap::const_iterator it;
+  std::string xml_content;
 
-  std::string xml_content =
-    "    <section>";
+  if (!id.empty ())
+   xml_content += "    <section id=\"" + id + "\">";
+  else
+   xml_content += "    <section>";
 
   for (it = obj.actions.begin(); it != obj.actions.end(); ++it) {
 
@@ -142,21 +160,55 @@ Ekiga::ContactActorMenu::ContactActorMenu (const Ekiga::Actor & _obj) : ActorMen
 
 
 void
+Ekiga::ContactActorMenu::add_gio_actions ()
+{
+  GSimpleAction *action = NULL;
+  ActionMap::const_iterator it;
+
+  for (it = obj.actions.begin(); it != obj.actions.end(); ++it) {
+
+    Ekiga::ContactAction *a = dynamic_cast<Ekiga::ContactAction *> (it->second.get ());
+
+    if (!a || !a->can_run_with_data (contact, uri)) {
+      g_action_map_remove_action (G_ACTION_MAP (g_application_get_default ()),
+                                  it->first.c_str ());
+    }
+    else if (a && a->can_run_with_data (contact, uri)) {
+
+      action = g_simple_action_new (it->first.c_str (), NULL);
+      g_object_set_data (G_OBJECT (action), "action", it->second.get ());
+      g_action_map_add_action (G_ACTION_MAP (g_application_get_default ()),
+                               G_ACTION (action));
+      g_signal_connect (action, "activate",
+                        G_CALLBACK (action_activated),
+                        (gpointer) this);
+      g_object_unref (action);
+    }
+  }
+}
+
+
+void
 Ekiga::ContactActorMenu::set_data (Ekiga::ContactPtr _contact,
                                    const std::string & _uri)
 {
   contact = _contact;
   uri = _uri;
+
+  add_gio_actions ();
 }
 
 
 const std::string
-Ekiga::ContactActorMenu::as_xml ()
+Ekiga::ContactActorMenu::as_xml (const std::string & id)
 {
   ActionMap::const_iterator it;
+  std::string xml_content;
 
-  std::string xml_content =
-    "    <section>";
+  if (!id.empty ())
+   xml_content += "    <section id=\"" + id + "\">";
+  else
+   xml_content += "    <section>";
 
   for (it = obj.actions.begin(); it != obj.actions.end(); ++it) {
 
@@ -177,3 +229,13 @@ Ekiga::ContactActorMenu::as_xml ()
 
   return xml_content;
 }
+
+
+Ekiga::ContactActorMenu *
+Ekiga::ContactActorMenu::create (const Ekiga::Actor & obj)
+{
+  Ekiga::ContactActorMenu *m = new Ekiga::ContactActorMenu (obj);
+  m->add_gio_actions ();
+
+  return m;
+}
diff --git a/lib/engine/gui/gtk-core/actor-menu.h b/lib/engine/gui/gtk-core/actor-menu.h
index 376e445..92c086a 100644
--- a/lib/engine/gui/gtk-core/actor-menu.h
+++ b/lib/engine/gui/gtk-core/actor-menu.h
@@ -60,18 +60,21 @@ namespace Ekiga {
   {
   public:
 
-    ActorMenu (const Actor & obj);
+    static ActorMenu* create (const Actor & obj);
 
     ~ActorMenu ();
 
     virtual void activate (Ekiga::Action *action);
-    virtual const std::string as_xml ();
+    virtual const std::string as_xml (const std::string & id = "");
 
     static const std::string get_xml_menu (const std::string & id,
                                            const std::string & content,
                                            bool full);
 
   protected:
+    ActorMenu (const Actor & obj);
+    virtual void add_gio_actions ();
+
     const Actor & obj;
   };
 
@@ -79,17 +82,23 @@ namespace Ekiga {
   {
   public:
 
-    ContactActorMenu (const Actor & obj);
+    static ContactActorMenu* create (const Actor & obj);
 
-    void set_data (ContactPtr _contact,
-                   const std::string & _uri);
+    void set_data (ContactPtr _contact = ContactPtr (),
+                   const std::string & _uri = "");
 
-    const std::string as_xml ();
+    const std::string as_xml (const std::string & id = "");
 
   protected:
+    ContactActorMenu (const Actor & obj);
+    void add_gio_actions ();
+
     ContactPtr contact;
     std::string uri;
   };
+
+  typedef boost::shared_ptr<ActorMenu> ActorMenuPtr;
+  typedef boost::shared_ptr<ContactActorMenu> ContactActorMenuPtr;
 }
 
 #endif


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