mirror of
https://github.com/transmission/transmission
synced 2024-12-26 09:37:56 +00:00
add a warning when removing built-in trackers
This commit is contained in:
parent
7620cd9a16
commit
b884651ac3
4 changed files with 70 additions and 17 deletions
|
@ -158,6 +158,8 @@
|
|||
<true/>
|
||||
<key>WarningRemainingSpace</key>
|
||||
<true/>
|
||||
<key>WarningRemoveBuiltInTracker</key>
|
||||
<true/>
|
||||
<key>WarningResetStats</key>
|
||||
<true/>
|
||||
</dict>
|
||||
|
|
|
@ -1448,11 +1448,12 @@ typedef enum
|
|||
[fTrackerTable editColumn: 0 row: i withEvent: nil select: YES];
|
||||
}
|
||||
|
||||
#warning warning when removing built-in
|
||||
- (void) removeTrackers
|
||||
{
|
||||
NSMutableIndexSet * indexes = [[fTrackerTable selectedRowIndexes] mutableCopy];
|
||||
NSMutableIndexSet * indexes = [[[fTrackerTable selectedRowIndexes] mutableCopy] autorelease];
|
||||
|
||||
#warning merge?
|
||||
//if a group is selected, remove all trackers in the group
|
||||
NSUInteger i;
|
||||
for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
||||
{
|
||||
|
@ -1464,10 +1465,72 @@ typedef enum
|
|||
}
|
||||
}
|
||||
|
||||
[fTrackers removeObjectsAtIndexes: indexes];
|
||||
[indexes release];
|
||||
//remove empty groups
|
||||
for (i = 0; i < [fTrackers count]; i++)
|
||||
if (![indexes containsIndex: i] && [[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]])
|
||||
{
|
||||
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;
|
||||
break;
|
||||
}
|
||||
|
||||
if (allSelected)
|
||||
[indexes addIndex: i];
|
||||
i = j;
|
||||
}
|
||||
|
||||
if ([fTrackers count] == [indexes count])
|
||||
{
|
||||
NSBeep();
|
||||
return;
|
||||
}
|
||||
|
||||
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
||||
|
||||
//determine if removing trackers not built-in to the torrent
|
||||
if ([[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?
|
||||
NSAlert * alert = [[NSAlert alloc] init];
|
||||
[alert setMessageText: NSLocalizedString(@"Are you sure you want to remove built-in trackers?",
|
||||
"Remove built-in tracker alert -> title")];
|
||||
[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")];
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"Remove", "Remove built-in tracker alert -> button")];
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Remove built-in tracker alert -> button")];
|
||||
|
||||
BOOL onLeopard = [NSApp isOnLeopardOrBetter];
|
||||
if (onLeopard)
|
||||
[alert setShowsSuppressionButton: YES];
|
||||
else
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"Don't Alert Again", "Remove built-in tracker alert -> button")];
|
||||
|
||||
NSInteger result = [alert runModal];
|
||||
if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertThirdButtonReturn))
|
||||
[[NSUserDefaults standardUserDefaults] setBool: NO forKey: @"WarningRemoveBuiltInTracker"];
|
||||
[alert release];
|
||||
|
||||
if (result != NSAlertFirstButtonReturn)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[fTrackers removeObjectsAtIndexes: indexes];
|
||||
|
||||
if (![torrent updateAllTrackers: fTrackers forAdd: NO])
|
||||
NSBeep();
|
||||
else
|
||||
|
|
|
@ -507,6 +507,7 @@
|
|||
[fDefaults setBool: YES forKey: @"WarningFolderDataSameName"];
|
||||
[fDefaults setBool: YES forKey: @"WarningResetStats"];
|
||||
[fDefaults setBool: YES forKey: @"WarningCreatorBlankAddress"];
|
||||
[fDefaults setBool: YES forKey: @"WarningRemoveBuiltInTracker"];
|
||||
}
|
||||
|
||||
- (void) setCheckForUpdate: (id) sender
|
||||
|
|
|
@ -829,19 +829,6 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
|
|||
}
|
||||
else
|
||||
{
|
||||
//remove empty groups
|
||||
int i;
|
||||
for (i = 0; i < [trackers count]; i++)
|
||||
if ([[trackers objectAtIndex: i] isKindOfClass: [NSNumber class]]
|
||||
&& (i+1 == [trackers count] || [[trackers objectAtIndex: i+1] isKindOfClass: [NSNumber class]]))
|
||||
{
|
||||
[trackers removeObjectAtIndex: i];
|
||||
i--;
|
||||
}
|
||||
|
||||
if ([trackers count] == 0)
|
||||
return NO;
|
||||
|
||||
//check if any user-added groups
|
||||
if ([[trackers objectAtIndex: 0] intValue] != 0)
|
||||
fAddedTrackers = NO;
|
||||
|
|
Loading…
Reference in a new issue