source: trunk/macosx/GlobalOptionsPopoverViewController.m @ 13162

Last change on this file since 13162 was 13162, checked in by livings124, 11 years ago

bump Mac copyright to 2012

File size: 6.0 KB
Line 
1/******************************************************************************
2 * $Id$
3 *
4 * Copyright (c) 2011-2012 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "GlobalOptionsPopoverViewController.h"
26
27@implementation GlobalOptionsPopoverViewController
28
29- (id) initWithHandle: (tr_session *) handle
30{
31    if ((self = [super initWithNibName: @"GlobalOptionsPopover" bundle: nil]))
32    {
33        fHandle = handle;
34       
35        fDefaults = [NSUserDefaults standardUserDefaults];
36    }
37   
38    return self;
39}
40
41- (void) awakeFromNib
42{
43    [fUploadLimitField setIntValue: [fDefaults integerForKey: @"UploadLimit"]];
44    [fDownloadLimitField setIntValue: [fDefaults integerForKey: @"DownloadLimit"]];
45   
46    [fRatioStopField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
47    [fIdleStopField setIntegerValue: [fDefaults integerForKey: @"IdleLimitMinutes"]];
48}
49
50- (IBAction) updatedDisplayString: (id) sender
51{
52    #warning setNeedsDisplay: instead of reloadData?
53    [[NSNotificationCenter defaultCenter] postNotificationName: @"ReloadTorrentTable" object: nil];
54}
55
56- (IBAction) setDownSpeedSetting: (id) sender
57{
58    tr_sessionLimitSpeed(fHandle, TR_DOWN, [fDefaults boolForKey: @"CheckDownload"]);
59   
60    [[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" object: nil];
61}
62
63- (IBAction) setDownSpeedLimit: (id) sender
64{
65    const NSInteger limit = [sender integerValue];
66    [fDefaults setInteger: limit forKey: @"DownloadLimit"];
67    tr_sessionSetSpeedLimit_KBps(fHandle, TR_DOWN, limit);
68   
69    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSpeedLimitValuesOutsidePrefs" object: nil];
70    [[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" object: nil];
71}
72
73- (IBAction) setUpSpeedSetting: (id) sender
74{
75    tr_sessionLimitSpeed(fHandle, TR_UP, [fDefaults boolForKey: @"CheckUpload"]);
76   
77    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateSpeedLimitValuesOutsidePrefs" object: nil];
78    [[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" object: nil];
79}
80
81- (IBAction) setUpSpeedLimit: (id) sender
82{
83    const NSInteger limit = [sender integerValue];
84    [fDefaults setInteger: limit forKey: @"UploadLimit"];
85    tr_sessionSetSpeedLimit_KBps(fHandle, TR_UP, limit);
86   
87    [[NSNotificationCenter defaultCenter] postNotificationName: @"SpeedLimitUpdate" object: nil];
88}
89
90- (IBAction) setRatioStopSetting: (id) sender
91{
92    tr_sessionSetRatioLimited(fHandle, [fDefaults boolForKey: @"RatioCheck"]);
93   
94    //reload main table for seeding progress
95    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
96   
97    //reload global settings in inspector
98    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateGlobalOptions" object: nil];
99}
100
101- (IBAction) setRatioStopLimit: (id) sender
102{
103    const CGFloat value = [sender floatValue];
104    [fDefaults setFloat: value forKey: @"RatioLimit"];
105    tr_sessionSetRatioLimit(fHandle, value);
106   
107    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateRatioStopValueOutsidePrefs" object: nil];
108   
109    //reload main table for seeding progress
110    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
111   
112    //reload global settings in inspector
113    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateGlobalOptions" object: nil];
114}
115
116- (IBAction) setIdleStopSetting: (id) sender
117{
118    tr_sessionSetIdleLimited(fHandle, [fDefaults boolForKey: @"IdleLimitCheck"]);
119   
120    //reload main table for remaining seeding time
121    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
122   
123    //reload global settings in inspector
124    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateGlobalOptions" object: nil];
125}
126
127- (IBAction) setIdleStopLimit: (id) sender
128{
129    const NSInteger value = [sender integerValue];
130    [fDefaults setInteger: value forKey: @"IdleLimitMinutes"];
131    tr_sessionSetIdleLimit(fHandle, value);
132   
133    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateIdleStopValueOutsidePrefs" object: nil];
134   
135    //reload main table for remaining seeding time
136    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
137   
138    //reload global settings in inspector
139    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateGlobalOptions" object: nil];
140}
141
142- (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor
143{
144    [fInitialString release];
145    fInitialString = [[control stringValue] retain];
146   
147    return YES;
148}
149
150- (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error
151{
152    NSBeep();
153    if (fInitialString)
154    {
155        [control setStringValue: fInitialString];
156        [fInitialString release];
157        fInitialString = nil;
158    }
159    return NO;
160}
161
162@end
Note: See TracBrowser for help on using the repository browser.