]> git.sesse.net Git - vlc/blob - modules/gui/macosx/about.m
macosx: save 6 l10n strings
[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 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];
142
143         [joinus_readytorender release];
144         [o_credits_textview setString: @""];
145
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.]];
153
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.
158              */
159             NSCalendar *gregorian =
160             [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
161             NSUInteger dayOfYear = [gregorian ordinalityOfUnit:NSDayCalendarUnit inUnit:NSYearCalendarUnit forDate:[NSDate date]];
162             [gregorian release];
163
164             if (dayOfYear >= 354)
165                 [o_icon_view setImage: [NSImage imageNamed:@"vlc-xmas"]];
166         }
167
168         b_isSetUp = YES;
169     }
170
171     /* Show the window */
172     b_restart = YES;
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];
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:[[NSString stringWithUTF8String: psz_thanks] stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:0 range:NSRangeFromString(@"680 2")]];
240     else
241         [o_credits_textview setString:[NSString stringWithUTF8String: 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     [o_credits_scrollview setHidden:NO];
255     [o_credits_textview setHidden:NO];
256     [o_joinus_txt setHidden:YES];
257
258     [o_credits_textview setString:[NSString stringWithUTF8String: psz_license]];
259
260     [o_credits_textview scrollPoint:NSMakePoint(0, 0)];
261     b_restart = YES;
262 }
263
264 /*****************************************************************************
265 * VLC Generic Help Window
266 *****************************************************************************/
267
268 - (void)showHelp
269 {
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")];
274
275     [o_help_window makeKeyAndOrderFront: self];
276
277     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
278                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
279 }
280
281 - (IBAction)helpGoHome:(id)sender
282 {
283     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
284                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
285 }
286
287 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
288 {
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]];
292 }
293
294 @end