source: trunk/macosx/InfoWindowController.m @ 10144

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

deselect trackers in inspector when changing selection with > 1 selected in the main table

  • Property svn:keywords set to Date Rev Author Id
File size: 68.1 KB
Line 
1/******************************************************************************
2 * $Id: InfoWindowController.m 10144 2010-02-09 00:10:27Z 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: [NSDictionary 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; //TrackerNode or NSString
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            [fTrackerTable deselectAll: self];
1218        }
1219        else
1220        {
1221            [fImageView setImage: [NSImage imageNamed: @"NSApplicationIcon"]];
1222           
1223            [fNameField setStringValue: NSLocalizedString(@"No Torrents Selected", "Inspector -> selected torrents")];
1224            [fBasicInfoField setStringValue: @""];
1225            [fBasicInfoField setToolTip: @""];
1226   
1227            [fHaveField setStringValue: @""];
1228            [fDownloadedTotalField setStringValue: @""];
1229            [fUploadedTotalField setStringValue: @""];
1230            [fFailedHashField setStringValue: @""];
1231            [fDateActivityField setStringValue: @""];
1232            [fRatioField setStringValue: @""];
1233           
1234            //options fields
1235            [fUploadLimitCheck setEnabled: NO];
1236            [fUploadLimitCheck setState: NSOffState];
1237            [fUploadLimitField setEnabled: NO];
1238            [fUploadLimitLabel setEnabled: NO];
1239            [fUploadLimitField setStringValue: @""];
1240           
1241            [fDownloadLimitCheck setEnabled: NO];
1242            [fDownloadLimitCheck setState: NSOffState];
1243            [fDownloadLimitField setEnabled: NO];
1244            [fDownloadLimitLabel setEnabled: NO];
1245            [fDownloadLimitField setStringValue: @""];
1246           
1247            [fGlobalLimitCheck setEnabled: NO];
1248            [fGlobalLimitCheck setState: NSOffState];
1249           
1250            [fPriorityPopUp setEnabled: NO];
1251            [fPriorityPopUp selectItemAtIndex: -1];
1252           
1253            [fRatioPopUp setEnabled: NO];
1254            [fRatioPopUp selectItemAtIndex: -1];
1255            [fRatioLimitField setHidden: YES];
1256            [fRatioLimitField setStringValue: @""];
1257           
1258            [fPeersConnectField setEnabled: NO];
1259            [fPeersConnectField setStringValue: @""];
1260            [fPeersConnectLabel setEnabled: NO];
1261           
1262            [fPeers release];
1263            fPeers = nil;
1264            [fPeerTable reloadData];
1265           
1266            [fTrackers release];
1267            fTrackers = nil;
1268           
1269            [fTrackerTable setTrackers: nil];
1270            [fTrackerTable reloadData];
1271        }
1272       
1273        [fFileController setTorrent: nil];
1274       
1275        [fNameField setToolTip: nil];
1276
1277        [fPiecesField setStringValue: @""];
1278        [fHashField setStringValue: @""];
1279        [fHashField setToolTip: nil];
1280        [fSecureField setStringValue: @""];
1281        [fCommentView setString: @""];
1282       
1283        [fCreatorField setStringValue: @""];
1284        [fDateCreatedField setStringValue: @""];
1285       
1286        [fDataLocationField setStringValue: @""];
1287        [fDataLocationField setToolTip: nil];
1288       
1289        [fRevealDataButton setHidden: YES];
1290       
1291        [fStateField setStringValue: @""];
1292        [fProgressField setStringValue: @""];
1293       
1294        [fErrorMessageView setString: @""];
1295       
1296        [fConnectedPeersField setStringValue: @""];
1297       
1298        [fDateAddedField setStringValue: @""];
1299        [fDateCompletedField setStringValue: @""];
1300       
1301        [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE];
1302        [fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS];
1303        [fPiecesControl setEnabled: NO];
1304        [fPiecesView setTorrent: nil];
1305       
1306        [fTrackerTable setTorrent: nil];
1307       
1308        [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_ADD_TAG];
1309        [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG];
1310       
1311        [fFileFilterField setEnabled: NO];
1312    }
1313    else
1314    {
1315        Torrent * torrent = [fTorrents objectAtIndex: 0];
1316       
1317        [fFileController setTorrent: torrent];
1318       
1319        if ([NSApp isOnSnowLeopardOrBetter])
1320            [fImageView setImage: [torrent icon]];
1321        else
1322        {
1323            NSImage * icon = [[torrent icon] copy];
1324            [icon setFlipped: NO];
1325            [fImageView setImage: icon];
1326            [icon release];
1327        }
1328       
1329        NSString * name = [torrent name];
1330        [fNameField setStringValue: name];
1331        [fNameField setToolTip: name];
1332       
1333        if (![torrent isMagnet])
1334        {
1335            NSString * basicString = [NSString stringForFileSize: [torrent size]];
1336            if ([torrent isFolder])
1337            {
1338                NSString * fileString;
1339                NSInteger fileCount = [torrent fileCount];
1340                if (fileCount == 1)
1341                    fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents");
1342                else
1343                    fileString= [NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount];
1344                basicString = [NSString stringWithFormat: @"%@, %@", fileString, basicString];
1345            }
1346            [fBasicInfoField setStringValue: basicString];
1347            [fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%llu bytes", "Inspector -> selected torrents"),
1348                                            [torrent size]]];
1349        }
1350        else
1351        {
1352            [fBasicInfoField setStringValue: NSLocalizedString(@"Magnetized transfer", "Inspector -> selected torrents")];
1353            [fBasicInfoField setToolTip: nil];
1354        }
1355       
1356        NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%d, %@", [torrent pieceCount],
1357                                        [NSString stringForFileSize: [torrent pieceSize]]] : @"";
1358        [fPiecesField setStringValue: piecesString];
1359                                       
1360        NSString * hashString = [torrent hashString];
1361        [fHashField setStringValue: hashString];
1362        [fHashField setToolTip: hashString];
1363        [fSecureField setStringValue: [torrent privateTorrent]
1364                        ? NSLocalizedString(@"Private Torrent, PEX and DHT automatically disabled", "Inspector -> private torrent")
1365                        : NSLocalizedString(@"Public Torrent", "Inspector -> private torrent")];
1366       
1367        NSString * commentString = [torrent comment];
1368        [fCommentView setString: commentString];
1369       
1370        NSString * creatorString = [torrent creator];
1371        [fCreatorField setStringValue: creatorString];
1372        [fDateCreatedField setObjectValue: [torrent dateCreated]];
1373       
1374        [fDateAddedField setObjectValue: [torrent dateAdded]];
1375       
1376        //set pieces view
1377        BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"];
1378        [fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE];
1379        [fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS];
1380        [fPiecesControl setEnabled: YES];
1381        [fPiecesView setTorrent: torrent];
1382       
1383        [fTrackerTable setTorrent: torrent];
1384        [fTrackerTable deselectAll: self];
1385        [fTrackerAddRemoveControl setEnabled: YES forSegment: TRACKER_ADD_TAG];
1386        [fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG];
1387
1388        [fFileFilterField setEnabled: [torrent isFolder]];
1389    }
1390   
1391    [fFileFilterField setStringValue: @""];
1392   
1393    //reset webseeds here, since it might be hidden regardless of number selected
1394    BOOL hasWebSeeds = NO;
1395    for (Torrent * torrent in fTorrents)
1396    {
1397        if ([torrent webSeedCount] > 0)
1398        {
1399            hasWebSeeds = YES;
1400            break;
1401        }
1402    }
1403   
1404    if (!hasWebSeeds)
1405    {
1406        [fWebSeeds release];
1407        fWebSeeds = nil;
1408        [fWebSeedTable reloadData];
1409    }
1410    [self setWebSeedTableHidden: !hasWebSeeds animate: YES];
1411   
1412    //update stats and settings
1413    [self updateInfoStats];
1414    [self updateOptions];
1415}
1416
1417- (void) resetInfoForTorrent: (NSNotification *) notification
1418{
1419    if (fTorrents && [fTorrents containsObject: [notification object]])
1420        [self resetInfo];
1421}
1422
1423- (void) updateInfoGeneral
1424{   
1425    if ([fTorrents count] != 1)
1426        return;
1427   
1428    Torrent * torrent = [fTorrents objectAtIndex: 0];
1429   
1430    NSString * location = [torrent dataLocation];
1431    [fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""];
1432    [fDataLocationField setToolTip: location ? location : @""];
1433   
1434    [fRevealDataButton setHidden: !location];
1435}
1436
1437- (void) updateInfoActivity
1438{
1439    NSInteger numberSelected = [fTorrents count];
1440    if (numberSelected == 0)
1441        return;
1442   
1443    uint64_t have = 0, haveVerified = 0, downloadedTotal = 0, uploadedTotal = 0, failedHash = 0;
1444    NSDate * lastActivity = nil;
1445    for (Torrent * torrent in fTorrents)
1446    {
1447        have += [torrent haveTotal];
1448        haveVerified += [torrent haveVerified];
1449        downloadedTotal += [torrent downloadedTotal];
1450        uploadedTotal += [torrent uploadedTotal];
1451        failedHash += [torrent failedHash];
1452       
1453        NSDate * nextLastActivity;
1454        if ((nextLastActivity = [torrent dateActivity]))
1455            lastActivity = lastActivity ? [lastActivity laterDate: nextLastActivity] : nextLastActivity;
1456    }
1457   
1458    if (have == 0)
1459        [fHaveField setStringValue: [NSString stringForFileSize: 0]];
1460    else
1461    {
1462        NSString * verifiedString = [NSString stringWithFormat: NSLocalizedString(@"%@ verified", "Inspector -> Activity tab -> have"),
1463                                        [NSString stringForFileSize: haveVerified]];
1464        if (have == haveVerified)
1465            [fHaveField setStringValue: verifiedString];
1466        else
1467            [fHaveField setStringValue: [NSString stringWithFormat: @"%@ (%@)", [NSString stringForFileSize: have], verifiedString]];
1468    }
1469   
1470    [fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
1471    [fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
1472    [fFailedHashField setStringValue: [NSString stringForFileSize: failedHash]];
1473   
1474    [fDateActivityField setObjectValue: lastActivity];
1475   
1476    if (numberSelected == 1)
1477    {
1478        Torrent * torrent = [fTorrents objectAtIndex: 0];
1479       
1480        [fStateField setStringValue: [torrent stateString]];
1481       
1482        if ([torrent isFolder])
1483            [fProgressField setStringValue: [NSString localizedStringWithFormat: NSLocalizedString(@"%.2f%% (%.2f%% selected)",
1484                "Inspector -> Activity tab -> progress"), 100.0 * [torrent progress], 100.0 * [torrent progressDone]]];
1485        else
1486            [fProgressField setStringValue: [NSString localizedStringWithFormat: @"%.2f%%", 100.0 * [torrent progress]]];
1487           
1488        [fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]];
1489       
1490        NSString * errorMessage = [torrent errorMessage];
1491        if (![errorMessage isEqualToString: [fErrorMessageView string]])
1492            [fErrorMessageView setString: errorMessage];
1493       
1494        [fDateCompletedField setObjectValue: [torrent dateCompleted]];
1495       
1496        [fPiecesView updateView];
1497    }
1498    else if (numberSelected > 1)
1499    {
1500        [fRatioField setStringValue: [NSString stringForRatio: tr_getRatio(uploadedTotal, downloadedTotal)]];
1501    }
1502    else;
1503}
1504
1505- (void) updateInfoTracker
1506{
1507    if ([fTorrents count] == 0)
1508        return;
1509   
1510    //get updated tracker stats
1511    if ([fTrackerTable editedRow] == -1)
1512    {
1513        [fTrackers release];
1514       
1515        if ([fTorrents count] == 1)
1516            fTrackers = [[[fTorrents objectAtIndex: 0] allTrackerStats] retain];
1517        else
1518        {
1519            fTrackers = [[NSMutableArray alloc] init];
1520            for (Torrent * torrent in fTorrents)
1521                [fTrackers addObjectsFromArray: [torrent allTrackerStats]];
1522        }
1523       
1524        [fTrackerTable setTrackers: fTrackers];
1525        [fTrackerTable reloadData];
1526    }
1527    else
1528    {
1529        NSAssert1([fTorrents count] == 1, @"Attempting to add tracker with %d transfers selected", [fTorrents count]);
1530       
1531        if ([NSApp isOnSnowLeopardOrBetter])
1532        {
1533            NSIndexSet * addedIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange([fTrackers count]-2, 2)];
1534            NSArray * tierAndTrackerBeingAdded = [fTrackers objectsAtIndexes: addedIndexes];
1535           
1536            [fTrackers release];
1537            fTrackers = [[[fTorrents objectAtIndex: 0] allTrackerStats] retain];
1538            [fTrackers addObjectsFromArray: tierAndTrackerBeingAdded];
1539           
1540            [fTrackerTable setTrackers: fTrackers];
1541           
1542            NSIndexSet * updateIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTrackers count]-2)],
1543                    * columnIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [[fTrackerTable tableColumns] count])];
1544            [fTrackerTable reloadDataForRowIndexes: updateIndexes columnIndexes: columnIndexes];
1545        }
1546    }
1547}
1548
1549- (void) updateInfoPeers
1550{
1551    if ([fTorrents count] == 0)
1552        return;
1553   
1554    if (!fPeers)
1555        fPeers = [[NSMutableArray alloc] init];
1556    else
1557        [fPeers removeAllObjects];
1558   
1559    if (!fWebSeeds)
1560        fWebSeeds = [[NSMutableArray alloc] init];
1561    else
1562        [fWebSeeds removeAllObjects];
1563   
1564    NSUInteger known = 0, connected = 0, tracker = 0, incoming = 0, cache = 0, pex = 0, dht = 0, ltep = 0,
1565                toUs = 0, fromUs = 0;
1566    BOOL anyActive = false;
1567    for (Torrent * torrent in fTorrents)
1568    {
1569        if ([torrent webSeedCount] > 0)
1570            [fWebSeeds addObjectsFromArray: [torrent webSeeds]];
1571       
1572        known += [torrent totalPeersKnown];
1573       
1574        if ([torrent isActive])
1575        {
1576            anyActive = YES;
1577            [fPeers addObjectsFromArray: [torrent peers]];
1578           
1579            const NSUInteger connectedThis = [torrent totalPeersConnected];
1580            if (connectedThis > 0)
1581            {
1582                connected += [torrent totalPeersConnected];
1583                tracker += [torrent totalPeersTracker];
1584                incoming += [torrent totalPeersIncoming];
1585                cache += [torrent totalPeersCache];
1586                pex += [torrent totalPeersPex];
1587                dht += [torrent totalPeersDHT];
1588                ltep += [torrent totalPeersLTEP];
1589               
1590                toUs += [torrent peersSendingToUs];
1591                fromUs += [torrent peersGettingFromUs];
1592            }
1593        }
1594    }
1595   
1596    [fPeers sortUsingDescriptors: [self peerSortDescriptors]];
1597    [fPeerTable reloadData];
1598   
1599    [fWebSeeds sortUsingDescriptors: [fWebSeedTable sortDescriptors]];
1600    [fWebSeedTable reloadData];
1601   
1602    NSString * knownString = [NSString stringWithFormat: NSLocalizedString(@"%d known", "Inspector -> Peers tab -> peers"), known];
1603    if (anyActive)
1604    {
1605        NSString * connectedText = [NSString stringWithFormat: NSLocalizedString(@"%d Connected", "Inspector -> Peers tab -> peers"),
1606                                    connected];
1607       
1608        if (connected > 0)
1609        {
1610            NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 6];
1611            if (tracker > 0)
1612                [fromComponents addObject: [NSString stringWithFormat:
1613                                        NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), tracker]];
1614            if (incoming > 0)
1615                [fromComponents addObject: [NSString stringWithFormat:
1616                                        NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), incoming]];
1617            if (cache > 0)
1618                [fromComponents addObject: [NSString stringWithFormat:
1619                                        NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), cache]];
1620            if (pex > 0)
1621                [fromComponents addObject: [NSString stringWithFormat:
1622                                        NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), pex]];
1623            if (dht > 0)
1624                [fromComponents addObject: [NSString stringWithFormat:
1625                                        NSLocalizedString(@"%d DHT", "Inspector -> Peers tab -> peers"), dht]];
1626            if (ltep > 0)
1627                [fromComponents addObject: [NSString stringWithFormat:
1628                                        NSLocalizedString(@"%d LTEP", "Inspector -> Peers tab -> peers"), ltep]];
1629           
1630            NSMutableArray * upDownComponents = [NSMutableArray arrayWithCapacity: 3];
1631            if (toUs > 0)
1632                [upDownComponents addObject: [NSString stringWithFormat:
1633                                        NSLocalizedString(@"DL from %d", "Inspector -> Peers tab -> peers"), toUs]];
1634            if (fromUs > 0)
1635                [upDownComponents addObject: [NSString stringWithFormat:
1636                                        NSLocalizedString(@"UL to %d", "Inspector -> Peers tab -> peers"), fromUs]];
1637            [upDownComponents addObject: knownString];
1638           
1639            connectedText = [connectedText stringByAppendingFormat: @": %@\n%@", [fromComponents componentsJoinedByString: @", "],
1640                                [upDownComponents componentsJoinedByString: @", "]];
1641        }
1642        else
1643            connectedText = [connectedText stringByAppendingFormat: @"\n%@", knownString];
1644       
1645        [fConnectedPeersField setStringValue: connectedText];
1646    }
1647    else
1648    {
1649        NSString * activeString;
1650        if ([fTorrents count] == 1)
1651            activeString = NSLocalizedString(@"Transfer Not Active", "Inspector -> Peers tab -> peers");
1652        else
1653            activeString = NSLocalizedString(@"Transfers Not Active", "Inspector -> Peers tab -> peers");
1654       
1655        NSString * connectedText = [activeString stringByAppendingFormat: @"\n%@", knownString];
1656        [fConnectedPeersField setStringValue: connectedText];
1657    }
1658}
1659
1660- (void) updateInfoFiles
1661{
1662    if ([fTorrents count] == 1)
1663        [fFileController reloadData];
1664}
1665
1666- (NSView *) tabViewForTag: (NSInteger) tag
1667{
1668    switch (tag)
1669    {
1670        case TAB_INFO_TAG:
1671            return fInfoView;
1672        case TAB_ACTIVITY_TAG:
1673            return fActivityView;
1674        case TAB_TRACKER_TAG:
1675            return fTrackerView;
1676        case TAB_PEERS_TAG:
1677            return fPeersView;
1678        case TAB_FILES_TAG:
1679            return fFilesView;
1680        case TAB_OPTIONS_TAG:
1681            return fOptionsView;
1682        default:
1683            NSAssert1(NO, @"Unknown tab view for tag: %d", tag);
1684            return nil;
1685    }
1686}
1687
1688- (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate
1689{
1690    if (fCurrentTabTag != TAB_PEERS_TAG || ![[self window] isVisible])
1691        animate = NO;
1692   
1693    if (fWebSeedTableAnimation)
1694    {
1695        [fWebSeedTableAnimation stopAnimation];
1696        [fWebSeedTableAnimation release];
1697        fWebSeedTableAnimation = nil;
1698    }
1699   
1700    NSRect webSeedFrame = [[fWebSeedTable enclosingScrollView] frame];
1701    NSRect peerFrame = [[fPeerTable enclosingScrollView] frame];
1702   
1703    if (hide)
1704    {
1705        CGFloat webSeedFrameMaxY = NSMaxY(webSeedFrame);
1706        webSeedFrame.size.height = 0;
1707        webSeedFrame.origin.y = webSeedFrameMaxY;
1708       
1709        peerFrame.size.height = webSeedFrameMaxY - peerFrame.origin.y;
1710    }
1711    else
1712    {
1713        webSeedFrame.origin.y -= fWebSeedTableHeight - webSeedFrame.size.height;
1714        webSeedFrame.size.height = fWebSeedTableHeight;
1715       
1716        peerFrame.size.height = (webSeedFrame.origin.y - fSpaceBetweenWebSeedAndPeer) - peerFrame.origin.y;
1717    }
1718   
1719    [[fWebSeedTable enclosingScrollView] setHidden: NO]; //this is needed for some reason
1720   
1721    //actually resize tables
1722    if (animate)
1723    {
1724        NSDictionary * webSeedDict = [NSDictionary dictionaryWithObjectsAndKeys:
1725                                    [fWebSeedTable enclosingScrollView], NSViewAnimationTargetKey,
1726                                    [NSValue valueWithRect: [[fWebSeedTable enclosingScrollView] frame]], NSViewAnimationStartFrameKey,
1727                                    [NSValue valueWithRect: webSeedFrame], NSViewAnimationEndFrameKey, nil],
1728                    * peerDict = [NSDictionary dictionaryWithObjectsAndKeys:
1729                                    [fPeerTable enclosingScrollView], NSViewAnimationTargetKey,
1730                                    [NSValue valueWithRect: [[fPeerTable enclosingScrollView] frame]], NSViewAnimationStartFrameKey,
1731                                    [NSValue valueWithRect: peerFrame], NSViewAnimationEndFrameKey, nil];
1732       
1733        fWebSeedTableAnimation = [[NSViewAnimation alloc] initWithViewAnimations:
1734                                        [NSArray arrayWithObjects: webSeedDict, peerDict, nil]];
1735        [fWebSeedTableAnimation setDuration: 0.125];
1736        [fWebSeedTableAnimation setAnimationBlockingMode: NSAnimationNonblocking];
1737        [fWebSeedTableAnimation setDelegate: self];
1738       
1739        [fWebSeedTableAnimation startAnimation];
1740    }
1741    else
1742    {
1743        [[fWebSeedTable enclosingScrollView] setFrame: webSeedFrame];
1744        [[fPeerTable enclosingScrollView] setFrame: peerFrame];
1745    }
1746}
1747
1748- (NSArray *) peerSortDescriptors
1749{
1750    NSMutableArray * descriptors = [NSMutableArray arrayWithCapacity: 2];
1751   
1752    NSArray * oldDescriptors = [fPeerTable sortDescriptors];
1753    BOOL useSecond = YES, asc = YES;
1754    if ([oldDescriptors count] > 0)
1755    {
1756        NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0];
1757        [descriptors addObject: descriptor];
1758       
1759        if ((useSecond = ![[descriptor key] isEqualToString: @"IP"]))
1760            asc = [descriptor ascending];
1761    }
1762   
1763    //sort by IP after primary sort
1764    if (useSecond)
1765    {
1766        NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc
1767                                                                        selector: @selector(compareNumeric:)];
1768        [descriptors addObject: secondDescriptor];
1769        [secondDescriptor release];
1770    }
1771   
1772    return descriptors;
1773}
1774
1775- (BOOL) canQuickLookFile: (FileListNode *) item
1776{
1777    Torrent * torrent = [fTorrents objectAtIndex: 0];
1778    return ([item isFolder] || [torrent fileProgress: item] >= 1.0) && [torrent fileLocation: item];
1779}
1780
1781#warning doesn't like blank addresses
1782- (void) addTrackers
1783{
1784    [[self window] makeKeyWindow];
1785   
1786    [fTrackers addObject: NSLocalizedString(@"New Tier", "inspector -> add tracker")];
1787    [fTrackers addObject: @""];
1788   
1789    [fTrackerTable setTrackers: fTrackers];
1790    [fTrackerTable reloadData];
1791    [fTrackerTable selectRowIndexes: [NSIndexSet indexSetWithIndex: [fTrackers count]-1] byExtendingSelection: NO];
1792    [fTrackerTable editColumn: [fTrackerTable columnWithIdentifier: @"Tracker"] row: [fTrackers count]-1 withEvent: nil select: YES];
1793}
1794
1795- (void) removeTrackers
1796{
1797    NSMutableIndexSet * removeIdentifiers = [NSMutableIndexSet indexSet];
1798   
1799    NSIndexSet * selectedIndexes = [fTrackerTable selectedRowIndexes];
1800    BOOL groupSelected = NO;
1801    for (NSUInteger i = 0; i < [fTrackers count]; ++i)
1802    {
1803        id object = [fTrackers objectAtIndex: i];
1804        if ([object isKindOfClass: [TrackerNode class]])
1805        {
1806            if (groupSelected || [selectedIndexes containsIndex: i])
1807                [removeIdentifiers addIndex: [(TrackerNode *)object identifier]];
1808        }
1809        else
1810        {
1811            groupSelected = [selectedIndexes containsIndex: i];
1812            if (!groupSelected && i > [selectedIndexes lastIndex])
1813                break;
1814        }
1815    }
1816   
1817    NSAssert([removeIdentifiers count] > 0, @"Trying to remove no trackers.");
1818   
1819    if ([[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveTrackers"])
1820    {
1821        NSAlert * alert = [[NSAlert alloc] init];
1822       
1823        if ([removeIdentifiers count] > 1)
1824        {
1825            [alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?",
1826                                                                "Remove trackers alert -> title"), [removeIdentifiers count]]];
1827            [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them."
1828                                        " This cannot be undone.", "Remove trackers alert -> message")];
1829        }
1830        else
1831        {
1832            [alert setMessageText: NSLocalizedString(@"Are you sure you want to remove this tracker?", "Remove trackers alert -> title")];
1833            [alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact it."
1834                                        " This cannot be undone.", "Remove trackers alert -> message")];
1835        }
1836       
1837        [alert addButtonWithTitle: NSLocalizedString(@"Remove", "Remove trackers alert -> button")];
1838        [alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Remove trackers alert -> button")];
1839       
1840        [alert setShowsSuppressionButton: YES];
1841
1842        NSInteger result = [alert runModal];
1843        if ([[alert suppressionButton] state] == NSOnState)
1844            [[NSUserDefaults standardUserDefaults] setBool: NO forKey: @"WarningRemoveTrackers"];
1845        [alert release];
1846       
1847        if (result != NSAlertFirstButtonReturn)
1848            return;
1849    }
1850   
1851    Torrent * torrent = [fTorrents objectAtIndex: 0];
1852    [torrent removeTrackersWithIdentifiers: removeIdentifiers];
1853   
1854    //reset table with either new or old value
1855    [fTrackers release];
1856    fTrackers = [[torrent allTrackerStats] retain];
1857   
1858    [fTrackerTable setTrackers: fTrackers];
1859    [fTrackerTable reloadData];
1860    [fTrackerTable deselectAll: self];
1861   
1862    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; //incase sort by tracker
1863}
1864
1865@end
Note: See TracBrowser for help on using the repository browser.