CatNiP prefinal
Sähköinen nuottikirja, HY-TKTKL-OHTUPROJ KESÄ11
|
00001 00027 00028 00029 00030 00031 00032 00033 #define LIBRARYTYPE self.libraryType.selectedSegmentIndex 00034 00035 #import "CatNiPViewController.h" 00036 @implementation CatNiPViewController 00037 @synthesize toolbarView; 00038 @synthesize toolbar; 00039 @synthesize libraryButton; 00040 @synthesize libraryType; 00041 @synthesize searchType; // not in use 00042 @synthesize notesButton; 00043 @synthesize playlistNavigateButton; 00044 @synthesize playlistNavigateSControl; 00045 00046 @synthesize libraryViewLeft; 00047 @synthesize libraryTableViewLeft; 00048 @synthesize librarySearchbarLeft; 00049 @synthesize libraryActivityIndicatorLeft; 00050 00051 @synthesize libraryViewRight; 00052 @synthesize libraryTableViewRight; 00053 @synthesize fitToWidthButton; 00054 @synthesize librarySearchbarRight; 00055 00056 @synthesize scoreView; 00057 00058 @synthesize imslpDelegateAndDataSource = IMSLPdds; 00059 @synthesize localDelegateAndDataSource = LOCALdds; 00060 @synthesize playlistsDelegateAndDataSource = PLAYLISTSdds; 00061 00062 @synthesize spc; 00063 @synthesize dpc; 00064 @synthesize npc; 00065 @synthesize ppc; 00066 00067 @synthesize defaultFont; 00068 @synthesize currentlyOpenedFile; 00069 @synthesize currentScore; 00070 @synthesize currentPlaylistIndex; 00071 // currentPlayList getter/setter implemented manually 00072 00073 - (void)dealloc 00074 { 00075 // kill 'em all 00076 [self.libraryTableViewLeft release]; 00077 [self.libraryButton release]; 00078 [self.libraryTableViewRight release]; 00079 [self.librarySearchbarLeft release]; 00080 [self.libraryViewLeft release]; 00081 [self.librarySearchbarRight release]; 00082 [self.libraryViewRight release]; 00083 [self.toolbar release]; 00084 [self.scoreView release]; 00085 [self.libraryType release]; 00086 [self.searchType release]; 00087 [self.toolbarView release]; 00088 [self.libraryActivityIndicatorLeft release]; 00089 [self.notesButton release]; 00090 [self.playlistNavigateButton release]; 00091 [self.playlistNavigateSControl release]; 00092 [self.imslpDelegateAndDataSource release]; 00093 [self.localDelegateAndDataSource release]; 00094 [self.playlistsDelegateAndDataSource release]; 00095 [self.npc release]; 00096 [self.spc release]; 00097 [self.dpc release]; 00098 [self.ppc release]; 00099 [self.fitToWidthButton release]; 00100 [self.currentScore release]; 00101 [super dealloc]; 00102 } 00103 00104 - (void)didReceiveMemoryWarning 00105 { 00106 // Releases the view if it doesn't have a superview. 00107 [super didReceiveMemoryWarning]; 00108 00109 00110 // Release any cached data, images, etc that aren't in use. 00111 } 00112 00113 #pragma mark - View lifecycle 00114 00115 00116 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 00117 - (void)viewDidLoad 00118 { 00119 /* default font and fontsize for UI elements. 00120 * If you change the font, check the heigh calculation of rows in tableView:heightForRowAtIndexPath: 00121 */ 00122 defaultFont = [UIFont fontWithName:@"Georgia" size:17.0]; 00123 00124 self.imslpDelegateAndDataSource = [[IMSLPDelegateDataSource alloc] initWithMaster:self]; 00125 self.localDelegateAndDataSource = [[LocalDelegateDataSource alloc] initWithMaster:self]; 00126 self.playlistsDelegateAndDataSource = [[PlaylistsDelegateDataSource alloc] initWithMaster:self]; 00127 00128 [self.libraryType addTarget:self action:@selector(libraryTypeChanged:) forControlEvents:UIControlEventValueChanged]; 00129 [self.playlistNavigateSControl addTarget:self action:@selector(playlistNavigatorChanged:) forControlEvents:UIControlEventValueChanged]; 00130 00131 // make cells selectable when in editing mode 00132 self.libraryTableViewRight.allowsSelectionDuringEditing = YES; 00133 self.libraryTableViewLeft.allowsSelectionDuringEditing = YES; 00134 00135 // make UI search views hidden 00136 self.libraryViewRight.hidden = YES; 00137 self.libraryViewLeft.hidden = YES; 00138 self.searchType.hidden = YES; 00139 self.libraryType.hidden = YES; 00140 [self.libraryActivityIndicatorLeft stopAnimating]; 00141 00142 // and transform their places outside the screen so that they will slide into user view. 00143 [self hideViewWithAnimation:self.libraryViewLeft]; 00144 [self hideViewWithAnimation:self.libraryViewRight]; 00145 00146 // add gesture recognizer for scoreView to intercept tapping and other hand 00147 // gestures for the application. 00148 UITapGestureRecognizer *scoreViewGR = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scoreView_tapped:)] autorelease]; 00149 [self.scoreView addGestureRecognizer:scoreViewGR]; 00150 00151 // read all composers from IMSLP to IMSLPdds' composer array 00152 [IMSLPQueryHelper readIMSLPCategory:@"Category:Composers" reportTo:self withMethod:@selector(imslpComposersReport:)]; 00153 00154 // Application-specific settings for the score view 00155 UIImage *appStoreIcon = [UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"CatNiPAppStoreIcon.png"]]; 00156 self.scoreView.documentView.placeholder = appStoreIcon; 00157 00158 NSString *firstScreen = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"CatNiPFirstScreen.pdf"]; 00159 [self.scoreView setScore:firstScreen]; 00160 00161 self.scoreView.documentView.preloadFactor = 1.0; 00162 00163 // Initialize the notes popover 00164 self.npc = [[NotesPopoverController alloc] initWithMaster:self]; 00165 notesTextView = npc.textView; 00166 notesPop = [[UIPopoverController alloc] initWithContentViewController:npc]; 00167 [notesPop setPopoverContentSize:CGSizeMake(500,400)]; 00168 notesPop.delegate = self.npc; 00169 00170 // Register as an error receiver 00171 [[CatNiPErrorManager sharedManager] addErrorConsumer:self]; 00172 } 00173 00174 - (void)viewDidUnload 00175 { 00176 // toolbar and its buttons 00177 [self setToolbarView:nil]; 00178 [self setToolbar:nil]; 00179 [self setLibraryType:nil]; 00180 [self setSearchType:nil]; 00181 [self setLibraryButton:nil]; 00182 00183 // left search elements 00184 [self setLibraryViewLeft:nil]; 00185 [self setLibraryTableViewLeft:nil]; 00186 [self setLibrarySearchbarLeft:nil]; 00187 [self setLibraryActivityIndicatorLeft:nil]; 00188 00189 // right search elements 00190 [self setLibraryTableViewRight:nil]; 00191 [self setLibraryViewRight:nil]; 00192 [self setLibrarySearchbarRight:nil]; 00193 00194 [self setScoreView:nil]; 00195 00196 [self setNpc:nil]; 00197 [self setDpc:nil]; 00198 [self setSpc:nil]; 00199 00200 [self setFitToWidthButton:nil]; 00201 [self setCurrentScore:nil]; 00202 [super viewDidUnload]; 00203 } 00204 00205 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 00206 { 00207 // Return YES for supported orientations 00208 return YES; 00209 } 00210 00211 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 00212 { 00213 float oldZoomScale = self.scoreView.documentView.zoomScale; 00214 00215 if(UIInterfaceOrientationIsPortrait(self.interfaceOrientation) && UIInterfaceOrientationIsLandscape(fromInterfaceOrientation)) 00216 [self.scoreView.documentView setZoomScale:self.scoreView.documentView.zoomScale * 3 / 4 animated:YES]; 00217 00218 if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation) && UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) 00219 [self.scoreView.documentView setZoomScale:self.scoreView.documentView.zoomScale * 4 / 3 animated:YES]; 00220 00221 float newZoomScale = self.scoreView.documentView.zoomScale; 00222 00223 // If the zoom scale does not change for whatever reason 00224 if(oldZoomScale == newZoomScale) 00225 [self.scoreView.documentView centerContent]; 00226 } 00227 00228 00229 #pragma mark - UISearchBarDelegate protocol 00230 /************ UISearchBarDelegate protocol's functions **************/ 00231 /* */ 00232 /* */ 00233 /* For more information about these check framework's API. */ 00234 /********************************************************************/ 00235 00236 00248 - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 00249 { 00250 //[self searchBarSearchButtonClicked:searchBar]; 00251 } 00252 00262 - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar 00263 { 00264 if (searchBar == self.librarySearchbarLeft) 00265 { 00266 NSIndexPath *indexPath; 00267 00268 if (LIBRARYTYPE == LOCAL) 00269 { 00270 NSArray *searchArray = self.localDelegateAndDataSource.composers; 00271 if ([searchArray count] == 0) return; 00272 indexPath = [NSIndexPath indexPathForRow:[self arrayToSearch:searchArray textToSearch:[searchBar text]] inSection:0]; 00273 [libraryTableViewLeft selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 00274 00275 } 00276 if (LIBRARYTYPE == IMSLP) 00277 { 00278 NSArray *searchArray = self.imslpDelegateAndDataSource.composers; 00279 if ([searchArray count] == 0) return; 00280 indexPath = [NSIndexPath indexPathForRow:[self arrayToSearch:searchArray textToSearch:[searchBar text]] inSection:0]; 00281 [libraryTableViewLeft selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 00282 00283 } 00284 if (LIBRARYTYPE == PLAYLISTS) 00285 { 00286 // search playlists and pick "best choice". 00287 } 00288 } 00289 else if (searchBar == self.librarySearchbarRight) 00290 { 00291 NSIndexPath *indexPath; 00292 00293 if (LIBRARYTYPE == LOCAL) 00294 { 00295 NSArray *searchArray = self.localDelegateAndDataSource.compositions; 00296 if ([searchArray count] == 0) return; 00297 indexPath = [NSIndexPath indexPathForRow:[self compositionDatasToSearch:searchArray textToSearch:[searchBar text]] inSection:0]; 00298 [libraryTableViewRight selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 00299 } 00300 if (LIBRARYTYPE == IMSLP) 00301 { 00302 NSArray *searchArray = self.imslpDelegateAndDataSource.compositions; 00303 if ([searchArray count] == 0) return; 00304 indexPath = [NSIndexPath indexPathForRow:[self arrayToSearch:searchArray textToSearch:[searchBar text]] inSection:0]; 00305 [libraryTableViewRight selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 00306 } 00307 if (LIBRARYTYPE == PLAYLISTS) 00308 { 00309 // search playlists and pick "best choice". 00310 } 00311 00312 } 00313 else 00314 { 00315 // bug fix message 00316 NSLog(@"searchBarSearchButtonClicked: in CatNiPViewController didn't recognize the searchbar that invoked the function."); 00317 } 00318 } 00319 00320 00321 #pragma mark - UIGestureRecognizer 00322 /**************** UIGestureRecognizers' functions ***************/ 00323 /* */ 00324 /* */ 00325 /* */ 00326 /*****************************************************************/ 00327 00336 -(void)scoreView_tapped:(UIGestureRecognizer *)recognizer 00337 { 00338 CGPoint p = [recognizer locationInView:self.scoreView]; 00339 NSLog(@"toolbar is tapped at (%f, %f)", p.x, p.y); 00340 00341 if (self.toolbarView.hidden == YES) 00342 { 00343 [self showToolbarWithAnimation]; 00344 } 00345 else 00346 { 00347 [self hideViewWithAnimation:self.libraryViewLeft]; 00348 [self hideViewWithAnimation:self.libraryViewRight]; 00349 self.libraryType.hidden = YES; 00350 [self hideToolbarWithAnimation]; 00351 } 00352 } 00353 00354 #pragma mark - Custom functions for application 00355 /**************** Custom functions for application ******************/ 00356 /* */ 00357 /* */ 00358 /* */ 00359 /********************************************************************/ 00360 00361 00370 - (IBAction)showHideLibrary:(id)sender 00371 { 00372 if (self.libraryViewLeft.hidden == YES) 00373 { 00374 [notesPop dismissPopoverAnimated:YES]; 00375 self.libraryType.hidden = NO; 00376 self.searchType.hidden = NO; 00377 [self showViewWithAnimation:self.libraryViewLeft]; 00378 [self.libraryTableViewLeft reloadData]; 00379 } 00380 else 00381 { 00382 [notesPop dismissPopoverAnimated:YES]; 00383 self.searchType.hidden = YES; 00384 self.libraryType.hidden = YES; 00385 [self hideViewWithAnimation:self.libraryViewRight]; 00386 [self hideViewWithAnimation:self.libraryViewLeft]; 00387 [self hideToolbarWithAnimation]; 00388 } 00389 } 00390 00404 -(UITableViewCell *)tableView:(UITableView *)tableView createCellWithIdentifier:(NSString *)identifier 00405 { 00406 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 00407 if (cell == nil) 00408 cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:identifier] autorelease]; 00409 00410 cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 00411 cell.textLabel.numberOfLines = 0; 00412 cell.textLabel.font = defaultFont; 00413 cell.selectionStyle = UITableViewCellSelectionStyleGray; 00414 00415 return cell; 00416 } 00417 00423 - (IBAction)showHideNotes:(id)sender 00424 { 00425 if(![notesPop isPopoverVisible]) 00426 [notesPop presentPopoverFromBarButtonItem:self.notesButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; 00427 else 00428 { 00429 self.currentScore.userNotes = npc.textView.text; 00430 [notesPop dismissPopoverAnimated:YES]; 00431 } 00432 } 00433 00445 - (NSInteger)arrayToSearch:(NSArray *)array textToSearch:(NSString *)text 00446 { 00447 for (int i = 0; i < [array count]; i++) { 00448 int c = [(NSString *)[array objectAtIndex:i] caseInsensitiveCompare:text]; 00449 if (c >= 0) return i; 00450 } 00451 return 0; 00452 } 00453 00454 -(NSInteger)compositionDatasToSearch:(NSArray *)array textToSearch:(NSString *)text 00455 { 00456 for (int i = 0; i < [array count]; i++) { 00457 int c = [(NSString *)[[array objectAtIndex:i] compositionName] caseInsensitiveCompare:text]; 00458 if (c >= 0) return i; 00459 } 00460 return 0; 00461 } 00462 00469 - (void)showScoreSheets:(LocalScoreData *)score { 00470 // If we're called it means the user opened a file directly, so we need to lose 00471 // the active playlist 00472 self.currentPlaylist = nil; 00473 self.playlistNavigateSControl.enabled = FALSE; 00474 [self openScoreSheet:score]; 00475 } 00476 00480 -(BOOL)openScoreSheet:(LocalScoreData *)score { 00481 00482 // dismiss popovers 00483 [detailPop dismissPopoverAnimated:YES]; 00484 [scorePop dismissPopoverAnimated:YES]; 00485 [notesPop dismissPopoverAnimated:YES]; 00486 00487 // hide searchbar keyboards 00488 [self.librarySearchbarLeft resignFirstResponder]; 00489 [self.librarySearchbarRight resignFirstResponder]; 00490 00491 // hide other UI elements 00492 self.libraryType.hidden = YES; 00493 [self hideToolbarWithAnimation]; 00494 [self hideViewWithAnimation:self.libraryViewLeft]; 00495 [self hideViewWithAnimation:self.libraryViewRight]; 00496 00497 @try 00498 { 00499 BOOL ret = [self.scoreView setScore:score.pdf]; 00500 if(ret) 00501 { 00502 self.currentScore = score; 00503 npc.textView.text = score.userNotes; 00504 } 00505 return ret; 00506 } 00507 @catch (NSException *exception) 00508 { 00509 UIAlertView* errorView = [UIAlertView alloc]; 00510 errorView = [[errorView 00511 initWithTitle:[exception name] message:[exception description] delegate:nil cancelButtonTitle:@"Sounds bad" otherButtonTitles: nil] autorelease]; 00512 [errorView show]; 00513 return NO; 00514 } 00515 @finally 00516 { 00517 // do we need this oh well! 00518 } 00519 return NO; 00520 00521 } 00532 - (void) openScorePopover:(CompositionData *)scores editable:(BOOL)ed 00533 { 00534 self.spc = [[ScorePopoverController alloc] initWithStyle:UITableViewStylePlain masterController:self compositionData:scores editable:ed]; 00535 00536 UITableViewCell *popInHere = [self.libraryTableViewRight cellForRowAtIndexPath:[libraryTableViewRight indexPathForSelectedRow]]; 00537 00538 // try to make popover show arrow in right spot and be of right size 00539 scorePop = [[UIPopoverController alloc] initWithContentViewController:spc]; 00540 [scorePop setPopoverContentSize:CGSizeMake(0, 400)]; 00541 [scorePop presentPopoverFromRect:popInHere.frame inView:self.libraryTableViewRight permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES]; 00542 [scorePop setPopoverContentSize:CGSizeMake(500, 400) animated:YES]; 00543 } 00544 00546 -(void)dismissScorePopover 00547 { 00548 [scorePop dismissPopoverAnimated:YES]; 00549 } 00550 00559 - (void) openDetailPopoverFromRect:(CGRect)rect inView:(UIView *)view withScore:(ScoreData *)score ofComposer:(NSString *)composer andComposition:(NSString *)composition 00560 { 00561 self.dpc = [[[DetailPopoverController alloc] initWithStyle:UITableViewStyleGrouped masterController:self dictionary:score.metaDataDict] autorelease]; 00562 self.dpc.composer = composer; 00563 self.dpc.composition = composition; 00564 self.dpc.description = score.description; 00565 00566 detailPop = [[UIPopoverController alloc] initWithContentViewController:dpc]; 00567 [detailPop setPopoverContentSize:CGSizeMake(400, 500)]; 00568 [detailPop presentPopoverFromRect:rect inView:view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:YES]; 00569 } 00570 00576 -(void)openPlaylistPopoverFromRect:(CGRect)rect inView:(UIView *)view withScore:(LocalScoreData *)score 00577 { 00578 self.ppc = [[PlaylistPopoverController alloc] initWithStyle:UITableViewStyleGrouped masterController:self andScore:score]; 00579 playlistPop =[[UIPopoverController alloc] initWithContentViewController:ppc]; 00580 [playlistPop setPopoverContentSize:CGSizeMake(400, 500)]; 00581 [playlistPop presentPopoverFromRect:rect inView:view permittedArrowDirections:UIPopoverArrowDirectionDown|UIPopoverArrowDirectionUp animated:YES]; 00582 } 00583 00585 -(void)dismissPlaylistPopover 00586 { 00587 [playlistPop dismissPopoverAnimated:YES]; 00588 } 00589 00590 00602 -(void)libraryTypeChanged:(id)sender { 00603 00604 // hide some UI elements 00605 [self hideViewWithAnimation:self.libraryViewRight]; 00606 [notesPop dismissPopoverAnimated:YES]; 00607 00608 switch (LIBRARYTYPE) // change delegate and datasource based on new librarytype 00609 { 00610 case IMSLP: 00611 [self.imslpDelegateAndDataSource changeLibraryTypeToIMSLP]; 00612 break; 00613 case LOCAL: 00614 [self.localDelegateAndDataSource changeLibraryTypeToLocal]; 00615 break; 00616 case PLAYLISTS: 00617 [self.playlistsDelegateAndDataSource changeLibraryTypeToPlaylists]; 00618 break; 00619 default: // library type not recognized 00620 NSLog(@"libraryTypeChanged: in CatNiPViewController couldn't spesify the library type that was given."); 00621 break; 00622 } 00623 } 00624 00626 -(void)hideToolbarWithAnimation 00627 { 00628 [UIView animateWithDuration:0.8 00629 delay:0.0 00630 options:UIViewAnimationOptionCurveEaseIn 00631 animations:^{ 00632 self.toolbarView.transform = CGAffineTransformMakeTranslation(0, -50);} 00633 completion:^(BOOL finished){self.toolbarView.hidden = YES;}]; 00634 } 00635 00637 -(void)showToolbarWithAnimation 00638 { 00639 [UIView animateWithDuration:0.8 00640 delay:0.0 00641 options:UIViewAnimationOptionCurveEaseIn 00642 animations:^{ 00643 self.toolbarView.hidden = NO; 00644 self.toolbarView.transform = CGAffineTransformMakeTranslation(0, 0);} 00645 completion:NULL]; 00646 } 00647 00649 -(void)hideViewWithAnimation:(UIView *)view 00650 { 00651 [UIView animateWithDuration:0.8 00652 delay:0.0 00653 options:UIViewAnimationOptionCurveEaseInOut 00654 animations:^{ 00655 view.transform = CGAffineTransformMakeTranslation(0, -1024); 00656 ;} 00657 completion:^(BOOL finished){view.hidden = YES;}]; 00658 } 00659 00661 -(void)showViewWithAnimation:(UIView *)view 00662 { 00663 [UIView animateWithDuration:0.8 00664 delay:0.0 00665 options:UIViewAnimationOptionCurveEaseInOut 00666 animations:^{ 00667 view.hidden = NO; 00668 view.transform = CGAffineTransformMakeTranslation(0, 0); 00669 if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)) 00670 { 00671 if (view == self.libraryViewLeft) view.frame = CGRectMake(0, 39, 384, 985); 00672 if (view == self.libraryViewRight) view.frame = CGRectMake(384, 39, 384, 985); 00673 } 00674 if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 00675 { 00676 if (view == self.libraryViewLeft) view.frame = CGRectMake(0, 39, 512, 729); 00677 if (view == self.libraryViewRight) view.frame = CGRectMake(512, 39, 512, 729); 00678 } 00679 ;} 00680 completion:NULL]; 00681 } 00690 -(void)setCurrentPlaylist:(Playlist *)currentPlaylist { 00691 [currentPlaylist retain]; 00692 [_currentPlaylist release]; 00693 _currentPlaylist = currentPlaylist; 00694 self.currentPlaylistIndex = -1; 00695 if(_currentPlaylist && [_currentPlaylist.scorelist count] > 0) { 00696 // Open the first score in the playlist 00697 LocalScoreData* firstScore = [_currentPlaylist.scorelist objectAtIndex:0]; 00698 self.playlistNavigateSControl.enabled = TRUE; 00699 [self openScoreSheet:firstScore]; 00700 self.currentPlaylistIndex = 0; 00701 } else { 00702 self.playlistNavigateSControl.enabled = FALSE; 00703 } 00704 00705 } 00710 -(Playlist *)currentPlaylist { 00711 return _currentPlaylist; 00712 } 00713 00722 -(void)playlistNavigatorChanged:(id)control { 00723 UISegmentedControl* nav = control; 00724 NSLog(@"urlrl"); 00725 if(self.currentPlaylist) { 00726 // We only do anything if there is an active playlist 00727 // We also check if the playlist is non-empty 00728 if([self.currentPlaylist.scorelist count] == 0) { 00729 // Pre-emptive return because nesting if:s are fugly. 00730 return; 00731 } 00732 NSInteger curIdx = self.currentPlaylistIndex; 00733 // NSInteger i = 0; 00734 // First we go through the playlist contents and find the index of the 00735 // current opened pdf file. This is an O(n) operation, but since we 00736 // can't be sure of the integrity of the playlist (ie. if the user has 00737 // managed to modify the playlist while it is open) we can't really 00738 // trust any cached index value for the pdf file 00739 // for (LocalScoreData* score in self.currentPlaylist.scorelist) { 00740 // if([self.currentlyOpenedFile caseInsensitiveCompare:score.pdf] == NSOrderedSame) { 00741 // curIdx = i; 00742 // } 00743 // i++; 00744 // } 00745 NSLog(@"In playlist navigation, curIdx: %d",curIdx); 00746 // nav.selectedSegmentIndex is only valid for the duration of this method call. 00747 // since the Segmented Control isn't persistent, ie. it automatically returns 00748 // to "nothing is selected" state after a press 00749 switch (nav.selectedSegmentIndex) { 00750 case 0: // Previous pressed 00751 if(curIdx > 0) { // We're at the non-first score in the playlist... 00752 LocalScoreData *newScore = [self.currentPlaylist.scorelist objectAtIndex:curIdx-1]; 00753 [self openScoreSheet:newScore]; 00754 self.currentPlaylistIndex = curIdx-1; 00755 } 00756 else if(curIdx == -1) { 00757 // No matching entry found in the playlist 00758 // Go to first entry I guess!!! 00759 LocalScoreData *newScore = [self.currentPlaylist.scorelist objectAtIndex:0]; 00760 [self openScoreSheet:newScore]; 00761 self.currentPlaylistIndex = 0; 00762 } 00763 break; 00764 case 1: // Next pressed 00765 if(curIdx+1 < [self.currentPlaylist.scorelist count]) { 00766 LocalScoreData *newScore = [self.currentPlaylist.scorelist objectAtIndex:curIdx+1]; 00767 [self openScoreSheet:newScore]; 00768 self.currentPlaylistIndex = curIdx+1; 00769 } else if(curIdx == -1) { 00770 // No matching entry found in the playlist 00771 // Go to last entry I guess!!! 00772 LocalScoreData *newScore = [self.currentPlaylist.scorelist objectAtIndex:[self.currentPlaylist.scorelist count]-1]; 00773 [self openScoreSheet:newScore]; 00774 self.currentPlaylistIndex = [self.currentPlaylist.scorelist count]-1; 00775 } 00776 break; 00777 default: 00778 break; 00779 00780 } 00781 } 00782 //NSLog(@"Selected segment: %d",[nav selectedSegmentIndex]); 00783 } 00784 00792 -(void) imslpComposersReport:(id)progress { 00793 if(progress == nil) { 00794 NSLog(@"Composers reading in process"); 00795 } 00796 else { 00797 NSLog(@"Composers reading done."); 00798 NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:progress]; 00799 [temp sortUsingSelector:@selector(compare:)]; 00800 self.imslpDelegateAndDataSource.composers = temp; 00801 [self.imslpDelegateAndDataSource.composers retain]; 00802 [temp release]; 00803 if (LIBRARYTYPE == IMSLP) // if library is set to IMSLP reload tabledata 00804 { 00805 [self.libraryActivityIndicatorLeft stopAnimating]; 00806 [self.libraryTableViewLeft reloadData]; 00807 } 00808 } 00809 } 00816 -(void) imslpCompositionsReport:(id)progress { 00817 if(progress == nil) { 00818 NSLog(@"Composition reading in process"); 00819 } 00820 else { 00821 NSLog(@"Composition reading done."); 00822 NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:progress]; 00823 [temp sortUsingSelector:@selector(compare:)]; 00824 self.imslpDelegateAndDataSource.compositions = temp; 00825 [self.imslpDelegateAndDataSource.compositions retain]; 00826 [temp release]; 00827 [self.libraryTableViewRight reloadData]; 00828 } 00829 } 00830 00831 -(void)imslpPageReport:(id)pageData { 00832 CompositionData* receivedData = (CompositionData*)pageData; 00833 00834 if (_readComposition) 00835 [_readComposition release]; 00836 00837 _readComposition = receivedData; 00838 [_readComposition retain]; 00839 00840 [self openScorePopover:_readComposition editable:NO]; 00841 } 00842 00852 -(void)saveAndShowScore:(id)fileNameParams :(id)ofComposition 00853 { 00854 NSLog(@"Loaded file %@ into path: %@",[fileNameParams objectAtIndex:0], [fileNameParams objectAtIndex:1]); 00855 LocalScoreData *loadedScore = [LocalDataHandler createLocalScoreData:fileNameParams ofComposition:ofComposition localScores:self.localDelegateAndDataSource.allLocalScores]; 00856 [[self.localDelegateAndDataSource allLocalScores] addObject:loadedScore]; 00857 [LocalDataHandler saveScoresToDefaultFile:self.localDelegateAndDataSource.allLocalScores]; 00858 [self showScoreSheets:loadedScore]; 00859 } 00860 00870 -(void)saveScore:(id)fileNameParams :(id)ofComposition 00871 { 00872 NSLog(@"Loaded file %@ into path: %@",[fileNameParams objectAtIndex:0], [fileNameParams objectAtIndex:1]); 00873 LocalScoreData *loadedScore = [LocalDataHandler createLocalScoreData:fileNameParams ofComposition:ofComposition localScores:self.localDelegateAndDataSource.allLocalScores]; 00874 [[self.localDelegateAndDataSource allLocalScores] addObject:loadedScore]; 00875 [LocalDataHandler saveScoresToDefaultFile:self.localDelegateAndDataSource.allLocalScores]; 00876 00877 // if scorepopover is shown at the moment update corresponding cell's accessoryview 00878 if ([scorePop isPopoverVisible] && LIBRARYTYPE == IMSLP) 00879 { 00880 for (int i = 0; i < [spc.compositionData.musicScores count]; i++) 00881 { 00882 ScoreData *s = [spc.compositionData.musicScores objectAtIndex:i]; 00883 if ([(NSString *)[fileNameParams objectAtIndex:0] compare:s.pdf] == 0) 00884 { 00885 NSIndexPath *ip = [NSIndexPath indexPathForRow:i inSection:0]; 00886 UITableViewCell *cell = [self.spc.tableView cellForRowAtIndexPath:ip]; 00887 cell.accessoryView = [self.spc IMSLPAccessoryViewForIndexPath:ip]; 00888 cell.editingAccessoryView = [self.spc IMSLPAccessoryViewForIndexPath:ip]; 00889 } 00890 } 00891 } 00892 } 00893 00894 - (IBAction)fitToWidth:(id)sender { 00895 [self.scoreView.documentView setZoomScale:self.scoreView.documentView.bounds.size.width / self.scoreView.documentView.document.size.width animated:YES]; 00896 } 00897 00898 00904 -(void)processError:(NSError *)error { 00905 //NSLog(@"Hello WORLD"); 00906 NSLog(@"recovery suggestion: %@", [error localizedRecoverySuggestion]); 00907 // NSArray* durr = [error localizedRecoveryOptions]; 00908 00909 UIAlertView* errorView = [UIAlertView alloc]; 00910 errorView = [[errorView initWithTitle:[error localizedFailureReason] message:[error localizedDescription] delegate:nil cancelButtonTitle:@"Oh dear" otherButtonTitles: nil] autorelease]; 00911 [errorView show]; 00912 } 00913 @end