source: trunk/macosx/InfoWindowController.m @ 1121

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

small adjustments to inspector and check for utf-8 strings

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