]> git.sesse.net Git - vlc/blob - modules/gui/macosx/about.m
* All : added an about VLC panel. It scrolls the names and the work of the
[vlc] / modules / gui / macosx / about.m
1 /*****************************************************************************
2  * about.m: MacOS X About Panel
3  *****************************************************************************
4  * Copyright (C) 2001-2003 VideoLAN
5  * $Id: about.m,v 1.1 2003/04/09 20:53:28 hartman Exp $
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 - (IBAction)showPanel:(id)sender
54 {    
55     if (!o_credits_path)
56     {
57         NSString *o_name;
58         NSString *o_version;
59     
60         // Get the info dictionary (Info.plist)
61         o_info_dict = [[NSBundle mainBundle] infoDictionary];
62         
63         // Get the localized info dictionary (InfoPlist.strings)
64         localInfoBundle = CFBundleGetMainBundle();
65         o_local_dict = (NSDictionary *)
66                         CFBundleGetLocalInfoDictionary( localInfoBundle );
67         
68         // Setup the app name field
69         o_name = [o_local_dict objectForKey:@"CFBundleName"];
70         
71         // Set the about box window title
72         [o_about_window setTitle:_NS("About VLC media player")];
73         
74         // Setup the version field
75         o_version = [o_info_dict objectForKey:@"CFBundleVersion"];
76     
77         // Setup the appnameversion field
78         o_name_version = [NSString stringWithFormat:@"%@ - Version %@", o_name, o_version];
79         [o_name_version_field setStringValue: o_name_version];
80         
81         // Setup our credits
82         o_credits_path = [[NSBundle mainBundle] pathForResource:@"AUTHORS" ofType:nil];
83         o_credits = [NSString stringWithContentsOfFile: o_credits_path ];
84         
85         // Parse the string
86         NSMutableString *o_outString = [NSMutableString string];
87         NSScanner *o_scan_credits = [NSScanner scannerWithString: o_credits];
88         NSCharacterSet *o_stopSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r"];
89         
90         while( ![o_scan_credits isAtEnd] )
91         {
92             NSString *o_person;
93             NSScanner *o_scan_person;
94             
95             [o_scan_credits scanUpToString:@"N:" intoString: nil];
96             [o_scan_credits scanString:@"N:" intoString: nil];
97             [o_scan_credits scanUpToString:@"N:" intoString: &o_person];
98             o_scan_person = [NSScanner scannerWithString: o_person];
99             
100             NSString *o_name;
101             NSString *o_email;
102             NSMutableString *o_jobs = [NSMutableString string];
103             NSString *o_next;
104
105             [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_name];
106             [o_scan_person scanString:@"E:" intoString: nil];
107             [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_email];
108             [o_scan_person scanUpToString:@"D:" intoString: &o_next];
109             [o_scan_person scanUpToString:@":" intoString: &o_next];
110             [o_scan_person scanString:@":" intoString: nil];
111     
112             while ( [o_next characterAtIndex:[o_next length] - 1] == 'D' )
113             {
114                 NSString *o_job;
115                 [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_job ];
116                 [o_jobs appendFormat: @"%@, ", o_job];
117                 [o_scan_person scanUpToString:@":" intoString: &o_next];
118                 [o_scan_person scanString:@":" intoString: nil];
119             }
120             
121             [o_outString appendFormat: @"%@ <%@>\n%@\n\n", o_name, o_email, o_jobs];
122             [o_credits_textview setString:o_outString];
123         }
124         
125         // Setup the copyright field
126         o_copyright = [o_local_dict objectForKey:@"NSHumanReadableCopyright"];
127         [o_copyright_field setStringValue:o_copyright];
128
129         // Setup the window
130         [o_credits_textview setDrawsBackground: NO];
131         [o_credits_scrollview setDrawsBackground: NO];
132         [o_about_window setExcludedFromWindowsMenu:YES];
133         [o_about_window setMenu:nil];
134         [o_about_window center];
135     }
136     
137     // Show the window
138     b_restart = YES;
139     [o_about_window makeKeyAndOrderFront:nil];
140 }
141
142 - (void)windowDidBecomeKey:(NSNotification *)notification
143 {
144     o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval:1/6
145                            target:self 
146                            selector:@selector(scrollCredits:) 
147                            userInfo:nil 
148                            repeats:YES];
149 }
150
151 - (void)windowDidResignKey:(NSNotification *)notification
152 {
153     [o_scroll_timer invalidate];
154 }
155
156 - (void)scrollCredits:(NSTimer *)timer
157 {
158     if (b_restart)
159     {
160         // Reset the startTime
161         i_start = [NSDate timeIntervalSinceReferenceDate] + 3.0;
162         f_current = 0;
163         b_restart = NO;
164     }
165
166     if ([NSDate timeIntervalSinceReferenceDate] >= i_start)
167     {
168         // Scroll to the position
169         [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
170         
171         // Increment the scroll position
172         f_current += 0.005;
173     }
174 }
175
176 @end