From 2924d05cf008f7c7794d4f4b65940a70ba2247bd Mon Sep 17 00:00:00 2001 From: Peng Huang Date: Mon, 12 Jul 2010 18:14:46 +0800 Subject: [PATCH] Fix problem with ibus-2.0 --- configure.ac | 2 +- src/PYConfig.cc | 89 ++++++++++++++++++++++++++++----------------------------- src/PYConfig.h | 30 +++++++++---------- 3 files changed, 59 insertions(+), 62 deletions(-) diff --git a/configure.ac b/configure.ac index ccb0ef4..358dff8 100644 --- a/configure.ac +++ b/configure.ac @@ -53,7 +53,7 @@ AM_PROG_LIBTOOL # check ibus PKG_CHECK_MODULES(IBUS, [ - ibus-1.0 + ibus-2.0 ]) # check sqlite diff --git a/src/PYConfig.cc b/src/PYConfig.cc index 114b74c..20fbef1 100644 --- a/src/PYConfig.cc +++ b/src/PYConfig.cc @@ -154,16 +154,15 @@ inline bool Config::read (const gchar * name, bool defval) { - GValue value = {0}; - if (ibus_config_get_value (get (), m_section.c_str (), name, &value)) { - if (G_VALUE_TYPE (&value) == G_TYPE_BOOLEAN) - return g_value_get_boolean (&value); + GVariant *value = NULL; + if ((value = ibus_config_get_value (get (), m_section.c_str (), name)) != NULL) { + if (g_variant_classify (value) == G_VARIANT_CLASS_BOOLEAN) + return g_variant_get_boolean (value); } // write default value to config - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, defval); - ibus_config_set_value (get (), m_section.c_str (), name, &value); + value = g_variant_new ("b", defval); + ibus_config_set_value (get (), m_section.c_str (), name, value); return defval; } @@ -172,66 +171,64 @@ inline gint Config::read (const gchar * name, gint defval) { - GValue value = {0}; - if (ibus_config_get_value (get (), m_section.c_str (), name, &value)) { - if (G_VALUE_TYPE (&value) == G_TYPE_INT) - return g_value_get_int (&value); + GVariant *value = NULL; + if ((value = ibus_config_get_value (get (), m_section.c_str (), name)) != NULL) { + if (g_variant_classify (value) == G_VARIANT_CLASS_INT32) + return g_variant_get_int32 (value); } // write default value to config - g_value_init (&value, G_TYPE_INT); - g_value_set_int (&value, defval); - ibus_config_set_value (get (), m_section.c_str (), name, &value); + value = g_variant_new ("i", defval); + ibus_config_set_value (get (), m_section.c_str (), name, value); return defval; } -inline const gchar * +inline std::string Config::read (const gchar * name, const gchar * defval) { - GValue value = {0}; - if (ibus_config_get_value (get (), m_section.c_str (), name, &value)) { - if (G_VALUE_TYPE (&value) == G_TYPE_STRING) - return g_value_get_string (&value); + GVariant *value = NULL; + if ((value = ibus_config_get_value (get (), m_section.c_str (), name)) != NULL) { + if (g_variant_classify (value) == G_VARIANT_CLASS_STRING) + return g_variant_get_string (value, NULL); } // write default value to config - g_value_init (&value, G_TYPE_STRING); - g_value_set_static_string (&value, defval); - ibus_config_set_value (get (), m_section.c_str (), name, &value); + value = g_variant_new ("s", defval); + ibus_config_set_value (get (), m_section.c_str (), name, value); return defval; } static inline bool -normalizeGValue (const GValue *value, bool defval) +normalizeGValue (GVariant *value, bool defval) { - if (value == NULL || G_VALUE_TYPE (value) != G_TYPE_BOOLEAN) + if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_BOOLEAN) return defval; - return g_value_get_boolean (value); + return g_variant_get_boolean (value); } static inline gint -normalizeGValue (const GValue *value, gint defval) +normalizeGValue (GVariant *value, gint defval) { - if (value == NULL || G_VALUE_TYPE (value) != G_TYPE_INT) + if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_INT32) return defval; - return g_value_get_int (value); + return g_variant_get_int32 (value); } -static inline const gchar * -normalizeGValue (const GValue *value, const gchar * defval) +static inline std::string +normalizeGValue (GVariant *value, const gchar * defval) { - if (value == NULL || G_VALUE_TYPE (value) != G_TYPE_STRING) + if (value == NULL || g_variant_classify (value) != G_VARIANT_CLASS_STRING) return defval; - return g_value_get_string (value); + return g_variant_get_string (value, NULL); } gboolean -Config::valueChanged (const std::string & section, - const std::string & name, - const GValue *value) +Config::valueChanged (const std::string §ion, + const std::string &name, + GVariant *value) { if (m_section != section) return FALSE; @@ -276,11 +273,11 @@ Config::valueChanged (const std::string & section, } void -Config::valueChangedCallback (IBusConfig *config, - const gchar *section, - const gchar *name, - const GValue *value, - Config *self) +Config::valueChangedCallback (IBusConfig *config, + const gchar *section, + const gchar *name, + GVariant *value, + Config *self) { self->valueChanged (section, name, value); } @@ -362,9 +359,9 @@ PinyinConfig::readDefaultValues (void) } gboolean -PinyinConfig::valueChanged (const std::string & section, - const std::string & name, - const GValue *value) +PinyinConfig::valueChanged (const std::string §ion, + const std::string &name, + GVariant *value) { if (m_section != section) return FALSE; @@ -465,9 +462,9 @@ BopomofoConfig::readDefaultValues (void) } gboolean -BopomofoConfig::valueChanged (const std::string & section, - const std::string & name, - const GValue *value) +BopomofoConfig::valueChanged (const std::string §ion, + const std::string &name, + GVariant *value) { if (m_section != section) return FALSE; diff --git a/src/PYConfig.h b/src/PYConfig.h index cec46e8..61b92bf 100644 --- a/src/PYConfig.h +++ b/src/PYConfig.h @@ -61,19 +61,19 @@ public: protected: bool read (const gchar * name, bool defval); gint read (const gchar * name, gint defval); - const gchar * read (const gchar * name, const gchar * defval); + std::string read (const gchar * name, const gchar * defval); virtual void readDefaultValues (void); - virtual gboolean valueChanged (const std::string & section, - const std::string & name, - const GValue *value); + virtual gboolean valueChanged (const std::string §ion, + const std::string &name, + GVariant *value); private: - static void valueChangedCallback (IBusConfig *config, - const gchar *section, - const gchar *name, - const GValue *value, - Config *self); + static void valueChangedCallback (IBusConfig *config, + const gchar *section, + const gchar *name, + GVariant *value, + Config *self); protected: std::string m_section; @@ -116,9 +116,9 @@ protected: PinyinConfig (Bus & bus); virtual void readDefaultValues (void); - virtual gboolean valueChanged (const std::string & section, - const std::string & name, - const GValue *value); + virtual gboolean valueChanged (const std::string §ion, + const std::string &name, + GVariant *value); private: static std::unique_ptr m_instance; @@ -134,9 +134,9 @@ protected: BopomofoConfig (Bus & bus); virtual void readDefaultValues (void); - virtual gboolean valueChanged (const std::string & section, - const std::string & name, - const GValue *value); + virtual gboolean valueChanged (const std::string §ion, + const std::string &name, + GVariant *value); private: static std::unique_ptr m_instance; -- 2.7.4