diff options
author | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 15:54:48 +0000 |
---|---|---|
committer | rsesek@chromium.org <rsesek@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-29 15:54:48 +0000 |
commit | c1ca1c3b1a234281fd24b8ec9a1802c4055d07a0 (patch) | |
tree | d40bab9751445bce8ecdf5da8f238b6a18c1f497 /chrome/browser/cocoa | |
parent | 0519e110045415c8d674a8a5d0cdd587b9ce8e1f (diff) | |
download | chromium_src-c1ca1c3b1a234281fd24b8ec9a1802c4055d07a0.zip chromium_src-c1ca1c3b1a234281fd24b8ec9a1802c4055d07a0.tar.gz chromium_src-c1ca1c3b1a234281fd24b8ec9a1802c4055d07a0.tar.bz2 |
[Mac] Hook up part of the download preferences
Enable the download location path and the prompt-for-download settings.
BUG=22047
TEST=Preferences --> Under the hood, set download location, downloaded file is in new location.
TEST=Enable prompt for download location, download file, save panel comes up.
Review URL: http://codereview.chromium.org/239008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.h | 6 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.mm | 55 |
2 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/preferences_window_controller.h b/chrome/browser/cocoa/preferences_window_controller.h index 5aa8b95..66bc78a 100644 --- a/chrome/browser/cocoa/preferences_window_controller.h +++ b/chrome/browser/cocoa/preferences_window_controller.h @@ -60,6 +60,9 @@ class Profile; BooleanPrefMember safeBrowsing_; BooleanPrefMember metricsRecording_; IntegerPrefMember cookieBehavior_; + IBOutlet NSPathControl* downloadLocationControl_; + StringPrefMember defaultDownloadLocation_; + BooleanPrefMember askForSaveLocation_; } // Designated initializer. |profile| should not be NULL. @@ -84,6 +87,9 @@ class Profile; - (IBAction)resetThemeToDefault:(id)sender; - (IBAction)themesGallery:(id)sender; +// Under the hood +- (IBAction)browseDownloadLocation:(id)sender; + // Usable from cocoa bindings to hook up the custom home pages table. @property(readonly) CustomHomePagesModel* customPagesSource; diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index b3f234d..8182420 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -74,6 +74,7 @@ std::wstring GetNewTabUIURLString() { - (void)setSafeBrowsing:(BOOL)value; - (void)setMetricsRecording:(BOOL)value; - (void)setCookieBehavior:(NSInteger)value; +- (void)setAskForSaveLocation:(BOOL)value; @end // A C++ class registered for changes in preferences. Bridges the @@ -201,6 +202,9 @@ class PrefObserverBridge : public NotificationObserver { metricsRecording_.Init(prefs::kMetricsReportingEnabled, local, observer_.get()); cookieBehavior_.Init(prefs::kCookieBehavior, prefs_, observer_.get()); + defaultDownloadLocation_.Init(prefs::kDownloadDefaultDirectory, prefs_, + observer_.get()); + askForSaveLocation_.Init(prefs::kPromptForDownload, prefs_, observer_.get()); } // Clean up what was registered in -registerPrefObservers. We only have to @@ -727,6 +731,38 @@ const int kDisabledIndex = 1; else if (*prefName == prefs::kCookieBehavior) { [self setCookieBehavior:cookieBehavior_.GetValue()]; } + else if (*prefName == prefs::kPromptForDownload) { + [self setAskForSaveLocation:askForSaveLocation_.GetValue() ? YES : NO]; + } +} + +// Set the new download path and notify the UI via KVO. +- (void)downloadPathPanelDidEnd:(NSOpenPanel*)panel + code:(NSInteger)returnCode + context:(void*)context { + if (returnCode == NSOKButton) { + [self recordUserAction:L"Options_SetDownloadDirectory"]; + NSURL* path = [[panel URLs] lastObject]; // We only allow 1 item. + [self willChangeValueForKey:@"defaultDownloadLocation"]; + defaultDownloadLocation_.SetValue(base::SysNSStringToWide([path path])); + [self didChangeValueForKey:@"defaultDownloadLocation"]; + } +} + +// Bring up an open panel to allow the user to set a new downloads location. +- (void)browseDownloadLocation:(id)sender { + NSOpenPanel* panel = [NSOpenPanel openPanel]; + [panel setAllowsMultipleSelection:NO]; + [panel setCanChooseFiles:NO]; + [panel setCanChooseDirectories:YES]; + NSString* path = base::SysWideToNSString(defaultDownloadLocation_.GetValue()); + [panel beginSheetForDirectory:path + file:nil + types:nil + modalForWindow:[self window] + modalDelegate:self + didEndSelector:@selector(downloadPathPanelDidEnd:code:context:) + contextInfo:NULL]; } // Returns whether the alternate error page checkbox should be checked based @@ -860,6 +896,25 @@ const int kDisabledIndex = 1; cookieBehavior_.SetValue(policy); } +- (NSURL*)defaultDownloadLocation { + NSString* pathString = + base::SysWideToNSString(defaultDownloadLocation_.GetValue()); + return [NSURL fileURLWithPath:pathString]; +} + +- (BOOL)askForSaveLocation { + return askForSaveLocation_.GetValue(); +} + +- (void)setAskForSaveLocation:(BOOL)value { + if (value) { + [self recordUserAction:L"Options_AskForSaveLocation_Enable"]; + } else { + [self recordUserAction:L"Options_AskForSaveLocation_Disable"]; + } + askForSaveLocation_.SetValue(value); +} + //------------------------------------------------------------------------- // Callback when preferences are changed. |prefName| is the name of the |