OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/importing_progress_view.h" | 5 #include "chrome/browser/views/importing_progress_view.h" |
6 | 6 |
7 #include "chrome/app/locales/locale_settings.h" | 7 #include "chrome/app/locales/locale_settings.h" |
8 #include "chrome/browser/views/standard_layout.h" | 8 #include "chrome/browser/views/standard_layout.h" |
9 #include "chrome/common/l10n_util.h" | 9 #include "chrome/common/l10n_util.h" |
10 #include "chrome/views/grid_layout.h" | 10 #include "chrome/views/grid_layout.h" |
11 #include "chrome/views/label.h" | 11 #include "chrome/views/label.h" |
12 #include "chrome/views/throbber.h" | 12 #include "chrome/views/throbber.h" |
13 #include "chrome/views/window.h" | 13 #include "chrome/views/window.h" |
14 | 14 |
15 #include "chromium_strings.h" | 15 #include "chromium_strings.h" |
16 #include "generated_resources.h" | 16 #include "generated_resources.h" |
17 | 17 |
18 //////////////////////////////////////////////////////////////////////////////// | 18 //////////////////////////////////////////////////////////////////////////////// |
19 // ImportingProgressView, public: | 19 // ImportingProgressView, public: |
20 | 20 |
21 ImportingProgressView::ImportingProgressView(const std::wstring& source_name, | 21 ImportingProgressView::ImportingProgressView(const std::wstring& source_name, |
22 int16 items, | 22 int16 items, |
23 ImporterHost* coordinator, | 23 ImporterHost* coordinator, |
24 ImportObserver* observer, | 24 ImportObserver* observer, |
25 HWND parent_window) | 25 HWND parent_window, |
| 26 bool bookmarks_import) |
26 : state_bookmarks_(new views::CheckmarkThrobber), | 27 : state_bookmarks_(new views::CheckmarkThrobber), |
27 state_searches_(new views::CheckmarkThrobber), | 28 state_searches_(new views::CheckmarkThrobber), |
28 state_passwords_(new views::CheckmarkThrobber), | 29 state_passwords_(new views::CheckmarkThrobber), |
29 state_history_(new views::CheckmarkThrobber), | 30 state_history_(new views::CheckmarkThrobber), |
30 state_cookies_(new views::CheckmarkThrobber), | 31 state_cookies_(new views::CheckmarkThrobber), |
31 label_info_(new views::Label(l10n_util::GetStringF( | |
32 IDS_IMPORT_PROGRESS_INFO, source_name))), | |
33 label_bookmarks_(new views::Label( | 32 label_bookmarks_(new views::Label( |
34 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS))), | 33 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_BOOKMARKS))), |
35 label_searches_(new views::Label( | 34 label_searches_(new views::Label( |
36 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_SEARCH))), | 35 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_SEARCH))), |
37 label_passwords_(new views::Label( | 36 label_passwords_(new views::Label( |
38 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_PASSWORDS))), | 37 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_PASSWORDS))), |
39 label_history_(new views::Label( | 38 label_history_(new views::Label( |
40 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_HISTORY))), | 39 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_HISTORY))), |
41 label_cookies_(new views::Label( | 40 label_cookies_(new views::Label( |
42 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_COOKIES))), | 41 l10n_util::GetString(IDS_IMPORT_PROGRESS_STATUS_COOKIES))), |
43 parent_window_(parent_window), | 42 parent_window_(parent_window), |
44 coordinator_(coordinator), | 43 coordinator_(coordinator), |
45 import_observer_(observer), | 44 import_observer_(observer), |
46 items_(items), | 45 items_(items), |
47 importing_(true) { | 46 importing_(true), |
| 47 bookmarks_import_(bookmarks_import) { |
| 48 std::wstring info_text = bookmarks_import ? |
| 49 l10n_util::GetString(IDS_IMPORT_BOOKMARKS) : |
| 50 l10n_util::GetStringF(IDS_IMPORT_PROGRESS_INFO, source_name); |
| 51 label_info_ = new views::Label(info_text); |
48 coordinator_->SetObserver(this); | 52 coordinator_->SetObserver(this); |
49 label_info_->SetMultiLine(true); | 53 label_info_->SetMultiLine(true); |
50 label_info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 54 label_info_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
51 label_bookmarks_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 55 label_bookmarks_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
52 label_searches_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 56 label_searches_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
53 label_passwords_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 57 label_passwords_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
54 label_history_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 58 label_history_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
55 label_cookies_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 59 label_cookies_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
56 | 60 |
57 // These are scoped pointers, so we don't need the parent to delete them. | 61 // These are scoped pointers, so we don't need the parent to delete them. |
(...skipping 13 matching lines...) Expand all Loading... |
71 RemoveChildView(state_bookmarks_.get()); | 75 RemoveChildView(state_bookmarks_.get()); |
72 RemoveChildView(state_searches_.get()); | 76 RemoveChildView(state_searches_.get()); |
73 RemoveChildView(state_passwords_.get()); | 77 RemoveChildView(state_passwords_.get()); |
74 RemoveChildView(state_history_.get()); | 78 RemoveChildView(state_history_.get()); |
75 RemoveChildView(state_cookies_.get()); | 79 RemoveChildView(state_cookies_.get()); |
76 RemoveChildView(label_bookmarks_.get()); | 80 RemoveChildView(label_bookmarks_.get()); |
77 RemoveChildView(label_searches_.get()); | 81 RemoveChildView(label_searches_.get()); |
78 RemoveChildView(label_passwords_.get()); | 82 RemoveChildView(label_passwords_.get()); |
79 RemoveChildView(label_history_.get()); | 83 RemoveChildView(label_history_.get()); |
80 RemoveChildView(label_cookies_.get()); | 84 RemoveChildView(label_cookies_.get()); |
| 85 |
| 86 if (importing_) { |
| 87 // We're being deleted while importing, clean up state so that the importer |
| 88 // doesn't have a reference to us and cancel the import. We can get here |
| 89 // if our parent window is closed, which closes our window and deletes us. |
| 90 importing_ = false; |
| 91 coordinator_->SetObserver(NULL); |
| 92 coordinator_->Cancel(); |
| 93 if (import_observer_) |
| 94 import_observer_->ImportComplete(); |
| 95 } |
81 } | 96 } |
82 | 97 |
83 //////////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////////// |
84 // ImportingProgressView, ImporterObserver implementation: | 99 // ImportingProgressView, ImporterObserver implementation: |
85 | 100 |
86 void ImportingProgressView::ImportItemStarted(ImportItem item) { | 101 void ImportingProgressView::ImportItemStarted(ImportItem item) { |
87 DCHECK(items_ & item); | 102 DCHECK(items_ & item); |
88 switch (item) { | 103 switch (item) { |
89 case FAVORITES: | 104 case FAVORITES: |
90 state_bookmarks_->Start(); | 105 state_bookmarks_->Start(); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 using views::GridLayout; | 225 using views::GridLayout; |
211 using views::ColumnSet; | 226 using views::ColumnSet; |
212 | 227 |
213 GridLayout* layout = CreatePanelGridLayout(this); | 228 GridLayout* layout = CreatePanelGridLayout(this); |
214 SetLayoutManager(layout); | 229 SetLayoutManager(layout); |
215 | 230 |
216 gfx::Size ps = state_history_->GetPreferredSize(); | 231 gfx::Size ps = state_history_->GetPreferredSize(); |
217 | 232 |
218 const int single_column_view_set_id = 0; | 233 const int single_column_view_set_id = 0; |
219 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); | 234 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); |
| 235 if (bookmarks_import_) { |
| 236 column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| 237 GridLayout::FIXED, ps.width(), 0); |
| 238 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
| 239 } |
220 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 240 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
221 GridLayout::USE_PREF, 0, 0); | 241 GridLayout::USE_PREF, 0, 0); |
222 const int double_column_view_set_id = 1; | 242 const int double_column_view_set_id = 1; |
223 column_set = layout->AddColumnSet(double_column_view_set_id); | 243 column_set = layout->AddColumnSet(double_column_view_set_id); |
224 column_set->AddPaddingColumn(0, kUnrelatedControlLargeHorizontalSpacing); | 244 column_set->AddPaddingColumn(0, kUnrelatedControlLargeHorizontalSpacing); |
225 column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 245 column_set->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
226 GridLayout::FIXED, ps.width(), 0); | 246 GridLayout::FIXED, ps.width(), 0); |
227 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); | 247 column_set->AddPaddingColumn(0, kRelatedControlHorizontalSpacing); |
228 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, | 248 column_set->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 1, |
229 GridLayout::USE_PREF, 0, 0); | 249 GridLayout::USE_PREF, 0, 0); |
230 column_set->AddPaddingColumn(0, kUnrelatedControlLargeHorizontalSpacing); | 250 column_set->AddPaddingColumn(0, kUnrelatedControlLargeHorizontalSpacing); |
231 | 251 |
232 layout->StartRow(0, single_column_view_set_id); | 252 layout->StartRow(0, single_column_view_set_id); |
| 253 if (bookmarks_import_) |
| 254 layout->AddView(state_bookmarks_.get()); |
233 layout->AddView(label_info_); | 255 layout->AddView(label_info_); |
234 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); | 256 layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing); |
235 | 257 |
236 if (items_ & FAVORITES) { | 258 if (items_ & FAVORITES && !bookmarks_import_) { |
237 layout->StartRow(0, double_column_view_set_id); | 259 layout->StartRow(0, double_column_view_set_id); |
238 layout->AddView(state_bookmarks_.get()); | 260 layout->AddView(state_bookmarks_.get()); |
239 layout->AddView(label_bookmarks_.get()); | 261 layout->AddView(label_bookmarks_.get()); |
240 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 262 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
241 } | 263 } |
242 if (items_ & SEARCH_ENGINES) { | 264 if (items_ & SEARCH_ENGINES) { |
243 layout->StartRow(0, double_column_view_set_id); | 265 layout->StartRow(0, double_column_view_set_id); |
244 layout->AddView(state_searches_.get()); | 266 layout->AddView(state_searches_.get()); |
245 layout->AddView(label_searches_.get()); | 267 layout->AddView(label_searches_.get()); |
246 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 268 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
(...skipping 23 matching lines...) Expand all Loading... |
270 | 292 |
271 void StartImportingWithUI(HWND parent_window, | 293 void StartImportingWithUI(HWND parent_window, |
272 int16 items, | 294 int16 items, |
273 ImporterHost* coordinator, | 295 ImporterHost* coordinator, |
274 const ProfileInfo& source_profile, | 296 const ProfileInfo& source_profile, |
275 Profile* target_profile, | 297 Profile* target_profile, |
276 ImportObserver* observer, | 298 ImportObserver* observer, |
277 bool first_run) { | 299 bool first_run) { |
278 DCHECK(items != 0); | 300 DCHECK(items != 0); |
279 ImportingProgressView* v = new ImportingProgressView( | 301 ImportingProgressView* v = new ImportingProgressView( |
280 source_profile.description, items, coordinator, observer, parent_window); | 302 source_profile.description, items, coordinator, observer, parent_window, |
| 303 source_profile.browser_type == BOOKMARKS_HTML); |
281 views::Window* window = | 304 views::Window* window = |
282 views::Window::CreateChromeWindow(parent_window, gfx::Rect(), v); | 305 views::Window::CreateChromeWindow(parent_window, gfx::Rect(), v); |
283 | 306 |
284 // In headless mode it means that we don't show the progress window, but it | 307 // In headless mode it means that we don't show the progress window, but it |
285 // still need it to exist. No user interaction will be required. | 308 // still need it to exist. No user interaction will be required. |
286 if (!coordinator->is_headless()) | 309 if (!coordinator->is_headless()) |
287 window->Show(); | 310 window->Show(); |
288 | 311 |
289 coordinator->StartImportSettings(source_profile, items, | 312 coordinator->StartImportSettings(source_profile, items, |
290 new ProfileWriter(target_profile), | 313 new ProfileWriter(target_profile), |
291 first_run); | 314 first_run); |
292 } | 315 } |
293 | 316 |
OLD | NEW |