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
|
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
#warning remove when 10.7-only with auto layout
|
2012-09-08 20:22:05 +00:00
|
|
|
[fInfoSectionLabel sizeToFit];
|
|
|
|
[fWhereSectionLabel sizeToFit];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSArray* labels = @[
|
|
|
|
fPiecesLabel,
|
|
|
|
fHashLabel,
|
|
|
|
fSecureLabel,
|
|
|
|
fCreatorLabel,
|
|
|
|
fDateCreatedLabel,
|
|
|
|
fCommentLabel,
|
|
|
|
fDataLocationLabel,
|
|
|
|
];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-09-27 00:16:21 +00:00
|
|
|
CGFloat oldMaxWidth = 0.0, originX, 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 = @[
|
|
|
|
fPiecesField,
|
|
|
|
fHashField,
|
|
|
|
fSecureField,
|
|
|
|
fCreatorField,
|
|
|
|
fDateCreatedField,
|
|
|
|
fCommentScrollView,
|
|
|
|
fDataLocationField,
|
|
|
|
];
|
|
|
|
|
|
|
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setInfoForTorrents:(NSArray*)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
|
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;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateInfo
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
|
|
|
if (!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
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = fTorrents[0];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* location = torrent.dataLocation;
|
2021-08-07 07:27:56 +00:00
|
|
|
fDataLocationField.stringValue = location ? location.stringByAbbreviatingWithTildeInPath : @"";
|
|
|
|
fDataLocationField.toolTip = location ? location : @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = fTorrents[0];
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)setupInfo
|
2010-03-09 02:26:52 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (fTorrents.count == 1)
|
2010-03-06 23:12:30 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
Torrent* torrent = 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]] :
|
|
|
|
@"";
|
2021-08-07 07:27:56 +00:00
|
|
|
fPiecesField.stringValue = piecesString;
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* hashString = torrent.hashString;
|
2021-08-07 07:27:56 +00:00
|
|
|
fHashField.stringValue = hashString;
|
|
|
|
fHashField.toolTip = hashString;
|
2021-08-15 09:41:48 +00:00
|
|
|
fSecureField.stringValue = torrent.privateTorrent ?
|
|
|
|
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;
|
2021-08-07 07:27:56 +00:00
|
|
|
fCommentView.string = commentString;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* creatorString = torrent.creator;
|
2021-08-07 07:27:56 +00:00
|
|
|
fCreatorField.stringValue = creatorString;
|
|
|
|
fDateCreatedField.objectValue = torrent.dateCreated;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fPiecesField.stringValue = @"";
|
|
|
|
fHashField.stringValue = @"";
|
|
|
|
fHashField.toolTip = nil;
|
|
|
|
fSecureField.stringValue = @"";
|
|
|
|
fCommentView.string = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fCreatorField.stringValue = @"";
|
|
|
|
fDateCreatedField.stringValue = @"";
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fDataLocationField.stringValue = @"";
|
|
|
|
fDataLocationField.toolTip = nil;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fRevealDataButton.hidden = YES;
|
2010-03-06 23:12:30 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = YES;
|
2010-03-07 01:40:32 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@end
|