about.m 8.77 KB
Newer Older
1 2 3
/*****************************************************************************
 * about.m: MacOS X About Panel
 *****************************************************************************
Felix Paul Kühne's avatar
Felix Paul Kühne committed
4
 * Copyright (C) 2001-2011 VLC authors and VideoLAN
5
 * $Id$
6 7
 *
 * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
8
 *          Felix Paul Kühne <fkuehne -at- videolan.org>
9 10 11 12 13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
14
 *
15 16 17 18 19 20 21
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
Antoine Cellerier's avatar
Antoine Cellerier committed
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 24 25 26 27
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
28 29 30 31
#import "intf.h"
#import "about.h"
#import <vlc_intf_strings.h>
#import <vlc_about.h>
32
#import "CompatibilityFixes.h"
33

Felix Paul Kühne's avatar
Felix Paul Kühne committed
34
#ifdef __x86_64__
35
#define PLATFORM "Intel 64bit"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
36
#elif __i386__
37
#define PLATFORM "Intel 32bit"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
38
#else
39
#define PLATFORM "PowerPC 32bit"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
40 41
#endif

42
/*****************************************************************************
43
 * VLAboutBox implementation
44 45 46 47 48 49 50 51 52 53
 *****************************************************************************/
@implementation VLAboutBox

static VLAboutBox *_o_sharedInstance = nil;

+ (VLAboutBox *)sharedInstance
{
    return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
}

54
- (id)init
55 56 57 58 59 60
{
    if (_o_sharedInstance) {
        [self dealloc];
    } else {
        _o_sharedInstance = [super init];
    }
61

62 63 64
    return _o_sharedInstance;
}

65 66 67 68 69 70
- (void) dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver: self];
    [super dealloc];
}

71 72
- (void)awakeFromNib
{
73
    if (OSX_LION)
74 75 76
        [o_about_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
}

77 78 79 80 81
/*****************************************************************************
* VLC About Window
*****************************************************************************/

- (void)showAbout
82
{
83
    if(! b_isSetUp )
84
    {
85
        /* Get the localized info dictionary (InfoPlist.strings) */
86
        NSDictionary *o_local_dict;
87 88
        o_local_dict = [[NSBundle mainBundle] localizedInfoDictionary];

89 90 91 92
        /* Setup the copyright field */
        [o_copyright_field setStringValue: [o_local_dict objectForKey:@"NSHumanReadableCopyright"]];

        /* Set the box title */
Felix Paul Kühne's avatar
Felix Paul Kühne committed
93
        [o_about_window setTitle: _NS("About VLC media player")];
94

95
        /* setup the creator / revision field */
96 97 98 99 100 101 102 103
        NSString *compiler;
#ifdef __clang__
        compiler = [NSString stringWithFormat:@"clang %s", __clang_version__];
#elif __llvm__
        compiler = [NSString stringWithFormat:@"llvm-gcc %s", __VERSION__];
#else
        compiler = [NSString stringWithFormat:@"gcc %s", __VERSION__];
#endif
104
        [o_revision_field setStringValue: [NSString stringWithFormat: _NS("Compiled by %@ with %@"), [NSString stringWithUTF8String:VLC_CompileBy()], compiler]];
105

106
        /* Setup the nameversion field */
107
        [o_name_version_field setStringValue: [NSString stringWithFormat:@"Version %s (%s)", VERSION_MESSAGE, PLATFORM]];
108

109
        NSMutableArray *tmpArray = [NSMutableArray arrayWithArray: [[NSString stringWithUTF8String: psz_authors]componentsSeparatedByString:@"\n\n"]];
110 111
        NSUInteger count = [tmpArray count];
        for( NSUInteger i = 0; i < count; i++ )
112 113 114 115 116 117 118
        {
            [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"\n" withString:@", "]];
            [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@", -" withString:@"\n-" options:0 range:NSRangeFromString(@"0 30")]];
            [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"-, " withString:@"-\n" options:0 range:NSRangeFromString(@"0 30")]];
            [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]];
        }
        NSString *authors = [tmpArray componentsJoinedByString:@"\n\n"];
119

120
        /* setup the authors and thanks field */
121
        [o_credits_textview setString: [NSString stringWithFormat: @"%@\n\n\n\n\n\n%@\n\n%@\n\n",
122 123 124
                                        [_NS(INTF_ABOUT_MSG) stringByReplacingOccurrencesOfString:@"\n" withString:@" "],
                                        authors,
                                        [[NSString stringWithUTF8String: psz_thanks] stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:0 range:NSRangeFromString(@"680 2")]]];
125

126
        /* Setup the window */
127 128 129 130 131
        [o_credits_textview setDrawsBackground: NO];
        [o_credits_scrollview setDrawsBackground: NO];
        [o_about_window setExcludedFromWindowsMenu:YES];
        [o_about_window setMenu:nil];
        [o_about_window center];
132
        [o_gpl_btn setTitle: _NS("License")];
133

134
        b_isSetUp = YES;
135
    }
136

137
    /* Show the window */
138
    b_restart = YES;
139
    [o_credits_textview scrollPoint:NSMakePoint( 0, 0 )];
140
    [o_about_window makeKeyAndOrderFront: nil];
141 142 143 144
}

- (void)windowDidBecomeKey:(NSNotification *)notification
{
145 146 147 148 149
    o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval: 1/6
                                                      target:self
                                                    selector:@selector(scrollCredits:)
                                                    userInfo:nil
                                                     repeats:YES];
150 151 152 153 154 155 156 157 158
}

- (void)windowDidResignKey:(NSNotification *)notification
{
    [o_scroll_timer invalidate];
}

- (void)scrollCredits:(NSTimer *)timer
{
159
    if( b_restart )
160
    {
161
        /* Reset the starttime */
162
        i_start = [NSDate timeIntervalSinceReferenceDate] + 4.0;
163
        f_current = 0;
164
        f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
165 166 167
        b_restart = NO;
    }

168
    if( [NSDate timeIntervalSinceReferenceDate] >= i_start )
169
    {
170
        /* Increment the scroll position */
171
        f_current += 0.005;
172 173 174 175

        /* Scroll to the position */
        [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];

176
        /* If at end, restart at the top */
177
        if( f_current >= f_end )
178
        {
179
            /* f_end may be wrong on first run, so don't trust it too much */
180
            if( f_end == [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height )
181 182 183 184 185 186
            {
                b_restart = YES;
                [o_credits_textview scrollPoint:NSMakePoint( 0, 0 )];
            }
            else
                f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
187
        }
188 189 190
    }
}

191 192 193 194 195 196 197 198
/*****************************************************************************
* VLC GPL Window, action called from the about window and the help menu
*****************************************************************************/

- (IBAction)showGPL:(id)sender
{
    [o_gpl_window setTitle: _NS("License")];
    [o_gpl_field setString: [NSString stringWithUTF8String: psz_license]];
199

200 201 202 203
    [o_gpl_window center];
    [o_gpl_window makeKeyAndOrderFront: sender];
}

204 205 206 207 208 209 210
/*****************************************************************************
* VLC Generic Help Window
*****************************************************************************/

- (void)showHelp
{
    [o_help_window setTitle: _NS("VLC media player Help")];
211 212 213 214
    [o_help_fwd_btn setToolTip: _NS("Next")];
    [o_help_bwd_btn setToolTip: _NS("Previous")];
    [o_help_home_btn setToolTip: _NS("Index")];

215
    [o_help_window makeKeyAndOrderFront: self];
216

217
    [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
218 219
                                        baseURL: [NSURL URLWithString:@"http://videolan.org"]];
}
220

221 222
- (IBAction)helpGoHome:(id)sender
{
223
    [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
224 225 226
                                        baseURL: [NSURL URLWithString:@"http://videolan.org"]];
}

227 228
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
{
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
229
    /* delegate to update button states (we're the frameLoadDelegate for our help's webview)« */
230
    [o_help_fwd_btn setEnabled: [o_help_web_view canGoForward]];
231 232 233
    [o_help_bwd_btn setEnabled: [o_help_web_view canGoBack]];
}

234
@end