Changeset 2088


Ignore:
Timestamp:
Jun 16, 2007, 3:19:55 AM (15 years ago)
Author:
livings124
Message:

hopefully optimize file pane a bit

Location:
branches/file_selection/macosx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/file_selection/macosx/InfoWindowController.m

    r2086 r2088  
    604604        NSDictionary * item;
    605605        NSIndexSet * indexSet = [fFileOutline selectedRowIndexes], * itemIndexes;
     606        NSMutableIndexSet * usedIndexes = [NSMutableIndexSet indexSet];
    606607        int i, index, state = (menuItem == fFileCheckItem) ? NSOnState : NSOffState;
    607608        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    608609        {
    609             item = [fFileOutline itemAtRow: i];
    610             if ([[item objectForKey: @"IsFolder"] boolValue])
     610            itemIndexes = [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"];
     611            if (![usedIndexes containsIndexes: itemIndexes])
    611612            {
    612                 itemIndexes = [item objectForKey: @"Indexes"];
    613                 if ([torrent checkForFileFolder: itemIndexes] != state
    614                         && [torrent canChangeDownloadCheckForFileFolder: itemIndexes])
     613                if ([torrent checkForFiles: itemIndexes] != state && [torrent canChangeDownloadCheckForFiles: itemIndexes])
    615614                    return YES;
    616             }
    617             else
    618             {
    619                 index = [[item objectForKey: @"Index"] intValue];
    620                 if ([torrent checkForFile: index] != state && [torrent canChangeDownloadCheckFile: index])
    621                     return YES;
     615                [usedIndexes addIndexes: itemIndexes];
    622616            }
    623617        }
     
    648642        for (i = [indexSet firstIndex]; i != NSNotFound && (!current || !other); i = [indexSet indexGreaterThanIndex: i])
    649643        {
    650             if ([torrent hasFilePriority: priority forItem: [fFileOutline itemAtRow: i]])
     644            if ([torrent hasFilePriority: priority forIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]])
    651645                current = YES;
    652646            else
     
    852846{
    853847    if ([[tableColumn identifier] isEqualToString: @"Check"])
    854     {
    855         Torrent * torrent = [fTorrents objectAtIndex: 0];
    856         if ([[item objectForKey: @"IsFolder"] boolValue])
    857             return [NSNumber numberWithInt: [torrent checkForFileFolder: [item objectForKey: @"Indexes"]]];
    858         else
    859             return [NSNumber numberWithInt: [torrent checkForFile: [[item objectForKey: @"Index"] intValue]]];
    860     }
     848        return [NSNumber numberWithInt: [[fTorrents objectAtIndex: 0] checkForFiles: [item objectForKey: @"Indexes"]]];
    861849    else
    862850        return item;
     
    875863            [cell setImage: [item objectForKey: @"Icon"]];
    876864            [(FileBrowserCell *)cell setProgress: [[fTorrents objectAtIndex: 0] fileProgress:
    877                                                     [[item objectForKey: @"Index"] intValue]]];
     865                                                    [[item objectForKey: @"Indexes"] firstIndex]]];
    878866        }
    879867    }
    880868    else if ([identifier isEqualToString: @"Check"])
     869        [cell setEnabled: [[fTorrents objectAtIndex: 0] canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]];
     870    else if ([identifier isEqualToString: @"Priority"])
    881871    {
    882872        Torrent * torrent = [fTorrents objectAtIndex: 0];
    883         if ([[item objectForKey: @"IsFolder"] boolValue])
    884             [cell setEnabled: [torrent canChangeDownloadCheckForFileFolder: [item objectForKey: @"Indexes"]]];
    885         else
    886             [cell setEnabled: [torrent canChangeDownloadCheckFile: [[item objectForKey: @"Index"] intValue]]];
    887     }
    888     else if ([identifier isEqualToString: @"Priority"])
    889     {
    890         Torrent * torrent = [fTorrents objectAtIndex: 0];
    891         [(NSSegmentedCell *)cell setSelected: [torrent hasFilePriority: PRIORITY_LOW forItem: item] forSegment: 0];
    892         [(NSSegmentedCell *)cell setSelected: [torrent hasFilePriority: PRIORITY_NORMAL forItem: item] forSegment: 1];
    893         [(NSSegmentedCell *)cell setSelected: [torrent hasFilePriority: PRIORITY_HIGH forItem: item] forSegment: 2];
     873        NSIndexSet * indexeSet = [item objectForKey: @"Indexes"];
     874        [(NSSegmentedCell *)cell setSelected: [torrent hasFilePriority: PRIORITY_LOW forIndexes: indexeSet] forSegment: 0];
     875        [(NSSegmentedCell *)cell setSelected: [torrent hasFilePriority: PRIORITY_NORMAL forIndexes: indexeSet] forSegment: 1];
     876        [(NSSegmentedCell *)cell setSelected: [torrent hasFilePriority: PRIORITY_HIGH forIndexes: indexeSet] forSegment: 2];
    894877    }
    895878    else;
     
    904887        Torrent * torrent = [fTorrents objectAtIndex: 0];
    905888        [torrent setFileCheckState: [object intValue] != NSOffState ? NSOnState : NSOffState
    906                                         forFileItem: item];
     889                                        forIndexes: [item objectForKey: @"Indexes"]];
    907890       
    908891        [torrent update];
     
    920903            actualPriority = PRIORITY_NORMAL;
    921904       
    922         [[fTorrents objectAtIndex: 0] setFilePriority: actualPriority forFileItem: item];
     905        [[fTorrents objectAtIndex: 0] setFilePriority: actualPriority forIndexes: [item objectForKey: @"Indexes"]];
    923906        [fFileOutline reloadData];
    924907    }
     
    945928    {
    946929        Torrent * torrent = [fTorrents objectAtIndex: 0];
    947         BOOL low = [torrent hasFilePriority: PRIORITY_LOW forItem: item],
    948             normal = [torrent hasFilePriority: PRIORITY_NORMAL forItem: item],
    949             high = [torrent hasFilePriority: PRIORITY_HIGH forItem: item];
     930        NSIndexSet * indexSet = [item objectForKey: @"Indexes"];
     931        BOOL low = [torrent hasFilePriority: PRIORITY_LOW forIndexes: indexSet],
     932            normal = [torrent hasFilePriority: PRIORITY_NORMAL forIndexes: indexSet],
     933            high = [torrent hasFilePriority: PRIORITY_HIGH forIndexes: indexSet];
    950934       
    951935        if (low && !normal && !high)
     
    10271011   
    10281012    Torrent * torrent = [fTorrents objectAtIndex: 0];
    1029     NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
     1013    NSIndexSet * indexSet = [fFileOutline selectedRowIndexes], * itemIndexes;
     1014    NSMutableIndexSet * usedIndexes = [NSMutableIndexSet indexSet];
    10301015    int i;
    10311016    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    1032         [torrent setFileCheckState: state forFileItem: [fFileOutline itemAtRow: i]];
     1017    {
     1018        itemIndexes = [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"];
     1019        if (![usedIndexes containsIndexes: itemIndexes])
     1020        {
     1021            [torrent setFileCheckState: state forIndexes: itemIndexes];
     1022            [usedIndexes addIndexes: itemIndexes];
     1023        }
     1024    }
    10331025   
    10341026    [fFileOutline reloadData];
     
    10491041    int i;
    10501042    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    1051         [torrent setFilePriority: priority forFileItem: [fFileOutline itemAtRow: i]];
     1043        [torrent setFilePriority: priority forIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
    10521044   
    10531045    [fFileOutline reloadData];
  • branches/file_selection/macosx/Torrent.h

    r2080 r2088  
    5858    NSMutableString * fNameString, * fProgressString, * fStatusString, * fShortStatusString, * fRemainingTimeString;
    5959   
    60     NSArray * fFileList;
     60    NSArray * fFileList, * fFlatFileList;
    6161   
    6262    int     fUploadLimit, fDownloadLimit;
     
    205205- (int) fileCount;
    206206- (float) fileProgress: (int) index;
    207 - (int) checkForFile: (int) index;
    208 - (int) checkForFileFolder: (NSIndexSet *) indexSet;
    209 - (BOOL) canChangeDownloadCheckFile: (int) index;
    210 - (BOOL) canChangeDownloadCheckForFileFolder: (NSIndexSet *) indexSet;
    211 - (void) setFileCheckState: (int) state forFileItem: (NSDictionary *) item;
    212 - (void) setFilePriority: (int) priority forFileItem: (NSMutableDictionary *) item;
    213 - (BOOL) hasFilePriority: (int) priority forItem: (NSDictionary *) item;
     207- (int) checkForFiles: (NSIndexSet *) indexSet;
     208- (BOOL) canChangeDownloadCheckForFiles: (NSIndexSet *) indexSet;
     209- (void) setFileCheckState: (int) state forIndexes: (NSIndexSet *) indexSet;
     210- (void) setFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet;
     211- (BOOL) hasFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet;
    214212
    215213- (NSDate *) dateAdded;
  • branches/file_selection/macosx/Torrent.m

    r2087 r2088  
    5151- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
    5252            withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
    53             fileSize: (uint64_t) size index: (int) index priority: (int) priority;
     53            flatList: (NSMutableArray *) flatList fileSize: (uint64_t) size index: (int) index priority: (int) priority;
    5454- (NSImage *) advancedBar;
    5555- (void) trashFile: (NSString *) path;
     
    13181318}
    13191319
    1320 - (int) checkForFile: (int) index
    1321 {
    1322     return (tr_torrentGetFilePriority(fHandle, index) != TR_PRI_DND || [self fileProgress: index] >= 1.0)
    1323             ? NSOnState : NSOffState;
    1324 }
    1325 
    1326 - (int) checkForFileFolder: (NSIndexSet *) indexSet
     1320- (int) checkForFiles: (NSIndexSet *) indexSet
    13271321{
    13281322    BOOL onState = NO, offState = NO;
     
    13301324    for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
    13311325    {
    1332         if ([self checkForFile: index] == NSOnState)
     1326        if (tr_torrentGetFilePriority(fHandle, index) != TR_PRI_DND || [self fileProgress: index] >= 1.0)
    13331327            onState = YES;
    13341328        else
     
    13411335}
    13421336
    1343 - (BOOL) canChangeDownloadCheckFile: (int) index
    1344 {
    1345     return [self fileProgress: index] < 1.0;
    1346 }
    1347 
    1348 - (BOOL) canChangeDownloadCheckForFileFolder: (NSIndexSet *) indexSet
     1337- (BOOL) canChangeDownloadCheckForFiles: (NSIndexSet *) indexSet
    13491338{
    13501339    int index;
    13511340    for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
    1352         if ([self canChangeDownloadCheckFile: index])
     1341        if ([self fileProgress: index] < 1.0)
    13531342            return YES;
    13541343    return NO;
    13551344}
    13561345
    1357 - (void) setFileCheckState: (int) state forFileItem: (NSDictionary *) item
    1358 {
    1359     if (![[item objectForKey: @"IsFolder"] boolValue])
     1346- (void) setFileCheckState: (int) state forIndexes: (NSIndexSet *) indexSet
     1347{
     1348    int index;
     1349    for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
    13601350    {
    13611351        tr_priority_t actualPriority;
    13621352        if (state == NSOnState)
    13631353        {
    1364             int priority = [[item objectForKey: @"Priority"] intValue];
     1354            int priority = [[[fFlatFileList objectAtIndex: index] objectForKey: @"Priority"] intValue];
    13651355            if (priority == PRIORITY_HIGH)
    13661356                actualPriority = TR_PRI_HIGH;
     
    13731363            actualPriority = TR_PRI_DND;
    13741364       
    1375         tr_torrentSetFilePriority(fHandle, [[item objectForKey: @"Index"] intValue], actualPriority);
    1376     }
    1377     else
    1378     {
    1379         NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
    1380         NSDictionary * child;
    1381         while ((child = [enumerator nextObject]))
    1382             [self setFileCheckState: state forFileItem: child];
    1383     }
    1384 }
    1385 
    1386 - (void) setFilePriority: (int) priority forFileItem: (NSMutableDictionary *) item
    1387 {
    1388     if (![[item objectForKey: @"IsFolder"] boolValue])
    1389     {
    1390         [item setObject: [NSNumber numberWithInt: priority] forKey: @"Priority"];
    1391        
    1392         int index = [[item objectForKey: @"Index"] intValue];
    1393         if ([self checkForFile: index] == NSOnState)
     1365        tr_torrentSetFilePriority(fHandle, index, actualPriority);
     1366    }
     1367}
     1368
     1369- (void) setFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet
     1370{
     1371    NSNumber * priorityValue = [NSNumber numberWithInt: priority];
     1372   
     1373    int index;
     1374    for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
     1375    {
     1376        [[fFlatFileList objectAtIndex: index] setObject: priorityValue forKey: @"Priority"];
     1377       
     1378        if ([self checkForFiles: [NSIndexSet indexSetWithIndex: index]] == NSOnState)
    13941379        {
    13951380            tr_priority_t actualPriority;
     
    14031388        }
    14041389    }
    1405     else
    1406     {
    1407         NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
    1408         NSMutableDictionary * child;
    1409         while ((child = [enumerator nextObject]))
    1410             [self setFilePriority: priority forFileItem: child];
    1411     }
    1412 }
    1413 
    1414 - (BOOL) hasFilePriority: (int) priority forItem: (NSDictionary *) item
    1415 {
    1416     if (![[item objectForKey: @"IsFolder"] boolValue])
    1417         return priority == [[item objectForKey: @"Priority"] intValue];
    1418     else
    1419     {
    1420         NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
    1421         NSDictionary * child;
    1422         while ((child = [enumerator nextObject]))
    1423             if ([self hasFilePriority: priority forItem: child])
    1424                 return YES;
    1425         return NO;
    1426     }
     1390}
     1391
     1392- (BOOL) hasFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet
     1393{
     1394    int index;
     1395    for (index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index])
     1396        if (priority == [[[fFlatFileList objectAtIndex: index] objectForKey: @"Priority"] intValue])
     1397            return YES;
     1398    return NO;
    14271399}
    14281400
     
    16161588    tr_priority_t actualPriority;
    16171589   
    1618     NSMutableArray * fileList = [[NSMutableArray alloc] init];
     1590    NSMutableArray * fileList = [[NSMutableArray alloc] init],
     1591                    * flatFileList = [[NSMutableArray alloc] initWithCapacity: count];
    16191592   
    16201593    for (i = 0; i < count; i++)
     
    16331606        priority = filePriorities ? [[filePriorities objectAtIndex: i] intValue] : PRIORITY_NORMAL;
    16341607        [self insertPath: pathComponents forSiblings: fileList withParent: nil previousPath: path
    1635                 fileSize: file->length index: i priority: priority];
     1608                flatList: flatFileList fileSize: file->length index: i priority: priority];
    16361609        [pathComponents autorelease];
    16371610       
     
    16531626    fFileList = [[NSArray alloc] initWithArray: fileList];
    16541627    [fileList release];
     1628    fFlatFileList = [[NSArray alloc] initWithArray: flatFileList];
     1629    [flatFileList release];
    16551630}
    16561631
    16571632- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
    16581633        withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
    1659         fileSize: (uint64_t) size index: (int) index priority: (int) priority
     1634        flatList: (NSMutableArray *) flatList fileSize: (uint64_t) size index: (int) index priority: (int) priority
    16601635{
    16611636    NSString * name = [components objectAtIndex: 0];
     
    16871662        else
    16881663        {
    1689             [dict setObject: [NSNumber numberWithInt: index] forKey: @"Index"];
     1664            [dict setObject: [NSIndexSet indexSetWithIndex: index] forKey: @"Indexes"];
    16901665            [dict setObject: [NSNumber numberWithUnsignedLongLong: size] forKey: @"Size"];
    16911666            [dict setObject: [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]] forKey: @"Icon"];
    16921667            [dict setObject: [NSNumber numberWithInt: priority] forKey: @"Priority"];
     1668           
     1669            [flatList addObject: dict];
    16931670        }
    16941671       
     
    16971674    }
    16981675    else
    1699     {
    1700         if (isFolder)
    1701             [[dict objectForKey: @"Indexes"] addIndex: index];
    1702     }
     1676        [[dict objectForKey: @"Indexes"] addIndex: index];
    17031677   
    17041678    if (isFolder)
     
    17061680        [components removeObjectAtIndex: 0];
    17071681        [self insertPath: components forSiblings: [dict objectForKey: @"Children"]
    1708             withParent: dict previousPath: currentPath fileSize: size index: index priority: priority];
     1682            withParent: dict previousPath: currentPath flatList: flatList fileSize: size index: index priority: priority];
    17091683    }
    17101684}
  • branches/file_selection/macosx/TorrentCell.m

    r2087 r2088  
    118118    }
    119119   
    120    
    121    
    122120    [[NSColor colorWithDeviceWhite: 0.0 alpha: 0.2] set];
    123121    [NSBezierPath strokeRect: NSInsetRect(barBounds, 0.5, 0.5)];
Note: See TracChangeset for help on using the changeset viewer.