1/******************************************************************************
2 * Copyright (c) 2007-2012 Transmission authors and contributors
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *****************************************************************************/
22
23#include <libtransmission/version.h>
24
25#import "AboutWindowController.h"
26
27@implementation AboutWindowController
28
29AboutWindowController * fAboutBoxInstance = nil;
30+ (AboutWindowController *) aboutController
31{
32    if (!fAboutBoxInstance)
33        fAboutBoxInstance = [[self alloc] initWithWindowNibName: @"AboutWindow"];
34    return fAboutBoxInstance;
35}
36
37- (void) awakeFromNib
38{
39    [fVersionField setStringValue: @(LONG_VERSION_STRING)];
40
41    [fCopyrightField setStringValue: [[NSBundle mainBundle] localizedStringForKey: @"NSHumanReadableCopyright"
42                                        value: nil table: @"InfoPlist"]];
43
44    [[fTextView textStorage] setAttributedString: [[NSAttributedString alloc] initWithPath:
45            [[NSBundle mainBundle] pathForResource: @"Credits" ofType: @"rtf"] documentAttributes: nil]];
46
47    //size license button
48    const CGFloat oldButtonWidth = NSWidth([fLicenseButton frame]);
49
50    [fLicenseButton setTitle: NSLocalizedString(@"License", "About window -> license button")];
51    [fLicenseButton sizeToFit];
52
53    NSRect buttonFrame = [fLicenseButton frame];
54    buttonFrame.size.width += 10.0;
55    buttonFrame.origin.x -= NSWidth(buttonFrame) - oldButtonWidth;
56    [fLicenseButton setFrame: buttonFrame];
57}
58
59- (void) windowDidLoad
60{
61    [[self window] center];
62}
63
64- (void) windowWillClose: (id) sender
65{
66    fAboutBoxInstance = nil;
67}
68
69- (IBAction) showLicense: (id) sender
70{
71    NSString * licenseText = [NSString stringWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"COPYING" ofType: nil]
72                                usedEncoding: nil error: NULL];
73    [fLicenseView setString: licenseText];
74    [fLicenseCloseButton setTitle: NSLocalizedString(@"OK", "About window -> license close button")];
75
76    [NSApp beginSheet: fLicenseSheet modalForWindow: [self window] modalDelegate: nil didEndSelector: nil contextInfo: nil];
77}
78
79- (IBAction) hideLicense: (id) sender
80{
81    [fLicenseSheet orderOut: nil];
82    [NSApp endSheet: fLicenseSheet];
83}
84
85@end
86