Changeset 9617


Ignore:
Timestamp:
Nov 28, 2009, 8:39:31 PM (12 years ago)
Author:
livings124
Message:

#2624 Message Log's level filter should act as an actual filter, and all messages should be stored

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r9616 r9617  
    295295        tr_bencDictAddBool(&settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, [fDefaults boolForKey: @"UseIncompleteDownloadFolder"]);
    296296       
    297         tr_bencDictAddInt(&settings, TR_PREFS_KEY_MSGLEVEL, [fDefaults integerForKey: @"MessageLevel"]);
     297        tr_bencDictAddInt(&settings, TR_PREFS_KEY_MSGLEVEL, TR_MSG_DBG);
    298298        tr_bencDictAddInt(&settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, [fDefaults integerForKey: @"PeersTotal"]);
    299299        tr_bencDictAddInt(&settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, [fDefaults integerForKey: @"PeersTorrent"]);
  • trunk/macosx/MessageWindowController.h

    r9296 r9617  
    3232    IBOutlet NSButton * fSaveButton, * fClearButton;
    3333   
    34     NSMutableArray * fMessages;
     34    NSMutableArray * fMessages, * fDisplayedMessages;
    3535   
    3636    NSDictionary * fAttributes;
  • trunk/macosx/MessageWindowController.m

    r9610 r9617  
    3232#define LEVEL_DEBUG 2
    3333
    34 #define UPDATE_SECONDS  0.6
     34#define UPDATE_SECONDS  0.75
    3535
    3636@interface MessageWindowController (Private)
     
    5252    [fTimer invalidate];
    5353    [fMessages release];
     54    [fDisplayedMessages release];
    5455   
    5556    [fAttributes release];
     
    6768        name: @"NSTableViewColumnDidResizeNotification" object: fMessageTable];
    6869   
    69     [window setContentBorderThickness: [[fMessageTable enclosingScrollView] frame].origin.y forEdge: NSMinYEdge];
     70    [window setContentBorderThickness: NSMinY([[fMessageTable enclosingScrollView] frame]) forEdge: NSMinYEdge];
    7071   
    7172    //initially sort peer table by date
     
    108109   
    109110    //select proper level in popup button
    110     switch (tr_getMessageLevel())
     111    switch ([[NSUserDefaults standardUserDefaults] integerForKey: @"MessageLevel"])
    111112    {
    112113        case TR_MSG_ERR:
     
    118119        case TR_MSG_DBG:
    119120            [fLevelButton selectItemAtIndex: LEVEL_DEBUG];
     121            break;
    120122    }
    121123   
    122124    fMessages = [[NSMutableArray alloc] init];
     125    fDisplayedMessages = [[NSMutableArray alloc] init];
    123126}
    124127
     
    148151    const BOOL shouldScroll = currentIndex == 0 || [scroller floatValue] == 1.0 || [scroller isHidden]
    149152                                || [scroller knobProportion] == 1.0;
     153   
     154    const NSInteger maxLevel = [[NSUserDefaults standardUserDefaults] integerForKey: @"MessageLevel"];
     155    BOOL changed = NO;
    150156   
    151157    for (tr_msg_list * currentMessage = messages; currentMessage != NULL; currentMessage = currentMessage->next)
     
    166172       
    167173        [fMessages addObject: message];
     174       
     175        if (currentMessage->level <= maxLevel)
     176        {
     177            [fDisplayedMessages addObject: message];
     178            changed = YES;
     179        }
    168180    }
    169181   
    170182    tr_freeMessageList(messages);
    171183   
    172     [fMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
    173    
    174     [fMessageTable reloadData];
    175     if (shouldScroll)
    176         [fMessageTable scrollRowToVisible: [fMessages count]-1];
     184    if (changed)
     185    {
     186        [fDisplayedMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
     187       
     188        [fMessageTable reloadData];
     189        if (shouldScroll)
     190            [fMessageTable scrollRowToVisible: [fDisplayedMessages count]-1];
     191    }
    177192}
    178193
    179194- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView
    180195{
    181     return [fMessages count];
     196    return [fDisplayedMessages count];
    182197}
    183198
     
    185200{
    186201    NSString * ident = [column identifier];
    187     NSDictionary * message = [fMessages objectAtIndex: row];
     202    NSDictionary * message = [fDisplayedMessages objectAtIndex: row];
    188203
    189204    if ([ident isEqualToString: @"Date"])
     
    219234        fAttributes = [[[[column dataCell] attributedStringValue] attributesAtIndex: 0 effectiveRange: NULL] retain];
    220235   
    221     const CGFloat count = floorf([[[fMessages objectAtIndex: row] objectForKey: @"Message"] sizeWithAttributes: fAttributes].width
     236    const CGFloat count = floorf([[[fDisplayedMessages objectAtIndex: row] objectForKey: @"Message"] sizeWithAttributes: fAttributes].width
    222237                                / [column width]);
    223238    return [tableView rowHeight] * (count + 1.0);
     
    226241- (void) tableView: (NSTableView *) tableView sortDescriptorsDidChange: (NSArray *) oldDescriptors
    227242{
    228     [fMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
     243    [fDisplayedMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
    229244    [fMessageTable reloadData];
    230245}
     
    233248                tableColumn: (NSTableColumn *) column row: (NSInteger) row mouseLocation: (NSPoint) mouseLocation
    234249{
    235     NSDictionary * message = [fMessages objectAtIndex: row];
     250    NSDictionary * message = [fDisplayedMessages objectAtIndex: row];
    236251    return [message objectForKey: @"File"];
    237252}
     
    242257    NSMutableArray * messageStrings = [NSMutableArray arrayWithCapacity: [indexes count]];
    243258   
    244     for (NSDictionary * message in [fMessages objectsAtIndexes: indexes])
     259    for (NSDictionary * message in [fDisplayedMessages objectsAtIndexes: indexes])
    245260        [messageStrings addObject: [self stringForMessage: message]];
    246261   
     
    272287- (void) changeLevel: (id) sender
    273288{
    274     [self updateLog: nil];
    275    
    276289    NSInteger level;
    277290    switch ([fLevelButton indexOfSelectedItem])
     
    288301    }
    289302   
    290     tr_setMessageLevel(level);
     303    if ([[NSUserDefaults standardUserDefaults] integerForKey: @"MessageLevel"] == level)
     304        return;
     305   
    291306    [[NSUserDefaults standardUserDefaults] setInteger: level forKey: @"MessageLevel"];
     307   
     308    if (level == TR_MSG_DBG) //all messages at this level
     309        [fDisplayedMessages setArray: fMessages];
     310    else
     311    {
     312        [fDisplayedMessages removeAllObjects];
     313        for (NSDictionary * message in fMessages)
     314            if ([[message objectForKey: @"Level"] integerValue] <= level)
     315                [fDisplayedMessages addObject: message];
     316    }
     317   
     318    [fDisplayedMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
     319   
     320    [fMessageTable deselectAll: nil];
     321    [fMessageTable reloadData];
    292322}
    293323
     
    295325{
    296326    [fMessages removeAllObjects];
     327    [fDisplayedMessages removeAllObjects];
    297328    [fMessageTable reloadData];
    298329}
     
    303334    NSSortDescriptor * descriptor = [[[NSSortDescriptor alloc] initWithKey: @"Index" ascending: YES] autorelease];
    304335    NSArray * descriptors = [[NSArray alloc] initWithObjects: descriptor, nil];
    305     NSArray * sortedMessages = [[fMessages sortedArrayUsingDescriptors: descriptors] retain];
     336    NSArray * sortedMessages = [[fDisplayedMessages sortedArrayUsingDescriptors: descriptors] retain];
    306337    [descriptors release];
    307338   
Note: See TracChangeset for help on using the changeset viewer.