Changeset 361


Ignore:
Timestamp:
Jun 15, 2006, 2:07:50 AM (16 years ago)
Author:
livings124
Message:

By popular demand: the return of "Remove Torrent File." It only applies to the files not moved to the private folder.

Location:
trunk/macosx
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r325 r361  
    9696- (void) stopTorrentWithIndex:      (NSIndexSet *) indexSet;
    9797
    98 - (void) removeTorrent:                 (id) sender;
    99 - (void) removeTorrentDeleteData:       (id) sender;
    100 - (void) removeTorrentWithIndex:        (NSIndexSet *) indexSet
    101                 deleteData:             (BOOL) deleteData;
     98- (void) removeWithIndex: (NSIndexSet *) indexSet
     99        deleteData: (BOOL) deleteData deleteTorrent: (BOOL) deleteData;
    102100- (void) removeSheetDidEnd: (NSWindow *) sheet returnCode: (int) returnCode
    103101                        contextInfo: (NSDictionary *) dict;
    104 - (void) confirmRemoveTorrents: (NSArray *) torrents
    105             deleteData: (BOOL) deleteData;
     102- (void) confirmRemove: (NSArray *) torrents
     103        deleteData: (BOOL) deleteData deleteTorrent: (BOOL) deleteTorrent;
     104- (void) removeNoDelete:                (id) sender;
     105- (void) removeDeleteData:       (id) sender;
     106- (void) removeDeleteTorrent:    (id) sender;
     107- (void) removeDeleteBoth:       (id) sender;
    106108
    107109- (void) copyTorrentFile: (id) sender;
  • trunk/macosx/Controller.m

    r357 r361  
    523523}
    524524
    525 - (void) removeTorrentWithIndex: (NSIndexSet *) indexSet
    526                      deleteData: (BOOL) deleteData
     525- (void) removeWithIndex: (NSIndexSet *) indexSet
     526        deleteData: (BOOL) deleteData deleteTorrent: (BOOL) deleteTorrent
    527527{
    528528    NSArray * torrents = [[self torrentsAtIndexes: indexSet] retain];
     
    540540            torrents, @"Torrents",
    541541            [NSNumber numberWithBool: deleteData], @"DeleteData",
     542            [NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent",
    542543            nil];
    543544
     
    574575    else
    575576    {
    576         [self confirmRemoveTorrents: torrents
    577                 deleteData: deleteData];
     577        [self confirmRemove: torrents
     578            deleteData: deleteData deleteTorrent: deleteTorrent];
    578579    }
    579580}
     
    585586
    586587    NSArray * torrents = [dict objectForKey: @"Torrents"];
    587     BOOL deleteData = [[dict objectForKey: @"DeleteData"] boolValue];
     588    BOOL deleteData = [[dict objectForKey: @"DeleteData"] boolValue],
     589        deleteTorrent = [[dict objectForKey: @"DeleteTorrent"] boolValue];
    588590    [dict release];
    589591   
    590592    if (returnCode == NSAlertDefaultReturn)
    591593    {
    592         [self confirmRemoveTorrents: torrents
    593             deleteData: deleteData];
     594        [self confirmRemove: torrents
     595            deleteData: deleteData deleteTorrent: deleteTorrent];
    594596    }
    595597    else
     
    597599}
    598600
    599 - (void) confirmRemoveTorrents: (NSArray *) torrents
    600             deleteData: (BOOL) deleteData
     601- (void) confirmRemove: (NSArray *) torrents
     602        deleteData: (BOOL) deleteData deleteTorrent: (BOOL) deleteTorrent
    601603{
    602604    Torrent * torrent;
     
    606608        [torrent stop];
    607609
    608         if( deleteData )
     610        if (deleteData)
    609611            [torrent trashData];
     612        if (deleteTorrent)
     613            [torrent trashTorrent];
    610614
    611615        [torrent removeForever];
     
    620624}
    621625
    622 - (void) removeTorrent: (id) sender
    623 {
    624     [self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteData: NO];
    625 }
    626 
    627 - (void) removeTorrentDeleteData: (id) sender
    628 {
    629     [self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteData: YES];
     626- (void) removeNoDelete: (id) sender
     627{
     628    [self removeWithIndex: [fTableView selectedRowIndexes] deleteData: NO deleteTorrent: NO];
     629}
     630
     631- (void) removeDeleteData: (id) sender
     632{
     633    [self removeWithIndex: [fTableView selectedRowIndexes] deleteData: YES deleteTorrent: NO];
     634}
     635
     636- (void) removeDeleteTorrent: (id) sender
     637{
     638    [self removeWithIndex: [fTableView selectedRowIndexes] deleteData: NO deleteTorrent: YES];
     639}
     640
     641- (void) removeDeleteBoth: (id) sender
     642{
     643    [self removeWithIndex: [fTableView selectedRowIndexes] deleteData: YES deleteTorrent: YES];
    630644}
    631645
     
    12541268
    12551269    //enable remove items
    1256     if (action == @selector(removeTorrent:) || action == @selector(removeTorrentDeleteData:))
    1257     {
    1258         BOOL active = NO;
     1270    if (action == @selector(removeNoDelete:) || action == @selector(removeDeleteData:)
     1271        || action == @selector(removeDeleteTorrent:) || action == @selector(removeDeleteBoth:))
     1272    {
     1273        BOOL active = NO,
     1274            canDelete = !(action == @selector(removeDeleteTorrent:)
     1275                            || action == @selector(removeDeleteBoth:));
    12591276        Torrent * torrent;
    12601277        NSIndexSet * indexSet = [fTableView selectedRowIndexes];
     
    12651282            torrent = [fTorrents objectAtIndex: i];
    12661283            if ([torrent isActive])
    1267             {
    12681284                active = YES;
     1285            if ([torrent publicTorrent])
     1286                canDelete = YES;
     1287           
     1288            if (active && canDelete)
    12691289                break;
    1270             }
    12711290        }
    12721291   
     
    12841303                            [title rangeOfString: ellipsis].location]];
    12851304        }
    1286         return canUseMenu && [fTableView numberOfSelectedRows] > 0;
     1305       
     1306        return canUseMenu && canDelete && [fTableView numberOfSelectedRows] > 0;
    12871307    }
    12881308
  • trunk/macosx/English.lproj/MainMenu.nib/classes.nib

    r323 r361  
    1010                linkHomepage = id;
    1111                openShowSheet = id;
    12                 removeTorrent = id;
    13                 removeTorrentDeleteData = id;
     12                removeDeleteBoth = id;
     13                removeDeleteData = id;
     14                removeDeleteTorrent = id;
     15                removeNoDelete = id;
    1416                resumeAllTorrents = id;
    1517                resumeTorrent = id;
  • trunk/macosx/English.lproj/MainMenu.nib/info.nib

    r352 r361  
    1414                <string>189 691 451 44 0 0 1152 842 </string>
    1515                <key>456</key>
    16                 <string>403 374 216 168 0 0 1152 842 </string>
     16                <string>396 374 216 168 0 0 1152 842 </string>
    1717                <key>581</key>
    1818                <string>324 628 112 68 0 0 1152 842 </string>
     
    3030        <key>IBOpenObjects</key>
    3131        <array>
    32                 <integer>1480</integer>
    3332                <integer>21</integer>
    3433        </array>
  • trunk/macosx/Torrent.h

    r354 r361  
    4040    NSDate       * fDate;
    4141   
    42     BOOL        fPrivateTorrent;
     42    BOOL        fPrivateTorrent, fPublicTorrent;
     43    NSString    * fPublicTorrentLocation;
    4344
    4445    NSUserDefaults  * fDefaults;
     
    5253}
    5354
    54 - (id)          initWithPath: (NSString *) path lib: (tr_handle_t *) lib;
    55 - (id)          initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib;
     55- (id)  initWithPath: (NSString *) path lib: (tr_handle_t *) lib;
     56- (id)  initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib;
     57
    5658- (NSDictionary *) history;
    5759                   
     
    7375- (void)        setRatioLimit: (float) limit;
    7476
    75 - (void)        reveal;
    76 - (void)        trashData;
     77- (void)    reveal;
     78- (void)    trashData;
     79- (void)    trashTorrent;
    7780
    7881- (NSImage *)  icon;
     
    8689- (int)        pieceCount;
    8790- (NSString *) hashString;
     91
    8892- (NSString *) torrentLocation;
     93- (NSString *) publicTorrentLocation;
    8994- (NSString *) dataLocation;
     95
     96- (BOOL) publicTorrent;
     97- (BOOL) privateTorrent;
    9098
    9199- (NSString *) state;
  • trunk/macosx/Torrent.m

    r357 r361  
    3030- (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib date: (NSDate *) date
    3131        stopRatioSetting: (NSNumber *) stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
    32 - (id) initWithHash: (NSString *) hashString lib: (tr_handle_t *) lib date: (NSDate *) date
    33         stopRatioSetting: (NSNumber *) stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
     32- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
     33        date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
     34        ratioLimit: (NSNumber *) ratioLimit;
    3435- (id) initForSuccessWithDate: (NSDate *) date stopRatioSetting: (NSNumber *)
    3536            stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
     
    4647    id torrent = [self initWithPath: path lib: lib date: nil
    4748                    stopRatioSetting: nil ratioLimit: nil];
    48                    
    49     if (torrent && fPrivateTorrent && [fDefaults boolForKey: @"DeleteOriginalTorrent"])
    50         [self trashFile: path];
     49   
     50    if (torrent)
     51    {
     52        fPrivateTorrent = [fDefaults boolForKey: @"SavePrivateTorrent"];
     53        fPublicTorrent = !fPrivateTorrent || ![fDefaults boolForKey: @"DeleteOriginalTorrent"];
     54   
     55        if (!fPublicTorrent)
     56        {
     57            [self trashFile: path];
     58            fPublicTorrentLocation = nil;
     59        }
     60        else
     61            fPublicTorrentLocation = [path retain];
     62    }
    5163   
    5264    return torrent;
     
    5769    //load from saved torrent file if set to, otherwise try to load from where torrent file should be
    5870    id torrent;
    59     NSNumber * privateCopy;
    60     if ((privateCopy = [history objectForKey: @"PrivateCopy"]) && [privateCopy boolValue])
     71    NSNumber * privateCopy, * publicCopy;
     72    fPrivateTorrent = (privateCopy = [history objectForKey: @"PrivateCopy"]) && [privateCopy boolValue];
     73    fPublicTorrent = !fPrivateTorrent || ((publicCopy = [history objectForKey: @"PublicCopy"])
     74                                            && [publicCopy boolValue]);
     75    NSString * path = [history objectForKey: @"TorrentPath"];
     76   
     77    if (fPrivateTorrent)
    6178        torrent = [self initWithHash: [history objectForKey: @"TorrentHash"]
    62             lib: lib date: [history objectForKey: @"Date"]
     79            path: [history objectForKey: @"TorrentPath"] lib: lib
     80            date: [history objectForKey: @"Date"]
    6381            stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
    6482            ratioLimit: [history objectForKey: @"RatioLimit"]];
     
    7189    if (torrent)
    7290    {
     91        if (fPublicTorrent)
     92            fPublicTorrentLocation = [path retain];
     93   
    7394        NSString * downloadFolder;
    7495        if (!(downloadFolder = [history objectForKey: @"DownloadFolder"]))
     
    88109    NSMutableDictionary * history = [NSMutableDictionary dictionaryWithObjectsAndKeys:
    89110                    [NSNumber numberWithBool: fPrivateTorrent], @"PrivateCopy",
     111                    [NSNumber numberWithBool: fPublicTorrent], @"PublicCopy",
    90112                    [self downloadFolder], @"DownloadFolder",
    91113                    [self isActive] ? @"NO" : @"YES", @"Paused",
     
    96118    if (fPrivateTorrent)
    97119        [history setObject: [self hashString] forKey: @"TorrentHash"];
    98     else
     120
     121    if (fPublicTorrent)
    99122        [history setObject: [self torrentLocation] forKey: @"TorrentPath"];
    100123   
     
    107130    {
    108131        tr_torrentClose( fLib, fHandle );
     132       
     133        if (fPublicTorrentLocation)
     134            [fPublicTorrentLocation release];
    109135       
    110136        [fDate release];
     
    136162    fStat = tr_torrentStat( fHandle );
    137163   
    138     if ([self isSeeding])
    139         if ((fStopRatioSetting == RATIO_CHECK && [self ratio] >= fRatioLimit)
    140             || (fStopRatioSetting == RATIO_GLOBAL && [fDefaults boolForKey: @"RatioCheck"]
    141                 && [self ratio] >= [fDefaults floatForKey: @"RatioLimit"]))
    142         {
    143             [self stop];
    144             [self setStopRatioSetting: RATIO_NO_CHECK];
    145             fFinishedSeeding = YES;
    146            
    147             fStat = tr_torrentStat( fHandle );
    148            
    149             [[NSNotificationCenter defaultCenter] postNotificationName:
    150                 @"TorrentRatioChanged" object: self];
    151         }
    152    
     164    if ([self isSeeding]
     165        && (fStopRatioSetting == RATIO_CHECK && [self ratio] >= fRatioLimit)
     166        || (fStopRatioSetting == RATIO_GLOBAL && [fDefaults boolForKey: @"RatioCheck"]
     167            && [self ratio] >= [fDefaults floatForKey: @"RatioLimit"]))
     168    {
     169        [self stop];
     170        [self setStopRatioSetting: RATIO_NO_CHECK];
     171        fFinishedSeeding = YES;
     172       
     173        fStat = tr_torrentStat( fHandle );
     174       
     175        [[NSNotificationCenter defaultCenter] postNotificationName:
     176            @"TorrentRatioChanged" object: self];
     177    }
     178
    153179    [fProgressString setString: @""];
    154180    if ([self progress] < 1.0)
     
    299325}
    300326
     327- (void) trashTorrent
     328{
     329    if (fPublicTorrent)
     330        [self trashFile: [self publicTorrentLocation]];
     331}
     332
    301333- (NSImage *) icon
    302334{
     
    348380{
    349381    return [NSString stringWithUTF8String: fInfo->torrent];
     382}
     383
     384- (NSString *) publicTorrentLocation
     385{
     386    return fPublicTorrentLocation;
     387}
     388
     389- (BOOL) publicTorrent
     390{
     391    return fPublicTorrent;
     392}
     393
     394- (BOOL) privateTorrent
     395{
     396    return fPrivateTorrent;
    350397}
    351398
     
    514561    fLib = lib;
    515562    fDefaults = [NSUserDefaults standardUserDefaults];
    516 
    517     fPrivateTorrent = [fDefaults boolForKey: @"SavePrivateTorrent"];
     563    fPublicTorrentLocation = path;
    518564
    519565    int error;
     
    528574}
    529575
    530 - (id) initWithHash: (NSString *) hashString lib: (tr_handle_t *) lib date: (NSDate *) date
    531         stopRatioSetting: (NSNumber *) stopRatioSetting ratioLimit: (NSNumber *) ratioLimit
     576- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
     577            date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
     578            ratioLimit: (NSNumber *) ratioLimit
    532579{
    533580    if (!(self = [super init]))
     
    536583    fLib = lib;
    537584    fDefaults = [NSUserDefaults standardUserDefaults];
    538    
    539     fPrivateTorrent = YES;
     585    fPublicTorrentLocation = path;
    540586
    541587    int error;
Note: See TracChangeset for help on using the changeset viewer.