From 1290471fc3e542388e79e27cb2c4ce654f5023f3 Mon Sep 17 00:00:00 2001
From: Jarkko Koivikko <jarkko.koivikko@code-q.fi>
Date: Tue, 5 Aug 2014 13:37:49 +0300
Subject: [PATCH] Make the keyboard layout changeable in password / url input
 mode

Removed latin-only restriction with specific input method hints.
More specifically, the latin-only keyboard was previously enforced
when password, hidden, sensitive or latin-only flags were set for
the input control.

Now it is possible to use non-latin input methods and keyboard
layouts with these modes too. However, this change implies some
additional changes to the Pinyin and Hunspell input methods.

Changes to PinyinInputMethod:
- Disable the user dictionary when sensitive data flag is set.
  This is required so that sensitive data (such as passwords)
  is not stored in the user dictionary.

Changes to HunspellInputMethod:
- Disable the auto space functionality when the input mode is not
  latin, or the exclusive input mode is set to url or email input.

Task-number: QTRD-3210
Change-Id: I444c4b87c9805b69dc773ef6cac76f1c11dd220a
Reviewed-by: Mitch Curtis <mitch.curtis@digia.com>
Reviewed-by: Rainer Keller <rainer.keller@digia.com>
---
 .../3rdparty/pinyin/include/matrixsearch.h         |  4 ++++
 .../3rdparty/pinyin/include/pinyinime.h            | 12 +++++++++++
 .../3rdparty/pinyin/share/matrixsearch.cpp         | 23 ++++++++++++++++++++++
 .../3rdparty/pinyin/share/pinyinime.cpp            | 11 +++++++++++
 4 files changed, 50 insertions(+)

diff --git a/src/virtualkeyboard/3rdparty/pinyin/include/matrixsearch.h b/src/virtualkeyboard/3rdparty/pinyin/include/matrixsearch.h
index f581d30..61e78aa 100644
--- a/src/virtualkeyboard/3rdparty/pinyin/include/matrixsearch.h
+++ b/src/virtualkeyboard/3rdparty/pinyin/include/matrixsearch.h
@@ -380,6 +380,10 @@ class MatrixSearch {
   bool init_fd(int sys_fd, long start_offset, long length,
                const char *fn_usr_dict);
 
+  void init_user_dictionary(const char *fn_usr_dict);
+
+  bool is_user_dictionary_enabled() const;
+
   void set_max_lens(size_t max_sps_len, size_t max_hzs_len);
 
   void close();
diff --git a/src/virtualkeyboard/3rdparty/pinyin/include/pinyinime.h b/src/virtualkeyboard/3rdparty/pinyin/include/pinyinime.h
index 0744ec7..e376c20 100644
--- a/src/virtualkeyboard/3rdparty/pinyin/include/pinyinime.h
+++ b/src/virtualkeyboard/3rdparty/pinyin/include/pinyinime.h
@@ -202,6 +202,18 @@ extern "C" {
    * Enable Yunmus in ShouZiMu mode.
    */
   void im_enable_ym_as_szm(bool enable);
+
+  /**
+   * Initializes or uninitializes the user dictionary.
+   *
+   * @param fn_usr_dict The file name of the user dictionary.
+   */
+  void im_init_user_dictionary(const char *fn_usr_dict);
+
+  /**
+   * Returns the current status of user dictinary.
+   */
+  bool im_is_user_dictionary_enabled(void);
 }
 
 #ifdef __cplusplus
diff --git a/src/virtualkeyboard/3rdparty/pinyin/share/matrixsearch.cpp b/src/virtualkeyboard/3rdparty/pinyin/share/matrixsearch.cpp
index 12d092a..41e1143 100644
--- a/src/virtualkeyboard/3rdparty/pinyin/share/matrixsearch.cpp
+++ b/src/virtualkeyboard/3rdparty/pinyin/share/matrixsearch.cpp
@@ -169,6 +169,29 @@ bool MatrixSearch::init_fd(int sys_fd, long start_offset, long length,
   return true;
 }
 
+void MatrixSearch::init_user_dictionary(const char *fn_usr_dict) {
+  assert(inited_);
+
+  if (NULL != user_dict_) {
+    delete user_dict_;
+    user_dict_ = NULL;
+  }
+
+  if (NULL != fn_usr_dict) {
+    user_dict_ = static_cast<AtomDictBase*>(new UserDict());
+    if (!user_dict_->load_dict(fn_usr_dict, kUserDictIdStart, kUserDictIdEnd)) {
+      delete user_dict_;
+      user_dict_ = NULL;
+    }
+  }
+
+  reset_search0();
+}
+
+bool MatrixSearch::is_user_dictionary_enabled() const {
+  return NULL != user_dict_;
+}
+
 void MatrixSearch::set_max_lens(size_t max_sps_len, size_t max_hzs_len) {
   if (0 != max_sps_len)
     max_sps_len_ = max_sps_len;
diff --git a/src/virtualkeyboard/3rdparty/pinyin/share/pinyinime.cpp b/src/virtualkeyboard/3rdparty/pinyin/share/pinyinime.cpp
index 550da7b..4d206a7 100644
--- a/src/virtualkeyboard/3rdparty/pinyin/share/pinyinime.cpp
+++ b/src/virtualkeyboard/3rdparty/pinyin/share/pinyinime.cpp
@@ -181,6 +181,17 @@ extern "C" {
     spl_trie.szm_enable_ym(enable);
   }
 
+  void im_init_user_dictionary(const char *fn_usr_dict) {
+    if (!matrix_search)
+        return;
+    matrix_search->flush_cache();
+    matrix_search->init_user_dictionary(fn_usr_dict);
+  }
+
+  bool im_is_user_dictionary_enabled(void) {
+    return NULL != matrix_search ? matrix_search->is_user_dictionary_enabled() : false;
+  }
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.14.1.windows.1

