Support synchronous get_surrounding_text function in ise-engine-loader 71/248171/3
authorInHong Han <inhong1.han@samsung.com>
Mon, 23 Nov 2020 07:09:15 +0000 (16:09 +0900)
committerInHong Han <inhong1.han@samsung.com>
Wed, 25 Nov 2020 02:43:27 +0000 (11:43 +0900)
Change-Id: I149cfc444c1eb4cd8fe883f8b3e41f229ad14cae

engine-loader/include/engine_loader.h
engine-loader/include/engine_loader_dbus.h
engine-loader/src/engine_loader.cpp
engine-loader/src/engine_loader_dbus.cpp

index 0266a2c..8c690d2 100644 (file)
@@ -73,6 +73,8 @@ public:
     void set_candidate_item_layout(std::vector<uint32_t> item);
     void change_candidate_number(uint32_t page_num);
     void long_press_candidate_item(uint32_t index);
+    void get_surrounding_text(int maxlen_before, int maxlen_after, scim::String &text, int &cursor);
+    void set_surrounding_text(char* text, int cursor);
 };
 
 #endif /* __ENGINE_LOADER_H */
\ No newline at end of file
index 0ef62d5..c6f07d3 100644 (file)
@@ -65,4 +65,5 @@ int engine_loader_candidate_table_page_down(GVariant *parameters, GVariant **rep
 int engine_loader_change_candidate_page_size(GVariant *parameters, GVariant **reply_body);
 int engine_loader_set_candidate_item_layout(GVariant *parameters, GVariant **reply_body);
 int engine_loader_change_candidate_number(GVariant *parameters, GVariant **reply_body);
-int engine_loader_long_press_candidate_item(GVariant *parameters, GVariant **reply_body);
\ No newline at end of file
+int engine_loader_long_press_candidate_item(GVariant *parameters, GVariant **reply_body);
+int engine_loader_set_surrounding_text(GVariant *parameters, GVariant **reply_body);
\ No newline at end of file
index 36ab6f8..6e65af2 100644 (file)
@@ -63,9 +63,11 @@ public:
     IMEngineModule engine_module;
 
     uint32 layout;
+    uint32 cursor_pos;
     bool is_focused;
+    char* surrounding_text;
 
-    EngineLoaderImpl(EngineLoader *thiz) : thiz(thiz), layout(0), is_focused(false)
+    EngineLoaderImpl(EngineLoader *thiz) : thiz(thiz), layout(0), cursor_pos(0), is_focused(false), surrounding_text(NULL)
     {
         m_config = ConfigBase::get(false, "socket");
         if (m_config.null())
@@ -89,6 +91,9 @@ public:
         if (engine_module.valid()) {
             engine_module.unload();
         }
+
+        if (surrounding_text != NULL)
+            free(surrounding_text);
     }
 
     void slot_show_preedit_string(IMEngineInstanceBase *si)
@@ -326,6 +331,9 @@ public:
                                    int maxlen_before,
                                    int maxlen_after)
     {
+        scim::String _text;
+        thiz->get_surrounding_text(maxlen_before, maxlen_after, _text, cursor);
+        text = utf8_mbstowcs(_text);
         return true;
     }
 
@@ -460,7 +468,7 @@ public:
             slot(this, &EngineLoader::EngineLoaderImpl::slot_send_private_command));
     }
 private:
-    EngineLoaderImpl() : thiz(NULL), layout(0), is_focused(false) { }
+    EngineLoaderImpl() : thiz(NULL), layout(0), cursor_pos(0), is_focused(false), surrounding_text(NULL) { }
 };
 
 EngineLoader::EngineLoader()
@@ -729,4 +737,22 @@ void EngineLoader::long_press_candidate_item(uint32_t index)
     if (!m_impl->si.null()) {
         m_impl->si->longpress_candidate(index);
     }
+}
+
+void EngineLoader::get_surrounding_text(int maxlen_before, int maxlen_after, scim::String &text, int &cursor)
+{
+    text = m_impl->surrounding_text;
+    cursor = m_impl->cursor_pos;
+}
+
+void EngineLoader::set_surrounding_text(char* text, int cursor)
+{
+    if (m_impl->surrounding_text) {
+        free(m_impl->surrounding_text);
+        m_impl->surrounding_text = NULL;
+    }
+
+    SECURE_LOGD("surrounding_text : %s", text);
+    m_impl->surrounding_text = strdup(text);
+    m_impl->cursor_pos = cursor;
 }
\ No newline at end of file
index 6e22e8b..27f80b0 100644 (file)
@@ -138,6 +138,8 @@ static void _client_dbus_method_call_handler(GDBusConnection *conn, const gchar
         ret = engine_loader_change_candidate_number(parameters, &reply_body);
     } else if (g_strcmp0(method_name, "long_press_candidate_item") == 0) {
         ret = engine_loader_long_press_candidate_item(parameters, &reply_body);
+    } else if (g_strcmp0(method_name, "set_surrounding_text") == 0) {
+        ret = engine_loader_set_surrounding_text(parameters, &reply_body);
     }
 
     if (ret == ENGINE_LOADER_ERROR_NONE)
@@ -266,6 +268,12 @@ static int _register_dbus_interface(void)
             "        <method name='long_press_candidate_item'>"
             "          <arg type='u' name='index' direction='in'/>"
             "        </method>"
+
+            "        <method name='set_surrounding_text'>"
+            "          <arg type='s' name='text' direction='in'/>"
+            "          <arg type='i' name='cursor' direction='in'/>"
+            "          <arg type='b' name='result' direction='out'/>"
+            "        </method>"
             "  </interface>"
             "  </node>";
 
@@ -749,3 +757,20 @@ int engine_loader_long_press_candidate_item(GVariant *parameters, GVariant **rep
 
     return ENGINE_LOADER_ERROR_NONE;
 }
+
+int engine_loader_set_surrounding_text(GVariant *parameters, GVariant **reply_body)
+{
+    char *text;
+    int cursor;
+
+    g_variant_get(parameters, "(&si)", &text, &cursor);
+    m_engine_loader.set_surrounding_text(text, cursor);
+
+    *reply_body = g_variant_new("(b)", true);
+    if (*reply_body == NULL) {
+        LOGE("Failed to create reply_body");
+        return ENGINE_LOADER_ERROR_OUT_OF_MEMORY;
+    }
+
+    return ENGINE_LOADER_ERROR_NONE;
+}