2010-03-06 23:12:30 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
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 "InfoGeneralViewController.h"
|
|
|
|
#import "NSStringAdditions.h"
|
|
|
|
#import "Torrent.h"
|
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
@interface InfoGeneralViewController (Private)
|
|
|
|
|
|
|
|
- (void) setupInfo;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
@implementation InfoGeneralViewController
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2010-03-14 03:09:12 +00:00
|
|
|
if ((self = [super initWithNibName: @"InfoGeneralView" bundle: nil]))
|
|
|
|
{
|
|
|
|
[self setTitle: NSLocalizedString(@"General Info", "Inspector view -> title")];
|
|
|
|
}
|
|
|
|
|
2010-03-06 23:12:30 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-03-13 02:52:11 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[fTorrents release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2012-09-26 18:59:34 +00:00
|
|
|
- (void) awakeFromNib
|
2012-09-08 20:22:05 +00:00
|
|
|
{
|
|
|
|
#warning remove when 10.7-only with auto layout
|
|
|
|
[fInfoSectionLabel sizeToFit];
|
|
|
|
[fWhereSectionLabel sizeToFit];
|
|
|
|
|
|
|
|
NSArray * labels = @[ fPiecesLabel, fHashLabel, fSecureLabel, fCreatorLabel, fDateCreatedLabel, fCommentLabel, fDataLocationLabel ];
|
|
|
|
|
2012-09-27 00:16:21 +00:00
|
|
|
CGFloat oldMaxWidth = 0.0, originX, newMaxWidth = 0.0;
|
2012-09-08 20:22:05 +00:00
|
|
|
for (NSTextField * label in labels)
|
|
|
|
{
|
2012-09-27 00:21:10 +00:00
|
|
|
const NSRect 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
|
|
|
}
|
|
|
|
|
|
|
|
[label sizeToFit];
|
|
|
|
const CGFloat newWidth = [label bounds].size.width;
|
|
|
|
if (newWidth > newMaxWidth)
|
|
|
|
newMaxWidth = newWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (NSTextField * label in labels)
|
|
|
|
{
|
|
|
|
NSRect frame = [label frame];
|
2012-09-27 00:16:21 +00:00
|
|
|
frame.origin.x = originX + (newMaxWidth - frame.size.width);
|
2012-09-08 20:22:05 +00:00
|
|
|
[label setFrame: frame];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray * fields = @[ fPiecesField, fHashField, fSecureField, fCreatorField, fDateCreatedField, fCommentScrollView, fDataLocationField ];
|
|
|
|
|
2012-10-14 17:33:23 +00:00
|
|
|
const CGFloat widthIncrease = newMaxWidth - oldMaxWidth;
|
2012-09-08 20:22:05 +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
|
|
|
}
|
2012-09-08 20:22:05 +00:00
|
|
|
|
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
|
2012-03-13 02:52:11 +00:00
|
|
|
[fTorrents release];
|
|
|
|
fTorrents = [torrents retain];
|
2010-03-06 23:12:30 +00:00
|
|
|
|
2010-03-09 02:26:52 +00:00
|
|
|
fSet = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateInfo
|
|
|
|
{
|
|
|
|
if (!fSet)
|
|
|
|
[self setupInfo];
|
|
|
|
|
|
|
|
if ([fTorrents count] != 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
|
|
|
NSString * location = [torrent dataLocation];
|
|
|
|
[fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""];
|
|
|
|
[fDataLocationField setToolTip: location ? location : @""];
|
|
|
|
|
|
|
|
[fRevealDataButton setHidden: !location];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) revealDataFile: (id) sender
|
|
|
|
{
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
NSString * location = [torrent dataLocation];
|
|
|
|
if (!location)
|
|
|
|
return;
|
|
|
|
|
2011-10-06 00:30:40 +00:00
|
|
|
NSURL * file = [NSURL fileURLWithPath: location];
|
|
|
|
[[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]];
|
2010-03-09 02:26:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation InfoGeneralViewController (Private)
|
|
|
|
|
|
|
|
- (void) setupInfo
|
|
|
|
{
|
2010-03-06 23:12:30 +00:00
|
|
|
if ([fTorrents count] == 1)
|
|
|
|
{
|
|
|
|
Torrent * torrent = [fTorrents objectAtIndex: 0];
|
|
|
|
|
2013-02-11 01:39:44 +00:00
|
|
|
#warning candidate for localizedStringWithFormat (although then we'll get two commas)
|
2012-08-13 00:52:04 +00:00
|
|
|
NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%ld, %@", [torrent pieceCount],
|
2010-03-06 23:12:30 +00:00
|
|
|
[NSString stringForFileSize: [torrent pieceSize]]] : @"";
|
|
|
|
[fPiecesField setStringValue: piecesString];
|
|
|
|
|
|
|
|
NSString * hashString = [torrent hashString];
|
|
|
|
[fHashField setStringValue: hashString];
|
|
|
|
[fHashField setToolTip: hashString];
|
|
|
|
[fSecureField setStringValue: [torrent privateTorrent]
|
2010-05-01 16:19:40 +00:00
|
|
|
? NSLocalizedString(@"Private Torrent, non-tracker peer discovery disabled", "Inspector -> private torrent")
|
2010-03-06 23:12:30 +00:00
|
|
|
: NSLocalizedString(@"Public Torrent", "Inspector -> private torrent")];
|
|
|
|
|
|
|
|
NSString * commentString = [torrent comment];
|
|
|
|
[fCommentView setString: commentString];
|
|
|
|
|
|
|
|
NSString * creatorString = [torrent creator];
|
|
|
|
[fCreatorField setStringValue: creatorString];
|
|
|
|
[fDateCreatedField setObjectValue: [torrent dateCreated]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[fPiecesField setStringValue: @""];
|
|
|
|
[fHashField setStringValue: @""];
|
|
|
|
[fHashField setToolTip: nil];
|
|
|
|
[fSecureField setStringValue: @""];
|
|
|
|
[fCommentView setString: @""];
|
|
|
|
|
|
|
|
[fCreatorField setStringValue: @""];
|
|
|
|
[fDateCreatedField setStringValue: @""];
|
|
|
|
|
|
|
|
[fDataLocationField setStringValue: @""];
|
|
|
|
[fDataLocationField setToolTip: nil];
|
|
|
|
|
|
|
|
[fRevealDataButton setHidden: YES];
|
|
|
|
}
|
2010-03-07 01:40:32 +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
|
2010-03-09 02:26:52 +00:00
|
|
|
|