Fixed window height so it's prettier.
[MenuTunes.git] / StatusWindowController.m
1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3
4 @implementation StatusWindowController
5
6 - (id)init
7 {
8     if ( (self = [super init]) ) {
9         [NSBundle loadNibNamed:@"StatusWindow" owner:self];
10         [statusWindow center];
11     }
12     return self;
13 }
14
15 - (void)setUpcomingSongs:(NSString *)string
16 {
17 int size = 0, i;
18     NSArray *lines = [string componentsSeparatedByString:@"\n"];
19     
20     for (i = 0; i < [lines count]; i++) {
21         int temp = [[lines objectAtIndex:i] sizeWithAttributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Lucida Grande" size:12] forKey:NSFontAttributeName]].width;
22         
23         if (temp > size) {
24             size = temp;
25         }
26     }
27     
28     if (size < 255) {
29         size = 255;
30     }
31     
32     [statusField setStringValue:string];
33     [statusWindow setFrame:NSMakeRect(0, 0, size + 45, 40 + ([lines count] * 15)) display:NO];
34     [statusWindow center];
35     [statusWindow makeKeyAndOrderFront:nil];
36 }
37
38 - (void)setTrackInfo:(NSString *)string
39 {
40     int size = 0, i;
41     NSArray *lines = [string componentsSeparatedByString:@"\n"];
42     
43     for (i = 0; i < [lines count]; i++) {
44         int temp = [[lines objectAtIndex:i] sizeWithAttributes:[NSDictionary dictionaryWithObject:[NSFont fontWithName:@"Lucida Grande" size:12] forKey:NSFontAttributeName]].width;
45         
46         if (temp > size) {
47             size = temp;
48         }
49     }
50     
51     if (size < 285) {
52         size = 285;
53     }
54     
55     [statusField setStringValue:string];
56     [statusWindow setFrame:NSMakeRect(0, 0, size + 45, 40 + ([lines count] * 16)) display:NO];
57     [statusWindow center];
58     [statusWindow makeKeyAndOrderFront:nil];
59 }
60
61 - (void)fadeWindowOut
62 {
63     [NSThread detachNewThreadSelector:@selector(fadeOutAux) toTarget:self withObject:nil];
64 }
65
66 - (void)fadeOutAux
67 {
68     NSAutoreleasePool *p00l = [[NSAutoreleasePool alloc] init];
69     float i;
70     for (i = 1.0; i > 0; i -= .003) {
71         [statusWindow setAlphaValue:i];
72     }
73     [statusWindow close];
74     [p00l release];
75 }
76
77 @end