| 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/first_run_customize_view.h" | 5 #include "chrome/browser/views/first_run_customize_view.h" |
| 6 | 6 |
| 7 #include "chrome/app/locales/locale_settings.h" | 7 #include "chrome/app/locales/locale_settings.h" |
| 8 #include "chrome/app/theme/theme_resources.h" | 8 #include "chrome/app/theme/theme_resources.h" |
| 9 #include "chrome/browser/importer/importer.h" | 9 #include "chrome/browser/importer/importer.h" |
| 10 #include "chrome/browser/first_run.h" | 10 #include "chrome/browser/first_run.h" |
| 11 #include "chrome/browser/shell_integration.h" | |
| 12 #include "chrome/browser/user_metrics.h" | 11 #include "chrome/browser/user_metrics.h" |
| 13 #include "chrome/browser/views/standard_layout.h" | 12 #include "chrome/browser/views/standard_layout.h" |
| 14 #include "chrome/common/l10n_util.h" | 13 #include "chrome/common/l10n_util.h" |
| 15 #include "chrome/common/resource_bundle.h" | 14 #include "chrome/common/resource_bundle.h" |
| 16 #include "chrome/views/checkbox.h" | 15 #include "chrome/views/checkbox.h" |
| 17 #include "chrome/views/combo_box.h" | 16 #include "chrome/views/combo_box.h" |
| 18 #include "chrome/views/image_view.h" | 17 #include "chrome/views/image_view.h" |
| 19 #include "chrome/views/label.h" | 18 #include "chrome/views/label.h" |
| 20 #include "chrome/views/throbber.h" | 19 #include "chrome/views/throbber.h" |
| 21 #include "chrome/views/window.h" | 20 #include "chrome/views/window.h" |
| 22 | 21 |
| 23 #include "chromium_strings.h" | 22 #include "chromium_strings.h" |
| 24 #include "generated_resources.h" | 23 #include "generated_resources.h" |
| 25 | 24 |
| 26 FirstRunCustomizeView::FirstRunCustomizeView(Profile* profile, | 25 FirstRunCustomizeView::FirstRunCustomizeView(Profile* profile, |
| 27 ImporterHost* importer_host, | 26 ImporterHost* importer_host, |
| 28 CustomizeViewObserver* observer) | 27 CustomizeViewObserver* observer, |
| 28 bool default_browser_checked) |
| 29 : FirstRunViewBase(profile), | 29 : FirstRunViewBase(profile), |
| 30 main_label_(NULL), | 30 main_label_(NULL), |
| 31 import_cbox_(NULL), | 31 import_cbox_(NULL), |
| 32 default_browser_cbox_(NULL), | |
| 33 import_from_combo_(NULL), | 32 import_from_combo_(NULL), |
| 34 shortcuts_label_(NULL), | 33 shortcuts_label_(NULL), |
| 35 desktop_shortcut_cbox_(NULL), | 34 desktop_shortcut_cbox_(NULL), |
| 36 quick_shortcut_cbox_(NULL), | 35 quick_shortcut_cbox_(NULL), |
| 37 customize_observer_(observer) { | 36 customize_observer_(observer) { |
| 38 importer_host_ = importer_host; | 37 importer_host_ = importer_host; |
| 39 DCHECK(importer_host_); | 38 DCHECK(importer_host_); |
| 40 SetupControls(); | 39 SetupControls(); |
| 40 |
| 41 // The checkbox for Default Browser should be the same for FirstRun and |
| 42 // the customize view, so that the user selection isn't lost when you uncheck |
| 43 // and then open the Customize dialog. Therefore, we propagate the selection |
| 44 // status of the default browser here. |
| 45 default_browser_->SetIsSelected(default_browser_checked); |
| 41 } | 46 } |
| 42 | 47 |
| 43 FirstRunCustomizeView::~FirstRunCustomizeView() { | 48 FirstRunCustomizeView::~FirstRunCustomizeView() { |
| 44 } | 49 } |
| 45 | 50 |
| 46 ChromeViews::CheckBox* FirstRunCustomizeView::MakeCheckBox(int label_id) { | 51 ChromeViews::CheckBox* FirstRunCustomizeView::MakeCheckBox(int label_id) { |
| 47 ChromeViews::CheckBox* cbox = | 52 ChromeViews::CheckBox* cbox = |
| 48 new ChromeViews::CheckBox(l10n_util::GetString(label_id)); | 53 new ChromeViews::CheckBox(l10n_util::GetString(label_id)); |
| 49 cbox->SetListener(this); | 54 cbox->SetListener(this); |
| 50 AddChildView(cbox); | 55 AddChildView(cbox); |
| 51 return cbox; | 56 return cbox; |
| 52 } | 57 } |
| 53 | 58 |
| 54 void FirstRunCustomizeView::SetupControls() { | 59 void FirstRunCustomizeView::SetupControls() { |
| 55 using ChromeViews::Label; | 60 using ChromeViews::Label; |
| 56 using ChromeViews::CheckBox; | 61 using ChromeViews::CheckBox; |
| 57 | 62 |
| 58 main_label_ = new Label(l10n_util::GetString(IDS_FR_CUSTOMIZE_DLG_TEXT)); | 63 main_label_ = new Label(l10n_util::GetString(IDS_FR_CUSTOMIZE_DLG_TEXT)); |
| 59 main_label_->SetMultiLine(true); | 64 main_label_->SetMultiLine(true); |
| 60 main_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); | 65 main_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); |
| 61 AddChildView(main_label_); | 66 AddChildView(main_label_); |
| 62 | 67 |
| 63 import_cbox_ = MakeCheckBox(IDS_FR_CUSTOMIZE_IMPORT); | 68 import_cbox_ = MakeCheckBox(IDS_FR_CUSTOMIZE_IMPORT); |
| 64 | 69 |
| 65 import_from_combo_ = new ChromeViews::ComboBox(this); | 70 import_from_combo_ = new ChromeViews::ComboBox(this); |
| 66 AddChildView(import_from_combo_); | 71 AddChildView(import_from_combo_); |
| 67 | 72 |
| 68 default_browser_cbox_ = MakeCheckBox(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER); | |
| 69 | |
| 70 shortcuts_label_ = | 73 shortcuts_label_ = |
| 71 new Label(l10n_util::GetString(IDS_FR_CUSTOMIZE_SHORTCUTS)); | 74 new Label(l10n_util::GetString(IDS_FR_CUSTOMIZE_SHORTCUTS)); |
| 72 shortcuts_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); | 75 shortcuts_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); |
| 73 AddChildView(shortcuts_label_); | 76 AddChildView(shortcuts_label_); |
| 74 | 77 |
| 75 // The two check boxes for the different shortcut creation. | 78 // The two check boxes for the different shortcut creation. |
| 76 desktop_shortcut_cbox_ = MakeCheckBox(IDS_FR_CUSTOM_SHORTCUT_DESKTOP); | 79 desktop_shortcut_cbox_ = MakeCheckBox(IDS_FR_CUSTOM_SHORTCUT_DESKTOP); |
| 77 desktop_shortcut_cbox_->SetIsSelected(true); | 80 desktop_shortcut_cbox_->SetIsSelected(true); |
| 78 | 81 |
| 79 quick_shortcut_cbox_ = MakeCheckBox(IDS_FR_CUSTOM_SHORTCUT_QUICKL); | 82 quick_shortcut_cbox_ = MakeCheckBox(IDS_FR_CUSTOM_SHORTCUT_QUICKL); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 110 import_cbox_->GetPreferredSize(&pref_size); | 113 import_cbox_->GetPreferredSize(&pref_size); |
| 111 import_cbox_->SetBounds(kPanelHorizMargin, next_v_space, | 114 import_cbox_->SetBounds(kPanelHorizMargin, next_v_space, |
| 112 pref_size.cx, pref_size.cy); | 115 pref_size.cx, pref_size.cy); |
| 113 | 116 |
| 114 import_cbox_->SetIsSelected(true); | 117 import_cbox_->SetIsSelected(true); |
| 115 | 118 |
| 116 int x_offset = import_cbox_->x() + | 119 int x_offset = import_cbox_->x() + |
| 117 import_cbox_->width(); | 120 import_cbox_->width(); |
| 118 | 121 |
| 119 import_from_combo_->GetPreferredSize(&pref_size); | 122 import_from_combo_->GetPreferredSize(&pref_size); |
| 120 import_from_combo_->SetBounds(x_offset, next_v_space, | 123 import_from_combo_->SetBounds(x_offset, |
| 121 pref_size.cx + kComboExtraPad, pref_size.cy); | 124 next_v_space + |
| 125 (import_cbox_->height() - |
| 126 pref_size.cy) / 2, |
| 127 pref_size.cx + kComboExtraPad, |
| 128 pref_size.cy); |
| 122 | 129 |
| 123 AdjustDialogWidth(import_from_combo_); | 130 AdjustDialogWidth(import_from_combo_); |
| 124 | 131 |
| 125 next_v_space = import_cbox_->y() + import_cbox_->height() + | 132 next_v_space = import_cbox_->y() + import_cbox_->height() + |
| 126 kUnrelatedControlVerticalSpacing; | 133 kUnrelatedControlVerticalSpacing; |
| 127 | 134 |
| 128 default_browser_cbox_->GetPreferredSize(&pref_size); | |
| 129 default_browser_cbox_->SetBounds(kPanelHorizMargin, next_v_space, | |
| 130 pref_size.cx, pref_size.cy); | |
| 131 | |
| 132 AdjustDialogWidth(default_browser_cbox_); | |
| 133 | |
| 134 next_v_space += default_browser_cbox_->height() + | |
| 135 kUnrelatedControlVerticalSpacing; | |
| 136 | |
| 137 shortcuts_label_->GetPreferredSize(&pref_size); | 135 shortcuts_label_->GetPreferredSize(&pref_size); |
| 138 shortcuts_label_->SetBounds(kPanelHorizMargin, next_v_space, | 136 shortcuts_label_->SetBounds(kPanelHorizMargin, next_v_space, |
| 139 pref_size.cx, pref_size.cy); | 137 pref_size.cx, pref_size.cy); |
| 140 | 138 |
| 141 AdjustDialogWidth(shortcuts_label_); | 139 AdjustDialogWidth(shortcuts_label_); |
| 142 | 140 |
| 143 next_v_space += shortcuts_label_->height() + | 141 next_v_space += shortcuts_label_->height() + |
| 144 kRelatedControlVerticalSpacing; | 142 kRelatedControlVerticalSpacing; |
| 145 | 143 |
| 146 desktop_shortcut_cbox_->GetPreferredSize(&pref_size); | 144 desktop_shortcut_cbox_->GetPreferredSize(&pref_size); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 return this; | 181 return this; |
| 184 } | 182 } |
| 185 | 183 |
| 186 bool FirstRunCustomizeView::Accept() { | 184 bool FirstRunCustomizeView::Accept() { |
| 187 if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) | 185 if (!IsDialogButtonEnabled(DIALOGBUTTON_OK)) |
| 188 return false; | 186 return false; |
| 189 | 187 |
| 190 DisableButtons(); | 188 DisableButtons(); |
| 191 import_cbox_->SetEnabled(false); | 189 import_cbox_->SetEnabled(false); |
| 192 import_from_combo_->SetEnabled(false); | 190 import_from_combo_->SetEnabled(false); |
| 193 default_browser_cbox_->SetEnabled(false); | |
| 194 desktop_shortcut_cbox_->SetEnabled(false); | 191 desktop_shortcut_cbox_->SetEnabled(false); |
| 195 quick_shortcut_cbox_->SetEnabled(false); | 192 quick_shortcut_cbox_->SetEnabled(false); |
| 196 | 193 |
| 197 if (desktop_shortcut_cbox_->IsSelected()) { | 194 if (desktop_shortcut_cbox_->IsSelected()) { |
| 198 UserMetrics::RecordAction(L"FirstRunCustom_Do_DesktopShortcut", profile_); | 195 UserMetrics::RecordAction(L"FirstRunCustom_Do_DesktopShortcut", profile_); |
| 199 CreateDesktopShortcut(); | 196 CreateDesktopShortcut(); |
| 200 } | 197 } |
| 201 if (quick_shortcut_cbox_->IsSelected()) { | 198 if (quick_shortcut_cbox_->IsSelected()) { |
| 202 UserMetrics::RecordAction(L"FirstRunCustom_Do_QuickLShortcut", profile_); | 199 UserMetrics::RecordAction(L"FirstRunCustom_Do_QuickLShortcut", profile_); |
| 203 CreateQuickLaunchShortcut(); | 200 CreateQuickLaunchShortcut(); |
| 204 } | 201 } |
| 205 if (!import_cbox_->IsSelected()) { | 202 if (!import_cbox_->IsSelected()) { |
| 206 UserMetrics::RecordAction(L"FirstRunCustom_No_Import", profile_); | 203 UserMetrics::RecordAction(L"FirstRunCustom_No_Import", profile_); |
| 207 } else { | 204 } else { |
| 208 int browser_selected = import_from_combo_->GetSelectedItem(); | 205 int browser_selected = import_from_combo_->GetSelectedItem(); |
| 209 FirstRun::ImportSettings(profile_, browser_selected, | 206 FirstRun::ImportSettings(profile_, browser_selected, |
| 210 GetDefaultImportItems(), window()->GetHWND()); | 207 GetDefaultImportItems(), window()->GetHWND()); |
| 211 } | 208 } |
| 212 if (default_browser_cbox_->IsSelected()) { | 209 if (default_browser_->IsSelected()) |
| 213 UserMetrics::RecordAction(L"FirstRunCustom_Do_DefBrowser", profile_); | 210 SetDefaultBrowser(); |
| 214 ShellIntegration::SetAsDefaultBrowser(); | |
| 215 } | |
| 216 | 211 |
| 217 if (customize_observer_) | 212 if (customize_observer_) |
| 218 customize_observer_->CustomizeAccepted(); | 213 customize_observer_->CustomizeAccepted(); |
| 219 | 214 |
| 220 // Exit the message loop we were started with so that startup can continue. | 215 // Exit the message loop we were started with so that startup can continue. |
| 221 MessageLoop::current()->Quit(); | 216 MessageLoop::current()->Quit(); |
| 222 | 217 |
| 223 return true; | 218 return true; |
| 224 } | 219 } |
| 225 | 220 |
| 226 bool FirstRunCustomizeView::Cancel() { | 221 bool FirstRunCustomizeView::Cancel() { |
| 227 if (customize_observer_) | 222 if (customize_observer_) |
| 228 customize_observer_->CustomizeCanceled(); | 223 customize_observer_->CustomizeCanceled(); |
| 229 | 224 |
| 230 // Don't quit the message loop in this case - we're still showing the main | 225 // Don't quit the message loop in this case - we're still showing the main |
| 231 // First run dialog box underneath ourselves. | 226 // First run dialog box underneath ourselves. |
| 232 | 227 |
| 233 return true; | 228 return true; |
| 234 } | 229 } |
| 235 | 230 |
| OLD | NEW |