Change for Web IME 41/41441/2
authorSungmin Kwak <sungmin.kwak@samsung.com>
Wed, 1 Apr 2015 05:53:32 +0000 (14:53 +0900)
committerLi Zhang <li2012.zhang@samsung.com>
Wed, 17 Jun 2015 09:13:34 +0000 (17:13 +0800)
Add isf_db_select_count_by_module_name()
Modify HelperAgent::open_connection() to read ime_info DB.

Change-Id: I00c3364765f2edb331923f24db28e075d6b47157

ism/src/isf_query_utility.cpp
ism/src/isf_query_utility.h
ism/src/scim_helper.cpp
ism/src/scim_helper_module.cpp
ism/src/scim_helper_module.h
ism/src/scim_module.cpp

index 0cf12545d337035acb28b982f04c10af39e3eda2..794e5b0f1a40547f89b99e51990f82ba332711d7 100644 (file)
@@ -453,7 +453,7 @@ static int _db_select_module_name_by_mode(TOOLBAR_MODE_T mode, std::vector<Strin
             i++;
         }
         else if (i == 0 && firsttry) {
-            LOGD("sqlite3_step returned %d, empty DB", ret);
+            LOGD("sqlite3_step returned %d, mode=%d, empty DB", ret, mode);
             firsttry = false;
 
             sqlite3_reset(pStmt);
@@ -520,7 +520,7 @@ static int _db_select_module_path_by_mode(TOOLBAR_MODE_T mode, std::vector<Strin
     } while (ret == SQLITE_ROW);
 
     if (ret != SQLITE_DONE) {
-        LOGE("sqlite3_step: %s", sqlite3_errmsg(databaseInfo.pHandle));
+        LOGW("sqlite3_step returned %d, mode=%d, %s", ret, mode, sqlite3_errmsg(databaseInfo.pHandle));
     }
 
 out:
@@ -578,6 +578,46 @@ out:
     return i;
 }
 
+/**
+ * @brief Gets the count of the same module name in ime_info table.
+ *
+ * @param module_name Module name
+ *
+ * @return the number of selected row.
+ */
+static int _db_select_count_by_module_name(const char *module_name)
+{
+    int ret = 0, i = 0;
+    sqlite3_stmt* pStmt = NULL;
+    static const char* pQuery = "SELECT COUNT(*) FROM ime_info WHERE mname = ?";
+
+    ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("%s", sqlite3_errmsg(databaseInfo.pHandle));
+        return 0;
+    }
+
+    ret = sqlite3_bind_text(pStmt, 1, module_name, -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("%s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
+
+    ret = sqlite3_step(pStmt);
+    if (ret != SQLITE_ROW) {
+        LOGE("sqlite3_step: %s", sqlite3_errmsg(databaseInfo.pHandle));
+    }
+    else {
+        i = sqlite3_column_int(pStmt, 0);
+    }
+
+out:
+    sqlite3_reset(pStmt);
+    sqlite3_clear_bindings(pStmt);
+    sqlite3_finalize(pStmt);
+    return i;
+}
+
 /**
  * @brief Update label data by appid in ime_info table.
  *
@@ -619,7 +659,7 @@ static int _db_update_label_by_appid(const char *appid, const char *label)
 
     ret = sqlite3_step(pStmt);
     if (ret != SQLITE_DONE) {
-        ISF_SAVE_LOG("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
+        ISF_SAVE_LOG("sqlite3_step returned %d, %s\n", ret, sqlite3_errmsg(databaseInfo.pHandle));
         LOGE("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
         ret = 0;
     }
@@ -675,7 +715,7 @@ static int _db_update_is_enabled_by_appid(const char *appid, bool is_enabled)
 
     ret = sqlite3_step(pStmt);
     if (ret != SQLITE_DONE) {
-        ISF_SAVE_LOG("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
+        ISF_SAVE_LOG("sqlite3_step returned %d, %s\n", ret, sqlite3_errmsg(databaseInfo.pHandle));
         LOGE("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
         ret = 0;
     }
@@ -731,7 +771,7 @@ static int _db_update_has_option_by_appid(const char *appid, bool has_option)
 
     ret = sqlite3_step(pStmt);
     if (ret != SQLITE_DONE) {
-        ISF_SAVE_LOG("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
+        ISF_SAVE_LOG("sqlite3_step returned %d, %s\n", ret, sqlite3_errmsg(databaseInfo.pHandle));
         LOGE("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
         ret = 0;
     }
@@ -854,8 +894,8 @@ static int _db_insert_ime_info(std::vector<ImeInfoDB> &ime_info)
 
         ret = sqlite3_step(pStmt);
         if (ret != SQLITE_DONE) {
-            ISF_SAVE_LOG("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
-            LOGE("sqlite3_step returned %d, %s", ret, sqlite3_errmsg(databaseInfo.pHandle));
+            ISF_SAVE_LOG("sqlite3_step returned %d, appid=%s, %s\n", ret, iter->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
+            LOGE("sqlite3_step returned %d, appid=%s, %s", ret, iter->appid.c_str(), sqlite3_errmsg(databaseInfo.pHandle));
             ret = SQLITE_ERROR;
             goto out;
         }
@@ -1099,6 +1139,8 @@ EAPI int isf_db_select_all_ime_info(std::vector<ImeInfoDB> &ime_info)
         ret = _db_select_all_ime_info(ime_info);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
 
     return ret;
 }
@@ -1124,6 +1166,9 @@ EAPI int isf_db_select_ime_info_by_appid(const char *appid, ImeInfoDB *pImeInfo)
         ret = _db_select_ime_info_by_appid(appid, pImeInfo);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
+
     return ret;
 }
 
@@ -1145,6 +1190,8 @@ EAPI int isf_db_select_module_name_by_mode(TOOLBAR_MODE_T mode, std::vector<Stri
         ret = _db_select_module_name_by_mode(mode, mname);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
 
     return ret;
 }
@@ -1167,6 +1214,8 @@ EAPI int isf_db_select_module_path_by_mode(TOOLBAR_MODE_T mode, std::vector<Stri
         ret = _db_select_module_path_by_mode(mode, mpath);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
 
     return ret;
 }
@@ -1192,6 +1241,34 @@ EAPI int isf_db_select_appids_by_pkgid(const char *pkgid, std::vector<String> &a
         ret = _db_select_appids_by_pkgid(pkgid, appids);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
+
+    return ret;
+}
+
+/**
+ * @brief Gets the count of the same module name in ime_info table.
+ *
+ * @param module_name Module name
+ *
+ * @return the number of selected row.
+ */
+EAPI int isf_db_select_count_by_module_name(const char *module_name)
+{
+    int ret = 0;
+
+    if (!module_name) {
+        LOGW("module_name is null.");
+        return 0;
+    }
+
+    if (_db_connect() == 0) {
+        ret = _db_select_count_by_module_name(module_name);
+        _db_disconnect();
+    }
+    else
+        LOGW("failed");
 
     return ret;
 }
@@ -1207,10 +1284,14 @@ EAPI int isf_db_select_appids_by_pkgid(const char *pkgid, std::vector<String> &a
 EAPI int isf_db_update_label_by_appid(const char *appid, const char *label)
 {
     int ret = 0;
+
     if (_db_connect() == 0) {
         ret = _db_update_label_by_appid(appid, label);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
+
     return ret;
 }
 
@@ -1225,10 +1306,14 @@ EAPI int isf_db_update_label_by_appid(const char *appid, const char *label)
 EAPI int isf_db_update_is_enabled_by_appid(const char *appid, bool is_enabled)
 {
     int ret = 0;
+
     if (_db_connect() == 0) {
         ret = _db_update_is_enabled_by_appid(appid, is_enabled);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
+
     return ret;
 }
 
@@ -1243,10 +1328,14 @@ EAPI int isf_db_update_is_enabled_by_appid(const char *appid, bool is_enabled)
 EAPI int isf_db_update_has_option_by_appid(const char *appid, bool has_option)
 {
     int ret = 0;
+
     if (_db_connect() == 0) {
         ret = _db_update_has_option_by_appid(appid, has_option);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
+
     return ret;
 }
 
@@ -1285,6 +1374,8 @@ EAPI int isf_db_insert_ime_info_by_pkgid(const char *pkgid)
 
         _db_disconnect();
     }
+    else
+        LOGW("failed");
 
     pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
 
@@ -1311,6 +1402,8 @@ EAPI int isf_db_delete_ime_info_by_pkgid(const char *pkgid)
         ret = _db_delete_ime_info_by_pkgid(pkgid);
         _db_disconnect();
     }
+    else
+        LOGW("failed");
 
     return ret;
 }
index f491b3eb3eca221b7c1186e4d28061f4ff12c807..923bcd5ad690cf62d275a3539252bfbff2ff955f 100644 (file)
@@ -69,6 +69,7 @@ EAPI int isf_db_select_ime_info_by_appid(const char *appid, ImeInfoDB *pImeInfo)
 EAPI int isf_db_select_module_name_by_mode(TOOLBAR_MODE_T mode, std::vector<String> &mname);
 EAPI int isf_db_select_module_path_by_mode(TOOLBAR_MODE_T mode, std::vector<String> &mpath);
 EAPI int isf_db_select_appids_by_pkgid(const char *pkgid, std::vector<String> &appids);
+EAPI int isf_db_select_count_by_module_name(const char *module_name);
 EAPI int isf_db_update_label_by_appid(const char *appid, const char *label);
 EAPI int isf_db_update_is_enabled_by_appid(const char *appid, bool is_enabled);
 EAPI int isf_db_update_has_option_by_appid(const char *appid, bool has_option);
index 973b20fc968e8ba3f8e980c9c29a3ebb0dcbef18..9b6bc8b0ec23b10143fb42996cd6c7a2fbe4c81a 100644 (file)
@@ -49,6 +49,8 @@
 
 #include "scim_private.h"
 #include "scim.h"
+#include <scim_panel_common.h>
+#include "isf_query_utility.h"
 
 EAPI scim::CommonLookupTable g_helper_candidate_table;
 
@@ -263,15 +265,25 @@ HelperAgent::open_connection (const HelperInfo &info,
     ISF_LOG ("scim_socket_open_connection () is successful.\n");
     ISF_SAVE_LOG ("scim_socket_open_connection successful\n");
 
+    bool match = false;
+    std::vector<ImeInfoDB> ime_info_db;
+    isf_db_select_all_ime_info (ime_info_db);
+    for (i = 0; i < (int)ime_info_db.size (); i++) {
+        if (ime_info_db[i].appid.compare (info.uuid) == 0) {
+            match = true;
+            break;
+        }
+    }
+
     m_impl->send.clear ();
     m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
     m_impl->send.put_data (magic);
     m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_REGISTER_HELPER);
     m_impl->send.put_data (info.uuid);
-    m_impl->send.put_data (info.name);
-    m_impl->send.put_data (info.icon);
+    m_impl->send.put_data (match? ime_info_db[i].label : info.name);
+    m_impl->send.put_data (match? ime_info_db[i].iconpath : info.icon);
     m_impl->send.put_data (info.description);
-    m_impl->send.put_data (info.option);
+    m_impl->send.put_data (match? ime_info_db[i].options : info.option);
 
     if (!m_impl->send.write_to_socket (m_impl->socket, magic)) {
         m_impl->socket.close ();
@@ -329,10 +341,10 @@ HelperAgent::open_connection (const HelperInfo &info,
     m_impl->send.put_data (magic);
     m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_REGISTER_ACTIVE_HELPER);
     m_impl->send.put_data (info.uuid);
-    m_impl->send.put_data (info.name);
-    m_impl->send.put_data (info.icon);
+    m_impl->send.put_data (match? ime_info_db[i].label : info.name);
+    m_impl->send.put_data (match? ime_info_db[i].iconpath : info.icon);
     m_impl->send.put_data (info.description);
-    m_impl->send.put_data (info.option);
+    m_impl->send.put_data (match? ime_info_db[i].options : info.option);
 
     if (!m_impl->send.write_to_socket (m_impl->socket_active, magic)) {
         ISF_SAVE_LOG ("Helper_Active write_to_socket() failed\n");
index 563f48f313342ae742d4036307feae6627fc989a..d413987d8dabcc02c2b725121fa34ef622bac042 100644 (file)
@@ -52,7 +52,7 @@
 namespace scim {
 
 HelperModule::HelperModule (const String &name)
-    : appid (""),
+    : module_name (""),
       m_number_of_helpers (0),
       m_get_helper_info (0),
       m_get_helper_lang (0),
@@ -70,15 +70,14 @@ HelperModule::load (const String &name)
         if (!m_module.load (name, "Helper"))
             return false;
 
-        appid = name;
-
+        module_name = name; // Module name is PkgID for Inhouse IME, "ise-web-helper-agent" for Web IME or AppID for Native IME.
 
         m_run_helper =
             (HelperModuleRunHelperFunc) m_module.symbol ("scim_helper_module_run_helper");
 
         if (!m_run_helper) {
             m_module.unload ();
-            appid = "";
+            module_name = "";
             m_number_of_helpers = 0;
             m_get_helper_info = 0;
             m_get_helper_lang = 0;
@@ -89,7 +88,7 @@ HelperModule::load (const String &name)
         }
     } catch (...) {
         m_module.unload ();
-        appid = "";
+        module_name = "";
         m_number_of_helpers = 0;
         m_get_helper_info = 0;
         m_get_helper_lang = 0;
@@ -112,26 +111,30 @@ bool
 HelperModule::valid () const
 {
     return (m_module.valid () &&
-            appid.length () > 0 &&
+            module_name.length () > 0 &&
             m_run_helper);
 }
 
 unsigned int
 HelperModule::number_of_helpers () const
 {
-    return static_cast<unsigned int>(1);
+    const char *web_ime_module_name = "ise-web-helper-agent";   // Only Web IME can have multiple helpers.
+    if (module_name.compare (web_ime_module_name) == 0) {
+        return static_cast<unsigned int>(isf_db_select_count_by_module_name (web_ime_module_name));
+    }
+
+    return 1u;
 }
 
 bool
 HelperModule::get_helper_info (unsigned int idx, HelperInfo &info) const
 {
-    if (m_module.valid () && m_run_helper && appid.length () > 0) {
-        std::vector<ImeInfoDB> ime_info;
-        std::vector<ImeInfoDB>::iterator iter;
+    if (m_module.valid () && m_run_helper && module_name.length () > 0) {
 
-        isf_db_select_all_ime_info (ime_info);
-        for (iter = ime_info.begin (); iter != ime_info.end (); iter++) {
-            if (iter->appid.compare(appid) == 0) {
+        std::vector<ImeInfoDB> ime_info_db;
+        isf_db_select_all_ime_info (ime_info_db);
+        for (std::vector<ImeInfoDB>::iterator iter = ime_info_db.begin (); iter != ime_info_db.end (); iter++) {
+            if (iter->module_name.compare (module_name) == 0) {
                 info.uuid = iter->appid;
                 info.name = iter->label;
                 info.icon = iter->iconpath;
index 82887267bef630dd46eb12a3d6275207b85a599c..5679cf158d87dd30f54c3795c9fe5afb50b0bef1 100644 (file)
@@ -150,7 +150,7 @@ typedef void (*HelperModuleSetPathInfoFunc)       (const char *path);
 class EAPI HelperModule
 {
     Module                          m_module;
-    String                          appid;
+    String                          module_name;
 
     HelperModuleNumberOfHelpersFunc m_number_of_helpers;
     HelperModuleGetHelperInfoFunc   m_get_helper_info;
index 14a23d8e5676593c82e0237e5cf1c32c922a06e6..a7c9e72deee543633ea3076c2def2c80f18a5faf 100644 (file)
@@ -100,12 +100,12 @@ scim_get_module_list (std::vector <String>& mod_list, const String& type)
     if (type.compare("Helper") == 0) {
         isf_db_select_module_name_by_mode(TOOLBAR_HELPER_MODE, mname);
         for (i = 0; i < mname.size(); i++)
-                mod_list.push_back(mname[i]);
+            mod_list.push_back(mname[i]);
     }
     else if (type.compare("IMEngine") == 0) {
         isf_db_select_module_name_by_mode(TOOLBAR_KEYBOARD_MODE, mname);
         for (i = 0; i < mname.size(); i++)
-                mod_list.push_back(mname[i]);
+            mod_list.push_back(mname[i]);
 
         struct stat sb;
         stat("/usr/lib/scim-1.0/1.4.0/IMEngine/socket.so", &sb);