Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: chrome/browser/gtk/options/advanced_contents_gtk.cc

Issue 155617: Implement gtk download options section. (Closed)
Patch Set: rebased Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/gtk/options/advanced_contents_gtk.h" 5 #include "chrome/browser/gtk/options/advanced_contents_gtk.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/path_service.h"
9 #include "chrome/browser/browser_list.h" 10 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/download/download_manager.h"
11 #include "chrome/browser/fonts_languages_window.h" 13 #include "chrome/browser/fonts_languages_window.h"
12 #include "chrome/browser/gtk/gtk_chrome_link_button.h" 14 #include "chrome/browser/gtk/gtk_chrome_link_button.h"
13 #include "chrome/browser/gtk/options/options_layout_gtk.h" 15 #include "chrome/browser/gtk/options/options_layout_gtk.h"
14 #include "chrome/browser/net/dns_global.h" 16 #include "chrome/browser/net/dns_global.h"
15 #include "chrome/browser/options_page_base.h" 17 #include "chrome/browser/options_page_base.h"
16 #include "chrome/browser/options_util.h" 18 #include "chrome/browser/options_util.h"
17 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
18 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 20 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
21 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/gtk_util.h" 22 #include "chrome/common/gtk_util.h"
20 #include "chrome/common/pref_member.h" 23 #include "chrome/common/pref_member.h"
21 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
22 #include "grit/chromium_strings.h" 25 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
24 #include "grit/locale_settings.h" 27 #include "grit/locale_settings.h"
25 #include "net/base/cookie_policy.h" 28 #include "net/base/cookie_policy.h"
26 29
27 namespace { 30 namespace {
28 31
(...skipping 25 matching lines...) Expand all
54 class DownloadSection : public OptionsPageBase { 57 class DownloadSection : public OptionsPageBase {
55 public: 58 public:
56 explicit DownloadSection(Profile* profile); 59 explicit DownloadSection(Profile* profile);
57 virtual ~DownloadSection() {} 60 virtual ~DownloadSection() {}
58 61
59 GtkWidget* get_page_widget() const { 62 GtkWidget* get_page_widget() const {
60 return page_; 63 return page_;
61 } 64 }
62 65
63 private: 66 private:
67 // Overridden from OptionsPageBase.
68 virtual void NotifyPrefChanged(const std::wstring* pref_name);
69
70 // Callbacks for the widgets.
71 static void OnDownloadLocationChanged(GtkFileChooser* widget,
72 DownloadSection* section);
73 static void OnDownloadAskForSaveLocationChanged(GtkWidget* widget,
74 DownloadSection* section);
75 static void OnResetFileHandlersClicked(GtkButton *button,
76 DownloadSection* section);
77
78 // The widgets for the download options.
79 GtkWidget* download_location_button_;
80 GtkWidget* download_ask_for_save_location_checkbox_;
81 GtkWidget* reset_file_handlers_label_;
82 GtkWidget* reset_file_handlers_button_;
83
64 // The widget containing the options for this section. 84 // The widget containing the options for this section.
65 GtkWidget* page_; 85 GtkWidget* page_;
66 86
87 // Pref members.
88 StringPrefMember default_download_location_;
89 BooleanPrefMember ask_for_save_location_;
90 StringPrefMember auto_open_files_;
91
92 // Flag to ignore gtk callbacks while we are loading prefs, to avoid
93 // then turning around and saving them again.
94 bool initializing_;
95
67 DISALLOW_COPY_AND_ASSIGN(DownloadSection); 96 DISALLOW_COPY_AND_ASSIGN(DownloadSection);
68 }; 97 };
69 98
70 DownloadSection::DownloadSection(Profile* profile) 99 DownloadSection::DownloadSection(Profile* profile)
71 : OptionsPageBase(profile) { 100 : OptionsPageBase(profile), initializing_(true) {
72 page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); 101 page_ = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
73 gtk_box_pack_start(GTK_BOX(page_), gtk_label_new("TODO download options"), 102
103 // Download location options.
104 download_location_button_ = gtk_file_chooser_button_new(
105 // TODO(mattm): There doesn't seem to be a reasonable localized string for
106 // the chooser title? (Though no other file choosers have a title either,
107 // bug 16890.)
108 "",
109 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER);
110 g_signal_connect(download_location_button_, "selection-changed",
111 G_CALLBACK(OnDownloadLocationChanged), this);
112 // Add the default download path to the list of shortcuts in the selector.
113 FilePath default_download_path;
114 if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS,
115 &default_download_path)) {
116 NOTREACHED();
117 } else {
118 if (!gtk_file_chooser_add_shortcut_folder(
119 GTK_FILE_CHOOSER(download_location_button_),
120 default_download_path.value().c_str(),
121 NULL)) {
122 NOTREACHED();
123 }
124 }
125
126 GtkWidget* download_location_control = gtk_util::CreateLabeledControlsGroup(
127 NULL,
128 l10n_util::GetStringUTF8(
129 IDS_OPTIONS_DOWNLOADLOCATION_BROWSE_TITLE).c_str(),
130 download_location_button_,
131 NULL);
132 gtk_box_pack_start(GTK_BOX(page_), download_location_control,
74 FALSE, FALSE, 0); 133 FALSE, FALSE, 0);
134
135 download_ask_for_save_location_checkbox_ = CreateCheckButtonWithWrappedLabel(
136 IDS_OPTIONS_DOWNLOADLOCATION_ASKFORSAVELOCATION);
137 gtk_box_pack_start(GTK_BOX(page_), download_ask_for_save_location_checkbox_,
138 FALSE, FALSE, 0);
139 g_signal_connect(download_ask_for_save_location_checkbox_, "clicked",
140 G_CALLBACK(OnDownloadAskForSaveLocationChanged), this);
141
142 // Option for resetting file handlers.
143 reset_file_handlers_label_ = CreateWrappedLabel(
144 IDS_OPTIONS_AUTOOPENFILETYPES_INFO);
145 gtk_misc_set_alignment(GTK_MISC(reset_file_handlers_label_), 0, 0);
146 gtk_box_pack_start(GTK_BOX(page_), reset_file_handlers_label_,
147 FALSE, FALSE, 0);
148
149 reset_file_handlers_button_ = gtk_button_new_with_label(
150 l10n_util::GetStringUTF8(
151 IDS_OPTIONS_AUTOOPENFILETYPES_RESETTODEFAULT).c_str());
152 g_signal_connect(reset_file_handlers_button_, "clicked",
153 G_CALLBACK(OnResetFileHandlersClicked), this);
154 // Stick it in an hbox so it doesn't expand to the whole width.
155 GtkWidget* button_hbox = gtk_hbox_new(FALSE, 0);
156 gtk_box_pack_start(GTK_BOX(button_hbox),
157 reset_file_handlers_button_,
158 FALSE, FALSE, 0);
159 gtk_box_pack_start(GTK_BOX(page_),
160 OptionsLayoutBuilderGtk::IndentWidget(button_hbox),
161 FALSE, FALSE, 0);
162
163 // Init prefs watchers.
164 default_download_location_.Init(prefs::kDownloadDefaultDirectory,
165 profile->GetPrefs(), this);
166 ask_for_save_location_.Init(prefs::kPromptForDownload,
167 profile->GetPrefs(), this);
168 auto_open_files_.Init(prefs::kDownloadExtensionsToOpen, profile->GetPrefs(),
169 this);
170
171 NotifyPrefChanged(NULL);
172 }
173
174 void DownloadSection::NotifyPrefChanged(const std::wstring* pref_name) {
175 initializing_ = true;
176 if (!pref_name || *pref_name == prefs::kDownloadDefaultDirectory) {
177 gtk_file_chooser_set_current_folder(
178 GTK_FILE_CHOOSER(download_location_button_),
179 FilePath::FromWStringHack(
180 default_download_location_.GetValue()).value().c_str());
181 }
182
183 if (!pref_name || *pref_name == prefs::kPromptForDownload) {
184 gtk_toggle_button_set_active(
185 GTK_TOGGLE_BUTTON(download_ask_for_save_location_checkbox_),
186 ask_for_save_location_.GetValue());
187 }
188
189 if (!pref_name || *pref_name == prefs::kDownloadExtensionsToOpen) {
190 bool enabled =
191 profile()->GetDownloadManager()->HasAutoOpenFileTypesRegistered();
192 gtk_widget_set_sensitive(reset_file_handlers_label_, enabled);
193 gtk_widget_set_sensitive(reset_file_handlers_button_, enabled);
194 }
195 initializing_ = false;
196 }
197
198 // static
199 void DownloadSection::OnDownloadLocationChanged(GtkFileChooser* widget,
200 DownloadSection* section) {
201 if (section->initializing_)
202 return;
203
204 gchar* folder = gtk_file_chooser_get_filename(widget);
205 FilePath path(folder);
206 g_free(folder);
207 // Gtk seems to call this signal multiple times, so we only set the pref and
208 // metric if something actually changed.
209 if (path.ToWStringHack() != section->default_download_location_.GetValue()) {
210 section->default_download_location_.SetValue(path.ToWStringHack());
211 section->UserMetricsRecordAction(L"Options_SetDownloadDirectory",
212 section->profile()->GetPrefs());
213 }
214 }
215
216 // static
217 void DownloadSection::OnDownloadAskForSaveLocationChanged(
218 GtkWidget* widget, DownloadSection* section) {
219 if (section->initializing_)
220 return;
221 bool enabled = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
222 if (enabled) {
223 section->UserMetricsRecordAction(L"Options_AskForSaveLocation_Enable",
224 section->profile()->GetPrefs());
225 } else {
226 section->UserMetricsRecordAction(L"Options_AskForSaveLocation_Disable",
227 section->profile()->GetPrefs());
228 }
229 section->ask_for_save_location_.SetValue(enabled);
230 }
231
232 // static
233 void DownloadSection::OnResetFileHandlersClicked(GtkButton *button,
234 DownloadSection* section) {
235 section->profile()->GetDownloadManager()->ResetAutoOpenFiles();
236 section->UserMetricsRecordAction(L"Options_ResetAutoOpenFiles",
237 section->profile()->GetPrefs());
75 } 238 }
76 239
77 /////////////////////////////////////////////////////////////////////////////// 240 ///////////////////////////////////////////////////////////////////////////////
78 // NetworkSection 241 // NetworkSection
79 242
80 class NetworkSection : public OptionsPageBase { 243 class NetworkSection : public OptionsPageBase {
81 public: 244 public:
82 explicit NetworkSection(Profile* profile); 245 explicit NetworkSection(Profile* profile);
83 virtual ~NetworkSection() {} 246 virtual ~NetworkSection() {}
84 247
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT), 728 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_CONTENT),
566 web_content_section_->get_page_widget(), false); 729 web_content_section_->get_page_widget(), false);
567 730
568 security_section_.reset(new SecuritySection(profile_)); 731 security_section_.reset(new SecuritySection(profile_));
569 options_builder.AddOptionGroup( 732 options_builder.AddOptionGroup(
570 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY), 733 l10n_util::GetStringUTF8(IDS_OPTIONS_ADVANCED_SECTION_TITLE_SECURITY),
571 security_section_->get_page_widget(), false); 734 security_section_->get_page_widget(), false);
572 735
573 page_ = options_builder.get_page_widget(); 736 page_ = options_builder.get_page_widget();
574 } 737 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698