summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-08-08 16:52:03 +0800
committerPeng Wu <alexepico@gmail.com>2012-08-08 17:00:54 +0800
commitc0b417a3a10b853cb030e1e8fd1c0c138f2ab801 (patch)
treeee1e637e1ebc0938533d98ffb09257742b9e41c8
parent2249b3cbdb13c3465b03b55e74eeea85f8612dcc (diff)
downloadibus-libpinyin-c0b417a3a10b853cb030e1e8fd1c0c138f2ab801.tar.gz
add dictionaries option
-rw-r--r--src/PYConfig.h2
-rw-r--r--src/PYLibPinyin.cc32
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;
}