From 4d6a548b773ab5d59641208b5668a000287075d3 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 25 Oct 2011 14:36:36 +0800 Subject: add user data directory support --- src/PYLibPinyin.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/PYLibPinyin.cc') diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc index d76e612..077e7e0 100644 --- a/src/PYLibPinyin.cc +++ b/src/PYLibPinyin.cc @@ -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); } -- cgit