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