Ignore:
Timestamp:
Aug 5, 2011, 11:18:02 PM (10 years ago)
Author:
livings124
Message:

generate the dock menu exclusively in code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r12619 r12628  
    125125
    126126#define UPDATE_UI_SECONDS   1.0
    127 
    128 #define DOCK_SEEDING_TAG        101
    129 #define DOCK_DOWNLOADING_TAG    102
    130127
    131128#define TRANSFER_PLIST  @"/Library/Application Support/Transmission/Transfers.plist"
     
    38813878{
    38823879    NSInteger seeding = 0, downloading = 0;
    3883     for (Torrent * torrent in fTorrents)
    3884     {
    3885         if ([torrent isSeeding])
    3886             seeding++;
    3887         else if ([torrent isActive])
    3888             downloading++;
    3889         else;
    3890     }
    3891    
    3892     NSMenuItem * seedingItem = [fDockMenu itemWithTag: DOCK_SEEDING_TAG],
    3893             * downloadingItem = [fDockMenu itemWithTag: DOCK_DOWNLOADING_TAG];
    3894    
    3895     BOOL hasSeparator = seedingItem || downloadingItem;
     3880    if (!fQuitting)
     3881    {
     3882        for (Torrent * torrent in fTorrents)
     3883        {
     3884            if ([torrent isSeeding])
     3885                seeding++;
     3886            else if ([torrent isActive])
     3887                downloading++;
     3888            else;
     3889        }
     3890    }
     3891   
     3892    NSMenu * menu = [[NSMenu alloc] init];
    38963893   
    38973894    if (seeding > 0)
    38983895    {
    38993896        NSString * title = [NSString stringWithFormat: NSLocalizedString(@"%d Seeding", "Dock item - Seeding"), seeding];
    3900         if (!seedingItem)
    3901         {
    3902             seedingItem = [[[NSMenuItem alloc] initWithTitle: title action: nil keyEquivalent: @""] autorelease];
    3903             [seedingItem setTag: DOCK_SEEDING_TAG];
    3904             [fDockMenu insertItem: seedingItem atIndex: 0];
    3905         }
    3906         else
    3907             [seedingItem setTitle: title];
    3908     }
    3909     else
    3910     {
    3911         if (seedingItem)
    3912             [fDockMenu removeItem: seedingItem];
     3897        [menu addItemWithTitle: title action: nil keyEquivalent: @""];
    39133898    }
    39143899   
     
    39163901    {
    39173902        NSString * title = [NSString stringWithFormat: NSLocalizedString(@"%d Downloading", "Dock item - Downloading"), downloading];
    3918         if (!downloadingItem)
    3919         {
    3920             downloadingItem = [[[NSMenuItem alloc] initWithTitle: title action: nil keyEquivalent: @""] autorelease];
    3921             [downloadingItem setTag: DOCK_DOWNLOADING_TAG];
    3922             [fDockMenu insertItem: downloadingItem atIndex: seeding > 0 ? 1 : 0];
    3923         }
    3924         else
    3925             [downloadingItem setTitle: title];
    3926     }
    3927     else
    3928     {
    3929         if (downloadingItem)
    3930             [fDockMenu removeItem: downloadingItem];
     3903        [menu addItemWithTitle: title action: nil keyEquivalent: @""];
    39313904    }
    39323905   
    39333906    if (seeding > 0 || downloading > 0)
    3934     {
    3935         if (!hasSeparator)
    3936             [fDockMenu insertItem: [NSMenuItem separatorItem] atIndex: (seeding > 0 && downloading > 0) ? 2 : 1];
    3937     }
    3938     else
    3939     {
    3940         if (hasSeparator)
    3941             [fDockMenu removeItemAtIndex: 0];
    3942     }
    3943    
    3944     return fDockMenu;
     3907        [menu addItem: [NSMenuItem separatorItem]];
     3908   
     3909    [menu addItemWithTitle: NSLocalizedString(@"Pause All", "Dock item") action: @selector(stopAllTorrents:) keyEquivalent: @""];
     3910    [menu addItemWithTitle: NSLocalizedString(@"Resume All", "Dock item") action: @selector(resumeAllTorrents:) keyEquivalent: @""];
     3911    [menu addItem: [NSMenuItem separatorItem]];
     3912    [menu addItemWithTitle: NSLocalizedString(@"Speed Limit", "Dock item") action: @selector(toggleSpeedLimit:) keyEquivalent: @""];
     3913   
     3914    return [menu autorelease];
    39453915}
    39463916
Note: See TracChangeset for help on using the changeset viewer.