source: branches/multitracker/macosx/InfoWindowController.m @ 1154

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

initial support for announce-list (currently crashes when a tracker fails)

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