1 /*****************************************************************************
2 * about.m: MacOS X About Panel
3 *****************************************************************************
4 * Copyright (C) 2001-2014 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"
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"
38 /*****************************************************************************
39 * VLAboutBox implementation
40 *****************************************************************************/
41 @implementation VLAboutBox
43 static VLAboutBox *_o_sharedInstance = nil;
45 + (VLAboutBox *)sharedInstance
47 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
52 if (_o_sharedInstance)
55 _o_sharedInstance = [super init];
57 return _o_sharedInstance;
63 [[NSNotificationCenter defaultCenter] removeObserver: self];
69 if (!OSX_SNOW_LEOPARD)
70 [o_about_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
73 /*****************************************************************************
75 *****************************************************************************/
80 /* Get the localized info dictionary (InfoPlist.strings) */
81 NSDictionary *o_local_dict;
82 o_local_dict = [[NSBundle mainBundle] localizedInfoDictionary];
84 /* Setup the copyright field */
85 [o_copyright_field setStringValue: [o_local_dict objectForKey:@"NSHumanReadableCopyright"]];
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];
94 attrStr = [[NSAttributedString alloc] initWithString:_NS("License") attributes:stringAttributes];
95 [o_gpl_btn setAttributedTitle:attrStr];
97 attrStr = [[NSAttributedString alloc] initWithString:_NS("Authors") attributes:stringAttributes];
98 [o_authors_btn setAttributedTitle:attrStr];
100 [o_trademarks_txt setStringValue:_NS("VLC media player and VideoLAN are trademarks of the VideoLAN Association.")];
102 /* setup the creator / revision field */
105 compiler = [NSString stringWithFormat:@"clang %s", __clang_version__];
107 compiler = [NSString stringWithFormat:@"llvm-gcc %s", __VERSION__];
109 [o_revision_field setStringValue: [NSString stringWithFormat: _NS("Compiled by %s with %@"), VLC_CompileBy(), compiler]];
111 /* Setup the nameversion field */
112 [o_name_version_field setStringValue: [NSString stringWithFormat:@"Version %s (%s)", VERSION_MESSAGE, PLATFORM]];
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:@","]]];
122 o_authors = [tmpArray componentsJoinedByString:@"\n\n"];
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];
140 [joinus_readytorender release];
141 [o_credits_textview setString: @""];
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.]];
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.
156 NSCalendar *gregorian =
157 [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
158 NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
161 if (dayOfYear >= 354)
162 [o_icon_view setImage: [NSImage imageNamed:@"vlc-xmas"]];
168 /* Show the window */
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];
180 - (void)windowDidBecomeKey:(NSNotification *)notification
182 o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval: 1/6
184 selector:@selector(scrollCredits:)
189 - (void)windowDidResignKey:(NSNotification *)notification
191 [o_scroll_timer invalidate];
194 - (void)scrollCredits:(NSTimer *)timer
197 /* Reset the starttime */
198 i_start = [NSDate timeIntervalSinceReferenceDate] + 4.0;
200 f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
204 if ([NSDate timeIntervalSinceReferenceDate] >= i_start) {
205 /* Increment the scroll position */
208 /* Scroll to the position */
209 [o_credits_textview scrollPoint:NSMakePoint(0, f_current)];
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) {
217 [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
219 f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
224 - (IBAction)buttonAction:(id)sender
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];
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")]];
238 [o_credits_textview setString:[NSString stringWithUTF8String:psz_license]];
240 [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
244 /*****************************************************************************
245 * VLC GPL Window, action called from the about window and the help menu
246 *****************************************************************************/
251 [self buttonAction:nil];
254 /*****************************************************************************
255 * VLC Generic Help Window
256 *****************************************************************************/
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")];
265 [o_help_window makeKeyAndOrderFront: self];
267 [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
268 baseURL: [NSURL URLWithString:@"http://videolan.org"]];
271 - (IBAction)helpGoHome:(id)sender
273 [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
274 baseURL: [NSURL URLWithString:@"http://videolan.org"]];
277 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
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]];