source: trunk/macosx/InfoWindowController.m @ 1124

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

merge tracker address and announce address into one field in the inspector

  • Property svn:keywords set to Date Rev Author Id
File size: 23.2 KB
Line 
1/******************************************************************************
2 * $Id: InfoWindowController.m 1124 2006-11-23 04:10:16Z livings124 $
3 *
4 * Copyright (c) 2006 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 "StringAdditions.h"
27
28#define RATIO_GLOBAL_TAG 0
29#define RATIO_NO_CHECK_TAG 1
30#define RATIO_CHECK_TAG 2
31
32#define MIN_WINDOW_WIDTH 300
33#define MAX_WINDOW_WIDTH 5000
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 109.0
44#define TAB_PEERS_HEIGHT 268.0
45#define TAB_FILES_HEIGHT 268.0
46#define TAB_OPTIONS_HEIGHT 83.0
47
48#define INVALID -99
49
50@interface InfoWindowController (Private)
51
52- (void) updateInfoActivity;
53- (void) updateInfoPeers;
54
55- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate;
56- (NSArray *) peerSortDescriptors;
57
58@end
59
60@implementation InfoWindowController
61
62- (id) initWithWindowNibName: (NSString *) name
63{
64    if ((self = [super initWithWindowNibName: name]))
65    {
66        fAppIcon = [[NSApp applicationIconImage] copy];
67        fDotGreen = [NSImage imageNamed: @"GreenDot.tiff"];
68        fDotRed = [NSImage imageNamed: @"RedDot.tiff"];
69        fCheckImage = [NSImage imageNamed: @"NSMenuCheckmark"];   
70    }
71    return self;
72}
73
74- (void) awakeFromNib
75{
76    fPeers = [[NSMutableArray alloc] initWithCapacity: 30];
77    fFiles = [[NSMutableArray alloc] initWithCapacity: 6];
78    [fFileTable setDoubleAction: @selector(revealFile:)];
79   
80    //window location and size
81    NSPanel * window = (NSPanel *)[self window];
82   
83    [window setBecomesKeyOnlyIfNeeded: YES];
84   
85    [window setFrameAutosaveName: @"InspectorWindowFrame"];
86    [window setFrameUsingName: @"InspectorWindowFrame"];
87   
88    //select tab
89    NSString * identifier = [[NSUserDefaults standardUserDefaults] stringForKey: @"InfoTab"];
90    if ([fTabView indexOfTabViewItemWithIdentifier: identifier] == NSNotFound)
91        identifier = TAB_INFO_IDENT;
92   
93    [fTabView selectTabViewItemWithIdentifier: identifier];
94    [self setWindowForTab: identifier animate: NO];
95   
96    //initially sort peer table by IP
97    if ([[fPeerTable sortDescriptors] count] == 0)
98        [fPeerTable setSortDescriptors: [NSArray arrayWithObject: [[fPeerTable tableColumnWithIdentifier: @"IP"]
99                                            sortDescriptorPrototype]]];
100   
101    [self updateInfoForTorrents: [NSArray array]];
102}
103
104- (void) dealloc
105{
106    [fTorrents release];
107    [fPeers release];
108    [fFiles release];
109
110    [fAppIcon release];
111    [super dealloc];
112}
113
114- (void) updateInfoForTorrents: (NSArray *) torrents
115{
116    if (fTorrents)
117        [fTorrents release];
118    fTorrents = [torrents retain];
119
120    int numberSelected = [fTorrents count];
121    if (numberSelected != 1)
122    {
123        if (numberSelected > 0)
124        {
125            [fNameField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d Torrents Selected",
126                                            "Inspector -> above tabs -> selected torrents"), numberSelected]];
127       
128            uint64_t size = 0;
129            NSEnumerator * enumerator = [torrents objectEnumerator];
130            Torrent * torrent;
131            while ((torrent = [enumerator nextObject]))
132                size += [torrent size];
133           
134            [fSizeField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%@ Total",
135                "Inspector -> above tabs -> total size (several torrents selected)"), [NSString stringForFileSize: size]]];
136        }
137        else
138        {
139            [fNameField setStringValue: NSLocalizedString(@"No Torrents Selected",
140                                                            "Inspector -> above tabs -> selected torrents")];
141            [fSizeField setStringValue: @""];
142   
143            [fDownloadedValidField setStringValue: @""];
144            [fDownloadedTotalField setStringValue: @""];
145            [fUploadedTotalField setStringValue: @""];
146        }
147       
148        [fImageView setImage: fAppIcon];
149       
150        [fNameField setToolTip: nil];
151
152        [fTrackerField setStringValue: @""];
153        [fTrackerField setToolTip: nil];
154        [fPiecesField setStringValue: @""];
155        [fHashField setStringValue: @""];
156        [fHashField setToolTip: nil];
157        [fCommentView setString: @""];
158       
159        [fCreatorField setStringValue: @""];
160        [fDateCreatedField setStringValue: @""];
161       
162        [fTorrentLocationField setStringValue: @""];
163        [fTorrentLocationField setToolTip: nil];
164        [fDataLocationField setStringValue: @""];
165        [fDataLocationField setToolTip: nil];
166        [fDateStartedField setStringValue: @""];
167       
168        [fRevealDataButton setHidden: YES];
169        [fRevealTorrentButton setHidden: YES];
170       
171        //don't allow empty fields to be selected
172        [fTrackerField setSelectable: NO];
173        [fHashField setSelectable: NO];
174        [fCreatorField setSelectable: NO];
175        [fTorrentLocationField setSelectable: NO];
176        [fDataLocationField setSelectable: NO];
177       
178        [fStateField setStringValue: @""];
179        [fRatioField setStringValue: @""];
180       
181        [fSeedersField setStringValue: @""];
182        [fLeechersField setStringValue: @""];
183        [fConnectedPeersField setStringValue: @""];
184        [fDownloadingFromField setStringValue: @""];
185        [fUploadingToField setStringValue: @""];
186        [fSwarmSpeedField setStringValue: @""];
187       
188        [fPeers removeAllObjects];
189        [fPeerTable reloadData];
190       
191        [fPiecesView setTorrent: nil];
192    }
193    else
194    {   
195        Torrent * torrent = [fTorrents objectAtIndex: 0];
196       
197        [fImageView setImage: [torrent icon]];
198       
199        NSString * name = [torrent name];
200        [fNameField setStringValue: name];
201        [fNameField setToolTip: name];
202        [fSizeField setStringValue: [NSString stringForFileSize: [torrent size]]];
203       
204        NSString * tracker = [[torrent tracker] stringByAppendingString: [torrent announce]],
205                * hashString = [torrent hashString],
206                * commentString = [torrent comment];
207        [fTrackerField setStringValue: tracker];
208        [fTrackerField setToolTip: tracker];
209        [fPiecesField setStringValue: [NSString stringWithFormat: @"%d, %@", [torrent pieceCount],
210                                        [NSString stringForFileSize: [torrent pieceSize]]]];
211        [fHashField setStringValue: hashString];
212        [fHashField setToolTip: hashString];
213        [fCommentView setString: commentString];
214       
215        [fCreatorField setStringValue: [torrent creator]];
216        [fDateCreatedField setObjectValue: [torrent dateCreated]];
217       
218        BOOL publicTorrent = [torrent publicTorrent];
219        [fTorrentLocationField setStringValue: publicTorrent
220                    ? [[torrent publicTorrentLocation] stringByAbbreviatingWithTildeInPath]
221                    : NSLocalizedString(@"Transmission Support Folder", "Torrent -> location when deleting original")];
222        if (publicTorrent)
223            [fTorrentLocationField setToolTip: [NSString stringWithFormat: @"%@\n\n%@",
224                        [torrent publicTorrentLocation], [torrent torrentLocation]]];
225        else
226            [fTorrentLocationField setToolTip: [torrent torrentLocation]];
227       
228        [fDateStartedField setObjectValue: [torrent date]];
229       
230        [fRevealDataButton setHidden: NO];
231        [fRevealTorrentButton setHidden: ![torrent publicTorrent]];
232       
233        //allow these fields to be selected
234        [fTrackerField setSelectable: YES];
235        [fHashField setSelectable: YES];
236        [fCommentView setSelectable: YES];
237        [fCreatorField setSelectable: YES];
238        [fTorrentLocationField setSelectable: YES];
239        [fDataLocationField setSelectable: YES];
240       
241        [fPiecesView setTorrent: torrent];
242    }
243   
244    //update stats and settings
245    [self updateInfoStats];
246    [self updateInfoSettings];
247
248    //set file table
249    [fFiles removeAllObjects];
250   
251    if (numberSelected > 0)
252    {
253        Torrent * torrent;
254        NSEnumerator * enumerator = [fTorrents objectEnumerator];
255        while ((torrent = [enumerator nextObject]))
256            [fFiles addObjectsFromArray: [torrent fileList]];
257       
258        if ([fFiles count] > 1)
259            [fFileTableStatusField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d files",
260                                        "Inspector -> Files tab -> bottom text (number of files)"), [fFiles count]]];
261        else
262            [fFileTableStatusField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d file",
263                                        "Inspector -> Files tab -> bottom text (number of files)"), [fFiles count]]];
264    }
265    else
266        [fFileTableStatusField setStringValue: NSLocalizedString(@"info not available",
267                                        "Inspector -> Files tab -> bottom text (number of files)")];
268   
269    [fFileTable deselectAll: nil];
270    [fFileTable reloadData];
271}
272
273- (void) updateInfoStats
274{
275    if ([[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_ACTIVITY_IDENT])
276        [self updateInfoActivity];
277    else if ([[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_PEERS_IDENT])
278        [self updateInfoPeers];
279    else;
280}
281
282- (void) updateInfoActivity
283{
284    int numberSelected = [fTorrents count];
285    if (numberSelected == 0)
286        return;
287   
288    float downloadedValid = 0;
289    uint64_t downloadedTotal = 0, uploadedTotal = 0;
290    Torrent * torrent;
291    NSEnumerator * enumerator = [fTorrents objectEnumerator];
292    while ((torrent = [enumerator nextObject]))
293    {
294        downloadedValid += [torrent downloadedValid];
295        downloadedTotal += [torrent downloadedTotal];
296        uploadedTotal += [torrent uploadedTotal];
297    }
298
299    [fDownloadedValidField setStringValue: [NSString stringForFileSize: downloadedValid]];
300    [fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
301    [fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
302   
303    if (numberSelected == 1)
304    {
305        torrent = [fTorrents objectAtIndex: 0];
306       
307        //append percentage to amount downloaded if 1 torrent
308        [fDownloadedValidField setStringValue: [[fDownloadedValidField stringValue]
309                                        stringByAppendingFormat: @" (%.2f%%)", 100.0 * [torrent progress]]];
310       
311        [fStateField setStringValue: [torrent stateString]];
312       
313        [fRatioField setStringValue: [NSString stringForRatioWithDownload: downloadedTotal upload: uploadedTotal]];
314       
315        [fSwarmSpeedField setStringValue: [torrent isActive] ? [NSString stringForSpeed: [torrent swarmSpeed]] : @""];
316       
317        [fPiecesView updateView: NO];
318    }
319}
320
321- (void) updateInfoPeers
322{
323    if ([fTorrents count] != 1)
324        return;
325    Torrent * torrent = [fTorrents objectAtIndex: 0];
326   
327    int seeders = [torrent seeders], leechers = [torrent leechers];
328    [fSeedersField setStringValue: seeders < 0 ? @"" : [NSString stringWithInt: seeders]];
329    [fLeechersField setStringValue: leechers < 0 ? @"" : [NSString stringWithInt: leechers]];
330   
331    BOOL active = [torrent isActive];
332    [fConnectedPeersField setStringValue: active ? [NSString stringWithFormat: NSLocalizedString(@"%d (%d incoming)",
333                                                                                "Inspector -> Peers tab -> connected"),
334                                                    [torrent totalPeers], [torrent totalPeersIncoming]]: @""];
335    [fDownloadingFromField setStringValue: active ? [NSString stringWithInt: [torrent peersUploading]] : @""];
336    [fUploadingToField setStringValue: active ? [NSString stringWithInt: [torrent peersDownloading]] : @""];
337   
338    [fPeers setArray: [torrent peers]];
339    [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
340   
341    [fPeerTable reloadData];
342}
343
344- (void) updateInfoSettings
345{
346    int numberSelected = [fTorrents count];
347
348    if (numberSelected > 0)
349    {
350        Torrent * torrent;
351       
352        if (numberSelected == 1)
353        {
354            torrent = [fTorrents objectAtIndex: 0];
355            [fDataLocationField setStringValue: [[torrent dataLocation] stringByAbbreviatingWithTildeInPath]];
356            [fDataLocationField setToolTip: [torrent dataLocation]];
357        }
358       
359        //set ratio settings
360        NSEnumerator * enumerator = [fTorrents objectEnumerator];
361        torrent = [enumerator nextObject]; //first torrent
362       
363        int ratioSetting = [torrent stopRatioSetting];
364        float ratioLimit = [torrent ratioLimit];
365       
366        while ((ratioSetting != INVALID || ratioLimit != INVALID)
367                && (torrent = [enumerator nextObject]))
368        {
369            if (ratioSetting != INVALID && ratioSetting != [torrent stopRatioSetting])
370                ratioSetting = INVALID;
371           
372            if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit])
373                ratioLimit = INVALID;
374        }
375       
376        [fRatioMatrix setEnabled: YES];
377       
378        if (ratioSetting == RATIO_CHECK)
379        {
380            [fRatioMatrix selectCellWithTag: RATIO_CHECK_TAG];
381            [fRatioLimitField setEnabled: YES];
382        }
383        else
384        {
385            if (ratioSetting == RATIO_NO_CHECK)
386                [fRatioMatrix selectCellWithTag: RATIO_NO_CHECK_TAG];
387            else if (ratioSetting == RATIO_GLOBAL)
388                [fRatioMatrix selectCellWithTag: RATIO_GLOBAL_TAG];
389            else
390                [fRatioMatrix deselectAllCells];
391           
392            [fRatioLimitField setEnabled: NO];
393        }
394       
395        if (ratioLimit != INVALID)
396            [fRatioLimitField setFloatValue: ratioLimit];
397        else
398            [fRatioLimitField setStringValue: @""];
399    }
400    else
401    {
402        [fRatioMatrix deselectAllCells];
403        [fRatioMatrix setEnabled: NO];
404       
405        [fRatioLimitField setEnabled: NO];
406        [fRatioLimitField setStringValue: @""];
407    }
408   
409    [self updateInfoStats];
410}
411
412- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
413{
414    SEL action = [menuItem action];
415   
416    if (action == @selector(revealFile:))
417        return [fFileTable numberOfSelectedRows] > 0 &&
418            [[[fTabView selectedTabViewItem] identifier] isEqualToString: TAB_FILES_IDENT];
419       
420    return YES;
421}
422
423- (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame
424{
425    NSRect windowRect = [window frame];
426    windowRect.size.width = [window minSize].width;   
427    return windowRect;
428}
429
430- (void) tabView: (NSTabView *) tabView didSelectTabViewItem: (NSTabViewItem *) tabViewItem
431{
432    NSString * identifier = [tabViewItem identifier];
433    [self setWindowForTab: identifier animate: YES];
434    [[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InfoTab"];
435}
436
437- (void) setWindowForTab: (NSString *) identifier animate: (BOOL) animate
438{
439    [self updateInfoStats];
440   
441    float height;
442    if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
443    {
444        height = TAB_ACTIVITY_HEIGHT;
445        [fPiecesView updateView: YES];
446    }
447    else if ([identifier isEqualToString: TAB_PEERS_IDENT])
448    {
449        height = TAB_PEERS_HEIGHT;
450    }
451    else if ([identifier isEqualToString: TAB_FILES_IDENT])
452        height = TAB_FILES_HEIGHT;
453    else if ([identifier isEqualToString: TAB_OPTIONS_IDENT])
454        height = TAB_OPTIONS_HEIGHT;
455    else
456        height = TAB_INFO_HEIGHT;
457   
458    NSWindow * window = [self window];
459    NSRect frame = [window frame];
460    NSView * view = [[fTabView selectedTabViewItem] view];
461   
462    float difference = height - [view frame].size.height;
463    frame.origin.y -= difference;
464    frame.size.height += difference;
465   
466    if (animate)
467    {
468        [view setHidden: YES];
469        [window setFrame: frame display: YES animate: YES];
470        [view setHidden: NO];
471    }
472    else
473        [window setFrame: frame display: YES];
474   
475    [window setMinSize: NSMakeSize(MIN_WINDOW_WIDTH, frame.size.height)];
476    [window setMaxSize: NSMakeSize(MAX_WINDOW_WIDTH, frame.size.height)];
477}
478
479- (void) setNextTab
480{
481    if ([fTabView indexOfTabViewItem: [fTabView selectedTabViewItem]] == [fTabView numberOfTabViewItems] - 1)
482        [fTabView selectFirstTabViewItem: nil];
483    else
484        [fTabView selectNextTabViewItem: nil];
485}
486
487- (void) setPreviousTab
488{
489    if ([fTabView indexOfTabViewItem: [fTabView selectedTabViewItem]] == 0)
490        [fTabView selectLastTabViewItem: nil];
491    else
492        [fTabView selectPreviousTabViewItem: nil];
493}
494
495- (int) numberOfRowsInTableView: (NSTableView *) tableView
496{
497    if (tableView == fPeerTable)
498        return [fPeers count];
499    else
500        return [fFiles count];
501}
502
503- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (int) row
504{
505    NSString * ident = [column identifier];
506    if (tableView == fPeerTable)
507    {
508        NSDictionary * peer = [fPeers objectAtIndex: row];
509       
510        if ([ident isEqualToString: @"Connected"])
511            return [[peer objectForKey: @"Connected"] boolValue] ? fDotGreen : fDotRed;
512        else if ([ident isEqualToString: @"Client"])
513            return [peer objectForKey: @"Client"];
514        else if  ([ident isEqualToString: @"Progress"])
515            return [peer objectForKey: @"Progress"];
516        else if ([ident isEqualToString: @"UL To"])
517            return [[peer objectForKey: @"UL To"] boolValue] ? fCheckImage : nil;
518        else if ([ident isEqualToString: @"DL From"])
519            return [[peer objectForKey: @"DL From"] boolValue] ? fCheckImage : nil;
520        else
521            return [peer objectForKey: @"IP"];
522    }
523    else
524    {
525        NSDictionary * file = [fFiles objectAtIndex: row];
526        if ([ident isEqualToString: @"Icon"])
527            return [[NSWorkspace sharedWorkspace] iconForFileType: [[file objectForKey: @"Name"] pathExtension]];
528        else if ([ident isEqualToString: @"Size"])
529            return [NSString stringForFileSize: [[file objectForKey: @"Size"] unsignedLongLongValue]];
530        else
531            return [[file objectForKey: @"Name"] lastPathComponent];
532    }
533}
534
535- (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn
536{
537    if (tableView == fPeerTable)
538    {
539        [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
540        [tableView reloadData];
541    }
542}
543
544- (BOOL) tableView: (NSTableView *) tableView shouldSelectRow:(int) row
545{
546    return tableView != fPeerTable;
547}
548
549- (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell
550        rect: (NSRectPointer) rect tableColumn: (NSTableColumn *) column
551        row: (int) row mouseLocation: (NSPoint) mouseLocation
552{
553    if (tableView == fFileTable)
554    {
555        NSDictionary * file = [fFiles objectAtIndex: row];
556        if ([[column identifier] isEqualToString: @"Size"])
557            return [[[file objectForKey: @"Size"] stringValue] stringByAppendingString: NSLocalizedString(@" bytes",
558                                                                        "Inspector -> Files tab -> table row tooltip")];
559        else
560            return [file objectForKey: @"Name"];
561    }
562    else if (tableView == fPeerTable)
563    {
564        if ([[column identifier] isEqualToString: @"Progress"])
565            return [NSString stringWithFormat: @"%.1f%%", [[[fPeers objectAtIndex: row]
566                                                objectForKey: @"Progress"] floatValue] * 100.0];
567        else
568        {
569            if ([[[fPeers objectAtIndex: row] objectForKey: @"Incoming"] boolValue])
570                return NSLocalizedString(@"From incoming connection", "Inspector -> Peers tab -> table row tooltip");
571            else
572                return NSLocalizedString(@"From outgoing connection", "Inspector -> Peers tab -> table row tooltip");
573        }
574    }
575    else
576        return nil;
577}
578
579- (NSArray *) peerSortDescriptors
580{
581    NSMutableArray * descriptors = [NSMutableArray array];
582   
583    NSArray * oldDescriptors = [fPeerTable sortDescriptors];
584    if ([oldDescriptors count] > 0)
585        [descriptors addObject: [oldDescriptors objectAtIndex: 0]];
586   
587    [descriptors addObject: [[fPeerTable tableColumnWithIdentifier: @"IP"] sortDescriptorPrototype]];
588   
589    return descriptors;
590}
591
592- (void) revealTorrentFile: (id) sender
593{
594    if ([fTorrents count] > 0)
595        [[fTorrents objectAtIndex: 0] revealPublicTorrent];
596}
597
598- (void) revealDataFile: (id) sender
599{
600    if ([fTorrents count] > 0)
601        [[fTorrents objectAtIndex: 0] revealData];
602}
603
604- (void) revealFile: (id) sender
605{
606    NSIndexSet * indexSet = [fFileTable selectedRowIndexes];
607    unsigned int i;
608    for (i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
609        [[NSWorkspace sharedWorkspace] selectFile: [[fFiles objectAtIndex: i] objectForKey: @"Name"]
610                                        inFileViewerRootedAtPath: nil];
611}
612
613- (void) setRatioCheck: (id) sender
614{
615    int ratioSetting, tag = [[fRatioMatrix selectedCell] tag];
616    if (tag == RATIO_CHECK_TAG)
617        ratioSetting = RATIO_CHECK;
618    else if (tag == RATIO_NO_CHECK_TAG)
619        ratioSetting = RATIO_NO_CHECK;
620    else
621        ratioSetting = RATIO_GLOBAL;
622
623    Torrent * torrent;
624    NSEnumerator * enumerator = [fTorrents objectEnumerator];
625    while ((torrent = [enumerator nextObject]))
626        [torrent setStopRatioSetting: ratioSetting];
627   
628    [self setRatioLimit: fRatioLimitField];
629    [fRatioLimitField setEnabled: tag == RATIO_CHECK_TAG];
630}
631
632- (void) setRatioLimit: (id) sender
633{
634    Torrent * torrent;
635    NSEnumerator * enumerator = [fTorrents objectEnumerator];
636
637    float ratioLimit = [sender floatValue];
638    if (![[sender stringValue] isEqualToString: [NSString stringWithFormat: @"%.2f", ratioLimit]] || ratioLimit < 0)
639    {
640        NSBeep();
641        float ratioLimit = [[enumerator nextObject] ratioLimit]; //use first torrent
642        while ((torrent = [enumerator nextObject]))
643            if (ratioLimit != [torrent ratioLimit])
644            {
645                [sender setStringValue: @""];
646                return;
647            }
648       
649        [sender setFloatValue: ratioLimit];
650    }
651    else
652    {
653        while ((torrent = [enumerator nextObject]))
654            [torrent setRatioLimit: ratioLimit];
655    }
656}
657
658@end
Note: See TracBrowser for help on using the repository browser.