diff options
-rw-r--r-- | chrome/app/nibs/Preferences.xib | 200 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.h | 7 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller.mm | 140 | ||||
-rw-r--r-- | chrome/browser/cocoa/preferences_window_controller_unittest.mm | 4 |
4 files changed, 322 insertions, 29 deletions
diff --git a/chrome/app/nibs/Preferences.xib b/chrome/app/nibs/Preferences.xib index 00123ef..22d1aa5 100644 --- a/chrome/app/nibs/Preferences.xib +++ b/chrome/app/nibs/Preferences.xib @@ -2,14 +2,15 @@ <archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03"> <data> <int key="IBDocument.SystemTarget">1050</int> - <string key="IBDocument.SystemVersion">9L30</string> - <string key="IBDocument.InterfaceBuilderVersion">677</string> + <string key="IBDocument.SystemVersion">9L31a</string> + <string key="IBDocument.InterfaceBuilderVersion">680</string> <string key="IBDocument.AppKitVersion">949.54</string> <string key="IBDocument.HIToolboxVersion">353.00</string> <object class="NSMutableArray" key="IBDocument.EditedObjectIDs"> <bool key="EncodedWithXMLCoder">YES</bool> <integer value="74"/> <integer value="3"/> + <integer value="482"/> </object> <object class="NSArray" key="IBDocument.PluginDependencies"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -1702,7 +1703,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string key="NSClassName">NSView</string> </object> <object class="NSCustomView" id="393583039"> - <nil key="NSNextResponder"/> + <reference key="NSNextResponder"/> <int key="NSvFlags">268</int> <object class="NSMutableArray" key="NSSubviews"> <bool key="EncodedWithXMLCoder">YES</bool> @@ -1722,6 +1723,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference key="NSTextColor" ref="748094473"/> </object> </object> + <object class="NSTextField" id="20640598"> + <reference key="NSNextResponder" ref="393583039"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{17, 290}, {128, 60}}</string> + <reference key="NSSuperview" ref="393583039"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="101746388"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">71303168</int> + <string key="NSContents">^IDS_SYNC_OPTIONS_GROUP_NAME</string> + <reference key="NSSupport" ref="290273273"/> + <reference key="NSControlView" ref="20640598"/> + <reference key="NSBackgroundColor" ref="592613688"/> + <reference key="NSTextColor" ref="748094473"/> + </object> + </object> <object class="NSMatrix" id="1019357609"> <reference key="NSNextResponder" ref="393583039"/> <int key="NSvFlags">266</int> @@ -1934,6 +1951,26 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <int key="NSPeriodicInterval">25</int> </object> </object> + <object class="NSButton" id="203729106"> + <reference key="NSNextResponder" ref="393583039"/> + <int key="NSvFlags">268</int> + <string key="NSFrame">{{146, 322}, {184, 32}}</string> + <reference key="NSSuperview" ref="393583039"/> + <bool key="NSEnabled">YES</bool> + <object class="NSButtonCell" key="NSCell" id="431766699"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">134217728</int> + <string key="NSContents">^IDS_SYNC_START_SYNC_BUTTON_LABEL</string> + <reference key="NSSupport" ref="445696277"/> + <reference key="NSControlView" ref="203729106"/> + <int key="NSButtonFlags">-2038284033</int> + <int key="NSButtonFlags2">129</int> + <string key="NSAlternateContents"/> + <string key="NSKeyEquivalent"/> + <int key="NSPeriodicDelay">200</int> + <int key="NSPeriodicInterval">25</int> + </object> + </object> <object class="NSTextField" id="921350969"> <reference key="NSNextResponder" ref="393583039"/> <int key="NSvFlags">268</int> @@ -1998,6 +2035,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference key="NSTextColor" ref="748094473"/> </object> </object> + <object class="NSTextField" id="90260648"> + <reference key="NSNextResponder" ref="393583039"/> + <int key="NSvFlags">266</int> + <string key="NSFrame">{{149, 294}, {364, 28}}</string> + <reference key="NSSuperview" ref="393583039"/> + <bool key="NSEnabled">YES</bool> + <object class="NSTextFieldCell" key="NSCell" id="123936632"> + <int key="NSCellFlags">67239424</int> + <int key="NSCellFlags2">272629760</int> + <string key="NSContents">^IDS_SYNC_NOT_SET_UP_INFO</string> + <reference key="NSSupport" ref="783256529"/> + <reference key="NSControlView" ref="90260648"/> + <reference key="NSBackgroundColor" ref="592613688"/> + <reference key="NSTextColor" ref="748094473"/> + </object> + </object> <object class="NSButton" id="885386403"> <reference key="NSNextResponder" ref="393583039"/> <int key="NSvFlags">268</int> @@ -2271,7 +2324,8 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> </object> - <string key="NSFrameSize">{530, 290}</string> + <string key="NSFrameSize">{530, 370}</string> + <reference key="NSSuperview"/> <string key="NSClassName">NSView</string> </object> <object class="NSCustomView" id="933437956"> @@ -2394,6 +2448,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <object class="NSCustomObject" id="376486454"> <string key="NSClassName">GTMIBArray</string> </object> + <object class="NSCustomObject" id="821768455"> + <string key="NSClassName">GTMIBArray</string> + </object> <object class="NSCustomObject" id="325031373"> <string key="NSClassName">GTMIBArray</string> </object> @@ -3482,6 +3539,62 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> <int key="connectionID">600</int> </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">syncButton_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="203729106"/> + </object> + <int key="connectionID">607</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">syncStatus_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="90260648"/> + </object> + <int key="connectionID">608</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBActionConnection" key="connection"> + <string key="label">doSyncAction:</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="203729106"/> + </object> + <int key="connectionID">609</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">object1_</string> + <reference key="source" ref="821768455"/> + <reference key="destination" ref="20640598"/> + </object> + <int key="connectionID">611</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">personalStuffGroupSync_</string> + <reference key="source" ref="1001"/> + <reference key="destination" ref="821768455"/> + </object> + <int key="connectionID">614</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">object2_</string> + <reference key="source" ref="821768455"/> + <reference key="destination" ref="203729106"/> + </object> + <int key="connectionID">615</int> + </object> + <object class="IBConnectionRecord"> + <object class="IBOutletConnection" key="connection"> + <string key="label">object3_</string> + <reference key="source" ref="821768455"/> + <reference key="destination" ref="90260648"/> + </object> + <int key="connectionID">616</int> + </object> </object> <object class="IBMutableOrderedSet" key="objectRecords"> <object class="NSArray" key="orderedObjects"> @@ -3955,6 +4068,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference ref="423027085"/> <reference ref="865039969"/> <reference ref="987908490"/> + <reference ref="20640598"/> + <reference ref="90260648"/> + <reference ref="203729106"/> </object> <reference key="parent" ref="415821041"/> <string key="objectName">Personal Stuff View</string> @@ -4656,6 +4772,54 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <reference key="object" ref="938815385"/> <reference key="parent" ref="415821041"/> </object> + <object class="IBObjectRecord"> + <int key="objectID">601</int> + <reference key="object" ref="20640598"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="101746388"/> + </object> + <reference key="parent" ref="393583039"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">602</int> + <reference key="object" ref="101746388"/> + <reference key="parent" ref="20640598"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">603</int> + <reference key="object" ref="90260648"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="123936632"/> + </object> + <reference key="parent" ref="393583039"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">604</int> + <reference key="object" ref="123936632"/> + <reference key="parent" ref="90260648"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">605</int> + <reference key="object" ref="203729106"/> + <object class="NSMutableArray" key="children"> + <bool key="EncodedWithXMLCoder">YES</bool> + <reference ref="431766699"/> + </object> + <reference key="parent" ref="393583039"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">606</int> + <reference key="object" ref="431766699"/> + <reference key="parent" ref="203729106"/> + </object> + <object class="IBObjectRecord"> + <int key="objectID">610</int> + <reference key="object" ref="821768455"/> + <reference key="parent" ref="415821041"/> + <string key="objectName">Personal Stuff Sync Group</string> + </object> </object> </object> <object class="NSMutableDictionary" key="flattenedProperties"> @@ -4807,7 +4971,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>59.IBPluginDependency</string> <string>596.IBPluginDependency</string> <string>60.IBPluginDependency</string> + <string>601.IBPluginDependency</string> + <string>602.IBPluginDependency</string> + <string>603.IBPluginDependency</string> + <string>604.IBPluginDependency</string> + <string>605.IBPluginDependency</string> + <string>606.IBPluginDependency</string> <string>61.IBPluginDependency</string> + <string>610.IBPluginDependency</string> <string>62.IBPluginDependency</string> <string>63.IBPluginDependency</string> <string>64.IBPluginDependency</string> @@ -4945,7 +5116,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <object class="NSMutableArray"> <bool key="EncodedWithXMLCoder">YES</bool> </object> - <string>{{86, 695}, {530, 290}}</string> + <string>{{181, 428}, {530, 370}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>{{87, 136}, {530, 463}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -4995,7 +5166,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> - <string>{{557, 200}, {443, 665}}</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>com.apple.InterfaceBuilder.CocoaPlugin</string> + <string>{{557, 191}, {443, 665}}</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> <string>com.apple.InterfaceBuilder.CocoaPlugin</string> @@ -5035,7 +5213,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> </object> </object> <nil key="sourceID"/> - <int key="maxID">600</int> + <int key="maxID">616</int> </object> <object class="IBClassDescriber" key="IBDocument.Classes"> <object class="NSMutableArray" key="referencedPartialClassDescriptions"> @@ -5187,6 +5365,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>addHomepage:</string> <string>browseDownloadLocation:</string> <string>clearData:</string> + <string>doSyncAction:</string> <string>importData:</string> <string>makeDefaultBrowser:</string> <string>manageSearchEngines:</string> @@ -5215,6 +5394,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>id</string> <string>id</string> <string>id</string> + <string>id</string> </object> </object> <object class="NSMutableDictionary" key="outlets"> @@ -5234,8 +5414,11 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>personalStuffGroupAutofill_</string> <string>personalStuffGroupBrowserData_</string> <string>personalStuffGroupPasswords_</string> + <string>personalStuffGroupSync_</string> <string>personalStuffGroupThemes_</string> <string>personalStuffView_</string> + <string>syncButton_</string> + <string>syncStatus_</string> <string>toolbar_</string> <string>underTheHoodContentView_</string> <string>underTheHoodScroller_</string> @@ -5257,7 +5440,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA</bytes> <string>NSArray</string> <string>NSArray</string> <string>NSArray</string> + <string>NSArray</string> <string>NSView</string> + <string>NSButton</string> + <string>NSTextField</string> <string>NSToolbar</string> <string>NSView</string> <string>NSScrollView</string> diff --git a/chrome/browser/cocoa/preferences_window_controller.h b/chrome/browser/cocoa/preferences_window_controller.h index 8f6351d..bd8e964 100644 --- a/chrome/browser/cocoa/preferences_window_controller.h +++ b/chrome/browser/cocoa/preferences_window_controller.h @@ -12,6 +12,7 @@ class PrefObserverBridge; class PrefService; class Profile; +class ProfileSyncService; @class SearchEngineListModel; // A window controller that handles the preferences window. The bulk of the @@ -30,6 +31,8 @@ class Profile; @private Profile* profile_; // weak ref PrefService* prefs_; // weak ref - Obtained from profile_ for convenience. + // weak ref - Also obtained from profile_ for convenience. May be NULL. + ProfileSyncService* syncService_; scoped_ptr<PrefObserverBridge> observer_; // Watches for pref changes. IBOutlet NSToolbar* toolbar_; @@ -49,6 +52,7 @@ class Profile; IBOutlet NSArray* basicsGroupDefaultBrowser_; // The groups of the Personal Stuff view for layout fixup. + IBOutlet NSArray* personalStuffGroupSync_; IBOutlet NSArray* personalStuffGroupPasswords_; IBOutlet NSArray* personalStuffGroupAutofill_; IBOutlet NSArray* personalStuffGroupBrowserData_; @@ -73,6 +77,8 @@ class Profile; // User Data panel BooleanPrefMember askSavePasswords_; BooleanPrefMember formAutofill_; + IBOutlet NSButton* syncButton_; + IBOutlet NSTextField* syncStatus_; // Under the hood panel IBOutlet NSView* underTheHoodContentView_; @@ -112,6 +118,7 @@ class Profile; - (IBAction)clearData:(id)sender; - (IBAction)resetThemeToDefault:(id)sender; - (IBAction)themesGallery:(id)sender; +- (IBAction)doSyncAction:(id)sender; // Under the hood - (IBAction)browseDownloadLocation:(id)sender; diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index bdb4dd6..1a4967a 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -6,7 +6,9 @@ #include <algorithm> #include "app/l10n_util.h" +#include "app/l10n_util_mac.h" #include "base/mac_util.h" +#include "base/string16.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" #include "chrome/browser/browser.h" @@ -26,6 +28,8 @@ #include "chrome/browser/safe_browsing/safe_browsing_service.h" #include "chrome/browser/session_startup_pref.h" #include "chrome/browser/shell_integration.h" +#include "chrome/browser/sync/profile_sync_service.h" +#include "chrome/browser/sync/sync_status_ui_helper.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_details.h" #include "chrome/common/notification_observer.h" @@ -249,7 +253,6 @@ NSInteger CompareFrameY(id view1, id view2, void* context) { return NSOrderedSame; } -#if !defined(GOOGLE_CHROME_BUILD) // Helper to remove a view and move everything above it down to take over the // space. void RemoveViewFromView(NSView* view, NSView* toRemove) { @@ -261,32 +264,48 @@ void RemoveViewFromView(NSView* view, NSView* toRemove) { NSUInteger index = [views indexOfObject:toRemove]; DCHECK_NE(index, NSNotFound); NSUInteger count = [views count]; - if (index == (count - 1)) - return; // It was the top item, nothing to do (shouldn't happen). - - // The amount to shift is the bottom of |toRemove| to the bottom of the view - // above it. - CGFloat shiftDown = - NSMinY([[views objectAtIndex:index + 1] frame]) - - NSMinY([toRemove frame]); - - // Now cycle over the views above it moving them down. - for (++index; index < count; ++index) { - NSView* view = [views objectAtIndex:index]; - NSPoint origin = [view frame].origin; - origin.y -= shiftDown; - [view setFrameOrigin:origin]; + CGFloat shrinkHeight = 0; + if (index < (count - 1)) { + // If we're not the topmost control, the amount to shift is the bottom of + // |toRemove| to the bottom of the view above it. + CGFloat shiftDown = + NSMinY([[views objectAtIndex:index + 1] frame]) - + NSMinY([toRemove frame]); + + // Now cycle over the views above it moving them down. + for (++index; index < count; ++index) { + NSView* view = [views objectAtIndex:index]; + NSPoint origin = [view frame].origin; + origin.y -= shiftDown; + [view setFrameOrigin:origin]; + } + + shrinkHeight = shiftDown; + } else if (index > 0) { + // If we're the topmost control, there's nothing to shift but we want to + // shrink until the top edge of the second-topmost control, unless it is + // actually higher than the topmost control (since we're sorting by the + // bottom edge). + shrinkHeight = std::max(0.f, + NSMaxY([toRemove frame]) - + NSMaxY([[views objectAtIndex:index - 1] frame])); } + // If we only have one control, don't do any resizing (for now). // Remove |toRemove|. [toRemove removeFromSuperview]; - // Resize the view. [GTMUILocalizerAndLayoutTweaker resizeViewWithoutAutoResizingSubViews:view - delta:NSMakeSize(0, -shiftDown)]; + delta:NSMakeSize(0, -shrinkHeight)]; +} + +// Simply removes all the views in |toRemove|. +void RemoveGroupFromView(NSView* view, NSArray* toRemove) { + for (NSView* viewToRemove in toRemove) { + RemoveViewFromView(view, viewToRemove); + } } -#endif // !defined(GOOGLE_CHROME_BUILD) // Helper to tweak the layout of the "Under the Hood" content by autosizing all // the views and moving things up vertically. Special case the two controls for @@ -332,6 +351,9 @@ CGFloat AutoSizeUnderTheHoodContent(NSView* view, // Callback when preferences are changed. |prefName| is the name of the // pref that has changed. - (void)prefChanged:(std::wstring*)prefName; +// Callback when sync state has changed. syncService_ needs to be +// queried to find out what happened. +- (void)syncStateChanged; // Record the user performed a certain action and save the preferences. - (void)recordUserAction:(const wchar_t*)action; - (void)registerPrefObservers; @@ -361,10 +383,14 @@ CGFloat AutoSizeUnderTheHoodContent(NSView* view, // A C++ class registered for changes in preferences. Bridges the // notification back to the PWC. -class PrefObserverBridge : public NotificationObserver { +class PrefObserverBridge : public NotificationObserver, + public ProfileSyncServiceObserver { public: PrefObserverBridge(PreferencesWindowController* controller) - : controller_(controller) { } + : controller_(controller) {} + + virtual ~PrefObserverBridge() {} + // Overridden from NotificationObserver: virtual void Observe(NotificationType type, const NotificationSource& source, @@ -372,6 +398,12 @@ class PrefObserverBridge : public NotificationObserver { if (type == NotificationType::PREF_CHANGED) [controller_ prefChanged:Details<std::wstring>(details).ptr()]; } + + // Overridden from ProfileSyncServiceObserver. + virtual void OnStateChanged() { + [controller_ syncStateChanged]; + } + private: PreferencesWindowController* controller_; // weak, owns us }; @@ -434,6 +466,11 @@ class PrefObserverBridge : public NotificationObserver { // it up a bit. [animation_ gtm_setDuration:0.2]; [animation_ setAnimationBlockingMode:NSAnimationNonblocking]; + + // TODO(akalin): handle incognito profiles? The windows version of this + // (in chrome/browser/views/options/content_page_view.cc) just does what + // we do below. + syncService_ = profile_->GetProfileSyncService(); } return self; } @@ -464,7 +501,7 @@ class PrefObserverBridge : public NotificationObserver { #endif // !defined(GOOGLE_CHROME_BUILD) // There are three problem children within the groups: - // Bascis - Default Browser + // Basics - Default Browser // Personal Stuff - Themes // Personal Stuff - Browser Data // These three have buttons that with some localizations are wider then the @@ -559,10 +596,24 @@ class PrefObserverBridge : public NotificationObserver { verticalShift += AutoSizeGroup(personalStuffGroupPasswords_, kAutoSizeGroupBehaviorVerticalToFit, verticalShift); + // We want to autosize the sync button but not the text field, so we use + // VerticalFirstToFit. + verticalShift += AutoSizeGroup(personalStuffGroupSync_, + kAutoSizeGroupBehaviorVerticalFirstToFit, + verticalShift); [GTMUILocalizerAndLayoutTweaker resizeViewWithoutAutoResizingSubViews:personalStuffView_ delta:NSMakeSize(0.0, verticalShift)]; + if (syncService_) { + syncService_->AddObserver(observer_.get()); + // Update the controls according to the initial state. + [self syncStateChanged]; + } else { + // If sync is disabled we don't want to show the sync controls at all. + RemoveGroupFromView(personalStuffView_, personalStuffGroupSync_); + } + // Make the window as wide as the views. NSWindow* prefsWindow = [self window]; NSRect frame = [prefsWindow frame]; @@ -613,6 +664,9 @@ class PrefObserverBridge : public NotificationObserver { } - (void)dealloc { + if (syncService_) { + syncService_->RemoveObserver(observer_.get()); + } [customPagesSource_ removeObserver:self forKeyPath:@"customHomePages"]; [[NSNotificationCenter defaultCenter] removeObserver:self]; [self unregisterPrefObservers]; @@ -1133,6 +1187,18 @@ const int kDisabledIndex = 1; } } +- (IBAction)doSyncAction:(id)sender { + DCHECK(syncService_); + if (syncService_->HasSyncSetupCompleted()) { + syncService_->DisableForUser(); + ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); + // TODO(akalin): Pop up a confirmation dialog before disabling syncing. + } else { + syncService_->EnableForUser(); + ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS); + } +} + - (void)setPasswordManagerEnabledIndex:(NSInteger)value { if (value == kEnabledIndex) [self recordUserAction:L"Options_PasswordManager_Enable"]; @@ -1526,6 +1592,36 @@ const int kDisabledIndex = 1; [self underHoodPrefChanged:prefName]; } +// Callback when sync service state has changed. +// +// TODO(akalin): Decomp this out since a lot of it is copied from the +// Windows version. +// TODO(akalin): Actually have a control for the link. +// TODO(akalin): Change the background of the status label/link on error. +// TODO(akalin): Make sure selecting the "Sync my bookmarks..." menu item +// pops up this preference pane if syncing has already been set up. +- (void)syncStateChanged { + DCHECK(syncService_); + + [syncButton_ setEnabled:!syncService_->WizardIsVisible()]; + NSString* buttonLabel; + if (syncService_->HasSyncSetupCompleted()) { + buttonLabel = l10n_util::GetNSStringWithFixup( + IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); + } else if (syncService_->SetupInProgress()) { + buttonLabel = l10n_util::GetNSStringWithFixup( + IDS_SYNC_NTP_SETUP_IN_PROGRESS); + } else { + buttonLabel = l10n_util::GetNSStringWithFixup( + IDS_SYNC_START_SYNC_BUTTON_LABEL); + } + [syncButton_ setTitle:buttonLabel]; + + string16 statusLabel, linkLabel; + SyncStatusUIHelper::GetLabels(syncService_, &statusLabel, &linkLabel); + [syncStatus_ setStringValue:base::SysUTF16ToNSString(statusLabel)]; +} + // Show the preferences window. - (IBAction)showPreferences:(id)sender { [self showWindow:sender]; diff --git a/chrome/browser/cocoa/preferences_window_controller_unittest.mm b/chrome/browser/cocoa/preferences_window_controller_unittest.mm index 8040e56..f09bfba 100644 --- a/chrome/browser/cocoa/preferences_window_controller_unittest.mm +++ b/chrome/browser/cocoa/preferences_window_controller_unittest.mm @@ -91,4 +91,8 @@ TEST_F(PrefsControllerTest, ValidateCustomHomePagesTable) { EXPECT_EQ(1U, [[pref_controller_ customPagesSource] countOfCustomHomePages]); } +// TODO(akalin): Figure out how to test sync controls. +// TODO(akalin): Figure out how to test that sync controls are not shown +// when there isn't a sync service. + } // namespace |