source: trunk/macosx/InfoWindowController.m @ 10131

Last change on this file since 10131 was 10131, checked in by livings124, 12 years ago

a couple more tweaks to displaying peers and webseeds

  • Property svn:keywords set to Date Rev Author Id
File size: 68.1 KB
Line 
1/******************************************************************************
2 * $Id: InfoWindowController.m 10131 2010-02-07 17:37:01Z livings124 $
3 *
4 * Copyright (c) 2006-2010 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 "FileListNode.h"
27#import "FileOutlineController.h"
28#import "FileOutlineView.h"
29#import "InfoTabButtonCell.h"
30#import "NSApplicationAdditions.h"
31#import "NSStringAdditions.h"
32#import "PeerProgressIndicatorCell.h"
33#import "PiecesView.h"
34#import "Torrent.h"
35#import "TrackerCell.h"
36#import "TrackerNode.h"
37#import "TrackerTableView.h"
38#include "utils.h" //tr_getRatio()
39
40#define TAB_INFO_IDENT @"Info"
41#define TAB_ACTIVITY_IDENT @"Activity"
42#define TAB_TRACKER_IDENT @"Tracker"
43#define TAB_PEERS_IDENT @"Peers"
44#define TAB_FILES_IDENT @"Files"
45#define TAB_OPTIONS_IDENT @"Options"
46
47#define TAB_MIN_HEIGHT 250
48
49#define TRACKER_GROUP_SEPARATOR_HEIGHT 14.0
50
51#define PIECES_CONTROL_PROGRESS 0
52#define PIECES_CONTROL_AVAILABLE 1
53
54#define OPTION_POPUP_GLOBAL 0
55#define OPTION_POPUP_NO_LIMIT 1
56#define OPTION_POPUP_LIMIT 2
57
58#define OPTION_POPUP_PRIORITY_HIGH 0
59#define OPTION_POPUP_PRIORITY_NORMAL 1
60#define OPTION_POPUP_PRIORITY_LOW 2
61
62#define INVALID -99
63
64#define TRACKER_ADD_TAG 0
65#define TRACKER_REMOVE_TAG 1
66
67typedef enum
68{
69    TAB_INFO_TAG = 0,
70    TAB_ACTIVITY_TAG = 1,
71    TAB_TRACKER_TAG = 2,
72    TAB_PEERS_TAG = 3,
73    TAB_FILES_TAG = 4,
74    TAB_OPTIONS_TAG = 5
75} tabTag;
76
77@interface InfoWindowController (Private)
78
79- (void) resetInfo;
80- (void) resetInfoForTorrent: (NSNotification *) notification;
81
82- (void) updateInfoGeneral;
83- (void) updateInfoActivity;
84- (void) updateInfoTracker;
85- (void) updateInfoPeers;
86- (void) updateInfoFiles;
87
88- (NSView *) tabViewForTag: (NSInteger) tag;
89- (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate;
90- (NSArray *) peerSortDescriptors;
91
92- (BOOL) canQuickLookFile: (FileListNode *) item;
93
94- (void) addTrackers;
95- (void) removeTrackers;
96
97@end
98
99@implementation InfoWindowController
100
101- (id) init
102{
103    if ((self = [super initWithWindowNibName: @"InfoWindow"]))
104    {
105        fTrackerCell = [[TrackerCell alloc] init];
106    }
107   
108    return self;
109}
110
111- (void) awakeFromNib
112{
113    //window location and size
114    NSPanel * window = (NSPanel *)[self window];
115   
116    CGFloat windowHeight = [window frame].size.height;
117   
118    [window setFrameAutosaveName: @"InspectorWindow"];
119    [window setFrameUsingName: @"InspectorWindow"];
120   
121    NSRect windowRect = [window frame];
122    windowRect.origin.y -= windowHeight - windowRect.size.height;
123    windowRect.size.height = windowHeight;
124    [window setFrame: windowRect display: NO];
125   
126    [window setBecomesKeyOnlyIfNeeded: YES];
127   
128    //set tab images and tooltips
129    [[fTabMatrix cellWithTag: TAB_INFO_TAG] setIcon: [NSImage imageNamed: @"InfoGeneral.png"]];
130    [[fTabMatrix cellWithTag: TAB_ACTIVITY_TAG] setIcon: [NSImage imageNamed: @"InfoActivity.png"]];
131    [[fTabMatrix cellWithTag: TAB_TRACKER_TAG] setIcon: [NSImage imageNamed: @"InfoTracker.png"]];
132    [[fTabMatrix cellWithTag: TAB_PEERS_TAG] setIcon: [NSImage imageNamed: @"InfoPeers.png"]];
133    [[fTabMatrix cellWithTag: TAB_FILES_TAG] setIcon: [NSImage imageNamed: @"InfoFiles.png"]];
134    [[fTabMatrix cellWithTag: TAB_OPTIONS_TAG] setIcon: [NSImage imageNamed: @"InfoOptions.png"]];
135   
136    //set selected tab
137    fCurrentTabTag = INVALID;
138    NSString * identifier = [[NSUserDefaults standardUserDefaults] stringForKey: @"InspectorSelected"];
139    NSInteger tag;
140    if ([identifier isEqualToString: TAB_INFO_IDENT])
141        tag = TAB_INFO_TAG;
142    else if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
143        tag = TAB_ACTIVITY_TAG;
144    else if ([identifier isEqualToString: TAB_TRACKER_IDENT])
145        tag = TAB_TRACKER_TAG;
146    else if ([identifier isEqualToString: TAB_PEERS_IDENT])
147        tag = TAB_PEERS_TAG;
148    else if ([identifier isEqualToString: TAB_FILES_IDENT])
149        tag = TAB_FILES_TAG;
150    else if ([identifier isEqualToString: TAB_OPTIONS_IDENT])
151        tag = TAB_OPTIONS_TAG;
152    else //safety
153    {
154        [[NSUserDefaults standardUserDefaults] setObject: TAB_INFO_IDENT forKey: @"InspectorSelected"];
155        tag = TAB_INFO_TAG;
156    }
157    [fTabMatrix selectCellWithTag: tag];
158    [self setTab: nil];
159   
160    if (![NSApp isOnSnowLeopardOrBetter])
161    {
162        //reset images for reveal button, since the images are also used in the main table
163        NSImage * revealOn = [[NSImage imageNamed: @"RevealOn.png"] copy],
164                * revealOff = [[NSImage imageNamed: @"RevealOff.png"] copy];
165       
166        [revealOn setFlipped: NO];
167        [revealOff setFlipped: NO];
168       
169        [fRevealDataButton setImage: revealOff];
170        [fRevealDataButton setAlternateImage: revealOn];
171       
172        [revealOn release];
173        [revealOff release];
174    }
175   
176    //initially sort peer table by IP
177    if ([[fPeerTable sortDescriptors] count] == 0)
178        [fPeerTable setSortDescriptors: [NSArray arrayWithObject: [[fPeerTable tableColumnWithIdentifier: @"IP"]
179                                            sortDescriptorPrototype]]];
180   
181    //initially sort webseed table by address
182    if ([[fWebSeedTable sortDescriptors] count] == 0)
183        [fWebSeedTable setSortDescriptors: [NSArray arrayWithObject: [[fWebSeedTable tableColumnWithIdentifier: @"Address"]
184                                            sortDescriptorPrototype]]];
185   
186    //set table header tool tips
187    [[fPeerTable tableColumnWithIdentifier: @"Encryption"] setHeaderToolTip: NSLocalizedString(@"Encrypted Connection",
188                                                                        "inspector -> peer table -> header tool tip")];
189    [[fPeerTable tableColumnWithIdentifier: @"Progress"] setHeaderToolTip: NSLocalizedString(@"Available",
190                                                                        "inspector -> peer table -> header tool tip")];
191    [[fPeerTable tableColumnWithIdentifier: @"UL To"] setHeaderToolTip: NSLocalizedString(@"Uploading To Peer",
192                                                                        "inspector -> peer table -> header tool tip")];
193    [[fPeerTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Peer",
194                                                                        "inspector -> peer table -> header tool tip")];
195   
196    [[fWebSeedTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Web Seed",
197                                                                        "inspector -> web seed table -> header tool tip")];
198   
199    //prepare for animating peer table and web seed table
200    NSRect webSeedTableFrame = [[fWebSeedTable enclosingScrollView] frame];
201    fWebSeedTableHeight = webSeedTableFrame.size.height;
202    fSpaceBetweenWebSeedAndPeer = webSeedTableFrame.origin.y - NSMaxY([[fPeerTable enclosingScrollView] frame]);
203   
204    [self setWebSeedTableHidden: YES animate: NO];
205   
206    //set blank inspector
207    [self setInfoForTorrents: [NSArray array]];
208   
209    //allow for update notifications
210    NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
211    [nc addObserver: self selector: @selector(resetInfoForTorrent:) name: @"ResetInspector" object: nil];
212    [nc addObserver: self selector: @selector(updateInfoStats) name: @"UpdateStats" object: nil];
213    [nc addObserver: self selector: @selector(updateOptions) name: @"UpdateOptions" object: nil];
214}
215
216- (void) dealloc
217{
218    //save resizeable view height
219    NSString * resizeSaveKey = nil;
220    switch (fCurrentTabTag)
221    {
222        case TAB_TRACKER_TAG:
223            resizeSaveKey = @"InspectorContentHeightTracker";
224            break;
225        case TAB_PEERS_TAG:
226            resizeSaveKey = @"InspectorContentHeightPeers";
227            break;
228        case TAB_FILES_TAG:
229            resizeSaveKey = @"InspectorContentHeightFiles";
230            break;
231    }
232    if (resizeSaveKey)
233        [[NSUserDefaults standardUserDefaults] setFloat: [[self tabViewForTag: fCurrentTabTag] frame].size.height forKey: resizeSaveKey];
234   
235    [[NSNotificationCenter defaultCenter] removeObserver: self];
236   
237    [fTorrents release];
238    [fPeers release];
239    [fWebSeeds release];
240    [fTrackers release];
241   
242    [fWebSeedTableAnimation release];
243   
244    [fTrackerCell release];
245   
246    [fPreviewPanel release];
247   
248    [super dealloc];
249}
250
251- (void) setInfoForTorrents: (NSArray *) torrents
252{
253    if (fTorrents && [fTorrents isEqualToArray: torrents])
254        return;
255   
256    [fTorrents release];
257    fTorrents = [torrents retain];
258   
259    [self resetInfo];
260}
261
262- (void) updateInfoStats
263{
264    switch ([fTabMatrix selectedTag])
265    {
266        case TAB_INFO_TAG:
267            [self updateInfoGeneral];
268            break;
269        case TAB_ACTIVITY_TAG:
270            [self updateInfoActivity];
271            break;
272        case TAB_TRACKER_TAG:
273            [self updateInfoTracker];
274            break;
275        case TAB_PEERS_TAG:
276            [self updateInfoPeers];
277            break;
278        case TAB_FILES_TAG:
279            [self updateInfoFiles];
280            break;
281    }
282}
283
284- (void) updateOptions
285{
286    if ([fTorrents count] == 0)
287        return;
288   
289    //get bandwidth info
290    NSEnumerator * enumerator = [fTorrents objectEnumerator];
291    Torrent * torrent = [enumerator nextObject]; //first torrent
292   
293    NSInteger uploadUseSpeedLimit = [torrent usesSpeedLimit: YES] ? NSOnState : NSOffState,
294                uploadSpeedLimit = [torrent speedLimit: YES],
295                downloadUseSpeedLimit = [torrent usesSpeedLimit: NO] ? NSOnState : NSOffState,
296                downloadSpeedLimit = [torrent speedLimit: NO],
297                globalUseSpeedLimit = [torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState;
298   
299    while ((torrent = [enumerator nextObject])
300            && (uploadUseSpeedLimit != NSMixedState || uploadSpeedLimit != INVALID
301                || downloadUseSpeedLimit != NSMixedState || downloadSpeedLimit != INVALID
302                || globalUseSpeedLimit != NSMixedState))
303    {
304        if (uploadUseSpeedLimit != NSMixedState && uploadUseSpeedLimit != ([torrent usesSpeedLimit: YES] ? NSOnState : NSOffState))
305            uploadUseSpeedLimit = NSMixedState;
306       
307        if (uploadSpeedLimit != INVALID && uploadSpeedLimit != [torrent speedLimit: YES])
308            uploadSpeedLimit = INVALID;
309       
310        if (downloadUseSpeedLimit != NSMixedState && downloadUseSpeedLimit != ([torrent usesSpeedLimit: NO] ? NSOnState : NSOffState))
311            downloadUseSpeedLimit = NSMixedState;
312       
313        if (downloadSpeedLimit != INVALID && downloadSpeedLimit != [torrent speedLimit: NO])
314            downloadSpeedLimit = INVALID;
315       
316        if (globalUseSpeedLimit != NSMixedState && globalUseSpeedLimit != ([torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState))
317            globalUseSpeedLimit = NSMixedState;
318    }
319   
320    //set upload view
321    [fUploadLimitCheck setState: uploadUseSpeedLimit];
322    [fUploadLimitCheck setEnabled: YES];
323   
324    [fUploadLimitLabel setEnabled: uploadUseSpeedLimit == NSOnState];
325    [fUploadLimitField setEnabled: uploadUseSpeedLimit == NSOnState];
326    if (uploadSpeedLimit != INVALID)
327        [fUploadLimitField setIntValue: uploadSpeedLimit];
328    else
329        [fUploadLimitField setStringValue: @""];
330   
331    //set download view
332    [fDownloadLimitCheck setState: downloadUseSpeedLimit];
333    [fDownloadLimitCheck setEnabled: YES];
334   
335    [fDownloadLimitLabel setEnabled: downloadUseSpeedLimit == NSOnState];
336    [fDownloadLimitField setEnabled: downloadUseSpeedLimit == NSOnState];
337    if (downloadSpeedLimit != INVALID)
338        [fDownloadLimitField setIntValue: downloadSpeedLimit];
339    else
340        [fDownloadLimitField setStringValue: @""];
341   
342    //set global check
343    [fGlobalLimitCheck setState: globalUseSpeedLimit];
344    [fGlobalLimitCheck setEnabled: YES];
345   
346    //get ratio info
347    enumerator = [fTorrents objectEnumerator];
348    torrent = [enumerator nextObject]; //first torrent
349   
350    NSInteger checkRatio = [torrent ratioSetting];
351    CGFloat ratioLimit = [torrent ratioLimit];
352   
353    while ((torrent = [enumerator nextObject]) && (checkRatio != INVALID || ratioLimit != INVALID))
354    {
355        if (checkRatio != INVALID && checkRatio != [torrent ratioSetting])
356            checkRatio = INVALID;
357       
358        if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit])
359            ratioLimit = INVALID;
360    }
361   
362    //set ratio view
363    NSInteger index;
364    if (checkRatio == TR_RATIOLIMIT_SINGLE)
365        index = OPTION_POPUP_LIMIT;
366    else if (checkRatio == TR_RATIOLIMIT_UNLIMITED)
367        index = OPTION_POPUP_NO_LIMIT;
368    else if (checkRatio == TR_RATIOLIMIT_GLOBAL)
369        index = OPTION_POPUP_GLOBAL;
370    else
371        index = -1;
372    [fRatioPopUp selectItemAtIndex: index];
373    [fRatioPopUp setEnabled: YES];
374   
375    [fRatioLimitField setHidden: checkRatio != TR_RATIOLIMIT_SINGLE];
376    if (ratioLimit != INVALID)
377        [fRatioLimitField setFloatValue: ratioLimit];
378    else
379        [fRatioLimitField setStringValue: @""];
380   
381    //get priority info
382    enumerator = [fTorrents objectEnumerator];
383    torrent = [enumerator nextObject]; //first torrent
384   
385    NSInteger priority = [torrent priority];
386   
387    while ((torrent = [enumerator nextObject]) && priority != INVALID)
388    {
389        if (priority != INVALID && priority != [torrent priority])
390            priority = INVALID;
391    }
392   
393    //set priority view
394    if (priority == TR_PRI_HIGH)
395        index = OPTION_POPUP_PRIORITY_HIGH;
396    else if (priority == TR_PRI_NORMAL)
397        index = OPTION_POPUP_PRIORITY_NORMAL;
398    else if (priority == TR_PRI_LOW)
399        index = OPTION_POPUP_PRIORITY_LOW;
400    else
401        index = -1;
402    [fPriorityPopUp selectItemAtIndex: index];
403    [fPriorityPopUp setEnabled: YES];
404   
405    //get peer info
406    enumerator = [fTorrents objectEnumerator];
407    torrent = [enumerator nextObject]; //first torrent
408   
409    NSInteger maxPeers = [torrent maxPeerConnect];
410   
411    while ((torrent = [enumerator nextObject]))
412    {
413        if (maxPeers != [torrent maxPeerConnect])
414        {
415            maxPeers = INVALID;
416            break;
417        }
418    }
419   
420    //set peer view
421    [fPeersConnectField setEnabled: YES];
422    [fPeersConnectLabel setEnabled: YES];
423    if (maxPeers != INVALID)
424        [fPeersConnectField setIntValue: maxPeers];
425    else
426        [fPeersConnectField setStringValue: @""];
427}
428
429- (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame
430{
431    NSRect windowRect = [window frame];
432    windowRect.size.width = [window minSize].width;
433    return windowRect;
434}
435
436- (void) animationDidEnd: (NSAnimation *) animation
437{
438    if (animation == fWebSeedTableAnimation)
439    {
440        [fWebSeedTableAnimation release];
441        fWebSeedTableAnimation = nil;
442    }
443}
444
445- (NSSize) windowWillResize: (NSWindow *) window toSize: (NSSize) proposedFrameSize
446{
447    //this is an edge-case - just stop the animation (stopAnimation jumps to end frame)
448    if (fWebSeedTableAnimation)
449    {
450        [fWebSeedTableAnimation stopAnimation];
451        [fWebSeedTableAnimation release];
452        fWebSeedTableAnimation = nil;
453    }
454   
455    return proposedFrameSize;
456}
457
458- (void) windowWillClose: (NSNotification *) notification
459{
460    if ([NSApp isOnSnowLeopardOrBetter] && fCurrentTabTag == TAB_FILES_TAG
461        && ([QLPreviewPanelSL sharedPreviewPanelExists] && [[QLPreviewPanelSL sharedPreviewPanel] isVisible]))
462        [[QLPreviewPanelSL sharedPreviewPanel] reloadData];
463}
464
465- (void) setTab: (id) sender
466{
467    const NSInteger oldTabTag = fCurrentTabTag;
468    fCurrentTabTag = [fTabMatrix selectedTag];
469    if (fCurrentTabTag == oldTabTag)
470        return;
471   
472    [self updateInfoStats];
473   
474    //take care of old view
475    CGFloat oldHeight = 0;
476    NSString * oldResizeSaveKey = nil;
477    if (oldTabTag != INVALID)
478    {
479        //deselect old tab item
480        [(InfoTabButtonCell *)[fTabMatrix cellWithTag: oldTabTag] setSelectedTab: NO];
481       
482        switch (oldTabTag)
483        {
484            case TAB_ACTIVITY_TAG:
485                [fPiecesView clearView];
486                break;
487           
488            case TAB_TRACKER_TAG:
489                [fTrackers release];
490                fTrackers = nil;
491               
492                oldResizeSaveKey = @"InspectorContentHeightTracker";
493                break;
494           
495            case TAB_PEERS_TAG:
496                //if in the middle of animating, just stop and resize immediately
497                if (fWebSeedTableAnimation)
498                    [self setWebSeedTableHidden: !fWebSeeds animate: NO];
499               
500                [fPeers release];
501                fPeers = nil;
502                [fWebSeeds release];
503                fWebSeeds = nil;
504               
505                oldResizeSaveKey = @"InspectorContentHeightPeers";
506                break;
507           
508            case TAB_FILES_TAG:
509                oldResizeSaveKey = @"InspectorContentHeightFiles";
510                break;
511        }
512       
513        NSView * oldView = [self tabViewForTag: oldTabTag];
514        oldHeight = [oldView frame].size.height;
515        if (oldResizeSaveKey)
516            [[NSUserDefaults standardUserDefaults] setFloat: oldHeight forKey: oldResizeSaveKey];
517       
518        //remove old view
519        [oldView setHidden: YES];
520        [oldView removeFromSuperview];
521    }
522   
523    //set new tab item
524    NSView * view = [self tabViewForTag: fCurrentTabTag];
525   
526    NSString * resizeSaveKey = nil;
527    NSString * identifier, * title;
528    switch (fCurrentTabTag)
529    {
530        case TAB_INFO_TAG:
531            identifier = TAB_INFO_IDENT;
532            title = NSLocalizedString(@"General Info", "Inspector -> title");
533            break;
534        case TAB_ACTIVITY_TAG:
535            identifier = TAB_ACTIVITY_IDENT;
536            title = NSLocalizedString(@"Activity", "Inspector -> title");
537            break;
538        case TAB_TRACKER_TAG:
539            identifier = TAB_TRACKER_IDENT;
540            title = NSLocalizedString(@"Trackers", "Inspector -> title");
541            resizeSaveKey = @"InspectorContentHeightTracker";
542            break;
543        case TAB_PEERS_TAG:
544            identifier = TAB_PEERS_IDENT;
545            title = NSLocalizedString(@"Peers", "Inspector -> title");
546            resizeSaveKey = @"InspectorContentHeightPeers";
547            break;
548        case TAB_FILES_TAG:
549            identifier = TAB_FILES_IDENT;
550            title = NSLocalizedString(@"Files", "Inspector -> title");
551            resizeSaveKey = @"InspectorContentHeightFiles";
552            break;
553        case TAB_OPTIONS_TAG:
554            identifier = TAB_OPTIONS_IDENT;
555            title = NSLocalizedString(@"Options", "Inspector -> title");
556            break;
557        default:
558            NSAssert1(NO, @"Unknown info tab selected: %d", fCurrentTabTag);
559            return;
560    }
561   
562    [[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InspectorSelected"];
563   
564    NSWindow * window = [self window];
565   
566    [window setTitle: [NSString stringWithFormat: @"%@ - %@", title, NSLocalizedString(@"Torrent Inspector", "Inspector -> title")]];
567   
568    //selected tab item
569    [(InfoTabButtonCell *)[fTabMatrix selectedCell] setSelectedTab: YES];
570   
571    NSRect windowRect = [window frame], viewRect = [view frame];
572   
573    if (resizeSaveKey)
574    {
575        CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: resizeSaveKey];
576        if (height != 0.0)
577            viewRect.size.height = MAX(height, TAB_MIN_HEIGHT);
578    }
579   
580    CGFloat difference = (viewRect.size.height - oldHeight) * [window userSpaceScaleFactor];
581    windowRect.origin.y -= difference;
582    windowRect.size.height += difference;
583   
584    if (resizeSaveKey)
585    {
586        if (!oldResizeSaveKey)
587        {
588            [window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height - viewRect.size.height + TAB_MIN_HEIGHT)];
589            [window setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
590        }
591    }
592    else
593    {
594        [window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height)];
595        [window setMaxSize: NSMakeSize(FLT_MAX, windowRect.size.height)];
596    }
597   
598    viewRect.size.width = windowRect.size.width;
599    [view setFrame: viewRect];
600   
601    [window setFrame: windowRect display: YES animate: oldTabTag != INVALID];
602    [[window contentView] addSubview: view];
603    [view setHidden: NO];
604   
605    if ([NSApp isOnSnowLeopardOrBetter] && (fCurrentTabTag == TAB_FILES_TAG || oldTabTag == TAB_FILES_TAG)
606        && ([QLPreviewPanelSL sharedPreviewPanelExists] && [[QLPreviewPanelSL sharedPreviewPanel] isVisible]))
607        [[QLPreviewPanelSL sharedPreviewPanel] reloadData];
608}
609
610- (void) setNextTab
611{
612    NSInteger tag = [fTabMatrix selectedTag]+1;
613    if (tag >= [fTabMatrix numberOfColumns])
614        tag = 0;
615   
616    [fTabMatrix selectCellWithTag: tag];
617    [self setTab: nil];
618}
619
620- (void) setPreviousTab
621{
622    NSInteger tag = [fTabMatrix selectedTag]-1;
623    if (tag < 0)
624        tag = [fTabMatrix numberOfColumns]-1;
625   
626    [fTabMatrix selectCellWithTag: tag];
627    [self setTab: nil];
628}
629
630- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView
631{
632    if (tableView == fPeerTable)
633        return fPeers ? [fPeers count] : 0;
634    else if (tableView == fWebSeedTable)
635        return fWebSeeds ? [fWebSeeds count] : 0;
636    else if (tableView == fTrackerTable)
637        return fTrackers ? [fTrackers count] : 0;
638    return 0;
639}
640
641- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (NSInteger) row
642{
643    if (tableView == fPeerTable)
644    {
645        NSString * ident = [column identifier];
646        NSDictionary * peer = [fPeers objectAtIndex: row];
647       
648        if ([ident isEqualToString: @"Encryption"])
649            return [[peer objectForKey: @"Encryption"] boolValue] ? [NSImage imageNamed: @"Lock.png"] : nil;
650        else if ([ident isEqualToString: @"Client"])
651            return [peer objectForKey: @"Client"];
652        else if  ([ident isEqualToString: @"Progress"])
653            return [peer objectForKey: @"Progress"];
654        else if ([ident isEqualToString: @"UL To"])
655        {
656            NSNumber * rate;
657            return (rate = [peer objectForKey: @"UL To Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
658        }
659        else if ([ident isEqualToString: @"DL From"])
660        {
661            NSNumber * rate;
662            return (rate = [peer objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
663        }
664        else
665            return [peer objectForKey: @"IP"];
666    }
667    else if (tableView == fWebSeedTable)
668    {
669        NSString * ident = [column identifier];
670        NSDictionary * webSeed = [fWebSeeds objectAtIndex: row];
671       
672        if ([ident isEqualToString: @"DL From"])
673        {
674            NSNumber * rate;
675            return (rate = [webSeed objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
676        }
677        else
678            return [webSeed objectForKey: @"Address"];
679    }
680    else if (tableView == fTrackerTable)
681    {
682        id item = [fTrackers objectAtIndex: row];
683       
684        if (![item isKindOfClass: [TrackerNode class]])
685        {
686            NSString * tierString = [NSString stringWithFormat: NSLocalizedString(@"Tier %d", "Inspector -> tracker table"),
687                                        [[item objectForKey: @"Tier"] integerValue]];
688            if ([fTorrents count] > 1)
689                tierString = [tierString stringByAppendingFormat: @" - %@", [item objectForKey: @"Name"]];
690            return tierString;
691        }
692        else
693            return item;
694    }
695    return nil;
696}
697
698- (NSCell *) tableView: (NSTableView *) tableView dataCellForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
699{
700    if (tableView == fTrackerTable)
701    {
702        const BOOL tracker = [[fTrackers objectAtIndex: row] isKindOfClass: [TrackerNode class]];
703        return tracker ? fTrackerCell : [tableColumn dataCellForRow: row];
704    }
705   
706    return nil;
707}
708
709- (CGFloat) tableView: (NSTableView *) tableView heightOfRow: (NSInteger) row
710{
711    if (tableView == fTrackerTable)
712    {
713        if (![[fTrackers objectAtIndex: row] isKindOfClass: [TrackerNode class]] && [tableView editedRow] != row)
714            return TRACKER_GROUP_SEPARATOR_HEIGHT;
715    }
716   
717    return [tableView rowHeight];
718}
719
720- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn
721    row: (NSInteger) row
722{
723    if (tableView == fPeerTable)
724    {
725        NSString * ident = [tableColumn identifier];
726       
727        if  ([ident isEqualToString: @"Progress"])
728        {
729            NSDictionary * peer = [fPeers objectAtIndex: row];
730            [(PeerProgressIndicatorCell *)cell setSeed: [[peer objectForKey: @"Seed"] boolValue]];
731        }
732    }
733}
734
735- (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn
736{
737    if (tableView == fPeerTable)
738    {
739        if (fPeers)
740        {
741            [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
742            [tableView reloadData];
743        }
744    }
745    else if (tableView == fWebSeedTable)
746    {
747        if (fWebSeeds)
748        {
749            [fWebSeeds sortUsingDescriptors: [fWebSeedTable sortDescriptors]];
750            [tableView reloadData];
751        }
752    }
753    else;
754}
755
756- (BOOL) tableView: (NSTableView *) tableView shouldSelectRow: (NSInteger) row
757{
758    return tableView == fTrackerTable;
759}
760
761- (void) tableViewSelectionDidChange: (NSNotification *) notification
762{
763    if ([notification object] == fTrackerTable)
764        [fTrackerAddRemoveControl setEnabled: [fTorrents count] == 1 && [fTrackerTable numberOfSelectedRows] > 0
765            forSegment: TRACKER_REMOVE_TAG];
766}
767
768- (BOOL) tableView: (NSTableView *) tableView isGroupRow: (NSInteger) row
769{
770    if (tableView == fTrackerTable)
771        return ![[fTrackers objectAtIndex: row] isKindOfClass: [TrackerNode class]] && [tableView editedRow] != row;
772    return NO;
773}
774
775- (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
776                tableColumn: (NSTableColumn *) column row: (NSInteger) row mouseLocation: (NSPoint) mouseLocation
777{
778    if (tableView == fPeerTable)
779    {
780        const BOOL multiple = [fTorrents count] > 1;
781       
782        NSDictionary * peer = [fPeers objectAtIndex: row];
783        NSMutableArray * components = [NSMutableArray arrayWithCapacity: multiple ? 6 : 5];
784       
785        if (multiple)
786            [components addObject: [peer objectForKey: @"Name"]];
787       
788        const CGFloat progress = [[peer objectForKey: @"Progress"] floatValue];
789        NSString * progressString = [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%",
790                                        "Inspector -> Peers tab -> table row tooltip"), progress * 100.0];
791        if (progress < 1.0 && [[peer objectForKey: @"Seed"] boolValue])
792            progressString = [progressString stringByAppendingFormat: @" (%@)", NSLocalizedString(@"Partial Seed",
793                                "Inspector -> Peers tab -> table row tooltip")];
794        [components addObject: progressString];
795       
796        if ([[peer objectForKey: @"Encryption"] boolValue])
797            [components addObject: NSLocalizedString(@"Encrypted Connection", "Inspector -> Peers tab -> table row tooltip")];
798       
799        NSString * portString;
800        NSInteger port;
801        if ((port = [[peer objectForKey: @"Port"] intValue]) > 0)
802            portString = [NSString stringWithFormat: @"%d", port];
803        else
804            portString = NSLocalizedString(@"N/A", "Inspector -> Peers tab -> table row tooltip");
805        [components addObject: [NSString stringWithFormat: @"%@: %@", NSLocalizedString(@"Port",
806            "Inspector -> Peers tab -> table row tooltip"), portString]];
807       
808        const NSInteger peerFrom = [[peer objectForKey: @"From"] integerValue];
809        switch (peerFrom)
810        {
811            case TR_PEER_FROM_TRACKER:
812                [components addObject: NSLocalizedString(@"From: tracker", "Inspector -> Peers tab -> table row tooltip")];
813                break;
814            case TR_PEER_FROM_INCOMING:
815                [components addObject: NSLocalizedString(@"From: incoming connection", "Inspector -> Peers tab -> table row tooltip")];
816                break;
817            case TR_PEER_FROM_RESUME:
818                [components addObject: NSLocalizedString(@"From: cache", "Inspector -> Peers tab -> table row tooltip")];
819                break;
820            case TR_PEER_FROM_PEX:
821                [components addObject: NSLocalizedString(@"From: peer exchange", "Inspector -> Peers tab -> table row tooltip")];
822                break;
823            case TR_PEER_FROM_DHT:
824                [components addObject: NSLocalizedString(@"From: distributed hash table", "Inspector -> Peers tab -> table row tooltip")];
825                break;
826            case TR_PEER_FROM_LTEP:
827                [components addObject: NSLocalizedString(@"From: libtorrent extension protocol handshake",
828                                        "Inspector -> Peers tab -> table row tooltip")];
829                break;
830            default:
831                NSAssert1(NO, @"Peer from unknown source: %d", peerFrom);
832        }
833       
834        //determing status strings from flags
835        NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 6];
836        NSString * flags = [peer objectForKey: @"Flags"];
837       
838        if ([flags rangeOfString: @"D"].location != NSNotFound)
839            [statusArray addObject: NSLocalizedString(@"Currently downloading (interested and not choked)",
840                "Inspector -> peer -> status")];
841        if ([flags rangeOfString: @"d"].location != NSNotFound)
842            [statusArray addObject: NSLocalizedString(@"You want to download, but peer does not want to send (interested and choked)",
843                "Inspector -> peer -> status")];
844        if ([flags rangeOfString: @"U"].location != NSNotFound)
845            [statusArray addObject: NSLocalizedString(@"Currently uploading (interested and not choked)",
846                "Inspector -> peer -> status")];
847        if ([flags rangeOfString: @"u"].location != NSNotFound)
848            [statusArray addObject: NSLocalizedString(@"Peer wants you to upload, but you do not want to (interested and choked)",
849                "Inspector -> peer -> status")];
850        if ([flags rangeOfString: @"K"].location != NSNotFound)
851            [statusArray addObject: NSLocalizedString(@"Peer is unchoking you, but you are not interested",
852                "Inspector -> peer -> status")];
853        if ([flags rangeOfString: @"?"].location != NSNotFound)
854            [statusArray addObject: NSLocalizedString(@"You unchoked the peer, but the peer is not interested",
855                "Inspector -> peer -> status")];
856       
857        if ([statusArray count] > 0)
858        {
859            NSString * statusStrings = [statusArray componentsJoinedByString: @"\n\n"];
860            [components addObject: [@"\n" stringByAppendingString: statusStrings]];
861        }
862       
863        return [components componentsJoinedByString: @"\n"];
864    }
865    else if (tableView == fTrackerTable)
866    {
867        id node = [fTrackers objectAtIndex: row];
868        if ([node isKindOfClass: [TrackerNode class]])
869            return [(TrackerNode *)node fullAnnounceAddress];
870    }
871    else if (tableView == fWebSeedTable)
872    {
873        if ([fTorrents count] > 1)
874            return [[fWebSeeds objectAtIndex: row] objectForKey: @"Name"];
875    }
876   
877    return nil;
878}
879
880- (void) tableView: (NSTableView *) tableView setObjectValue: (id) object forTableColumn: (NSTableColumn *) tableColumn
881    row: (NSInteger) row
882{
883    if (tableView != fTrackerTable)
884        return;
885   
886    Torrent * torrent= [fTorrents objectAtIndex: 0];
887   
888    BOOL added = NO;
889    for (NSString * tracker in [object componentsSeparatedByString: @"\n"])
890        if ([torrent addTrackerToNewTier: tracker])
891            added = YES;
892   
893    if (!added)
894        NSBeep();
895   
896    //reset table with either new or old value
897    [fTrackers release];
898    fTrackers = [[torrent allTrackerStats] retain];
899   
900    [fTrackerTable setTrackers: fTrackers];
901    [fTrackerTable reloadData];
902    [fTrackerTable deselectAll: self];
903   
904    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; //incase sort by tracker
905}
906
907- (void) addRemoveTracker: (id) sender
908{
909    //don't allow add/remove when currently adding - it leads to weird results
910    if ([fTrackerTable editedRow] != -1)
911        return;
912   
913    if ([[sender cell] tagForSegment: [sender selectedSegment]] == TRACKER_REMOVE_TAG)
914        [self removeTrackers];
915    else
916        [self addTrackers];
917}
918
919- (NSArray *) quickLookURLs
920{
921    FileOutlineView * fileOutlineView = [fFileController outlineView];
922    Torrent * torrent = [fTorrents objectAtIndex: 0];
923    NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
924    NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]];
925   
926    for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
927    {
928        FileListNode * item = [fileOutlineView itemAtRow: i];
929        if ([self canQuickLookFile: item])
930            [urlArray addObject: [NSURL fileURLWithPath: [torrent fileLocation: item]]];
931    }
932   
933    return urlArray;
934}
935
936- (BOOL) canQuickLook
937{
938    if (fCurrentTabTag != TAB_FILES_TAG || ![[self window] isVisible] || [fTorrents count] != 1 || ![NSApp isOnSnowLeopardOrBetter])
939        return NO;
940   
941    Torrent * torrent = [fTorrents objectAtIndex: 0];
942    if (![torrent isFolder])
943        return NO;
944   
945    FileOutlineView * fileOutlineView = [fFileController outlineView];
946    NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
947   
948    for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
949        if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]])
950            return YES;
951   
952    return NO;
953}
954
955#warning uncomment (in header too)
956- (NSRect) quickLookSourceFrameForPreviewItem: (id /*<QLPreviewItem>*/) item
957{
958    FileOutlineView * fileOutlineView = [fFileController outlineView];
959   
960    NSString * fullPath = [(NSURL *)item path];
961    Torrent * torrent = [fTorrents objectAtIndex: 0];
962    NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]];
963   
964    for (NSUInteger row = visibleRows.location; row < NSMaxRange(visibleRows); row++)
965    {
966        FileListNode * rowItem = [fileOutlineView itemAtRow: row];
967        if ([[torrent fileLocation: rowItem] isEqualToString: fullPath])
968        {
969            NSRect frame = [fileOutlineView iconRectForRow: row];
970           
971            if (!NSIntersectsRect([fileOutlineView visibleRect], frame))
972                return NSZeroRect;
973           
974            frame.origin = [fileOutlineView convertPoint: frame.origin toView: nil];
975            frame.origin = [[self window] convertBaseToScreen: frame.origin];
976            frame.origin.y -= frame.size.height;
977            return frame;
978        }
979    }
980   
981    return NSZeroRect;
982}
983
984- (void) setPiecesView: (id) sender
985{
986    [self setPiecesViewForAvailable: [sender selectedSegment] == PIECES_CONTROL_AVAILABLE];
987}
988
989- (void) setPiecesViewForAvailable: (BOOL) available
990{
991    [fPiecesControl setSelected: available forSegment: PIECES_CONTROL_AVAILABLE];
992    [fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS];
993   
994    [[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"];
995    [fPiecesView updateView];
996}
997
998- (void) revealDataFile: (id) sender
999{
1000    Torrent * torrent = [fTorrents objectAtIndex: 0];
1001    NSString * location = [torrent dataLocation];
1002    if (!location)
1003        return;
1004   
1005    if ([NSApp isOnSnowLeopardOrBetter])
1006    {
1007        NSURL * file = [NSURL fileURLWithPath: location];
1008        [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]];
1009    }
1010    else
1011        [[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil];
1012}
1013
1014- (void) setFileFilterText: (id) sender
1015{
1016    [fFileController setFilterText: [sender stringValue]];
1017}
1018
1019- (void) setUseSpeedLimit: (id) sender
1020{
1021    const BOOL upload = sender == fUploadLimitCheck;
1022   
1023    if ([sender state] == NSMixedState)
1024        [sender setState: NSOnState];
1025    const BOOL limit = [sender state] == NSOnState;
1026   
1027    for (Torrent * torrent in fTorrents)
1028        [torrent setUseSpeedLimit: limit upload: upload];
1029   
1030    NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField;
1031    [field setEnabled: limit];
1032    if (limit)
1033    {
1034        [field selectText: self];
1035        [[self window] makeKeyAndOrderFront: self];
1036    }
1037   
1038    NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel;
1039    [label setEnabled: limit];
1040}
1041
1042- (void) setUseGlobalSpeedLimit: (id) sender
1043{
1044    if ([sender state] == NSMixedState)
1045        [sender setState: NSOnState];
1046    const BOOL limit = [sender state] == NSOnState;
1047   
1048    for (Torrent * torrent in fTorrents)
1049        [torrent setUseGlobalSpeedLimit: limit];
1050}
1051
1052- (void) setSpeedLimit: (id) sender
1053{
1054    const BOOL upload = sender == fUploadLimitField;
1055    const NSInteger limit = [sender intValue];
1056   
1057    for (Torrent * torrent in fTorrents)
1058        [torrent setSpeedLimit: limit upload: upload];
1059}
1060
1061- (void) setRatioSetting: (id) sender
1062{
1063    NSInteger setting;
1064    bool single = NO;
1065    switch ([sender indexOfSelectedItem])
1066    {
1067        case OPTION_POPUP_LIMIT:
1068            setting = TR_RATIOLIMIT_SINGLE;
1069            single = YES;
1070            break;
1071        case OPTION_POPUP_NO_LIMIT:
1072            setting = TR_RATIOLIMIT_UNLIMITED;
1073            break;
1074        case OPTION_POPUP_GLOBAL:
1075            setting = TR_RATIOLIMIT_GLOBAL;
1076            break;
1077        default:
1078            NSAssert1(NO, @"Unknown option selected in ratio popup: %d", [sender indexOfSelectedItem]);
1079            return;
1080    }
1081   
1082    for (Torrent * torrent in fTorrents)
1083        [torrent setRatioSetting: setting];
1084   
1085    [fRatioLimitField setHidden: !single];
1086    if (single)
1087    {
1088        [fRatioLimitField selectText: self];
1089        [[self window] makeKeyAndOrderFront: self];
1090    }
1091}
1092
1093- (void) setRatioLimit: (id) sender
1094{
1095    CGFloat limit = [sender floatValue];
1096   
1097    for (Torrent * torrent in fTorrents)
1098        [torrent setRatioLimit: limit];
1099}
1100
1101- (void) setPriority: (id) sender
1102{
1103    tr_priority_t priority;
1104    switch ([sender indexOfSelectedItem])
1105    {
1106        case OPTION_POPUP_PRIORITY_HIGH:
1107            priority = TR_PRI_HIGH;
1108            break;
1109        case OPTION_POPUP_PRIORITY_NORMAL:
1110            priority = TR_PRI_NORMAL;
1111            break;
1112        case OPTION_POPUP_PRIORITY_LOW:
1113            priority = TR_PRI_LOW;
1114            break;
1115        default:
1116            NSAssert1(NO, @"Unknown option selected in priority popup: %d", [sender indexOfSelectedItem]);
1117            return;
1118    }
1119   
1120    for (Torrent * torrent in fTorrents)
1121        [torrent setPriority: priority];
1122   
1123    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
1124}
1125
1126- (void) setPeersConnectLimit: (id) sender
1127{
1128    NSInteger limit = [sender intValue];
1129   
1130    for (Torrent * torrent in fTorrents)
1131        [torrent setMaxPeerConnect: limit];
1132}
1133
1134- (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor
1135{
1136    [fInitialString release];
1137    fInitialString = [[control stringValue] retain];
1138   
1139    return YES;
1140}
1141
1142- (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error
1143{
1144    NSBeep();
1145    if (fInitialString)
1146    {
1147        [control setStringValue: fInitialString];
1148        [fInitialString release];
1149        fInitialString = nil;
1150    }
1151    return NO;
1152}
1153
1154@end
1155
1156@implementation InfoWindowController (Private)
1157
1158- (void) resetInfo
1159{
1160    const NSUInteger numberSelected = [fTorrents count];
1161    if (numberSelected != 1)
1162    {
1163        if (numberSelected > 0)
1164        {
1165            [fImageView setImage: [NSImage imageNamed: NSImageNameMultipleDocuments]];
1166           
1167            [fNameField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d Torrents Selected",
1168                                            "Inspector -> selected torrents"), numberSelected]];
1169       
1170            uint64_t size = 0;
1171            NSUInteger fileCount = 0, magnetCount = 0;
1172            for (Torrent * torrent in fTorrents)
1173            {
1174                size += [torrent size];
1175                fileCount += [torrent fileCount];
1176                if ([torrent isMagnet])
1177                    ++magnetCount;
1178            }
1179           
1180            NSMutableArray * fileStrings = [NSMutableArray arrayWithCapacity: 2];
1181            if (fileCount > 0)
1182            {
1183                NSString * fileString;
1184                if (fileCount == 1)
1185                    fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents");
1186                else
1187                    fileString = [NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount];
1188                [fileStrings addObject: fileString];
1189            }
1190            if (magnetCount > 0)
1191            {
1192                NSString * magnetString;
1193                if (magnetCount == 1)
1194                    magnetString = NSLocalizedString(@"1 magnetized transfer", "Inspector -> selected torrents");
1195                else
1196                    magnetString = [NSString stringWithFormat: NSLocalizedString(@"%d magnetized transfers",
1197                                    "Inspector -> selected torrents"), magnetCount];
1198                [fileStrings addObject: magnetString];
1199            }
1200           
1201            NSString * fileString = [fileStrings componentsJoinedByString: @" + "];
1202           
1203            if (magnetCount < numberSelected)
1204            {
1205                [fBasicInfoField setStringValue: [NSString stringWithFormat: @"%@, %@", fileString,
1206                    [NSString stringWithFormat: NSLocalizedString(@"%@ total", "Inspector -> selected torrents"),
1207                        [NSString stringForFileSize: size]]]];
1208                [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%llu bytes", "Inspector -> selected torrents"),
1209                                                size]];
1210            }
1211            else
1212            {
1213                [fBasicInfoField setStringValue: fileString];
1214                [fBasicInfoField setToolTip: nil];
1215            }
1216        }
1217        else
1218        {
1219            [fImageView setImage: [NSImage imageNamed: @"NSApplicationIcon"]];
1220           
1221            [fNameField setStringValue: NSLocalizedString(@"No Torrents Selected", "Inspector -> selected torrents")];
1222            [fBasicInfoField setStringValue: @""];
1223            [fBasicInfoField setToolTip: @""];
1224   
1225            [fHaveField setStringValue: @""];
1226            [fDownloadedTotalField setStringValue: @""];
1227            [fUploadedTotalField setStringValue: @""];
1228            [fFailedHashField setStringValue: @""];
1229            [fDateActivityField setStringValue: @""];
1230            [fRatioField setStringValue: @""];
1231           
1232            //options fields
1233            [fUploadLimitCheck setEnabled: NO];
1234            [fUploadLimitCheck setState: NSOffState];
1235            [fUploadLimitField setEnabled: NO];
1236            [fUploadLimitLabel setEnabled: NO];
1237            [fUploadLimitField setStringValue: @""];
1238           
1239            [fDownloadLimitCheck setEnabled: NO];
1240            [fDownloadLimitCheck setState: NSOffState];
1241            [fDownloadLimitField setEnabled: NO];
1242            [fDownloadLimitLabel setEnabled: NO];
1243            [fDownloadLimitField setStringValue: @""];
1244           
1245            [fGlobalLimitCheck setEnabled: NO];
1246            [fGlobalLimitCheck setState: NSOffState];
1247           
1248            [fPriorityPopUp setEnabled: NO];
1249            [fPriorityPopUp selectItemAtIndex: -1];
1250           
1251            [fRatioPopUp setEnabled: NO];
1252            [fRatioPopUp selectItemAtIndex: -1];
1253            [fRatioLimitField setHidden: YES];
1254            [fRatioLimitField setStringValue: @""];
1255           
1256            [fPeersConnectField setEnabled: NO];
1257            [fPeersConnectField setStringValue: @""];
1258            [fPeersConnectLabel setEnabled: NO];
1259           
1260            [fPeers release];
1261            fPeers = nil;
1262            [fPeerTable reloadData];
1263           
1264            [fTrackers release];
1265            fTrackers = nil;
1266           
1267            [fTrackerTable setTrackers: nil];
1268            [fTrackerTable deselectAll: self];
1269            [fTrackerTable reloadData];
1270        }
1271       
1272        [fFileController setTorrent: nil];
1273       
1274        [fNameField setToolTip: nil];
1275
1276        [fPiecesField setStringValue: @""];
1277        [fHashField setStringValue: @""];
1278        [fHashField setToolTip: nil];
1279        [fSecureField setStringValue: @""];
1280        [fCommentView setString: @""];
1281       
1282        [fCreatorField setStringValue: @""];
1283        [fDateCreatedField setStringValue: @""];
1284       
1285        [fDataLocationField setStringValue: @""];
1286        [fDataLocationField setToolTip: nil];
1287       
1288        [fRevealDataButton setHidden: YES];
1289       
1290        [fStateField setStringValue: @""];
1291        [fProgressField setStringValue: @""];
1292       
1293        [fErrorMessageView setString: @""];
1294       
1295        [fConnectedPeersField setStringValue: @""];
1296       
1297        [fDateAddedField setStringValue: @""];
1298        [fDateCompletedField setStringValue: @""];
1299       
1300        [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE];
1301        [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS];
1302        [fPiecesControl setEnabled: NO];
1303        [fPiecesView setTorrent: nil];
1304       
1305        [fTrackerTable setTorrent: nil];
1306       
1307        [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_ADD_TAG];
1308        [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG];
1309       
1310        [fFileFilterField setEnabled: NO];
1311    }
1312    else
1313    {
1314        Torrent * torrent = [fTorrents objectAtIndex: 0];
1315       
1316        [fFileController setTorrent: torrent];
1317       
1318        if ([NSApp isOnSnowLeopardOrBetter])
1319            [fImageView setImage: [torrent icon]];
1320        else
1321        {
1322            NSImage * icon = [[torrent icon] copy];
1323            [icon setFlipped: NO];
1324            [fImageView setImage: icon];
1325            [icon release];
1326        }
1327       
1328        NSString * name = [torrent name];
1329        [fNameField setStringValue: name];
1330        [fNameField setToolTip: name];
1331       
1332        if (![torrent isMagnet])
1333        {
1334            NSString * basicString = [NSString stringForFileSize: [torrent size]];
1335            if ([torrent isFolder])
1336            {
1337                NSString * fileString;
1338                NSInteger fileCount = [torrent fileCount];
1339                if (fileCount == 1)
1340                    fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents");
1341                else
1342                    fileString= [NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount];
1343                basicString = [NSString stringWithFormat: @"%@, %@", fileString, basicString];
1344            }
1345            [fBasicInfoField setStringValue: basicString];
1346            [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%llu bytes", "Inspector -> selected torrents"),
1347                                            [torrent size]]];
1348        }
1349        else
1350        {
1351            [fBasicInfoField setStringValue: NSLocalizedString(@"Magnetized transfer", "Inspector -> selected torrents")];
1352            [fBasicInfoField setToolTip: nil];
1353        }
1354       
1355        NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%d, %@", [torrent pieceCount],
1356                                        [NSString stringForFileSize: [torrent pieceSize]]] : @"";
1357        [fPiecesField setStringValue: piecesString];
1358                                       
1359        NSString * hashString = [torrent hashString];
1360        [fHashField setStringValue: hashString];
1361        [fHashField setToolTip: hashString];
1362        [fSecureField setStringValue: [torrent privateTorrent]
1363                        ? NSLocalizedString(@"Private Torrent, PEX and DHT automatically disabled", "Inspector -> private torrent")
1364                        : NSLocalizedString(@"Public Torrent", "Inspector -> private torrent")];
1365       
1366        NSString * commentString = [torrent comment];
1367        [fCommentView setString: commentString];
1368       
1369        NSString * creatorString = [torrent creator];
1370        [fCreatorField setStringValue: creatorString];
1371        [fDateCreatedField setObjectValue: [torrent dateCreated]];
1372       
1373        [fDateAddedField setObjectValue: [torrent dateAdded]];
1374       
1375        //set pieces view
1376        BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"];
1377        [fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE];
1378        [fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS];
1379        [fPiecesControl setEnabled: YES];
1380        [fPiecesView setTorrent: torrent];
1381       
1382        [fTrackerTable setTorrent: torrent];
1383        [fTrackerTable deselectAll: self];
1384        [fTrackerAddRemoveControl setEnabled: YES forSegment: TRACKER_ADD_TAG];
1385        [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG];
1386
1387        [fFileFilterField setEnabled: [torrent isFolder]];
1388    }
1389   
1390    [fFileFilterField setStringValue: @""];
1391   
1392    //reset webseeds here, since it might be hidden regardless of number selected
1393    BOOL hasWebSeeds = NO;
1394    for (Torrent * torrent in fTorrents)
1395    {
1396        if ([torrent webSeedCount] > 0)
1397        {
1398            hasWebSeeds = YES;
1399            break;
1400        }
1401    }
1402   
1403    if (!hasWebSeeds)
1404    {
1405        [fWebSeeds release];
1406        fWebSeeds = nil;
1407        [fWebSeedTable reloadData];
1408    }
1409    [self setWebSeedTableHidden: !hasWebSeeds animate: YES];
1410   
1411    //update stats and settings
1412    [self updateInfoStats];
1413    [self updateOptions];
1414}
1415
1416- (void) resetInfoForTorrent: (NSNotification *) notification
1417{
1418    if (fTorrents && [fTorrents containsObject: [notification object]])
1419        [self resetInfo];
1420}
1421
1422- (void) updateInfoGeneral
1423{   
1424    if ([fTorrents count] != 1)
1425        return;
1426   
1427    Torrent * torrent = [fTorrents objectAtIndex: 0];
1428   
1429    NSString * location = [torrent dataLocation];
1430    [fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""];
1431    [fDataLocationField setToolTip: location ? location : @""];
1432   
1433    [fRevealDataButton setHidden: !location];
1434}
1435
1436- (void) updateInfoActivity
1437{
1438    NSInteger numberSelected = [fTorrents count];
1439    if (numberSelected == 0)
1440        return;
1441   
1442    uint64_t have = 0, haveVerified = 0, downloadedTotal = 0, uploadedTotal = 0, failedHash = 0;
1443    NSDate * lastActivity = nil;
1444    for (Torrent * torrent in fTorrents)
1445    {
1446        have += [torrent haveTotal];
1447        haveVerified += [torrent haveVerified];
1448        downloadedTotal += [torrent downloadedTotal];
1449        uploadedTotal += [torrent uploadedTotal];
1450        failedHash += [torrent failedHash];
1451       
1452        NSDate * nextLastActivity;
1453        if ((nextLastActivity = [torrent dateActivity]))
1454            lastActivity = lastActivity ? [lastActivity laterDate: nextLastActivity] : nextLastActivity;
1455    }
1456   
1457    if (have == 0)
1458        [fHaveField setStringValue: [NSString stringForFileSize: 0]];
1459    else
1460    {
1461        NSString * verifiedString = [NSString stringWithFormat: NSLocalizedString(@"%@ verified", "Inspector -> Activity tab -> have"),
1462                                        [NSString stringForFileSize: haveVerified]];
1463        if (have == haveVerified)
1464            [fHaveField setStringValue: verifiedString];
1465        else
1466            [fHaveField setStringValue: [NSString stringWithFormat: @"%@ (%@)", [NSString stringForFileSize: have], verifiedString]];
1467    }
1468   
1469    [fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
1470    [fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
1471    [fFailedHashField setStringValue: [NSString stringForFileSize: failedHash]];
1472   
1473    [fDateActivityField setObjectValue: lastActivity];
1474   
1475    if (numberSelected == 1)
1476    {
1477        Torrent * torrent = [fTorrents objectAtIndex: 0];
1478       
1479        [fStateField setStringValue: [torrent stateString]];
1480       
1481        if ([torrent isFolder])
1482            [fProgressField setStringValue: [NSString localizedStringWithFormat: NSLocalizedString(@"%.2f%% (%.2f%% selected)",
1483                "Inspector -> Activity tab -> progress"), 100.0 * [torrent progress], 100.0 * [torrent progressDone]]];
1484        else
1485            [fProgressField setStringValue: [NSString localizedStringWithFormat: @"%.2f%%", 100.0 * [torrent progress]]];
1486           
1487        [fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]];
1488       
1489        NSString * errorMessage = [torrent errorMessage];
1490        if (![errorMessage isEqualToString: [fErrorMessageView string]])
1491            [fErrorMessageView setString: errorMessage];
1492       
1493        [fDateCompletedField setObjectValue: [torrent dateCompleted]];
1494       
1495        [fPiecesView updateView];
1496    }
1497    else if (numberSelected > 1)
1498    {
1499        [fRatioField setStringValue: [NSString stringForRatio: tr_getRatio(uploadedTotal, downloadedTotal)]];
1500    }
1501    else;
1502}
1503
1504- (void) updateInfoTracker
1505{
1506    if ([fTorrents count] == 0)
1507        return;
1508   
1509    //get updated tracker stats
1510    if ([fTrackerTable editedRow] == -1)
1511    {
1512        [fTrackers release];
1513       
1514        if ([fTorrents count] == 1)
1515            fTrackers = [[[fTorrents objectAtIndex: 0] allTrackerStats] retain];
1516        else
1517        {
1518            fTrackers = [[NSMutableArray alloc] init];
1519            for (Torrent * torrent in fTorrents)
1520                [fTrackers addObjectsFromArray: [torrent allTrackerStats]];
1521        }
1522       
1523        [fTrackerTable setTrackers: fTrackers];
1524        [fTrackerTable reloadData];
1525    }
1526    else
1527    {
1528        NSAssert1([fTorrents count] == 1, @"Attempting to add tracker with %d transfers selected", [fTorrents count]);
1529       
1530        if ([NSApp isOnSnowLeopardOrBetter])
1531        {
1532            NSIndexSet * addedIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange([fTrackers count]-2, 2)];
1533            NSArray * tierAndTrackerBeingAdded = [fTrackers objectsAtIndexes: addedIndexes];
1534           
1535            [fTrackers release];
1536            fTrackers = [[[fTorrents objectAtIndex: 0] allTrackerStats] retain];
1537            [fTrackers addObjectsFromArray: tierAndTrackerBeingAdded];
1538           
1539            [fTrackerTable setTrackers: fTrackers];
1540           
1541            NSIndexSet * updateIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTrackers count]-2)],
1542                    * columnIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [[fTrackerTable tableColumns] count])];
1543            [fTrackerTable reloadDataForRowIndexes: updateIndexes columnIndexes: columnIndexes];
1544        }
1545    }
1546}
1547
1548- (void) updateInfoPeers
1549{
1550    if ([fTorrents count] == 0)
1551        return;
1552   
1553    if (!fPeers)
1554        fPeers = [[NSMutableArray alloc] init];
1555    else
1556        [fPeers removeAllObjects];
1557   
1558    if (!fWebSeeds)
1559        fWebSeeds = [[NSMutableArray alloc] init];
1560    else
1561        [fWebSeeds removeAllObjects];
1562   
1563    NSUInteger known = 0, connected = 0, tracker = 0, incoming = 0, cache = 0, pex = 0, dht = 0, ltep = 0,
1564                toUs = 0, fromUs = 0;
1565    BOOL anyActive = false;
1566    for (Torrent * torrent in fTorrents)
1567    {
1568        if ([torrent webSeedCount] > 0)
1569            [fWebSeeds addObjectsFromArray: [torrent webSeeds]];
1570       
1571        known += [torrent totalPeersKnown];
1572       
1573        if ([torrent isActive])
1574        {
1575            anyActive = YES;
1576            [fPeers addObjectsFromArray: [torrent peers]];
1577           
1578            const NSUInteger connectedThis = [torrent totalPeersConnected];
1579            if (connectedThis > 0)
1580            {
1581                connected += [torrent totalPeersConnected];
1582                tracker += [torrent totalPeersTracker];
1583                incoming += [torrent totalPeersIncoming];
1584                cache += [torrent totalPeersCache];
1585                pex += [torrent totalPeersPex];
1586                dht += [torrent totalPeersDHT];
1587                ltep += [torrent totalPeersLTEP];
1588               
1589                toUs += [torrent peersSendingToUs];
1590                fromUs += [torrent peersGettingFromUs];
1591            }
1592        }
1593    }
1594   
1595    [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
1596    [fPeerTable reloadData];
1597   
1598    [fWebSeeds sortUsingDescriptors: [fWebSeedTable sortDescriptors]];
1599    [fWebSeedTable reloadData];
1600   
1601    NSString * knownString = [NSString stringWithFormat: NSLocalizedString(@"%d known", "Inspector -> Peers tab -> peers"), known];
1602    if (anyActive)
1603    {
1604        NSString * connectedText = [NSString stringWithFormat: NSLocalizedString(@"%d Connected", "Inspector -> Peers tab -> peers"),
1605                                    connected];
1606       
1607        if (connected > 0)
1608        {
1609            NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 6];
1610            if (tracker > 0)
1611                [fromComponents addObject: [NSString stringWithFormat:
1612                                        NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), tracker]];
1613            if (incoming > 0)
1614                [fromComponents addObject: [NSString stringWithFormat:
1615                                        NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), incoming]];
1616            if (cache > 0)
1617                [fromComponents addObject: [NSString stringWithFormat:
1618                                        NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), cache]];
1619            if (pex > 0)
1620                [fromComponents addObject: [NSString stringWithFormat:
1621                                        NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), pex]];
1622            if (dht > 0)
1623                [fromComponents addObject: [NSString stringWithFormat:
1624                                        NSLocalizedString(@"%d DHT", "Inspector -> Peers tab -> peers"), dht]];
1625            if (ltep > 0)
1626                [fromComponents addObject: [NSString stringWithFormat:
1627                                        NSLocalizedString(@"%d LTEP", "Inspector -> Peers tab -> peers"), ltep]];
1628           
1629            NSMutableArray * upDownComponents = [NSMutableArray arrayWithCapacity: 3];
1630            if (toUs > 0)
1631                [upDownComponents addObject: [NSString stringWithFormat:
1632                                        NSLocalizedString(@"DL from %d", "Inspector -> Peers tab -> peers"), toUs]];
1633            if (fromUs > 0)
1634                [upDownComponents addObject: [NSString stringWithFormat:
1635                                        NSLocalizedString(@"UL to %d", "Inspector -> Peers tab -> peers"), fromUs]];
1636            [upDownComponents addObject: knownString];
1637           
1638            connectedText = [connectedText stringByAppendingFormat: @": %@\n%@", [fromComponents componentsJoinedByString: @", "],
1639                                [upDownComponents componentsJoinedByString: @", "]];
1640        }
1641        else
1642            connectedText = [connectedText stringByAppendingFormat: @"\n%@", knownString];
1643       
1644        [fConnectedPeersField setStringValue: connectedText];
1645    }
1646    else
1647    {
1648        NSString * activeString;
1649        if ([fTorrents count] == 1)
1650            activeString = NSLocalizedString(@"Transfer Not Active", "Inspector -> Peers tab -> peers");
1651        else
1652            activeString = NSLocalizedString(@"Transfers Not Active", "Inspector -> Peers tab -> peers");
1653       
1654        NSString * connectedText = [activeString stringByAppendingFormat: @"\n%@", knownString];
1655        [fConnectedPeersField setStringValue: connectedText];
1656    }
1657}
1658
1659- (void) updateInfoFiles
1660{
1661    if ([fTorrents count] == 1)
1662        [fFileController reloadData];
1663}
1664
1665- (NSView *) tabViewForTag: (NSInteger) tag
1666{
1667    switch (tag)
1668    {
1669        case TAB_INFO_TAG:
1670            return fInfoView;
1671        case TAB_ACTIVITY_TAG:
1672            return fActivityView;
1673        case TAB_TRACKER_TAG:
1674            return fTrackerView;
1675        case TAB_PEERS_TAG:
1676            return fPeersView;
1677        case TAB_FILES_TAG:
1678            return fFilesView;
1679        case TAB_OPTIONS_TAG:
1680            return fOptionsView;
1681        default:
1682            NSAssert1(NO, @"Unknown tab view for tag: %d", tag);
1683            return nil;
1684    }
1685}
1686
1687- (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate
1688{
1689    if (fCurrentTabTag != TAB_PEERS_TAG || ![[self window] isVisible])
1690        animate = NO;
1691   
1692    if (fWebSeedTableAnimation)
1693    {
1694        [fWebSeedTableAnimation stopAnimation];
1695        [fWebSeedTableAnimation release];
1696        fWebSeedTableAnimation = nil;
1697    }
1698   
1699    NSRect webSeedFrame = [[fWebSeedTable enclosingScrollView] frame];
1700    NSRect peerFrame = [[fPeerTable enclosingScrollView] frame];
1701   
1702    if (hide)
1703    {
1704        CGFloat webSeedFrameMaxY = NSMaxY(webSeedFrame);
1705        webSeedFrame.size.height = 0;
1706        webSeedFrame.origin.y = webSeedFrameMaxY;
1707       
1708        peerFrame.size.height = webSeedFrameMaxY - peerFrame.origin.y;
1709    }
1710    else
1711    {
1712        webSeedFrame.origin.y -= fWebSeedTableHeight - webSeedFrame.size.height;
1713        webSeedFrame.size.height = fWebSeedTableHeight;
1714       
1715        peerFrame.size.height = (webSeedFrame.origin.y - fSpaceBetweenWebSeedAndPeer) - peerFrame.origin.y;
1716    }
1717   
1718    [[fWebSeedTable enclosingScrollView] setHidden: NO]; //this is needed for some reason
1719   
1720    //actually resize tables
1721    if (animate)
1722    {
1723        NSDictionary * webSeedDict = [NSDictionary dictionaryWithObjectsAndKeys:
1724                                    [fWebSeedTable enclosingScrollView], NSViewAnimationTargetKey,
1725                                    [NSValue valueWithRect: [[fWebSeedTable enclosingScrollView] frame]], NSViewAnimationStartFrameKey,
1726                                    [NSValue valueWithRect: webSeedFrame], NSViewAnimationEndFrameKey, nil],
1727                    * peerDict = [NSDictionary dictionaryWithObjectsAndKeys:
1728                                    [fPeerTable enclosingScrollView], NSViewAnimationTargetKey,
1729                                    [NSValue valueWithRect: [[fPeerTable enclosingScrollView] frame]], NSViewAnimationStartFrameKey,
1730                                    [NSValue valueWithRect: peerFrame], NSViewAnimationEndFrameKey, nil];
1731       
1732        fWebSeedTableAnimation = [[NSViewAnimation alloc] initWithViewAnimations:
1733                                        [NSArray arrayWithObjects: webSeedDict, peerDict, nil]];
1734        [fWebSeedTableAnimation setDuration: 0.125];
1735        [fWebSeedTableAnimation setAnimationBlockingMode: NSAnimationNonblocking];
1736        [fWebSeedTableAnimation setDelegate: self];
1737       
1738        [fWebSeedTableAnimation startAnimation];
1739    }
1740    else
1741    {
1742        [[fWebSeedTable enclosingScrollView] setFrame: webSeedFrame];
1743        [[fPeerTable enclosingScrollView] setFrame: peerFrame];
1744    }
1745}
1746
1747- (NSArray *) peerSortDescriptors
1748{
1749    NSMutableArray * descriptors = [NSMutableArray arrayWithCapacity: 2];
1750   
1751    NSArray * oldDescriptors = [fPeerTable sortDescriptors];
1752    BOOL useSecond = YES, asc = YES;
1753    if ([oldDescriptors count] > 0)
1754    {
1755        NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0];
1756        [descriptors addObject: descriptor];
1757       
1758        if ((useSecond = ![[descriptor key] isEqualToString: @"IP"]))
1759            asc = [descriptor ascending];
1760    }
1761   
1762    //sort by IP after primary sort
1763    if (useSecond)
1764    {
1765        NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc
1766                                                                        selector: @selector(compareNumeric:)];
1767        [descriptors addObject: secondDescriptor];
1768        [secondDescriptor release];
1769    }
1770   
1771    return descriptors;
1772}
1773
1774- (BOOL) canQuickLookFile: (FileListNode *) item
1775{
1776    Torrent * torrent = [fTorrents objectAtIndex: 0];
1777    return ([item isFolder] || [torrent fileProgress: item] >= 1.0) && [torrent fileLocation: item];
1778}
1779
1780#warning doesn't like blank addresses
1781- (void) addTrackers
1782{
1783    [[self window] makeKeyWindow];
1784   
1785    [fTrackers addObject: NSLocalizedString(@"New Tier", "inspector -> add tracker")];
1786    [fTrackers addObject: @""];
1787   
1788    [fTrackerTable setTrackers: fTrackers];
1789    [fTrackerTable reloadData];
1790    [fTrackerTable selectRowIndexes: [NSIndexSet indexSetWithIndex: [fTrackers count]-1] byExtendingSelection: NO];
1791    [fTrackerTable editColumn: [fTrackerTable columnWithIdentifier: @"Tracker"] row: [fTrackers count]-1 withEvent: nil select: YES];
1792}
1793
1794- (void) removeTrackers
1795{
1796    NSMutableIndexSet * removeIdentifiers = [NSMutableIndexSet indexSet];
1797   
1798    NSIndexSet * selectedIndexes = [fTrackerTable selectedRowIndexes];
1799    BOOL groupSelected = NO;
1800    for (NSUInteger i = 0; i < [fTrackers count]; ++i)
1801    {
1802        id object = [fTrackers objectAtIndex: i];
1803        if ([object isKindOfClass: [TrackerNode class]])
1804        {
1805            if (groupSelected || [selectedIndexes containsIndex: i])
1806                [removeIdentifiers addIndex: [(TrackerNode *)object identifier]];
1807        }
1808        else
1809        {
1810            groupSelected = [selectedIndexes containsIndex: i];
1811            if (!groupSelected && i > [selectedIndexes lastIndex])
1812                break;
1813        }
1814    }
1815   
1816    NSAssert([removeIdentifiers count] > 0, @"Trying to remove no trackers.");
1817   
1818    if ([[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveTrackers"])
1819    {
1820        NSAlert * alert = [[NSAlert alloc] init];
1821       
1822        if ([removeIdentifiers count] > 1)
1823        {
1824            [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?",
1825                                                                "Remove trackers alert -> title"), [removeIdentifiers count]]];
1826            [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them."
1827                                        " This cannot be undone.", "Remove trackers alert -> message")];
1828        }
1829        else
1830        {
1831            [alert setMessageText: NSLocalizedString(@"Are you sure you want to remove this tracker?", "Remove trackers alert -> title")];
1832            [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact it."
1833                                        " This cannot be undone.", "Remove trackers alert -> message")];
1834        }
1835       
1836        [alert addButtonWithTitle: NSLocalizedString(@"Remove", "Remove trackers alert -> button")];
1837        [alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Remove trackers alert -> button")];
1838       
1839        [alert setShowsSuppressionButton: YES];
1840
1841        NSInteger result = [alert runModal];
1842        if ([[alert suppressionButton] state] == NSOnState)
1843            [[NSUserDefaults standardUserDefaults] setBool: NO forKey: @"WarningRemoveTrackers"];
1844        [alert release];
1845       
1846        if (result != NSAlertFirstButtonReturn)
1847            return;
1848    }
1849   
1850    Torrent * torrent = [fTorrents objectAtIndex: 0];
1851    [torrent removeTrackersWithIdentifiers: removeIdentifiers];
1852   
1853    //reset table with either new or old value
1854    [fTrackers release];
1855    fTrackers = [[torrent allTrackerStats] retain];
1856   
1857    [fTrackerTable setTrackers: fTrackers];
1858    [fTrackerTable reloadData];
1859    [fTrackerTable deselectAll: self];
1860   
1861    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; //incase sort by tracker
1862}
1863
1864@end
Note: See TracBrowser for help on using the repository browser.