From: Haifeng Deng Date: Wed, 30 Oct 2013 02:24:53 +0000 (+0800) Subject: Add monitor for OSP IME X-Git-Tag: submit/tizen/20140310.020845~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b40d525f034bf68e43c963f6d18d9f9fde6038e;p=platform%2Fcore%2Fuifw%2Fisf.git Add monitor for OSP IME Change-Id: Id42b652423355785eae04049dda5a231ef97c2f0 --- diff --git a/ism/extras/efl_panel/isf_panel_efl.cpp b/ism/extras/efl_panel/isf_panel_efl.cpp index c4778e90..ce908193 100644 --- a/ism/extras/efl_panel/isf_panel_efl.cpp +++ b/ism/extras/efl_panel/isf_panel_efl.cpp @@ -118,6 +118,8 @@ typedef enum _WINDOW_STATE { WINDOW_STATE_ON, } WINDOW_STATE; +typedef std::map OSPEmRepository; + ///////////////////////////////////////////////////////////////////////////// // Declaration of internal functions. @@ -322,8 +324,12 @@ static Ecore_X_Window _ise_window = 0; static Ecore_X_Window _app_window = 0; static Ecore_X_Window _control_window = 0; -static Ecore_File_Monitor *_helper_ise_em = NULL; -static Ecore_File_Monitor *_keyboard_ise_em = NULL; +static Ecore_File_Monitor *_inh_helper_ise_em = NULL; +static Ecore_File_Monitor *_inh_keyboard_ise_em = NULL; +static Ecore_File_Monitor *_osp_helper_ise_em = NULL; +static Ecore_File_Monitor *_osp_keyboard_ise_em = NULL; +static OSPEmRepository _osp_bin_em; +static OSPEmRepository _osp_info_em; static bool hw_kbd_mode = false; @@ -547,32 +553,169 @@ static String get_module_file_path (const String &module_name, const String &typ String strFile; if (module_name.substr (0, 1) == String ("/")) { - strFile = module_name + ".so"; + strFile = module_name + String (".so"); if (access (strFile.c_str (), R_OK) == 0) - return strFile.substr (0, strFile.find_last_of ('/') + 1); + return strFile; } /* Check inhouse path */ strFile = String (SCIM_MODULE_PATH) + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION) + String (SCIM_PATH_DELIM_STRING) + type + - String (SCIM_PATH_DELIM_STRING) + module_name + ".so"; + String (SCIM_PATH_DELIM_STRING) + module_name + String (".so"); if (access (strFile.c_str (), R_OK) == 0) - return strFile.substr (0, strFile.find_last_of ('/') + 1); + return strFile; const char *module_path_env = getenv ("SCIM_MODULE_PATH"); if (module_path_env) { strFile = String (module_path_env) + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION) + String (SCIM_PATH_DELIM_STRING) + type + - String (SCIM_PATH_DELIM_STRING) + module_name + ".so"; + String (SCIM_PATH_DELIM_STRING) + module_name + String (".so"); if (access (strFile.c_str (), R_OK) == 0) - return strFile.substr (0, strFile.find_last_of ('/') + 1); + return strFile; } return String (""); } +/** + * @brief Get module names for all 3rd party's IMEs. + * @param ops_module_names The list to store module names for all 3rd party's IMEs. + * @return module name list size + */ +static int osp_module_list_get (std::vector &ops_module_names) +{ + const char *module_path_env = getenv ("SCIM_MODULE_PATH"); + if (module_path_env) { + String path = String (module_path_env) + + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION) + + String (SCIM_PATH_DELIM_STRING) + String ("Helper"); + ops_module_names.clear (); + + DIR *dir = opendir (path.c_str ()); + if (dir) { + struct dirent *file = readdir (dir); + while (file) { + struct stat filestat; + String absfn = path + String (SCIM_PATH_DELIM_STRING) + file->d_name; + stat (absfn.c_str (), &filestat); + if (S_ISREG (filestat.st_mode)) { + String link_name = String (file->d_name); + ops_module_names.push_back (link_name.substr (0, link_name.find_last_of ('.'))); + } + + file = readdir (dir); + } + closedir (dir); + } + } + + std::sort (ops_module_names.begin (), ops_module_names.end ()); + ops_module_names.erase (std::unique (ops_module_names.begin (), ops_module_names.end ()), ops_module_names.end ()); + + return ops_module_names.size (); +} + +static String osp_module_name_get (const String &path) +{ + String pkg_id = path.substr (path.find_last_of (SCIM_PATH_DELIM) + 1); + String ise_name = String (""); + String bin_path = path + String ("/bin"); + DIR *dir = opendir (bin_path.c_str ()); + if (dir) { + struct dirent *file = readdir (dir); + while (file) { + struct stat filestat; + String absfn = bin_path + String (SCIM_PATH_DELIM_STRING) + file->d_name; + stat (absfn.c_str (), &filestat); + if (S_ISREG (filestat.st_mode)) { + String ext = absfn.substr (absfn.length () - 4); + if (ext == String (".exe")) { + int begin = absfn.find_last_of (SCIM_PATH_DELIM) + 1; + ise_name = absfn.substr (begin, absfn.find_last_of ('.') - begin); + break; + } + } + + file = readdir (dir); + } + closedir (dir); + } else { + LOGD ("open (%s) is failed!!!", bin_path.c_str ()); + } + String module_name = String (""); + if (ise_name.length () > 0) + module_name = pkg_id + String (".") + ise_name; + + LOGD ("module name = %s", module_name.c_str ()); + return module_name; +} + +static void osp_engine_dir_monitor_cb (void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path) +{ + String em_path = String (ecore_file_monitor_path_get (em)); + String manifest_file = em_path.substr (0, em_path.find_last_of (SCIM_PATH_DELIM)) + String ("/info/manifest.xml"); + String ext = String (path).substr (String (path).length () - 4); + + if (event == ECORE_FILE_EVENT_CLOSED) { + if (String (path) == manifest_file || ext == String (".exe")) { + LOGD ("path = %s, event = %d", path, event); + String pkg_path = em_path.substr (0, em_path.find_last_of (SCIM_PATH_DELIM)); + String module_name = osp_module_name_get (pkg_path); + const char *module_path_env = getenv ("SCIM_MODULE_PATH"); + if (module_path_env && module_name.length () > 0) { + String module_path = String (module_path_env) + + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION) + + String (SCIM_PATH_DELIM_STRING) + String ("Helper") + String (SCIM_PATH_DELIM_STRING) + module_name + String (".so"); + isf_update_ise_module (String (module_path), _config); + _panel_agent->update_ise_list (_uuids); + + String uuid = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), _initial_ise_uuid); + int index = get_ise_index (uuid); + if (_modes[index] == TOOLBAR_HELPER_MODE) { + String active_module = get_module_file_path (_module_names[index], String ("Helper")); + if (String (module_path) == active_module) { + /* Restart helper ISE */ + _panel_agent->hide_helper (uuid); + _panel_agent->stop_helper (uuid); + _panel_agent->start_helper (uuid); + } + } + } + } + } +} + +static void add_monitor_for_osp_module (const String &module_name) +{ + String rpath = String ("/opt/apps/") + module_name.substr (0, module_name.find_first_of ('.')); + String exe_path = rpath + String ("/bin"); + String manifest_path = rpath + String ("/info"); + + if (_osp_bin_em.find (module_name) == _osp_bin_em.end () || _osp_bin_em[module_name] == NULL) { + _osp_bin_em[module_name] = ecore_file_monitor_add (exe_path.c_str (), osp_engine_dir_monitor_cb, NULL); + LOGD ("add %s", module_name.c_str ()); + } + if (_osp_info_em.find (module_name) == _osp_info_em.end () || _osp_info_em[module_name] == NULL) { + _osp_info_em[module_name] = ecore_file_monitor_add (manifest_path.c_str (), osp_engine_dir_monitor_cb, NULL); + } +} + +/** + * @brief : add monitor for engine file and info file update of 3rd party's IMEs + */ +static void add_monitor_for_all_osp_modules (void) +{ + std::vector osp_module_list; + osp_module_list_get (osp_module_list); + + if (osp_module_list.size () > 0) { + for (unsigned int i = 0; i < osp_module_list.size (); i++) + add_monitor_for_osp_module (osp_module_list[i]); + } +} + /** * @brief Callback function for ISE file monitor. * @@ -583,25 +726,60 @@ static String get_module_file_path (const String &module_name, const String &typ */ static void ise_file_monitor_cb (void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path) { - SCIM_DEBUG_MAIN (3) << __FUNCTION__ << "...\n"; + SCIM_DEBUG_MAIN (3) << __FUNCTION__ << " path=" << path << "\n"; + LOGD ("path = %s, event = %d", path, event); + + String directory = String (path); + directory = directory.substr (0, 4); + if (event == ECORE_FILE_EVENT_DELETED_FILE || event == ECORE_FILE_EVENT_CLOSED || + (event == ECORE_FILE_EVENT_CREATED_FILE && directory == String ("/opt"))) { + String file_path = String (path); + String file_ext = file_path.substr (file_path.length () - 3); + if (file_ext != String (".so")) { + LOGD ("%s is not valid so file!!!", path); + return; + } - if (event == ECORE_FILE_EVENT_DELETED_FILE || event == ECORE_FILE_EVENT_CLOSED) { - int index = GPOINTER_TO_INT (data); - String strFile = String (ecore_file_monitor_path_get (em)) + - String (SCIM_PATH_DELIM_STRING) + _module_names[index] + String (".so"); - - if (String (path) == strFile) { - if (event == ECORE_FILE_EVENT_DELETED_FILE) { - /* Update ISE list */ - std::vector list; - slot_get_ise_list (list); - } else if (event == ECORE_FILE_EVENT_CLOSED) { - if (_modes[index] == TOOLBAR_HELPER_MODE) { - /* Restart helper ISE */ - _panel_agent->hide_helper (_uuids[index]); - _panel_agent->stop_helper (_uuids[index]); - _panel_agent->start_helper (_uuids[index]); - } + int begin = String (path).find_last_of (SCIM_PATH_DELIM) + 1; + String module_name = String (path).substr (begin, String (path).find_last_of ('.') - begin); + + if (event == ECORE_FILE_EVENT_DELETED_FILE) { + /* Update ISE list */ + std::vector list; + slot_get_ise_list (list); + + /* delete osp monitor */ + OSPEmRepository::iterator iter = _osp_bin_em.find (module_name); + if (iter != _osp_bin_em.end ()) { + ecore_file_monitor_del (iter->second); + _osp_bin_em.erase (iter); + LOGD ("delete %s", module_name.c_str ()); + } + iter = _osp_info_em.find (module_name); + if (iter != _osp_info_em.end ()) { + ecore_file_monitor_del (iter->second); + _osp_info_em.erase (iter); + } + } else if (event == ECORE_FILE_EVENT_CLOSED || ECORE_FILE_EVENT_CREATED_FILE) { + isf_update_ise_module (String (path), _config); + _panel_agent->update_ise_list (_uuids); + + String uuid = scim_global_config_read (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), _initial_ise_uuid); + int index = get_ise_index (uuid); + String strFile = String (ecore_file_monitor_path_get (em)) + + String (SCIM_PATH_DELIM_STRING) + _module_names[index] + String (".so"); + + if (String (path) == strFile && _modes[index] == TOOLBAR_HELPER_MODE) { + /* Restart helper ISE */ + _panel_agent->hide_helper (uuid); + _panel_agent->stop_helper (uuid); + _panel_agent->start_helper (uuid); + } + + /* add osp monitor */ + if (event == ECORE_FILE_EVENT_CREATED_FILE && directory == String ("/opt")) { + add_monitor_for_osp_module (module_name); + LOGD ("add %s", module_name.c_str ()); } } } @@ -610,36 +788,94 @@ static void ise_file_monitor_cb (void *data, Ecore_File_Monitor *em, Ecore_File_ /** * @brief Delete keyboard ISE file monitor. */ -static void delete_keyboard_ise_em (void) { - if (_keyboard_ise_em) { - ecore_file_monitor_del (_keyboard_ise_em); - _keyboard_ise_em = NULL; +static void delete_ise_directory_em (void) { + if (_inh_keyboard_ise_em) { + ecore_file_monitor_del (_inh_keyboard_ise_em); + _inh_keyboard_ise_em = NULL; + } + if (_inh_helper_ise_em) { + ecore_file_monitor_del (_inh_helper_ise_em); + _inh_helper_ise_em = NULL; } -} -/** - * @brief Delete helper ISE file monitor. - */ -static void delete_helper_ise_em (void) { - if (_helper_ise_em) { - ecore_file_monitor_del (_helper_ise_em); - _helper_ise_em = NULL; + if (_osp_keyboard_ise_em) { + ecore_file_monitor_del (_osp_keyboard_ise_em); + _osp_keyboard_ise_em = NULL; } + if (_osp_helper_ise_em) { + ecore_file_monitor_del (_osp_helper_ise_em); + _osp_helper_ise_em = NULL; + } + + OSPEmRepository::iterator iter; + for (iter = _osp_bin_em.begin (); iter != _osp_bin_em.end (); iter++) { + if (iter->second) { + ecore_file_monitor_del (iter->second); + iter->second = NULL; + } + } + for (iter = _osp_info_em.begin (); iter != _osp_info_em.end (); iter++) { + if (iter->second) { + ecore_file_monitor_del (iter->second); + iter->second = NULL; + } + } + _osp_bin_em.clear (); + _osp_info_em.clear (); } /** - * @brief Add keyboard ISE file monitor. - * - * @param module_name The keyboard ISE's module name. + * @brief Add inhouse ISEs and OSP ISEs directory monitor. */ -static void add_keyboard_ise_em (const String &uuid, const String &module_name) { +static void add_ise_directory_em (void) { SCIM_DEBUG_MAIN (3) << __FUNCTION__ << "...\n"; - String path = get_module_file_path (module_name, "IMEngine"); - if (path.length () > 0 && access (path.c_str (), R_OK) == 0) { - delete_keyboard_ise_em (); - _keyboard_ise_em = ecore_file_monitor_add (path.c_str (), ise_file_monitor_cb, GINT_TO_POINTER(get_ise_index (uuid))); + // inhouse IMEngine path + String path = String (SCIM_MODULE_PATH) + + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION) + + String (SCIM_PATH_DELIM_STRING) + String ("IMEngine"); + if (_inh_keyboard_ise_em == NULL) + _inh_keyboard_ise_em = ecore_file_monitor_add (path.c_str (), ise_file_monitor_cb, NULL); + + // inhouse Helper path + path = String (SCIM_MODULE_PATH) + + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION) + + String (SCIM_PATH_DELIM_STRING) + String ("Helper"); + if (_inh_helper_ise_em == NULL) + _inh_helper_ise_em = ecore_file_monitor_add (path.c_str (), ise_file_monitor_cb, NULL); + + const char *module_path_env = getenv ("SCIM_MODULE_PATH"); + if (module_path_env) { + // OSP IMEngine path + path = String (module_path_env) + + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION) + + String (SCIM_PATH_DELIM_STRING) + String ("IMEngine"); + if (access (path.c_str (), R_OK) == 0) { + if (_osp_keyboard_ise_em == NULL) { + _osp_keyboard_ise_em = ecore_file_monitor_add (path.c_str (), ise_file_monitor_cb, NULL); + LOGD ("ecore_file_monitor_add path=%s", path.c_str ()); + } + } else { + LOGD ("access path=%s is failed!!!", path.c_str ()); + } + + // OSP Helper path + path = String (module_path_env) + + String (SCIM_PATH_DELIM_STRING) + String (SCIM_BINARY_VERSION) + + String (SCIM_PATH_DELIM_STRING) + String ("Helper"); + if (access (path.c_str (), R_OK) == 0) { + if (_osp_helper_ise_em == NULL) { + _osp_helper_ise_em = ecore_file_monitor_add (path.c_str (), ise_file_monitor_cb, NULL); + LOGD ("ecore_file_monitor_add path=%s", path.c_str ()); + } + } else { + LOGD ("access path=%s is failed!!!", path.c_str ()); + } + } else { + LOGD ("getenv (\"SCIM_MODULE_PATH\") is failed!!!"); } + + add_monitor_for_all_osp_modules (); } /** @@ -664,13 +900,8 @@ static bool set_keyboard_ise (const String &uuid, const String &module_name) uint32 kbd_option = 0; String kbd_uuid, kbd_name; isf_get_keyboard_ise (_config, kbd_uuid, kbd_name, kbd_option); - if (kbd_uuid == uuid) { - if (_keyboard_ise_em == NULL) { - add_keyboard_ise_em (uuid, module_name); - delete_helper_ise_em (); - } + if (kbd_uuid == uuid) return false; - } } _panel_agent->change_factory (uuid); @@ -678,10 +909,6 @@ static bool set_keyboard_ise (const String &uuid, const String &module_name) String language = String ("~other");/*scim_get_locale_language (scim_get_current_locale ());*/ _config->write (String (SCIM_CONFIG_DEFAULT_IMENGINE_FACTORY) + String ("/") + language, uuid); - /* Add directory monitor for keyboard ISE */ - add_keyboard_ise_em (uuid, module_name); - delete_helper_ise_em (); - return true; } @@ -721,7 +948,6 @@ static bool set_helper_ise (const String &uuid, const String &module_name) String language = String ("~other");/*scim_get_locale_language (scim_get_current_locale ());*/ _config->write (String (SCIM_CONFIG_DEFAULT_IMENGINE_FACTORY) + String ("/") + language, kbd_uuid); - delete_keyboard_ise_em (); } char buf[256] = {0}; snprintf (buf, sizeof (buf), "time:%ld pid:%d %s %s Start helper(%s)\n", @@ -731,13 +957,6 @@ static bool set_helper_ise (const String &uuid, const String &module_name) _panel_agent->start_helper (uuid); _config->write (String (SCIM_CONFIG_DEFAULT_HELPER_ISE), uuid); - /* Add directory monitor for helper ISE */ - String path = get_module_file_path (module_name, "Helper"); - if (path.length () > 0 && access (path.c_str (), R_OK) == 0) { - delete_helper_ise_em (); - _helper_ise_em = ecore_file_monitor_add (path.c_str (), ise_file_monitor_cb, GINT_TO_POINTER(get_ise_index (uuid))); - } - return true; } @@ -3611,10 +3830,11 @@ static bool slot_get_ise_list (std::vector &list) _panel_agent->change_factory (active_uuid); _config->write (IMENGINE_KEY, active_uuid); _config->flush (); - delete_keyboard_ise_em (); } } } + + add_ise_directory_em (); return ret; } @@ -3774,12 +3994,8 @@ static void slot_set_keyboard_ise (const String &uuid) uint32 ise_option = 0; String ise_uuid, ise_name; isf_get_keyboard_ise (_config, ise_uuid, ise_name, ise_option); - if (ise_uuid == uuid) { - if (_keyboard_ise_em == NULL) { - add_keyboard_ise_em (uuid, _module_names[get_ise_index (uuid)]); - } + if (ise_uuid == uuid) return; - } String language = String ("~other");/*scim_get_locale_language (scim_get_current_locale ());*/ _config->write (String (SCIM_CONFIG_DEFAULT_IMENGINE_FACTORY) + String ("/") + language, uuid); @@ -3788,11 +4004,6 @@ static void slot_set_keyboard_ise (const String &uuid) _panel_agent->change_factory (uuid); _panel_agent->reload_config (); - - /* Add directory monitor for keyboard ISE */ - if (_keyboard_ise_em == NULL) { - add_keyboard_ise_em (uuid, _module_names[get_ise_index (uuid)]); - } } /** @@ -4574,94 +4785,6 @@ static void _launch_default_soft_keyboard (void) check_hardware_keyboard (); } -/** - * @brief Get module names for all 3rd party's IMEs. - * @param ops_module_names The list to store module names for all 3rd party's IMEs. - * @return module name list size - */ -static int scim_get_osp_module_list (std::vector &ops_module_names) -{ - char *path = "/opt/apps/scim/lib/scim-1.0/1.4.0/Helper"; - ops_module_names.clear (); - - DIR *dir = opendir (path); - if (dir) { - struct dirent *file = readdir (dir); - while (file) { - struct stat filestat; - String absfn = String(path) + String (SCIM_PATH_DELIM_STRING) + file->d_name; - stat (absfn.c_str (), &filestat); - if (S_ISREG (filestat.st_mode)) { - String link_name = String (file->d_name); - ops_module_names.push_back (link_name.substr (0, link_name.find_last_of ('.'))); - } - - file = readdir (dir); - } - closedir (dir); - } - - std::sort (ops_module_names.begin (), ops_module_names.end ()); - ops_module_names.erase (std::unique (ops_module_names.begin (), ops_module_names.end ()), ops_module_names.end ()); - - return ops_module_names.size (); -} - -static void osp_engine_dir_monitor_cb (void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path) -{ - if (!data) return; - char *osp_module_name = (char *)data; - - String rpath = String ("/opt/apps/") + String (osp_module_name).substr (0, String (osp_module_name).find_first_of ('.')); - String osp_ime_name = String (osp_module_name).substr (String (osp_module_name).find_first_of ('.') + 1, String (osp_module_name).find_last_of ('.')); - String exe_path = rpath + String ("/bin/") + osp_ime_name + String (".exe"); - - if (event == ECORE_FILE_EVENT_CLOSED) { - if (String (path) == exe_path) { - LOGD ("%s", ecore_file_monitor_path_get (em)); - LOGD ("%s", osp_module_name); - } - } -} - -static void osp_info_dir_monitor_cb (void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path) -{ - if (!data) return; - char *osp_module_name = (char *)data; - - String rpath = String ("/opt/apps/") + String (osp_module_name).substr (0, String (osp_module_name).find_first_of ('.')); - String osp_ime_name = String (osp_module_name).substr (String (osp_module_name).find_first_of('.') + 1, String (osp_module_name).find_last_of('.')); - String manifest_path = rpath + String ("/info/manifest.xml"); - - if (event == ECORE_FILE_EVENT_CLOSED) { - if (String (path) == manifest_path) { - LOGD ("%s", ecore_file_monitor_path_get (em)); - LOGD ("%s", osp_module_name); - } - } -} - -/** - * @brief : add monitor for engine file and info file update of 3rd party's IMEs - */ -static void add_monitor_for_osp_modules () -{ - LOGD (""); - std::vector osp_module_list; - scim_get_osp_module_list (osp_module_list); - - if (osp_module_list.size () > 0) { - for (unsigned int i = 0; i < osp_module_list.size (); i++) { - LOGD ("%s", osp_module_list[i].c_str ()); - String rpath = String ("/opt/apps/") + osp_module_list[i].substr (0, osp_module_list[i].find_first_of ('.')); - String exe_path = rpath + String ("/bin"); - String manifest_path = rpath + String ("/info"); - ecore_file_monitor_add (exe_path.c_str (), osp_engine_dir_monitor_cb, (void *)(strdup (osp_module_list[i].c_str ()))); - ecore_file_monitor_add (manifest_path.c_str (), osp_info_dir_monitor_cb, (void *)(strdup (osp_module_list[i].c_str ()))); - } - } -} - /** * @brief : Launches default soft keyboard for performance enhancement (It's not mandatory) */ @@ -4979,8 +5102,7 @@ cleanup: ui_candidate_delete_check_size_timer (); ui_candidate_delete_longpress_timer (); ui_candidate_delete_destroy_timer (); - delete_keyboard_ise_em (); - delete_helper_ise_em (); + delete_ise_directory_em (); ui_close_tts (); if (!_config.null ()) diff --git a/ism/extras/efl_panel/isf_panel_utility.cpp b/ism/extras/efl_panel/isf_panel_utility.cpp index 3010f68a..cb389ebe 100644 --- a/ism/extras/efl_panel/isf_panel_utility.cpp +++ b/ism/extras/efl_panel/isf_panel_utility.cpp @@ -34,6 +34,7 @@ #include "scim_stl_map.h" #include "isf_panel_utility.h" #include "isf_query_utility.h" +#include #include #include @@ -384,6 +385,10 @@ static bool add_keyboard_ise_module (const String module_name, const ConfigPoint } } ime_module.unload (); + } else { + LOGD ("Failed to load (%s)!!!", module_name.c_str ()); + fclose (engine_list_file); + return false; } int ret = fclose (engine_list_file); @@ -440,6 +445,10 @@ static bool add_helper_ise_module (const String module_name) } } helper_module.unload (); + } else { + LOGD ("Failed to load (%s)!!!", module_name.c_str ()); + fclose (engine_list_file); + return false; } int ret = fclose (engine_list_file); @@ -499,7 +508,8 @@ bool isf_update_ise_list (LOAD_ISE_TYPE type, const ConfigPointer &config) if (std::find (uninstall_modules.begin (), uninstall_modules.end (), _module_names [i]) == uninstall_modules.end ()) { uninstall_modules.push_back (_module_names [i]); String filename = String (USER_ENGINE_FILE_NAME); - isf_remove_ise_info_from_file (filename.c_str (), _module_names [i].c_str ()); + if (isf_remove_ise_info_from_file (filename.c_str (), _module_names [i].c_str ()) == false) + LOGD ("Failed to remove %s from cache file : %s!!!", _module_names [i].c_str (), filename.c_str ()); } } } @@ -550,6 +560,80 @@ bool isf_update_ise_list (LOAD_ISE_TYPE type, const ConfigPointer &config) return ret; } +bool isf_remove_ise_module (const String module_name, const ConfigPointer &config) +{ + if (std::find (_module_names.begin (), _module_names.end (), module_name) == _module_names.end ()) { + LOGD ("Cannot to find %s!!!", module_name.c_str ()); + return true; + } + + String filename = String (USER_ENGINE_FILE_NAME); + if (isf_remove_ise_info_from_file (filename.c_str (), module_name.c_str ())) { + isf_get_factory_list (ALL_ISE, config, _uuids, _names, _module_names, _langs, _icons, _modes, _options); + + /* Update _groups */ + _groups.clear (); + std::vector ise_langs; + for (size_t i = 0; i < _uuids.size (); ++i) { + scim_split_string_list (ise_langs, _langs[i]); + for (size_t j = 0; j < ise_langs.size (); j++) { + if (std::find (_groups[ise_langs[j]].begin (), _groups[ise_langs[j]].end (), i) == _groups[ise_langs[j]].end ()) + _groups[ise_langs[j]].push_back (i); + } + ise_langs.clear (); + } + return true; + } else { + LOGD ("Failed to remove %s from cache file : %s!!!", module_name.c_str (), filename.c_str ()); + return false; + } +} + +bool isf_update_ise_module (const String strModulePath, const ConfigPointer &config) +{ + bool ret = false; + struct stat filestat; + stat (strModulePath.c_str (), &filestat); + if (!S_ISDIR (filestat.st_mode)) { + int begin = strModulePath.find_last_of (SCIM_PATH_DELIM) + 1; + String mod_name = strModulePath.substr (begin, strModulePath.find_last_of ('.') - begin); + String path = strModulePath.substr (0, strModulePath.find_last_of (SCIM_PATH_DELIM)); + LOGD ("module_name = %s, path = %s", mod_name.c_str (), path.c_str ()); + + if (mod_name.length () > 0 && path.length () > 1) { + if (isf_remove_ise_module (mod_name, config)) { + String type = path.substr (path.find_last_of (SCIM_PATH_DELIM) + 1); + LOGD ("type = %s", type.c_str ()); + if (type == String ("Helper")) { + if (add_helper_ise_module (mod_name)) + ret = true; + } else if (type == String ("IMEngine")) { + if (add_keyboard_ise_module (mod_name, config)) + ret = true; + } + } + } else { + LOGD ("%s is not valid so file!!!", strModulePath.c_str ()); + } + } + + /* Update _groups */ + if (ret) { + _groups.clear (); + std::vector ise_langs; + for (size_t i = 0; i < _uuids.size (); ++i) { + scim_split_string_list (ise_langs, _langs[i]); + for (size_t j = 0; j < ise_langs.size (); j++) { + if (std::find (_groups[ise_langs[j]].begin (), _groups[ise_langs[j]].end (), i) == _groups[ise_langs[j]].end ()) + _groups[ise_langs[j]].push_back (i); + } + ise_langs.clear (); + } + } + + return ret; +} + /* vi:ts=4:nowrap:ai:expandtab */ diff --git a/ism/extras/efl_panel/isf_panel_utility.h b/ism/extras/efl_panel/isf_panel_utility.h index ce25c71d..81cb35dc 100644 --- a/ism/extras/efl_panel/isf_panel_utility.h +++ b/ism/extras/efl_panel/isf_panel_utility.h @@ -64,6 +64,7 @@ void isf_get_helper_ises_in_languages (const std::vector &lang_list, std void isf_save_ise_information (void); void isf_load_ise_information (LOAD_ISE_TYPE type, const ConfigPointer &config); bool isf_update_ise_list (LOAD_ISE_TYPE type, const ConfigPointer &config); +bool isf_update_ise_module (const String strModulePath, const ConfigPointer &config); #endif /* __ISF_PANEL_UTILITY_H */ diff --git a/ism/src/isf_query_utility.cpp b/ism/src/isf_query_utility.cpp index dd2ab7e8..afd680ea 100644 --- a/ism/src/isf_query_utility.cpp +++ b/ism/src/isf_query_utility.cpp @@ -302,15 +302,18 @@ EAPI bool isf_add_helper_info_to_file (const char *filename, const char *module_ return isf_write_ise_info_list (filename, info_list); } -EAPI void isf_remove_ise_info_from_file (const char *filename, const char *module_name) +EAPI bool isf_remove_ise_info_from_file (const char *filename, const char *module_name) { std::vector info_list; std::vector::iterator iter; - isf_read_ise_info_list (filename, info_list); - remove_ise_info_from_list (info_list, module_name); + if (isf_read_ise_info_list (filename, info_list)) { - isf_write_ise_info_list (filename, info_list); + remove_ise_info_from_list (info_list, module_name); + + return isf_write_ise_info_list (filename, info_list); + } + return false; } EAPI void isf_update_ise_info_to_file (const char *filename, const ConfigPointer &config) diff --git a/ism/src/isf_query_utility.h b/ism/src/isf_query_utility.h index af65bab8..81cc7711 100644 --- a/ism/src/isf_query_utility.h +++ b/ism/src/isf_query_utility.h @@ -61,7 +61,7 @@ EAPI bool isf_read_ise_info_list (const char *filename, std::vector &in EAPI bool isf_write_ise_info_list (const char *filename, std::vector &info_list); EAPI bool isf_add_keyboard_info_to_file (const char *filename, const char *module_name, const ConfigPointer &config); EAPI bool isf_add_helper_info_to_file (const char *filename, const char *module_name); -EAPI void isf_remove_ise_info_from_file (const char *filename, const char *module_name); +EAPI bool isf_remove_ise_info_from_file (const char *filename, const char *module_name); EAPI void isf_update_ise_info_to_file (const char *filename, const ConfigPointer &config); #endif /* __ISF_QUERY_UTILITY_H */