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/gtk/options/content_page_gtk.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "app/l10n_util.h" | |
10 #include "base/command_line.h" | |
11 #include "base/utf_string_conversions.h" | |
12 #include "chrome/browser/defaults.h" | |
13 #include "chrome/browser/gtk/gtk_chrome_link_button.h" | |
14 #include "chrome/browser/gtk/gtk_theme_provider.h" | |
15 #include "chrome/browser/gtk/gtk_util.h" | |
16 #include "chrome/browser/gtk/import_dialog_gtk.h" | |
17 #include "chrome/browser/gtk/options/options_layout_gtk.h" | |
18 #include "chrome/browser/gtk/options/passwords_exceptions_window_gtk.h" | |
19 #include "chrome/browser/importer/importer_data_types.h" | |
20 #include "chrome/browser/prefs/pref_service.h" | |
21 #include "chrome/browser/profiles/profile.h" | |
22 #include "chrome/browser/sync/sync_ui_util.h" | |
23 #include "chrome/browser/ui/browser.h" | |
24 #include "chrome/browser/ui/browser_list.h" | |
25 #include "chrome/browser/ui/browser_window.h" | |
26 #include "chrome/common/notification_service.h" | |
27 #include "chrome/common/pref_names.h" | |
28 #include "chrome/common/url_constants.h" | |
29 #include "gfx/gtk_util.h" | |
30 #include "grit/app_resources.h" | |
31 #include "grit/chromium_strings.h" | |
32 #include "grit/generated_resources.h" | |
33 #include "grit/locale_settings.h" | |
34 | |
35 #if defined(OS_CHROMEOS) | |
36 #include "chrome/browser/chromeos/options/options_window_view.h" | |
37 #endif // defined(OS_CHROMEOS) | |
38 | |
39 namespace { | |
40 | |
41 // Background color for the status label when it's showing an error. | |
42 static const GdkColor kSyncLabelErrorBgColor = GDK_COLOR_RGB(0xff, 0x9a, 0x9a); | |
43 | |
44 // Helper for WrapLabelAtAllocationHack. | |
45 void OnLabelAllocate(GtkWidget* label, GtkAllocation* allocation) { | |
46 gtk_util::SetLabelWidth(label, allocation->width); | |
47 | |
48 // Disconnect ourselves. Repeatedly resizing based on allocation causes | |
49 // the dialog to become unshrinkable. | |
50 g_signal_handlers_disconnect_by_func( | |
51 label, reinterpret_cast<gpointer>(OnLabelAllocate), NULL); | |
52 } | |
53 | |
54 // Set the label to use a request size equal to its initial allocation | |
55 // size. This causes the label to wrap at the width of the container | |
56 // it is in, instead of at the default width. This is called a hack | |
57 // because GTK doesn't really work when a widget to make its size | |
58 // request depend on its allocation. It does, however, have the | |
59 // intended effect of wrapping the label at the proper width. | |
60 void WrapLabelAtAllocationHack(GtkWidget* label) { | |
61 g_signal_connect(label, "size-allocate", | |
62 G_CALLBACK(OnLabelAllocate), NULL); | |
63 } | |
64 | |
65 } // anonymous namespace | |
66 | |
67 /////////////////////////////////////////////////////////////////////////////// | |
68 // ContentPageGtk, public: | |
69 | |
70 ContentPageGtk::ContentPageGtk(Profile* profile) | |
71 : OptionsPageBase(profile), | |
72 sync_status_label_background_(NULL), | |
73 sync_status_label_(NULL), | |
74 #if !defined(OS_CHROMEOS) | |
75 sync_action_link_background_(NULL), | |
76 sync_action_link_(NULL), | |
77 #endif | |
78 sync_start_stop_button_(NULL), | |
79 sync_customize_button_(NULL), | |
80 privacy_dashboard_link_(NULL), | |
81 initializing_(true), | |
82 sync_service_(NULL), | |
83 managed_prefs_banner_(profile->GetPrefs(), OPTIONS_PAGE_CONTENT) { | |
84 if (profile->GetProfileSyncService()) { | |
85 sync_service_ = profile->GetProfileSyncService(); | |
86 sync_service_->AddObserver(this); | |
87 } | |
88 | |
89 // Prepare the group options layout. | |
90 scoped_ptr<OptionsLayoutBuilderGtk> | |
91 options_builder(OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout()); | |
92 options_builder->AddWidget(managed_prefs_banner_.banner_widget(), false); | |
93 if (sync_service_) { | |
94 options_builder->AddOptionGroup( | |
95 l10n_util::GetStringUTF8(IDS_SYNC_OPTIONS_GROUP_NAME), | |
96 InitSyncGroup(), false); | |
97 UpdateSyncControls(); | |
98 } | |
99 | |
100 // Add preferences observers. | |
101 ask_to_save_passwords_.Init(prefs::kPasswordManagerEnabled, | |
102 profile->GetPrefs(), this); | |
103 form_autofill_enabled_.Init(prefs::kAutoFillEnabled, | |
104 profile->GetPrefs(), this); | |
105 if (browser_defaults::kCanToggleSystemTitleBar) { | |
106 use_custom_chrome_frame_.Init(prefs::kUseCustomChromeFrame, | |
107 profile->GetPrefs(), this); | |
108 } | |
109 | |
110 options_builder->AddOptionGroup( | |
111 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_GROUP_NAME), | |
112 InitPasswordSavingGroup(), false); | |
113 options_builder->AddOptionGroup( | |
114 l10n_util::GetStringUTF8(IDS_AUTOFILL_SETTING_WINDOWS_GROUP_NAME), | |
115 InitFormAutoFillGroup(), false); | |
116 options_builder->AddOptionGroup( | |
117 l10n_util::GetStringUTF8(IDS_OPTIONS_BROWSING_DATA_GROUP_NAME), | |
118 InitBrowsingDataGroup(), false); | |
119 options_builder->AddOptionGroup( | |
120 l10n_util::GetStringUTF8(IDS_APPEARANCE_GROUP_NAME), | |
121 InitThemesGroup(), false); | |
122 page_ = options_builder->get_page_widget(); | |
123 | |
124 // Load initial values. | |
125 NotifyPrefChanged(NULL); | |
126 | |
127 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | |
128 NotificationService::AllSources()); | |
129 ObserveThemeChanged(); | |
130 } | |
131 | |
132 ContentPageGtk::~ContentPageGtk() { | |
133 if (sync_service_) | |
134 sync_service_->RemoveObserver(this); | |
135 } | |
136 | |
137 /////////////////////////////////////////////////////////////////////////////// | |
138 // ContentsPageView, ProfileSyncServiceObserver implementation: | |
139 | |
140 void ContentPageGtk::OnStateChanged() { | |
141 // If the UI controls are not yet initialized, then don't do anything. This | |
142 // can happen if the Options dialog is up, but the Content tab is not yet | |
143 // clicked. | |
144 if (!initializing_) | |
145 UpdateSyncControls(); | |
146 } | |
147 | |
148 /////////////////////////////////////////////////////////////////////////////// | |
149 // ContentPageGtk, private: | |
150 | |
151 // If |pref_name| is NULL, set the state of all the widgets. (This is used | |
152 // in ContentPageGtk() above to initialize the dialog.) Otherwise, reset the | |
153 // state of the widget for the given preference name, as it has changed. | |
154 void ContentPageGtk::NotifyPrefChanged(const std::string* pref_name) { | |
155 initializing_ = true; | |
156 if (!pref_name || *pref_name == prefs::kPasswordManagerEnabled) { | |
157 if (ask_to_save_passwords_.GetValue()) { | |
158 gtk_toggle_button_set_active( | |
159 GTK_TOGGLE_BUTTON(passwords_asktosave_radio_), TRUE); | |
160 } else { | |
161 gtk_toggle_button_set_active( | |
162 GTK_TOGGLE_BUTTON(passwords_neversave_radio_), TRUE); | |
163 } | |
164 bool isPasswordManagerEnabled = !ask_to_save_passwords_.IsManaged(); | |
165 gtk_widget_set_sensitive(passwords_asktosave_radio_, | |
166 isPasswordManagerEnabled); | |
167 gtk_widget_set_sensitive(passwords_neversave_radio_, | |
168 isPasswordManagerEnabled); | |
169 gtk_widget_set_sensitive(show_passwords_button_, | |
170 isPasswordManagerEnabled || | |
171 ask_to_save_passwords_.GetValue()); | |
172 } | |
173 if (!pref_name || *pref_name == prefs::kAutoFillEnabled) { | |
174 bool disabled_by_policy = form_autofill_enabled_.IsManaged() && | |
175 !form_autofill_enabled_.GetValue(); | |
176 gtk_widget_set_sensitive(autofill_button_, !disabled_by_policy); | |
177 } | |
178 if (browser_defaults::kCanToggleSystemTitleBar && | |
179 (!pref_name || *pref_name == prefs::kUseCustomChromeFrame)) { | |
180 if (use_custom_chrome_frame_.GetValue()) { | |
181 gtk_toggle_button_set_active( | |
182 GTK_TOGGLE_BUTTON(system_title_bar_hide_radio_), TRUE); | |
183 } else { | |
184 gtk_toggle_button_set_active( | |
185 GTK_TOGGLE_BUTTON(system_title_bar_show_radio_), TRUE); | |
186 } | |
187 } | |
188 initializing_ = false; | |
189 } | |
190 | |
191 void ContentPageGtk::Observe(NotificationType type, | |
192 const NotificationSource& source, | |
193 const NotificationDetails& details) { | |
194 if (type == NotificationType::BROWSER_THEME_CHANGED) | |
195 ObserveThemeChanged(); | |
196 else | |
197 OptionsPageBase::Observe(type, source, details); | |
198 } | |
199 | |
200 void ContentPageGtk::ObserveThemeChanged() { | |
201 #if defined(TOOLKIT_GTK) | |
202 GtkThemeProvider* provider = GtkThemeProvider::GetFrom(profile()); | |
203 bool is_gtk_theme = provider->UseGtkTheme(); | |
204 gtk_widget_set_sensitive(gtk_theme_button_, !is_gtk_theme); | |
205 #else | |
206 BrowserThemeProvider* provider = | |
207 reinterpret_cast<BrowserThemeProvider*>(profile()->GetThemeProvider()); | |
208 bool is_gtk_theme = false; | |
209 #endif | |
210 | |
211 bool is_classic_theme = !is_gtk_theme && provider->GetThemeID().empty(); | |
212 gtk_widget_set_sensitive(themes_reset_button_, !is_classic_theme); | |
213 } | |
214 | |
215 GtkWidget* ContentPageGtk::InitPasswordSavingGroup() { | |
216 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | |
217 | |
218 // Ask to save radio button. | |
219 passwords_asktosave_radio_ = gtk_radio_button_new_with_label(NULL, | |
220 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_ASKTOSAVE).c_str()); | |
221 g_signal_connect(passwords_asktosave_radio_, "toggled", | |
222 G_CALLBACK(OnPasswordRadioToggledThunk), this); | |
223 gtk_box_pack_start(GTK_BOX(vbox), passwords_asktosave_radio_, FALSE, | |
224 FALSE, 0); | |
225 | |
226 // Never save radio button. | |
227 passwords_neversave_radio_ = gtk_radio_button_new_with_label_from_widget( | |
228 GTK_RADIO_BUTTON(passwords_asktosave_radio_), | |
229 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_NEVERSAVE).c_str()); | |
230 g_signal_connect(passwords_neversave_radio_, "toggled", | |
231 G_CALLBACK(OnPasswordRadioToggledThunk), this); | |
232 gtk_box_pack_start(GTK_BOX(vbox), passwords_neversave_radio_, FALSE, | |
233 FALSE, 0); | |
234 | |
235 // Add the show passwords button into its own horizontal box so it does not | |
236 // depend on the spacing above. | |
237 GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); | |
238 gtk_container_add(GTK_CONTAINER(vbox), button_hbox); | |
239 show_passwords_button_ = gtk_button_new_with_label( | |
240 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_SHOWPASSWORDS).c_str()); | |
241 g_signal_connect(show_passwords_button_, "clicked", | |
242 G_CALLBACK(OnShowPasswordsButtonClickedThunk), this); | |
243 gtk_box_pack_start(GTK_BOX(button_hbox), show_passwords_button_, FALSE, | |
244 FALSE, 0); | |
245 | |
246 return vbox; | |
247 } | |
248 | |
249 GtkWidget* ContentPageGtk::InitFormAutoFillGroup() { | |
250 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | |
251 | |
252 GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); | |
253 gtk_container_add(GTK_CONTAINER(vbox), button_hbox); | |
254 | |
255 // AutoFill button. | |
256 autofill_button_ = gtk_button_new_with_label( | |
257 l10n_util::GetStringUTF8(IDS_AUTOFILL_OPTIONS).c_str()); | |
258 | |
259 g_signal_connect(G_OBJECT(autofill_button_), "clicked", | |
260 G_CALLBACK(OnAutoFillButtonClickedThunk), this); | |
261 gtk_box_pack_start(GTK_BOX(button_hbox), autofill_button_, FALSE, FALSE, 0); | |
262 | |
263 return vbox; | |
264 } | |
265 | |
266 GtkWidget* ContentPageGtk::InitBrowsingDataGroup() { | |
267 GtkWidget* button_box = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); | |
268 | |
269 // Import button. | |
270 GtkWidget* import_button = gtk_button_new_with_label( | |
271 l10n_util::GetStringUTF8(IDS_OPTIONS_IMPORT_DATA_BUTTON).c_str()); | |
272 g_signal_connect(import_button, "clicked", | |
273 G_CALLBACK(OnImportButtonClickedThunk), this); | |
274 gtk_box_pack_start(GTK_BOX(button_box), import_button, FALSE, FALSE, 0); | |
275 | |
276 return button_box; | |
277 } | |
278 | |
279 GtkWidget* ContentPageGtk::InitThemesGroup() { | |
280 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | |
281 GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); | |
282 | |
283 #if defined(TOOLKIT_GTK) | |
284 // GTK theme button. | |
285 gtk_theme_button_ = gtk_button_new_with_label( | |
286 l10n_util::GetStringUTF8(IDS_THEMES_GTK_BUTTON).c_str()); | |
287 g_signal_connect(gtk_theme_button_, "clicked", | |
288 G_CALLBACK(OnGtkThemeButtonClickedThunk), this); | |
289 gtk_box_pack_start(GTK_BOX(hbox), gtk_theme_button_, FALSE, FALSE, 0); | |
290 #endif | |
291 | |
292 // Reset theme button. | |
293 themes_reset_button_ = gtk_button_new_with_label( | |
294 l10n_util::GetStringUTF8(IDS_THEMES_SET_CLASSIC).c_str()); | |
295 g_signal_connect(themes_reset_button_, "clicked", | |
296 G_CALLBACK(OnResetDefaultThemeButtonClickedThunk), this); | |
297 gtk_box_pack_start(GTK_BOX(hbox), themes_reset_button_, FALSE, FALSE, 0); | |
298 | |
299 // Get themes button. | |
300 GtkWidget* themes_gallery_button = gtk_chrome_link_button_new( | |
301 l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_BUTTON).c_str()); | |
302 g_signal_connect(themes_gallery_button, "clicked", | |
303 G_CALLBACK(OnGetThemesButtonClickedThunk), this); | |
304 gtk_box_pack_start(GTK_BOX(hbox), themes_gallery_button, FALSE, FALSE, 0); | |
305 | |
306 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
307 | |
308 // "Use system title bar and borders" radio buttons. | |
309 if (browser_defaults::kCanToggleSystemTitleBar) { | |
310 // Use system title bar and borders | |
311 system_title_bar_show_radio_ = gtk_radio_button_new_with_label(NULL, | |
312 l10n_util::GetStringUTF8(IDS_SHOW_WINDOW_DECORATIONS_RADIO).c_str()); | |
313 g_signal_connect(system_title_bar_show_radio_, "toggled", | |
314 G_CALLBACK(OnSystemTitleBarRadioToggledThunk), this); | |
315 gtk_box_pack_start(GTK_BOX(vbox), system_title_bar_show_radio_, FALSE, | |
316 FALSE, 0); | |
317 | |
318 // Hide system title bar and use custom borders | |
319 system_title_bar_hide_radio_ = gtk_radio_button_new_with_label_from_widget( | |
320 GTK_RADIO_BUTTON(system_title_bar_show_radio_), | |
321 l10n_util::GetStringUTF8(IDS_HIDE_WINDOW_DECORATIONS_RADIO).c_str()); | |
322 g_signal_connect(system_title_bar_hide_radio_, "toggled", | |
323 G_CALLBACK(OnSystemTitleBarRadioToggledThunk), this); | |
324 gtk_box_pack_start(GTK_BOX(vbox), system_title_bar_hide_radio_, FALSE, | |
325 FALSE, 0); | |
326 } | |
327 | |
328 return vbox; | |
329 } | |
330 | |
331 GtkWidget* ContentPageGtk::InitSyncGroup() { | |
332 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | |
333 | |
334 // Sync label. | |
335 sync_status_label_background_ = gtk_event_box_new(); | |
336 sync_status_label_ = gtk_label_new(""); | |
337 WrapLabelAtAllocationHack(sync_status_label_); | |
338 | |
339 gtk_misc_set_alignment(GTK_MISC(sync_status_label_), 0, 0.5); | |
340 gtk_box_pack_start(GTK_BOX(vbox), sync_status_label_background_, FALSE, | |
341 FALSE, 0); | |
342 gtk_container_add(GTK_CONTAINER(sync_status_label_background_), | |
343 sync_status_label_); | |
344 | |
345 #if !defined(OS_CHROMEOS) | |
346 // Sync action link. | |
347 GtkWidget* link_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); | |
348 sync_action_link_background_ = gtk_event_box_new(); | |
349 sync_action_link_ = gtk_chrome_link_button_new(""); | |
350 g_signal_connect(sync_action_link_, "clicked", | |
351 G_CALLBACK(OnSyncActionLinkClickedThunk), this); | |
352 gtk_box_pack_start(GTK_BOX(vbox), link_hbox, FALSE, FALSE, 0); | |
353 gtk_box_pack_start(GTK_BOX(link_hbox), sync_action_link_background_, FALSE, | |
354 FALSE, 0); | |
355 gtk_container_add(GTK_CONTAINER(sync_action_link_background_), | |
356 sync_action_link_); | |
357 gtk_widget_hide(sync_action_link_background_); | |
358 #endif | |
359 | |
360 // Add the sync button into its own horizontal box so it does not | |
361 // depend on the spacing above. | |
362 GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); | |
363 gtk_container_add(GTK_CONTAINER(vbox), button_hbox); | |
364 sync_start_stop_button_ = gtk_button_new_with_label(""); | |
365 g_signal_connect(sync_start_stop_button_, "clicked", | |
366 G_CALLBACK(OnSyncStartStopButtonClickedThunk), this); | |
367 gtk_box_pack_start(GTK_BOX(button_hbox), sync_start_stop_button_, FALSE, | |
368 FALSE, 0); | |
369 sync_customize_button_ = gtk_button_new_with_label(""); | |
370 g_signal_connect(sync_customize_button_, "clicked", | |
371 G_CALLBACK(OnSyncCustomizeButtonClickedThunk), this); | |
372 gtk_box_pack_start(GTK_BOX(button_hbox), sync_customize_button_, FALSE, | |
373 FALSE, 0); | |
374 | |
375 // Add the privacy dashboard link. | |
376 GtkWidget* dashboard_link_hbox = | |
377 gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); | |
378 GtkWidget* dashboard_link_background = gtk_event_box_new(); | |
379 std::string dashboard_link_label = | |
380 l10n_util::GetStringUTF8(IDS_SYNC_PRIVACY_DASHBOARD_LINK_LABEL); | |
381 privacy_dashboard_link_ = | |
382 gtk_chrome_link_button_new(dashboard_link_label.c_str()); | |
383 g_signal_connect(privacy_dashboard_link_, "clicked", | |
384 G_CALLBACK(OnPrivacyDashboardLinkClickedThunk), this); | |
385 gtk_box_pack_start(GTK_BOX(vbox), dashboard_link_hbox, FALSE, FALSE, 0); | |
386 gtk_box_pack_start(GTK_BOX(dashboard_link_hbox), | |
387 dashboard_link_background, FALSE, FALSE, 0); | |
388 gtk_container_add(GTK_CONTAINER(dashboard_link_background), | |
389 privacy_dashboard_link_); | |
390 | |
391 | |
392 return vbox; | |
393 } | |
394 | |
395 void ContentPageGtk::UpdateSyncControls() { | |
396 DCHECK(sync_service_); | |
397 string16 status_label; | |
398 string16 link_label; | |
399 std::string customize_button_label; | |
400 bool managed = sync_service_->IsManaged(); | |
401 bool sync_setup_completed = sync_service_->HasSyncSetupCompleted(); | |
402 bool status_has_error = sync_ui_util::GetStatusLabels(sync_service_, | |
403 &status_label, &link_label) == sync_ui_util::SYNC_ERROR; | |
404 customize_button_label = | |
405 l10n_util::GetStringUTF8(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL); | |
406 | |
407 std::string start_stop_button_label; | |
408 bool is_start_stop_button_visible = false; | |
409 bool is_start_stop_button_sensitive = false; | |
410 if (sync_setup_completed) { | |
411 start_stop_button_label = | |
412 l10n_util::GetStringUTF8(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); | |
413 #if defined(OS_CHROMEOS) | |
414 is_start_stop_button_visible = false; | |
415 #else | |
416 is_start_stop_button_visible = true; | |
417 #endif | |
418 is_start_stop_button_sensitive = !managed; | |
419 } else if (sync_service_->SetupInProgress()) { | |
420 start_stop_button_label = | |
421 l10n_util::GetStringUTF8(IDS_SYNC_NTP_SETUP_IN_PROGRESS); | |
422 is_start_stop_button_visible = true; | |
423 is_start_stop_button_sensitive = false; | |
424 } else { | |
425 start_stop_button_label = | |
426 l10n_util::GetStringUTF8(IDS_SYNC_START_SYNC_BUTTON_LABEL); | |
427 is_start_stop_button_visible = true; | |
428 is_start_stop_button_sensitive = !managed; | |
429 } | |
430 gtk_widget_set_no_show_all(sync_start_stop_button_, | |
431 !is_start_stop_button_visible); | |
432 if (is_start_stop_button_visible) | |
433 gtk_widget_show(sync_start_stop_button_); | |
434 else | |
435 gtk_widget_hide(sync_start_stop_button_); | |
436 gtk_widget_set_sensitive(sync_start_stop_button_, | |
437 is_start_stop_button_sensitive); | |
438 gtk_button_set_label(GTK_BUTTON(sync_start_stop_button_), | |
439 start_stop_button_label.c_str()); | |
440 | |
441 gtk_label_set_label(GTK_LABEL(sync_status_label_), | |
442 UTF16ToUTF8(status_label).c_str()); | |
443 | |
444 gtk_widget_set_child_visible(sync_customize_button_, | |
445 sync_setup_completed && !status_has_error); | |
446 gtk_button_set_label(GTK_BUTTON(sync_customize_button_), | |
447 customize_button_label.c_str()); | |
448 gtk_widget_set_sensitive(sync_customize_button_, !managed); | |
449 #if !defined(OS_CHROMEOS) | |
450 gtk_chrome_link_button_set_label(GTK_CHROME_LINK_BUTTON(sync_action_link_), | |
451 UTF16ToUTF8(link_label).c_str()); | |
452 if (link_label.empty()) { | |
453 gtk_widget_set_no_show_all(sync_action_link_background_, TRUE); | |
454 gtk_widget_hide(sync_action_link_background_); | |
455 } else { | |
456 gtk_widget_set_no_show_all(sync_action_link_background_, FALSE); | |
457 gtk_widget_show(sync_action_link_background_); | |
458 } | |
459 gtk_widget_set_sensitive(sync_action_link_, !managed); | |
460 #endif | |
461 if (status_has_error) { | |
462 gtk_widget_modify_bg(sync_status_label_background_, GTK_STATE_NORMAL, | |
463 &kSyncLabelErrorBgColor); | |
464 #if !defined(OS_CHROMEOS) | |
465 gtk_widget_modify_bg(sync_action_link_background_, GTK_STATE_NORMAL, | |
466 &kSyncLabelErrorBgColor); | |
467 #endif | |
468 } else { | |
469 gtk_widget_modify_bg(sync_status_label_background_, GTK_STATE_NORMAL, NULL); | |
470 #if !defined(OS_CHROMEOS) | |
471 gtk_widget_modify_bg(sync_action_link_background_, GTK_STATE_NORMAL, NULL); | |
472 #endif | |
473 } | |
474 } | |
475 | |
476 void ContentPageGtk::OnAutoFillButtonClicked(GtkWidget* widget) { | |
477 ShowAutoFillDialog(NULL, profile()->GetPersonalDataManager(), profile()); | |
478 } | |
479 | |
480 void ContentPageGtk::OnImportButtonClicked(GtkWidget* widget) { | |
481 ImportDialogGtk::Show( | |
482 GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
483 profile(), importer::ALL); | |
484 } | |
485 | |
486 void ContentPageGtk::OnGtkThemeButtonClicked(GtkWidget* widget) { | |
487 UserMetricsRecordAction(UserMetricsAction("Options_GtkThemeSet"), | |
488 profile()->GetPrefs()); | |
489 profile()->SetNativeTheme(); | |
490 } | |
491 | |
492 void ContentPageGtk::OnResetDefaultThemeButtonClicked(GtkWidget* widget) { | |
493 UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset"), | |
494 profile()->GetPrefs()); | |
495 profile()->ClearTheme(); | |
496 } | |
497 | |
498 void ContentPageGtk::OnGetThemesButtonClicked(GtkWidget* widget) { | |
499 UserMetricsRecordAction(UserMetricsAction("Options_ThemesGallery"), | |
500 profile()->GetPrefs()); | |
501 #if defined(OS_CHROMEOS) | |
502 // Close options dialog for ChromeOS becuase it is always stacked on top | |
503 // of browser window and blocks user's view. | |
504 chromeos::CloseOptionsWindow(); | |
505 #endif // defined(OS_CHROMEOS) | |
506 | |
507 BrowserList::GetLastActive()->OpenThemeGalleryTabAndActivate(); | |
508 } | |
509 | |
510 void ContentPageGtk::OnSystemTitleBarRadioToggled(GtkWidget* widget) { | |
511 DCHECK(browser_defaults::kCanToggleSystemTitleBar); | |
512 if (initializing_) | |
513 return; | |
514 | |
515 // We get two signals when selecting a radio button, one for the old radio | |
516 // being toggled off and one for the new one being toggled on. Ignore the | |
517 // signal for the toggling off the old button. | |
518 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) | |
519 return; | |
520 | |
521 bool use_custom = gtk_toggle_button_get_active( | |
522 GTK_TOGGLE_BUTTON(system_title_bar_hide_radio_)); | |
523 if (use_custom) { | |
524 UserMetricsRecordAction(UserMetricsAction("Options_CustomFrame_Enable"), | |
525 profile()->GetPrefs()); | |
526 } else { | |
527 UserMetricsRecordAction(UserMetricsAction("Options_CustomFrame_Disable"), | |
528 profile()->GetPrefs()); | |
529 } | |
530 | |
531 use_custom_chrome_frame_.SetValue(use_custom); | |
532 } | |
533 | |
534 void ContentPageGtk::OnShowPasswordsButtonClicked(GtkWidget* widget) { | |
535 ShowPasswordsExceptionsWindow(profile()); | |
536 } | |
537 | |
538 void ContentPageGtk::OnPasswordRadioToggled(GtkWidget* widget) { | |
539 if (initializing_) | |
540 return; | |
541 | |
542 // We get two signals when selecting a radio button, one for the old radio | |
543 // being toggled off and one for the new one being toggled on. Ignore the | |
544 // signal for the toggling off the old button. | |
545 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) | |
546 return; | |
547 | |
548 bool enabled = gtk_toggle_button_get_active( | |
549 GTK_TOGGLE_BUTTON(passwords_asktosave_radio_)); | |
550 if (enabled) { | |
551 UserMetricsRecordAction(UserMetricsAction("Options_PasswordManager_Enable"), | |
552 profile()->GetPrefs()); | |
553 } else { | |
554 UserMetricsRecordAction( | |
555 UserMetricsAction("Options_PasswordManager_Disable"), | |
556 profile()->GetPrefs()); | |
557 } | |
558 ask_to_save_passwords_.SetValue(enabled); | |
559 } | |
560 | |
561 void ContentPageGtk::OnSyncStartStopButtonClicked(GtkWidget* widget) { | |
562 DCHECK(sync_service_ && !sync_service_->IsManaged()); | |
563 | |
564 if (sync_service_->HasSyncSetupCompleted()) { | |
565 GtkWidget* dialog = gtk_message_dialog_new( | |
566 GTK_WINDOW(gtk_widget_get_toplevel(widget)), | |
567 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL), | |
568 GTK_MESSAGE_WARNING, | |
569 GTK_BUTTONS_NONE, | |
570 "%s", | |
571 l10n_util::GetStringFUTF8( | |
572 IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL, | |
573 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str()); | |
574 gtk_util::ApplyMessageDialogQuirks(dialog); | |
575 gtk_window_set_title(GTK_WINDOW(dialog), | |
576 l10n_util::GetStringUTF8( | |
577 IDS_SYNC_STOP_SYNCING_DIALOG_TITLE).c_str()); | |
578 gtk_dialog_add_buttons( | |
579 GTK_DIALOG(dialog), | |
580 l10n_util::GetStringUTF8(IDS_CANCEL).c_str(), | |
581 GTK_RESPONSE_REJECT, | |
582 l10n_util::GetStringUTF8( | |
583 IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL).c_str(), | |
584 GTK_RESPONSE_ACCEPT, | |
585 NULL); | |
586 | |
587 g_signal_connect(dialog, "response", | |
588 G_CALLBACK(OnStopSyncDialogResponseThunk), this); | |
589 | |
590 gtk_util::ShowDialog(dialog); | |
591 return; | |
592 } else { | |
593 sync_service_->ShowLoginDialog(NULL); | |
594 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS); | |
595 } | |
596 } | |
597 | |
598 void ContentPageGtk::OnSyncCustomizeButtonClicked(GtkWidget* widget) { | |
599 // sync_customize_button_ should be invisible if sync is not yet set up. | |
600 DCHECK(sync_service_ && !sync_service_->IsManaged() && | |
601 sync_service_->HasSyncSetupCompleted()); | |
602 sync_service_->ShowConfigure(NULL); | |
603 } | |
604 | |
605 void ContentPageGtk::OnSyncActionLinkClicked(GtkWidget* widget) { | |
606 DCHECK(sync_service_ && !sync_service_->IsManaged()); | |
607 sync_service_->ShowConfigure(NULL); | |
608 } | |
609 | |
610 void ContentPageGtk::OnStopSyncDialogResponse(GtkWidget* widget, int response) { | |
611 if (response == GTK_RESPONSE_ACCEPT) { | |
612 sync_service_->DisableForUser(); | |
613 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); | |
614 } | |
615 gtk_widget_destroy(widget); | |
616 } | |
617 | |
618 void ContentPageGtk::OnPrivacyDashboardLinkClicked(GtkWidget* widget) { | |
619 BrowserList::GetLastActive()->OpenPrivacyDashboardTabAndActivate(); | |
620 } | |
OLD | NEW |