From aa03df49ca94467840e083f41bac567f6e115a61 Mon Sep 17 00:00:00 2001 From: Alexandre Lision <alexandre.lision@savoirfairelinux.com> Date: Tue, 26 Jan 2016 09:39:25 -0500 Subject: [PATCH] history: fix history limit Since history is now handled by LRC, set the history limit instead of storing it client side. There is a race condition in LRC, we need to make sure daemon is started before creating the history, otherwise dring.yml is not parsed when we ask what is the currently set historyLimit and returns default value. Change-Id: I433a37ab559721df82225a6fe2695525ed85fcd0 Tuleap: #103 --- src/Constants.h | 2 -- src/GeneralPrefsVC.mm | 44 ++++++++++++++++++++++++---------- src/main.mm | 2 ++ ui/Base.lproj/GeneralPrefs.xib | 36 +++++++++++++++++++--------- 4 files changed, 58 insertions(+), 26 deletions(-) diff --git a/src/Constants.h b/src/Constants.h index f353bf4e..9ac6ef8a 100644 --- a/src/Constants.h +++ b/src/Constants.h @@ -31,6 +31,4 @@ namespace Preferences { NSString * const WindowBehaviour = @"window_behaviour"; /* KVO compliant */ NSString * const Notifications = @"enable_notifications"; - - NSString * const ShowAdvanced = @"show_advanced"; } diff --git a/src/GeneralPrefsVC.mm b/src/GeneralPrefsVC.mm index 30c72bc7..0e7e51f0 100644 --- a/src/GeneralPrefsVC.mm +++ b/src/GeneralPrefsVC.mm @@ -27,31 +27,42 @@ #import "Constants.h" @interface GeneralPrefsVC () -@property (unsafe_unretained) IBOutlet NSTextField *historyChangedLabel; -@property (unsafe_unretained) IBOutlet NSView *advancedGeneralSettings; -@property (unsafe_unretained) IBOutlet NSButton *startUpButton; -@property (unsafe_unretained) IBOutlet NSButton *toggleAutomaticUpdateCheck; -@property (unsafe_unretained) IBOutlet NSPopUpButton *checkIntervalPopUp; -@property (unsafe_unretained) IBOutlet NSView *sparkleContainer; +@property (unsafe_unretained) IBOutlet NSTextField* historyChangedLabel; +@property (unsafe_unretained) IBOutlet NSButton* startUpButton; +@property (unsafe_unretained) IBOutlet NSButton* toggleAutomaticUpdateCheck; +@property (unsafe_unretained) IBOutlet NSPopUpButton* checkIntervalPopUp; +@property (unsafe_unretained) IBOutlet NSView* sparkleContainer; +@property (unsafe_unretained) IBOutlet NSTextField* historyTextField; +@property (unsafe_unretained) IBOutlet NSStepper* historyStepper; +@property (unsafe_unretained) IBOutlet NSButton* historySwitch; @end @implementation GeneralPrefsVC @synthesize historyChangedLabel; -@synthesize advancedGeneralSettings; @synthesize startUpButton; @synthesize toggleAutomaticUpdateCheck; @synthesize checkIntervalPopUp; @synthesize sparkleContainer; +@synthesize historyTextField; +@synthesize historyStepper; +@synthesize historySwitch; - (void)loadView { [super loadView]; [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:Preferences::HistoryLimit options:NSKeyValueObservingOptionNew context:NULL]; - [[NSUserDefaults standardUserDefaults] addObserver:self forKeyPath:Preferences::ShowAdvanced options:NSKeyValueObservingOptionNew context:NULL]; [startUpButton setState:[self isLaunchAtStartup]]; + int historyLimit = CategorizedHistoryModel::instance().historyLimit(); + [historyTextField setStringValue:[NSString stringWithFormat:@"%d", historyLimit]]; + [historyStepper setIntValue:historyLimit]; + + BOOL limited = CategorizedHistoryModel::instance().isHistoryLimited(); + [historySwitch setState:limited]; + [historyStepper setEnabled:limited]; + [historyTextField setEnabled:limited]; #if ENABLE_SPARKLE [sparkleContainer setHidden:NO]; SUUpdater *updater = [SUUpdater sharedUpdater]; @@ -63,13 +74,11 @@ [sparkleContainer setHidden:YES]; #endif - //[advancedGeneralSettings setHidden:![[NSUserDefaults standardUserDefaults] boolForKey:Preferences::ShowAdvanced]]; } - (void) dealloc { [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:Preferences::HistoryLimit]; - [[NSUserDefaults standardUserDefaults] removeObserver:self forKeyPath:Preferences::ShowAdvanced]; } - (IBAction)clearHistory:(id)sender { @@ -77,14 +86,23 @@ [historyChangedLabel setHidden:NO]; } +- (IBAction)toggleHistory:(id)sender { + CategorizedHistoryModel::instance().setHistoryLimited([sender state]); + int historyLimit = CategorizedHistoryModel::instance().historyLimit(); + [historyTextField setStringValue:[NSString stringWithFormat:@"%d", historyLimit]]; + [historyStepper setIntValue:historyLimit]; + [historyChangedLabel setHidden:NO]; + [historyStepper setEnabled:[sender state]]; + [historyTextField setEnabled:[sender state]]; +} + // KVO handler -(void)observeValueForKeyPath:(NSString *)aKeyPath ofObject:(id)anObject change:(NSDictionary *)aChange context:(void *)aContext { - if (aKeyPath == Preferences::HistoryLimit) { + if ([aKeyPath isEqualToString:Preferences::HistoryLimit]) { + CategorizedHistoryModel::instance().setHistoryLimit([[aChange objectForKey: NSKeyValueChangeNewKey] integerValue]); [historyChangedLabel setHidden:NO]; - } else if (aKeyPath == Preferences::ShowAdvanced) { - //[advancedGeneralSettings setHidden:[[aChange objectForKey: NSKeyValueChangeNewKey] boolValue]]; } } diff --git a/src/main.mm b/src/main.mm index 075ee706..fd412b7d 100644 --- a/src/main.mm +++ b/src/main.mm @@ -33,6 +33,7 @@ #import <categorizedhistorymodel.h> #import <localhistorycollection.h> #import <numbercategorymodel.h> +#import <callmodel.h> #import "backends/AddressBookBackend.h" #import "delegates/ImageManipulationDelegate.h" @@ -62,6 +63,7 @@ int main(int argc, const char *argv[]) { } } + CallModel::instance(); CategorizedHistoryModel::instance().addCollection<LocalHistoryCollection>(LoadOptions::FORCE_ENABLED); /* make sure basic number categories exist, in case user has no contacts diff --git a/ui/Base.lproj/GeneralPrefs.xib b/ui/Base.lproj/GeneralPrefs.xib index ab6def3a..d49bd234 100644 --- a/ui/Base.lproj/GeneralPrefs.xib +++ b/ui/Base.lproj/GeneralPrefs.xib @@ -1,13 +1,16 @@ <?xml version="1.0" encoding="UTF-8" standalone="no"?> -<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> +<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="9531" systemVersion="15B42" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct"> <dependencies> - <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/> + <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="9531"/> </dependencies> <objects> <customObject id="-2" userLabel="File's Owner" customClass="GeneralPrefsVC"> <connections> <outlet property="checkIntervalPopUp" destination="RYP-3d-PCa" id="JNO-GR-CV8"/> <outlet property="historyChangedLabel" destination="Gyi-ID-Z3v" id="aoO-Fh-UCQ"/> + <outlet property="historyStepper" destination="QmA-ZI-ZL5" id="dDV-1G-rZs"/> + <outlet property="historySwitch" destination="DgD-2y-4g5" id="GYk-pz-jGT"/> + <outlet property="historyTextField" destination="tHZ-7Q-5iP" id="keP-y2-7Pg"/> <outlet property="sparkleContainer" destination="yVO-jk-ay3" id="zni-hI-88D"/> <outlet property="startUpButton" destination="1Nr-L4-fcd" id="veu-Hi-c7L"/> <outlet property="toggleAutomaticUpdateCheck" destination="MCd-PD-kd7" id="rSB-ac-Nm2"/> @@ -68,6 +71,9 @@ <behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/> <font key="font" metaFont="system"/> </buttonCell> + <connections> + <action selector="toggleHistory:" target="-2" id="TiP-Pw-MFu"/> + </connections> </button> <stepper horizontalHuggingPriority="750" verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="QmA-ZI-ZL5"> <rect key="frame" x="251" y="141" width="19" height="27"/> @@ -87,7 +93,11 @@ <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/> </textFieldCell> <connections> - <binding destination="Sz0-vm-i3t" name="value" keyPath="values.history_limit" id="O2j-lT-MbR"/> + <binding destination="Sz0-vm-i3t" name="value" keyPath="values.history_limit" id="4us-N3-vCf"> + <dictionary key="options"> + <bool key="NSContinuouslyUpdatesValue" value="YES"/> + </dictionary> + </binding> </connections> </textField> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="nah-Jm-ZYB"> @@ -111,14 +121,6 @@ <action selector="clearHistory:" target="-2" id="yN7-bB-7EY"/> </connections> </button> - <textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Gyi-ID-Z3v"> - <rect key="frame" x="361" y="144" width="167" height="17"/> - <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="(Applied on application restart)" id="OTl-vx-S43"> - <font key="font" metaFont="smallSystem"/> - <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> - <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> - </textFieldCell> - </textField> <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="j3T-5j-Fom"> <rect key="frame" x="38" y="303" width="94" height="17"/> <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Interruptions" id="Rzy-Gh-3wQ"> @@ -192,9 +194,21 @@ <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> </textFieldCell> </textField> + <textField hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Gyi-ID-Z3v"> + <rect key="frame" x="310" y="148" width="169" height="14"/> + <constraints> + <constraint firstAttribute="width" relation="greaterThanOrEqual" constant="165" id="wfZ-X2-WX8"/> + </constraints> + <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="(Applied on application restart)" id="OTl-vx-S43"> + <font key="font" metaFont="smallSystem"/> + <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/> + <color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/> + </textFieldCell> + </textField> </subviews> <constraints> <constraint firstItem="Is4-pD-LOT" firstAttribute="leading" secondItem="lIm-zX-RIV" secondAttribute="trailing" constant="8" id="Apx-HB-LIX"/> + <constraint firstItem="Gyi-ID-Z3v" firstAttribute="leading" secondItem="nah-Jm-ZYB" secondAttribute="trailing" constant="8" id="EYY-WC-fCM"/> <constraint firstItem="Oth-up-2k2" firstAttribute="leading" secondItem="Is4-pD-LOT" secondAttribute="leading" id="Fdb-2p-ULe"/> <constraint firstItem="nah-Jm-ZYB" firstAttribute="leading" secondItem="QmA-ZI-ZL5" secondAttribute="trailing" constant="8" id="JJi-0O-nUi"/> <constraint firstItem="QmA-ZI-ZL5" firstAttribute="leading" secondItem="tHZ-7Q-5iP" secondAttribute="trailing" constant="8" id="YPs-UE-IFi"/> -- GitLab