From c0b417a3a10b853cb030e1e8fd1c0c138f2ab801 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 8 Aug 2012 16:52:03 +0800 Subject: add dictionaries option --- src/PYConfig.h | 2 ++ src/PYLibPinyin.cc | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/PYConfig.h b/src/PYConfig.h index 0bd63e7..560e852 100644 --- a/src/PYConfig.h +++ b/src/PYConfig.h @@ -40,6 +40,7 @@ protected: virtual ~Config (void); public: + std::string dictionaries (void) const { return m_dictionaries; } guint option (void) const { return m_option & m_option_mask; } guint orientation (void) const { return m_orientation; } guint pageSize (void) const { return m_page_size; } @@ -81,6 +82,7 @@ private: protected: std::string m_section; + std::string m_dictionaries; guint m_option; guint m_option_mask; diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc index 293bd0b..eb2b937 100644 --- a/src/PYLibPinyin.cc +++ b/src/PYLibPinyin.cc @@ -65,13 +65,19 @@ LibPinyinBackEnd::initPinyinContext (Config *config) g_free(userdir); userdir = NULL; } context = pinyin_init ("/usr/share/libpinyin/data", userdir); + g_free (userdir); -#if 0 - pinyin_load_phrase_library(m_pinyin_context, 2); -#endif - /* TODO: load phrase libraries here. */ + const char *dicts = config->dictionaries ().c_str (); + gchar ** indices = g_strsplit_set (dicts, "", -1); + for (size_t i = 0; i < g_strv_length(indices); ++i) { + int index = atoi (indices [i]); + if (index <= 1) + continue; + + pinyin_load_phrase_library (context, index); + } + g_strfreev (indices); - g_free(userdir); return context; } @@ -105,13 +111,19 @@ LibPinyinBackEnd::initChewingContext (Config *config) g_free(userdir); userdir = NULL; } context = pinyin_init ("/usr/share/libpinyin/data", userdir); + g_free(userdir); -#if 0 - pinyin_load_phrase_library(m_chewing_context, 2); -#endif - /* TODO: load phrase libraries here. */ + const char *dicts = config->dictionaries ().c_str (); + gchar ** indices = g_strsplit_set (dicts, "", -1); + for (size_t i = 0; i < g_strv_length(indices); ++i) { + int index = atoi (indices [i]); + if (index <= 1) + continue; + + pinyin_load_phrase_library (context, index); + } + g_strfreev (indices); - g_free(userdir); return context; } -- cgit