Changeset 8843
- Timestamp:
- Jul 20, 2009, 12:40:01 AM (13 years ago)
- Location:
- trunk/macosx
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/AddWindowController.h
r7659 r8843 41 41 42 42 Torrent * fTorrent; 43 NSString * fDestination ;43 NSString * fDestination, * fTorrentFile; 44 44 BOOL fLockDestination; 45 45 … … 51 51 52 52 - (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; 54 55 55 56 - (Torrent *) torrent; -
trunk/macosx/AddWindowController.m
r7659 r8843 50 50 51 51 - (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 53 54 { 54 55 if ((self = [super initWithWindowNibName: @"AddWindow"])) 55 56 { 56 57 fTorrent = torrent; 57 if (path) 58 fDestination = [[path stringByExpandingTildeInPath] retain]; 58 fDestination = [[path stringByExpandingTildeInPath] retain]; 59 59 fLockDestination = lockDestination; 60 60 61 61 fController = controller; 62 62 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; 66 67 67 68 fGroupValue = [torrent groupValue]; … … 239 240 [fTorrent setGroupValue: fGroupValue]; 240 241 241 if ( [fDeleteCheck state] == NSOnState)242 [ fTorrent trashTorrent];242 if (fTorrentFile && [fDeleteCheck state] == NSOnState) 243 [Torrent trashFile: fTorrentFile]; 243 244 244 245 [fFileController setTorrent: nil]; //avoid a crash when window tries to update -
trunk/macosx/Controller.m
r8842 r8843 777 777 } 778 778 779 torrentFileState deleteTorrentFile;779 BOOL deleteTorrentFile, canToggleDelete = NO; 780 780 switch (type) 781 781 { 782 782 case ADD_CREATED: 783 deleteTorrentFile = TORRENT_FILE_SAVE;783 deleteTorrentFile = NO; 784 784 break; 785 785 case ADD_URL: 786 deleteTorrentFile = TORRENT_FILE_DELETE;786 deleteTorrentFile = YES; 787 787 break; 788 788 default: 789 deleteTorrentFile = TORRENT_FILE_DEFAULT; 789 deleteTorrentFile = [fDefaults boolForKey: @"DeleteOriginalTorrent"]; 790 canToggleDelete = YES; 790 791 } 791 792 … … 839 840 Torrent * torrent; 840 841 if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location 841 deleteTorrentFile: showWindow ? TORRENT_FILE_SAVE: deleteTorrentFile lib: fLib]))842 deleteTorrentFile: showWindow ? NO : deleteTorrentFile lib: fLib])) 842 843 continue; 843 844 … … 860 861 { 861 862 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]; 863 865 [addController showWindow: self]; 864 866 } -
trunk/macosx/Torrent.h
r8439 r8843 28 28 @class FileListNode; 29 29 30 typedef enum31 {32 TORRENT_FILE_DELETE,33 TORRENT_FILE_SAVE,34 TORRENT_FILE_DEFAULT35 } torrentFileState;36 37 30 #define STAT_TIME_NONE -1 38 31 #define STAT_TIME_NOW -2 … … 48 41 BOOL fUseIncompleteFolder; 49 42 NSString * fDownloadFolder, * fIncompleteFolder; 50 51 BOOL fPublicTorrent;52 NSString * fPublicTorrentLocation;53 43 54 44 NSUserDefaults * fDefaults; … … 73 63 } 74 64 75 - (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: ( torrentFileState) torrentDelete65 - (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete 76 66 lib: (tr_session *) lib; 77 67 - (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_session *) lib; … … 128 118 129 119 - (void) revealData; 130 - (void) revealPublicTorrent;120 + (void) trashFile: (NSString *) path; 131 121 - (void) trashData; 132 - (void) trashTorrent;133 122 - (void) moveTorrentDataFileTo: (NSString *) folder; 134 123 - (void) copyTorrentFileTo: (NSString *) path; … … 171 160 172 161 - (NSString *) torrentLocation; 173 - (NSString *) publicTorrentLocation;174 162 - (NSString *) dataLocation; 175 176 - (BOOL) publicTorrent;177 163 178 164 - (CGFloat) progress; -
trunk/macosx/Torrent.m
r8800 r8843 32 32 33 33 - (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib 34 publicTorrent: (NSNumber *) publicTorrent publicTorrentLocation: (NSString *) publicTorrentLoc35 34 downloadFolder: (NSString *) downloadFolder 36 35 useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder … … 56 55 - (void) updateAllTrackers: (NSMutableArray *) trackers; 57 56 58 + (void) trashFile: (NSString *) path;59 60 57 - (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path; 61 58 … … 81 78 @implementation Torrent 82 79 83 - (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: ( torrentFileState) torrentDelete80 - (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete 84 81 lib: (tr_session *) lib 85 82 { 86 83 self = [self initWithPath: path hash: nil torrentStruct: NULL lib: lib 87 publicTorrent: torrentDelete != TORRENT_FILE_DEFAULT ? [NSNumber numberWithBool: torrentDelete == TORRENT_FILE_SAVE] : nil88 publicTorrentLocation: path89 84 downloadFolder: location 90 85 useIncompleteFolder: nil incompleteFolder: nil … … 93 88 if (self) 94 89 { 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]) 103 91 [Torrent trashFile: path]; 104 else;105 92 } 106 93 return self; … … 110 97 { 111 98 self = [self initWithPath: nil hash: nil torrentStruct: torrentStruct lib: lib 112 publicTorrent: [NSNumber numberWithBool: NO] publicTorrentLocation: nil113 99 downloadFolder: location 114 100 useIncompleteFolder: nil incompleteFolder: nil … … 123 109 hash: [history objectForKey: @"TorrentHash"] 124 110 torrentStruct: NULL lib: lib 125 publicTorrent: [history objectForKey: @"PublicCopy"]126 publicTorrentLocation: [history objectForKey: @"TorrentPath"]127 111 downloadFolder: [history objectForKey: @"DownloadFolder"] 128 112 useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"] … … 174 158 [self torrentLocation], @"InternalTorrentPath", 175 159 [self hashString], @"TorrentHash", 176 [NSNumber numberWithBool: fPublicTorrent], @"PublicCopy",177 160 fDownloadFolder, @"DownloadFolder", 178 161 [NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder", … … 184 167 if (fIncompleteFolder) 185 168 [history setObject: fIncompleteFolder forKey: @"IncompleteFolder"]; 186 187 if (fPublicTorrent)188 [history setObject: [self publicTorrentLocation] forKey: @"TorrentPath"];189 169 190 170 return history; … … 206 186 [fDownloadFolder release]; 207 187 [fIncompleteFolder release]; 208 209 [fPublicTorrentLocation release];210 188 211 189 [fIcon release]; … … 464 442 } 465 443 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 } 470 457 } 471 458 … … 473 460 { 474 461 tr_torrentDeleteLocalData(fHandle, trashDataFile); 475 }476 477 - (void) trashTorrent478 {479 if (fPublicTorrent)480 {481 [Torrent trashFile: fPublicTorrentLocation];482 [fPublicTorrentLocation release];483 fPublicTorrentLocation = nil;484 485 fPublicTorrent = NO;486 }487 462 } 488 463 … … 879 854 } 880 855 881 - (NSString *) publicTorrentLocation882 {883 return fPublicTorrentLocation;884 }885 886 856 - (NSString *) dataLocation 887 857 { 888 858 return [[self downloadFolder] stringByAppendingPathComponent: [self name]]; 889 }890 891 - (BOOL) publicTorrent892 {893 return fPublicTorrent;894 859 } 895 860 … … 1596 1561 1597 1562 - (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib 1598 publicTorrent: (NSNumber *) publicTorrent publicTorrentLocation: (NSString *) publicTorrentLoc1599 1563 downloadFolder: (NSString *) downloadFolder 1600 1564 useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder … … 1606 1570 1607 1571 fDefaults = [NSUserDefaults standardUserDefaults]; 1608 1609 fPublicTorrent = publicTorrentLoc && (publicTorrent ? [publicTorrent boolValue] : ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);1610 if (fPublicTorrent)1611 fPublicTorrentLocation = [publicTorrentLoc retain];1612 1572 1613 1573 fDownloadFolder = downloadFolder ? downloadFolder : [fDefaults stringForKey: @"DownloadFolder"]; … … 1953 1913 } 1954 1914 1955 + (void) trashFile: (NSString *) path1956 {1957 //attempt to move to trash1958 if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation1959 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 1969 1915 - (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path 1970 1916 {
Note: See TracChangeset
for help on using the changeset viewer.