OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_LANGUAGE_COMBOBOX_MODEL_H_ | 5 #ifndef CHROME_BROWSER_LANGUAGE_COMBOBOX_MODEL_H_ |
6 #define CHROME_BROWSER_LANGUAGE_COMBOBOX_MODEL_H_ | 6 #define CHROME_BROWSER_LANGUAGE_COMBOBOX_MODEL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "app/combobox_model.h" | 13 #include "app/combobox_model.h" |
14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
15 #include "base/string16.h" | 15 #include "base/string16.h" |
16 | 16 |
17 class Profile; | 17 class Profile; |
18 | 18 |
19 /////////////////////////////////////////////////////////////////////////////// | 19 /////////////////////////////////////////////////////////////////////////////// |
20 // LanguageList | 20 // LanguageList |
21 // Provides code to enumerate locale names for language selection lists. | 21 // Provides code to enumerate locale names for language selection lists. |
22 // To be used by combobox, menu or other models. | 22 // To be used by combobox, menu or other models. |
23 class LanguageList { | 23 class LanguageList { |
24 public: | 24 public: |
25 struct LocaleData { | 25 struct LocaleData { |
26 LocaleData() { } | 26 LocaleData() { } |
27 LocaleData(const std::wstring& name, const std::string& code) | 27 LocaleData(const string16& name, const std::string& code) |
28 : native_name(name), locale_code(code) { } | 28 : native_name(name), locale_code(code) { } |
29 | 29 |
30 std::wstring native_name; | 30 string16 native_name; |
31 std::string locale_code; // E.g., en-us. | 31 std::string locale_code; // E.g., en-us. |
32 }; | 32 }; |
33 typedef std::map<std::wstring, LocaleData> LocaleDataMap; | 33 typedef std::map<string16, LocaleData> LocaleDataMap; |
34 | 34 |
35 LanguageList(); | 35 LanguageList(); |
36 | 36 |
37 explicit LanguageList(const std::vector<std::string>& locale_codes); | 37 explicit LanguageList(const std::vector<std::string>& locale_codes); |
38 | 38 |
39 virtual ~LanguageList(); | 39 virtual ~LanguageList(); |
40 | 40 |
41 // Duplicates specified languages at the beginning of the list for | 41 // Duplicates specified languages at the beginning of the list for |
42 // easier access. | 42 // easier access. |
43 void CopySpecifiedLanguagesUp(const std::string& locale_codes); | 43 void CopySpecifiedLanguagesUp(const std::string& locale_codes); |
44 | 44 |
45 int get_languages_count() const; | 45 int get_languages_count() const; |
46 | 46 |
47 std::wstring GetLanguageNameAt(int index) const; | 47 string16 GetLanguageNameAt(int index) const; |
48 | 48 |
49 // Return the locale for the given index. E.g., may return pt-BR. | 49 // Return the locale for the given index. E.g., may return pt-BR. |
50 std::string GetLocaleFromIndex(int index) const; | 50 std::string GetLocaleFromIndex(int index) const; |
51 | 51 |
52 // Returns the index for the given locale. Returns -1 if the locale is not | 52 // Returns the index for the given locale. Returns -1 if the locale is not |
53 // in the combobox model. | 53 // in the combobox model. |
54 int GetIndexFromLocale(const std::string& locale) const; | 54 int GetIndexFromLocale(const std::string& locale) const; |
55 | 55 |
56 private: | 56 private: |
57 // The names of all the locales in the current application locale. | 57 // The names of all the locales in the current application locale. |
58 std::vector<std::wstring> locale_names_; | 58 std::vector<string16> locale_names_; |
59 | 59 |
60 // A map of some extra data (LocaleData) keyed off the name of the locale. | 60 // A map of some extra data (LocaleData) keyed off the name of the locale. |
61 LocaleDataMap native_names_; | 61 LocaleDataMap native_names_; |
62 | 62 |
63 void InitNativeNames(const std::vector<std::string>& locale_codes); | 63 void InitNativeNames(const std::vector<std::string>& locale_codes); |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(LanguageList); | 65 DISALLOW_COPY_AND_ASSIGN(LanguageList); |
66 }; | 66 }; |
67 | 67 |
68 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 22 matching lines...) Expand all Loading... |
91 int GetSelectedLanguageIndex(const std::string& prefs); | 91 int GetSelectedLanguageIndex(const std::string& prefs); |
92 | 92 |
93 private: | 93 private: |
94 // Profile. | 94 // Profile. |
95 Profile* profile_; | 95 Profile* profile_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(LanguageComboboxModel); | 97 DISALLOW_COPY_AND_ASSIGN(LanguageComboboxModel); |
98 }; | 98 }; |
99 | 99 |
100 #endif // CHROME_BROWSER_LANGUAGE_COMBOBOX_MODEL_H_ | 100 #endif // CHROME_BROWSER_LANGUAGE_COMBOBOX_MODEL_H_ |
OLD | NEW |