- int i;
- NSImageCell *imgCell = [[[NSImageCell alloc] init] autorelease];
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- NSString *temp;
-
- mt = [tunes retain];
-
- //Load the nib
- [NSBundle loadNibNamed:@"Preferences" owner:self];
-
- //Show our window
- [window setLevel:NSStatusWindowLevel];
- [window center];
- [window makeKeyAndOrderFront:nil];
-
- //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]];
-
- //Set the list of items you can have.
- availableItems = [[NSMutableArray alloc] initWithObjects:@"Current Track Info", @"Upcoming Songs", @"Playlists", @"EQ Presets", @"Play/Pause", @"Next Track", @"Previous Track", @"Fast Forward", @"Rewind", @"<separator>", nil];
-
- //Get our preferred menu
- myItems = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"menu"] mutableCopy];
- if (myItems == nil)
- {
- myItems = [[NSMutableArray alloc] initWithObjects:@"Play/Pause", @"Next Track", @"Previous Track", @"Fast Forward", @"Rewind", @"<separator>", @"Upcoming Songs", @"Playlists", @"EQ Presets", @"<separator>", @"PreferencesÉ", @"Quit", @"<separator>", @"Current Track Info", nil];
- [[NSUserDefaults standardUserDefaults] setObject:myItems forKey:@"menu"];
- }
-
- //Delete items in the availableItems array that are already part of the menu
- for (i = 0; i < [myItems count]; i++) {
- NSString *item = [myItems objectAtIndex:i];
- if (![item isEqualToString:@"<separator>"])
- {
- [availableItems removeObject:item];
- }
- }
-
- //Items that show should a submenu image
- submenuItems = [[NSArray alloc] initWithObjects:@"Upcoming Songs", @"Playlists", @"EQ Presets", nil];
-
- //Fill in the number of songs in advance to show field
- if ([defaults integerForKey:@"SongsInAdvance"]) {
- [songsInAdvance setIntValue:[defaults integerForKey:@"SongsInAdvance"]];
- } else {
- [songsInAdvance setIntValue:5];
- }
-
- //Fill in hot key buttons
- if ([defaults objectForKey:@"PlayPause"]){
- playPauseCombo = [defaults keyComboForKey:@"PlayPause"];
- [playPauseButton setTitle:[playPauseCombo userDisplayRep]];
- } else {
- playPauseCombo = [[KeyCombo alloc] init];
- }
-
- if ([defaults objectForKey:@"NextTrack"]) {
- nextTrackCombo = [defaults keyComboForKey:@"NextTrack"];
- [nextTrackButton setTitle:[nextTrackCombo userDisplayRep]];
- } else {
- nextTrackCombo = [[KeyCombo alloc] init];
- }
-
- if ([defaults objectForKey:@"PrevTrack"]) {
- prevTrackCombo = [defaults keyComboForKey:@"PrevTrack"];
- [previousTrackButton setTitle:[prevTrackCombo userDisplayRep]];
- } else {
- prevTrackCombo = [[KeyCombo alloc] init];
- }
-
- if ([defaults objectForKey:@"TrackInfo"]) {
- trackInfoCombo = [defaults keyComboForKey:@"TrackInfo"];
- [trackInfoButton setTitle:[trackInfoCombo userDisplayRep]];
- } else {
- trackInfoCombo = [[KeyCombo alloc] init];
- }
-
- if ([defaults objectForKey:@"UpcomingSongs"]) {
- upcomingSongsCombo = [defaults keyComboForKey:@"UpcomingSongs"];
- [upcomingSongsButton setTitle:[upcomingSongsCombo userDisplayRep]];
- } else {
- upcomingSongsCombo = [[KeyCombo alloc] init];
- }
-
- //Check current track info buttons
-
- //Album and name get special treatment because they are defaults
- if ( (temp = [defaults stringForKey:@"showAlbum"]) ) {
- if ((temp == nil) || [temp isEqualToString:@"1"]) {
- [albumCheckbox setState:NSOnState];
- } else {
- [albumCheckbox setState:NSOffState];
- }
- }
-
- if ( (temp = [defaults stringForKey:@"showName"]) ) {
- if ((temp == nil) || [temp isEqualToString:@"1"]) {
- [nameCheckbox setState:NSOnState];
- } else {
- [nameCheckbox setState:NSOffState];
- }
- }
-
- [artistCheckbox setState:[defaults boolForKey:@"showArtist"] ? NSOnState : NSOffState];
- [trackTimeCheckbox setState:[defaults boolForKey:@"showTime"] ? NSOnState : NSOffState];
-
- //Set the launch at login checkbox state
- {
- NSMutableDictionary *loginwindow;
- NSMutableArray *loginarray;
- int i;
-
- [defaults synchronize];
- loginwindow = [[defaults persistentDomainForName:@"loginwindow"] mutableCopy];
- loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
-
- for (i = 0; i < [loginarray count]; i++) {
- NSDictionary *tempDict = [loginarray objectAtIndex:i];
-
- //Here we are seeing if our program is already in loginwindow.plist.
- //See the problem below for this problem here. We will do the same thing.
-
- if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:@"VocabularyBuilder.app"]) {
- [launchAtLoginCheckbox setState:NSOnState];
- }
- }
- }