Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions AppController.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@
// to handle command flow and acts as delegate for the initial window.
@interface AppController : NSObject <NSApplicationDelegate> {
IBOutlet SCDurationSlider* blockDurationSlider_;
IBOutlet NSTextField* blockSliderTimeDisplayLabel_;
IBOutlet NSTextField* blocklistTeaserLabel_;
IBOutlet NSTextField* blockSliderTimeDurationDisplayLabel_;
IBOutlet NSTextField* blockSliderTimeEndDisplayLabel_;
IBOutlet NSTextField* blocklistTeaserLabel_;
IBOutlet NSButton* submitButton_;
IBOutlet NSWindow* initialWindow_;

IBOutlet NSMenuItem* domainListMenuItem_;
IBOutlet NSMenuItem* editBlocklistMenuItem_;
IBOutlet NSMenuItem* editBlocklistMenuItem_;
IBOutlet NSButton* editBlocklistButton_;
IBOutlet DomainListWindowController* domainListWindowController_;
IBOutlet TimerWindowController* timerWindowController_;
NSWindowController* preferencesWindowController_;
NSUserDefaults* defaults_;
SCSettings* settings_;
SCSettings* settings_;
NSLock* refreshUILock_;
BOOL blockIsOn;
BOOL addingBlock;
Expand Down
5 changes: 3 additions & 2 deletions AppController.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ - (IBAction)updateTimeSliderDisplay:(id)sender {
numMinutes = [defaults_ integerForKey: @"BlockDuration"];
}

blockSliderTimeDisplayLabel_.stringValue = blockDurationSlider_.durationDescription;
blockSliderTimeDurationDisplayLabel_.stringValue = blockDurationSlider_.timeDurationDescription;
blockSliderTimeEndDisplayLabel_.stringValue = blockDurationSlider_.timeEndDescription;

[submitButton_ setEnabled: (numMinutes > 0) && ([[defaults_ arrayForKey: @"Blocklist"] count] > 0)];
}
Expand Down Expand Up @@ -144,7 +145,7 @@ - (BOOL)showLongBlockWarningsIfNecessary {

NSAlert* alert = [[NSAlert alloc] init];
alert.messageText = NSLocalizedString(@"That's a long block!", "Long block warning title");
alert.informativeText = [NSString stringWithFormat: NSLocalizedString(@"Remember that once you start the block, you can't turn it back off until the timer expires in %@ - even if you accidentally blocked a site you need. Consider starting a shorter block first, to test your list and make sure everything's working properly.", @"Long block warning message"), [SCDurationSlider timeSliderDisplayStringFromNumberOfMinutes: blockDuration]];
alert.informativeText = [NSString stringWithFormat: NSLocalizedString(@"Remember that once you start the block, you can't turn it back off until the timer expires in %@ - even if you accidentally blocked a site you need. Consider starting a shorter block first, to test your list and make sure everything's working properly.", @"Long block warning message"), [SCDurationSlider timeSliderDurationDisplayStringFromNumberOfMinutes: blockDuration]];
[alert addButtonWithTitle: NSLocalizedString(@"Cancel", @"Button to cancel a long block")];
[alert addButtonWithTitle: NSLocalizedString(@"Start Block Anyway", "Button to start a long block despite warnings")];
alert.showsSuppressionButton = YES;
Expand Down
23 changes: 17 additions & 6 deletions Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,16 @@ DQ
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="478">
<rect key="frame" x="17" y="78" width="585" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="1 minute" id="479">
<rect key="frame" x="17" y="78" width="290" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" title="1 minute" id="479">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="rFZ-Tu-gCC">
<rect key="frame" x="313" y="78" width="290" height="16"/>
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="right" title="1 minute" id="Jkx-oB-TPU">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
Expand All @@ -305,19 +313,21 @@ DQ
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="543" secondAttribute="trailing" constant="20" id="0Wn-BM-hpf"/>
<constraint firstItem="rFZ-Tu-gCC" firstAttribute="leading" secondItem="478" secondAttribute="trailing" constant="10" id="BtI-Lb-5g2"/>
<constraint firstItem="465" firstAttribute="trailing" secondItem="543" secondAttribute="trailing" id="Eqk-xh-OIc"/>
<constraint firstAttribute="trailing" secondItem="rFZ-Tu-gCC" secondAttribute="trailing" constant="19" id="Gus-Sa-aUF"/>
<constraint firstItem="541" firstAttribute="centerX" secondItem="372" secondAttribute="centerX" id="KyZ-Mc-sxV"/>
<constraint firstAttribute="bottom" secondItem="543" secondAttribute="bottom" constant="11" id="MQd-6b-WA4"/>
<constraint firstItem="JfI-b0-nf0" firstAttribute="centerY" secondItem="543" secondAttribute="centerY" id="NDo-M0-Sne"/>
<constraint firstItem="JfI-b0-nf0" firstAttribute="leading" secondItem="478" secondAttribute="leading" id="UNP-ql-5cB"/>
<constraint firstItem="478" firstAttribute="leading" secondItem="372" secondAttribute="leading" constant="19" id="WdA-X8-Sm5"/>
<constraint firstItem="rFZ-Tu-gCC" firstAttribute="width" secondItem="478" secondAttribute="width" id="Xck-dp-1pl"/>
<constraint firstItem="465" firstAttribute="centerX" secondItem="541" secondAttribute="centerX" id="fF7-jW-hAj"/>
<constraint firstItem="543" firstAttribute="top" secondItem="465" secondAttribute="bottom" constant="15" id="gCe-4n-0nP"/>
<constraint firstItem="465" firstAttribute="top" secondItem="478" secondAttribute="bottom" constant="10" id="hYl-Vr-Chb"/>
<constraint firstItem="541" firstAttribute="top" secondItem="372" secondAttribute="top" constant="30" id="jXt-Fy-vdp"/>
<constraint firstItem="478" firstAttribute="trailing" secondItem="543" secondAttribute="trailing" id="jmb-Wp-H3Y"/>
<constraint firstItem="543" firstAttribute="leading" secondItem="JfI-b0-nf0" secondAttribute="trailing" constant="23" id="mPT-an-Lpy"/>
<constraint firstItem="543" firstAttribute="leading" relation="lessThanOrEqual" secondItem="478" secondAttribute="trailing" constant="-10" id="o6E-qg-6q9"/>
<constraint firstItem="478" firstAttribute="bottom" secondItem="465" secondAttribute="top" constant="-10" id="spp-LO-oaf"/>
<constraint firstItem="465" firstAttribute="top" secondItem="rFZ-Tu-gCC" secondAttribute="bottom" constant="10" id="spZ-i2-pbD"/>
</constraints>
</view>
<connections>
Expand All @@ -328,7 +338,8 @@ DQ
<customObject id="469" customClass="AppController">
<connections>
<outlet property="blockDurationSlider_" destination="465" id="669"/>
<outlet property="blockSliderTimeDisplayLabel_" destination="478" id="670"/>
<outlet property="blockSliderTimeDurationDisplayLabel_" destination="478" id="hu8-kp-Pfa"/>
<outlet property="blockSliderTimeEndDisplayLabel_" destination="rFZ-Tu-gCC" id="g3q-F2-hcD"/>
<outlet property="blocklistTeaserLabel_" destination="JfI-b0-nf0" id="PED-q3-MAF"/>
<outlet property="domainListMenuItem_" destination="503" id="673"/>
<outlet property="editBlocklistButton_" destination="543" id="6tH-Bv-ZNK"/>
Expand Down
12 changes: 8 additions & 4 deletions SCDurationSlider.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ NS_ASSUME_NONNULL_BEGIN

@property (nonatomic, assign) NSInteger maxDuration;
@property (readonly) NSInteger durationValueMinutes;
@property (readonly) NSString* durationDescription;
@property (readonly) NSString* timeDurationDescription;
@property (readonly) NSString* timeEndDescription;

- (NSInteger)durationValueMinutes;
- (void)bindDurationToObject:(id)obj keyPath:(NSString*)keyPath;
- (NSString*)durationDescription;
- (NSString*)timeDurationDescription;
- (NSString*)timeEndDescription;

+ (NSString *)timeSliderDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds;
+ (NSString *)timeSliderDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes;
+ (NSString *)timeSliderDurationDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds;
+ (NSString *)timeSliderEndDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds;
+ (NSString *)timeSliderDurationDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes;
+ (NSString *)timeSliderEndDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes;

@end

Expand Down
52 changes: 47 additions & 5 deletions SCDurationSlider.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,17 @@ - (void)bindDurationToObject:(id)obj keyPath:(NSString*)keyPath {
}];
}

- (NSString*)durationDescription {
return [SCDurationSlider timeSliderDisplayStringFromNumberOfMinutes: self.durationValueMinutes];
- (NSString*)timeDurationDescription {
return [SCDurationSlider timeSliderDurationDisplayStringFromNumberOfMinutes: self.durationValueMinutes];
}

- (NSString*)timeEndDescription {
return [SCDurationSlider timeSliderEndDisplayStringFromNumberOfMinutes: self.durationValueMinutes];
}

// String conversion utility methods

+ (NSString *)timeSliderDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds {
+ (NSString *)timeSliderDurationDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds {
static SCTimeIntervalFormatter* formatter = nil;
if (formatter == nil) {
formatter = [[SCTimeIntervalFormatter alloc] init];
Expand All @@ -88,7 +92,45 @@ + (NSString *)timeSliderDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSe
return formatted;
}

+ (NSString *)timeSliderDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes {
+ (NSString *)timeSliderEndDisplayStringFromTimeInterval:(NSTimeInterval)numberOfSeconds {
static NSDateFormatter* formatter = nil;
if (formatter == nil) {
formatter = [[NSDateFormatter alloc] init];
}
formatter.timeStyle = NSDateFormatterNoStyle;
formatter.dateStyle = NSDateFormatterShortStyle;
NSString* todayDateStr = [formatter stringFromDate: [NSDate date]];
NSDate* targetDate = [NSDate dateWithTimeIntervalSinceNow:numberOfSeconds];
NSString* targetDateStr = [formatter stringFromDate: targetDate];

formatter.timeStyle = NSDateFormatterShortStyle;
formatter.dateStyle = [targetDateStr isEqual:todayDateStr] ? NSDateFormatterNoStyle : NSDateFormatterShortStyle;

NSString* formatted = [formatter stringForObjectValue:targetDate];
return formatted;
}

+ (NSString *)timeSliderDurationDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes {
if (numberOfMinutes < 0) return @"Invalid duration";

static NSCalendar* gregorian = nil;
if (gregorian == nil) {
gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
}

NSRange secondsRangePerMinute = [gregorian
rangeOfUnit:NSCalendarUnitSecond
inUnit:NSCalendarUnitMinute
forDate:[NSDate date]];
NSInteger numberOfSecondsPerMinute = (NSInteger)NSMaxRange(secondsRangePerMinute);

NSTimeInterval numberOfSecondsSelected = (NSTimeInterval)(numberOfSecondsPerMinute * numberOfMinutes);

NSString* displayString = [SCDurationSlider timeSliderDurationDisplayStringFromTimeInterval:numberOfSecondsSelected];
return displayString;
}

+ (NSString *)timeSliderEndDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinutes {
if (numberOfMinutes < 0) return @"Invalid duration";

static NSCalendar* gregorian = nil;
Expand All @@ -104,7 +146,7 @@ + (NSString *)timeSliderDisplayStringFromNumberOfMinutes:(NSInteger)numberOfMinu

NSTimeInterval numberOfSecondsSelected = (NSTimeInterval)(numberOfSecondsPerMinute * numberOfMinutes);

NSString* displayString = [SCDurationSlider timeSliderDisplayStringFromTimeInterval:numberOfSecondsSelected];
NSString* displayString = [SCDurationSlider timeSliderEndDisplayStringFromTimeInterval:numberOfSecondsSelected];
return displayString;
}

Expand Down
2 changes: 1 addition & 1 deletion TimerWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ - (IBAction)updateExtendSliderDisplay:(id)sender {
extendDurationSlider_.integerValue = extendDurationSlider_.maxDuration;
}

extendDurationLabel_.stringValue = extendDurationSlider_.durationDescription;
extendDurationLabel_.stringValue = extendDurationSlider_.timeDurationDescription;
}

- (IBAction) closeAddSheet:(id)sender {
Expand Down