pluralize the "remove tracker" dialogue appropriately; merge more of the remove code

This commit is contained in:
Mitchell Livingston 2008-06-02 19:17:04 +00:00
parent 6d7077522b
commit 2b72de34ab
1 changed files with 46 additions and 39 deletions

View File

@ -1452,15 +1452,21 @@ typedef enum
{ {
NSMutableIndexSet * indexes = [[[fTrackerTable selectedRowIndexes] mutableCopy] autorelease]; NSMutableIndexSet * indexes = [[[fTrackerTable selectedRowIndexes] mutableCopy] autorelease];
//get all rows to remove and determine if any built-in trackers are being remove
NSUInteger i = 0; NSUInteger i = 0, numberBuiltIn = 0;
while (i < [fTrackers count]) while (i < [fTrackers count])
{ {
BOOL builtIn = i != 0 || [[fTrackers objectAtIndex: i] intValue] != 0;
//if a group is selected, remove all trackers in the group //if a group is selected, remove all trackers in the group
if ([indexes containsIndex: i]) if ([indexes containsIndex: i])
{ {
for (i = i+1; i < [fTrackers count] && ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; i++) for (i = i+1; i < [fTrackers count] && ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; i++)
{
[indexes addIndex: i]; [indexes addIndex: i];
if (builtIn)
numberBuiltIn++;
}
} }
//remove empty groups //remove empty groups
else else
@ -1468,19 +1474,18 @@ typedef enum
BOOL allSelected = YES; BOOL allSelected = YES;
NSUInteger j; NSUInteger j;
for (j = i+1; j < [fTrackers count] && ![[fTrackers objectAtIndex: j] isKindOfClass: [NSNumber class]]; j++) for (j = i+1; j < [fTrackers count] && ![[fTrackers objectAtIndex: j] isKindOfClass: [NSNumber class]]; j++)
if (![indexes containsIndex: j])
{ {
if (![indexes containsIndex: j])
allSelected = NO; allSelected = NO;
break; else if (builtIn)
numberBuiltIn++;
else;
} }
if (allSelected) if (allSelected)
[indexes addIndex: i]; [indexes addIndex: i];
i = j;
//get to next group i = j;
while (i < [fTrackers count] && ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]])
i++;
} }
} }
@ -1492,25 +1497,28 @@ typedef enum
Torrent * torrent = [fTorrents objectAtIndex: 0]; Torrent * torrent = [fTorrents objectAtIndex: 0];
//determine if removing trackers not built-in to the torrent //determine if removing trackers built into the torrent
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveBuiltInTracker"]) if (numberBuiltIn > 0 && [[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveBuiltInTracker"])
{
BOOL allBuiltIn = ![torrent hasAddedTrackers];
if (!allBuiltIn)
{
for (i=1; i < [fTrackers count]; i++)
if ([[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]])
break;
}
if (allBuiltIn || [indexes indexGreaterThanOrEqualToIndex: i] != NSNotFound)
{ {
#warning pluralize? #warning pluralize?
NSAlert * alert = [[NSAlert alloc] init]; NSAlert * alert = [[NSAlert alloc] init];
[alert setMessageText: NSLocalizedString(@"Are you sure you want to remove built-in trackers?",
"Remove built-in tracker alert -> title")]; if (numberBuiltIn > 1)
{
[alert setMessageText: [NSString stringWithFormat:
NSLocalizedString(@"Are you sure you want to remove %d built-in trackers?",
"Remove built-in tracker alert -> title"), numberBuiltIn]];
[alert setInformativeText: NSLocalizedString(@"These tracker addresses are part of the torrent file." [alert setInformativeText: NSLocalizedString(@"These tracker addresses are part of the torrent file."
" Once removed, Transmission will no longer attempt to contact them.", "Remove built-in tracker alert -> message")]; " Once removed, Transmission will no longer attempt to contact them.", "Remove built-in tracker alert -> message")];
}
else
{
[alert setMessageText: NSLocalizedString(@"Are you sure you want to remove a built-in tracker?",
"Remove built-in tracker alert -> title")];
[alert setInformativeText: NSLocalizedString(@"The tracker address is part of the torrent file."
" Once removed, Transmission will no longer attempt to contact it.", "Remove built-in tracker alert -> message")];
}
[alert addButtonWithTitle: NSLocalizedString(@"Remove", "Remove built-in tracker alert -> button")]; [alert addButtonWithTitle: NSLocalizedString(@"Remove", "Remove built-in tracker alert -> button")];
[alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Remove built-in tracker alert -> button")]; [alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Remove built-in tracker alert -> button")];
@ -1528,7 +1536,6 @@ typedef enum
if (result != NSAlertFirstButtonReturn) if (result != NSAlertFirstButtonReturn)
return; return;
} }
}
[fTrackers removeObjectsAtIndexes: indexes]; [fTrackers removeObjectsAtIndexes: indexes];