#2794 Don't apply auto-grouping until torrent is demagnetized

This commit is contained in:
Mitchell Livingston 2012-10-30 00:22:10 +00:00
parent 7e2f344ff6
commit 1e0f36fda0
7 changed files with 91 additions and 36 deletions

View File

@ -23,6 +23,7 @@
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#import "Torrent.h"
@class Controller;
@class Torrent;
@ -47,6 +48,7 @@
NSString * fDestination;
NSInteger fGroupValue;
TorrentDeterminationType fGroupDeterminationType;
}
- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path controller: (Controller *) controller;

View File

@ -37,7 +37,7 @@
- (void) confirmAdd;
- (void) setDestinationPath: (NSString *) destination;
- (void) setDestinationPath: (NSString *) destination determinationType: (TorrentDeterminationType) determinationType;
- (void) setGroupsMenu;
- (void) changeGroupValue: (id) sender;
@ -58,6 +58,7 @@
fController = controller;
fGroupValue = [torrent groupValue];
fGroupDeterminationType = TorrentDeterminationAutomatic;
}
return self;
}
@ -88,7 +89,7 @@
[fStartCheck setState: [[NSUserDefaults standardUserDefaults] boolForKey: @"AutoStartDownload"] ? NSOnState : NSOffState];
if (fDestination)
[self setDestinationPath: fDestination];
[self setDestinationPath: fDestination determinationType: TorrentDeterminationAutomatic];
else
{
[fLocationField setStringValue: @""];
@ -189,7 +190,7 @@
[panel beginSheetModalForWindow: [self window] completionHandler: ^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton)
[self setDestinationPath: [[[panel URLs] objectAtIndex: 0] path]];
[self setDestinationPath: [[[panel URLs] objectAtIndex: 0] path] determinationType:TorrentDeterminationUserSpecified];
else
{
if (!fDestination)
@ -251,6 +252,7 @@
if (![fGroupPopUp selectItemWithTag: fGroupValue])
{
fGroupValue = -1;
fGroupDeterminationType = TorrentDeterminationAutomatic;
[fGroupPopUp selectItemWithTag: fGroupValue];
}
}
@ -261,7 +263,7 @@
- (void) confirmAdd
{
[fTorrent setGroupValue: fGroupValue];
[fTorrent setGroupValue: fGroupValue determinationType: fGroupDeterminationType];
if ([fStartCheck state] == NSOnState)
[fTorrent startTransfer];
@ -270,7 +272,7 @@
[fController askOpenMagnetConfirmed: self add: YES]; //ensure last, since it releases this controller
}
- (void) setDestinationPath: (NSString *) destination
- (void) setDestinationPath: (NSString *) destination determinationType: (TorrentDeterminationType) determinationType
{
destination = [destination stringByExpandingTildeInPath];
if (!fDestination || ![fDestination isEqualToString: destination])
@ -278,7 +280,7 @@
[fDestination release];
fDestination = [destination retain];
[fTorrent changeDownloadFolderBeforeUsing: fDestination];
[fTorrent changeDownloadFolderBeforeUsing: fDestination determinationType: determinationType];
}
[fLocationField setStringValue: [fDestination stringByAbbreviatingWithTildeInPath]];
@ -298,12 +300,13 @@
- (void) changeGroupValue: (id) sender
{
NSInteger previousGroup = fGroupValue;
fGroupValue = [sender tag];
fGroupValue = [sender tag];
fGroupDeterminationType = TorrentDeterminationUserSpecified;
if ([[GroupsController groups] usesCustomDownloadLocationForIndex: fGroupValue])
[self setDestinationPath: [[GroupsController groups] customDownloadLocationForIndex: fGroupValue]];
[self setDestinationPath: [[GroupsController groups] customDownloadLocationForIndex: fGroupValue] determinationType: TorrentDeterminationAutomatic];
else if ([fDestination isEqualToString: [[GroupsController groups] customDownloadLocationForIndex: previousGroup]])
[self setDestinationPath: [[NSUserDefaults standardUserDefaults] stringForKey: @"DownloadFolder"]];
[self setDestinationPath: [[NSUserDefaults standardUserDefaults] stringForKey: @"DownloadFolder"] determinationType: TorrentDeterminationAutomatic];
else;
}

View File

@ -23,6 +23,7 @@
*****************************************************************************/
#import <Cocoa/Cocoa.h>
#import "Torrent.h"
@class Controller;
@class FileOutlineController;
@ -52,6 +53,8 @@
NSInteger fGroupValue;
NSTimer * fTimer;
TorrentDeterminationType fGroupValueDetermination;
}
- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path lockDestination: (BOOL) lockDestination

View File

@ -42,7 +42,7 @@
- (void) confirmAdd;
- (void) setDestinationPath: (NSString *) destination;
- (void) setDestinationPath: (NSString *) destination determinationType: (TorrentDeterminationType) determinationType;
- (void) setGroupsMenu;
- (void) changeGroupValue: (id) sender;
@ -71,7 +71,8 @@
fCanToggleDelete = canToggleDelete;
fGroupValue = [torrent groupValue];
fGroupValueDetermination = TorrentDeterminationAutomatic;
[fVerifyIndicator setUsesThreadedAnimation: YES];
}
return self;
@ -126,7 +127,7 @@
[fDeleteCheck setEnabled: fCanToggleDelete];
if (fDestination)
[self setDestinationPath: fDestination];
[self setDestinationPath: fDestination determinationType: (fLockDestination ? TorrentDeterminationUserSpecified : TorrentDeterminationAutomatic)];
else
{
[fLocationField setStringValue: @""];
@ -179,8 +180,8 @@
[panel beginSheetModalForWindow: [self window] completionHandler: ^(NSInteger result) {
if (result == NSFileHandlingPanelOKButton)
{
fLockDestination = NO;
[self setDestinationPath: [[[panel URLs] objectAtIndex: 0] path]];
fLockDestination = YES;
[self setDestinationPath: [[[panel URLs] objectAtIndex: 0] path] determinationType: TorrentDeterminationUserSpecified];
}
else
{
@ -299,6 +300,7 @@
if (![fGroupPopUp selectItemWithTag: fGroupValue])
{
fGroupValue = -1;
fGroupValueDetermination = TorrentDeterminationAutomatic;
[fGroupPopUp selectItemWithTag: fGroupValue];
}
}
@ -335,8 +337,8 @@
[fTimer invalidate];
[fTimer release];
fTimer = nil;
[fTorrent setGroupValue: fGroupValue];
[fTorrent setGroupValue: fGroupValue determinationType: fGroupValueDetermination];
if (fTorrentFile && fCanToggleDelete && [fDeleteCheck state] == NSOnState)
[Torrent trashFile: fTorrentFile];
@ -349,7 +351,7 @@
[fController askOpenConfirmed: self add: YES]; //ensure last, since it releases this controller
}
- (void) setDestinationPath: (NSString *) destination
- (void) setDestinationPath: (NSString *) destination determinationType: (TorrentDeterminationType) determinationType
{
destination = [destination stringByExpandingTildeInPath];
if (!fDestination || ![fDestination isEqualToString: destination])
@ -357,7 +359,7 @@
[fDestination release];
fDestination = [destination retain];
[fTorrent changeDownloadFolderBeforeUsing: fDestination];
[fTorrent changeDownloadFolderBeforeUsing: fDestination determinationType: determinationType];
}
[fLocationField setStringValue: [fDestination stringByAbbreviatingWithTildeInPath]];
@ -378,13 +380,14 @@
{
NSInteger previousGroup = fGroupValue;
fGroupValue = [sender tag];
fGroupValueDetermination = TorrentDeterminationUserSpecified;
if (!fLockDestination)
{
if ([[GroupsController groups] usesCustomDownloadLocationForIndex: fGroupValue])
[self setDestinationPath: [[GroupsController groups] customDownloadLocationForIndex: fGroupValue]];
[self setDestinationPath: [[GroupsController groups] customDownloadLocationForIndex: fGroupValue] determinationType: TorrentDeterminationAutomatic];
else if ([fDestination isEqualToString: [[GroupsController groups] customDownloadLocationForIndex: previousGroup]])
[self setDestinationPath: [[NSUserDefaults standardUserDefaults] stringForKey: @"DownloadFolder"]];
[self setDestinationPath: [[NSUserDefaults standardUserDefaults] stringForKey: @"DownloadFolder"] determinationType: TorrentDeterminationAutomatic];
else;
}
}

View File

@ -532,6 +532,9 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
[nc addObserver: self selector: @selector(torrentFinishedSeeding:)
name: @"TorrentFinishedSeeding" object: nil];
[nc addObserver: self selector: @selector(applyFilter)
name: kTorrentDidChangeGroupNotification object: nil];
//avoids need of setting delegate
[nc addObserver: self selector: @selector(torrentTableViewSelectionDidChange:)
name: NSOutlineViewSelectionDidChangeNotification object: fTableView];
@ -946,7 +949,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
if (!lockDestination && [[GroupsController groups] usesCustomDownloadLocationForIndex: [torrent groupValue]])
{
location = [[GroupsController groups] customDownloadLocationForIndex: [torrent groupValue]];
[torrent changeDownloadFolderBeforeUsing: location];
[torrent changeDownloadFolderBeforeUsing: location determinationType: TorrentDeterminationAutomatic];
}
//verify the data right away if it was newly created
@ -1043,7 +1046,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
if ([[GroupsController groups] usesCustomDownloadLocationForIndex: [torrent groupValue]])
{
location = [[GroupsController groups] customDownloadLocationForIndex: [torrent groupValue]];
[torrent changeDownloadFolderBeforeUsing: location];
[torrent changeDownloadFolderBeforeUsing: location determinationType: TorrentDeterminationAutomatic];
}
if ([fDefaults boolForKey: @"MagnetOpenAsk"] || !location)
@ -2847,7 +2850,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
{
[fTableView removeCollapsedGroup: [torrent groupValue]]; //remove old collapsed group
[torrent setGroupValue: [(NSMenuItem *)sender tag]];
[torrent setGroupValue: [(NSMenuItem *)sender tag] determinationType: TorrentDeterminationUserSpecified];
}
[self applyFilter];
@ -3196,7 +3199,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
//change groups
if (item)
[torrent setGroupValue: [item groupIndex]];
[torrent setGroupValue: [item groupIndex] determinationType: TorrentDeterminationUserSpecified];
}
//reorder queue order
@ -4786,7 +4789,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
if ([[GroupsController groups] usesCustomDownloadLocationForIndex: [torrent groupValue]])
{
location = [[GroupsController groups] customDownloadLocationForIndex: [torrent groupValue]];
[torrent changeDownloadFolderBeforeUsing: location];
[torrent changeDownloadFolderBeforeUsing: location determinationType: TorrentDeterminationAutomatic];
}
[torrent update];

View File

@ -28,6 +28,13 @@
@class FileListNode;
typedef enum {
TorrentDeterminationAutomatic = 0,
TorrentDeterminationUserSpecified
} TorrentDeterminationType;
#define kTorrentDidChangeGroupNotification @"TorrentDidChangeGroup"
@interface Torrent : NSObject <NSCopying, QLPreviewItem>
{
tr_torrent * fHandle;
@ -49,6 +56,9 @@
BOOL fRemoveWhenFinishSeeding;
NSInteger fGroupValue;
TorrentDeterminationType fGroupValueDetermination;
TorrentDeterminationType fDownloadFolderDetermination;
BOOL fResumeOnWake;
@ -65,7 +75,7 @@
- (void) closeRemoveTorrent: (BOOL) trashFiles;
- (void) changeDownloadFolderBeforeUsing: (NSString *) folder;
- (void) changeDownloadFolderBeforeUsing: (NSString *) folder determinationType: (TorrentDeterminationType) determinationType;
- (NSString *) currentDirectory;
@ -206,7 +216,7 @@
- (uint64_t) failedHash;
- (NSInteger) groupValue;
- (void) setGroupValue: (NSInteger) groupValue;
- (void) setGroupValue: (NSInteger) groupValue determinationType: (TorrentDeterminationType) determinationType;;
- (NSInteger) groupOrderValue;
- (void) checkGroupValueForRemoval: (NSNotification *) notification;

View File

@ -242,12 +242,14 @@ int trashDataFile(const char * filename)
tr_torrentRemove(fHandle, trashFiles, trashDataFile);
}
- (void) changeDownloadFolderBeforeUsing: (NSString *) folder
- (void) changeDownloadFolderBeforeUsing: (NSString *) folder determinationType: (TorrentDeterminationType) determinationType
{
//if data existed in original download location, unexclude it before changing the location
[self setTimeMachineExclude: NO];
tr_torrentSetDownloadDir(fHandle, [folder UTF8String]);
fDownloadFolderDetermination = determinationType;
}
- (NSString *) currentDirectory
@ -644,8 +646,7 @@ int trashDataFile(const char * filename)
{
if (stats[i].tier != prevTier)
{
[trackers addObject: [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInteger: stats[i].tier + 1], @"Tier",
[self name], @"Name", nil]];
[trackers addObject: @{ @"Tier" : @(stats[i].tier + 1), @"Name" : [self name] }];
prevTier = stats[i].tier;
}
@ -1311,9 +1312,14 @@ int trashDataFile(const char * filename)
return fGroupValue;
}
- (void) setGroupValue: (NSInteger) goupValue
- (void) setGroupValue: (NSInteger) groupValue determinationType: (TorrentDeterminationType) determinationType;
{
fGroupValue = goupValue;
if (groupValue != fGroupValue)
{
fGroupValue = groupValue;
[[NSNotificationCenter defaultCenter] postNotificationName: kTorrentDidChangeGroupNotification object: self];
}
fGroupValueDetermination = determinationType;
}
- (NSInteger) groupOrderValue
@ -1649,7 +1655,18 @@ int trashDataFile(const char * filename)
if (![self isMagnet])
[self createFileList];
fGroupValue = groupValue ? [groupValue intValue] : [[GroupsController groups] groupIndexForTorrent: self];
fDownloadFolderDetermination = TorrentDeterminationAutomatic;
if (groupValue)
{
fGroupValueDetermination = TorrentDeterminationUserSpecified;
fGroupValue = [groupValue intValue];
}
else
{
fGroupValueDetermination = TorrentDeterminationAutomatic;
fGroupValue = [[GroupsController groups] groupIndexForTorrent: self];
}
fRemoveWhenFinishSeeding = removeWhenFinishSeeding ? [removeWhenFinishSeeding boolValue] : [fDefaults boolForKey: @"RemoveWhenFinishSeeding"];
@ -1844,9 +1861,23 @@ int trashDataFile(const char * filename)
- (void) metadataRetrieved
{
fStat = tr_torrentStat(fHandle);
[self createFileList];
/* If the torrent is in no group, or the group was automatically determined based on criteria evaluated
* before we had metadata for this torrent, redetermine the group
*/
if ((fGroupValueDetermination == TorrentDeterminationAutomatic) || ([self groupValue] == -1))
[self setGroupValue: [[GroupsController groups] groupIndexForTorrent: self] determinationType: TorrentDeterminationAutomatic];
//change the location if the group calls for it and it's either not already set or was set automatically before
if (((fDownloadFolderDetermination == TorrentDeterminationAutomatic) || !tr_torrentGetCurrentDir(fHandle)) &&
[[GroupsController groups] usesCustomDownloadLocationForIndex: [self groupValue]])
{
NSString *location = [[GroupsController groups] customDownloadLocationForIndex: [self groupValue]];
[self changeDownloadFolderBeforeUsing: location determinationType:TorrentDeterminationAutomatic];
}
[[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self];
}