From 7295b0638e4a80e3e167533b633e98bd9a2769b0 Mon Sep 17 00:00:00 2001 From: "yanjie.hu" Date: Tue, 26 Mar 2013 12:26:32 +0800 Subject: [PATCH] set default english when config empty Change-Id: I5b7308b30677b3761d4d34dbdb94236bde1a6d5c --- src/include/languages.h | 8 ++++++- src/ise.cpp | 6 ++++-- src/languages.cpp | 55 ++++++++++++++++++++++++++++++++++--------------- src/option.cpp | 4 ++-- src/setup_module.cpp | 3 ++- 5 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/include/languages.h b/src/include/languages.h index 3ff1886..ff46dac 100644 --- a/src/include/languages.h +++ b/src/include/languages.h @@ -99,7 +99,8 @@ public: static sclboolean set_language_enabled(const sclchar *name, sclboolean enabled); static sclboolean set_language_enabled_temporarily(const sclchar *name, sclboolean enabled_temporarily); - static sclboolean set_enabled_languages(const std::vector &languages, sclboolean enabled); + /* if languages num is 0, enable default language, othewise enable languages assigned */ + static sclboolean set_enabled_languages(const std::vector &languages); static sclboolean set_all_languages_enabled(sclboolean enabled); static const sclchar* get_current_language(); @@ -109,6 +110,11 @@ public: static LANGUAGE_INFO* get_language_info(int index); static const sclchar* get_resource_file_path(); +private: + /* enable languages, if languages num is 0, return false */ + static sclboolean enable_languages(const std::vector &languages); + /* enable default language, regards the 1st language in the language_vector is the default language*/ + static sclboolean enable_default_language(); protected: static std::vector language_vector; diff --git a/src/ise.cpp b/src/ise.cpp index 71da82a..82fe08f 100644 --- a/src/ise.cpp +++ b/src/ise.cpp @@ -249,7 +249,8 @@ void ise_show(int ic) if (gSCLUI && g_ise_common) { read_ise_config_values(); - ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages, TRUE); + + ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages); /* Reset input mode if the input context value has changed */ if (ic != g_keyboard_state.ic) { @@ -386,7 +387,8 @@ ise_create() } read_ise_config_values(); - ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages, TRUE); + ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages); + ISELanguageManager::select_language(g_config_values.selected_language.c_str()); } diff --git a/src/languages.cpp b/src/languages.cpp index 0fd1ea3..3da2eb9 100644 --- a/src/languages.cpp +++ b/src/languages.cpp @@ -28,6 +28,20 @@ std::string ISELanguageManager::current_language; std::string ISELanguageManager::temporary_language; std::string ISELanguageManager::default_resource_file; +sclboolean +ISELanguageManager::set_all_languages_enabled(sclboolean enabled) +{ + sclboolean ret = TRUE; + + std::vector::iterator iter; + for (iter = language_vector.begin(); iter != language_vector.end(); ++iter) { + iter->enabled = enabled; + iter->enabled_temporarily = FALSE; + } + + return ret; +} + /* Each language-specific source files should put their callback information in the following vectors */ sclboolean ISELanguageManager::add_language(LANGUAGE_INFO language) { @@ -330,35 +344,42 @@ sclboolean ISELanguageManager::set_language_enabled_temporarily(const sclchar *n return ret; } -sclboolean ISELanguageManager::set_enabled_languages(const std::vector &languages, sclboolean enabled) +sclboolean ISELanguageManager::enable_languages(const std::vector &vec_language_id) { sclboolean ret = FALSE; - if (languages.size() == 0) { - /* If there is NO language currently enabled, just enable ALL of them */ - set_all_languages_enabled(TRUE); - } else { - /* Otherwise, disable all languages and enable only those described in the config file */ - set_all_languages_enabled(FALSE); + if (vec_language_id.size() != 0) { + ret = set_all_languages_enabled(FALSE); + + if (ret == FALSE) return ret; std::vector::const_iterator citer; - for (citer = languages.begin(); - citer != languages.end(); citer++) { - set_language_enabled(citer->c_str(), enabled); + for (citer = vec_language_id.begin(); citer != vec_language_id.end(); ++citer) { + ret = set_language_enabled(citer->c_str(), TRUE); + if (ret == FALSE) return FALSE; } } return ret; } -sclboolean ISELanguageManager::set_all_languages_enabled(sclboolean enabled) -{ - sclboolean ret = TRUE; +/* FIXME A temporaty way for enable default language */ +sclboolean ISELanguageManager::enable_default_language() { + if (language_vector.size()) { + LANGUAGE_INFO &default_language = language_vector.at(0); + default_language.enabled = TRUE; + default_language.enabled_temporarily = FALSE; + return TRUE; + } - for (std::vector::iterator iter = language_vector.begin(); - iter != language_vector.end();std::advance(iter, 1)) { - iter->enabled = enabled; - iter->enabled_temporarily = FALSE; + return FALSE; +} + +sclboolean ISELanguageManager::set_enabled_languages(const std::vector &vec_language_id) { + sclboolean ret = FALSE; + + if (vec_language_id.size() == 0 || FALSE == enable_languages(vec_language_id)) { + ret = enable_default_language(); } return ret; diff --git a/src/option.cpp b/src/option.cpp index 9b20caf..c7ca5fa 100644 --- a/src/option.cpp +++ b/src/option.cpp @@ -506,7 +506,7 @@ language_selection_finished_cb(void *data, Evas_Object *obj, void *event_info) { if (ISELanguageManager::get_enabled_languages_num() == 0) { read_ise_config_values(); - ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages, TRUE); + ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages); } std::string languages = compose_selected_languages_string(); strncpy(main_itemdata[SETTING_ITEM_ID_LANGUAGE].sub_text, languages.c_str(), ITEM_DATA_STRING_LEN - 1); @@ -740,7 +740,7 @@ open_option_window(Evas_Object *parent, sclint degree) read_ise_config_values(); /* To make sure there is no temporary language in the enabled language list */ - ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages, TRUE); + ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages); set_option_values(); diff --git a/src/setup_module.cpp b/src/setup_module.cpp index f7a8b2d..51bbe41 100644 --- a/src/setup_module.cpp +++ b/src/setup_module.cpp @@ -112,7 +112,8 @@ static void load_config (const ConfigPointer &config) read_ise_config_values(); - ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages, TRUE); + ISELanguageManager::set_enabled_languages(g_config_values.enabled_languages); + ISELanguageManager::select_language(g_config_values.selected_language.c_str()); } } -- 2.7.4