source: trunk/macosx/InfoWindowController.m @ 2337

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

hopefully function for getting priorities is a bit faster

  • Property svn:keywords set to Date Rev Author Id
File size: 44.2 KB
Line 
1/******************************************************************************
2 * $Id: InfoWindowController.m 2337 2007-07-13 04:20:11Z 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    SEL action = [menuItem action];
605   
606    if (action == @selector(revealFile:))
607        return [fFileOutline numberOfSelectedRows] > 0 &&
608            [[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_FILES_IDENT];
609   
610    if (action == @selector(setCheck:))
611    {
612        if ([fFileOutline numberOfSelectedRows] <= 0)
613            return NO;
614       
615        Torrent * torrent = [fTorrents objectAtIndex: 0];
616        NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
617        NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
618        int i, index, state = (menuItem == fFileCheckItem) ? NSOnState : NSOffState;
619        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
620            [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
621       
622        return [torrent checkForFiles: itemIndexes] != state && [torrent canChangeDownloadCheckForFiles: itemIndexes];
623    }
624   
625    if (action == @selector(setOnlySelectedCheck:))
626    {
627        if ([fFileOutline numberOfSelectedRows] <= 0)
628            return NO;
629       
630        Torrent * torrent = [fTorrents objectAtIndex: 0];
631        NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
632        NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
633        int i, index;
634        for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
635            [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
636           
637        return [torrent canChangeDownloadCheckForFiles: itemIndexes];
638    }
639   
640    if (action == @selector(setPriority:))
641    {
642        if ([fFileOutline numberOfSelectedRows] <= 0)
643        {
644            [menuItem setState: NSOffState];
645            return NO;
646        }
647       
648        //determine which priorities are checked
649        NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
650        BOOL current = NO, other = NO;
651        int i, priority;
652        Torrent * torrent = [fTorrents objectAtIndex: 0];
653       
654        if (menuItem == fFilePriorityHigh)
655            priority = TR_PRI_HIGH;
656        else if (menuItem == fFilePriorityLow)
657            priority = TR_PRI_LOW;
658        else
659            priority = TR_PRI_NORMAL;
660       
661        NSIndexSet * fileIndexSet;
662        for (i = [indexSet firstIndex]; i != NSNotFound && (!current || !other); i = [indexSet indexGreaterThanIndex: i])
663        {
664            fileIndexSet = [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"];
665            if (![torrent canChangeDownloadCheckForFiles: fileIndexSet])
666                continue;
667            else if ([torrent hasFilePriority: priority forIndexes: fileIndexSet])
668                current = YES;
669            else
670                other = YES;
671        }
672       
673        [menuItem setState: current ? NSOnState : NSOffState];
674        return current || other;
675    }
676   
677    return YES;
678}
679
680- (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame
681{
682    NSRect windowRect = [window frame];
683    windowRect.size.width = [window minSize].width;
684    return windowRect;
685}
686
687- (void) tabView: (NSTabView *) tabView didSelectTabViewItem: (NSTabViewItem *) tabViewItem
688{
689    NSString * identifier = [tabViewItem identifier];
690    [self setWindowForTab: identifier animate: YES];
691    [[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InspectorSelected"];
692}
693
694- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate
695{
696    [self updateInfoStats];
697   
698    float height;
699    if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
700    {
701        height = TAB_ACTIVITY_HEIGHT;
702        [fPiecesView updateView: YES];
703    }
704    else if ([identifier isEqualToString: TAB_PEERS_IDENT])
705        height = TAB_PEERS_HEIGHT;
706    else if ([identifier isEqualToString: TAB_FILES_IDENT])
707        height = TAB_FILES_HEIGHT;
708    else if ([identifier isEqualToString: TAB_OPTIONS_IDENT])
709        height = TAB_OPTIONS_HEIGHT;
710    else
711        height = TAB_INFO_HEIGHT;
712   
713    NSWindow * window = [self window];
714    NSRect frame = [window frame];
715    NSView * view = [[fTabView selectedTabViewItem] view];
716   
717    float difference = height - [view frame].size.height;
718    frame.origin.y -= difference;
719    frame.size.height += difference;
720   
721    if (animate)
722    {
723        [view setHidden: YES];
724        [window setFrame: frame display: YES animate: YES];
725        [view setHidden: NO];
726    }
727    else
728        [window setFrame: frame display: YES];
729   
730    [window setMinSize: NSMakeSize(MIN_WINDOW_WIDTH, frame.size.height)];
731    [window setMaxSize: NSMakeSize(MAX_WINDOW_WIDTH, frame.size.height)];
732}
733
734- (void) setNextTab
735{
736    if ([fTabView indexOfTabViewItem: [fTabView selectedTabViewItem]] == [fTabView numberOfTabViewItems] - 1)
737        [fTabView selectFirstTabViewItem: nil];
738    else
739        [fTabView selectNextTabViewItem: nil];
740}
741
742- (void) setPreviousTab
743{
744    if ([fTabView indexOfTabViewItem: [fTabView selectedTabViewItem]] == 0)
745        [fTabView selectLastTabViewItem: nil];
746    else
747        [fTabView selectPreviousTabViewItem: nil];
748}
749
750- (int) numberOfRowsInTableView: (NSTableView *) tableView
751{
752    if (tableView == fPeerTable)
753        return fPeers ? [fPeers count] : 0;
754    return 0;
755}
756
757- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (int) row
758{
759    if (tableView == fPeerTable)
760    {
761        NSString * ident = [column identifier];
762        NSDictionary * peer = [fPeers objectAtIndex: row];
763       
764        if ([ident isEqualToString: @"Connected"])
765            return [[peer objectForKey: @"Connected"] boolValue] ? fDotGreen : fDotRed;
766        else if ([ident isEqualToString: @"Client"])
767            return [peer objectForKey: @"Client"];
768        else if  ([ident isEqualToString: @"Progress"])
769            return [peer objectForKey: @"Progress"]; //returning nil is fine
770        else if ([ident isEqualToString: @"UL To"])
771        {
772            NSNumber * rate;
773            return (rate = [peer objectForKey: @"UL To Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
774        }
775        else if ([ident isEqualToString: @"DL From"])
776        {
777            NSNumber * rate;
778            return (rate = [peer objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
779        }
780        else
781            return [peer objectForKey: @"IP"];
782    }
783    return nil;
784}
785
786- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell
787            forTableColumn: (NSTableColumn *) tableColumn row: (int) row
788{
789    if (tableView == fPeerTable)
790    {
791        if ([[tableColumn identifier] isEqualToString: @"Progress"])
792            [cell setHidden: ![[[fPeers objectAtIndex: row] objectForKey: @"Connected"] boolValue]];
793    }
794}
795
796- (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn
797{
798    if (tableView == fPeerTable)
799    {
800        if (fPeers)
801        {
802            NSArray * oldPeers = fPeers;
803            fPeers = [[fPeers sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain];
804            [oldPeers release];
805            [tableView reloadData];
806        }
807    }
808}
809
810- (BOOL) tableView: (NSTableView *) tableView shouldSelectRow:(int) row
811{
812    return tableView != fPeerTable;
813}
814
815- (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
816                tableColumn: (NSTableColumn *) column row: (int) row mouseLocation: (NSPoint) mouseLocation
817{
818    if (tableView == fPeerTable)
819    {
820        NSDictionary * peer = [fPeers objectAtIndex: row];
821       
822        NSMutableArray * components = [NSMutableArray arrayWithCapacity: 3];
823       
824        if ([[peer objectForKey: @"Connected"] boolValue])
825            [components addObject: [NSString stringWithFormat:
826                                    NSLocalizedString(@"Progress: %.1f%%", "Inspector -> Peers tab -> table row tooltip"),
827                                    [[peer objectForKey: @"Progress"] floatValue] * 100.0]];
828       
829        int port;
830        if ((port = [[peer objectForKey: @"Port"] intValue]) > 0)
831            [components addObject: [NSString stringWithFormat:
832                                    NSLocalizedString(@"Port: %d", "Inspector -> Peers tab -> table row tooltip"), port]];
833        else
834            [components addObject: NSLocalizedString(@"Port: N/A", "Inspector -> Peers tab -> table row tooltip")];
835       
836        int from = [[peer objectForKey: @"From"] intValue];
837        if (from == TR_PEER_FROM_INCOMING)
838            [components addObject: NSLocalizedString(@"From: incoming connection", "Inspector -> Peers tab -> table row tooltip")];
839        else if (from == TR_PEER_FROM_CACHE)
840            [components addObject: NSLocalizedString(@"From: cache", "Inspector -> Peers tab -> table row tooltip")];
841        else if (from == TR_PEER_FROM_PEX)
842            [components addObject: NSLocalizedString(@"From: peer exchange", "Inspector -> Peers tab -> table row tooltip")];
843        else
844            [components addObject: NSLocalizedString(@"From: tracker", "Inspector -> Peers tab -> table row tooltip")];
845       
846        return [components componentsJoinedByString: @"\n"];
847    }
848    return nil;
849}
850
851- (int) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
852{
853    if (!item)
854        return [fFiles count];
855    return [[item objectForKey: @"IsFolder"] boolValue] ? [[item objectForKey: @"Children"] count] : 0;
856}
857
858- (BOOL) outlineView: (NSOutlineView *) outlineView isItemExpandable: (id) item
859{
860    return [[item objectForKey: @"IsFolder"] boolValue];
861}
862
863- (id) outlineView: (NSOutlineView *) outlineView child: (int) index ofItem: (id) item
864{
865    return [(item ? [item objectForKey: @"Children"] : fFiles) objectAtIndex: index];
866}
867
868- (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
869{
870    if ([[tableColumn identifier] isEqualToString: @"Check"])
871        return [NSNumber numberWithInt: [[fTorrents objectAtIndex: 0] checkForFiles: [item objectForKey: @"Indexes"]]];
872    else
873        return item;
874}
875
876- (void) outlineView: (NSOutlineView *) outlineView willDisplayCell: (id) cell
877            forTableColumn: (NSTableColumn *) tableColumn item: (id) item
878{
879    NSString * identifier = [tableColumn identifier];
880    if ([identifier isEqualToString: @"Name"])
881    {
882        if ([[item objectForKey: @"IsFolder"] boolValue])
883            [cell setImage: nil];
884        else
885        {
886            [cell setImage: [item objectForKey: @"Icon"]];
887            [(FileBrowserCell *)cell setProgress: [[fTorrents objectAtIndex: 0] fileProgress:
888                                                    [[item objectForKey: @"Indexes"] firstIndex]]];
889        }
890    }
891    else if ([identifier isEqualToString: @"Check"])
892        [cell setEnabled: [[fTorrents objectAtIndex: 0] canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]];
893    else if ([identifier isEqualToString: @"Priority"])
894        [(FilePriorityCell *)cell setItem: item];
895    else;
896}
897
898- (void) outlineView: (NSOutlineView *) outlineView setObjectValue: (id) object
899        forTableColumn: (NSTableColumn *) tableColumn byItem: (id) item
900{
901    NSString * identifier = [tableColumn identifier];
902    if ([identifier isEqualToString: @"Check"])
903    {
904        Torrent * torrent = [fTorrents objectAtIndex: 0];
905        NSIndexSet * indexSet;
906        if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask)
907            indexSet = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [torrent fileCount])];
908        else
909            indexSet = [item objectForKey: @"Indexes"];
910       
911        [torrent setFileCheckState: [object intValue] != NSOffState ? NSOnState : NSOffState forIndexes: indexSet];
912        [fFileOutline reloadData];
913    }
914    else;
915}
916
917- (NSString *) outlineView: (NSOutlineView *) outlineView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
918        tableColumn: (NSTableColumn *) tableColumn item: (id) item mouseLocation: (NSPoint) mouseLocation
919{
920    NSString * ident = [tableColumn identifier];
921    if ([ident isEqualToString: @"Name"])
922        return [[[fTorrents objectAtIndex: 0] downloadFolder] stringByAppendingPathComponent: [item objectForKey: @"Path"]];
923    else if ([ident isEqualToString: @"Check"])
924    {
925        int check = [cell state];
926        if (check == NSOffState)
927            return NSLocalizedString(@"Don't Download", "Inspector -> files tab -> tooltip");
928        else if (check == NSMixedState)
929            return NSLocalizedString(@"Download Some", "Inspector -> files tab -> tooltip");
930        else
931            return NSLocalizedString(@"Download", "Inspector -> files tab -> tooltip");
932    }
933    else if ([ident isEqualToString: @"Priority"])
934    {
935        NSArray * priorities = [[fTorrents objectAtIndex: 0] filePrioritiesForIndexes: [item objectForKey: @"Indexes"]];
936       
937        int count = [priorities count];
938        if (count == 0)
939            return NSLocalizedString(@"Priority Not Available", "Inspector -> files tab -> tooltip");
940        else if (count > 1)
941            return NSLocalizedString(@"Multiple Priorities", "Inspector -> files tab -> tooltip");
942        else
943        {
944            int priority = [[priorities objectAtIndex: 0] intValue];
945            if (priority == TR_PRI_LOW)
946                return NSLocalizedString(@"Low Priority", "Inspector -> files tab -> tooltip");
947            else if (priority == TR_PRI_HIGH)
948                return NSLocalizedString(@"High Priority", "Inspector -> files tab -> tooltip");
949            else
950                return NSLocalizedString(@"Normal Priority", "Inspector -> files tab -> tooltip");
951        }
952    }
953    else
954        return nil;
955}
956
957- (float) outlineView: (NSOutlineView *) outlineView heightOfRowByItem: (id) item
958{
959    if ([[item objectForKey: @"IsFolder"] boolValue])
960        return FILE_ROW_SMALL_HEIGHT;
961    else
962        return [outlineView rowHeight];
963}
964
965- (void) setFileOutlineHoverRowForEvent: (NSEvent *) event
966{
967    [fFileOutline setHoverRowForEvent: [[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_FILES_IDENT]
968                                        ? event : nil];
969}
970
971- (NSArray *) peerSortDescriptors
972{
973    NSMutableArray * descriptors = [NSMutableArray array];
974   
975    NSArray * oldDescriptors = [fPeerTable sortDescriptors];
976    BOOL useSecond = YES, asc = YES;
977    if ([oldDescriptors count] > 0)
978    {
979        NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0];
980        [descriptors addObject: descriptor];
981       
982        if ((useSecond = ![[descriptor key] isEqualToString: @"IP"]))
983            asc = [descriptor ascending];
984    }
985   
986    //sort by IP after primary sort
987    if (useSecond)
988    {
989        NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc
990                                                                        selector: @selector(compareIP:)];
991        [descriptors addObject: secondDescriptor];
992        [secondDescriptor release];
993    }
994   
995    return descriptors;
996}
997
998- (void) setPiecesView: (id) sender
999{
1000    [self setPiecesViewForAvailable: [sender selectedSegment] == PIECES_CONTROL_AVAILABLE];
1001}
1002
1003- (void) setPiecesViewForAvailable: (BOOL) available
1004{
1005    [fPiecesControl setSelected: available forSegment: PIECES_CONTROL_AVAILABLE];
1006    [fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS];
1007   
1008    [[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"];
1009    [fPiecesView updateView: YES];
1010}
1011
1012- (void) revealTorrentFile: (id) sender
1013{
1014    if ([fTorrents count] > 0)
1015        [[fTorrents objectAtIndex: 0] revealPublicTorrent];
1016}
1017
1018- (void) revealDataFile: (id) sender
1019{
1020    if ([fTorrents count] > 0)
1021        [[fTorrents objectAtIndex: 0] revealData];
1022}
1023
1024- (void) revealFile: (id) sender
1025{
1026    if (!fFiles)
1027        return;
1028   
1029    NSString * folder = [[fTorrents objectAtIndex: 0] downloadFolder];
1030    NSIndexSet * indexes = [fFileOutline selectedRowIndexes];
1031    int i;
1032    for (i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
1033        [[NSWorkspace sharedWorkspace] selectFile: [folder stringByAppendingPathComponent:
1034                [[fFileOutline itemAtRow: i] objectForKey: @"Path"]] inFileViewerRootedAtPath: nil];
1035}
1036
1037- (void) setCheck: (id) sender
1038{
1039    int state = sender == fFileCheckItem ? NSOnState : NSOffState;
1040   
1041    Torrent * torrent = [fTorrents objectAtIndex: 0];
1042    NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
1043    NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
1044    int i;
1045    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
1046        [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
1047   
1048    [torrent setFileCheckState: state forIndexes: itemIndexes];
1049    [fFileOutline reloadData];
1050}
1051
1052- (void) setOnlySelectedCheck: (id) sender
1053{
1054    Torrent * torrent = [fTorrents objectAtIndex: 0];
1055    NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
1056    NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
1057    int i;
1058    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
1059        [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
1060   
1061    [torrent setFileCheckState: NSOnState forIndexes: itemIndexes];
1062   
1063    NSMutableIndexSet * remainingItemIndexes = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [torrent fileCount])];
1064    [remainingItemIndexes removeIndexes: itemIndexes];
1065    [torrent setFileCheckState: NSOffState forIndexes: remainingItemIndexes];
1066   
1067    [fFileOutline reloadData];
1068}
1069
1070- (void) setPriority: (id) sender
1071{
1072    int priority;
1073    if (sender == fFilePriorityHigh)
1074        priority = TR_PRI_HIGH;
1075    else if (sender == fFilePriorityLow)
1076        priority = TR_PRI_LOW;
1077    else
1078        priority = TR_PRI_NORMAL;
1079   
1080    Torrent * torrent = [fTorrents objectAtIndex: 0];
1081    NSIndexSet * indexSet = [fFileOutline selectedRowIndexes];
1082    NSMutableIndexSet * itemIndexes = [NSMutableIndexSet indexSet];
1083    int i;
1084    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
1085        [itemIndexes addIndexes: [[fFileOutline itemAtRow: i] objectForKey: @"Indexes"]];
1086   
1087    [torrent setFilePriority: priority forIndexes: itemIndexes];
1088    [fFileOutline reloadData];
1089}
1090
1091- (void) setLimitSetting: (id) sender
1092{
1093    BOOL upload = sender == fUploadLimitPopUp;
1094    int setting;
1095    if ((setting = [self popUpIndexToStateSetting: [sender indexOfSelectedItem]]) == INVALID)
1096        return;
1097   
1098    Torrent * torrent;
1099    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1100    while ((torrent = [enumerator nextObject]))
1101        upload ? [torrent setCheckUpload: setting] : [torrent setCheckDownload: setting];
1102   
1103    NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField;
1104    [field setHidden: setting != NSOnState];
1105    if (setting == NSOnState)
1106    {
1107        [field selectText: self];
1108        [[self window] makeKeyAndOrderFront:self];
1109    }
1110   
1111    NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel;
1112    [label setHidden: setting != NSOnState];
1113}
1114
1115- (void) setSpeedLimit: (id) sender
1116{
1117    BOOL upload = sender == fUploadLimitField;
1118   
1119    Torrent * torrent;
1120    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1121
1122    int limit = [sender intValue];
1123    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%i", limit]] || limit < 0)
1124    {
1125        NSBeep();
1126       
1127        torrent = [enumerator nextObject]; //use first torrent
1128        limit = upload ? [torrent uploadLimit] : [torrent downloadLimit];
1129        while ((torrent = [enumerator nextObject]))
1130            if (limit != (upload ? [torrent uploadLimit] : [torrent downloadLimit]))
1131            {
1132                [sender setStringValue: @""];
1133                return;
1134            }
1135       
1136        [sender setIntValue: limit];
1137    }
1138    else
1139    {
1140        while ((torrent = [enumerator nextObject]))
1141            upload ? [torrent setUploadLimit: limit] : [torrent setDownloadLimit: limit];
1142    }
1143}
1144
1145- (void) setRatioSetting: (id) sender
1146{
1147    int setting;
1148    if ((setting = [self popUpIndexToStateSetting: [sender indexOfSelectedItem]]) == INVALID)
1149        return;
1150   
1151    Torrent * torrent;
1152    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1153    while ((torrent = [enumerator nextObject]))
1154        [torrent setRatioSetting: setting];
1155   
1156    [fRatioLimitField setHidden: setting != NSOnState];
1157    if (setting == NSOnState)
1158    {
1159        [fRatioLimitField selectText: self];
1160        [[self window] makeKeyAndOrderFront:self];
1161    }
1162   
1163    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
1164}
1165
1166- (void) setRatioLimit: (id) sender
1167{
1168    Torrent * torrent;
1169    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1170
1171    float ratioLimit = [sender floatValue];
1172    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]] || ratioLimit < 0)
1173    {
1174        NSBeep();
1175        float ratioLimit = [[enumerator nextObject] ratioLimit]; //use first torrent
1176        while ((torrent = [enumerator nextObject]))
1177            if (ratioLimit != [torrent ratioLimit])
1178            {
1179                [sender setStringValue: @""];
1180                return;
1181            }
1182       
1183        [sender setFloatValue: ratioLimit];
1184    }
1185    else
1186    {
1187        while ((torrent = [enumerator nextObject]))
1188            [torrent setRatioLimit: ratioLimit];
1189    }
1190   
1191    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
1192}
1193
1194- (void) setPex: (id) sender
1195{
1196        int state = [sender state];
1197        if (state == NSMixedState)
1198        {
1199                state = NSOnState;
1200                [sender setState: state];
1201        }
1202       
1203        Torrent * torrent;
1204    NSEnumerator * enumerator = [fTorrents objectEnumerator];
1205       
1206        while ((torrent = [enumerator nextObject]))
1207                [torrent setPex: state == NSOnState];
1208}
1209
1210@end
Note: See TracBrowser for help on using the repository browser.