Changeset 3264


Ignore:
Timestamp:
Oct 1, 2007, 9:52:31 PM (14 years ago)
Author:
livings124
Message:

"switch-ify" some code

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/InfoWindowController.m

    r3259 r3264  
    335335- (Torrent *) selectedTorrent
    336336{
    337     return fTorrents && [fTorrents count] > 0 ? [fTorrents objectAtIndex: 0] : nil;
     337    return fTorrents && [fTorrents count] == 1 ? [fTorrents objectAtIndex: 0] : nil;
    338338}
    339339
     
    431431    Torrent * torrent = [fTorrents objectAtIndex: 0];
    432432   
    433     int seeders = [torrent seeders], leechers = [torrent leechers], downloaded = [torrent completedFromTracker];
    434     [fSeedersField setStringValue: seeders < 0 ? @"" : [NSString stringWithFormat: @"%d", seeders]];
    435     [fLeechersField setStringValue: leechers < 0 ? @"" : [NSString stringWithFormat: @"%d", leechers]];
    436     [fCompletedFromTrackerField setStringValue: downloaded < 0 ? @"" : [NSString stringWithFormat: @"%d", downloaded]];
     433    int seeders = [torrent seeders], leechers = [torrent leechers], completed = [torrent completedFromTracker];
     434    [fSeedersField setStringValue: seeders > 0 ? [NSString stringWithFormat: @"%d", seeders] : @""];
     435    [fLeechersField setStringValue: leechers > 0 ? [NSString stringWithFormat: @"%d", leechers] : @""];
     436    [fCompletedFromTrackerField setStringValue: completed > 0 ? [NSString stringWithFormat: @"%d", completed] : @""];
    437437   
    438438    BOOL active = [torrent isActive];
     
    461461                                        NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), count]];
    462462           
    463             connected = [NSString stringWithFormat: @"%@: %@", connected, [components componentsJoinedByString: @", "]];
     463            connected = [connected stringByAppendingFormat: @": %@", [components componentsJoinedByString: @", "]];
    464464        }
    465465       
    466466        [fConnectedPeersField setStringValue: connected];
    467     }
    468     else
     467       
     468        [fDownloadingFromField setIntValue: [torrent peersSendingToUs]];
     469        [fUploadingToField setIntValue: [torrent peersGettingFromUs]];
     470    }
     471    else
     472    {
    469473        [fConnectedPeersField setStringValue: NSLocalizedString(@"info not available", "Inspector -> Peers tab -> peers")];
    470    
    471     [fDownloadingFromField setStringValue: active ? [NSString stringWithFormat: @"%d", [torrent peersSendingToUs]] : @""];
    472     [fUploadingToField setStringValue: active ? [NSString stringWithFormat: @"%d", [torrent peersGettingFromUs]] : @""];
     474        [fDownloadingFromField setStringValue: @""];
     475        [fUploadingToField setStringValue: @""];
     476    }
     477   
    473478    [fKnownField setIntValue: [torrent totalPeersKnown]];
    474479   
  • trunk/macosx/MessageWindowController.m

    r3112 r3264  
    9090    //select proper level in popup button
    9191    int level = tr_getMessageLevel();
    92     if (level == TR_MSG_ERR)
    93         [fLevelButton selectItemAtIndex: LEVEL_ERROR];
    94     else if (level == TR_MSG_INF)
    95         [fLevelButton selectItemAtIndex: LEVEL_INFO];
    96     else
    97         [fLevelButton selectItemAtIndex: LEVEL_DEBUG];
     92    switch (level)
     93        {
     94            case TR_MSG_ERR:
     95                [fLevelButton selectItemAtIndex: LEVEL_ERROR];
     96                break;
     97            case TR_MSG_INF:
     98                [fLevelButton selectItemAtIndex: LEVEL_INFO];
     99                break;
     100            case TR_MSG_DBG:
     101                [fLevelButton selectItemAtIndex: LEVEL_DEBUG];
     102        }
    98103   
    99104    [self setDebugWarningHidden: level != TR_MSG_DBG];
     
    145150    else if ([ident isEqualToString: @"Level"])
    146151    {
    147         int level = [[message objectForKey: @"Level"] intValue];
    148         if (level == TR_MSG_ERR)
    149             return fErrorImage;
    150         else if (level == TR_MSG_INF)
    151             return fInfoImage;
    152         else
    153             return fDebugImage;
     152        switch ([[message objectForKey: @"Level"] intValue])
     153        {
     154            case TR_MSG_ERR:
     155                return fErrorImage;
     156            case TR_MSG_INF:
     157                return fInfoImage;
     158            case TR_MSG_DBG:
     159                return fDebugImage;
     160            default:
     161                return nil;
     162        }
    154163    }
    155164    else
     
    198207    [self updateLog: nil];
    199208   
    200     int selection = [fLevelButton indexOfSelectedItem], level;
    201     if (selection == LEVEL_INFO)
    202         level = TR_MSG_INF;
    203     else if (selection == LEVEL_DEBUG)
    204         level = TR_MSG_DBG;
    205     else
    206         level = TR_MSG_ERR;
     209    int level;
     210    switch ([fLevelButton indexOfSelectedItem])
     211    {
     212        case LEVEL_ERROR:
     213            level = TR_MSG_ERR;
     214            break;
     215        case LEVEL_INFO:
     216            level = TR_MSG_INF;
     217            break;
     218        case LEVEL_DEBUG:
     219            level = TR_MSG_DBG;
     220            break;
     221    }
    207222   
    208223    [self setDebugWarningHidden: level != TR_MSG_DBG];
     
    273288- (NSString *) stringForMessage: (NSDictionary *) message
    274289{
    275     int level = [[message objectForKey: @"Level"] intValue];
    276     NSString * levelString;
    277     if (level == TR_MSG_ERR)
    278         levelString = @"Error";
    279     else if (level == TR_MSG_INF)
    280         levelString = @"Info";
    281     else
    282         levelString = @"Debug";
    283    
    284     return [NSString stringWithFormat: @"%@ [%@] %@", [message objectForKey: @"Date"], levelString, [message objectForKey: @"Message"]];
     290    NSString * level;
     291    switch ([[message objectForKey: @"Level"] intValue])
     292    {
     293        case TR_MSG_ERR:
     294            level = @"Error";
     295            break;
     296        case TR_MSG_INF:
     297            level = @"Info";
     298            break;
     299        case TR_MSG_DBG:
     300            level = @"Debug";
     301            break;
     302        default:
     303            level = @"";
     304    }
     305   
     306    return [NSString stringWithFormat: @"%@ [%@] %@", [message objectForKey: @"Date"], level, [message objectForKey: @"Message"]];
    285307}
    286308
  • trunk/macosx/Torrent.m

    r3259 r3264  
    10081008        case TR_STATUS_DOWNLOAD:
    10091009            return [self eta] >= 0 ? [self etaString] : NSLocalizedString(@"Unknown", "Torrent -> remaining time");
    1010             break;
    10111010       
    10121011        case TR_STATUS_SEED:
     
    10141013            return [NSLocalizedString(@"Ratio: ", "Torrent -> status string") stringByAppendingString:
    10151014                                                                            [NSString stringForRatio: [self ratio]]];
    1016             break;
    10171015       
    10181016        default:
     
    10271025        case TR_STATUS_STOPPED:
    10281026            return NSLocalizedString(@"Paused", "Torrent -> status string");
    1029             break;
    10301027       
    10311028        case TR_STATUS_STOPPING:
    10321029            return [NSLocalizedString(@"Stopping", "Torrent -> status string") stringByAppendingEllipsis];
    1033             break;
    10341030
    10351031        case TR_STATUS_CHECK:
    10361032            return [NSString stringWithFormat: NSLocalizedString(@"Checking existing data (%.2f%%)",
    10371033                                    "Torrent -> status string"), 100.0 * fStat->recheckProgress];
    1038             break;
    10391034       
    10401035        case TR_STATUS_CHECK_WAIT:
    10411036            return [NSLocalizedString(@"Waiting to check existing data", "Torrent -> status string") stringByAppendingEllipsis];
    1042             break;
    10431037
    10441038        case TR_STATUS_DOWNLOAD:
    10451039            return NSLocalizedString(@"Downloading", "Torrent -> status string");
    1046             break;
    10471040
    10481041        case TR_STATUS_SEED:
    10491042        case TR_STATUS_DONE:
    10501043            return NSLocalizedString(@"Seeding", "Torrent -> status string");
    1051             break;
    10521044       
    10531045        default:
Note: See TracChangeset for help on using the changeset viewer.