[ekiga] Added a simple little menu builder



commit 5281ec3e41ae549209e466789e560b254de9c30a
Author: Julien Puydt <jpuydt gnome org>
Date:   Thu Jun 25 14:08:19 2009 +0200

    Added a simple little menu builder
    
    I have uses in my head for that one... but it may take
    month before it becomes real :-(

 lib/engine/framework/menu-builder-tools.cpp |   48 ++++++++++++++++++++++++++
 lib/engine/framework/menu-builder-tools.h   |   49 +++++++++++++++++++++++++++
 2 files changed, 97 insertions(+), 0 deletions(-)
---
diff --git a/lib/engine/framework/menu-builder-tools.cpp b/lib/engine/framework/menu-builder-tools.cpp
index 573dd86..1569f62 100644
--- a/lib/engine/framework/menu-builder-tools.cpp
+++ b/lib/engine/framework/menu-builder-tools.cpp
@@ -254,3 +254,51 @@ Ekiga::TemporaryMenuBuilder::clear ()
     delete *iter;
   helpers.clear ();
 }
+
+Ekiga::Activator::Activator (const std::string label_):
+  label(label_), did_it(false)
+{}
+
+Ekiga::Activator::~Activator ()
+{}
+
+void
+Ekiga::Activator::add_action (const std::string /*icon*/,
+			      const std::string label_,
+			      sigc::slot0<void> callback)
+{
+  if (label == label_) {
+
+    did_it = true;
+    callback ();
+  }
+}
+
+void
+Ekiga::Activator::add_separator ()
+{
+}
+
+void
+Ekiga::Activator::add_ghost (const std::string /*icon*/,
+			     const std::string /*label*/)
+{
+}
+
+bool
+Ekiga::Activator::empty () const
+{
+  return true;
+}
+
+int
+Ekiga::Activator::size () const
+{
+  return 0;
+}
+
+bool
+Ekiga::Activator::could_act () const
+{
+  return did_it;
+}
diff --git a/lib/engine/framework/menu-builder-tools.h b/lib/engine/framework/menu-builder-tools.h
index 5f7fed5..dee1e19 100644
--- a/lib/engine/framework/menu-builder-tools.h
+++ b/lib/engine/framework/menu-builder-tools.h
@@ -195,6 +195,55 @@ namespace Ekiga
 
     void clear ();
   };
+
+  /* Activator menu builder
+   *
+   * Yet another menu builder which doesn't build a menu (!) : you build it
+   * with an action label, and it will trigger that action when used. It also
+   * provides a method to check if the action could be carried on.
+   *
+   * For example, you can do :
+   * <pre>
+   *  Activator do ("accept");
+   *  Ekiga::Call call;
+   *
+   *  call.populate_menu (do); // we accept the call if the action is available
+   *
+   *  if (do.could_act ()) {
+   *    ...
+   *  } else {
+   *    ...
+   *  }
+   * </pre>
+   */
+  class Activator: public MenuBuilder
+  {
+  public:
+
+    Activator (const std::string label_);
+
+    ~Activator ();
+
+    void add_action (const std::string icon,
+		     const std::string label,
+		     sigc::slot0<void> callback);
+
+    void add_separator ();
+
+    void add_ghost (const std::string icon,
+		    const std::string label);
+
+    bool empty () const;
+
+    int size () const;
+
+    bool could_act () const;
+
+  private:
+
+    const std::string label;
+    bool did_it;
+  };
 };
 
 #endif



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