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