]> git.sesse.net Git - vlc/blob - modules/gui/macosx/about.m
macosx: re-implement macosx-background
[vlc] / modules / gui / macosx / about.m
1 /*****************************************************************************
2  * about.m: MacOS X About Panel
3  *****************************************************************************
4  * Copyright (C) 2001-2012 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
8  *          Felix Paul Kühne <fkuehne -at- videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Preamble
27  *****************************************************************************/
28 #import "intf.h"
29 #import "about.h"
30 #import <vlc_intf_strings.h>
31 #import <vlc_about.h>
32 #import "CompatibilityFixes.h"
33
34 #ifdef __x86_64__
35 #define PLATFORM "Intel 64bit"
36 #elif __i386__
37 #define PLATFORM "Intel 32bit"
38 #else
39 #define PLATFORM "PowerPC 32bit"
40 #endif
41
42 /*****************************************************************************
43  * VLAboutBox implementation
44  *****************************************************************************/
45 @implementation VLAboutBox
46
47 static VLAboutBox *_o_sharedInstance = nil;
48
49 + (VLAboutBox *)sharedInstance
50 {
51     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
52 }
53
54 - (id)init
55 {
56     if (_o_sharedInstance) {
57         [self dealloc];
58     } else {
59         _o_sharedInstance = [super init];
60     }
61
62     return _o_sharedInstance;
63 }
64
65 - (void) dealloc
66 {
67     [[NSNotificationCenter defaultCenter] removeObserver: self];
68     [o_color_backdrop release];
69     [super dealloc];
70 }
71
72 - (void)awakeFromNib
73 {
74     if (OSX_LION)
75         [o_about_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
76
77     /* add a colored backdrop to get a white window background */
78     o_color_backdrop = [[VLAboutColoredBackdrop alloc] initWithFrame: [[o_about_window contentView] frame]];
79     [[o_about_window contentView] addSubview: o_color_backdrop positioned: NSWindowBelow relativeTo: nil];
80 }
81
82 /*****************************************************************************
83 * VLC About Window
84 *****************************************************************************/
85
86 - (void)showAbout
87 {
88     if(! b_isSetUp )
89     {
90         /* Get the localized info dictionary (InfoPlist.strings) */
91         NSDictionary *o_local_dict;
92         o_local_dict = [[NSBundle mainBundle] localizedInfoDictionary];
93
94         /* Setup the copyright field */
95         [o_copyright_field setStringValue: [o_local_dict objectForKey:@"NSHumanReadableCopyright"]];
96
97         /* Set the box title */
98         [o_about_window setTitle: _NS("About VLC media player")];
99
100         /* setup the creator / revision field */
101         NSString *compiler;
102 #ifdef __clang__
103         compiler = [NSString stringWithFormat:@"clang %s", __clang_version__];
104 #elif __llvm__
105         compiler = [NSString stringWithFormat:@"llvm-gcc %s", __VERSION__];
106 #else
107         compiler = [NSString stringWithFormat:@"gcc %s", __VERSION__];
108 #endif
109         [o_revision_field setStringValue: [NSString stringWithFormat: _NS("Compiled by %@ with %@"), [NSString stringWithUTF8String:VLC_CompileBy()], compiler]];
110
111         /* Setup the nameversion field */
112         [o_name_version_field setStringValue: [NSString stringWithFormat:@"Version %s (%s)", VERSION_MESSAGE, PLATFORM]];
113
114         NSMutableArray *tmpArray = [NSMutableArray arrayWithArray: [[NSString stringWithUTF8String: psz_authors]componentsSeparatedByString:@"\n\n"]];
115         NSUInteger count = [tmpArray count];
116         for( NSUInteger i = 0; i < count; i++ )
117         {
118             [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"\n" withString:@", "]];
119             [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@", -" withString:@"\n-" options:0 range:NSRangeFromString(@"0 30")]];
120             [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"-, " withString:@"-\n" options:0 range:NSRangeFromString(@"0 30")]];
121             [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]];
122         }
123         NSString *authors = [tmpArray componentsJoinedByString:@"\n\n"];
124
125         /* setup the authors and thanks field */
126         [o_credits_textview setString: [NSString stringWithFormat: @"%@\n\n\n\n\n\n%@\n\n%@\n\n",
127                                         [_NS(INTF_ABOUT_MSG) stringByReplacingOccurrencesOfString:@"\n" withString:@" "],
128                                         authors,
129                                         [[NSString stringWithUTF8String: psz_thanks] stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:0 range:NSRangeFromString(@"680 2")]]];
130
131         /* Setup the window */
132         [o_credits_textview setDrawsBackground: NO];
133         [o_credits_scrollview setDrawsBackground: NO];
134         [o_about_window setExcludedFromWindowsMenu:YES];
135         [o_about_window setMenu:nil];
136         [o_about_window center];
137         [o_gpl_btn setTitle: _NS("License")];
138
139         b_isSetUp = YES;
140     }
141
142     /* Show the window */
143     b_restart = YES;
144     [o_credits_textview scrollPoint:NSMakePoint( 0, 0 )];
145     [o_about_window makeKeyAndOrderFront: nil];
146 }
147
148 - (void)windowDidBecomeKey:(NSNotification *)notification
149 {
150     o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval: 1/6
151                                                       target:self
152                                                     selector:@selector(scrollCredits:)
153                                                     userInfo:nil
154                                                      repeats:YES];
155 }
156
157 - (void)windowDidResignKey:(NSNotification *)notification
158 {
159     [o_scroll_timer invalidate];
160 }
161
162 - (void)scrollCredits:(NSTimer *)timer
163 {
164     if( b_restart )
165     {
166         /* Reset the starttime */
167         i_start = [NSDate timeIntervalSinceReferenceDate] + 4.0;
168         f_current = 0;
169         f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
170         b_restart = NO;
171     }
172
173     if( [NSDate timeIntervalSinceReferenceDate] >= i_start )
174     {
175         /* Increment the scroll position */
176         f_current += 0.005;
177
178         /* Scroll to the position */
179         [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
180
181         /* If at end, restart at the top */
182         if( f_current >= f_end )
183         {
184             /* f_end may be wrong on first run, so don't trust it too much */
185             if( f_end == [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height )
186             {
187                 b_restart = YES;
188                 [o_credits_textview scrollPoint:NSMakePoint( 0, 0 )];
189             }
190             else
191                 f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
192         }
193     }
194 }
195
196 /*****************************************************************************
197 * VLC GPL Window, action called from the about window and the help menu
198 *****************************************************************************/
199
200 - (IBAction)showGPL:(id)sender
201 {
202     [o_gpl_window setTitle: _NS("License")];
203     [o_gpl_field setString: [NSString stringWithUTF8String: psz_license]];
204
205     [o_gpl_window center];
206     [o_gpl_window makeKeyAndOrderFront: sender];
207 }
208
209 /*****************************************************************************
210 * VLC Generic Help Window
211 *****************************************************************************/
212
213 - (void)showHelp
214 {
215     [o_help_window setTitle: _NS("VLC media player Help")];
216     [o_help_fwd_btn setToolTip: _NS("Next")];
217     [o_help_bwd_btn setToolTip: _NS("Previous")];
218     [o_help_home_btn setToolTip: _NS("Index")];
219
220     [o_help_window makeKeyAndOrderFront: self];
221
222     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
223                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
224 }
225
226 - (IBAction)helpGoHome:(id)sender
227 {
228     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
229                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
230 }
231
232 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
233 {
234     /* delegate to update button states (we're the frameLoadDelegate for our help's webview)« */
235     [o_help_fwd_btn setEnabled: [o_help_web_view canGoForward]];
236     [o_help_bwd_btn setEnabled: [o_help_web_view canGoBack]];
237 }
238
239 @end
240
241 @implementation VLAboutColoredBackdrop
242
243 - (void)drawRect:(NSRect)rect {
244     [[NSColor whiteColor] setFill];
245     NSRectFill(rect);
246 }
247
248 @end