Changeset 2238


Ignore:
Timestamp:
Jun 29, 2007, 11:11:58 PM (15 years ago)
Author:
livings124
Message:

show a warning when trying to open a duplicate torrent

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r2198 r2238  
    112112- (void) openFilesAskWithDict:  (NSDictionary *) dictionary;
    113113- (void) openShowSheet:         (id) sender;
     114
     115- (void) duplicateOpenAlert: (NSString *) name;
     116
    114117- (void) openURL:               (NSURL *) torrentURL;
    115118- (void) openURLEndSheet:       (id) sender;
  • trunk/macosx/Controller.m

    r2237 r2238  
    704704    Torrent * torrent;
    705705    NSString * torrentPath;
     706    tr_info_t info;
    706707    NSEnumerator * enumerator = [filenames objectEnumerator];
    707708    while ((torrentPath = [enumerator nextObject]))
     
    715716            location = [torrentPath stringByDeletingLastPathComponent];
    716717       
     718        if (tr_torrentParse(fLib, [torrentPath UTF8String], NULL, &info) == TR_EDUPLICATE)
     719        {
     720            [self duplicateOpenAlert: [NSString stringWithUTF8String: info.name]];
     721            tr_metainfoFree(&info);
     722            continue;
     723        }
     724        tr_metainfoFree(&info);
     725       
    717726        if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location forceDeleteTorrent: delete lib: fLib]))
    718727            continue;
     
    777786    {
    778787        torrentPath = [files objectAtIndex: 0];
    779         if (tr_torrentParse(fLib, [torrentPath UTF8String], NULL, &info) == TR_OK)
     788        canAdd = tr_torrentParse(fLib, [torrentPath UTF8String], NULL, &info);
     789        if (canAdd == TR_OK)
    780790            break;
     791        else if (canAdd == TR_EDUPLICATE)
     792            [self duplicateOpenAlert: [NSString stringWithUTF8String: info.name]];
     793        else;
    781794       
    782795        tr_metainfoFree(&info);
     
    817830    {
    818831        NSString * torrentPath = [dictionary objectForKey: @"Path"];
    819         Torrent * torrent = [[Torrent alloc] initWithPath: torrentPath
    820                             location: [[openPanel filenames] objectAtIndex: 0]
     832        Torrent * torrent = [[Torrent alloc] initWithPath: torrentPath location: [[openPanel filenames] objectAtIndex: 0]
    821833                            forceDeleteTorrent: [[dictionary objectForKey: @"Delete"] boolValue] lib: fLib];
    822834       
     
    881893   
    882894    [dictionary release];
     895}
     896
     897- (void) duplicateOpenAlert: (NSString *) name
     898{
     899    NSAlert * alert = [[NSAlert alloc] init];
     900    [alert addButtonWithTitle: NSLocalizedString(@"OK", "Open duplicate alert -> button")];
     901    [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Transfer of \"%@\" is already running.",
     902                            "Open duplicate alert -> title"), name]];
     903    [alert setInformativeText:
     904            NSLocalizedString(@"The torrent file cannot be opened because it is a duplicate of an already running transfer.",
     905                            "Open duplicate alert -> message")];
     906    [alert setAlertStyle: NSWarningAlertStyle];
     907   
     908    [alert runModal];
     909    [alert release];
    883910}
    884911
     
    12851312    Torrent * torrent;
    12861313    while ((torrent = [enumerator nextObject]))
    1287     {
    12881314        [torrent resetCache];
    1289     }
     1315   
    12901316    #warning reset queue?
    12911317}
     
    20012027    }
    20022028   
    2003     NSEnumerator * enumerator;
    2004     if (![[fDefaults stringForKey: @"DownloadChoice"] isEqualToString: @"Ask"])
    2005     {
    2006         enumerator = [newNames objectEnumerator];
    2007         int count;
    2008         while ((file = [enumerator nextObject]))
    2009         {
    2010             count = [fTorrents count];
     2029    BOOL ask = [[fDefaults stringForKey: @"DownloadChoice"] isEqualToString: @"Ask"];
     2030   
     2031    NSEnumerator * enumerator = [newNames objectEnumerator];
     2032    int canAdd, count;
     2033    while ((file = [enumerator nextObject]))
     2034    {
     2035        canAdd = tr_torrentParse(fLib, [file UTF8String], NULL, NULL);
     2036        if (canAdd == TR_OK)
     2037        {
     2038            if (!ask)
     2039                count = [fTorrents count];
    20112040            [self openFiles: [NSArray arrayWithObject: file]];
    20122041           
    20132042            //check if torrent was opened
    2014             if ([fTorrents count] > count)
     2043            if (!ask && [fTorrents count] > count)
    20152044                [GrowlApplicationBridge notifyWithTitle: NSLocalizedString(@"Torrent File Auto Added",
    20162045                    "Growl notification title") description: [file lastPathComponent]
    20172046                    notificationName: GROWL_AUTO_ADD iconData: nil priority: 0 isSticky: NO clickContext: nil];
    20182047        }
    2019     }
    2020     else
    2021         [self openFiles: newNames];
    2022    
    2023     //check if an import fails because of an error so it can be tried again
    2024     enumerator = [newNames objectEnumerator];
    2025     while ((file = [enumerator nextObject]))
    2026         if (tr_torrentParse(fLib, [file UTF8String], NULL, NULL) == TR_EINVALID)
     2048        else if (canAdd == TR_EINVALID)
    20272049            [fAutoImportedNames removeObject: [file lastPathComponent]];
     2050        else;
     2051    }
    20282052   
    20292053    [newNames release];
  • trunk/macosx/InfoWindowController.m

    r2226 r2238  
    952952}
    953953
    954 #warning need?
    955954- (void) setFileOutlineHoverRowForEvent: (NSEvent *) event
    956955{
Note: See TracChangeset for help on using the changeset viewer.