Commit 31caf918 authored by tc@google.com's avatar tc@google.com

Add general options page. Options are working with the following exceptions:

Custom start urls and default search options widgets aren't hooked up.
Home page settings work, but are overridden by the linux start page settings.
Default browser checking/setting functions are not implemented, so the option
isn't useful yet.

Refactors some common code out of browser/views/options/options_page_view.*
into browser/options_page_base.{cc,h}

BUG=11507

Patch by Matt Mueller (mattm@google.com).

Review URL: http://codereview.chromium.org/113967


git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17115 0039d316-1c4b-4281-b951-d872f2087c98
parent ad05af6e
...@@ -304,6 +304,11 @@ std::string GetStringUTF8(int message_id) { ...@@ -304,6 +304,11 @@ std::string GetStringUTF8(int message_id) {
return UTF16ToUTF8(rb.GetLocalizedString(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, static string16 GetStringF(int message_id,
const string16& a, const string16& a,
const string16& b, const string16& b,
......
...@@ -67,6 +67,7 @@ std::wstring GetLocalName(const std::string& locale_code_str, ...@@ -67,6 +67,7 @@ std::wstring GetLocalName(const std::string& locale_code_str,
// Pulls resource string from the string bundle and returns it. // Pulls resource string from the string bundle and returns it.
std::wstring GetString(int message_id); std::wstring GetString(int message_id);
std::string GetStringUTF8(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| // Get a resource string and replace $1-$2-$3 with |a| and |b|
// respectively. Additionally, $$ is replaced by $. // respectively. Additionally, $$ is replaced by $.
......
...@@ -807,6 +807,14 @@ ...@@ -807,6 +807,14 @@
RelativePath=".\login_prompt.h" RelativePath=".\login_prompt.h"
> >
</File> </File>
<File
RelativePath=".\options_page_base.cc"
>
</File>
<File
RelativePath=".\options_page_base.h"
>
</File>
<File <File
RelativePath=".\options_window.h" RelativePath=".\options_window.h"
> >
......
This diff is collapsed.
// 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_
// 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);
}
// 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_
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "app/l10n_util.h" #include "app/l10n_util.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/gtk/options/general_page_gtk.h"
#include "chrome/browser/profile.h" #include "chrome/browser/profile.h"
#include "chrome/common/pref_member.h" #include "chrome/common/pref_member.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
...@@ -54,6 +55,9 @@ class OptionsWindowGtk { ...@@ -54,6 +55,9 @@ class OptionsWindowGtk {
// The Profile associated with these options. // The Profile associated with these options.
Profile* profile_; Profile* profile_;
// The options pages
GeneralPageGtk general_page_;
// The last page the user was on when they opened the Options window. // The last page the user was on when they opened the Options window.
IntegerPrefMember last_selected_page_; IntegerPrefMember last_selected_page_;
...@@ -69,7 +73,7 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile) ...@@ -69,7 +73,7 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile)
// Always show preferences for the original profile. Most state when off // Always show preferences for the original profile. Most state when off
// the record comes from the original profile, but we explicitly use // the record comes from the original profile, but we explicitly use
// the original profile to avoid potential problems. // 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 // The download manager needs to be initialized before the contents of the
// Options Window are created. // Options Window are created.
profile_->GetDownloadManager(); profile_->GetDownloadManager();
...@@ -93,7 +97,7 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile) ...@@ -93,7 +97,7 @@ OptionsWindowGtk::OptionsWindowGtk(Profile* profile)
gtk_notebook_append_page( gtk_notebook_append_page(
GTK_NOTEBOOK(notebook_), GTK_NOTEBOOK(notebook_),
gtk_label_new("TODO general"), general_page_.get_page_widget(),
gtk_label_new( gtk_label_new(
l10n_util::GetStringUTF8(IDS_OPTIONS_GENERAL_TAB_LABEL).c_str())); l10n_util::GetStringUTF8(IDS_OPTIONS_GENERAL_TAB_LABEL).c_str()));
......
// 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());
}
// 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_
...@@ -14,30 +14,13 @@ ...@@ -14,30 +14,13 @@
// OptionsPageView // OptionsPageView
OptionsPageView::OptionsPageView(Profile* profile) OptionsPageView::OptionsPageView(Profile* profile)
: profile_(profile), : OptionsPageBase(profile),
initialized_(false) { initialized_(false) {
} }
OptionsPageView::~OptionsPageView() { 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: // OptionsPageView, views::View overrides:
......
...@@ -5,9 +5,7 @@ ...@@ -5,9 +5,7 @@
#ifndef CHROME_BROWSER_VIEWS_OPTIONS_OPTIONS_PAGE_VIEW_H__ #ifndef CHROME_BROWSER_VIEWS_OPTIONS_OPTIONS_PAGE_VIEW_H__
#define 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/options_page_base.h"
#include "chrome/browser/profile.h"
#include "chrome/common/notification_observer.h"
#include "views/controls/link.h" #include "views/controls/link.h"
#include "views/controls/button/native_button.h" #include "views/controls/button/native_button.h"
...@@ -20,7 +18,7 @@ class PrefService; ...@@ -20,7 +18,7 @@ class PrefService;
// initialization is done just once. // initialization is done just once.
// //
class OptionsPageView : public views::View, class OptionsPageView : public views::View,
public NotificationObserver { public OptionsPageBase {
public: public:
virtual ~OptionsPageView(); virtual ~OptionsPageView();
...@@ -29,44 +27,20 @@ class OptionsPageView : public views::View, ...@@ -29,44 +27,20 @@ class OptionsPageView : public views::View,
// being closed when a modal dialog box is showing, for example. // being closed when a modal dialog box is showing, for example.
virtual bool CanClose() const { return true; } 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: protected:
// This class cannot be instantiated directly, but its constructor must be // This class cannot be instantiated directly, but its constructor must be
// called by derived classes. // called by derived classes.
explicit OptionsPageView(Profile* profile); 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. // Initializes the layout of the controls within the panel.
virtual void InitControlLayout() = 0; 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: // views::View overrides:
virtual void ViewHierarchyChanged(bool is_add, virtual void ViewHierarchyChanged(bool is_add,
views::View* parent, views::View* parent,
views::View* child); views::View* child);
private: private:
// The Profile associated with this page.
Profile* profile_;
// Whether or not the control layout has been initialized for this page. // Whether or not the control layout has been initialized for this page.
bool initialized_; bool initialized_;
......
...@@ -938,6 +938,10 @@ ...@@ -938,6 +938,10 @@
'browser/gtk/menu_gtk.h', 'browser/gtk/menu_gtk.h',
'browser/gtk/nine_box.cc', 'browser/gtk/nine_box.cc',
'browser/gtk/nine_box.h', '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/options/options_window_gtk.cc',
'browser/gtk/sad_tab_gtk.cc', 'browser/gtk/sad_tab_gtk.cc',
'browser/gtk/sad_tab_gtk.h', 'browser/gtk/sad_tab_gtk.h',
...@@ -1091,6 +1095,8 @@ ...@@ -1091,6 +1095,8 @@
'browser/net/url_fetcher_protect.h', 'browser/net/url_fetcher_protect.h',
'browser/net/url_fixer_upper.cc', 'browser/net/url_fixer_upper.cc',
'browser/net/url_fixer_upper.h', 'browser/net/url_fixer_upper.h',
'browser/options_page_base.cc',
'browser/options_page_base.h',
'browser/options_window.h', 'browser/options_window.h',
'browser/page_state.cc', 'browser/page_state.cc',
'browser/page_state.h', 'browser/page_state.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment