Changeset 2010


Ignore:
Timestamp:
Jun 9, 2007, 8:44:55 PM (15 years ago)
Author:
livings124
Message:

getting closer to working file selection gui...now it's a bit more dynamic and accurate, might be a bit slower in theory, though

Location:
branches/file_selection
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/file_selection/libtransmission/torrent.c

    r2005 r2010  
    600600}
    601601
     602/* !!!!!!!!!! ADD ABILITY TO DO FOR INDIVIDUAL FILES !!!!!!!!!!!!!! */
    602603float * tr_torrentCompletion( tr_torrent_t * tor )
    603604{
  • branches/file_selection/macosx/FileBrowserCell.h

    r1644 r2010  
    2727@interface FileBrowserCell : NSBrowserCell
    2828{
     29    float fPercent;
    2930}
    3031
     32- (void) setProgress: (float) progress;
     33
    3134@end
  • branches/file_selection/macosx/FileBrowserCell.m

    r1644 r2010  
    4040    [image setScalesWhenResized: YES];
    4141    [super setImage: image];
     42}
     43
     44- (void) setProgress: (float) progress
     45{
     46    fPercent = progress * 100.0;
    4247}
    4348
     
    8691       
    8792        NSString * statusString = [NSString stringWithFormat: NSLocalizedString(@"%.2f%% of %@",
    88                                                                 "Inspector -> Files tab -> file status string"),
    89                                     100.0 * [[item objectForKey: @"Progress"] floatValue],
     93                                    "Inspector -> Files tab -> file status string"), fPercent,
    9094                                    [NSString stringForFileSize: [[item objectForKey: @"Size"] unsignedLongLongValue]]];
    9195       
  • branches/file_selection/macosx/InfoWindowController.m

    r2008 r2010  
    2424
    2525#import "InfoWindowController.h"
     26#import "FileBrowserCell.h"
    2627#import "StringAdditions.h"
    2728
     
    429430- (void) updateInfoFiles
    430431{
    431     if ([fTorrents count] != 1)
    432         return;
    433    
    434     if ([[fTorrents objectAtIndex: 0] updateFileProgress])
     432    if ([fTorrents count] == 1)
    435433        [fFileOutline reloadData];
    436434}
     
    796794   
    797795    if ([[tableColumn identifier] isEqualToString: @"Check"])
    798         return [item objectForKey: @"Check"];
     796        return [NSNumber numberWithInt: [[fTorrents objectAtIndex: 0] shouldDownloadItem: item]];
    799797    else
    800798        return item;
     
    809807            return;
    810808       
    811         [cell setImage: [[item objectForKey: @"IsFolder"] boolValue] ? fFolderIcon : [item objectForKey: @"Icon"]];
     809        BOOL isFolder;
     810        #warning move folder icon into FileBrowserCell
     811        if ((isFolder = [[item objectForKey: @"IsFolder"] boolValue]))
     812            [cell setImage: fFolderIcon];
     813        else
     814        {
     815            [cell setImage: [item objectForKey: @"Icon"]];
     816            [(FileBrowserCell *)cell setProgress: [[fTorrents objectAtIndex: 0] fileProgress:
     817                                                    [[item objectForKey: @"Index"] floatValue]]];
     818        }
    812819    }
    813820    else if ([[tableColumn identifier] isEqualToString: @"Check"])
     
    821828       
    822829        [(NSButtonCell *)cell setImagePosition: NSImageOnly];
    823         [cell setEnabled: [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Remaining"] intValue] > 0
    824                                                                     : [[item objectForKey: @"Progress"] floatValue] < 1.0];
     830        [cell setEnabled: [[fTorrents objectAtIndex: 0] canChangeDownloadItemCheck: item]];
    825831    }
    826832    else;
     
    834840   
    835841    [torrent setFileCheckState: state forFileItem: item];
    836     NSMutableDictionary * topItem = [torrent resetFileCheckStateForItemParent: item];
    837    
    838     [fFileOutline reloadItem: topItem reloadChildren: YES];
     842    [fFileOutline reloadData];
    839843}
    840844
  • branches/file_selection/macosx/Torrent.h

    r1972 r2010  
    5454    NSMutableString * fNameString, * fProgressString, * fStatusString, * fShortStatusString, * fRemainingTimeString;
    5555   
    56     NSArray * fFileList, * fFileFlatList;
     56    NSArray * fFileList;
    5757   
    5858    int     fUploadLimit, fDownloadLimit;
     
    202202- (NSArray *) fileList;
    203203- (int) fileCount;
    204 - (BOOL) updateFileProgress;
    205 - (void) setFileCheckState: (int) state forFileItem: (NSMutableDictionary *) item;
    206 - (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild;
     204- (float) fileProgress: (int) index;
     205- (int) shouldDownloadItem: (NSDictionary *) item;
     206- (BOOL) canChangeDownloadItemCheck: (NSDictionary *) item;
     207- (void) setFileCheckState: (int) state forFileItem: (NSDictionary *) item;
    207208
    208209- (NSDate *) dateAdded;
  • branches/file_selection/macosx/Torrent.m

    r2008 r2010  
    4949- (void) createFileListShouldDownload: (NSArray *) filesShouldDownload priorities: (NSArray *) filePriorities;
    5050- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
    51         withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
    52         fileSize: (uint64_t) size state: (int) state flatList: (NSMutableArray *) flatList;
     51            withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
     52            fileSize: (uint64_t) size index: (int) index;
    5353- (NSImage *) advancedBar;
    5454- (void) trashFile: (NSString *) path;
     
    175175                    nil];
    176176   
    177     NSMutableArray * filesShouldDownload = [NSMutableArray arrayWithCapacity: [fFileFlatList count]];
    178     NSEnumerator * enumerator = [fFileFlatList objectEnumerator];
    179     NSDictionary * file;
    180     while ((file = [enumerator nextObject]))
    181         [filesShouldDownload addObject: [file objectForKey: @"Check"]];
     177    //set file priorities
     178    int fileCount = [self fileCount];
     179    NSMutableArray * filesShouldDownload = [NSMutableArray arrayWithCapacity: fileCount];
     180   
     181    tr_priority_t * priorities = tr_torrentGetFilePriorities(fHandle);
     182    int i;
     183    for (i = 0; i < fileCount; i++)
     184        [filesShouldDownload addObject: [NSNumber numberWithInt: priorities[i]]];
     185    free(priorities);
    182186    [history setObject: filesShouldDownload forKey: @"FilesShouldDownload"];
    183187   
     
    237241       
    238242        [fFileList release];
    239         [fFileFlatList release];
    240243       
    241244        [fBitmap release];
     
    13031306}
    13041307
    1305 - (BOOL) updateFileProgress
    1306 {
    1307     BOOL change = NO;
     1308- (float) fileProgress: (int) index
     1309{
     1310    #warning redo for single
    13081311    float * progress = tr_torrentCompletion(fHandle);
    1309     NSNumber * progressNum;
    1310     NSMutableDictionary * item, * dict;
    1311    
    1312     int i, fileCount = [self fileCount];
    1313     for (i = 0; i < fileCount; i++)
    1314     {
    1315         if (!(progressNum = [[fFileFlatList objectAtIndex: i] objectForKey: @"Progress"])
    1316                 || [progressNum floatValue] != progress[i])
    1317         {
    1318             item = [fFileFlatList objectAtIndex: i];
    1319             [item setObject: [NSNumber numberWithFloat: progress[i]] forKey: @"Progress"];
    1320             change = YES;
    1321            
    1322             if (progress[i] == 1.0)
    1323             {
    1324                 dict = item;
    1325                 while ((dict = [dict objectForKey: @"Parent"]))
    1326                     [dict setObject: [NSNumber numberWithInt: [[dict objectForKey: @"Remaining"] intValue]-1]
    1327                             forKey: @"Remaining"];
    1328                
    1329                 [item setObject: [NSNumber numberWithInt: NSOnState] forKey: @"Check"];
    1330                 [self resetFileCheckStateForItemParent: item];
    1331             }
    1332         }
    1333     }
    1334    
     1312    float fileProgress = progress[index];
    13351313    free(progress);
    13361314   
    1337     return change;
    1338 }
    1339 
    1340 - (void) setFileCheckState: (int) state forFileItem: (NSMutableDictionary *) item
    1341 {
    1342     [item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
    1343    
     1315    return fileProgress;
     1316}
     1317
     1318- (int) shouldDownloadItem: (NSDictionary *) item
     1319{
     1320    if ([[item objectForKey: @"IsFolder"] boolValue])
     1321    {
     1322        #warning do
     1323        return NSOnState;
     1324    }
     1325    else
     1326    {
     1327        int index = [[item objectForKey: @"Index"] intValue];
     1328        return tr_torrentGetFilePriority(fHandle, index) != TR_PRI_DND || [self fileProgress: index] >= 1.0
     1329                ? NSOnState : NSOffState;
     1330    }
     1331}
     1332
     1333- (BOOL) canChangeDownloadItemCheck: (NSDictionary *) item
     1334{
     1335    if ([[item objectForKey: @"IsFolder"] boolValue])
     1336    {
     1337        #warning do
     1338        return YES;
     1339    }
     1340    else
     1341    {
     1342        #warning why is this happening?
     1343        float progress = [self fileProgress: [[item objectForKey: @"Index"] intValue]];
     1344        if (progress < 1.0)
     1345            NSLog(@"hi %f", progress);
     1346        else
     1347            NSLog(@"asdgagh %f", progress);
     1348        return [self fileProgress: [[item objectForKey: @"Index"] intValue]] < 1.0;
     1349    }
     1350}
     1351
     1352- (void) setFileCheckState: (int) state forFileItem: (NSDictionary *) item
     1353{
    13441354    if (![[item objectForKey: @"IsFolder"] boolValue])
    1345         return;
    1346    
    1347     NSMutableDictionary * child;
    1348     NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
    1349     while ((child = [enumerator nextObject]))
    1350         if (state != [[child objectForKey: @"Check"] intValue])
     1355        tr_torrentSetFilePriority(fHandle, [[item objectForKey: @"Index"] intValue],
     1356                                    state == NSOnState ? TR_PRI_NORMAL : TR_PRI_DND);
     1357    else
     1358    {
     1359        NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
     1360        NSDictionary * child;
     1361        while ((child = [enumerator nextObject]))
    13511362            [self setFileCheckState: state forFileItem: child];
    1352 }
    1353 
    1354 - (NSMutableDictionary *) resetFileCheckStateForItemParent: (NSMutableDictionary *) originalChild
    1355 {
    1356     NSMutableDictionary * item;
    1357     if (!(item = [originalChild objectForKey: @"Parent"]))
    1358         return originalChild;
    1359    
    1360     int state = INVALID;
    1361    
    1362     NSMutableDictionary * child;
    1363     NSEnumerator * enumerator = [[item objectForKey: @"Children"] objectEnumerator];
    1364     while ((child = [enumerator nextObject]))
    1365     {
    1366         if (state == INVALID)
    1367         {
    1368             state = [[child objectForKey: @"Check"] intValue];
    1369             if (state == NSMixedState)
    1370                 break;
    1371         }
    1372         else if (state != [[child objectForKey: @"Check"] intValue])
    1373         {
    1374             state = NSMixedState;
    1375             break;
    1376         }
    1377         else;
    1378     }
    1379    
    1380     if (state != [[item objectForKey: @"Check"] intValue])
    1381     {
    1382         [item setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
    1383         return [self resetFileCheckStateForItemParent: item];
    1384     }
    1385     else
    1386         return originalChild;
     1363    }
    13871364}
    13881365
     
    15751552    int shouldDownload;
    15761553   
    1577     NSMutableArray * fileList = [[NSMutableArray alloc] init],
    1578                     * fileFlatList = [[NSMutableArray alloc] initWithCapacity: count];
     1554    NSMutableArray * fileList = [[NSMutableArray alloc] init];
    15791555   
    15801556    for (i = 0; i < count; i++)
     
    15901566        else
    15911567            path = @"";
     1568       
     1569        [self insertPath: pathComponents forSiblings: fileList withParent: nil previousPath: path
     1570                fileSize: file->length index: i];
     1571        [pathComponents autorelease];
    15921572       
    15931573        shouldDownload = filesShouldDownload ? [[filesShouldDownload objectAtIndex: i] intValue] : NSOnState;
    15941574        #warning add priorities
    15951575        tr_torrentSetFilePriority(fHandle, i, shouldDownload == NSOnState ? TR_PRI_NORMAL : TR_PRI_DND);
    1596        
    1597         [self insertPath: pathComponents forSiblings: fileList withParent: nil previousPath: path
    1598                 fileSize: file->length state: shouldDownload flatList: fileFlatList];
    1599         [pathComponents autorelease];
    16001576    }
    16011577   
    16021578    fFileList = [[NSArray alloc] initWithArray: fileList];
    16031579    [fileList release];
    1604     fFileFlatList = [[NSArray alloc] initWithArray: fileFlatList];
    1605     [fileFlatList release];
    16061580}
    16071581
    16081582- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
    16091583        withParent: (NSMutableDictionary *) parent previousPath: (NSString *) previousPath
    1610         fileSize: (uint64_t) size state: (int) state flatList: (NSMutableArray *) flatList
     1584        fileSize: (uint64_t) size index: (int) index
    16111585{
    16121586    NSString * name = [components objectAtIndex: 0];
     
    16341608        {
    16351609            [dict setObject: [NSMutableArray array] forKey: @"Children"];
    1636             [dict setObject: [NSNumber numberWithInt: 1] forKey: @"Remaining"];
    16371610        }
    16381611        else
    16391612        {
    1640             [flatList addObject: dict];
     1613            [dict setObject: [NSNumber numberWithInt: index] forKey: @"Index"];
    16411614            [dict setObject: [NSNumber numberWithUnsignedLongLong: size] forKey: @"Size"];
    16421615            [dict setObject: [[NSWorkspace sharedWorkspace] iconForFileType: [name pathExtension]] forKey: @"Icon"];
     
    16451618        if (parent)
    16461619            [dict setObject: parent forKey: @"Parent"];
    1647         [dict setObject: [NSNumber numberWithInt: state] forKey: @"Check"];
    16481620    }
    16491621    else
     
    16511623        if (isFolder)
    16521624            [dict setObject: [NSNumber numberWithInt: [[dict objectForKey: @"Remaining"] intValue]+1] forKey: @"Remaining"];
    1653        
    1654         int dictState = [[dict objectForKey: @"Check"] intValue];
    1655         if (dictState != NSMixedState && dictState != state)
    1656             [dict setObject: [NSNumber numberWithInt: NSMixedState] forKey: @"Check"];
    16571625    }
    16581626   
     
    16611629        [components removeObjectAtIndex: 0];
    16621630        [self insertPath: components forSiblings: [dict objectForKey: @"Children"]
    1663             withParent: dict previousPath: currentPath fileSize: size state: state flatList: flatList];
     1631            withParent: dict previousPath: currentPath fileSize: size index: index];
    16641632    }
    16651633}
Note: See TracChangeset for help on using the changeset viewer.