Changeset 648

Show
Ignore:
Timestamp:
07/30/08 17:26:17 (4 months ago)
Author:
gbooker
Message:

Added the ability to delete collections; useful for disks that no longer exist.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/CoreData/SapphireFrappliance/MetaData/SapphireMObjects/SapphireCollectionDirectory.h

    r611 r648  
    11#import "_SapphireCollectionDirectory.h" 
    22 
    3 @interface SapphireCollectionDirectory : _SapphireCollectionDirectory {} 
     3@interface SapphireCollectionDirectory : _SapphireCollectionDirectory { 
     4        BOOL            toDelete; 
     5
    46+ (SapphireCollectionDirectory *)collectionAtPath:(NSString *)path mount:(BOOL)isMount skip:(BOOL)skip hidden:(BOOL)hidden manual:(BOOL)manual inContext:(NSManagedObjectContext *)moc; 
    57+ (SapphireCollectionDirectory *)collectionAtPath:(NSString *)path inContext:(NSManagedObjectContext *)moc; 
    68+ (NSArray *)availableCollectionDirectoriesInContext:(NSManagedObjectContext *)moc; 
    79+ (NSArray *)skippedCollectionDirectoriesInContext:(NSManagedObjectContext *)moc; 
     10+ (NSArray *)allCollectionsInContext:(NSManagedObjectContext *)moc; 
     11 
     12- (BOOL)deleteValue; 
     13- (void)setDeleteValue:(BOOL)del; 
    814@end 
  • branches/CoreData/SapphireFrappliance/MetaData/SapphireMObjects/SapphireCollectionDirectory.m

    r611 r648  
    8282        return ret; 
    8383} 
     84 
     85+ (NSArray *)allCollectionsInContext:(NSManagedObjectContext *)moc 
     86{ 
     87        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(manualCollection == YES) OR (isMount == YES)"]; 
     88        NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"directory.path" ascending:YES]; 
     89        NSArray *ret = doSortedFetchRequest(MY_NAME, moc, predicate, sort); 
     90         
     91        [sort release]; 
     92        return ret; 
     93} 
     94 
     95- (BOOL)deleteValue 
     96{ 
     97        return toDelete; 
     98} 
     99 
     100- (void)setDeleteValue:(BOOL)del 
     101{ 
     102        toDelete = del; 
     103} 
    84104@end 
  • branches/CoreData/SapphireFrappliance/Settings/SapphireCollectionSettings.m

    r560 r648  
    3636         
    3737        moc = [context retain]; 
    38         collections = [[SapphireCollectionDirectory availableCollectionDirectoriesInContext:moc] retain]; 
     38        //Scan collections 
     39        [SapphireCollectionDirectory availableCollectionDirectoriesInContext:moc]; 
     40        collections = [[SapphireCollectionDirectory allCollectionsInContext:moc] retain]; 
     41         
    3942        [[self list] setDatasource:self]; 
    4043 
  • branches/CoreData/SapphireFrappliance/Settings/SapphireSettings.h

    r541 r648  
    3636        NSDictionary                            *defaults;                              /*!< @brief The default settings, in order*/ 
    3737        NSManagedObjectContext          *moc;                                   /*!< @brief The context*/ 
     38        int                                                     lastCommand;                    /*!< @brief The last command issued*/ 
    3839} 
    3940 
  • branches/CoreData/SapphireFrappliance/Settings/SapphireSettings.m

    r560 r648  
    3131#import "SapphireCollectionSettings.h" 
    3232#import "SapphireFileMetaData.h" 
     33#import "SapphireCollectionDirectory.h" 
     34#import "SapphireDirectoryMetaData.h" 
     35#import "SapphireMetaDataSupport.h" 
    3336#import <SapphireCompatClasses/SapphireFrontRowCompat.h> 
    3437#import "NSString-Extensions.h" 
     38#import "NSFileManager-Extensions.h" 
    3539 
    3640static SapphireSettings *sharedInstance = nil; 
     
    5761#define LAST_PREDICATE                          @"LastPredicate" 
    5862 
     63typedef enum { 
     64        COMMAND_OTHER, 
     65        COMMAND_DELETE_COLLECTION, 
     66} SettingsCommand; 
     67 
    5968+ (SapphireSettings *)sharedSettings 
    6069{ 
     
    7584        self = [super initWithScene:scene]; 
    7685         
     86        lastCommand = COMMAND_OTHER; 
    7787        /*Setup display*/ 
    7888        moc = [context retain]; 
     
    8393                                                                                                BRLocalizedString(@"  Hide Collections", @"Hide Collections menu item"), 
    8494                                                                                                BRLocalizedString(@"  Don't Import Collections", @"Don't Import Collections menu item"), 
     95                                                                                                BRLocalizedString(@"  Delete Collections", @"Delete Collections menu item"), 
    8596                                                                                                BRLocalizedString(@"  Skip \"Favorite Shows\" filter", @"Skip Favorite shows menu item"), 
    8697/*                                                                                              BRLocalizedString(@"  Skip \"Top Shows\" filter", @"Skip Top shows menu item"),*/ 
     
    103114                                                                                                BRLocalizedString(@"Allows the user to specify which collections should be hidden from Sapphire's main menu.", @"Hide Collections description"), 
    104115                                                                                                BRLocalizedString(@"Allows the user to specify which collections should be skipped when importing meta data.", @"Don't Import Collections description"), 
     116                                                                                                BRLocalizedString(@"Allows the user to specify which collections should be delete along with its data.  Use this for collections which will never be used again.", @"Delete Collections description"), 
    105117                                                                                                BRLocalizedString(@"Tells Sapphire that when changing filter settings, skip over the favorite shows filter.", @"Skip Favorite shows description"), 
    106118/*                                                                                              BRLocalizedString(@"Skip \"Top Shows\" filter", @"Skip Top shows description"),*/ 
     
    120132                                                                                                        @"", 
    121133                                                                                                /*      @"",*/ 
     134                                                                                                        @"", 
    122135                                                                                                        @"", 
    123136                                                                                                        @"", 
     
    141154                                                                                                [theme gem:FILE_GEM_KEY], 
    142155                                                                                                [theme gem:FILE_GEM_KEY], 
     156                                                                                                [theme gem:FILE_GEM_KEY], 
    143157                                                                                                [theme gem:YELLOW_GEM_KEY], 
    144158                                                                                                /*[theme gem:GREEN_GEM_KEY],*/ 
     
    178192        BRListControl *list = [self list]; 
    179193        [list setDatasource:self]; 
    180         [SapphireFrontRowCompat addDividerAtIndex:5 toList:list]; 
     194        [SapphireFrontRowCompat addDividerAtIndex:6 toList:list]; 
    181195        /*Save our instance*/ 
    182196        sharedInstance = [self retain]; 
     
    369383{ 
    370384    // handle being revealed when the user presses Menu 
     385         
     386        if(lastCommand == COMMAND_DELETE_COLLECTION) 
     387        { 
     388                NSArray *collections = [SapphireCollectionDirectory allCollectionsInContext:moc]; 
     389                NSEnumerator *colEnum = [collections objectEnumerator]; 
     390                SapphireCollectionDirectory *collection; 
     391                BOOL change = NO; 
     392                while((collection = [colEnum nextObject]) != nil) 
     393                { 
     394                        if([collection deleteValue]) 
     395                        { 
     396                                change = YES; 
     397                                SapphireDirectoryMetaData *dir = [collection directory]; 
     398                                if([[NSFileManager defaultManager] isDirectory:[dir path]]) 
     399                                        [moc deleteObject:collection]; 
     400                                else 
     401                                        [moc deleteObject:dir]; 
     402                        } 
     403                } 
     404                if(change) 
     405                        [SapphireMetaDataSupport save:moc]; 
     406        } 
    371407     
    372408    // always call super 
     
    438474    // This is called when the user changed a setting 
    439475 
     476        lastCommand = COMMAND_OTHER; 
    440477        /*Check for populate show data*/ 
    441478        if(row==0) 
     
    489526                [colSettings setSettingSelector:@selector(setSkipValue:)]; 
    490527                [colSettings setListTitle:BRLocalizedString(@"Skip Collections", @"Skip Collections Menu Title")] ; 
     528                [[self stack] pushController:colSettings]; 
     529                [colSettings release]; 
     530        } 
     531        else if(row == 5) 
     532        { 
     533                SapphireCollectionSettings *colSettings = [[SapphireCollectionSettings alloc] initWithScene:[self scene] context:moc]; 
     534                [colSettings setGettingSelector:@selector(deleteValue)]; 
     535                [colSettings setSettingSelector:@selector(setDeleteValue:)]; 
     536                [colSettings setListTitle:BRLocalizedString(@"Delete Collections", @"Delete Collections Menu Title")]; 
     537                lastCommand = COMMAND_DELETE_COLLECTION; 
    491538                [[self stack] pushController:colSettings]; 
    492539                [colSettings release];