Changeset 141


Ignore:
Timestamp:
Mar 10, 2006, 9:10:17 PM (17 years ago)
Author:
titer
Message:

First pass at updating the OS X interface (still doesn't work yet)

Location:
branches/new_api
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • branches/new_api/libtransmission/transmission.c

    r140 r141  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    423423}
    424424
    425 void tr_torrentAvailability( tr_torrent_t * tor, uint8_t * tab, int size )
     425void tr_torrentAvailability( tr_torrent_t * tor, int8_t * tab, int size )
    426426{
    427427    int i, j, piece;
  • branches/new_api/libtransmission/transmission.h

    r140 r141  
    177177 * of connected peers who have the piece.
    178178 **********************************************************************/
    179 void tr_torrentAvailability( tr_torrent_t *, uint8_t * tab, int size );
     179void tr_torrentAvailability( tr_torrent_t *, int8_t * tab, int size );
    180180
    181181/***********************************************************************
     
    230230#define TR_STATUS_DOWNLOAD 0x002 /* Downloading */
    231231#define TR_STATUS_SEED     0x004 /* Seeding */
    232 #define TR_STATUS_ACTIVE   0x007 /* CHECK | DOWNLOAD | SEED */
    233232#define TR_STATUS_STOPPING 0x008 /* Sending 'stopped' to the tracker */
    234233#define TR_STATUS_STOPPED  0x010 /* Sent 'stopped' but thread still
    235234                                    running (for internal use only) */
    236235#define TR_STATUS_PAUSE    0x020 /* Paused */
    237 #define TR_STATUS_INACTIVE 0x038 /* STOPPING | STOPPED | PAUSE */
     236
     237#define TR_STATUS_ACTIVE   (TR_STATUS_CHECK|TR_STATUS_DOWNLOAD|TR_STATUS_SEED)
     238#define TR_STATUS_INACTIVE (TR_STATUS_STOPPING|TR_STATUS_STOPPED|TR_STATUS_PAUSE)
    238239    int         status;
    239240
  • branches/new_api/macosx/Controller.h

    r107 r141  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    3333@interface Controller : NSObject
    3434{
    35     tr_handle_t                 * fHandle;
     35    tr_handle_t                 * fLib;
    3636    int                         fCount, fSeeding, fDownloading, fCompleted;
    37     tr_stat_t                   * fStat;
    38     int                         fResumeOnWake[TR_MAX_TORRENT_COUNT];
     37    NSMutableArray              * fTorrents;
    3938
    4039    NSToolbar                   * fToolbar;
  • branches/new_api/macosx/Controller.m

    r126 r141  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    2323#import <IOKit/IOMessage.h>
    2424
     25#import "Controller.h"
     26#import "Torrent.h"
    2527#import "NameCell.h"
    2628#import "ProgressCell.h"
     
    5658{
    5759    [fWindow setContentMinSize: NSMakeSize( 400, 120 )];
    58    
    59     fHandle = tr_init();
    60 
    61     [fPrefsController setPrefsWindow: fHandle];
     60
     61    fLib = tr_init();
     62
     63    [fPrefsController setPrefsWindow: fLib];
    6264    fDefaults = [NSUserDefaults standardUserDefaults];
    63    
     65
    6466    [fInfoPanel setFrameAutosaveName:@"InfoPanel"];
    6567
     
    6769    [fAdvancedBarItem setState: [fDefaults
    6870        boolForKey:@"UseAdvancedBar"] ? NSOnState : NSOffState];
    69    
     71
    7072    fToolbar = [[NSToolbar alloc] initWithIdentifier: @"Transmission Toolbar"];
    7173    [fToolbar setDelegate: self];
     
    109111    NSDictionary * dic;
    110112
     113    Torrent * torrent;
    111114    NSEnumerator * enumerator = [[fDefaults arrayForKey: @"History"] objectEnumerator];
    112115    while ((dic = [enumerator nextObject]))
     
    115118        downloadFolder = [dic objectForKey: @"DownloadFolder"];
    116119        paused         = [dic objectForKey: @"Paused"];
    117            
     120
    118121        if (!torrentPath || !downloadFolder || !paused)
    119122            continue;
    120123
    121         if (tr_torrentInit(fHandle, [torrentPath UTF8String]))
     124        torrent = [[Torrent alloc] initWithPath: torrentPath lib: fLib];
     125        if( !torrent )
    122126            continue;
    123127
    124         tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
    125                                 [downloadFolder UTF8String] );
     128        [fTorrents addObject: torrent];
     129
     130        [torrent setFolder: downloadFolder];
    126131
    127132        if ([paused isEqualToString: @"NO"])
    128             tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
     133            [torrent start];
    129134    }
    130135
     
    138143    //initialize badging
    139144    fBadger = [[Badger alloc] init];
    140    
     145
    141146    //update the interface every 500 ms
    142     fCount = 0;
    143147    fDownloading = 0;
    144148    fSeeding = 0;
    145149    fCompleted = 0;
    146     fStat  = nil;
    147150    [self updateUI: nil];
    148151    fTimer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self
     
    200203                            nil, nil, message);
    201204        return NSTerminateLater;
    202     }                                                                           
    203    
     205    }
     206
    204207    return NSTerminateNow;
    205208}
     
    215218- (void) applicationWillTerminate: (NSNotification *) notification
    216219{
    217     int i;
    218    
     220    NSEnumerator * enumerator;
     221    Torrent * torrent;
     222
    219223    // Stop updating the interface
    220224    [fTimer invalidate];
     
    223227    //clear badge
    224228    [fBadger clearBadge];
    225     [fBadger release];                                                         
     229    [fBadger release];
    226230
    227231    // Save history
    228232    [self updateTorrentHistory];
    229    
     233
    230234    // Stop running torrents
    231     for( i = 0; i < fCount; i++ )
    232         if( fStat[i].status & ( TR_STATUS_CHECK | TR_STATUS_DOWNLOAD |
    233                     TR_STATUS_SEED ) )
    234             tr_torrentStop( fHandle, i );
     235    enumerator = [fTorrents objectEnumerator];
     236    while( ( torrent = [enumerator nextObject] ) )
     237    {
     238        [torrent stop];
     239    }
    235240
    236241    // Wait for torrents to stop (5 seconds timeout)
    237242    NSDate * start = [NSDate date];
    238     while( fCount > 0 )
    239     {
     243    while( [fTorrents count] )
     244    {
     245        torrent = [fTorrents objectAtIndex: 0];
    240246        while( [[NSDate date] timeIntervalSinceDate: start] < 5 &&
    241                 !( fStat[0].status & TR_STATUS_PAUSE ) )
     247                ![torrent isPaused] )
    242248        {
    243249            usleep( 100000 );
    244             tr_torrentStat( fHandle, &fStat );
    245         }
    246         tr_torrentClose( fHandle, 0 );
    247         fCount = tr_torrentStat( fHandle, &fStat );
    248     }
    249 
    250     tr_close( fHandle );
     250            [torrent update];
     251        }
     252        [fTorrents removeObject: torrent];
     253        [torrent release];
     254    }
     255    [fTorrents release];
     256
     257    tr_close( fLib );
    251258}
    252259
     
    258265        [fPrefsWindow center];
    259266    }
    260    
     267
    261268    [fPrefsWindow makeKeyAndOrderFront:NULL];
    262269}
     
    265272    contextInfo: (void *) info
    266273{
     274    Torrent * torrent = [fTorrents lastObject];
    267275    if (code == NSOKButton)
    268276    {
    269         tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
    270                          [[[s filenames] objectAtIndex: 0] UTF8String] );
    271         tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
     277        [torrent setFolder: [[s filenames] objectAtIndex: 0]];
     278        [torrent start];
    272279    }
    273280    else
    274281    {
    275         tr_torrentClose( fHandle, tr_torrentCount( fHandle ) - 1 );
     282        [torrent release];
    276283    }
    277284    [NSApp stopModal];
     
    282289{
    283290    NSString * downloadChoice, * downloadFolder, * torrentPath;
     291    Torrent * torrent;
    284292
    285293    downloadChoice = [fDefaults stringForKey: @"DownloadChoice"];
     
    289297    while ((torrentPath = [enumerator nextObject]))
    290298    {
    291         if( tr_torrentInit( fHandle, [torrentPath UTF8String] ) )
     299        torrent = [[Torrent alloc] initWithPath: torrentPath lib: fLib];
     300        if( !torrent )
    292301            continue;
     302        [fTorrents addObject: torrent];
    293303
    294304        /* Add it to the "File > Open Recent" menu */
     
    298308        if( [downloadChoice isEqualToString: @"Constant"] )
    299309        {
    300             tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
    301                                  [[downloadFolder stringByExpandingTildeInPath] UTF8String] );
    302             tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
     310            [torrent setFolder: [downloadFolder stringByExpandingTildeInPath]];
     311            [torrent start];
    303312        }
    304313        else if( [downloadChoice isEqualToString: @"Torrent"] )
    305314        {
    306             tr_torrentSetFolder( fHandle, tr_torrentCount( fHandle ) - 1,
    307                 [[torrentPath stringByDeletingLastPathComponent] UTF8String] );
    308             tr_torrentStart( fHandle, tr_torrentCount( fHandle ) - 1 );
     315            [torrent setFolder: [torrentPath stringByDeletingLastPathComponent]];
     316            [torrent start];
    309317        }
    310318        else
    311319        {
    312320            NSOpenPanel * panel = [NSOpenPanel openPanel];
    313            
     321
    314322            [panel setPrompt: @"Select Download Folder"];
    315323            [panel setMessage: [NSString stringWithFormat:
     
    356364    panel     = [NSOpenPanel openPanel];
    357365    fileTypes = [NSArray arrayWithObject: @"torrent"];
    358    
     366
    359367    [panel setAllowsMultipleSelection: YES];
    360368    [panel setCanChooseFiles:          YES];
     
    394402- (void) resumeAllTorrents: (id) sender
    395403{
    396     int i;
    397     for ( i = 0; i < fCount; i++)
    398     {
    399         if ( fStat[i].status & ( TR_STATUS_STOPPING
    400         | TR_STATUS_PAUSE | TR_STATUS_STOPPED ) )
    401         {
    402             [self resumeTorrentWithIndex: i];
    403         }
     404    NSEnumerator * enumerator = [fTorrents objectEnumerator];
     405    Torrent * torrent;
     406    while( ( torrent = [enumerator nextObject] ) )
     407    {
     408        [torrent stop];
    404409    }
    405410}
     
    407412- (void) resumeTorrentWithIndex: (int) idx
    408413{
    409     tr_torrentStart( fHandle, idx );
    410     [self updateUI: NULL];
     414    [[fTorrents objectAtIndex: idx] start];
     415    [self updateUI: nil];
    411416    [self updateTorrentHistory];
    412417}
     
    419424- (void) stopAllTorrents: (id) sender
    420425{
    421     int i;
    422     for ( i = 0; i < fCount; i++)
    423     {
    424         if ( fStat[i].status & ( TR_STATUS_CHECK
    425         | TR_STATUS_DOWNLOAD | TR_STATUS_SEED) )
    426         {
    427             [self stopTorrentWithIndex: i];
    428         }
     426    NSEnumerator * enumerator = [fTorrents objectEnumerator];
     427    Torrent * torrent;
     428    while( ( torrent = [enumerator nextObject] ) )
     429    {
     430        [torrent start];
    429431    }
    430432}
     
    432434- (void) stopTorrentWithIndex: (int) idx
    433435{
    434     tr_torrentStop( fHandle, idx );
    435     [self updateUI: NULL];
     436    Torrent * torrent = [fTorrents objectAtIndex: idx];
     437    [torrent stop];
     438    [self updateUI: nil];
    436439    [self updateTorrentHistory];
    437440}
     
    441444                     deleteData: (BOOL) deleteData
    442445{
    443     if ( fStat[idx].status & ( TR_STATUS_CHECK
    444         | TR_STATUS_DOWNLOAD | TR_STATUS_SEED )  )
     446    Torrent * torrent = [fTorrents objectAtIndex: idx];
     447
     448    if( [torrent isActive] )
    445449    {
    446450        if ([fDefaults boolForKey: @"CheckRemove"])
     
    452456                        nil];
    453457            [dict retain];
    454            
     458
    455459            NSBeginAlertSheet(@"Confirm Remove",
    456460                                @"Remove", @"Cancel", nil,
     
    464468            [self stopTorrentWithIndex:idx];
    465469    }
    466    
     470
    467471    [self confirmRemoveTorrentWithIndex: idx
    468472            deleteTorrent: deleteTorrent
     
    479483        return;
    480484    }
    481    
     485
    482486    int idx = [[dict objectForKey:@"Index"] intValue];
    483    
     487
    484488    [self stopTorrentWithIndex:idx];
    485489
     
    489493    [dict release];
    490494}
    491                      
     495
    492496- (void) confirmRemoveTorrentWithIndex: (int) idx
    493497            deleteTorrent: (BOOL) deleteTorrent
    494498            deleteData: (BOOL) deleteData
    495499{
     500#if 0
    496501    if( deleteData )
    497502    {
     
    505510            fStat[idx].info.torrent]];
    506511    }
    507    
     512
    508513    tr_torrentClose( fHandle, idx );
    509514    [self updateUI: NULL];
    510515    [self updateTorrentHistory];
     516#endif
    511517}
    512518
     
    546552{
    547553    float dl, ul;
    548     int row, i;
    549 
    550     //Update the NSTableView
    551     if (fStat)
    552         free(fStat);
    553        
    554     fCount = tr_torrentStat( fHandle, &fStat );
    555     fDownloading = 0;
    556     fSeeding = 0;
    557     [fTableView updateUI: fStat];
     554    NSEnumerator * enumerator;
     555    Torrent * torrent;
     556
     557    /* Update the TableView */
     558    enumerator = [fTorrents objectEnumerator];
     559    while( ( torrent = [enumerator nextObject] ) )
     560    {
     561        [torrent update];
     562
     563        if( [torrent justFinished] )
     564        {
     565            /* Notifications */
     566            [self notifyGrowl: [torrent name]];
     567            if( ![fWindow isKeyWindow] )
     568            {
     569                fCompleted++;
     570            }
     571        }
     572    }
     573    [fTableView reloadData];
    558574
    559575    //Update the global DL/UL rates
    560     tr_torrentRates( fHandle, &dl, &ul );
     576    tr_torrentRates( fLib, &dl, &ul );
    561577    NSString * downloadRate = [NSString stringForSpeed: dl];
    562578    NSString * uploadRate = [NSString stringForSpeed: ul];
     
    564580    [fTotalULField setStringValue: uploadRate];
    565581
     582#if 0
    566583    //Update DL/UL totals in the Info panel
    567584    row = [fTableView selectedRow];
     
    573590            [NSString stringForFileSize: fStat[row].uploaded]];
    574591    }
    575    
    576     //check if torrents have recently ended.
    577     for (i = 0; i < fCount; i++)
    578     {
    579         if (fStat[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD))
    580             fDownloading++;
    581         else if (fStat[i].status & TR_STATUS_SEED)
    582             fSeeding++;
    583 
    584         if( !tr_getFinished( fHandle, i ) )
    585             continue;
    586 
    587         if( ![fWindow isKeyWindow] )
    588             fCompleted++;
    589         [self notifyGrowl: [NSString stringWithUTF8String:
    590             fStat[i].info.name]];
    591         tr_setFinished( fHandle, i, 0 );
    592     }
     592#endif
    593593
    594594    //badge dock
     
    602602- (void) updateTorrentHistory
    603603{
    604     if( !fStat )
     604    if( [fTorrents count] < 1 )
    605605        return;
    606606
    607     NSMutableArray * history = [NSMutableArray arrayWithCapacity: fCount];
    608 
    609     int i;
    610     for (i = 0; i < fCount; i++)
     607    NSMutableArray * history = [NSMutableArray
     608        arrayWithCapacity: [fTorrents count]];
     609
     610    NSEnumerator * enumerator = [fTorrents objectEnumerator];
     611    Torrent * torrent;
     612    while( ( torrent = [enumerator nextObject] ) )
     613    {
    611614        [history addObject: [NSDictionary dictionaryWithObjectsAndKeys:
    612             [NSString stringWithUTF8String: fStat[i].info.torrent],
    613             @"TorrentPath",
    614             [NSString stringWithUTF8String: tr_torrentGetFolder( fHandle, i )],
    615             @"DownloadFolder",
    616             fStat[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD |
    617               TR_STATUS_SEED) ? @"NO" : @"YES",
    618             @"Paused",
     615            [torrent path],                      @"TorrentPath",
     616            [torrent getFolder],                 @"DownloadFolder",
     617            [torrent isActive] ? @"NO" : @"YES", @"Paused",
    619618            nil]];
     619    }
    620620
    621621    [fDefaults setObject: history forKey: @"History"];
     
    624624- (int) numberOfRowsInTableView: (NSTableView *) t
    625625{
    626     return fCount;
     626    return [fTorrents count];
    627627}
    628628
     
    630630    (NSTableColumn *) tableColumn row: (int) rowIndex
    631631{
    632     return NULL;
    633 }
    634 
    635 - (void) tableView: (NSTableView *) t willDisplayCell: (id) cell
    636     forTableColumn: (NSTableColumn *) tableColumn row: (int) rowIndex
    637 {
    638     BOOL w;
    639 
    640     w = [fWindow isKeyWindow] && rowIndex == [fTableView selectedRow];
    641     if( [[tableColumn identifier] isEqualToString: @"Name"] )
    642     {
    643         [(NameCell *) cell setStat: &fStat[rowIndex] whiteText: w];
    644     }
    645     else if( [[tableColumn identifier] isEqualToString: @"Progress"] )
    646     {
    647         [(ProgressCell *) cell setStat: &fStat[rowIndex] whiteText: w];
    648     }
     632    return [fTorrents objectAtIndex: rowIndex];
    649633}
    650634
     
    671655        return NSDragOperationNone;
    672656
    673     [fTableView setDropRow: fCount dropOperation: NSTableViewDropAbove];
     657    [fTableView setDropRow: [fTorrents count]
     658        dropOperation: NSTableViewDropAbove];
    674659    return NSDragOperationGeneric;
    675660}
     
    695680    }
    696681
     682#if 0
    697683    /* Update info window */
    698684    [fInfoTitle setStringValue: [NSString stringWithUTF8String:
     
    710696    [fInfoFolder setStringValue: [[NSString stringWithUTF8String:
    711697        tr_torrentGetFolder( fHandle, row )] lastPathComponent]];
    712        
     698
    713699    if ( fStat[row].seeders == -1 ) {
    714700        [fInfoSeeders setStringValue: [NSString stringWithUTF8String: "?"]];
     
    723709            fStat[row].leechers]];
    724710    }
     711#endif
    725712}
    726713
     
    825812    if (action == @selector(removeTorrent:))
    826813        return [fTableView selectedRow] >= 0;
    827        
     814
    828815
    829816    //enable resume all item
     
    833820    //enable pause all item
    834821    if (action == @selector(stopAllTorrents:))
    835         return fDownloading > 0 || fSeeding > 0;                               
    836    
     822        return fDownloading > 0 || fSeeding > 0;
     823
    837824    return YES;
    838825}
     
    840827- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
    841828{
     829#if 0
    842830    SEL action = [menuItem action];
    843831
     
    845833    if ([fToolbar customizationPaletteIsRunning])
    846834        return NO;
    847        
     835
    848836    //enable customize toolbar item
    849837    if (action == @selector(showHideToolbar:))
     
    852840        return YES;
    853841    }
    854        
     842
    855843    //enable show info
    856844    if (action == @selector(showInfo:))
     
    866854    //enable pause all item
    867855    if (action == @selector(stopAllTorrents:))
    868         return fDownloading > 0 || fSeeding > 0;                               
    869    
     856        return fDownloading > 0 || fSeeding > 0;
     857
    870858    int row = [fTableView selectedRow];
    871        
     859
    872860    //enable remove items
    873861    if (action == @selector(removeTorrent:)
     
    890878        return row >= 0;
    891879    }
    892    
     880
    893881    //enable reveal in finder item
    894882    if (action == @selector(revealFromMenu:))
    895883        return row >= 0;
    896        
     884
    897885    //enable and change pause / remove item
    898886    if (action == @selector(resumeTorrent:) || action == @selector(stopTorrent:))
     
    910898        return row >= 0;
    911899    }
    912    
     900#endif
    913901    return YES;
    914902}
     
    917905                          (void *) messageArgument
    918906{
    919     int i;
     907    NSEnumerator * enumerator;;
     908    Torrent * torrent;
    920909
    921910    switch( messageType )
     
    924913            /* Close all connections before going to sleep and remember
    925914               we should resume when we wake up */
    926             for( i = 0; i < fCount; i++ )
     915            enumerator = [fTorrents objectEnumerator];
     916            while( ( torrent = [enumerator nextObject] ) )
    927917            {
    928                 if( fStat[i].status & ( TR_STATUS_CHECK |
    929                         TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) )
     918                [torrent sleep];
     919            }
     920
     921            /* Wait for torrents to stop (5 seconds timeout) */
     922            NSDate * start = [NSDate date];
     923            enumerator = [fTorrents objectEnumerator];
     924            while( ( torrent = [enumerator nextObject] ) )
     925            {
     926                while( [[NSDate date] timeIntervalSinceDate: start] < 5 &&
     927                        ![torrent isPaused] )
    930928                {
    931                     tr_torrentStop( fHandle, i );
    932                     fResumeOnWake[i] = 1;
    933                 }
    934                 else
    935                 {
    936                     fResumeOnWake[i] = 0;
     929                    usleep( 100000 );
     930                    [torrent update];
    937931                }
    938932            }
    939933
    940             /* TODO: wait a few seconds to let the torrents
    941                stop properly */
    942            
    943934            IOAllowPowerChange( fRootPort, (long) messageArgument );
    944935            break;
     
    954945        case kIOMessageSystemHasPoweredOn:
    955946            /* Resume download after we wake up */
    956             for( i = 0; i < fCount; i++ )
     947            enumerator = [fTorrents objectEnumerator];
     948            while( ( torrent = [enumerator nextObject] ) )
    957949            {
    958                 if( fResumeOnWake[i] )
    959                 {
    960                     tr_torrentStart( fHandle, i );
    961                 }
     950                [torrent wakeUp];
    962951            }
    963952            break;
     
    973962    rectWin  = [fWindow frame];
    974963    rectView = [fScrollView frame];
    975     foo      = 25.0 + MAX( 1, fCount ) * ( [fTableView rowHeight] +
    976                  [fTableView intercellSpacing].height ) -
    977                  rectView.size.height;
     964    foo      = 25.0 - rectView.size.height + MAX( 1U, [fTorrents count] ) *
     965        ( [fTableView rowHeight] + [fTableView intercellSpacing].height );
    978966
    979967    rectWin.size.height += foo;
     
    1008996    if( !fHasGrowl )
    1009997        return;
    1010    
     998
    1011999    growlScript = [NSString stringWithFormat:
    10121000        @"tell application \"System Events\"\n"
     
    10291017
    10301018- (void) growlRegister: (id) sender
    1031 {   
     1019{
    10321020    NSString * growlScript;
    10331021    NSAppleScript * appleScript;
     
    10361024    if( !fHasGrowl )
    10371025        return;
    1038    
     1026
    10391027    growlScript = [NSString stringWithFormat:
    10401028        @"tell application \"System Events\"\n"
     
    10481036         "  end if\n"
    10491037         "end tell"];
    1050          
     1038
    10511039    appleScript = [[NSAppleScript alloc] initWithSource: growlScript];
    10521040    if( ![appleScript executeAndReturnError: &error] )
     
    10591047- (void) revealFromMenu: (id) sender
    10601048{
     1049#if 0
    10611050    int row = [fTableView selectedRow];
    10621051    if (row >= 0)
     
    10661055            [NSString stringWithUTF8String: fStat[row].info.name]]];
    10671056    }
     1057#endif
    10681058}
    10691059
     
    10731063    NSAppleScript * appleScript;
    10741064    NSDictionary * error;
    1075    
     1065
    10761066    string = [NSString stringWithFormat:
    10771067        @"tell application \"Finder\"\n"
     
    11421132    [fDefaults setObject: [NSDate date] forKey: @"VersionCheckLast"];
    11431133}
    1144    
     1134
    11451135- (void) checkForUpdateAuto: (BOOL) automatic
    11461136{
     
    11511141
    11521142- (void) URLResourceDidFinishLoading: (NSURL *) sender
    1153 {   
     1143{
    11541144    NSDictionary * dict = [NSPropertyListSerialization
    11551145                            propertyListFromData: [sender resourceDataUsingCache: NO]
  • branches/new_api/macosx/NameCell.h

    r119 r141  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    2525
    2626#import <Cocoa/Cocoa.h>
    27 #import <transmission.h>
    28 #import "Controller.h"
    2927
    3028@interface NameCell : NSCell
    3129{
    32     BOOL       fWhiteText;
    33 
    34     NSString * fNameString;
    35     NSString * fSizeString;
    36     NSString * fTimeString;
    37     NSString * fPeersString;
    38 
    39     NSMutableDictionary * fIcons;
    40     NSImage             * fCurrentIcon;
    4130}
    42 - (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w;
    4331@end
    4432
  • branches/new_api/macosx/NameCell.m

    r119 r141  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    2222
    2323#import "NameCell.h"
     24#import "Torrent.h"
    2425#import "StringAdditions.h"
    2526#import "Utils.h"
     
    2728@implementation NameCell
    2829
    29 - (id) init
    30 {
    31     if ((self = [super init]))
    32         fIcons = [[NSMutableDictionary alloc] initWithCapacity: 10];
    33 
    34     return self;
    35 }
    36 
    37 - (void) dealloc
    38 {
    39     [fIcons release];
    40     [super dealloc];
    41 }
    42 
    43 - (NSImage *) iconForFileType: (NSString *) type
    44 {
    45     NSImage * icon;
    46     if (!(icon = [fIcons objectForKey: type]))
    47     {
    48         /* Unknown file type, get its icon and cache it */
    49         icon = [[NSWorkspace sharedWorkspace] iconForFileType: type];
    50         [icon setFlipped: YES];
    51 
    52         [fIcons setObject: icon forKey: type];
    53     }
    54 
    55     return icon;
    56 }
    57 
    58 - (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w
    59 {
    60     fWhiteText = w;
    61 
    62     fNameString  = [NSString stringWithUTF8String: stat->info.name];
    63     fSizeString  = [NSString stringWithFormat: @" (%@)",
    64                     [NSString stringForFileSize: stat->info.totalSize]];
    65 
    66     fCurrentIcon = [self iconForFileType: stat->info.fileCount > 1 ?
    67         NSFileTypeForHFSTypeCode('fldr') : [fNameString pathExtension]];
    68 
    69     fTimeString  = @"";
    70     fPeersString = @"";
    71 
    72     if( stat->status & TR_STATUS_PAUSE )
    73     {
    74         fTimeString = [NSString stringWithFormat:
    75             @"Paused (%.2f %%)", 100 * stat->progress];
    76     }
    77     else if( stat->status & TR_STATUS_CHECK )
    78     {
    79         fTimeString = [NSString stringWithFormat:
    80             @"Checking existing files (%.2f %%)", 100 * stat->progress];
    81     }
    82     else if( stat->status & TR_STATUS_DOWNLOAD )
    83     {
    84         if( stat->eta < 0 )
    85         {
    86             fTimeString = [NSString stringWithFormat:
    87                 @"Finishing in --:--:-- (%.2f %%)", 100 * stat->progress];
    88         }
    89         else
    90         {
    91             fTimeString = [NSString stringWithFormat:
    92                 @"Finishing in %02d:%02d:%02d (%.2f %%)",
    93                 stat->eta / 3600, ( stat->eta / 60 ) % 60,
    94                 stat->eta % 60, 100 * stat->progress];
    95         }
    96         fPeersString = [NSString stringWithFormat:
    97             @"Downloading from %d of %d peer%s",
    98             stat->peersUploading, stat->peersTotal,
    99             ( stat->peersTotal == 1 ) ? "" : "s"];
    100     }
    101     else if( stat->status & TR_STATUS_SEED )
    102     {
    103         fTimeString  = [NSString stringWithFormat:
    104             @"Seeding, uploading to %d of %d peer%s",
    105             stat->peersDownloading, stat->peersTotal,
    106             ( stat->peersTotal == 1 ) ? "" : "s"];
    107     }
    108     else if( stat->status & TR_STATUS_STOPPING )
    109     {
    110         fTimeString  = @"Stopping...";
    111     }
    112 
    113     if( ( stat->status & ( TR_STATUS_DOWNLOAD | TR_STATUS_SEED ) ) &&
    114         ( stat->status & TR_TRACKER_ERROR ) )
    115     {
    116         fPeersString = [NSString stringWithFormat: @"%@%@",
    117             @"Error: ", [NSString stringWithUTF8String: stat->error]];
    118     }
    119 }
    120 
    12130- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view
    12231{
     32    Torrent * torrent = [self objectValue];
     33
    12334    NSString * string;
    12435    NSPoint pen;
     
    13344    float cellWidth = cellFrame.size.width;
    13445
    135     pen.x += 5;
    136     pen.y += 5;
    137     [fCurrentIcon drawAtPoint: pen fromRect:
    138         NSMakeRect(0,0,[fCurrentIcon size].width,[fCurrentIcon size].height)
     46    pen.x += 5; pen.y += 5;
     47    NSImage * icon = [torrent icon];
     48    [icon drawAtPoint: pen fromRect:
     49        NSMakeRect( 0, 0, [icon size].width, [icon size].height )
    13950        operation: NSCompositeSourceOver fraction: 1.0];
    14051
    14152    attributes = [NSMutableDictionary dictionaryWithCapacity: 2];
    142     [attributes setObject: fWhiteText ? [NSColor whiteColor] :
     53    [attributes setObject: /*fWhiteText*/0 ? [NSColor whiteColor] :
    14354        [NSColor blackColor] forKey: NSForegroundColorAttributeName];
    14455
     
    14758
    14859    pen.x += 37;
    149     string = [[fNameString stringFittingInWidth: cellWidth -
    150         72 - [fSizeString sizeWithAttributes: attributes].width
    151         withAttributes: attributes] stringByAppendingString: fSizeString];
     60    NSString * sizeString = [NSString stringWithFormat: @" (%@)",
     61        [NSString stringForFileSize: [torrent size]]];
     62    string = [[[torrent name] stringFittingInWidth: cellWidth -
     63        72 - [sizeString sizeWithAttributes: attributes].width
     64        withAttributes: attributes] stringByAppendingString: sizeString];
    15265    [string drawAtPoint: pen withAttributes: attributes];
    15366
     
    15669
    15770    pen.x += 5; pen.y += 20;
    158     [fTimeString drawAtPoint: pen withAttributes: attributes];
     71    [[torrent statusString] drawAtPoint: pen withAttributes: attributes];
    15972
    16073    pen.x += 0; pen.y += 15;
    161     string = [fPeersString stringFittingInWidth: cellFrame.size.width -
    162         77 withAttributes: attributes];
     74    string = [[torrent infoString] stringFittingInWidth:
     75        ( cellFrame.size.width - 77 ) withAttributes: attributes];
    16376    [string drawAtPoint: pen withAttributes: attributes];
    16477
  • branches/new_api/macosx/ProgressCell.h

    r34 r141  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    2525
    2626#import <Cocoa/Cocoa.h>
    27 #import <transmission.h>
    2827
    2928@interface ProgressCell : NSCell
    3029{
    31     tr_stat_t * fStat;
    32     BOOL        fWhiteText;
    33 
    34     NSString  * fDlString;
    35     NSString  * fUlString;
    36 
    37     NSBitmapImageRep * fBackgroundBmp;
    38     NSBitmapImageRep * fProgressBmp;
    3930}
    40 - (id)   init;
    41 - (void) setStat: (tr_stat_t *) stat whiteText: (BOOL) w;
    42 - (void) buildSimpleBar;
    43 - (void) buildAdvancedBar;
    44 - (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view;
    4531@end
    4632
  • branches/new_api/macosx/ProgressCell.m

    r94 r141  
    11/******************************************************************************
    2  * Copyright (c) 2005 Eric Petit
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
    33 *
    44 * Permission is hereby granted, free of charge, to any person obtaining a
     
    8181      0x00ED00FF, 0x00F200FF, 0x00F400FF, 0x00B500FF };
    8282
     83#if 0
    8384/***********************************************************************
    8485 * init
     
    259260    }
    260261}
     262#endif
    261263
    262264/***********************************************************************
     
    268270- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) view
    269271{
     272#if 0
    270273    NSImage * img;
    271274    NSMutableDictionary * attributes;
     
    308311
    309312    [view unlockFocus];
     313#endif
    310314}
    311315
  • branches/new_api/macosx/TorrentTableView.m

    r34 r141  
     1/******************************************************************************
     2 * Copyright (c) 2005-2006 Transmission authors and contributors
     3 *
     4 * Permission is hereby granted, free of charge, to any person obtaining a
     5 * copy of this software and associated documentation files (the "Software"),
     6 * to deal in the Software without restriction, including without limitation
     7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     8 * and/or sell copies of the Software, and to permit persons to whom the
     9 * Software is furnished to do so, subject to the following conditions:
     10 *
     11 * The above copyright notice and this permission notice shall be included in
     12 * all copies or substantial portions of the Software.
     13 *
     14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     20 * DEALINGS IN THE SOFTWARE.
     21 *****************************************************************************/
     22
    123#import "TorrentTableView.h"
    224#import "Controller.h"
     
    88110    else if( [self pointInRevealRect: point] )
    89111    {
     112#if 0
    90113        [fController finderReveal: [NSString stringWithFormat:
    91114            @"%@/%@", [NSString stringWithUTF8String: fStat[row].folder],
    92115            [NSString stringWithUTF8String: fStat[row].info.name]]];
    93116        [self display];
     117#endif
    94118    }
    95119    else if( row >= 0 && col == [self columnWithIdentifier: @"Progress"]
    96120             && ( [e modifierFlags] & NSAlternateKeyMask ) )
    97121    {
    98         [fController advancedChanged: NULL];
     122        [fController advancedChanged: nil];
    99123    }
    100124    else
  • branches/new_api/macosx/Transmission.xcodeproj/project.pbxproj

    r103 r141  
    3737                4DF7500D08A103AD007B0D70 /* Info.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DF7500808A103AD007B0D70 /* Info.png */; };
    3838                4DF7500E08A103AD007B0D70 /* Remove.png in Resources */ = {isa = PBXBuildFile; fileRef = 4DF7500908A103AD007B0D70 /* Remove.png */; };
     39                4DFBC2DF09C0970D00D5C571 /* Torrent.m in Sources */ = {isa = PBXBuildFile; fileRef = 4DFBC2DE09C0970D00D5C571 /* Torrent.m */; };
    3940                8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
    4041                8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
     
    115116                4DF7500808A103AD007B0D70 /* Info.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Info.png; path = Images/Info.png; sourceTree = "<group>"; };
    116117                4DF7500908A103AD007B0D70 /* Remove.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Remove.png; path = Images/Remove.png; sourceTree = "<group>"; };
     118                4DFBC2DD09C0970D00D5C571 /* Torrent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Torrent.h; sourceTree = "<group>"; };
     119                4DFBC2DE09C0970D00D5C571 /* Torrent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Torrent.m; sourceTree = "<group>"; };
    117120                8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
    118121                8D1107320486CEB800E47090 /* Transmission.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Transmission.app; sourceTree = BUILT_PRODUCTS_DIR; };
     
    150153                                4DE5CCA50980735700BE280E /* Badger.h */,
    151154                                4DE5CCA60980735700BE280E /* Badger.m */,
     155                                4DFBC2DD09C0970D00D5C571 /* Torrent.h */,
     156                                4DFBC2DE09C0970D00D5C571 /* Torrent.m */,
    152157                        );
    153158                        name = Classes;
     
    340345                                4DE5CC9D0980656F00BE280E /* StringAdditions.m in Sources */,
    341346                                4DE5CCA70980735700BE280E /* Badger.m in Sources */,
     347                                4DFBC2DF09C0970D00D5C571 /* Torrent.m in Sources */,
    342348                        );
    343349                        runOnlyForDeploymentPostprocessing = 0;
Note: See TracChangeset for help on using the changeset viewer.