1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 16:52:39 +00:00

allow creation of torrents with no announce address

This commit is contained in:
Mitchell Livingston 2008-05-28 23:57:25 +00:00
parent e02449e421
commit aed40c4318
7 changed files with 118 additions and 103 deletions

View file

@ -454,7 +454,7 @@
4DE5CCA80980739100BE280E /* Badge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Badge.png; path = macosx/Images/Badge.png; sourceTree = "<group>"; };
4DE5CCB80981D27700BE280E /* ResumeAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ResumeAll.png; path = macosx/Images/ResumeAll.png; sourceTree = "<group>"; };
4DE5CCB90981D27700BE280E /* PauseAll.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = PauseAll.png; path = macosx/Images/PauseAll.png; sourceTree = "<group>"; };
4DE5CCCA0981D9BE00BE280E /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.xml; name = Defaults.plist; path = macosx/Defaults.plist; sourceTree = "<group>"; };
4DE5CCCA0981D9BE00BE280E /* Defaults.plist */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.plist.xml; name = Defaults.plist; path = macosx/Defaults.plist; sourceTree = "<group>"; };
4DF0C5A90899190500DD8943 /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = Controller.m; path = macosx/Controller.m; sourceTree = "<group>"; };
4DF0C5AA0899190500DD8943 /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Controller.h; path = macosx/Controller.h; sourceTree = "<group>"; };
4DF7500708A103AD007B0D70 /* Open.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Open.png; path = macosx/Images/Open.png; sourceTree = "<group>"; };

View file

@ -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]];

View file

@ -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;

View file

@ -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];

View file

@ -152,6 +152,8 @@
<false/>
<key>WarningDuplicate</key>
<true/>
<key>WarningCreatorBlankAddress</key>
<true/>
<key>WarningFolderDataSameName</key>
<true/>
<key>WarningRemainingSpace</key>

View file

@ -2,9 +2,9 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.02">
<data>
<int key="IBDocument.SystemTarget">1050</int>
<string key="IBDocument.SystemVersion">9C7010</string>
<string key="IBDocument.InterfaceBuilderVersion">652</string>
<string key="IBDocument.AppKitVersion">949.26</string>
<string key="IBDocument.SystemVersion">9D34</string>
<string key="IBDocument.InterfaceBuilderVersion">667</string>
<string key="IBDocument.AppKitVersion">949.33</string>
<string key="IBDocument.HIToolboxVersion">352.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -492,7 +492,7 @@
<reference key="NSSuperview" ref="755547124"/>
<bool key="NSEnabled">YES</bool>
<object class="NSButtonCell" key="NSCell" id="671503663">
<int key="NSCellFlags">604110336</int>
<int key="NSCellFlags">67239424</int>
<int key="NSCellFlags2">134217728</int>
<string key="NSContents">Create</string>
<reference key="NSSupport" ref="364179855"/>
@ -782,12 +782,12 @@
<int key="connectionID">86</int>
</object>
<object class="IBConnectionRecord">
<object class="IBOutletConnection" key="connection">
<string key="label">fCreateButton</string>
<object class="IBActionConnection" key="connection">
<string key="label">toggleOpenCheck:</string>
<reference key="source" ref="578092914"/>
<reference key="destination" ref="697506694"/>
<reference key="destination" ref="631380462"/>
</object>
<int key="connectionID">87</int>
<int key="connectionID">88</int>
</object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
@ -1308,7 +1308,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">87</int>
<int key="maxID">88</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@ -1324,6 +1324,7 @@
<string>cancelCreateWindow:</string>
<string>create:</string>
<string>setLocation:</string>
<string>toggleOpenCheck:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -1331,6 +1332,7 @@
<string>id</string>
<string>id</string>
<string>id</string>
<string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
@ -1338,7 +1340,6 @@
<object class="NSMutableArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>fCommentView</string>
<string>fCreateButton</string>
<string>fIconView</string>
<string>fLocationField</string>
<string>fNameField</string>
@ -1353,7 +1354,6 @@
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSTextView</string>
<string>NSButton</string>
<string>NSImageView</string>
<string>NSTextField</string>
<string>NSTextField</string>
@ -1381,6 +1381,7 @@
</object>
<object class="IBPartialClassDescription">
<string key="className">FirstResponder</string>
<string key="superclassName">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBUserSource</string>
<string key="minorKey"/>
@ -1400,13 +1401,6 @@
<string key="minorKey">macosx/NSMenuAdditions.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">macosx/IPCController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">

View file

@ -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