Browse Source

Can turn alarm on and off

Thomas Buck 9 years ago
parent
commit
b634d183a6
3 changed files with 60 additions and 13 deletions
  1. 12
    4
      OtaClock/Base.lproj/MainMenu.xib
  2. 1
    1
      OtaClock/Info.plist
  3. 47
    8
      OtaClock/MainWindow.m

+ 12
- 4
OtaClock/Base.lproj/MainMenu.xib View File

84
             </view>
84
             </view>
85
             <connections>
85
             <connections>
86
                 <outlet property="alarmDatePicker" destination="A2I-e6-ur5" id="wh1-Z1-r9q"/>
86
                 <outlet property="alarmDatePicker" destination="A2I-e6-ur5" id="wh1-Z1-r9q"/>
87
+                <outlet property="alarmModeItem" destination="S8W-ak-RY9" id="cdh-MO-cra"/>
88
+                <outlet property="alarmTextItem" destination="Sk9-Xp-wdP" id="s0c-OH-mqZ"/>
87
                 <outlet property="changeSize1" destination="Acr-Ff-Lm2" id="qUp-XP-Ffo"/>
89
                 <outlet property="changeSize1" destination="Acr-Ff-Lm2" id="qUp-XP-Ffo"/>
88
                 <outlet property="changeSize10" destination="eMz-8d-XLg" id="Ppm-Gu-5xS"/>
90
                 <outlet property="changeSize10" destination="eMz-8d-XLg" id="Ppm-Gu-5xS"/>
89
                 <outlet property="changeSize2" destination="sRn-WM-cKW" id="luN-Dk-xw4"/>
91
                 <outlet property="changeSize2" destination="sRn-WM-cKW" id="luN-Dk-xw4"/>
113
                             </menuItem>
115
                             </menuItem>
114
                             <menuItem title="Alarm Mode" id="S8W-ak-RY9">
116
                             <menuItem title="Alarm Mode" id="S8W-ak-RY9">
115
                                 <modifierMask key="keyEquivalentModifierMask"/>
117
                                 <modifierMask key="keyEquivalentModifierMask"/>
118
+                                <connections>
119
+                                    <action selector="toggleAlarm:" target="QvC-M9-y7g" id="nMc-tu-sCH"/>
120
+                                </connections>
116
                             </menuItem>
121
                             </menuItem>
117
                             <menuItem title="Show Date" id="0Cy-4I-9bF">
122
                             <menuItem title="Show Date" id="0Cy-4I-9bF">
118
                                 <modifierMask key="keyEquivalentModifierMask"/>
123
                                 <modifierMask key="keyEquivalentModifierMask"/>
253
                             <menuItem title="Item" id="IRB-i7-bez">
258
                             <menuItem title="Item" id="IRB-i7-bez">
254
                                 <modifierMask key="keyEquivalentModifierMask"/>
259
                                 <modifierMask key="keyEquivalentModifierMask"/>
255
                             </menuItem>
260
                             </menuItem>
261
+                            <menuItem title="Item" enabled="NO" id="Sk9-Xp-wdP">
262
+                                <modifierMask key="keyEquivalentModifierMask"/>
263
+                            </menuItem>
256
                         </items>
264
                         </items>
257
                     </menu>
265
                     </menu>
258
                 </menuItem>
266
                 </menuItem>
273
             <point key="canvasLocation" x="292.5" y="80.5"/>
281
             <point key="canvasLocation" x="292.5" y="80.5"/>
274
         </menu>
282
         </menu>
275
         <datePicker verticalHuggingPriority="750" id="A2I-e6-ur5">
283
         <datePicker verticalHuggingPriority="750" id="A2I-e6-ur5">
276
-            <rect key="frame" x="0.0" y="0.0" width="200" height="31"/>
284
+            <rect key="frame" x="0.0" y="0.0" width="125" height="127"/>
277
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
285
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
278
-            <datePickerCell key="cell" borderStyle="bezel" alignment="left" id="aSU-YP-y5q">
286
+            <datePickerCell key="cell" borderStyle="bezel" alignment="left" datePickerStyle="clockAndCalendar" id="aSU-YP-y5q">
279
                 <font key="font" metaFont="system"/>
287
                 <font key="font" metaFont="system"/>
280
                 <calendarDate key="date" timeIntervalSinceReferenceDate="-595929600" calendarFormat="%Y-%m-%d %H:%M:%S %z">
288
                 <calendarDate key="date" timeIntervalSinceReferenceDate="-595929600" calendarFormat="%Y-%m-%d %H:%M:%S %z">
281
                     <!--1982-02-12 16:00:00 +0000-->
289
                     <!--1982-02-12 16:00:00 +0000-->
283
                 </calendarDate>
291
                 </calendarDate>
284
                 <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
292
                 <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
285
                 <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
293
                 <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
286
-                <datePickerElements key="datePickerElements" year="YES" month="YES" day="YES" hour="YES" minute="YES" second="YES"/>
294
+                <datePickerElements key="datePickerElements" hour="YES" minute="YES"/>
287
             </datePickerCell>
295
             </datePickerCell>
288
             <connections>
296
             <connections>
289
                 <action selector="alarmDateSelected:" target="QvC-M9-y7g" id="ghc-DM-FuW"/>
297
                 <action selector="alarmDateSelected:" target="QvC-M9-y7g" id="ghc-DM-FuW"/>
290
             </connections>
298
             </connections>
291
-            <point key="canvasLocation" x="121.5" y="377"/>
299
+            <point key="canvasLocation" x="284" y="354.5"/>
292
         </datePicker>
300
         </datePicker>
293
     </objects>
301
     </objects>
294
 </document>
302
 </document>

+ 1
- 1
OtaClock/Info.plist View File

19
 	<key>CFBundleSignature</key>
19
 	<key>CFBundleSignature</key>
20
 	<string>????</string>
20
 	<string>????</string>
21
 	<key>CFBundleVersion</key>
21
 	<key>CFBundleVersion</key>
22
-	<string>371</string>
22
+	<string>389</string>
23
 	<key>LSApplicationCategoryType</key>
23
 	<key>LSApplicationCategoryType</key>
24
 	<string>public.app-category.utilities</string>
24
 	<string>public.app-category.utilities</string>
25
 	<key>LSMinimumSystemVersion</key>
25
 	<key>LSMinimumSystemVersion</key>

+ 47
- 8
OtaClock/MainWindow.m View File

19
 #define CONFIG_MILITARY_TIME @"military_time"
19
 #define CONFIG_MILITARY_TIME @"military_time"
20
 #define CONFIG_SHOW_DATE @"show_date"
20
 #define CONFIG_SHOW_DATE @"show_date"
21
 #define CONFIG_ALARM_TIME @"alarm_time"
21
 #define CONFIG_ALARM_TIME @"alarm_time"
22
+#define CONFIG_ALARM_MODE @"alarm_mode"
22
 
23
 
23
 #define MOUSE_CENTER_X 67
24
 #define MOUSE_CENTER_X 67
24
 #define MOUSE_CENTER_Y 47
25
 #define MOUSE_CENTER_Y 47
52
 @property (weak) IBOutlet NSMenuItem *keepOnTopItem;
53
 @property (weak) IBOutlet NSMenuItem *keepOnTopItem;
53
 @property (weak) IBOutlet NSMenuItem *setAlarmItem;
54
 @property (weak) IBOutlet NSMenuItem *setAlarmItem;
54
 @property (weak) IBOutlet NSMenuItem *showDateItem;
55
 @property (weak) IBOutlet NSMenuItem *showDateItem;
56
+@property (weak) IBOutlet NSMenuItem *alarmModeItem;
57
+@property (weak) IBOutlet NSMenuItem *alarmTextItem;
55
 
58
 
56
 @property (weak) IBOutlet NSMenuItem *changeSize1;
59
 @property (weak) IBOutlet NSMenuItem *changeSize1;
57
 @property (weak) IBOutlet NSMenuItem *changeSize2;
60
 @property (weak) IBOutlet NSMenuItem *changeSize2;
154
         self.alarmDatePicker.dateValue = [defaults objectForKey:CONFIG_ALARM_TIME];
157
         self.alarmDatePicker.dateValue = [defaults objectForKey:CONFIG_ALARM_TIME];
155
     }
158
     }
156
     self.setAlarmItem.view = self.alarmDatePicker;
159
     self.setAlarmItem.view = self.alarmDatePicker;
160
+    NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:self.alarmDatePicker.dateValue];
161
+    [self.alarmTextItem setTitle:[NSString stringWithFormat:@"%02ld:%02ld", (long)[components hour], (long)[components minute]]];
157
     
162
     
158
     // load show date state
163
     // load show date state
159
     if ([defaults objectForKey:CONFIG_SHOW_DATE] == nil) {
164
     if ([defaults objectForKey:CONFIG_SHOW_DATE] == nil) {
167
         self.showDateItem.state = NSOffState;
172
         self.showDateItem.state = NSOffState;
168
     }
173
     }
169
     
174
     
175
+    if ([defaults objectForKey:CONFIG_ALARM_MODE] != nil) {
176
+        if ([defaults boolForKey:CONFIG_ALARM_MODE] == YES) {
177
+            [self.alarmModeItem setState:NSOnState];
178
+            [[self.mainView render] drawAlarmDate:self.alarmDatePicker.dateValue];
179
+        }
180
+    }
181
+    
170
     [[self.mainView render] drawDate:showDate];
182
     [[self.mainView render] drawDate:showDate];
171
     
183
     
172
     [self setFrame:frame display:YES];
184
     [self setFrame:frame display:YES];
173
 }
185
 }
174
 
186
 
187
+- (IBAction)toggleAlarm:(id)sender {
188
+    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
189
+    
190
+    if (self.alarmModeItem.state == NSOnState) {
191
+        // Turn off alarm
192
+        [self.alarmModeItem setState:NSOffState];
193
+        [[self.mainView render] drawAlarmDate:nil];
194
+        [defaults setBool:NO forKey:CONFIG_ALARM_MODE];
195
+    } else {
196
+        // Turn on alarm
197
+        [self.alarmModeItem setState:NSOnState];
198
+        [[self.mainView render] drawAlarmDate:self.alarmDatePicker.dateValue];
199
+        [defaults setBool:YES forKey:CONFIG_ALARM_MODE];
200
+    }
201
+    
202
+    [defaults synchronize];
203
+    self.mainView.needsDisplay = YES;
204
+}
205
+
175
 - (void)drawAnimation:(NSNumber *)anim {
206
 - (void)drawAnimation:(NSNumber *)anim {
176
     if ([anim integerValue] > (3 * ANIMATION_SHADOW_HACK)) {
207
     if ([anim integerValue] > (3 * ANIMATION_SHADOW_HACK)) {
177
         [[self.mainView render] drawAnimation:0]; // reset
208
         [[self.mainView render] drawAnimation:0]; // reset
194
     
225
     
195
     // Check if a second went by
226
     // Check if a second went by
196
     NSDate *now = [NSDate date];
227
     NSDate *now = [NSDate date];
197
-    NSDateComponents *components = [[NSCalendar currentCalendar] components:NSSecondCalendarUnit fromDate:now];
228
+    NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit) fromDate:now];
198
     static NSInteger lastSec = -1;
229
     static NSInteger lastSec = -1;
199
     if (lastSec == [components second]) {
230
     if (lastSec == [components second]) {
200
         return;
231
         return;
204
     [[self.mainView render] drawWithDate:now];
235
     [[self.mainView render] drawWithDate:now];
205
     [[self.mainView render] blinkDots];
236
     [[self.mainView render] blinkDots];
206
     
237
     
207
-    NSTimeInterval in = [now timeIntervalSinceDate:self.alarmDatePicker.dateValue];
208
-    if ((in >= -0.5) && (in <= 0.5)) {
209
-        // We have reached the alarm time
210
-        NSLog(@"Alarm time reached!");
211
-        [self drawAnimation:[NSNumber numberWithInteger:1]];
238
+    if (self.alarmModeItem.state == NSOnState) {
239
+        NSDateComponents *alarmComponents = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:self.alarmDatePicker.dateValue];
240
+        if (([components minute] == [alarmComponents minute]) && ([components hour] == [alarmComponents hour]) && ([components second] == 0)) {
241
+            // We have reached the alarm time
242
+            NSLog(@"Alarm time reached!");
243
+            [self drawAnimation:[NSNumber numberWithInteger:1]];
244
+        }
212
     }
245
     }
213
     
246
     
214
     self.mainView.needsDisplay = YES;
247
     self.mainView.needsDisplay = YES;
235
 }
268
 }
236
 
269
 
237
 - (IBAction)alarmDateSelected:(id)sender {
270
 - (IBAction)alarmDateSelected:(id)sender {
238
-    [[self.mainView render] drawAlarmDate:self.alarmDatePicker.dateValue];
239
-    self.mainView.needsDisplay = YES;
271
+    // Update text representation
272
+    NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:self.alarmDatePicker.dateValue];
273
+    [self.alarmTextItem setTitle:[NSString stringWithFormat:@"%02ld:%02ld", (long)[components hour], (long)[components minute]]];
274
+    
275
+    if (self.alarmModeItem.state == NSOnState) {
276
+        [[self.mainView render] drawAlarmDate:self.alarmDatePicker.dateValue];
277
+        self.mainView.needsDisplay = YES;
278
+    }
240
     
279
     
241
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
280
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
242
     [defaults setObject:self.alarmDatePicker.dateValue forKey:CONFIG_ALARM_TIME];
281
     [defaults setObject:self.alarmDatePicker.dateValue forKey:CONFIG_ALARM_TIME];

Loading…
Cancel
Save