source: trunk/macosx/InfoGeneralViewController.m @ 13539

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

uncomment resizing code for localizations post-2.7

  • Property svn:keywords set to Date Rev Author Id
File size: 5.9 KB
Line 
1/******************************************************************************
2 * $Id: InfoGeneralViewController.m 13539 2012-09-26 18:59:34Z 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- (void) awakeFromNib
55{
56    #warning remove when 10.7-only with auto layout
57    [fInfoSectionLabel sizeToFit];
58    [fWhereSectionLabel sizeToFit];
59   
60    NSArray * labels = @[ fPiecesLabel, fHashLabel, fSecureLabel, fCreatorLabel, fDateCreatedLabel, fCommentLabel, fDataLocationLabel ];
61   
62    CGFloat oldMaxWidth = 0.0, newMaxWidth = 0.0;
63    NSTextField * oldLongestLabel = nil;
64    for (NSTextField * label in labels)
65    {
66        const CGFloat oldWidth = [label bounds].size.width;
67        if (oldWidth > oldMaxWidth)
68        {
69            oldMaxWidth = oldWidth;
70            oldLongestLabel = label;
71        }
72       
73        [label sizeToFit];
74        const CGFloat newWidth = [label bounds].size.width;
75        if (newWidth > newMaxWidth)
76            newMaxWidth = newWidth;
77    }
78   
79    for (NSTextField * label in labels)
80    {
81        NSRect frame = [label frame];
82        frame.origin.x = [oldLongestLabel frame].origin.x;
83        frame.origin.x += newMaxWidth - frame.size.width;
84        [label setFrame: frame];
85    }
86   
87    NSArray * fields = @[ fPiecesField, fHashField, fSecureField, fCreatorField, fDateCreatedField, fCommentScrollView, fDataLocationField ];
88   
89    for (NSView * field in fields) {
90        const CGFloat widthIncrease = newMaxWidth - oldMaxWidth;
91        NSRect frame = [field frame];
92        frame.origin.x += widthIncrease;
93        frame.size.width -= widthIncrease;
94        [field setFrame: frame];
95    }
96}
97
98- (void) setInfoForTorrents: (NSArray *) torrents
99{
100    //don't check if it's the same in case the metadata changed
101    [fTorrents release];
102    fTorrents = [torrents retain];
103   
104    fSet = NO;
105}
106
107- (void) updateInfo
108{
109    if (!fSet)
110        [self setupInfo];
111   
112    if ([fTorrents count] != 1)
113        return;
114   
115    Torrent * torrent = [fTorrents objectAtIndex: 0];
116   
117    NSString * location = [torrent dataLocation];
118    [fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""];
119    [fDataLocationField setToolTip: location ? location : @""];
120   
121    [fRevealDataButton setHidden: !location];
122}
123
124- (void) revealDataFile: (id) sender
125{
126    Torrent * torrent = [fTorrents objectAtIndex: 0];
127    NSString * location = [torrent dataLocation];
128    if (!location)
129        return;
130   
131    NSURL * file = [NSURL fileURLWithPath: location];
132    [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]];
133}
134
135@end
136
137@implementation InfoGeneralViewController (Private)
138
139- (void) setupInfo
140{
141    if ([fTorrents count] == 1)
142    {
143        Torrent * torrent = [fTorrents objectAtIndex: 0];
144       
145        NSString * piecesString = ![torrent isMagnet] ? [NSString stringWithFormat: @"%ld, %@", [torrent pieceCount],
146                                        [NSString stringForFileSize: [torrent pieceSize]]] : @"";
147        [fPiecesField setStringValue: piecesString];
148                                       
149        NSString * hashString = [torrent hashString];
150        [fHashField setStringValue: hashString];
151        [fHashField setToolTip: hashString];
152        [fSecureField setStringValue: [torrent privateTorrent]
153                        ? NSLocalizedString(@"Private Torrent, non-tracker peer discovery disabled", "Inspector -> private torrent")
154                        : NSLocalizedString(@"Public Torrent", "Inspector -> private torrent")];
155       
156        NSString * commentString = [torrent comment];
157        [fCommentView setString: commentString];
158       
159        NSString * creatorString = [torrent creator];
160        [fCreatorField setStringValue: creatorString];
161        [fDateCreatedField setObjectValue: [torrent dateCreated]];
162    }
163    else
164    {
165        [fPiecesField setStringValue: @""];
166        [fHashField setStringValue: @""];
167        [fHashField setToolTip: nil];
168        [fSecureField setStringValue: @""];
169        [fCommentView setString: @""];
170       
171        [fCreatorField setStringValue: @""];
172        [fDateCreatedField setStringValue: @""];
173       
174        [fDataLocationField setStringValue: @""];
175        [fDataLocationField setToolTip: nil];
176       
177        [fRevealDataButton setHidden: YES];
178    }
179   
180    fSet = YES;
181}
182
183@end
184
Note: See TracBrowser for help on using the repository browser.