Changeset 55


Ignore:
Timestamp:
Jan 29, 2006, 1:20:22 AM (15 years ago)
Author:
titer
Message:

The quit dialog now displays the number of active torrents
Disables idle sleep if at least one torrent is active
Cosmetic changes

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r36 r55  
    3434{
    3535    tr_handle_t                 * fHandle;
    36     int                         fCount, fCompleted;
     36    int                         fCount, fSeeding, fDownloading, fCompleted;
    3737    tr_stat_t                   * fStat;
    3838    int                         fResumeOnWake[TR_MAX_TORRENT_COUNT];
  • trunk/macosx/Controller.m

    r38 r55  
    137137    //initialize badging
    138138    fBadger = [[Badger alloc] init];
    139     fCompleted = 0;
    140139   
    141140    //update the interface every 500 ms
    142141    fCount = 0;
    143     fStat  = NULL;
     142    fDownloading = 0;
     143    fSeeding = 0;
     144    fCompleted = 0;
     145
     146    fStat  = nil;
    144147    fTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5 target: self
    145148        selector: @selector( updateUI: ) userInfo: NULL repeats: YES];
     
    174177- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
    175178{
    176     if ([[fDefaults stringForKey: @"CheckQuit"] isEqualToString:@"YES"])
    177     {
    178         int i;
    179         for( i = 0; i < fCount; i++ )
    180         {
    181             if( fStat[i].status & ( TR_STATUS_CHECK |
    182                     TR_STATUS_DOWNLOAD ) )
    183             {
    184                 NSBeginAlertSheet(@"Confirm Quit",
    185                                 @"Quit", @"Cancel", nil,
    186                                 fWindow, self,
    187                                 @selector(quitSheetDidEnd:returnCode:contextInfo:),
    188                                 NULL, NULL, @"There are active torrents. Do you really want to quit?");
    189                 return NSTerminateLater;
    190             }
    191         }
    192     }
     179    int active = fDownloading + fSeeding;
     180    if (active > 0 && [[NSUserDefaults standardUserDefaults] boolForKey: @"CheckQuit"])
     181    {
     182        NSString * message = active == 1
     183            ? @"There is an active torrent. Do you really want to quit?"
     184            : [NSString stringWithFormat:
     185                @"There are %d active torrents. Do you really want to quit?", fDownloading];
     186
     187        NSBeginAlertSheet(@"Confirm Quit",
     188                            @"Quit", @"Cancel", nil,
     189                            fWindow, self,
     190                            @selector(quitSheetDidEnd:returnCode:contextInfo:),
     191                            nil, nil, message);
     192        return NSTerminateLater;
     193    }                                                                           
    193194   
    194195    [self quitProcedure];
     
    454455{
    455456    if ( fStat[idx].status & ( TR_STATUS_CHECK
    456         | TR_STATUS_DOWNLOAD)  )
    457     {
    458         if ([[fDefaults stringForKey: @"CheckRemove"] isEqualToString:@"YES"])
     457        | TR_STATUS_DOWNLOAD | TR_STATUS_SEED )  )
     458    {
     459        if ([fDefaults boolForKey: @"CheckRemove"])
    459460        {
    460461            NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:
     
    564565       
    565566    fCount = tr_torrentStat( fHandle, &fStat );
     567    fDownloading = 0;
     568    fSeeding = 0;
    566569    [fTableView updateUI: fStat];
    567570
     
    586589    for (i = 0; i < fCount; i++)
    587590    {
     591        if (fStat[i].status & (TR_STATUS_CHECK | TR_STATUS_DOWNLOAD))
     592            fDownloading++;
     593        else if (fStat[i].status & TR_STATUS_SEED)
     594            fSeeding++;
     595
    588596        if( !tr_getFinished( fHandle, i ) )
    589597            continue;
     
    799807- (BOOL)validateToolbarItem:(NSToolbarItem *)toolbarItem
    800808{
     809    SEL action = [toolbarItem action];
     810
    801811    //enable remove item
    802     if ([toolbarItem action] == @selector(removeTorrent:))
     812    if (action == @selector(removeTorrent:))
    803813        return [fTableView selectedRow] >= 0;
    804814       
    805     //enable pause all and resume all items
    806     if ([toolbarItem action] == @selector(stopAllTorrents:)
    807             || [toolbarItem action] == @selector(resumeAllTorrents:))
    808         return fCount > 0;
     815
     816    //enable resume all item
     817    if (action == @selector(resumeAllTorrents:))
     818        return fCount > fDownloading + fSeeding;
     819
     820    //enable pause all item
     821    if (action == @selector(stopAllTorrents:))
     822        return fDownloading > 0 || fSeeding > 0;                               
    809823   
    810824    return YES;
     
    813827- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
    814828{
     829    SEL action = [menuItem action];
     830
    815831    //disable menus if customize sheet is active
    816832    if ([fToolbar customizationPaletteIsRunning])
     
    818834       
    819835    //enable customize toolbar item
    820     if ([menuItem action] == @selector(showHideToolbar:))
     836    if (action == @selector(showHideToolbar:))
    821837    {
    822838        [menuItem setTitle: [fToolbar isVisible] ? @"Hide Toolbar" : @"Show Toolbar"];
     
    825841       
    826842    //enable show info
    827     if ([menuItem action] == @selector(showInfo:))
     843    if (action == @selector(showInfo:))
    828844    {
    829845        [menuItem setTitle: [fInfoPanel isVisible] ? @"Hide Info" : @"Show Info"];
    830846        return YES;
    831847    }
    832    
    833     //enable pause all and resume all
    834     if ([menuItem action] == @selector(stopAllTorrents:) || [menuItem action] == @selector(resumeAllTorrents:))
    835         return fCount > 0;
    836        
     848
     849    //enable resume all item
     850    if (action == @selector(resumeAllTorrents:))
     851        return fCount > fDownloading + fSeeding;
     852
     853    //enable pause all item
     854    if (action == @selector(stopAllTorrents:))
     855        return fDownloading > 0 || fSeeding > 0;                               
     856   
    837857    int row = [fTableView selectedRow];
    838858       
    839859    //enable remove items
    840     if ([menuItem action] == @selector(removeTorrent:)
    841         || [menuItem action] == @selector(removeTorrentDeleteFile:)
    842         || [menuItem action] == @selector(removeTorrentDeleteData:)
    843         || [menuItem action] == @selector(removeTorrentDeleteBoth:))
     860    if (action == @selector(removeTorrent:)
     861        || action == @selector(removeTorrentDeleteFile:)
     862        || action == @selector(removeTorrentDeleteData:)
     863        || action == @selector(removeTorrentDeleteBoth:))
    844864    {
    845865        //append or remove ellipsis when needed
     
    859879   
    860880    //enable reveal in finder item
    861     if ([menuItem action] == @selector(revealFromMenu:))
     881    if (action == @selector(revealFromMenu:))
    862882        return row >= 0;
    863883       
    864884    //enable and change pause / remove item
    865     if ([menuItem action] == @selector(resumeTorrent:) || [menuItem action] == @selector(stopTorrent:))
     885    if (action == @selector(resumeTorrent:) || action == @selector(stopTorrent:))
    866886    {
    867887        if (row >= 0 && fStat[row].status & TR_STATUS_PAUSE)
     
    912932
    913933        case kIOMessageCanSystemSleep:
    914             /* Do not prevent idle sleep */
    915             /* TODO: prevent it unless there are all paused? */
    916             IOAllowPowerChange( fRootPort, (long) messageArgument );
     934            /* Prevent idle sleep unless all paused */
     935            if (fDownloading > 0 || fSeeding > 0)
     936                IOCancelPowerChange( fRootPort, (long) messageArgument );
     937            else
     938                IOAllowPowerChange( fRootPort, (long) messageArgument );
    917939            break;
    918940
Note: See TracChangeset for help on using the changeset viewer.