diff options
-rw-r--r-- | app/l10n_util.cc | 5 | ||||
-rw-r--r-- | app/l10n_util.h | 1 | ||||
-rw-r--r-- | chrome/browser/browser.vcproj | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.cc | 415 | ||||
-rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.h | 106 | ||||
-rw-r--r-- | chrome/browser/gtk/options/options_layout_gtk.cc | 53 | ||||
-rw-r--r-- | chrome/browser/gtk/options/options_layout_gtk.h | 32 | ||||
-rw-r--r-- | chrome/browser/gtk/options/options_window_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/browser/options_page_base.cc | 36 | ||||
-rw-r--r-- | chrome/browser/options_page_base.h | 55 | ||||
-rw-r--r-- | chrome/browser/views/options/options_page_view.cc | 19 | ||||
-rw-r--r-- | chrome/browser/views/options/options_page_view.h | 30 | ||||
-rw-r--r-- | chrome/chrome.gyp | 6 |
13 files changed, 726 insertions, 48 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc index 1fb06af..81fb7f4 100644 --- a/app/l10n_util.cc +++ b/app/l10n_util.cc @@ -304,6 +304,11 @@ std::string GetStringUTF8(int message_id) { return UTF16ToUTF8(rb.GetLocalizedString(message_id)); } +string16 GetStringUTF16(int message_id) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + return rb.GetLocalizedString(message_id); +} + static string16 GetStringF(int message_id, const string16& a, const string16& b, diff --git a/app/l10n_util.h b/app/l10n_util.h index 0fe391c..69d3271 100644 --- a/app/l10n_util.h +++ b/app/l10n_util.h @@ -67,6 +67,7 @@ std::wstring GetLocalName(const std::string& locale_code_str, // Pulls resource string from the string bundle and returns it. std::wstring GetString(int message_id); std::string GetStringUTF8(int message_id); +string16 GetStringUTF16(int message_id); // Get a resource string and replace $1-$2-$3 with |a| and |b| // respectively. Additionally, $$ is replaced by $. diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 52afa04..4ee28a7 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -808,6 +808,14 @@ > </File> <File + RelativePath=".\options_page_base.cc" + > + </File> + <File + RelativePath=".\options_page_base.h" + > + </File> + <File RelativePath=".\options_window.h" > </File> diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc new file mode 100644 index 0000000..95fdeef --- /dev/null +++ b/chrome/browser/gtk/options/general_page_gtk.cc @@ -0,0 +1,415 @@ +// Copyright (c) 2006-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/general_page_gtk.h" + +#include "app/l10n_util.h" +#include "chrome/browser/gtk/options/options_layout_gtk.h" +#include "chrome/browser/net/url_fixer_upper.h" +#include "chrome/browser/session_startup_pref.h" +#include "chrome/browser/shell_integration.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" +#include "chrome/common/url_constants.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" + +// TODO(mattm): spacing constants should be moved into a system-wide location +namespace { + +// Spacing between options of the same group +const int kOptionSpacing = 6; + +// Horizontal spacing between a label and it's control +const int kLabelSpacing = 12; + +// Markup for the text showing the current state of the default browser +const char kDefaultBrowserLabelMarkup[] = "<span color='#%s'>%s</span>"; + +// Color of the default browser text when Chromium is the default browser +const char kDefaultBrowserLabelColor[] = "008700"; + +// Color of the default browser text when Chromium is not the default browser +const char kNotDefaultBrowserLabelColor[] = "870000"; + +} + +/////////////////////////////////////////////////////////////////////////////// +// GeneralPageGtk, public: + +GeneralPageGtk::GeneralPageGtk(Profile* profile) + : OptionsPageBase(profile) { + OptionsLayoutBuilderGtk options_builder(4); + options_builder.AddOptionGroup( + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_GROUP_NAME), + InitStartupGroup()); + options_builder.AddOptionGroup( + l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_GROUP_NAME), + InitHomepageGroup()); + options_builder.AddOptionGroup( + l10n_util::GetStringUTF8(IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME), + InitDefaultSearchGroup()); + options_builder.AddOptionGroup( + l10n_util::GetStringUTF8(IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME), + InitDefaultBrowserGroup()); + page_ = options_builder.get_page_widget(); + + profile->GetPrefs()->AddPrefObserver(prefs::kRestoreOnStartup, this); + profile->GetPrefs()->AddPrefObserver(prefs::kURLsToRestoreOnStartup, this); + + new_tab_page_is_home_page_.Init(prefs::kHomePageIsNewTabPage, + profile->GetPrefs(), this); + homepage_.Init(prefs::kHomePage, profile->GetPrefs(), this); + show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); + + // Load initial values + NotifyPrefChanged(NULL); +} + +GeneralPageGtk::~GeneralPageGtk() { + profile()->GetPrefs()->RemovePrefObserver(prefs::kRestoreOnStartup, this); + profile()->GetPrefs()->RemovePrefObserver( + prefs::kURLsToRestoreOnStartup, this); +} + +/////////////////////////////////////////////////////////////////////////////// +// GeneralPageGtk, OptionsPageBase overrides: + +void GeneralPageGtk::NotifyPrefChanged(const std::wstring* pref_name) { + if (!pref_name || *pref_name == prefs::kRestoreOnStartup) { + PrefService* prefs = profile()->GetPrefs(); + const SessionStartupPref startup_pref = + SessionStartupPref::GetStartupPref(prefs); + switch (startup_pref.type) { + case SessionStartupPref::DEFAULT: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(startup_homepage_radio_), + TRUE); + EnableCustomHomepagesControls(false); + break; + + case SessionStartupPref::LAST: + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(startup_last_session_radio_), TRUE); + EnableCustomHomepagesControls(false); + break; + + case SessionStartupPref::URLS: + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(startup_custom_radio_), + TRUE); + EnableCustomHomepagesControls(true); + break; + } + } + + // TODO(mattm): kURLsToRestoreOnStartup + + if (!pref_name || *pref_name == prefs::kHomePageIsNewTabPage) { + if (new_tab_page_is_home_page_.GetValue()) { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(homepage_use_newtab_radio_), TRUE); + gtk_widget_set_sensitive(homepage_use_url_entry_, FALSE); + } else { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(homepage_use_url_radio_), TRUE); + gtk_widget_set_sensitive(homepage_use_url_entry_, TRUE); + } + } + + if (!pref_name || *pref_name == prefs::kHomePage) { + bool enabled = homepage_.GetValue() != + UTF8ToWide(chrome::kChromeUINewTabURL); + if (enabled) + gtk_entry_set_text(GTK_ENTRY(homepage_use_url_entry_), + WideToUTF8(homepage_.GetValue()).c_str()); + } + + if (!pref_name || *pref_name == prefs::kShowHomeButton) { + gtk_toggle_button_set_active( + GTK_TOGGLE_BUTTON(homepage_show_home_button_checkbox_), + show_home_button_.GetValue()); + } +} + +void GeneralPageGtk::HighlightGroup(OptionsGroup highlight_group) { + // TODO(mattm): implement group highlighting +} + +/////////////////////////////////////////////////////////////////////////////// +// GeneralPageGtk, private: + +GtkWidget* GeneralPageGtk::InitStartupGroup() { + GtkWidget* vbox = gtk_vbox_new(FALSE, kOptionSpacing); + + startup_homepage_radio_ = gtk_radio_button_new_with_label(NULL, + l10n_util::GetStringUTF8( + IDS_OPTIONS_STARTUP_SHOW_DEFAULT_AND_NEWTAB).c_str()); + g_signal_connect(G_OBJECT(startup_homepage_radio_), "toggled", + G_CALLBACK(OnStartupRadioToggled), this); + gtk_container_add(GTK_CONTAINER(vbox), startup_homepage_radio_); + + startup_last_session_radio_ = gtk_radio_button_new_with_label_from_widget( + GTK_RADIO_BUTTON(startup_homepage_radio_), + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_SHOW_LAST_SESSION).c_str()); + g_signal_connect(G_OBJECT(startup_last_session_radio_), "toggled", + G_CALLBACK(OnStartupRadioToggled), this); + gtk_container_add(GTK_CONTAINER(vbox), startup_last_session_radio_); + + startup_custom_radio_ = gtk_radio_button_new_with_label_from_widget( + GTK_RADIO_BUTTON(startup_homepage_radio_), + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_SHOW_PAGES).c_str()); + g_signal_connect(G_OBJECT(startup_custom_radio_), "toggled", + G_CALLBACK(OnStartupRadioToggled), this); + gtk_container_add(GTK_CONTAINER(vbox), startup_custom_radio_); + + GtkWidget* url_list_container = gtk_hbox_new(FALSE, kOptionSpacing); + gtk_container_add(GTK_CONTAINER(vbox), url_list_container); + + GtkWidget* scroll_window = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window), + GTK_POLICY_NEVER, + GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll_window), + GTK_SHADOW_ETCHED_IN); + gtk_container_add(GTK_CONTAINER(url_list_container), + scroll_window); + startup_custom_pages_tree_ = gtk_tree_view_new(); + gtk_container_add(GTK_CONTAINER(scroll_window), startup_custom_pages_tree_); + + GtkWidget* url_list_buttons = gtk_vbox_new(FALSE, kOptionSpacing); + gtk_box_pack_end(GTK_BOX(url_list_container), url_list_buttons, + FALSE, FALSE, 0); + + // TODO(mattm): fix mnemonics (see + // MenuGtk::ConvertAcceleratorsFromWindowsStyle) + startup_add_custom_page_button_ = gtk_button_new_with_label( + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_ADD_BUTTON).c_str()); + gtk_container_add(GTK_CONTAINER(url_list_buttons), + startup_add_custom_page_button_); + startup_remove_custom_page_button_ = gtk_button_new_with_label( + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_REMOVE_BUTTON).c_str()); + gtk_container_add(GTK_CONTAINER(url_list_buttons), + startup_remove_custom_page_button_); + startup_use_current_page_button_ = gtk_button_new_with_label( + l10n_util::GetStringUTF8(IDS_OPTIONS_STARTUP_USE_CURRENT).c_str()); + gtk_container_add(GTK_CONTAINER(url_list_buttons), + startup_use_current_page_button_); + + // TODO(mattm): hook up custom url list stuff + + return vbox; +} + +GtkWidget* GeneralPageGtk::InitHomepageGroup() { + GtkWidget* vbox = gtk_vbox_new(FALSE, kOptionSpacing); + + homepage_use_newtab_radio_ = gtk_radio_button_new_with_label(NULL, + l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_USE_NEWTAB).c_str()); + g_signal_connect(G_OBJECT(homepage_use_newtab_radio_), "toggled", + G_CALLBACK(OnNewTabIsHomePageToggled), this); + gtk_container_add(GTK_CONTAINER(vbox), homepage_use_newtab_radio_); + + GtkWidget* homepage_hbox = gtk_hbox_new(FALSE, kLabelSpacing); + gtk_container_add(GTK_CONTAINER(vbox), homepage_hbox); + + homepage_use_url_radio_ = gtk_radio_button_new_with_label_from_widget( + GTK_RADIO_BUTTON(homepage_use_newtab_radio_), + l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_USE_URL).c_str()); + g_signal_connect(G_OBJECT(homepage_use_url_radio_), "toggled", + G_CALLBACK(OnNewTabIsHomePageToggled), this); + gtk_box_pack_start(GTK_BOX(homepage_hbox), homepage_use_url_radio_, + FALSE, FALSE, 0); + homepage_use_url_entry_ = gtk_entry_new(); + g_signal_connect(G_OBJECT(homepage_use_url_entry_), "changed", + G_CALLBACK(OnHomepageUseUrlEntryChanged), this); + gtk_box_pack_start(GTK_BOX(homepage_hbox), homepage_use_url_entry_, + TRUE, TRUE, 0); + + homepage_show_home_button_checkbox_ = gtk_check_button_new_with_label( + l10n_util::GetStringUTF8(IDS_OPTIONS_HOMEPAGE_SHOW_BUTTON).c_str()); + g_signal_connect(G_OBJECT(homepage_show_home_button_checkbox_), "toggled", + G_CALLBACK(OnShowHomeButtonToggled), this); + gtk_container_add(GTK_CONTAINER(vbox), homepage_show_home_button_checkbox_); + + return vbox; +} + +GtkWidget* GeneralPageGtk::InitDefaultSearchGroup() { + GtkWidget* hbox = gtk_hbox_new(FALSE, kOptionSpacing); + + // TODO(mattm): hook these up + default_search_engine_combobox_ = gtk_combo_box_new(); + gtk_container_add(GTK_CONTAINER(hbox), default_search_engine_combobox_); + + default_search_manage_engines_button_ = gtk_button_new_with_label( + l10n_util::GetStringUTF8( + IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES_LINK).c_str()); + gtk_box_pack_end(GTK_BOX(hbox), default_search_manage_engines_button_, + FALSE, FALSE, 0); + + return hbox; +} + +GtkWidget* GeneralPageGtk::InitDefaultBrowserGroup() { + GtkWidget* vbox = gtk_vbox_new(FALSE, kOptionSpacing); + + default_browser_status_label_ = gtk_label_new(NULL); + gtk_box_pack_start(GTK_BOX(vbox), default_browser_status_label_, + FALSE, FALSE, 0); + + default_browser_use_as_default_button_ = gtk_button_new_with_label( + l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)).c_str()); + g_signal_connect(G_OBJECT(default_browser_use_as_default_button_), "clicked", + G_CALLBACK(OnBrowserUseAsDefaultClicked), this); + gtk_box_pack_start(GTK_BOX(vbox), default_browser_use_as_default_button_, + FALSE, FALSE, 0); + + GtkWidget* vbox_alignment = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); + gtk_container_add(GTK_CONTAINER(vbox_alignment), vbox); + + SetDefaultBrowserUIState(ShellIntegration::IsDefaultBrowser()); + + return vbox_alignment; +} + +// static +void GeneralPageGtk::OnStartupRadioToggled(GtkToggleButton* toggle_button, + GeneralPageGtk* general_page) { + if (!gtk_toggle_button_get_active(toggle_button)) { + // When selecting a radio button, we get two signals (one for the old radio + // being toggled off, one for the new one being toggled on.) Ignore the + // signal for toggling off the old button. + return; + } + general_page->SaveStartupPref(); + GtkWidget* sender = GTK_WIDGET(toggle_button); + if (sender == general_page->startup_homepage_radio_) { + general_page->UserMetricsRecordAction(L"Options_Startup_Homepage", + general_page->profile()->GetPrefs()); + } else if (sender == general_page->startup_last_session_radio_) { + general_page->UserMetricsRecordAction(L"Options_Startup_LastSession", + general_page->profile()->GetPrefs()); + } else if (sender == general_page->startup_custom_radio_) { + general_page->UserMetricsRecordAction(L"Options_Startup_Custom", + general_page->profile()->GetPrefs()); + } +} + +// static +void GeneralPageGtk::OnNewTabIsHomePageToggled(GtkToggleButton* toggle_button, + GeneralPageGtk* general_page) { + if (!gtk_toggle_button_get_active(toggle_button)) { + // Ignore the signal for toggling off the old button. + return; + } + GtkWidget* sender = GTK_WIDGET(toggle_button); + if (sender == general_page->homepage_use_newtab_radio_) { + general_page->SetHomepage(GURL()); + general_page->UserMetricsRecordAction(L"Options_Homepage_UseNewTab", + general_page->profile()->GetPrefs()); + gtk_widget_set_sensitive(general_page->homepage_use_url_entry_, FALSE); + } else if (sender == general_page->homepage_use_url_radio_) { + general_page->SetHomepageFromEntry(); + general_page->UserMetricsRecordAction(L"Options_Homepage_UseURL", + general_page->profile()->GetPrefs()); + gtk_widget_set_sensitive(general_page->homepage_use_url_entry_, TRUE); + } +} + +// static +void GeneralPageGtk::OnHomepageUseUrlEntryChanged( + GtkEditable* editable, + GeneralPageGtk* general_page) { + general_page->SetHomepageFromEntry(); +} + +// static +void GeneralPageGtk::OnShowHomeButtonToggled(GtkToggleButton* toggle_button, + GeneralPageGtk* general_page) { + bool enabled = gtk_toggle_button_get_active(toggle_button); + general_page->show_home_button_.SetValue(enabled); + if (enabled) { + general_page->UserMetricsRecordAction(L"Options_Homepage_ShowHomeButton", + general_page->profile()->GetPrefs()); + } else { + general_page->UserMetricsRecordAction(L"Options_Homepage_HideHomeButton", + general_page->profile()->GetPrefs()); + } +} + +// static +void GeneralPageGtk::OnBrowserUseAsDefaultClicked( + GtkButton* button, + GeneralPageGtk* general_page) { + general_page->SetDefaultBrowserUIState( + ShellIntegration::SetAsDefaultBrowser()); + // If the user made Chrome the default browser, then he/she arguably wants + // to be notified when that changes. + general_page->profile()->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, + true); + general_page->UserMetricsRecordAction(L"Options_SetAsDefaultBrowser", + general_page->profile()->GetPrefs()); +} + +void GeneralPageGtk::SaveStartupPref() { + SessionStartupPref pref; + + if (gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(startup_last_session_radio_))) { + pref.type = SessionStartupPref::LAST; + } else if (gtk_toggle_button_get_active( + GTK_TOGGLE_BUTTON(startup_custom_radio_))) { + pref.type = SessionStartupPref::URLS; + } + + // TODO(mattm): save custom URL list + // pref.urls = startup_custom_pages_table_model_->GetURLs(); + + SessionStartupPref::SetStartupPref(profile()->GetPrefs(), pref); +} + +void GeneralPageGtk::SetHomepage(const GURL& homepage) { + if (!homepage.is_valid() || homepage.spec() == chrome::kChromeUINewTabURL) { + new_tab_page_is_home_page_.SetValue(true); + } else { + new_tab_page_is_home_page_.SetValue(false); + homepage_.SetValue(UTF8ToWide(homepage.spec())); + } +} + +void GeneralPageGtk::SetHomepageFromEntry() { + GURL url(URLFixerUpper::FixupURL( + gtk_entry_get_text(GTK_ENTRY(homepage_use_url_entry_)), "")); + SetHomepage(url); +} + +void GeneralPageGtk::EnableCustomHomepagesControls(bool enable) { + gtk_widget_set_sensitive(startup_add_custom_page_button_, enable); + GtkTreeSelection* selection = gtk_tree_view_get_selection( + GTK_TREE_VIEW(startup_custom_pages_tree_)); + gtk_widget_set_sensitive(startup_remove_custom_page_button_, + enable && gtk_tree_selection_count_selected_rows(selection)); + gtk_widget_set_sensitive(startup_use_current_page_button_, enable); + gtk_widget_set_sensitive(startup_custom_pages_tree_, enable); +} + +void GeneralPageGtk::SetDefaultBrowserUIState(bool is_default) { + const char* color; + std::string text; + if (is_default) { + color = kDefaultBrowserLabelColor; + text = l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_DEFAULT, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); + } else { + color = kNotDefaultBrowserLabelColor; + text = l10n_util::GetStringFUTF8(IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT, + l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)); + } + char* markup = g_markup_printf_escaped(kDefaultBrowserLabelMarkup, + color, text.c_str()); + gtk_label_set_markup(GTK_LABEL(default_browser_status_label_), markup); + g_free(markup); + + gtk_widget_set_sensitive(default_browser_use_as_default_button_, !is_default); +} diff --git a/chrome/browser/gtk/options/general_page_gtk.h b/chrome/browser/gtk/options/general_page_gtk.h new file mode 100644 index 0000000..2bb2003 --- /dev/null +++ b/chrome/browser/gtk/options/general_page_gtk.h @@ -0,0 +1,106 @@ +// Copyright (c) 2006-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_GENERAL_PAGE_GTK_H_ +#define CHROME_BROWSER_GTK_OPTIONS_GENERAL_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" +#include "googleurl/src/gurl.h" + +class GeneralPageGtk : public OptionsPageBase { + public: + explicit GeneralPageGtk(Profile* profile); + ~GeneralPageGtk(); + + GtkWidget* get_page_widget() const { + return page_; + } + + private: + // Overridden from OptionsPageBase + virtual void NotifyPrefChanged(const std::wstring* pref_name); + virtual void HighlightGroup(OptionsGroup highlight_group); + + // Initialize the option group widgets, return their container + GtkWidget* InitStartupGroup(); + GtkWidget* InitHomepageGroup(); + GtkWidget* InitDefaultSearchGroup(); + GtkWidget* InitDefaultBrowserGroup(); + + // Saves the startup preference from the values in the ui + void SaveStartupPref(); + + // Sets the home page preferences for kNewTabPageIsHomePage and kHomePage. + // If a blank string is passed in we revert to using NewTab page as the Home + // page. When setting the Home Page to NewTab page, we preserve the old value + // of kHomePage (we don't overwrite it). + void SetHomepage(const GURL& homepage); + + // Sets the home page pref using the value in the entry box + void SetHomepageFromEntry(); + + // Callback for startup radio buttons + static void OnStartupRadioToggled(GtkToggleButton* toggle_button, + GeneralPageGtk* general_page); + + // Callback for new tab behavior radio buttons + static void OnNewTabIsHomePageToggled(GtkToggleButton* toggle_button, + GeneralPageGtk* general_page); + + // Callback for homepage URL entry + static void OnHomepageUseUrlEntryChanged(GtkEditable* editable, + GeneralPageGtk* general_page); + + // Callback for Show Home Button option + static void OnShowHomeButtonToggled(GtkToggleButton* toggle_button, + GeneralPageGtk* general_page); + + // Callback for use as default browser button + static void OnBrowserUseAsDefaultClicked(GtkButton* button, + GeneralPageGtk* general_page); + + // Enables/Disables the controls associated with the custom start pages + // option if that preference is not selected. + void EnableCustomHomepagesControls(bool enable); + + // Sets the UI state to match + void SetDefaultBrowserUIState(bool is_default); + + // Widgets of the startup group + GtkWidget* startup_homepage_radio_; + GtkWidget* startup_last_session_radio_; + GtkWidget* startup_custom_radio_; + GtkWidget* startup_custom_pages_tree_; + GtkWidget* startup_add_custom_page_button_; + GtkWidget* startup_remove_custom_page_button_; + GtkWidget* startup_use_current_page_button_; + + // Widgets and prefs of the homepage group + GtkWidget* homepage_use_newtab_radio_; + GtkWidget* homepage_use_url_radio_; + GtkWidget* homepage_use_url_entry_; + GtkWidget* homepage_show_home_button_checkbox_; + BooleanPrefMember new_tab_page_is_home_page_; + StringPrefMember homepage_; + BooleanPrefMember show_home_button_; + + // Widgets of the default search group + GtkWidget* default_search_engine_combobox_; + GtkWidget* default_search_manage_engines_button_; + + // Widgets of the default browser group + GtkWidget* default_browser_status_label_; + GtkWidget* default_browser_use_as_default_button_; + + // The parent GtkTable widget + GtkWidget* page_; + + DISALLOW_COPY_AND_ASSIGN(GeneralPageGtk); +}; + +#endif // CHROME_BROWSER_GTK_OPTIONS_GENERAL_PAGE_GTK_H_ diff --git a/chrome/browser/gtk/options/options_layout_gtk.cc b/chrome/browser/gtk/options/options_layout_gtk.cc new file mode 100644 index 0000000..e55f47c --- /dev/null +++ b/chrome/browser/gtk/options/options_layout_gtk.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2006-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/options_layout_gtk.h" + +namespace { + +// Style for option group titles +const char kGroupTitleMarkup[] = + "<span weight='bold'>%s</span>"; + +// Space around the outsides of the page +const int kBorderSize = 12; + +// Indent of the options within each group +const int kOptionsIndent = 12; + +// Spacing between options of the same group +const int kOptionSpacing = 6; + +// Spacing between groups +const int kGroupSpacing = 18; + +} + +OptionsLayoutBuilderGtk::OptionsLayoutBuilderGtk(int num_rows) { + page_ = gtk_vbox_new(FALSE, kGroupSpacing); + gtk_container_set_border_width(GTK_CONTAINER(page_), kBorderSize); +} + +void OptionsLayoutBuilderGtk::AddOptionGroup(const std::string& title, + GtkWidget* content) { + GtkWidget* title_label = gtk_label_new(NULL); + char* markup = g_markup_printf_escaped(kGroupTitleMarkup, + title.c_str()); + gtk_label_set_markup(GTK_LABEL(title_label), markup); + g_free(markup); + + GtkWidget* title_alignment = gtk_alignment_new(0.0, 0.5, 0.0, 0.0); + gtk_container_add(GTK_CONTAINER(title_alignment), title_label); + + GtkWidget* content_alignment = gtk_alignment_new(0.0, 0.5, 1.0, 1.0); + gtk_alignment_set_padding(GTK_ALIGNMENT(content_alignment), 0, 0, + kOptionsIndent, 0); + gtk_container_add(GTK_CONTAINER(content_alignment), content); + + GtkWidget* group = gtk_vbox_new(FALSE, kOptionSpacing); + gtk_container_add(GTK_CONTAINER(group), title_alignment); + gtk_container_add(GTK_CONTAINER(group), content_alignment); + + gtk_box_pack_start(GTK_BOX(page_), group, FALSE, FALSE, 0); +} diff --git a/chrome/browser/gtk/options/options_layout_gtk.h b/chrome/browser/gtk/options/options_layout_gtk.h new file mode 100644 index 0000000..5ab722a --- /dev/null +++ b/chrome/browser/gtk/options/options_layout_gtk.h @@ -0,0 +1,32 @@ +// Copyright (c) 2006-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_OPTIONS_LAYOUT_GTK_H_ +#define CHROME_BROWSER_GTK_OPTIONS_OPTIONS_LAYOUT_GTK_H_ + +#include <gtk/gtk.h> +#include <string> + +#include "base/basictypes.h" + +class OptionsLayoutBuilderGtk { + public: + explicit OptionsLayoutBuilderGtk(int num_rows); + + GtkWidget* get_page_widget() { + return page_; + } + + // Adds an option group to the table. Handles layout and the placing of + // separators between groups. + void AddOptionGroup(const std::string& title, GtkWidget* content); + + private: + // The parent widget + GtkWidget* page_; + + DISALLOW_COPY_AND_ASSIGN(OptionsLayoutBuilderGtk); +}; + +#endif // CHROME_BROWSER_GTK_OPTIONS_OPTIONS_LAYOUT_GTK_H_ diff --git a/chrome/browser/gtk/options/options_window_gtk.cc b/chrome/browser/gtk/options/options_window_gtk.cc index 7fe8365..ea382d2 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/general_page_gtk.h" #include "chrome/browser/profile.h" #include "chrome/common/pref_member.h" #include "chrome/common/pref_names.h" @@ -54,6 +55,9 @@ class OptionsWindowGtk { // The Profile associated with these options. Profile* profile_; + // The options pages + GeneralPageGtk general_page_; + // The last page the user was on when they opened the Options window. IntegerPrefMember last_selected_page_; @@ -69,7 +73,7 @@ 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()) { + : profile_(profile->GetOriginalProfile()), general_page_(profile_) { // The download manager needs to be initialized before the contents of the // Options Window are created. profile_->GetDownloadManager(); @@ -93,7 +97,7 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile) gtk_notebook_append_page( GTK_NOTEBOOK(notebook_), - gtk_label_new("TODO general"), + general_page_.get_page_widget(), gtk_label_new( l10n_util::GetStringUTF8(IDS_OPTIONS_GENERAL_TAB_LABEL).c_str())); diff --git a/chrome/browser/options_page_base.cc b/chrome/browser/options_page_base.cc new file mode 100644 index 0000000..d875f33 --- /dev/null +++ b/chrome/browser/options_page_base.cc @@ -0,0 +1,36 @@ +// Copyright (c) 2006-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/options_page_base.h" + +#include "chrome/browser/metrics/user_metrics.h" +#include "chrome/common/notification_service.h" +#include "chrome/common/pref_service.h" + +/////////////////////////////////////////////////////////////////////////////// +// OptionsPageBase + +OptionsPageBase::OptionsPageBase(Profile* profile) + : profile_(profile) { +} + +OptionsPageBase::~OptionsPageBase() { +} + +void OptionsPageBase::UserMetricsRecordAction(const wchar_t* action, + PrefService* prefs) { + UserMetrics::RecordComputedAction(action, profile()); + if (prefs) + prefs->ScheduleSavePersistentPrefs(); +} + +/////////////////////////////////////////////////////////////////////////////// +// OptionsPageBase, NotificationObserver implementation: + +void OptionsPageBase::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + if (type == NotificationType::PREF_CHANGED) + NotifyPrefChanged(Details<std::wstring>(details).ptr()); +} diff --git a/chrome/browser/options_page_base.h b/chrome/browser/options_page_base.h new file mode 100644 index 0000000..dd79767 --- /dev/null +++ b/chrome/browser/options_page_base.h @@ -0,0 +1,55 @@ +// Copyright (c) 2006-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_OPTIONS_PAGE_BASE_H_ +#define CHROME_BROWSER_OPTIONS_PAGE_BASE_H_ + +#include "chrome/browser/options_window.h" +#include "chrome/browser/profile.h" +#include "chrome/common/notification_observer.h" + +class PrefService; + +/////////////////////////////////////////////////////////////////////////////// +// OptionsPageBase +// +// A base class for Options dialog pages that handles observing preferences +// +class OptionsPageBase : public NotificationObserver { + public: + virtual ~OptionsPageBase(); + + // Highlights the specified group to attract the user's attention. + virtual void HighlightGroup(OptionsGroup highlight_group) { } + + // Overridden from NotificationObserver: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + protected: + // This class cannot be instantiated directly, but its constructor must be + // called by derived classes. + explicit OptionsPageBase(Profile* profile); + + // Returns the Profile associated with this page. + Profile* profile() const { return profile_; } + + // Records a user action and schedules the prefs file to be saved. + void UserMetricsRecordAction(const wchar_t* action, PrefService* prefs); + + // Allows the UI to update when a preference value changes. The parameter is + // the specific pref that changed, or NULL if all pref UI should be + // validated. This should be called during setup, but with NULL as the + // parameter to allow initial state to be set. + virtual void NotifyPrefChanged(const std::wstring* pref_name) { } + + private: + // The Profile associated with this page. + Profile* profile_; + + DISALLOW_EVIL_CONSTRUCTORS(OptionsPageBase); +}; + +#endif // CHROME_BROWSER_OPTIONS_PAGE_BASE_H_ diff --git a/chrome/browser/views/options/options_page_view.cc b/chrome/browser/views/options/options_page_view.cc index 6190621..6e7747b 100644 --- a/chrome/browser/views/options/options_page_view.cc +++ b/chrome/browser/views/options/options_page_view.cc @@ -14,30 +14,13 @@ // OptionsPageView OptionsPageView::OptionsPageView(Profile* profile) - : profile_(profile), + : OptionsPageBase(profile), initialized_(false) { } OptionsPageView::~OptionsPageView() { } -void OptionsPageView::UserMetricsRecordAction(const wchar_t* action, - PrefService* prefs) { - UserMetrics::RecordComputedAction(action, profile()); - if (prefs) - prefs->ScheduleSavePersistentPrefs(); -} - -/////////////////////////////////////////////////////////////////////////////// -// OptionsPageView, NotificationObserver implementation: - -void OptionsPageView::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - if (type == NotificationType::PREF_CHANGED) - NotifyPrefChanged(Details<std::wstring>(details).ptr()); -} - /////////////////////////////////////////////////////////////////////////////// // OptionsPageView, views::View overrides: diff --git a/chrome/browser/views/options/options_page_view.h b/chrome/browser/views/options/options_page_view.h index 1a0a023..15c1c34 100644 --- a/chrome/browser/views/options/options_page_view.h +++ b/chrome/browser/views/options/options_page_view.h @@ -5,9 +5,7 @@ #ifndef CHROME_BROWSER_VIEWS_OPTIONS_OPTIONS_PAGE_VIEW_H__ #define CHROME_BROWSER_VIEWS_OPTIONS_OPTIONS_PAGE_VIEW_H__ -#include "chrome/browser/options_window.h" -#include "chrome/browser/profile.h" -#include "chrome/common/notification_observer.h" +#include "chrome/browser/options_page_base.h" #include "views/controls/link.h" #include "views/controls/button/native_button.h" @@ -20,7 +18,7 @@ class PrefService; // initialization is done just once. // class OptionsPageView : public views::View, - public NotificationObserver { + public OptionsPageBase { public: virtual ~OptionsPageView(); @@ -29,44 +27,20 @@ class OptionsPageView : public views::View, // being closed when a modal dialog box is showing, for example. virtual bool CanClose() const { return true; } - // Highlights the specified group to attract the user's attention. - virtual void HighlightGroup(OptionsGroup highlight_group) { } - - // Overridden from NotificationObserver: - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - protected: // This class cannot be instantiated directly, but its constructor must be // called by derived classes. explicit OptionsPageView(Profile* profile); - // Returns the Profile associated with this page. - Profile* profile() const { return profile_; } - - // Records a user action and schedules the prefs file to be saved. - void UserMetricsRecordAction(const wchar_t* action, PrefService* prefs); - // Initializes the layout of the controls within the panel. virtual void InitControlLayout() = 0; - // Allows the UI to update when a preference value changes. The parameter is - // the specific pref that changed, or NULL if all pref UI should be - // validated. This is also called immediately after InitControlLayout() - // during setup, but with NULL as the parameter to allow initial state to be - // set. - virtual void NotifyPrefChanged(const std::wstring* pref_name) { } - // views::View overrides: virtual void ViewHierarchyChanged(bool is_add, views::View* parent, views::View* child); private: - // The Profile associated with this page. - Profile* profile_; - // Whether or not the control layout has been initialized for this page. bool initialized_; diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index fcaa0fa..668398d 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -938,6 +938,10 @@ 'browser/gtk/menu_gtk.h', 'browser/gtk/nine_box.cc', 'browser/gtk/nine_box.h', + 'browser/gtk/options/general_page_gtk.cc', + 'browser/gtk/options/general_page_gtk.h', + 'browser/gtk/options/options_layout_gtk.cc', + 'browser/gtk/options/options_layout_gtk.h', 'browser/gtk/options/options_window_gtk.cc', 'browser/gtk/sad_tab_gtk.cc', 'browser/gtk/sad_tab_gtk.h', @@ -1091,6 +1095,8 @@ 'browser/net/url_fetcher_protect.h', 'browser/net/url_fixer_upper.cc', 'browser/net/url_fixer_upper.h', + 'browser/options_page_base.cc', + 'browser/options_page_base.h', 'browser/options_window.h', 'browser/page_state.cc', 'browser/page_state.h', |