2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2011-2023 Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2011-07-23 15:54:02 +00:00
|
|
|
|
|
|
|
#import "GlobalOptionsPopoverViewController.h"
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@interface GlobalOptionsPopoverViewController ()
|
|
|
|
|
|
|
|
@property(nonatomic, readonly) tr_session* fHandle;
|
|
|
|
@property(nonatomic, readonly) NSUserDefaults* fDefaults;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fUploadLimitField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDownloadLimitField;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fRatioStopField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fIdleStopField;
|
|
|
|
|
|
|
|
@property(nonatomic, copy) NSString* fInitialString;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2011-07-23 15:54:02 +00:00
|
|
|
@implementation GlobalOptionsPopoverViewController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)initWithHandle:(tr_session*)handle
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithNibName:@"GlobalOptionsPopover" bundle:nil]))
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
_fHandle = handle;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
_fDefaults = NSUserDefaults.standardUserDefaults;
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-23 15:54:02 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-10-25 16:14:42 +00:00
|
|
|
self.fUploadLimitField.integerValue = [self.fDefaults integerForKey:@"UploadLimit"];
|
|
|
|
self.fDownloadLimitField.integerValue = [self.fDefaults integerForKey:@"DownloadLimit"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioStopField.floatValue = [self.fDefaults floatForKey:@"RatioLimit"];
|
|
|
|
self.fIdleStopField.integerValue = [self.fDefaults integerForKey:@"IdleLimitMinutes"];
|
2015-12-27 01:48:27 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[self.view setFrameSize:self.view.fittingSize];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)updatedDisplayString:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"RefreshTorrentTable" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setDownSpeedSetting:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_sessionLimitSpeed(self.fHandle, TR_DOWN, [self.fDefaults boolForKey:@"CheckDownload"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setDownSpeedLimit:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const limit = [sender integerValue];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setInteger:limit forKey:@"DownloadLimit"];
|
|
|
|
tr_sessionSetSpeedLimit_KBps(self.fHandle, TR_DOWN, limit);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateSpeedLimitValuesOutsidePrefs" object:nil];
|
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setUpSpeedSetting:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_sessionLimitSpeed(self.fHandle, TR_UP, [self.fDefaults boolForKey:@"CheckUpload"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateSpeedLimitValuesOutsidePrefs" object:nil];
|
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setUpSpeedLimit:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const limit = [sender integerValue];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setInteger:limit forKey:@"UploadLimit"];
|
|
|
|
tr_sessionSetSpeedLimit_KBps(self.fHandle, TR_UP, limit);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"SpeedLimitUpdate" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setRatioStopSetting:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_sessionSetRatioLimited(self.fHandle, [self.fDefaults boolForKey:@"RatioCheck"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-05 02:42:04 +00:00
|
|
|
//reload main table for seeding progress
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-23 15:54:02 +00:00
|
|
|
//reload global settings in inspector
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateGlobalOptions" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setRatioStopLimit:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const value = [sender floatValue];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setFloat:value forKey:@"RatioLimit"];
|
|
|
|
tr_sessionSetRatioLimit(self.fHandle, value);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateRatioStopValueOutsidePrefs" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-05 02:42:04 +00:00
|
|
|
//reload main table for seeding progress
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-23 15:54:02 +00:00
|
|
|
//reload global settings in inspector
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateGlobalOptions" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setIdleStopSetting:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
tr_sessionSetIdleLimited(self.fHandle, [self.fDefaults boolForKey:@"IdleLimitCheck"]);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-05 02:38:11 +00:00
|
|
|
//reload main table for remaining seeding time
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-23 15:54:02 +00:00
|
|
|
//reload global settings in inspector
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateGlobalOptions" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setIdleStopLimit:(id)sender
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const value = [sender integerValue];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fDefaults setInteger:value forKey:@"IdleLimitMinutes"];
|
|
|
|
tr_sessionSetIdleLimit(self.fHandle, value);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateIdleStopValueOutsidePrefs" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-08-05 02:38:11 +00:00
|
|
|
//reload main table for remaining seeding time
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-23 15:54:02 +00:00
|
|
|
//reload global settings in inspector
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateGlobalOptions" object:nil];
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)control:(NSControl*)control textShouldBeginEditing:(NSText*)fieldEditor
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fInitialString = control.stringValue;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-07-23 15:54:02 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)control:(NSControl*)control didFailToFormatString:(NSString*)string errorDescription:(NSString*)error
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
|
|
|
NSBeep();
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fInitialString)
|
2011-07-23 15:54:02 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
control.stringValue = self.fInitialString;
|
|
|
|
self.fInitialString = nil;
|
2011-07-23 15:54:02 +00:00
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|