source: trunk/macosx/InfoWindowController.m @ 2226

Last change on this file since 2226 was 2226, checked in by livings124, 15 years ago

remove some nslogs

  • Property svn:keywords set to Date Rev Author Id
File size: 43.7 KB
Line 
1/******************************************************************************
2 * $Id: InfoWindowController.m 2226 2007-06-29 01:59:14Z livings124 $
3 *
4 * Copyright (c) 2006-2007 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 "InfoWindowController.h"
26#import "FileBrowserCell.h"
27#import "FilePriorityCell.h"
28#import "StringAdditions.h"
29
30#define MIN_WINDOW_WIDTH 300
31#define MAX_WINDOW_WIDTH 5000
32
33#define FILE_ROW_SMALL_HEIGHT 18.0
34
35#define TAB_INFO_IDENT @"Info"
36#define TAB_ACTIVITY_IDENT @"Activity"
37#define TAB_PEERS_IDENT @"Peers"
38#define TAB_FILES_IDENT @"Files"
39#define TAB_OPTIONS_IDENT @"Options"
40
41//15 spacing at the bottom of each tab
42#define TAB_INFO_HEIGHT 268.0
43#define TAB_ACTIVITY_HEIGHT 274.0
44#define TAB_PEERS_HEIGHT 279.0
45#define TAB_FILES_HEIGHT 279.0
46#define TAB_OPTIONS_HEIGHT 158.0
47
48#define PIECES_CONTROL_PROGRESS 0
49#define PIECES_CONTROL_AVAILABLE 1
50
51#define OPTION_POPUP_GLOBAL 0
52#define OPTION_POPUP_NO_LIMIT 1
53#define OPTION_POPUP_LIMIT 2
54
55#define INVALID -99
56
57@interface InfoWindowController (Private)
58
59- (void) updateInfoGeneral;
60- (void) updateInfoActivity;
61- (void) updateInfoPeers;
62- (void) updateInfoFiles;
63- (void) updateInfoSettings;
64
65- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate;
66- (NSArray *) peerSortDescriptors;
67
68- (int) stateSettingToPopUpIndex: (int) index;
69- (int) popUpIndexToStateSetting: (int) index;
70
71@end
72
73@implementation InfoWindowController
74
75- (id) initWithWindowNibName: (NSString *) name
76{
77    if ((self = [super initWithWindowNibName: name]))
78    {
79        fAppIcon = [NSImage imageNamed: @"NSApplicationIcon"];
80        fDotGreen = [NSImage imageNamed: @"GreenDot.tiff"];
81        fDotRed = [NSImage imageNamed: @"RedDot.tiff"];
82    }
83    return self;
84}
85
86- (void) awakeFromNib
87{
88    //window location and size
89    NSPanel * window = (NSPanel *)[self window];
90   
91    [window setFrameAutosaveName: @"InspectorWindowFrame"];
92    [window setFrameUsingName: @"InspectorWindowFrame"];
93   
94    //select tab
95    NSString * identifier = [[NSUserDefaults standardUserDefaults] stringForKey: @"InspectorSelected"];
96    if ([fTabView indexOfTabViewItemWithIdentifier: identifier] == NSNotFound)
97        identifier = TAB_INFO_IDENT;
98   
99    [fTabView selectTabViewItemWithIdentifier: identifier];
100    [self setWindowForTab: identifier animate: NO];
101   
102    //initially sort peer table by IP
103    if ([[fPeerTable sortDescriptors] count] == 0)
104        [fPeerTable setSortDescriptors: [NSArray arrayWithObject: [[fPeerTable tableColumnWithIdentifier: @"IP"]
105                                            sortDescriptorPrototype]]];
106   
107    //set file table
108    [fFileOutline setDoubleAction: @selector(revealFile:)];
109   
110    //set file outline
111    FilePriorityCell * priorityCell = [[[FilePriorityCell alloc] init] autorelease];
112    [[fFileOutline tableColumnWithIdentifier: @"Priority"] setDataCell: priorityCell];
113   
114    //set blank inspector
115    [self updateInfoForTorrents: [NSArray array]];
116}
117
118- (void) dealloc
119{
120    if (fTorrents)
121        [fTorrents release];
122    if (fPeers)
123        [fPeers release];
124    if (fFiles)
125        [fFiles release];
126   
127    [super dealloc];
128}
129
130- (void) updateInfoForTorrents: (NSArray *) torrents
131{
132    if (fTorrents)
133        [fTorrents release];
134    fTorrents = [torrents retain];
135
136    int numberSelected = [fTorrents count];
137    if (numberSelected != 1)
138    {
139        if (numberSelected > 0)
140        {
141            [fNameField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d Torrents Selected",
142                                            "Inspector -> above tabs -> selected torrents"), numberSelected]];
143       
144            uint64_t size = 0;
145            NSEnumerator * enumerator = [torrents objectEnumerator];
146            Torrent * torrent;
147            while ((torrent = [enumerator nextObject]))
148                size += [torrent size];
149           
150            [fSizeField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ Total",
151                "Inspector -> above tabs -> total size (several torrents selected)"), [NSString stringForFileSize: size]]];
152        }
153        else
154        {
155            [fNameField setStringValue: NSLocalizedString(@"No Torrents Selected",
156                                                            "Inspector -> above tabs -> selected torrents")];
157            [fSizeField setStringValue: @""];
158   
159            [fDownloadedValidField setStringValue: @""];
160            [fDownloadedTotalField setStringValue: @""];
161            [fUploadedTotalField setStringValue: @""];
162        }
163       
164        [fImageView setImage: fAppIcon];
165       
166        [fNameField setToolTip: nil];
167
168        [fTrackerField setStringValue: @""];
169        [fTrackerField setToolTip: nil];
170        [fPiecesField setStringValue: @""];
171        [fHashField setStringValue: @""];
172        [fHashField setToolTip: nil];
173        [fSecureField setStringValue: @""];
174        [fCommentView setString: @""];
175       
176        [fCreatorField setStringValue: @""];
177        [fDateCreatedField setStringValue: @""];
178        [fCommentView setSelectable: NO];
179       
180        [fTorrentLocationField setStringValue: @""];
181        [fTorrentLocationField setToolTip: nil];
182        [fDataLocationField setStringValue: @""];
183        [fDataLocationField setToolTip: nil];
184       
185        [fRevealDataButton setHidden: YES];
186        [fRevealTorrentButton setHidden: YES];
187       
188        //don't allow empty fields to be selected
189        [fTrackerField setSelectable: NO];
190        [fHashField setSelectable: NO];
191        [fCreatorField setSelectable: NO];
192        [fTorrentLocationField setSelectable: NO];
193        [fDataLocationField setSelectable: NO];
194       
195        [fStateField setStringValue: @""];
196        [fProgressField setStringValue: @""];
197        [fRatioField setStringValue: @""];
198       
199        [fSeedersField setStringValue: @""];
200        [fLeechersField setStringValue: @""];
201        [fCompletedFromTrackerField setStringValue: @""];
202        [fConnectedPeersField setStringValue: NSLocalizedString(@"info not available", "Inspector -> Peers tab -> peers")];
203        [fDownloadingFromField setStringValue: @""];
204        [fUploadingToField setStringValue: @""];
205        [fSwarmSpeedField setStringValue: @""];
206        [fErrorMessageView setString: @""];
207        [fErrorMessageView setSelectable: NO];
208       
209        [fDateAddedField setStringValue: @""];
210        [fDateCompletedField setStringValue: @""];
211        [fDateActivityField setStringValue: @""];
212       
213        [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE];
214        [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS];
215        [fPiecesControl setEnabled: NO];
216        [fPiecesView setTorrent: nil];
217       
218        if (fPeers)
219        {
220            [fPeers release];
221            fPeers = nil;
222        }
223       
224        if (fFiles)
225        {
226            [fFiles release];
227            fFiles = nil;
228        }
229        [fFileTableStatusField setStringValue: NSLocalizedString(@"info not available",
230                                        "Inspector -> Files tab -> bottom text (number of files)")];
231    }
232    else
233    {   
234        Torrent * torrent = [fTorrents objectAtIndex: 0];
235       
236        [fImageView setImage: [torrent icon]];
237       
238        NSString * name = [torrent name];
239        [fNameField setStringValue: name];
240        [fNameField setToolTip: name];
241        [fSizeField setStringValue: [NSString stringForFileSize: [torrent size]]];
242       
243        NSString * hashString = [torrent hashString],
244                * commentString = [torrent comment];
245        [fPiecesField setStringValue: [NSString stringWithFormat: @"%d, %@", [torrent pieceCount],
246                                        [NSString stringForFileSize: [torrent pieceSize]]]];
247        [fHashField setStringValue: hashString];
248        [fHashField setToolTip: hashString];
249        [fSecureField setStringValue: [torrent privateTorrent]
250                        ? NSLocalizedString(@"Private Torrent, PEX disabled", "Inspector -> is private torrent")
251                        : NSLocalizedString(@"Public Torrent", "Inspector -> is not private torrent")];
252        [fCommentView setString: commentString];
253       
254        [fCreatorField setStringValue: [torrent creator]];
255        [fDateCreatedField setObjectValue: [torrent dateCreated]];
256       
257        BOOL publicTorrent = [torrent publicTorrent];
258        [fTorrentLocationField setStringValue: publicTorrent
259                    ? [[torrent publicTorrentLocation] stringByAbbreviatingWithTildeInPath]
260                    : NSLocalizedString(@"Transmission Support Folder", "Torrent -> location when deleting original")];
261        if (publicTorrent)
262            [fTorrentLocationField setToolTip: [NSString stringWithFormat: @"%@\n\n%@",
263                        [torrent publicTorrentLocation], [torrent torrentLocation]]];
264        else
265            [fTorrentLocationField setToolTip: [torrent torrentLocation]];
266       
267        [fDateAddedField setObjectValue: [torrent dateAdded]];
268       
269        [fRevealDataButton setHidden: NO];
270        [fRevealTorrentButton setHidden: ![torrent publicTorrent]];
271       
272        //allow these fields to be selected
273        [fTrackerField setSelectable: YES];
274        [fHashField setSelectable: YES];
275        [fCommentView setSelectable: YES];
276        [fCreatorField setSelectable: YES];
277        [fTorrentLocationField setSelectable: YES];
278        [fDataLocationField setSelectable: YES];
279       
280        //set pieces view
281        BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"];
282        [fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE];
283        [fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS];
284        [fPiecesControl setEnabled: YES];
285        [fPiecesView setTorrent: torrent];
286       
287        //set file table
288        [fFileOutline deselectAll: nil];
289        if (fFiles)
290            [fFiles release];
291        fFiles = [[torrent fileList] retain];
292       
293        [self updateInfoFiles];
294       
295        int fileCount = [torrent fileCount];
296        if (fileCount != 1)
297            [fFileTableStatusField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d files total",
298                                "Inspector -> Files tab -> bottom text (number of files)"), fileCount]];
299        else
300            [fFileTableStatusField setStringValue: NSLocalizedString(@"1 file total",
301                                "Inspector -> Files tab -> bottom text (number of files)")];
302    }
303   
304    //update stats and settings
305    [self updateInfoSettings];
306   
307    [fPeerTable reloadData];
308    [fFileOutline deselectAll: nil];
309    [fFileOutline reloadData];
310}
311
312- (Torrent *) selectedTorrent
313{
314    return fTorrents && [fTorrents count] > 0 ? [fTorrents objectAtIndex: 0] : nil;
315}
316
317- (void) updateInfoStats
318{
319    NSString * ident = [[fTabView selectedTabViewItem] identifier];
320    if ([ident isEqualToString: TAB_ACTIVITY_IDENT])
321        [self updateInfoActivity];
322    else if ([ident isEqualToString: TAB_PEERS_IDENT])
323        [self updateInfoPeers];
324    else if ([ident isEqualToString: TAB_INFO_IDENT])
325        [self updateInfoGeneral];
326    else if ([ident isEqualToString: TAB_FILES_IDENT])
327        [self updateInfoFiles];
328    else;
329}
330
331- (void) updateInfoGeneral
332{   
333    if ([fTorrents count] != 1)
334        return;
335   
336    Torrent * torrent = [fTorrents objectAtIndex: 0];
337   
338    NSString * tracker = [[torrent trackerAddress] stringByAppendingString: [torrent trackerAddressAnnounce]];
339    [fTrackerField setStringValue: tracker];
340    [fTrackerField setToolTip: tracker];
341   
342    NSString * location = [torrent dataLocation];
343    [fDataLocationField setStringValue: [location stringByAbbreviatingWithTildeInPath]];
344    [fDataLocationField setToolTip: location];
345}
346
347- (void) updateInfoActivity
348{
349    int numberSelected = [fTorrents count];
350    if (numberSelected == 0)
351        return;
352   
353    uint64_t  downloadedValid = 0, downloadedTotal = 0, uploadedTotal = 0;
354    Torrent * torrent;
355    NSEnumerator * enumerator = [fTorrents objectEnumerator];
356    while ((torrent = [enumerator nextObject]))
357    {
358        downloadedValid += [torrent downloadedValid];
359        downloadedTotal += [torrent downloadedTotal];
360        uploadedTotal += [torrent uploadedTotal];
361    }
362
363    [fDownloadedValidField setStringValue: [NSString stringForFileSize: downloadedValid]];
364    [fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
365    [fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
366   
367    if (numberSelected == 1)
368    {
369        torrent = [fTorrents objectAtIndex: 0];
370       
371        [fStateField setStringValue: [torrent stateString]];
372        [fProgressField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%.2f%% (%.2f%% selected)",
373                    "Inspector -> Activity tab -> progress"), 100.0 * [torrent progress], 100.0 * [torrent progressDone]]];
374        [fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]];
375        [fSwarmSpeedField setStringValue: [torrent isActive] ? [NSString stringForSpeed: [torrent swarmSpeed]] : @""];
376       
377        NSString * errorMessage = [torrent errorMessage];
378        if (![errorMessage isEqualToString: [fErrorMessageView string]])
379        {
380            [fErrorMessageView setString: errorMessage];
381            [fErrorMessageView setSelectable: ![errorMessage isEqualToString: @""]];
382        }
383       
384        [fDateCompletedField setObjectValue: [torrent dateCompleted]];
385        [fDateActivityField setObjectValue: [torrent dateActivity]];
386       
387        [fPiecesView updateView: NO];
388    }
389}
390
391- (void) updateInfoPeers
392{
393    if ([fTorrents count] != 1)
394        return;
395    Torrent * torrent = [fTorrents objectAtIndex: 0];
396   
397    int seeders = [torrent seeders], leechers = [torrent leechers], downloaded = [torrent completedFromTracker];
398    [fSeedersField setStringValue: seeders < 0 ? @"" : [NSString stringWithInt: seeders]];
399    [fLeechersField setStringValue: leechers < 0 ? @"" : [NSString stringWithInt: leechers]];
400    [fCompletedFromTrackerField setStringValue: downloaded < 0 ? @"" : [NSString stringWithInt: downloaded]];
401   
402    BOOL active = [torrent isActive];
403   
404    if (active)
405    {
406        int total = [torrent totalPeers];
407        NSString * connected = [NSString stringWithFormat:
408                                NSLocalizedString(@"%d Connected", "Inspector -> Peers tab -> peers"), total];
409       
410        if (total > 0)
411        {
412            NSMutableArray * components = [NSMutableArray arrayWithCapacity: 4];
413            int count;
414            if ((count = [torrent totalPeersTracker]) > 0)
415                [components addObject: [NSString stringWithFormat:
416                                        NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), count]];
417            if ((count = [torrent totalPeersIncoming]) > 0)
418                [components addObject: [NSString stringWithFormat:
419                                        NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), count]];
420            if ((count = [torrent totalPeersPex]) > 0)
421                [components addObject: [NSString stringWithFormat:
422                                        NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), count]];
423            if ((count = [torrent totalPeersCache]) > 0)
424                [components addObject: [NSString stringWithFormat:
425                                        NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), count]];
426           
427            connected = [NSString stringWithFormat: @"%@: %@", connected, [components componentsJoinedByString: @", "]];
428        }
429       
430        [fConnectedPeersField setStringValue: connected];
431    }
432    else
433        [fConnectedPeersField setStringValue: NSLocalizedString(@"info not available", "Inspector -> Peers tab -> peers")];
434   
435    [fDownloadingFromField setStringValue: active ? [NSString stringWithInt: [torrent peersUploading]] : @""];
436    [fUploadingToField setStringValue: active ? [NSString stringWithInt: [torrent peersDownloading]] : @""];
437   
438    if (fPeers)
439        [fPeers release];
440    fPeers = [[[torrent peers] sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain];
441   
442    [fPeerTable reloadData];
443}
444
445- (void) updateInfoFiles
446{
447    if ([fTorrents count] == 1)
448        [fFileOutline reloadData];
449}
450
451- (void) updateInfoSettings
452{
453    if ([fTorrents count] > 0)
454    {
455        Torrent * torrent;
456       
457        //set bandwidth limits
458        NSEnumerator * enumerator = [fTorrents objectEnumerator];
459        torrent = [enumerator nextObject]; //first torrent
460       
461        int checkUpload = [torrent checkUpload],
462            checkDownload = [torrent checkDownload],
463            uploadLimit = [torrent uploadLimit],
464            downloadLimit = [torrent downloadLimit];
465       
466        while ((checkUpload != INVALID || uploadLimit != INVALID
467                || checkDownload != INVALID || downloadLimit != INVALID)
468                && (torrent = [enumerator nextObject]))
469        {
470            if (checkUpload != INVALID && checkUpload != [torrent checkUpload])
471                checkUpload = INVALID;
472           
473            if (uploadLimit != INVALID && uploadLimit != [torrent uploadLimit])
474                uploadLimit = INVALID;
475           
476            if (checkDownload != INVALID && checkDownload != [torrent checkDownload])
477                checkDownload = INVALID;
478           
479            if (downloadLimit != INVALID && downloadLimit != [torrent downloadLimit])
480                downloadLimit = INVALID;
481        }
482       
483        [fUploadLimitPopUp setEnabled: YES];
484        [fUploadLimitPopUp selectItemAtIndex: [self stateSettingToPopUpIndex: checkUpload]];
485        [fUploadLimitLabel setHidden: checkUpload != NSOnState];
486        [fUploadLimitField setHidden: checkUpload != NSOnState];
487        if (uploadLimit != INVALID)
488            [fUploadLimitField setIntValue: uploadLimit];
489        else
490            [fUploadLimitField setStringValue: @""];
491       
492        [fDownloadLimitPopUp setEnabled: YES];
493        [fDownloadLimitPopUp selectItemAtIndex: [self stateSettingToPopUpIndex: checkDownload]];
494        [fDownloadLimitLabel setHidden: checkDownload != NSOnState];
495        [fDownloadLimitField setHidden: checkDownload != NSOnState];
496        if (downloadLimit != INVALID)
497            [fDownloadLimitField setIntValue: downloadLimit];
498        else
499            [fDownloadLimitField setStringValue: @""];
500       
501        //set ratio settings
502        enumerator = [fTorrents objectEnumerator];
503        torrent = [enumerator nextObject]; //first torrent
504       
505        int checkRatio = [torrent ratioSetting];
506        float ratioLimit = [torrent ratioLimit];
507       
508        while ((checkRatio != INVALID || checkRatio != INVALID)
509                && (torrent = [enumerator nextObject]))
510        {
511            if (checkRatio != INVALID && checkRatio != [torrent ratioSetting])
512                checkRatio = INVALID;
513           
514            if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit])
515                ratioLimit = INVALID;
516        }
517       
518        [fRatioPopUp setEnabled: YES];
519        [fRatioPopUp selectItemAtIndex: [self stateSettingToPopUpIndex: checkRatio]];
520        [fRatioLimitField setHidden: checkRatio != NSOnState];
521        if (ratioLimit != INVALID)
522            [fRatioLimitField setFloatValue: ratioLimit];
523        else
524            [fRatioLimitField setStringValue: @""];
525               
526                //set pex check
527                enumerator = [fTorrents objectEnumerator];
528        torrent = [enumerator nextObject]; //first torrent
529               
530                BOOL pexEnabled = ![torrent privateTorrent];
531                int pexState = [torrent pex] ? NSOnState : NSOffState;
532               
533                while ((pexEnabled || pexState != NSMixedState)
534                && (torrent = [enumerator nextObject]))
535        {
536            if (pexEnabled)
537                pexEnabled = ![torrent privateTorrent];
538           
539            if (pexState != NSMixedState && pexState != ([torrent pex] ? NSOnState : NSOffState))
540                pexState = NSMixedState;
541        }
542               
543                [fPexCheck setEnabled: pexEnabled];
544                [fPexCheck setState: pexState];
545    }
546    else
547    {
548        [fUploadLimitPopUp setEnabled: NO];
549        [fUploadLimitPopUp selectItemAtIndex: -1];
550        [fUploadLimitField setHidden: YES];
551        [fUploadLimitLabel setHidden: YES];
552        [fUploadLimitField setStringValue: @""];
553       
554        [fDownloadLimitPopUp setEnabled: NO];
555        [fDownloadLimitPopUp selectItemAtIndex: -1];
556        [fDownloadLimitField setHidden: YES];
557        [fDownloadLimitLabel setHidden: YES];
558        [fDownloadLimitField setStringValue: @""];
559       
560        [fRatioPopUp setEnabled: NO];
561        [fRatioPopUp selectItemAtIndex: -1];
562        [fRatioLimitField setHidden: YES];
563        [fRatioLimitField setStringValue: @""];
564               
565                [fPexCheck setEnabled: NO];
566        [fPexCheck setState: NSOffState];
567    }
568   
569    [self updateInfoStats];
570}
571
572- (void) updateRatioForTorrent: (Torrent *) torrent
573{
574    if ([fTorrents containsObject: torrent])
575        [self updateInfoSettings];
576}
577
578- (int) stateSettingToPopUpIndex: (int) index
579{
580    if (index == NSOnState)
581        return OPTION_POPUP_LIMIT;
582    else if (index == NSOffState)
583        return OPTION_POPUP_NO_LIMIT;
584    else if (index == NSMixedState)
585        return OPTION_POPUP_GLOBAL;
586    else
587        return -1;
588}
589
590- (int) popUpIndexToStateSetting: (int) index
591{
592    if (index == OPTION_POPUP_LIMIT)
593        return NSOnState;
594    else if (index == OPTION_POPUP_NO_LIMIT)
595        return NSOffState;
596    else if (index == OPTION_POPUP_GLOBAL)
597        return NSMixedState;
598    else
599        return INVALID;
600}
601
602- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
603{
604    if ([fTorrents count] != 1)
605        return NO;
606   
607    SEL action = [menuItem action];
608   
609    if (action == @selector(revealFile:))
610        return [fFileOutline numberOfSelectedRows] > 0 &&
611            [[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_FILES_IDENT];
612   
613    if (action == @selector(setCheck:))
614    {
615        Torrent * torrent = [fTorrents objectAtIndex: 0];
616        NSDictionary * item;
617        NSIndexSet * indexSet = [fFileOutline selectedRowIndexes], * itemIndexes;
618        NSMutableIndexSet * usedIndexes = [NSMutableIndexSet indexSet];
619        int i, index, state = (menuItem == fFileCheckItem) ? NSOnState : NSOffState;
620        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
621        {
622            itemIndexes = [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"];
623            if (![usedIndexes containsIndexes: itemIndexes])
624            {
625                if ([torrent checkForFiles: itemIndexes] != state && [torrent canChangeDownloadCheckForFiles: itemIndexes])
626                    return YES;
627                [usedIndexes addIndexes: itemIndexes];
628            }
629        }
630        return NO;
631    }
632   
633    #warning disable if all can't be checked
634    if (action == @selector(setOnlySelectedCheck:))
635        return [fFileOutline selectedRow] != -1;
636   
637    if (action == @selector(setPriority:))
638    {
639        if ([fFileOutline numberOfSelectedRows] <= 0)
640        {
641            [menuItem setState: NSOffState];
642            return NO;
643        }
644       
645        //determine which priorities are checked
646        NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
647        BOOL current = NO, other = NO;
648        int i, priority;
649        Torrent * torrent = [fTorrents objectAtIndex: 0];
650       
651        if (menuItem == fFilePriorityHigh)
652            priority = PRIORITY_HIGH;
653        else if (menuItem == fFilePriorityLow)
654            priority = PRIORITY_LOW;
655        else
656            priority = PRIORITY_NORMAL;
657       
658        for (i = [indexSet firstIndex]; i != NSNotFound && (!current || !other); i = [indexSet indexGreaterThanIndex: i])
659        {
660            if ([torrent hasFilePriority: priority forIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]])
661                current = YES;
662            else
663                other = YES;
664        }
665       
666        [menuItem setState: current ? (other ? NSMixedState : NSOnState) : NSOffState];
667        return YES;
668    }
669   
670    return YES;
671}
672
673- (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame
674{
675    NSRect windowRect = [window frame];
676    windowRect.size.width = [window minSize].width;
677    return windowRect;
678}
679
680- (void) tabView: (NSTabView *) tabView didSelectTabViewItem: (NSTabViewItem *) tabViewItem
681{
682    NSString * identifier = [tabViewItem identifier];
683    [self setWindowForTab: identifier animate: YES];
684    [[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InspectorSelected"];
685}
686
687- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate
688{
689    [self updateInfoStats];
690   
691    float height;
692    if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
693    {
694        height = TAB_ACTIVITY_HEIGHT;
695        [fPiecesView updateView: YES];
696    }
697    else if ([identifier isEqualToString: TAB_PEERS_IDENT])
698        height = TAB_PEERS_HEIGHT;
699    else if ([identifier isEqualToString: TAB_FILES_IDENT])
700        height = TAB_FILES_HEIGHT;
701    else if ([identifier isEqualToString: TAB_OPTIONS_IDENT])
702        height = TAB_OPTIONS_HEIGHT;
703    else
704        height = TAB_INFO_HEIGHT;
705   
706    NSWindow * window = [self window];
707    NSRect frame = [window frame];
708    NSView * view = [[fTabView selectedTabViewItem] view];
709   
710    float difference = height - [view frame].size.height;
711    frame.origin.y -= difference;
712    frame.size.height += difference;
713   
714    if (animate)
715    {
716        [view setHidden: YES];
717        [window setFrame: frame display: YES animate: YES];
718        [view setHidden: NO];
719    }
720    else
721        [window setFrame: frame display: YES];
722   
723    [window setMinSize: NSMakeSize(MIN_WINDOW_WIDTH, frame.size.height)];
724    [window setMaxSize: NSMakeSize(MAX_WINDOW_WIDTH, frame.size.height)];
725}
726
727- (void) setNextTab
728{
729    if ([fTabView indexOfTabViewItem: [fTabView selectedTabViewItem]] == [fTabView numberOfTabViewItems] - 1)
730        [fTabView selectFirstTabViewItem: nil];
731    else
732        [fTabView selectNextTabViewItem: nil];
733}
734
735- (void) setPreviousTab
736{
737    if ([fTabView indexOfTabViewItem: [fTabView selectedTabViewItem]] == 0)
738        [fTabView selectLastTabViewItem: nil];
739    else
740        [fTabView selectPreviousTabViewItem: nil];
741}
742
743- (int) numberOfRowsInTableView: (NSTableView *) tableView
744{
745    if (tableView == fPeerTable)
746        return fPeers ? [fPeers count] : 0;
747    return 0;
748}
749
750- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (int) row
751{
752    if (tableView == fPeerTable)
753    {
754        NSString * ident = [column identifier];
755        NSDictionary * peer = [fPeers objectAtIndex: row];
756       
757        if ([ident isEqualToString: @"Connected"])
758            return [[peer objectForKey: @"Connected"] boolValue] ? fDotGreen : fDotRed;
759        else if ([ident isEqualToString: @"Client"])
760            return [peer objectForKey: @"Client"];
761        else if  ([ident isEqualToString: @"Progress"])
762            return [peer objectForKey: @"Progress"]; //returning nil is fine
763        else if ([ident isEqualToString: @"UL To"])
764        {
765            NSNumber * rate;
766            return (rate = [peer objectForKey: @"UL To Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
767        }
768        else if ([ident isEqualToString: @"DL From"])
769        {
770            NSNumber * rate;
771            return (rate = [peer objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
772        }
773        else
774            return [peer objectForKey: @"IP"];
775    }
776    return nil;
777}
778
779- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell
780            forTableColumn: (NSTableColumn *) tableColumn row: (int) row
781{
782    if (tableView == fPeerTable)
783    {
784        if ([[tableColumn identifier] isEqualToString: @"Progress"])
785            [cell setHidden: ![[[fPeers objectAtIndex: row] objectForKey: @"Connected"] boolValue]];
786    }
787}
788
789- (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn
790{
791    if (tableView == fPeerTable)
792    {
793        if (fPeers)
794        {
795            NSArray * oldPeers = fPeers;
796            fPeers = [[fPeers sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain];
797            [oldPeers release];
798            [tableView reloadData];
799        }
800    }
801}
802
803- (BOOL) tableView: (NSTableView *) tableView shouldSelectRow:(int) row
804{
805    return tableView != fPeerTable;
806}
807
808- (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
809                tableColumn: (NSTableColumn *) column row: (int) row mouseLocation: (NSPoint) mouseLocation
810{
811    if (tableView == fPeerTable)
812    {
813        NSDictionary * peer = [fPeers objectAtIndex: row];
814       
815        NSMutableArray * components = [NSMutableArray arrayWithCapacity: 3];
816       
817        if ([[peer objectForKey: @"Connected"] boolValue])
818            [components addObject: [NSString stringWithFormat:
819                                    NSLocalizedString(@"Progress: %.1f%%", "Inspector -> Peers tab -> table row tooltip"),
820                                    [[peer objectForKey: @"Progress"] floatValue] * 100.0]];
821       
822        int port;
823        if ((port = [[peer objectForKey: @"Port"] intValue]) > 0)
824            [components addObject: [NSString stringWithFormat:
825                                    NSLocalizedString(@"Port: %d", "Inspector -> Peers tab -> table row tooltip"), port]];
826        else
827            [components addObject: NSLocalizedString(@"Port: N/A", "Inspector -> Peers tab -> table row tooltip")];
828       
829        int from = [[peer objectForKey: @"From"] intValue];
830        if (from == TR_PEER_FROM_INCOMING)
831            [components addObject: NSLocalizedString(@"From: incoming connection", "Inspector -> Peers tab -> table row tooltip")];
832        else if (from == TR_PEER_FROM_CACHE)
833            [components addObject: NSLocalizedString(@"From: cache", "Inspector -> Peers tab -> table row tooltip")];
834        else if (from == TR_PEER_FROM_PEX)
835            [components addObject: NSLocalizedString(@"From: peer exchange", "Inspector -> Peers tab -> table row tooltip")];
836        else
837            [components addObject: NSLocalizedString(@"From: tracker", "Inspector -> Peers tab -> table row tooltip")];
838       
839        return [components componentsJoinedByString: @"\n"];
840    }
841    return nil;
842}
843
844- (int) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
845{
846    if (!item)
847        return [fFiles count];
848    return [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Children"] count] : 0;
849}
850
851- (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item
852{
853    return [[item objectForKey: @"IsFolder"] boolValue];
854}
855
856- (id) outlineView: (NSOutlineView *) outlineView child: (int) index ofItem: (id) item
857{
858    return [(item ? [item objectForKey: @"Children"] : fFiles) objectAtIndex: index];
859}
860
861- (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
862{
863    if ([[tableColumn identifier] isEqualToString: @"Check"])
864        return [NSNumber numberWithInt: [[fTorrents objectAtIndex: 0] checkForFiles: [item objectForKey: @"Indexes"]]];
865    else
866        return item;
867}
868
869- (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell
870            forTableColumn: (NSTableColumn *) tableColumn item: (id) item
871{
872    NSString * identifier = [tableColumn identifier];
873    if ([identifier isEqualToString: @"Name"])
874    {
875        if ([[item objectForKey: @"IsFolder"] boolValue])
876            [cell setImage: nil];
877        else
878        {
879            [cell setImage: [item objectForKey: @"Icon"]];
880            [(FileBrowserCell *)cell setProgress: [[fTorrents objectAtIndex: 0] fileProgress:
881                                                    [[item objectForKey: @"Indexes"] firstIndex]]];
882        }
883    }
884    else if ([identifier isEqualToString: @"Check"])
885        [cell setEnabled: [[fTorrents objectAtIndex: 0] canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]];
886    else if ([identifier isEqualToString: @"Priority"])
887        [(FilePriorityCell *)cell setItem: item];
888    else;
889}
890
891- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object
892        forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
893{
894    NSString * identifier = [tableColumn identifier];
895    if ([identifier isEqualToString: @"Check"])
896    {
897        Torrent * torrent = [fTorrents objectAtIndex: 0];
898        [torrent setFileCheckState: [object intValue] != NSOffState ? NSOnState : NSOffState
899                                        forIndexes: [item objectForKey: @"Indexes"]];
900        [fFileOutline reloadData];
901    }
902    else;
903}
904
905- (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
906                tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation
907{
908    NSString * ident = [tableColumn identifier];
909    if ([ident isEqualToString: @"Name"])
910        return [[[fTorrents objectAtIndex: 0] downloadFolder] stringByAppendingPathComponent: [item objectForKey: @"Path"]];
911    else if ([ident isEqualToString: @"Check"])
912    {
913        int check = [cell state];
914        if (check == NSOffState)
915            return NSLocalizedString(@"Don't Download", "Inspector -> files tab -> tooltip");
916        else if (check == NSMixedState)
917            return NSLocalizedString(@"Download Some", "Inspector -> files tab -> tooltip");
918        else
919            return NSLocalizedString(@"Download", "Inspector -> files tab -> tooltip");
920    }
921    else if ([ident isEqualToString: @"Priority"])
922    {
923        Torrent * torrent = [fTorrents objectAtIndex: 0];
924        NSIndexSet * indexSet = [item objectForKey: @"Indexes"];
925       
926        if (![torrent canChangeDownloadCheckForFiles: indexSet])
927            return NSLocalizedString(@"Priority Not Available", "Inspector -> files tab -> tooltip");
928       
929        BOOL low = [torrent hasFilePriority: PRIORITY_LOW forIndexes: indexSet],
930            normal = [torrent hasFilePriority: PRIORITY_NORMAL forIndexes: indexSet],
931            high = [torrent hasFilePriority: PRIORITY_HIGH forIndexes: indexSet];
932       
933        if (low && !normal && !high)
934            return NSLocalizedString(@"Low Priority", "Inspector -> files tab -> tooltip");
935        else if (!low && normal && !high)
936            return NSLocalizedString(@"Normal Priority", "Inspector -> files tab -> tooltip");
937        else if (!low && !normal && high)
938            return NSLocalizedString(@"High Priority", "Inspector -> files tab -> tooltip");
939        else
940            return NSLocalizedString(@"Multiple Priorities", "Inspector -> files tab -> tooltip");
941    }
942    else
943        return nil;
944}
945
946- (float) outlineView: (NSOutlineView *) outlineView heightOfRowByItem: (id) item
947{
948    if ([[item objectForKey: @"IsFolder"] boolValue])
949        return FILE_ROW_SMALL_HEIGHT;
950    else
951        return [outlineView rowHeight];
952}
953
954#warning need?
955- (void) setFileOutlineHoverRowForEvent: (NSEvent *) event
956{
957    [fFileOutline setHoverRowForEvent: [[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_FILES_IDENT] ? event : nil];
958}
959
960- (NSArray *) peerSortDescriptors
961{
962    NSMutableArray * descriptors = [NSMutableArray array];
963   
964    NSArray * oldDescriptors = [fPeerTable sortDescriptors];
965    BOOL useSecond = YES, asc = YES;
966    if ([oldDescriptors count] > 0)
967    {
968        NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0];
969        [descriptors addObject: descriptor];
970       
971        if ((useSecond = ![[descriptor key] isEqualToString: @"IP"]))
972            asc = [descriptor ascending];
973    }
974   
975    //sort by IP after primary sort
976    if (useSecond)
977    {
978        NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc
979                                                                        selector: @selector(compareIP:)];
980        [descriptors addObject: secondDescriptor];
981        [secondDescriptor release];
982    }
983   
984    return descriptors;
985}
986
987- (void) setPiecesView: (id) sender
988{
989    [self setPiecesViewForAvailable: [sender selectedSegment] == PIECES_CONTROL_AVAILABLE];
990}
991
992- (void) setPiecesViewForAvailable: (BOOL) available
993{
994    [fPiecesControl setSelected: available forSegment: PIECES_CONTROL_AVAILABLE];
995    [fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS];
996   
997    [[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"];
998    [fPiecesView updateView: YES];
999}
1000
1001- (void) revealTorrentFile: (id) sender
1002{
1003    if ([fTorrents count] > 0)
1004        [[fTorrents objectAtIndex: 0] revealPublicTorrent];
1005}
1006
1007- (void) revealDataFile: (id) sender
1008{
1009    if ([fTorrents count] > 0)
1010        [[fTorrents objectAtIndex: 0] revealData];
1011}
1012
1013- (void) revealFile: (id) sender
1014{
1015    if (!fFiles)
1016        return;
1017   
1018    NSString * folder = [[fTorrents objectAtIndex: 0] downloadFolder];
1019    NSIndexSet * indexes = [fFileOutline selectedRowIndexes];
1020    int i;
1021    for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
1022        [[NSWorkspace sharedWorkspace] selectFile: [folder stringByAppendingPathComponent:
1023                [[fFileOutline itemAtRow: i] objectForKey: @"Path"]] inFileViewerRootedAtPath: nil];
1024}
1025
1026- (void) setCheck: (id) sender
1027{
1028    int state = sender == fFileCheckItem ? NSOnState : NSOffState;
1029   
1030    Torrent * torrent = [fTorrents objectAtIndex: 0];
1031    NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
1032    NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
1033    int i;
1034    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
1035        [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
1036   
1037    [torrent setFileCheckState: state forIndexes: itemIndexes];
1038    [fFileOutline reloadData];
1039}
1040
1041- (void) setOnlySelectedCheck: (id) sender
1042{
1043    Torrent * torrent = [fTorrents objectAtIndex: 0];
1044    NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
1045    NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
1046    int i;
1047    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
1048        [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
1049   
1050    [torrent setFileCheckState: NSOnState forIndexes: itemIndexes];
1051   
1052    NSMutableIndexSet * remainingItemIndexes = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [torrent fileCount])];
1053    [remainingItemIndexes removeIndexes: itemIndexes];
1054    [torrent setFileCheckState: NSOffState forIndexes: remainingItemIndexes];
1055   
1056    [fFileOutline reloadData];
1057}
1058
1059- (void) setPriority: (id) sender
1060{
1061    int priority;
1062    if (sender == fFilePriorityHigh)
1063        priority = PRIORITY_HIGH;
1064    else if (sender == fFilePriorityLow)
1065        priority = PRIORITY_LOW;
1066    else
1067        priority = PRIORITY_NORMAL;
1068   
1069    Torrent * torrent = [fTorrents objectAtIndex: 0];
1070    NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
1071    NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
1072    int i;
1073    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
1074        [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
1075   
1076    [torrent setFilePriority: priority forIndexes: itemIndexes];
1077    [fFileOutline reloadData];
1078}
1079
1080- (void) setLimitSetting: (id) sender
1081{
1082    BOOL upload = sender == fUploadLimitPopUp;
1083    int setting;
1084    if ((setting = [self popUpIndexToStateSetting: [sender indexOfSelectedItem]]) == INVALID)
1085        return;
1086   
1087    Torrent * torrent;
1088    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1089    while ((torrent = [enumerator nextObject]))
1090        upload ? [torrent setCheckUpload: setting] : [torrent setCheckDownload: setting];
1091   
1092    NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField;
1093    [field setHidden: setting != NSOnState];
1094    if (setting == NSOnState)
1095    {
1096        [field selectText: self];
1097        [[self window] makeKeyAndOrderFront:self];
1098    }
1099   
1100    NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel;
1101    [label setHidden: setting != NSOnState];
1102}
1103
1104- (void) setSpeedLimit: (id) sender
1105{
1106    BOOL upload = sender == fUploadLimitField;
1107   
1108    Torrent * torrent;
1109    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1110
1111    int limit = [sender intValue];
1112    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%i", limit]] || limit < 0)
1113    {
1114        NSBeep();
1115       
1116        torrent = [enumerator nextObject]; //use first torrent
1117        limit = upload ? [torrent uploadLimit] : [torrent downloadLimit];
1118        while ((torrent = [enumerator nextObject]))
1119            if (limit != (upload ? [torrent uploadLimit] : [torrent downloadLimit]))
1120            {
1121                [sender setStringValue: @""];
1122                return;
1123            }
1124       
1125        [sender setIntValue: limit];
1126    }
1127    else
1128    {
1129        while ((torrent = [enumerator nextObject]))
1130            upload ? [torrent setUploadLimit: limit] : [torrent setDownloadLimit: limit];
1131    }
1132}
1133
1134- (void) setRatioSetting: (id) sender
1135{
1136    int setting;
1137    if ((setting = [self popUpIndexToStateSetting: [sender indexOfSelectedItem]]) == INVALID)
1138        return;
1139   
1140    Torrent * torrent;
1141    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1142    while ((torrent = [enumerator nextObject]))
1143        [torrent setRatioSetting: setting];
1144   
1145    [fRatioLimitField setHidden: setting != NSOnState];
1146    if (setting == NSOnState)
1147    {
1148        [fRatioLimitField selectText: self];
1149        [[self window] makeKeyAndOrderFront:self];
1150    }
1151   
1152    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
1153}
1154
1155- (void) setRatioLimit: (id) sender
1156{
1157    Torrent * torrent;
1158    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1159
1160    float ratioLimit = [sender floatValue];
1161    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]] || ratioLimit < 0)
1162    {
1163        NSBeep();
1164        float ratioLimit = [[enumerator nextObject] ratioLimit]; //use first torrent
1165        while ((torrent = [enumerator nextObject]))
1166            if (ratioLimit != [torrent ratioLimit])
1167            {
1168                [sender setStringValue: @""];
1169                return;
1170            }
1171       
1172        [sender setFloatValue: ratioLimit];
1173    }
1174    else
1175    {
1176        while ((torrent = [enumerator nextObject]))
1177            [torrent setRatioLimit: ratioLimit];
1178    }
1179   
1180    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
1181}
1182
1183- (void) setPex: (id) sender
1184{
1185        int state = [sender state];
1186        if (state == NSMixedState)
1187        {
1188                state = NSOnState;
1189                [sender setState: state];
1190        }
1191       
1192        Torrent * torrent;
1193    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1194       
1195        while ((torrent = [enumerator nextObject]))
1196                [torrent setPex: state == NSOnState];
1197}
1198
1199@end
Note: See TracBrowser for help on using the repository browser.