source: trunk/macosx/InfoGeneralViewController.m @ 13481

Last change on this file since 13481 was 13481, checked in by livings124, 10 years ago

add in placeholder code so thatInfoGeneralView can be localized with a strings file after 2.7

  • Property svn:keywords set to Date Rev Author Id
File size: 5.9 KB
Line 
1/******************************************************************************
2 * $Id: InfoGeneralViewController.m 13481 2012-09-08 20:22:05Z livings124 $
3 *
4 * Copyright (c) 2010-2012 Transmission authors and contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *****************************************************************************/
24
25#import "InfoGeneralViewController.h"
26#import "NSStringAdditions.h"
27#import "Torrent.h"
28
29@interface InfoGeneralViewController (Private)
30
31- (void) setupInfo;
32
33@end
34
35@implementation InfoGeneralViewController
36
37- (id) init
38{
39    if ((self = [super initWithNibName: @"InfoGeneralView" bundle: nil]))
40    {
41        [self setTitle: NSLocalizedString(@"General Info", "Inspector view -> title")];
42    }
43   
44    return self;
45}
46
47- (void) dealloc
48{
49    [fTorrents release];
50   
51    [super dealloc];
52}
53
54#warning uncomment after 2.7
55/*- (void) awakeFromNib
56{
57    #warning remove when 10.7-only with auto layout
58    [fInfoSectionLabel sizeToFit];
59    [fWhereSectionLabel sizeToFit];
60   
61    NSArray * labels = @[ fPiecesLabel, fHashLabel, fSecureLabel, fCreatorLabel, fDateCreatedLabel, fCommentLabel, fDataLocationLabel ];
62   
63    CGFloat oldMaxWidth = 0.0, newMaxWidth = 0.0;
64    NSTextField * oldLongestLabel = nil;
65    for (NSTextField * label in labels)
66    {
67        const CGFloat oldWidth = [label bounds].size.width;
68        if (oldWidth > oldMaxWidth)
69        {
70            oldMaxWidth = oldWidth;
71            oldLongestLabel = label;
72        }
73       
74        [label sizeToFit];
75        const CGFloat newWidth = [label bounds].size.width;
76        if (newWidth > newMaxWidth)
77            newMaxWidth = newWidth;
78    }
79   
80    for (NSTextField * label in labels)
81    {
82        NSRect frame = [label frame];
83        frame.origin.x = [oldLongestLabel frame].origin.x;
84        frame.origin.x += newMaxWidth - frame.size.width;
85        [label setFrame: frame];
86    }
87   
88    NSArray * fields = @[ fPiecesField, fHashField, fSecureField, fCreatorField, fDateCreatedField, fCommentScrollView, fDataLocationField ];
89   
90    for (NSView * field in fields) {
91        const CGFloat widthIncrease = newMaxWidth - oldMaxWidth;
92        NSRect frame = [field frame];
93        frame.origin.x += widthIncrease;
94        frame.size.width -= widthIncrease;
95        [field setFrame: frame];
96    }
97}*/
98
99- (void) setInfoForTorrents: (NSArray *) torrents
100{
101    //don't check if it's the same in case the metadata changed
102    [fTorrents release];
103    fTorrents = [torrents retain];
104   
105    fSet = NO;
106}
107
108- (void) updateInfo
109{
110    if (!fSet)
111        [self setupInfo];
112   
113    if ([fTorrents count] != 1)
114        return;
115   
116    Torrent * torrent = [fTorrents objectAtIndex: 0];
117   
118    NSString * location = [torrent dataLocation];
119    [fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""];
120    [fDataLocationField setToolTip: location ? location : @""];
121   
122    [fRevealDataButton setHidden: !location];
123}
124
125- (void) revealDataFile: (id) sender
126{
127    Torrent * torrent = [fTorrents objectAtIndex: 0];
128    NSString * location = [torrent dataLocation];
129    if (!location)
130        return;
131   
132    NSURL * file = [NSURL fileURLWithPath: location];
133    [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]];
134}
135
136@end
137
138@implementation InfoGeneralViewController (Private)
139
140- (void) setupInfo
141{
142    if ([fTorrents count] == 1)
143    {
144        Torrent * torrent = [fTorrents objectAtIndex: 0];
145       
146        NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%ld, %@", [torrent pieceCount],
147                                        [NSString stringForFileSize: [torrent pieceSize]]] : @"";
148        [fPiecesField setStringValue: piecesString];
149                                       
150        NSString * hashString = [torrent hashString];
151        [fHashField setStringValue: hashString];
152        [fHashField setToolTip: hashString];
153        [fSecureField setStringValue: [torrent privateTorrent]
154                        ? NSLocalizedString(@"Private Torrent, non-tracker peer discovery disabled", "Inspector -> private torrent")
155                        : NSLocalizedString(@"Public Torrent", "Inspector -> private torrent")];
156       
157        NSString * commentString = [torrent comment];
158        [fCommentView setString: commentString];
159       
160        NSString * creatorString = [torrent creator];
161        [fCreatorField setStringValue: creatorString];
162        [fDateCreatedField setObjectValue: [torrent dateCreated]];
163    }
164    else
165    {
166        [fPiecesField setStringValue: @""];
167        [fHashField setStringValue: @""];
168        [fHashField setToolTip: nil];
169        [fSecureField setStringValue: @""];
170        [fCommentView setString: @""];
171       
172        [fCreatorField setStringValue: @""];
173        [fDateCreatedField setStringValue: @""];
174       
175        [fDataLocationField setStringValue: @""];
176        [fDataLocationField setToolTip: nil];
177       
178        [fRevealDataButton setHidden: YES];
179    }
180   
181    fSet = YES;
182}
183
184@end
185
Note: See TracBrowser for help on using the repository browser.