2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2009-01-10 23:37:37 +00:00
|
|
|
* Copyright (c) 2006-2009 Transmission authors and contributors
|
2007-09-16 01:02:06 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#import "InfoWindowController.h"
|
2008-05-22 18:39:49 +00:00
|
|
|
#import "FileListNode.h"
|
2009-09-26 04:02:39 +00:00
|
|
|
#import "FileOutlineController.h"
|
|
|
|
#import "FileOutlineView.h"
|
|
|
|
#import "InfoTabButtonCell.h"
|
2009-08-29 23:16:25 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
2009-09-26 04:02:39 +00:00
|
|
|
#import "PeerProgressIndicatorCell.h"
|
|
|
|
#import "PiecesView.h"
|
|
|
|
#import "Torrent.h"
|
2009-09-28 01:57:35 +00:00
|
|
|
#import "TrackerCell.h"
|
2009-09-26 04:02:39 +00:00
|
|
|
#import "TrackerNode.h"
|
|
|
|
#import "TrackerTableView.h"
|
2008-10-16 03:44:54 +00:00
|
|
|
#include "utils.h" //tr_getRatio()
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
#define TAB_INFO_IDENT @"Info"
|
|
|
|
#define TAB_ACTIVITY_IDENT @"Activity"
|
2008-02-22 01:36:30 +00:00
|
|
|
#define TAB_TRACKER_IDENT @"Tracker"
|
2007-09-16 01:02:06 +00:00
|
|
|
#define TAB_PEERS_IDENT @"Peers"
|
|
|
|
#define TAB_FILES_IDENT @"Files"
|
|
|
|
#define TAB_OPTIONS_IDENT @"Options"
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
#define TAB_MIN_HEIGHT 250
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
#define TRACKER_GROUP_SEPARATOR_HEIGHT 14.0
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#define PIECES_CONTROL_PROGRESS 0
|
|
|
|
#define PIECES_CONTROL_AVAILABLE 1
|
|
|
|
|
|
|
|
#define OPTION_POPUP_GLOBAL 0
|
|
|
|
#define OPTION_POPUP_NO_LIMIT 1
|
|
|
|
#define OPTION_POPUP_LIMIT 2
|
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
#define OPTION_POPUP_PRIORITY_HIGH 0
|
|
|
|
#define OPTION_POPUP_PRIORITY_NORMAL 1
|
|
|
|
#define OPTION_POPUP_PRIORITY_LOW 2
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
#define INVALID -99
|
|
|
|
|
2008-06-02 17:26:02 +00:00
|
|
|
#define TRACKER_ADD_TAG 0
|
|
|
|
#define TRACKER_REMOVE_TAG 1
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
TAB_INFO_TAG = 0,
|
2007-12-17 16:06:20 +00:00
|
|
|
TAB_ACTIVITY_TAG = 1,
|
2008-02-22 01:36:30 +00:00
|
|
|
TAB_TRACKER_TAG = 2,
|
|
|
|
TAB_PEERS_TAG = 3,
|
|
|
|
TAB_FILES_TAG = 4,
|
|
|
|
TAB_OPTIONS_TAG = 5
|
2007-10-06 22:23:44 +00:00
|
|
|
} tabTag;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@interface InfoWindowController (Private)
|
|
|
|
|
|
|
|
- (void) updateInfoGeneral;
|
|
|
|
- (void) updateInfoActivity;
|
2008-02-22 01:36:30 +00:00
|
|
|
- (void) updateInfoTracker;
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) updateInfoPeers;
|
|
|
|
- (void) updateInfoFiles;
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSView *) tabViewForTag: (NSInteger) tag;
|
2008-06-08 21:13:35 +00:00
|
|
|
- (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate;
|
2008-06-22 01:31:50 +00:00
|
|
|
- (NSArray *) peerSortDescriptors;
|
|
|
|
|
|
|
|
- (BOOL) canQuickLookFile: (FileListNode *) item;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-09-29 03:02:44 +00:00
|
|
|
- (void) addTrackers;
|
|
|
|
- (void) removeTrackers;
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoWindowController
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
2009-09-28 01:57:35 +00:00
|
|
|
if ((self = [super initWithWindowNibName: @"InfoWindow"]))
|
|
|
|
{
|
|
|
|
fTrackerCell = [[TrackerCell alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2007-10-07 12:24:26 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 02:25:58 +00:00
|
|
|
- (void) awakeFromNib
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
//window location and size
|
|
|
|
NSPanel * window = (NSPanel *)[self window];
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat windowHeight = [window frame].size.height;
|
2007-10-07 12:24:26 +00:00
|
|
|
|
|
|
|
[window setFrameAutosaveName: @"InspectorWindow"];
|
|
|
|
[window setFrameUsingName: @"InspectorWindow"];
|
|
|
|
|
|
|
|
NSRect windowRect = [window frame];
|
|
|
|
windowRect.origin.y -= windowHeight - windowRect.size.height;
|
|
|
|
windowRect.size.height = windowHeight;
|
|
|
|
[window setFrame: windowRect display: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[window setBecomesKeyOnlyIfNeeded: YES];
|
|
|
|
|
2007-10-07 02:31:36 +00:00
|
|
|
//set tab images and tooltips
|
|
|
|
[[fTabMatrix cellWithTag: TAB_INFO_TAG] setIcon: [NSImage imageNamed: @"InfoGeneral.png"]];
|
2007-10-08 03:59:08 +00:00
|
|
|
[[fTabMatrix cellWithTag: TAB_ACTIVITY_TAG] setIcon: [NSImage imageNamed: @"InfoActivity.png"]];
|
2008-02-22 04:37:52 +00:00
|
|
|
[[fTabMatrix cellWithTag: TAB_TRACKER_TAG] setIcon: [NSImage imageNamed: @"InfoTracker.png"]];
|
2007-10-08 03:59:08 +00:00
|
|
|
[[fTabMatrix cellWithTag: TAB_PEERS_TAG] setIcon: [NSImage imageNamed: @"InfoPeers.png"]];
|
|
|
|
[[fTabMatrix cellWithTag: TAB_FILES_TAG] setIcon: [NSImage imageNamed: @"InfoFiles.png"]];
|
2007-10-07 02:31:36 +00:00
|
|
|
[[fTabMatrix cellWithTag: TAB_OPTIONS_TAG] setIcon: [NSImage imageNamed: @"InfoOptions.png"]];
|
|
|
|
|
2007-10-06 22:23:44 +00:00
|
|
|
//set selected tab
|
2007-10-07 02:25:39 +00:00
|
|
|
fCurrentTabTag = INVALID;
|
2007-09-16 01:02:06 +00:00
|
|
|
NSString * identifier = [[NSUserDefaults standardUserDefaults] stringForKey: @"InspectorSelected"];
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger tag;
|
2007-10-06 22:23:44 +00:00
|
|
|
if ([identifier isEqualToString: TAB_INFO_IDENT])
|
|
|
|
tag = TAB_INFO_TAG;
|
|
|
|
else if ([identifier isEqualToString: TAB_ACTIVITY_IDENT])
|
|
|
|
tag = TAB_ACTIVITY_TAG;
|
2008-02-22 01:36:30 +00:00
|
|
|
else if ([identifier isEqualToString: TAB_TRACKER_IDENT])
|
|
|
|
tag = TAB_TRACKER_TAG;
|
2007-10-06 22:23:44 +00:00
|
|
|
else if ([identifier isEqualToString: TAB_PEERS_IDENT])
|
|
|
|
tag = TAB_PEERS_TAG;
|
|
|
|
else if ([identifier isEqualToString: TAB_FILES_IDENT])
|
|
|
|
tag = TAB_FILES_TAG;
|
|
|
|
else if ([identifier isEqualToString: TAB_OPTIONS_IDENT])
|
|
|
|
tag = TAB_OPTIONS_TAG;
|
|
|
|
else //safety
|
|
|
|
{
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject: TAB_INFO_IDENT forKey: @"InspectorSelected"];
|
|
|
|
tag = TAB_INFO_TAG;
|
|
|
|
}
|
|
|
|
[fTabMatrix selectCellWithTag: tag];
|
|
|
|
[self setTab: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-08-29 23:16:25 +00:00
|
|
|
if (![NSApp isOnSnowLeopardOrBetter])
|
|
|
|
{
|
2009-10-26 02:02:25 +00:00
|
|
|
//reset images for reveal button, since the images are also used in the main table
|
|
|
|
NSImage * revealOn = [[NSImage imageNamed: @"RevealOn.png"] copy],
|
|
|
|
* revealOff = [[NSImage imageNamed: @"RevealOff.png"] copy];
|
|
|
|
|
2009-08-29 23:16:25 +00:00
|
|
|
[revealOn setFlipped: NO];
|
|
|
|
[revealOff setFlipped: NO];
|
2009-10-26 02:02:25 +00:00
|
|
|
|
|
|
|
[fRevealDataButton setImage: revealOff];
|
|
|
|
[fRevealDataButton setAlternateImage: revealOn];
|
|
|
|
|
|
|
|
[revealOn release];
|
|
|
|
[revealOff release];
|
2009-08-29 23:16:25 +00:00
|
|
|
}
|
2008-01-15 21:49:40 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//initially sort peer table by IP
|
|
|
|
if ([[fPeerTable sortDescriptors] count] == 0)
|
|
|
|
[fPeerTable setSortDescriptors: [NSArray arrayWithObject: [[fPeerTable tableColumnWithIdentifier: @"IP"]
|
|
|
|
sortDescriptorPrototype]]];
|
|
|
|
|
2008-06-08 15:54:34 +00:00
|
|
|
//initially sort webseed table by address
|
|
|
|
if ([[fWebSeedTable sortDescriptors] count] == 0)
|
|
|
|
[fWebSeedTable setSortDescriptors: [NSArray arrayWithObject: [[fWebSeedTable tableColumnWithIdentifier: @"Address"]
|
|
|
|
sortDescriptorPrototype]]];
|
|
|
|
|
2007-11-17 16:22:50 +00:00
|
|
|
//set table header tool tips
|
2008-12-26 05:57:51 +00:00
|
|
|
[[fPeerTable tableColumnWithIdentifier: @"Encryption"] setHeaderToolTip: NSLocalizedString(@"Encrypted Connection",
|
|
|
|
"inspector -> peer table -> header tool tip")];
|
|
|
|
[[fPeerTable tableColumnWithIdentifier: @"Progress"] setHeaderToolTip: NSLocalizedString(@"Available",
|
|
|
|
"inspector -> peer table -> header tool tip")];
|
|
|
|
[[fPeerTable tableColumnWithIdentifier: @"UL To"] setHeaderToolTip: NSLocalizedString(@"Uploading To Peer",
|
|
|
|
"inspector -> peer table -> header tool tip")];
|
|
|
|
[[fPeerTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Peer",
|
|
|
|
"inspector -> peer table -> header tool tip")];
|
|
|
|
|
|
|
|
[[fWebSeedTable tableColumnWithIdentifier: @"DL From"] setHeaderToolTip: NSLocalizedString(@"Downloading From Web Seed",
|
|
|
|
"inspector -> web seed table -> header tool tip")];
|
2007-11-17 16:22:50 +00:00
|
|
|
|
2008-06-08 01:17:36 +00:00
|
|
|
//prepare for animating peer table and web seed table
|
2008-06-08 02:10:10 +00:00
|
|
|
NSRect webSeedTableFrame = [[fWebSeedTable enclosingScrollView] frame];
|
|
|
|
fWebSeedTableHeight = webSeedTableFrame.size.height;
|
|
|
|
fSpaceBetweenWebSeedAndPeer = webSeedTableFrame.origin.y - NSMaxY([[fPeerTable enclosingScrollView] frame]);
|
2008-06-08 01:17:36 +00:00
|
|
|
|
2008-06-08 21:13:35 +00:00
|
|
|
[self setWebSeedTableHidden: YES animate: NO];
|
2008-06-08 01:17:36 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//set blank inspector
|
2007-10-29 18:07:09 +00:00
|
|
|
[self setInfoForTorrents: [NSArray array]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//allow for update notifications
|
|
|
|
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
|
|
|
[nc addObserver: self selector: @selector(updateInfoStats) name: @"UpdateStats" object: nil];
|
2007-10-29 18:07:09 +00:00
|
|
|
[nc addObserver: self selector: @selector(updateOptions) name: @"UpdateOptions" object: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-10-07 12:24:26 +00:00
|
|
|
//save resizeable view height
|
2008-02-27 01:57:13 +00:00
|
|
|
NSString * resizeSaveKey = nil;
|
|
|
|
switch (fCurrentTabTag)
|
|
|
|
{
|
|
|
|
case TAB_TRACKER_TAG:
|
|
|
|
resizeSaveKey = @"InspectorContentHeightTracker";
|
|
|
|
break;
|
|
|
|
case TAB_PEERS_TAG:
|
|
|
|
resizeSaveKey = @"InspectorContentHeightPeers";
|
|
|
|
break;
|
|
|
|
case TAB_FILES_TAG:
|
|
|
|
resizeSaveKey = @"InspectorContentHeightFiles";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (resizeSaveKey)
|
|
|
|
[[NSUserDefaults standardUserDefaults] setFloat: [[self tabViewForTag: fCurrentTabTag] frame].size.height forKey: resizeSaveKey];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
|
|
|
|
[fTorrents release];
|
|
|
|
[fPeers release];
|
2008-06-07 23:38:05 +00:00
|
|
|
[fWebSeeds release];
|
2008-02-27 13:52:43 +00:00
|
|
|
[fTrackers release];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-06-08 15:54:34 +00:00
|
|
|
[fWebSeedTableAnimation release];
|
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
[fTrackerCell release];
|
|
|
|
|
2009-09-04 04:10:46 +00:00
|
|
|
[fPreviewPanel release];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2007-10-29 18:07:09 +00:00
|
|
|
- (void) setInfoForTorrents: (NSArray *) torrents
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-02-27 13:59:26 +00:00
|
|
|
if (fTorrents && [fTorrents isEqualToArray: torrents])
|
|
|
|
return;
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fTorrents release];
|
|
|
|
fTorrents = [torrents retain];
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
NSUInteger numberSelected = [fTorrents count];
|
2007-09-16 01:02:06 +00:00
|
|
|
if (numberSelected != 1)
|
|
|
|
{
|
|
|
|
if (numberSelected > 0)
|
|
|
|
{
|
2008-12-26 05:57:51 +00:00
|
|
|
[fImageView setImage: [NSImage imageNamed: NSImageNameMultipleDocuments]];
|
2007-10-27 18:40:43 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fNameField setStringValue: [NSString stringWithFormat: NSLocalizedString(@"%d Torrents Selected",
|
2008-03-19 18:03:02 +00:00
|
|
|
"Inspector -> selected torrents"), numberSelected]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
uint64_t size = 0;
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger fileCount = 0;
|
2008-12-26 15:11:37 +00:00
|
|
|
for (Torrent * torrent in torrents)
|
2007-11-25 04:06:26 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
size += [torrent size];
|
2007-11-25 04:06:26 +00:00
|
|
|
fileCount += [torrent fileCount];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-03-18 22:11:43 +00:00
|
|
|
[fBasicInfoField setStringValue: [NSString stringWithFormat: @"%@, %@",
|
2008-04-07 13:25:55 +00:00
|
|
|
[NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount],
|
|
|
|
[NSString stringWithFormat: NSLocalizedString(@"%@ total", "Inspector -> selected torrents"),
|
2008-03-18 22:11:43 +00:00
|
|
|
[NSString stringForFileSize: size]]]];
|
2008-05-29 00:58:20 +00:00
|
|
|
[fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%llu bytes", "Inspector -> selected torrents"),
|
2008-03-19 18:03:02 +00:00
|
|
|
size]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-27 18:40:43 +00:00
|
|
|
[fImageView setImage: [NSImage imageNamed: @"NSApplicationIcon"]];
|
|
|
|
|
2008-03-19 18:03:02 +00:00
|
|
|
[fNameField setStringValue: NSLocalizedString(@"No Torrents Selected", "Inspector -> selected torrents")];
|
2007-11-25 04:06:26 +00:00
|
|
|
[fBasicInfoField setStringValue: @""];
|
2007-11-26 21:56:18 +00:00
|
|
|
[fBasicInfoField setToolTip: @""];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-09-26 03:27:00 +00:00
|
|
|
[fHaveField setStringValue: @""];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fDownloadedTotalField setStringValue: @""];
|
|
|
|
[fUploadedTotalField setStringValue: @""];
|
2007-09-26 18:32:32 +00:00
|
|
|
[fFailedHashField setStringValue: @""];
|
2008-03-06 16:13:05 +00:00
|
|
|
[fDateActivityField setStringValue: @""];
|
2008-10-16 03:44:54 +00:00
|
|
|
[fRatioField setStringValue: @""];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//options fields
|
2009-03-05 01:10:09 +00:00
|
|
|
[fUploadLimitCheck setEnabled: NO];
|
|
|
|
[fUploadLimitCheck setState: NSOffState];
|
|
|
|
[fUploadLimitField setEnabled: NO];
|
|
|
|
[fUploadLimitLabel setEnabled: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fUploadLimitField setStringValue: @""];
|
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
[fDownloadLimitCheck setEnabled: NO];
|
|
|
|
[fDownloadLimitCheck setState: NSOffState];
|
|
|
|
[fDownloadLimitField setEnabled: NO];
|
|
|
|
[fDownloadLimitLabel setEnabled: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fDownloadLimitField setStringValue: @""];
|
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
[fGlobalLimitCheck setEnabled: NO];
|
|
|
|
[fGlobalLimitCheck setState: NSOffState];
|
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
[fPriorityPopUp setEnabled: NO];
|
|
|
|
[fPriorityPopUp selectItemAtIndex: -1];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fRatioPopUp setEnabled: NO];
|
|
|
|
[fRatioPopUp selectItemAtIndex: -1];
|
|
|
|
[fRatioLimitField setHidden: YES];
|
|
|
|
[fRatioLimitField setStringValue: @""];
|
|
|
|
|
2007-12-22 05:21:25 +00:00
|
|
|
[fPeersConnectField setEnabled: NO];
|
2007-12-23 17:35:42 +00:00
|
|
|
[fPeersConnectField setStringValue: @""];
|
2008-06-17 21:18:00 +00:00
|
|
|
[fPeersConnectLabel setEnabled: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
[fFileController setTorrent: nil];
|
2007-10-20 19:13:52 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fNameField setToolTip: nil];
|
|
|
|
|
|
|
|
[fPiecesField setStringValue: @""];
|
|
|
|
[fHashField setStringValue: @""];
|
|
|
|
[fHashField setToolTip: nil];
|
|
|
|
[fSecureField setStringValue: @""];
|
|
|
|
[fCommentView setString: @""];
|
|
|
|
|
|
|
|
[fCreatorField setStringValue: @""];
|
|
|
|
[fDateCreatedField setStringValue: @""];
|
|
|
|
[fCommentView setSelectable: NO];
|
|
|
|
|
|
|
|
[fDataLocationField setStringValue: @""];
|
|
|
|
[fDataLocationField setToolTip: nil];
|
|
|
|
|
|
|
|
[fRevealDataButton setHidden: YES];
|
|
|
|
|
|
|
|
//don't allow empty fields to be selected
|
|
|
|
[fHashField setSelectable: NO];
|
|
|
|
[fCreatorField setSelectable: NO];
|
|
|
|
[fDataLocationField setSelectable: NO];
|
|
|
|
|
|
|
|
[fStateField setStringValue: @""];
|
|
|
|
[fProgressField setStringValue: @""];
|
|
|
|
|
|
|
|
[fSwarmSpeedField setStringValue: @""];
|
|
|
|
[fErrorMessageView setString: @""];
|
|
|
|
[fErrorMessageView setSelectable: NO];
|
|
|
|
|
2008-04-28 18:44:00 +00:00
|
|
|
[fConnectedPeersField setStringValue: @""];
|
2007-10-01 16:23:00 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
[fDateAddedField setStringValue: @""];
|
|
|
|
[fDateCompletedField setStringValue: @""];
|
|
|
|
|
|
|
|
[fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE];
|
|
|
|
[fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS];
|
|
|
|
[fPiecesControl setEnabled: NO];
|
|
|
|
[fPiecesView setTorrent: nil];
|
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
[fPeers release];
|
|
|
|
fPeers = nil;
|
2008-06-08 15:54:34 +00:00
|
|
|
[fPeerTable reloadData];
|
2008-02-27 13:52:43 +00:00
|
|
|
|
2008-06-07 23:38:05 +00:00
|
|
|
[fWebSeeds release];
|
|
|
|
fWebSeeds = nil;
|
2008-06-08 15:54:34 +00:00
|
|
|
[fWebSeedTable reloadData];
|
2008-06-08 21:13:35 +00:00
|
|
|
[self setWebSeedTableHidden: YES animate: YES];
|
2008-06-07 23:38:05 +00:00
|
|
|
|
2009-10-01 01:15:37 +00:00
|
|
|
[fTrackerTable setTorrent: nil];
|
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
[fTrackers release];
|
|
|
|
fTrackers = nil;
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2009-09-29 03:02:44 +00:00
|
|
|
[fTrackerTable setTrackers: fTrackers];
|
2009-09-26 04:02:39 +00:00
|
|
|
[fTrackerTable reloadData];
|
|
|
|
|
2008-06-02 17:26:02 +00:00
|
|
|
[fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_ADD_TAG];
|
|
|
|
[fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG];
|
2008-12-07 21:32:03 +00:00
|
|
|
|
|
|
|
[fFileFilterField setEnabled: NO];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
2008-06-08 01:17:36 +00:00
|
|
|
{
|
2007-09-16 01:02:06 +00:00
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
[fFileController setTorrent: torrent];
|
2007-10-20 19:13:52 +00:00
|
|
|
|
2009-09-16 01:16:12 +00:00
|
|
|
if ([NSApp isOnSnowLeopardOrBetter])
|
|
|
|
[fImageView setImage: [torrent icon]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSImage * icon = [[torrent icon] copy];
|
|
|
|
[icon setFlipped: NO];
|
|
|
|
[fImageView setImage: icon];
|
|
|
|
[icon release];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
NSString * name = [torrent name];
|
|
|
|
[fNameField setStringValue: name];
|
|
|
|
[fNameField setToolTip: name];
|
2007-11-25 04:06:26 +00:00
|
|
|
|
|
|
|
NSString * basicString = [NSString stringForFileSize: [torrent size]];
|
2008-05-29 22:16:03 +00:00
|
|
|
if ([torrent isFolder])
|
2007-11-25 04:06:26 +00:00
|
|
|
{
|
|
|
|
NSString * fileString;
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger fileCount = [torrent fileCount];
|
2007-11-25 04:06:26 +00:00
|
|
|
if (fileCount == 1)
|
2008-04-07 13:25:55 +00:00
|
|
|
fileString = NSLocalizedString(@"1 file", "Inspector -> selected torrents");
|
2007-11-25 04:06:26 +00:00
|
|
|
else
|
2008-04-07 13:25:55 +00:00
|
|
|
fileString= [NSString stringWithFormat: NSLocalizedString(@"%d files", "Inspector -> selected torrents"), fileCount];
|
2008-03-18 22:11:43 +00:00
|
|
|
basicString = [NSString stringWithFormat: @"%@, %@", fileString, basicString];
|
2007-11-25 04:06:26 +00:00
|
|
|
}
|
|
|
|
[fBasicInfoField setStringValue: basicString];
|
2008-05-29 00:56:58 +00:00
|
|
|
[fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%llu bytes", "Inspector -> selected torrents"),
|
2008-03-19 18:03:02 +00:00
|
|
|
[torrent size]]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
NSString * hashString = [torrent hashString];
|
|
|
|
[fPiecesField setStringValue: [NSString stringWithFormat: @"%d, %@", [torrent pieceCount],
|
|
|
|
[NSString stringForFileSize: [torrent pieceSize]]]];
|
|
|
|
[fHashField setStringValue: hashString];
|
|
|
|
[fHashField setToolTip: hashString];
|
|
|
|
[fSecureField setStringValue: [torrent privateTorrent]
|
2009-05-19 22:51:37 +00:00
|
|
|
? NSLocalizedString(@"Private Torrent, PEX and DHT automatically disabled", "Inspector -> private torrent")
|
2007-12-24 05:05:56 +00:00
|
|
|
: NSLocalizedString(@"Public Torrent", "Inspector -> private torrent")];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
NSString * commentString = [torrent comment];
|
|
|
|
[fCommentView setString: commentString];
|
|
|
|
|
|
|
|
NSString * creatorString = [torrent creator];
|
|
|
|
[fCreatorField setStringValue: creatorString];
|
|
|
|
[fDateCreatedField setObjectValue: [torrent dateCreated]];
|
|
|
|
|
|
|
|
[fDateAddedField setObjectValue: [torrent dateAdded]];
|
|
|
|
|
|
|
|
//allow these fields to be selected
|
|
|
|
[fHashField setSelectable: YES];
|
|
|
|
[fCommentView setSelectable: ![commentString isEqualToString: @""]];
|
|
|
|
[fCreatorField setSelectable: ![creatorString isEqualToString: @""]];
|
|
|
|
|
|
|
|
//set pieces view
|
|
|
|
BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"];
|
|
|
|
[fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE];
|
|
|
|
[fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS];
|
|
|
|
[fPiecesControl setEnabled: YES];
|
|
|
|
[fPiecesView setTorrent: torrent];
|
2008-02-27 13:52:43 +00:00
|
|
|
|
2008-06-08 18:02:16 +00:00
|
|
|
//get webseeds for table - if no webseeds for this torrent, clear the table
|
2008-06-08 16:38:15 +00:00
|
|
|
BOOL hasWebSeeds = [torrent webSeedCount] > 0;
|
2008-06-08 21:13:35 +00:00
|
|
|
[self setWebSeedTableHidden: !hasWebSeeds animate: YES];
|
2008-06-08 16:38:15 +00:00
|
|
|
if (!hasWebSeeds)
|
|
|
|
{
|
|
|
|
[fWebSeeds release];
|
|
|
|
fWebSeeds = nil;
|
|
|
|
[fWebSeedTable reloadData];
|
|
|
|
}
|
2008-06-07 23:38:05 +00:00
|
|
|
|
2009-10-01 01:15:37 +00:00
|
|
|
[fTrackerTable setTorrent: torrent];
|
2008-06-02 17:26:02 +00:00
|
|
|
[fTrackerTable deselectAll: self];
|
|
|
|
[fTrackerAddRemoveControl setEnabled: YES forSegment: TRACKER_ADD_TAG];
|
|
|
|
[fTrackerAddRemoveControl setEnabled: NO forSegment: TRACKER_REMOVE_TAG];
|
2009-09-21 03:44:24 +00:00
|
|
|
|
2008-12-07 21:51:01 +00:00
|
|
|
[fFileFilterField setEnabled: [torrent isFolder]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-07 21:32:03 +00:00
|
|
|
[fFileFilterField setStringValue: @""];
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
//update stats and settings
|
|
|
|
[self updateInfoStats];
|
2007-10-29 18:07:09 +00:00
|
|
|
[self updateOptions];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfoStats
|
|
|
|
{
|
2007-10-06 22:23:44 +00:00
|
|
|
switch ([fTabMatrix selectedTag])
|
|
|
|
{
|
|
|
|
case TAB_INFO_TAG:
|
|
|
|
[self updateInfoGeneral];
|
|
|
|
break;
|
|
|
|
case TAB_ACTIVITY_TAG:
|
|
|
|
[self updateInfoActivity];
|
|
|
|
break;
|
2008-02-22 01:36:30 +00:00
|
|
|
case TAB_TRACKER_TAG:
|
|
|
|
[self updateInfoTracker];
|
|
|
|
break;
|
2007-10-06 22:23:44 +00:00
|
|
|
case TAB_PEERS_TAG:
|
|
|
|
[self updateInfoPeers];
|
|
|
|
break;
|
|
|
|
case TAB_FILES_TAG:
|
|
|
|
[self updateInfoFiles];
|
|
|
|
break;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-10-29 19:11:21 +00:00
|
|
|
- (void) updateOptions
|
|
|
|
{
|
|
|
|
if ([fTorrents count] == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
//get bandwidth info
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
Torrent * torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
NSInteger uploadUseSpeedLimit = [torrent usesSpeedLimit: YES] ? NSOnState : NSOffState,
|
2008-11-02 01:07:01 +00:00
|
|
|
uploadSpeedLimit = [torrent speedLimit: YES],
|
2009-03-05 01:10:09 +00:00
|
|
|
downloadUseSpeedLimit = [torrent usesSpeedLimit: NO] ? NSOnState : NSOffState,
|
|
|
|
downloadSpeedLimit = [torrent speedLimit: NO],
|
|
|
|
globalUseSpeedLimit = [torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState;
|
2007-10-29 19:11:21 +00:00
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject])
|
2009-03-05 01:10:09 +00:00
|
|
|
&& (uploadUseSpeedLimit != NSMixedState || uploadSpeedLimit != INVALID
|
|
|
|
|| downloadUseSpeedLimit != NSMixedState || downloadSpeedLimit != INVALID
|
|
|
|
|| globalUseSpeedLimit != NSMixedState))
|
2007-10-29 19:11:21 +00:00
|
|
|
{
|
2009-03-05 01:23:19 +00:00
|
|
|
if (uploadUseSpeedLimit != NSMixedState && uploadUseSpeedLimit != ([torrent usesSpeedLimit: YES] ? NSOnState : NSOffState))
|
2009-03-05 01:10:09 +00:00
|
|
|
uploadUseSpeedLimit = NSMixedState;
|
2007-10-29 19:11:21 +00:00
|
|
|
|
|
|
|
if (uploadSpeedLimit != INVALID && uploadSpeedLimit != [torrent speedLimit: YES])
|
|
|
|
uploadSpeedLimit = INVALID;
|
|
|
|
|
2009-03-05 01:23:19 +00:00
|
|
|
if (downloadUseSpeedLimit != NSMixedState && downloadUseSpeedLimit != ([torrent usesSpeedLimit: NO] ? NSOnState : NSOffState))
|
2009-03-05 01:10:09 +00:00
|
|
|
downloadUseSpeedLimit = NSMixedState;
|
2007-10-29 19:11:21 +00:00
|
|
|
|
|
|
|
if (downloadSpeedLimit != INVALID && downloadSpeedLimit != [torrent speedLimit: NO])
|
|
|
|
downloadSpeedLimit = INVALID;
|
2009-03-05 01:10:09 +00:00
|
|
|
|
2009-03-05 01:23:19 +00:00
|
|
|
if (globalUseSpeedLimit != NSMixedState && globalUseSpeedLimit != ([torrent usesGlobalSpeedLimit] ? NSOnState : NSOffState))
|
2009-03-05 01:10:09 +00:00
|
|
|
globalUseSpeedLimit = NSMixedState;
|
2007-10-29 19:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//set upload view
|
2009-03-05 01:10:09 +00:00
|
|
|
[fUploadLimitCheck setState: uploadUseSpeedLimit];
|
|
|
|
[fUploadLimitCheck setEnabled: YES];
|
2007-10-29 19:11:21 +00:00
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
[fUploadLimitLabel setEnabled: uploadUseSpeedLimit == NSOnState];
|
|
|
|
[fUploadLimitField setEnabled: uploadUseSpeedLimit == NSOnState];
|
2007-10-29 19:11:21 +00:00
|
|
|
if (uploadSpeedLimit != INVALID)
|
|
|
|
[fUploadLimitField setIntValue: uploadSpeedLimit];
|
|
|
|
else
|
|
|
|
[fUploadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
//set download view
|
2009-03-05 01:10:09 +00:00
|
|
|
[fDownloadLimitCheck setState: downloadUseSpeedLimit];
|
|
|
|
[fDownloadLimitCheck setEnabled: YES];
|
2007-10-29 19:11:21 +00:00
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
[fDownloadLimitLabel setEnabled: downloadUseSpeedLimit == NSOnState];
|
|
|
|
[fDownloadLimitField setEnabled: downloadUseSpeedLimit == NSOnState];
|
2007-10-29 19:11:21 +00:00
|
|
|
if (downloadSpeedLimit != INVALID)
|
|
|
|
[fDownloadLimitField setIntValue: downloadSpeedLimit];
|
|
|
|
else
|
|
|
|
[fDownloadLimitField setStringValue: @""];
|
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
//set global check
|
|
|
|
[fGlobalLimitCheck setState: globalUseSpeedLimit];
|
|
|
|
[fGlobalLimitCheck setEnabled: YES];
|
|
|
|
|
2007-10-29 19:11:21 +00:00
|
|
|
//get ratio info
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger checkRatio = [torrent ratioSetting];
|
|
|
|
CGFloat ratioLimit = [torrent ratioLimit];
|
2007-10-29 19:11:21 +00:00
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
while ((torrent = [enumerator nextObject]) && (checkRatio != INVALID || ratioLimit != INVALID))
|
2007-10-29 19:11:21 +00:00
|
|
|
{
|
|
|
|
if (checkRatio != INVALID && checkRatio != [torrent ratioSetting])
|
|
|
|
checkRatio = INVALID;
|
|
|
|
|
|
|
|
if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit])
|
|
|
|
ratioLimit = INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set ratio view
|
2009-03-05 01:10:09 +00:00
|
|
|
NSInteger index;
|
2009-02-14 21:15:57 +00:00
|
|
|
if (checkRatio == TR_RATIOLIMIT_SINGLE)
|
2007-10-29 19:11:21 +00:00
|
|
|
index = OPTION_POPUP_LIMIT;
|
2009-02-14 21:15:57 +00:00
|
|
|
else if (checkRatio == TR_RATIOLIMIT_UNLIMITED)
|
2007-10-29 19:11:21 +00:00
|
|
|
index = OPTION_POPUP_NO_LIMIT;
|
2009-02-14 21:15:57 +00:00
|
|
|
else if (checkRatio == TR_RATIOLIMIT_GLOBAL)
|
2007-10-29 19:11:21 +00:00
|
|
|
index = OPTION_POPUP_GLOBAL;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
[fRatioPopUp selectItemAtIndex: index];
|
|
|
|
[fRatioPopUp setEnabled: YES];
|
|
|
|
|
2009-02-14 21:15:57 +00:00
|
|
|
[fRatioLimitField setHidden: checkRatio != TR_RATIOLIMIT_SINGLE];
|
2007-10-29 19:11:21 +00:00
|
|
|
if (ratioLimit != INVALID)
|
|
|
|
[fRatioLimitField setFloatValue: ratioLimit];
|
|
|
|
else
|
|
|
|
[fRatioLimitField setStringValue: @""];
|
2007-12-22 05:21:25 +00:00
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
//get priority info
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
|
|
|
NSInteger priority = [torrent priority];
|
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject]) && priority != INVALID)
|
|
|
|
{
|
|
|
|
if (priority != INVALID && priority != [torrent priority])
|
|
|
|
priority = INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set priority view
|
|
|
|
if (priority == TR_PRI_HIGH)
|
|
|
|
index = OPTION_POPUP_PRIORITY_HIGH;
|
|
|
|
else if (priority == TR_PRI_NORMAL)
|
|
|
|
index = OPTION_POPUP_PRIORITY_NORMAL;
|
|
|
|
else if (priority == TR_PRI_LOW)
|
|
|
|
index = OPTION_POPUP_PRIORITY_LOW;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
[fPriorityPopUp selectItemAtIndex: index];
|
|
|
|
[fPriorityPopUp setEnabled: YES];
|
|
|
|
|
2007-12-22 05:21:25 +00:00
|
|
|
//get peer info
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger maxPeers = [torrent maxPeerConnect];
|
2007-12-22 05:21:25 +00:00
|
|
|
|
2007-12-25 19:08:06 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
2007-12-22 05:21:25 +00:00
|
|
|
{
|
2007-12-25 19:08:06 +00:00
|
|
|
if (maxPeers != [torrent maxPeerConnect])
|
|
|
|
{
|
2007-12-22 05:21:25 +00:00
|
|
|
maxPeers = INVALID;
|
2007-12-25 19:08:06 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-12-22 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//set peer view
|
|
|
|
[fPeersConnectField setEnabled: YES];
|
2008-06-17 21:18:00 +00:00
|
|
|
[fPeersConnectLabel setEnabled: YES];
|
2007-12-22 05:21:25 +00:00
|
|
|
if (maxPeers != INVALID)
|
|
|
|
[fPeersConnectField setIntValue: maxPeers];
|
|
|
|
else
|
|
|
|
[fPeersConnectField setStringValue: @""];
|
2007-10-29 19:11:21 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
- (NSRect) windowWillUseStandardFrame: (NSWindow *) window defaultFrame: (NSRect) defaultFrame
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-10-07 15:55:27 +00:00
|
|
|
NSRect windowRect = [window frame];
|
|
|
|
windowRect.size.width = [window minSize].width;
|
|
|
|
return windowRect;
|
|
|
|
}
|
|
|
|
|
2008-06-08 05:36:49 +00:00
|
|
|
- (void) animationDidEnd: (NSAnimation *) animation
|
2008-06-08 04:11:29 +00:00
|
|
|
{
|
2008-06-08 05:36:49 +00:00
|
|
|
if (animation == fWebSeedTableAnimation)
|
|
|
|
{
|
|
|
|
[fWebSeedTableAnimation release];
|
|
|
|
fWebSeedTableAnimation = nil;
|
|
|
|
}
|
2008-06-08 04:11:29 +00:00
|
|
|
}
|
|
|
|
|
2008-06-08 05:36:49 +00:00
|
|
|
- (NSSize) windowWillResize: (NSWindow *) window toSize: (NSSize) proposedFrameSize
|
2008-06-08 04:11:29 +00:00
|
|
|
{
|
2008-06-08 05:36:49 +00:00
|
|
|
//this is an edge-case - just stop the animation (stopAnimation jumps to end frame)
|
2008-06-08 04:11:29 +00:00
|
|
|
if (fWebSeedTableAnimation)
|
2008-06-08 05:36:49 +00:00
|
|
|
{
|
|
|
|
[fWebSeedTableAnimation stopAnimation];
|
|
|
|
[fWebSeedTableAnimation release];
|
|
|
|
fWebSeedTableAnimation = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return proposedFrameSize;
|
2008-06-08 04:11:29 +00:00
|
|
|
}
|
|
|
|
|
2009-10-11 23:50:13 +00:00
|
|
|
- (void) windowWillClose: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
if ([NSApp isOnSnowLeopardOrBetter] && fCurrentTabTag == TAB_FILES_TAG
|
|
|
|
&& ([QLPreviewPanelSL sharedPreviewPanelExists] && [[QLPreviewPanelSL sharedPreviewPanel] isVisible]))
|
|
|
|
[[QLPreviewPanelSL sharedPreviewPanel] reloadData];
|
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
- (void) setTab: (id) sender
|
|
|
|
{
|
2009-09-04 04:10:46 +00:00
|
|
|
const NSInteger oldTabTag = fCurrentTabTag;
|
2008-02-27 02:06:46 +00:00
|
|
|
fCurrentTabTag = [fTabMatrix selectedTag];
|
|
|
|
if (fCurrentTabTag == oldTabTag)
|
|
|
|
return;
|
2008-02-27 01:57:13 +00:00
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
[self updateInfoStats];
|
2008-02-27 01:57:13 +00:00
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
//take care of old view
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat oldHeight = 0;
|
2008-02-27 02:06:46 +00:00
|
|
|
NSString * oldResizeSaveKey = nil;
|
2008-02-27 01:57:13 +00:00
|
|
|
if (oldTabTag != INVALID)
|
2008-02-27 02:06:46 +00:00
|
|
|
{
|
|
|
|
//deselect old tab item
|
|
|
|
[(InfoTabButtonCell *)[fTabMatrix cellWithTag: oldTabTag] setSelectedTab: NO];
|
|
|
|
|
|
|
|
switch (oldTabTag)
|
|
|
|
{
|
2008-06-09 23:23:55 +00:00
|
|
|
case TAB_ACTIVITY_TAG:
|
|
|
|
[fPiecesView clearView];
|
|
|
|
break;
|
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
case TAB_TRACKER_TAG:
|
|
|
|
oldResizeSaveKey = @"InspectorContentHeightTracker";
|
|
|
|
break;
|
2008-06-09 23:23:55 +00:00
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
case TAB_PEERS_TAG:
|
2008-06-08 05:36:49 +00:00
|
|
|
//if in the middle of animating, just stop and resize immediately
|
|
|
|
if (fWebSeedTableAnimation)
|
2008-06-08 21:13:35 +00:00
|
|
|
[self setWebSeedTableHidden: !fWebSeeds animate: NO];
|
2008-06-08 05:36:49 +00:00
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
[fPeers release];
|
|
|
|
fPeers = nil;
|
2008-06-08 16:38:15 +00:00
|
|
|
[fWebSeeds release];
|
|
|
|
fWebSeeds = nil;
|
2008-02-27 13:52:43 +00:00
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
oldResizeSaveKey = @"InspectorContentHeightPeers";
|
|
|
|
break;
|
2008-06-09 23:23:55 +00:00
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
case TAB_FILES_TAG:
|
|
|
|
oldResizeSaveKey = @"InspectorContentHeightFiles";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSView * oldView = [self tabViewForTag: oldTabTag];
|
2008-02-27 01:57:13 +00:00
|
|
|
oldHeight = [oldView frame].size.height;
|
2008-02-27 02:06:46 +00:00
|
|
|
if (oldResizeSaveKey)
|
|
|
|
[[NSUserDefaults standardUserDefaults] setFloat: oldHeight forKey: oldResizeSaveKey];
|
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
//remove old view
|
2008-02-27 02:06:46 +00:00
|
|
|
[oldView setHidden: YES];
|
|
|
|
[oldView removeFromSuperview];
|
|
|
|
}
|
2008-02-27 01:57:13 +00:00
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
//set new tab item
|
|
|
|
NSView * view = [self tabViewForTag: fCurrentTabTag];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-02-27 13:52:43 +00:00
|
|
|
NSString * resizeSaveKey = nil;
|
2008-02-26 22:56:27 +00:00
|
|
|
NSString * identifier, * title;
|
2007-10-07 15:55:27 +00:00
|
|
|
switch (fCurrentTabTag)
|
|
|
|
{
|
|
|
|
case TAB_INFO_TAG:
|
|
|
|
identifier = TAB_INFO_IDENT;
|
2007-10-10 02:35:16 +00:00
|
|
|
title = NSLocalizedString(@"General Info", "Inspector -> title");
|
2007-10-07 15:55:27 +00:00
|
|
|
break;
|
|
|
|
case TAB_ACTIVITY_TAG:
|
|
|
|
identifier = TAB_ACTIVITY_IDENT;
|
2007-10-10 02:35:16 +00:00
|
|
|
title = NSLocalizedString(@"Activity", "Inspector -> title");
|
2007-10-07 15:55:27 +00:00
|
|
|
break;
|
2008-02-22 01:36:30 +00:00
|
|
|
case TAB_TRACKER_TAG:
|
|
|
|
identifier = TAB_TRACKER_IDENT;
|
|
|
|
title = NSLocalizedString(@"Tracker", "Inspector -> title");
|
2008-02-27 01:57:13 +00:00
|
|
|
resizeSaveKey = @"InspectorContentHeightTracker";
|
2008-02-22 01:36:30 +00:00
|
|
|
break;
|
2007-10-07 15:55:27 +00:00
|
|
|
case TAB_PEERS_TAG:
|
|
|
|
identifier = TAB_PEERS_IDENT;
|
2007-10-10 02:35:16 +00:00
|
|
|
title = NSLocalizedString(@"Peers", "Inspector -> title");
|
2008-02-27 01:57:13 +00:00
|
|
|
resizeSaveKey = @"InspectorContentHeightPeers";
|
2007-10-07 15:55:27 +00:00
|
|
|
break;
|
|
|
|
case TAB_FILES_TAG:
|
|
|
|
identifier = TAB_FILES_IDENT;
|
2007-10-10 02:35:16 +00:00
|
|
|
title = NSLocalizedString(@"Files", "Inspector -> title");
|
2008-02-27 01:57:13 +00:00
|
|
|
resizeSaveKey = @"InspectorContentHeightFiles";
|
2007-10-07 15:55:27 +00:00
|
|
|
break;
|
|
|
|
case TAB_OPTIONS_TAG:
|
|
|
|
identifier = TAB_OPTIONS_IDENT;
|
2007-10-10 02:35:16 +00:00
|
|
|
title = NSLocalizedString(@"Options", "Inspector -> title");
|
2007-10-07 15:55:27 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-10-11 17:17:29 +00:00
|
|
|
NSAssert1(NO, @"Unknown info tab selected: %d", fCurrentTabTag);
|
2007-10-07 15:55:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-02-27 02:06:46 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setObject: identifier forKey: @"InspectorSelected"];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
NSWindow * window = [self window];
|
|
|
|
|
2007-10-10 02:35:16 +00:00
|
|
|
[window setTitle: [NSString stringWithFormat: @"%@ - %@", title, NSLocalizedString(@"Torrent Inspector", "Inspector -> title")]];
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
//selected tab item
|
|
|
|
[(InfoTabButtonCell *)[fTabMatrix selectedCell] setSelectedTab: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
NSRect windowRect = [window frame], viewRect = [view frame];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
if (resizeSaveKey)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat height = [[NSUserDefaults standardUserDefaults] floatForKey: resizeSaveKey];
|
|
|
|
if (height != 0.0)
|
2007-10-07 15:55:27 +00:00
|
|
|
viewRect.size.height = MAX(height, TAB_MIN_HEIGHT);
|
2007-10-06 22:23:44 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat difference = (viewRect.size.height - oldHeight) * [window userSpaceScaleFactor];
|
2007-10-06 22:23:44 +00:00
|
|
|
windowRect.origin.y -= difference;
|
|
|
|
windowRect.size.height += difference;
|
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
if (resizeSaveKey)
|
2007-10-06 22:23:44 +00:00
|
|
|
{
|
2008-02-27 02:06:46 +00:00
|
|
|
if (!oldResizeSaveKey)
|
2007-10-06 22:23:44 +00:00
|
|
|
{
|
|
|
|
[window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height - viewRect.size.height + TAB_MIN_HEIGHT)];
|
|
|
|
[window setMaxSize: NSMakeSize(FLT_MAX, FLT_MAX)];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[window setMinSize: NSMakeSize([window minSize].width, windowRect.size.height)];
|
|
|
|
[window setMaxSize: NSMakeSize(FLT_MAX, windowRect.size.height)];
|
|
|
|
}
|
|
|
|
|
|
|
|
viewRect.size.width = windowRect.size.width;
|
|
|
|
[view setFrame: viewRect];
|
|
|
|
|
2007-10-07 03:05:55 +00:00
|
|
|
[window setFrame: windowRect display: YES animate: oldTabTag != INVALID];
|
2007-10-06 22:23:44 +00:00
|
|
|
[[window contentView] addSubview: view];
|
|
|
|
[view setHidden: NO];
|
2008-05-20 23:57:42 +00:00
|
|
|
|
2009-09-07 14:54:22 +00:00
|
|
|
if ([NSApp isOnSnowLeopardOrBetter] && (fCurrentTabTag == TAB_FILES_TAG || oldTabTag == TAB_FILES_TAG)
|
2009-10-10 13:21:27 +00:00
|
|
|
&& ([QLPreviewPanelSL sharedPreviewPanelExists] && [[QLPreviewPanelSL sharedPreviewPanel] isVisible]))
|
2009-10-11 23:50:13 +00:00
|
|
|
[[QLPreviewPanelSL sharedPreviewPanel] reloadData];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNextTab
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger tag = [fTabMatrix selectedTag]+1;
|
2007-10-06 22:23:44 +00:00
|
|
|
if (tag >= [fTabMatrix numberOfColumns])
|
|
|
|
tag = 0;
|
|
|
|
|
|
|
|
[fTabMatrix selectCellWithTag: tag];
|
|
|
|
[self setTab: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPreviousTab
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger tag = [fTabMatrix selectedTag]-1;
|
2007-10-06 22:23:44 +00:00
|
|
|
if (tag < 0)
|
|
|
|
tag = [fTabMatrix numberOfColumns]-1;
|
|
|
|
|
|
|
|
[fTabMatrix selectCellWithTag: tag];
|
|
|
|
[self setTab: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableView
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (tableView == fPeerTable)
|
|
|
|
return fPeers ? [fPeers count] : 0;
|
2008-06-07 23:38:05 +00:00
|
|
|
else if (tableView == fWebSeedTable)
|
|
|
|
return fWebSeeds ? [fWebSeeds count] : 0;
|
2008-02-26 22:56:27 +00:00
|
|
|
else if (tableView == fTrackerTable)
|
2008-02-27 13:52:43 +00:00
|
|
|
return fTrackers ? [fTrackers count] : 0;
|
2007-09-16 01:02:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (NSInteger) row
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (tableView == fPeerTable)
|
|
|
|
{
|
|
|
|
NSString * ident = [column identifier];
|
|
|
|
NSDictionary * peer = [fPeers objectAtIndex: row];
|
|
|
|
|
2007-10-01 11:34:01 +00:00
|
|
|
if ([ident isEqualToString: @"Encryption"])
|
2007-10-28 03:29:20 +00:00
|
|
|
return [[peer objectForKey: @"Encryption"] boolValue] ? [NSImage imageNamed: @"Lock.png"] : nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
else if ([ident isEqualToString: @"Client"])
|
|
|
|
return [peer objectForKey: @"Client"];
|
|
|
|
else if ([ident isEqualToString: @"Progress"])
|
2007-10-01 11:34:01 +00:00
|
|
|
return [peer objectForKey: @"Progress"];
|
2007-09-16 01:02:06 +00:00
|
|
|
else if ([ident isEqualToString: @"UL To"])
|
|
|
|
{
|
|
|
|
NSNumber * rate;
|
|
|
|
return (rate = [peer objectForKey: @"UL To Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
|
|
|
|
}
|
|
|
|
else if ([ident isEqualToString: @"DL From"])
|
|
|
|
{
|
|
|
|
NSNumber * rate;
|
|
|
|
return (rate = [peer objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return [peer objectForKey: @"IP"];
|
|
|
|
}
|
2008-06-07 23:38:05 +00:00
|
|
|
else if (tableView == fWebSeedTable)
|
|
|
|
{
|
2008-06-08 15:54:34 +00:00
|
|
|
NSString * ident = [column identifier];
|
|
|
|
NSDictionary * webSeed = [fWebSeeds objectAtIndex: row];
|
|
|
|
|
|
|
|
if ([ident isEqualToString: @"DL From"])
|
|
|
|
{
|
|
|
|
NSNumber * rate;
|
|
|
|
return (rate = [webSeed objectForKey: @"DL From Rate"]) ? [NSString stringForSpeedAbbrev: [rate floatValue]] : @"";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return [webSeed objectForKey: @"Address"];
|
2008-06-07 23:38:05 +00:00
|
|
|
}
|
2008-02-26 22:56:27 +00:00
|
|
|
else if (tableView == fTrackerTable)
|
|
|
|
{
|
2008-02-27 13:52:43 +00:00
|
|
|
id item = [fTrackers objectAtIndex: row];
|
2009-09-21 03:44:24 +00:00
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
if ([item isKindOfClass: [NSNumber class]])
|
2009-09-21 03:44:24 +00:00
|
|
|
return [NSString stringWithFormat: NSLocalizedString(@"Tier %d", "Inspector -> tracker table"), [item integerValue]];
|
2009-09-28 01:57:35 +00:00
|
|
|
else
|
|
|
|
return item;
|
2009-09-21 03:44:24 +00:00
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
- (NSCell *) tableView: (NSTableView *) tableView dataCellForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
|
2009-09-21 03:44:24 +00:00
|
|
|
{
|
|
|
|
if (tableView == fTrackerTable)
|
|
|
|
{
|
2009-09-29 03:02:44 +00:00
|
|
|
const BOOL tracker = [[fTrackers objectAtIndex: row] isKindOfClass: [TrackerNode class]];
|
|
|
|
return tracker ? fTrackerCell : [tableColumn dataCellForRow: row];
|
2009-09-21 03:44:24 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2009-09-28 01:57:35 +00:00
|
|
|
- (CGFloat) tableView: (NSTableView *) tableView heightOfRow: (NSInteger) row
|
|
|
|
{
|
|
|
|
if (tableView == fTrackerTable)
|
|
|
|
{
|
|
|
|
if ([[fTrackers objectAtIndex: row] isKindOfClass: [NSNumber class]])
|
|
|
|
return TRACKER_GROUP_SEPARATOR_HEIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [tableView rowHeight];
|
|
|
|
}
|
|
|
|
|
2008-12-03 00:18:18 +00:00
|
|
|
- (void) tableView: (NSTableView *) tableView willDisplayCell: (id) cell forTableColumn: (NSTableColumn *) tableColumn
|
|
|
|
row: (NSInteger) row
|
|
|
|
{
|
|
|
|
if (tableView == fPeerTable)
|
|
|
|
{
|
|
|
|
NSString * ident = [tableColumn identifier];
|
|
|
|
|
|
|
|
if ([ident isEqualToString: @"Progress"])
|
|
|
|
{
|
|
|
|
NSDictionary * peer = [fPeers objectAtIndex: row];
|
|
|
|
[(PeerProgressIndicatorCell *)cell setSeed: [[peer objectForKey: @"Seed"] boolValue]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) tableView: (NSTableView *) tableView didClickTableColumn: (NSTableColumn *) tableColumn
|
|
|
|
{
|
|
|
|
if (tableView == fPeerTable)
|
|
|
|
{
|
|
|
|
if (fPeers)
|
|
|
|
{
|
|
|
|
NSArray * oldPeers = fPeers;
|
|
|
|
fPeers = [[fPeers sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain];
|
|
|
|
[oldPeers release];
|
|
|
|
[tableView reloadData];
|
|
|
|
}
|
|
|
|
}
|
2008-06-08 15:54:34 +00:00
|
|
|
else if (tableView == fWebSeedTable)
|
|
|
|
{
|
|
|
|
if (fWebSeeds)
|
|
|
|
{
|
|
|
|
NSArray * oldWebSeeds = fWebSeeds;
|
|
|
|
fWebSeeds = [[fWebSeeds sortedArrayUsingDescriptors: [fWebSeedTable sortDescriptors]] retain];
|
|
|
|
[oldWebSeeds release];
|
|
|
|
[tableView reloadData];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (BOOL) tableView: (NSTableView *) tableView shouldSelectRow: (NSInteger) row
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-06-02 17:26:02 +00:00
|
|
|
return tableView == fTrackerTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableViewSelectionDidChange: (NSNotification *) notification
|
|
|
|
{
|
|
|
|
if ([notification object] == fTrackerTable)
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger numSelected = [fTrackerTable numberOfSelectedRows];
|
2008-06-02 17:26:02 +00:00
|
|
|
[fTrackerAddRemoveControl setEnabled: numSelected > 0 forSegment: TRACKER_REMOVE_TAG];
|
|
|
|
}
|
2008-02-26 22:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) tableView: (NSTableView *) tableView isGroupRow: (NSInteger) row
|
|
|
|
{
|
|
|
|
if (tableView == fTrackerTable)
|
2008-02-27 13:52:43 +00:00
|
|
|
return [[fTrackers objectAtIndex: row] isKindOfClass: [NSNumber class]];
|
2008-02-26 22:56:27 +00:00
|
|
|
return NO;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) tableView: (NSTableView *) tableView toolTipForCell: (NSCell *) cell rect: (NSRectPointer) rect
|
2008-11-02 01:07:01 +00:00
|
|
|
tableColumn: (NSTableColumn *) column row: (NSInteger) row mouseLocation: (NSPoint) mouseLocation
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
if (tableView == fPeerTable)
|
|
|
|
{
|
|
|
|
NSDictionary * peer = [fPeers objectAtIndex: row];
|
2007-11-20 13:08:10 +00:00
|
|
|
NSMutableArray * components = [NSMutableArray arrayWithCapacity: 5];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-12-03 00:18:18 +00:00
|
|
|
CGFloat progress = [[peer objectForKey: @"Progress"] floatValue];
|
2008-12-06 01:18:25 +00:00
|
|
|
NSString * progressString = [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%",
|
|
|
|
"Inspector -> Peers tab -> table row tooltip"), progress * 100.0];
|
2008-12-03 00:18:18 +00:00
|
|
|
if (progress < 1.0 && [[peer objectForKey: @"Seed"] boolValue])
|
2008-12-06 01:18:25 +00:00
|
|
|
progressString = [progressString stringByAppendingFormat: @" (%@)", NSLocalizedString(@"Partial Seed",
|
|
|
|
"Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
[components addObject: progressString];
|
2007-10-01 11:34:01 +00:00
|
|
|
|
|
|
|
if ([[peer objectForKey: @"Encryption"] boolValue])
|
|
|
|
[components addObject: NSLocalizedString(@"Encrypted Connection", "Inspector -> Peers tab -> table row tooltip")];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-04-01 15:24:35 +00:00
|
|
|
NSString * portString;
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger port;
|
2007-09-16 01:02:06 +00:00
|
|
|
if ((port = [[peer objectForKey: @"Port"] intValue]) > 0)
|
2008-04-01 15:24:35 +00:00
|
|
|
portString = [NSString stringWithFormat: @"%d", port];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
2008-04-01 15:24:35 +00:00
|
|
|
portString = NSLocalizedString(@"N/A", "Inspector -> Peers tab -> table row tooltip");
|
|
|
|
[components addObject: [NSString stringWithFormat: @"%@: %@", NSLocalizedString(@"Port",
|
|
|
|
"Inspector -> Peers tab -> table row tooltip"), portString]];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-11 17:17:29 +00:00
|
|
|
const NSInteger peerFrom = [[peer objectForKey: @"From"] integerValue];
|
|
|
|
switch (peerFrom)
|
2007-10-01 11:41:15 +00:00
|
|
|
{
|
|
|
|
case TR_PEER_FROM_TRACKER:
|
|
|
|
[components addObject: NSLocalizedString(@"From: tracker", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
|
|
|
case TR_PEER_FROM_INCOMING:
|
|
|
|
[components addObject: NSLocalizedString(@"From: incoming connection", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
|
|
|
case TR_PEER_FROM_CACHE:
|
|
|
|
[components addObject: NSLocalizedString(@"From: cache", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
|
|
|
case TR_PEER_FROM_PEX:
|
|
|
|
[components addObject: NSLocalizedString(@"From: peer exchange", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
2009-05-19 22:51:37 +00:00
|
|
|
case TR_PEER_FROM_DHT:
|
|
|
|
[components addObject: NSLocalizedString(@"From: distributed hash table", "Inspector -> Peers tab -> table row tooltip")];
|
|
|
|
break;
|
2009-10-11 17:17:29 +00:00
|
|
|
default:
|
|
|
|
NSAssert1(NO, @"Peer from unknown source: %d", peerFrom);
|
2007-10-01 11:41:15 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-29 01:44:54 +00:00
|
|
|
//determing status strings from flags
|
2008-11-25 03:04:17 +00:00
|
|
|
NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 6];
|
2008-01-14 05:53:38 +00:00
|
|
|
NSString * flags = [peer objectForKey: @"Flags"];
|
|
|
|
|
|
|
|
if ([flags rangeOfString: @"D"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Currently downloading (interested and not choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
2008-11-25 03:04:17 +00:00
|
|
|
if ([flags rangeOfString: @"d"].location != NSNotFound)
|
2008-01-14 05:53:38 +00:00
|
|
|
[statusArray addObject: NSLocalizedString(@"You want to download, but peer does not want to send (interested and choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
if ([flags rangeOfString: @"U"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Currently uploading (interested and not choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
2008-11-25 03:04:17 +00:00
|
|
|
if ([flags rangeOfString: @"u"].location != NSNotFound)
|
2008-01-14 05:53:38 +00:00
|
|
|
[statusArray addObject: NSLocalizedString(@"Peer wants you to upload, but you do not want to (interested and choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
if ([flags rangeOfString: @"K"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Peer is unchoking you, but you are not interested",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
if ([flags rangeOfString: @"?"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"You unchoked the peer, but the peer is not interested",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
|
|
|
|
if ([statusArray count] > 0)
|
2008-11-25 03:04:17 +00:00
|
|
|
{
|
|
|
|
NSString * statusStrings = [statusArray componentsJoinedByString: @"\n\n"];
|
|
|
|
[components addObject: [@"\n" stringByAppendingString: statusStrings]];
|
|
|
|
}
|
2008-01-09 19:52:11 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return [components componentsJoinedByString: @"\n"];
|
|
|
|
}
|
2009-09-28 02:55:16 +00:00
|
|
|
else if (tableView == fTrackerTable)
|
|
|
|
{
|
|
|
|
id node = [fTrackers objectAtIndex: row];
|
|
|
|
if (![node isKindOfClass: [NSNumber class]])
|
|
|
|
return [(TrackerNode *)node fullAnnounceAddress];
|
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:26:02 +00:00
|
|
|
- (void) tableView: (NSTableView *) tableView setObjectValue: (id) object forTableColumn: (NSTableColumn *) tableColumn
|
|
|
|
row: (NSInteger) row
|
|
|
|
{
|
|
|
|
if (tableView != fTrackerTable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Torrent * torrent= [fTorrents objectAtIndex: 0];
|
2009-09-29 03:02:44 +00:00
|
|
|
if (![torrent addTrackerToNewTier: object])
|
2008-06-02 17:26:02 +00:00
|
|
|
NSBeep();
|
|
|
|
|
|
|
|
//reset table with either new or old value
|
|
|
|
[fTrackers release];
|
2009-09-29 03:02:44 +00:00
|
|
|
fTrackers = [[torrent allTrackerStats] retain];
|
2008-06-02 17:26:02 +00:00
|
|
|
|
|
|
|
[fTrackerTable setTrackers: fTrackers];
|
|
|
|
[fTrackerTable reloadData];
|
2009-09-29 03:02:44 +00:00
|
|
|
[fTrackerTable deselectAll: self];
|
2009-10-11 13:45:50 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; //incase sort by tracker
|
2008-06-02 17:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) addRemoveTracker: (id) sender
|
|
|
|
{
|
2009-09-29 03:02:44 +00:00
|
|
|
//don't allow add/remove when currently adding - it leads to weird results
|
2008-06-02 17:26:02 +00:00
|
|
|
if ([fTrackerTable editedRow] != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ([[sender cell] tagForSegment: [sender selectedSegment]] == TRACKER_REMOVE_TAG)
|
|
|
|
[self removeTrackers];
|
|
|
|
else
|
2009-09-29 03:02:44 +00:00
|
|
|
[self addTrackers];
|
2008-06-02 17:26:02 +00:00
|
|
|
}
|
|
|
|
|
2009-10-11 17:17:29 +00:00
|
|
|
#warning is editing trackers needed?
|
2009-09-29 03:02:44 +00:00
|
|
|
/*- (BOOL) tableView: (NSTableView *) tableView shouldEditTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
|
2008-06-02 17:26:02 +00:00
|
|
|
{
|
2008-06-02 19:42:14 +00:00
|
|
|
if (tableView != fTrackerTable)
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
NSUInteger i;
|
|
|
|
for (i = row-1; ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; i--);
|
|
|
|
|
|
|
|
return [[fTrackers objectAtIndex: i] intValue] == 0;
|
2009-09-29 03:02:44 +00:00
|
|
|
}*/
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2009-10-11 23:16:46 +00:00
|
|
|
- (NSArray *) quickLookURLs
|
2009-09-04 04:10:46 +00:00
|
|
|
{
|
2009-10-11 23:16:46 +00:00
|
|
|
FileOutlineView * fileOutlineView = [fFileController outlineView];
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
|
|
|
|
NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]];
|
|
|
|
|
|
|
|
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
|
|
|
{
|
|
|
|
FileListNode * item = [fileOutlineView itemAtRow: i];
|
|
|
|
if ([self canQuickLookFile: item])
|
2009-10-22 00:10:41 +00:00
|
|
|
[urlArray addObject: [NSURL fileURLWithPath: [torrent fileLocation: item]]];
|
2009-10-11 23:16:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return urlArray;
|
2009-09-04 04:10:46 +00:00
|
|
|
}
|
|
|
|
|
2009-10-11 23:16:46 +00:00
|
|
|
- (BOOL) canQuickLook
|
2009-09-04 04:10:46 +00:00
|
|
|
{
|
2009-10-12 00:19:04 +00:00
|
|
|
if (fCurrentTabTag != TAB_FILES_TAG || ![[self window] isVisible] || [fTorrents count] != 1 || ![NSApp isOnSnowLeopardOrBetter])
|
2009-10-11 23:16:46 +00:00
|
|
|
return NO;
|
|
|
|
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
if (![torrent isFolder])
|
|
|
|
return NO;
|
|
|
|
|
|
|
|
FileOutlineView * fileOutlineView = [fFileController outlineView];
|
|
|
|
NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
|
|
|
|
|
|
|
|
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
|
|
|
if ([self canQuickLookFile: [fileOutlineView itemAtRow: i]])
|
|
|
|
return YES;
|
2009-09-04 04:10:46 +00:00
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2009-10-11 23:16:46 +00:00
|
|
|
#warning uncomment (in header too)
|
|
|
|
- (NSRect) quickLookSourceFrameForPreviewItem: (id /*<QLPreviewItem>*/) item
|
2009-09-04 04:10:46 +00:00
|
|
|
{
|
2009-09-05 01:58:13 +00:00
|
|
|
FileOutlineView * fileOutlineView = [fFileController outlineView];
|
|
|
|
|
2009-10-21 13:01:14 +00:00
|
|
|
NSString * fullPath = [(NSURL *)item path];
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
2009-09-05 01:58:13 +00:00
|
|
|
NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]];
|
|
|
|
|
|
|
|
for (NSUInteger row = visibleRows.location; row < NSMaxRange(visibleRows); row++)
|
|
|
|
{
|
|
|
|
FileListNode * rowItem = [fileOutlineView itemAtRow: row];
|
2009-10-21 13:01:14 +00:00
|
|
|
if ([[torrent fileLocation: rowItem] isEqualToString: fullPath])
|
2009-09-05 01:58:13 +00:00
|
|
|
{
|
|
|
|
NSRect frame = [fileOutlineView iconRectForRow: row];
|
2009-10-12 03:15:37 +00:00
|
|
|
|
|
|
|
if (!NSIntersectsRect([fileOutlineView visibleRect], frame))
|
|
|
|
return NSZeroRect;
|
|
|
|
|
2009-09-05 01:58:13 +00:00
|
|
|
frame.origin = [fileOutlineView convertPoint: frame.origin toView: nil];
|
|
|
|
frame.origin = [[self window] convertBaseToScreen: frame.origin];
|
|
|
|
frame.origin.y -= frame.size.height;
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSZeroRect;
|
2009-09-04 04:10:46 +00:00
|
|
|
}
|
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
- (void) setPiecesView: (id) sender
|
|
|
|
{
|
|
|
|
[self setPiecesViewForAvailable: [sender selectedSegment] == PIECES_CONTROL_AVAILABLE];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPiecesViewForAvailable: (BOOL) available
|
|
|
|
{
|
|
|
|
[fPiecesControl setSelected: available forSegment: PIECES_CONTROL_AVAILABLE];
|
|
|
|
[fPiecesControl setSelected: !available forSegment: PIECES_CONTROL_PROGRESS];
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool: available forKey: @"PiecesViewShowAvailability"];
|
2008-06-09 23:23:55 +00:00
|
|
|
[fPiecesView updateView];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealDataFile: (id) sender
|
|
|
|
{
|
|
|
|
if ([fTorrents count] > 0)
|
2009-08-30 17:50:05 +00:00
|
|
|
{
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
2009-10-21 22:15:36 +00:00
|
|
|
NSString * location = [torrent dataLocation];
|
|
|
|
if (!location)
|
|
|
|
return;
|
|
|
|
|
2009-08-30 17:50:05 +00:00
|
|
|
if ([NSApp isOnSnowLeopardOrBetter])
|
|
|
|
{
|
2009-10-21 22:15:36 +00:00
|
|
|
NSURL * file = [NSURL fileURLWithPath: location];
|
2009-08-30 17:50:05 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]];
|
|
|
|
}
|
|
|
|
else
|
2009-10-21 22:15:36 +00:00
|
|
|
[[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil];
|
2009-08-30 17:50:05 +00:00
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2008-12-07 21:32:03 +00:00
|
|
|
|
|
|
|
- (void) setFileFilterText: (id) sender
|
|
|
|
{
|
|
|
|
[fFileController setFilterText: [sender stringValue]];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-03-05 01:10:09 +00:00
|
|
|
- (void) setUseSpeedLimit: (id) sender
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-03-05 01:10:09 +00:00
|
|
|
const BOOL upload = sender == fUploadLimitCheck;
|
2009-03-05 01:23:19 +00:00
|
|
|
|
|
|
|
if ([sender state] == NSMixedState)
|
|
|
|
[sender setState: NSOnState];
|
2009-03-05 01:10:09 +00:00
|
|
|
const BOOL limit = [sender state] == NSOnState;
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-12-26 15:11:37 +00:00
|
|
|
for (Torrent * torrent in fTorrents)
|
2009-03-05 01:10:09 +00:00
|
|
|
[torrent setUseSpeedLimit: limit upload: upload];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField;
|
2009-03-05 01:10:09 +00:00
|
|
|
[field setEnabled: limit];
|
|
|
|
if (limit)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
|
|
|
[field selectText: self];
|
2009-03-05 01:10:09 +00:00
|
|
|
[[self window] makeKeyAndOrderFront: self];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel;
|
2009-03-05 01:10:09 +00:00
|
|
|
[label setEnabled: limit];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
|
|
|
|
2009-03-05 01:23:19 +00:00
|
|
|
- (void) setUseGlobalSpeedLimit: (id) sender
|
|
|
|
{
|
|
|
|
if ([sender state] == NSMixedState)
|
|
|
|
[sender setState: NSOnState];
|
|
|
|
const BOOL limit = [sender state] == NSOnState;
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setUseGlobalSpeedLimit: limit];
|
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
- (void) setSpeedLimit: (id) sender
|
|
|
|
{
|
2009-03-05 01:23:19 +00:00
|
|
|
const BOOL upload = sender == fUploadLimitField;
|
|
|
|
const NSInteger limit = [sender intValue];
|
2007-10-07 15:55:27 +00:00
|
|
|
|
2008-12-26 15:11:37 +00:00
|
|
|
for (Torrent * torrent in fTorrents)
|
2007-12-23 17:08:13 +00:00
|
|
|
[torrent setSpeedLimit: limit upload: upload];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioSetting: (id) sender
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger setting;
|
2009-02-14 21:15:57 +00:00
|
|
|
bool single = NO;
|
2007-10-15 01:57:56 +00:00
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
|
|
|
case OPTION_POPUP_LIMIT:
|
2009-02-14 21:15:57 +00:00
|
|
|
setting = TR_RATIOLIMIT_SINGLE;
|
|
|
|
single = YES;
|
2007-10-15 01:57:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_POPUP_NO_LIMIT:
|
2009-02-14 21:15:57 +00:00
|
|
|
setting = TR_RATIOLIMIT_UNLIMITED;
|
2007-10-15 01:57:56 +00:00
|
|
|
break;
|
|
|
|
case OPTION_POPUP_GLOBAL:
|
2009-02-14 21:15:57 +00:00
|
|
|
setting = TR_RATIOLIMIT_GLOBAL;
|
2007-10-15 01:57:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-10-11 17:17:29 +00:00
|
|
|
NSAssert1(NO, @"Unknown option selected in ratio popup: %d", [sender indexOfSelectedItem]);
|
2007-10-15 01:57:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2007-10-07 15:55:27 +00:00
|
|
|
|
2008-12-26 15:11:37 +00:00
|
|
|
for (Torrent * torrent in fTorrents)
|
2007-10-07 15:55:27 +00:00
|
|
|
[torrent setRatioSetting: setting];
|
|
|
|
|
|
|
|
[fRatioLimitField setHidden: !single];
|
|
|
|
if (single)
|
|
|
|
{
|
|
|
|
[fRatioLimitField selectText: self];
|
2009-02-14 21:15:57 +00:00
|
|
|
[[self window] makeKeyAndOrderFront: self];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioLimit: (id) sender
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat limit = [sender floatValue];
|
2007-12-23 17:08:13 +00:00
|
|
|
|
2008-12-26 15:11:37 +00:00
|
|
|
for (Torrent * torrent in fTorrents)
|
2007-12-23 17:08:13 +00:00
|
|
|
[torrent setRatioLimit: limit];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 03:36:35 +00:00
|
|
|
- (void) setPriority: (id) sender
|
|
|
|
{
|
|
|
|
tr_priority_t priority;
|
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
|
|
|
case OPTION_POPUP_PRIORITY_HIGH:
|
|
|
|
priority = TR_PRI_HIGH;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_PRIORITY_NORMAL:
|
|
|
|
priority = TR_PRI_NORMAL;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_PRIORITY_LOW:
|
|
|
|
priority = TR_PRI_LOW;
|
|
|
|
break;
|
|
|
|
default:
|
2009-10-11 17:17:29 +00:00
|
|
|
NSAssert1(NO, @"Unknown option selected in priority popup: %d", [sender indexOfSelectedItem]);
|
2009-04-20 03:36:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
[torrent setPriority: priority];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
|
|
|
|
}
|
|
|
|
|
2007-12-22 05:21:25 +00:00
|
|
|
- (void) setPeersConnectLimit: (id) sender
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger limit = [sender intValue];
|
2007-12-23 17:08:13 +00:00
|
|
|
|
2008-12-26 15:11:37 +00:00
|
|
|
for (Torrent * torrent in fTorrents)
|
2007-12-23 17:08:13 +00:00
|
|
|
[torrent setMaxPeerConnect: limit];
|
|
|
|
}
|
2007-12-22 05:21:25 +00:00
|
|
|
|
2007-12-23 17:08:13 +00:00
|
|
|
- (BOOL) control: (NSControl *) control textShouldBeginEditing: (NSText *) fieldEditor
|
|
|
|
{
|
|
|
|
[fInitialString release];
|
|
|
|
fInitialString = [[control stringValue] retain];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) control: (NSControl *) control didFailToFormatString: (NSString *) string errorDescription: (NSString *) error
|
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
if (fInitialString)
|
2007-12-22 05:21:25 +00:00
|
|
|
{
|
2007-12-23 17:08:13 +00:00
|
|
|
[control setStringValue: fInitialString];
|
|
|
|
[fInitialString release];
|
|
|
|
fInitialString = nil;
|
2007-12-22 05:21:25 +00:00
|
|
|
}
|
2007-12-23 17:08:13 +00:00
|
|
|
return NO;
|
2007-12-22 05:21:25 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoWindowController (Private)
|
|
|
|
|
|
|
|
- (void) updateInfoGeneral
|
|
|
|
{
|
|
|
|
if ([fTorrents count] != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
|
|
|
NSString * location = [torrent dataLocation];
|
2009-10-21 13:01:14 +00:00
|
|
|
[fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""];
|
|
|
|
[fDataLocationField setToolTip: location ? location : @""];
|
2009-10-25 16:31:28 +00:00
|
|
|
[fDataLocationField setSelectable: location != nil];
|
|
|
|
|
|
|
|
[fRevealDataButton setHidden: !location];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfoActivity
|
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger numberSelected = [fTorrents count];
|
2007-10-07 15:55:27 +00:00
|
|
|
if (numberSelected == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
uint64_t have = 0, haveVerified = 0, downloadedTotal = 0, uploadedTotal = 0, failedHash = 0;
|
2008-03-06 16:13:05 +00:00
|
|
|
NSDate * lastActivity = nil;
|
2008-12-26 15:11:37 +00:00
|
|
|
for (Torrent * torrent in fTorrents)
|
2007-10-07 15:55:27 +00:00
|
|
|
{
|
|
|
|
have += [torrent haveTotal];
|
|
|
|
haveVerified += [torrent haveVerified];
|
|
|
|
downloadedTotal += [torrent downloadedTotal];
|
|
|
|
uploadedTotal += [torrent uploadedTotal];
|
|
|
|
failedHash += [torrent failedHash];
|
2008-03-06 16:13:05 +00:00
|
|
|
|
|
|
|
NSDate * nextLastActivity;
|
|
|
|
if ((nextLastActivity = [torrent dateActivity]))
|
2008-03-07 13:23:01 +00:00
|
|
|
lastActivity = lastActivity ? [lastActivity laterDate: nextLastActivity] : nextLastActivity;
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (have == 0)
|
|
|
|
[fHaveField setStringValue: [NSString stringForFileSize: 0]];
|
|
|
|
else
|
2008-04-12 17:52:37 +00:00
|
|
|
{
|
|
|
|
NSString * verifiedString = [NSString stringWithFormat: NSLocalizedString(@"%@ verified", "Inspector -> Activity tab -> have"),
|
|
|
|
[NSString stringForFileSize: haveVerified]];
|
|
|
|
if (have == haveVerified)
|
|
|
|
[fHaveField setStringValue: verifiedString];
|
|
|
|
else
|
|
|
|
[fHaveField setStringValue: [NSString stringWithFormat: @"%@ (%@)", [NSString stringForFileSize: have], verifiedString]];
|
|
|
|
}
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
[fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
|
|
|
|
[fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
|
|
|
|
[fFailedHashField setStringValue: [NSString stringForFileSize: failedHash]];
|
|
|
|
|
2008-03-06 16:13:05 +00:00
|
|
|
[fDateActivityField setObjectValue: lastActivity];
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
if (numberSelected == 1)
|
|
|
|
{
|
2008-12-26 15:11:37 +00:00
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
[fStateField setStringValue: [torrent stateString]];
|
2008-03-31 20:58:33 +00:00
|
|
|
|
2008-05-29 22:16:03 +00:00
|
|
|
if ([torrent isFolder])
|
2008-03-31 20:58:33 +00:00
|
|
|
[fProgressField setStringValue: [NSString localizedStringWithFormat: NSLocalizedString(@"%.2f%% (%.2f%% selected)",
|
|
|
|
"Inspector -> Activity tab -> progress"), 100.0 * [torrent progress], 100.0 * [torrent progressDone]]];
|
|
|
|
else
|
|
|
|
[fProgressField setStringValue: [NSString localizedStringWithFormat: @"%.2f%%", 100.0 * [torrent progress]]];
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
[fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]];
|
|
|
|
[fSwarmSpeedField setStringValue: [torrent isActive] ? [NSString stringForSpeed: [torrent swarmSpeed]] : @""];
|
|
|
|
|
|
|
|
NSString * errorMessage = [torrent errorMessage];
|
|
|
|
if (![errorMessage isEqualToString: [fErrorMessageView string]])
|
|
|
|
{
|
|
|
|
[fErrorMessageView setString: errorMessage];
|
|
|
|
[fErrorMessageView setSelectable: ![errorMessage isEqualToString: @""]];
|
|
|
|
}
|
|
|
|
|
|
|
|
[fDateCompletedField setObjectValue: [torrent dateCompleted]];
|
|
|
|
|
2008-06-09 21:20:01 +00:00
|
|
|
[fPiecesView updateView];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
2008-10-16 03:44:54 +00:00
|
|
|
else if (numberSelected > 1)
|
|
|
|
{
|
|
|
|
[fRatioField setStringValue: [NSString stringForRatio: tr_getRatio(uploadedTotal, downloadedTotal)]];
|
|
|
|
}
|
|
|
|
else;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-02-22 01:36:30 +00:00
|
|
|
- (void) updateInfoTracker
|
|
|
|
{
|
2009-09-26 04:02:39 +00:00
|
|
|
if ([fTorrents count] != 1)
|
2008-02-22 01:36:30 +00:00
|
|
|
return;
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
2009-10-11 17:17:29 +00:00
|
|
|
//get updated tracker stats
|
2009-09-29 03:02:44 +00:00
|
|
|
if ([fTrackerTable editedRow] == -1)
|
|
|
|
{
|
|
|
|
[fTrackers release];
|
|
|
|
fTrackers = [[torrent allTrackerStats] retain];
|
|
|
|
|
|
|
|
[fTrackerTable setTrackers: fTrackers];
|
|
|
|
[fTrackerTable reloadData];
|
|
|
|
}
|
2009-09-29 23:56:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if ([NSApp isOnSnowLeopardOrBetter])
|
|
|
|
{
|
|
|
|
NSIndexSet * addedIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange([fTrackers count]-2, 2)];
|
|
|
|
NSArray * tierAndTrackerBeingAdded = [fTrackers objectsAtIndexes: addedIndexes];
|
|
|
|
|
|
|
|
[fTrackers release];
|
|
|
|
fTrackers = [[torrent allTrackerStats] retain];
|
|
|
|
[fTrackers addObjectsFromArray: tierAndTrackerBeingAdded];
|
|
|
|
|
|
|
|
[fTrackerTable setTrackers: fTrackers];
|
|
|
|
|
|
|
|
NSIndexSet * updateIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fTrackers count]-2)],
|
|
|
|
* columnIndexes = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [[fTrackerTable tableColumns] count])];
|
|
|
|
[fTrackerTable reloadDataForRowIndexes: updateIndexes columnIndexes: columnIndexes];
|
|
|
|
}
|
|
|
|
}
|
2008-02-22 01:36:30 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
- (void) updateInfoPeers
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-10-07 15:55:27 +00:00
|
|
|
if ([fTorrents count] != 1)
|
|
|
|
return;
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-28 21:05:50 +00:00
|
|
|
NSString * knownString = [NSString stringWithFormat: NSLocalizedString(@"%d known", "Inspector -> Peers tab -> peers"),
|
|
|
|
[torrent totalPeersKnown]];
|
2009-10-07 00:44:06 +00:00
|
|
|
if ([torrent isActive])
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2009-10-28 21:05:50 +00:00
|
|
|
const NSInteger total = [torrent totalPeersConnected];
|
|
|
|
NSString * connectedText = [NSString stringWithFormat: NSLocalizedString(@"%d Connected", "Inspector -> Peers tab -> peers"),
|
|
|
|
total];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
if (total > 0)
|
|
|
|
{
|
2009-10-28 21:05:50 +00:00
|
|
|
NSMutableArray * fromComponents = [NSMutableArray arrayWithCapacity: 5];
|
2008-11-02 01:07:01 +00:00
|
|
|
NSInteger count;
|
2007-10-07 15:55:27 +00:00
|
|
|
if ((count = [torrent totalPeersTracker]) > 0)
|
2009-10-28 21:05:50 +00:00
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
2007-10-07 15:55:27 +00:00
|
|
|
NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), count]];
|
|
|
|
if ((count = [torrent totalPeersIncoming]) > 0)
|
2009-10-28 21:05:50 +00:00
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
2007-10-07 15:55:27 +00:00
|
|
|
NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), count]];
|
2009-05-19 22:51:37 +00:00
|
|
|
if ((count = [torrent totalPeersCache]) > 0)
|
2009-10-28 21:05:50 +00:00
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
2009-05-19 22:51:37 +00:00
|
|
|
NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), count]];
|
2007-10-07 15:55:27 +00:00
|
|
|
if ((count = [torrent totalPeersPex]) > 0)
|
2009-10-28 21:05:50 +00:00
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
2007-10-07 15:55:27 +00:00
|
|
|
NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), count]];
|
2009-05-19 22:51:37 +00:00
|
|
|
if ((count = [torrent totalPeersDHT]) > 0)
|
2009-10-28 21:05:50 +00:00
|
|
|
[fromComponents addObject: [NSString stringWithFormat:
|
2009-05-19 22:51:37 +00:00
|
|
|
NSLocalizedString(@"%d DHT", "Inspector -> Peers tab -> peers"), count]];
|
2007-10-07 15:55:27 +00:00
|
|
|
|
2009-10-28 21:05:50 +00:00
|
|
|
NSMutableArray * upDownComponents = [NSMutableArray arrayWithCapacity: 3];
|
|
|
|
if ((count = [torrent peersSendingToUs]) > 0)
|
|
|
|
[upDownComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"DL from %d", "Inspector -> Peers tab -> peers"), count]];
|
|
|
|
if ((count = [torrent peersGettingFromUs]) > 0)
|
|
|
|
[upDownComponents addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"UL to %d", "Inspector -> Peers tab -> peers"), count]];
|
|
|
|
[upDownComponents addObject: knownString];
|
|
|
|
|
|
|
|
connectedText = [connectedText stringByAppendingFormat: @": %@\n%@", [fromComponents componentsJoinedByString: @", "],
|
|
|
|
[upDownComponents componentsJoinedByString: @", "]];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
2009-10-29 01:44:54 +00:00
|
|
|
else
|
|
|
|
connectedText = [connectedText stringByAppendingFormat: @"\n%@", knownString];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2009-10-28 21:05:50 +00:00
|
|
|
[fConnectedPeersField setStringValue: connectedText];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-28 21:05:50 +00:00
|
|
|
NSString * connectedText = [NSString stringWithFormat: @"%@\n%@",
|
|
|
|
NSLocalizedString(@"Not Connected", "Inspector -> Peers tab -> peers"), knownString];
|
|
|
|
[fConnectedPeersField setStringValue: connectedText];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
[fPeers release];
|
|
|
|
fPeers = [[[torrent peers] sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain];
|
|
|
|
[fPeerTable reloadData];
|
2008-06-08 15:54:34 +00:00
|
|
|
|
2008-06-08 16:38:15 +00:00
|
|
|
if ([torrent webSeedCount] > 0)
|
|
|
|
{
|
|
|
|
[fWebSeeds release];
|
2008-06-08 18:02:16 +00:00
|
|
|
fWebSeeds = [[[torrent webSeeds] sortedArrayUsingDescriptors: [fWebSeedTable sortDescriptors]] retain];
|
2008-06-08 16:38:15 +00:00
|
|
|
[fWebSeedTable reloadData];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
- (void) updateInfoFiles
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-10-07 15:55:27 +00:00
|
|
|
if ([fTorrents count] == 1)
|
2008-01-04 00:29:13 +00:00
|
|
|
[fFileController reloadData];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-11-02 01:07:01 +00:00
|
|
|
- (NSView *) tabViewForTag: (NSInteger) tag
|
2007-10-07 12:24:26 +00:00
|
|
|
{
|
|
|
|
switch (tag)
|
|
|
|
{
|
|
|
|
case TAB_INFO_TAG:
|
|
|
|
return fInfoView;
|
|
|
|
case TAB_ACTIVITY_TAG:
|
|
|
|
return fActivityView;
|
2008-02-22 01:36:30 +00:00
|
|
|
case TAB_TRACKER_TAG:
|
|
|
|
return fTrackerView;
|
2007-10-07 12:24:26 +00:00
|
|
|
case TAB_PEERS_TAG:
|
|
|
|
return fPeersView;
|
|
|
|
case TAB_FILES_TAG:
|
|
|
|
return fFilesView;
|
|
|
|
case TAB_OPTIONS_TAG:
|
|
|
|
return fOptionsView;
|
|
|
|
default:
|
2009-10-11 17:17:29 +00:00
|
|
|
NSAssert1(NO, @"Unknown tab view for tag: %d", tag);
|
2007-10-07 12:24:26 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-08 21:13:35 +00:00
|
|
|
- (void) setWebSeedTableHidden: (BOOL) hide animate: (BOOL) animate
|
2008-06-08 01:17:36 +00:00
|
|
|
{
|
2008-06-08 05:36:49 +00:00
|
|
|
if (fCurrentTabTag != TAB_PEERS_TAG || ![[self window] isVisible])
|
2008-06-08 01:17:36 +00:00
|
|
|
animate = NO;
|
|
|
|
|
2008-06-08 04:11:29 +00:00
|
|
|
if (fWebSeedTableAnimation)
|
|
|
|
{
|
|
|
|
[fWebSeedTableAnimation stopAnimation];
|
|
|
|
[fWebSeedTableAnimation release];
|
|
|
|
fWebSeedTableAnimation = nil;
|
|
|
|
}
|
|
|
|
|
2008-06-08 01:17:36 +00:00
|
|
|
NSRect webSeedFrame = [[fWebSeedTable enclosingScrollView] frame];
|
|
|
|
NSRect peerFrame = [[fPeerTable enclosingScrollView] frame];
|
|
|
|
|
2008-06-08 02:10:10 +00:00
|
|
|
if (hide)
|
2008-06-08 01:17:36 +00:00
|
|
|
{
|
2008-11-02 01:07:01 +00:00
|
|
|
CGFloat webSeedFrameMaxY = NSMaxY(webSeedFrame);
|
2008-06-08 01:17:36 +00:00
|
|
|
webSeedFrame.size.height = 0;
|
2008-06-08 02:10:10 +00:00
|
|
|
webSeedFrame.origin.y = webSeedFrameMaxY;
|
|
|
|
|
|
|
|
peerFrame.size.height = webSeedFrameMaxY - peerFrame.origin.y;
|
2008-06-08 01:17:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-06-08 02:10:10 +00:00
|
|
|
webSeedFrame.origin.y -= fWebSeedTableHeight - webSeedFrame.size.height;
|
2008-06-08 01:27:49 +00:00
|
|
|
webSeedFrame.size.height = fWebSeedTableHeight;
|
2008-06-08 02:10:10 +00:00
|
|
|
|
|
|
|
peerFrame.size.height = (webSeedFrame.origin.y - fSpaceBetweenWebSeedAndPeer) - peerFrame.origin.y;
|
|
|
|
}
|
2008-06-08 01:17:36 +00:00
|
|
|
|
2008-06-08 04:11:29 +00:00
|
|
|
[[fWebSeedTable enclosingScrollView] setHidden: NO]; //this is needed for some reason
|
|
|
|
|
2008-06-08 01:17:36 +00:00
|
|
|
//actually resize tables
|
2008-06-08 02:10:10 +00:00
|
|
|
if (animate)
|
|
|
|
{
|
2008-06-08 04:11:29 +00:00
|
|
|
NSDictionary * webSeedDict = [NSDictionary dictionaryWithObjectsAndKeys:
|
2008-06-08 05:36:49 +00:00
|
|
|
[fWebSeedTable enclosingScrollView], NSViewAnimationTargetKey,
|
|
|
|
[NSValue valueWithRect: [[fWebSeedTable enclosingScrollView] frame]], NSViewAnimationStartFrameKey,
|
|
|
|
[NSValue valueWithRect: webSeedFrame], NSViewAnimationEndFrameKey, nil],
|
2008-06-08 04:11:29 +00:00
|
|
|
* peerDict = [NSDictionary dictionaryWithObjectsAndKeys:
|
2008-06-08 05:36:49 +00:00
|
|
|
[fPeerTable enclosingScrollView], NSViewAnimationTargetKey,
|
|
|
|
[NSValue valueWithRect: [[fPeerTable enclosingScrollView] frame]], NSViewAnimationStartFrameKey,
|
|
|
|
[NSValue valueWithRect: peerFrame], NSViewAnimationEndFrameKey, nil];
|
2008-06-08 04:11:29 +00:00
|
|
|
|
|
|
|
fWebSeedTableAnimation = [[NSViewAnimation alloc] initWithViewAnimations:
|
|
|
|
[NSArray arrayWithObjects: webSeedDict, peerDict, nil]];
|
2008-06-08 15:54:34 +00:00
|
|
|
[fWebSeedTableAnimation setDuration: 0.125];
|
2008-06-08 05:36:49 +00:00
|
|
|
[fWebSeedTableAnimation setAnimationBlockingMode: NSAnimationNonblocking];
|
2008-06-08 04:11:29 +00:00
|
|
|
[fWebSeedTableAnimation setDelegate: self];
|
|
|
|
|
|
|
|
[fWebSeedTableAnimation startAnimation];
|
2008-06-08 02:10:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[[fWebSeedTable enclosingScrollView] setFrame: webSeedFrame];
|
|
|
|
[[fPeerTable enclosingScrollView] setFrame: peerFrame];
|
|
|
|
}
|
2008-06-08 01:17:36 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
- (NSArray *) peerSortDescriptors
|
|
|
|
{
|
|
|
|
NSMutableArray * descriptors = [NSMutableArray arrayWithCapacity: 2];
|
|
|
|
|
|
|
|
NSArray * oldDescriptors = [fPeerTable sortDescriptors];
|
|
|
|
BOOL useSecond = YES, asc = YES;
|
|
|
|
if ([oldDescriptors count] > 0)
|
|
|
|
{
|
|
|
|
NSSortDescriptor * descriptor = [oldDescriptors objectAtIndex: 0];
|
|
|
|
[descriptors addObject: descriptor];
|
|
|
|
|
|
|
|
if ((useSecond = ![[descriptor key] isEqualToString: @"IP"]))
|
|
|
|
asc = [descriptor ascending];
|
|
|
|
}
|
|
|
|
|
|
|
|
//sort by IP after primary sort
|
|
|
|
if (useSecond)
|
|
|
|
{
|
|
|
|
NSSortDescriptor * secondDescriptor = [[NSSortDescriptor alloc] initWithKey: @"IP" ascending: asc
|
2008-06-27 06:08:12 +00:00
|
|
|
selector: @selector(compareNumeric:)];
|
2007-10-07 12:24:26 +00:00
|
|
|
[descriptors addObject: secondDescriptor];
|
|
|
|
[secondDescriptor release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return descriptors;
|
|
|
|
}
|
|
|
|
|
2008-06-22 01:31:50 +00:00
|
|
|
- (BOOL) canQuickLookFile: (FileListNode *) item
|
|
|
|
{
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
2009-10-22 00:10:41 +00:00
|
|
|
return ([item isFolder] || [torrent fileProgress: item] >= 1.0) && [torrent fileLocation: item];
|
2008-06-22 01:31:50 +00:00
|
|
|
}
|
|
|
|
|
2009-09-21 03:56:57 +00:00
|
|
|
#warning doesn't like blank addresses
|
2008-06-02 17:26:02 +00:00
|
|
|
- (void) addTrackers
|
|
|
|
{
|
|
|
|
[[self window] makeKeyWindow];
|
|
|
|
|
2009-09-29 03:02:44 +00:00
|
|
|
[fTrackers addObject: [NSNumber numberWithInt: [(TrackerNode *)[fTrackers lastObject] tier]+1]];
|
2009-09-17 00:33:39 +00:00
|
|
|
[fTrackers addObject: @""];
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2009-09-29 03:02:44 +00:00
|
|
|
[fTrackerTable setTrackers: fTrackers];
|
2008-06-02 17:26:02 +00:00
|
|
|
[fTrackerTable reloadData];
|
2009-09-17 00:33:39 +00:00
|
|
|
[fTrackerTable selectRowIndexes: [NSIndexSet indexSetWithIndex: [fTrackers count]-1] byExtendingSelection: NO];
|
2009-09-28 01:57:35 +00:00
|
|
|
[fTrackerTable editColumn: [fTrackerTable columnWithIdentifier: @"Tracker"] row: [fTrackers count]-1 withEvent: nil select: YES];
|
2008-06-02 17:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) removeTrackers
|
|
|
|
{
|
2009-09-29 03:53:57 +00:00
|
|
|
const NSInteger oldCount = [fTrackers count] - [(TrackerNode *)[fTrackers lastObject] tier];
|
2009-10-10 19:55:47 +00:00
|
|
|
NSMutableSet * addresses = [NSMutableSet setWithCapacity: oldCount];
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2009-09-29 03:53:57 +00:00
|
|
|
NSIndexSet * indexes = [fTrackerTable selectedRowIndexes];
|
|
|
|
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
2008-06-02 17:26:02 +00:00
|
|
|
{
|
2009-09-29 03:53:57 +00:00
|
|
|
id item = [fTrackers objectAtIndex: i];
|
|
|
|
if ([item isKindOfClass: [NSNumber class]])
|
2008-06-02 17:26:02 +00:00
|
|
|
{
|
2009-10-01 01:15:37 +00:00
|
|
|
for (++i; i < [fTrackers count] && ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; ++i)
|
|
|
|
[addresses addObject: [[fTrackers objectAtIndex: i] fullAnnounceAddress]];
|
2009-09-29 03:53:57 +00:00
|
|
|
--i;
|
2008-06-02 17:26:02 +00:00
|
|
|
}
|
2008-06-02 18:47:54 +00:00
|
|
|
else
|
2009-09-29 03:53:57 +00:00
|
|
|
[addresses addObject: [(TrackerNode *)item fullAnnounceAddress]];
|
2008-06-02 18:47:54 +00:00
|
|
|
}
|
2008-06-02 18:34:58 +00:00
|
|
|
|
2009-09-29 03:53:57 +00:00
|
|
|
if (oldCount == [addresses count])
|
2008-06-02 18:34:58 +00:00
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
return;
|
|
|
|
}
|
2008-06-02 17:26:02 +00:00
|
|
|
|
2009-09-17 01:10:18 +00:00
|
|
|
if ([[NSUserDefaults standardUserDefaults] boolForKey: @"WarningRemoveTrackers"])
|
2008-06-02 18:34:58 +00:00
|
|
|
{
|
2008-06-02 19:17:04 +00:00
|
|
|
NSAlert * alert = [[NSAlert alloc] init];
|
2008-06-02 18:34:58 +00:00
|
|
|
|
2009-09-29 03:53:57 +00:00
|
|
|
if ([addresses count] > 1)
|
2008-06-02 18:34:58 +00:00
|
|
|
{
|
2009-09-17 01:10:18 +00:00
|
|
|
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"Are you sure you want to remove %d trackers?",
|
2009-09-29 03:53:57 +00:00
|
|
|
"Remove trackers alert -> title"), [addresses count]]];
|
2009-09-17 01:10:18 +00:00
|
|
|
[alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact them."
|
|
|
|
" This cannot be undone.", "Remove trackers alert -> message")];
|
2008-06-02 18:34:58 +00:00
|
|
|
}
|
2008-06-02 19:17:04 +00:00
|
|
|
else
|
|
|
|
{
|
2009-09-17 01:10:18 +00:00
|
|
|
[alert setMessageText: NSLocalizedString(@"Are you sure you want to remove this tracker?", "Remove trackers alert -> title")];
|
|
|
|
[alert setInformativeText: NSLocalizedString(@"Once removed, Transmission will no longer attempt to contact it."
|
|
|
|
" This cannot be undone.", "Remove trackers alert -> message")];
|
2008-06-02 19:17:04 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 01:10:18 +00:00
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Remove", "Remove trackers alert -> button")];
|
|
|
|
[alert addButtonWithTitle: NSLocalizedString(@"Cancel", "Remove trackers alert -> button")];
|
2008-06-02 19:17:04 +00:00
|
|
|
|
2008-12-26 05:57:51 +00:00
|
|
|
[alert setShowsSuppressionButton: YES];
|
2008-06-02 19:17:04 +00:00
|
|
|
|
|
|
|
NSInteger result = [alert runModal];
|
2008-12-26 05:57:51 +00:00
|
|
|
if ([[alert suppressionButton] state] == NSOnState)
|
2009-09-17 01:10:18 +00:00
|
|
|
[[NSUserDefaults standardUserDefaults] setBool: NO forKey: @"WarningRemoveTrackers"];
|
2008-06-02 19:17:04 +00:00
|
|
|
[alert release];
|
|
|
|
|
|
|
|
if (result != NSAlertFirstButtonReturn)
|
|
|
|
return;
|
2008-06-02 18:34:58 +00:00
|
|
|
}
|
|
|
|
|
2009-09-17 01:15:00 +00:00
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
2009-09-29 03:53:57 +00:00
|
|
|
[torrent removeTrackersWithAnnounceAddresses: addresses];
|
2008-06-02 17:26:02 +00:00
|
|
|
|
|
|
|
//reset table with either new or old value
|
|
|
|
[fTrackers release];
|
2009-09-29 03:02:44 +00:00
|
|
|
fTrackers = [[torrent allTrackerStats] retain];
|
2008-06-02 17:26:02 +00:00
|
|
|
|
|
|
|
[fTrackerTable setTrackers: fTrackers];
|
|
|
|
[fTrackerTable reloadData];
|
2009-09-29 03:53:57 +00:00
|
|
|
[fTrackerTable deselectAll: self];
|
2009-10-11 13:45:50 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil]; //incase sort by tracker
|
2008-06-02 17:26:02 +00:00
|
|
|
}
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
@end
|