source: trunk/macosx/InfoWindowController.m @ 1123

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

combine pieces and piece size in inspector

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