From aed40c4318449e0f6a848e7ab444a62ecb60d5d5 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 28 May 2008 23:57:25 +0000 Subject: [PATCH] allow creation of torrents with no announce address --- Transmission.xcodeproj/project.pbxproj | 2 +- macosx/Controller.m | 1 + macosx/CreatorWindowController.h | 6 +- macosx/CreatorWindowController.m | 179 ++++++++++++++----------- macosx/Defaults.plist | 2 + macosx/English.lproj/Creator.xib | 30 ++--- macosx/PrefsController.m | 1 + 7 files changed, 118 insertions(+), 103 deletions(-) diff --git a/Transmission.xcodeproj/project.pbxproj b/Transmission.xcodeproj/project.pbxproj index 768f72d60..273cbcfef 100644 --- a/Transmission.xcodeproj/project.pbxproj +++ b/Transmission.xcodeproj/project.pbxproj @@ -454,7 +454,7 @@ 4DE5CCA80980739100BE280E /* Badge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Badge.png; path = macosx/Images/Badge.png; sourceTree = ""; }; 4DE5CCB80981D27700BE280E /* ResumeAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeAll.png; path = macosx/Images/ResumeAll.png; sourceTree = ""; }; 4DE5CCB90981D27700BE280E /* PauseAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PauseAll.png; path = macosx/Images/PauseAll.png; sourceTree = ""; }; - 4DE5CCCA0981D9BE00BE280E /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; name = Defaults.plist; path = macosx/Defaults.plist; sourceTree = ""; }; + 4DE5CCCA0981D9BE00BE280E /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.xml; name = Defaults.plist; path = macosx/Defaults.plist; sourceTree = ""; }; 4DF0C5A90899190500DD8943 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = Controller.m; path = macosx/Controller.m; sourceTree = ""; }; 4DF0C5AA0899190500DD8943 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Controller.h; path = macosx/Controller.h; sourceTree = ""; }; 4DF7500708A103AD007B0D70 /* Open.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Open.png; path = macosx/Images/Open.png; sourceTree = ""; }; diff --git a/macosx/Controller.m b/macosx/Controller.m index 02c79c51d..4953db71c 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -1206,6 +1206,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy enumerator = [torrents objectEnumerator]; while ((torrent = [enumerator nextObject])) { + #warning redo, since now can be removed through rpc //expand the group, since either the whole group is being removed, it is already expanded, or not showing groups [fTableView removeCollapsedGroup: [torrent groupValue]]; diff --git a/macosx/CreatorWindowController.h b/macosx/CreatorWindowController.h index e617c9171..cead20782 100644 --- a/macosx/CreatorWindowController.h +++ b/macosx/CreatorWindowController.h @@ -31,13 +31,13 @@ IBOutlet NSImageView * fIconView; IBOutlet NSTextField * fNameField, * fStatusField, * fPiecesField, * fTrackerField, * fLocationField; IBOutlet NSTextView * fCommentView; - IBOutlet NSButton *fCreateButton, * fPrivateCheck, * fOpenCheck; + IBOutlet NSButton * fPrivateCheck, * fOpenCheck; IBOutlet NSView * fProgressView; IBOutlet NSProgressIndicator * fProgressIndicator; tr_metainfo_builder * fInfo; - NSString * fPath, * fLocation; + NSString * fPath, * fLocation, * fTracker; BOOL fOpenTorrent; NSTimer * fTimer; @@ -51,6 +51,8 @@ - (id) initWithHandle: (tr_handle *) handle path: (NSString *) path; +- (void) toggleOpenCheck: (id) sender; + - (void) setLocation: (id) sender; - (void) create: (id) sender; - (void) cancelCreateWindow: (id) sender; diff --git a/macosx/CreatorWindowController.m b/macosx/CreatorWindowController.m index b621fe8fa..5ce10bfcb 100644 --- a/macosx/CreatorWindowController.m +++ b/macosx/CreatorWindowController.m @@ -29,8 +29,10 @@ @interface CreatorWindowController (Private) + (NSString *) chooseFile; -- (void) updateEnableCreateButtonForTrackerField; +- (void) updateEnableOpenCheckForTrackerField; - (void) locationSheetClosed: (NSSavePanel *) openPanel returnCode: (int) code contextInfo: (void *) info; + +- (void) createReal; - (void) checkProgress; - (void) failureSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info; @@ -150,13 +152,12 @@ NSString * tracker; if ((tracker = [fDefaults stringForKey: @"CreatorTracker"])) [fTrackerField setStringValue: tracker]; - [self updateEnableCreateButtonForTrackerField]; if ([fDefaults objectForKey: @"CreatorPrivate"]) [fPrivateCheck setState: [fDefaults boolForKey: @"CreatorPrivate"] ? NSOnState : NSOffState]; - if ([fDefaults objectForKey: @"CreatorOpen"]) - [fOpenCheck setState: [fDefaults boolForKey: @"CreatorOpen"] ? NSOnState : NSOffState]; + fOpenTorrent = [fDefaults boolForKey: @"CreatorOpen"]; + [self updateEnableOpenCheckForTrackerField]; } - (void) dealloc @@ -164,6 +165,8 @@ [fPath release]; [fLocation release]; + [fTracker release]; + if (fInfo) tr_metaInfoBuilderFree(fInfo); @@ -173,6 +176,17 @@ [super dealloc]; } +- (void) toggleOpenCheck: (id) sender +{ + fOpenTorrent = [fOpenCheck state] == NSOnState; +} + +- (void) controlTextDidChange: (NSNotification *) notification +{ + if ([notification object] == fTrackerField) + [self updateEnableOpenCheckForTrackerField]; +} + - (void) setLocation: (id) sender { NSSavePanel * panel = [NSSavePanel savePanel]; @@ -189,74 +203,13 @@ contextInfo: nil]; } -- (void) controlTextDidChange: (NSNotification *) notification -{ - if ([notification object] == fTrackerField) - [self updateEnableCreateButtonForTrackerField]; -} - - (void) create: (id) sender { - NSString * trackerString = [fTrackerField stringValue]; - if ([trackerString rangeOfString: @"://"].location == NSNotFound) - trackerString = [@"http://" stringByAppendingString: trackerString]; - - //parse tracker string - if (!tr_httpIsValidURL([trackerString UTF8String])) + /*if ([[fTrackerField stringValue] isEqualToString: @""] && [fDefaults boolForKey: @"WarningCreatorBlankAddress"]) { - NSAlert * alert = [[[NSAlert alloc] init] autorelease]; - [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> warning -> button")]; - [alert setInformativeText: NSLocalizedString(@"Change the tracker address to create the torrent file.", - "Create torrent -> warning -> info")]; - [alert setAlertStyle: NSWarningAlertStyle]; - - //check common reasons for failure - NSString * prefix = [trackerString substringToIndex: [trackerString rangeOfString: @"://"].location]; - if ([prefix caseInsensitiveCompare: @"http"] != NSOrderedSame && [prefix caseInsensitiveCompare: @"https"] != NSOrderedSame) - [alert setMessageText: NSLocalizedString(@"The tracker address must begin with \"http://\" or \"https://\".", - "Create torrent -> warning -> message")]; - else - [alert setMessageText: NSLocalizedString(@"The tracker address is invalid.", "Create torrent -> warning -> message")]; - - [alert beginSheetModalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil]; - return; } - - //check if a file with the same name and location already exists - if ([[NSFileManager defaultManager] fileExistsAtPath: fLocation]) - { - NSArray * pathComponents = [fLocation pathComponents]; - int count = [pathComponents count]; - - NSAlert * alert = [[[NSAlert alloc] init] autorelease]; - [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> file already exists warning -> button")]; - [alert setMessageText: NSLocalizedString(@"A torrent file with this name and directory cannot be created.", - "Create torrent -> file already exists warning -> title")]; - [alert setInformativeText: [NSString stringWithFormat: - NSLocalizedString(@"A file with the name \"%@\" already exists in the directory \"%@\". " - "Choose a new name or directory to create the torrent file.", - "Create torrent -> file already exists warning -> warning"), - [pathComponents objectAtIndex: count-1], [pathComponents objectAtIndex: count-2]]]; - [alert setAlertStyle: NSWarningAlertStyle]; - - [alert beginSheetModalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil]; - return; - } - - fOpenTorrent = [fOpenCheck state] == NSOnState; - - //store values - [fDefaults setObject: trackerString forKey: @"CreatorTracker"]; - [fDefaults setBool: [fPrivateCheck state] == NSOnState forKey: @"CreatorPrivate"]; - [fDefaults setBool: fOpenTorrent forKey: @"CreatorOpen"]; - [fDefaults setObject: [fLocation stringByDeletingLastPathComponent] forKey: @"CreatorLocation"]; - - [[NSNotificationCenter defaultCenter] postNotificationName: @"BeginCreateTorrentFile" object: fLocation userInfo: nil]; - tr_makeMetaInfo(fInfo, [fLocation UTF8String], [trackerString UTF8String], [[fCommentView string] UTF8String], - [fPrivateCheck state] == NSOnState); - - fTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(checkProgress) - userInfo: nil repeats: YES]; + else*/ + [self createReal]; } - (void) cancelCreateWindow: (id) sender @@ -296,20 +249,11 @@ return success ? [[panel filenames] objectAtIndex: 0] : nil; } -- (void) updateEnableCreateButtonForTrackerField +- (void) updateEnableOpenCheckForTrackerField { - NSString * string = [fTrackerField stringValue]; - BOOL enable = YES; - if ([string isEqualToString: @""]) - enable = NO; - else - { - NSRange prefixRange = [string rangeOfString: @"://"]; - if (prefixRange.location != NSNotFound && [string length] == NSMaxRange(prefixRange)) - enable = NO; - } - - [fCreateButton setEnabled: enable]; + BOOL hasTracker = ![[fTrackerField stringValue] isEqualToString: @""]; + [fOpenCheck setEnabled: hasTracker]; + [fOpenCheck setState: (fOpenTorrent && hasTracker) ? NSOnState : NSOffState]; } - (void) locationSheetClosed: (NSSavePanel *) panel returnCode: (int) code contextInfo: (void *) info @@ -324,6 +268,77 @@ } } +- (void) createReal +{ + [fTracker release]; //incase a previous create was aborted + fTracker = [[fTrackerField stringValue] retain]; + + //parse non-empty tracker strings + if (![fTracker isEqualToString: @""]) + { + if ([fTracker rangeOfString: @"://"].location == NSNotFound) + { + NSString * fullTracker = [@"http://" stringByAppendingString: fTracker]; + [fTracker release]; + fTracker = [fullTracker retain]; + } + + if (!tr_httpIsValidURL([fTracker UTF8String])) + { + NSAlert * alert = [[[NSAlert alloc] init] autorelease]; + [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> warning -> button")]; + [alert setInformativeText: NSLocalizedString(@"Change the tracker address to create the torrent file.", + "Create torrent -> warning -> info")]; + [alert setAlertStyle: NSWarningAlertStyle]; + + //check common reasons for failure + NSString * prefix = [fTracker substringToIndex: [fTracker rangeOfString: @"://"].location]; + if ([prefix caseInsensitiveCompare: @"http"] != NSOrderedSame && [prefix caseInsensitiveCompare: @"https"] != NSOrderedSame) + [alert setMessageText: NSLocalizedString(@"The tracker address must begin with \"http://\" or \"https://\".", + "Create torrent -> warning -> message")]; + else + [alert setMessageText: NSLocalizedString(@"The tracker address is invalid.", "Create torrent -> warning -> message")]; + + [alert beginSheetModalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil]; + return; + } + } + + //check if a file with the same name and location already exists + if ([[NSFileManager defaultManager] fileExistsAtPath: fLocation]) + { + NSArray * pathComponents = [fLocation pathComponents]; + int count = [pathComponents count]; + + NSAlert * alert = [[[NSAlert alloc] init] autorelease]; + [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> file already exists warning -> button")]; + [alert setMessageText: NSLocalizedString(@"A torrent file with this name and directory cannot be created.", + "Create torrent -> file already exists warning -> title")]; + [alert setInformativeText: [NSString stringWithFormat: + NSLocalizedString(@"A file with the name \"%@\" already exists in the directory \"%@\". " + "Choose a new name or directory to create the torrent file.", + "Create torrent -> file already exists warning -> warning"), + [pathComponents objectAtIndex: count-1], [pathComponents objectAtIndex: count-2]]]; + [alert setAlertStyle: NSWarningAlertStyle]; + + [alert beginSheetModalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil]; + return; + } + + //store values + [fDefaults setObject: fTracker forKey: @"CreatorTracker"]; + [fDefaults setBool: [fPrivateCheck state] == NSOnState forKey: @"CreatorPrivate"]; + [fDefaults setBool: fOpenTorrent forKey: @"CreatorOpen"]; + [fDefaults setObject: [fLocation stringByDeletingLastPathComponent] forKey: @"CreatorLocation"]; + + [[NSNotificationCenter defaultCenter] postNotificationName: @"BeginCreateTorrentFile" object: fLocation userInfo: nil]; + tr_makeMetaInfo(fInfo, [fLocation UTF8String], [fTracker UTF8String], [[fCommentView string] UTF8String], + [fPrivateCheck state] == NSOnState); + + fTimer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @selector(checkProgress) + userInfo: nil repeats: YES]; +} + - (void) checkProgress { if (fInfo->isDone) @@ -335,7 +350,7 @@ switch (fInfo->result) { case TR_MAKEMETA_OK: - if (fOpenTorrent) + if (fOpenTorrent && ![fTracker isEqualToString: @""]) { NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: fLocation, @"File", [fPath stringByDeletingLastPathComponent], @"Path", nil]; diff --git a/macosx/Defaults.plist b/macosx/Defaults.plist index 82b90eeb4..4992be741 100644 --- a/macosx/Defaults.plist +++ b/macosx/Defaults.plist @@ -152,6 +152,8 @@ WarningDuplicate + WarningCreatorBlankAddress + WarningFolderDataSameName WarningRemainingSpace diff --git a/macosx/English.lproj/Creator.xib b/macosx/English.lproj/Creator.xib index 3ddbaf059..5a9d2a8ea 100644 --- a/macosx/English.lproj/Creator.xib +++ b/macosx/English.lproj/Creator.xib @@ -2,9 +2,9 @@ 1050 - 9C7010 - 652 - 949.26 + 9D34 + 667 + 949.33 352.00 YES @@ -492,7 +492,7 @@ YES - 604110336 + 67239424 134217728 Create @@ -782,12 +782,12 @@ 86 - - fCreateButton + + toggleOpenCheck: - + - 87 + 88 @@ -1308,7 +1308,7 @@ - 87 + 88 @@ -1324,6 +1324,7 @@ cancelCreateWindow: create: setLocation: + toggleOpenCheck: YES @@ -1331,6 +1332,7 @@ id id id + id @@ -1338,7 +1340,6 @@ YES fCommentView - fCreateButton fIconView fLocationField fNameField @@ -1353,7 +1354,6 @@ YES NSTextView - NSButton NSImageView NSTextField NSTextField @@ -1381,6 +1381,7 @@ FirstResponder + NSObject IBUserSource @@ -1400,13 +1401,6 @@ macosx/NSMenuAdditions.h - - NSObject - - IBProjectSource - macosx/IPCController.h - - NSObject diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index ff0a3e800..16c5b1baa 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -506,6 +506,7 @@ [fDefaults setBool: YES forKey: @"WarningRemainingSpace"]; [fDefaults setBool: YES forKey: @"WarningFolderDataSameName"]; [fDefaults setBool: YES forKey: @"WarningResetStats"]; + [fDefaults setBool: YES forKey: @"WarningCreatorBlankAddress"]; } - (void) setCheckForUpdate: (id) sender