File ibus-pinyin-ibus-1.4-build.diff of Package ibus-pinyin

---
 src/PYConfig.cc |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 src/PYConfig.h  |   16 ++++++++---
 2 files changed, 85 insertions(+), 8 deletions(-)

--- a/src/PYConfig.cc
+++ b/src/PYConfig.cc
@@ -153,6 +153,18 @@
 Config::read (const gchar * name,
               bool          defval)
 {
+#if IBUS_CHECK_VERSION(1,3,99)
+    GVariant *value = NULL;
+    value = ibus_config_get_value (get<IBusConfig> (), m_section.c_str (), name);
+    if (value) {
+        if (g_variant_classify (value) == G_VARIANT_CLASS_BOOLEAN)
+            return g_variant_get_boolean (value);
+    }
+
+    // write default value to config
+    value = g_variant_new ("b", defval);
+    ibus_config_set_value (get<IBusConfig> (), m_section.c_str (), name, value);
+#else
     GValue value = {0};
     if (ibus_config_get_value (get<IBusConfig> (), m_section.c_str (), name, &value)) {
         if (G_VALUE_TYPE (&value) == G_TYPE_BOOLEAN)
@@ -163,6 +175,7 @@
     g_value_init (&value, G_TYPE_BOOLEAN);
     g_value_set_boolean (&value, defval);
     ibus_config_set_value (get<IBusConfig> (), m_section.c_str (), name, &value);
+#endif
 
     return defval;
 }
@@ -171,6 +184,18 @@
 Config::read (const gchar * name,
               gint          defval)
 {
+#if IBUS_CHECK_VERSION(1,3,99)
+    GVariant *value = NULL;
+    value = ibus_config_get_value (get<IBusConfig> (), m_section.c_str (), name);
+    if (value) {
+	if (g_variant_classify (value) == G_VARIANT_CLASS_INT32)
+	    return g_variant_get_int32 (value);
+    }
+
+    // write default value to config
+    value = g_variant_new ("i", defval);
+    ibus_config_set_value (get<IBusConfig> (), m_section.c_str (), name, value);
+#else
     GValue value = {0};
     if (ibus_config_get_value (get<IBusConfig> (), m_section.c_str (), name, &value)) {
         if (G_VALUE_TYPE (&value) == G_TYPE_INT)
@@ -181,6 +206,7 @@
     g_value_init (&value, G_TYPE_INT);
     g_value_set_int (&value, defval);
     ibus_config_set_value (get<IBusConfig> (), m_section.c_str (), name, &value);
+#endif
 
     return defval;
 }
@@ -189,6 +215,18 @@
 Config::read (const gchar * name,
               const gchar * defval)
 {
+#if IBUS_CHECK_VERSION(1,3,99)
+    GVariant *value = NULL;
+    value = ibus_config_get_value (get<IBusConfig> (), m_section.c_str (), name);
+    if (value) {
+	if (g_variant_classify (value) == G_VARIANT_CLASS_STRING)
+            return g_variant_get_string (value, NULL);
+    }
+
+    // write default value to config
+    value = g_variant_new ("s", defval);
+    ibus_config_set_value (get<IBusConfig> (), m_section.c_str (), name, value);
+#else
     GValue value = {0};
     if (ibus_config_get_value (get<IBusConfig> (), m_section.c_str (), name, &value)) {
         if (G_VALUE_TYPE (&value) == G_TYPE_STRING)
@@ -199,10 +237,20 @@
     g_value_init (&value, G_TYPE_STRING);
     g_value_set_static_string (&value, defval);
     ibus_config_set_value (get<IBusConfig> (), m_section.c_str (), name, &value);
+#endif
 
     return defval;
 }
 
+#if IBUS_CHECK_VERSION(1,3,99)
+static inline bool
+normalizeGValue (GVariant *value, bool defval)
+{
+    if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_BOOLEAN)
+        return defval;
+    return g_variant_get_boolean (value);
+}
+#else
 static inline bool
 normalizeGValue (const GValue *value, bool defval)
 {
@@ -210,7 +258,17 @@
         return defval;
     return g_value_get_boolean (value);
 }
+#endif
 
+#if IBUS_CHECK_VERSION(1,3,99)
+static inline gint
+normalizeGValue (GVariant *value, gint defval)
+{
+    if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_INT32)
+        return defval;
+    return g_variant_get_int32 (value);
+}
+#else
 static inline gint
 normalizeGValue (const GValue *value, gint defval)
 {
@@ -218,7 +276,17 @@
         return defval;
     return g_value_get_int (value);
 }
+#endif
 
+#if IBUS_CHECK_VERSION(1,3,99)
+static inline const gchar *
+normalizeGValue (GVariant *value, const gchar * defval)
+{
+    if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_STRING)
+        return defval;
+    return g_variant_get_string (value, NULL);
+}
+#else
 static inline const gchar *
 normalizeGValue (const GValue *value, const gchar * defval)
 {
@@ -226,11 +294,12 @@
         return defval;
     return g_value_get_string (value);
 }
+#endif
 
 gboolean
 Config::valueChanged (const std::string & section,
                       const std::string & name,
-                      const GValue  *value)
+                      ibus_valref_t value)
 {
     if (m_section != section)
         return FALSE;
@@ -278,7 +347,7 @@
 Config::valueChangedCallback (IBusConfig    *config,
                               const gchar   *section,
                               const gchar   *name,
-                              const GValue  *value,
+                              ibus_valref_t  value,
                               Config        *self)
 {
     self->valueChanged (section, name, value);
@@ -363,7 +432,7 @@
 gboolean
 PinyinConfig::valueChanged (const std::string & section,
                       const std::string & name,
-                      const GValue  *value)
+                      ibus_valref_t value)
 {
     if (m_section != section)
         return FALSE;
@@ -465,7 +534,7 @@
 gboolean
 BopomofoConfig::valueChanged (const std::string & section,
                               const std::string & name,
-                              const GValue  *value)
+                              ibus_valref_t value)
 {
     if (m_section != section)
         return FALSE;
--- a/src/PYConfig.h
+++ b/src/PYConfig.h
@@ -26,6 +26,14 @@
 #include <ibus.h>
 #include "PYObject.h"
 
+#if IBUS_CHECK_VERSION(1,3,99)
+typedef GVariant *ibus_valref_t;
+typedef GVariant ibus_val_t;
+#else
+typedef const GValue *ibus_valref_t;
+typedef GValue ibus_val_t;
+#endif
+
 namespace PY {
 
 class Bus;
@@ -66,12 +74,12 @@
 
     virtual gboolean valueChanged (const std::string & section,
                                    const std::string & name,
-                                   const GValue  *value);
+                                   ibus_valref_t value);
 private:
     static void valueChangedCallback (IBusConfig    *config,
                                       const gchar   *section,
                                       const gchar   *name,
-                                      const GValue  *value,
+                                      ibus_valref_t  value,
                                       Config        *self);
 
 protected:
@@ -115,7 +123,7 @@
 
     virtual gboolean valueChanged (const std::string & section,
                                    const std::string & name,
-                                   const GValue  *value);
+                                   ibus_valref_t value);
 
 private:
     static boost::scoped_ptr<PinyinConfig> m_instance;
@@ -133,7 +141,7 @@
 
     virtual gboolean valueChanged (const std::string & section,
                                    const std::string & name,
-                                   const GValue  *value);
+                                   ibus_valref_t value);
 
 private:
     static boost::scoped_ptr<BopomofoConfig> m_instance;
openSUSE Build Service is sponsored by