Changeset 1269

Show
Ignore:
Timestamp:
06/06/10 18:45:50 (2 years ago)
Author:
gbooker
Message:

Run calculations on auto-sort dirs for TV shows and present it in a nice UI.

Location:
trunk/SapphireFrappliance
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/SapphireFrappliance/Browser/SapphireMarkMenu.m

    r1268 r1269  
    697697                                [invoke setTarget:self]; 
    698698                                [invoke setArgument:&dirMeta atIndex:3]; 
     699                                [invoke retainArguments]; 
    699700                                 
    700701                                SapphireConfirmPrompt *confirm = [[SapphireConfirmPrompt alloc] initWithScene:[self scene] title:BRLocalizedString(@"Delete Directory?", @"Delete Directory Prompt Title") subtitle:[NSString stringWithFormat:BRLocalizedString(@"Are you sure you wish to delete %@?", @"parameter is file/dir that is being deleted"), [[dirMeta path] lastPathComponent]] invokation:invoke]; 
     
    787788                                [invoke setTarget:self]; 
    788789                                [invoke setArgument:&fileMeta atIndex:3]; 
     790                                [invoke retainArguments]; 
    789791                                 
    790792                                SapphireConfirmPrompt *confirm = [[SapphireConfirmPrompt alloc] initWithScene:[self scene] title:BRLocalizedString(@"Delete File?", @"Delete File Prompt Title") subtitle:[NSString stringWithFormat:BRLocalizedString(@"Are you sure you wish to delete %@?", @"parameter is file/dir that is being deleted"), [[fileMeta path] lastPathComponent]] invokation:invoke]; 
  • trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireSeason.h

    r1251 r1269  
    99- (NSComparisonResult)compare:(SapphireSeason *)other; 
    1010- (NSString *)seasonName; 
     11- (NSString *)autoSortPath; 
    1112@end 
  • trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireSeason.m

    r1251 r1269  
    6262} 
    6363 
     64- (NSString *)autoSortPath 
     65{ 
     66        NSString *showPath = [self.tvShow autoSortPath]; 
     67        if(showPath == nil) 
     68                return nil; 
     69         
     70        return [showPath stringByAppendingPathComponent:[self seasonName]]; 
     71} 
     72 
    6473- (NSPredicate *)metaFileFetchPredicate 
    6574{ 
  • trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireTVShow.h

    r1261 r1269  
    1010- (NSComparisonResult)compare:(SapphireTVShow *)other; 
    1111- (NSString *)calculateAutoSortPath; 
     12- (NSString *)autoSortPath; 
     13- (void)setAutoSortPath:(NSString *)path; 
    1214@end 
  • trunk/SapphireFrappliance/MetaData/SapphireMObjects/SapphireTVShow.m

    r1261 r1269  
    99#import "SapphireTVTranslation.h" 
    1010#import "SapphireFileMetaData.h" 
     11#import "SapphireOtherInformation.h" 
     12 
     13NSString *autoSortPathKey = @"autoSortPath"; 
    1114 
    1215@implementation SapphireTVShow 
     
    179182        } 
    180183         
     184        if(!cropTwoDirs) 
     185        { 
     186                NSString *lastPathComponent = [sortPath lastPathComponent]; 
     187                if([[lastPathComponent lowercaseString] hasPrefix:@"season"]) 
     188                        sortPath = [sortPath stringByDeletingLastPathComponent]; 
     189        } 
     190         
    181191        return sortPath; 
    182192} 
    183193 
     194- (NSString *)autoSortPath 
     195{ 
     196        return [self otherInformationForKey:autoSortPathKey]; 
     197} 
     198 
     199- (void)setAutoSortPath:(NSString *)path 
     200{ 
     201        [self setOtherObject:path forKey:autoSortPathKey]; 
     202} 
     203 
    184204@end 
  • trunk/SapphireFrappliance/MetaData/Support/SapphireOtherInformation.m

    r1251 r1269  
    5454{ 
    5555        NSMutableDictionary *mutOther = [[self otherInformation] mutableCopy]; 
     56        if(mutOther == nil) 
     57                mutOther = [[NSMutableDictionary alloc] init]; 
    5658        [mutOther setObject:obj forKey:key]; 
    5759        NSDictionary *dict = [mutOther copy]; 
  • trunk/SapphireFrappliance/Settings/SapphireSettings.m

    r1251 r1269  
    3434#import "SapphireDirectoryMetaData.h" 
    3535#import "SapphireMetaDataSupport.h" 
     36#import "SapphireTVShow.h" 
     37#import "SapphireConfirmPrompt.h" 
     38#import "CoreDataSupportFunctions.h" 
     39#import "SapphireErrorDisplayController.h" 
     40 
    3641#import <SapphireCompatClasses/SapphireFrontRowCompat.h> 
    3742#import "NSString-Extensions.h" 
     
    6873        COMMAND_IMPORT_TV_DATA, 
    6974        COMMAND_IMPORT_MOVIE_DATA, 
     75        COMMAND_IMPORT_TV_AUTOSORT_CALCULATE, 
    7076        COMMAND_IMPORT_HIDE_POSTER_CHOOSER, 
    7177        COMMAND_IMPORT_USE_DIR_NAME, 
     
    134140                        [theme gem:IMDB_GEM_KEY], SETTING_GEM, 
    135141                        [NSNumber numberWithInt:COMMAND_IMPORT_MOVIE_DATA], SETTING_COMMAND, 
     142                        nil], 
     143                [NSDictionary dictionaryWithObjectsAndKeys: 
     144                        BRLocalizedString(@"  Calculate TV Directories", @"Calculate TV Dirs menu item"), SETTING_NAME, 
     145                        BRLocalizedString(@"Tells Sapphire to calculate directories where each TV show is stored.", @"Calculate TV Dirs description"), SETTING_DESCRIPTION, 
     146                        [theme gem:TVR_GEM_KEY], SETTING_GEM, 
     147                        [NSNumber numberWithInt:COMMAND_IMPORT_TV_AUTOSORT_CALCULATE], SETTING_COMMAND, 
    136148                        nil], 
    137149/*              [NSDictionary dictionaryWithObjectsAndKeys: 
     
    424436} 
    425437 
     438- (SapphireConfirmPrompt *)nextAutoSortPathConfirm:(NSArray *)shows 
     439{ 
     440        int i, count = [shows count]; 
     441        SapphireTVShow *show; 
     442        NSString *calcAutoPath; 
     443        NSString *autoPath; 
     444        for(i=0; i<count; i++) 
     445        { 
     446                show = [shows objectAtIndex:i]; 
     447                calcAutoPath = [show calculateAutoSortPath]; 
     448                autoPath = [show autoSortPath]; 
     449                if(autoPath == nil && calcAutoPath == nil) 
     450                        continue; 
     451                if(autoPath == nil || calcAutoPath == nil) 
     452                        //Only one of them is nil 
     453                        break; 
     454                if(![autoPath isEqualToString:calcAutoPath]) 
     455                        break; 
     456        } 
     457         
     458        if(i == count) 
     459                return nil; 
     460         
     461        NSArray *newArray = [shows subarrayWithRange:NSMakeRange(i+1, count-i-1)]; 
     462        NSInvocation *invoke = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(promptResult:forShow:remaining:)]]; 
     463        [invoke setTarget:self]; 
     464        [invoke setSelector:@selector(promptResult:forShow:remaining:)]; 
     465        [invoke setArgument:&show atIndex:3]; 
     466        [invoke setArgument:&newArray atIndex:4]; 
     467        [invoke retainArguments]; 
     468         
     469        NSString *question; 
     470        if(calcAutoPath != nil) 
     471                question = [NSString stringWithFormat:BRLocalizedString(@"Do you want to set the show path for %@ to %@?", @"Prompt for setting a show's path, arguments are show name and path"), [show name], calcAutoPath]; 
     472        else 
     473                question = [NSString stringWithFormat:BRLocalizedString(@"Do you want to delete the show path for %@?", @"Prompt for deleting a show's path, argument is show name"), [show name]]; 
     474         
     475        SapphireConfirmPrompt *prompt = [[SapphireConfirmPrompt alloc] initWithScene:[self scene] title:BRLocalizedString(@"Show Path", @"Show Path") subtitle:question invokation:invoke]; 
     476        return [prompt autorelease]; 
     477} 
     478 
     479- (BRLayerController *)promptResult:(SapphireConfirmPromptResult)result forShow:(SapphireTVShow *)show remaining:(NSArray *)remain 
     480{ 
     481        if(result == SapphireConfirmPromptResultAbort) 
     482                return nil; 
     483         
     484        if(result == SapphireConfirmPromptResultOK) 
     485        { 
     486                [show setAutoSortPath:[show calculateAutoSortPath]]; 
     487                [SapphireMetaDataSupport save:moc]; 
     488        } 
     489         
     490        return [self nextAutoSortPathConfirm:remain]; 
     491} 
     492 
    426493- (void)wasExhumed 
    427494{ 
     
    546613                        [menu release]; 
    547614                        [importer release]; 
     615                        break; 
     616                } 
     617                case COMMAND_IMPORT_TV_AUTOSORT_CALCULATE: 
     618                { 
     619                        NSArray *shows = doFetchRequest(SapphireTVShowName, moc, nil); 
     620                        SapphireConfirmPrompt *confirm = [self nextAutoSortPathConfirm:shows]; 
     621                        if(confirm != nil) 
     622                                [[self stack] pushController:confirm]; 
     623                        else 
     624                        { 
     625                                SapphireErrorDisplayController *error = [[SapphireErrorDisplayController alloc] initWithScene:[self scene] error:BRLocalizedString(@"No Changes", @"No Changes") longError:BRLocalizedString(@"Sapphire didn't detect any changes to show paths", @"Display info for no show path changes detected")]; 
     626                                [[self stack] pushController:error]; 
     627                                [error release]; 
     628                        } 
    548629                        break; 
    549630                }