Add isf_control_is_ime_enabled() API for inputmethod-manager 31/41731/1
authorSungmin Kwak <sungmin.kwak@samsung.com>
Tue, 14 Apr 2015 05:02:38 +0000 (14:02 +0900)
committerLi Zhang <li2012.zhang@samsung.com>
Wed, 17 Jun 2015 09:21:01 +0000 (17:21 +0800)
Change-Id: Ie5e8c6b12f0cef702e864669f840bb4bf60170ec

ism/extras/efl_panel/isf_panel_efl.cpp
ism/src/isf_control.cpp
ism/src/isf_control.h
ism/src/isf_imcontrol_client.cpp
ism/src/isf_imcontrol_client.h
ism/src/isf_query_utility.cpp
ism/src/isf_query_utility.h
ism/src/scim_panel_agent.cpp
ism/src/scim_panel_agent.h
ism/src/scim_trans_commands.h

index 9806419..de9d195 100644 (file)
@@ -198,6 +198,7 @@ static void       slot_set_has_option_helper_ise_info  (const String &appid, boo
 static void       slot_set_enable_helper_ise_info      (const String &appid, bool is_enabled);
 static void       slot_show_helper_ise_list            (void);
 static void       slot_show_helper_ise_selector        (void);
+static bool       slot_is_helper_ise_enabled           (String appid, int &enabled);
 static bool       slot_get_ise_information             (String uuid, String &name, String &language, int &type, int &option, String &module_name);
 static bool       slot_get_keyboard_ise_list           (std::vector<String> &name_list);
 static void       slot_get_language_list               (std::vector<String> &name);
@@ -2966,7 +2967,7 @@ static void ui_settle_candidate_window (void)
         spot_x = _spot_location_x;
         spot_y = _spot_location_y;
 
-        rectinfo ise_rect = {0, 0, ise_width, ise_height};
+        rectinfo ise_rect = {0, 0, (uint32)ise_width, (uint32)ise_height};
         if (_candidate_angle == 90 || _candidate_angle == 270) {
             if (ise_rect.height <= (uint32)0 || ise_rect.height >= (uint32)_screen_width)
                 ise_rect.height = ISE_DEFAULT_HEIGHT_LANDSCAPE * _width_rate;
@@ -3439,6 +3440,7 @@ static bool initialize_panel_agent (const String &config, const String &display,
     _panel_agent->signal_connect_set_enable_helper_ise_info (slot (slot_set_enable_helper_ise_info));
     _panel_agent->signal_connect_show_helper_ise_list       (slot (slot_show_helper_ise_list));
     _panel_agent->signal_connect_show_helper_ise_selector   (slot (slot_show_helper_ise_selector));
+    _panel_agent->signal_connect_is_helper_ise_enabled      (slot (slot_is_helper_ise_enabled));
     _panel_agent->signal_connect_get_ise_information        (slot (slot_get_ise_information));
     _panel_agent->signal_connect_get_keyboard_ise_list      (slot (slot_get_keyboard_ise_list));
     _panel_agent->signal_connect_get_language_list          (slot (slot_get_language_list));
@@ -4854,6 +4856,27 @@ static void slot_show_helper_ise_selector (void)
     SECURE_LOGD("Launch %s", app_id);
 }
 
+static bool slot_is_helper_ise_enabled (String appid, int &enabled)
+{
+    bool is_enabled = false;
+
+    if (appid.length() == 0) {
+        LOGW("Invalid appid");
+        return false;
+    }
+
+    if (_ime_info.size() == 0)
+        isf_db_select_all_ime_info(_ime_info);
+
+    if (isf_db_select_is_enabled_by_appid(appid.c_str(), &is_enabled)) {
+        enabled = static_cast<int>(is_enabled);
+    }
+    else
+        return false;
+
+    return true;
+}
+
 /**
  * @brief Get the ISE's information.
  *
index de55468..783c829 100644 (file)
@@ -314,6 +314,27 @@ EAPI int isf_control_show_ime_selector (void)
     return 0;
 }
 
+EAPI int isf_control_is_ime_enabled (const char *appid, bool *enabled)
+{
+    if (!appid || !enabled)
+        return -1;
+
+    int nEnabled = -1;
+
+    IMControlClient imcontrol_client;
+    imcontrol_client.open_connection ();
+    imcontrol_client.prepare ();
+    imcontrol_client.is_helper_ise_enabled (appid, nEnabled);
+    imcontrol_client.close_connection ();
+
+    if (nEnabled < 0)
+        return -1;
+    else
+        *enabled = static_cast<bool>(nEnabled);
+
+    return 0;
+}
+
 /*
 vi:ts=4:nowrap:ai:expandtab
 */
index fecfa77..dc31e52 100644 (file)
@@ -73,7 +73,7 @@ EAPI int isf_control_set_active_ise_by_uuid (const char *uuid);
  * @param uuid The parameter is used to store active ISE's UUID.
  *             Application needs free *uuid if it is not used.
  *
- * @return the length of UUID if successfully, otherwise return -1;
+ * @return the length of UUID if successfully, otherwise return -1
  */
 EAPI int isf_control_get_active_ise (char **uuid);
 
@@ -96,7 +96,7 @@ EAPI int isf_control_get_ise_list (char ***uuid_list);
  * @param type     The parameter is used to store ISE's type.
  * @param option   The parameter is used to store ISE's option.
  *
- * @return 0 if successfully, otherwise return -1;
+ * @return 0 if successfully, otherwise return -1
  */
 EAPI int isf_control_get_ise_info (const char *uuid, char **name, char **language, ISE_TYPE_T *type, int *option);
 
@@ -110,14 +110,14 @@ EAPI int isf_control_get_ise_info (const char *uuid, char **name, char **languag
  * @param option   The parameter is used to store ISE's option.
  * @param module_name The parameter is used to store ISE's module file name.
  *
- * @return 0 if successfully, otherwise return -1;
+ * @return 0 if successfully, otherwise return -1
  */
 EAPI int isf_control_get_ise_info_and_module_name (const char *uuid, char **name, char **language, ISE_TYPE_T *type, int *option, char **module_name);
 
 /**
  * @brief Set active ISE to default ISE.
  *
- * @return 0 if successfully, otherwise return -1;
+ * @return 0 if successfully, otherwise return -1
  */
 EAPI int isf_control_set_active_ise_to_default (void);
 
@@ -133,7 +133,7 @@ EAPI int isf_control_reset_ise_option (void);
  *
  * @param uuid The initial ISE's UUID.
  *
- * @return 0 if successfully, otherwise return -1;
+ * @return 0 if successfully, otherwise return -1
  */
 EAPI int isf_control_set_initial_ise_by_uuid (const char *uuid);
 
@@ -166,7 +166,7 @@ EAPI int isf_control_get_ise_count (ISE_TYPE_T type);
 /**
  * @brief Show ISE's option window.
  *
- * @return 0 if successfully, otherwise return -1;
+ * @return 0 if successfully, otherwise return -1
  */
 EAPI int isf_control_show_ise_option_window ();
 
@@ -214,7 +214,7 @@ EAPI int isf_control_get_active_ime (char **appid);
  *
  * @param[in] appid Application ID of IME to set as active one
  *
- * @return 0 on success, otherwise -1
+ * @return 0 on success, otherwise return -1
  */
 EAPI int isf_control_set_active_ime (const char *appid);
 
@@ -226,7 +226,7 @@ EAPI int isf_control_set_active_ime (const char *appid);
  * @param[in] appid Application ID of IME to enable or disable
  * @param[in] is_enabled @c true to enable the IME, otherwise @c false
  *
- * @return 0 if successfully, otherwise return -1;
+ * @return 0 on success, otherwise return -1
  */
 EAPI int isf_control_set_enable_ime (const char *appid, bool is_enabled);
 
@@ -237,7 +237,7 @@ EAPI int isf_control_set_enable_ime (const char *appid, bool is_enabled);
  *
  * @since_tizen 2.4
  *
- * @return 0 if successfully, otherwise return -1;
+ * @return 0 on success, otherwise return -1
  */
 EAPI int isf_control_show_ime_list (void);
 
@@ -248,10 +248,21 @@ EAPI int isf_control_show_ime_list (void);
  *
  * @since_tizen 2.4
  *
- * @return 0 if successfully, otherwise return -1;
+ * @return 0 on success, otherwise return -1
  */
 EAPI int isf_control_show_ime_selector (void);
 
+/**
+ * @brief Checks if the specific IME is enabled or disabled in the system keyboard setting.
+ *
+ * @since_tizen 2.4
+ *
+ * @param[in] appid The application ID of the IME
+ * @param[out] enabled The On (enabled) and Off (disabled) state of the IME
+ *
+ * @return 0 on success, otherwise return -1
+ */
+EAPI int isf_control_is_ime_enabled (const char *appid, bool *enabled);
 
 #ifdef __cplusplus
 }
index 1c88f4b..efbada6 100644 (file)
@@ -434,6 +434,26 @@ public:
     void show_helper_ise_selector (void) {
         m_trans.put_command (ISM_TRANS_CMD_SHOW_HELPER_ISE_SELECTOR);
     }
+
+    void is_helper_ise_enabled (const char* appid, int &enabled)
+    {
+        int    cmd;
+        uint32 tmp_enabled;
+
+        m_trans.put_command (ISM_TRANS_CMD_IS_HELPER_ISE_ENABLED);
+        m_trans.put_data (String (appid));
+        m_trans.write_to_socket (m_socket_imclient2panel);
+        if (!m_trans.read_from_socket (m_socket_imclient2panel, m_socket_timeout))
+            std::cerr << __func__ << " read_from_socket() may be timeout \n";
+
+        if (m_trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
+                m_trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK &&
+                m_trans.get_data (tmp_enabled)) {
+            enabled = static_cast<int>(tmp_enabled);
+        } else {
+            std::cerr << __func__ << " get_command() or get_data() may fail!!!\n";
+        }
+    }
 };
 
 IMControlClient::IMControlClient ()
@@ -545,6 +565,11 @@ void IMControlClient::show_helper_ise_selector (void)
     m_impl->show_helper_ise_selector ();
 }
 
+void IMControlClient::is_helper_ise_enabled (const char* appid, int &enabled)
+{
+    m_impl->is_helper_ise_enabled (appid, enabled);
+}
+
 };
 
 /*
index 8cc595a..b4c2886 100644 (file)
@@ -61,6 +61,7 @@ public:
     void set_enable_helper_ise_info (const char *appid, bool is_enabled);
     void show_helper_ise_list (void);
     void show_helper_ise_selector (void);
+    void is_helper_ise_enabled (const char* appid, int &enabled);
 };
 
 }
index 794e5b0..1798a5b 100644 (file)
@@ -579,6 +579,52 @@ out:
 }
 
 /**
+ * @brief Select "is_enabled" by appid in ime_info table.
+ *
+ * @param[in] appid appid in ime_info table.
+ * @param[out] is_enabled Helper ISE enabled or not.
+ *
+ * @return 1 if it is successful, otherwise return 0.
+ */
+static int _db_select_is_enabled_by_appid(const char *appid, bool *is_enabled)
+{
+    int ret = 0, i = 0;
+    sqlite3_stmt* pStmt = NULL;
+    static const char* pQuery = "SELECT is_enabled FROM ime_info WHERE appid = ?";
+
+    if (!appid || !is_enabled)
+        return i;
+
+    ret = sqlite3_prepare_v2(databaseInfo.pHandle, pQuery, -1, &pStmt, NULL);
+    if (ret != SQLITE_OK) {
+        LOGE("%s", sqlite3_errmsg(databaseInfo.pHandle));
+        return i;
+    }
+
+    ret = sqlite3_bind_text(pStmt, 1, appid, -1, SQLITE_TRANSIENT);
+    if (ret != SQLITE_OK) {
+        LOGE("%s", sqlite3_errmsg(databaseInfo.pHandle));
+        goto out;
+    }
+
+    ret = sqlite3_step(pStmt);
+    if (ret != SQLITE_ROW) {
+        LOGE("%s", sqlite3_errmsg(databaseInfo.pHandle));
+    }
+    else {
+        *is_enabled = (bool)sqlite3_column_int(pStmt, 0);
+        i = 1;
+        SECURE_LOGD("is_enabled=%d by appid=\"%s\"", *is_enabled, appid);
+    }
+
+out:
+    sqlite3_reset(pStmt);
+    sqlite3_clear_bindings(pStmt);
+    sqlite3_finalize(pStmt);
+    return i;
+}
+
+/**
  * @brief Gets the count of the same module name in ime_info table.
  *
  * @param module_name Module name
@@ -1248,6 +1294,34 @@ EAPI int isf_db_select_appids_by_pkgid(const char *pkgid, std::vector<String> &a
 }
 
 /**
+ * @brief Select "is_enabled" by appid in ime_info table.
+ *
+ * @param[in] appid appid in ime_info table.
+ * @param[out] is_enabled Helper ISE enabled or not.
+ *
+ * @return 1 if it is successful, otherwise return 0.
+ */
+EAPI int isf_db_select_is_enabled_by_appid(const char *appid, bool *is_enabled)
+{
+    int ret = 0;
+
+    if (!appid || !is_enabled) {
+        LOGW("Input parameter is null.");
+        return 0;
+    }
+
+    if (_db_connect() == 0) {
+        ret = _db_select_is_enabled_by_appid(appid, is_enabled);
+        _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
@@ -1299,7 +1373,7 @@ EAPI int isf_db_update_label_by_appid(const char *appid, const char *label)
  * @brief Update "is_enabled" data by appid in ime_info table.
  *
  * @param appid appid in ime_info table.
- * @param enabled Helper ISE enabled or not.
+ * @param is_enabled Helper ISE enabled or not.
  *
  * @return 1 if it is successful, otherwise return 0.
  */
index 923bcd5..ba937bc 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_is_enabled_by_appid(const char *appid, bool *is_enabled);
 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);
index 5aa436f..40d2e3f 100644 (file)
@@ -150,6 +150,9 @@ typedef Signal2<void, char *, std::vector <String> &>
 typedef Signal2<bool, const String &, ISE_INFO &>
         PanelAgentSignalStringISEINFO;
 
+typedef Signal2<bool, String, int &>
+        PanelAgentSignalStringInt;
+
 typedef Signal1<void, const KeyEvent &>
         PanelAgentSignalKeyEvent;
 
@@ -349,6 +352,7 @@ class PanelAgent::PanelAgentImpl
     PanelAgentSignalStringBool          m_signal_set_enable_helper_ise_info;
     PanelAgentSignalVoid                m_signal_show_helper_ise_list;
     PanelAgentSignalVoid                m_signal_show_helper_ise_selector;
+    PanelAgentSignalStringInt           m_signal_is_helper_ise_enabled;
     PanelAgentSignalBoolString4int2     m_signal_get_ise_information;
     PanelAgentSignalBoolStringVector    m_signal_get_keyboard_ise_list;
     PanelAgentSignalIntIntIntInt        m_signal_update_ise_geometry;
@@ -2462,6 +2466,32 @@ public:
         m_signal_show_helper_ise_selector ();
     }
 
+    void is_helper_ise_enabled (int client_id)
+    {
+        SCIM_DEBUG_MAIN(4) << __func__ << "\n";
+
+        String strAppid;
+        int nEnabled = 0;
+        bool ret = false;
+
+        if (m_recv_trans.get_data (strAppid)) {
+            ret = m_signal_is_helper_ise_enabled (strAppid, nEnabled);
+        }
+
+        Transaction trans;
+        Socket client_socket (client_id);
+        trans.clear ();
+        trans.put_command (SCIM_TRANS_CMD_REPLY);
+        if (ret) {
+            trans.put_command (SCIM_TRANS_CMD_OK);
+            trans.put_data (static_cast<uint32>(nEnabled));
+        }
+        else {
+            trans.put_command (SCIM_TRANS_CMD_FAIL);
+        }
+        trans.write_to_socket (client_socket);
+    }
+
     void get_ise_information (int client_id)
     {
         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
@@ -3305,6 +3335,11 @@ public:
         return m_signal_show_helper_ise_selector.connect (slot);
     }
 
+    Connection signal_connect_is_helper_ise_enabled   (PanelAgentSlotStringInt                *slot)
+    {
+        return m_signal_is_helper_ise_enabled.connect (slot);
+    }
+
     Connection signal_connect_get_ise_information        (PanelAgentSlotBoolString4int2        *slot)
     {
         return m_signal_get_ise_information.connect (slot);
@@ -3975,6 +4010,9 @@ private:
                 else if (cmd == ISM_TRANS_CMD_SHOW_HELPER_ISE_SELECTOR) {
                     show_helper_ise_selector (client_id);
                 }
+                else if (cmd == ISM_TRANS_CMD_IS_HELPER_ISE_ENABLED) {
+                    is_helper_ise_enabled (client_id);
+                }
             }
 
             socket_transaction_end ();
@@ -6673,6 +6711,12 @@ PanelAgent::signal_connect_show_helper_ise_selector   (PanelAgentSlotVoid
 }
 
 Connection
+PanelAgent::signal_connect_is_helper_ise_enabled      (PanelAgentSlotStringInt           *slot)
+{
+    return m_impl->signal_connect_is_helper_ise_enabled (slot);
+}
+
+Connection
 PanelAgent::signal_connect_get_ise_information        (PanelAgentSlotBoolString4int2     *slot)
 {
     return m_impl->signal_connect_get_ise_information (slot);
index d84605c..ab45e80 100644 (file)
@@ -160,6 +160,9 @@ typedef Slot2<void, char *, std::vector<String> &>
 typedef Slot2<bool, const String &, ISE_INFO &>
         PanelAgentSlotStringISEINFO;
 
+typedef Slot2<bool, String, int &>
+        PanelAgentSlotStringInt;
+
 typedef Slot1<void, const KeyEvent &>
         PanelAgentSlotKeyEvent;
 
@@ -1056,6 +1059,13 @@ public:
     Connection signal_connect_show_helper_ise_selector  (PanelAgentSlotVoid   *slot);
 
     /**
+     * @brief Signal: Checks if the specific IME is enabled or disabled in the system keyboard setting
+     *
+     * slot prototype: bool is_helper_ise_enabled (const String, int &);
+     */
+    Connection signal_connect_is_helper_ise_enabled  (PanelAgentSlotStringInt   *slot);
+
+    /**
      * @brief Signal: Get the ISE information according to UUID.
      *
      * slot prototype: bool get_ise_information (String, String &, String &, int &, int &);
index 43c03df..83d2715 100644 (file)
@@ -635,6 +635,7 @@ const int ISM_TRANS_CMD_GET_ALL_HELPER_ISE_INFO           = 1019;
 const int ISM_TRANS_CMD_SET_ENABLE_HELPER_ISE_INFO        = 1020;
 const int ISM_TRANS_CMD_SHOW_HELPER_ISE_LIST              = 1021;
 const int ISM_TRANS_CMD_SHOW_HELPER_ISE_SELECTOR          = 1022;
+const int ISM_TRANS_CMD_IS_HELPER_ISE_ENABLED             = 1023;
 
 /* IMControl to ISE */
 const int ISM_TRANS_CMD_SET_ISE_MODE                      = 1108;