#893 add statistics "reset" button

This commit is contained in:
Mitchell Livingston
2008-04-22 21:04:01 +00:00
parent 1b901ca9df
commit 468104028b
5 changed files with 264 additions and 424 deletions

View File

@@ -24,6 +24,7 @@
#import "StatsWindowController.h"
#import "NSStringAdditions.h"
#import "NSApplicationAdditions.h"
#define UPDATE_SECONDS 1.0
@@ -31,6 +32,9 @@
- (void) updateStats;
- (void) performResetStats;
- (void) resetSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info;
@end
@implementation StatsWindowController
@@ -106,9 +110,20 @@ tr_handle * fLib;
NSRect windowRect = [[self window] frame];
windowRect.size.width += maxWidth - oldWidth;
[[self window] setFrame: windowRect display: YES];
//resize reset button
float oldButtonWidth = [fResetButton frame].size.width;
[fResetButton setTitle: NSLocalizedString(@"Reset", "Stats window -> reset button")];
[fResetButton sizeToFit];
NSRect buttonFrame = [fResetButton frame];
buttonFrame.size.width += 10.0;
buttonFrame.origin.x -= buttonFrame.size.width - oldButtonWidth;
[fResetButton setFrame: buttonFrame];
}
- (void) windowWillClose: (id)sender
- (void) windowWillClose: (id) sender
{
[fTimer invalidate];
@@ -116,6 +131,31 @@ tr_handle * fLib;
fStatsWindowInstance = nil;
}
- (void) resetStats: (id) sender
{
if (![[NSUserDefaults standardUserDefaults] boolForKey: @"WarningResetStats"])
{
[self performResetStats];
return;
}
NSAlert * alert = [[NSAlert alloc] init];
[alert setMessageText: NSLocalizedString(@"Are you sure you want to reset usage statistics?", "Stats reset -> title")];
[alert setInformativeText: NSLocalizedString(@"This will clear the global statistics displayed by Transmission. "
"Individual transfer statistics will not be effected.", "Stats reset -> message")];
[alert setAlertStyle: NSWarningAlertStyle];
[alert addButtonWithTitle: NSLocalizedString(@"Reset", "Stats reset -> button")];
[alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Stats reset -> button")];
if ([NSApp isOnLeopardOrBetter])
[alert setShowsSuppressionButton: YES];
else
[alert addButtonWithTitle: NSLocalizedString(@"Don't Alert Again", "Open duplicate alert -> button")];
[alert beginSheetModalForWindow: [self window] modalDelegate: self
didEndSelector: @selector(resetSheetClosed:returnCode:contextInfo:) contextInfo: nil];
}
@end
@implementation StatsWindowController (Private)
@@ -160,4 +200,21 @@ tr_handle * fLib;
statsAll.sessionCount]];
}
- (void) performResetStats
{
tr_clearSessionStats(fLib);
[self updateStats];
}
- (void) resetSheetClosed: (NSAlert *) alert returnCode: (int) code contextInfo: (void *) info
{
[[alert window] orderOut: nil];
if (([NSApp isOnLeopardOrBetter] ? [[alert suppressionButton] state] == NSOnState : code == NSAlertThirdButtonReturn))
[[NSUserDefaults standardUserDefaults] setBool: NO forKey: @"WarningResetStats"];
if (code == NSAlertFirstButtonReturn)
[self performResetStats];
}
@end