Changeset 5367


Ignore:
Timestamp:
Mar 24, 2008, 7:38:29 PM (14 years ago)
Author:
livings124
Message:

support newly added errors in the torrent creator window

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/CreatorWindowController.m

    r5297 r5367  
    2525#import "CreatorWindowController.h"
    2626#import "NSStringAdditions.h"
     27#include "utils.h" //tr_httpParseURL
    2728
    2829@interface CreatorWindowController (Private)
     
    189190- (void) create: (id) sender
    190191{
     192    NSString * trackerString = [fTrackerField stringValue];
     193    if ([trackerString rangeOfString: @"://"].location == NSNotFound)
     194        trackerString = [@"http://" stringByAppendingString: trackerString];
     195   
    191196    //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
    195207        if (![trackerString hasPrefix: @"http://"])
    196         {
    197             NSAlert * alert = [[[NSAlert alloc] init] autorelease];
    198             [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> http warning -> button")];
    199208            [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")];
    222214       
    223215        [alert beginSheetModalForWindow: [self window] modalDelegate: self didEndSelector: nil contextInfo: nil];
     
    318310        fTimer = nil;
    319311       
    320         if (fInfo->failed)
     312        NSAlert * alert;
     313        switch (fInfo->result)
    321314        {
    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];
    325332                [alert addButtonWithTitle: NSLocalizedString(@"OK", "Create torrent -> failed -> button")];
    326333                [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Creation of \"%@\" failed.",
    327334                                                "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")];
    330335                [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
    331344               
    332345                [alert beginSheetModalForWindow: [self window] modalDelegate: self
    333346                        didEndSelector: @selector(failureSheetClosed:returnCode:contextInfo:) contextInfo: nil];
    334                 return;
    335             }
    336347        }
    337         else
    338         {
    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];
    348348    }
    349349    else
     
    353353        if (!fStarted)
    354354        {
     355            fStarted = YES;
     356           
    355357            NSWindow * window = [self window];
    356358           
     
    370372           
    371373            [[window standardWindowButton:NSWindowCloseButton] setEnabled: NO];
    372            
    373             fStarted = YES;
    374374        }
    375375    }
Note: See TracChangeset for help on using the changeset viewer.