]> git.sesse.net Git - vlc/blob - modules/gui/macosx/about.m
* use the current copyright scheme in the about-box; removed a useless colon introduc...
[vlc] / modules / gui / macosx / about.m
1 /*****************************************************************************
2  * about.m: MacOS X About Panel
3  *****************************************************************************
4  * Copyright (C) 2001-2005 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include "intf.h"
28 #include "about.h"
29
30 /*****************************************************************************
31  * VLAboutBox implementation 
32  *****************************************************************************/
33 @implementation VLAboutBox
34
35 static VLAboutBox *_o_sharedInstance = nil;
36
37 + (VLAboutBox *)sharedInstance
38 {
39     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
40 }
41
42 - (id)init 
43 {
44     if (_o_sharedInstance) {
45         [self dealloc];
46     } else {
47         _o_sharedInstance = [super init];
48     }
49     
50     return _o_sharedInstance;
51 }
52
53 - (void)showPanel
54 {    
55     if (!o_credits_path)
56     {
57         NSString *o_name;
58         NSString *o_version;
59         NSString *o_thanks_path;
60                 
61         /* Get the info dictionary (Info.plist) */
62         o_info_dict = [[NSBundle mainBundle] infoDictionary];
63         
64         /* Get the localized info dictionary (InfoPlist.strings) */
65         localInfoBundle = CFBundleGetMainBundle();
66         o_local_dict = (NSDictionary *)
67                         CFBundleGetLocalInfoDictionary( localInfoBundle );
68         
69         /* Setup the name field */
70         o_name = [o_local_dict objectForKey:@"CFBundleName"];
71         
72         /* Set the about box title */
73         [o_about_window setTitle:_NS("About VLC media player")];
74         
75         /* Setup the version field */
76         o_version = [o_info_dict objectForKey:@"CFBundleVersion"];
77         
78         /* setup the creator / revision field */
79         [o_revision_field setStringValue: [NSString stringWithFormat: \
80             _NS("Compiled by %s, based on SVN revision %s"), VLC_CompileBy(), \
81             VLC_Changeset()]];
82     
83         /* Setup the nameversion field */
84         o_name_version = [NSString stringWithFormat:@"%@ - Version %@", o_name, o_version];
85         [o_name_version_field setStringValue: o_name_version];
86         
87         /* Setup our credits */
88         o_credits_path = [[NSBundle mainBundle] pathForResource:@"AUTHORS" ofType:nil];
89         o_credits = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile: o_credits_path ] encoding:NSWindowsCP1252StringEncoding];
90         
91         /* Parse the authors string */
92         NSMutableString *o_outString = [NSMutableString stringWithFormat: @"%@\n\n", _NS(INTF_ABOUT_MSG)];
93         NSScanner *o_scan_credits = [NSScanner scannerWithString: o_credits];
94         NSCharacterSet *o_stopSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r"];
95         
96         while( ![o_scan_credits isAtEnd] )
97         {
98             NSString *o_person;
99             NSScanner *o_scan_person;
100             
101             [o_scan_credits scanUpToString:@"N:" intoString: nil];
102             [o_scan_credits scanString:@"N:" intoString: nil];
103             [o_scan_credits scanUpToString:@"N:" intoString: &o_person];
104             o_scan_person = [NSScanner scannerWithString: o_person];
105             
106             NSString *o_name;
107             NSString *o_email;
108             NSMutableString *o_jobs = [NSMutableString string];
109             NSString *o_next;
110
111             [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_name];
112             [o_scan_person scanString:@"E:" intoString: nil];
113             [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_email];
114             [o_scan_person scanUpToString:@"D:" intoString: &o_next];
115             [o_scan_person scanUpToString:@":" intoString: &o_next];
116             [o_scan_person scanString:@":" intoString: nil];
117     
118             while ( [o_next characterAtIndex:[o_next length] - 1] == 'D' )
119             {
120                 NSString *o_job;
121                 [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_job ];
122                 [o_jobs appendFormat: @"%@, ", o_job];
123                 [o_scan_person scanUpToString:@":" intoString: &o_next];
124                 [o_scan_person scanString:@":" intoString: nil];
125             }
126             
127             [o_outString appendFormat: @"%@ <%@>\n%@\n\n", o_name, o_email, o_jobs];
128         }
129         
130         /* Parse the thanks string */
131         o_thanks_path = [[NSBundle mainBundle] pathForResource:@"THANKS" ofType:nil];
132         o_thanks = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile: 
133                         o_thanks_path ] encoding:NSWindowsCP1252StringEncoding];
134         
135         NSScanner *o_scan_thanks = [NSScanner scannerWithString: o_thanks];
136         [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: nil];
137         
138         while( ![o_scan_thanks isAtEnd] )
139         {
140             NSString *o_person;
141             NSString *o_job;
142             
143             [o_scan_thanks scanUpToString:@" - " intoString: &o_person];
144             [o_scan_thanks scanString:@" - " intoString: nil];
145             [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: &o_job];
146             [o_outString appendFormat: @"%@\n%@\n\n", o_person, o_job];
147         }
148         [o_credits_textview setString:o_outString];
149         
150         /* Setup the copyright field */
151         o_copyright = [o_local_dict objectForKey:@"NSHumanReadableCopyright"];
152         [o_copyright_field setStringValue:o_copyright];
153
154         /* Setup the window */
155         [o_credits_textview setDrawsBackground: NO];
156         [o_credits_scrollview setDrawsBackground: NO];
157         [o_about_window setExcludedFromWindowsMenu:YES];
158         [o_about_window setMenu:nil];
159         [o_about_window center];
160     }
161     
162     /* Show the window */
163     b_restart = YES;
164     [o_about_window makeKeyAndOrderFront:nil];
165 }
166
167 - (void)windowDidBecomeKey:(NSNotification *)notification
168 {
169     o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval:1/6
170                            target:self 
171                            selector:@selector(scrollCredits:) 
172                            userInfo:nil 
173                            repeats:YES];
174 }
175
176 - (void)windowDidResignKey:(NSNotification *)notification
177 {
178     [o_scroll_timer invalidate];
179 }
180
181 - (void)scrollCredits:(NSTimer *)timer
182 {
183     if (b_restart)
184     {
185         /* Reset the starttime */
186         i_start = [NSDate timeIntervalSinceReferenceDate] + 3.0;
187         f_current = 0;
188         f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
189         b_restart = NO;
190     }
191
192     if ([NSDate timeIntervalSinceReferenceDate] >= i_start)
193     {
194         /* Scroll to the position */
195         [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
196         
197         /* Increment the scroll position */
198         f_current += 0.005;
199         
200         /* If at end, restart at the top */
201         if ( f_current >= f_end )
202         {
203             b_restart = YES;
204         }
205     }
206 }
207
208 @end