-
Notifications
You must be signed in to change notification settings - Fork 3
/
PreferenceWindowController.m
182 lines (174 loc) · 5.75 KB
/
PreferenceWindowController.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//
// PreferenceWindowController.m
// Jabber
//
// Created by David Chisnall on 19/10/2004.
// Copyright 2004 __MyCompanyName__. All rights reserved.
//
#import <XMPPKit/XMPPPresence.h>
#import "PreferenceWindowController.h"
#import "RosterController.h"
#import "MessageWindowController.h"
#import "TRUserDefaults.h"
@implementation PreferenceWindowController
+ (void) initialize
{
NSUserDefaults * settings = [NSUserDefaults standardUserDefaults];
NSMutableDictionary * colours = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.75f
green:0.41f
blue:0.0f
alpha:1.0f]],
@"Away",
[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.69f
green:0.0f
blue:0.0f
alpha:1.0f]],
@"Do Not Disturb",
[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.75f
green:0.41f
blue:0.0f
alpha:1.0f]],
@"Extended Away",
[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.0f
green:0.35f
blue:0.0f
alpha:1.0f]],
@"Free For Chat",
[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.57f
green:0.57f
blue:0.57f
alpha:1.0f]],
@"Offline",
[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.0f
green:0.35f
blue:0.0f
alpha:1.0f]],
@"Online",
[NSArchiver archivedDataWithRootObject:[NSColor colorWithCalibratedRed:0.57f
green:0.57f
blue:0.57f
alpha:1.0f]],
@"Unknown",
nil];
//TODO: Set this from a .plist file so it can be locallised without recompiling.
[settings registerDefaults:[NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSDictionary dictionaryWithObjectsAndKeys:@"Drinking Coffee", @"Coffee", nil],
@"CustomMessages",
[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithUnsignedChar:40], @"Coffee", nil],
@"CustomPresence",
[NSDictionary dictionary],
@"ExpandedGroups",
[NSNumber numberWithUnsignedChar:60],
@"HiddenPresences",
@"Hero",
@"MessageSound",
@"Pop",
@"OfflineSound",
@"Submarine",
@"OnlineSound",
colours,
@"PresenceColours",
nil]];
}
- (void)showWindow:(id)_sender
{
NSUserDefaults * pref = [NSUserDefaults standardUserDefaults];
[chatColour setColor:[pref colourForPresence:PRESENCE_CHAT]];
[onlineColour setColor:[pref colourForPresence:PRESENCE_ONLINE]];
[awayColour setColor:[pref colourForPresence:PRESENCE_AWAY]];
[xaColour setColor:[pref colourForPresence:PRESENCE_XA]];
[dndColour setColor:[pref colourForPresence:PRESENCE_DND]];
[offlineColour setColor:[pref colourForPresence:PRESENCE_OFFLINE]];
[unknownColour setColor:[pref colourForPresence:PRESENCE_UNKNOWN]];
NSString * soundName = [pref objectForKey:@"OnlineSound"];
/* little workaround with the help of else block to avoid the soundName ever empty string
* until the problem will be discovered and fixed correctly
*/
if(soundName != nil && ![soundName isEqual:@""])
{
[onlineSoundBox setStringValue:soundName];
}
else
{
[onlineSoundBox setStringValue:@"Submarine"];
}
soundName = [pref stringForKey:@"OfflineSound"];
if(soundName != nil && ![soundName isEqual:@""])
{
[offlineSoundBox setStringValue:soundName];
}
else
{
[offlineSoundBox setStringValue:@"Pop"];
}
soundName = [pref stringForKey:@"MessageSound"];
if(soundName != nil && ![soundName isEqual:@""])
{
[messageSoundBox setStringValue:soundName];
}
else
{
[messageSoundBox setStringValue:@"Hero"];
}
[super showWindow:_sender];
}
- (void) loadSoundForComboBox:(NSComboBox*)_box
{
NSOpenPanel * openPanel = [NSOpenPanel openPanel];
[openPanel setAllowsMultipleSelection:NO];
[openPanel setDirectoryURL:[[NSURL alloc] initWithString:@"/System/Library/Sounds"]];
[openPanel setAllowedFileTypes:[NSSound soundUnfilteredTypes]];
if ([openPanel runModal] == NSOKButton)
{
[_box setStringValue:[[openPanel URLs] objectAtIndex:0]];
}
}
- (IBAction) selectOnlineSound:(id)_sender
{
[self loadSoundForComboBox:onlineSoundBox];
}
- (IBAction) selectOfflineSound:(id)_sender
{
[self loadSoundForComboBox:offlineSoundBox];
}
- (IBAction) selectMessageSound:(id)_sender
{
[self loadSoundForComboBox:messageSoundBox];
}
- (void)windowWillClose:(NSNotification *)aNotification
{
NSUserDefaults * pref = [NSUserDefaults standardUserDefaults];
[pref setColour:[chatColour color] forPresence:PRESENCE_CHAT];
[pref setColour:[onlineColour color] forPresence:PRESENCE_ONLINE];
[pref setColour:[awayColour color] forPresence:PRESENCE_AWAY];
[pref setColour:[xaColour color] forPresence:PRESENCE_XA];
[pref setColour:[dndColour color] forPresence:PRESENCE_DND];
[pref setColour:[offlineColour color] forPresence:PRESENCE_OFFLINE];
[pref setColour:[unknownColour color] forPresence:PRESENCE_UNKNOWN];
[pref setObject:[onlineSoundBox stringValue] forKey:@"OnlineSound"];
[pref setObject:[offlineSoundBox stringValue] forKey:@"OfflineSound"];
[pref setObject:[messageSoundBox stringValue] forKey:@"MessageSound"];
}
- (void) playSound:(NSString*)_soundName
{
NSSound * sound = [NSSound soundNamed:_soundName];
if(sound == nil)
{
sound = [[NSSound alloc] initWithContentsOfFile:_soundName byReference:YES];
}
[sound play];
}
- (IBAction) playOnlineSound:(id)_sender
{
[self playSound:[onlineSoundBox stringValue]];
}
- (IBAction) playOfflineSound:(id)_sender
{
[self playSound:[offlineSoundBox stringValue]];
}
- (IBAction) playMessageSound:(id)_sender
{
[self playSound:[messageSoundBox stringValue]];
}
@end