]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/open.m
macosx: Fix a memleak.
[vlc] / modules / gui / macosx / open.m
index df3194495ee8c6f0ab09951330a1ba10b95f9f49..36fac3802ee4bb78b325bd078ee46e64499d64e2 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * open.m: MacOS X module for vlc
  *****************************************************************************
- * Copyright (C) 2002-2007 the VideoLAN team
+ * Copyright (C) 2002-2008 the VideoLAN team
  * $Id$
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
 #import "output.h"
 #import "eyetv.h"
 
+#define setEyeTVUnconnected \
+[o_capture_lbl setStringValue: _NS("No device connected")]; \
+[o_capture_long_lbl setStringValue: _NS("VLC could not detect any EyeTV compatible device.\n\nCheck the device's connection, make sure that the latest EyeTV software is installed and try again.")]; \
+[o_capture_lbl displayIfNeeded]; \
+[o_capture_long_lbl displayIfNeeded]; \
+[self showCaptureView: o_capture_label_view]
+
+
 /*****************************************************************************
  * GetEjectableMediaOfClass
  *****************************************************************************/
@@ -83,7 +91,7 @@ NSArray *GetEjectableMediaOfClass( const char *psz_class )
     p_list = [NSMutableArray arrayWithCapacity: 1];
  
     next_media = IOIteratorNext( media_iterator );
-    if( next_media != nil )
+    if( next_media )
     {
         char psz_buf[0x32];
         size_t dev_path_length;
@@ -116,7 +124,7 @@ NSArray *GetEjectableMediaOfClass( const char *psz_class )
  
             IOObjectRelease( next_media );
  
-        } while( ( next_media = IOIteratorNext( media_iterator ) ) != nil );
+        } while( ( next_media = IOIteratorNext( media_iterator ) ) );
     }
  
     IOObjectRelease( media_iterator );
@@ -162,6 +170,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [[o_tabview tabViewItemAtIndex: 0] setLabel: _NS("File")];
     [[o_tabview tabViewItemAtIndex: 1] setLabel: _NS("Disc")];
     [[o_tabview tabViewItemAtIndex: 2] setLabel: _NS("Network")];
+    [[o_tabview tabViewItemAtIndex: 3] setLabel: _NS("Capture")];
 
     [o_file_btn_browse setTitle: _NS("Browse...")];
     [o_file_stream setTitle: _NS("Treat as a pipe rather than as a file")];
@@ -189,12 +198,26 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
     [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
     [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
+
     [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
-    /* FIXME: implement EyeTV l10n here */
-    [self setSubPanel];
 
+    [o_capture_mode_pop removeAllItems];
+    if( MACOS_VERSION > 10.4f )
+        [o_capture_mode_pop addItemWithTitle: @"iSight"];
+    [o_capture_mode_pop addItemWithTitle: _NS("Screen")];
+    [o_capture_mode_pop addItemWithTitle: @"EyeTV"];
+    [o_screen_lbl setStringValue: _NS("Screen Capture Input")];
+    [o_screen_long_lbl setStringValue: _NS("This facility allows you to process your screen's output.")];
+    [o_screen_fps_lbl setStringValue: _NS("Frames per Second:")];
+    [o_eyetv_currentChannel_lbl setStringValue: _NS("Current channel:")];
+    [o_eyetv_previousProgram_btn setTitle: _NS("Previous Channel")];
+    [o_eyetv_nextProgram_btn setTitle: _NS("Next Channel")];
+    [o_eyetv_chn_status_txt setStringValue: _NS("Retrieving Channel Info...")];
+    [o_eyetv_noInstance_lbl setStringValue: _NS("EyeTV is not launched")];
+    [o_eyetv_noInstanceLong_lbl setStringValue: _NS("VLC could not connect to EyeTV.\nMake sure that you installed VLC's EyeTV plugin.")];
+    [o_eyetv_launchEyeTV_btn setTitle: _NS("Launch EyeTV now")];
+
+    [self setSubPanel];
 
     [[NSNotificationCenter defaultCenter] addObserver: self
         selector: @selector(openFilePathChanged:)
@@ -235,23 +258,17 @@ static VLCOpen *_o_sharedMainInstance = nil;
         name: NSControlTextDidChangeNotification
         object: o_net_http_url];
 
-    /* wake up with the correct EyeTV GUI */
-    if( [[[VLCMain sharedInstance] getEyeTVController] isEyeTVrunning] == YES )
-        [o_eyetv_tabView selectTabViewItemWithIdentifier:@"nodevice"];
-    else if( [[[VLCMain sharedInstance] getEyeTVController] isDeviceConnected] == YES )
-    {
-        [o_eyetv_tabView selectTabViewItemWithIdentifier:@"eyetvup"];
-        [self setupChannelInfo];
-    }
-    else
-        [o_eyetv_tabView selectTabViewItemWithIdentifier:@"noeyetv"];
-
     [[NSDistributedNotificationCenter defaultCenter] addObserver: self
                                                         selector: @selector(eyetvChanged:)
                                                             name: NULL
                                                           object: @"VLCEyeTVSupport"
                                               suspensionBehavior: NSNotificationSuspensionBehaviorDeliverImmediately];
+
+    [[NSNotificationCenter defaultCenter] addObserver: self
+                                             selector: @selector(screenFPSfieldChanged:)
+                                                 name: NSControlTextDidChangeNotification
+                                               object: o_screen_fps_fld];
+
     /* register clicks on text fields */
     [[NSNotificationCenter defaultCenter] addObserver: self
                                              selector: @selector(textFieldWasClicked:)
@@ -411,6 +428,10 @@ static VLCOpen *_o_sharedMainInstance = nil;
     {
         [self openNetInfoChanged: nil];
     }
+    else if( [o_label isEqualToString: _NS("Capture")] )
+    {
+        [self openCaptureModeChanged: nil];
+    }
 }
 
 - (void)openFileGeneric
@@ -431,12 +452,19 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [self openTarget: 2];
 }
 
+- (void)openCapture
+{
+    [self openCaptureModeChanged: nil];
+    [self showCaptureView: o_capture_label_view];
+    [self openTarget: 3];
+}
+
 - (void)openFilePathChanged:(NSNotification *)o_notification
 {
     NSString *o_mrl_string;
     NSString *o_filename = [o_file_path stringValue];
     NSString *o_ext = [o_filename pathExtension];
-    vlc_bool_t b_stream = [o_file_stream state];
+    bool b_stream = [o_file_stream state];
     BOOL b_dir = NO;
  
     [[NSFileManager defaultManager] fileExistsAtPath:o_filename isDirectory:&b_dir];
@@ -794,15 +822,96 @@ static VLCOpen *_o_sharedMainInstance = nil;
     }
 }
 
+- (void)showCaptureView: theView
+{
+    NSRect o_view_rect;
+    o_view_rect = [theView frame];
+    if( o_currentCaptureView )
+    {
+        [o_currentCaptureView removeFromSuperviewWithoutNeedingDisplay];
+        [o_currentCaptureView release];
+    }
+    [theView setFrame: NSMakeRect( 0, 10, o_view_rect.size.width, o_view_rect.size.height)];
+    [theView setNeedsDisplay: YES];
+    [theView setAutoresizesSubviews: YES];
+    [[[o_tabview tabViewItemAtIndex: 3] view] addSubview: theView];
+    [theView displayIfNeeded];
+    o_currentCaptureView = theView;
+    [o_currentCaptureView retain];
+}
+
+- (IBAction)openCaptureModeChanged:(id)sender
+{
+    if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
+    {
+        if( [[[VLCMain sharedInstance] getEyeTVController] isEyeTVrunning] == YES )
+        {
+            if( [[[VLCMain sharedInstance] getEyeTVController] isDeviceConnected] == YES )
+            {
+                [self showCaptureView: o_eyetv_running_view];
+                [self setupChannelInfo];
+            }
+            else
+            {
+                setEyeTVUnconnected;
+            }
+        }
+        else
+            [self showCaptureView: o_eyetv_notLaunched_view];
+        [o_mrl setStringValue: @""];
+    } 
+    else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
+    {
+        [self showCaptureView: o_screen_view];
+        [o_mrl setStringValue: [NSString stringWithFormat:@"screen:// :screen-fps=%@", [o_screen_fps_fld stringValue]]];
+    }
+    else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"iSight"] )
+    {
+        [o_capture_lbl setStringValue: _NS("iSight Capture Input")];
+        [o_capture_long_lbl setStringValue: _NS("This facility allows you to process your iSight's input signal.\n\nNo settings are available in this version, so you will be provided a 640px*480px raw video stream.\n\nLive Audio input is not supported.")];
+        [o_capture_lbl displayIfNeeded];
+        [o_capture_long_lbl displayIfNeeded];
+        
+        [self showCaptureView: o_capture_label_view];
+        [o_mrl setStringValue: @"qtcapture://"];
+    }
+}
+
+- (IBAction)screenStepperChanged:(id)sender
+{
+    [o_screen_fps_fld setIntValue: [o_screen_fps_stp intValue]];
+    [o_panel makeFirstResponder: o_screen_fps_fld];
+    [o_mrl setStringValue: [NSString stringWithFormat:@"screen:// :screen-fps=%@", [o_screen_fps_fld stringValue]]];
+}
+
+- (void)screenFPSfieldChanged:(NSNotification *)o_notification
+{
+    [o_screen_fps_stp setIntValue: [o_screen_fps_fld intValue]];
+    if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
+        [o_screen_fps_fld setIntValue: 1];
+    [o_mrl setStringValue: [NSString stringWithFormat:@"screen:// :screen-fps=%i", [o_screen_fps_fld intValue]]];
+}
+
 - (IBAction)eyetvSwitchChannel:(id)sender
 {
     if( sender == o_eyetv_nextProgram_btn )
-        [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: YES]];
+    {
+        int chanNum = [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: YES];
+        [o_eyetv_channels_pop selectItemWithTag:chanNum];
+        [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
+    }
     else if( sender == o_eyetv_previousProgram_btn )
-        [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: NO]];
+    {
+        int chanNum = [[[VLCMain sharedInstance] getEyeTVController] switchChannelUp: NO];
+        [o_eyetv_channels_pop selectItemWithTag:chanNum];
+        [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
+    }
     else if( sender == o_eyetv_channels_pop )
-        [[[VLCMain sharedInstance] getEyeTVController] selectChannel:
-            [[sender selectedItem] tag]];
+    {
+        int chanNum = [[sender selectedItem] tag];
+        [[[VLCMain sharedInstance] getEyeTVController] selectChannel:chanNum];
+        [o_mrl setStringValue: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
+    }
     else
         msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
 }
@@ -817,7 +926,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
     if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
     {
         msg_Dbg( VLCIntf, "eyetv device was added" );
-        [o_eyetv_tabView selectTabViewItemWithIdentifier:@"eyetvup"];
+        [self showCaptureView: o_eyetv_running_view];
         [self setupChannelInfo];
     }
     else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
@@ -825,23 +934,23 @@ static VLCOpen *_o_sharedMainInstance = nil;
         /* leave the channel selection like that,
          * switch to our "no device" tab */
         msg_Dbg( VLCIntf, "eyetv device was removed" );
-        [o_eyetv_tabView selectTabViewItemWithIdentifier:@"nodevice"];
+        setEyeTVUnconnected;
     }
     else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
     {
         /* switch to the "launch eyetv" tab */
         msg_Dbg( VLCIntf, "eyetv was terminated" );
-        [o_eyetv_tabView selectTabViewItemWithIdentifier:@"noeyetv"];
+        [self showCaptureView: o_eyetv_notLaunched_view];
     }
     else if( [[o_notification name] isEqualToString: @"PluginInit"] )
     {
         /* we got no device yet */
         msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
-        [o_eyetv_tabView selectTabViewItemWithIdentifier:@"nodevice"];
+        setEyeTVUnconnected;
     }
     else
         msg_Warn( VLCIntf, "unknown external notify '%s' received", [[o_notification name] UTF8String] );
-}
+}    
 
 /* little helper method, since this code needs to be run by multiple objects */
 - (void)setupChannelInfo
@@ -865,9 +974,6 @@ static VLCOpen *_o_sharedMainInstance = nil;
     if( channels ) 
     {
         NSString *channel;
-        [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("Tuner")
-                                                   action: nil
-                                            keyEquivalent: @""] setTag:x++];
         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
         while( channel = [channels nextObject] )
         {
@@ -875,7 +981,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
              * additionally, we save a bit of time */
             [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
                                                    action: nil
-                                            keyEquivalent: @""] setTag:x++];
+                                            keyEquivalent: @""] setTag:++x];
         }
         /* make Tuner the default */
         [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] getEyeTVController] currentChannel]];
@@ -884,8 +990,6 @@ static VLCOpen *_o_sharedMainInstance = nil;
     /* clean up GUI */
     [o_eyetv_chn_bgbar setHidden: YES];
     [o_eyetv_chn_status_txt setHidden: YES];
-
-    [o_mrl setStringValue: @"eyetv:"];
 }
 
 - (IBAction)subsChanged:(id)sender