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