Update iTunesRemote to match the new API. MainController and
[MenuTunes.git] / PreferencesController.m
index e1c47d1..a7c909e 100755 (executable)
@@ -1,5 +1,5 @@
 #import "PreferencesController.h"
-#import "NewMainController.h"
+#import "MainController.h"
 #import "HotKeyCenter.h"
 #import <ITKit/ITWindowPositioning.h>
 
@@ -85,6 +85,10 @@ static PreferencesController *prefs = nil;
         [self setupMenuItems];  // Setup the arrays of menu items
         [self setupUI]; // Sets up additional UI
         [window setDelegate:self];
+        [menuTableView reloadData];
+        
+        //Change the launch player checkbox to the proper name
+        [launchPlayerAtLaunchCheckbox setTitle:[NSString stringWithFormat:@"Launch %@ when MenuTunes launches", [[controller currentRemote] playerSimpleName]]]; //This isn't localized...
     }
     
     [window setLevel:NSStatusWindowLevel];
@@ -145,6 +149,7 @@ static PreferencesController *prefs = nil;
 
 - (IBAction)changeHotKey:(id)sender
 {
+    [controller clearHotKeys];
     switch ([sender tag])
     {
         case 4010:
@@ -208,8 +213,8 @@ static PreferencesController *prefs = nil;
 
     [df setObject:[NSArray arrayWithObjects:
         @"playPause",
-        @"nextTrack",
         @"prevTrack",
+        @"nextTrack",
         @"fastForward",
         @"rewind",
         @"showPlayer",
@@ -334,41 +339,42 @@ static PreferencesController *prefs = nil;
     
     if ([currentHotKey isEqualToString:@"PlayPause"]) {
         [playPauseButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" combo:combo target:[MainController sharedController] action:@selector(playPause)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"PlayPause" combo:combo target:[MainController sharedController] action:@selector(playPause)];
     } else if ([currentHotKey isEqualToString:@"NextTrack"]) {
         [nextTrackButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" combo:combo target:[MainController sharedController] action:@selector(nextSong)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"NextTrack" combo:combo target:[MainController sharedController] action:@selector(nextSong)];
     } else if ([currentHotKey isEqualToString:@"PrevTrack"]) {
         [previousTrackButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" combo:combo target:[MainController sharedController] action:@selector(prevSong)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"PrevTrack" combo:combo target:[MainController sharedController] action:@selector(prevSong)];
     } else if ([currentHotKey isEqualToString:@"ShowPlayer"]) {
         [showPlayerButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"ShowPlayer" combo:combo target:[MainController sharedController] action:@selector(showPlayer)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"ShowPlayer" combo:combo target:[MainController sharedController] action:@selector(showPlayer)];
     } else if ([currentHotKey isEqualToString:@"TrackInfo"]) {
         [trackInfoButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" combo:combo target:[MainController sharedController] action:@selector(showCurrentTrackInfo)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"TrackInfo" combo:combo target:[MainController sharedController] action:@selector(showCurrentTrackInfo)];
     } else if ([currentHotKey isEqualToString:@"UpcomingSongs"]) {
         [upcomingSongsButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" combo:combo target:[MainController sharedController] action:@selector(showUpcomingSongs)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"UpcomingSongs" combo:combo target:[MainController sharedController] action:@selector(showUpcomingSongs)];
     } else if ([currentHotKey isEqualToString:@"IncrementVolume"]) {
         [volumeIncrementButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" combo:combo target:[MainController sharedController] action:@selector(incrementVolume)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"IncrementVolume" combo:combo target:[MainController sharedController] action:@selector(incrementVolume)];
     } else if ([currentHotKey isEqualToString:@"DecrementVolume"]) {
         [volumeDecrementButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" combo:combo target:[MainController sharedController] action:@selector(decrementVolume)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"DecrementVolume" combo:combo target:[MainController sharedController] action:@selector(decrementVolume)];
     } else if ([currentHotKey isEqualToString:@"IncrementRating"]) {
         [ratingIncrementButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating" combo:combo target:[MainController sharedController] action:@selector(incrementRating)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"IncrementRating" combo:combo target:[MainController sharedController] action:@selector(incrementRating)];
     } else if ([currentHotKey isEqualToString:@"DecrementRating"]) {
         [ratingDecrementButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating" combo:combo target:[MainController sharedController] action:@selector(decrementRating)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"DecrementRating" combo:combo target:[MainController sharedController] action:@selector(decrementRating)];
     } else if ([currentHotKey isEqualToString:@"ToggleShuffle"]) {
         [toggleShuffleButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" combo:combo target:[MainController sharedController] action:@selector(toggleShuffle)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"ToggleShuffle" combo:combo target:[MainController sharedController] action:@selector(toggleShuffle)];
     } else if ([currentHotKey isEqualToString:@"ToggleLoop"]) {
         [toggleLoopButton setTitle:string];
-        [[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" combo:combo target:[MainController sharedController] action:@selector(toggleLoop)];
+        //[[HotKeyCenter sharedCenter] addHotKey:@"ToggleLoop" combo:combo target:[MainController sharedController] action:@selector(toggleLoop)];
     }
+    [controller setupHotKeys];
     [self cancelHotKey:sender];
 }
 
@@ -628,7 +634,7 @@ static PreferencesController *prefs = nil;
     if ( flag ) {
         NSMutableDictionary *loginwindow;
         NSMutableArray *loginarray;
-        ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);;
+        ComponentInstance temp = OpenDefaultComponent(kOSAComponentType, kAppleScriptSubtype);
         int i;
         BOOL skip = NO;
 
@@ -762,28 +768,30 @@ static PreferencesController *prefs = nil;
         dragData = [pb stringForType:@"MenuTableViewPboardType"];
         dragRow = [dragData intValue];
         temp = [myItems objectAtIndex:dragRow];
-        [myItems removeObjectAtIndex:dragRow];
         
         if (tableView == menuTableView) {
+            [myItems insertObject:temp atIndex:row];
             if (row > dragRow) {
-                [myItems insertObject:temp atIndex:row - 1];
+                [myItems removeObjectAtIndex:dragRow];
             } else {
-                [myItems insertObject:temp atIndex:row];
+                [myItems removeObjectAtIndex:dragRow + 1];
             }
         } else {
             if (![temp isEqualToString:@"separator"]) {
                 [availableItems addObject:temp];
             }
+            [myItems removeObjectAtIndex:dragRow];
         }
     } else if ([[pb types] containsObject:@"AllTableViewPboardType"]) {
         dragData = [pb stringForType:@"AllTableViewPboardType"];
         dragRow = [dragData intValue];
         temp = [availableItems objectAtIndex:dragRow];
         
+        [myItems insertObject:temp atIndex:row];
+        
         if (![temp isEqualToString:@"separator"]) {
             [availableItems removeObjectAtIndex:dragRow];
         }
-        [myItems insertObject:temp atIndex:row];
     }
     
     [menuTableView reloadData];