Explorar el Código

Can turn alarm on and off

Thomas Buck hace 9 años
padre
commit
b634d183a6
Se han modificado 3 ficheros con 60 adiciones y 13 borrados
  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 Ver fichero

@@ -84,6 +84,8 @@
84 84
             </view>
85 85
             <connections>
86 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 89
                 <outlet property="changeSize1" destination="Acr-Ff-Lm2" id="qUp-XP-Ffo"/>
88 90
                 <outlet property="changeSize10" destination="eMz-8d-XLg" id="Ppm-Gu-5xS"/>
89 91
                 <outlet property="changeSize2" destination="sRn-WM-cKW" id="luN-Dk-xw4"/>
@@ -113,6 +115,9 @@
113 115
                             </menuItem>
114 116
                             <menuItem title="Alarm Mode" id="S8W-ak-RY9">
115 117
                                 <modifierMask key="keyEquivalentModifierMask"/>
118
+                                <connections>
119
+                                    <action selector="toggleAlarm:" target="QvC-M9-y7g" id="nMc-tu-sCH"/>
120
+                                </connections>
116 121
                             </menuItem>
117 122
                             <menuItem title="Show Date" id="0Cy-4I-9bF">
118 123
                                 <modifierMask key="keyEquivalentModifierMask"/>
@@ -253,6 +258,9 @@
253 258
                             <menuItem title="Item" id="IRB-i7-bez">
254 259
                                 <modifierMask key="keyEquivalentModifierMask"/>
255 260
                             </menuItem>
261
+                            <menuItem title="Item" enabled="NO" id="Sk9-Xp-wdP">
262
+                                <modifierMask key="keyEquivalentModifierMask"/>
263
+                            </menuItem>
256 264
                         </items>
257 265
                     </menu>
258 266
                 </menuItem>
@@ -273,9 +281,9 @@
273 281
             <point key="canvasLocation" x="292.5" y="80.5"/>
274 282
         </menu>
275 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 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 287
                 <font key="font" metaFont="system"/>
280 288
                 <calendarDate key="date" timeIntervalSinceReferenceDate="-595929600" calendarFormat="%Y-%m-%d %H:%M:%S %z">
281 289
                     <!--1982-02-12 16:00:00 +0000-->
@@ -283,12 +291,12 @@
283 291
                 </calendarDate>
284 292
                 <color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
285 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 295
             </datePickerCell>
288 296
             <connections>
289 297
                 <action selector="alarmDateSelected:" target="QvC-M9-y7g" id="ghc-DM-FuW"/>
290 298
             </connections>
291
-            <point key="canvasLocation" x="121.5" y="377"/>
299
+            <point key="canvasLocation" x="284" y="354.5"/>
292 300
         </datePicker>
293 301
     </objects>
294 302
 </document>

+ 1
- 1
OtaClock/Info.plist Ver fichero

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

+ 47
- 8
OtaClock/MainWindow.m Ver fichero

@@ -19,6 +19,7 @@
19 19
 #define CONFIG_MILITARY_TIME @"military_time"
20 20
 #define CONFIG_SHOW_DATE @"show_date"
21 21
 #define CONFIG_ALARM_TIME @"alarm_time"
22
+#define CONFIG_ALARM_MODE @"alarm_mode"
22 23
 
23 24
 #define MOUSE_CENTER_X 67
24 25
 #define MOUSE_CENTER_Y 47
@@ -52,6 +53,8 @@
52 53
 @property (weak) IBOutlet NSMenuItem *keepOnTopItem;
53 54
 @property (weak) IBOutlet NSMenuItem *setAlarmItem;
54 55
 @property (weak) IBOutlet NSMenuItem *showDateItem;
56
+@property (weak) IBOutlet NSMenuItem *alarmModeItem;
57
+@property (weak) IBOutlet NSMenuItem *alarmTextItem;
55 58
 
56 59
 @property (weak) IBOutlet NSMenuItem *changeSize1;
57 60
 @property (weak) IBOutlet NSMenuItem *changeSize2;
@@ -154,6 +157,8 @@
154 157
         self.alarmDatePicker.dateValue = [defaults objectForKey:CONFIG_ALARM_TIME];
155 158
     }
156 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 163
     // load show date state
159 164
     if ([defaults objectForKey:CONFIG_SHOW_DATE] == nil) {
@@ -167,11 +172,37 @@
167 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 182
     [[self.mainView render] drawDate:showDate];
171 183
     
172 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 206
 - (void)drawAnimation:(NSNumber *)anim {
176 207
     if ([anim integerValue] > (3 * ANIMATION_SHADOW_HACK)) {
177 208
         [[self.mainView render] drawAnimation:0]; // reset
@@ -194,7 +225,7 @@
194 225
     
195 226
     // Check if a second went by
196 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 229
     static NSInteger lastSec = -1;
199 230
     if (lastSec == [components second]) {
200 231
         return;
@@ -204,11 +235,13 @@
204 235
     [[self.mainView render] drawWithDate:now];
205 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 247
     self.mainView.needsDisplay = YES;
@@ -235,8 +268,14 @@
235 268
 }
236 269
 
237 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 280
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
242 281
     [defaults setObject:self.alarmDatePicker.dateValue forKey:CONFIG_ALARM_TIME];

Loading…
Cancelar
Guardar