+
+/*************************************************************************/
+#pragma mark -
+#pragma mark PRIVATE METHOD IMPLEMENTATIONS
+/*************************************************************************/
+
+- (void)setupWindow
+{
+ if ( ! [NSBundle loadNibNamed:@"Preferences" owner:self] ) {
+ NSLog( @"Failed to load Preferences.nib" );
+ NSBeep();
+ return;
+ }
+}
+
+- (void)setupCustomizationTables
+{
+ NSImageCell *imgCell = [[[NSImageCell alloc] initImageCell:nil] autorelease];
+
+ // Set the table view cells up
+ [imgCell setImageScaling:NSScaleNone];
+ [[menuTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
+ [[allTableView tableColumnWithIdentifier:@"submenu"] setDataCell:imgCell];
+
+ // Register for drag and drop
+ [menuTableView registerForDraggedTypes:[NSArray arrayWithObjects:
+ @"MenuTableViewPboardType",
+ @"AllTableViewPboardType",
+ nil]];
+ [allTableView registerForDraggedTypes:[NSArray arrayWithObjects:
+ @"MenuTableViewPboardType",
+ @"AllTableViewPboardType",
+ nil]];
+}
+
+- (void)setupMenuItems
+{
+ NSEnumerator *itemEnum;
+ id anItem;
+ // Set the list of items you can have.
+ availableItems = [[NSMutableArray alloc] initWithObjects:
+ @"Current Track Info",
+ @"Upcoming Songs",
+ @"Playlists",
+ @"EQ Presets",
+ @"Song Rating",
+ @"Play/Pause",
+ @"Next Track",
+ @"Previous Track",
+ @"Fast Forward",
+ @"Rewind",
+ @"Show Player",
+ @"<separator>",
+ nil];
+
+ // Get our preferred menu
+ myItems = [[df arrayForKey:@"menu"] mutableCopy];
+
+ // Delete items in the availableItems array that are already part of the menu
+ itemEnum = [myItems objectEnumerator];
+ while ( (anItem = [itemEnum nextObject]) ) {
+ if ( ! [anItem isEqualToString:@"<separator>"] ) {
+ [availableItems removeObject:anItem];
+ }
+ }
+
+ // Items that show should a submenu image
+ submenuItems = [[NSArray alloc] initWithObjects:
+ @"Upcoming Songs",
+ @"Playlists",
+ @"EQ Presets",
+ @"Song Rating",
+ nil];
+}
+
+- (void)setupUI
+{
+ NSMutableDictionary *loginwindow;
+ NSMutableArray *loginarray;
+ NSEnumerator *loginEnum;
+ id anItem;
+
+ // Fill in the number of songs in advance to show field
+ [songsInAdvance setIntValue:[df integerForKey:@"SongsInAdvance"]];
+
+ // Fill in hot key buttons
+ if ([df objectForKey:@"PlayPause"]){
+ anItem = [df keyComboForKey:@"PlayPause"];
+ [hotKeysDictionary setObject:anItem forKey:@"PlayPause"];
+ [playPauseButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PlayPause"];
+ }
+
+ if ([df objectForKey:@"NextTrack"]) {
+ anItem = [df keyComboForKey:@"NextTrack"];
+ [hotKeysDictionary setObject:anItem forKey:@"NextTrack"];
+ [nextTrackButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"NextTrack"];
+ }
+
+ if ([df objectForKey:@"PrevTrack"]) {
+ anItem = [df keyComboForKey:@"PrevTrack"];
+ [hotKeysDictionary setObject:anItem forKey:@"PrevTrack"];
+ [previousTrackButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"PrevTrack"];
+ }
+
+ if ([df objectForKey:@"ToggleVisualizer"]) {
+ anItem = [df keyComboForKey:@"ToggleVisualizer"];
+ [hotKeysDictionary setObject:anItem forKey:@"ToggleVisualizer"];
+ [visualizerButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleVisualizer"];
+ }
+
+ if ([df objectForKey:@"TrackInfo"]) {
+ anItem = [df keyComboForKey:@"TrackInfo"];
+ [hotKeysDictionary setObject:anItem forKey:@"TrackInfo"];
+ [trackInfoButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"TrackInfo"];
+ }
+
+ if ([df objectForKey:@"UpcomingSongs"]) {
+ anItem = [df keyComboForKey:@"UpcomingSongs"];
+ [hotKeysDictionary setObject:anItem forKey:@"UpcomingSongs"];
+ [upcomingSongsButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"UpcomingSongs"];
+ }
+
+ if ([df objectForKey:@"IncrementVolume"]) {
+ anItem = [df keyComboForKey:@"IncrementVolume"];
+ [hotKeysDictionary setObject:anItem forKey:@"IncrementVolume"];
+ [volumeIncrementButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementVolume"];
+ }
+
+ if ([df objectForKey:@"DecrementVolume"]) {
+ anItem = [df keyComboForKey:@"DecrementVolume"];
+ [hotKeysDictionary setObject:anItem forKey:@"DecrementVolume"];
+ [volumeDecrementButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementVolume"];
+ }
+
+ if ([df objectForKey:@"IncrementRating"]) {
+ anItem = [df keyComboForKey:@"IncrementRating"];
+ [hotKeysDictionary setObject:anItem forKey:@"IncrementRating"];
+ [ratingIncrementButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"IncrementRating"];
+ }
+
+ if ([df objectForKey:@"DecrementRating"]) {
+ anItem = [df keyComboForKey:@"DecrementRating"];
+ [hotKeysDictionary setObject:anItem forKey:@"DecrementRating"];
+ [ratingDecrementButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"DecrementRating"];
+ }
+
+ if ([df objectForKey:@"ToggleLoop"]) {
+ anItem = [df keyComboForKey:@"ToggleLoop"];
+ [hotKeysDictionary setObject:anItem forKey:@"ToggleLoop"];
+ [toggleLoopButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleLoop"];
+ }
+
+ if ([df objectForKey:@"ToggleShuffle"]) {
+ anItem = [df keyComboForKey:@"ToggleShuffle"];
+ [hotKeysDictionary setObject:anItem forKey:@"ToggleShuffle"];
+ [toggleShuffleButton setTitle:[anItem userDisplayRep]];
+ } else {
+ [hotKeysDictionary setObject:[KeyCombo keyCombo] forKey:@"ToggleShuffle"];
+ }
+
+ // Check current track info buttons
+ [albumCheckbox setState:[df boolForKey:@"showAlbum"] ? NSOnState : NSOffState];
+ [nameCheckbox setState:NSOnState]; // Song info will ALWAYS show song title.
+ [nameCheckbox setEnabled:NO]; // Song info will ALWAYS show song title.
+ [artistCheckbox setState:[df boolForKey:@"showArtist"] ? NSOnState : NSOffState];
+ [trackTimeCheckbox setState:[df boolForKey:@"showTime"] ? NSOnState : NSOffState];
+
+ // Set the launch at login checkbox state
+ [df synchronize];
+ loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
+ loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
+
+ loginEnum = [loginarray objectEnumerator];
+ while ( (anItem = [loginEnum nextObject]) ) {
+ if ([[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
+ [launchAtLoginCheckbox setState:NSOnState];
+ }
+ }
+}
+
+- (IBAction)changeMenus:(id)sender
+{
+ [df setObject:myItems forKey:@"menu"];
+ [df synchronize];
+ [controller rebuildMenu];
+}
+
+- (void)setLaunchesAtLogin:(BOOL)flag
+{
+ if ( flag ) {
+ NSMutableDictionary *loginwindow;
+ NSMutableArray *loginarray;
+ ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);;
+ int i;
+ BOOL skip = NO;
+
+ [df synchronize];
+ loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
+ loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
+
+ for (i = 0; i < [loginarray count]; i++) {
+ NSDictionary *tempDict = [loginarray objectAtIndex:i];
+ if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
+ skip = YES;
+ }
+ }
+
+ if (!skip) {
+ AEDesc scriptDesc, resultDesc;
+ NSString *script = [NSString stringWithFormat:@"tell application \"System Events\"\nmake new login item at end of login items with properties {path:\"%@\", kind:\"APPLICATION\"}\nend tell", [[NSBundle mainBundle] bundlePath]];
+
+ AECreateDesc(typeChar, [script cString], [script cStringLength],
+ &scriptDesc);
+
+ OSADoScript(temp, &scriptDesc, kOSANullScript, typeChar, kOSAModeCanInteract, &resultDesc);
+
+ AEDisposeDesc(&scriptDesc);
+ AEDisposeDesc(&resultDesc);
+ CloseComponent(temp);
+ }
+
+ } else {
+ NSMutableDictionary *loginwindow;
+ NSMutableArray *loginarray;
+ int i;
+
+ [df synchronize];
+ loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy];
+ loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
+
+ for (i = 0; i < [loginarray count]; i++) {
+ NSDictionary *tempDict = [loginarray objectAtIndex:i];
+ if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) {
+ [loginarray removeObjectAtIndex:i];
+ [df setPersistentDomain:loginwindow forName:@"loginwindow"];
+ [df synchronize];
+ break;
+ }
+ }
+ }
+}
+
+
+/*************************************************************************/
+#pragma mark -
+#pragma mark NSWindow DELEGATE METHODS
+/*************************************************************************/