]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/about.m
ASF: help stupid compiler
[vlc] / modules / gui / macosx / about.m
index d9983c0e06eecc2d58b6ddbce31c9b7f00efe94a..e02ae55c97119f71ab1c7d7db43093ded61542fe 100644 (file)
@@ -1,16 +1,17 @@
 /*****************************************************************************
  * about.m: MacOS X About Panel
  *****************************************************************************
- * Copyright (C) 2001-2003 VideoLAN
+ * Copyright (C) 2001-2011 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Derk-Jan Hartman <thedj@users.sourceforge.net>
+ *          Felix Paul Kühne <fkuehne -at- videolan.org>
  *
  * 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
  *
  * 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.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "intf.h"
-#include "about.h"
+#import "intf.h"
+#import "about.h"
+#import <vlc_intf_strings.h>
+#import <vlc_about.h>
+#import "CompatibilityFixes.h"
+
+#ifdef __x86_64__
+#define PLATFORM "Intel 64bit"
+#elif __i386__
+#define PLATFORM "Intel 32bit"
+#else
+#define PLATFORM "PowerPC 32bit"
+#endif
 
 /*****************************************************************************
- * VLAboutBox implementation 
+ * VLAboutBox implementation
  *****************************************************************************/
 @implementation VLAboutBox
 
@@ -39,112 +51,83 @@ static VLAboutBox *_o_sharedInstance = nil;
     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
 }
 
-- (id)init 
+- (id)init
 {
     if (_o_sharedInstance) {
         [self dealloc];
     } else {
         _o_sharedInstance = [super init];
     }
-    
     return _o_sharedInstance;
 }
 
-- (IBAction)showPanel:(id)sender
-{    
-    if (!o_credits_path)
+- (void) dealloc
+{
+    [[NSNotificationCenter defaultCenter] removeObserver: self];
+    [super dealloc];
+}
+
+- (void)awakeFromNib
+{
+    if (OSX_LION)
+        [o_about_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
+}
+
+/*****************************************************************************
+* VLC About Window
+*****************************************************************************/
+
+- (void)showAbout
+{
+    if(! b_isSetUp )
     {
-        NSString *o_name;
-        NSString *o_version;
-        NSString *o_thanks_path;
-    
-        /* Get the info dictionary (Info.plist) */
-        o_info_dict = [[NSBundle mainBundle] infoDictionary];
-        
+        /* we want to know when VLC wants to quit to prevent a crash while scrolling our credits */
+        [[NSNotificationCenter defaultCenter] addObserver: self
+                                                 selector: @selector(VLCWillTerminate)
+                                                     name: NSApplicationWillTerminateNotification
+                                                   object: nil];
+
         /* Get the localized info dictionary (InfoPlist.strings) */
-        localInfoBundle = CFBundleGetMainBundle();
-        o_local_dict = (NSDictionary *)
-                        CFBundleGetLocalInfoDictionary( localInfoBundle );
-        
-        /* Setup the name field */
-        o_name = [o_local_dict objectForKey:@"CFBundleName"];
-        
-        /* Set the about box title */
-        [o_about_window setTitle:_NS("About VLC media player")];
-        
-        /* Setup the version field */
-        o_version = [o_info_dict objectForKey:@"CFBundleVersion"];
-    
+        NSDictionary *o_local_dict;
+        o_local_dict = [[NSBundle mainBundle] localizedInfoDictionary];
+
+        /* Setup the copyright field */
+        [o_copyright_field setStringValue: [o_local_dict objectForKey:@"NSHumanReadableCopyright"]];
+
+        /* Set the box title */
+        [o_about_window setTitle: _NS("About VLC media player")];
+
+        /* setup the creator / revision field */
+        NSString *compiler;
+#ifdef __clang__
+        compiler = [NSString stringWithFormat:@"clang %s", __clang_version__];
+#elif __llvm__
+        compiler = [NSString stringWithFormat:@"llvm-gcc %s", __VERSION__];
+#else
+        compiler = [NSString stringWithFormat:@"gcc %s", __VERSION__];
+#endif
+        [o_revision_field setStringValue: [NSString stringWithFormat: _NS("Compiled by %@ with %@"), [NSString stringWithUTF8String:VLC_CompileBy()], compiler]];
+
         /* Setup the nameversion field */
-        o_name_version = [NSString stringWithFormat:@"%@ - Version %@", o_name, o_version];
-        [o_name_version_field setStringValue: o_name_version];
-        
-        /* Setup our credits */
-        o_credits_path = [[NSBundle mainBundle] pathForResource:@"AUTHORS" ofType:nil];
-        o_credits = [[NSString alloc] initWithData: [NSData dataWithContentsOfFile: o_credits_path ] encoding:NSWindowsCP1252StringEncoding];
-        
-        /* Parse the authors string */
-        NSMutableString *o_outString = [NSMutableString stringWithFormat: @"%@\n\n", _NS(INTF_ABOUT_MSG)];
-        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];
-        }
-        
-        /* 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];
+        [o_name_version_field setStringValue: [NSString stringWithFormat:@"Version %s (%s)", VERSION_MESSAGE, PLATFORM]];
         
-        NSScanner *o_scan_thanks = [NSScanner scannerWithString: o_thanks];
-        [o_scan_thanks scanUpToCharactersFromSet: o_stopSet intoString: nil];
-        
-        while( ![o_scan_thanks isAtEnd] )
+        NSMutableArray *tmpArray = [NSMutableArray arrayWithArray: [[NSString stringWithUTF8String: psz_authors]componentsSeparatedByString:@"\n\n"]];
+        NSUInteger count = [tmpArray count];
+        for( NSUInteger i = 0; i < count; i++ )
         {
-            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];
+            [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"\n" withString:@", "]];
+            [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@", -" withString:@"\n-" options:0 range:NSRangeFromString(@"0 30")]];
+            [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByReplacingOccurrencesOfString:@"-, " withString:@"-\n" options:0 range:NSRangeFromString(@"0 30")]];
+            [tmpArray replaceObjectAtIndex:i withObject:[[tmpArray objectAtIndex:i]stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]]];
         }
-        [o_credits_textview setString:o_outString];
-        
-        /* Setup the copyright field */
-        o_copyright = [o_local_dict objectForKey:@"NSHumanReadableCopyright"];
-        [o_copyright_field setStringValue:o_copyright];
+        NSString *authors = [tmpArray componentsJoinedByString:@"\n\n"];
+
+        /* setup the authors and thanks field */
+        [o_credits_textview setString: [NSString stringWithFormat: @"%@\n\n\n\n\n\n%@\n\n%@\n\n", 
+                                        [_NS(INTF_ABOUT_MSG) stringByReplacingOccurrencesOfString:@"\n" withString:@" "],
+                                        authors,
+                                        [[NSString stringWithUTF8String: psz_thanks] stringByReplacingOccurrencesOfString:@"\n" withString:@" " options:0 range:NSRangeFromString(@"680 2")]]];
 
         /* Setup the window */
         [o_credits_textview setDrawsBackground: NO];
@@ -152,20 +135,24 @@ static VLAboutBox *_o_sharedInstance = nil;
         [o_about_window setExcludedFromWindowsMenu:YES];
         [o_about_window setMenu:nil];
         [o_about_window center];
+        [o_gpl_btn setTitle: _NS("License")];
+
+        b_isSetUp = YES;
     }
-    
+
     /* Show the window */
     b_restart = YES;
-    [o_about_window makeKeyAndOrderFront:nil];
+    [o_credits_textview scrollPoint:NSMakePoint( 0, 0 )];
+    [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];
+    o_scroll_timer = [NSTimer scheduledTimerWithTimeInterval: 1/6
+                                                      target:self
+                                                    selector:@selector(scrollCredits:)
+                                                    userInfo:nil
+                                                     repeats:YES];
 }
 
 - (void)windowDidResignKey:(NSNotification *)notification
@@ -175,29 +162,85 @@ static VLAboutBox *_o_sharedInstance = nil;
 
 - (void)scrollCredits:(NSTimer *)timer
 {
-    if (b_restart)
+    if( b_restart )
     {
         /* Reset the starttime */
-        i_start = [NSDate timeIntervalSinceReferenceDate] + 3.0;
+        i_start = [NSDate timeIntervalSinceReferenceDate] + 4.0;
         f_current = 0;
         f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
         b_restart = NO;
     }
 
-    if ([NSDate timeIntervalSinceReferenceDate] >= i_start)
+    if( [NSDate timeIntervalSinceReferenceDate] >= i_start )
     {
-        /* Scroll to the position */
-        [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
-        
         /* Increment the scroll position */
         f_current += 0.005;
-        
+
+        /* Scroll to the position */
+        [o_credits_textview scrollPoint:NSMakePoint( 0, f_current )];
+
         /* If at end, restart at the top */
-        if ( f_current >= f_end )
+        if( f_current >= f_end )
         {
-            b_restart = YES;
+            /* f_end may be wrong on first run, so don't trust it too much */
+            if( f_end == [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height ) 
+            {
+                b_restart = YES;
+                [o_credits_textview scrollPoint:NSMakePoint( 0, 0 )];
+            }
+            else
+                f_end = [o_credits_textview bounds].size.height - [o_credits_scrollview bounds].size.height;
         }
     }
 }
 
+- (void)VLCWillTerminate
+{
+    [o_scroll_timer invalidate];
+    [[NSNotificationCenter defaultCenter] removeObserver: self];
+}
+
+/*****************************************************************************
+* VLC GPL Window, action called from the about window and the help menu
+*****************************************************************************/
+
+- (IBAction)showGPL:(id)sender
+{
+    [o_gpl_window setTitle: _NS("License")];
+    [o_gpl_field setString: [NSString stringWithUTF8String: psz_license]];
+    
+    [o_gpl_window center];
+    [o_gpl_window makeKeyAndOrderFront: sender];
+}
+
+/*****************************************************************************
+* VLC Generic Help Window
+*****************************************************************************/
+
+- (void)showHelp
+{
+    [o_help_window setTitle: _NS("VLC media player Help")];
+    [o_help_fwd_btn setToolTip: _NS("Next")];
+    [o_help_bwd_btn setToolTip: _NS("Previous")];
+    [o_help_home_btn setToolTip: _NS("Index")];
+
+    [o_help_window makeKeyAndOrderFront: self];
+    
+    [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
+                                        baseURL: [NSURL URLWithString:@"http://videolan.org"]];
+}
+
+- (IBAction)helpGoHome:(id)sender
+{
+    [[o_help_web_view mainFrame] loadHTMLString: _NS(I_LONGHELP)
+                                        baseURL: [NSURL URLWithString:@"http://videolan.org"]];
+}
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    /* delegate to update button states (we're the frameLoadDelegate for our help's webview)« */
+    [o_help_fwd_btn setEnabled: [o_help_web_view canGoForward]]; 
+    [o_help_bwd_btn setEnabled: [o_help_web_view canGoBack]];
+}
+
 @end