-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrowlITTSWPrefs.m
343 lines (299 loc) · 12.1 KB
/
GrowlITTSWPrefs.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#import "GrowlITTSWPrefs.h"
#import "GrowlPositioningDefines.h"
#import "GrowlDefinesInternal.h"
#define GrowlITTSWPrefsDomain @"com.ithinksw.growl-ittsw"
@interface GrowlPositionController
+ (enum GrowlPosition)selectedOriginPosition;
@end
@implementation GrowlITTSWPrefs
+ (Class)appearanceEffect {
SYNCHRONIZE_GROWL_PREFS();
NSString *className = nil;
READ_GROWL_PREF_VALUE(@"appearanceEffect", GrowlITTSWPrefsDomain, NSString *, &className);
if (className) {
Class effectClass = NSClassFromString(className);
if (effectClass && [effectClass isSubclassOfClass:[ITWindowEffect class]]) {
return effectClass;
}
}
return NSClassFromString(@"ITCutWindowEffect");
}
+ (float)appearanceSpeed {
SYNCHRONIZE_GROWL_PREFS();
float appearanceSpeed = 0.8f;
READ_GROWL_PREF_FLOAT(@"appearanceSpeed", GrowlITTSWPrefsDomain, &appearanceSpeed);
return appearanceSpeed;
}
+ (Class)vanishEffect {
SYNCHRONIZE_GROWL_PREFS();
NSString *className = nil;
READ_GROWL_PREF_VALUE(@"vanishEffect", GrowlITTSWPrefsDomain, NSString *, &className);
if (className) {
Class effectClass = NSClassFromString(className);
if (effectClass && [effectClass isSubclassOfClass:[ITWindowEffect class]]) {
return effectClass;
}
}
return NSClassFromString(@"ITCutWindowEffect");
}
+ (float)vanishSpeed {
SYNCHRONIZE_GROWL_PREFS();
float vanishSpeed = 0.8f;
READ_GROWL_PREF_FLOAT(@"vanishSpeed", GrowlITTSWPrefsDomain, &vanishSpeed);
return vanishSpeed;
}
+ (float)vanishDelay {
SYNCHRONIZE_GROWL_PREFS();
float vanishDelay = 4.0f;
READ_GROWL_PREF_FLOAT(@"vanishDelay", GrowlITTSWPrefsDomain, &vanishDelay);
return vanishDelay;
}
+ (ITTSWBackgroundMode)backgroundStyle {
SYNCHRONIZE_GROWL_PREFS();
int backgroundStyle = ITTSWBackgroundReadable;
READ_GROWL_PREF_INT(@"backgroundStyle", GrowlITTSWPrefsDomain, &backgroundStyle);
return backgroundStyle;
}
+ (NSColor *)backgroundColor {
SYNCHRONIZE_GROWL_PREFS();
NSData *backgroundColorData = nil;
READ_GROWL_PREF_VALUE(@"backgroundColor", GrowlITTSWPrefsDomain, NSData *, &backgroundColorData);
if (backgroundColorData && [backgroundColorData isKindOfClass:[NSData class]]) {
NSColor *backgroundColor = [NSUnarchiver unarchiveObjectWithData:backgroundColorData];
if (backgroundColor && [backgroundColor isKindOfClass:[NSColor class]]) {
return backgroundColor;
}
}
return [NSColor blueColor];
}
+ (ITTransientStatusWindowSizing)windowSize {
SYNCHRONIZE_GROWL_PREFS();
ITTransientStatusWindowSizing windowSize = ITTransientStatusWindowMini;
READ_GROWL_PREF_INT(@"windowSize", GrowlITTSWPrefsDomain, &windowSize);
return windowSize;
}
+ (int)screenIndex {
SYNCHRONIZE_GROWL_PREFS();
int screenIndex = 0;
READ_GROWL_PREF_INT(@"screenIndex", GrowlITTSWPrefsDomain, &screenIndex);
return screenIndex;
}
+ (NSScreen *)screen {
NSArray *screens = [NSScreen screens];
int screenIndex = [GrowlITTSWPrefs screenIndex];
if ([screens count] >= (screenIndex+1)) {
return [screens objectAtIndex:screenIndex];
}
return [screens objectAtIndex:0];
}
+ (ITHorizontalWindowPosition)horizontalPosition {
switch ([GrowlPositionController selectedOriginPosition]) {
case GrowlBottomLeftPosition:
case GrowlTopLeftPosition:
return ITWindowPositionLeft;
break;
default:
case GrowlBottomRightPosition:
case GrowlTopRightPosition:
return ITWindowPositionRight;
break;
}
}
+ (ITVerticalWindowPosition)verticalPosition {
switch ([GrowlPositionController selectedOriginPosition]) {
case GrowlBottomLeftPosition:
case GrowlBottomRightPosition:
return ITWindowPositionBottom;
break;
default:
case GrowlTopLeftPosition:
case GrowlTopRightPosition:
return ITWindowPositionTop;
break;
}
}
+ (float)imageSize {
SYNCHRONIZE_GROWL_PREFS();
float imageSize = 110.0f;
READ_GROWL_PREF_FLOAT(@"imageSize", GrowlITTSWPrefsDomain, &imageSize);
return imageSize;
}
+ (BOOL)imageNoUpscale {
SYNCHRONIZE_GROWL_PREFS();
BOOL imageNoUpscale = NO;
READ_GROWL_PREF_BOOL(@"imageNoUpscale", GrowlITTSWPrefsDomain, &imageNoUpscale);
return imageNoUpscale;
}
+ (BOOL)wrapNotifications {
SYNCHRONIZE_GROWL_PREFS();
BOOL wrapNotifications = NO;
READ_GROWL_PREF_BOOL(@"wrapNotifications", GrowlITTSWPrefsDomain, &wrapNotifications);
return wrapNotifications;
}
+ (int)wrapColumns {
SYNCHRONIZE_GROWL_PREFS();
int wrapColumns = 64;
READ_GROWL_PREF_INT(@"wrapColumns", GrowlITTSWPrefsDomain, &wrapColumns);
return wrapColumns;
}
- (NSString *)mainNibName {
return @"GrowlITTSWPrefs";
}
- (void)didSelect {
[appearanceEffectButton selectItemAtIndex:[appearanceEffectButton indexOfItemWithRepresentedObject:[GrowlITTSWPrefs appearanceEffect]]];
[appearanceSpeedSlider setFloatValue:-([GrowlITTSWPrefs appearanceSpeed])];
[vanishEffectButton selectItemAtIndex:[vanishEffectButton indexOfItemWithRepresentedObject:[GrowlITTSWPrefs vanishEffect]]];
[vanishSpeedSlider setFloatValue:-([GrowlITTSWPrefs vanishSpeed])];
[vanishDelaySlider setFloatValue:[GrowlITTSWPrefs vanishDelay]];
ITTSWBackgroundMode backgroundStyle = [GrowlITTSWPrefs backgroundStyle];
[backgroundStyleButton selectItemWithTag:backgroundStyle];
if (backgroundStyle == ITTSWBackgroundColored) {
[backgroundColorWell setEnabled:YES];
} else {
[backgroundColorWell setEnabled:NO];
}
[[NSColorPanel sharedColorPanel] setShowsAlpha:YES];
[backgroundColorWell setColor:[GrowlITTSWPrefs backgroundColor]];
[windowSizeButton selectItemWithTag:[GrowlITTSWPrefs windowSize]];
[screenButton removeAllItems];
NSArray *screens = [NSScreen screens];
int screenCount = 0;
for (NSScreen *screen in screens) {
NSSize screenSize = [screen frame].size;
NSMenuItem *screenItem = [[NSMenuItem alloc] initWithTitle:[NSString stringWithFormat:@"Screen %i (%1.0fx%1.0f)", screenCount+1, screenSize.width, screenSize.height] action:NULL keyEquivalent:@""];
[screenItem setRepresentedObject:screen];
[[screenButton menu] addItem:screenItem];
screenCount++;
}
if (screenCount > 1) {
[screenButton setEnabled:YES];
} else {
[screenButton setEnabled:NO];
}
[screenButton selectItemAtIndex:[screenButton indexOfItemWithRepresentedObject:[GrowlITTSWPrefs screen]]];
[imageSizeSlider setFloatValue:[GrowlITTSWPrefs imageSize]];
[imageNoUpscaleButton setState:([GrowlITTSWPrefs imageNoUpscale] ? NSOnState : NSOffState)];
BOOL wrapNotifications = [GrowlITTSWPrefs wrapNotifications];
[wrapNotificationsButton setState:(wrapNotifications ? NSOnState : NSOffState)];
[wrapColumnsField setIntValue:[GrowlITTSWPrefs wrapColumns]];
[wrapColumnsField setEnabled:wrapNotifications];
}
- (void)awakeFromNib {
NSArray *effectClasses = [ITWindowEffect effectClasses];
for (Class effectClass in effectClasses) {
NSMenuItem *appearanceEffectItem = [[NSMenuItem alloc] initWithTitle:[effectClass effectName] action:NULL keyEquivalent:@""];
NSMenuItem *vanishEffectItem = [[NSMenuItem alloc] initWithTitle:[effectClass effectName] action:NULL keyEquivalent:@""];
[appearanceEffectItem setRepresentedObject:effectClass];
[vanishEffectItem setRepresentedObject:effectClass];
[[appearanceEffectButton menu] addItem:[appearanceEffectItem autorelease]];
[[vanishEffectButton menu] addItem:[vanishEffectItem autorelease]];
}
NSArray *backgroundStyles = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"Mac OS X", @"name", [NSNumber numberWithInt:ITTSWBackgroundApple], @"index", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Very Readable", @"name", [NSNumber numberWithInt:ITTSWBackgroundReadable], @"index", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Custom Color...", @"name", [NSNumber numberWithInt:ITTSWBackgroundColored], @"index", nil],
nil];
for (NSDictionary *backgroundStyleDict in backgroundStyles) {
NSString *backgroundStyleName = [backgroundStyleDict objectForKey:@"name"];
ITTSWBackgroundMode backgroundStyle = [[backgroundStyleDict objectForKey:@"index"] intValue];
NSMenuItem *backgroundStyleItem = [[NSMenuItem alloc] initWithTitle:backgroundStyleName action:NULL keyEquivalent:@""];
[backgroundStyleItem setTag:backgroundStyle];
[[backgroundStyleButton menu] addItem:[backgroundStyleItem autorelease]];
}
NSArray *windowSizes = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"Regular", @"name", [NSNumber numberWithInt:ITTransientStatusWindowRegular], @"index", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Small", @"name", [NSNumber numberWithInt:ITTransientStatusWindowSmall], @"index", nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"Mini", @"name", [NSNumber numberWithInt:ITTransientStatusWindowMini], @"index", nil],
nil];
for (NSDictionary *windowSizeDict in windowSizes) {
NSString *windowSizeName = [windowSizeDict objectForKey:@"name"];
ITTransientStatusWindowSizing windowSize = [[windowSizeDict objectForKey:@"index"] intValue];
NSMenuItem *windowSizeItem = [[NSMenuItem alloc] initWithTitle:windowSizeName action:NULL keyEquivalent:@""];
[windowSizeItem setTag:windowSize];
[[windowSizeButton menu] addItem:[windowSizeItem autorelease]];
}
[self didSelect];
}
- (IBAction)setAppearanceEffect:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
WRITE_GROWL_PREF_VALUE(@"appearanceEffect", NSStringFromClass([[appearanceEffectButton selectedItem] representedObject]), GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setAppearanceSpeed:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
float appearanceSpeed = -([appearanceSpeedSlider floatValue]);
WRITE_GROWL_PREF_FLOAT(@"appearanceSpeed", appearanceSpeed, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setVanishEffect:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
WRITE_GROWL_PREF_VALUE(@"vanishEffect", NSStringFromClass([[vanishEffectButton selectedItem] representedObject]), GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setVanishSpeed:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
float vanishSpeed = -([vanishSpeedSlider floatValue]);
WRITE_GROWL_PREF_FLOAT(@"vanishSpeed", vanishSpeed, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setVanishDelay:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
float vanishDelay = [vanishDelaySlider floatValue];
WRITE_GROWL_PREF_FLOAT(@"vanishDelay", vanishDelay, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setBackgroundStyle:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
int style = [[backgroundStyleButton selectedItem] tag];
if (style == 2) { // colored
[backgroundColorWell setEnabled:YES];
} else {
[backgroundColorWell setEnabled:NO];
}
WRITE_GROWL_PREF_INT(@"backgroundStyle", style, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setBackgroundColor:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
WRITE_GROWL_PREF_VALUE(@"backgroundColor", [NSArchiver archivedDataWithRootObject:[backgroundColorWell color]], GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setWindowSize:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
int size = [[windowSizeButton selectedItem] tag];
WRITE_GROWL_PREF_INT(@"windowSize", size, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setScreen:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
int screenIndex = [screenButton indexOfSelectedItem];
WRITE_GROWL_PREF_INT(@"screenIndex", screenIndex, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setImageSize:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
float imageSize = [imageSizeSlider floatValue];
WRITE_GROWL_PREF_FLOAT(@"imageSize", imageSize, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setImageNoUpscale:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
BOOL imageNoUpscale = ([imageNoUpscaleButton state] == NSOnState) ? YES : NO;
WRITE_GROWL_PREF_BOOL(@"imageNoUpscale", imageNoUpscale, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setWrap:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
BOOL wrapNotifications = ([wrapNotificationsButton state] == NSOnState) ? YES : NO;
[wrapColumnsField setEnabled:wrapNotifications];
WRITE_GROWL_PREF_BOOL(@"wrapNotifications", wrapNotifications, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
- (IBAction)setWrapColumns:(id)sender {
SYNCHRONIZE_GROWL_PREFS();
int wrapColumns = [wrapColumnsField intValue];
[wrapColumnsField setIntValue:wrapColumns];
WRITE_GROWL_PREF_INT(@"wrapColumns", wrapColumns, GrowlITTSWPrefsDomain);
UPDATE_GROWL_PREFS();
}
@end