source: trunk/macosx/InfoOptionsViewController.m @ 13480

Last change on this file since 13480 was 13480, checked in by livings124, 10 years ago

add in placeholder code so that InfoOptionsView? can be localized with a strings file after 2.7

  • Property svn:keywords set to Date Rev Author Id
File size: 22.1 KB
Line 
1/******************************************************************************
2 * $Id: InfoOptionsViewController.m 13480 2012-09-08 18:09:02Z livings124 $
3 *
4 * Copyright (c) 2010-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 "InfoOptionsViewController.h"
26#import "NSStringAdditions.h"
27#import "Torrent.h"
28
29#define OPTION_POPUP_GLOBAL 0
30#define OPTION_POPUP_NO_LIMIT 1
31#define OPTION_POPUP_LIMIT 2
32
33#define OPTION_POPUP_PRIORITY_HIGH 0
34#define OPTION_POPUP_PRIORITY_NORMAL 1
35#define OPTION_POPUP_PRIORITY_LOW 2
36
37#define INVALID -99
38
39@interface InfoOptionsViewController (Private)
40
41- (void) setupInfo;
42- (void) setGlobalLabels;
43- (void) updateOptionsNotification: (NSNotification *) notification;
44
45@end
46
47@implementation InfoOptionsViewController
48
49- (id) init
50{
51    if ((self = [super initWithNibName: @"InfoOptionsView" bundle: nil]))
52    {
53        [self setTitle: NSLocalizedString(@"Options", "Inspector view -> title")];
54    }
55   
56    return self;
57}
58
59- (void) awakeFromNib
60{
61    [self setGlobalLabels];
62   
63    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(setGlobalLabels) name: @"UpdateGlobalOptions" object: nil];
64    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(updateOptionsNotification:) name: @"UpdateOptionsNotification" object: nil];
65   
66    #warning remove when 10.7-only with auto layout
67    /*const CGFloat padding = 6.0; //this shows as 8 in IB
68    [fPrioritySectionLabel sizeToFit];
69    [fPriorityLabel sizeToFit];
70    NSRect priorityPopUpFrame = [fPriorityPopUp frame];
71    priorityPopUpFrame.origin.x = NSMaxX([fPriorityLabel frame]) + padding;
72    [fPriorityPopUp setFrame: priorityPopUpFrame];
73   
74    [fTransferBandwidthSectionLabel sizeToFit];
75    [fDownloadLimitCheck sizeToFit];
76    [fUploadLimitCheck sizeToFit];
77    NSRect downloadLimitFieldFrame = [fDownloadLimitField frame];
78    NSRect uploadLimitFieldFrame = [fUploadLimitField frame];
79    const CGFloat speedLimitFieldX = MAX(NSMaxX([fDownloadLimitCheck frame]), NSMaxX([fUploadLimitCheck frame])) + padding;
80    downloadLimitFieldFrame.origin.x = speedLimitFieldX;
81    uploadLimitFieldFrame.origin.x = speedLimitFieldX;
82    [fDownloadLimitField setFrame: downloadLimitFieldFrame];
83    [fUploadLimitField setFrame: uploadLimitFieldFrame];
84    [fDownloadLimitLabel sizeToFit];
85    [fUploadLimitLabel sizeToFit];
86    NSRect downloadLimitLabelFrame = [fDownloadLimitLabel frame];
87    NSRect uploadLimitLabelFrame = [fUploadLimitLabel frame];
88    downloadLimitLabelFrame.origin.x = NSMaxX([fDownloadLimitField frame]) + padding;
89    uploadLimitLabelFrame.origin.x = NSMaxX([fUploadLimitField frame]) + padding;
90    [fDownloadLimitLabel setFrame: downloadLimitLabelFrame];
91    [fUploadLimitLabel setFrame: uploadLimitLabelFrame];
92    [fGlobalLimitCheck sizeToFit];
93   
94    [fSeedingLimitsSectionLabel sizeToFit];
95    [fRatioLabel sizeToFit];
96    [fInactivityLabel sizeToFit];
97    NSRect ratioPopUpFrame = [fRatioPopUp frame];
98    NSRect idlePopUpFrame = [fIdlePopUp frame];
99    const CGFloat seedingLimitPopUpX = MAX(NSMaxX([fRatioLabel frame]), NSMaxX([fInactivityLabel frame])) + padding;
100    ratioPopUpFrame.origin.x = seedingLimitPopUpX;
101    idlePopUpFrame.origin.x = seedingLimitPopUpX;
102    [fRatioPopUp setFrame: ratioPopUpFrame];
103    [fIdlePopUp setFrame: idlePopUpFrame];
104    NSRect ratioLimitFieldFrame = [fRatioLimitField frame];
105    NSRect idleLimitFieldFrame = [fIdleLimitField frame];
106    const CGFloat seedingLimitFieldX = NSMaxX(ratioPopUpFrame) + padding;
107    ratioLimitFieldFrame.origin.x = seedingLimitFieldX + 2.0;
108    idleLimitFieldFrame.origin.x = seedingLimitFieldX + 2.0;
109    [fRatioLimitField setFrame: ratioLimitFieldFrame];
110    [fIdleLimitField setFrame: idleLimitFieldFrame];
111    [fIdleLimitLabel sizeToFit];
112    NSRect idleLimitLabelFrame = [fIdleLimitLabel frame];
113    idleLimitLabelFrame.origin.x = NSMaxX(idleLimitFieldFrame) + padding;
114    [fIdleLimitLabel setFrame: idleLimitLabelFrame];
115    NSRect ratioLimitGlobalLabelFrame = [fRatioLimitGlobalLabel frame];
116    NSRect idleLimitGlobalLabelFrame = [fIdleLimitGlobalLabel frame];
117    ratioLimitGlobalLabelFrame.origin.x = seedingLimitFieldX;
118    idleLimitGlobalLabelFrame.origin.x = seedingLimitFieldX;
119    [fRatioLimitGlobalLabel setFrame: ratioLimitGlobalLabelFrame];
120    [fIdleLimitGlobalLabel setFrame: idleLimitGlobalLabelFrame];
121    [fRemoveSeedingCompleteCheck sizeToFit];
122   
123    [fAdvancedSectionLabel sizeToFit];
124    [fMaxConnectionsLabel sizeToFit];
125    NSRect peersConnectFrame = [fPeersConnectField frame];
126    peersConnectFrame.origin.x = NSMaxX([fMaxConnectionsLabel frame]) + padding;
127    [fPeersConnectField setFrame: peersConnectFrame];
128    [fPeersConnectLabel sizeToFit];
129    NSRect peersConnectLabelFrame = [fPeersConnectLabel frame];
130    peersConnectLabelFrame.origin.x = NSMaxX(peersConnectFrame) + padding;
131    [fPeersConnectLabel setFrame: peersConnectLabelFrame];*/
132}
133
134- (void) dealloc
135{
136    [[NSNotificationCenter defaultCenter] removeObserver: self];
137   
138    [fTorrents release];
139   
140    [super dealloc];
141}
142
143- (void) setInfoForTorrents: (NSArray *) torrents
144{
145    //don't check if it's the same in case the metadata changed
146    [fTorrents release];
147    fTorrents = [torrents retain];
148   
149    fSet = NO;
150}
151
152- (void) updateInfo
153{
154    if (!fSet)
155        [self setupInfo];
156   
157    fSet = YES;
158}
159
160- (void) updateOptions
161{
162    if ([fTorrents count] == 0)
163        return;
164   
165    //get bandwidth info
166    NSEnumerator * enumerator = [fTorrents objectEnumerator];
167    Torrent * torrent = [enumerator nextObject]; //first torrent
168   
169    NSInteger uploadUseSpeedLimit = [torrent usesSpeedLimit: YES] ? NSOnState : NSOffState,
170                uploadSpeedLimit = [torrent speedLimit: YES],
171                downloadUseSpeedLimit = [torrent usesSpeedLimit: NO] ? NSOnState : NSOffState,
172                downloadSpeedLimit = [torrent speedLimit: NO],
173                globalUseSpeedLimit = [torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState;
174   
175    while ((torrent = [enumerator nextObject])
176            && (uploadUseSpeedLimit != NSMixedState || uploadSpeedLimit != INVALID
177                || downloadUseSpeedLimit != NSMixedState || downloadSpeedLimit != INVALID
178                || globalUseSpeedLimit != NSMixedState))
179    {
180        if (uploadUseSpeedLimit != NSMixedState && uploadUseSpeedLimit != ([torrent usesSpeedLimit: YES] ? NSOnState : NSOffState))
181            uploadUseSpeedLimit = NSMixedState;
182       
183        if (uploadSpeedLimit != INVALID && uploadSpeedLimit != [torrent speedLimit: YES])
184            uploadSpeedLimit = INVALID;
185       
186        if (downloadUseSpeedLimit != NSMixedState && downloadUseSpeedLimit != ([torrent usesSpeedLimit: NO] ? NSOnState : NSOffState))
187            downloadUseSpeedLimit = NSMixedState;
188       
189        if (downloadSpeedLimit != INVALID && downloadSpeedLimit != [torrent speedLimit: NO])
190            downloadSpeedLimit = INVALID;
191       
192        if (globalUseSpeedLimit != NSMixedState && globalUseSpeedLimit != ([torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState))
193            globalUseSpeedLimit = NSMixedState;
194    }
195   
196    //set upload view
197    [fUploadLimitCheck setState: uploadUseSpeedLimit];
198    [fUploadLimitCheck setEnabled: YES];
199   
200    [fUploadLimitLabel setEnabled: uploadUseSpeedLimit == NSOnState];
201    [fUploadLimitField setEnabled: uploadUseSpeedLimit == NSOnState];
202    if (uploadSpeedLimit != INVALID)
203        [fUploadLimitField setIntValue: uploadSpeedLimit];
204    else
205        [fUploadLimitField setStringValue: @""];
206   
207    //set download view
208    [fDownloadLimitCheck setState: downloadUseSpeedLimit];
209    [fDownloadLimitCheck setEnabled: YES];
210   
211    [fDownloadLimitLabel setEnabled: downloadUseSpeedLimit == NSOnState];
212    [fDownloadLimitField setEnabled: downloadUseSpeedLimit == NSOnState];
213    if (downloadSpeedLimit != INVALID)
214        [fDownloadLimitField setIntValue: downloadSpeedLimit];
215    else
216        [fDownloadLimitField setStringValue: @""];
217   
218    //set global check
219    [fGlobalLimitCheck setState: globalUseSpeedLimit];
220    [fGlobalLimitCheck setEnabled: YES];
221   
222    //get ratio and idle info
223    enumerator = [fTorrents objectEnumerator];
224    torrent = [enumerator nextObject]; //first torrent
225   
226    NSInteger checkRatio = [torrent ratioSetting], checkIdle = [torrent idleSetting],
227            removeWhenFinishSeeding = [torrent removeWhenFinishSeeding] ? NSOnState : NSOffState;
228    CGFloat ratioLimit = [torrent ratioLimit];
229    NSUInteger idleLimit = [torrent idleLimitMinutes];
230   
231    while ((torrent = [enumerator nextObject])
232            && (checkRatio != INVALID || ratioLimit != INVALID || checkIdle != INVALID || idleLimit != INVALID))
233    {
234        if (checkRatio != INVALID && checkRatio != [torrent ratioSetting])
235            checkRatio = INVALID;
236       
237        if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit])
238            ratioLimit = INVALID;
239       
240        if (checkIdle != INVALID && checkIdle != [torrent idleSetting])
241            checkIdle = INVALID;
242       
243        if (idleLimit != INVALID && idleLimit != [torrent idleLimitMinutes])
244            idleLimit = INVALID;
245       
246        if (removeWhenFinishSeeding != NSMixedState && removeWhenFinishSeeding != ([torrent removeWhenFinishSeeding] ? NSOnState : NSOffState))
247            removeWhenFinishSeeding = NSMixedState;
248    }
249   
250    //set ratio view
251    NSInteger index;
252    if (checkRatio == TR_RATIOLIMIT_SINGLE)
253        index = OPTION_POPUP_LIMIT;
254    else if (checkRatio == TR_RATIOLIMIT_UNLIMITED)
255        index = OPTION_POPUP_NO_LIMIT;
256    else if (checkRatio == TR_RATIOLIMIT_GLOBAL)
257        index = OPTION_POPUP_GLOBAL;
258    else
259        index = -1;
260    [fRatioPopUp selectItemAtIndex: index];
261    [fRatioPopUp setEnabled: YES];
262   
263    [fRatioLimitField setHidden: checkRatio != TR_RATIOLIMIT_SINGLE];
264    if (ratioLimit != INVALID)
265        [fRatioLimitField setFloatValue: ratioLimit];
266    else
267        [fRatioLimitField setStringValue: @""];
268   
269    [fRatioLimitGlobalLabel setHidden: checkRatio != TR_RATIOLIMIT_GLOBAL];
270   
271    //set idle view
272    if (checkIdle == TR_IDLELIMIT_SINGLE)
273        index = OPTION_POPUP_LIMIT;
274    else if (checkIdle == TR_IDLELIMIT_UNLIMITED)
275        index = OPTION_POPUP_NO_LIMIT;
276    else if (checkIdle == TR_IDLELIMIT_GLOBAL)
277        index = OPTION_POPUP_GLOBAL;
278    else
279        index = -1;
280    [fIdlePopUp selectItemAtIndex: index];
281    [fIdlePopUp setEnabled: YES];
282   
283    [fIdleLimitField setHidden: checkIdle != TR_IDLELIMIT_SINGLE];
284    if (idleLimit != INVALID)
285        [fIdleLimitField setIntegerValue: idleLimit];
286    else
287        [fIdleLimitField setStringValue: @""];
288    [fIdleLimitLabel setHidden: checkIdle != TR_IDLELIMIT_SINGLE];
289   
290    [fIdleLimitGlobalLabel setHidden: checkIdle != TR_IDLELIMIT_GLOBAL];
291   
292    //set remove transfer when seeding finishes
293    [fRemoveSeedingCompleteCheck setState: removeWhenFinishSeeding];
294    [fRemoveSeedingCompleteCheck setEnabled: YES];
295   
296    //get priority info
297    enumerator = [fTorrents objectEnumerator];
298    torrent = [enumerator nextObject]; //first torrent
299   
300    NSInteger priority = [torrent priority];
301   
302    while ((torrent = [enumerator nextObject]) && priority != INVALID)
303    {
304        if (priority != INVALID && priority != [torrent priority])
305            priority = INVALID;
306    }
307   
308    //set priority view
309    if (priority == TR_PRI_HIGH)
310        index = OPTION_POPUP_PRIORITY_HIGH;
311    else if (priority == TR_PRI_NORMAL)
312        index = OPTION_POPUP_PRIORITY_NORMAL;
313    else if (priority == TR_PRI_LOW)
314        index = OPTION_POPUP_PRIORITY_LOW;
315    else
316        index = -1;
317    [fPriorityPopUp selectItemAtIndex: index];
318    [fPriorityPopUp setEnabled: YES];
319   
320    //get peer info
321    enumerator = [fTorrents objectEnumerator];
322    torrent = [enumerator nextObject]; //first torrent
323   
324    NSInteger maxPeers = [torrent maxPeerConnect];
325   
326    while ((torrent = [enumerator nextObject]))
327    {
328        if (maxPeers != [torrent maxPeerConnect])
329        {
330            maxPeers = INVALID;
331            break;
332        }
333    }
334   
335    //set peer view
336    [fPeersConnectField setEnabled: YES];
337    [fPeersConnectLabel setEnabled: YES];
338    if (maxPeers != INVALID)
339        [fPeersConnectField setIntValue: maxPeers];
340    else
341        [fPeersConnectField setStringValue: @""];
342}
343
344- (void) setUseSpeedLimit: (id) sender
345{
346    const BOOL upload = sender == fUploadLimitCheck;
347   
348    if ([(NSButton *)sender state] == NSMixedState)
349        [sender setState: NSOnState];
350    const BOOL limit = [(NSButton *)sender state] == NSOnState;
351   
352    for (Torrent * torrent in fTorrents)
353        [torrent setUseSpeedLimit: limit upload: upload];
354   
355    NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField;
356    [field setEnabled: limit];
357    if (limit)
358    {
359        [field selectText: self];
360        [[[self view] window] makeKeyAndOrderFront: self];
361    }
362   
363    NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel;
364    [label setEnabled: limit];
365   
366    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
367}
368
369- (void) setUseGlobalSpeedLimit: (id) sender
370{
371    if ([(NSButton *)sender state] == NSMixedState)
372        [sender setState: NSOnState];
373    const BOOL limit = [(NSButton *)sender state] == NSOnState;
374   
375    for (Torrent * torrent in fTorrents)
376        [torrent setUseGlobalSpeedLimit: limit];
377   
378    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
379}
380
381- (void) setSpeedLimit: (id) sender
382{
383    const BOOL upload = sender == fUploadLimitField;
384    const NSInteger limit = [sender intValue];
385   
386    for (Torrent * torrent in fTorrents)
387        [torrent setSpeedLimit: limit upload: upload];
388   
389    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
390}
391
392- (void) setRatioSetting: (id) sender
393{
394    NSInteger setting;
395    BOOL single = NO;
396    switch ([sender indexOfSelectedItem])
397    {
398        case OPTION_POPUP_LIMIT:
399            setting = TR_RATIOLIMIT_SINGLE;
400            single = YES;
401            break;
402        case OPTION_POPUP_NO_LIMIT:
403            setting = TR_RATIOLIMIT_UNLIMITED;
404            break;
405        case OPTION_POPUP_GLOBAL:
406            setting = TR_RATIOLIMIT_GLOBAL;
407            break;
408        default:
409            NSAssert1(NO, @"Unknown option selected in ratio popup: %ld", [sender indexOfSelectedItem]);
410            return;
411    }
412   
413    for (Torrent * torrent in fTorrents)
414        [torrent setRatioSetting: setting];
415   
416    [fRatioLimitField setHidden: !single];
417    if (single)
418    {
419        [fRatioLimitField selectText: self];
420        [[[self view] window] makeKeyAndOrderFront: self];
421    }
422   
423    [fRatioLimitGlobalLabel setHidden: setting != TR_RATIOLIMIT_GLOBAL];
424   
425    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
426}
427
428- (void) setRatioLimit: (id) sender
429{
430    const CGFloat limit = [sender floatValue];
431   
432    for (Torrent * torrent in fTorrents)
433        [torrent setRatioLimit: limit];
434   
435    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
436}
437
438- (void) setIdleSetting: (id) sender
439{
440    NSInteger setting;
441    BOOL single = NO;
442    switch ([sender indexOfSelectedItem])
443    {
444        case OPTION_POPUP_LIMIT:
445            setting = TR_IDLELIMIT_SINGLE;
446            single = YES;
447            break;
448        case OPTION_POPUP_NO_LIMIT:
449            setting = TR_IDLELIMIT_UNLIMITED;
450            break;
451        case OPTION_POPUP_GLOBAL:
452            setting = TR_IDLELIMIT_GLOBAL;
453            break;
454        default:
455            NSAssert1(NO, @"Unknown option selected in idle popup: %ld", [sender indexOfSelectedItem]);
456            return;
457    }
458   
459    for (Torrent * torrent in fTorrents)
460        [torrent setIdleSetting: setting];
461   
462    [fIdleLimitField setHidden: !single];
463    [fIdleLimitLabel setHidden: !single];
464    if (single)
465    {
466        [fIdleLimitField selectText: self];
467        [[[self view] window] makeKeyAndOrderFront: self];
468    }
469   
470    [fIdleLimitGlobalLabel setHidden: setting != TR_IDLELIMIT_GLOBAL];
471   
472    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
473}
474
475- (void) setIdleLimit: (id) sender
476{
477    const NSUInteger limit = [sender integerValue];
478   
479    for (Torrent * torrent in fTorrents)
480        [torrent setIdleLimitMinutes: limit];
481   
482    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
483}
484
485- (IBAction) setRemoveWhenSeedingCompletes: (id) sender
486{
487    if ([(NSButton *)sender state] == NSMixedState)
488        [sender setState: NSOnState];
489    const BOOL enable = [(NSButton *)sender state] == NSOnState;
490   
491    for (Torrent * torrent in fTorrents)
492        [torrent setRemoveWhenFinishSeeding: enable];
493   
494    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
495}
496
497- (void) setPriority: (id) sender
498{
499    tr_priority_t priority;
500    switch ([sender indexOfSelectedItem])
501    {
502        case OPTION_POPUP_PRIORITY_HIGH:
503            priority = TR_PRI_HIGH;
504            break;
505        case OPTION_POPUP_PRIORITY_NORMAL:
506            priority = TR_PRI_NORMAL;
507            break;
508        case OPTION_POPUP_PRIORITY_LOW:
509            priority = TR_PRI_LOW;
510            break;
511        default:
512            NSAssert1(NO, @"Unknown option selected in priority popup: %ld", [sender indexOfSelectedItem]);
513            return;
514    }
515   
516    for (Torrent * torrent in fTorrents)
517        [torrent setPriority: priority];
518   
519    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
520   
521    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
522}
523
524- (void) setPeersConnectLimit: (id) sender
525{
526    NSInteger limit = [sender intValue];
527   
528    for (Torrent * torrent in fTorrents)
529        [torrent setMaxPeerConnect: limit];
530   
531    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateOptionsNotification" object: self];
532}
533
534- (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor
535{
536    [fInitialString release];
537    fInitialString = [[control stringValue] retain];
538   
539    return YES;
540}
541
542- (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error
543{
544    NSBeep();
545    if (fInitialString)
546    {
547        [control setStringValue: fInitialString];
548        [fInitialString release];
549        fInitialString = nil;
550    }
551    return NO;
552}
553
554@end
555
556@implementation InfoOptionsViewController (Private)
557
558- (void) setupInfo
559{
560    if ([fTorrents count] == 0)
561    {
562        [fUploadLimitCheck setEnabled: NO];
563        [fUploadLimitCheck setState: NSOffState];
564        [fUploadLimitField setEnabled: NO];
565        [fUploadLimitLabel setEnabled: NO];
566        [fUploadLimitField setStringValue: @""];
567       
568        [fDownloadLimitCheck setEnabled: NO];
569        [fDownloadLimitCheck setState: NSOffState];
570        [fDownloadLimitField setEnabled: NO];
571        [fDownloadLimitLabel setEnabled: NO];
572        [fDownloadLimitField setStringValue: @""];
573       
574        [fGlobalLimitCheck setEnabled: NO];
575        [fGlobalLimitCheck setState: NSOffState];
576       
577        [fPriorityPopUp setEnabled: NO];
578        [fPriorityPopUp selectItemAtIndex: -1];
579       
580        [fRatioPopUp setEnabled: NO];
581        [fRatioPopUp selectItemAtIndex: -1];
582        [fRatioLimitField setHidden: YES];
583        [fRatioLimitField setStringValue: @""];
584        [fRatioLimitGlobalLabel setHidden: YES];
585       
586        [fIdlePopUp setEnabled: NO];
587        [fIdlePopUp selectItemAtIndex: -1];
588        [fIdleLimitField setHidden: YES];
589        [fIdleLimitField setStringValue: @""];
590        [fIdleLimitLabel setHidden: YES];
591        [fIdleLimitGlobalLabel setHidden: YES];
592       
593        [fRemoveSeedingCompleteCheck setEnabled: NO];
594        [fRemoveSeedingCompleteCheck setState: NSOffState];
595       
596        [fPeersConnectField setEnabled: NO];
597        [fPeersConnectField setStringValue: @""];
598        [fPeersConnectLabel setEnabled: NO];
599    }
600    else
601        [self updateOptions];
602}
603
604- (void) setGlobalLabels
605{
606    NSString * global = [[NSUserDefaults standardUserDefaults] boolForKey: @"RatioCheck"]
607        ? [NSString stringForRatio: [[NSUserDefaults standardUserDefaults] floatForKey: @"RatioLimit"]]
608        : NSLocalizedString(@"disabled", "Info options -> global setting");
609    [fRatioLimitGlobalLabel setStringValue: global];
610   
611    //idle field
612    NSString * globalIdle;
613    if ([[NSUserDefaults standardUserDefaults] boolForKey: @"IdleLimitCheck"])
614    {
615        const NSInteger globalMin = [[NSUserDefaults standardUserDefaults] integerForKey: @"IdleLimitMinutes"];
616        globalIdle = globalMin == 1 ? NSLocalizedString(@"1 minute", "Info options -> global setting")
617            : [NSString localizedStringWithFormat: NSLocalizedString(@"%d minutes", "Info options -> global setting"), globalMin];
618    }
619    else
620        globalIdle = NSLocalizedString(@"disabled", "Info options -> global setting");
621    [fIdleLimitGlobalLabel setStringValue: globalIdle];
622}
623
624- (void) updateOptionsNotification: (NSNotification *) notification
625{
626    if ([notification object] != self)
627        [self updateOptions];
628}
629
630@end
Note: See TracBrowser for help on using the repository browser.