2010-03-06 23:12:30 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2010-2012 Transmission authors and contributors
|
2010-03-06 23:12:30 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#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"
|
|
|
|
|
|
|
|
#define OPTION_POPUP_GLOBAL 0
|
|
|
|
#define OPTION_POPUP_NO_LIMIT 1
|
|
|
|
#define OPTION_POPUP_LIMIT 2
|
|
|
|
|
|
|
|
#define OPTION_POPUP_PRIORITY_HIGH 0
|
|
|
|
#define OPTION_POPUP_PRIORITY_NORMAL 1
|
|
|
|
#define OPTION_POPUP_PRIORITY_LOW 2
|
|
|
|
|
|
|
|
#define INVALID -99
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
@interface InfoOptionsViewController (Private)
|
|
|
|
|
|
|
|
- (void) setupInfo;
|
2011-02-12 03:28:36 +00:00
|
|
|
- (void) setGlobalLabels;
|
2011-06-04 13:48:56 +00:00
|
|
|
- (void) updateOptionsNotification: (NSNotification *) notification;
|
2010-03-09 02:26:52 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@implementation InfoOptionsViewController
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2010-03-14 03:09:12 +00:00
|
|
|
if ((self = [super initWithNibName: @"InfoOptionsView" bundle: nil]))
|
|
|
|
{
|
|
|
|
[self setTitle: NSLocalizedString(@"Options", "Inspector view -> title")];
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-02-12 03:28:36 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
|
|
|
[self setGlobalLabels];
|
|
|
|
|
2011-06-04 13:48:56 +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
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2011-02-12 03:28:36 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[fTorrents release];
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
[super dealloc];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setInfoForTorrents: (NSArray *) torrents
|
|
|
|
{
|
2010-04-17 18:44:34 +00:00
|
|
|
//don't check if it's the same in case the metadata changed
|
2012-03-13 02:52:11 +00:00
|
|
|
[fTorrents release];
|
|
|
|
fTorrents = [torrents retain];
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfo
|
|
|
|
{
|
|
|
|
if (!fSet)
|
|
|
|
[self setupInfo];
|
|
|
|
|
|
|
|
fSet = YES;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateOptions
|
|
|
|
{
|
|
|
|
if ([fTorrents count] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//get bandwidth info
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
Torrent * torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
|
|
|
NSInteger uploadUseSpeedLimit = [torrent usesSpeedLimit: YES] ? NSOnState : NSOffState,
|
|
|
|
uploadSpeedLimit = [torrent speedLimit: YES],
|
|
|
|
downloadUseSpeedLimit = [torrent usesSpeedLimit: NO] ? NSOnState : NSOffState,
|
|
|
|
downloadSpeedLimit = [torrent speedLimit: NO],
|
|
|
|
globalUseSpeedLimit = [torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState;
|
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject])
|
|
|
|
&& (uploadUseSpeedLimit != NSMixedState || uploadSpeedLimit != INVALID
|
|
|
|
|| downloadUseSpeedLimit != NSMixedState || downloadSpeedLimit != INVALID
|
|
|
|
|| globalUseSpeedLimit != NSMixedState))
|
|
|
|
{
|
|
|
|
if (uploadUseSpeedLimit != NSMixedState && uploadUseSpeedLimit != ([torrent usesSpeedLimit: YES] ? NSOnState : NSOffState))
|
|
|
|
uploadUseSpeedLimit = NSMixedState;
|
|
|
|
|
|
|
|
if (uploadSpeedLimit != INVALID && uploadSpeedLimit != [torrent speedLimit: YES])
|
|
|
|
uploadSpeedLimit = INVALID;
|
|
|
|
|
|
|
|
if (downloadUseSpeedLimit != NSMixedState && downloadUseSpeedLimit != ([torrent usesSpeedLimit: NO] ? NSOnState : NSOffState))
|
|
|
|
downloadUseSpeedLimit = NSMixedState;
|
|
|
|
|
|
|
|
if (downloadSpeedLimit != INVALID && downloadSpeedLimit != [torrent speedLimit: NO])
|
|
|
|
downloadSpeedLimit = INVALID;
|
|
|
|
|
|
|
|
if (globalUseSpeedLimit != NSMixedState && globalUseSpeedLimit != ([torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState))
|
|
|
|
globalUseSpeedLimit = NSMixedState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set upload view
|
|
|
|
[fUploadLimitCheck setState: uploadUseSpeedLimit];
|
|
|
|
[fUploadLimitCheck setEnabled: YES];
|
|
|
|
|
|
|
|
[fUploadLimitLabel setEnabled: uploadUseSpeedLimit == NSOnState];
|
|
|
|
[fUploadLimitField setEnabled: uploadUseSpeedLimit == NSOnState];
|
|
|
|
if (uploadSpeedLimit != INVALID)
|
|
|
|
[fUploadLimitField setIntValue: uploadSpeedLimit];
|
|
|
|
else
|
|
|
|
[fUploadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
//set download view
|
|
|
|
[fDownloadLimitCheck setState: downloadUseSpeedLimit];
|
|
|
|
[fDownloadLimitCheck setEnabled: YES];
|
|
|
|
|
|
|
|
[fDownloadLimitLabel setEnabled: downloadUseSpeedLimit == NSOnState];
|
|
|
|
[fDownloadLimitField setEnabled: downloadUseSpeedLimit == NSOnState];
|
|
|
|
if (downloadSpeedLimit != INVALID)
|
|
|
|
[fDownloadLimitField setIntValue: downloadSpeedLimit];
|
|
|
|
else
|
|
|
|
[fDownloadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
//set global check
|
|
|
|
[fGlobalLimitCheck setState: globalUseSpeedLimit];
|
|
|
|
[fGlobalLimitCheck setEnabled: YES];
|
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
//get ratio and idle info
|
2010-03-06 23:12:30 +00:00
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
2012-07-07 01:47:12 +00:00
|
|
|
NSInteger checkRatio = [torrent ratioSetting], checkIdle = [torrent idleSetting],
|
|
|
|
removeWhenFinishSeeding = [torrent removeWhenFinishSeeding] ? NSOnState : NSOffState;
|
2010-03-06 23:12:30 +00:00
|
|
|
CGFloat ratioLimit = [torrent ratioLimit];
|
2010-07-24 03:19:41 +00:00
|
|
|
NSUInteger idleLimit = [torrent idleLimitMinutes];
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2010-07-16 03:12:57 +00:00
|
|
|
while ((torrent = [enumerator nextObject])
|
2010-07-24 03:19:41 +00:00
|
|
|
&& (checkRatio != INVALID || ratioLimit != INVALID || checkIdle != INVALID || idleLimit != INVALID))
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
if (checkRatio != INVALID && checkRatio != [torrent ratioSetting])
|
|
|
|
checkRatio = INVALID;
|
|
|
|
|
|
|
|
if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit])
|
|
|
|
ratioLimit = INVALID;
|
2010-07-16 03:12:57 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
if (checkIdle != INVALID && checkIdle != [torrent idleSetting])
|
|
|
|
checkIdle = INVALID;
|
2010-07-16 03:12:57 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
if (idleLimit != INVALID && idleLimit != [torrent idleLimitMinutes])
|
|
|
|
idleLimit = INVALID;
|
2012-07-07 01:47:12 +00:00
|
|
|
|
|
|
|
if (removeWhenFinishSeeding != NSMixedState && removeWhenFinishSeeding != ([torrent removeWhenFinishSeeding] ? NSOnState : NSOffState))
|
|
|
|
removeWhenFinishSeeding = NSMixedState;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//set ratio view
|
|
|
|
NSInteger index;
|
|
|
|
if (checkRatio == TR_RATIOLIMIT_SINGLE)
|
|
|
|
index = OPTION_POPUP_LIMIT;
|
|
|
|
else if (checkRatio == TR_RATIOLIMIT_UNLIMITED)
|
|
|
|
index = OPTION_POPUP_NO_LIMIT;
|
|
|
|
else if (checkRatio == TR_RATIOLIMIT_GLOBAL)
|
|
|
|
index = OPTION_POPUP_GLOBAL;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
[fRatioPopUp selectItemAtIndex: index];
|
|
|
|
[fRatioPopUp setEnabled: YES];
|
|
|
|
|
|
|
|
[fRatioLimitField setHidden: checkRatio != TR_RATIOLIMIT_SINGLE];
|
|
|
|
if (ratioLimit != INVALID)
|
|
|
|
[fRatioLimitField setFloatValue: ratioLimit];
|
|
|
|
else
|
|
|
|
[fRatioLimitField setStringValue: @""];
|
|
|
|
|
2011-02-12 03:13:14 +00:00
|
|
|
[fRatioLimitGlobalLabel setHidden: checkRatio != TR_RATIOLIMIT_GLOBAL];
|
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
//set idle view
|
|
|
|
if (checkIdle == TR_IDLELIMIT_SINGLE)
|
2010-07-16 03:12:57 +00:00
|
|
|
index = OPTION_POPUP_LIMIT;
|
2010-07-24 03:19:41 +00:00
|
|
|
else if (checkIdle == TR_IDLELIMIT_UNLIMITED)
|
2010-07-16 03:12:57 +00:00
|
|
|
index = OPTION_POPUP_NO_LIMIT;
|
2010-07-24 03:19:41 +00:00
|
|
|
else if (checkIdle == TR_IDLELIMIT_GLOBAL)
|
2010-07-16 03:12:57 +00:00
|
|
|
index = OPTION_POPUP_GLOBAL;
|
|
|
|
else
|
|
|
|
index = -1;
|
2010-07-24 03:19:41 +00:00
|
|
|
[fIdlePopUp selectItemAtIndex: index];
|
|
|
|
[fIdlePopUp setEnabled: YES];
|
2010-07-16 03:12:57 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
[fIdleLimitField setHidden: checkIdle != TR_IDLELIMIT_SINGLE];
|
|
|
|
if (idleLimit != INVALID)
|
|
|
|
[fIdleLimitField setIntegerValue: idleLimit];
|
2010-07-16 03:12:57 +00:00
|
|
|
else
|
2010-07-24 03:19:41 +00:00
|
|
|
[fIdleLimitField setStringValue: @""];
|
|
|
|
[fIdleLimitLabel setHidden: checkIdle != TR_IDLELIMIT_SINGLE];
|
2010-07-16 03:12:57 +00:00
|
|
|
|
2011-02-12 03:13:14 +00:00
|
|
|
[fIdleLimitGlobalLabel setHidden: checkIdle != TR_IDLELIMIT_GLOBAL];
|
|
|
|
|
2012-07-07 01:47:12 +00:00
|
|
|
//set remove transfer when seeding finishes
|
|
|
|
[fRemoveSeedingCompleteCheck setState: removeWhenFinishSeeding];
|
|
|
|
[fRemoveSeedingCompleteCheck setEnabled: YES];
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
//get priority info
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
|
|
|
NSInteger priority = [torrent priority];
|
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject]) && priority != INVALID)
|
|
|
|
{
|
|
|
|
if (priority != INVALID && priority != [torrent priority])
|
|
|
|
priority = INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set priority view
|
|
|
|
if (priority == TR_PRI_HIGH)
|
|
|
|
index = OPTION_POPUP_PRIORITY_HIGH;
|
|
|
|
else if (priority == TR_PRI_NORMAL)
|
|
|
|
index = OPTION_POPUP_PRIORITY_NORMAL;
|
|
|
|
else if (priority == TR_PRI_LOW)
|
|
|
|
index = OPTION_POPUP_PRIORITY_LOW;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
[fPriorityPopUp selectItemAtIndex: index];
|
|
|
|
[fPriorityPopUp setEnabled: YES];
|
|
|
|
|
|
|
|
//get peer info
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
|
|
|
NSInteger maxPeers = [torrent maxPeerConnect];
|
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
if (maxPeers != [torrent maxPeerConnect])
|
|
|
|
{
|
|
|
|
maxPeers = INVALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//set peer view
|
|
|
|
[fPeersConnectField setEnabled: YES];
|
|
|
|
[fPeersConnectLabel setEnabled: YES];
|
|
|
|
if (maxPeers != INVALID)
|
|
|
|
[fPeersConnectField setIntValue: maxPeers];
|
|
|
|
else
|
|
|
|
[fPeersConnectField setStringValue: @""];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setUseSpeedLimit: (id) sender
|
|
|
|
{
|
|
|
|
const BOOL upload = sender == fUploadLimitCheck;
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
if ([(NSButton *)sender state] == NSMixedState)
|
2010-03-06 23:12:30 +00:00
|
|
|
[sender setState: NSOnState];
|
2011-10-06 00:30:40 +00:00
|
|
|
const BOOL limit = [(NSButton *)sender state] == NSOnState;
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setUseSpeedLimit: limit upload: upload];
|
|
|
|
|
|
|
|
NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField;
|
|
|
|
[field setEnabled: limit];
|
|
|
|
if (limit)
|
|
|
|
{
|
|
|
|
[field selectText: self];
|
|
|
|
[[[self view] window] makeKeyAndOrderFront: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel;
|
|
|
|
[label setEnabled: limit];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setUseGlobalSpeedLimit: (id) sender
|
|
|
|
{
|
2011-10-06 00:30:40 +00:00
|
|
|
if ([(NSButton *)sender state] == NSMixedState)
|
2010-03-06 23:12:30 +00:00
|
|
|
[sender setState: NSOnState];
|
2011-10-06 00:30:40 +00:00
|
|
|
const BOOL limit = [(NSButton *)sender state] == NSOnState;
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setUseGlobalSpeedLimit: limit];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSpeedLimit: (id) sender
|
|
|
|
{
|
|
|
|
const BOOL upload = sender == fUploadLimitField;
|
|
|
|
const NSInteger limit = [sender intValue];
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setSpeedLimit: limit upload: upload];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioSetting: (id) sender
|
|
|
|
{
|
|
|
|
NSInteger setting;
|
2011-02-12 03:13:14 +00:00
|
|
|
BOOL single = NO;
|
2010-03-06 23:12:30 +00:00
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
|
|
|
case OPTION_POPUP_LIMIT:
|
|
|
|
setting = TR_RATIOLIMIT_SINGLE;
|
|
|
|
single = YES;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_NO_LIMIT:
|
|
|
|
setting = TR_RATIOLIMIT_UNLIMITED;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_GLOBAL:
|
|
|
|
setting = TR_RATIOLIMIT_GLOBAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown option selected in ratio popup: %d", [sender indexOfSelectedItem]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setRatioSetting: setting];
|
|
|
|
|
|
|
|
[fRatioLimitField setHidden: !single];
|
|
|
|
if (single)
|
|
|
|
{
|
|
|
|
[fRatioLimitField selectText: self];
|
|
|
|
[[[self view] window] makeKeyAndOrderFront: self];
|
|
|
|
}
|
2011-02-12 03:13:14 +00:00
|
|
|
|
2011-02-12 03:28:36 +00:00
|
|
|
[fRatioLimitGlobalLabel setHidden: setting != TR_RATIOLIMIT_GLOBAL];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioLimit: (id) sender
|
|
|
|
{
|
2010-07-16 03:12:57 +00:00
|
|
|
const CGFloat limit = [sender floatValue];
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setRatioLimit: limit];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 03:19:41 +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])
|
|
|
|
{
|
|
|
|
case OPTION_POPUP_LIMIT:
|
2010-07-24 03:19:41 +00:00
|
|
|
setting = TR_IDLELIMIT_SINGLE;
|
2010-07-16 03:12:57 +00:00
|
|
|
single = YES;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_NO_LIMIT:
|
2010-07-24 03:19:41 +00:00
|
|
|
setting = TR_IDLELIMIT_UNLIMITED;
|
2010-07-16 03:12:57 +00:00
|
|
|
break;
|
|
|
|
case OPTION_POPUP_GLOBAL:
|
2010-07-24 03:19:41 +00:00
|
|
|
setting = TR_IDLELIMIT_GLOBAL;
|
2010-07-16 03:12:57 +00:00
|
|
|
break;
|
|
|
|
default:
|
2010-07-24 03:19:41 +00:00
|
|
|
NSAssert1(NO, @"Unknown option selected in idle popup: %d", [sender indexOfSelectedItem]);
|
2010-07-16 03:12:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
2010-07-24 03:19:41 +00:00
|
|
|
[torrent setIdleSetting: setting];
|
2010-07-16 03:12:57 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
[fIdleLimitField setHidden: !single];
|
|
|
|
[fIdleLimitLabel setHidden: !single];
|
2010-07-16 03:12:57 +00:00
|
|
|
if (single)
|
|
|
|
{
|
2010-07-24 03:19:41 +00:00
|
|
|
[fIdleLimitField selectText: self];
|
2010-07-16 03:12:57 +00:00
|
|
|
[[[self view] window] makeKeyAndOrderFront: self];
|
|
|
|
}
|
2011-02-12 03:13:14 +00:00
|
|
|
|
2011-02-12 03:28:36 +00:00
|
|
|
[fIdleLimitGlobalLabel setHidden: setting != TR_IDLELIMIT_GLOBAL];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
- (void) setIdleLimit: (id) sender
|
2010-07-16 03:12:57 +00:00
|
|
|
{
|
|
|
|
const NSUInteger limit = [sender integerValue];
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
2010-07-24 03:19:41 +00:00
|
|
|
[torrent setIdleLimitMinutes: limit];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-07-16 03:12:57 +00:00
|
|
|
}
|
|
|
|
|
2012-07-07 01:47:12 +00:00
|
|
|
- (IBAction) setRemoveWhenSeedingCompletes: (id) sender
|
|
|
|
{
|
|
|
|
if ([(NSButton *)sender state] == NSMixedState)
|
|
|
|
[sender setState: NSOnState];
|
|
|
|
const BOOL enable = [(NSButton *)sender state] == NSOnState;
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setRemoveWhenFinishSeeding: enable];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
- (void) setPriority: (id) sender
|
|
|
|
{
|
|
|
|
tr_priority_t priority;
|
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
|
|
|
case OPTION_POPUP_PRIORITY_HIGH:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_PRIORITY_NORMAL:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_PRIORITY_LOW:
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Unknown option selected in priority popup: %d", [sender indexOfSelectedItem]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setPriority: priority];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPeersConnectLimit: (id) sender
|
|
|
|
{
|
|
|
|
NSInteger limit = [sender intValue];
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setMaxPeerConnect: limit];
|
2011-06-04 13:48:56 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor
|
|
|
|
{
|
2012-03-13 02:52:11 +00:00
|
|
|
[fInitialString release];
|
|
|
|
fInitialString = [[control stringValue] retain];
|
2010-03-06 23:12:30 +00:00
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error
|
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
if (fInitialString)
|
|
|
|
{
|
|
|
|
[control setStringValue: fInitialString];
|
2012-03-13 02:52:11 +00:00
|
|
|
[fInitialString release];
|
2010-03-06 23:12:30 +00:00
|
|
|
fInitialString = nil;
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoOptionsViewController (Private)
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
- (void) setupInfo
|
|
|
|
{
|
|
|
|
if ([fTorrents count] == 0)
|
|
|
|
{
|
|
|
|
[fUploadLimitCheck setEnabled: NO];
|
|
|
|
[fUploadLimitCheck setState: NSOffState];
|
|
|
|
[fUploadLimitField setEnabled: NO];
|
|
|
|
[fUploadLimitLabel setEnabled: NO];
|
|
|
|
[fUploadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
[fDownloadLimitCheck setEnabled: NO];
|
|
|
|
[fDownloadLimitCheck setState: NSOffState];
|
|
|
|
[fDownloadLimitField setEnabled: NO];
|
|
|
|
[fDownloadLimitLabel setEnabled: NO];
|
|
|
|
[fDownloadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
[fGlobalLimitCheck setEnabled: NO];
|
|
|
|
[fGlobalLimitCheck setState: NSOffState];
|
|
|
|
|
|
|
|
[fPriorityPopUp setEnabled: NO];
|
|
|
|
[fPriorityPopUp selectItemAtIndex: -1];
|
|
|
|
|
|
|
|
[fRatioPopUp setEnabled: NO];
|
|
|
|
[fRatioPopUp selectItemAtIndex: -1];
|
|
|
|
[fRatioLimitField setHidden: YES];
|
|
|
|
[fRatioLimitField setStringValue: @""];
|
2011-02-12 03:13:14 +00:00
|
|
|
[fRatioLimitGlobalLabel setHidden: YES];
|
2010-03-09 02:26:52 +00:00
|
|
|
|
2010-07-24 03:19:41 +00:00
|
|
|
[fIdlePopUp setEnabled: NO];
|
|
|
|
[fIdlePopUp selectItemAtIndex: -1];
|
|
|
|
[fIdleLimitField setHidden: YES];
|
|
|
|
[fIdleLimitField setStringValue: @""];
|
|
|
|
[fIdleLimitLabel setHidden: YES];
|
2011-02-12 03:13:14 +00:00
|
|
|
[fIdleLimitGlobalLabel setHidden: YES];
|
2010-07-16 03:12:57 +00:00
|
|
|
|
2012-07-07 01:47:12 +00:00
|
|
|
[fRemoveSeedingCompleteCheck setEnabled: NO];
|
|
|
|
[fRemoveSeedingCompleteCheck setState: NSOffState];
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
[fPeersConnectField setEnabled: NO];
|
|
|
|
[fPeersConnectField setStringValue: @""];
|
|
|
|
[fPeersConnectLabel setEnabled: NO];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[self updateOptions];
|
|
|
|
}
|
|
|
|
|
2011-02-12 03:28:36 +00:00
|
|
|
- (void) setGlobalLabels
|
|
|
|
{
|
|
|
|
NSString * global = [[NSUserDefaults standardUserDefaults] boolForKey: @"RatioCheck"]
|
|
|
|
? [NSString stringForRatio: [[NSUserDefaults standardUserDefaults] floatForKey: @"RatioLimit"]]
|
|
|
|
: NSLocalizedString(@"disabled", "Info options -> global setting");
|
|
|
|
[fRatioLimitGlobalLabel setStringValue: global];
|
|
|
|
|
|
|
|
//idle field
|
|
|
|
NSString * globalIdle;
|
|
|
|
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"IdleLimitCheck"])
|
|
|
|
{
|
|
|
|
const NSInteger globalMin = [[NSUserDefaults standardUserDefaults] integerForKey: @"IdleLimitMinutes"];
|
|
|
|
globalIdle = globalMin == 1 ? NSLocalizedString(@"1 minute", "Info options -> global setting")
|
|
|
|
: [NSString stringWithFormat: NSLocalizedString(@"%d minutes", "Info options -> global setting"), globalMin];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
globalIdle = NSLocalizedString(@"disabled", "Info options -> global setting");
|
|
|
|
[fIdleLimitGlobalLabel setStringValue: globalIdle];
|
|
|
|
}
|
|
|
|
|
2011-06-04 13:48:56 +00:00
|
|
|
- (void) updateOptionsNotification: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
if ([notification object] != self)
|
|
|
|
[self updateOptions];
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@end
|