Changeset 885


Ignore:
Timestamp:
Sep 22, 2006, 3:40:12 AM (15 years ago)
Author:
livings124
Message:

get rid of annoying warning

Location:
branches/nat-traversal
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/nat-traversal/Transmission.xcodeproj/project.pbxproj

    r871 r885  
    281281                4DCCBB3C09C3D71100D3CABF /* TorrentCell.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = TorrentCell.m; path = macosx/TorrentCell.m; sourceTree = "<group>"; };
    282282                4DCCBB3D09C3D71100D3CABF /* TorrentCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = TorrentCell.h; path = macosx/TorrentCell.h; sourceTree = "<group>"; };
    283                 4DDBB71909E16BAE00284745 /* transmissioncli */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = transmissioncli; sourceTree = BUILT_PRODUCTS_DIR; };
     283                4DDBB71909E16BAE00284745 /* transmissioncli */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = transmissioncli; sourceTree = BUILT_PRODUCTS_DIR; };
    284284                4DDBB71B09E16BF100284745 /* transmissioncli.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = transmissioncli.c; path = cli/transmissioncli.c; sourceTree = "<group>"; };
    285285                4DDFDD20099A5D8E00189D81 /* DownloadBadge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = DownloadBadge.png; path = macosx/Images/DownloadBadge.png; sourceTree = "<group>"; };
  • branches/nat-traversal/macosx/Torrent.m

    r884 r885  
    316316}
    317317
     318- (void) startTransfer
     319{
     320    if (![self isActive])
     321    {
     322        tr_torrentStart(fHandle);
     323
     324        fFinishedSeeding = NO;
     325        fWaitToStart = NO;
     326    }
     327}
     328
     329- (void) stopTransfer
     330{
     331    if ([self isActive])
     332    {
     333        BOOL wasSeeding = [self isSeeding];
     334   
     335        tr_torrentStop(fHandle);
     336
     337        if (!wasSeeding)
     338            [[NSNotificationCenter defaultCenter] postNotificationName: @"StoppedDownloading" object: self];
     339    }
     340}
     341
     342- (void) stopTransferForQuit
     343{
     344    if ([self isActive])
     345        tr_torrentStop(fHandle);
     346}
     347
     348- (void) removeForever
     349{
     350    if (fPrivateTorrent)
     351        tr_torrentRemoveSaved(fHandle);
     352}
     353
     354- (void) sleep
     355{
     356    if ((fResumeOnWake = [self isActive]))
     357        tr_torrentStop(fHandle);
     358}
     359
     360- (void) wakeUp
     361{
     362    if (fResumeOnWake)
     363        tr_torrentStart(fHandle);
     364}
     365
     366- (float) ratio
     367{
     368    float downloaded = [self downloadedTotal];
     369    return downloaded > 0 ? (float)[self uploadedTotal] / downloaded : -1;
     370}
     371
     372- (int) stopRatioSetting
     373{
     374        return fStopRatioSetting;
     375}
     376
     377- (void) setStopRatioSetting: (int) setting
     378{
     379    fStopRatioSetting = setting;
     380}
     381
     382- (float) ratioLimit
     383{
     384    return fRatioLimit;
     385}
     386
     387- (void) setRatioLimit: (float) limit
     388{
     389    if (limit >= 0)
     390        fRatioLimit = limit;
     391}
     392
     393- (void) setWaitToStart: (BOOL) wait
     394{
     395    fWaitToStart = wait;
     396}
     397
     398- (BOOL) waitingToStart
     399{
     400    return fWaitToStart;
     401}
     402
     403- (void) revealData
     404{
     405    [[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] inFileViewerRootedAtPath: nil];
     406}
     407
     408- (void) trashData
     409{
     410    [self trashFile: [self dataLocation]];
     411}
     412
     413- (void) trashTorrent
     414{
     415    if (fPublicTorrent)
     416        [self trashFile: [self publicTorrentLocation]];
     417}
     418
     419- (NSImage *) icon
     420{
     421    return fIcon;
     422}
     423
     424- (NSImage *) iconFlipped
     425{
     426    return fIconFlipped;
     427}
     428
     429- (NSImage *) iconSmall
     430{
     431    return fIconSmall;
     432}
     433
     434- (NSString *) name
     435{
     436    return [NSString stringWithUTF8String: fInfo->name];
     437}
     438
     439- (uint64_t) size
     440{
     441    return fInfo->totalSize;
     442}
     443
     444- (NSString *) tracker
     445{
     446    return [NSString stringWithFormat: @"%s:%d", fInfo->trackerAddress, fInfo->trackerPort];
     447}
     448
     449- (NSString *) announce
     450{
     451    return [NSString stringWithUTF8String: fInfo->trackerAnnounce];
     452}
     453
     454- (int) pieceSize
     455{
     456    return fInfo->pieceSize;
     457}
     458
     459- (int) pieceCount
     460{
     461    return fInfo->pieceCount;
     462}
     463
     464- (NSString *) hashString
     465{
     466    return [NSString stringWithUTF8String: fInfo->hashString];
     467}
     468
     469- (NSString *) torrentLocation
     470{
     471    return [NSString stringWithUTF8String: fInfo->torrent];
     472}
     473
     474- (NSString *) publicTorrentLocation
     475{
     476    return fPublicTorrentLocation;
     477}
     478
     479- (NSString *) torrentLocationString
     480{
     481    return fPrivateTorrent ? @"Transmission Support Folder" : [fPublicTorrentLocation stringByAbbreviatingWithTildeInPath];
     482}
     483
     484- (NSString *) dataLocation
     485{
     486    return [[self downloadFolder] stringByAppendingPathComponent: [self name]];
     487}
     488
     489- (BOOL) publicTorrent
     490{
     491    return fPublicTorrent;
     492}
     493
     494- (BOOL) privateTorrent
     495{
     496    return fPrivateTorrent;
     497}
     498
     499- (NSString *) stateString
     500{
     501    switch( fStat->status )
     502    {
     503        case TR_STATUS_PAUSE:
     504            return @"Paused";
     505            break;
     506
     507        case TR_STATUS_CHECK:
     508            return [@"Checking existing files" stringByAppendingEllipsis];
     509            break;
     510
     511        case TR_STATUS_DOWNLOAD:
     512            return @"Downloading";
     513            break;
     514
     515        case TR_STATUS_SEED:
     516            return @"Seeding";
     517            break;
     518
     519        case TR_STATUS_STOPPING:
     520            return [@"Stopping" stringByAppendingEllipsis];
     521            break;
     522       
     523        default:
     524            return @"N/A";
     525    }
     526}
     527
     528- (float) progress
     529{
     530    return fStat->progress;
     531}
     532
     533- (int) eta
     534{
     535    return fStat->eta;
     536}
     537
     538- (BOOL) isActive
     539{
     540    return fStat->status & TR_STATUS_ACTIVE;
     541}
     542
     543- (BOOL) isSeeding
     544{
     545    return fStat->status == TR_STATUS_SEED;
     546}
     547
     548- (BOOL) isPaused
     549{
     550    return fStat->status == TR_STATUS_PAUSE;
     551}
     552
     553- (BOOL) isError
     554{
     555    return fStat->error & TR_ETRACKER;
     556}
     557
     558- (BOOL) justFinished
     559{
     560    return tr_getFinished(fHandle);
     561}
     562
     563- (NSArray *) peers
     564{
     565    int totalPeers, i;
     566    tr_peer_stat_t * peers = tr_torrentPeers(fHandle, & totalPeers);
     567   
     568    NSMutableArray * peerDics = [NSMutableArray arrayWithCapacity: totalPeers];
     569    tr_peer_stat_t peer;
     570    NSString * client;
     571    for (i = 0; i < totalPeers; i++)
     572    {
     573        peer = peers[i];
     574        [peerDics addObject: [NSDictionary dictionaryWithObjectsAndKeys:
     575            [NSNumber numberWithBool: peer.isConnected], @"Connected",
     576            [NSString stringWithCString: (char *) peer.addr encoding: NSUTF8StringEncoding], @"IP",
     577            [NSString stringWithCString: (char *) peer.client encoding: NSUTF8StringEncoding], @"Client",
     578            [NSNumber numberWithBool: peer.isDownloading], @"UL To",
     579            [NSNumber numberWithBool: peer.isUploading], @"DL From", nil]];
     580    }
     581   
     582    tr_torrentPeersFree(peers, totalPeers);
     583   
     584    return peerDics;
     585}
     586
     587- (NSString *) progressString
     588{
     589    return fProgressString;
     590}
     591
     592- (NSString *) statusString
     593{
     594    return fStatusString;
     595}
     596
     597- (NSString *) shortStatusString
     598{
     599    return fShortStatusString;
     600}
     601
     602- (NSString *) remainingTimeString
     603{
     604    return fRemainingTimeString;
     605}
     606
     607- (int) seeders
     608{
     609    return fStat->seeders;
     610}
     611
     612- (int) leechers
     613{
     614    return fStat->leechers;
     615}
     616
     617- (int) totalPeers
     618{
     619    return fStat->peersTotal;
     620}
     621
     622//peers uploading to you
     623- (int) peersUploading
     624{
     625    return fStat->peersUploading;
     626}
     627
     628//peers downloading from you
     629- (int) peersDownloading
     630{
     631    return fStat->peersDownloading;
     632}
     633
     634- (float) downloadRate
     635{
     636    return fStat->rateDownload;
     637}
     638
     639- (float) uploadRate
     640{
     641    return fStat->rateUpload;
     642}
     643
     644- (float) downloadedValid
     645{
     646    return [self progress] * [self size];
     647}
     648
     649- (uint64_t) downloadedTotal
     650{
     651    return fStat->downloaded;
     652}
     653
     654- (uint64_t) uploadedTotal
     655{
     656    return fStat->uploaded;
     657}
     658
     659- (float) swarmSpeed
     660{
     661    return fStat->swarmspeed;
     662}
     663
     664- (NSNumber *) orderValue
     665{
     666    return [NSNumber numberWithInt: fOrderValue];
     667}
     668
     669- (void) setOrderValue: (int) orderValue
     670{
     671    fOrderValue = orderValue;
     672}
     673
     674- (NSArray *) fileList
     675{
     676    int count = fInfo->fileCount, i;
     677    tr_file_t file;
     678    NSMutableArray * files = [NSMutableArray arrayWithCapacity: count];
     679   
     680    for (i = 0; i < count; i++)
     681    {
     682        file = fInfo->files[i];
     683        [files addObject: [NSDictionary dictionaryWithObjectsAndKeys:
     684            [[self downloadFolder] stringByAppendingPathComponent: [NSString stringWithUTF8String: file.name]], @"Name",
     685            [NSNumber numberWithUnsignedLongLong: file.length], @"Size", nil]];
     686    }
     687   
     688    return files;
     689}
     690
     691- (NSDate *) date
     692{
     693    return fDate;
     694}
     695
     696- (NSNumber *) stateSortKey
     697{
     698    if (![self isActive])
     699        return [NSNumber numberWithInt: 0];
     700    else if ([self isSeeding])
     701        return [NSNumber numberWithInt: 1];
     702    else
     703        return [NSNumber numberWithInt: 2];
     704}
     705
     706- (NSNumber *) progressSortKey
     707{
     708    //if finished downloading sort by ratio instead of progress
     709    float progress = [self progress];
     710    return [NSNumber numberWithFloat: progress < 1.0 ? progress : 2.0 + [self ratio]];
     711}
     712
     713@end
     714
     715
     716@implementation Torrent (Private)
     717
     718//if a hash is given, attempt to load that; otherwise, attempt to open file at path
     719- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
     720        privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent
     721        date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
     722        ratioLimit: (NSNumber *) ratioLimit waitToStart: (NSNumber *) waitToStart
     723        orderValue: (NSNumber *) orderValue
     724{
     725    if (!(self = [super init]))
     726        return nil;
     727
     728    fLib = lib;
     729    fDefaults = [NSUserDefaults standardUserDefaults];
     730
     731    fPrivateTorrent = privateTorrent ? [privateTorrent boolValue] : [fDefaults boolForKey: @"SavePrivateTorrent"];
     732    fPublicTorrent = !fPrivateTorrent || (publicTorrent ? [publicTorrent boolValue]
     733                                            : ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);
     734
     735    int error;
     736    if (fPrivateTorrent && hashString)
     737        fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FSAVEPRIVATE, & error);
     738   
     739    if (!fHandle && path)
     740        fHandle = tr_torrentInit(fLib, [path UTF8String], fPrivateTorrent ? TR_FSAVEPRIVATE : 0, & error);
     741
     742    if (!fHandle)
     743    {
     744        [self release];
     745        return nil;
     746    }
     747   
     748    fInfo = tr_torrentInfo( fHandle );
     749
     750    if (fPublicTorrent)
     751        fPublicTorrentLocation = [path retain];
     752
     753    fDate = date ? [date retain] : [[NSDate alloc] init];
     754   
     755    fStopRatioSetting = stopRatioSetting ? [stopRatioSetting intValue] : -1;
     756    fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"];
     757    fFinishedSeeding = NO;
     758   
     759    fWaitToStart = waitToStart ? [waitToStart boolValue] : [fDefaults boolForKey: @"StartAtOpen"];
     760    fOrderValue = orderValue ? [orderValue intValue] : tr_torrentCount(fLib) - 1;
     761   
     762    NSString * fileType = fInfo->multifile ? NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension];
     763    fIcon = [[NSWorkspace sharedWorkspace] iconForFileType: fileType];
     764    [fIcon retain];
     765   
     766    fIconFlipped = [fIcon copy];
     767    [fIconFlipped setFlipped: YES];
     768   
     769    fIconSmall = [fIconFlipped copy];
     770    [fIconSmall setScalesWhenResized: YES];
     771    [fIconSmall setSize: NSMakeSize(16.0, 16.0)];
     772
     773    fProgressString = [[NSMutableString alloc] initWithCapacity: 50];
     774    fStatusString = [[NSMutableString alloc] initWithCapacity: 75];
     775    fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30];
     776    fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30];
     777
     778    [self update];
     779    return self;
     780}
     781
    318782- (NSImage *) advancedBar
    319783{
     
    393857}
    394858
    395 - (void) startTransfer
    396 {
    397     if (![self isActive])
    398     {
    399         tr_torrentStart(fHandle);
    400 
    401         fFinishedSeeding = NO;
    402         fWaitToStart = NO;
    403     }
    404 }
    405 
    406 - (void) stopTransfer
    407 {
    408     if ([self isActive])
    409     {
    410         BOOL wasSeeding = [self isSeeding];
    411    
    412         tr_torrentStop(fHandle);
    413 
    414         if (!wasSeeding)
    415             [[NSNotificationCenter defaultCenter] postNotificationName: @"StoppedDownloading" object: self];
    416     }
    417 }
    418 
    419 - (void) stopTransferForQuit
    420 {
    421     if ([self isActive])
    422         tr_torrentStop(fHandle);
    423 }
    424 
    425 - (void) removeForever
    426 {
    427     if (fPrivateTorrent)
    428         tr_torrentRemoveSaved(fHandle);
    429 }
    430 
    431 - (void) sleep
    432 {
    433     if ((fResumeOnWake = [self isActive]))
    434         tr_torrentStop(fHandle);
    435 }
    436 
    437 - (void) wakeUp
    438 {
    439     if (fResumeOnWake)
    440         tr_torrentStart(fHandle);
    441 }
    442 
    443 - (float) ratio
    444 {
    445     float downloaded = [self downloadedTotal];
    446     return downloaded > 0 ? (float)[self uploadedTotal] / downloaded : -1;
    447 }
    448 
    449 - (int) stopRatioSetting
    450 {
    451         return fStopRatioSetting;
    452 }
    453 
    454 - (void) setStopRatioSetting: (int) setting
    455 {
    456     fStopRatioSetting = setting;
    457 }
    458 
    459 - (float) ratioLimit
    460 {
    461     return fRatioLimit;
    462 }
    463 
    464 - (void) setRatioLimit: (float) limit
    465 {
    466     if (limit >= 0)
    467         fRatioLimit = limit;
    468 }
    469 
    470 - (void) setWaitToStart: (BOOL) wait
    471 {
    472     fWaitToStart = wait;
    473 }
    474 
    475 - (BOOL) waitingToStart
    476 {
    477     return fWaitToStart;
    478 }
    479 
    480 - (void) revealData
    481 {
    482     [[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] inFileViewerRootedAtPath: nil];
    483 }
    484 
    485 - (void) trashData
    486 {
    487     [self trashFile: [self dataLocation]];
    488 }
    489 
    490 - (void) trashTorrent
    491 {
    492     if (fPublicTorrent)
    493         [self trashFile: [self publicTorrentLocation]];
    494 }
    495 
    496 - (NSImage *) icon
    497 {
    498     return fIcon;
    499 }
    500 
    501 - (NSImage *) iconFlipped
    502 {
    503     return fIconFlipped;
    504 }
    505 
    506 - (NSImage *) iconSmall
    507 {
    508     return fIconSmall;
    509 }
    510 
    511 - (NSString *) name
    512 {
    513     return [NSString stringWithUTF8String: fInfo->name];
    514 }
    515 
    516 - (uint64_t) size
    517 {
    518     return fInfo->totalSize;
    519 }
    520 
    521 - (NSString *) tracker
    522 {
    523     return [NSString stringWithFormat: @"%s:%d", fInfo->trackerAddress, fInfo->trackerPort];
    524 }
    525 
    526 - (NSString *) announce
    527 {
    528     return [NSString stringWithUTF8String: fInfo->trackerAnnounce];
    529 }
    530 
    531 - (int) pieceSize
    532 {
    533     return fInfo->pieceSize;
    534 }
    535 
    536 - (int) pieceCount
    537 {
    538     return fInfo->pieceCount;
    539 }
    540 
    541 - (NSString *) hashString
    542 {
    543     return [NSString stringWithUTF8String: fInfo->hashString];
    544 }
    545 
    546 - (NSString *) torrentLocation
    547 {
    548     return [NSString stringWithUTF8String: fInfo->torrent];
    549 }
    550 
    551 - (NSString *) publicTorrentLocation
    552 {
    553     return fPublicTorrentLocation;
    554 }
    555 
    556 - (NSString *) torrentLocationString
    557 {
    558     return fPrivateTorrent ? @"Transmission Support Folder" : [fPublicTorrentLocation stringByAbbreviatingWithTildeInPath];
    559 }
    560 
    561 - (NSString *) dataLocation
    562 {
    563     return [[self downloadFolder] stringByAppendingPathComponent: [self name]];
    564 }
    565 
    566 - (BOOL) publicTorrent
    567 {
    568     return fPublicTorrent;
    569 }
    570 
    571 - (BOOL) privateTorrent
    572 {
    573     return fPrivateTorrent;
    574 }
    575 
    576 - (NSString *) stateString
    577 {
    578     switch( fStat->status )
    579     {
    580         case TR_STATUS_PAUSE:
    581             return @"Paused";
    582             break;
    583 
    584         case TR_STATUS_CHECK:
    585             return [@"Checking existing files" stringByAppendingEllipsis];
    586             break;
    587 
    588         case TR_STATUS_DOWNLOAD:
    589             return @"Downloading";
    590             break;
    591 
    592         case TR_STATUS_SEED:
    593             return @"Seeding";
    594             break;
    595 
    596         case TR_STATUS_STOPPING:
    597             return [@"Stopping" stringByAppendingEllipsis];
    598             break;
    599        
    600         default:
    601             return @"N/A";
    602     }
    603 }
    604 
    605 - (float) progress
    606 {
    607     return fStat->progress;
    608 }
    609 
    610 - (int) eta
    611 {
    612     return fStat->eta;
    613 }
    614 
    615 - (BOOL) isActive
    616 {
    617     return fStat->status & TR_STATUS_ACTIVE;
    618 }
    619 
    620 - (BOOL) isSeeding
    621 {
    622     return fStat->status == TR_STATUS_SEED;
    623 }
    624 
    625 - (BOOL) isPaused
    626 {
    627     return fStat->status == TR_STATUS_PAUSE;
    628 }
    629 
    630 - (BOOL) isError
    631 {
    632     return fStat->error & TR_ETRACKER;
    633 }
    634 
    635 - (BOOL) justFinished
    636 {
    637     return tr_getFinished(fHandle);
    638 }
    639 
    640 - (NSArray *) peers
    641 {
    642     int totalPeers, i;
    643     tr_peer_stat_t * peers = tr_torrentPeers(fHandle, & totalPeers);
    644    
    645     NSMutableArray * peerDics = [NSMutableArray arrayWithCapacity: totalPeers];
    646     tr_peer_stat_t peer;
    647     NSString * client;
    648     for (i = 0; i < totalPeers; i++)
    649     {
    650         peer = peers[i];
    651         [peerDics addObject: [NSDictionary dictionaryWithObjectsAndKeys:
    652             [NSNumber numberWithBool: peer.isConnected], @"Connected",
    653             [NSString stringWithCString: (char *) peer.addr encoding: NSUTF8StringEncoding], @"IP",
    654             [NSString stringWithCString: (char *) peer.client encoding: NSUTF8StringEncoding], @"Client",
    655             [NSNumber numberWithBool: peer.isDownloading], @"UL To",
    656             [NSNumber numberWithBool: peer.isUploading], @"DL From", nil]];
    657     }
    658    
    659     tr_torrentPeersFree(peers, totalPeers);
    660    
    661     return peerDics;
    662 }
    663 
    664 - (NSString *) progressString
    665 {
    666     return fProgressString;
    667 }
    668 
    669 - (NSString *) statusString
    670 {
    671     return fStatusString;
    672 }
    673 
    674 - (NSString *) shortStatusString
    675 {
    676     return fShortStatusString;
    677 }
    678 
    679 - (NSString *) remainingTimeString
    680 {
    681     return fRemainingTimeString;
    682 }
    683 
    684 - (int) seeders
    685 {
    686     return fStat->seeders;
    687 }
    688 
    689 - (int) leechers
    690 {
    691     return fStat->leechers;
    692 }
    693 
    694 - (int) totalPeers
    695 {
    696     return fStat->peersTotal;
    697 }
    698 
    699 //peers uploading to you
    700 - (int) peersUploading
    701 {
    702     return fStat->peersUploading;
    703 }
    704 
    705 //peers downloading from you
    706 - (int) peersDownloading
    707 {
    708     return fStat->peersDownloading;
    709 }
    710 
    711 - (float) downloadRate
    712 {
    713     return fStat->rateDownload;
    714 }
    715 
    716 - (float) uploadRate
    717 {
    718     return fStat->rateUpload;
    719 }
    720 
    721 - (float) downloadedValid
    722 {
    723     return [self progress] * [self size];
    724 }
    725 
    726 - (uint64_t) downloadedTotal
    727 {
    728     return fStat->downloaded;
    729 }
    730 
    731 - (uint64_t) uploadedTotal
    732 {
    733     return fStat->uploaded;
    734 }
    735 
    736 - (float) swarmSpeed
    737 {
    738     return fStat->swarmspeed;
    739 }
    740 
    741 - (NSNumber *) orderValue
    742 {
    743     return [NSNumber numberWithInt: fOrderValue];
    744 }
    745 
    746 - (void) setOrderValue: (int) orderValue
    747 {
    748     fOrderValue = orderValue;
    749 }
    750 
    751 - (NSArray *) fileList
    752 {
    753     int count = fInfo->fileCount, i;
    754     tr_file_t file;
    755     NSMutableArray * files = [NSMutableArray arrayWithCapacity: count];
    756    
    757     for (i = 0; i < count; i++)
    758     {
    759         file = fInfo->files[i];
    760         [files addObject: [NSDictionary dictionaryWithObjectsAndKeys:
    761             [[self downloadFolder] stringByAppendingPathComponent: [NSString stringWithUTF8String: file.name]], @"Name",
    762             [NSNumber numberWithUnsignedLongLong: file.length], @"Size", nil]];
    763     }
    764    
    765     return files;
    766 }
    767 
    768 - (NSDate *) date
    769 {
    770     return fDate;
    771 }
    772 
    773 - (NSNumber *) stateSortKey
    774 {
    775     if (![self isActive])
    776         return [NSNumber numberWithInt: 0];
    777     else if ([self isSeeding])
    778         return [NSNumber numberWithInt: 1];
    779     else
    780         return [NSNumber numberWithInt: 2];
    781 }
    782 
    783 - (NSNumber *) progressSortKey
    784 {
    785     //if finished downloading sort by ratio instead of progress
    786     float progress = [self progress];
    787     return [NSNumber numberWithFloat: progress < 1.0 ? progress : 2.0 + [self ratio]];
    788 }
    789 
    790 @end
    791 
    792 
    793 @implementation Torrent (Private)
    794 
    795 //if a hash is given, attempt to load that; otherwise, attempt to open file at path
    796 - (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
    797         privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent
    798         date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
    799         ratioLimit: (NSNumber *) ratioLimit waitToStart: (NSNumber *) waitToStart
    800         orderValue: (NSNumber *) orderValue
    801 {
    802     if (!(self = [super init]))
    803         return nil;
    804 
    805     fLib = lib;
    806     fDefaults = [NSUserDefaults standardUserDefaults];
    807 
    808     fPrivateTorrent = privateTorrent ? [privateTorrent boolValue] : [fDefaults boolForKey: @"SavePrivateTorrent"];
    809     fPublicTorrent = !fPrivateTorrent || (publicTorrent ? [publicTorrent boolValue]
    810                                             : ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);
    811 
    812     int error;
    813     if (fPrivateTorrent && hashString)
    814         fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FSAVEPRIVATE, & error);
    815    
    816     if (!fHandle && path)
    817         fHandle = tr_torrentInit(fLib, [path UTF8String], fPrivateTorrent ? TR_FSAVEPRIVATE : 0, & error);
    818 
    819     if (!fHandle)
    820     {
    821         [self release];
    822         return nil;
    823     }
    824    
    825     fInfo = tr_torrentInfo( fHandle );
    826 
    827     if (fPublicTorrent)
    828         fPublicTorrentLocation = [path retain];
    829 
    830     fDate = date ? [date retain] : [[NSDate alloc] init];
    831    
    832     fStopRatioSetting = stopRatioSetting ? [stopRatioSetting intValue] : -1;
    833     fRatioLimit = ratioLimit ? [ratioLimit floatValue] : [fDefaults floatForKey: @"RatioLimit"];
    834     fFinishedSeeding = NO;
    835    
    836     fWaitToStart = waitToStart ? [waitToStart boolValue] : [fDefaults boolForKey: @"StartAtOpen"];
    837     fOrderValue = orderValue ? [orderValue intValue] : tr_torrentCount(fLib) - 1;
    838    
    839     NSString * fileType = fInfo->multifile ? NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension];
    840     fIcon = [[NSWorkspace sharedWorkspace] iconForFileType: fileType];
    841     [fIcon retain];
    842    
    843     fIconFlipped = [fIcon copy];
    844     [fIconFlipped setFlipped: YES];
    845    
    846     fIconSmall = [fIconFlipped copy];
    847     [fIconSmall setScalesWhenResized: YES];
    848     [fIconSmall setSize: NSMakeSize(16.0, 16.0)];
    849 
    850     fProgressString = [[NSMutableString alloc] initWithCapacity: 50];
    851     fStatusString = [[NSMutableString alloc] initWithCapacity: 75];
    852     fShortStatusString = [[NSMutableString alloc] initWithCapacity: 30];
    853     fRemainingTimeString = [[NSMutableString alloc] initWithCapacity: 30];
    854 
    855     [self update];
    856     return self;
    857 }
    858 
    859859- (void) trashFile: (NSString *) path
    860860{
Note: See TracChangeset for help on using the changeset viewer.