2023-11-01 21:11:11 +00:00
|
|
|
// This file Copyright © 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.
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
#import "InfoOptionsViewController.h"
|
2011-02-12 03:13:14 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2010-03-06 23:12:30 +00:00
|
|
|
#import "Torrent.h"
|
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
typedef NS_ENUM(NSInteger, OptionPopupType) {
|
|
|
|
OptionPopupTypeGlobal = 0,
|
|
|
|
OptionPopupTypeNoLimit = 1,
|
|
|
|
OptionPopupTypeLimit = 2,
|
|
|
|
};
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
typedef NS_ENUM(NSUInteger, OptionPopupPriority) {
|
|
|
|
OptionPopupPriorityHigh = 0,
|
|
|
|
OptionPopupPriorityNormal = 1,
|
|
|
|
OptionPopupPriorityLow = 2,
|
|
|
|
};
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
static NSInteger const kInvalidValue = -99;
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
static CGFloat const kStackViewInset = 12.0;
|
|
|
|
static CGFloat const kStackViewSpacing = 8.0;
|
2022-07-17 23:04:32 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@interface InfoOptionsViewController ()
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
@property(nonatomic, copy) NSArray<Torrent*>* fTorrents;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
|
|
|
@property(nonatomic) BOOL fSet;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSPopUpButton* fPriorityPopUp;
|
|
|
|
@property(nonatomic) IBOutlet NSPopUpButton* fRatioPopUp;
|
|
|
|
@property(nonatomic) IBOutlet NSPopUpButton* fIdlePopUp;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fUploadLimitCheck;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fDownloadLimitCheck;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fGlobalLimitCheck;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fRemoveSeedingCompleteCheck;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fUploadLimitField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDownloadLimitField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fRatioLimitField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fIdleLimitField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fUploadLimitLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDownloadLimitLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fIdleLimitLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fRatioLimitGlobalLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fIdleLimitGlobalLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fPeersConnectLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fPeersConnectField;
|
|
|
|
|
|
|
|
@property(nonatomic, copy) NSString* fInitialString;
|
2010-03-09 02:26:52 +00:00
|
|
|
|
2022-07-17 23:04:32 +00:00
|
|
|
@property(nonatomic) IBOutlet NSStackView* fOptionsStackView;
|
|
|
|
@property(nonatomic) IBOutlet NSView* fSeedingView;
|
2022-12-21 20:21:16 +00:00
|
|
|
@property(nonatomic, readonly) CGFloat fHeightChange;
|
2022-12-16 18:27:37 +00:00
|
|
|
@property(nonatomic, readwrite) CGFloat fCurrentHeight;
|
|
|
|
@property(nonatomic, readonly) CGFloat fHorizLayoutHeight;
|
|
|
|
@property(nonatomic, readonly) CGFloat fHorizLayoutWidth;
|
|
|
|
@property(nonatomic, readonly) CGFloat fVertLayoutHeight;
|
2022-07-17 23:04:32 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
@end
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@implementation InfoOptionsViewController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)init
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithNibName:@"InfoOptionsView" bundle:nil]))
|
2010-03-14 03:09:12 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
self.title = NSLocalizedString(@"Options", "Inspector view -> title");
|
2010-03-14 03:09:12 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2011-02-12 03:28:36 +00:00
|
|
|
{
|
2022-12-16 18:27:37 +00:00
|
|
|
[self checkWindowSize];
|
|
|
|
|
2011-02-12 03:28:36 +00:00
|
|
|
[self setGlobalLabels];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(setGlobalLabels) name:@"UpdateGlobalOptions" object:nil];
|
|
|
|
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(updateOptionsNotification:)
|
|
|
|
name:@"UpdateOptionsNotification"
|
|
|
|
object:nil];
|
2011-02-12 03:28:36 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 18:27:37 +00:00
|
|
|
- (CGFloat)fHorizLayoutHeight
|
2022-07-17 23:04:32 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
return NSHeight(self.fPriorityView.frame) + 2 * kStackViewInset;
|
2022-07-17 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 18:27:37 +00:00
|
|
|
- (CGFloat)fHorizLayoutWidth
|
2022-07-17 23:04:32 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
return NSWidth(self.fPriorityView.frame) + NSWidth(self.fSeedingView.frame) + (2 * kStackViewInset) + kStackViewSpacing;
|
2022-07-17 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 18:27:37 +00:00
|
|
|
- (CGFloat)fVertLayoutHeight
|
2022-07-17 23:04:32 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
return NSHeight(self.fPriorityView.frame) + NSHeight(self.fSeedingView.frame) + (2 * kStackViewInset) + kStackViewSpacing;
|
2022-07-17 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
2022-12-16 18:27:37 +00:00
|
|
|
- (CGFloat)fHeightChange
|
|
|
|
{
|
|
|
|
return self.oldHeight - self.fCurrentHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)viewRect
|
2022-07-17 23:04:32 +00:00
|
|
|
{
|
2022-12-21 20:21:16 +00:00
|
|
|
NSRect viewRect = self.view.frame;
|
2022-07-17 23:04:32 +00:00
|
|
|
|
2022-12-21 20:21:16 +00:00
|
|
|
CGFloat difference = self.fHeightChange;
|
2022-12-24 17:54:37 +00:00
|
|
|
|
|
|
|
// we check for existence of self.view.window
|
|
|
|
// as when view is shown from TorrentTableView.mm popover we don't want to customize the view height
|
|
|
|
if (self.view.window)
|
2022-12-16 18:27:37 +00:00
|
|
|
{
|
|
|
|
viewRect.size.height -= difference;
|
|
|
|
}
|
|
|
|
|
|
|
|
return viewRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)checkLayout
|
|
|
|
{
|
|
|
|
if (NSWidth(self.view.window.frame) >= self.fHorizLayoutWidth + 1)
|
2022-07-17 23:04:32 +00:00
|
|
|
{
|
|
|
|
self.fOptionsStackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
|
2022-12-16 18:27:37 +00:00
|
|
|
self.fCurrentHeight = self.fHorizLayoutHeight;
|
2022-07-17 23:04:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.fOptionsStackView.orientation = NSUserInterfaceLayoutOrientationVertical;
|
2022-12-16 18:27:37 +00:00
|
|
|
self.fCurrentHeight = self.fVertLayoutHeight;
|
2022-07-17 23:04:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:27:37 +00:00
|
|
|
- (void)checkWindowSize
|
2022-07-17 23:04:32 +00:00
|
|
|
{
|
2022-12-16 18:27:37 +00:00
|
|
|
self.oldHeight = self.fCurrentHeight;
|
2022-07-17 23:04:32 +00:00
|
|
|
|
2022-12-24 17:54:37 +00:00
|
|
|
[self updateWindowLayout];
|
2022-07-17 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateWindowLayout
|
|
|
|
{
|
2022-12-24 17:54:37 +00:00
|
|
|
// we check for existence of self.view.window
|
|
|
|
// as when view is shown from TorrentTableView.mm popover we don't want to customize the view height
|
|
|
|
if (self.view.window)
|
2022-07-17 23:04:32 +00:00
|
|
|
{
|
2022-12-16 18:27:37 +00:00
|
|
|
[self checkLayout];
|
|
|
|
|
|
|
|
CGFloat difference = self.fHeightChange;
|
|
|
|
|
2022-07-17 23:04:32 +00:00
|
|
|
NSRect windowRect = self.view.window.frame;
|
|
|
|
windowRect.origin.y += difference;
|
|
|
|
windowRect.size.height -= difference;
|
|
|
|
|
|
|
|
self.view.window.minSize = NSMakeSize(self.view.window.minSize.width, NSHeight(windowRect));
|
|
|
|
self.view.window.maxSize = NSMakeSize(FLT_MAX, NSHeight(windowRect));
|
|
|
|
|
|
|
|
self.view.frame = [self viewRect];
|
|
|
|
[self.view.window setFrame:windowRect display:YES animate:YES];
|
|
|
|
}
|
2022-12-24 17:54:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// set popover width
|
|
|
|
NSRect rect = self.view.frame;
|
|
|
|
rect.size.width = NSWidth(self.fOptionsStackView.frame) + (2 * kStackViewInset);
|
|
|
|
self.view.frame = rect;
|
|
|
|
}
|
2022-07-17 23:04:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)setInfoForTorrents:(NSArray<Torrent*>*)torrents
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2010-04-17 18:44:34 +00:00
|
|
|
//don't check if it's the same in case the metadata changed
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTorrents = torrents;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSet = NO;
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateInfo
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fSet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
[self setupInfo];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSet = YES;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateOptions
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTorrents.count == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//get bandwidth info
|
2022-02-22 16:04:20 +00:00
|
|
|
NSEnumerator* enumerator = [self.fTorrents objectEnumerator];
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
NSInteger uploadUseSpeedLimit = [torrent usesSpeedLimit:YES] ? NSControlStateValueOn : NSControlStateValueOff;
|
2022-12-21 20:21:16 +00:00
|
|
|
NSUInteger uploadSpeedLimit = [torrent speedLimit:YES];
|
|
|
|
BOOL multipleUploadSpeedLimits = NO;
|
2021-10-31 15:18:27 +00:00
|
|
|
NSInteger downloadUseSpeedLimit = [torrent usesSpeedLimit:NO] ? NSControlStateValueOn : NSControlStateValueOff;
|
2022-12-21 20:21:16 +00:00
|
|
|
NSUInteger downloadSpeedLimit = [torrent speedLimit:NO];
|
|
|
|
BOOL multipleDownloadSpeedLimits = NO;
|
2021-10-31 15:18:27 +00:00
|
|
|
NSInteger globalUseSpeedLimit = torrent.usesGlobalSpeedLimit ? NSControlStateValueOn : NSControlStateValueOff;
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject]) &&
|
2022-12-21 20:21:16 +00:00
|
|
|
(uploadUseSpeedLimit != NSControlStateValueMixed || !multipleUploadSpeedLimits || downloadUseSpeedLimit != NSControlStateValueMixed ||
|
|
|
|
!multipleDownloadSpeedLimits || globalUseSpeedLimit != NSControlStateValueMixed))
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
if (uploadUseSpeedLimit != NSControlStateValueMixed &&
|
|
|
|
uploadUseSpeedLimit != ([torrent usesSpeedLimit:YES] ? NSControlStateValueOn : NSControlStateValueOff))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
uploadUseSpeedLimit = NSControlStateValueMixed;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-12-21 20:21:16 +00:00
|
|
|
if (!multipleUploadSpeedLimits && uploadSpeedLimit != [torrent speedLimit:YES])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-12-21 20:21:16 +00:00
|
|
|
multipleUploadSpeedLimits = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
if (downloadUseSpeedLimit != NSControlStateValueMixed &&
|
|
|
|
downloadUseSpeedLimit != ([torrent usesSpeedLimit:NO] ? NSControlStateValueOn : NSControlStateValueOff))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
downloadUseSpeedLimit = NSControlStateValueMixed;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-12-21 20:21:16 +00:00
|
|
|
if (!multipleDownloadSpeedLimits && downloadSpeedLimit != [torrent speedLimit:NO])
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-12-21 20:21:16 +00:00
|
|
|
multipleDownloadSpeedLimits = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
if (globalUseSpeedLimit != NSControlStateValueMixed &&
|
|
|
|
globalUseSpeedLimit != (torrent.usesGlobalSpeedLimit ? NSControlStateValueOn : NSControlStateValueOff))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
globalUseSpeedLimit = NSControlStateValueMixed;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//set upload view
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fUploadLimitCheck.state = uploadUseSpeedLimit;
|
|
|
|
self.fUploadLimitCheck.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fUploadLimitLabel.enabled = uploadUseSpeedLimit == NSControlStateValueOn;
|
|
|
|
self.fUploadLimitField.enabled = uploadUseSpeedLimit == NSControlStateValueOn;
|
2022-12-21 20:21:16 +00:00
|
|
|
if (!multipleUploadSpeedLimits)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-25 16:14:42 +00:00
|
|
|
self.fUploadLimitField.integerValue = uploadSpeedLimit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fUploadLimitField.stringValue = @"";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//set download view
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDownloadLimitCheck.state = downloadUseSpeedLimit;
|
|
|
|
self.fDownloadLimitCheck.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDownloadLimitLabel.enabled = downloadUseSpeedLimit == NSControlStateValueOn;
|
|
|
|
self.fDownloadLimitField.enabled = downloadUseSpeedLimit == NSControlStateValueOn;
|
2022-12-21 20:21:16 +00:00
|
|
|
if (!multipleDownloadSpeedLimits)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-25 16:14:42 +00:00
|
|
|
self.fDownloadLimitField.integerValue = downloadSpeedLimit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDownloadLimitField.stringValue = @"";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//set global check
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fGlobalLimitCheck.state = globalUseSpeedLimit;
|
|
|
|
self.fGlobalLimitCheck.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
//get ratio and idle info
|
2022-02-22 16:04:20 +00:00
|
|
|
enumerator = [self.fTorrents objectEnumerator];
|
2010-03-06 23:12:30 +00:00
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger checkRatio = torrent.ratioSetting;
|
|
|
|
NSInteger checkIdle = torrent.idleSetting;
|
2022-03-30 21:52:23 +00:00
|
|
|
NSInteger removeWhenFinishSeeding = torrent.removeWhenFinishSeeding ? NSControlStateValueOn : NSControlStateValueOff;
|
2021-08-07 07:27:56 +00:00
|
|
|
CGFloat ratioLimit = torrent.ratioLimit;
|
2022-12-21 20:21:16 +00:00
|
|
|
BOOL multipleRatioLimits = NO;
|
2021-08-07 07:27:56 +00:00
|
|
|
NSUInteger idleLimit = torrent.idleLimitMinutes;
|
2022-12-21 20:21:16 +00:00
|
|
|
BOOL multipleIdleLimits = NO;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
while ((torrent = [enumerator nextObject]) &&
|
2022-12-21 20:21:16 +00:00
|
|
|
(checkRatio != kInvalidValue || !multipleRatioLimits || checkIdle != kInvalidValue || !multipleIdleLimits))
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
if (checkRatio != kInvalidValue && checkRatio != torrent.ratioSetting)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
checkRatio = kInvalidValue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-12-21 20:21:16 +00:00
|
|
|
if (!multipleRatioLimits && ratioLimit != torrent.ratioLimit)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-12-21 20:21:16 +00:00
|
|
|
multipleRatioLimits = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
if (checkIdle != kInvalidValue && checkIdle != torrent.idleSetting)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
checkIdle = kInvalidValue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-12-21 20:21:16 +00:00
|
|
|
if (!multipleIdleLimits && idleLimit != torrent.idleLimitMinutes)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-12-21 20:21:16 +00:00
|
|
|
multipleIdleLimits = YES;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
if (removeWhenFinishSeeding != NSControlStateValueMixed &&
|
2022-03-30 21:52:23 +00:00
|
|
|
removeWhenFinishSeeding != (torrent.removeWhenFinishSeeding ? NSControlStateValueOn : NSControlStateValueOff))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
removeWhenFinishSeeding = NSControlStateValueMixed;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//set ratio view
|
|
|
|
NSInteger index;
|
|
|
|
if (checkRatio == TR_RATIOLIMIT_SINGLE)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupTypeLimit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else if (checkRatio == TR_RATIOLIMIT_UNLIMITED)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupTypeNoLimit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else if (checkRatio == TR_RATIOLIMIT_GLOBAL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupTypeGlobal;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
index = -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fRatioPopUp selectItemAtIndex:index];
|
|
|
|
self.fRatioPopUp.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioLimitField.hidden = checkRatio != TR_RATIOLIMIT_SINGLE;
|
2022-12-21 20:21:16 +00:00
|
|
|
if (!multipleRatioLimits)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioLimitField.floatValue = ratioLimit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioLimitField.stringValue = @"";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioLimitGlobalLabel.hidden = checkRatio != TR_RATIOLIMIT_GLOBAL;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
//set idle view
|
|
|
|
if (checkIdle == TR_IDLELIMIT_SINGLE)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupTypeLimit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-07-24 03:19:41 +00:00
|
|
|
else if (checkIdle == TR_IDLELIMIT_UNLIMITED)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupTypeNoLimit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-07-24 03:19:41 +00:00
|
|
|
else if (checkIdle == TR_IDLELIMIT_GLOBAL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupTypeGlobal;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-07-16 03:12:57 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-07-16 03:12:57 +00:00
|
|
|
index = -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fIdlePopUp selectItemAtIndex:index];
|
|
|
|
self.fIdlePopUp.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIdleLimitField.hidden = checkIdle != TR_IDLELIMIT_SINGLE;
|
2022-12-21 20:21:16 +00:00
|
|
|
if (!multipleIdleLimits)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIdleLimitField.integerValue = idleLimit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-07-16 03:12:57 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIdleLimitField.stringValue = @"";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIdleLimitLabel.hidden = checkIdle != TR_IDLELIMIT_SINGLE;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIdleLimitGlobalLabel.hidden = checkIdle != TR_IDLELIMIT_GLOBAL;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-07-07 01:47:12 +00:00
|
|
|
//set remove transfer when seeding finishes
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRemoveSeedingCompleteCheck.state = removeWhenFinishSeeding;
|
|
|
|
self.fRemoveSeedingCompleteCheck.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//get priority info
|
2022-02-22 16:04:20 +00:00
|
|
|
enumerator = [self.fTorrents objectEnumerator];
|
2010-03-06 23:12:30 +00:00
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger priority = torrent.priority;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
while ((torrent = [enumerator nextObject]) && priority != kInvalidValue)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-04-29 22:51:40 +00:00
|
|
|
if (priority != torrent.priority)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
priority = kInvalidValue;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//set priority view
|
|
|
|
if (priority == TR_PRI_HIGH)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupPriorityHigh;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else if (priority == TR_PRI_NORMAL)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupPriorityNormal;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else if (priority == TR_PRI_LOW)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
index = OptionPopupPriorityLow;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
index = -1;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPriorityPopUp selectItemAtIndex:index];
|
|
|
|
self.fPriorityPopUp.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//get peer info
|
2022-02-22 16:04:20 +00:00
|
|
|
enumerator = [self.fTorrents objectEnumerator];
|
2010-03-06 23:12:30 +00:00
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger maxPeers = torrent.maxPeerConnect;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (maxPeers != torrent.maxPeerConnect)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
maxPeers = kInvalidValue;
|
2010-03-06 23:12:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//set peer view
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPeersConnectField.enabled = YES;
|
|
|
|
self.fPeersConnectLabel.enabled = YES;
|
2022-10-19 19:28:21 +00:00
|
|
|
if (maxPeers != kInvalidValue)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-10-25 16:14:42 +00:00
|
|
|
self.fPeersConnectField.integerValue = maxPeers;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPeersConnectField.stringValue = @"";
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setUseSpeedLimit:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const upload = sender == self.fUploadLimitCheck;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-10-31 15:18:27 +00:00
|
|
|
if (((NSButton*)sender).state == NSControlStateValueMixed)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
[sender setState:NSControlStateValueOn];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-10-31 15:18:27 +00:00
|
|
|
BOOL const limit = ((NSButton*)sender).state == NSControlStateValueOn;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[torrent setUseSpeedLimit:limit upload:upload];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSTextField* field = upload ? self.fUploadLimitField : self.fDownloadLimitField;
|
2021-08-07 07:27:56 +00:00
|
|
|
field.enabled = limit;
|
2010-03-06 23:12:30 +00:00
|
|
|
if (limit)
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[field selectText:self];
|
|
|
|
[self.view.window makeKeyAndOrderFront:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSTextField* label = upload ? self.fUploadLimitLabel : self.fDownloadLimitLabel;
|
2021-08-07 07:27:56 +00:00
|
|
|
label.enabled = limit;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setUseGlobalSpeedLimit:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
if (((NSButton*)sender).state == NSControlStateValueMixed)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
[sender setState:NSControlStateValueOn];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-10-31 15:18:27 +00:00
|
|
|
BOOL const limit = ((NSButton*)sender).state == NSControlStateValueOn;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
torrent.usesGlobalSpeedLimit = limit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setSpeedLimit:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
BOOL const upload = sender == self.fUploadLimitField;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const limit = [sender intValue];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[torrent setSpeedLimit:limit upload:upload];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRatioSetting:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
NSInteger setting;
|
2011-02-12 03:13:14 +00:00
|
|
|
BOOL single = NO;
|
2010-03-06 23:12:30 +00:00
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupTypeLimit:
|
2021-08-15 09:41:48 +00:00
|
|
|
setting = TR_RATIOLIMIT_SINGLE;
|
|
|
|
single = YES;
|
|
|
|
break;
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupTypeNoLimit:
|
2021-08-15 09:41:48 +00:00
|
|
|
setting = TR_RATIOLIMIT_UNLIMITED;
|
|
|
|
break;
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupTypeGlobal:
|
2021-08-15 09:41:48 +00:00
|
|
|
setting = TR_RATIOLIMIT_GLOBAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown option selected in ratio popup: %ld", [sender indexOfSelectedItem]);
|
|
|
|
return;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-09-24 12:56:57 +00:00
|
|
|
torrent.ratioSetting = static_cast<tr_ratiolimit>(setting);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioLimitField.hidden = !single;
|
2010-03-06 23:12:30 +00:00
|
|
|
if (single)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fRatioLimitField selectText:self];
|
2021-08-15 09:41:48 +00:00
|
|
|
[self.view.window makeKeyAndOrderFront:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioLimitGlobalLabel.hidden = setting != TR_RATIOLIMIT_GLOBAL;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setRatioLimit:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const limit = [sender floatValue];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
torrent.ratioLimit = limit;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setIdleSetting:(id)sender
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
|
|
|
NSInteger setting;
|
2011-02-12 03:13:14 +00:00
|
|
|
BOOL single = NO;
|
2010-07-16 03:12:57 +00:00
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupTypeLimit:
|
2021-08-15 09:41:48 +00:00
|
|
|
setting = TR_IDLELIMIT_SINGLE;
|
|
|
|
single = YES;
|
|
|
|
break;
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupTypeNoLimit:
|
2021-08-15 09:41:48 +00:00
|
|
|
setting = TR_IDLELIMIT_UNLIMITED;
|
|
|
|
break;
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupTypeGlobal:
|
2021-08-15 09:41:48 +00:00
|
|
|
setting = TR_IDLELIMIT_GLOBAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown option selected in idle popup: %ld", [sender indexOfSelectedItem]);
|
|
|
|
return;
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-09-24 12:56:57 +00:00
|
|
|
torrent.idleSetting = static_cast<tr_idlelimit>(setting);
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIdleLimitField.hidden = !single;
|
|
|
|
self.fIdleLimitLabel.hidden = !single;
|
2010-07-16 03:12:57 +00:00
|
|
|
if (single)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fIdleLimitField selectText:self];
|
2021-08-15 09:41:48 +00:00
|
|
|
[self.view.window makeKeyAndOrderFront:self];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIdleLimitGlobalLabel.hidden = setting != TR_IDLELIMIT_GLOBAL;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setIdleLimit:(id)sender
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSUInteger const limit = [sender integerValue];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
torrent.idleLimitMinutes = limit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)setRemoveWhenSeedingCompletes:(id)sender
|
2012-07-07 01:47:12 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
if (((NSButton*)sender).state == NSControlStateValueMixed)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-10-31 15:18:27 +00:00
|
|
|
[sender setState:NSControlStateValueOn];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2021-10-31 15:18:27 +00:00
|
|
|
BOOL const enable = ((NSButton*)sender).state == NSControlStateValueOn;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
torrent.removeWhenFinishSeeding = enable;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2012-07-07 01:47:12 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPriority:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
tr_priority_t priority;
|
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupPriorityHigh:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupPriorityNormal:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
2022-10-19 19:28:21 +00:00
|
|
|
case OptionPopupPriorityLow:
|
2021-08-15 09:41:48 +00:00
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown option selected in priority popup: %ld", [sender indexOfSelectedItem]);
|
|
|
|
return;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
torrent.priority = priority;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateUI" object:nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPeersConnectLimit:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
NSInteger limit = [sender intValue];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
torrent.maxPeerConnect = limit;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter postNotificationName:@"UpdateOptionsNotification" object:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)control:(NSControl*)control textShouldBeginEditing:(NSText*)fieldEditor
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fInitialString = control.stringValue;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)control:(NSControl*)control didFailToFormatString:(NSString*)string errorDescription:(NSString*)error
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
NSBeep();
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fInitialString)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
control.stringValue = self.fInitialString;
|
|
|
|
self.fInitialString = nil;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setupInfo
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTorrents.count == 0)
|
|
|
|
{
|
|
|
|
self.fUploadLimitCheck.enabled = NO;
|
|
|
|
self.fUploadLimitCheck.state = NSControlStateValueOff;
|
|
|
|
self.fUploadLimitField.enabled = NO;
|
|
|
|
self.fUploadLimitLabel.enabled = NO;
|
|
|
|
self.fUploadLimitField.stringValue = @"";
|
|
|
|
|
|
|
|
self.fDownloadLimitCheck.enabled = NO;
|
|
|
|
self.fDownloadLimitCheck.state = NSControlStateValueOff;
|
|
|
|
self.fDownloadLimitField.enabled = NO;
|
|
|
|
self.fDownloadLimitLabel.enabled = NO;
|
|
|
|
self.fDownloadLimitField.stringValue = @"";
|
|
|
|
|
|
|
|
self.fGlobalLimitCheck.enabled = NO;
|
|
|
|
self.fGlobalLimitCheck.state = NSControlStateValueOff;
|
|
|
|
|
|
|
|
self.fPriorityPopUp.enabled = NO;
|
|
|
|
[self.fPriorityPopUp selectItemAtIndex:-1];
|
|
|
|
|
|
|
|
self.fRatioPopUp.enabled = NO;
|
|
|
|
[self.fRatioPopUp selectItemAtIndex:-1];
|
|
|
|
self.fRatioLimitField.hidden = YES;
|
|
|
|
self.fRatioLimitField.stringValue = @"";
|
|
|
|
self.fRatioLimitGlobalLabel.hidden = YES;
|
|
|
|
|
|
|
|
self.fIdlePopUp.enabled = NO;
|
|
|
|
[self.fIdlePopUp selectItemAtIndex:-1];
|
|
|
|
self.fIdleLimitField.hidden = YES;
|
|
|
|
self.fIdleLimitField.stringValue = @"";
|
|
|
|
self.fIdleLimitLabel.hidden = YES;
|
|
|
|
self.fIdleLimitGlobalLabel.hidden = YES;
|
|
|
|
|
|
|
|
self.fRemoveSeedingCompleteCheck.enabled = NO;
|
|
|
|
self.fRemoveSeedingCompleteCheck.state = NSControlStateValueOff;
|
|
|
|
|
|
|
|
self.fPeersConnectField.enabled = NO;
|
|
|
|
self.fPeersConnectField.stringValue = @"";
|
|
|
|
self.fPeersConnectLabel.enabled = NO;
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
[self updateOptions];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setGlobalLabels
|
2011-02-12 03:28:36 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* global = [NSUserDefaults.standardUserDefaults boolForKey:@"RatioCheck"] ?
|
|
|
|
[NSString stringForRatio:[NSUserDefaults.standardUserDefaults floatForKey:@"RatioLimit"]] :
|
|
|
|
NSLocalizedString(@"disabled", "Info options -> global setting");
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioLimitGlobalLabel.stringValue = global;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-02-12 03:28:36 +00:00
|
|
|
//idle field
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* globalIdle;
|
|
|
|
if ([NSUserDefaults.standardUserDefaults boolForKey:@"IdleLimitCheck"])
|
2011-02-12 03:28:36 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSInteger const globalMin = [NSUserDefaults.standardUserDefaults integerForKey:@"IdleLimitMinutes"];
|
|
|
|
globalIdle = globalMin == 1 ?
|
|
|
|
NSLocalizedString(@"1 minute", "Info options -> global setting") :
|
2022-05-14 05:31:24 +00:00
|
|
|
[NSString localizedStringWithFormat:NSLocalizedString(@"%ld minutes", "Info options -> global setting"), globalMin];
|
2011-02-12 03:28:36 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-02-12 03:28:36 +00:00
|
|
|
globalIdle = NSLocalizedString(@"disabled", "Info options -> global setting");
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fIdleLimitGlobalLabel.stringValue = globalIdle;
|
2011-02-12 03:28:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateOptionsNotification:(NSNotification*)notification
|
2011-06-04 13:48:56 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (notification.object != self)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2011-06-04 13:48:56 +00:00
|
|
|
[self updateOptions];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2011-06-04 13:48:56 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@end
|