diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 00:58:52 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-05 00:58:52 +0000 |
commit | e640fe10be27b0c5f49b42988fb89770c8eddc43 (patch) | |
tree | 771efdeee09bed0ead1bee5122b7d78370909c3b /chrome/browser/gtk | |
parent | 0cbfdaadad196f6699dd67ff291522dc421610e4 (diff) | |
download | chromium_src-e640fe10be27b0c5f49b42988fb89770c8eddc43.zip chromium_src-e640fe10be27b0c5f49b42988fb89770c8eddc43.tar.gz chromium_src-e640fe10be27b0c5f49b42988fb89770c8eddc43.tar.bz2 |
[GTK] instant confirm dialog
BUG=58937
TEST=manual
Review URL: http://codereview.chromium.org/4427001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65160 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/instant_confirm_dialog_gtk.cc | 82 | ||||
-rw-r--r-- | chrome/browser/gtk/instant_confirm_dialog_gtk.h | 31 | ||||
-rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.cc | 19 | ||||
-rw-r--r-- | chrome/browser/gtk/options/general_page_gtk.h | 2 |
4 files changed, 129 insertions, 5 deletions
diff --git a/chrome/browser/gtk/instant_confirm_dialog_gtk.cc b/chrome/browser/gtk/instant_confirm_dialog_gtk.cc new file mode 100644 index 0000000..c313cec --- /dev/null +++ b/chrome/browser/gtk/instant_confirm_dialog_gtk.cc @@ -0,0 +1,82 @@ +// Copyright (c) 2010 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/instant_confirm_dialog_gtk.h" + +#include <gtk/gtk.h> + +#include "app/l10n_util.h" +#include "chrome/browser/gtk/gtk_chrome_link_button.h" +#include "chrome/browser/gtk/gtk_util.h" +#include "chrome/browser/instant/instant_confirm_dialog.h" +#include "chrome/browser/prefs/pref_service.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/show_options_url.h" +#include "chrome/common/pref_names.h" +#include "googleurl/src/gurl.h" +#include "grit/generated_resources.h" + +namespace browser { + +void ShowInstantConfirmDialog(GtkWindow* parent, Profile* profile) { + new InstantConfirmDialogGtk(parent, profile); +} + +} // namespace browser + +InstantConfirmDialogGtk::InstantConfirmDialogGtk( + GtkWindow* parent, Profile* profile) : profile_(profile) { + dialog_ = gtk_dialog_new_with_buttons( + l10n_util::GetStringUTF8(IDS_INSTANT_OPT_IN_TITLE).c_str(), + parent, + static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + NULL); + g_signal_connect(dialog_, "response", + G_CALLBACK(OnDialogResponseThunk), this); + + GtkBox* vbox = GTK_BOX(GTK_DIALOG(dialog_)->vbox); + gtk_box_set_spacing(vbox, gtk_util::kControlSpacing); + + GtkWidget* label = gtk_label_new( + l10n_util::GetStringUTF8(IDS_INSTANT_OPT_IN_MESSAGE).c_str()); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_box_pack_start(vbox, label, FALSE, FALSE, 0); + + GtkWidget* link_button = gtk_chrome_link_button_new( + l10n_util::GetStringUTF8(IDS_OPTIONS_LEARN_MORE_LABEL).c_str()); + g_signal_connect(link_button, "clicked", + G_CALLBACK(OnLinkButtonClickedThunk), this); + + GtkWidget* action_area = GTK_DIALOG(dialog_)->action_area; + gtk_container_add(GTK_CONTAINER(action_area), link_button); + gtk_button_box_set_child_secondary(GTK_BUTTON_BOX(action_area), + link_button, + TRUE); + + gtk_dialog_set_default_response(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); + gtk_widget_show_all(dialog_); +} + +InstantConfirmDialogGtk::~InstantConfirmDialogGtk() { + gtk_widget_destroy(dialog_); +} + +void InstantConfirmDialogGtk::OnDialogResponse(GtkWidget* dialog, + int response) { + if (response == GTK_RESPONSE_ACCEPT) { + PrefService* service = profile_->GetPrefs(); + if (service) { + service->SetBoolean(prefs::kInstantEnabled, true); + service->SetBoolean(prefs::kInstantConfirmDialogShown, true); + } + } + + delete this; +} + +void InstantConfirmDialogGtk::OnLinkButtonClicked(GtkWidget* button) { + browser::ShowOptionsURL(profile_, GURL(browser::kInstantLearnMoreURL)); +} diff --git a/chrome/browser/gtk/instant_confirm_dialog_gtk.h b/chrome/browser/gtk/instant_confirm_dialog_gtk.h new file mode 100644 index 0000000..29a184e --- /dev/null +++ b/chrome/browser/gtk/instant_confirm_dialog_gtk.h @@ -0,0 +1,31 @@ +// Copyright (c) 2010 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_INSTANT_CONFIRM_DIALOG_GTK_H_ +#define CHROME_BROWSER_GTK_INSTANT_CONFIRM_DIALOG_GTK_H_ + +#include "app/gtk_signal.h" +#include "base/basictypes.h" + +class Profile; +typedef struct _GtkWindow GtkWindow; + +// A dialog that explains some of the privacy implications surrounding instant. +// Shown when the user enables instant for the first time. +class InstantConfirmDialogGtk { + public: + InstantConfirmDialogGtk(GtkWindow* parent, Profile* profile); + ~InstantConfirmDialogGtk(); + + private: + CHROMEGTK_CALLBACK_1(InstantConfirmDialogGtk, void, OnDialogResponse, int); + CHROMEGTK_CALLBACK_0(InstantConfirmDialogGtk, void, OnLinkButtonClicked); + + GtkWidget* dialog_; + Profile* profile_; + + DISALLOW_COPY_AND_ASSIGN(InstantConfirmDialogGtk); +}; + +#endif // CHROME_BROWSER_GTK_INSTANT_CONFIRM_DIALOG_GTK_H_ diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc index a708201..01aef9e 100644 --- a/chrome/browser/gtk/options/general_page_gtk.cc +++ b/chrome/browser/gtk/options/general_page_gtk.cc @@ -122,6 +122,10 @@ GeneralPageGtk::~GeneralPageGtk() { default_browser_worker_->ObserverDestroyed(); } +GtkWindow* GeneralPageGtk::GetWindow() { + return GTK_WINDOW(gtk_widget_get_toplevel(page_)); +} + /////////////////////////////////////////////////////////////////////////////// // GeneralPageGtk, OptionsPageBase overrides: @@ -197,8 +201,7 @@ void GeneralPageGtk::NotifyPrefChanged(const std::string* pref_name) { if ((!pref_name || *pref_name == prefs::kInstantEnabled) && instant_checkbox_) { gtk_toggle_button_set_active( - GTK_TOGGLE_BUTTON(instant_checkbox_), - instant_.GetValue()); + GTK_TOGGLE_BUTTON(instant_checkbox_), instant_.GetValue()); } initializing_ = false; @@ -483,7 +486,7 @@ void GeneralPageGtk::OnStartupAddCustomPageClicked(GtkWidget* button) { new UrlPickerDialogGtk( NewCallback(this, &GeneralPageGtk::OnAddCustomUrl), profile(), - GTK_WINDOW(gtk_widget_get_toplevel(page_))); + GetWindow()); } void GeneralPageGtk::OnStartupRemoveCustomPageClicked(GtkWidget* button) { @@ -545,9 +548,15 @@ void GeneralPageGtk::OnInstantToggled(GtkWidget* toggle_button) { if (initializing_) return; - // TODO(estade): show confirm dialog. bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button)); - instant_.SetValue(enabled); + + if (enabled) { + if (!instant_.GetValue()) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(instant_checkbox_), false); + browser::ShowInstantConfirmDialogIfNecessary(GetWindow(), profile()); + } else { + instant_.SetValue(enabled); + } // TODO(estade): UMA? } diff --git a/chrome/browser/gtk/options/general_page_gtk.h b/chrome/browser/gtk/options/general_page_gtk.h index e788476a..0050b2b 100644 --- a/chrome/browser/gtk/options/general_page_gtk.h +++ b/chrome/browser/gtk/options/general_page_gtk.h @@ -36,6 +36,8 @@ class GeneralPageGtk : public OptionsPageBase, GtkWidget* get_page_widget() const { return page_; } private: + GtkWindow* GetWindow(); + // Overridden from OptionsPageBase virtual void NotifyPrefChanged(const std::string* pref_name); virtual void HighlightGroup(OptionsGroup highlight_group); |