Changeset 5367
- Timestamp:
- Mar 24, 2008, 7:38:29 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/CreatorWindowController.m
r5297 r5367 25 25 #import "CreatorWindowController.h" 26 26 #import "NSStringAdditions.h" 27 #include "utils.h" //tr_httpParseURL 27 28 28 29 @interface CreatorWindowController (Private) … … 189 190 - (void) create: (id) sender 190 191 { 192 NSString * trackerString = [fTrackerField stringValue]; 193 if ([trackerString rangeOfString: @"://"].location == NSNotFound) 194 trackerString = [@"http://" stringByAppendingString: trackerString]; 195 191 196 //parse tracker string 192 NSString * trackerString = [fTrackerField stringValue]; 193 if ([trackerString rangeOfString: @"://"].location != NSNotFound) 194 { 197 if (tr_httpParseURL([trackerString UTF8String], -1, NULL, NULL, NULL)) 198 { 199 NSAlert * alert = [[[NSAlert alloc] init] autorelease]; 200 [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> warning -> button")]; 201 [alert setMessageText: NSLocalizedString(@"The tracker address cannot be blank.", "Create torrent -> warning -> title")]; 202 [alert setInformativeText: NSLocalizedString(@"Change the tracker address to create the torrent.", 203 "Create torrent -> warning -> info")]; 204 [alert setAlertStyle: NSWarningAlertStyle]; 205 206 //check common reasons for failure 195 207 if (![trackerString hasPrefix: @"http://"]) 196 {197 NSAlert * alert = [[[NSAlert alloc] init] autorelease];198 [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> http warning -> button")];199 208 [alert setMessageText: NSLocalizedString(@"The tracker address must begin with \"http://\".", 200 "Create torrent -> http warning -> title")]; 201 [alert setInformativeText: NSLocalizedString(@"Change the tracker address to create the torrent.", 202 "Create torrent -> http warning -> warning")]; 203 [alert setAlertStyle: NSWarningAlertStyle]; 204 205 [alert beginSheetModalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil]; 206 return; 207 } 208 } 209 else 210 trackerString = [@"http://" stringByAppendingString: trackerString]; 211 212 //don't allow blank addresses 213 if ([trackerString length] <= 7) 214 { 215 NSAlert * alert = [[[NSAlert alloc] init] autorelease]; 216 [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> no url warning -> button")]; 217 [alert setMessageText: NSLocalizedString(@"The tracker address cannot be blank.", 218 "Create torrent -> no url warning -> title")]; 219 [alert setInformativeText: NSLocalizedString(@"Change the tracker address to create the torrent.", 220 "Create torrent -> no url warning -> warning")]; 221 [alert setAlertStyle: NSWarningAlertStyle]; 209 "Create torrent -> warning -> message")]; 210 else if ([trackerString length] <= 7) //don't allow blank addresses 211 [alert setMessageText: NSLocalizedString(@"The tracker address cannot be blank.", "Create torrent -> warning -> message")]; 212 else 213 [alert setMessageText: NSLocalizedString(@"The tracker address is invalid.", "Create torrent -> warning -> message")]; 222 214 223 215 [alert beginSheetModalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil]; … … 318 310 fTimer = nil; 319 311 320 if (fInfo->failed) 312 NSAlert * alert; 313 switch (fInfo->result) 321 314 { 322 if (!fInfo->abortFlag) 323 { 324 NSAlert * alert = [[[NSAlert alloc] init] autorelease]; 315 case TR_MAKEMETA_OK: 316 if (fOpenTorrent) 317 { 318 NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: fLocation, @"File", 319 [fPath stringByDeletingLastPathComponent], @"Path", nil]; 320 [[NSNotificationCenter defaultCenter] postNotificationName: @"OpenCreatedTorrentFile" object: self userInfo: dict]; 321 } 322 323 [[self window] close]; 324 break; 325 326 case TR_MAKEMETA_CANCELLED: 327 [[self window] close]; 328 break; 329 330 default: 331 alert = [[[NSAlert alloc] init] autorelease]; 325 332 [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> failed -> button")]; 326 333 [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Creation of \"%@\" failed.", 327 334 "Create torrent -> failed -> title"), [fLocation lastPathComponent]]]; 328 [alert setInformativeText: NSLocalizedString(@"There was an error parsing the data file. "329 "The torrent file was not created.", "Create torrent -> failed -> warning")];330 335 [alert setAlertStyle: NSWarningAlertStyle]; 336 337 if (fInfo->result == TR_MAKEMETA_IO_READ) 338 [alert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@"Could not read \"%s\": %s", 339 "Create torrent -> failed -> warning"), fInfo->errfile, fInfo->my_errno]]; 340 else if (fInfo->result == TR_MAKEMETA_IO_WRITE) 341 [alert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@"Could not write \"%s\": %s", 342 "Create torrent -> failed -> warning"), fInfo->errfile, fInfo->my_errno]]; 343 else; //invalid url should have been caught before creating 331 344 332 345 [alert beginSheetModalForWindow: [self window] modalDelegate: self 333 346 didEndSelector: @selector(failureSheetClosed:returnCode:contextInfo:) contextInfo: nil]; 334 return;335 }336 347 } 337 else338 {339 if (fOpenTorrent)340 {341 NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: fLocation, @"File",342 [fPath stringByDeletingLastPathComponent], @"Path", nil];343 [[NSNotificationCenter defaultCenter] postNotificationName: @"OpenCreatedTorrentFile" object: self userInfo: dict];344 }345 }346 347 [[self window] close];348 348 } 349 349 else … … 353 353 if (!fStarted) 354 354 { 355 fStarted = YES; 356 355 357 NSWindow * window = [self window]; 356 358 … … 370 372 371 373 [[window standardWindowButton:NSWindowCloseButton] setEnabled: NO]; 372 373 fStarted = YES;374 374 } 375 375 }
Note: See TracChangeset
for help on using the changeset viewer.