bc224a34a7090af90ec871fe7d4126f0487ccb35
[vlc.git] / 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  * AboutWindowController implementation
40  *****************************************************************************/
41 @interface AboutWindowController ()
42 {
43     NSTimer *o_scroll_timer;
44     float f_current;
45     CGFloat f_end;
46     NSTimeInterval i_start;
47     BOOL b_restart;
48
49     NSString *o_authors;
50 }
51 @end
52
53 @implementation AboutWindowController
54
55 - (id)init
56 {
57     self = [super initWithWindowNibName:@"About"];
58     if (self) {
59
60         [self setWindowFrameAutosaveName:@"about"];
61     }
62
63     return self;
64 }
65
66 - (void) dealloc
67 {
68     [[NSNotificationCenter defaultCenter] removeObserver: self];
69 }
70
71 /*****************************************************************************
72 * VLC About Window
73 *****************************************************************************/
74
75 - (void)showAbout
76 {
77     [self window];
78
79     /* Show the window */
80     b_restart = YES;
81     [o_credits_scrollview setHidden:YES];
82     [o_credits_textview setHidden:YES];
83     [o_joinus_txt setHidden:NO];
84     [o_copyright_field setHidden:NO];
85     [o_revision_field setHidden:NO];
86     [o_name_version_field setHidden:NO];
87     [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
88
89     [self showWindow:nil];
90 }
91
92 - (void)windowDidLoad
93 {
94     [[self window] setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
95
96     /* Get the localized info dictionary (InfoPlist.strings) */
97     NSDictionary *o_local_dict;
98     o_local_dict = [[NSBundle mainBundle] localizedInfoDictionary];
99
100     /* Setup the copyright field */
101     [o_copyright_field setStringValue: [o_local_dict objectForKey:@"NSHumanReadableCopyright"]];
102
103     /* l10n */
104     [[self window] setTitle: _NS("About VLC media player")];
105     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];
106     NSAttributedString *attrStr;
107     attrStr = [[NSAttributedString alloc] initWithString:_NS("Credits") attributes:stringAttributes];
108     [o_credits_btn setAttributedTitle:attrStr];
109     attrStr = [[NSAttributedString alloc] initWithString:_NS("License") attributes:stringAttributes];
110     [o_gpl_btn setAttributedTitle:attrStr];
111     attrStr = [[NSAttributedString alloc] initWithString:_NS("Authors") attributes:stringAttributes];
112     [o_authors_btn setAttributedTitle:attrStr];
113     attrStr = nil;
114     [o_trademarks_txt setStringValue:_NS("VLC media player and VideoLAN are trademarks of the VideoLAN Association.")];
115
116     /* setup the creator / revision field */
117     NSString *compiler;
118 #ifdef __clang__
119     compiler = [NSString stringWithFormat:@"clang %s", __clang_version__];
120 #else
121     compiler = [NSString stringWithFormat:@"llvm-gcc %s", __VERSION__];
122 #endif
123     [o_revision_field setStringValue: [NSString stringWithFormat: _NS("Compiled by %s with %@"), VLC_CompileBy(), compiler]];
124
125     /* Setup the nameversion field */
126     [o_name_version_field setStringValue: [NSString stringWithFormat:@"Version %s (%s)", VERSION_MESSAGE, PLATFORM]];
127
128     NSMutableArray *tmpArray = [NSMutableArray arrayWithArray: [toNSStr(psz_authors) componentsSeparatedByString:@"\n\n"]];
129     NSUInteger count = [tmpArray count];
130     for (NSUInteger i = 0; i < count; i++) {
131         [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"\n" withString:@", "]];
132         [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@", -" withString:@"\n-" options:0 range:NSRangeFromString(@"0 30")]];
133         [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"-, " withString:@"-\n" options:0 range:NSRangeFromString(@"0 30")]];
134         [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]];
135     }
136     o_authors = [tmpArray componentsJoinedByString:@"\n\n"];
137
138     /* setup join us! */
139     NSString *joinus = toNSStr(_(""
140                                  "<p>VLC media player is a free and open source media player, encoder, and "
141                                  "streamer made by the volunteers of the <a href=\"http://www.videolan.org/"
142                                  "\"><span style=\" text-decoration: underline; color:#0057ae;\">VideoLAN</"
143                                  "span></a> community.</p><p>VLC uses its internal codecs, works on "
144                                  "essentially every popular platform, and can read almost all files, CDs, "
145                                  "DVDs, network streams, capture cards and other media formats!</p><p><a href="
146                                  "\"http://www.videolan.org/contribute/\"><span style=\" text-decoration: "
147                                  "underline; color:#0057ae;\">Help and join us!</span></a>"));
148     NSString *fontfamily;
149     if (OSX_YOSEMITE)
150         fontfamily = @"Helvetica Neue";
151     else
152         fontfamily = @"Lucida Grande";
153     NSString *joinUsWithStyle = [NSString stringWithFormat:@"<div style=\"text-align:left;font-family:%@;\">%@</div>",
154                                  fontfamily, joinus];
155     NSAttributedString *joinus_readytorender = [[NSAttributedString alloc] initWithHTML:[joinUsWithStyle dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:NSUTF8StringEncoding] forKey:NSCharacterEncodingDocumentOption] documentAttributes:NULL];
156     [o_joinus_txt setAllowsEditingTextAttributes: YES];
157     [o_joinus_txt setSelectable: YES];
158     [o_joinus_txt setAttributedStringValue:joinus_readytorender];
159
160     [o_credits_textview setString: @""];
161
162     /* Setup the window */
163     [o_credits_textview setDrawsBackground: NO];
164     [o_credits_scrollview setDrawsBackground: NO];
165     [[self window] setExcludedFromWindowsMenu:YES];
166     [[self window] setMenu:nil];
167     [[self window] setBackgroundColor: [NSColor colorWithCalibratedWhite:.96 alpha:1.]];
168
169     if (config_GetInt(VLCIntf, "macosx-icon-change")) {
170         /* After day 354 of the year, the usual VLC cone is replaced by another cone
171          * wearing a Father Xmas hat.
172          * Note: this icon doesn't represent an endorsement of The Coca-Cola Company.
173          */
174         NSCalendar *gregorian =
175         [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
176         NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
177
178         if (dayOfYear >= 354)
179             [o_icon_view setImage: [NSImage imageNamed:@"vlc-xmas"]];
180     }
181 }
182
183 - (void)windowDidBecomeKey:(NSNotification *)notification
184 {
185     o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval: 1/6
186                                                       target:self
187                                                     selector:@selector(scrollCredits:)
188                                                     userInfo:nil
189                                                      repeats:YES];
190 }
191
192 - (void)windowDidResignKey:(NSNotification *)notification
193 {
194     [o_scroll_timer invalidate];
195 }
196
197 - (void)scrollCredits:(NSTimer *)timer
198 {
199     if (b_restart) {
200         /* Reset the starttime */
201         i_start = [NSDate timeIntervalSinceReferenceDate] + 4.0;
202         f_current = 0;
203         f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
204         b_restart = NO;
205     }
206
207     if ([NSDate timeIntervalSinceReferenceDate] >= i_start) {
208         /* Increment the scroll position */
209         f_current += 0.005;
210
211         /* Scroll to the position */
212         [o_credits_textview scrollPoint:NSMakePoint(0, f_current)];
213
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) {
218                 sleep(2);
219                 b_restart = YES;
220                 [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
221             } else
222                 f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
223         }
224     }
225 }
226
227 - (IBAction)buttonAction:(id)sender
228 {
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];
235
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:[toNSStr(psz_thanks) stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:0 range:NSRangeFromString(@"680 2")]];
240     else
241         [o_credits_textview setString:toNSStr(psz_license)];
242
243     [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
244     b_restart = YES;
245 }
246
247 /*****************************************************************************
248 * VLC GPL Window, action called from the about window and the help menu
249 *****************************************************************************/
250
251 - (void)showGPL
252 {
253     [self showAbout];
254     [self buttonAction:nil];
255 }
256
257 @end
258
259 /*****************************************************************************
260  * VLC Help Window Controller
261  *****************************************************************************/
262
263 @implementation HelpWindowController
264
265 - (id)init
266 {
267     self = [super initWithWindowNibName:@"Help"];
268     if (self) {
269
270         [self setWindowFrameAutosaveName:@"help"];
271     }
272
273     return self;
274 }
275
276 - (void)windowDidLoad
277 {
278     [[self window] setTitle: _NS("VLC media player Help")];
279     [o_help_fwd_btn setToolTip: _NS("Next")];
280     [o_help_bwd_btn setToolTip: _NS("Previous")];
281     [o_help_home_btn setToolTip: _NS("Index")];
282 }
283
284 - (void)showHelp
285 {
286     [self showWindow:nil];
287     [self helpGoHome:nil];
288 }
289
290 - (IBAction)helpGoHome:(id)sender
291 {
292     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
293                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
294 }
295
296 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
297 {
298     /* delegate to update button states (we're the frameLoadDelegate for our help's webview)« */
299     [o_help_fwd_btn setEnabled: [o_help_web_view canGoForward]];
300     [o_help_bwd_btn setEnabled: [o_help_web_view canGoBack]];
301 }
302
303 @end