summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2013-02-08 10:29:05 +0800
committerPeng Wu <alexepico@gmail.com>2013-02-08 10:29:05 +0800
commit42fdd95eeea6e72f65fe74e356b6ab96bc95666c (patch)
tree342bb2b21f0c0e36a446d6cbd4c55bf118ba7a50
parent00b1261817b55f04531bcac76191b27f796ab1ea (diff)
downloadibus-libpinyin-42fdd95eeea6e72f65fe74e356b6ab96bc95666c.tar.gz
ibus-libpinyin-42fdd95eeea6e72f65fe74e356b6ab96bc95666c.tar.xz
ibus-libpinyin-42fdd95eeea6e72f65fe74e356b6ab96bc95666c.zip
write clearPinyinUserData
-rw-r--r--src/PYConfig.cc19
-rw-r--r--src/PYLibPinyin.cc14
-rw-r--r--src/PYLibPinyin.h3
-rw-r--r--src/PYPConfig.cc15
4 files changed, 31 insertions, 20 deletions
diff --git a/src/PYConfig.cc b/src/PYConfig.cc
index c9fd251..2ed964c 100644
--- a/src/PYConfig.cc
+++ b/src/PYConfig.cc
@@ -69,25 +69,6 @@ Config::initDefaultValues (void)
void
Config::readDefaultValues (void)
{
-#if defined(HAVE_IBUS_CONFIG_GET_VALUES)
- /* read all values together */
- initDefaultValues ();
- GVariant *values =
- ibus_config_get_values (get<IBusConfig> (), m_section.c_str ());
- g_return_if_fail (values != NULL);
-
- GVariantIter iter;
- gchar *name;
- GVariant *value;
- g_variant_iter_init (&iter, values);
- while (g_variant_iter_next (&iter, "{sv}", &name, &value)) {
- valueChanged (m_section, name, value);
- g_free (name);
- g_variant_unref (value);
- }
- g_variant_unref (values);
-#else
-#endif
}
inline bool
diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc
index 3187706..811400c 100644
--- a/src/PYLibPinyin.cc
+++ b/src/PYLibPinyin.cc
@@ -20,6 +20,8 @@
*/
#include "PYLibPinyin.h"
+
+#include <string.h>
#include <pinyin.h>
#include "PYPConfig.h"
@@ -237,6 +239,18 @@ LibPinyinBackEnd::modified (void)
static_cast<gpointer> (this));
}
+bool
+LibPinyinBackEnd::clearPinyinUserData (const char * target)
+{
+ if (0 == strcmp("all", target))
+ pinyin_mask_out(m_pinyin_context, 0x0, 0x0);
+ else if (0 == strcmp("user", target))
+ pinyin_mask_out(m_pinyin_context, PHRASE_INDEX_LIBRARY_MASK,
+ PHRASE_INDEX_MAKE_TOKEN(15, null_token));
+ else
+ g_warning("unknown clear target: %s.\n", target);
+}
+
gboolean
LibPinyinBackEnd::timeoutCallback (gpointer data)
{
diff --git a/src/PYLibPinyin.h b/src/PYLibPinyin.h
index e1d1803..18fd9d1 100644
--- a/src/PYLibPinyin.h
+++ b/src/PYLibPinyin.h
@@ -50,6 +50,9 @@ public:
void freeChewingInstance (pinyin_instance_t *instance);
void modified (void);
+ bool importPinyinDictionary(const char * filename);
+ bool clearPinyinUserData(const char * target);
+
/* use static initializer in C++. */
static LibPinyinBackEnd & instance (void) { return *m_instance; }
diff --git a/src/PYPConfig.cc b/src/PYPConfig.cc
index 8ed07f7..de78dda 100644
--- a/src/PYPConfig.cc
+++ b/src/PYPConfig.cc
@@ -20,6 +20,7 @@
*/
#include "PYPConfig.h"
+#include <string.h>
#include <pinyin.h>
#include "PYBus.h"
#include "PYLibPinyin.h"
@@ -50,6 +51,8 @@ const gchar * const CONFIG_GUIDE_KEY = "GuideKey";
const gchar * const CONFIG_AUXILIARY_SELECT_KEY_F = "AuxiliarySelectKey_F";
const gchar * const CONFIG_AUXILIARY_SELECT_KEY_KP = "AuxiliarySelectKey_KP";
const gchar * const CONFIG_ENTER_KEY = "EnterKey";
+const gchar * const CONFIG_CLEAR_USER_DATA = "ClearUserData";
+const gchar * const CONFIG_IMPORT_DICTIONARY = "ImportDictionary";
const guint PINYIN_DEFAULT_OPTION =
PINYIN_INCOMPLETE |
@@ -136,6 +139,13 @@ LibPinyinConfig::readDefaultValues (void)
GVariant *value;
g_variant_iter_init (&iter, values);
while (g_variant_iter_next (&iter, "{sv}", &name, &value)) {
+ /* skip signals here. */
+ if (0 == strcmp(CONFIG_CLEAR_USER_DATA, name))
+ continue;
+
+ if (0 == strcmp(CONFIG_IMPORT_DICTIONARY, name))
+ continue;
+
valueChanged (m_section, name, value);
g_free (name);
g_variant_unref (value);
@@ -393,7 +403,10 @@ LibPinyinPinyinConfig::valueChanged (const std::string &section,
m_comma_period_page = normalizeGVariant (value, true);
else if (CONFIG_AUTO_COMMIT == name)
m_auto_commit = normalizeGVariant (value, false);
- /* correct pinyin */
+ else if (CONFIG_CLEAR_USER_DATA == name) {
+ std::string target = normalizeGVariant (value, std::string(""));
+ LibPinyinBackEnd::instance ().clearPinyinUserData(target.c_str ());
+ } /* correct pinyin */
else if (CONFIG_CORRECT_PINYIN == name) {
if (normalizeGVariant (value, true))
m_option_mask |= PINYIN_CORRECT_ALL;