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/importer_view.h" | 5 #include "chrome/browser/views/importer_view.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/string16.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
12 #include "chrome/browser/importer/importer_data_types.h" | 12 #include "chrome/browser/importer/importer_data_types.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "grit/locale_settings.h" | 14 #include "grit/locale_settings.h" |
15 #include "views/controls/button/checkbox.h" | 15 #include "views/controls/button/checkbox.h" |
16 #include "views/controls/label.h" | 16 #include "views/controls/label.h" |
17 #include "views/grid_layout.h" | 17 #include "views/grid_layout.h" |
18 #include "views/standard_layout.h" | 18 #include "views/standard_layout.h" |
(...skipping 16 matching lines...) Expand all Loading... | |
35 | 35 |
36 ImporterView::ImporterView(Profile* profile, int initial_state) | 36 ImporterView::ImporterView(Profile* profile, int initial_state) |
37 : import_from_label_(NULL), | 37 : import_from_label_(NULL), |
38 profile_combobox_(NULL), | 38 profile_combobox_(NULL), |
39 import_items_label_(NULL), | 39 import_items_label_(NULL), |
40 history_checkbox_(NULL), | 40 history_checkbox_(NULL), |
41 favorites_checkbox_(NULL), | 41 favorites_checkbox_(NULL), |
42 passwords_checkbox_(NULL), | 42 passwords_checkbox_(NULL), |
43 search_engines_checkbox_(NULL), | 43 search_engines_checkbox_(NULL), |
44 profile_(profile), | 44 profile_(profile), |
45 importer_host_(new ImporterHost()), | 45 ALLOW_THIS_IN_INITIALIZER_LIST(importer_host_(new ImporterHost(this))), |
46 initial_state_(initial_state) { | 46 initial_state_(initial_state) { |
47 DCHECK(profile); | 47 DCHECK(profile); |
48 SetupControl(); | 48 SetupControl(); |
49 } | 49 } |
50 | 50 |
51 ImporterView::~ImporterView() { | 51 ImporterView::~ImporterView() { |
52 } | 52 } |
53 | 53 |
54 void ImporterView::SetupControl() { | 54 void ImporterView::SetupControl() { |
55 // Adds all controls. | 55 // Adds all controls. |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 172 |
173 void ImporterView::ButtonPressed( | 173 void ImporterView::ButtonPressed( |
174 views::Button* sender, const views::Event& event) { | 174 views::Button* sender, const views::Event& event) { |
175 // When no checkbox is checked we should disable the "Import" button. | 175 // When no checkbox is checked we should disable the "Import" button. |
176 // This forces the button to evaluate what state they should be in. | 176 // This forces the button to evaluate what state they should be in. |
177 GetDialogClientView()->UpdateDialogButtons(); | 177 GetDialogClientView()->UpdateDialogButtons(); |
178 } | 178 } |
179 | 179 |
180 int ImporterView::GetItemCount() { | 180 int ImporterView::GetItemCount() { |
181 DCHECK(importer_host_.get()); | 181 DCHECK(importer_host_.get()); |
182 int item_count = importer_host_->GetAvailableProfileCount(); | 182 |
183 if (checkbox_items_.size() < static_cast<size_t>(item_count)) | 183 int item_count; |
sky
2010/12/16 23:07:22
This code should live in SourceProfilesLoaded, and
James Hawkins
2010/12/16 23:32:13
Done.
| |
184 checkbox_items_.resize(item_count, initial_state_); | 184 if (!importer_host_->source_profiles_loaded()) { |
185 item_count = 1; | |
186 } else { | |
187 item_count = importer_host_->GetAvailableProfileCount(); | |
188 | |
189 if (checkbox_items_.size() < static_cast<size_t>(item_count)) | |
190 checkbox_items_.resize(item_count, initial_state_); | |
191 } | |
192 | |
185 return item_count; | 193 return item_count; |
186 } | 194 } |
187 | 195 |
188 string16 ImporterView::GetItemAt(int index) { | 196 string16 ImporterView::GetItemAt(int index) { |
189 DCHECK(importer_host_.get()); | 197 DCHECK(importer_host_.get()); |
190 return WideToUTF16Hack(importer_host_->GetSourceProfileNameAt(index)); | 198 |
199 if (!importer_host_->source_profiles_loaded()) | |
200 return l10n_util::GetStringUTF16(IDS_IMPORT_LOADING_PROFILES); | |
201 else | |
202 return WideToUTF16Hack(importer_host_->GetSourceProfileNameAt(index)); | |
191 } | 203 } |
192 | 204 |
193 void ImporterView::ItemChanged(views::Combobox* combobox, | 205 void ImporterView::ItemChanged(views::Combobox* combobox, |
194 int prev_index, int new_index) { | 206 int prev_index, int new_index) { |
195 DCHECK(combobox); | 207 DCHECK(combobox); |
196 DCHECK(checkbox_items_.size() >= | 208 DCHECK(checkbox_items_.size() >= |
197 static_cast<size_t>(importer_host_->GetAvailableProfileCount())); | 209 static_cast<size_t>(importer_host_->GetAvailableProfileCount())); |
198 | 210 |
199 if (prev_index == new_index) | 211 if (prev_index == new_index) |
200 return; | 212 return; |
201 | 213 |
202 // Save the current state | 214 // Save the current state |
203 uint16 prev_items = GetCheckedItems(); | 215 uint16 prev_items = GetCheckedItems(); |
204 checkbox_items_[prev_index] = prev_items; | 216 checkbox_items_[prev_index] = prev_items; |
205 | 217 |
206 // Enable/Disable the checkboxes for this Item | 218 // Enable/Disable the checkboxes for this Item |
207 uint16 new_enabled_items = importer_host_->GetSourceProfileInfoAt( | 219 uint16 new_enabled_items = importer_host_->GetSourceProfileInfoAt( |
208 new_index).services_supported; | 220 new_index).services_supported; |
209 SetCheckedItemsState(new_enabled_items); | 221 SetCheckedItemsState(new_enabled_items); |
210 | 222 |
211 // Set the checked items for this Item | 223 // Set the checked items for this Item |
212 uint16 new_items = checkbox_items_[new_index]; | 224 uint16 new_items = checkbox_items_[new_index]; |
213 SetCheckedItems(new_items); | 225 SetCheckedItems(new_items); |
214 } | 226 } |
215 | 227 |
228 void ImporterView::SourceProfilesLoaded() { | |
229 // Reload the profile combobox. | |
230 profile_combobox_->ModelChanged(); | |
231 } | |
232 | |
216 void ImporterView::ImportCanceled() { | 233 void ImporterView::ImportCanceled() { |
217 ImportComplete(); | 234 ImportComplete(); |
218 } | 235 } |
219 | 236 |
220 void ImporterView::ImportComplete() { | 237 void ImporterView::ImportComplete() { |
221 // Now close this window since the import completed or was canceled. | 238 // Now close this window since the import completed or was canceled. |
222 window()->Close(); | 239 window()->Close(); |
223 } | 240 } |
224 | 241 |
225 views::Checkbox* ImporterView::InitCheckbox(const std::wstring& text, | 242 views::Checkbox* ImporterView::InitCheckbox(const std::wstring& text, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 if (favorites_checkbox_->IsEnabled()) | 295 if (favorites_checkbox_->IsEnabled()) |
279 favorites_checkbox_->SetChecked(!!(items & importer::FAVORITES)); | 296 favorites_checkbox_->SetChecked(!!(items & importer::FAVORITES)); |
280 | 297 |
281 if (passwords_checkbox_->IsEnabled()) | 298 if (passwords_checkbox_->IsEnabled()) |
282 passwords_checkbox_->SetChecked(!!(items & importer::PASSWORDS)); | 299 passwords_checkbox_->SetChecked(!!(items & importer::PASSWORDS)); |
283 | 300 |
284 if (search_engines_checkbox_->IsEnabled()) | 301 if (search_engines_checkbox_->IsEnabled()) |
285 search_engines_checkbox_->SetChecked(!!(items & | 302 search_engines_checkbox_->SetChecked(!!(items & |
286 importer::SEARCH_ENGINES)); | 303 importer::SEARCH_ENGINES)); |
287 } | 304 } |
OLD | NEW |