| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/views/options/general_page_view.h" | 5 #include "chrome/browser/views/options/general_page_view.h" |
| 6 | 6 |
| 7 #include "app/combobox_model.h" | 7 #include "app/combobox_model.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/string16.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/custom_home_pages_table_model.h" | 14 #include "chrome/browser/custom_home_pages_table_model.h" |
| 14 #include "chrome/browser/dom_ui/new_tab_ui.h" | 15 #include "chrome/browser/dom_ui/new_tab_ui.h" |
| 15 #include "chrome/browser/net/url_fixer_upper.h" | 16 #include "chrome/browser/net/url_fixer_upper.h" |
| 16 #include "chrome/browser/pref_service.h" | 17 #include "chrome/browser/pref_service.h" |
| 17 #include "chrome/browser/profile.h" | 18 #include "chrome/browser/profile.h" |
| 18 #include "chrome/browser/session_startup_pref.h" | 19 #include "chrome/browser/session_startup_pref.h" |
| 19 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
| 20 #include "chrome/browser/search_engines/template_url_model.h" | 21 #include "chrome/browser/search_engines/template_url_model.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 public: | 58 public: |
| 58 explicit SearchEngineListModel(Profile* profile); | 59 explicit SearchEngineListModel(Profile* profile); |
| 59 virtual ~SearchEngineListModel(); | 60 virtual ~SearchEngineListModel(); |
| 60 | 61 |
| 61 // Sets the Combobox. SearchEngineListModel needs a handle to the Combobox | 62 // Sets the Combobox. SearchEngineListModel needs a handle to the Combobox |
| 62 // so that when the TemplateURLModel changes the combobox can be updated. | 63 // so that when the TemplateURLModel changes the combobox can be updated. |
| 63 void SetCombobox(views::Combobox* combobox); | 64 void SetCombobox(views::Combobox* combobox); |
| 64 | 65 |
| 65 // ComboboxModel overrides: | 66 // ComboboxModel overrides: |
| 66 virtual int GetItemCount(); | 67 virtual int GetItemCount(); |
| 67 virtual std::wstring GetItemAt(int index); | 68 virtual string16 GetItemAt(int index); |
| 68 | 69 |
| 69 // Returns the TemplateURL at the specified index. | 70 // Returns the TemplateURL at the specified index. |
| 70 const TemplateURL* GetTemplateURLAt(int index); | 71 const TemplateURL* GetTemplateURLAt(int index); |
| 71 | 72 |
| 72 TemplateURLModel* model() { return template_url_model_; } | 73 TemplateURLModel* model() { return template_url_model_; } |
| 73 | 74 |
| 74 private: | 75 private: |
| 75 // TemplateURLModelObserver methods. | 76 // TemplateURLModelObserver methods. |
| 76 virtual void OnTemplateURLModelChanged(); | 77 virtual void OnTemplateURLModelChanged(); |
| 77 | 78 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 if (template_url_model_ && template_url_model_->loaded()) | 115 if (template_url_model_ && template_url_model_->loaded()) |
| 115 ChangeComboboxSelection(); | 116 ChangeComboboxSelection(); |
| 116 else | 117 else |
| 117 combobox_->SetEnabled(false); | 118 combobox_->SetEnabled(false); |
| 118 } | 119 } |
| 119 | 120 |
| 120 int SearchEngineListModel::GetItemCount() { | 121 int SearchEngineListModel::GetItemCount() { |
| 121 return static_cast<int>(template_urls_.size()); | 122 return static_cast<int>(template_urls_.size()); |
| 122 } | 123 } |
| 123 | 124 |
| 124 std::wstring SearchEngineListModel::GetItemAt(int index) { | 125 string16 SearchEngineListModel::GetItemAt(int index) { |
| 125 DCHECK(index < GetItemCount()); | 126 DCHECK(index < GetItemCount()); |
| 126 return template_urls_[index]->short_name(); | 127 return WideToUTF16Hack(template_urls_[index]->short_name()); |
| 127 } | 128 } |
| 128 | 129 |
| 129 const TemplateURL* SearchEngineListModel::GetTemplateURLAt(int index) { | 130 const TemplateURL* SearchEngineListModel::GetTemplateURLAt(int index) { |
| 130 DCHECK(index >= 0 && index < static_cast<int>(template_urls_.size())); | 131 DCHECK(index >= 0 && index < static_cast<int>(template_urls_.size())); |
| 131 return template_urls_[static_cast<int>(index)]; | 132 return template_urls_[static_cast<int>(index)]; |
| 132 } | 133 } |
| 133 | 134 |
| 134 void SearchEngineListModel::OnTemplateURLModelChanged() { | 135 void SearchEngineListModel::OnTemplateURLModelChanged() { |
| 135 ResetContents(); | 136 ResetContents(); |
| 136 } | 137 } |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 } | 797 } |
| 797 homepage_use_url_textfield_->SetEnabled(enabled); | 798 homepage_use_url_textfield_->SetEnabled(enabled); |
| 798 homepage_use_url_textfield_->SetReadOnly(!enabled); | 799 homepage_use_url_textfield_->SetReadOnly(!enabled); |
| 799 } | 800 } |
| 800 | 801 |
| 801 void GeneralPageView::SetDefaultSearchProvider() { | 802 void GeneralPageView::SetDefaultSearchProvider() { |
| 802 const int index = default_search_engine_combobox_->selected_item(); | 803 const int index = default_search_engine_combobox_->selected_item(); |
| 803 default_search_engines_model_->model()->SetDefaultSearchProvider( | 804 default_search_engines_model_->model()->SetDefaultSearchProvider( |
| 804 default_search_engines_model_->GetTemplateURLAt(index)); | 805 default_search_engines_model_->GetTemplateURLAt(index)); |
| 805 } | 806 } |
| OLD | NEW |