| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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 "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" |
| 9 #include "base/gfx/gtk_util.h" |
| 10 #include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h" |
| 11 #include "chrome/browser/gtk/import_dialog_gtk.h" |
| 12 #include "chrome/browser/gtk/options/options_layout_gtk.h" |
| 13 #include "chrome/common/gtk_util.h" |
| 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/common/pref_service.h" |
| 16 #include "chrome/common/url_constants.h" |
| 17 #include "grit/app_resources.h" |
| 18 #include "grit/chromium_strings.h" |
| 19 #include "grit/generated_resources.h" |
| 20 |
| 21 /////////////////////////////////////////////////////////////////////////////// |
| 22 // ContentPageGtk, public: |
| 23 |
| 24 ContentPageGtk::ContentPageGtk(Profile* profile) |
| 25 : OptionsPageBase(profile), |
| 26 initializing_(true) { |
| 27 |
| 28 // Prepare the group options layout. |
| 29 OptionsLayoutBuilderGtk options_builder(4); |
| 30 options_builder.AddOptionGroup( |
| 31 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_GROUP_NAME), |
| 32 InitPasswordSavingGroup(), false); |
| 33 options_builder.AddOptionGroup( |
| 34 l10n_util::GetStringUTF8(IDS_AUTOFILL_SETTING_WINDOWS_GROUP_NAME), |
| 35 InitFormAutofillGroup(), false); |
| 36 options_builder.AddOptionGroup( |
| 37 l10n_util::GetStringUTF8(IDS_OPTIONS_BROWSING_DATA_GROUP_NAME), |
| 38 InitBrowsingDataGroup(), false); |
| 39 options_builder.AddOptionGroup( |
| 40 l10n_util::GetStringUTF8(IDS_THEMES_GROUP_NAME), |
| 41 InitThemesGroup(), false); |
| 42 page_ = options_builder.get_page_widget(); |
| 43 |
| 44 // Add preferences observers. |
| 45 ask_to_save_passwords_.Init(prefs::kPasswordManagerEnabled, |
| 46 profile->GetPrefs(), this); |
| 47 ask_to_save_form_autofill_.Init(prefs::kFormAutofillEnabled, |
| 48 profile->GetPrefs(), this); |
| 49 |
| 50 // Load initial values |
| 51 NotifyPrefChanged(NULL); |
| 52 } |
| 53 |
| 54 ContentPageGtk::~ContentPageGtk() { |
| 55 } |
| 56 |
| 57 void ContentPageGtk::NotifyPrefChanged(const std::wstring* pref_name) { |
| 58 initializing_ = true; |
| 59 if (!pref_name || *pref_name == prefs::kPasswordManagerEnabled) { |
| 60 if (ask_to_save_passwords_.GetValue()) { |
| 61 gtk_toggle_button_set_active( |
| 62 GTK_TOGGLE_BUTTON(passwords_asktosave_radio_), TRUE); |
| 63 } else { |
| 64 gtk_toggle_button_set_active( |
| 65 GTK_TOGGLE_BUTTON(passwords_neversave_radio_), TRUE); |
| 66 } |
| 67 } |
| 68 if (!pref_name || *pref_name == prefs::kFormAutofillEnabled) { |
| 69 if (ask_to_save_form_autofill_.GetValue()) { |
| 70 gtk_toggle_button_set_active( |
| 71 GTK_TOGGLE_BUTTON(form_autofill_asktosave_radio_), TRUE); |
| 72 } else { |
| 73 gtk_toggle_button_set_active( |
| 74 GTK_TOGGLE_BUTTON(form_autofill_neversave_radio_), TRUE); |
| 75 } |
| 76 } |
| 77 initializing_ = false; |
| 78 } |
| 79 |
| 80 /////////////////////////////////////////////////////////////////////////////// |
| 81 // ContentPageGtk, private: |
| 82 |
| 83 GtkWidget* ContentPageGtk::InitPasswordSavingGroup() { |
| 84 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
| 85 |
| 86 // Ask to save radio button. |
| 87 passwords_asktosave_radio_ = gtk_radio_button_new_with_label(NULL, |
| 88 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_ASKTOSAVE).c_str()); |
| 89 g_signal_connect(G_OBJECT(passwords_asktosave_radio_), "toggled", |
| 90 G_CALLBACK(OnPasswordRadioToggled), this); |
| 91 gtk_box_pack_start(GTK_BOX(vbox), passwords_asktosave_radio_, FALSE, |
| 92 FALSE, 0); |
| 93 |
| 94 // Never save radio button. |
| 95 passwords_neversave_radio_ = gtk_radio_button_new_with_label_from_widget( |
| 96 GTK_RADIO_BUTTON(passwords_asktosave_radio_), |
| 97 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_NEVERSAVE).c_str()); |
| 98 g_signal_connect(G_OBJECT(passwords_neversave_radio_), "toggled", |
| 99 G_CALLBACK(OnPasswordRadioToggled), this); |
| 100 gtk_box_pack_start(GTK_BOX(vbox), passwords_neversave_radio_, FALSE, |
| 101 FALSE, 0); |
| 102 |
| 103 // Add the exceptions button into its own horizontal box so it does not |
| 104 // depend on the spacing above. |
| 105 GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); |
| 106 gtk_container_add(GTK_CONTAINER(vbox), button_hbox); |
| 107 GtkWidget* passwords_exceptions_button = gtk_button_new_with_label( |
| 108 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_EXCEPTIONS).c_str()); |
| 109 g_signal_connect(G_OBJECT(passwords_exceptions_button), "clicked", |
| 110 G_CALLBACK(OnPasswordsExceptionsButtonClicked), this); |
| 111 gtk_box_pack_start(GTK_BOX(button_hbox), passwords_exceptions_button, FALSE, |
| 112 FALSE, 0); |
| 113 |
| 114 return vbox; |
| 115 } |
| 116 |
| 117 GtkWidget* ContentPageGtk::InitFormAutofillGroup() { |
| 118 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
| 119 |
| 120 // Ask to save radio button. |
| 121 form_autofill_asktosave_radio_ = gtk_radio_button_new_with_label(NULL, |
| 122 l10n_util::GetStringUTF8(IDS_OPTIONS_AUTOFILL_SAVE).c_str()); |
| 123 g_signal_connect(G_OBJECT(form_autofill_asktosave_radio_), "toggled", |
| 124 G_CALLBACK(OnAutofillRadioToggled), this); |
| 125 gtk_box_pack_start(GTK_BOX(vbox), form_autofill_asktosave_radio_, FALSE, |
| 126 FALSE, 0); |
| 127 |
| 128 // Never save radio button. |
| 129 form_autofill_neversave_radio_ = gtk_radio_button_new_with_label_from_widget( |
| 130 GTK_RADIO_BUTTON(form_autofill_asktosave_radio_), |
| 131 l10n_util::GetStringUTF8(IDS_OPTIONS_AUTOFILL_NEVERSAVE).c_str()); |
| 132 g_signal_connect(G_OBJECT(form_autofill_neversave_radio_), "toggled", |
| 133 G_CALLBACK(OnAutofillRadioToggled), this); |
| 134 gtk_box_pack_start(GTK_BOX(vbox), form_autofill_neversave_radio_, FALSE, |
| 135 FALSE, 0); |
| 136 |
| 137 return vbox; |
| 138 } |
| 139 |
| 140 GtkWidget* ContentPageGtk::InitBrowsingDataGroup() { |
| 141 GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); |
| 142 |
| 143 // Browsing data label. |
| 144 GtkWidget* browsing_data_label = gtk_label_new( |
| 145 l10n_util::GetStringUTF8(IDS_OPTIONS_BROWSING_DATA_INFO).c_str()); |
| 146 gtk_label_set_line_wrap(GTK_LABEL(browsing_data_label), TRUE); |
| 147 gtk_misc_set_alignment(GTK_MISC(browsing_data_label), 0, 0); |
| 148 gtk_box_pack_start(GTK_BOX(vbox), browsing_data_label, FALSE, FALSE, 0); |
| 149 |
| 150 // Horizontal two button layout. |
| 151 GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); |
| 152 gtk_container_add(GTK_CONTAINER(vbox), button_hbox); |
| 153 |
| 154 // Import button. |
| 155 GtkWidget* import_button = gtk_button_new_with_label( |
| 156 l10n_util::GetStringUTF8(IDS_OPTIONS_IMPORT_DATA_BUTTON).c_str()); |
| 157 g_signal_connect(G_OBJECT(import_button), "clicked", |
| 158 G_CALLBACK(OnImportButtonClicked), this); |
| 159 gtk_box_pack_start(GTK_BOX(button_hbox), import_button, FALSE, FALSE, 0); |
| 160 |
| 161 // Clear data button. |
| 162 GtkWidget* clear_data_button = gtk_button_new_with_label( |
| 163 l10n_util::GetStringUTF8(IDS_OPTIONS_CLEAR_DATA_BUTTON).c_str()); |
| 164 g_signal_connect(G_OBJECT(clear_data_button), "clicked", |
| 165 G_CALLBACK(OnClearBrowsingDataButtonClicked), this); |
| 166 gtk_box_pack_start(GTK_BOX(button_hbox), clear_data_button, FALSE, FALSE, 0); |
| 167 |
| 168 return vbox; |
| 169 } |
| 170 |
| 171 GtkWidget* ContentPageGtk::InitThemesGroup() { |
| 172 GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); |
| 173 |
| 174 // Reset themes button. |
| 175 GtkWidget* themes_reset_button = gtk_button_new_with_label( |
| 176 l10n_util::GetStringUTF8(IDS_THEMES_RESET_BUTTON).c_str()); |
| 177 g_signal_connect(G_OBJECT(themes_reset_button), "clicked", |
| 178 G_CALLBACK(OnResetDefaultThemeButtonClicked), this); |
| 179 gtk_box_pack_start(GTK_BOX(hbox), themes_reset_button, FALSE, FALSE, 0); |
| 180 |
| 181 return hbox; |
| 182 } |
| 183 |
| 184 // static |
| 185 void ContentPageGtk::OnImportButtonClicked(GtkButton* widget, |
| 186 ContentPageGtk* page) { |
| 187 ImportDialogGtk::Show( |
| 188 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), |
| 189 page->profile()); |
| 190 } |
| 191 |
| 192 // static |
| 193 void ContentPageGtk::OnClearBrowsingDataButtonClicked(GtkButton* widget, |
| 194 ContentPageGtk* page) { |
| 195 ClearBrowsingDataDialogGtk::Show( |
| 196 GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), |
| 197 page->profile()); |
| 198 } |
| 199 |
| 200 // static |
| 201 void ContentPageGtk::OnResetDefaultThemeButtonClicked(GtkButton* widget, |
| 202 ContentPageGtk* page) { |
| 203 page->UserMetricsRecordAction(L"Options_ThemesReset", |
| 204 page->profile()->GetPrefs()); |
| 205 page->profile()->ClearTheme(); |
| 206 } |
| 207 |
| 208 // static |
| 209 void ContentPageGtk::OnPasswordsExceptionsButtonClicked(GtkButton* widget, |
| 210 ContentPageGtk* page) { |
| 211 NOTIMPLEMENTED(); |
| 212 } |
| 213 |
| 214 // static |
| 215 void ContentPageGtk::OnPasswordRadioToggled(GtkToggleButton* widget, |
| 216 ContentPageGtk* page) { |
| 217 if (page->initializing_) |
| 218 return; |
| 219 |
| 220 // We get two signals when selecting a radio button, one for the old radio |
| 221 // being toggled off and one for the new one being toggled on. Ignore the |
| 222 // signal for the toggling off the old button. |
| 223 if (!gtk_toggle_button_get_active(widget)) |
| 224 return; |
| 225 |
| 226 bool enabled = gtk_toggle_button_get_active( |
| 227 GTK_TOGGLE_BUTTON(page->passwords_asktosave_radio_)); |
| 228 if (enabled) { |
| 229 page->UserMetricsRecordAction(L"Options_PasswordManager_Enable", |
| 230 page->profile()->GetPrefs()); |
| 231 } else { |
| 232 page->UserMetricsRecordAction(L"Options_PasswordManager_Disable", |
| 233 page->profile()->GetPrefs()); |
| 234 } |
| 235 page->ask_to_save_passwords_.SetValue(enabled); |
| 236 } |
| 237 |
| 238 // static |
| 239 void ContentPageGtk::OnAutofillRadioToggled(GtkToggleButton* widget, |
| 240 ContentPageGtk* page) { |
| 241 if (page->initializing_) |
| 242 return; |
| 243 |
| 244 // We get two signals when selecting a radio button, one for the old radio |
| 245 // being toggled off and one for the new one being toggled on. Ignore the |
| 246 // signal for the toggling off the old button. |
| 247 if (!gtk_toggle_button_get_active(widget)) |
| 248 return; |
| 249 |
| 250 bool enabled = gtk_toggle_button_get_active( |
| 251 GTK_TOGGLE_BUTTON(page->form_autofill_asktosave_radio_)); |
| 252 if (enabled) { |
| 253 page->UserMetricsRecordAction(L"Options_FormAutofill_Enable", |
| 254 page->profile()->GetPrefs()); |
| 255 } else { |
| 256 page->UserMetricsRecordAction(L"Options_FormAutofill_Disable", |
| 257 page->profile()->GetPrefs()); |
| 258 } |
| 259 page->ask_to_save_form_autofill_.SetValue(enabled); |
| 260 } |
| OLD | NEW |