Changeset 1345 for trunk

Show
Ignore:
Timestamp:
05/08/11 15:38:59 (13 months ago)
Author:
gbooker
Message:

Made computed auto sort paths into a set, and ask about each item in the set.

Location:
trunk/SapphireFrappliance
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireTVShow.h

    r1269 r1345  
    99 
    1010- (NSComparisonResult)compare:(SapphireTVShow *)other; 
    11 - (NSString *)calculateAutoSortPath; 
     11- (NSSet *)calculateAutoSortPaths; 
    1212- (NSString *)autoSortPath; 
    1313- (void)setAutoSortPath:(NSString *)path; 
  • trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireTVShow.m

    r1291 r1345  
    151151} 
    152152 
    153 - (NSString *)calculateAutoSortPath 
     153- (NSSet *)calculateAutoSortPaths 
    154154{ 
    155155        NSArray *files = doFetchRequest(SapphireFileMetaDataName, [self managedObjectContext], [self metaFileFetchPredicate]); 
     
    157157                return nil; 
    158158         
    159         NSString *sortPath = [[(SapphireFileMetaData *)[files objectAtIndex:0] path] stringByDeletingLastPathComponent]; 
    160         BOOL cropTwoDirs = NO; 
    161159        NSEnumerator *fileEnum = [files objectEnumerator]; 
    162160        SapphireFileMetaData *file; 
     161        NSMutableSet *paths = [NSMutableSet set]; 
    163162        while((file = [fileEnum nextObject]) != nil) 
    164163        { 
    165164                NSString *dirPath = [[file path] stringByDeletingLastPathComponent]; 
    166                 if(cropTwoDirs) 
     165                NSString *dirName = [dirPath lastPathComponent]; 
     166                if([[dirName lowercaseString] hasPrefix:@"season"]) 
    167167                        dirPath = [dirPath stringByDeletingLastPathComponent]; 
    168168                 
    169                 if([dirPath isEqualToString:sortPath]) 
    170                         continue; 
    171                  
    172                 if(!cropTwoDirs) 
    173                 { 
    174                         sortPath = [sortPath stringByDeletingLastPathComponent]; 
    175                         dirPath = [dirPath stringByDeletingLastPathComponent]; 
    176                         cropTwoDirs = YES; 
    177                         if([dirPath isEqualToString:sortPath]) 
    178                                 continue; 
    179                 } 
    180                  
    181                 return nil; 
     169                [paths addObject:dirPath]; 
    182170        } 
    183171         
    184         if(!cropTwoDirs) 
    185         { 
    186                 NSString *lastPathComponent = [sortPath lastPathComponent]; 
    187                 if([[lastPathComponent lowercaseString] hasPrefix:@"season"]) 
    188                         sortPath = [sortPath stringByDeletingLastPathComponent]; 
    189         } 
    190          
    191         return sortPath; 
     172        return paths; 
    192173} 
    193174 
  • trunk/SapphireFrappliance/Settings/SapphireSettings.m

    r1324 r1345  
    491491} 
    492492 
    493 - (SapphireConfirmPrompt *)nextAutoSortPathConfirm:(NSArray *)shows 
    494 { 
    495         int i, count = [shows count]; 
    496         SapphireTVShow *show; 
     493int checkPaths(NSString *autoPath, NSArray *computedPaths, int startIndex) 
     494{ 
     495        int i, count = [computedPaths count]; 
     496        for (i=startIndex; i<count; i++) { 
     497                if(![autoPath isEqualToString:[computedPaths objectAtIndex:i]]) 
     498                        break; 
     499        } 
     500        return i; 
     501} 
     502 
     503- (SapphireConfirmPrompt *)nextAutoSortPathConfirm:(NSArray *)paths forShow:(SapphireTVShow *)show remaining:(NSArray *)remaining 
     504{ 
    497505        NSString *calcAutoPath = nil; 
    498         NSString *autoPath; 
    499         for(i=0; i<count; i++) 
     506        NSString *autoPath = [show autoSortPath]; 
     507        if([paths count] > 0) 
    500508        { 
    501                 show = [shows objectAtIndex:i]; 
    502                 calcAutoPath = [show calculateAutoSortPath]; 
    503                 autoPath = [show autoSortPath]; 
    504                 if(autoPath == nil && calcAutoPath == nil) 
    505                         continue; 
    506                 if(autoPath == nil || calcAutoPath == nil) 
    507                         //Only one of them is nil 
    508                         break; 
    509                 if(![autoPath isEqualToString:calcAutoPath]) 
    510                         break; 
     509                int skipCount = checkPaths(autoPath, paths, 1);  //We had just checked the first one, continue after that. 
     510                paths = [paths subarrayWithRange:NSMakeRange(skipCount, [paths count]-skipCount)]; 
    511511        } 
    512          
    513         if(i == count) 
    514                 return nil; 
    515          
    516         NSArray *newArray = [shows subarrayWithRange:NSMakeRange(i+1, count-i-1)]; 
    517         NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(promptResult:forShow:remaining:)]]; 
     512        if([paths count] != 0) 
     513                calcAutoPath = [paths objectAtIndex:0]; 
     514        else 
     515        { 
     516                int i, count = [remaining count]; 
     517                for(i=0; i<count; i++) 
     518                { 
     519                        show = [remaining objectAtIndex:i]; 
     520                        autoPath = [show autoSortPath]; 
     521                        paths = [[show calculateAutoSortPaths] allObjects]; 
     522                        NSLog(@"Paths for %@ are %@", [show name], paths); 
     523                        if([paths count]) 
     524                        { 
     525                                int skipCount = checkPaths(autoPath, paths, 0); 
     526                                if(skipCount > 0) 
     527                                        paths = [paths subarrayWithRange:NSMakeRange(skipCount, [paths count]-skipCount)]; 
     528                        } 
     529                        if([paths count]) 
     530                        { 
     531                                calcAutoPath = [paths objectAtIndex:0]; 
     532                                break; 
     533                        } 
     534                } 
     535                if(i == count) 
     536                        return nil; 
     537                remaining = [remaining subarrayWithRange:NSMakeRange(i + 1, [remaining count] - i - 1)]; 
     538        } 
     539         
     540        NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(promptResult:forShow:paths:remaining:)]]; 
    518541        [invoke setTarget:self]; 
    519         [invoke setSelector:@selector(promptResult:forShow:remaining:)]; 
     542        [invoke setSelector:@selector(promptResult:forShow:paths:remaining:)]; 
    520543        [invoke setArgument:&show atIndex:3]; 
    521         [invoke setArgument:&newArray atIndex:4]; 
     544        [invoke setArgument:&paths atIndex:4]; 
     545        [invoke setArgument:&remaining atIndex:5]; 
    522546        [invoke retainArguments]; 
    523547         
     
    532556} 
    533557 
    534 - (BRLayerController *)promptResult:(SapphireConfirmPromptResult)result forShow:(SapphireTVShow *)show remaining:(NSArray *)remain 
     558- (BRLayerController *)promptResult:(SapphireConfirmPromptResult)result forShow:(SapphireTVShow *)show paths:(NSArray *)paths remaining:(NSArray *)remain 
    535559{ 
    536560        if(result == SapphireConfirmPromptResultAbort) 
     
    539563        if(result == SapphireConfirmPromptResultOK) 
    540564        { 
    541                 [show setAutoSortPath:[show calculateAutoSortPath]]; 
     565                [show setAutoSortPath:[paths objectAtIndex:0]]; 
    542566                [SapphireMetaDataSupport save:moc]; 
     567                return [self nextAutoSortPathConfirm:nil forShow:nil remaining:remain]; 
    543568        } 
    544569         
    545         return [self nextAutoSortPathConfirm:remain]; 
     570        return [self nextAutoSortPathConfirm:paths forShow:show remaining:remain]; 
    546571} 
    547572 
     
    683708                { 
    684709                        NSArray *shows = doFetchRequest(SapphireTVShowName, moc, nil); 
    685                         SapphireConfirmPrompt *confirm = [self nextAutoSortPathConfirm:shows]; 
     710                        SapphireConfirmPrompt *confirm = [self nextAutoSortPathConfirm:nil forShow:nil remaining:shows]; 
    686711                        if(confirm != nil) 
    687712                                [[self stack] pushController:confirm];