add user data directory support
authorPeng Wu <alexepico@gmail.com>
Tue, 25 Oct 2011 06:36:36 +0000 (14:36 +0800)
committerPeng Wu <alexepico@gmail.com>
Thu, 22 Dec 2011 04:23:14 +0000 (12:23 +0800)
src/PYLibPinyin.cc

index d76e612..077e7e0 100644 (file)
@@ -47,8 +47,15 @@ pinyin_instance_t *
 LibPinyinBackEnd::allocPinyinInstance ()
 {
     if (NULL == m_pinyin_context) {
-        m_pinyin_context = pinyin_init ("/usr/share/libpinyin/data", NULL);
+        gchar * userdir = g_build_filename (g_get_home_dir(), ".cache",
+                                            "ibus", "libpinyin", NULL);
+        int retval = g_mkdir_with_parents (userdir, 0700);
+        if (retval) {
+            g_free(userdir); userdir = NULL;
+        }
+        m_pinyin_context = pinyin_init ("/usr/share/libpinyin/data", userdir);
         setPinyinOptions (&PinyinConfig::instance ());
+        g_free(userdir);
     }
     return pinyin_alloc_instance (m_pinyin_context);
 }
@@ -63,8 +70,15 @@ pinyin_instance_t *
 LibPinyinBackEnd::allocChewingInstance ()
 {
     if (NULL == m_chewing_context) {
+        gchar * userdir = g_build_filename (g_get_home_dir(), ".cache",
+                                            "ibus", "libbopomofo", NULL);
+        int retval = g_mkdir_with_parents (userdir, 0700);
+        if (retval) {
+            g_free(userdir); userdir = NULL;
+        }
         m_chewing_context = pinyin_init ("/usr/share/libpinyin/data", NULL);
         setChewingOptions (&BopomofoConfig::instance ());
+        g_free(userdir);
     }
     return pinyin_alloc_instance (m_chewing_context);
 }