Adding background style in the General status window settings.
[MenuTunes.git] / StatusWindowController.m
1 #import "StatusWindowController.h"
2 #import "StatusWindow.h"
3 #import "PreferencesController.h"
4 #import "MainController.h"
5
6 #import <ITKit/ITTSWBackgroundView.h>
7 #import <ITKit/ITWindowEffect.h>
8 #import <ITKit/ITCutWindowEffect.h>
9 #import <ITKit/ITDissolveWindowEffect.h>
10 #import <ITKit/ITSlideHorizontallyWindowEffect.h>
11 #import <ITKit/ITSlideVerticallyWindowEffect.h>
12 #import <ITKit/ITPivotWindowEffect.h>
13
14
15 static StatusWindowController *sharedController;
16
17
18 @implementation StatusWindowController
19
20
21 + (StatusWindowController *)sharedController
22 {
23     if ( ! sharedController ) {
24         sharedController = [[StatusWindowController alloc] init];
25     }
26     
27     return sharedController;
28 }
29
30
31 - (id)init
32 {
33     if ( ( self = [super init] ) ) {
34     
35         float exitDelay;
36         int entryTag;
37         int exitTag;
38         float entrySpeed;
39         float exitSpeed;
40         
41         ITWindowEffect *entryEffect;
42         ITWindowEffect *exitEffect;
43
44         _window = [[StatusWindow sharedWindow] retain];
45         df = [[NSUserDefaults standardUserDefaults] retain];
46
47         exitDelay  = [df floatForKey:@"statusWindowVanishDelay"];
48         entryTag   = [df integerForKey:@"statusWindowAppearanceEffect"];
49         exitTag    = [df integerForKey:@"statusWindowVanishEffect"];
50         entrySpeed = [df floatForKey:@"statusWindowAppearanceSpeed"];
51         exitSpeed  = [df floatForKey:@"statusWindowVanishSpeed"];
52
53         [_window setExitMode:ITTransientStatusWindowExitAfterDelay];
54         [_window setExitDelay:(exitDelay ? exitDelay : 4.0)];
55
56         [_window setHorizontalPosition:[df integerForKey:@"statusWindowHorizontalPosition"]];
57         [_window setVerticalPosition:[df integerForKey:@"statusWindowVerticalPosition"]];
58
59         if ( entryTag == 2101 ) {
60             entryEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
61         } else if ( entryTag == 2102 ) {
62             entryEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
63         } else if ( entryTag == 2103 ) {
64             entryEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
65         } else if ( entryTag == 2104 ) {
66             entryEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
67         } else {
68             entryEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
69         }
70
71         [_window setEntryEffect:entryEffect];
72
73         if ( exitTag == 2100 ) {
74             exitEffect = [[[ITCutWindowEffect alloc] initWithWindow:_window] autorelease];
75         } else if ( exitTag == 2102 ) {
76             exitEffect = [[[ITSlideVerticallyWindowEffect alloc] initWithWindow:_window] autorelease];
77         } else if ( exitTag == 2103 ) {
78             exitEffect = [[[ITSlideHorizontallyWindowEffect alloc] initWithWindow:_window] autorelease];
79         } else if ( exitTag == 2104 ) {
80             exitEffect = [[[ITPivotWindowEffect alloc] initWithWindow:_window] autorelease];
81         } else {
82             exitEffect = [[[ITDissolveWindowEffect alloc] initWithWindow:_window] autorelease];
83         }
84
85         [_window setExitEffect:exitEffect];
86
87         [[_window entryEffect] setEffectTime:(entrySpeed ? entrySpeed : 0.8)];
88         [[_window exitEffect]  setEffectTime:(exitSpeed  ? exitSpeed  : 0.8)];
89         
90         [(ITTSWBackgroundView *)[_window contentView]setBackgroundMode:
91             (ITTSWBackgroundMode)[df integerForKey:@"statusWindowBackgroundMode"]];
92             
93         [(ITTSWBackgroundView *)[_window contentView]setBackgroundColor:
94             (NSColor *)[NSUnarchiver unarchiveObjectWithData:[df dataForKey:@"statusWindowBackgroundColor"]]];
95     }
96     
97     return self;
98 }
99
100 - (void)dealloc
101 {
102     [_window release];
103     [super dealloc];
104 }
105
106 - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source
107                                title:            (NSString *)title
108                                album:            (NSString *)album
109                               artist:            (NSString *)artist
110                                 time:            (NSString *)time  // FLOW: Should probably be NSDate or something.
111                                track:            (NSString *)track
112                               rating:                   (int)rating
113 {
114     NSImage  *image = nil;
115     NSString *text  = title;
116     
117     if ( source == ITMTRemoteLibrarySource ) {
118         image = [NSImage imageNamed:@"Library"];
119     } else if ( source == ITMTRemoteCDSource ) {
120         image = [NSImage imageNamed:@"CD"];
121     } else if ( source == ITMTRemoteRadioSource ) {
122         image = [NSImage imageNamed:@"Radio"];
123     } else if ( source == ITMTRemoteiPodSource ) {
124         image = [NSImage imageNamed:@"iPod"];
125     } else if ( source == ITMTRemoteGenericDeviceSource ) {
126         image = [NSImage imageNamed:@"MP3Player"];
127     } else if ( source == ITMTRemoteSharedLibrarySource ) {
128         image = [NSImage imageNamed:@"Library"];
129     }
130
131     [_window setImage:image];
132
133     if ( album ) {
134         text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]];
135     }
136     if ( artist ) {
137         text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]];
138     }
139     if ( time ) {
140         text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]];
141     }
142     if ( track ) {
143         text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]];
144     }
145     if ( rating > -1 ) {
146
147         NSString *ratingString = [NSString string];
148         NSString *emptyChar    = [NSString stringWithUTF8String:"☆"];
149         NSString *fullChar     = [NSString stringWithUTF8String:"★"];
150         int       i;
151         
152         for ( i = 1; i < 6; i++ ) {
153                 
154             if ( rating >= i ) {
155                 ratingString = [ratingString stringByAppendingString:fullChar];
156             } else {
157                 ratingString = [ratingString stringByAppendingString:emptyChar];
158             }
159         }
160     
161         text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]];
162     }
163     
164     [_window buildTextWindowWithString:text];
165     [_window appear:self];
166 }
167
168 - (void)showUpcomingSongsWindowWithTitles:(NSArray *)titleStrings
169 {
170 //  NSString *bull = [NSString stringWithUTF8String:"‣ "];
171     NSString *bull = [NSString stringWithUTF8String:"♪ "];
172     NSString *end  = [@"\n" stringByAppendingString:bull];
173     [_window setImage:[NSImage imageNamed:@"Upcoming"]];
174     [_window buildTextWindowWithString:[bull stringByAppendingString:[titleStrings componentsJoinedByString:end]]];
175     [_window appear:self];
176 }
177
178 - (void)showVolumeWindowWithLevel:(float)level
179 {
180     [_window setImage:[NSImage imageNamed:@"Volume"]];
181     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"▊"]
182                                       size:18
183                                      count:10
184                                     active:( ceil(level * 100) / 10 )];
185     [_window appear:self];
186 }
187
188 - (void)showRatingWindowWithRating:(float)rating
189 {
190     [_window setImage:[NSImage imageNamed:@"Rating"]];
191     [_window buildMeterWindowWithCharacter:[NSString stringWithUTF8String:"★"]
192                                       size:48
193                                      count:5
194                                     active:( ceil(rating * 100) / 20 )];
195     [_window appear:self];
196 }
197
198 - (void)showShuffleWindow:(BOOL)shuffle
199 {
200     [_window setImage:[NSImage imageNamed:@"Shuffle"]];
201     [_window buildTextWindowWithString:( shuffle ? @"Shuffle On" : @"Shuffle Off")];
202     [_window appear:self];
203 }
204
205 - (void)showRepeatWindowWithMode:(StatusWindowRepeatMode)mode
206 {
207     NSString *string = nil;
208     
209     if ( mode == StatusWindowRepeatNone ) {
210         string = @"Repeat Off";
211     } else if ( mode == StatusWindowRepeatGroup ) {
212         string = @"Repeat Playlist";
213     } else if ( mode == StatusWindowRepeatTrack ) {
214         string = @"Repeat One Track";
215     }
216     
217     [_window setImage:[NSImage imageNamed:@"Repeat"]];
218     [_window buildTextWindowWithString:string];
219     [_window appear:self];
220 }
221
222 - (void)showSetupQueryWindow
223 {
224     NSString *message = @"Would you like MenuTunes to launch\nautomatically at startup?";
225
226     [_window setImage:[NSImage imageNamed:@"Setup"]];
227     [_window buildDialogWindowWithMessage:message
228                             defaultButton:@"Launch at Startup"
229                           alternateButton:@"Launch Manually"
230                                    target:[PreferencesController sharedPrefs]
231                             defaultAction:@selector(autoLaunchOK)
232                           alternateAction:@selector(autoLaunchCancel)];
233
234     [_window appear:self];
235     [_window setLocked:YES];
236 }
237
238
239 - (void)showRegistrationQueryWindow
240 {
241     NSString *message = @"Your 7-day unlimited trial period has elapsed.\nYou must register to continue using MenuTunes.";
242
243     [_window setImage:[NSImage imageNamed:@"Register"]];
244     [_window buildDialogWindowWithMessage:message
245                             defaultButton:@"Register Now"
246                           alternateButton:@"Quit MenuTunes"
247                                    target:[MainController sharedController]
248                             defaultAction:@selector(registerNowOK)
249                           alternateAction:@selector(registerNowCancel)];
250
251     [_window appear:self];
252     [_window setLocked:YES];
253 }
254
255 - (void)showReconnectQueryWindow
256 {
257     NSString *message = @"The selected shared player is available again.\nWould you like to reconnect to it?.";
258
259     [_window setImage:[NSImage imageNamed:@"Register"]];
260     [_window buildDialogWindowWithMessage:message
261                             defaultButton:@"Reconnect"
262                           alternateButton:@"Ignore"
263                                    target:[MainController sharedController]
264                             defaultAction:@selector(reconnect)
265                           alternateAction:@selector(cancelReconnect)];
266
267     [_window appear:self];
268     [_window setLocked:YES];
269 }
270
271 @end