Changeset 272 for trunk/macosx/Torrent.m


Ignore:
Timestamp:
Jun 6, 2006, 6:05:57 PM (16 years ago)
Author:
livings124
Message:

First commit on my own 8-)

Sorting by progress, sorting no longer causes crashes.
New look for the table.
Info is now inspector: can set individual and multiple ratio limits, shows listing of files, more info in general, resizes when changing tabs, can change tabs with cmd-left and cmd-right.
Menu items moved to "Transfers" menu.
Sliding status bar in its own view.
Prefs moved into their own nib.
Toolbar items for pause and resume selected (many wanted this, but it needs better icons)
New icons for Transfers and General.
A lot of tweaking of main window to fix alignment etc.
Sparkle used for updated (still needs to be added to website to work).

And a lot more tweaking and changes that I'm too lazy to list.

...now let's hope I commit this right

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.m

    r261 r272  
    5858            downloadFolder = [[fDefaults stringForKey: @"DownloadFolder"]
    5959                                stringByExpandingTildeInPath];
    60         [self setFolder: downloadFolder];
     60        [self setDownloadFolder: downloadFolder];
    6161
    6262        NSString * paused;
     
    6464            [self start];
    6565    }
    66    
    6766    return self;
    6867}
     
    7170{
    7271    return [NSDictionary dictionaryWithObjectsAndKeys:
    73             [self path], @"TorrentPath",
    74             [self getFolder], @"DownloadFolder",
     72            [self torrentLocation], @"TorrentPath",
     73            [self downloadFolder], @"DownloadFolder",
    7574            [self isActive] ? @"NO" : @"YES", @"Paused",
    7675            [self date], @"Date",
     
    8786        [fDate release];
    8887        [fIcon release];
    89         [fIconNonFlipped release];
     88        [fIconFlipped release];
     89        [fProgressString release];
    9090        [fStatusString release];
    91         [fInfoString release];
    92         [fDownloadString release];
    93         [fUploadString release];
    9491    }
    9592    [super dealloc];
    9693}
    9794
    98 - (void) setFolder: (NSString *) path
     95- (void) setDownloadFolder: (NSString *) path
    9996{
    10097    tr_torrentSetFolder( fHandle, [path UTF8String] );
    10198}
    10299
    103 - (NSString *) getFolder
     100- (NSString *) downloadFolder
    104101{
    105102    return [NSString stringWithUTF8String: tr_torrentGetFolder( fHandle )];
     
    116113   
    117114    if ([self isSeeding])
    118         if ((fStopRatioSetting == 1 && [self ratio] >= fRatioLimit)
    119             || (fStopRatioSetting == -1 && [fDefaults boolForKey: @"RatioCheck"]
     115        if ((fStopRatioSetting == RATIO_CHECK && [self ratio] >= fRatioLimit)
     116            || (fStopRatioSetting == RATIO_GLOBAL && [fDefaults boolForKey: @"RatioCheck"]
    120117                && [self ratio] >= [fDefaults floatForKey: @"RatioLimit"]))
    121118        {
    122119            [self stop];
    123             [self setStopRatioSetting: 0];
     120            [self setStopRatioSetting: RATIO_NO_CHECK];
    124121           
    125122            fStat = tr_torrentStat( fHandle );
     123           
     124            [[NSNotificationCenter defaultCenter] postNotificationName:
     125                @"TorrentRatioChanged" object: self];
    126126        }
    127 
    128     [fStatusString setString: @""];
    129     [fInfoString setString: @""];
     127   
     128    [fProgressString setString: @""];
     129    if ([self progress] < 1.0)
     130        [fProgressString appendFormat: @"%@ of %@ completed (%.2f%%)", [NSString stringForFileSize:
     131                [self downloaded]], [NSString stringForFileSize: [self size]], 100 * [self progress]];
     132    else
     133        [fProgressString appendFormat: @"%@, uploaded %@ (ratio: %@)", [NSString stringForFileSize:
     134                [self size]], [NSString stringForFileSize: [self uploaded]],
     135                [NSString stringForRatioWithDownload: [self downloaded] upload: [self uploaded]]];
    130136
    131137    switch( fStat->status )
    132138    {
    133139        case TR_STATUS_PAUSE:
    134             [fStatusString appendFormat: @"Paused (%.2f %%)",
    135                 100 * fStat->progress];
     140            [fStatusString setString: @"Paused"];
    136141            break;
    137142
    138143        case TR_STATUS_CHECK:
     144            [fStatusString setString: [@"Checking existing files" stringByAppendingString: NS_ELLIPSIS]];
     145            break;
     146
     147        case TR_STATUS_DOWNLOAD:
     148            [fStatusString setString: @""];
    139149            [fStatusString appendFormat:
    140                 @"Checking existing files (%.2f %%)",
    141                 100 * fStat->progress];
    142             break;
    143 
    144         case TR_STATUS_DOWNLOAD:
    145             if( fStat->eta < 0 )
    146             {
    147                 [fStatusString appendFormat:
    148                     @"Finishing in --:--:-- (%.2f %%)",
    149                     100 * fStat->progress];
    150             }
     150                @"Downloading from %d of %d peer%s",
     151                [self peersUploading], [self totalPeers],
     152                ([self totalPeers] == 1) ? "" : "s"];
     153           
     154            int eta = fStat->eta;
     155            if (eta < 0)
     156                [fProgressString appendString: @" - remaining time unknown"];
    151157            else
    152158            {
    153                 [fStatusString appendFormat:
    154                     @"Finishing in %02d:%02d:%02d (%.2f %%)",
    155                     fStat->eta / 3600, ( fStat->eta / 60 ) % 60,
    156                     fStat->eta % 60, 100 * fStat->progress];
     159                if (eta < 60)
     160                    [fProgressString appendFormat: @" - %d sec remaining", eta];
     161                else if (eta < 3600)
     162                    [fProgressString appendFormat: @" - %d min %02d sec remaining",
     163                                                    eta / 60, eta % 60];
     164                else
     165                    [fProgressString appendFormat: @" - %d hr %02d min remaining",
     166                                                    eta / 3600, (eta / 60) % 60];
    157167            }
    158             [fInfoString appendFormat:
    159                 @"Downloading from %d of %d peer%s",
    160                 fStat->peersUploading, fStat->peersTotal,
    161                 ( fStat->peersTotal == 1 ) ? "" : "s"];
    162168            break;
    163169
    164170        case TR_STATUS_SEED:
     171            [fStatusString setString: @""];
    165172            [fStatusString appendFormat:
    166                 @"Seeding, uploading to %d of %d peer%s",
    167                 fStat->peersDownloading, fStat->peersTotal,
    168                 ( fStat->peersTotal == 1 ) ? "" : "s"];
     173                @"Seeding to %d of %d peer%s",
     174                [self peersDownloading], [self totalPeers],
     175                ([self totalPeers] == 1) ? "" : "s"];
    169176            break;
    170177
    171178        case TR_STATUS_STOPPING:
    172             [fStatusString setString: [@"Stopping"
    173                 stringByAppendingString: NS_ELLIPSIS]];
    174             break;
    175     }
    176 
     179            [fStatusString setString: [@"Stopping" stringByAppendingString: NS_ELLIPSIS]];
     180            break;
     181    }
     182   
    177183    if( fStat->error & TR_ETRACKER )
    178184    {
    179         [fInfoString setString: [@"Error: " stringByAppendingString:
     185        [fStatusString setString: [@"Error: " stringByAppendingString:
    180186            [NSString stringWithUTF8String: fStat->trackerError]]];
    181187    }
    182188
    183     if( fStat->progress == 1.0 )
    184     {
    185         [fDownloadString setString: [@"Ratio: " stringByAppendingString:
    186             [NSString stringForRatio: fStat->downloaded
    187             upload: fStat->uploaded]]];
    188     }
    189     else
    190     {
    191         [fDownloadString setString: [@"DL: " stringByAppendingString:
    192             [NSString stringForSpeed: fStat->rateDownload]]];
    193     }
    194     [fUploadString setString: [@"UL: " stringByAppendingString:
    195         [NSString stringForSpeed: fStat->rateUpload]]];
     189    if ([self isActive])
     190    {
     191        if ([self progress] < 1.0)
     192            [fStatusString appendFormat: @" - DL: %@, ", [NSString stringForSpeed: [self downloadRate]]];
     193        [fStatusString appendString: [@"UL: " stringByAppendingString:
     194                                                [NSString stringForSpeed: [self uploadRate]]]];
     195    }
    196196}
    197197
     
    230230- (float) ratio
    231231{
    232     uint64_t downloaded = [self downloaded];
    233     return downloaded > 0 ? [self uploaded] / downloaded : -1;
    234 }
    235 
    236 /*  1: Check ratio
    237     0: Don't check ratio
    238    -1: Use defaults */
     232    float downloaded = [self downloaded];
     233    return downloaded > 0 ? (float)[self uploaded] / downloaded : -1;
     234}
     235
    239236- (int) stopRatioSetting
    240237{
     
    260257- (void) reveal
    261258{
    262     [[NSWorkspace sharedWorkspace] selectFile: [[self getFolder]
    263         stringByAppendingPathComponent: [self name]]
     259    [[NSWorkspace sharedWorkspace] selectFile: [self dataLocation]
    264260        inFileViewerRootedAtPath: nil];
    265261}
     
    267263- (void) trashTorrent
    268264{
    269     [self trashPath: [self path]];
     265    [self trashPath: [self torrentLocation]];
    270266}
    271267
    272268- (void) trashData
    273269{
    274     [self trashPath: [[self getFolder]
    275         stringByAppendingPathComponent: [self name]]];
     270    [self trashPath: [self dataLocation]];
    276271}
    277272
     
    281276}
    282277
    283 - (NSImage *) iconNonFlipped
    284 {
    285     return fIconNonFlipped;
    286 }
    287 
    288 - (NSString *) path
    289 {
    290     return [NSString stringWithUTF8String: fInfo->torrent];
     278- (NSImage *) iconFlipped
     279{
     280    return fIconFlipped;
    291281}
    292282
     
    322312}
    323313
    324 - (NSString *) hash
     314- (NSString *) hashString
    325315{
    326316    NSMutableString * string = [NSMutableString
     
    334324}
    335325
     326- (NSString *) torrentLocation
     327{
     328    return [NSString stringWithUTF8String: fInfo->torrent];;
     329}
     330
     331- (NSString *) dataLocation
     332{
     333    return [[self downloadFolder] stringByAppendingPathComponent: [self name]];
     334}
     335
     336- (NSString *) state
     337{
     338    switch( fStat->status )
     339    {
     340        case TR_STATUS_PAUSE:
     341            return @"Paused";
     342            break;
     343
     344        case TR_STATUS_CHECK:
     345            return [@"Checking existing files" stringByAppendingString: NS_ELLIPSIS];
     346            break;
     347
     348        case TR_STATUS_DOWNLOAD:
     349            return @"Downloading";
     350            break;
     351
     352        case TR_STATUS_SEED:
     353            return @"Seeding";
     354            break;
     355
     356        case TR_STATUS_STOPPING:
     357            return [@"Stopping" stringByAppendingString: NS_ELLIPSIS];
     358            break;
     359       
     360        default:
     361            return @"N/A";
     362    }
     363}
     364
    336365- (float) progress
    337366{
     
    359388}
    360389
     390- (NSString *) progressString
     391{
     392    return fProgressString;
     393}
     394
    361395- (NSString *) statusString
    362396{
     
    364398}
    365399
    366 - (NSString *) infoString
    367 {
    368     return fInfoString;
    369 }
    370 
    371 - (NSString *) downloadString
    372 {
    373     return fDownloadString;
    374 }
    375 
    376 - (NSString *) uploadString
    377 {
    378     return fUploadString;
    379 }
    380 
    381400- (int) seeders
    382401{
     
    389408}
    390409
     410- (int) totalPeers
     411{
     412    return fStat->peersTotal;
     413}
     414
     415//peers uploading to you
     416- (int) peersUploading
     417{
     418    return fStat->peersUploading;
     419}
     420
     421//peers downloading from you
     422- (int) peersDownloading
     423{
     424    return fStat->peersDownloading;
     425}
     426
     427- (float) downloadRate
     428{
     429    return fStat->rateDownload;
     430}
     431
     432- (float) uploadRate
     433{
     434    return fStat->rateUpload;
     435}
     436
    391437- (uint64_t) downloaded
    392438{
     
    397443{
    398444    return fStat->uploaded;
     445}
     446
     447- (NSArray *) fileList
     448{
     449    int count = fInfo->fileCount, i;
     450    NSMutableArray * files = [NSMutableArray arrayWithCapacity: count];
     451    for (i = 0; i < count; i++)
     452        [files addObject: [[self downloadFolder] stringByAppendingPathComponent:
     453            [NSString stringWithUTF8String: fInfo->files[i].name]]];
     454    return files;
    399455}
    400456
     
    414470}
    415471
     472- (NSNumber *) progressSortKey
     473{
     474    return [NSNumber numberWithFloat: [self progress]];
     475}
     476
    416477@end
    417478
     
    445506        NSFileTypeForHFSTypeCode('fldr') : [[self name] pathExtension];
    446507    fIcon = [[NSWorkspace sharedWorkspace] iconForFileType: fileType];
    447     [fIcon setFlipped: YES];
    448508    [fIcon retain];
    449     fIconNonFlipped = [[NSWorkspace sharedWorkspace] iconForFileType: fileType];
    450     [fIconNonFlipped retain];
    451 
    452     fStatusString   = [[NSMutableString alloc] initWithCapacity: 50];
    453     fInfoString     = [[NSMutableString alloc] initWithCapacity: 50];
    454     fDownloadString = [[NSMutableString alloc] initWithCapacity: 10];
    455     fUploadString   = [[NSMutableString alloc] initWithCapacity: 10];
     509   
     510    fIconFlipped = [fIcon copy];
     511    [fIconFlipped setFlipped: YES];
     512
     513    fProgressString = [[NSMutableString alloc] initWithCapacity: 50];
     514    fStatusString = [[NSMutableString alloc] initWithCapacity: 75];
    456515
    457516    [self update];
Note: See TracChangeset for help on using the changeset viewer.