-
Notifications
You must be signed in to change notification settings - Fork 3
/
TRUserDefaults.m
98 lines (81 loc) · 3.01 KB
/
TRUserDefaults.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
//
// NSUserDefaultsWithColour.m
// Jabber
//
// Created by David Chisnall on 02/11/2004.
// Copyright 2004 __MyCompanyName__. All rights reserved.
//
#import <XMPPKit/XMPPPresence.h>
#import "TRUserDefaults.h"
@implementation NSUserDefaults(TRJabberAdditions)
- (void) setColour:(NSColor *)_colour forPresence:(unsigned char)_presence
{
NSMutableDictionary * colours = [NSMutableDictionary dictionaryWithDictionary:[self dictionaryForKey:@"PresenceColours"]];
[colours setObject:[NSArchiver archivedDataWithRootObject:_colour]
forKey:[XMPPPresence displayStringForPresence:_presence]];
[self setObject:colours forKey:@"PresenceColours"];
}
- (NSColor*) colourForPresence:(unsigned char)_presence;
{
return [NSUnarchiver unarchiveObjectWithData:[[self dictionaryForKey:@"PresenceColours"] objectForKey:[XMPPPresence displayStringForPresence:_presence]]];
}
- (void) setColour:(NSColor *)_colour forKey:(NSString *)_key
{
NSData * data=[NSArchiver archivedDataWithRootObject:_colour];
[self setObject:data forKey:_key];
}
- (NSColor *) colourForKey:(NSString *)_key
{
NSColor * colour=nil;
NSData * data=[self dataForKey:_key];
if(data != nil)
{
colour=(NSColor *)[NSUnarchiver unarchiveObjectWithData:data];
}
return colour;
}
- (unsigned char) presenceForKey:(NSString*)_key
{
return (unsigned char)[self integerForKey:_key];
}
- (void) setPresence:(unsigned char)_presence forKey:(NSString *)_key
{
[self setInteger:(int) _presence forKey:_key];
}
- (NSSound*) soundForKey:(NSString*)_key
{
NSSound * sound = [NSSound soundNamed:[self stringForKey:_key]];
if(sound == nil)
{
sound = [[NSSound alloc] initWithContentsOfFile:[self stringForKey:_key] byReference:YES];
}
return sound;
}
- (void) setExpanded:(NSString*)_group to:(BOOL)_expanded
{
NSMutableDictionary * groups = [NSMutableDictionary dictionaryWithDictionary:[self dictionaryForKey:@"ExpandedGroups"]];
[groups setObject:[NSNumber numberWithBool:_expanded] forKey:_group];
[self setObject:groups forKey:@"ExpandedGroups"];
}
- (BOOL) expandedGroup:(NSString*)_group
{
return [[[self dictionaryForKey:@"ExpandedGroups"] objectForKey:_group] boolValue];
}
- (NSString*) customMessageNamed:(NSString*)_name
{
return [[self dictionaryForKey:@"CustomMessages"] objectForKey:_name];
}
- (unsigned char) customPresenceNamed:(NSString*)_name
{
return [[[self dictionaryForKey:@"CustomPresences"] objectForKey:_name] unsignedCharValue];
}
- (void) setCustomPresence:(unsigned char)_presence withMessage:(NSString*)_message named:(NSString*)_name
{
NSMutableDictionary * presences = [NSMutableDictionary dictionaryWithDictionary:[self dictionaryForKey:@"CustomPresences"]];
NSMutableDictionary * messages = [NSMutableDictionary dictionaryWithDictionary:[self dictionaryForKey:@"CustomMessages"]];
[presences setObject:[NSNumber numberWithUnsignedChar:_presence] forKey:_name];
[messages setObject:_message forKey:_name];
[self setObject:presences forKey:@"CustomPresences"];
[self setObject:messages forKey:@"CustomMessages"];
}
@end