| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_MODEL_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_MODEL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 #include <vector> | |
| 12 | |
| 13 #include "base/string16.h" | |
| 14 #include "chrome/browser/language_combobox_model.h" | |
| 15 #include "chrome/browser/prefs/pref_member.h" | |
| 16 #include "chrome/browser/prefs/pref_service.h" | |
| 17 #include "third_party/cros/chromeos_input_method.h" | |
| 18 | |
| 19 class Profile; | |
| 20 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 // The combobox model is used for adding languages in the language config | |
| 24 // view. | |
| 25 class AddLanguageComboboxModel : public ::LanguageComboboxModel { | |
| 26 public: | |
| 27 AddLanguageComboboxModel(Profile* profile, | |
| 28 const std::vector<std::string>& locale_codes); | |
| 29 // LanguageComboboxModel overrides. | |
| 30 virtual int GetItemCount(); | |
| 31 virtual string16 GetItemAt(int index); | |
| 32 | |
| 33 // Converts the given index (index of the items in the combobox) to the | |
| 34 // index of the internal language list. The returned index can be used | |
| 35 // for GetLocaleFromIndex() and GetLanguageNameAt(). | |
| 36 int GetLanguageIndex(int index) const; | |
| 37 | |
| 38 // Marks the given language code to be ignored. Ignored languages won't | |
| 39 // be shown in the combobox. It would be simpler if we could remove and | |
| 40 // add language codes from the model, but ComboboxModel does not allow | |
| 41 // items to be added/removed. Thus we use |ignore_set_| instead. | |
| 42 void SetIgnored(const std::string& language_code, bool ignored); | |
| 43 | |
| 44 private: | |
| 45 std::set<std::string> ignore_set_; | |
| 46 DISALLOW_COPY_AND_ASSIGN(AddLanguageComboboxModel); | |
| 47 }; | |
| 48 | |
| 49 // The model of LanguageConfigView. | |
| 50 class LanguageConfigModel : public NotificationObserver { | |
| 51 public: | |
| 52 explicit LanguageConfigModel(PrefService* pref_service); | |
| 53 | |
| 54 // Counts the number of active input methods for the given language code. | |
| 55 size_t CountNumActiveInputMethods(const std::string& language_code); | |
| 56 | |
| 57 // Returns true if the language code is in the preferred language list. | |
| 58 bool HasLanguageCode(const std::string& language_code) const; | |
| 59 | |
| 60 // Adds the given language to the preferred language list, and returns | |
| 61 // the index of the row where the language is added. | |
| 62 size_t AddLanguageCode(const std::string& language_code); | |
| 63 | |
| 64 // Removes the language at the given row. | |
| 65 void RemoveLanguageAt(size_t row); | |
| 66 | |
| 67 // Updates Chrome's input method preferences. | |
| 68 void UpdateInputMethodPreferences( | |
| 69 const std::vector<std::string>& new_input_method_ids); | |
| 70 | |
| 71 // Deactivates the input methods for the given language code. | |
| 72 void DeactivateInputMethodsFor(const std::string& language_code); | |
| 73 | |
| 74 // Activates or deactivates an IME whose ID is |input_method_id|. | |
| 75 void SetInputMethodActivated(const std::string& input_method_id, | |
| 76 bool activated); | |
| 77 | |
| 78 // Returns true if an IME of |input_method_id| is activated. | |
| 79 bool InputMethodIsActivated(const std::string& input_method_id); | |
| 80 | |
| 81 // Gets the list of active IME IDs like "pinyin" and "m17n:ar:kbd" from | |
| 82 // the underlying preference object. The original contents of | |
| 83 // |out_input_method_ids| are lost. | |
| 84 void GetActiveInputMethodIds( | |
| 85 std::vector<std::string>* out_input_method_ids); | |
| 86 | |
| 87 // Gets the list of preferred language codes like "en-US" and "fr" from | |
| 88 // the underlying preference object. The original contents of | |
| 89 // |out_language_codes| are lost. | |
| 90 void GetPreferredLanguageCodes( | |
| 91 std::vector<std::string>* out_language_codes); | |
| 92 | |
| 93 // Gets the list of input method ids associated with the given language | |
| 94 // code. The original contents of |input_method_ids| will be lost. | |
| 95 void GetInputMethodIdsFromLanguageCode( | |
| 96 const std::string& language_code, | |
| 97 std::vector<std::string>* input_method_ids) const; | |
| 98 | |
| 99 // Callback for |preferred_language_codes_| pref updates. Initializes | |
| 100 // the preferred language codes based on the updated pref value. | |
| 101 void NotifyPrefChanged(); | |
| 102 | |
| 103 // NotificationObserver overrides. | |
| 104 virtual void Observe(NotificationType type, | |
| 105 const NotificationSource& source, | |
| 106 const NotificationDetails& details); | |
| 107 | |
| 108 const std::string& preferred_language_code_at(size_t at) const { | |
| 109 return preferred_language_codes_[at]; | |
| 110 } | |
| 111 | |
| 112 size_t num_preferred_language_codes() const { | |
| 113 return preferred_language_codes_.size(); | |
| 114 } | |
| 115 | |
| 116 const std::string& supported_input_method_id_at(size_t at) const { | |
| 117 return supported_input_method_ids_[at]; | |
| 118 } | |
| 119 | |
| 120 size_t num_supported_input_method_ids() const { | |
| 121 return supported_input_method_ids_.size(); | |
| 122 } | |
| 123 | |
| 124 const std::vector<std::string>& supported_language_codes() const { | |
| 125 return supported_language_codes_; | |
| 126 } | |
| 127 | |
| 128 private: | |
| 129 // Initializes id_to_{code,display_name}_map_ maps, | |
| 130 // as well as supported_{language_codes,input_method_ids}_ vectors. | |
| 131 void InitInputMethodIdVectors(); | |
| 132 | |
| 133 PrefService* pref_service_; | |
| 134 // The codes of the preferred languages. | |
| 135 std::vector<std::string> preferred_language_codes_; | |
| 136 StringPrefMember preferred_languages_pref_; | |
| 137 StringPrefMember preload_engines_pref_; | |
| 138 // List of supported language codes like "en" and "ja". | |
| 139 std::vector<std::string> supported_language_codes_; | |
| 140 // List of supported IME IDs like "pinyin" and "m17n:ar:kbd". | |
| 141 std::vector<std::string> supported_input_method_ids_; | |
| 142 | |
| 143 DISALLOW_COPY_AND_ASSIGN(LanguageConfigModel); | |
| 144 }; | |
| 145 | |
| 146 } // namespace chromeos | |
| 147 | |
| 148 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_LANGUAGE_CONFIG_MODEL_H_ | |
| OLD | NEW |