when using the add dialog, delete the torrent file (if set in preferences)

This commit is contained in:
Mitchell Livingston 2008-01-04 06:31:41 +00:00
parent ce18bc26ae
commit 1647bd629a
4 changed files with 29 additions and 12 deletions

View File

@ -23,9 +23,9 @@
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#import "Torrent.h"
@class Controller;
@class Torrent;
@interface AddWindowController : NSWindowController
{
@ -37,15 +37,15 @@
Torrent * fTorrent;
NSString * fDestination;
BOOL fDeleteTorrent;
}
- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path controller: (Controller *) controller;
- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path controller: (Controller *) controller
deleteTorrent: (torrentFileState) deleteTorrent;
- (void) setDestination: (id) sender;
- (void) add: (id) sender;
- (void) cancelAdd: (id) sender;

View File

@ -24,7 +24,6 @@
#import "AddWindowController.h"
#import "Controller.h"
#import "Torrent.h"
#import "NSStringAdditions.h"
#import "ExpandedPathToIconTransformer.h"
@ -36,7 +35,10 @@
@implementation AddWindowController
#warning add check to delete torrent file
- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path controller: (Controller *) controller
deleteTorrent: (torrentFileState) deleteTorrent
{
if ((self = [super initWithWindowNibName: @"AddWindow"]))
{
@ -45,6 +47,9 @@
fDestination = [[path stringByExpandingTildeInPath] retain];
fController = controller;
fDeleteTorrent = deleteTorrent == TORRENT_FILE_DELETE || (deleteTorrent == TORRENT_FILE_DEFAULT
&& [[NSUserDefaults standardUserDefaults] boolForKey: @"DeleteOriginalTorrent"]);
}
return self;
}
@ -121,7 +126,8 @@
[fController askOpenConfirmed: fTorrent];
#warning remove torrent file if necessary
if (fDeleteTorrent)
[fTorrent trashTorrent];
[self release];
}

View File

@ -745,6 +745,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
NSString * torrentPath;
tr_info info;
NSEnumerator * enumerator = [filenames objectEnumerator];
BOOL showWindow = [fDefaults boolForKey: @"DownloadAsk"];
while ((torrentPath = [enumerator nextObject]))
{
NSString * location;
@ -768,14 +769,19 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
tr_metainfoFree(&info);
tr_ctorFree(ctor);
if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location deleteTorrentFile: deleteTorrent lib: fLib]))
if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location
deleteTorrentFile: showWindow ? TORRENT_FILE_SAVE : deleteTorrent lib: fLib]))
continue;
//add it to the "File -> Open Recent" menu
[[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
if ([fDefaults boolForKey: @"DownloadAsk"])
[[[AddWindowController alloc] initWithTorrent: torrent destination: location controller: self] showWindow: self];
if (showWindow)
{
AddWindowController * addController = [[AddWindowController alloc] initWithTorrent: torrent destination: location
controller: self deleteTorrent: deleteTorrent];
[addController showWindow: self];
}
else
{
[torrent setWaitToStart: [fDefaults boolForKey: @"AutoStartDownload"]];

View File

@ -65,7 +65,6 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
@implementation Torrent
#warning add init for add dialog
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
lib: (tr_handle *) lib
@ -438,7 +437,13 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
- (void) trashTorrent
{
if (fPublicTorrent)
[self trashFile: [self publicTorrentLocation]];
{
[self trashFile: fPublicTorrentLocation];
[fPublicTorrentLocation release];
fPublicTorrentLocation = nil;
fPublicTorrent = NO;
}
}
- (void) moveTorrentDataFileTo: (NSString *) folder