| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/views/first_run_customize_view.h" | |
| 6 | |
| 7 #include "app/l10n_util.h" | |
| 8 #include "app/resource_bundle.h" | |
| 9 #include "base/win_util.h" | |
| 10 #include "chrome/browser/importer/importer.h" | |
| 11 #include "chrome/browser/first_run.h" | |
| 12 #include "chrome/browser/metrics/user_metrics.h" | |
| 13 #include "chrome/installer/util/browser_distribution.h" | |
| 14 #include "grit/chromium_strings.h" | |
| 15 #include "grit/generated_resources.h" | |
| 16 #include "grit/locale_settings.h" | |
| 17 #include "grit/theme_resources.h" | |
| 18 #include "views/controls/button/checkbox.h" | |
| 19 #include "views/controls/image_view.h" | |
| 20 #include "views/controls/label.h" | |
| 21 #include "views/controls/throbber.h" | |
| 22 #include "views/standard_layout.h" | |
| 23 #include "views/window/window.h" | |
| 24 | |
| 25 FirstRunCustomizeView::FirstRunCustomizeView( | |
| 26 Profile* profile, | |
| 27 ImporterHost* importer_host, | |
| 28 CustomizeViewObserver* observer, | |
| 29 bool default_browser_checked, | |
| 30 bool homepage_defined, | |
| 31 int import_items, | |
| 32 int dont_import_items, | |
| 33 bool search_engine_experiment, | |
| 34 bool randomize_search_engine_experiment) | |
| 35 : FirstRunViewBase(profile, homepage_defined, import_items, | |
| 36 dont_import_items, search_engine_experiment, | |
| 37 randomize_search_engine_experiment), | |
| 38 main_label_(NULL), | |
| 39 import_cbox_(NULL), | |
| 40 import_from_combo_(NULL), | |
| 41 shortcuts_label_(NULL), | |
| 42 desktop_shortcut_cbox_(NULL), | |
| 43 quick_shortcut_cbox_(NULL), | |
| 44 customize_observer_(observer) { | |
| 45 importer_host_ = importer_host; | |
| 46 DCHECK(importer_host_); | |
| 47 SetupControls(); | |
| 48 | |
| 49 // The checkbox for Default Browser should be the same for FirstRun and | |
| 50 // the customize view, so that the user selection isn't lost when you uncheck | |
| 51 // and then open the Customize dialog. Therefore, we propagate the selection | |
| 52 // status of the default browser here. | |
| 53 if (default_browser_) | |
| 54 default_browser_->SetChecked(default_browser_checked); | |
| 55 } | |
| 56 | |
| 57 FirstRunCustomizeView::~FirstRunCustomizeView() { | |
| 58 } | |
| 59 | |
| 60 views::Checkbox* FirstRunCustomizeView::MakeCheckBox(int label_id) { | |
| 61 views::Checkbox* cbox = new views::Checkbox(l10n_util::GetString(label_id)); | |
| 62 cbox->set_listener(this); | |
| 63 AddChildView(cbox); | |
| 64 return cbox; | |
| 65 } | |
| 66 | |
| 67 void FirstRunCustomizeView::SetupControls() { | |
| 68 using views::Label; | |
| 69 using views::Checkbox; | |
| 70 | |
| 71 main_label_ = new Label(l10n_util::GetString(IDS_FR_CUSTOMIZE_DLG_TEXT)); | |
| 72 main_label_->SetMultiLine(true); | |
| 73 main_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); | |
| 74 AddChildView(main_label_); | |
| 75 | |
| 76 import_cbox_ = MakeCheckBox(IDS_FR_CUSTOMIZE_IMPORT); | |
| 77 | |
| 78 import_from_combo_ = new views::Combobox(this); | |
| 79 AddChildView(import_from_combo_); | |
| 80 | |
| 81 shortcuts_label_ = | |
| 82 new Label(l10n_util::GetString(IDS_FR_CUSTOMIZE_SHORTCUTS)); | |
| 83 shortcuts_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); | |
| 84 AddChildView(shortcuts_label_); | |
| 85 | |
| 86 // The two check boxes for the different shortcut creation. | |
| 87 desktop_shortcut_cbox_ = MakeCheckBox(IDS_FR_CUSTOM_SHORTCUT_DESKTOP); | |
| 88 desktop_shortcut_cbox_->SetChecked(true); | |
| 89 | |
| 90 quick_shortcut_cbox_ = MakeCheckBox(IDS_FR_CUSTOM_SHORTCUT_QUICKL); | |
| 91 // For windows 7 create quick launch default is not checked. | |
| 92 bool ql_default = (win_util::GetWinVersion() < win_util::WINVERSION_WIN7); | |
| 93 quick_shortcut_cbox_->SetChecked(ql_default); | |
| 94 } | |
| 95 | |
| 96 gfx::Size FirstRunCustomizeView::GetPreferredSize() { | |
| 97 return gfx::Size(views::Window::GetLocalizedContentsSize( | |
| 98 IDS_FIRSTRUNCUSTOMIZE_DIALOG_WIDTH_CHARS, | |
| 99 IDS_FIRSTRUNCUSTOMIZE_DIALOG_HEIGHT_LINES)); | |
| 100 } | |
| 101 | |
| 102 void FirstRunCustomizeView::Layout() { | |
| 103 FirstRunViewBase::Layout(); | |
| 104 | |
| 105 const int kVertSpacing = 8; | |
| 106 const int kComboExtraPad = 8; | |
| 107 | |
| 108 gfx::Size canvas = GetPreferredSize(); | |
| 109 | |
| 110 // Welcome label goes in to to the left. It does not go across the | |
| 111 // entire window because the background gets busy on the right. | |
| 112 gfx::Size pref_size = main_label_->GetPreferredSize(); | |
| 113 main_label_->SetBounds(kPanelHorizMargin, kPanelVertMargin, | |
| 114 canvas.width() - pref_size.width(), | |
| 115 pref_size.height()); | |
| 116 AdjustDialogWidth(main_label_); | |
| 117 | |
| 118 int next_v_space = background_image()->y() + | |
| 119 background_image()->height() + kPanelVertMargin; | |
| 120 | |
| 121 pref_size = import_cbox_->GetPreferredSize(); | |
| 122 import_cbox_->SetBounds(kPanelHorizMargin, next_v_space, | |
| 123 pref_size.width(), pref_size.height()); | |
| 124 | |
| 125 import_cbox_->SetChecked(true); | |
| 126 | |
| 127 int x_offset = import_cbox_->x() + | |
| 128 import_cbox_->width(); | |
| 129 | |
| 130 pref_size = import_from_combo_->GetPreferredSize(); | |
| 131 import_from_combo_->SetBounds(x_offset, | |
| 132 next_v_space + | |
| 133 (import_cbox_->height() - | |
| 134 pref_size.height()) / 2, | |
| 135 pref_size.width() + kComboExtraPad, | |
| 136 pref_size.height()); | |
| 137 | |
| 138 AdjustDialogWidth(import_from_combo_); | |
| 139 | |
| 140 next_v_space = import_cbox_->y() + import_cbox_->height() + | |
| 141 kUnrelatedControlVerticalSpacing; | |
| 142 | |
| 143 pref_size = shortcuts_label_->GetPreferredSize(); | |
| 144 shortcuts_label_->SetBounds(kPanelHorizMargin, next_v_space, | |
| 145 pref_size.width(), pref_size.height()); | |
| 146 | |
| 147 AdjustDialogWidth(shortcuts_label_); | |
| 148 | |
| 149 next_v_space += shortcuts_label_->height() + | |
| 150 kRelatedControlVerticalSpacing; | |
| 151 | |
| 152 pref_size = desktop_shortcut_cbox_->GetPreferredSize(); | |
| 153 desktop_shortcut_cbox_->SetBounds(kPanelHorizMargin, next_v_space, | |
| 154 pref_size.width(), pref_size.height()); | |
| 155 | |
| 156 AdjustDialogWidth(desktop_shortcut_cbox_); | |
| 157 | |
| 158 next_v_space += desktop_shortcut_cbox_->height() + | |
| 159 kRelatedControlVerticalSpacing; | |
| 160 | |
| 161 pref_size = quick_shortcut_cbox_->GetPreferredSize(); | |
| 162 quick_shortcut_cbox_->SetBounds(kPanelHorizMargin, next_v_space, | |
| 163 pref_size.width(), pref_size.height()); | |
| 164 | |
| 165 AdjustDialogWidth(quick_shortcut_cbox_); | |
| 166 } | |
| 167 | |
| 168 void FirstRunCustomizeView::ButtonPressed( | |
| 169 views::Button* sender, const views::Event& event) { | |
| 170 if (import_cbox_ == sender) { | |
| 171 // Disable the import combobox if the user unchecks the checkbox. | |
| 172 import_from_combo_->SetEnabled(import_cbox_->checked()); | |
| 173 } | |
| 174 | |
| 175 // Call the function of the base class to update its buttons. | |
| 176 FirstRunViewBase::ButtonPressed(sender, event); | |
| 177 } | |
| 178 | |
| 179 int FirstRunCustomizeView::GetItemCount() { | |
| 180 return importer_host_->GetAvailableProfileCount(); | |
| 181 } | |
| 182 | |
| 183 std::wstring FirstRunCustomizeView::GetItemAt(int index) { | |
| 184 return importer_host_->GetSourceProfileNameAt(index); | |
| 185 } | |
| 186 | |
| 187 std::wstring FirstRunCustomizeView::GetWindowTitle() const { | |
| 188 return l10n_util::GetString(IDS_FR_CUSTOMIZE_DLG_TITLE); | |
| 189 } | |
| 190 | |
| 191 views::View* FirstRunCustomizeView::GetContentsView() { | |
| 192 return this; | |
| 193 } | |
| 194 | |
| 195 bool FirstRunCustomizeView::Accept() { | |
| 196 if (!IsDialogButtonEnabled(MessageBoxFlags::DIALOGBUTTON_OK)) | |
| 197 return false; | |
| 198 | |
| 199 DisableButtons(); | |
| 200 import_cbox_->SetEnabled(false); | |
| 201 import_from_combo_->SetEnabled(false); | |
| 202 desktop_shortcut_cbox_->SetEnabled(false); | |
| 203 quick_shortcut_cbox_->SetEnabled(false); | |
| 204 | |
| 205 if (desktop_shortcut_cbox_->checked()) { | |
| 206 UserMetrics::RecordAction( | |
| 207 UserMetricsAction("FirstRunCustom_Do_DesktopShortcut"), profile_); | |
| 208 CreateDesktopShortcut(); | |
| 209 } | |
| 210 if (quick_shortcut_cbox_->checked()) { | |
| 211 UserMetrics::RecordAction( | |
| 212 UserMetricsAction("FirstRunCustom_Do_QuickLShortcut"), profile_); | |
| 213 CreateQuickLaunchShortcut(); | |
| 214 } | |
| 215 if (!import_cbox_->checked()) { | |
| 216 UserMetrics::RecordAction(UserMetricsAction("FirstRunCustom_No_Import"), | |
| 217 profile_); | |
| 218 } else { | |
| 219 int browser_selected = import_from_combo_->selected_item(); | |
| 220 FirstRun::ImportSettings(profile_, | |
| 221 importer_host_->GetSourceProfileInfoAt(browser_selected).browser_type, | |
| 222 GetImportItems(), window()->GetNativeWindow()); | |
| 223 } | |
| 224 if (default_browser_ && default_browser_->checked()) | |
| 225 SetDefaultBrowser(); | |
| 226 | |
| 227 // The customize observer is responsible for shutting down the startup | |
| 228 // message loop. | |
| 229 if (customize_observer_) { | |
| 230 customize_observer_->CustomizeAccepted(); | |
| 231 } else { | |
| 232 // Exit the message loop we were started with so that startup can continue. | |
| 233 MessageLoop::current()->Quit(); | |
| 234 FirstRunComplete(); | |
| 235 } | |
| 236 return true; | |
| 237 } | |
| 238 | |
| 239 bool FirstRunCustomizeView::Cancel() { | |
| 240 if (customize_observer_) | |
| 241 customize_observer_->CustomizeCanceled(); | |
| 242 | |
| 243 // Don't quit the message loop in this case - we're still showing the main | |
| 244 // First run dialog box underneath ourselves. | |
| 245 | |
| 246 return true; | |
| 247 } | |
| OLD | NEW |