Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 5acaa18324
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 108 lines (91 sloc) 2.91 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
//
// PPNewStationController.m
// PlayerPiano
//
// Created by Matt Ball on 5/22/10.
//

#import "PPNewStationController.h"
#import <PianoBar/PPSearchResult.h>
#import <PianoBar/PPStation.h>

@interface PPNewStationController ()
@property (nonatomic, retain, readwrite) NSArray *searchResults;
@end

@implementation PPNewStationController

@synthesize searchField=_searchField, artistItem=_artistItem, songItem=_songItem,
arrayController=_arrayController;
@synthesize pianobar=_pianobar, searchResults=_searchResults, searchType=_searchType;

- (void)dealloc
{
[_searchField release];
_searchField = nil;
[_artistItem release];
_artistItem = nil;
[_songItem release];
_songItem = nil;
[_arrayController release];
_arrayController = nil;
[_pianobar release];
_pianobar = nil;
[_searchResults release];
_searchResults = nil;
[super dealloc];
}

- (IBAction)search:(id)sender
{
if ([[self.searchField stringValue] length] == 0) {
self.searchResults = nil;
return;
}

if (self.searchType == PPNewStationSearchTypeArtist) {
self.searchResults = [self.pianobar stationsSimilarToArtist:[self.searchField stringValue]];
} else if (self.searchType == PPNewStationSearchTypeSong) {
self.searchResults = [self.pianobar stationsSimilarToSong:[self.searchField stringValue]];
}
}

- (IBAction)cancel:(id)sender
{
[NSApp endSheet:[self window]];
}

- (IBAction)addStation:(id)sender
{
if ([[self.arrayController selectedObjects] count] == 0) {
NSLog(@"No selection");
return;
}

PPSearchResult *result = [[self.arrayController selectedObjects] objectAtIndex:0];
NSString *musicID = result.musicID;
[self.pianobar createStationForMusicID:musicID];

// Find out what station number it is
NSString *stationPrefix = result.title;
if (self.searchType == PPNewStationSearchTypeArtist) {
stationPrefix = result.artist;
}

PPStation *newStation = nil;
for (PPStation *station in self.pianobar.stations) {
if ([station.name hasPrefix:stationPrefix]) {
newStation = station;
break;
}
}
if (newStation) {
self.pianobar.selectedStation = newStation;
}

[NSApp endSheet:[self window]];
}

- (IBAction)setSearchTypeArtist:(id)sender
{
self.searchType = PPNewStationSearchTypeArtist;
[[self.searchField cell] setPlaceholderString:NSLocalizedString(@"Artist", @"New Station search placeholder: Artist")];
[self.artistItem setState:NSOnState];
[self.songItem setState:NSOffState];
[[self.searchField cell] setSearchMenuTemplate:[[self.searchField cell] searchMenuTemplate]];
}

- (IBAction)setSearchTypeSong:(id)sender
{
self.searchType = PPNewStationSearchTypeSong;
[[self.searchField cell] setPlaceholderString:NSLocalizedString(@"Song", @"New Station search placeholder: Song")];
[self.artistItem setState:NSOffState];
[self.songItem setState:NSOnState];
[[self.searchField cell] setSearchMenuTemplate:[[self.searchField cell] searchMenuTemplate]];
}

@end
Something went wrong with that request. Please try again.