mirror of
https://github.com/transmission/transmission.git
synced 2025-12-25 04:45:56 +00:00
#893 add statistics "reset" button
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user