2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2010-2022 Transmission authors and contributors.
|
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2018-09-30 10:37:30 +00:00
|
|
|
#include <libtransmission/transmission.h>
|
|
|
|
#include <libtransmission/utils.h> //tr_getRatio()
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
#import "InfoActivityViewController.h"
|
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
#import "PiecesView.h"
|
|
|
|
#import "Torrent.h"
|
2010-04-23 16:59:14 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
#define PIECES_CONTROL_PROGRESS 0
|
|
|
|
#define PIECES_CONTROL_AVAILABLE 1
|
|
|
|
|
2022-07-17 23:04:32 +00:00
|
|
|
#define STACKVIEW_INSET 12.0
|
|
|
|
#define STACKVIEW_HORIZONTAL_SPACING 20.0
|
|
|
|
#define STACKVIEW_VERTICAL_SPACING 8.0
|
|
|
|
|
2022-01-24 01:32:45 +00:00
|
|
|
@interface InfoActivityViewController ()
|
2010-03-09 02:26:52 +00:00
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
@property(nonatomic, copy) NSArray<Torrent*>* fTorrents;
|
2022-02-22 16:04:20 +00:00
|
|
|
|
|
|
|
@property(nonatomic) BOOL fSet;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDateAddedField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDateCompletedField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDateActivityField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fStateField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fProgressField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fHaveField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDownloadedTotalField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fUploadedTotalField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fFailedHashField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fRatioField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDownloadTimeField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fSeedTimeField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextView* fErrorMessageView;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet PiecesView* fPiecesView;
|
|
|
|
@property(nonatomic) IBOutlet NSSegmentedControl* fPiecesControl;
|
|
|
|
|
|
|
|
//remove when we switch to auto layout
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fTransferSectionLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDatesSectionLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fTimeSectionLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fStateLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fProgressLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fHaveLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDownloadedLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fUploadedLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fFailedDLLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fRatioLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fErrorLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDateAddedLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDateCompletedLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDateActivityLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDownloadTimeLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fSeedTimeLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSScrollView* fErrorScrollView;
|
|
|
|
|
2022-07-17 23:04:32 +00:00
|
|
|
@property(nonatomic) IBOutlet NSStackView* fActivityStackView;
|
|
|
|
@property(nonatomic) IBOutlet NSView* fDatesView;
|
|
|
|
@property(nonatomic, readonly) CGFloat currentHeight;
|
|
|
|
@property(nonatomic, readonly) CGFloat horizLayoutHeight;
|
|
|
|
@property(nonatomic, readonly) CGFloat horizLayoutWidth;
|
|
|
|
@property(nonatomic, readonly) CGFloat vertLayoutHeight;
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setupInfo;
|
2010-03-09 02:26:52 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@implementation InfoActivityViewController
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (instancetype)init
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ((self = [super initWithNibName:@"InfoActivityView" bundle:nil]))
|
2010-03-14 03:09:12 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
self.title = NSLocalizedString(@"Activity", "Inspector view -> title");
|
2010-03-14 03:09:12 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2010-04-06 01:41:16 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTransferSectionLabel sizeToFit];
|
|
|
|
[self.fDatesSectionLabel sizeToFit];
|
|
|
|
[self.fTimeSectionLabel sizeToFit];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* labels = @[
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStateLabel,
|
|
|
|
self.fProgressLabel,
|
|
|
|
self.fHaveLabel,
|
|
|
|
self.fDownloadedLabel,
|
|
|
|
self.fUploadedLabel,
|
|
|
|
self.fFailedDLLabel,
|
|
|
|
self.fRatioLabel,
|
|
|
|
self.fErrorLabel,
|
|
|
|
self.fDateAddedLabel,
|
|
|
|
self.fDateCompletedLabel,
|
|
|
|
self.fDateActivityLabel,
|
|
|
|
self.fDownloadTimeLabel,
|
|
|
|
self.fSeedTimeLabel
|
2021-08-15 09:41:48 +00:00
|
|
|
];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-05-01 12:26:45 +00:00
|
|
|
CGFloat oldMaxWidth = 0.0, originX = 0.0, newMaxWidth = 0.0;
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSTextField* label in labels)
|
2012-09-27 00:17:43 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const oldFrame = label.frame;
|
2012-09-27 00:17:43 +00:00
|
|
|
if (oldFrame.size.width > oldMaxWidth)
|
|
|
|
{
|
|
|
|
oldMaxWidth = oldFrame.size.width;
|
|
|
|
originX = oldFrame.origin.x;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-09-27 00:17:43 +00:00
|
|
|
[label sizeToFit];
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const newWidth = label.bounds.size.width;
|
2012-09-27 00:17:43 +00:00
|
|
|
if (newWidth > newMaxWidth)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-09-27 00:17:43 +00:00
|
|
|
newMaxWidth = newWidth;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-09-27 00:17:43 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
for (NSTextField* label in labels)
|
2012-09-27 00:17:43 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect frame = label.frame;
|
2012-09-27 00:17:43 +00:00
|
|
|
frame.origin.x = originX + (newMaxWidth - frame.size.width);
|
2021-08-07 07:27:56 +00:00
|
|
|
label.frame = frame;
|
2012-09-27 00:17:43 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* fields = @[
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDateAddedField,
|
|
|
|
self.fDateCompletedField,
|
|
|
|
self.fDateActivityField,
|
|
|
|
self.fStateField,
|
|
|
|
self.fProgressField,
|
|
|
|
self.fHaveField,
|
|
|
|
self.fDownloadedTotalField,
|
|
|
|
self.fUploadedTotalField,
|
|
|
|
self.fFailedHashField,
|
|
|
|
self.fRatioField,
|
|
|
|
self.fDownloadTimeField,
|
|
|
|
self.fSeedTimeField,
|
|
|
|
self.fErrorScrollView
|
2021-08-15 09:41:48 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
CGFloat const widthIncrease = newMaxWidth - oldMaxWidth;
|
|
|
|
for (NSView* field in fields)
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect frame = field.frame;
|
2012-09-27 00:17:43 +00:00
|
|
|
frame.origin.x += widthIncrease;
|
|
|
|
frame.size.width -= widthIncrease;
|
2021-08-07 07:27:56 +00:00
|
|
|
field.frame = frame;
|
2012-10-29 22:44:12 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-03-12 02:56:35 +00:00
|
|
|
//set the click action of the pieces view
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning after 2.8 just hook this up in the xib
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPiecesView.action = @selector(updatePiecesView:);
|
|
|
|
self.fPiecesView.target = self;
|
2010-04-06 01:41:16 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)dealloc
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[NSNotificationCenter.defaultCenter removeObserver:self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-07-17 23:04:32 +00:00
|
|
|
- (CGFloat)currentHeight
|
|
|
|
{
|
|
|
|
return NSHeight(self.view.frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)horizLayoutHeight
|
|
|
|
{
|
|
|
|
return NSHeight(self.fTransferView.frame) + 2 * STACKVIEW_INSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)horizLayoutWidth
|
|
|
|
{
|
|
|
|
return NSWidth(self.fTransferView.frame) + NSWidth(self.fDatesView.frame) + (2 * STACKVIEW_INSET) + STACKVIEW_HORIZONTAL_SPACING;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)vertLayoutHeight
|
|
|
|
{
|
|
|
|
return NSHeight(self.fTransferView.frame) + NSHeight(self.fDatesView.frame) + (2 * STACKVIEW_INSET) + STACKVIEW_VERTICAL_SPACING;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat)changeInWindowHeight
|
|
|
|
{
|
|
|
|
CGFloat difference = 0;
|
|
|
|
|
|
|
|
if (NSWidth(self.view.window.frame) >= self.horizLayoutWidth + 1)
|
|
|
|
{
|
|
|
|
self.fActivityStackView.orientation = NSUserInterfaceLayoutOrientationHorizontal;
|
|
|
|
|
|
|
|
//add some padding between views in horizontal layout
|
|
|
|
self.fActivityStackView.spacing = STACKVIEW_HORIZONTAL_SPACING;
|
|
|
|
|
|
|
|
difference = NSHeight(self.view.frame) - self.horizLayoutHeight;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self.fActivityStackView.orientation = NSUserInterfaceLayoutOrientationVertical;
|
|
|
|
self.fActivityStackView.spacing = STACKVIEW_VERTICAL_SPACING;
|
|
|
|
|
|
|
|
difference = NSHeight(self.view.frame) - self.vertLayoutHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return difference;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSRect)viewRect
|
|
|
|
{
|
|
|
|
CGFloat difference = self.changeInWindowHeight;
|
|
|
|
|
|
|
|
NSRect windowRect = self.view.window.frame, viewRect = self.view.frame;
|
|
|
|
if (difference != 0)
|
|
|
|
{
|
|
|
|
viewRect.size.height -= difference;
|
|
|
|
viewRect.size.width = NSWidth(windowRect);
|
|
|
|
}
|
|
|
|
|
|
|
|
return viewRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateWindowLayout
|
|
|
|
{
|
|
|
|
CGFloat difference = self.changeInWindowHeight;
|
|
|
|
|
|
|
|
if (difference != 0)
|
|
|
|
{
|
|
|
|
NSRect windowRect = self.view.window.frame;
|
|
|
|
windowRect.origin.y += difference;
|
|
|
|
windowRect.size.height -= difference;
|
|
|
|
|
|
|
|
self.view.window.minSize = NSMakeSize(self.view.window.minSize.width, NSHeight(windowRect));
|
|
|
|
self.view.window.maxSize = NSMakeSize(FLT_MAX, NSHeight(windowRect));
|
|
|
|
|
|
|
|
self.view.frame = [self viewRect];
|
|
|
|
[self.view.window setFrame:windowRect display:YES animate:YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 22:51:40 +00:00
|
|
|
- (void)setInfoForTorrents:(NSArray<Torrent*>*)torrents
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2010-04-17 18:44:34 +00:00
|
|
|
//don't check if it's the same in case the metadata changed
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fTorrents = torrents;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSet = NO;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateInfo
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (!self.fSet)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
[self setupInfo];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger const numberSelected = self.fTorrents.count;
|
2010-03-06 23:12:30 +00:00
|
|
|
if (numberSelected == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
uint64_t have = 0, haveVerified = 0, downloadedTotal = 0, uploadedTotal = 0, failedHash = 0;
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDate* lastActivity = nil;
|
2022-02-22 16:04:20 +00:00
|
|
|
for (Torrent* torrent in self.fTorrents)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
have += torrent.haveTotal;
|
|
|
|
haveVerified += torrent.haveVerified;
|
|
|
|
downloadedTotal += torrent.downloadedTotal;
|
|
|
|
uploadedTotal += torrent.uploadedTotal;
|
|
|
|
failedHash += torrent.failedHash;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSDate* nextLastActivity;
|
2021-08-07 07:27:56 +00:00
|
|
|
if ((nextLastActivity = torrent.dateActivity))
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
lastActivity = lastActivity ? [lastActivity laterDate:nextLastActivity] : nextLastActivity;
|
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (have == 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fHaveField.stringValue = [NSString stringForFileSize:0];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* verifiedString = [NSString stringWithFormat:NSLocalizedString(@"%@ verified", "Inspector -> Activity tab -> have"),
|
|
|
|
[NSString stringForFileSize:haveVerified]];
|
2010-03-06 23:12:30 +00:00
|
|
|
if (have == haveVerified)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fHaveField.stringValue = verifiedString;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fHaveField.stringValue = [NSString stringWithFormat:@"%@ (%@)", [NSString stringForFileSize:have], verifiedString];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDownloadedTotalField.stringValue = [NSString stringForFileSize:downloadedTotal];
|
|
|
|
self.fUploadedTotalField.stringValue = [NSString stringForFileSize:uploadedTotal];
|
|
|
|
self.fFailedHashField.stringValue = [NSString stringForFileSize:failedHash];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDateActivityField.objectValue = lastActivity;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (numberSelected == 1)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
Torrent* torrent = self.fTorrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStateField.stringValue = torrent.stateString;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* progressString = [NSString percentString:torrent.progress longDecimals:YES];
|
2021-08-07 07:27:56 +00:00
|
|
|
if (torrent.folder)
|
2010-06-18 03:21:29 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* progressSelectedString = [NSString
|
|
|
|
stringWithFormat:NSLocalizedString(@"%@ selected", "Inspector -> Activity tab -> progress"),
|
|
|
|
[NSString percentString:torrent.progressDone longDecimals:YES]];
|
|
|
|
progressString = [progressString stringByAppendingFormat:@" (%@)", progressSelectedString];
|
2010-06-18 03:21:29 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fProgressField.stringValue = progressString;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioField.stringValue = [NSString stringForRatio:torrent.ratio];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* errorMessage = torrent.errorMessage;
|
2022-02-22 16:04:20 +00:00
|
|
|
if (![errorMessage isEqualToString:self.fErrorMessageView.string])
|
|
|
|
self.fErrorMessageView.string = errorMessage;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDateCompletedField.objectValue = torrent.dateCompleted;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-04-17 10:59:59 +00:00
|
|
|
//uses a relative date, so can't be set once
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDateAddedField.objectValue = torrent.dateAdded;
|
2021-08-15 09:41:48 +00:00
|
|
|
|
|
|
|
static NSDateComponentsFormatter* timeFormatter;
|
2020-12-23 03:00:06 +00:00
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
timeFormatter = [NSDateComponentsFormatter new];
|
|
|
|
timeFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort;
|
|
|
|
timeFormatter.allowedUnits = NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
|
|
|
|
timeFormatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropLeading;
|
|
|
|
});
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDownloadTimeField.stringValue = [timeFormatter stringFromTimeInterval:torrent.secondsDownloading];
|
|
|
|
self.fSeedTimeField.stringValue = [timeFormatter stringFromTimeInterval:torrent.secondsSeeding];
|
2021-08-15 09:41:48 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPiecesView updateView];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else if (numberSelected > 1)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRatioField.stringValue = [NSString stringForRatio:tr_getRatio(uploadedTotal, downloadedTotal)];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setPiecesView:(id)sender
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const availability = [sender selectedSegment] == PIECES_CONTROL_AVAILABLE;
|
|
|
|
[NSUserDefaults.standardUserDefaults setBool:availability forKey:@"PiecesViewShowAvailability"];
|
2013-03-12 03:33:54 +00:00
|
|
|
[self updatePiecesView:nil];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updatePiecesView:(id)sender
|
2013-03-12 03:08:59 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const piecesAvailableSegment = [NSUserDefaults.standardUserDefaults boolForKey:@"PiecesViewShowAvailability"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPiecesControl setSelected:piecesAvailableSegment forSegment:PIECES_CONTROL_AVAILABLE];
|
|
|
|
[self.fPiecesControl setSelected:!piecesAvailableSegment forSegment:PIECES_CONTROL_PROGRESS];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPiecesView updateView];
|
2013-03-12 03:08:59 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)clearView
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPiecesView clearView];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setupInfo
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSUInteger const count = self.fTorrents.count;
|
2010-03-09 02:26:52 +00:00
|
|
|
if (count != 1)
|
|
|
|
{
|
|
|
|
if (count == 0)
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fHaveField.stringValue = @"";
|
|
|
|
self.fDownloadedTotalField.stringValue = @"";
|
|
|
|
self.fUploadedTotalField.stringValue = @"";
|
|
|
|
self.fFailedHashField.stringValue = @"";
|
|
|
|
self.fDateActivityField.objectValue = @""; //using [field setStringValue: @""] causes "December 31, 1969 7:00 PM" to be displayed, at least on 10.7.3
|
|
|
|
self.fRatioField.stringValue = @"";
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fStateField.stringValue = @"";
|
|
|
|
self.fProgressField.stringValue = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fErrorMessageView.string = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-04-17 03:11:34 +00:00
|
|
|
//using [field setStringValue: @""] causes "December 31, 1969 7:00 PM" to be displayed, at least on 10.7.3
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDateAddedField.objectValue = @"";
|
|
|
|
self.fDateCompletedField.objectValue = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDownloadTimeField.stringValue = @"";
|
|
|
|
self.fSeedTimeField.stringValue = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPiecesControl setSelected:NO forSegment:PIECES_CONTROL_AVAILABLE];
|
|
|
|
[self.fPiecesControl setSelected:NO forSegment:PIECES_CONTROL_PROGRESS];
|
|
|
|
self.fPiecesControl.enabled = NO;
|
|
|
|
self.fPiecesView.torrent = nil;
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
Torrent* torrent = self.fTorrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const piecesAvailableSegment = [NSUserDefaults.standardUserDefaults boolForKey:@"PiecesViewShowAvailability"];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fPiecesControl setSelected:piecesAvailableSegment forSegment:PIECES_CONTROL_AVAILABLE];
|
|
|
|
[self.fPiecesControl setSelected:!piecesAvailableSegment forSegment:PIECES_CONTROL_PROGRESS];
|
|
|
|
self.fPiecesControl.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPiecesView.torrent = torrent;
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSet = YES;
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|