2010-03-06 23:12:30 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2010-2012 Transmission authors and contributors
|
2010-03-06 23:12:30 +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 "InfoActivityViewController.h"
|
2014-10-17 05:12:00 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2010-03-06 23:12:30 +00:00
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
#import "PiecesView.h"
|
|
|
|
#import "Torrent.h"
|
2010-04-23 16:59:14 +00:00
|
|
|
|
|
|
|
#include "transmission.h" // required by utils.h
|
2010-03-06 23:12:30 +00:00
|
|
|
#include "utils.h" //tr_getRatio()
|
|
|
|
|
|
|
|
#define PIECES_CONTROL_PROGRESS 0
|
|
|
|
#define PIECES_CONTROL_AVAILABLE 1
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
@interface InfoActivityViewController (Private)
|
|
|
|
|
|
|
|
- (void) setupInfo;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@implementation InfoActivityViewController
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2010-03-14 03:09:12 +00:00
|
|
|
if ((self = [super initWithNibName: @"InfoActivityView" bundle: nil]))
|
|
|
|
{
|
|
|
|
[self setTitle: NSLocalizedString(@"Activity", "Inspector view -> title")];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2010-04-06 01:41:16 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2012-10-29 22:44:12 +00:00
|
|
|
[fTransferSectionLabel sizeToFit];
|
2012-09-27 00:17:43 +00:00
|
|
|
[fDatesSectionLabel sizeToFit];
|
|
|
|
[fTimeSectionLabel sizeToFit];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-09-27 00:17:43 +00:00
|
|
|
NSArray * labels = @[ fStateLabel, fProgressLabel, fHaveLabel, fDownloadedLabel, fUploadedLabel, fFailedDLLabel, fRatioLabel, fErrorLabel, fDateAddedLabel, fDateCompletedLabel, fDateActivityLabel, fDownloadTimeLabel, fSeedTimeLabel ];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-09-27 00:17:43 +00:00
|
|
|
CGFloat oldMaxWidth = 0.0, originX, newMaxWidth = 0.0;
|
|
|
|
for (NSTextField * label in labels)
|
|
|
|
{
|
2012-09-27 00:21:10 +00:00
|
|
|
const NSRect 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];
|
|
|
|
const CGFloat newWidth = [label bounds].size.width;
|
|
|
|
if (newWidth > newMaxWidth)
|
|
|
|
newMaxWidth = newWidth;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-09-27 00:17:43 +00:00
|
|
|
for (NSTextField * label in labels)
|
|
|
|
{
|
|
|
|
NSRect frame = [label frame];
|
|
|
|
frame.origin.x = originX + (newMaxWidth - frame.size.width);
|
|
|
|
[label setFrame: frame];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-09-27 00:17:43 +00:00
|
|
|
NSArray * fields = @[ fDateAddedField, fDateCompletedField, fDateActivityField, fStateField, fProgressField, fHaveField, fDownloadedTotalField, fUploadedTotalField, fFailedHashField, fRatioField, fDownloadTimeField, fSeedTimeField, fErrorScrollView ];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-10-14 17:33:23 +00:00
|
|
|
const CGFloat widthIncrease = newMaxWidth - oldMaxWidth;
|
2012-09-27 00:17:43 +00:00
|
|
|
for (NSView * field in fields) {
|
|
|
|
NSRect frame = [field frame];
|
|
|
|
frame.origin.x += widthIncrease;
|
|
|
|
frame.size.width -= widthIncrease;
|
|
|
|
[field setFrame: 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
|
2013-03-12 03:08:59 +00:00
|
|
|
#warning after 2.8 just hook this up in the xib
|
|
|
|
[fPiecesView setAction:@selector(updatePiecesView:)];
|
2013-03-12 02:56:35 +00:00
|
|
|
[fPiecesView setTarget:self];
|
2010-04-06 01:41:16 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2010-04-06 01:41:16 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setInfoForTorrents: (NSArray *) torrents
|
|
|
|
{
|
2010-04-17 18:44:34 +00:00
|
|
|
//don't check if it's the same in case the metadata changed
|
2017-07-29 16:14:22 +00:00
|
|
|
fTorrents = torrents;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = NO;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfo
|
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
if (!fSet)
|
|
|
|
[self setupInfo];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
const NSInteger numberSelected = [fTorrents count];
|
|
|
|
if (numberSelected == 0)
|
|
|
|
return;
|
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;
|
|
|
|
NSDate * lastActivity = nil;
|
|
|
|
for (Torrent * torrent in fTorrents)
|
|
|
|
{
|
|
|
|
have += [torrent haveTotal];
|
|
|
|
haveVerified += [torrent haveVerified];
|
|
|
|
downloadedTotal += [torrent downloadedTotal];
|
|
|
|
uploadedTotal += [torrent uploadedTotal];
|
|
|
|
failedHash += [torrent failedHash];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
NSDate * nextLastActivity;
|
|
|
|
if ((nextLastActivity = [torrent dateActivity]))
|
|
|
|
lastActivity = lastActivity ? [lastActivity laterDate: nextLastActivity] : nextLastActivity;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (have == 0)
|
|
|
|
[fHaveField setStringValue: [NSString stringForFileSize: 0]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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]];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fDownloadedTotalField setStringValue: [NSString stringForFileSize: downloadedTotal]];
|
|
|
|
[fUploadedTotalField setStringValue: [NSString stringForFileSize: uploadedTotal]];
|
|
|
|
[fFailedHashField setStringValue: [NSString stringForFileSize: failedHash]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fDateActivityField setObjectValue: lastActivity];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
if (numberSelected == 1)
|
|
|
|
{
|
2017-07-08 09:16:01 +00:00
|
|
|
Torrent * torrent = fTorrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fStateField setStringValue: [torrent stateString]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-06-24 00:00:43 +00:00
|
|
|
NSString * progressString = [NSString percentString: [torrent progress] longDecimals: YES];
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([torrent isFolder])
|
2010-06-18 03:21:29 +00:00
|
|
|
{
|
2010-06-24 00:00:43 +00:00
|
|
|
NSString * progressSelectedString = [NSString stringWithFormat:
|
|
|
|
NSLocalizedString(@"%@ selected", "Inspector -> Activity tab -> progress"),
|
|
|
|
[NSString percentString: [torrent progressDone] longDecimals: YES]];
|
2010-06-18 03:21:29 +00:00
|
|
|
progressString = [progressString stringByAppendingFormat: @" (%@)", progressSelectedString];
|
|
|
|
}
|
|
|
|
[fProgressField setStringValue: progressString];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fRatioField setStringValue: [NSString stringForRatio: [torrent ratio]]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
NSString * errorMessage = [torrent errorMessage];
|
|
|
|
if (![errorMessage isEqualToString: [fErrorMessageView string]])
|
|
|
|
[fErrorMessageView setString: errorMessage];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fDateCompletedField setObjectValue: [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
|
|
|
|
[fDateAddedField setObjectValue: [torrent dateAdded]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2014-10-17 05:12:00 +00:00
|
|
|
if ([NSApp isOnYosemiteOrBetter]) {
|
|
|
|
static NSDateComponentsFormatter *timeFormatter;
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
timeFormatter = [NSDateComponentsFormatter new];
|
|
|
|
timeFormatter.unitsStyle = NSDateComponentsFormatterUnitsStyleShort;
|
|
|
|
timeFormatter.allowedUnits = NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
|
|
|
|
timeFormatter.zeroFormattingBehavior = NSDateComponentsFormatterZeroFormattingBehaviorDropLeading;
|
|
|
|
});
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2014-10-17 05:12:00 +00:00
|
|
|
[fDownloadTimeField setStringValue: [timeFormatter stringFromTimeInterval:[torrent secondsDownloading]]];
|
|
|
|
[fSeedTimeField setStringValue: [timeFormatter stringFromTimeInterval:[torrent secondsSeeding]]];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
[fDownloadTimeField setStringValue: [NSString timeString: [torrent secondsDownloading] includesTimeRemainingPhrase:NO showSeconds: YES]];
|
|
|
|
[fSeedTimeField setStringValue: [NSString timeString: [torrent secondsSeeding] includesTimeRemainingPhrase:NO showSeconds: YES]];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
[fPiecesView updateView];
|
|
|
|
}
|
|
|
|
else if (numberSelected > 1)
|
|
|
|
{
|
|
|
|
[fRatioField setStringValue: [NSString stringForRatio: tr_getRatio(uploadedTotal, downloadedTotal)]];
|
|
|
|
}
|
|
|
|
else;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setPiecesView: (id) sender
|
|
|
|
{
|
2010-04-06 01:41:16 +00:00
|
|
|
const BOOL 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
|
|
|
}
|
|
|
|
|
2013-03-12 03:08:59 +00:00
|
|
|
|
|
|
|
- (void) updatePiecesView: (id) sender
|
|
|
|
{
|
|
|
|
const BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-03-12 03:08:59 +00:00
|
|
|
[fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE];
|
|
|
|
[fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2013-03-12 03:08:59 +00:00
|
|
|
[fPiecesView updateView];
|
|
|
|
}
|
|
|
|
|
2010-03-14 01:52:45 +00:00
|
|
|
- (void) clearView
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
|
|
|
[fPiecesView clearView];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2010-03-09 02:26:52 +00:00
|
|
|
|
|
|
|
@implementation InfoActivityViewController (Private)
|
|
|
|
|
|
|
|
- (void) setupInfo
|
|
|
|
{
|
|
|
|
const NSUInteger count = [fTorrents count];
|
|
|
|
if (count != 1)
|
|
|
|
{
|
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
[fHaveField setStringValue: @""];
|
|
|
|
[fDownloadedTotalField setStringValue: @""];
|
|
|
|
[fUploadedTotalField setStringValue: @""];
|
|
|
|
[fFailedHashField setStringValue: @""];
|
2012-04-17 03:11:34 +00:00
|
|
|
[fDateActivityField setObjectValue: @""]; //using [field setStringValue: @""] causes "December 31, 1969 7:00 PM" to be displayed, at least on 10.7.3
|
2010-03-09 02:26:52 +00:00
|
|
|
[fRatioField setStringValue: @""];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
[fStateField setStringValue: @""];
|
|
|
|
[fProgressField setStringValue: @""];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
[fErrorMessageView setString: @""];
|
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
|
|
|
|
[fDateAddedField setObjectValue: @""];
|
|
|
|
[fDateCompletedField setObjectValue: @""];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-12-23 20:07:41 +00:00
|
|
|
[fDownloadTimeField setStringValue: @""];
|
|
|
|
[fSeedTimeField setStringValue: @""];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
[fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_AVAILABLE];
|
|
|
|
[fPiecesControl setSelected: NO forSegment: PIECES_CONTROL_PROGRESS];
|
|
|
|
[fPiecesControl setEnabled: NO];
|
|
|
|
[fPiecesView setTorrent: nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-08 09:16:01 +00:00
|
|
|
Torrent * torrent = fTorrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-04-06 01:41:16 +00:00
|
|
|
const BOOL piecesAvailableSegment = [[NSUserDefaults standardUserDefaults] boolForKey: @"PiecesViewShowAvailability"];
|
2010-03-09 02:26:52 +00:00
|
|
|
[fPiecesControl setSelected: piecesAvailableSegment forSegment: PIECES_CONTROL_AVAILABLE];
|
|
|
|
[fPiecesControl setSelected: !piecesAvailableSegment forSegment: PIECES_CONTROL_PROGRESS];
|
|
|
|
[fPiecesControl setEnabled: YES];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
[fPiecesView setTorrent: torrent];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|