]> git.sesse.net Git - vlc/blob - modules/gui/macosx/about.m
* small clean-up, so the about-class is not needed in the main-nib anymore
[vlc] / modules / gui / macosx / about.m
1 /*****************************************************************************
2  * about.m: MacOS X About Panel
3  *****************************************************************************
4  * Copyright (C) 2001-2003 VideoLAN
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                 /* Load the needed nib-file */
62                 [NSBundle loadNibNamed:@"About" owner:self];
63                 
64         /* Get the info dictionary (Info.plist) */
65         o_info_dict = [[NSBundle mainBundle] infoDictionary];
66         
67         /* Get the localized info dictionary (InfoPlist.strings) */
68         localInfoBundle = CFBundleGetMainBundle();
69         o_local_dict = (NSDictionary *)
70                         CFBundleGetLocalInfoDictionary( localInfoBundle );
71         
72         /* Setup the name field */
73         o_name = [o_local_dict objectForKey:@"CFBundleName"];
74         
75         /* Set the about box title */
76         [o_about_window setTitle:_NS("About VLC media player")];
77         
78         /* Setup the version field */
79         o_version = [o_info_dict objectForKey:@"CFBundleVersion"];
80     
81         /* Setup the nameversion field */
82         o_name_version = [NSString stringWithFormat:@"%@ - Version %@", o_name, o_version];
83         [o_name_version_field setStringValue: o_name_version];
84         
85         /* Setup our credits */
86         o_credits_path = [[NSBundle mainBundle] pathForResource:@"AUTHORS" ofType:nil];
87         o_credits = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile: o_credits_path ] encoding:NSWindowsCP1252StringEncoding];
88         
89         /* Parse the authors string */
90         NSMutableString *o_outString = [NSMutableString stringWithFormat: @"%@\n\n", _NS(INTF_ABOUT_MSG)];
91         NSScanner *o_scan_credits = [NSScanner scannerWithString: o_credits];
92         NSCharacterSet *o_stopSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r"];
93         
94         while( ![o_scan_credits isAtEnd] )
95         {
96             NSString *o_person;
97             NSScanner *o_scan_person;
98             
99             [o_scan_credits scanUpToString:@"N:" intoString: nil];
100             [o_scan_credits scanString:@"N:" intoString: nil];
101             [o_scan_credits scanUpToString:@"N:" intoString: &o_person];
102             o_scan_person = [NSScanner scannerWithString: o_person];
103             
104             NSString *o_name;
105             NSString *o_email;
106             NSMutableString *o_jobs = [NSMutableString string];
107             NSString *o_next;
108
109             [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_name];
110             [o_scan_person scanString:@"E:" intoString: nil];
111             [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_email];
112             [o_scan_person scanUpToString:@"D:" intoString: &o_next];
113             [o_scan_person scanUpToString:@":" intoString: &o_next];
114             [o_scan_person scanString:@":" intoString: nil];
115     
116             while ( [o_next characterAtIndex:[o_next length] - 1] == 'D' )
117             {
118                 NSString *o_job;
119                 [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_job ];
120                 [o_jobs appendFormat: @"%@, ", o_job];
121                 [o_scan_person scanUpToString:@":" intoString: &o_next];
122                 [o_scan_person scanString:@":" intoString: nil];
123             }
124             
125             [o_outString appendFormat: @"%@ <%@>\n%@\n\n", o_name, o_email, o_jobs];
126         }
127         
128         /* Parse the thanks string */
129         o_thanks_path = [[NSBundle mainBundle] pathForResource:@"THANKS" ofType:nil];
130         o_thanks = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile: 
131                         o_thanks_path ] encoding:NSWindowsCP1252StringEncoding];
132         
133         NSScanner *o_scan_thanks = [NSScanner scannerWithString: o_thanks];
134         [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: nil];
135         
136         while( ![o_scan_thanks isAtEnd] )
137         {
138             NSString *o_person;
139             NSString *o_job;
140             
141             [o_scan_thanks scanUpToString:@" - " intoString: &o_person];
142             [o_scan_thanks scanString:@" - " intoString: nil];
143             [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: &o_job];
144             [o_outString appendFormat: @"%@\n%@\n\n", o_person, o_job];
145         }
146         [o_credits_textview setString:o_outString];
147         
148         /* Setup the copyright field */
149         o_copyright = [o_local_dict objectForKey:@"NSHumanReadableCopyright"];
150         [o_copyright_field setStringValue:o_copyright];
151
152         /* Setup the window */
153         [o_credits_textview setDrawsBackground: NO];
154         [o_credits_scrollview setDrawsBackground: NO];
155         [o_about_window setExcludedFromWindowsMenu:YES];
156         [o_about_window setMenu:nil];
157         [o_about_window center];
158     }
159     
160     /* Show the window */
161     b_restart = YES;
162     [o_about_window makeKeyAndOrderFront:nil];
163 }
164
165 - (void)windowDidBecomeKey:(NSNotification *)notification
166 {
167     o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval:1/6
168                            target:self 
169                            selector:@selector(scrollCredits:) 
170                            userInfo:nil 
171                            repeats:YES];
172 }
173
174 - (void)windowDidResignKey:(NSNotification *)notification
175 {
176     [o_scroll_timer invalidate];
177 }
178
179 - (void)scrollCredits:(NSTimer *)timer
180 {
181     if (b_restart)
182     {
183         /* Reset the starttime */
184         i_start = [NSDate timeIntervalSinceReferenceDate] + 3.0;
185         f_current = 0;
186         f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
187         b_restart = NO;
188     }
189
190     if ([NSDate timeIntervalSinceReferenceDate] >= i_start)
191     {
192         /* Scroll to the position */
193         [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
194         
195         /* Increment the scroll position */
196         f_current += 0.005;
197         
198         /* If at end, restart at the top */
199         if ( f_current >= f_end )
200         {
201             b_restart = YES;
202         }
203     }
204 }
205
206 @end