diff options
author | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-20 06:21:20 +0000 |
---|---|---|
committer | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-20 06:21:20 +0000 |
commit | 481f33edad1063047b34c20cc6c2ca6f3ee8bdec (patch) | |
tree | 1fb621bca51abb284461d0ecb13aa3a943ed1856 | |
parent | 7747414c115302f2dad064079da3a7c5495901cb (diff) | |
download | chromium_src-481f33edad1063047b34c20cc6c2ca6f3ee8bdec.zip chromium_src-481f33edad1063047b34c20cc6c2ca6f3ee8bdec.tar.gz chromium_src-481f33edad1063047b34c20cc6c2ca6f3ee8bdec.tar.bz2 |
Add Personal Stuff tab page to Options in Linux.
Following the same approach as the general tab page..
BUG=11507
TEST=The Personal stuff tab is fully functioning, the prefs save correctly.
Review URL: http://codereview.chromium.org/125105
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18892 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/gtk/options/content_page_gtk.cc | 260 | ||||
-rw-r--r-- | chrome/browser/gtk/options/content_page_gtk.h | 78 | ||||
-rw-r--r-- | chrome/browser/gtk/options/options_window_gtk.cc | 18 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 |
4 files changed, 352 insertions, 6 deletions
diff --git a/chrome/browser/gtk/options/content_page_gtk.cc b/chrome/browser/gtk/options/content_page_gtk.cc new file mode 100644 index 0000000..310a3a7 --- /dev/null +++ b/chrome/browser/gtk/options/content_page_gtk.cc @@ -0,0 +1,260 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/gtk/options/content_page_gtk.h" + +#include "app/l10n_util.h" +#include "app/resource_bundle.h" +#include "base/gfx/gtk_util.h" +#include "chrome/browser/gtk/clear_browsing_data_dialog_gtk.h" +#include "chrome/browser/gtk/import_dialog_gtk.h" +#include "chrome/browser/gtk/options/options_layout_gtk.h" +#include "chrome/common/gtk_util.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" +#include "chrome/common/url_constants.h" +#include "grit/app_resources.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" + +/////////////////////////////////////////////////////////////////////////////// +// ContentPageGtk, public: + +ContentPageGtk::ContentPageGtk(Profile* profile) + : OptionsPageBase(profile), + initializing_(true) { + + // Prepare the group options layout. + OptionsLayoutBuilderGtk options_builder(4); + options_builder.AddOptionGroup( + l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_GROUP_NAME), + InitPasswordSavingGroup(), false); + options_builder.AddOptionGroup( + l10n_util::GetStringUTF8(IDS_AUTOFILL_SETTING_WINDOWS_GROUP_NAME), + InitFormAutofillGroup(), false); + options_builder.AddOptionGroup( + l10n_util::GetStringUTF8(IDS_OPTIONS_BROWSING_DATA_GROUP_NAME), + InitBrowsingDataGroup(), false); + options_builder.AddOptionGroup( + l10n_util::GetStringUTF8(IDS_THEMES_GROUP_NAME), + InitThemesGroup(), false); + page_ = options_builder.get_page_widget(); + + // Add preferences observers. + ask_to_save_passwords_.Init(prefs::kPasswordManagerEnabled, + profile->GetPrefs(), this); + ask_to_save_form_autofill_.Init(prefs::kFormAutofillEnabled, + profile->GetPrefs(), this); + + // Load initial values + NotifyPrefChanged(NULL); +} + +ContentPageGtk::~ContentPageGtk() { +} + +void ContentPageGtk::NotifyPrefChanged(const std::wstring* pref_name) { + initializing_ = true; + if (!pref_name || *pref_name == prefs::kPasswordManagerEnabled) { + if (ask_to_save_passwords_.GetValue()) { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(passwords_asktosave_radio_), TRUE); + } else { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(passwords_neversave_radio_), TRUE); + } + } + if (!pref_name || *pref_name == prefs::kFormAutofillEnabled) { + if (ask_to_save_form_autofill_.GetValue()) { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(form_autofill_asktosave_radio_), TRUE); + } else { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(form_autofill_neversave_radio_), TRUE); + } + } + initializing_ = false; +} + +/////////////////////////////////////////////////////////////////////////////// +// ContentPageGtk, private: + +GtkWidget* ContentPageGtk::InitPasswordSavingGroup() { + GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + + // Ask to save radio button. + passwords_asktosave_radio_ = gtk_radio_button_new_with_label(NULL, + l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_ASKTOSAVE).c_str()); + g_signal_connect(G_OBJECT(passwords_asktosave_radio_), "toggled", + G_CALLBACK(OnPasswordRadioToggled), this); + gtk_box_pack_start(GTK_BOX(vbox), passwords_asktosave_radio_, FALSE, + FALSE, 0); + + // Never save radio button. + passwords_neversave_radio_ = gtk_radio_button_new_with_label_from_widget( + GTK_RADIO_BUTTON(passwords_asktosave_radio_), + l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_NEVERSAVE).c_str()); + g_signal_connect(G_OBJECT(passwords_neversave_radio_), "toggled", + G_CALLBACK(OnPasswordRadioToggled), this); + gtk_box_pack_start(GTK_BOX(vbox), passwords_neversave_radio_, FALSE, + FALSE, 0); + + // Add the exceptions button into its own horizontal box so it does not + // depend on the spacing above. + GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); + gtk_container_add(GTK_CONTAINER(vbox), button_hbox); + GtkWidget* passwords_exceptions_button = gtk_button_new_with_label( + l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_EXCEPTIONS).c_str()); + g_signal_connect(G_OBJECT(passwords_exceptions_button), "clicked", + G_CALLBACK(OnPasswordsExceptionsButtonClicked), this); + gtk_box_pack_start(GTK_BOX(button_hbox), passwords_exceptions_button, FALSE, + FALSE, 0); + + return vbox; +} + +GtkWidget* ContentPageGtk::InitFormAutofillGroup() { + GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + + // Ask to save radio button. + form_autofill_asktosave_radio_ = gtk_radio_button_new_with_label(NULL, + l10n_util::GetStringUTF8(IDS_OPTIONS_AUTOFILL_SAVE).c_str()); + g_signal_connect(G_OBJECT(form_autofill_asktosave_radio_), "toggled", + G_CALLBACK(OnAutofillRadioToggled), this); + gtk_box_pack_start(GTK_BOX(vbox), form_autofill_asktosave_radio_, FALSE, + FALSE, 0); + + // Never save radio button. + form_autofill_neversave_radio_ = gtk_radio_button_new_with_label_from_widget( + GTK_RADIO_BUTTON(form_autofill_asktosave_radio_), + l10n_util::GetStringUTF8(IDS_OPTIONS_AUTOFILL_NEVERSAVE).c_str()); + g_signal_connect(G_OBJECT(form_autofill_neversave_radio_), "toggled", + G_CALLBACK(OnAutofillRadioToggled), this); + gtk_box_pack_start(GTK_BOX(vbox), form_autofill_neversave_radio_, FALSE, + FALSE, 0); + + return vbox; +} + +GtkWidget* ContentPageGtk::InitBrowsingDataGroup() { + GtkWidget* vbox = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); + + // Browsing data label. + GtkWidget* browsing_data_label = gtk_label_new( + l10n_util::GetStringUTF8(IDS_OPTIONS_BROWSING_DATA_INFO).c_str()); + gtk_label_set_line_wrap(GTK_LABEL(browsing_data_label), TRUE); + gtk_misc_set_alignment(GTK_MISC(browsing_data_label), 0, 0); + gtk_box_pack_start(GTK_BOX(vbox), browsing_data_label, FALSE, FALSE, 0); + + // Horizontal two button layout. + GtkWidget* button_hbox = gtk_hbox_new(FALSE, gtk_util::kControlSpacing); + gtk_container_add(GTK_CONTAINER(vbox), button_hbox); + + // Import button. + GtkWidget* import_button = gtk_button_new_with_label( + l10n_util::GetStringUTF8(IDS_OPTIONS_IMPORT_DATA_BUTTON).c_str()); + g_signal_connect(G_OBJECT(import_button), "clicked", + G_CALLBACK(OnImportButtonClicked), this); + gtk_box_pack_start(GTK_BOX(button_hbox), import_button, FALSE, FALSE, 0); + + // Clear data button. + GtkWidget* clear_data_button = gtk_button_new_with_label( + l10n_util::GetStringUTF8(IDS_OPTIONS_CLEAR_DATA_BUTTON).c_str()); + g_signal_connect(G_OBJECT(clear_data_button), "clicked", + G_CALLBACK(OnClearBrowsingDataButtonClicked), this); + gtk_box_pack_start(GTK_BOX(button_hbox), clear_data_button, FALSE, FALSE, 0); + + return vbox; +} + +GtkWidget* ContentPageGtk::InitThemesGroup() { + GtkWidget* hbox = gtk_hbox_new(FALSE, gtk_util::kLabelSpacing); + + // Reset themes button. + GtkWidget* themes_reset_button = gtk_button_new_with_label( + l10n_util::GetStringUTF8(IDS_THEMES_RESET_BUTTON).c_str()); + g_signal_connect(G_OBJECT(themes_reset_button), "clicked", + G_CALLBACK(OnResetDefaultThemeButtonClicked), this); + gtk_box_pack_start(GTK_BOX(hbox), themes_reset_button, FALSE, FALSE, 0); + + return hbox; +} + +// static +void ContentPageGtk::OnImportButtonClicked(GtkButton* widget, + ContentPageGtk* page) { + ImportDialogGtk::Show( + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), + page->profile()); +} + +// static +void ContentPageGtk::OnClearBrowsingDataButtonClicked(GtkButton* widget, + ContentPageGtk* page) { + ClearBrowsingDataDialogGtk::Show( + GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(widget))), + page->profile()); +} + +// static +void ContentPageGtk::OnResetDefaultThemeButtonClicked(GtkButton* widget, + ContentPageGtk* page) { + page->UserMetricsRecordAction(L"Options_ThemesReset", + page->profile()->GetPrefs()); + page->profile()->ClearTheme(); +} + +// static +void ContentPageGtk::OnPasswordsExceptionsButtonClicked(GtkButton* widget, + ContentPageGtk* page) { + NOTIMPLEMENTED(); +} + +// static +void ContentPageGtk::OnPasswordRadioToggled(GtkToggleButton* widget, + ContentPageGtk* page) { + if (page->initializing_) + return; + + // We get two signals when selecting a radio button, one for the old radio + // being toggled off and one for the new one being toggled on. Ignore the + // signal for the toggling off the old button. + if (!gtk_toggle_button_get_active(widget)) + return; + + bool enabled = gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(page->passwords_asktosave_radio_)); + if (enabled) { + page->UserMetricsRecordAction(L"Options_PasswordManager_Enable", + page->profile()->GetPrefs()); + } else { + page->UserMetricsRecordAction(L"Options_PasswordManager_Disable", + page->profile()->GetPrefs()); + } + page->ask_to_save_passwords_.SetValue(enabled); +} + +// static +void ContentPageGtk::OnAutofillRadioToggled(GtkToggleButton* widget, + ContentPageGtk* page) { + if (page->initializing_) + return; + + // We get two signals when selecting a radio button, one for the old radio + // being toggled off and one for the new one being toggled on. Ignore the + // signal for the toggling off the old button. + if (!gtk_toggle_button_get_active(widget)) + return; + + bool enabled = gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(page->form_autofill_asktosave_radio_)); + if (enabled) { + page->UserMetricsRecordAction(L"Options_FormAutofill_Enable", + page->profile()->GetPrefs()); + } else { + page->UserMetricsRecordAction(L"Options_FormAutofill_Disable", + page->profile()->GetPrefs()); + } + page->ask_to_save_form_autofill_.SetValue(enabled); +} diff --git a/chrome/browser/gtk/options/content_page_gtk.h b/chrome/browser/gtk/options/content_page_gtk.h new file mode 100644 index 0000000..95b044e0 --- /dev/null +++ b/chrome/browser/gtk/options/content_page_gtk.h @@ -0,0 +1,78 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_GTK_OPTIONS_CONTENT_PAGE_GTK_H_ +#define CHROME_BROWSER_GTK_OPTIONS_CONTENT_PAGE_GTK_H_ + +#include <gtk/gtk.h> + +#include "chrome/browser/options_page_base.h" +#include "chrome/browser/profile.h" +#include "chrome/common/pref_member.h" + +class ContentPageGtk : public OptionsPageBase { + public: + explicit ContentPageGtk(Profile* profile); + ~ContentPageGtk(); + + GtkWidget* get_page_widget() const { + return page_; + } + + private: + // Overridden from OptionsPageBase. + virtual void NotifyPrefChanged(const std::wstring* pref_name); + + // Initialize the option group widgets, return their container. + GtkWidget* InitPasswordSavingGroup(); + GtkWidget* InitFormAutofillGroup(); + GtkWidget* InitBrowsingDataGroup(); + GtkWidget* InitThemesGroup(); + + // Callback for import button. + static void OnImportButtonClicked(GtkButton* widget, ContentPageGtk* page); + + // Callback for clear data button. + static void OnClearBrowsingDataButtonClicked(GtkButton* widget, + ContentPageGtk* page); + + // Callback for reset default theme button. + static void OnResetDefaultThemeButtonClicked(GtkButton* widget, + ContentPageGtk* page); + + // Callback for passwords exceptions button. + static void OnPasswordsExceptionsButtonClicked(GtkButton* widget, + ContentPageGtk* page); + + // Callback for password radio buttons. + static void OnPasswordRadioToggled(GtkToggleButton* widget, + ContentPageGtk* page); + + // Callback for form autofill radio buttons. + static void OnAutofillRadioToggled(GtkToggleButton* widget, + ContentPageGtk* page); + + // Widgets for the Password saving group. + GtkWidget* passwords_asktosave_radio_; + GtkWidget* passwords_neversave_radio_; + + // Widget for the Form Autofill group. + GtkWidget* form_autofill_asktosave_radio_; + GtkWidget* form_autofill_neversave_radio_; + + // The parent GtkTable widget + GtkWidget* page_; + + // Pref members. + BooleanPrefMember ask_to_save_passwords_; + BooleanPrefMember ask_to_save_form_autofill_; + + // Flag to ignore gtk callbacks while we are loading prefs, to avoid + // then turning around and saving them again. + bool initializing_; + + DISALLOW_COPY_AND_ASSIGN(ContentPageGtk); +}; + +#endif // CHROME_BROWSER_GTK_OPTIONS_CONTENT_PAGE_GTK_H_ diff --git a/chrome/browser/gtk/options/options_window_gtk.cc b/chrome/browser/gtk/options/options_window_gtk.cc index 5e99ec7..93c13aa 100644 --- a/chrome/browser/gtk/options/options_window_gtk.cc +++ b/chrome/browser/gtk/options/options_window_gtk.cc @@ -9,6 +9,7 @@ #include "app/l10n_util.h" #include "base/message_loop.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/gtk/options/content_page_gtk.h" #include "chrome/browser/gtk/options/general_page_gtk.h" #include "chrome/browser/profile.h" #include "chrome/common/gtk_util.h" @@ -25,7 +26,7 @@ /////////////////////////////////////////////////////////////////////////////// // OptionsWindowGtk // -// The contents of the Options dialog window. +// The contents of the Options dialog window. class OptionsWindowGtk { public: @@ -48,18 +49,21 @@ class OptionsWindowGtk { // This function gets called when stats reporting option is changed. void LoggingChanged(GtkWidget* widget); - // The options dialog + // The options dialog. GtkWidget *dialog_; - // The container of the option pages + // The container of the option pages. GtkWidget *notebook_; // The Profile associated with these options. Profile* profile_; - // The options pages + // The general page. GeneralPageGtk general_page_; + // The content page. + ContentPageGtk content_page_; + // The last page the user was on when they opened the Options window. IntegerPrefMember last_selected_page_; @@ -75,7 +79,9 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile) // Always show preferences for the original profile. Most state when off // the record comes from the original profile, but we explicitly use // the original profile to avoid potential problems. - : profile_(profile->GetOriginalProfile()), general_page_(profile_) { + : profile_(profile->GetOriginalProfile()), + general_page_(profile_), + content_page_(profile_) { // The download manager needs to be initialized before the contents of the // Options Window are created. profile_->GetDownloadManager(); @@ -107,7 +113,7 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile) gtk_notebook_append_page( GTK_NOTEBOOK(notebook_), - gtk_label_new("TODO content"), + content_page_.get_page_widget(), gtk_label_new( l10n_util::GetStringUTF8(IDS_OPTIONS_CONTENT_TAB_LABEL).c_str())); diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 346986f..7bb23ec 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1009,6 +1009,8 @@ 'browser/gtk/menu_gtk.h', 'browser/gtk/nine_box.cc', 'browser/gtk/nine_box.h', + 'browser/gtk/options/content_page_gtk.cc', + 'browser/gtk/options/content_page_gtk.h', 'browser/gtk/options/general_page_gtk.cc', 'browser/gtk/options/general_page_gtk.h', 'browser/gtk/options/options_layout_gtk.cc', |