#5286 Files renamed in Mac Inspector are not re-sorted

This commit is contained in:
Mitchell Livingston
2013-02-11 01:39:44 +00:00
parent 88f49eb55d
commit 196bbafadb
2 changed files with 52 additions and 32 deletions

View File

@@ -140,6 +140,7 @@
{ {
Torrent * torrent = [fTorrents objectAtIndex: 0]; Torrent * torrent = [fTorrents objectAtIndex: 0];
#warning candidate for localizedStringWithFormat (although then we'll get two commas)
NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%ld, %@", [torrent pieceCount], NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%ld, %@", [torrent pieceCount],
[NSString stringForFileSize: [torrent pieceSize]]] : @""; [NSString stringForFileSize: [torrent pieceSize]]] : @"";
[fPiecesField setStringValue: piecesString]; [fPiecesField setStringValue: piecesString];

View File

@@ -53,6 +53,7 @@
- (void) ratioLimitHit; - (void) ratioLimitHit;
- (void) idleLimitHit; - (void) idleLimitHit;
- (void) metadataRetrieved; - (void) metadataRetrieved;
- (void)renameFinished: (BOOL) success withNodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName;
- (BOOL) shouldShowEta; - (BOOL) shouldShowEta;
- (NSString *) etaString; - (NSString *) etaString;
@@ -95,38 +96,12 @@ void renameCallback(tr_torrent * torrent, const char * oldPathCharString, const
{ {
@autoreleasepool @autoreleasepool
{ {
NSDictionary * contextDict = (NSDictionary *)contextInfo;
NSString * oldPath = [NSString stringWithUTF8String: oldPathCharString]; NSString * oldPath = [NSString stringWithUTF8String: oldPathCharString];
NSString * path = [oldPath stringByDeletingLastPathComponent];
NSString * newName = [NSString stringWithUTF8String: newNameCharString]; NSString * newName = [NSString stringWithUTF8String: newNameCharString];
if (error == 0) NSDictionary * contextDict = [(NSDictionary *)contextInfo autorelease];
{ Torrent * torrentObject = [contextDict objectForKey: @"Torrent"];
NSString * oldName = [oldPath lastPathComponent]; [torrentObject renameFinished: error == 0 withNodes: [contextDict objectForKey: @"Nodes"] completionHandler: [contextDict objectForKey: @"CompletionHandler"] oldPath: oldPath newName: newName];
void (^__block updateNodeAndChildrenForRename)(FileListNode *) = ^(FileListNode * node) {
[node updateFromOldName: oldName toNewName: newName inPath: path];
if ([node isFolder]) {
[[node children] enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * childNode, NSUInteger idx, BOOL * stop) {
updateNodeAndChildrenForRename(childNode);
}];
}
};
NSArray * nodes = [contextDict objectForKey: @"Nodes"];
[nodes enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * node, NSUInteger idx, BOOL *stop) {
updateNodeAndChildrenForRename(node);
}];
}
else
NSLog(@"Error renaming %@ to %@", oldPath, [path stringByAppendingPathComponent: newName]);
typedef void (^RenameCompletionBlock)(BOOL);
RenameCompletionBlock completionHandler = [contextDict objectForKey: @"CompletionHandler"];
completionHandler(error == 0);
[contextDict release];
} }
} }
@@ -848,7 +823,7 @@ int trashDataFile(const char * filename)
NSParameterAssert(newName != nil); NSParameterAssert(newName != nil);
NSParameterAssert(![newName isEqualToString: @""]); NSParameterAssert(![newName isEqualToString: @""]);
NSDictionary * contextInfo = [@{ @"Nodes" : fFileList, @"CompletionHandler" : [[completionHandler copy] autorelease] } retain]; NSDictionary * contextInfo = [@{ @"Torrent" : self, @"CompletionHandler" : [[completionHandler copy] autorelease] } retain];
tr_torrentRenamePath(fHandle, fInfo->name, [newName UTF8String], renameCallback, contextInfo); tr_torrentRenamePath(fHandle, fInfo->name, [newName UTF8String], renameCallback, contextInfo);
} }
@@ -859,7 +834,7 @@ int trashDataFile(const char * filename)
NSParameterAssert(newName != nil); NSParameterAssert(newName != nil);
NSParameterAssert(![newName isEqualToString: @""]); NSParameterAssert(![newName isEqualToString: @""]);
NSDictionary * contextInfo = [@{ @"Nodes" : @[ node ], @"CompletionHandler" : [[completionHandler copy] autorelease] } retain]; NSDictionary * contextInfo = [@{ @"Torrent" : self, @"Nodes" : @[ node ], @"CompletionHandler" : [[completionHandler copy] autorelease] } retain];
NSString * oldPath = [[node path] stringByAppendingPathComponent: [node name]]; NSString * oldPath = [[node path] stringByAppendingPathComponent: [node name]];
tr_torrentRenamePath(fHandle, [oldPath UTF8String], [newName UTF8String], renameCallback, contextInfo); tr_torrentRenamePath(fHandle, [oldPath UTF8String], [newName UTF8String], renameCallback, contextInfo);
@@ -1748,7 +1723,7 @@ int trashDataFile(const char * filename)
if ([self isFolder]) if ([self isFolder])
{ {
const NSInteger count = [self fileCount]; const NSInteger count = [self fileCount];
NSMutableArray * fileList = [NSMutableArray arrayWithCapacity: count], NSMutableArray * fileList = [NSMutableArray array],
* flatFileList = [NSMutableArray arrayWithCapacity: count]; * flatFileList = [NSMutableArray arrayWithCapacity: count];
for (NSInteger i = 0; i < count; i++) for (NSInteger i = 0; i < count; i++)
@@ -1943,6 +1918,50 @@ int trashDataFile(const char * filename)
[[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self userInfo: @{ @"Torrent" : self }]; [[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self userInfo: @{ @"Torrent" : self }];
} }
- (void)renameFinished: (BOOL) success withNodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName
{
NSParameterAssert(completionHandler != nil);
NSParameterAssert(oldPath != nil);
NSParameterAssert(newName != nil);
NSString * path = [oldPath stringByDeletingLastPathComponent];
if (success)
{
NSString * oldName = [oldPath lastPathComponent];
void (^__block updateNodeAndChildrenForRename)(FileListNode *) = ^(FileListNode * node) {
[node updateFromOldName: oldName toNewName: newName inPath: path];
if ([node isFolder]) {
[[node children] enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * childNode, NSUInteger idx, BOOL * stop) {
updateNodeAndChildrenForRename(childNode);
}];
}
};
if (!nodes)
nodes = fFlatFileList;
[nodes enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * node, NSUInteger idx, BOOL *stop) {
updateNodeAndChildrenForRename(node);
}];
//resort lists
NSMutableArray * fileList = [fFileList mutableCopy];
[fFileList release];
[self sortFileList: fileList];
fFileList = fileList;
NSMutableArray * flatFileList = [fFlatFileList mutableCopy];
[fFlatFileList release];
[self sortFileList: flatFileList];
fFlatFileList = flatFileList;
}
else
NSLog(@"Error renaming %@ to %@", oldPath, [path stringByAppendingPathComponent: newName]);
completionHandler(success);
}
- (BOOL) shouldShowEta - (BOOL) shouldShowEta
{ {
if (fStat->activity == TR_STATUS_DOWNLOAD) if (fStat->activity == TR_STATUS_DOWNLOAD)