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
|
|
|
|
|
|
|
#import "InfoGeneralViewController.h"
|
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
|
2022-01-24 01:32:45 +00:00
|
|
|
@interface InfoGeneralViewController ()
|
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* fPiecesField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fHashField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fSecureField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDataLocationField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fCreatorField;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDateCreatedField;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSTextView* fCommentView;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fRevealDataButton;
|
|
|
|
|
|
|
|
//remove when we switch to auto layout
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fPiecesLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fHashLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fSecureLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fCreatorLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDateCreatedLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fCommentLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fDataLocationLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fInfoSectionLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fWhereSectionLabel;
|
|
|
|
@property(nonatomic) IBOutlet NSScrollView* fCommentScrollView;
|
|
|
|
|
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 InfoGeneralViewController
|
|
|
|
|
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:@"InfoGeneralView" bundle:nil]))
|
2010-03-14 03:09:12 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
self.title = NSLocalizedString(@"General Info", "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
|
2012-09-08 20:22:05 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
#warning remove when switching to auto layout
|
|
|
|
[self.fInfoSectionLabel sizeToFit];
|
|
|
|
[self.fWhereSectionLabel 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.fPiecesLabel,
|
|
|
|
self.fHashLabel,
|
|
|
|
self.fSecureLabel,
|
|
|
|
self.fCreatorLabel,
|
|
|
|
self.fDateCreatedLabel,
|
|
|
|
self.fCommentLabel,
|
|
|
|
self.fDataLocationLabel,
|
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-08 20:22:05 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSRect const oldFrame = label.frame;
|
2012-09-27 00:16:21 +00:00
|
|
|
if (oldFrame.size.width > oldMaxWidth)
|
2012-09-08 20:22:05 +00:00
|
|
|
{
|
2012-09-27 00:16:21 +00:00
|
|
|
oldMaxWidth = oldFrame.size.width;
|
|
|
|
originX = oldFrame.origin.x;
|
2012-09-08 20:22:05 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-09-08 20:22:05 +00:00
|
|
|
[label sizeToFit];
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const newWidth = label.bounds.size.width;
|
2012-09-08 20:22:05 +00:00
|
|
|
if (newWidth > newMaxWidth)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-09-08 20:22:05 +00:00
|
|
|
newMaxWidth = newWidth;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2012-09-08 20:22:05 +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-08 20:22:05 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSRect frame = label.frame;
|
2012-09-27 00:16:21 +00:00
|
|
|
frame.origin.x = originX + (newMaxWidth - frame.size.width);
|
2021-08-07 07:27:56 +00:00
|
|
|
label.frame = frame;
|
2012-09-08 20:22:05 +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.fPiecesField,
|
|
|
|
self.fHashField,
|
|
|
|
self.fSecureField,
|
|
|
|
self.fCreatorField,
|
|
|
|
self.fDateCreatedField,
|
|
|
|
self.fCommentScrollView,
|
|
|
|
self.fDataLocationField,
|
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-08 20:22:05 +00:00
|
|
|
frame.origin.x += widthIncrease;
|
|
|
|
frame.size.width -= widthIncrease;
|
2021-08-07 07:27:56 +00:00
|
|
|
field.frame = frame;
|
2012-09-08 20:22:05 +00:00
|
|
|
}
|
2012-10-29 22:44:12 +00:00
|
|
|
}
|
2012-09-08 20:22:05 +00:00
|
|
|
|
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-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateInfo
|
2010-03-09 02:26:52 +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
|
|
|
if (self.fTorrents.count != 1)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
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
|
|
|
NSString* location = torrent.dataLocation;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDataLocationField.stringValue = location ? location.stringByAbbreviatingWithTildeInPath : @"";
|
|
|
|
self.fDataLocationField.toolTip = location ? location : @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRevealDataButton.hidden = !location;
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)revealDataFile:(id)sender
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
Torrent* torrent = self.fTorrents[0];
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = torrent.dataLocation;
|
2010-03-09 02:26:52 +00:00
|
|
|
if (!location)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2010-03-09 02:26:52 +00:00
|
|
|
return;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSURL* file = [NSURL fileURLWithPath:location];
|
|
|
|
[NSWorkspace.sharedWorkspace activateFileViewerSelectingURLs:@[ file ]];
|
2010-03-09 02:26:52 +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
|
|
|
if (self.fTorrents.count == 1)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
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
|
|
|
#warning candidate for localizedStringWithFormat (although then we'll get two commas)
|
|
|
|
NSString* piecesString = !torrent.magnet ?
|
|
|
|
[NSString stringWithFormat:@"%ld, %@", torrent.pieceCount, [NSString stringForFileSize:torrent.pieceSize]] :
|
|
|
|
@"";
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPiecesField.stringValue = piecesString;
|
2021-08-07 07:27:56 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* hashString = torrent.hashString;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fHashField.stringValue = hashString;
|
|
|
|
self.fHashField.toolTip = hashString;
|
|
|
|
self.fSecureField.stringValue = torrent.privateTorrent ?
|
2021-08-15 09:41:48 +00:00
|
|
|
NSLocalizedString(@"Private Torrent, non-tracker peer discovery disabled", "Inspector -> private torrent") :
|
|
|
|
NSLocalizedString(@"Public Torrent", "Inspector -> private torrent");
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* commentString = torrent.comment;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fCommentView.string = commentString;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* creatorString = torrent.creator;
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fCreatorField.stringValue = creatorString;
|
|
|
|
self.fDateCreatedField.objectValue = torrent.dateCreated;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fPiecesField.stringValue = @"";
|
|
|
|
self.fHashField.stringValue = @"";
|
|
|
|
self.fHashField.toolTip = nil;
|
|
|
|
self.fSecureField.stringValue = @"";
|
|
|
|
self.fCommentView.string = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fCreatorField.stringValue = @"";
|
|
|
|
self.fDateCreatedField.stringValue = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fDataLocationField.stringValue = @"";
|
|
|
|
self.fDataLocationField.toolTip = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fRevealDataButton.hidden = YES;
|
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.fSet = YES;
|
2010-03-07 01:40:32 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@end
|