2007-09-16 01:02:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-02 16:55:05 +00:00
|
|
|
* Copyright (c) 2006-2008 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"
|
2007-10-07 02:25:39 +00:00
|
|
|
#import "InfoTabButtonCell.h"
|
2007-10-27 18:40:43 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-09-16 01:02:06 +00:00
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
#define INVALID -99
|
|
|
|
|
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;
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
- (NSView *) tabViewForTag: (int) tag;
|
2007-09-16 01:02:06 +00:00
|
|
|
- (NSArray *) peerSortDescriptors;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoWindowController
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
return [super initWithWindowNibName: @"InfoWindow"];
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
float windowHeight = [window frame].size.height;
|
|
|
|
|
|
|
|
[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"];
|
2007-10-06 22:23:44 +00:00
|
|
|
int tag;
|
|
|
|
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
|
|
|
|
2008-01-15 21:49:40 +00:00
|
|
|
//reset images for reveal buttons, since the images are also used in the main table
|
|
|
|
NSImage * revealOn = [[NSImage imageNamed: @"RevealOn.png"] copy],
|
|
|
|
* revealOff = [[NSImage imageNamed: @"RevealOff.png"] copy];
|
|
|
|
[revealOn setFlipped: NO];
|
|
|
|
[revealOff setFlipped: NO];
|
|
|
|
|
|
|
|
[fRevealDataButton setImage: revealOff];
|
|
|
|
[fRevealDataButton setAlternateImage: revealOn];
|
|
|
|
[fRevealTorrentButton setImage: revealOff];
|
|
|
|
[fRevealTorrentButton setAlternateImage: revealOn];
|
|
|
|
|
|
|
|
[revealOn release];
|
|
|
|
[revealOff release];
|
|
|
|
|
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]]];
|
|
|
|
|
2007-11-17 16:22:50 +00:00
|
|
|
//set table header tool tips
|
|
|
|
if ([NSApp isOnLeopardOrBetter])
|
|
|
|
{
|
|
|
|
[[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",
|
2008-01-04 00:29:13 +00:00
|
|
|
"inspector -> peer table -> header tool tip")];
|
2007-11-17 16:22:50 +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-02-27 13:52:43 +00:00
|
|
|
[fTrackers 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];
|
|
|
|
|
|
|
|
int numberSelected = [fTorrents count];
|
|
|
|
if (numberSelected != 1)
|
|
|
|
{
|
|
|
|
if (numberSelected > 0)
|
|
|
|
{
|
2007-10-27 22:11:41 +00:00
|
|
|
[fImageView setImage: [NSImage imageNamed: [NSApp isOnLeopardOrBetter]
|
|
|
|
? NSImageNameMultipleDocuments : @"NSApplicationIcon"]];
|
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;
|
2007-11-25 04:06:26 +00:00
|
|
|
int fileCount = 0;
|
2007-09-16 01:02:06 +00:00
|
|
|
NSEnumerator * enumerator = [torrents objectEnumerator];
|
|
|
|
Torrent * torrent;
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
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-03-19 18:03:02 +00:00
|
|
|
[fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%u bytes", "Inspector -> selected torrents"),
|
|
|
|
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: @""];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//options fields
|
|
|
|
[fUploadLimitPopUp setEnabled: NO];
|
|
|
|
[fUploadLimitPopUp selectItemAtIndex: -1];
|
|
|
|
[fUploadLimitField setHidden: YES];
|
|
|
|
[fUploadLimitLabel setHidden: YES];
|
|
|
|
[fUploadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
[fDownloadLimitPopUp setEnabled: NO];
|
|
|
|
[fDownloadLimitPopUp selectItemAtIndex: -1];
|
|
|
|
[fDownloadLimitField setHidden: YES];
|
|
|
|
[fDownloadLimitLabel setHidden: YES];
|
|
|
|
[fDownloadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
[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: @""];
|
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];
|
|
|
|
|
|
|
|
[fTrackerField setStringValue: @""];
|
|
|
|
[fPiecesField setStringValue: @""];
|
|
|
|
[fHashField setStringValue: @""];
|
|
|
|
[fHashField setToolTip: nil];
|
|
|
|
[fSecureField setStringValue: @""];
|
|
|
|
[fCommentView setString: @""];
|
|
|
|
|
|
|
|
[fCreatorField setStringValue: @""];
|
|
|
|
[fDateCreatedField setStringValue: @""];
|
|
|
|
[fCommentView setSelectable: NO];
|
|
|
|
|
|
|
|
[fTorrentLocationField setStringValue: @""];
|
|
|
|
[fTorrentLocationField setToolTip: nil];
|
|
|
|
[fDataLocationField setStringValue: @""];
|
|
|
|
[fDataLocationField setToolTip: nil];
|
|
|
|
|
|
|
|
[fRevealDataButton setHidden: YES];
|
|
|
|
[fRevealTorrentButton setHidden: YES];
|
|
|
|
|
|
|
|
//don't allow empty fields to be selected
|
|
|
|
[fTrackerField setSelectable: NO];
|
|
|
|
[fHashField setSelectable: NO];
|
|
|
|
[fCreatorField setSelectable: NO];
|
|
|
|
[fTorrentLocationField setSelectable: NO];
|
|
|
|
[fDataLocationField setSelectable: NO];
|
|
|
|
|
|
|
|
[fStateField setStringValue: @""];
|
|
|
|
[fProgressField setStringValue: @""];
|
|
|
|
[fRatioField setStringValue: @""];
|
|
|
|
|
|
|
|
[fSwarmSpeedField setStringValue: @""];
|
|
|
|
[fErrorMessageView setString: @""];
|
|
|
|
[fErrorMessageView setSelectable: NO];
|
|
|
|
|
2008-02-22 01:36:30 +00:00
|
|
|
[fAnnounceAddressField setStringValue: @""];
|
|
|
|
[fAnnounceAddressField setToolTip: nil];
|
|
|
|
[fAnnounceAddressField setSelectable: NO];
|
|
|
|
[fAnnounceLastField setStringValue: @""];
|
|
|
|
[fAnnounceResponseField setStringValue: @""];
|
2008-02-22 04:37:52 +00:00
|
|
|
[fAnnounceResponseField setToolTip: nil];
|
|
|
|
[fAnnounceResponseField setSelectable: NO];
|
2008-02-22 01:36:30 +00:00
|
|
|
[fAnnounceNextField setStringValue: @""];
|
|
|
|
|
|
|
|
[fScrapeAddressField setStringValue: @""];
|
|
|
|
[fScrapeAddressField setToolTip: nil];
|
|
|
|
[fScrapeAddressField setSelectable: NO];
|
|
|
|
[fScrapeLastField setStringValue: @""];
|
|
|
|
[fScrapeResponseField setStringValue: @""];
|
2008-02-22 04:37:52 +00:00
|
|
|
[fScrapeResponseField setToolTip: nil];
|
|
|
|
[fScrapeResponseField setSelectable: NO];
|
2008-02-22 01:36:30 +00:00
|
|
|
[fScrapeNextField setStringValue: @""];
|
|
|
|
|
2008-04-28 18:44:00 +00:00
|
|
|
[fConnectedPeersField setStringValue: @""];
|
2007-10-01 16:23:00 +00:00
|
|
|
[fDownloadingFromField setStringValue: @""];
|
|
|
|
[fUploadingToField setStringValue: @""];
|
|
|
|
[fKnownField setStringValue: @""];
|
|
|
|
[fSeedersField setStringValue: @""];
|
|
|
|
[fLeechersField setStringValue: @""];
|
|
|
|
[fCompletedFromTrackerField setStringValue: @""];
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
[fTrackers release];
|
|
|
|
fTrackers = nil;
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
2008-01-04 00:29:13 +00:00
|
|
|
[fFileController setTorrent: torrent];
|
2007-10-20 19:13:52 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
NSImage * icon = [[torrent icon] copy];
|
|
|
|
[icon setFlipped: NO];
|
|
|
|
[fImageView setImage: icon];
|
|
|
|
[icon release];
|
|
|
|
|
|
|
|
NSString * name = [torrent name];
|
|
|
|
[fNameField setStringValue: name];
|
|
|
|
[fNameField setToolTip: name];
|
2007-11-25 04:06:26 +00:00
|
|
|
|
|
|
|
NSString * basicString = [NSString stringForFileSize: [torrent size]];
|
|
|
|
if ([torrent folder])
|
|
|
|
{
|
|
|
|
NSString * fileString;
|
|
|
|
int fileCount = [torrent fileCount];
|
|
|
|
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-03-19 18:03:02 +00:00
|
|
|
[fBasicInfoField setToolTip: [NSString stringWithFormat: NSLocalizedString(@"%u bytes", "Inspector -> selected torrents"),
|
|
|
|
[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]
|
2007-12-24 05:05:56 +00:00
|
|
|
? NSLocalizedString(@"Private Torrent, PEX automatically disabled", "Inspector -> private torrent")
|
|
|
|
: 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]];
|
|
|
|
|
|
|
|
BOOL publicTorrent = [torrent publicTorrent];
|
|
|
|
[fTorrentLocationField setStringValue: publicTorrent
|
|
|
|
? [[torrent publicTorrentLocation] stringByAbbreviatingWithTildeInPath]
|
|
|
|
: NSLocalizedString(@"Transmission Support Folder", "Torrent -> location when deleting original")];
|
|
|
|
if (publicTorrent)
|
2008-05-01 02:20:53 +00:00
|
|
|
[fTorrentLocationField setToolTip: [[torrent publicTorrentLocation] stringByAppendingFormat: @"\n\n%@",
|
|
|
|
[torrent torrentLocation]]];
|
2007-09-16 01:02:06 +00:00
|
|
|
else
|
|
|
|
[fTorrentLocationField setToolTip: [torrent torrentLocation]];
|
|
|
|
|
|
|
|
[fDateAddedField setObjectValue: [torrent dateAdded]];
|
|
|
|
|
|
|
|
[fRevealDataButton setHidden: NO];
|
|
|
|
[fRevealTorrentButton setHidden: ![torrent publicTorrent]];
|
|
|
|
|
|
|
|
//allow these fields to be selected
|
|
|
|
[fTrackerField setSelectable: YES];
|
|
|
|
[fHashField setSelectable: YES];
|
|
|
|
[fCommentView setSelectable: ![commentString isEqualToString: @""]];
|
|
|
|
[fCreatorField setSelectable: ![creatorString isEqualToString: @""]];
|
|
|
|
[fTorrentLocationField setSelectable: YES];
|
|
|
|
[fDataLocationField setSelectable: YES];
|
2008-02-22 01:36:30 +00:00
|
|
|
[fAnnounceAddressField setSelectable: YES];
|
|
|
|
[fScrapeAddressField setSelectable: YES];
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
//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
|
|
|
|
|
|
|
//get trackers for table
|
|
|
|
[fTrackers release];
|
2008-03-21 21:07:31 +00:00
|
|
|
fTrackers = [[torrent allTrackers: YES] retain];
|
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
|
|
|
|
2008-02-26 22:56:27 +00:00
|
|
|
[fTrackerTable reloadData];
|
2007-09-16 01:02:06 +00:00
|
|
|
[fPeerTable reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|
|
|
|
|
|
|
|
int uploadSpeedMode = [torrent speedMode: YES],
|
|
|
|
uploadSpeedLimit = [torrent speedLimit: YES],
|
|
|
|
downloadSpeedMode = [torrent speedMode: NO],
|
|
|
|
downloadSpeedLimit = [torrent speedLimit: NO];
|
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject])
|
|
|
|
&& (uploadSpeedMode != INVALID || uploadSpeedLimit != INVALID
|
|
|
|
|| downloadSpeedMode != INVALID || downloadSpeedLimit != INVALID))
|
|
|
|
{
|
|
|
|
if (uploadSpeedMode != INVALID && uploadSpeedMode != [torrent speedMode: YES])
|
|
|
|
uploadSpeedMode = INVALID;
|
|
|
|
|
|
|
|
if (uploadSpeedLimit != INVALID && uploadSpeedLimit != [torrent speedLimit: YES])
|
|
|
|
uploadSpeedLimit = INVALID;
|
|
|
|
|
|
|
|
if (downloadSpeedMode != INVALID && downloadSpeedMode != [torrent speedMode: NO])
|
|
|
|
downloadSpeedMode = INVALID;
|
|
|
|
|
|
|
|
if (downloadSpeedLimit != INVALID && downloadSpeedLimit != [torrent speedLimit: NO])
|
|
|
|
downloadSpeedLimit = INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set upload view
|
|
|
|
int index;
|
|
|
|
if (uploadSpeedMode == TR_SPEEDLIMIT_SINGLE)
|
|
|
|
index = OPTION_POPUP_LIMIT;
|
|
|
|
else if (uploadSpeedMode == TR_SPEEDLIMIT_UNLIMITED)
|
|
|
|
index = OPTION_POPUP_NO_LIMIT;
|
|
|
|
else if (uploadSpeedMode == TR_SPEEDLIMIT_GLOBAL)
|
|
|
|
index = OPTION_POPUP_GLOBAL;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
[fUploadLimitPopUp selectItemAtIndex: index];
|
|
|
|
[fUploadLimitPopUp setEnabled: YES];
|
|
|
|
|
|
|
|
[fUploadLimitLabel setHidden: uploadSpeedMode != TR_SPEEDLIMIT_SINGLE];
|
|
|
|
[fUploadLimitField setHidden: uploadSpeedMode != TR_SPEEDLIMIT_SINGLE];
|
|
|
|
if (uploadSpeedLimit != INVALID)
|
|
|
|
[fUploadLimitField setIntValue: uploadSpeedLimit];
|
|
|
|
else
|
|
|
|
[fUploadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
//set download view
|
|
|
|
if (downloadSpeedMode == TR_SPEEDLIMIT_SINGLE)
|
|
|
|
index = OPTION_POPUP_LIMIT;
|
|
|
|
else if (downloadSpeedMode == TR_SPEEDLIMIT_UNLIMITED)
|
|
|
|
index = OPTION_POPUP_NO_LIMIT;
|
|
|
|
else if (downloadSpeedMode == TR_SPEEDLIMIT_GLOBAL)
|
|
|
|
index = OPTION_POPUP_GLOBAL;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
[fDownloadLimitPopUp selectItemAtIndex: index];
|
|
|
|
[fDownloadLimitPopUp setEnabled: YES];
|
|
|
|
|
|
|
|
[fDownloadLimitLabel setHidden: downloadSpeedMode != TR_SPEEDLIMIT_SINGLE];
|
|
|
|
[fDownloadLimitField setHidden: downloadSpeedMode != TR_SPEEDLIMIT_SINGLE];
|
|
|
|
if (downloadSpeedLimit != INVALID)
|
|
|
|
[fDownloadLimitField setIntValue: downloadSpeedLimit];
|
|
|
|
else
|
|
|
|
[fDownloadLimitField setStringValue: @""];
|
|
|
|
|
|
|
|
//get ratio info
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
|
|
|
int checkRatio = [torrent ratioSetting];
|
|
|
|
float ratioLimit = [torrent ratioLimit];
|
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject]) && (checkRatio != INVALID || checkRatio != INVALID))
|
|
|
|
{
|
|
|
|
if (checkRatio != INVALID && checkRatio != [torrent ratioSetting])
|
|
|
|
checkRatio = INVALID;
|
|
|
|
|
|
|
|
if (ratioLimit != INVALID && ratioLimit != [torrent ratioLimit])
|
|
|
|
ratioLimit = INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
//set ratio view
|
|
|
|
if (checkRatio == NSOnState)
|
|
|
|
index = OPTION_POPUP_LIMIT;
|
|
|
|
else if (checkRatio == NSOffState)
|
|
|
|
index = OPTION_POPUP_NO_LIMIT;
|
|
|
|
else if (checkRatio == NSMixedState)
|
|
|
|
index = OPTION_POPUP_GLOBAL;
|
|
|
|
else
|
|
|
|
index = -1;
|
|
|
|
[fRatioPopUp selectItemAtIndex: index];
|
|
|
|
[fRatioPopUp setEnabled: YES];
|
|
|
|
|
|
|
|
[fRatioLimitField setHidden: checkRatio != NSOnState];
|
|
|
|
if (ratioLimit != INVALID)
|
|
|
|
[fRatioLimitField setFloatValue: ratioLimit];
|
|
|
|
else
|
|
|
|
[fRatioLimitField setStringValue: @""];
|
2007-12-22 05:21:25 +00:00
|
|
|
|
|
|
|
//get peer info
|
|
|
|
enumerator = [fTorrents objectEnumerator];
|
|
|
|
torrent = [enumerator nextObject]; //first torrent
|
|
|
|
|
|
|
|
int maxPeers = [torrent maxPeerConnect];
|
|
|
|
|
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];
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setTab: (id) sender
|
|
|
|
{
|
|
|
|
int 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-02-27 01:57:13 +00:00
|
|
|
float 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)
|
|
|
|
{
|
|
|
|
case TAB_TRACKER_TAG:
|
|
|
|
oldResizeSaveKey = @"InspectorContentHeightTracker";
|
|
|
|
break;
|
|
|
|
case TAB_PEERS_TAG:
|
2008-02-27 13:52:43 +00:00
|
|
|
[fPeers release];
|
|
|
|
fPeers = nil;
|
|
|
|
|
2008-02-27 02:06:46 +00:00
|
|
|
oldResizeSaveKey = @"InspectorContentHeightPeers";
|
|
|
|
break;
|
|
|
|
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
|
|
|
|
|
|
|
[fPiecesView updateView: YES];
|
|
|
|
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:
|
|
|
|
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-02-27 01:57:13 +00:00
|
|
|
float height = [[NSUserDefaults standardUserDefaults] floatForKey: resizeSaveKey];
|
2007-10-07 15:55:27 +00:00
|
|
|
if (height != 0)
|
|
|
|
viewRect.size.height = MAX(height, TAB_MIN_HEIGHT);
|
2007-10-06 22:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float difference = (viewRect.size.height - oldHeight) * [window userSpaceScaleFactor];
|
|
|
|
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];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNextTab
|
|
|
|
{
|
2007-10-06 22:23:44 +00:00
|
|
|
int tag = [fTabMatrix selectedTag]+1;
|
|
|
|
if (tag >= [fTabMatrix numberOfColumns])
|
|
|
|
tag = 0;
|
|
|
|
|
|
|
|
[fTabMatrix selectCellWithTag: tag];
|
|
|
|
[self setTab: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPreviousTab
|
|
|
|
{
|
2007-10-06 22:23:44 +00:00
|
|
|
int tag = [fTabMatrix selectedTag]-1;
|
|
|
|
if (tag < 0)
|
|
|
|
tag = [fTabMatrix numberOfColumns]-1;
|
|
|
|
|
|
|
|
[fTabMatrix selectCellWithTag: tag];
|
|
|
|
[self setTab: nil];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int) numberOfRowsInTableView: (NSTableView *) tableView
|
|
|
|
{
|
|
|
|
if (tableView == fPeerTable)
|
|
|
|
return fPeers ? [fPeers 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) column row: (int) row
|
|
|
|
{
|
|
|
|
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-02-26 22:56:27 +00:00
|
|
|
else if (tableView == fTrackerTable)
|
|
|
|
{
|
2008-02-27 13:52:43 +00:00
|
|
|
id item = [fTrackers objectAtIndex: row];
|
2008-02-26 22:56:27 +00:00
|
|
|
if ([item isKindOfClass: [NSNumber class]])
|
2008-02-27 01:25:37 +00:00
|
|
|
return [NSString stringWithFormat: NSLocalizedString(@"Tier %d", "Inspector -> tracker table"), [item intValue]+1];
|
2008-02-26 22:56:27 +00:00
|
|
|
else
|
|
|
|
return item;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-01 11:34:01 +00:00
|
|
|
- (BOOL) tableView: (NSTableView *) tableView shouldSelectRow: (int) row
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2008-02-26 22:56:27 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|
|
|
|
tableColumn: (NSTableColumn *) column row: (int) row mouseLocation: (NSPoint) mouseLocation
|
|
|
|
{
|
|
|
|
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-03-24 00:06:54 +00:00
|
|
|
[components addObject: [NSString localizedStringWithFormat: NSLocalizedString(@"Progress: %.1f%%",
|
2007-10-01 11:41:15 +00:00
|
|
|
"Inspector -> Peers tab -> table row tooltip"), [[peer objectForKey: @"Progress"] floatValue] * 100.0]];
|
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;
|
2007-09-16 01:02:06 +00:00
|
|
|
int port;
|
|
|
|
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
|
|
|
|
2007-10-01 11:41:15 +00:00
|
|
|
switch ([[peer objectForKey: @"From"] intValue])
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2008-01-14 05:53:38 +00:00
|
|
|
//determing status strings from flags
|
|
|
|
NSMutableArray * statusArray = [NSMutableArray arrayWithCapacity: 3];
|
|
|
|
NSString * flags = [peer objectForKey: @"Flags"];
|
|
|
|
|
|
|
|
if ([flags rangeOfString: @"D"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Currently downloading (interested and not choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
else if ([flags rangeOfString: @"d"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"You want to download, but peer does not want to send (interested and choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
else;
|
|
|
|
|
|
|
|
if ([flags rangeOfString: @"U"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Currently uploading (interested and not choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
else if ([flags rangeOfString: @"u"].location != NSNotFound)
|
|
|
|
[statusArray addObject: NSLocalizedString(@"Peer wants you to upload, but you do not want to (interested and choked)",
|
|
|
|
"Inspector -> peer -> status")];
|
|
|
|
else;
|
|
|
|
|
|
|
|
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)
|
|
|
|
[components addObject: [@"\n" stringByAppendingString: [statusArray componentsJoinedByString: @"\n\n"]]];
|
2008-01-09 19:52:11 +00:00
|
|
|
|
2007-09-16 01:02:06 +00:00
|
|
|
return [components componentsJoinedByString: @"\n"];
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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"];
|
|
|
|
[fPiecesView updateView: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealTorrentFile: (id) sender
|
|
|
|
{
|
|
|
|
if ([fTorrents count] > 0)
|
|
|
|
[[fTorrents objectAtIndex: 0] revealPublicTorrent];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealDataFile: (id) sender
|
|
|
|
{
|
|
|
|
if ([fTorrents count] > 0)
|
|
|
|
[[fTorrents objectAtIndex: 0] revealData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSpeedMode: (id) sender
|
|
|
|
{
|
|
|
|
BOOL upload = sender == fUploadLimitPopUp;
|
2007-10-15 01:57:56 +00:00
|
|
|
int mode;
|
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
|
|
|
case OPTION_POPUP_LIMIT:
|
|
|
|
mode = TR_SPEEDLIMIT_SINGLE;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_NO_LIMIT:
|
|
|
|
mode = TR_SPEEDLIMIT_UNLIMITED;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_GLOBAL:
|
|
|
|
mode = TR_SPEEDLIMIT_GLOBAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setSpeedMode: mode upload: upload];
|
|
|
|
|
|
|
|
NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField;
|
|
|
|
|
|
|
|
BOOL single = mode == TR_SPEEDLIMIT_SINGLE;
|
|
|
|
[field setHidden: !single];
|
|
|
|
if (single)
|
|
|
|
{
|
|
|
|
[field selectText: self];
|
|
|
|
[[self window] makeKeyAndOrderFront:self];
|
|
|
|
}
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
NSTextField * label = upload ? fUploadLimitLabel : fDownloadLimitLabel;
|
|
|
|
[label setHidden: !single];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setSpeedLimit: (id) sender
|
|
|
|
{
|
|
|
|
BOOL upload = sender == fUploadLimitField;
|
2007-12-23 17:08:13 +00:00
|
|
|
int limit = [sender intValue];
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
2007-12-23 17:08:13 +00:00
|
|
|
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setSpeedLimit: limit upload: upload];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioSetting: (id) sender
|
|
|
|
{
|
2007-10-15 01:57:56 +00:00
|
|
|
int setting;
|
|
|
|
switch ([sender indexOfSelectedItem])
|
|
|
|
{
|
|
|
|
case OPTION_POPUP_LIMIT:
|
|
|
|
setting = NSOnState;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_NO_LIMIT:
|
|
|
|
setting = NSOffState;
|
|
|
|
break;
|
|
|
|
case OPTION_POPUP_GLOBAL:
|
|
|
|
setting = NSMixedState;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setRatioSetting: setting];
|
|
|
|
|
|
|
|
BOOL single = setting == NSOnState;
|
|
|
|
[fRatioLimitField setHidden: !single];
|
|
|
|
if (single)
|
|
|
|
{
|
|
|
|
[fRatioLimitField selectText: self];
|
|
|
|
[[self window] makeKeyAndOrderFront:self];
|
|
|
|
}
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateUI" object: nil];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setRatioLimit: (id) sender
|
|
|
|
{
|
2007-12-23 17:08:13 +00:00
|
|
|
float limit = [sender floatValue];
|
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
2007-12-23 17:08:13 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[torrent setRatioLimit: limit];
|
2007-10-07 15:55:27 +00:00
|
|
|
}
|
|
|
|
|
2007-12-22 05:21:25 +00:00
|
|
|
- (void) setPeersConnectLimit: (id) sender
|
|
|
|
{
|
2007-12-23 17:08:13 +00:00
|
|
|
int limit = [sender intValue];
|
|
|
|
|
2007-12-22 05:21:25 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
2007-12-23 17:08:13 +00:00
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
[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];
|
|
|
|
|
2008-04-24 06:35:21 +00:00
|
|
|
[fTrackerField setStringValue: [torrent trackerAddressAnnounce]];
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
NSString * location = [torrent dataLocation];
|
|
|
|
[fDataLocationField setStringValue: [location stringByAbbreviatingWithTildeInPath]];
|
|
|
|
[fDataLocationField setToolTip: location];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfoActivity
|
|
|
|
{
|
|
|
|
int numberSelected = [fTorrents count];
|
|
|
|
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;
|
2007-10-07 15:55:27 +00:00
|
|
|
Torrent * torrent;
|
|
|
|
NSEnumerator * enumerator = [fTorrents objectEnumerator];
|
|
|
|
while ((torrent = [enumerator nextObject]))
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
|
|
|
[fStateField setStringValue: [torrent stateString]];
|
2008-03-31 20:58:33 +00:00
|
|
|
|
|
|
|
if ([torrent folder])
|
|
|
|
[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]];
|
|
|
|
|
|
|
|
[fPiecesView updateView: NO];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2008-05-06 01:53:15 +00:00
|
|
|
#warning reload table when necessary?
|
2008-02-22 01:36:30 +00:00
|
|
|
- (void) updateInfoTracker
|
|
|
|
{
|
|
|
|
if ([fTorrents count] != 1)
|
|
|
|
return;
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
|
|
|
//announce fields
|
2008-04-24 06:35:21 +00:00
|
|
|
NSString * announceAddress = [torrent trackerAddressAnnounce];
|
2008-02-22 01:36:30 +00:00
|
|
|
[fAnnounceAddressField setStringValue: announceAddress];
|
|
|
|
[fAnnounceAddressField setToolTip: announceAddress];
|
|
|
|
|
|
|
|
[fAnnounceLastField setObjectValue: [torrent lastAnnounceTime]];
|
2008-02-22 04:37:52 +00:00
|
|
|
|
|
|
|
NSString * announceResponse = [torrent announceResponse];
|
|
|
|
[fAnnounceResponseField setStringValue: announceResponse];
|
|
|
|
[fAnnounceResponseField setToolTip: announceResponse];
|
|
|
|
[fAnnounceResponseField setSelectable: ![announceResponse isEqualToString: @""]];
|
2008-02-22 01:36:30 +00:00
|
|
|
|
|
|
|
int announceNext = [torrent nextAnnounceTime];
|
2008-02-22 15:29:20 +00:00
|
|
|
[fAnnounceNextField setStringValue: announceNext > 0 ? [NSString timeString: announceNext showSeconds: YES] : @""];
|
2008-02-22 01:36:30 +00:00
|
|
|
|
|
|
|
//scrape fields
|
2008-04-24 06:35:21 +00:00
|
|
|
NSString * scrapeAddress;
|
|
|
|
if ((scrapeAddress = [torrent trackerAddressScrape]))
|
2008-03-30 04:41:55 +00:00
|
|
|
{
|
|
|
|
[fScrapeAddressField setStringValue: scrapeAddress];
|
|
|
|
[fScrapeAddressField setToolTip: scrapeAddress];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fScrapeAddressField setStringValue: @""];
|
|
|
|
[fScrapeAddressField setToolTip: @""];
|
|
|
|
}
|
2008-02-22 01:36:30 +00:00
|
|
|
|
|
|
|
[fScrapeLastField setObjectValue: [torrent lastScrapeTime]];
|
2008-02-22 04:37:52 +00:00
|
|
|
|
|
|
|
NSString * scrapeResponse = [torrent scrapeResponse];
|
|
|
|
[fScrapeResponseField setStringValue: scrapeResponse];
|
|
|
|
[fScrapeResponseField setToolTip: scrapeResponse];
|
|
|
|
[fScrapeResponseField setSelectable: ![scrapeResponse isEqualToString: @""]];
|
2008-02-22 01:36:30 +00:00
|
|
|
|
|
|
|
int scrapeNext = [torrent nextScrapeTime];
|
2008-02-22 15:29:20 +00:00
|
|
|
[fScrapeNextField setStringValue: scrapeNext > 0 ? [NSString timeString: scrapeNext showSeconds: YES] : @""];
|
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
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
int seeders = [torrent seeders], leechers = [torrent leechers], completed = [torrent completedFromTracker];
|
2007-10-17 00:46:20 +00:00
|
|
|
[fSeedersField setStringValue: seeders >= 0 ? [NSString stringWithFormat: @"%d", seeders] : @""];
|
|
|
|
[fLeechersField setStringValue: leechers >= 0 ? [NSString stringWithFormat: @"%d", leechers] : @""];
|
|
|
|
[fCompletedFromTrackerField setStringValue: completed >= 0 ? [NSString stringWithFormat: @"%d", completed] : @""];
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
BOOL active = [torrent isActive];
|
|
|
|
|
|
|
|
if (active)
|
2007-09-16 01:02:06 +00:00
|
|
|
{
|
2007-10-07 15:55:27 +00:00
|
|
|
int total = [torrent totalPeersConnected];
|
|
|
|
NSString * connected = [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)
|
|
|
|
{
|
|
|
|
NSMutableArray * components = [NSMutableArray arrayWithCapacity: 4];
|
|
|
|
int count;
|
|
|
|
if ((count = [torrent totalPeersTracker]) > 0)
|
|
|
|
[components addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d tracker", "Inspector -> Peers tab -> peers"), count]];
|
|
|
|
if ((count = [torrent totalPeersIncoming]) > 0)
|
|
|
|
[components addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d incoming", "Inspector -> Peers tab -> peers"), count]];
|
|
|
|
if ((count = [torrent totalPeersPex]) > 0)
|
|
|
|
[components addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d PEX", "Inspector -> Peers tab -> peers"), count]];
|
|
|
|
if ((count = [torrent totalPeersCache]) > 0)
|
|
|
|
[components addObject: [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%d cache", "Inspector -> Peers tab -> peers"), count]];
|
|
|
|
|
|
|
|
connected = [connected stringByAppendingFormat: @": %@", [components componentsJoinedByString: @", "]];
|
|
|
|
}
|
2007-09-16 01:02:06 +00:00
|
|
|
|
2007-10-07 15:55:27 +00:00
|
|
|
[fConnectedPeersField setStringValue: connected];
|
|
|
|
|
|
|
|
[fDownloadingFromField setIntValue: [torrent peersSendingToUs]];
|
|
|
|
[fUploadingToField setIntValue: [torrent peersGettingFromUs]];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-04-28 18:44:00 +00:00
|
|
|
[fConnectedPeersField setStringValue: @""];
|
2007-10-07 15:55:27 +00:00
|
|
|
[fDownloadingFromField setStringValue: @""];
|
|
|
|
[fUploadingToField setStringValue: @""];
|
2007-09-16 01:02:06 +00:00
|
|
|
}
|
2007-10-07 15:55:27 +00:00
|
|
|
|
|
|
|
[fKnownField setIntValue: [torrent totalPeersKnown]];
|
|
|
|
|
|
|
|
[fPeers release];
|
|
|
|
fPeers = [[[torrent peers] sortedArrayUsingDescriptors: [self peerSortDescriptors]] retain];
|
|
|
|
|
|
|
|
[fPeerTable 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
|
|
|
}
|
|
|
|
|
2007-10-07 12:24:26 +00:00
|
|
|
- (NSView *) tabViewForTag: (int) tag
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|
|
|
|
selector: @selector(compareIP:)];
|
|
|
|
[descriptors addObject: secondDescriptor];
|
|
|
|
[secondDescriptor release];
|
|
|
|
}
|
|
|
|
|
|
|
|
return descriptors;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|