ekiga r6516 - in trunk: . lib/engine/framework
- From: jpuydt svn gnome org
- To: svn-commits-list gnome org
- Subject: ekiga r6516 - in trunk: . lib/engine/framework
- Date: Sat, 26 Jul 2008 00:53:28 +0000 (UTC)
Author: jpuydt
Date: Sat Jul 26 00:53:27 2008
New Revision: 6516
URL: http://svn.gnome.org/viewvc/ekiga?rev=6516&view=rev
Log:
Added new TemporaryMenuBuilder tool
Modified:
trunk/ChangeLog
trunk/lib/engine/framework/menu-builder-tools.cpp
trunk/lib/engine/framework/menu-builder-tools.h
Modified: trunk/lib/engine/framework/menu-builder-tools.cpp
==============================================================================
--- trunk/lib/engine/framework/menu-builder-tools.cpp (original)
+++ trunk/lib/engine/framework/menu-builder-tools.cpp Sat Jul 26 00:53:27 2008
@@ -35,6 +35,9 @@
#include "menu-builder-tools.h"
+/* First, the implementation of the short menu builder
+ */
+
Ekiga::ShortMenuBuilder::ShortMenuBuilder (MenuBuilder &builder_)
: builder(builder_), active(true)
{
@@ -63,6 +66,8 @@
}
+/* Second, the implementation of the trigger menu builder
+ */
Ekiga::TriggerMenuBuilder::TriggerMenuBuilder ()
: active(true)
@@ -96,3 +101,149 @@
else
return 1;
}
+
+
+/* third, the implementation of the temporary menu builder
+ * (with first the definiton of its helpers)
+ */
+
+class TemporaryMenuBuilderHelperAction:
+ public Ekiga::TemporaryMenuBuilderHelper
+{
+public:
+
+ TemporaryMenuBuilderHelperAction (const std::string icon_,
+ const std::string label_,
+ sigc::slot<void> callback_):
+ icon(icon_), label(label_), callback(callback_)
+ {
+ }
+
+ bool populate_menu (Ekiga::MenuBuilder& builder)
+ {
+ builder.add_action (icon, label, callback);
+ return true;
+ }
+
+private:
+
+ std::string icon;
+ std::string label;
+ sigc::slot<void> callback;
+};
+
+class TemporaryMenuBuilderHelperSeparator:
+ public Ekiga::TemporaryMenuBuilderHelper
+{
+public:
+
+ TemporaryMenuBuilderHelperSeparator ()
+ {}
+
+ bool populate_menu (Ekiga::MenuBuilder& builder)
+ {
+ builder.add_separator ();
+ return false;
+ }
+};
+
+class TemporaryMenuBuilderHelperGhost:
+ public Ekiga::TemporaryMenuBuilderHelper
+{
+public:
+
+ TemporaryMenuBuilderHelperGhost (const std::string icon_,
+ const std::string label_):
+ icon(icon_), label(label_)
+ {
+ }
+
+ bool populate_menu (Ekiga::MenuBuilder& builder)
+ {
+ builder.add_ghost (icon, label);
+ return false;
+ }
+
+private:
+
+ std::string icon;
+ std::string label;
+};
+
+Ekiga::TemporaryMenuBuilder::TemporaryMenuBuilder ()
+ : count(0)
+{
+ /* nothing more */
+}
+
+Ekiga::TemporaryMenuBuilder::~TemporaryMenuBuilder ()
+{
+ clear ();
+}
+
+void
+Ekiga::TemporaryMenuBuilder::add_action (const std::string icon,
+ const std::string label,
+ sigc::slot<void> callback)
+{
+ TemporaryMenuBuilderHelperAction* helper = NULL;
+
+ helper = new TemporaryMenuBuilderHelperAction (icon, label, callback);
+
+ count++;
+ helpers.push_back (helper);
+}
+
+void
+Ekiga::TemporaryMenuBuilder::add_separator ()
+{
+ TemporaryMenuBuilderHelperSeparator* helper = NULL;
+
+ helper = new TemporaryMenuBuilderHelperSeparator;
+
+ helpers.push_back (helper);
+}
+
+void
+Ekiga::TemporaryMenuBuilder::add_ghost (const std::string icon,
+ const std::string label)
+{
+ TemporaryMenuBuilderHelperGhost* helper = NULL;
+
+ helper = new TemporaryMenuBuilderHelperGhost (icon, label);
+
+ helpers.push_back (helper);
+}
+
+int
+Ekiga::TemporaryMenuBuilder::size () const
+{
+ return count;
+}
+
+bool
+Ekiga::TemporaryMenuBuilder::populate_menu (MenuBuilder& builder)
+{
+ bool result = false;
+
+ for (std::list<TemporaryMenuBuilderHelper*>::iterator iter = helpers.begin ();
+ iter != helpers.end ();
+ ++iter)
+ result = result || (*iter)->populate_menu (builder);
+
+ clear ();
+
+ return result;
+}
+
+void
+Ekiga::TemporaryMenuBuilder::clear ()
+{
+ count = 0;
+
+ for (std::list<TemporaryMenuBuilderHelper*>::iterator iter = helpers.begin ();
+ iter != helpers.end ();
+ ++iter)
+ delete *iter;
+ helpers.clear ();
+}
Modified: trunk/lib/engine/framework/menu-builder-tools.h
==============================================================================
--- trunk/lib/engine/framework/menu-builder-tools.h (original)
+++ trunk/lib/engine/framework/menu-builder-tools.h Sat Jul 26 00:53:27 2008
@@ -127,6 +127,72 @@
bool active;
};
+
+ /** Temporary menu builder
+ *
+ * Again, this menu builder doesn't really build a menu itself ; instead
+ * it stores what is given to it, to give it later to a real menu builder.
+ * The idea is that the fact the populate_menu methods return a boolean
+ * allows knowing whether something was given, but there is no way to
+ * know if something will be given.
+ *
+ * For example, you can do :
+ * <pre>
+ * SomeRealMenuBuilder builder;
+ * TemporartyMenuBuilder tmp_builder;
+ *
+ * if (object1->populate_menu (tmp_builder)) {
+ *
+ * builder.add_ghost ("", "Object 1");
+ * tmp_builder.populate_menu (builder);
+ * }
+ * if (object2->populate_menu (tmp_builder)) {
+ *
+ * builder.add_ghost ("", "Object 2");
+ * tmp_builder.populate_menu (builder);
+ * }
+ * </pre>
+ *
+ */
+
+ /* it's stupid to have to make it public, but... */
+ class TemporaryMenuBuilderHelper
+ {
+ public:
+
+ virtual bool populate_menu (Ekiga::MenuBuilder& builder) = 0;
+ };
+
+ class TemporaryMenuBuilder: public MenuBuilder
+ {
+ public:
+
+ TemporaryMenuBuilder ();
+
+ ~TemporaryMenuBuilder ();
+
+ void add_action (const std::string icon,
+ const std::string label,
+ sigc::slot<void> callback);
+
+ void add_separator ();
+
+ void add_ghost (const std::string icon,
+ const std::string label);
+
+ int size () const;
+
+ /* this empties this temporary builder, so it can be reused */
+ bool populate_menu (MenuBuilder& builder);
+
+ private:
+
+ int count;
+
+ std::list<TemporaryMenuBuilderHelper*> helpers;
+
+ void clear ();
+ };
};
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]