add dictionaries option
authorPeng Wu <alexepico@gmail.com>
Wed, 8 Aug 2012 08:52:03 +0000 (16:52 +0800)
committerPeng Wu <alexepico@gmail.com>
Wed, 8 Aug 2012 09:00:54 +0000 (17:00 +0800)
src/PYConfig.h
src/PYLibPinyin.cc

index 0bd63e7..560e852 100644 (file)
@@ -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;
 
index 293bd0b..eb2b937 100644 (file)
@@ -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;
 }