prepare for re-adding "remove tracker" functionality

This commit is contained in:
Mitchell Livingston 2009-09-29 03:53:57 +00:00
parent edefc9a10a
commit 15f1f18e56
3 changed files with 32 additions and 70 deletions

View File

@ -1692,42 +1692,24 @@ typedef enum
- (void) removeTrackers
{
NSMutableIndexSet * indexes = [[[fTrackerTable selectedRowIndexes] mutableCopy] autorelease];
const NSInteger oldCount = [fTrackers count] - [(TrackerNode *)[fTrackers lastObject] tier];
NSMutableArray * addresses = [NSMutableArray arrayWithCapacity: oldCount];
//get all rows to remove
NSUInteger i = 0, trackerCount = 0;
while (i < [fTrackers count])
NSIndexSet * indexes = [fTrackerTable selectedRowIndexes];
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
{
//if a group is selected, remove all trackers in the group
if ([indexes containsIndex: i])
id item = [fTrackers objectAtIndex: i];
if ([item isKindOfClass: [NSNumber class]])
{
for (i = i+1; i < [fTrackers count] && ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; i++)
{
[indexes addIndex: i];
trackerCount++;
}
for (NSInteger j = i+1; j < [fTrackers count] && ![[fTrackers objectAtIndex: j] isKindOfClass: [NSNumber class]]; ++j, ++i)
[addresses addObject: [fTrackers objectAtIndex: j]];
--i;
}
//remove empty groups
else
{
BOOL allSelected = YES;
NSUInteger j;
for (j = i+1; j < [fTrackers count] && ![[fTrackers objectAtIndex: j] isKindOfClass: [NSNumber class]]; j++)
{
if (![indexes containsIndex: j])
allSelected = NO;
else
trackerCount++;
}
if (allSelected)
[indexes addIndex: i];
i = j;
}
[addresses addObject: [(TrackerNode *)item fullAnnounceAddress]];
}
if ([fTrackers count] == [indexes count])
if (oldCount == [addresses count])
{
NSBeep();
return;
@ -1737,10 +1719,10 @@ typedef enum
{
NSAlert * alert = [[NSAlert alloc] init];
if (trackerCount > 1)
if ([addresses count] > 1)
{
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?",
"Remove trackers alert -> title"), trackerCount]];
"Remove trackers alert -> title"), [addresses count]]];
[alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them."
" This cannot be undone.", "Remove trackers alert -> message")];
}
@ -1765,12 +1747,8 @@ typedef enum
return;
}
[fTrackers removeObjectsAtIndexes: indexes];
#warning fix!
Torrent * torrent = [fTorrents objectAtIndex: 0];
[torrent updateAllTrackersForRemove: fTrackers];
[fTrackerTable deselectAll: self];
[torrent removeTrackersWithAnnounceAddresses: addresses];
//reset table with either new or old value
[fTrackers release];
@ -1778,6 +1756,7 @@ typedef enum
[fTrackerTable setTrackers: fTrackers];
[fTrackerTable reloadData];
[fTrackerTable deselectAll: self];
}
@end

View File

@ -135,7 +135,7 @@
- (NSMutableArray *) allTrackerStats;
- (NSMutableArray *) allTrackersFlat; //used by GroupRules
- (BOOL) addTrackerToNewTier: (NSString *) tracker;
- (void) updateAllTrackersForRemove: (NSMutableArray *) trackers;
- (void) removeTrackersWithAnnounceAddresses: (NSArray *) trackers;
- (NSString *) comment;
- (NSString *) creator;

View File

@ -53,8 +53,6 @@
- (NSString *) etaString;
- (void) updateAllTrackers: (NSMutableArray *) trackers;
- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path;
@end
@ -732,10 +730,23 @@ int trashDataFile(const char * filename)
return YES;
}
#warning this doesn't work
- (void) updateAllTrackersForRemove: (NSMutableArray *) trackers
- (void) removeTrackersWithAnnounceAddresses: (NSArray *) trackers
{
[self updateAllTrackers: trackers];
//recreate the tracker structure
const int oldTrackerCount = fInfo->trackerCount;
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, oldTrackerCount-1);
NSInteger newCount = 0;
for (NSInteger oldIndex = 0; oldIndex < oldTrackerCount; ++newCount, ++oldIndex)
{
if (![trackers containsObject: [NSString stringWithUTF8String: fInfo->trackers[oldIndex].announce]])
trackerStructs[newCount] = fInfo->trackers[oldIndex];
else
--newCount;
}
tr_torrentSetAnnounceList(fHandle, trackerStructs, newCount);
tr_free(trackerStructs);
}
- (NSString *) comment
@ -1806,34 +1817,6 @@ int trashDataFile(const char * filename)
}
}
#warning needs to be removed
- (void) updateAllTrackers: (NSMutableArray *) trackers
{
//get count
NSInteger count = 0;
for (id object in trackers)
if (![object isKindOfClass: [NSNumber class]])
count++;
//recreate the tracker structure
tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, count);
NSInteger tier = 0, i = 0;
for (id object in trackers)
{
if (![object isKindOfClass: [NSNumber class]])
{
trackerStructs[i].tier = tier;
trackerStructs[i].announce = (char *)[object UTF8String];
i++;
}
else
tier++;
}
tr_torrentSetAnnounceList(fHandle, trackerStructs, count);
tr_free(trackerStructs);
}
- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path
{
CSBackupSetItemExcluded((CFURLRef)[NSURL fileURLWithPath: path], exclude, true);