[glibmm] OptionGroup: Add set_translate_slot().
- From: José Alburquerque <jaalburqu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] OptionGroup: Add set_translate_slot().
- Date: Thu, 27 May 2010 04:57:15 +0000 (UTC)
commit 4a3d2f5c4624620674f96f9855eb20fec3d7930a
Author: José Alburquerque <jaalburqu svn gnome org>
Date: Thu May 27 00:08:53 2010 -0400
OptionGroup: Add set_translate_slot().
* glib/src/optiongroup.ccg:
* glib/src/optiongroup.hg: Wrap g_option_group_set_translate_func().
ChangeLog | 7 +++++++
glib/src/optiongroup.ccg | 39 +++++++++++++++++++++++++++++++++++++++
glib/src/optiongroup.hg | 25 +++++++++++++++++++------
3 files changed, 65 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 592f1e7..8761df4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-05-27 José Alburquerque <jaalburqu svn gnome org>
+
+ OptionGroup: Add set_translate_slot().
+
+ * glib/src/optiongroup.ccg:
+ * glib/src/optiongroup.hg: Wrap g_option_group_set_translate_func().
+
2010-05-25 José Alburquerque <jaalburqu svn gnome org>
Add _IGNORE's for g_iconv().
diff --git a/glib/src/optiongroup.ccg b/glib/src/optiongroup.ccg
index c27595a..e7941fb 100644
--- a/glib/src/optiongroup.ccg
+++ b/glib/src/optiongroup.ccg
@@ -21,6 +21,7 @@
#include <glibmm/optionentry.h>
#include <glibmm/optioncontext.h>
#include <glibmm/utility.h>
+#include <glibmm/exceptionhandler.h>
//#include <glibmm/containers.h>
#include <glib.h> // g_malloc
@@ -69,6 +70,33 @@ static void g_callback_error(GOptionContext* context, GOptionGroup* /* group */,
return option_group->on_error(cppContext, *option_group);
}
+const gchar* OptionGroup_Translate_glibmm_callback(const gchar* string,
+ gpointer data)
+{
+ Glib::OptionGroup::SlotTranslate* the_slot =
+ static_cast<Glib::OptionGroup::SlotTranslate*>(data);
+
+ #ifdef GLIBMM_EXCEPTIONS_ENABLED
+ try
+ {
+ #endif //GLIBMM_EXCEPTIONS_ENABLED
+ return g_strdup((*the_slot)(Glib::ustring(string)).c_str());
+ #ifdef GLIBMM_EXCEPTIONS_ENABLED
+ }
+ catch(...)
+ {
+ Glib::exception_handlers_invoke();
+ }
+ #endif //GLIBMM_EXCEPTIONS_ENABLED
+
+ return 0;
+}
+
+static void OptionGroup_Translate_glibmm_callback_destroy(void* data)
+{
+ delete static_cast<Glib::OptionGroup::SlotTranslate*>(data);
+}
+
} /* extern "C" */
} //anonymous namespace
@@ -213,6 +241,17 @@ void OptionGroup::on_error(OptionContext& /* context */, OptionGroup& /* group *
{
}
+void OptionGroup::set_translate_slot(const SlotTranslate& slot)
+{
+ // Create a copy of the slot. A pointer to this will be passed through the
+ // callback's data parameter. It will be deleted when
+ // OptionGroup_Translate_glibmm_callback_destroy() is called.
+ SlotTranslate* slot_copy = new SlotTranslate(slot);
+ g_option_group_set_translate_func(gobj(),
+ &OptionGroup_Translate_glibmm_callback, slot_copy,
+ &OptionGroup_Translate_glibmm_callback_destroy);
+}
+
OptionGroup::CppOptionEntry::CppOptionEntry()
: carg_type_(G_OPTION_ARG_NONE), carg_(0), cpparg_(0), entry_(0)
diff --git a/glib/src/optiongroup.hg b/glib/src/optiongroup.hg
index 0bc826e..2894f93 100644
--- a/glib/src/optiongroup.hg
+++ b/glib/src/optiongroup.hg
@@ -20,6 +20,7 @@
_DEFS(glibmm,glib)
#include <glibmm/ustring.h>
+#include <sigc++/slot.h>
#include <map>
#include <vector>
#include <glib.h> //TODO: Try to hide this.
@@ -46,6 +47,10 @@ class OptionGroup
{
_CLASS_GENERIC(OptionGroup, GOptionGroup)
public:
+ /** For example Glib::ustring on_translate(const Glib::ustring& original);.
+ */
+ typedef sigc::slot<Glib::ustring, const Glib::ustring&> SlotTranslate;
+
OptionGroup(const Glib::ustring& name, const Glib::ustring& description, const Glib::ustring& help_description = Glib::ustring());
/** This always takes ownership of the underlying GOptionGroup,
@@ -77,12 +82,20 @@ public:
void add_entry(const OptionEntry& entry, vecustrings& arg);
void add_entry_filename(const OptionEntry& entry, vecstrings& arg);
-/* TODO:
-void g_option_group_set_translate_func (GOptionGroup *group,
- GTranslateFunc func,
- gpointer data,
- GDestroyNotify destroy_notify);
-*/
+ /** Sets the slot which is used to translate user-visible strings, for --help
+ * output. Different groups can use a different SlotTranslate. If a translate
+ * slot is not set, strings are not translated.
+ *
+ * If you are using gettext(), you only need to set the translation domain,
+ * see set_translation_domain().
+ *
+ * @param slot the slot to be used for translation.
+ *
+ * @newin{2,26}
+ */
+ void set_translate_slot(const SlotTranslate& slot);
+ _IGNORE(g_option_group_set_translate_func)
+
_WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), g_option_group_set_translation_domain)
GOptionGroup* gobj() { return gobject_; }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]