about.m
上传用户:riyaled888
上传日期:2009-03-27
资源大小:7338k
文件大小:8k
源码类别:

多媒体

开发平台:

MultiPlatform

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