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/gtk/first_run_dialog.h" | 5 #include "chrome/browser/gtk/first_run_dialog.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" |
8 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/gtk/gtk_chrome_link_button.h" | 11 #include "chrome/browser/gtk/gtk_chrome_link_button.h" |
| 12 #include "chrome/browser/gtk/gtk_floating_container.h" |
11 #include "chrome/browser/gtk/gtk_util.h" | 13 #include "chrome/browser/gtk/gtk_util.h" |
12 #include "chrome/browser/importer/importer_data_types.h" | 14 #include "chrome/browser/importer/importer_data_types.h" |
13 #include "chrome/browser/platform_util.h" | 15 #include "chrome/browser/platform_util.h" |
14 #include "chrome/browser/process_singleton.h" | 16 #include "chrome/browser/process_singleton.h" |
| 17 #include "chrome/browser/profile.h" |
15 #include "chrome/browser/shell_integration.h" | 18 #include "chrome/browser/shell_integration.h" |
16 #include "chrome/installer/util/google_update_settings.h" | 19 #include "chrome/installer/util/google_update_settings.h" |
| 20 #include "gfx/gtk_util.h" |
17 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
18 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
19 #include "grit/locale_settings.h" | 23 #include "grit/locale_settings.h" |
| 24 #include "grit/theme_resources.h" |
20 | 25 |
21 #if defined(USE_LINUX_BREAKPAD) | 26 #if defined(USE_LINUX_BREAKPAD) |
22 #include "chrome/app/breakpad_linux.h" | 27 #include "chrome/app/breakpad_linux.h" |
23 #endif | 28 #endif |
24 | 29 |
| 30 namespace { |
| 31 |
| 32 const gchar* kSearchEngineKey = "template-url-search-engine"; |
| 33 |
| 34 // Height of the label that displays the search engine's logo (in lieu of the |
| 35 // actual logo) in chromium. |
| 36 const int kLogoLabelHeight = 100; |
| 37 |
| 38 // The width of the explanatory label. The 180 is the width of the large images. |
| 39 const int kExplanationWidth = 3 * 180; |
| 40 |
| 41 // Horizontal spacing between search engine choices. |
| 42 const int kSearchEngineSpacing = 6; |
| 43 |
| 44 // Set the (x, y) coordinates of the welcome message (which floats on top of |
| 45 // the omnibox image at the top of the first run dialog). |
| 46 void SetWelcomePosition(GtkFloatingContainer* container, |
| 47 GtkAllocation* allocation, |
| 48 GtkWidget* label) { |
| 49 GValue value = { 0, }; |
| 50 g_value_init(&value, G_TYPE_INT); |
| 51 g_value_set_int(&value, gtk_util::kContentAreaSpacing); |
| 52 gtk_container_child_set_property(GTK_CONTAINER(container), |
| 53 label, "x", &value); |
| 54 |
| 55 GtkRequisition req; |
| 56 gtk_widget_size_request(label, &req); |
| 57 int y = allocation->height / 2 - req.height / 2; |
| 58 |
| 59 g_value_set_int(&value, y); |
| 60 gtk_container_child_set_property(GTK_CONTAINER(container), |
| 61 label, "y", &value); |
| 62 g_value_unset(&value); |
| 63 } |
| 64 |
| 65 } // namespace |
| 66 |
25 // static | 67 // static |
26 bool FirstRunDialog::Show(Profile* profile, | 68 bool FirstRunDialog::Show(Profile* profile, |
27 ProcessSingleton* process_singleton) { | 69 ProcessSingleton* process_singleton) { |
28 int response = -1; | 70 int response = -1; |
29 // Object deletes itself. | 71 // Object deletes itself. |
30 FirstRunDialog* first_run = new FirstRunDialog(profile, response); | 72 new FirstRunDialog(profile, response); |
31 | 73 |
32 // Prevent further launches of Chrome until First Run UI is done. | 74 // Prevent further launches of Chrome until First Run UI is done. |
33 process_singleton->Lock(GTK_WINDOW(first_run->dialog_)); | 75 // We don't actually use the parameter to Lock() on Posix. |
| 76 process_singleton->Lock(NULL); |
34 | 77 |
35 // TODO(port): it should be sufficient to just run the dialog: | 78 // TODO(port): it should be sufficient to just run the dialog: |
36 // int response = gtk_dialog_run(GTK_DIALOG(dialog)); | 79 // int response = gtk_dialog_run(GTK_DIALOG(dialog)); |
37 // but that spins a nested message loop and hoses us. :( | 80 // but that spins a nested message loop and hoses us. :( |
38 // http://code.google.com/p/chromium/issues/detail?id=12552 | 81 // http://code.google.com/p/chromium/issues/detail?id=12552 |
39 // Instead, run a loop and extract the response manually. | 82 // Instead, run a loop and extract the response manually. |
40 g_signal_connect(first_run->dialog_, "response", | |
41 G_CALLBACK(OnResponseDialogThunk), first_run); | |
42 gtk_widget_show_all(first_run->dialog_); | |
43 MessageLoop::current()->Run(); | 83 MessageLoop::current()->Run(); |
44 | 84 |
45 process_singleton->Unlock(); | 85 process_singleton->Unlock(); |
46 return (response == GTK_RESPONSE_ACCEPT); | 86 return (response == GTK_RESPONSE_ACCEPT); |
47 } | 87 } |
48 | 88 |
49 FirstRunDialog::FirstRunDialog(Profile* profile, int& response) | 89 FirstRunDialog::FirstRunDialog(Profile* profile, int& response) |
50 : dialog_(NULL), report_crashes_(NULL), make_default_(NULL), | 90 : search_engine_window_(NULL), |
51 import_data_(NULL), import_profile_(NULL), profile_(profile), | 91 dialog_(NULL), |
52 response_(response), importer_host_(new ImporterHost()) { | 92 report_crashes_(NULL), |
| 93 make_default_(NULL), |
| 94 profile_(profile), |
| 95 chosen_search_engine_(NULL), |
| 96 response_(response), |
| 97 importer_host_(new ImporterHost()) { |
| 98 search_engines_model_ = profile_->GetTemplateURLModel(); |
| 99 DCHECK(!search_engines_model_->loaded()); |
| 100 search_engines_model_->AddObserver(this); |
| 101 search_engines_model_->Load(); |
| 102 |
| 103 ShowSearchEngineWindow(); |
| 104 } |
| 105 |
| 106 FirstRunDialog::~FirstRunDialog() { |
| 107 } |
| 108 |
| 109 void FirstRunDialog::ShowSearchEngineWindow() { |
| 110 search_engine_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
| 111 gtk_window_set_title( |
| 112 GTK_WINDOW(search_engine_window_), |
| 113 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str()); |
| 114 gtk_window_set_resizable(GTK_WINDOW(search_engine_window_), FALSE); |
| 115 g_signal_connect(search_engine_window_, "destroy", |
| 116 G_CALLBACK(OnSearchEngineWindowDestroyThunk), this); |
| 117 GtkWidget* content_area = gtk_vbox_new(FALSE, 0); |
| 118 gtk_container_add(GTK_CONTAINER(search_engine_window_), content_area); |
| 119 |
| 120 GdkPixbuf* pixbuf = |
| 121 ResourceBundle::GetSharedInstance().GetPixbufNamed( |
| 122 IDR_SEARCH_ENGINE_DIALOG_TOP); |
| 123 GtkWidget* top_image = gtk_image_new_from_pixbuf(pixbuf); |
| 124 // Right align the image. |
| 125 gtk_misc_set_alignment(GTK_MISC(top_image), 1, 0); |
| 126 gtk_widget_set_size_request(top_image, 0, -1); |
| 127 |
| 128 GtkWidget* welcome_message = gtk_util::CreateBoldLabel( |
| 129 l10n_util::GetStringUTF8(IDS_FR_SEARCH_MAIN_LABEL)); |
| 130 |
| 131 GtkWidget* top_area = gtk_floating_container_new(); |
| 132 gtk_container_add(GTK_CONTAINER(top_area), top_image); |
| 133 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(top_area), |
| 134 welcome_message); |
| 135 g_signal_connect(top_area, "set-floating-position", |
| 136 G_CALLBACK(SetWelcomePosition), welcome_message); |
| 137 |
| 138 gtk_box_pack_start(GTK_BOX(content_area), top_area, |
| 139 FALSE, FALSE, 0); |
| 140 |
| 141 GtkWidget* bubble_area_background = gtk_event_box_new(); |
| 142 gtk_widget_modify_bg(bubble_area_background, |
| 143 GTK_STATE_NORMAL, &gfx::kGdkWhite); |
| 144 |
| 145 GtkWidget* bubble_area_box = gtk_vbox_new(FALSE, 0); |
| 146 gtk_container_set_border_width(GTK_CONTAINER(bubble_area_box), |
| 147 gtk_util::kContentAreaSpacing); |
| 148 gtk_container_add(GTK_CONTAINER(bubble_area_background), |
| 149 bubble_area_box); |
| 150 |
| 151 GtkWidget* explanation = gtk_label_new( |
| 152 l10n_util::GetStringFUTF8(IDS_FR_SEARCH_TEXT, |
| 153 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str()); |
| 154 gtk_util::SetLabelColor(explanation, &gfx::kGdkBlack); |
| 155 gtk_label_set_line_wrap(GTK_LABEL(explanation), TRUE); |
| 156 gtk_widget_set_size_request(explanation, kExplanationWidth, -1); |
| 157 gtk_box_pack_start(GTK_BOX(bubble_area_box), explanation, FALSE, FALSE, 0); |
| 158 |
| 159 // We will fill this in after the TemplateURLModel has loaded. |
| 160 search_engine_hbox_ = gtk_hbox_new(FALSE, kSearchEngineSpacing); |
| 161 gtk_box_pack_start(GTK_BOX(bubble_area_box), search_engine_hbox_, |
| 162 FALSE, FALSE, 0); |
| 163 |
| 164 gtk_box_pack_start(GTK_BOX(content_area), bubble_area_background, |
| 165 TRUE, TRUE, 0); |
| 166 |
| 167 gtk_widget_show_all(content_area); |
| 168 gtk_window_present(GTK_WINDOW(search_engine_window_)); |
| 169 } |
| 170 |
| 171 void FirstRunDialog::ShowDialog() { |
| 172 #if defined(GOOGLE_CHROME_BUILD) |
53 dialog_ = gtk_dialog_new_with_buttons( | 173 dialog_ = gtk_dialog_new_with_buttons( |
54 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(), | 174 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(), |
55 NULL, // No parent | 175 NULL, // No parent |
56 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | 176 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), |
57 GTK_STOCK_QUIT, | 177 GTK_STOCK_QUIT, |
58 GTK_RESPONSE_REJECT, | 178 GTK_RESPONSE_REJECT, |
59 NULL); | 179 NULL); |
60 gtk_util::AddButtonToDialog(dialog_, | 180 gtk_util::AddButtonToDialog(dialog_, |
61 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_OK).c_str(), | 181 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_OK).c_str(), |
62 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); | 182 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); |
63 | 183 |
64 // Normally we would do the following: | |
65 // gtk_widget_realize(dialog_); | |
66 // gtk_util::SetWindowSizeFromResources(GTK_WINDOW(dialog_), | |
67 // IDS_FIRSTRUN_DIALOG_WIDTH_CHARS, | |
68 // -1, | |
69 // false); // resizable | |
70 // But because the first run dialog has extra widgets in Windows, the | |
71 // resources specify a dialog that is way too big. So instead in just this | |
72 // one case we let GTK size the dialog itself and just mark it non-resizable | |
73 // manually: | |
74 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); | 184 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); |
75 | 185 |
76 g_signal_connect(dialog_, "delete-event", | 186 g_signal_connect(dialog_, "delete-event", |
77 G_CALLBACK(gtk_widget_hide_on_delete), NULL); | 187 G_CALLBACK(gtk_widget_hide_on_delete), NULL); |
78 | 188 |
79 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; | 189 GtkWidget* content_area = GTK_DIALOG(dialog_)->vbox; |
80 gtk_box_set_spacing(GTK_BOX(content_area), 18); | |
81 | 190 |
82 GtkWidget* vbox = gtk_vbox_new(FALSE, 12); | |
83 | |
84 #if defined(GOOGLE_CHROME_BUILD) | |
85 GtkWidget* check_label = gtk_label_new( | 191 GtkWidget* check_label = gtk_label_new( |
86 l10n_util::GetStringUTF8(IDS_OPTIONS_ENABLE_LOGGING).c_str()); | 192 l10n_util::GetStringUTF8(IDS_OPTIONS_ENABLE_LOGGING).c_str()); |
87 gtk_label_set_line_wrap(GTK_LABEL(check_label), TRUE); | 193 gtk_label_set_line_wrap(GTK_LABEL(check_label), TRUE); |
88 | 194 |
89 GtkWidget* learn_more_link = gtk_chrome_link_button_new( | 195 GtkWidget* learn_more_link = gtk_chrome_link_button_new( |
90 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); | 196 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); |
91 // Stick it in an hbox so it doesn't expand to the whole width. | 197 // Stick it in an hbox so it doesn't expand to the whole width. |
92 GtkWidget* learn_more_hbox = gtk_hbox_new(FALSE, 0); | 198 GtkWidget* learn_more_hbox = gtk_hbox_new(FALSE, 0); |
93 gtk_box_pack_start(GTK_BOX(learn_more_hbox), | 199 gtk_box_pack_start(GTK_BOX(learn_more_hbox), |
94 gtk_util::IndentWidget(learn_more_link), | 200 gtk_util::IndentWidget(learn_more_link), |
95 FALSE, FALSE, 0); | 201 FALSE, FALSE, 0); |
96 g_signal_connect(learn_more_link, "clicked", | 202 g_signal_connect(learn_more_link, "clicked", |
97 G_CALLBACK(OnLearnMoreLinkClickedThunk), this); | 203 G_CALLBACK(OnLearnMoreLinkClickedThunk), this); |
98 | 204 |
99 report_crashes_ = gtk_check_button_new(); | 205 report_crashes_ = gtk_check_button_new(); |
100 gtk_container_add(GTK_CONTAINER(report_crashes_), check_label); | 206 gtk_container_add(GTK_CONTAINER(report_crashes_), check_label); |
101 | 207 |
102 GtkWidget* report_vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | 208 gtk_box_pack_start(GTK_BOX(content_area), report_crashes_, FALSE, FALSE, 0); |
103 gtk_box_pack_start(GTK_BOX(report_vbox), report_crashes_, FALSE, FALSE, 0); | 209 gtk_box_pack_start(GTK_BOX(content_area), learn_more_hbox, FALSE, FALSE, 0); |
104 gtk_box_pack_start(GTK_BOX(report_vbox), learn_more_hbox, FALSE, FALSE, 0); | |
105 gtk_box_pack_start(GTK_BOX(vbox), report_vbox, FALSE, FALSE, 0); | |
106 #endif | |
107 | 210 |
108 make_default_ = gtk_check_button_new_with_label( | 211 make_default_ = gtk_check_button_new_with_label( |
109 l10n_util::GetStringUTF8(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER).c_str()); | 212 l10n_util::GetStringUTF8(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER).c_str()); |
110 gtk_box_pack_start(GTK_BOX(vbox), make_default_, FALSE, FALSE, 0); | 213 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(make_default_), TRUE); |
| 214 gtk_box_pack_start(GTK_BOX(content_area), make_default_, FALSE, FALSE, 0); |
111 | 215 |
112 GtkWidget* combo_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); | 216 g_signal_connect(dialog_, "response", |
113 import_data_ = gtk_check_button_new_with_label( | 217 G_CALLBACK(OnResponseDialogThunk), this); |
114 l10n_util::GetStringUTF8(IDS_FR_CUSTOMIZE_IMPORT).c_str()); | 218 gtk_widget_show_all(dialog_); |
115 gtk_box_pack_start(GTK_BOX(combo_hbox), import_data_, FALSE, FALSE, 0); | 219 #else // !defined(GOOGLE_CHROME_BUILD) |
116 import_profile_ = gtk_combo_box_new_text(); | 220 // We don't show the dialog in chromium. Pretend the user accepted. |
117 gtk_box_pack_start(GTK_BOX(combo_hbox), import_profile_, TRUE, TRUE, 0); | 221 OnResponseDialog(NULL, GTK_RESPONSE_ACCEPT); |
118 gtk_box_pack_start(GTK_BOX(vbox), combo_hbox, FALSE, FALSE, 0); | 222 #endif // !defined(GOOGLE_CHROME_BUILD) |
| 223 } |
119 | 224 |
120 // Detect any supported browsers that we can import from and fill | 225 void FirstRunDialog::OnTemplateURLModelChanged() { |
121 // up the combo box. If none found, disable import data checkbox. | 226 // We only watch the search engine model change once, on load. Remove |
122 int profiles_count = importer_host_->GetAvailableProfileCount(); | 227 // observer so we don't try to redraw if engines change under us. |
123 if (profiles_count > 0) { | 228 search_engines_model_->RemoveObserver(this); |
124 for (int i = 0; i < profiles_count; i++) { | 229 |
125 std::wstring profile = importer_host_->GetSourceProfileNameAt(i); | 230 // Add search engines in search_engines_model_ to buttons list. The |
126 gtk_combo_box_append_text(GTK_COMBO_BOX(import_profile_), | 231 // first three will always be from prepopulated data. |
127 WideToUTF8(profile).c_str()); | 232 std::vector<const TemplateURL*> template_urls = |
| 233 search_engines_model_->GetTemplateURLs(); |
| 234 |
| 235 std::vector<const TemplateURL*>::iterator search_engine_iter; |
| 236 |
| 237 std::string choose_text = l10n_util::GetStringUTF8(IDS_FR_SEARCH_CHOOSE); |
| 238 for (std::vector<const TemplateURL*>::iterator search_engine_iter = |
| 239 template_urls.begin(); |
| 240 search_engine_iter < template_urls.end() && |
| 241 search_engine_iter < template_urls.begin() + 3; |
| 242 ++search_engine_iter) { |
| 243 // Create a container for the search engine widgets. |
| 244 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
| 245 |
| 246 // We show text on Chromium and images on Google Chrome. |
| 247 bool show_images = false; |
| 248 #if defined(GOOGLE_CHROME_BUILD) |
| 249 show_images = true; |
| 250 #endif |
| 251 |
| 252 // Create the image (maybe). |
| 253 int logo_id = (*search_engine_iter)->logo_id(); |
| 254 if (show_images && logo_id > 0) { |
| 255 GdkPixbuf* pixbuf = |
| 256 ResourceBundle::GetSharedInstance().GetPixbufNamed(logo_id); |
| 257 GtkWidget* image = gtk_image_new_from_pixbuf(pixbuf); |
| 258 gtk_box_pack_start(GTK_BOX(vbox), image, FALSE, FALSE, 0); |
| 259 } else { |
| 260 GtkWidget* logo_label = gtk_label_new(NULL); |
| 261 char* markup = g_markup_printf_escaped( |
| 262 "<span weight='bold' size='x-large' color='black'>%s</span>", |
| 263 WideToUTF8((*search_engine_iter)->short_name()).c_str()); |
| 264 gtk_label_set_markup(GTK_LABEL(logo_label), markup); |
| 265 g_free(markup); |
| 266 gtk_widget_set_size_request(logo_label, -1, kLogoLabelHeight); |
| 267 gtk_box_pack_start(GTK_BOX(vbox), logo_label, FALSE, FALSE, 0); |
128 } | 268 } |
129 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(import_data_), TRUE); | 269 |
130 gtk_combo_box_set_active(GTK_COMBO_BOX(import_profile_), 0); | 270 // Create the button. |
| 271 GtkWidget* button = gtk_button_new_with_label(choose_text.c_str()); |
| 272 g_signal_connect(button, "clicked", |
| 273 G_CALLBACK(OnSearchEngineButtonClickedThunk), this); |
| 274 g_object_set_data(G_OBJECT(button), kSearchEngineKey, |
| 275 const_cast<TemplateURL*>(*search_engine_iter)); |
| 276 |
| 277 GtkWidget* button_centerer = gtk_hbox_new(FALSE, 0); |
| 278 gtk_box_pack_start(GTK_BOX(button_centerer), button, TRUE, FALSE, 0); |
| 279 gtk_box_pack_start(GTK_BOX(vbox), button_centerer, FALSE, FALSE, 0); |
| 280 |
| 281 gtk_box_pack_start(GTK_BOX(search_engine_hbox_), vbox, TRUE, TRUE, 0); |
| 282 gtk_widget_show_all(search_engine_hbox_); |
| 283 } |
| 284 } |
| 285 |
| 286 void FirstRunDialog::OnSearchEngineButtonClicked(GtkWidget* sender) { |
| 287 chosen_search_engine_ = static_cast<TemplateURL*>( |
| 288 g_object_get_data(G_OBJECT(sender), kSearchEngineKey)); |
| 289 gtk_widget_destroy(search_engine_window_); |
| 290 } |
| 291 |
| 292 void FirstRunDialog::OnSearchEngineWindowDestroy(GtkWidget* sender) { |
| 293 search_engine_window_ = NULL; |
| 294 if (chosen_search_engine_) { |
| 295 search_engines_model_->SetDefaultSearchProvider(chosen_search_engine_); |
| 296 ShowDialog(); |
131 } else { | 297 } else { |
132 gtk_combo_box_append_text(GTK_COMBO_BOX(import_profile_), | 298 FirstRunDone(); |
133 l10n_util::GetStringUTF8(IDS_IMPORT_NO_PROFILE_FOUND).c_str()); | |
134 gtk_combo_box_set_active(GTK_COMBO_BOX(import_profile_), 0); | |
135 gtk_widget_set_sensitive(import_data_, FALSE); | |
136 gtk_widget_set_sensitive(import_profile_, FALSE); | |
137 } | 299 } |
138 | |
139 gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0); | |
140 } | 300 } |
141 | 301 |
142 void FirstRunDialog::OnResponseDialog(GtkWidget* widget, int response) { | 302 void FirstRunDialog::OnResponseDialog(GtkWidget* widget, int response) { |
143 bool import_started = false; | 303 if (dialog_) |
144 gtk_widget_hide_all(dialog_); | 304 gtk_widget_hide_all(dialog_); |
145 response_ = response; | 305 response_ = response; |
146 | 306 |
| 307 bool do_import = false; |
| 308 |
147 if (response == GTK_RESPONSE_ACCEPT) { | 309 if (response == GTK_RESPONSE_ACCEPT) { |
148 // Mark that first run has ran. | 310 // Mark that first run has ran. |
149 FirstRun::CreateSentinel(); | 311 FirstRun::CreateSentinel(); |
150 | 312 |
151 // Check if user has opted into reporting. | 313 // Check if user has opted into reporting. |
152 if (report_crashes_ && | 314 if (report_crashes_ && |
153 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(report_crashes_))) { | 315 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(report_crashes_))) { |
154 #if defined(USE_LINUX_BREAKPAD) | 316 #if defined(USE_LINUX_BREAKPAD) |
155 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) { | 317 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) { |
156 InitCrashReporter(); | 318 InitCrashReporter(); |
157 } | 319 } |
158 #endif | 320 #endif |
159 } else { | 321 } else { |
160 GoogleUpdateSettings::SetCollectStatsConsent(false); | 322 GoogleUpdateSettings::SetCollectStatsConsent(false); |
161 } | 323 } |
162 | 324 |
163 // If selected set as default browser. | 325 // If selected set as default browser. |
164 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(make_default_))) | 326 if (make_default_ && |
| 327 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(make_default_))) { |
165 ShellIntegration::SetAsDefaultBrowser(); | 328 ShellIntegration::SetAsDefaultBrowser(); |
| 329 } |
166 | 330 |
167 // Import data if selected. | 331 do_import = importer_host_->GetAvailableProfileCount() > 0; |
168 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(import_data_))) { | 332 if (do_import) { |
| 333 // Import data. |
169 const ProfileInfo& source_profile = | 334 const ProfileInfo& source_profile = |
170 importer_host_->GetSourceProfileInfoAt( | 335 importer_host_->GetSourceProfileInfoAt(0); |
171 gtk_combo_box_get_active(GTK_COMBO_BOX(import_profile_))); | |
172 int items = importer::SEARCH_ENGINES + importer::HISTORY + | 336 int items = importer::SEARCH_ENGINES + importer::HISTORY + |
173 importer::FAVORITES + importer::HOME_PAGE + importer::PASSWORDS; | 337 importer::HOME_PAGE + importer::PASSWORDS; |
| 338 importer_host_->SetObserver(this); |
174 // TODO(port): Should we do the actual import in a new process like | 339 // TODO(port): Should we do the actual import in a new process like |
175 // Windows? | 340 // Windows? |
176 StartImportingWithUI(GTK_WINDOW(dialog_), items, importer_host_.get(), | 341 importer_host_->StartImportSettings(source_profile, |
177 source_profile, profile_, this, true); | 342 profile_, |
178 import_started = true; | 343 items, |
| 344 new ProfileWriter(profile_), |
| 345 true); |
179 } | 346 } |
180 } | 347 } |
181 if (!import_started) | 348 |
| 349 if (!do_import) |
182 FirstRunDone(); | 350 FirstRunDone(); |
183 } | 351 } |
184 | 352 |
| 353 void FirstRunDialog::ImportEnded() { |
| 354 FirstRunDone(); |
| 355 } |
| 356 |
185 void FirstRunDialog::OnLearnMoreLinkClicked(GtkButton* button) { | 357 void FirstRunDialog::OnLearnMoreLinkClicked(GtkButton* button) { |
186 platform_util::OpenExternal(GURL( | 358 platform_util::OpenExternal(GURL( |
187 l10n_util::GetStringUTF8(IDS_LEARN_MORE_REPORTING_URL))); | 359 l10n_util::GetStringUTF8(IDS_LEARN_MORE_REPORTING_URL))); |
188 } | 360 } |
189 | 361 |
190 void FirstRunDialog::FirstRunDone() { | 362 void FirstRunDialog::FirstRunDone() { |
191 // Set preference to show first run bubble and welcome page. | |
192 FirstRun::SetShowFirstRunBubblePref(true); | |
193 FirstRun::SetShowWelcomePagePref(); | 363 FirstRun::SetShowWelcomePagePref(); |
194 | 364 |
195 gtk_widget_destroy(dialog_); | 365 if (dialog_) |
| 366 gtk_widget_destroy(dialog_); |
196 MessageLoop::current()->Quit(); | 367 MessageLoop::current()->Quit(); |
197 delete this; | 368 delete this; |
198 } | 369 } |
OLD | NEW |