@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;
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
[fPath release];
[fLocation release];
+ [fTracker release];
+
if (fInfo)
tr_metaInfoBuilderFree(fInfo);
[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];
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
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
}
}
+- (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)
switch (fInfo->result)
{
case TR_MAKEMETA_OK:
- if (fOpenTorrent)
+ if (fOpenTorrent && ![fTracker isEqualToString: @""])
{
NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: fLocation, @"File",
[fPath stringByDeletingLastPathComponent], @"Path", nil];
<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>
<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"/>
<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">
</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">
<string>cancelCreateWindow:</string>
<string>create:</string>
<string>setLocation:</string>
+ <string>toggleOpenCheck:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
<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>
<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>
</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"/>
<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">