From b884651ac3798e9838818fc60961749e63e2c2f0 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Mon, 2 Jun 2008 18:34:58 +0000 Subject: [PATCH] add a warning when removing built-in trackers --- macosx/Defaults.plist | 2 + macosx/InfoWindowController.m | 71 +++++++++++++++++++++++++++++++++-- macosx/PrefsController.m | 1 + macosx/Torrent.m | 13 ------- 4 files changed, 70 insertions(+), 17 deletions(-) diff --git a/macosx/Defaults.plist b/macosx/Defaults.plist index 4992be741..2a67c7995 100644 --- a/macosx/Defaults.plist +++ b/macosx/Defaults.plist @@ -158,6 +158,8 @@ WarningRemainingSpace + WarningRemoveBuiltInTracker + WarningResetStats diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index d96e2bea5..a1023c8af 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -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 diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 16c5b1baa..ea5f504ae 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -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 diff --git a/macosx/Torrent.m b/macosx/Torrent.m index eb245ed3b..52173ad37 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -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;