1 /*****************************************************************************
2 * about.m: MacOS X About Panel
3 *****************************************************************************
4 * Copyright (C) 2001-2013 VLC authors and VideoLAN
7 * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
8 * Felix Paul Kühne <fkuehne -at- videolan.org>
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.
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.
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 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
30 #import <vlc_intf_strings.h>
32 #import "CompatibilityFixes.h"
35 #define PLATFORM "Intel 64bit"
37 #define PLATFORM "Intel 32bit"
39 #define PLATFORM "PowerPC 32bit"
42 /*****************************************************************************
43 * VLAboutBox implementation
44 *****************************************************************************/
45 @implementation VLAboutBox
47 static VLAboutBox *_o_sharedInstance = nil;
49 + (VLAboutBox *)sharedInstance
51 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
56 if (_o_sharedInstance)
59 _o_sharedInstance = [super init];
61 return _o_sharedInstance;
67 [[NSNotificationCenter defaultCenter] removeObserver: self];
73 if (!OSX_SNOW_LEOPARD)
74 [o_about_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
77 /*****************************************************************************
79 *****************************************************************************/
84 /* Get the localized info dictionary (InfoPlist.strings) */
85 NSDictionary *o_local_dict;
86 o_local_dict = [[NSBundle mainBundle] localizedInfoDictionary];
88 /* Setup the copyright field */
89 [o_copyright_field setStringValue: [o_local_dict objectForKey:@"NSHumanReadableCopyright"]];
92 [o_about_window setTitle: _NS("About VLC media player")];
93 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];
94 NSAttributedString *attrStr;
95 attrStr = [[NSAttributedString alloc] initWithString:_NS("Credits") attributes:stringAttributes];
96 [o_credits_btn setAttributedTitle:attrStr];
98 attrStr = [[NSAttributedString alloc] initWithString:_NS("License") attributes:stringAttributes];
99 [o_gpl_btn setAttributedTitle:attrStr];
101 attrStr = [[NSAttributedString alloc] initWithString:_NS("Authors") attributes:stringAttributes];
102 [o_authors_btn setAttributedTitle:attrStr];
104 [o_trademarks_txt setStringValue:_NS("VLC media player and VideoLAN are trademarks of the VideoLAN Association.")];
106 /* setup the creator / revision field */
109 compiler = [NSString stringWithFormat:@"clang %s", __clang_version__];
111 compiler = [NSString stringWithFormat:@"llvm-gcc %s", __VERSION__];
113 compiler = [NSString stringWithFormat:@"gcc %s", __VERSION__];
115 [o_revision_field setStringValue: [NSString stringWithFormat: _NS("Compiled by %s with %@"), VLC_CompileBy(), compiler]];
117 /* Setup the nameversion field */
118 [o_name_version_field setStringValue: [NSString stringWithFormat:@"Version %s (%s)", VERSION_MESSAGE, PLATFORM]];
120 NSMutableArray *tmpArray = [NSMutableArray arrayWithArray: [[NSString stringWithUTF8String: psz_authors]componentsSeparatedByString:@"\n\n"]];
121 NSUInteger count = [tmpArray count];
122 for (NSUInteger i = 0; i < count; i++) {
123 [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"\n" withString:@", "]];
124 [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@", -" withString:@"\n-" options:0 range:NSRangeFromString(@"0 30")]];
125 [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"-, " withString:@"-\n" options:0 range:NSRangeFromString(@"0 30")]];
126 [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]];
128 o_authors = [tmpArray componentsJoinedByString:@"\n\n"];
132 NSString *joinus = [NSString stringWithString:_NS("<p>VLC media player is a free and open source media player, encoder, and streamer made by the volunteers of the "
133 "<a href=\"http://www.videolan.org/\"><span style=\" text-decoration: underline; color:#0057ae;\">VideoLAN</span>"
134 "</a> community.</p><p>VLC uses its internal codecs, works on essentially every popular platform, and can read "
135 "almost all files, CDs, DVDs, network streams, capture cards and other media formats!</p><p>"
136 "<a href=\"http://www.videolan.org/contribute/\"><span style=\" text-decoration: underline; color:#0057ae;\">Help "
137 "and join us!</span></a>")];
138 NSAttributedString *joinus_readytorender = [[NSAttributedString alloc] initWithHTML:[joinus dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES] documentAttributes:NULL];
139 [o_joinus_txt setAllowsEditingTextAttributes: YES];
140 [o_joinus_txt setSelectable: YES];
141 [o_joinus_txt setAttributedStringValue:joinus_readytorender];
143 [joinus_readytorender release];
144 [o_credits_textview setString: @""];
146 /* Setup the window */
147 [o_credits_textview setDrawsBackground: NO];
148 [o_credits_scrollview setDrawsBackground: NO];
149 [o_about_window setExcludedFromWindowsMenu:YES];
150 [o_about_window setMenu:nil];
151 [o_about_window center];
152 [o_about_window setBackgroundColor: [NSColor colorWithCalibratedWhite:.96 alpha:1.]];
154 if (config_GetInt(VLCIntf, "macosx-icon-change")) {
155 /* After day 354 of the year, the usual VLC cone is replaced by another cone
156 * wearing a Father Xmas hat.
157 * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
159 NSCalendar *gregorian =
160 [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
161 NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
164 if (dayOfYear >= 354)
165 [o_icon_view setImage: [NSImage imageNamed:@"vlc-xmas"]];
171 /* Show the window */
173 [o_credits_scrollview setHidden:YES];
174 [o_credits_textview setHidden:YES];
175 [o_joinus_txt setHidden:NO];
176 [o_copyright_field setHidden:NO];
177 [o_revision_field setHidden:NO];
178 [o_name_version_field setHidden:NO];
179 [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
180 [o_about_window makeKeyAndOrderFront: nil];
183 - (void)windowDidBecomeKey:(NSNotification *)notification
185 o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval: 1/6
187 selector:@selector(scrollCredits:)
192 - (void)windowDidResignKey:(NSNotification *)notification
194 [o_scroll_timer invalidate];
197 - (void)scrollCredits:(NSTimer *)timer
200 /* Reset the starttime */
201 i_start = [NSDate timeIntervalSinceReferenceDate] + 4.0;
203 f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
207 if ([NSDate timeIntervalSinceReferenceDate] >= i_start) {
208 /* Increment the scroll position */
211 /* Scroll to the position */
212 [o_credits_textview scrollPoint:NSMakePoint(0, f_current)];
214 /* If at end, restart at the top */
215 if (f_current >= f_end) {
216 /* f_end may be wrong on first run, so don't trust it too much */
217 if (f_end == [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height) {
220 [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
222 f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
227 - (IBAction)buttonAction:(id)sender
229 [o_credits_scrollview setHidden:NO];
230 [o_credits_textview setHidden:NO];
231 [o_joinus_txt setHidden:YES];
232 [o_copyright_field setHidden:YES];
233 [o_revision_field setHidden:YES];
234 [o_name_version_field setHidden:YES];
236 if (sender == o_authors_btn)
237 [o_credits_textview setString:o_authors];
238 else if (sender == o_credits_btn)
239 [o_credits_textview setString:[[NSString stringWithUTF8String: psz_thanks] stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:0 range:NSRangeFromString(@"680 2")]];
241 [o_credits_textview setString:[NSString stringWithUTF8String: psz_license]];
243 [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
247 /*****************************************************************************
248 * VLC GPL Window, action called from the about window and the help menu
249 *****************************************************************************/
254 [o_credits_scrollview setHidden:NO];
255 [o_credits_textview setHidden:NO];
256 [o_joinus_txt setHidden:YES];
258 [o_credits_textview setString:[NSString stringWithUTF8String: psz_license]];
260 [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
264 /*****************************************************************************
265 * VLC Generic Help Window
266 *****************************************************************************/
270 [o_help_window setTitle: _NS("VLC media player Help")];
271 [o_help_fwd_btn setToolTip: _NS("Next")];
272 [o_help_bwd_btn setToolTip: _NS("Previous")];
273 [o_help_home_btn setToolTip: _NS("Index")];
275 [o_help_window makeKeyAndOrderFront: self];
277 [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
278 baseURL: [NSURL URLWithString:@"http://videolan.org"]];
281 - (IBAction)helpGoHome:(id)sender
283 [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
284 baseURL: [NSURL URLWithString:@"http://videolan.org"]];
287 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
289 /* delegate to update button states (we're the frameLoadDelegate for our help's webview)« */
290 [o_help_fwd_btn setEnabled: [o_help_web_view canGoForward]];
291 [o_help_bwd_btn setEnabled: [o_help_web_view canGoBack]];