summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2014-07-15 13:22:51 +0800
committerPeng Wu <alexepico@gmail.com>2014-07-15 13:22:51 +0800
commit18c1dab51499105a2e32dab405cf6d8809cce281 (patch)
tree306d4a4aef7564522a6639af5931b37fbc31688a
parent6533c108f06c7e268fe8377d4054bfc841ee8608 (diff)
downloadibus-libzhuyin-18c1dab51499105a2e32dab405cf6d8809cce281.tar.gz
ibus-libzhuyin-18c1dab51499105a2e32dab405cf6d8809cce281.tar.xz
ibus-libzhuyin-18c1dab51499105a2e32dab405cf6d8809cce281.zip
add methods to class LibZhuyinBackEnd
-rw-r--r--src/ZYLibZhuyin.cc59
-rw-r--r--src/ZYLibZhuyin.h2
2 files changed, 59 insertions, 2 deletions
diff --git a/src/ZYLibZhuyin.cc b/src/ZYLibZhuyin.cc
index 190d3da..bdaebad 100644
--- a/src/ZYLibZhuyin.cc
+++ b/src/ZYLibZhuyin.cc
@@ -150,6 +150,65 @@ LibZhuyinBackEnd::modified (void)
}
gboolean
+LibZhuyinBackEnd::importZhuyinDictionary (const char * filename)
+{
+ /* user phrase library should be already loaded here. */
+ FILE * dictfile = fopen (filename, "r");
+ if (NULL == dictfile)
+ return FALSE;
+
+ import_iterator_t * iter = zhuyin_begin_add_phrases
+ (m_zhuyin_context, USER_DICTIONARY);
+
+ if (NULL == iter)
+ return FALSE;
+
+ char* linebuf = NULL; size_t size = 0; ssize_t read;
+ while ((read = getline (&linebuf, &size, dictfile)) != -1) {
+ if (0 == strlen (linebuf))
+ continue;
+
+ if ( '\n' == linebuf[strlen (linebuf) - 1] ) {
+ linebuf[strlen (linebuf) - 1] = '\0';
+ }
+
+ gchar ** items = g_strsplit_set (linebuf, " \t", 2);
+ guint len = g_strv_length (items);
+
+ if (2 != len)
+ continue;
+
+ gchar * phrase = items[0];
+ gchar * zhuyin = items[1];
+
+ zhuyin_iterator_add_phrase (iter, phrase, zhuyin, -1);
+
+ g_strfreev (items);
+ }
+
+ zhuyin_end_add_phrases (iter);
+ fclose (dictfile);
+
+ zhuyin_save (m_zhuyin_context);
+ return TRUE;
+}
+
+gboolean
+LibZhuyinBackEnd::cleanZhuyinUserData (const char * target)
+{
+ if (0 == strcmp ("all", target))
+ zhuyin_mask_out (m_zhuyin_context, 0x0, 0x0);
+ else if (0 == strcmp ("user", target))
+ zhuyin_mask_out (m_zhuyin_context, PHRASE_INDEX_LIBRARY_MASK,
+ PHRASE_INDEX_MAKE_TOKEN (USER_DICTIONARY, null_token));
+ else
+ g_warning ("unknown clear target: %s.\n", target);
+
+ zhuyin_save (m_zhuyin_context);
+ return TRUE;
+}
+
+gboolean
LibZhuyinBackEnd::timeoutCallback (gpointer data)
{
LibZhuyinBackEnd *self = static_cast<LibZhuyinBackEnd *>(data);
diff --git a/src/ZYLibZhuyin.h b/src/ZYLibZhuyin.h
index be1eb84..a9a3e13 100644
--- a/src/ZYLibZhuyin.h
+++ b/src/ZYLibZhuyin.h
@@ -47,10 +47,8 @@ public:
void modified (void);
-#if 0
gboolean importZhuyinDictionary (const char * filename);
gboolean cleanZhuyinUserData (const char * target);
-#endif
/* use static initializer in C++. */
static LibZhuyinBackEnd & instance (void) { return *m_instance; }