-
Notifications
You must be signed in to change notification settings - Fork 1
/
prefs.m
118 lines (103 loc) · 5.27 KB
/
prefs.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* Copyright © 2003, Leaky Puppy Software, Net Monkey Inc.
This file is part of Fob.
Fob is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Fob is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Fob; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
// prefs.m
// Fob
//
// Created by Thomas Finley on Fri Jan 10 2003.
// Copyright (c) 2003 Leaky Puppy Software, for Net Monkey Inc. All rights reserved.
// This program is distributed under the terms of the GNU General Public License.
#include "prefs.h"
#include "Alarm.h"
#define SECONDS(H, M, S) (((H)*60+(M))*60+(S))
NSString *FobPresetAlarmsKey = @"Preset Alarms";
NSString *FobActiveAlarmsKey = @"Active Alarms";
NSString *FobPausedAlarmsKey = @"Paused Alarms";
NSString *FobConfirmDeleteKey = @"Confirm Delete";
NSString *FobKeepWindowOpenKey = @"Keep Window Open";
NSString *FobFeedbackLevelKey = @"Feedback Level";
NSString *FobBounceLevelKey = @"Bounce Level";
NSString *FobDisplayedAlarmKey = @"Displayed Alarm";
NSString *FobStatusItemVisibleKey = @"Status Item Visible";
NSString *FobStatusItemTitleVisibleKey = @"Status Item Displays Title";
NSString *FobScaleDockTimeKey = @"Time Scaled to Fit Dock Icon";
NSString *FobDisableCommandQKey = @"Command-Q Disabled";
NSString *FobDockMenuSubmenusKey = @"Dock Menu Alarms in Submenus";
NSString *FobClearDueOnQuitKey = @"Clear Due Alarms on Quit";
const FeedbackLevel kDefaultFeedbackLevel = beep;
const BounceLevel kDefaultBounceLevel = dont;
const BOOL kDefaultConfirmDelete = YES;
const BOOL kDefaultKeepWindowOpen = NO;
const BOOL kDefaultStatusItemVisible = NO;
const BOOL kDefaultStatusItemTitleVisible = YES;
const BOOL kDefaultScaleDockTime = NO;
const BOOL kDefaultDisableCommandQ = NO;
const BOOL kDefaultDockMenuSubmenus = NO;
const BOOL kDefaultClearDueOnQuitKey = NO;
long long alarmTimes[] = {
SECONDS(0,20,0), SECONDS(0,45,0), 0
};
NSString * alarmNames[] = {
@"Broil Halibut", @"Soda in Freezer"
};
NSMutableArray * correspondingDataArray(NSArray * array) {
int i;
NSMutableArray *newArray = [NSMutableArray arrayWithCapacity:[array count]];
for (i=0; i<[array count]; i++)
[newArray addObject:[NSArchiver archivedDataWithRootObject:[array objectAtIndex:i]]];
return newArray;
}
NSMutableArray * correspondingObjectArray(NSArray * array) {
int i;
NSMutableArray *newArray = [NSMutableArray arrayWithCapacity:[array count]];
for (i=0; i<[array count]; i++)
[newArray addObject:[NSUnarchiver unarchiveObjectWithData:[array objectAtIndex:i]]];
return newArray;
}
NSMutableDictionary *factoryDefaults() {
NSMutableDictionary *defaults = [NSMutableDictionary dictionary];
long long *alarmT = alarmTimes;
NSString **alarmN = alarmNames;
NSMutableArray *presetArray = [NSMutableArray array];
while (*alarmT) {
Alarm *alarm = [Alarm alarmWithTitle:*alarmN forSecondDuration:*alarmT];
NSData *alarmAsData = [NSArchiver archivedDataWithRootObject:alarm];
[presetArray addObject:alarmAsData];
alarmT++;
alarmN++;
}
[defaults setObject:presetArray forKey:FobPresetAlarmsKey];
[defaults setObject:[NSArray array] forKey:FobActiveAlarmsKey];
[defaults setObject:[NSNumber numberWithInt:kDefaultFeedbackLevel]
forKey:FobFeedbackLevelKey];
[defaults setObject:[NSNumber numberWithInt:kDefaultBounceLevel]
forKey:FobBounceLevelKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultConfirmDelete]
forKey:FobConfirmDeleteKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultKeepWindowOpen]
forKey:FobKeepWindowOpenKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultStatusItemVisible]
forKey:FobStatusItemVisibleKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultStatusItemTitleVisible]
forKey:FobStatusItemTitleVisibleKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultScaleDockTime]
forKey:FobScaleDockTimeKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultDisableCommandQ]
forKey:FobDisableCommandQKey];
[defaults setObject:[NSArchiver archivedDataWithRootObject:
[Alarm alarmWithTitle:NSLocalizedString(@"DefaultAlarmLabel", nil)
forSecondDuration:SECONDS(0,5,0)]]
forKey:FobDisplayedAlarmKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultStatusItemVisible]
forKey:FobStatusItemVisibleKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultDockMenuSubmenus]
forKey:FobDockMenuSubmenusKey];
[defaults setObject:[NSNumber numberWithBool:kDefaultClearDueOnQuitKey]
forKey:FobClearDueOnQuitKey];
return defaults;
}
void setFactoryDefaults() {
[[NSUserDefaults standardUserDefaults] registerDefaults:factoryDefaults()];
}