2023-02-11 20:49:42 +00:00
|
|
|
// This file Copyright © 2010-2023 Transmission authors and contributors.
|
2022-01-20 18:27:56 +00:00
|
|
|
// 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;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2022-11-14 18:30:03 +00:00
|
|
|
// Associated Press Style: "Use a semicolon to clarify a series that includes a number of commas."
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* piecesString = !torrent.magnet ?
|
2022-11-14 18:30:03 +00:00
|
|
|
[NSString localizedStringWithFormat:@"%ld; %@", torrent.pieceCount, [NSString stringForFileSize:torrent.pieceSize]] :
|
2021-08-15 09:41:48 +00:00
|
|
|
@"";
|
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
|