* implemented the generic VLC media player Help window on OSX to match the QT4 interf...
[vlc.git] / modules / gui / macosx / about.m
1 /*****************************************************************************
2  * about.m: MacOS X About Panel
3  *****************************************************************************
4  * Copyright (C) 2001-2007 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "intf.h"
28 #include "about.h"
29 #include <vlc_intf_strings.h>
30 #import <WebKit/WebKit.h>
31
32 /*****************************************************************************
33  * VLAboutBox implementation
34  *****************************************************************************/
35 @implementation VLAboutBox
36
37 static VLAboutBox *_o_sharedInstance = nil;
38
39 + (VLAboutBox *)sharedInstance
40 {
41     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
42 }
43
44 - (id)init
45 {
46     if (_o_sharedInstance) {
47         [self dealloc];
48     } else {
49         _o_sharedInstance = [super init];
50     }
51  
52     return _o_sharedInstance;
53 }
54
55 /*****************************************************************************
56 * VLC About Window
57 *****************************************************************************/
58
59 - (void)showAbout
60 {
61     if (!o_credits_path)
62     {
63         NSString *o_name;
64         NSString *o_version;
65         NSString *o_thanks_path;
66         
67         /* Get the info dictionary (Info.plist) */
68         o_info_dict = [[NSBundle mainBundle] infoDictionary];
69  
70         /* Get the localized info dictionary (InfoPlist.strings) */
71         localInfoBundle = CFBundleGetMainBundle();
72         o_local_dict = (NSDictionary *)
73                         CFBundleGetLocalInfoDictionary( localInfoBundle );
74  
75         /* Setup the name field */
76         o_name = [o_local_dict objectForKey:@"CFBundleName"];
77  
78         /* Set the about box title */
79         [o_about_window setTitle:_NS("About VLC media player")];
80  
81         /* Setup the version field */
82         o_version = [o_info_dict objectForKey:@"CFBundleVersion"];
83  
84         /* setup the creator / revision field */
85         if( VLC_Changeset() != "exported" )
86         [o_revision_field setStringValue: [NSString stringWithFormat: \
87             _NS("Compiled by %s, based on SVN revision %s"), VLC_CompileBy(), \
88             VLC_Changeset()]];
89         else
90         [o_revision_field setStringValue: [NSString stringWithFormat: \
91             _NS("Compiled by %s"), VLC_CompileBy()]];
92  
93         /* Setup the nameversion field */
94         o_name_version = [NSString stringWithFormat:@"Version %@", o_version];
95         [o_name_version_field setStringValue: o_name_version];
96  
97         /* Setup our credits */
98         o_credits_path = [[NSBundle mainBundle] pathForResource:@"AUTHORS" ofType:nil];
99         o_credits = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile: o_credits_path ] encoding:NSUTF8StringEncoding];
100  
101         /* Parse the authors string */
102         NSMutableString *o_outString = [NSMutableString stringWithFormat: @"%@\n\n", _NS(INTF_ABOUT_MSG)];
103         NSScanner *o_scan_credits = [NSScanner scannerWithString: o_credits];
104         NSCharacterSet *o_stopSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r"];
105  
106         while( ![o_scan_credits isAtEnd] )
107         {
108             NSString *o_person;
109             NSScanner *o_scan_person;
110  
111             [o_scan_credits scanUpToString:@"N:" intoString: nil];
112             [o_scan_credits scanString:@"N:" intoString: nil];
113             [o_scan_credits scanUpToString:@"N:" intoString: &o_person];
114             o_scan_person = [NSScanner scannerWithString: o_person];
115  
116             NSString *o_name;
117             NSString *o_email;
118             NSMutableString *o_jobs = [NSMutableString string];
119             NSString *o_next;
120
121             [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_name];
122             [o_scan_person scanString:@"E:" intoString: nil];
123             [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_email];
124             [o_scan_person scanUpToString:@"D:" intoString: &o_next];
125             [o_scan_person scanUpToString:@":" intoString: &o_next];
126             [o_scan_person scanString:@":" intoString: nil];
127  
128             while ( [o_next characterAtIndex:[o_next length] - 1] == 'D' )
129             {
130                 NSString *o_job;
131                 [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_job ];
132                 [o_jobs appendFormat: @"%@, ", o_job];
133                 [o_scan_person scanUpToString:@":" intoString: &o_next];
134                 [o_scan_person scanString:@":" intoString: nil];
135             }
136  
137             [o_outString appendFormat: @"%@ <%@>\n%@\n\n", o_name, o_email, o_jobs];
138         }
139  
140         /* Parse the thanks string */
141         o_thanks_path = [[NSBundle mainBundle] pathForResource:@"THANKS" ofType:nil];
142         o_thanks = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile:
143                         o_thanks_path ] encoding:NSUTF8StringEncoding];
144  
145         NSScanner *o_scan_thanks = [NSScanner scannerWithString: o_thanks];
146         [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: nil];
147  
148         while( ![o_scan_thanks isAtEnd] )
149         {
150             NSString *o_person;
151             NSString *o_job;
152  
153             [o_scan_thanks scanUpToString:@" - " intoString: &o_person];
154             [o_scan_thanks scanString:@" - " intoString: nil];
155             [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: &o_job];
156             [o_outString appendFormat: @"%@\n%@\n\n", o_person, o_job];
157         }
158         [o_credits_textview setString:o_outString];
159  
160         /* Setup the copyright field */
161         o_copyright = [o_local_dict objectForKey:@"NSHumanReadableCopyright"];
162         [o_copyright_field setStringValue:o_copyright];
163
164         /* Setup the window */
165         [o_credits_textview setDrawsBackground: NO];
166         [o_credits_scrollview setDrawsBackground: NO];
167         [o_about_window setExcludedFromWindowsMenu:YES];
168         [o_about_window setMenu:nil];
169         [o_about_window center];
170     }
171  
172     /* Show the window */
173     b_restart = YES;
174     [o_about_window makeKeyAndOrderFront:nil];
175 }
176
177 - (void)windowDidBecomeKey:(NSNotification *)notification
178 {
179     o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval:1/6
180                            target:self
181                            selector:@selector(scrollCredits:)
182                            userInfo:nil
183                            repeats:YES];
184 }
185
186 - (void)windowDidResignKey:(NSNotification *)notification
187 {
188     [o_scroll_timer invalidate];
189 }
190
191 - (void)scrollCredits:(NSTimer *)timer
192 {
193     if (b_restart)
194     {
195         /* Reset the starttime */
196         i_start = [NSDate timeIntervalSinceReferenceDate] + 3.0;
197         f_current = 0;
198         f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
199         b_restart = NO;
200     }
201
202     if ([NSDate timeIntervalSinceReferenceDate] >= i_start)
203     {
204         /* Scroll to the position */
205         [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
206  
207         /* Increment the scroll position */
208         f_current += 0.005;
209  
210         /* If at end, restart at the top */
211         if ( f_current >= f_end )
212         {
213             b_restart = YES;
214         }
215     }
216 }
217
218 /*****************************************************************************
219 * VLC Generic Help Window
220 *****************************************************************************/
221
222 - (void)showHelp
223 {
224     [o_help_window setTitle: _NS("VLC media player Help")];
225     [o_help_window makeKeyAndOrderFront: self];
226
227     [[o_help_web_view mainFrame] loadHTMLString: [NSString stringWithString: _NS(I_LONGHELP)]
228                                         baseURL: [NSURL URLWithString:@"http://videolan.org"]];
229 }
230
231 @end