Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: chrome/browser/ui/views/importer_view.cc

Issue 5873005: Views: Implement the ImporterList::Observer in ImporterView to enable the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Line length fix. Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/importer_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 bool ImporterView::IsModal() const { 143 bool ImporterView::IsModal() const {
144 return true; 144 return true;
145 } 145 }
146 146
147 std::wstring ImporterView::GetWindowTitle() const { 147 std::wstring ImporterView::GetWindowTitle() const {
148 return l10n_util::GetString(IDS_IMPORT_SETTINGS_TITLE); 148 return l10n_util::GetString(IDS_IMPORT_SETTINGS_TITLE);
149 } 149 }
150 150
151 bool ImporterView::Accept() { 151 bool ImporterView::Accept() {
152 if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) { 152 if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK))
153 return false; 153 return false;
154 }
155 154
156 uint16 items = GetCheckedItems(); 155 uint16 items = GetCheckedItems();
157 156
158 int selected_index = profile_combobox_->selected_item(); 157 int selected_index = profile_combobox_->selected_item();
159 StartImportingWithUI(GetWidget()->GetNativeView(), items, 158 StartImportingWithUI(GetWidget()->GetNativeView(), items,
160 importer_host_.get(), 159 importer_host_.get(),
161 importer_host_->GetSourceProfileInfoAt(selected_index), 160 importer_host_->GetSourceProfileInfoAt(selected_index),
162 profile_, this, false); 161 profile_, this, false);
163 // We return false here to prevent the window from being closed. We will be 162 // We return false here to prevent the window from being closed. We will be
164 // notified back by our implementation of ImportObserver when the import is 163 // notified back by our implementation of ImportObserver when the import is
165 // complete so that we can close ourselves. 164 // complete so that we can close ourselves.
166 return false; 165 return false;
167 } 166 }
168 167
169 views::View* ImporterView::GetContentsView() { 168 views::View* ImporterView::GetContentsView() {
170 return this; 169 return this;
171 } 170 }
172 171
173 void ImporterView::ButtonPressed( 172 void ImporterView::ButtonPressed(
174 views::Button* sender, const views::Event& event) { 173 views::Button* sender, const views::Event& event) {
175 // When no checkbox is checked we should disable the "Import" button. 174 // When no checkbox is checked we should disable the "Import" button.
176 // This forces the button to evaluate what state they should be in. 175 // This forces the button to evaluate what state they should be in.
177 GetDialogClientView()->UpdateDialogButtons(); 176 GetDialogClientView()->UpdateDialogButtons();
178 } 177 }
179 178
180 int ImporterView::GetItemCount() { 179 int ImporterView::GetItemCount() {
181 DCHECK(importer_host_.get()); 180 DCHECK(importer_host_.get());
182 int item_count = importer_host_->GetAvailableProfileCount(); 181 return checkbox_items_.size();
183 if (checkbox_items_.size() < static_cast<size_t>(item_count))
184 checkbox_items_.resize(item_count, initial_state_);
185 return item_count;
186 } 182 }
187 183
188 string16 ImporterView::GetItemAt(int index) { 184 string16 ImporterView::GetItemAt(int index) {
189 DCHECK(importer_host_.get()); 185 DCHECK(importer_host_.get());
190 return WideToUTF16Hack(importer_host_->GetSourceProfileNameAt(index)); 186
187 if (!importer_host_->source_profiles_loaded())
188 return l10n_util::GetStringUTF16(IDS_IMPORT_LOADING_PROFILES);
189 else
190 return WideToUTF16Hack(importer_host_->GetSourceProfileNameAt(index));
191 } 191 }
192 192
193 void ImporterView::ItemChanged(views::Combobox* combobox, 193 void ImporterView::ItemChanged(views::Combobox* combobox,
194 int prev_index, int new_index) { 194 int prev_index, int new_index) {
195 DCHECK(combobox); 195 DCHECK(combobox);
196 DCHECK(checkbox_items_.size() >= 196 DCHECK(checkbox_items_.size() >=
197 static_cast<size_t>(importer_host_->GetAvailableProfileCount())); 197 static_cast<size_t>(importer_host_->GetAvailableProfileCount()));
198 198
199 if (prev_index == new_index) 199 if (prev_index == new_index)
200 return; 200 return;
201 201
202 if (!importer_host_->source_profiles_loaded()) {
203 SetCheckedItemsState(0);
204 return;
205 }
206
202 // Save the current state 207 // Save the current state
203 uint16 prev_items = GetCheckedItems(); 208 uint16 prev_items = GetCheckedItems();
204 checkbox_items_[prev_index] = prev_items; 209 checkbox_items_[prev_index] = prev_items;
205 210
206 // Enable/Disable the checkboxes for this Item 211 // Enable/Disable the checkboxes for this Item
207 uint16 new_enabled_items = importer_host_->GetSourceProfileInfoAt( 212 uint16 new_enabled_items = importer_host_->GetSourceProfileInfoAt(
208 new_index).services_supported; 213 new_index).services_supported;
209 SetCheckedItemsState(new_enabled_items); 214 SetCheckedItemsState(new_enabled_items);
210 215
211 // Set the checked items for this Item 216 // Set the checked items for this Item
212 uint16 new_items = checkbox_items_[new_index]; 217 uint16 new_items = checkbox_items_[new_index];
213 SetCheckedItems(new_items); 218 SetCheckedItems(new_items);
214 } 219 }
215 220
221 void ImporterView::SourceProfilesLoaded() {
222 DCHECK(importer_host_->source_profiles_loaded());
223 checkbox_items_.resize(
224 importer_host_->GetAvailableProfileCount(), initial_state_);
225
226 // Reload the profile combobox.
227 profile_combobox_->ModelChanged();
228 }
229
216 void ImporterView::ImportCanceled() { 230 void ImporterView::ImportCanceled() {
217 ImportComplete(); 231 ImportComplete();
218 } 232 }
219 233
220 void ImporterView::ImportComplete() { 234 void ImporterView::ImportComplete() {
221 // Now close this window since the import completed or was canceled. 235 // Now close this window since the import completed or was canceled.
222 window()->Close(); 236 window()->Close();
223 } 237 }
224 238
225 views::Checkbox* ImporterView::InitCheckbox(const std::wstring& text, 239 views::Checkbox* ImporterView::InitCheckbox(const std::wstring& text,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 if (history_checkbox_->IsEnabled()) 289 if (history_checkbox_->IsEnabled())
276 history_checkbox_->SetChecked(!!(items & importer::HISTORY)); 290 history_checkbox_->SetChecked(!!(items & importer::HISTORY));
277 291
278 if (favorites_checkbox_->IsEnabled()) 292 if (favorites_checkbox_->IsEnabled())
279 favorites_checkbox_->SetChecked(!!(items & importer::FAVORITES)); 293 favorites_checkbox_->SetChecked(!!(items & importer::FAVORITES));
280 294
281 if (passwords_checkbox_->IsEnabled()) 295 if (passwords_checkbox_->IsEnabled())
282 passwords_checkbox_->SetChecked(!!(items & importer::PASSWORDS)); 296 passwords_checkbox_->SetChecked(!!(items & importer::PASSWORDS));
283 297
284 if (search_engines_checkbox_->IsEnabled()) 298 if (search_engines_checkbox_->IsEnabled())
285 search_engines_checkbox_->SetChecked(!!(items & 299 search_engines_checkbox_->SetChecked(!!(items & importer::SEARCH_ENGINES));
286 importer::SEARCH_ENGINES));
287 } 300 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/importer_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698