Changeset 8843


Ignore:
Timestamp:
Jul 20, 2009, 12:40:01 AM (13 years ago)
Author:
livings124
Message:

#2287 Remove options to delete torrent file when removing, and remove internal storing of torrent file location

Location:
trunk/macosx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/AddWindowController.h

    r7659 r8843  
    4141   
    4242    Torrent * fTorrent;
    43     NSString * fDestination;
     43    NSString * fDestination, * fTorrentFile;
    4444    BOOL fLockDestination;
    4545   
     
    5151
    5252- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path lockDestination: (BOOL) lockDestination
    53     controller: (Controller *) controller deleteTorrent: (torrentFileState) deleteTorrent;
     53    controller: (Controller *) controller torrentFile: (NSString *) torrentFile
     54    deleteTorrent: (BOOL) deleteTorrent canToggleDelete: (BOOL) canToggleDelete;
    5455
    5556- (Torrent *) torrent;
  • trunk/macosx/AddWindowController.m

    r7659 r8843  
    5050
    5151- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path lockDestination: (BOOL) lockDestination
    52     controller: (Controller *) controller deleteTorrent: (torrentFileState) deleteTorrent
     52    controller: (Controller *) controller torrentFile: (NSString *) torrentFile
     53    deleteTorrent: (BOOL) deleteTorrent canToggleDelete: (BOOL) canToggleDelete
    5354{
    5455    if ((self = [super initWithWindowNibName: @"AddWindow"]))
    5556    {
    5657        fTorrent = torrent;
    57         if (path)
    58             fDestination = [[path stringByExpandingTildeInPath] retain];
     58        fDestination = [[path stringByExpandingTildeInPath] retain];
    5959        fLockDestination = lockDestination;
    6060       
    6161        fController = controller;
    6262       
    63         fDeleteTorrent = deleteTorrent == TORRENT_FILE_DELETE || (deleteTorrent == TORRENT_FILE_DEFAULT
    64                             && [[NSUserDefaults standardUserDefaults] boolForKey: @"DeleteOriginalTorrent"]);
    65         fDeleteEnable = deleteTorrent == TORRENT_FILE_DEFAULT;
     63        fTorrentFile = [[torrentFile stringByExpandingTildeInPath] retain];
     64       
     65        fDeleteTorrent = deleteTorrent;
     66        fDeleteEnable = canToggleDelete;
    6667       
    6768        fGroupValue = [torrent groupValue];
     
    239240    [fTorrent setGroupValue: fGroupValue];
    240241   
    241     if ([fDeleteCheck state] == NSOnState)
    242         [fTorrent trashTorrent];
     242    if (fTorrentFile && [fDeleteCheck state] == NSOnState)
     243        [Torrent trashFile: fTorrentFile];
    243244   
    244245    [fFileController setTorrent: nil]; //avoid a crash when window tries to update
  • trunk/macosx/Controller.m

    r8842 r8843  
    777777    }
    778778   
    779     torrentFileState deleteTorrentFile;
     779    BOOL deleteTorrentFile, canToggleDelete = NO;
    780780    switch (type)
    781781    {
    782782        case ADD_CREATED:
    783             deleteTorrentFile = TORRENT_FILE_SAVE;
     783            deleteTorrentFile = NO;
    784784            break;
    785785        case ADD_URL:
    786             deleteTorrentFile = TORRENT_FILE_DELETE;
     786            deleteTorrentFile = YES;
    787787            break;
    788788        default:
    789             deleteTorrentFile = TORRENT_FILE_DEFAULT;
     789            deleteTorrentFile = [fDefaults boolForKey: @"DeleteOriginalTorrent"];
     790            canToggleDelete = YES;
    790791    }
    791792   
     
    839840        Torrent * torrent;
    840841        if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location
    841                             deleteTorrentFile: showWindow ? TORRENT_FILE_SAVE : deleteTorrentFile lib: fLib]))
     842                            deleteTorrentFile: showWindow ? NO : deleteTorrentFile lib: fLib]))
    842843            continue;
    843844       
     
    860861        {
    861862            AddWindowController * addController = [[AddWindowController alloc] initWithTorrent: torrent destination: location
    862                                                     lockDestination: lockDestination controller: self deleteTorrent: deleteTorrentFile];
     863                                                    lockDestination: lockDestination controller: self torrentFile: torrentPath
     864                                                    deleteTorrent: deleteTorrentFile canToggleDelete: canToggleDelete];
    863865            [addController showWindow: self];
    864866        }
  • trunk/macosx/Torrent.h

    r8439 r8843  
    2828@class FileListNode;
    2929
    30 typedef enum
    31 {
    32     TORRENT_FILE_DELETE,
    33     TORRENT_FILE_SAVE,
    34     TORRENT_FILE_DEFAULT
    35 } torrentFileState;
    36 
    3730#define STAT_TIME_NONE -1
    3831#define STAT_TIME_NOW -2
     
    4841    BOOL fUseIncompleteFolder;
    4942    NSString * fDownloadFolder, * fIncompleteFolder;
    50    
    51     BOOL fPublicTorrent;
    52     NSString * fPublicTorrentLocation;
    5343       
    5444    NSUserDefaults * fDefaults;
     
    7363}
    7464
    75 - (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
     65- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete
    7666        lib: (tr_session *) lib;
    7767- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_session *) lib;
     
    128118
    129119- (void) revealData;
    130 - (void) revealPublicTorrent;
     120+ (void) trashFile: (NSString *) path;
    131121- (void) trashData;
    132 - (void) trashTorrent;
    133122- (void) moveTorrentDataFileTo: (NSString *) folder;
    134123- (void) copyTorrentFileTo: (NSString *) path;
     
    171160
    172161- (NSString *) torrentLocation;
    173 - (NSString *) publicTorrentLocation;
    174162- (NSString *) dataLocation;
    175 
    176 - (BOOL) publicTorrent;
    177163
    178164- (CGFloat) progress;
  • trunk/macosx/Torrent.m

    r8800 r8843  
    3232
    3333- (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib
    34         publicTorrent: (NSNumber *) publicTorrent publicTorrentLocation: (NSString *) publicTorrentLoc
    3534        downloadFolder: (NSString *) downloadFolder
    3635        useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
     
    5655- (void) updateAllTrackers: (NSMutableArray *) trackers;
    5756
    58 + (void) trashFile: (NSString *) path;
    59 
    6057- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path;
    6158
     
    8178@implementation Torrent
    8279
    83 - (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
     80- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete
    8481        lib: (tr_session *) lib
    8582{
    8683    self = [self initWithPath: path hash: nil torrentStruct: NULL lib: lib
    87             publicTorrent: torrentDelete != TORRENT_FILE_DEFAULT ? [NSNumber numberWithBool: torrentDelete == TORRENT_FILE_SAVE] : nil
    88             publicTorrentLocation: path
    8984            downloadFolder: location
    9085            useIncompleteFolder: nil incompleteFolder: nil
     
    9388    if (self)
    9489    {
    95         //if the public and private torrent files are the same, then there is no public torrent
    96         if ([[self torrentLocation] isEqualToString: path])
    97         {
    98             fPublicTorrent = NO;
    99             [fPublicTorrentLocation release];
    100             fPublicTorrentLocation = nil;
    101         }
    102         else if (!fPublicTorrent)
     90        if (torrentDelete && [[self torrentLocation] isEqualToString: path])
    10391            [Torrent trashFile: path];
    104         else;
    10592    }
    10693    return self;
     
    11097{
    11198    self = [self initWithPath: nil hash: nil torrentStruct: torrentStruct lib: lib
    112             publicTorrent: [NSNumber numberWithBool: NO] publicTorrentLocation: nil
    11399            downloadFolder: location
    114100            useIncompleteFolder: nil incompleteFolder: nil
     
    123109                hash: [history objectForKey: @"TorrentHash"]
    124110                torrentStruct: NULL lib: lib
    125                 publicTorrent: [history objectForKey: @"PublicCopy"]
    126                 publicTorrentLocation: [history objectForKey: @"TorrentPath"]
    127111                downloadFolder: [history objectForKey: @"DownloadFolder"]
    128112                useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"]
     
    174158                    [self torrentLocation], @"InternalTorrentPath",
    175159                    [self hashString], @"TorrentHash",
    176                     [NSNumber numberWithBool: fPublicTorrent], @"PublicCopy",
    177160                    fDownloadFolder, @"DownloadFolder",
    178161                    [NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder",
     
    184167    if (fIncompleteFolder)
    185168        [history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];
    186 
    187     if (fPublicTorrent)
    188         [history setObject: [self publicTorrentLocation] forKey: @"TorrentPath"];
    189169       
    190170    return history;
     
    206186    [fDownloadFolder release];
    207187    [fIncompleteFolder release];
    208    
    209     [fPublicTorrentLocation release];
    210188   
    211189    [fIcon release];
     
    464442}
    465443
    466 - (void) revealPublicTorrent
    467 {
    468     if (fPublicTorrent)
    469         [[NSWorkspace sharedWorkspace] selectFile: fPublicTorrentLocation inFileViewerRootedAtPath: nil];
     444#warning should be somewhere else?
     445+ (void) trashFile: (NSString *) path
     446{
     447    //attempt to move to trash
     448    if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation
     449        source: [path stringByDeletingLastPathComponent] destination: @""
     450        files: [NSArray arrayWithObject: [path lastPathComponent]] tag: nil])
     451    {
     452        //if cannot trash, just delete it (will work if it's on a remote volume)
     453        NSError * error;
     454        if (![[NSFileManager defaultManager] removeItemAtPath: path error: &error])
     455            NSLog(@"Could not trash %@: %@", path, [error localizedDescription]);
     456    }
    470457}
    471458
     
    473460{
    474461    tr_torrentDeleteLocalData(fHandle, trashDataFile);
    475 }
    476 
    477 - (void) trashTorrent
    478 {
    479     if (fPublicTorrent)
    480     {
    481         [Torrent trashFile: fPublicTorrentLocation];
    482         [fPublicTorrentLocation release];
    483         fPublicTorrentLocation = nil;
    484        
    485         fPublicTorrent = NO;
    486     }
    487462}
    488463
     
    879854}
    880855
    881 - (NSString *) publicTorrentLocation
    882 {
    883     return fPublicTorrentLocation;
    884 }
    885 
    886856- (NSString *) dataLocation
    887857{
    888858    return [[self downloadFolder] stringByAppendingPathComponent: [self name]];
    889 }
    890 
    891 - (BOOL) publicTorrent
    892 {
    893     return fPublicTorrent;
    894859}
    895860
     
    15961561
    15971562- (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib
    1598         publicTorrent: (NSNumber *) publicTorrent publicTorrentLocation: (NSString *) publicTorrentLoc
    15991563        downloadFolder: (NSString *) downloadFolder
    16001564        useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
     
    16061570   
    16071571    fDefaults = [NSUserDefaults standardUserDefaults];
    1608 
    1609     fPublicTorrent = publicTorrentLoc && (publicTorrent ? [publicTorrent boolValue] : ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);
    1610     if (fPublicTorrent)
    1611         fPublicTorrentLocation = [publicTorrentLoc retain];
    16121572   
    16131573    fDownloadFolder = downloadFolder ? downloadFolder : [fDefaults stringForKey: @"DownloadFolder"];
     
    19531913}
    19541914
    1955 + (void) trashFile: (NSString *) path
    1956 {
    1957     //attempt to move to trash
    1958     if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation
    1959         source: [path stringByDeletingLastPathComponent] destination: @""
    1960         files: [NSArray arrayWithObject: [path lastPathComponent]] tag: nil])
    1961     {
    1962         //if cannot trash, just delete it (will work if it's on a remote volume)
    1963         NSError * error;
    1964         if (![[NSFileManager defaultManager] removeItemAtPath: path error: &error])
    1965             NSLog(@"Could not trash %@: %@", path, [error localizedDescription]);
    1966     }
    1967 }
    1968 
    19691915- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path
    19701916{
Note: See TracChangeset for help on using the changeset viewer.