about.m 7.5 KB
Newer Older
1
2
3
/*****************************************************************************
 * about.m: MacOS X About Panel
 *****************************************************************************
4
 * Copyright (C) 2001-2005 the VideoLAN team
5
 * $Id$
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 *
 * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include "intf.h"
#include "about.h"

/*****************************************************************************
 * VLAboutBox implementation 
 *****************************************************************************/
@implementation VLAboutBox

static VLAboutBox *_o_sharedInstance = nil;

+ (VLAboutBox *)sharedInstance
{
    return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
}

- (id)init 
{
    if (_o_sharedInstance) {
        [self dealloc];
    } else {
        _o_sharedInstance = [super init];
    }
    
    return _o_sharedInstance;
}

53
- (void)showPanel
54
55
56
57
58
{    
    if (!o_credits_path)
    {
        NSString *o_name;
        NSString *o_version;
59
        NSString *o_thanks_path;
60
		
61
        /* Get the info dictionary (Info.plist) */
62
63
        o_info_dict = [[NSBundle mainBundle] infoDictionary];
        
64
        /* Get the localized info dictionary (InfoPlist.strings) */
65
66
67
68
        localInfoBundle = CFBundleGetMainBundle();
        o_local_dict = (NSDictionary *)
                        CFBundleGetLocalInfoDictionary( localInfoBundle );
        
69
        /* Setup the name field */
70
71
        o_name = [o_local_dict objectForKey:@"CFBundleName"];
        
72
        /* Set the about box title */
73
74
        [o_about_window setTitle:_NS("About VLC media player")];
        
75
        /* Setup the version field */
76
77
        o_version = [o_info_dict objectForKey:@"CFBundleVersion"];
    
78
        /* Setup the nameversion field */
79
80
81
        o_name_version = [NSString stringWithFormat:@"%@ - Version %@", o_name, o_version];
        [o_name_version_field setStringValue: o_name_version];
        
82
        /* Setup our credits */
83
        o_credits_path = [[NSBundle mainBundle] pathForResource:@"AUTHORS" ofType:nil];
84
        o_credits = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile: o_credits_path ] encoding:NSWindowsCP1252StringEncoding];
85
        
86
        /* Parse the authors string */
hartman's avatar
hartman committed
87
        NSMutableString *o_outString = [NSMutableString stringWithFormat: @"%@\n\n", _NS(INTF_ABOUT_MSG)];
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
        NSScanner *o_scan_credits = [NSScanner scannerWithString: o_credits];
        NSCharacterSet *o_stopSet = [NSCharacterSet characterSetWithCharactersInString:@"\n\r"];
        
        while( ![o_scan_credits isAtEnd] )
        {
            NSString *o_person;
            NSScanner *o_scan_person;
            
            [o_scan_credits scanUpToString:@"N:" intoString: nil];
            [o_scan_credits scanString:@"N:" intoString: nil];
            [o_scan_credits scanUpToString:@"N:" intoString: &o_person];
            o_scan_person = [NSScanner scannerWithString: o_person];
            
            NSString *o_name;
            NSString *o_email;
            NSMutableString *o_jobs = [NSMutableString string];
            NSString *o_next;

            [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_name];
            [o_scan_person scanString:@"E:" intoString: nil];
            [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_email];
            [o_scan_person scanUpToString:@"D:" intoString: &o_next];
            [o_scan_person scanUpToString:@":" intoString: &o_next];
            [o_scan_person scanString:@":" intoString: nil];
    
            while ( [o_next characterAtIndex:[o_next length] - 1] == 'D' )
            {
                NSString *o_job;
                [o_scan_person scanUpToCharactersFromSet: o_stopSet intoString: &o_job ];
                [o_jobs appendFormat: @"%@, ", o_job];
                [o_scan_person scanUpToString:@":" intoString: &o_next];
                [o_scan_person scanString:@":" intoString: nil];
            }
            
            [o_outString appendFormat: @"%@ <%@>\n%@\n\n", o_name, o_email, o_jobs];
        }
        
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
        /* Parse the thanks string */
        o_thanks_path = [[NSBundle mainBundle] pathForResource:@"THANKS" ofType:nil];
        o_thanks = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile: 
                        o_thanks_path ] encoding:NSWindowsCP1252StringEncoding];
        
        NSScanner *o_scan_thanks = [NSScanner scannerWithString: o_thanks];
        [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: nil];
        
        while( ![o_scan_thanks isAtEnd] )
        {
            NSString *o_person;
            NSString *o_job;
            
            [o_scan_thanks scanUpToString:@" - " intoString: &o_person];
            [o_scan_thanks scanString:@" - " intoString: nil];
            [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: &o_job];
            [o_outString appendFormat: @"%@\n%@\n\n", o_person, o_job];
        }
        [o_credits_textview setString:o_outString];
        
        /* Setup the copyright field */
146
147
148
        o_copyright = [o_local_dict objectForKey:@"NSHumanReadableCopyright"];
        [o_copyright_field setStringValue:o_copyright];

149
        /* Setup the window */
150
151
152
153
154
155
156
        [o_credits_textview setDrawsBackground: NO];
        [o_credits_scrollview setDrawsBackground: NO];
        [o_about_window setExcludedFromWindowsMenu:YES];
        [o_about_window setMenu:nil];
        [o_about_window center];
    }
    
157
    /* Show the window */
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
    b_restart = YES;
    [o_about_window makeKeyAndOrderFront:nil];
}

- (void)windowDidBecomeKey:(NSNotification *)notification
{
    o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval:1/6
                           target:self 
                           selector:@selector(scrollCredits:) 
                           userInfo:nil 
                           repeats:YES];
}

- (void)windowDidResignKey:(NSNotification *)notification
{
    [o_scroll_timer invalidate];
}

- (void)scrollCredits:(NSTimer *)timer
{
    if (b_restart)
    {
180
        /* Reset the starttime */
181
182
        i_start = [NSDate timeIntervalSinceReferenceDate] + 3.0;
        f_current = 0;
183
        f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
184
185
186
187
188
        b_restart = NO;
    }

    if ([NSDate timeIntervalSinceReferenceDate] >= i_start)
    {
189
        /* Scroll to the position */
190
191
        [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
        
192
        /* Increment the scroll position */
193
        f_current += 0.005;
194
195
196
197
198
199
        
        /* If at end, restart at the top */
        if ( f_current >= f_end )
        {
            b_restart = YES;
        }
200
201
202
203
    }
}

@end