]> git.sesse.net Git - vlc/blob - modules/gui/macosx/about.m
macosx: add yosemite guard
[vlc] / modules / gui / macosx / about.m
1 /*****************************************************************************
2  * about.m: MacOS X About Panel
3  *****************************************************************************
4  * Copyright (C) 2001-2014 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 /* this is a bit weird, but we should be confident that there will be more than
35  * one arch to support again one day */
36 #define PLATFORM "Intel 64bit"
37
38 /*****************************************************************************
39  * VLAboutBox implementation
40  *****************************************************************************/
41 @implementation VLAboutBox
42
43 static VLAboutBox *_o_sharedInstance = nil;
44
45 + (VLAboutBox *)sharedInstance
46 {
47     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
48 }
49
50 - (id)init
51 {
52     if (_o_sharedInstance)
53         [self dealloc];
54     else
55         _o_sharedInstance = [super init];
56
57     return _o_sharedInstance;
58 }
59
60 - (void) dealloc
61 {
62     [o_authors release];
63     [[NSNotificationCenter defaultCenter] removeObserver: self];
64     [super dealloc];
65 }
66
67 - (void)awakeFromNib
68 {
69     if (!OSX_SNOW_LEOPARD)
70         [o_about_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
71 }
72
73 /*****************************************************************************
74 * VLC About Window
75 *****************************************************************************/
76
77 - (void)showAbout
78 {
79     if (! b_isSetUp) {
80         /* Get the localized info dictionary (InfoPlist.strings) */
81         NSDictionary *o_local_dict;
82         o_local_dict = [[NSBundle mainBundle] localizedInfoDictionary];
83
84         /* Setup the copyright field */
85         [o_copyright_field setStringValue: [o_local_dict objectForKey:@"NSHumanReadableCopyright"]];
86
87         /* l10n */
88         [o_about_window setTitle: _NS("About VLC media player")];
89         NSDictionary *stringAttributes = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:NSUnderlineStyleSingle], NSUnderlineStyleAttributeName, [NSColor colorWithCalibratedRed:0. green:0.3411 blue:0.6824 alpha:1.], NSForegroundColorAttributeName, [NSFont systemFontOfSize:13], NSFontAttributeName, nil];
90         NSAttributedString *attrStr;
91         attrStr = [[NSAttributedString alloc] initWithString:_NS("Credits") attributes:stringAttributes];
92         [o_credits_btn setAttributedTitle:attrStr];
93         [attrStr release];
94         attrStr = [[NSAttributedString alloc] initWithString:_NS("License") attributes:stringAttributes];
95         [o_gpl_btn setAttributedTitle:attrStr];
96         [attrStr release];
97         attrStr = [[NSAttributedString alloc] initWithString:_NS("Authors") attributes:stringAttributes];
98         [o_authors_btn setAttributedTitle:attrStr];
99         [attrStr release];
100         [o_trademarks_txt setStringValue:_NS("VLC media player and VideoLAN are trademarks of the VideoLAN Association.")];
101
102         /* setup the creator / revision field */
103         NSString *compiler;
104 #ifdef __clang__
105         compiler = [NSString stringWithFormat:@"clang %s", __clang_version__];
106 #else
107         compiler = [NSString stringWithFormat:@"llvm-gcc %s", __VERSION__];
108 #endif
109         [o_revision_field setStringValue: [NSString stringWithFormat: _NS("Compiled by %s with %@"), 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             [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"\n" withString:@", "]];
118             [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@", -" withString:@"\n-" options:0 range:NSRangeFromString(@"0 30")]];
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]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]];
121         }
122         o_authors = [tmpArray componentsJoinedByString:@"\n\n"];
123         [o_authors retain];
124
125         /* setup join us! */
126         NSString *joinus = [NSString stringWithUTF8String:_(""
127                                                             "<p>VLC media player is a free and open source media player, encoder, and "
128                                                             "streamer made by the volunteers of the <a href=\"http://www.videolan.org/"
129                                                             "\"><span style=\" text-decoration: underline; color:#0057ae;\">VideoLAN</"
130                                                             "span></a> community.</p><p>VLC uses its internal codecs, works on "
131                                                             "essentially every popular platform, and can read almost all files, CDs, "
132                                                             "DVDs, network streams, capture cards and other media formats!</p><p><a href="
133                                                             "\"http://www.videolan.org/contribute/\"><span style=\" text-decoration: "
134                                                             "underline; color:#0057ae;\">Help and join us!</span></a>")];
135         NSAttributedString *joinus_readytorender = [[NSAttributedString alloc] initWithHTML:[joinus dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:NSUTF8StringEncoding] forKey:NSCharacterEncodingDocumentOption] documentAttributes:NULL];
136         [o_joinus_txt setAllowsEditingTextAttributes: YES];
137         [o_joinus_txt setSelectable: YES];
138         [o_joinus_txt setAttributedStringValue:joinus_readytorender];
139
140         [joinus_readytorender release];
141         [o_credits_textview setString: @""];
142
143         /* Setup the window */
144         [o_credits_textview setDrawsBackground: NO];
145         [o_credits_scrollview setDrawsBackground: NO];
146         [o_about_window setExcludedFromWindowsMenu:YES];
147         [o_about_window setMenu:nil];
148         [o_about_window center];
149         [o_about_window setBackgroundColor: [NSColor colorWithCalibratedWhite:.96 alpha:1.]];
150
151         if (config_GetInt(VLCIntf, "macosx-icon-change")) {
152             /* After day 354 of the year, the usual VLC cone is replaced by another cone
153              * wearing a Father Xmas hat.
154              * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
155              */
156             NSCalendar *gregorian =
157             [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
158             NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
159             [gregorian release];
160
161             if (dayOfYear >= 354)
162                 [o_icon_view setImage: [NSImage imageNamed:@"vlc-xmas"]];
163         }
164
165         b_isSetUp = YES;
166     }
167
168     /* Show the window */
169     b_restart = YES;
170     [o_credits_scrollview setHidden:YES];
171     [o_credits_textview setHidden:YES];
172     [o_joinus_txt setHidden:NO];
173     [o_copyright_field setHidden:NO];
174     [o_revision_field setHidden:NO];
175     [o_name_version_field setHidden:NO];
176     [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
177     [o_about_window makeKeyAndOrderFront: nil];
178 }
179
180 - (void)windowDidBecomeKey:(NSNotification *)notification
181 {
182     o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval: 1/6
183                                                       target:self
184                                                     selector:@selector(scrollCredits:)
185                                                     userInfo:nil
186                                                      repeats:YES];
187 }
188
189 - (void)windowDidResignKey:(NSNotification *)notification
190 {
191     [o_scroll_timer invalidate];
192 }
193
194 - (void)scrollCredits:(NSTimer *)timer
195 {
196     if (b_restart) {
197         /* Reset the starttime */
198         i_start = [NSDate timeIntervalSinceReferenceDate] + 4.0;
199         f_current = 0;
200         f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
201         b_restart = NO;
202     }
203
204     if ([NSDate timeIntervalSinceReferenceDate] >= i_start) {
205         /* Increment the scroll position */
206         f_current += 0.005;
207
208         /* Scroll to the position */
209         [o_credits_textview scrollPoint:NSMakePoint(0, f_current)];
210
211         /* If at end, restart at the top */
212         if (f_current >= f_end) {
213             /* f_end may be wrong on first run, so don't trust it too much */
214             if (f_end == [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height) {
215                 sleep(2);
216                 b_restart = YES;
217                 [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
218             } else
219                 f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
220         }
221     }
222 }
223
224 - (IBAction)buttonAction:(id)sender
225 {
226     [o_credits_scrollview setHidden:NO];
227     [o_credits_textview setHidden:NO];
228     [o_joinus_txt setHidden:YES];
229     [o_copyright_field setHidden:YES];
230     [o_revision_field setHidden:YES];
231     [o_name_version_field setHidden:YES];
232
233     if (sender == o_authors_btn)
234         [o_credits_textview setString:o_authors];
235     else if (sender == o_credits_btn)
236         [o_credits_textview setString:[[NSString stringWithUTF8String:psz_thanks] stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:0 range:NSRangeFromString(@"680 2")]];
237     else
238         [o_credits_textview setString:[NSString stringWithUTF8String:psz_license]];
239
240     [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
241     b_restart = YES;
242 }
243
244 /*****************************************************************************
245 * VLC GPL Window, action called from the about window and the help menu
246 *****************************************************************************/
247
248 - (void)showGPL
249 {
250     [self showAbout];
251     [self buttonAction:nil];
252 }
253
254 /*****************************************************************************
255 * VLC Generic Help Window
256 *****************************************************************************/
257
258 - (void)showHelp
259 {
260     [o_help_window setTitle: _NS("VLC media player Help")];
261     [o_help_fwd_btn setToolTip: _NS("Next")];
262     [o_help_bwd_btn setToolTip: _NS("Previous")];
263     [o_help_home_btn setToolTip: _NS("Index")];
264
265     [o_help_window makeKeyAndOrderFront: self];
266
267     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
268                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
269 }
270
271 - (IBAction)helpGoHome:(id)sender
272 {
273     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
274                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
275 }
276
277 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
278 {
279     /* delegate to update button states (we're the frameLoadDelegate for our help's webview)« */
280     [o_help_fwd_btn setEnabled: [o_help_web_view canGoForward]];
281     [o_help_bwd_btn setEnabled: [o_help_web_view canGoBack]];
282 }
283
284 @end