]> git.sesse.net Git - vlc/blob - modules/gui/macosx/about.m
Merge branch 'master' into lpcm_encoder
[vlc] / modules / gui / macosx / about.m
1 /*****************************************************************************
2  * about.m: MacOS X About Panel
3  *****************************************************************************
4  * Copyright (C) 2001-2009 the VideoLAN team
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
33 #ifdef __x86_64__
34 #define PLATFORM "Intel 64bit"
35 #elif __i386__
36 #define PLATFORM "Intel 32bit"
37 #else
38 #define PLATFORM "PowerPC 32bit"
39 #endif
40
41 /*****************************************************************************
42  * VLAboutBox implementation
43  *****************************************************************************/
44 @implementation VLAboutBox
45
46 static VLAboutBox *_o_sharedInstance = nil;
47
48 + (VLAboutBox *)sharedInstance
49 {
50     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
51 }
52
53 - (id)init
54 {
55     if (_o_sharedInstance) {
56         [self dealloc];
57     } else {
58         _o_sharedInstance = [super init];
59     }
60  
61     return _o_sharedInstance;
62 }
63
64 - (void) dealloc
65 {
66     [[NSNotificationCenter defaultCenter] removeObserver: self];
67     [super dealloc];
68 }
69
70 /*****************************************************************************
71 * VLC About Window
72 *****************************************************************************/
73
74 - (void)showAbout
75 {
76     if(! b_isSetUp )
77     {
78         /* we want to know when VLC wants to quit to prevent a crash while scrolling our credits */
79         [[NSNotificationCenter defaultCenter] addObserver: self
80                                                  selector: @selector(VLCWillTerminate)
81                                                      name: NSApplicationWillTerminateNotification
82                                                    object: nil];
83         
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         /* Set the box title */
92         [o_about_window setTitle: _NS("About VLC media player")];
93
94         /* setup the creator / revision field */
95         [o_revision_field setStringValue: 
96             [NSString stringWithFormat: _NS("Compiled by %s"), VLC_CompileBy()]];
97  
98         /* Setup the nameversion field */
99         [o_name_version_field setStringValue: [NSString stringWithFormat:@"Version %s (%s)", VLC_Version(), PLATFORM]];
100
101         /* setup the authors and thanks field */
102         [o_credits_textview setString: [NSString stringWithFormat: @"%@\n\n\n\n%@\n%@\n\n%@", 
103                                             _NS(INTF_ABOUT_MSG), 
104                                             _NS("VLC was brought to you by:"),
105                                             [NSString stringWithUTF8String: psz_authors], 
106                                             [NSString stringWithUTF8String: psz_thanks]]];
107
108         /* Setup the window */
109         [o_credits_textview setDrawsBackground: NO];
110         [o_credits_scrollview setDrawsBackground: NO];
111         [o_about_window setExcludedFromWindowsMenu:YES];
112         [o_about_window setMenu:nil];
113         [o_about_window center];
114         [o_gpl_btn setTitle: _NS("License")];
115         
116         b_isSetUp = YES;
117     }
118  
119     /* Show the window */
120     b_restart = YES;
121     [o_credits_textview scrollPoint:NSMakePoint( 0, 0 )];
122     [o_about_window makeKeyAndOrderFront: nil];
123 }
124
125 - (void)windowDidBecomeKey:(NSNotification *)notification
126 {
127     o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval: 1/6
128                                                       target:self
129                                                     selector:@selector(scrollCredits:)
130                                                     userInfo:nil
131                                                      repeats:YES];
132 }
133
134 - (void)windowDidResignKey:(NSNotification *)notification
135 {
136     [o_scroll_timer invalidate];
137 }
138
139 - (void)scrollCredits:(NSTimer *)timer
140 {
141     if( b_restart )
142     {
143         /* Reset the starttime */
144         i_start = [NSDate timeIntervalSinceReferenceDate] + 5.0;
145         f_current = 0;
146         f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
147         b_restart = NO;
148     }
149
150     if( [NSDate timeIntervalSinceReferenceDate] >= i_start )
151     {
152         /* Scroll to the position */
153         [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
154  
155         /* Increment the scroll position */
156         f_current += 0.005;
157  
158         /* If at end, restart at the top */
159         if( f_current >= f_end )
160         {
161             [o_credits_textview scrollPoint:NSMakePoint( 0, 0 )];
162             b_restart = YES;
163         }
164     }
165 }
166
167 - (void)VLCWillTerminate
168 {
169     [o_scroll_timer invalidate];
170     [[NSNotificationCenter defaultCenter] removeObserver: self];
171 }
172
173 /*****************************************************************************
174 * VLC GPL Window, action called from the about window and the help menu
175 *****************************************************************************/
176
177 - (IBAction)showGPL:(id)sender
178 {
179     [o_gpl_window setTitle: _NS("License")];
180     [o_gpl_field setString: [NSString stringWithUTF8String: psz_license]];
181     
182     [o_gpl_window center];
183     [o_gpl_window makeKeyAndOrderFront: sender];
184 }
185
186 /*****************************************************************************
187 * VLC Generic Help Window
188 *****************************************************************************/
189
190 - (void)showHelp
191 {
192     [o_help_window setTitle: _NS("VLC media player Help")];
193     [o_help_fwd_btn setToolTip: _NS("Next")];
194     [o_help_bwd_btn setToolTip: _NS("Previous")];
195     [o_help_home_btn setToolTip: _NS("Index")];
196
197     [o_help_window makeKeyAndOrderFront: self];
198     
199     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
200                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
201 }
202
203 - (IBAction)helpGoHome:(id)sender
204 {
205     [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
206                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
207 }
208
209 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
210 {
211     /* delegate to update button states (we're the frameLoadDelegate for our help's webview)« */
212     [o_help_fwd_btn setEnabled: [o_help_web_view canGoForward]]; 
213     [o_help_bwd_btn setEnabled: [o_help_web_view canGoBack]];
214 }
215
216 @end