Changeset 1519


Ignore:
Timestamp:
Mar 2, 2007, 1:34:06 AM (15 years ago)
Author:
livings124
Message:

move torrent check code to the Torrent class

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoWindowController.m

    r1514 r1519  
    6161- (NSArray *) peerSortDescriptors;
    6262
    63 - (void) setFileCheckState: (int) state forItem: (NSMutableDictionary *) item;
    64 - (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild;
    65 
    6663- (int) stateSettingToPopUpIndex: (int) index;
    6764- (int) popUpIndexToStateSetting: (int) index;
     
    108105    [fFileOutline setDoubleAction: @selector(revealFile:)];
    109106   
    110     [[NSNotificationCenter defaultCenter] addObserver: self
    111             selector: @selector(fileFinished:) name: @"FileFinished" object: nil];
    112    
    113107    //set blank inspector
    114108    [self updateInfoForTorrents: [NSArray array]];
     
    117111- (void) dealloc
    118112{
    119     [[NSNotificationCenter defaultCenter] removeObserver: self];
    120    
    121113    if (fTorrents)
    122114        [fTorrents release];
     
    730722    else if ([[tableColumn identifier] isEqualToString: @"Check"])
    731723    {
    732         /*if (!item)
     724        if (!item)
    733725        {
    734726            [(NSButtonCell *)cell setImagePosition: NSNoImage];
     
    739731        [(NSButtonCell *)cell setImagePosition: NSImageOnly];
    740732        [cell setEnabled: [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Remaining"] intValue] > 0
    741                                                                     : [[item objectForKey: @"Progress"] floatValue] < 1.0];*/
    742         [(NSButtonCell *)cell setImagePosition: NSNoImage];
     733                                                                    : [[item objectForKey: @"Progress"] floatValue] < 1.0];
     734        //[(NSButtonCell *)cell setImagePosition: NSNoImage];
    743735    }
    744736    else;
     
    748740        forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
    749741{
     742    Torrent * torrent = [fTorrents objectAtIndex: 0];
    750743    int state = [object intValue] != NSOffState ? NSOnState : NSOffState;
    751744   
    752     [self setFileCheckState: state forItem: item];
    753     NSMutableDictionary * topItem = [self resetFileCheckStateForItemParent: item];
     745    [torrent setFileCheckState: state forFileItem: item];
     746    NSMutableDictionary * topItem = [torrent resetFileCheckStateForItemParent: item];
    754747   
    755748    [fFileOutline reloadItem: topItem reloadChildren: YES];
    756 }
    757 
    758 - (void) fileFinished: (NSNotification *) notification
    759 {
    760     NSMutableDictionary * item = [notification object];
    761    
    762     [item setObject: [NSNumber numberWithInt: NSOnState] forKey: @"Check"];
    763     NSMutableDictionary * topItem = [self resetFileCheckStateForItemParent: item];
    764    
    765     [fFileOutline reloadItem: topItem reloadChildren: YES];
    766 }
    767 
    768 - (void) setFileCheckState: (int) state forItem: (NSMutableDictionary *) item
    769 {
    770     [item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
    771    
    772     if (![[item objectForKey: @"IsFolder"] boolValue])
    773         return;
    774    
    775     NSMutableDictionary * child;
    776     NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
    777     while ((child = [enumerator nextObject]))
    778         if (state != [[child objectForKey: @"Check"] intValue])
    779             [self setFileCheckState: state forItem: child];
    780 }
    781 
    782 - (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild
    783 {
    784     NSMutableDictionary * item;
    785     if (!(item = [originalChild objectForKey: @"Parent"]))
    786         return originalChild;
    787    
    788     int state = INVALID;
    789    
    790     NSMutableDictionary * child;
    791     NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
    792     while ((child = [enumerator nextObject]))
    793     {
    794         if (state == INVALID)
    795         {
    796             state = [[child objectForKey: @"Check"] intValue];
    797             if (state == NSMixedState)
    798                 break;
    799         }
    800         else if (state != [[child objectForKey: @"Check"] intValue])
    801         {
    802             state = NSMixedState;
    803             break;
    804         }
    805         else;
    806     }
    807    
    808     if (state != [[item objectForKey: @"Check"] intValue])
    809     {
    810         [item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
    811         return [self resetFileCheckStateForItemParent: item];
    812     }
    813     else
    814         return originalChild;
    815749}
    816750
  • trunk/macosx/Torrent.h

    r1514 r1519  
    173173- (float)       swarmSpeed;
    174174
    175 - (BOOL) updateFileProgress;
    176 
    177175- (NSNumber *) orderValue;
    178176- (void) setOrderValue: (int) orderValue;
     
    180178- (NSArray *) fileList;
    181179- (int) fileCount;
     180- (BOOL) updateFileProgress;
     181- (void) setFileCheckState: (int) state forFileItem: (NSMutableDictionary *) item;
     182- (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild;
    182183
    183184- (NSDate *) date;
  • trunk/macosx/Torrent.m

    r1517 r1519  
    3030#define MAX_PIECES 324
    3131#define BLANK_PIECE -99
     32
     33#define INVALID -99
    3234
    3335@interface Torrent (Private)
     
    10441046}
    10451047
     1048- (NSNumber *) orderValue
     1049{
     1050    return [NSNumber numberWithInt: fOrderValue];
     1051}
     1052
     1053- (void) setOrderValue: (int) orderValue
     1054{
     1055    fOrderValue = orderValue;
     1056}
     1057
     1058- (NSArray *) fileList
     1059{
     1060    return fFileList;
     1061}
     1062
     1063- (int) fileCount
     1064{
     1065    return fInfo->fileCount;
     1066}
     1067
    10461068- (BOOL) updateFileProgress
    10471069{
     
    10681090                            forKey: @"Remaining"];
    10691091               
    1070                 [[NSNotificationCenter defaultCenter] postNotificationName: @"FileFinished" object: item];
     1092                [item setObject: [NSNumber numberWithInt: NSOnState] forKey: @"Check"];
     1093                [self resetFileCheckStateForItemParent: item];
    10711094            }
    10721095        }
     
    10781101}
    10791102
    1080 - (NSNumber *) orderValue
    1081 {
    1082     return [NSNumber numberWithInt: fOrderValue];
    1083 }
    1084 
    1085 - (void) setOrderValue: (int) orderValue
    1086 {
    1087     fOrderValue = orderValue;
    1088 }
    1089 
    1090 - (NSArray *) fileList
    1091 {
    1092     return fFileList;
    1093 }
    1094 
    1095 - (int) fileCount
    1096 {
    1097     return fInfo->fileCount;
     1103- (void) setFileCheckState: (int) state forFileItem: (NSMutableDictionary *) item
     1104{
     1105    [item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
     1106   
     1107    if (![[item objectForKey: @"IsFolder"] boolValue])
     1108        return;
     1109   
     1110    NSMutableDictionary * child;
     1111    NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
     1112    while ((child = [enumerator nextObject]))
     1113        if (state != [[child objectForKey: @"Check"] intValue])
     1114            [self setFileCheckState: state forFileItem: child];
     1115}
     1116
     1117- (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild
     1118{
     1119    NSMutableDictionary * item;
     1120    if (!(item = [originalChild objectForKey: @"Parent"]))
     1121        return originalChild;
     1122   
     1123    int state = INVALID;
     1124   
     1125    NSMutableDictionary * child;
     1126    NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
     1127    while ((child = [enumerator nextObject]))
     1128    {
     1129        if (state == INVALID)
     1130        {
     1131            state = [[child objectForKey: @"Check"] intValue];
     1132            if (state == NSMixedState)
     1133                break;
     1134        }
     1135        else if (state != [[child objectForKey: @"Check"] intValue])
     1136        {
     1137            state = NSMixedState;
     1138            break;
     1139        }
     1140        else;
     1141    }
     1142   
     1143    if (state != [[item objectForKey: @"Check"] intValue])
     1144    {
     1145        [item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
     1146        return [self resetFileCheckStateForItemParent: item];
     1147    }
     1148    else
     1149        return originalChild;
    10981150}
    10991151
Note: See TracChangeset for help on using the changeset viewer.