cap the message log count in the Mac UI
This commit is contained in:
parent
ad06c660c8
commit
25c8e4f0d0
|
@ -125,6 +125,7 @@ typedef enum
|
|||
- (void) openShowSheet: (id) sender;
|
||||
|
||||
- (void) invalidOpenAlert: (NSString *) filename;
|
||||
- (void) invalidOpenMagnetAlert: (NSString *) address;
|
||||
- (void) duplicateOpenAlert: (NSString *) name;
|
||||
|
||||
- (void) openURL: (NSString *) urlString;
|
||||
|
|
|
@ -942,10 +942,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
|||
Torrent * torrent;
|
||||
if (!(torrent = [[Torrent alloc] initWithMagnetAddress: address location: nil lib: fLib]))
|
||||
{
|
||||
NSRunAlertPanel(NSLocalizedString(@"Adding magnetized transfer failed", "Magnet link failed -> title"),
|
||||
[NSString stringWithFormat: NSLocalizedString(@"There was an error when adding the magnet link \"%@\"."
|
||||
" The transfer will not occur.", "Magnet link failed -> message"), address],
|
||||
NSLocalizedString(@"OK", "Magnet link failed -> button"), nil, nil);
|
||||
[self invalidOpenMagnetAlert: address];
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1074,6 +1071,24 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
|||
[alert release];
|
||||
}
|
||||
|
||||
- (void) invalidOpenMagnetAlert: (NSString *) address
|
||||
{
|
||||
if (![fDefaults boolForKey: @"WarningInvalidOpen"])
|
||||
return;
|
||||
|
||||
NSAlert * alert = [[NSAlert alloc] init];
|
||||
[alert setMessageText: NSLocalizedString(@"Adding magnetized transfer failed", "Magnet link failed -> title")];
|
||||
[alert setInformativeText: [NSString stringWithFormat: NSLocalizedString(@"There was an error when adding the magnet link \"%@\"."
|
||||
" The transfer will not occur.", "Magnet link failed -> message"), address]];
|
||||
[alert setAlertStyle: NSWarningAlertStyle];
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Magnet link failed -> button")];
|
||||
|
||||
[alert runModal];
|
||||
if ([[alert suppressionButton] state] == NSOnState)
|
||||
[fDefaults setBool: NO forKey: @"WarningInvalidOpen"];
|
||||
[alert release];
|
||||
}
|
||||
|
||||
- (void) duplicateOpenAlert: (NSString *) name
|
||||
{
|
||||
if (![fDefaults boolForKey: @"WarningDuplicate"])
|
||||
|
@ -1083,7 +1098,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
|||
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"A transfer of \"%@\" already exists.",
|
||||
"Open duplicate alert -> title"), name]];
|
||||
[alert setInformativeText:
|
||||
NSLocalizedString(@"The torrent file cannot be opened because it is a duplicate of an already added transfer.",
|
||||
NSLocalizedString(@"The transfer cannot be added because it is a duplicate of an already existing transfer.",
|
||||
"Open duplicate alert -> message")];
|
||||
[alert setAlertStyle: NSWarningAlertStyle];
|
||||
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Open duplicate alert -> button")];
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#import "NSApplicationAdditions.h"
|
||||
#import "NSStringAdditions.h"
|
||||
#import <transmission.h>
|
||||
#import <utils.h>
|
||||
|
||||
#define LEVEL_ERROR 0
|
||||
#define LEVEL_INFO 1
|
||||
|
@ -190,6 +191,42 @@
|
|||
|
||||
if (changed)
|
||||
{
|
||||
if ([fMessages count] > TR_MAX_MSG_LOG)
|
||||
{
|
||||
const NSUInteger removeCount = [fMessages count] - TR_MAX_MSG_LOG;
|
||||
|
||||
//find the latest message to removed that is also displayed
|
||||
NSDictionary * latestMessageToRemove = nil;
|
||||
for (NSInteger i = removeCount-1; i >= 0; --i)
|
||||
{
|
||||
NSDictionary * message = [fMessages objectAtIndex: i];
|
||||
if ([[message objectForKey: @"Level"] integerValue] <= maxLevel)
|
||||
{
|
||||
latestMessageToRemove = message;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (latestMessageToRemove)
|
||||
{
|
||||
NSSortDescriptor * descriptor = [[[NSSortDescriptor alloc] initWithKey: @"Index" ascending: NO] autorelease];
|
||||
[fDisplayedMessages sortUsingDescriptors: [NSArray arrayWithObject: descriptor]];
|
||||
|
||||
//sort in reverse and find the message within the bounds of the number of messages to remove
|
||||
const NSUInteger displayedCount = [fDisplayedMessages count];
|
||||
const NSUInteger removeDisplayedCount = MIN(removeCount, displayedCount);
|
||||
const NSUInteger lastIndex = [fDisplayedMessages indexOfObject: latestMessageToRemove inRange:
|
||||
NSMakeRange(displayedCount-removeDisplayedCount, removeDisplayedCount)];
|
||||
NSAssert(lastIndex != NSNotFound, @"message to trim not found when it should be");
|
||||
|
||||
NSIndexSet * removeIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(lastIndex, displayedCount-lastIndex)];
|
||||
[fDisplayedMessages removeObjectsAtIndexes: removeIndexes];
|
||||
}
|
||||
|
||||
NSIndexSet * removeIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, removeCount)];
|
||||
[fMessages removeObjectsAtIndexes: removeIndexes];
|
||||
}
|
||||
|
||||
[fDisplayedMessages sortUsingDescriptors: [fMessageTable sortDescriptors]];
|
||||
|
||||
[fMessageTable reloadData];
|
||||
|
|
|
@ -1748,6 +1748,7 @@ int trashDataFile(const char * filename)
|
|||
|
||||
[self createFileList];
|
||||
|
||||
#warning only call when torrent is selected
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName: @"ResetInspector" object: self];
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue