]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/open.m
macosx: minor code optimization
[vlc] / modules / gui / macosx / open.m
index 979e26d72c7550d6b24e01b2d40d78de858d6099..e64d5174b0e4454fd0a51360c977a590acba84ff 100644 (file)
@@ -82,12 +82,10 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (id)init
 {
-    if( _o_sharedMainInstance) {
+    if (_o_sharedMainInstance)
         [self dealloc];
-    } else {
+    else
         _o_sharedMainInstance = [super init];
-        p_intf = VLCIntf;
-    }
 
     return _o_sharedMainInstance;
 }
@@ -98,18 +96,16 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [o_specialMediaFolders release];
     if (o_opticalDevices)
         [o_opticalDevices release];
-    if( o_file_slave_path )
+    if (o_file_slave_path)
         [o_file_slave_path release];
     [o_mrl release];
     if (o_sub_path)
         [o_sub_path release];
     [o_currentOpticalMediaIconView release];
     [o_currentOpticalMediaView release];
-    int i;
-    for( i = 0; i < [o_displayInfos count]; i ++ )
-    {
+    for (int i = 0; i < [o_displayInfos count]; i ++) {
         NSValue *v = [o_displayInfos objectAtIndex:i];
-        free( [v pointerValue] );
+        free([v pointerValue]);
     }
     [o_displayInfos removeAllObjects];
     [o_displayInfos release];
@@ -119,7 +115,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (void)awakeFromNib
 {
-    if (OSX_LION)
+    if (!OSX_SNOW_LEOPARD)
         [o_panel setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
 
     [o_panel setTitle: _NS("Open Source")];
@@ -198,8 +194,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [[o_net_mode cellAtRow:0 column:0] setTitle: _NS("Unicast")];
     [[o_net_mode cellAtRow:1 column:0] setTitle: _NS("Multicast")];
 
-    [o_net_udp_port setIntValue: config_GetInt( p_intf, "server-port" )];
-    [o_net_udp_port_stp setIntValue: config_GetInt( p_intf, "server-port" )];
+    [o_net_udp_port setIntValue: config_GetInt(VLCIntf, "server-port")];
+    [o_net_udp_port_stp setIntValue: config_GetInt(VLCIntf, "server-port")];
 
     [o_eyetv_chn_bgbar setUsesThreadedAnimation: YES];
 
@@ -229,26 +225,23 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
     [self qtkvideoDevices];
     [o_qtk_video_device_pop removeAllItems];
-    msg_Dbg( VLCIntf, "Found %lu video capture devices", [qtkvideoDevices count] );
+    msg_Dbg(VLCIntf, "Found %lu video capture devices", [qtkvideoDevices count]);
 
-    if([qtkvideoDevices count] >= 1)
-    {
-        if (!qtk_currdevice_uid) {
+    if ([qtkvideoDevices count] >= 1) {
+        if (!qtk_currdevice_uid)
             qtk_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeVideo] uniqueID]
                                                                 stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
-        }
+
         NSUInteger deviceCount = [qtkvideoDevices count];
-        for(int ivideo = 0; ivideo < deviceCount; ivideo++){
+        for (int ivideo = 0; ivideo < deviceCount; ivideo++) {
             QTCaptureDevice *qtk_device;
             qtk_device = [qtkvideoDevices objectAtIndex:ivideo];
             [o_qtk_video_device_pop addItemWithTitle: [qtk_device localizedDisplayName]];
-            if([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid]){
+
+            if ([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid])
                 [o_qtk_video_device_pop selectItemAtIndex:ivideo];
-            }
         }
-    }
-    else
-    {
+    } else {
         [o_qtk_video_device_pop addItemWithTitle: _NS("None")];
         [qtk_currdevice_uid release];
     }
@@ -256,28 +249,25 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [self qtkaudioDevices];
     [o_qtk_audio_device_pop removeAllItems];
     [o_screen_qtk_audio_pop removeAllItems];
-    msg_Dbg( VLCIntf, "Found %lu audio capture devices", [qtkaudioDevices count] );
+    msg_Dbg(VLCIntf, "Found %lu audio capture devices", [qtkaudioDevices count]);
 
-    if([qtkaudioDevices count] >= 1)
-    {
-        if (!qtkaudio_currdevice_uid) {
+    if ([qtkaudioDevices count] >= 1) {
+        if (!qtkaudio_currdevice_uid)
             qtkaudio_currdevice_uid = [[[QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound] uniqueID]
                                   stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
-        }
+
         NSUInteger deviceCount = [qtkaudioDevices count];
-        for(int iaudio = 0; iaudio < deviceCount; iaudio++){
+        for (int iaudio = 0; iaudio < deviceCount; iaudio++) {
             QTCaptureDevice *qtkaudio_device;
             qtkaudio_device = [qtkaudioDevices objectAtIndex:iaudio];
             [o_qtk_audio_device_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
             [o_screen_qtk_audio_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
-            if([[[qtkaudio_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]){
+            if ([[[qtkaudio_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]) {
                 [o_qtk_audio_device_pop selectItemAtIndex:iaudio];
                 [o_screen_qtk_audio_pop selectItemAtIndex:iaudio];
             }
         }
-    }
-    else
-    {
+    } else {
         [o_qtk_audio_device_pop addItemWithTitle: _NS("None")];
         [o_screen_qtk_audio_pop addItemWithTitle: _NS("None")];
         [qtkaudio_currdevice_uid release];
@@ -356,6 +346,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 {
     int i_index;
     module_config_t * p_item;
+    intf_thread_t * p_intf = VLCIntf;
 
     [o_file_sub_ckbox setTitle: _NS("Load subtitles file:")];
     [o_file_sub_path_lbl setStringValue: _NS("Choose a file")];
@@ -381,52 +372,50 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [o_file_sub_font_box setTitle: _NS("Font Properties")];
     [o_file_sub_file_box setTitle: _NS("Subtitle File")];
 
-    p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-encoding" );
+    p_item = config_FindConfig(VLC_OBJECT(p_intf), "subsdec-encoding");
 
-    if( p_item )
-    {
-        for( i_index = 0; p_item->list.psz && p_item->list.psz[i_index];
-             i_index++ )
-        {
-            [o_file_sub_encoding_pop addItemWithTitle:
-                [NSString stringWithUTF8String: p_item->list.psz[i_index]]];
+    if (p_item) {
+        for (int i = 0; i < p_item->list_count; i++) {
+            [o_file_sub_encoding_pop addItemWithTitle: _NS(p_item->list_text[i])];
+            [[o_file_sub_encoding_pop lastItem] setRepresentedObject:[NSString stringWithFormat:@"%s", p_item->list.psz[i]]];
+            if (p_item->value.psz && !strcmp(p_item->value.psz, p_item->list.psz[i]))
+                [o_file_sub_encoding_pop selectItem: [o_file_sub_encoding_pop lastItem]];
         }
-        [o_file_sub_encoding_pop selectItemWithTitle:
-                [NSString stringWithUTF8String: p_item->value.psz]];
+
+        if ([o_file_sub_encoding_pop indexOfSelectedItem] < 0)
+            [o_file_sub_encoding_pop selectItemAtIndex:0];
     }
 
-    p_item = config_FindConfig( VLC_OBJECT(p_intf), "subsdec-align" );
+    p_item = config_FindConfig(VLC_OBJECT(p_intf), "subsdec-align");
+
+    if (p_item) {
+        for (i_index = 0; i_index < p_item->list_count; i_index++)
+            [o_file_sub_align_pop addItemWithTitle: _NS(p_item->list_text[i_index])];
 
-    if ( p_item )
-    {
-        for ( i_index = 0; i_index < p_item->list_count; i_index++ )
-        {
-            [o_file_sub_align_pop addItemWithTitle:
-             _NS(p_item->list_text[i_index])];
-        }
         [o_file_sub_align_pop selectItemAtIndex: p_item->value.i];
     }
 
-    p_item = config_FindConfig( VLC_OBJECT(p_intf), "freetype-rel-fontsize" );
+    p_item = config_FindConfig(VLC_OBJECT(p_intf), "freetype-rel-fontsize");
 
-    if ( p_item )
-    {
-        for ( i_index = 0; i_index < p_item->list_count; i_index++ )
-        {
+    if (p_item) {
+        for (i_index = 0; i_index < p_item->list_count; i_index++) {
             [o_file_sub_size_pop addItemWithTitle: _NS(p_item->list_text[i_index])];
-            if ( p_item->value.i == p_item->list.i[i_index] )
-            {
+
+            if (p_item->value.i == p_item->list.i[i_index])
                 [o_file_sub_size_pop selectItemAtIndex: i_index];
-            }
         }
     }
 }
 
 - (void)openTarget:(int)i_type
 {
+    /* check whether we already run a modal dialog */
+    if ([NSApp modalWindow] != nil)
+        return;
+
     int i_result;
 
-    b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
+    b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
 
     [o_tabview selectTabViewItemAtIndex: i_type];
     [o_file_sub_ckbox setState: NSOffState];
@@ -434,34 +423,28 @@ static VLCOpen *_o_sharedMainInstance = nil;
     i_result = [NSApp runModalForWindow: o_panel];
     [o_panel close];
 
-    if( i_result )
-    {
+    if (i_result) {
         NSMutableDictionary *o_dic;
         NSMutableArray *o_options = [NSMutableArray array];
 
         o_dic = [NSMutableDictionary dictionaryWithObject: [self MRL] forKey: @"ITEM_URL"];
-        if( [o_file_sub_ckbox state] == NSOnState )
-        {
+        if ([o_file_sub_ckbox state] == NSOnState) {
             module_config_t * p_item;
 
             [o_options addObject: [NSString stringWithFormat: @"sub-file=%@", o_sub_path]];
-            if( [o_file_sub_override state] == NSOnState )
-            {
-                [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)( [o_file_sub_delay intValue] * 10 )]];
+            if ([o_file_sub_override state] == NSOnState) {
+                [o_options addObject: [NSString stringWithFormat: @"sub-delay=%i", (int)([o_file_sub_delay intValue] * 10)]];
                 [o_options addObject: [NSString stringWithFormat: @"sub-fps=%f", [o_file_sub_fps floatValue]]];
             }
             [o_options addObject: [NSString stringWithFormat:
-                    @"subsdec-encoding=%@",
-                    [o_file_sub_encoding_pop titleOfSelectedItem]]];
+                    @"subsdec-encoding=%@", [[o_file_sub_encoding_pop selectedItem] representedObject]]];
             [o_options addObject: [NSString stringWithFormat:
-                    @"subsdec-align=%li",
-                    [o_file_sub_align_pop indexOfSelectedItem]]];
+                    @"subsdec-align=%li", [o_file_sub_align_pop indexOfSelectedItem]]];
 
-            p_item = config_FindConfig( VLC_OBJECT(p_intf),
-                                            "freetype-rel-fontsize" );
+            p_item = config_FindConfig(VLC_OBJECT(VLCIntf),
+                                            "freetype-rel-fontsize");
 
-            if ( p_item )
-            {
+            if (p_item) {
                 [o_options addObject: [NSString stringWithFormat:
                     @"freetype-rel-fontsize=%i",
                     p_item->list.i[[o_file_sub_size_pop indexOfSelectedItem]]]];
@@ -470,40 +453,37 @@ static VLCOpen *_o_sharedMainInstance = nil;
         NSArray * components = [[o_file_starttime_fld stringValue] componentsSeparatedByString:@":"];
         NSUInteger componentCount = [components count];
         NSInteger tempValue;
-        if( componentCount == 1 )
-            tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] );
-        else if( componentCount == 2 )
-            tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue] );
-        else if( componentCount == 3 )
-            tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue] );
+        if (componentCount == 1)
+            tempValue = 1000000 * ([[components objectAtIndex:0] intValue]);
+        else if (componentCount == 2)
+            tempValue = 1000000 * ([[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue]);
+        else if (componentCount == 3)
+            tempValue = 1000000 * ([[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue]);
         if (tempValue > 0)
             [o_options addObject: [NSString stringWithFormat:@"start-time=%li", tempValue]];
         components = [[o_file_stoptime_fld stringValue] componentsSeparatedByString:@":"];
         componentCount = [components count];
-        if( componentCount == 1 )
-            tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] );
-        else if( componentCount == 2 )
-            tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue] );
-        else if( componentCount == 3 )
-            tempValue = 1000000 * ( [[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue] );
+        if (componentCount == 1)
+            tempValue = 1000000 * ([[components objectAtIndex:0] intValue]);
+        else if (componentCount == 2)
+            tempValue = 1000000 * ([[components objectAtIndex:0] intValue] * 60 + [[components objectAtIndex:1] intValue]);
+        else if (componentCount == 3)
+            tempValue = 1000000 * ([[components objectAtIndex:0] intValue] * 3600 + [[components objectAtIndex:1] intValue] * 60 + [[components objectAtIndex:2] intValue]);
         if (tempValue > 0)
             [o_options addObject: [NSString stringWithFormat:@"stop-time=%li", tempValue]];
-        if( [o_output_ckbox state] == NSOnState )
-        {
+        if ([o_output_ckbox state] == NSOnState) {
             NSArray * soutMRL = [o_sout_options soutMRL];
             NSUInteger count = [soutMRL count];
             for (NSUInteger i = 0 ; i < count ; i++)
                 [o_options addObject: [NSString stringWithString: [soutMRL objectAtIndex: i]]];
         }
-        if( [o_file_slave_ckbox state] && o_file_slave_path )
+        if ([o_file_slave_ckbox state] && o_file_slave_path)
            [o_options addObject: [NSString stringWithFormat: @"input-slave=%@", o_file_slave_path]];
-        if( [[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")] )
-        {
-            if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
-            {
+        if ([[[o_tabview selectedTabViewItem] label] isEqualToString: _NS("Capture")]) {
+            if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")]) {
                 int selected_index = [o_screen_screen_pop indexOfSelectedItem];
                 NSValue *v = [o_displayInfos objectAtIndex:selected_index];
-                struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
+                struct display_info_t *item = (struct display_info_t *)[v pointerValue];
 
                 [o_options addObject: [NSString stringWithFormat: @"screen-fps=%f", [o_screen_fps_fld floatValue]]];
                 [o_options addObject: [NSString stringWithFormat: @"screen-display-id=%i", item->id]];
@@ -511,17 +491,15 @@ static VLCOpen *_o_sharedMainInstance = nil;
                 [o_options addObject: [NSString stringWithFormat: @"screen-top=%i", [o_screen_top_fld intValue]]];
                 [o_options addObject: [NSString stringWithFormat: @"screen-width=%i", [o_screen_width_fld intValue]]];
                 [o_options addObject: [NSString stringWithFormat: @"screen-height=%i", [o_screen_height_fld intValue]]];
-                if( [o_screen_follow_mouse_ckb intValue] == YES )
+                if ([o_screen_follow_mouse_ckb intValue] == YES)
                     [o_options addObject: @"screen-follow-mouse"];
                 else
                     [o_options addObject: @"no-screen-follow-mouse"];
                 if ([o_screen_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
                    [o_options addObject: [NSString stringWithFormat: @"input-slave=qtsound://%@", qtkaudio_currdevice_uid]];
             }
-            else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")] )
-            {
-                if ([o_qtk_video_ckb state])
-                {
+            else if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")]) {
+                if ([o_qtk_video_ckb state]) {
                     [o_options addObject: [NSString stringWithFormat: @"qtcapture-width=%i", [o_capture_width_fld intValue]]];
                     [o_options addObject: [NSString stringWithFormat: @"qtcapture-height=%i", [o_capture_height_fld intValue]]];
                     if ([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
@@ -532,7 +510,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
         /* apply the options to our item(s) */
         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
-        if( b_autoplay )
+        if (b_autoplay)
             [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:NO];
         else
             [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject: o_dic] atPos: -1 enqueue:YES];
@@ -542,10 +520,10 @@ static VLCOpen *_o_sharedMainInstance = nil;
 - (IBAction)screenChanged:(id)sender
 {
     int selected_index = [o_screen_screen_pop indexOfSelectedItem];
-    if( selected_index >= [o_displayInfos count] ) return;
+    if (selected_index >= [o_displayInfos count]) return;
 
     NSValue *v = [o_displayInfos objectAtIndex:selected_index];
-    struct display_info_t *item = ( struct display_info_t * )[v pointerValue];
+    struct display_info_t *item = (struct display_info_t *)[v pointerValue];
 
     [o_screen_left_stp setMaxValue: item->rect.size.width];
     [o_screen_top_stp setMaxValue: item->rect.size.height];
@@ -558,8 +536,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 - (IBAction)qtkChanged:(id)sender
 {
     NSInteger i_selectedDevice = [o_qtk_video_device_pop indexOfSelectedItem];
-    if( [qtkvideoDevices count] >= 1 )
-    {
+    if ([qtkvideoDevices count] >= 1) {
         NSValue *sizes = [[[[qtkvideoDevices objectAtIndex:i_selectedDevice] formatDescriptions] objectAtIndex: 0] attributeForKey: QTFormatDescriptionVideoEncodedPixelsSizeAttribute];
 
         [o_capture_width_fld setIntValue: [sizes sizeValue].width];
@@ -572,9 +549,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (IBAction)qtkAudioChanged:(id)sender
 {
-    NSInteger i_selectedDevice = [sender indexOfSelectedItem];
-    if( [qtkaudioDevices count] >= 1 )
-    {
+    NSInteger i_selectedDevice = [o_qtk_audio_device_pop indexOfSelectedItem];
+    if ([qtkaudioDevices count] >= 1) {
         qtkaudio_currdevice_uid = [[(QTCaptureDevice *)[qtkaudioDevices objectAtIndex:i_selectedDevice] uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
     }
     [o_screen_qtk_audio_pop selectItemAtIndex: i_selectedDevice];
@@ -602,22 +578,14 @@ static VLCOpen *_o_sharedMainInstance = nil;
 {
     NSString *o_label = [o_tvi label];
 
-    if( [o_label isEqualToString: _NS("File")] )
-    {
+    if ([o_label isEqualToString: _NS("File")])
         [self openFilePathChanged: nil];
-    }
-    else if( [o_label isEqualToString: _NS("Disc")] )
-    {
+    else if ([o_label isEqualToString: _NS("Disc")])
         [self scanOpticalMedia: nil];
-    }
-    else if( [o_label isEqualToString: _NS("Network")] )
-    {
+    else if ([o_label isEqualToString: _NS("Network")])
         [self openNetInfoChanged: nil];
-    }
-    else if( [o_label isEqualToString: _NS("Capture")] )
-    {
+    else if ([o_label isEqualToString: _NS("Capture")])
         [self openCaptureModeChanged: nil];
-    }
 }
 
 - (IBAction)expandMRLfieldAction:(id)sender
@@ -626,20 +594,19 @@ static VLCOpen *_o_sharedMainInstance = nil;
     o_win_rect = [o_panel frame];
     o_view_rect = [o_mrl_view frame];
 
-    if( [o_mrl_btn state] == NSOffState )
-    {
+    if ([o_mrl_btn state] == NSOffState) {
         /* we need to collaps, restore the panel size */
         o_win_rect.size.height = o_win_rect.size.height - o_view_rect.size.height;
-        o_win_rect.origin.y = ( o_win_rect.origin.y + o_view_rect.size.height ) - o_view_rect.size.height;
+        o_win_rect.origin.y = (o_win_rect.origin.y + o_view_rect.size.height) - o_view_rect.size.height;
 
         /* remove the MRL view */
         [o_mrl_view removeFromSuperview];
     } else {
         /* we need to expand */
-        [o_mrl_view setFrame: NSMakeRect( 0,
+        [o_mrl_view setFrame: NSMakeRect(0,
                                          [o_mrl_btn frame].origin.y,
                                          o_view_rect.size.width,
-                                         o_view_rect.size.height )];
+                                         o_view_rect.size.height)];
         [o_mrl_view setNeedsDisplay: NO];
         [o_mrl_view setAutoresizesSubviews: YES];
 
@@ -648,8 +615,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
     }
 
     [[o_panel animator] setFrame: o_win_rect display:YES];
-//    [o_panel displayIfNeeded];
-    if( [o_mrl_btn state] == NSOnState )
+
+    if ([o_mrl_btn state] == NSOnState)
         [[o_panel contentView] addSubview: o_mrl_view];
 }
 
@@ -684,39 +651,35 @@ static VLCOpen *_o_sharedMainInstance = nil;
 - (void)openFile
 {
     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
-    b_autoplay = config_GetInt( VLCIntf, "macosx-autoplay" );
+    b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
 
     [o_open_panel setAllowsMultipleSelection: YES];
     [o_open_panel setCanChooseDirectories: YES];
     [o_open_panel setTitle: _NS("Open File")];
     [o_open_panel setPrompt: _NS("Open")];
 
-    if( [o_open_panel runModal] == NSOKButton )
-    {
+    if ([o_open_panel runModal] == NSOKButton) {
         NSArray * o_urls = [o_open_panel URLs];
         NSUInteger count = [o_urls count];
         NSMutableArray *o_values = [NSMutableArray arrayWithCapacity:count];
         NSMutableArray *o_array = [NSMutableArray arrayWithCapacity:count];
-        for( NSUInteger i = 0; i < count; i++ )
-        {
+        for (NSUInteger i = 0; i < count; i++)
             [o_values addObject: [[o_urls objectAtIndex: i] path]];
-        }
         [o_values sortUsingSelector:@selector(caseInsensitiveCompare:)];
 
-        for( NSUInteger i = 0; i < count; i++ )
-        {
+        for (NSUInteger i = 0; i < count; i++) {
             NSDictionary *o_dic;
             char *psz_uri = vlc_path2uri([[o_values objectAtIndex:i] UTF8String], "file");
-            if( !psz_uri )
+            if (!psz_uri)
                 continue;
 
             o_dic = [NSDictionary dictionaryWithObject:[NSString stringWithCString:psz_uri encoding:NSUTF8StringEncoding] forKey:@"ITEM_URL"];
 
-            free( psz_uri );
+            free(psz_uri);
 
             [o_array addObject: o_dic];
         }
-        if( b_autoplay )
+        if (b_autoplay)
             [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
         else
             [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
@@ -728,23 +691,22 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (void)openFilePathChanged:(NSNotification *)o_notification
 {
-    if ( o_file_path && [o_file_path length] > 0 )
-    {
+    if (o_file_path && [o_file_path length] > 0) {
         bool b_stream = [o_file_stream state];
         BOOL b_dir = NO;
 
         [[NSFileManager defaultManager] fileExistsAtPath:o_file_path isDirectory:&b_dir];
 
         char *psz_uri = vlc_path2uri([o_file_path UTF8String], "file");
-        if( !psz_uri ) return;
+        if (!psz_uri) return;
 
         NSMutableString *o_mrl_string = [NSMutableString stringWithUTF8String: psz_uri ];
         NSRange offile = [o_mrl_string rangeOfString:@"file"];
-        free( psz_uri );
+        free(psz_uri);
 
-        if( b_dir )
+        if (b_dir)
             [o_mrl_string replaceCharactersInRange:offile withString: @"directory"];
-        else if( b_stream )
+        else if (b_stream)
             [o_mrl_string replaceCharactersInRange:offile withString: @"stream"];
 
         [o_file_name setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_path]];
@@ -753,9 +715,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
         [o_file_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_path]];
         [o_file_icon_well setHidden: NO];
         [self setMRL: o_mrl_string];
-    }
-    else
-    {
+    } else {
         [o_file_name setStringValue: @""];
         [o_file_name_stub setHidden: NO];
         [o_file_stream setHidden: YES];
@@ -773,9 +733,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [o_open_panel setTitle: _NS("Open File")];
     [o_open_panel setPrompt: _NS("Open")];
     [o_open_panel beginSheetModalForWindow:[sender window] completionHandler:^(NSInteger returnCode) {
-        if (returnCode == NSFileHandlingPanelOKButton)
-        {
-            if( o_file_path )
+        if (returnCode == NSFileHandlingPanelOKButton) {
+            if (o_file_path)
                 [o_file_path release];
             o_file_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
             [o_file_path retain];
@@ -791,29 +750,24 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (IBAction)inputSlaveAction:(id)sender
 {
-    if( sender == o_file_slave_ckbox )
+    if (sender == o_file_slave_ckbox)
         [o_file_slave_select_btn setEnabled: [o_file_slave_ckbox state]];
-    else
-    {
+    else {
         NSOpenPanel *o_open_panel;
         o_open_panel = [NSOpenPanel openPanel];
         [o_open_panel setCanChooseFiles: YES];
         [o_open_panel setCanChooseDirectories: NO];
-        if( [o_open_panel runModal] == NSOKButton )
-        {
-            if( o_file_slave_path )
+        if ([o_open_panel runModal] == NSOKButton) {
+            if (o_file_slave_path)
                 [o_file_slave_path release];
             o_file_slave_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
             [o_file_slave_path retain];
         }
     }
-    if( o_file_slave_path && [o_file_slave_ckbox state] == NSOnState)
-    {
+    if (o_file_slave_path && [o_file_slave_ckbox state] == NSOnState) {
         [o_file_slave_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_file_slave_path]];
         [o_file_slave_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile: o_file_slave_path]];
-    }
-    else
-    {
+    } else {
         [o_file_slave_filename_lbl setStringValue: @""];
         [o_file_slave_icon_well setImage: NULL];
     }
@@ -835,10 +789,9 @@ static VLCOpen *_o_sharedMainInstance = nil;
 {
     NSRect o_view_rect;
     o_view_rect = [theView frame];
-    [theView setFrame: NSMakeRect( 233, 0, o_view_rect.size.width, o_view_rect.size.height)];
+    [theView setFrame: NSMakeRect(233, 0, o_view_rect.size.width, o_view_rect.size.height)];
     [theView setAutoresizesSubviews: YES];
-    if (o_currentOpticalMediaView)
-    {
+    if (o_currentOpticalMediaView) {
         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaView with: theView];
         [o_currentOpticalMediaView release];
     }
@@ -849,11 +802,10 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
     NSImageView *imageView;
     imageView = [[NSImageView alloc] init];
-    [imageView setFrame: NSMakeRect( 53, 61, 128, 128 )];
+    [imageView setFrame: NSMakeRect(53, 61, 128, 128)];
     [icon setSize: NSMakeSize(128,128)];
     [imageView setImage: icon];
-    if (o_currentOpticalMediaIconView)
-    {
+    if (o_currentOpticalMediaIconView) {
         [[[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] animator] replaceSubview: o_currentOpticalMediaIconView with: imageView];
         [o_currentOpticalMediaIconView release];
     }
@@ -872,19 +824,19 @@ static VLCOpen *_o_sharedMainInstance = nil;
     OSStatus err;
     FSRef ref;
     FSVolumeRefNum actualVolume;
-    err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
+    err = FSPathMakeRef ((const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL);
 
     // get a FSVolumeRefNum from mountPath
-    if ( noErr == err ) {
+    if (noErr == err) {
         FSCatalogInfo   catalogInfo;
-        err = FSGetCatalogInfo ( &ref,
+        err = FSGetCatalogInfo (&ref,
                                 kFSCatInfoVolume,
                                 &catalogInfo,
                                 NULL,
                                 NULL,
                                 NULL
-                                );
-        if ( noErr == err )
+                               );
+        if (noErr == err)
             actualVolume = catalogInfo.volume;
         else
             return @"";
@@ -893,9 +845,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
         return @"";
 
     GetVolParmsInfoBuffer volumeParms;
-    err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
-    if ( noErr == err )
-    {
+    err = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
+    if (noErr == err) {
         NSString *bsdName = [NSString stringWithUTF8String:(char *)volumeParms.vMDeviceID];
         return [NSString stringWithFormat:@"/dev/r%@", bsdName];
     }
@@ -908,19 +859,19 @@ static VLCOpen *_o_sharedMainInstance = nil;
     OSStatus err;
     FSRef ref;
     FSVolumeRefNum actualVolume;
-    err = FSPathMakeRef ( (const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL );
+    err = FSPathMakeRef ((const UInt8 *) [mountPath fileSystemRepresentation], &ref, NULL);
 
     // get a FSVolumeRefNum from mountPath
-    if ( noErr == err ) {
+    if (noErr == err) {
         FSCatalogInfo   catalogInfo;
-        err = FSGetCatalogInfo ( &ref,
+        err = FSGetCatalogInfo (&ref,
                                 kFSCatInfoVolume,
                                 &catalogInfo,
                                 NULL,
                                 NULL,
                                 NULL
-                                );
-        if ( noErr == err )
+                               );
+        if (noErr == err)
             actualVolume = catalogInfo.volume;
         else
             return NULL;
@@ -929,7 +880,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
         return NULL;
 
     GetVolParmsInfoBuffer volumeParms;
-    err = FSGetVolumeParms( actualVolume, &volumeParms, sizeof(volumeParms) );
+    err = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
 
     CFMutableDictionaryRef matchingDict;
     io_service_t service;
@@ -945,47 +896,40 @@ static VLCOpen *_o_sharedMainInstance = nil;
         if (IOObjectConformsTo(service, kIOCDMediaClass)) {
             returnValue = kVLCMediaAudioCD;
         }
-        else if(IOObjectConformsTo(service, kIODVDMediaClass))
+        else if (IOObjectConformsTo(service, kIODVDMediaClass))
             returnValue = kVLCMediaDVD;
-        else if(IOObjectConformsTo(service, kIOBDMediaClass))
+        else if (IOObjectConformsTo(service, kIOBDMediaClass))
             returnValue = kVLCMediaBD;
-        else
-        {
+        else {
             if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
                 returnValue = kVLCMediaVideoTSFolder;
             else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
                 returnValue = kVLCMediaBDMVFolder;
-            else
-            {
+            else {
                 // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
                 NSFileManager * fm = [[NSFileManager alloc] init];
 
                 NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
-                for (int i = 0; i < [dirContents count]; i++)
-                {
+                for (int i = 0; i < [dirContents count]; i++) {
                     NSString *currentFile = [dirContents objectAtIndex:i];
                     NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
 
                     BOOL isDir;
                     if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
                     {
-                        if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame)
-                        {
+                        if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame) {
                             returnValue = kVLCMediaSVCD;
                             break;
                         }
-                        if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame)
-                        {
+                        if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame) {
                             returnValue = kVLCMediaVCD;
                             break;
                         }
-                        if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame)
-                        {
+                        if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame) {
                             returnValue = kVLCMediaBDMVFolder;
                             break;
                         }
-                        if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame)
-                        {
+                        if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame) {
                             returnValue = kVLCMediaVideoTSFolder;
                             break;
                         }
@@ -994,7 +938,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
                 [fm release];
 
-                if(!returnValue)
+                if (!returnValue)
                     returnValue = kVLCMediaVideoTSFolder;
             }
         }
@@ -1011,8 +955,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
     NSString *o_device_path = [o_dict objectForKey:@"devicePath"];
     NSImage *o_image = [o_dict objectForKey:@"image"];
 
-    if ([diskType isEqualToString: kVLCMediaDVD] || [diskType isEqualToString: kVLCMediaVideoTSFolder])
-    {
+    if ([diskType isEqualToString: kVLCMediaDVD] || [diskType isEqualToString: kVLCMediaVideoTSFolder]) {
         [o_disc_dvd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_opticalDevicePath]];
         [o_disc_dvdwomenus_lbl setStringValue: [o_disc_dvd_lbl stringValue]];
 
@@ -1023,35 +966,27 @@ static VLCOpen *_o_sharedMainInstance = nil;
             [self setMRL: [NSString stringWithFormat: @"dvdread://%@#%i:%i-", o_device_path, [o_disc_dvdwomenus_title intValue], [o_disc_dvdwomenus_chapter intValue]]];
             [self showOpticalMediaView: o_disc_dvdwomenus_view withIcon: o_image];
         }
-    }
-    else if ([diskType isEqualToString: kVLCMediaAudioCD])
-    {
+    } else if ([diskType isEqualToString: kVLCMediaAudioCD]) {
         [o_disc_audiocd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
         [o_disc_audiocd_trackcount_lbl setStringValue: [NSString stringWithFormat:_NS("%i tracks"), [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath: o_opticalDevicePath error:NULL] count] - 1]]; // minus .TOC.plist
         [self showOpticalMediaView: o_disc_audiocd_view withIcon: o_image];
         [self setMRL: [NSString stringWithFormat: @"cdda://%@", o_device_path]];
-    }
-    else if ([diskType isEqualToString: kVLCMediaVCD])
-    {
+    } else if ([diskType isEqualToString: kVLCMediaVCD]) {
         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
         [self showOpticalMediaView: o_disc_vcd_view withIcon: o_image];
         [self setMRL: [NSString stringWithFormat: @"vcd://%@#%i:%i", o_device_path, [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
-    }
-    else if ([diskType isEqualToString: kVLCMediaSVCD])
-    {
+    } else if ([diskType isEqualToString: kVLCMediaSVCD]) {
         [o_disc_vcd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
         [self showOpticalMediaView: o_disc_vcd_view withIcon: o_image];
         [self setMRL: [NSString stringWithFormat: @"vcd://%@@%i:%i", o_device_path, [o_disc_vcd_title intValue], [o_disc_vcd_chapter intValue]]];
-    }
-    else if ([diskType isEqualToString: kVLCMediaBD] || [diskType isEqualToString: kVLCMediaBDMVFolder])
-    {
+    } else if ([diskType isEqualToString: kVLCMediaBD] || [diskType isEqualToString: kVLCMediaBDMVFolder]) {
         [o_disc_bd_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath: o_opticalDevicePath]];
         [self showOpticalMediaView: o_disc_bd_view withIcon: o_image];
         [self setMRL: [NSString stringWithFormat: @"bluray://%@", o_opticalDevicePath]];
-    }
-    else
-    {
-        msg_Warn( VLCIntf, "unknown disk type, no idea what to display" );
+    } else {
+        if (VLCIntf)
+            msg_Warn(VLCIntf, "unknown disk type, no idea what to display");
+
         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed:@"NSApplicationIcon"]];
     }
 }
@@ -1125,10 +1060,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
     }
 
     NSUInteger count = [o_allMediaDevices count];
-    if (count > 0)
-    {
-        for (NSUInteger i = 0; i < count ; i++)
-        {
+    if (count > 0) {
+        for (NSUInteger i = 0; i < count ; i++) {
             NSDictionary *o_dict = [o_allMediaDevices objectAtIndex: i];
             [o_disc_selector_pop addItemWithTitle: [[NSFileManager defaultManager] displayNameAtPath:[o_dict objectForKey:@"path"]]];
         }
@@ -1143,10 +1076,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
             [o_disc_selector_pop selectItemAtIndex: [[o_disc_selector_pop itemArray] count] - 1];
 
         [self discSelectorChanged:nil];
-    }
-    else
-    {
-        msg_Dbg( VLCIntf, "no optical media found" );
+    } else {
+        msg_Dbg(VLCIntf, "no optical media found");
         [o_disc_selector_pop setHidden: YES];
         [self showOpticalMediaView: o_disc_nodisc_view withIcon: [NSImage imageNamed: @"NSApplicationIcon"]];
     }
@@ -1165,16 +1096,18 @@ static VLCOpen *_o_sharedMainInstance = nil;
     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
 
     [o_open_panel setAllowsMultipleSelection: NO];
-    [o_open_panel setCanChooseFiles: NO];
     [o_open_panel setCanChooseDirectories: YES];
     [o_open_panel setTitle: [sender title]];
     [o_open_panel setPrompt: _NS("Open")];
 
-    if ([o_open_panel runModal] == NSOKButton)
-    {
+    /* work-around for Mountain Lion, which treats folders called "BDMV" including an item named "INDEX.BDM"
+     * as a _FILE_. Don't ask, move on. There is nothing to see here */
+    [o_open_panel setCanChooseFiles: YES];
+    [o_open_panel setAllowedFileTypes:[NSArray arrayWithObjects:@"public.directory", nil]];
+
+    if ([o_open_panel runModal] == NSOKButton) {
         NSString *o_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
-        if ([o_path length] > 0 )
-        {
+        if ([o_path length] > 0) {
             [NSThread detachNewThreadSelector:@selector(scanSpecialPath:) toTarget:self withObject:o_path];
         }
     }
@@ -1228,10 +1161,10 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (void)textFieldWasClicked:(NSNotification *)o_notification
 {
-    if( [o_notification object] == o_net_udp_port )
+    if ([o_notification object] == o_net_udp_port)
         [o_net_mode selectCellAtRow: 0 column: 0];
-    else if[o_notification object] == o_net_udpm_addr ||
-             [o_notification object] == o_net_udpm_port )
+    else if ([o_notification object] == o_net_udpm_addr ||
+             [o_notification object] == o_net_udpm_port)
         [o_net_mode selectCellAtRow: 1 column: 0];
     else
         [o_net_mode selectCellAtRow: 2 column: 0];
@@ -1241,14 +1174,13 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (IBAction)openNetModeChanged:(id)sender
 {
-    if( sender == o_net_mode )
-    {
-        if( [[sender selectedCell] tag] == 0 )
+    if (sender == o_net_mode) {
+        if ([[sender selectedCell] tag] == 0)
             [o_panel makeFirstResponder: o_net_udp_port];
-        else if ( [[sender selectedCell] tag] == 1 )
+        else if ([[sender selectedCell] tag] == 1)
             [o_panel makeFirstResponder: o_net_udpm_addr];
         else
-            msg_Warn( p_intf, "Unknown sender tried to change UDP/RTP mode" );
+            msg_Warn(VLCIntf, "Unknown sender tried to change UDP/RTP mode");
     }
 
     [self openNetInfoChanged: nil];
@@ -1258,15 +1190,13 @@ static VLCOpen *_o_sharedMainInstance = nil;
 {
     int i_tag = [sender tag];
 
-    if( i_tag == 0 )
-    {
+    if (i_tag == 0) {
         [o_net_udp_port setIntValue: [o_net_udp_port_stp intValue]];
         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
                                                             object: o_net_udp_port];
         [o_panel makeFirstResponder: o_net_udp_port];
     }
-    else if( i_tag == 1 )
-    {
+    else if (i_tag == 1) {
         [o_net_udpm_port setIntValue: [o_net_udpm_port_stp intValue]];
         [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCOpenTextFieldWasClicked"
                                                             object: o_net_udpm_port];
@@ -1280,54 +1210,46 @@ static VLCOpen *_o_sharedMainInstance = nil;
 {
     NSString *o_mrl_string = [NSString string];
 
-    if( [o_net_udp_panel isVisible] )
-    {
+    if ([o_net_udp_panel isVisible]) {
         NSString *o_mode;
         o_mode = [[o_net_mode selectedCell] title];
 
-        if( [o_mode isEqualToString: _NS("Unicast")] )
-        {
+        if ([o_mode isEqualToString: _NS("Unicast")]) {
             int i_port = [o_net_udp_port intValue];
 
-            if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
+            if ([[o_net_udp_protocol_mat selectedCell] tag] == 0)
                 o_mrl_string = @"udp://";
             else
                 o_mrl_string = @"rtp://";
 
-            if( i_port != config_GetInt( p_intf, "server-port" ) )
-            {
+            if (i_port != config_GetInt(VLCIntf, "server-port")) {
                 o_mrl_string =
                     [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
             }
         }
-        else if( [o_mode isEqualToString: _NS("Multicast")] )
-        {
+        else if ([o_mode isEqualToString: _NS("Multicast")]) {
             NSString *o_addr = [o_net_udpm_addr stringValue];
             int i_port = [o_net_udpm_port intValue];
 
-            if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
+            if ([[o_net_udp_protocol_mat selectedCell] tag] == 0)
                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
             else
                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
 
-            if( i_port != config_GetInt( p_intf, "server-port" ) )
-            {
+            if (i_port != config_GetInt(VLCIntf, "server-port")) {
                 o_mrl_string =
                     [o_mrl_string stringByAppendingFormat: @":%i", i_port];
             }
         }
-    }
-    else
-    {
+    } else
         o_mrl_string = [o_net_http_url stringValue];
-    }
+
     [self setMRL: o_mrl_string];
 }
 
 - (IBAction)openNetUDPButtonAction:(id)sender
 {
-    if( sender == o_net_openUDP_btn )
-    {
+    if (sender == o_net_openUDP_btn) {
         [NSApp beginSheet: o_net_udp_panel
            modalForWindow: o_panel
             modalDelegate: self
@@ -1335,41 +1257,35 @@ static VLCOpen *_o_sharedMainInstance = nil;
               contextInfo: nil];
         [self openNetInfoChanged: nil];
     }
-    else if( sender == o_net_udp_cancel_btn )
-    {
+    else if (sender == o_net_udp_cancel_btn) {
         [o_net_udp_panel orderOut: sender];
         [NSApp endSheet: o_net_udp_panel];
     }
-    else if( sender == o_net_udp_ok_btn )
-    {
+    else if (sender == o_net_udp_ok_btn) {
         NSString *o_mrl_string = [NSString string];
-        if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")] )
-        {
+        if ([[[o_net_mode selectedCell] title] isEqualToString: _NS("Unicast")]) {
             int i_port = [o_net_udp_port intValue];
 
-            if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
+            if ([[o_net_udp_protocol_mat selectedCell] tag] == 0)
                 o_mrl_string = @"udp://";
             else
                 o_mrl_string = @"rtp://";
 
-            if( i_port != config_GetInt( p_intf, "server-port" ) )
-            {
+            if (i_port != config_GetInt(VLCIntf, "server-port")) {
                 o_mrl_string =
                 [o_mrl_string stringByAppendingFormat: @"@:%i", i_port];
             }
         }
-        else if( [[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")] )
-        {
+        else if ([[[o_net_mode selectedCell] title] isEqualToString: _NS("Multicast")]) {
             NSString *o_addr = [o_net_udpm_addr stringValue];
             int i_port = [o_net_udpm_port intValue];
 
-            if( [[o_net_udp_protocol_mat selectedCell] tag] == 0 )
+            if ([[o_net_udp_protocol_mat selectedCell] tag] == 0)
                 o_mrl_string = [NSString stringWithFormat: @"udp://@%@", o_addr];
             else
                 o_mrl_string = [NSString stringWithFormat: @"rtp://@%@", o_addr];
 
-            if( i_port != config_GetInt( p_intf, "server-port" ) )
-            {
+            if (i_port != config_GetInt(VLCIntf, "server-port")) {
                 o_mrl_string =
                 [o_mrl_string stringByAppendingFormat: @":%i", i_port];
             }
@@ -1388,15 +1304,12 @@ static VLCOpen *_o_sharedMainInstance = nil;
 {
     NSRect o_view_rect;
     o_view_rect = [theView frame];
-    [theView setFrame: NSMakeRect( 0, -10, o_view_rect.size.width, o_view_rect.size.height)];
+    [theView setFrame: NSMakeRect(0, -10, o_view_rect.size.width, o_view_rect.size.height)];
     [theView setAutoresizesSubviews: YES];
-    if (o_currentCaptureView)
-    {
+    if (o_currentCaptureView) {
         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] replaceSubview: o_currentCaptureView with: theView];
         [o_currentCaptureView release];
-    }
-    else
-    {
+    } else {
         [[[[o_tabview tabViewItemAtIndex: 3] view] animator] addSubview: theView];
     }
     o_currentCaptureView = theView;
@@ -1405,67 +1318,58 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (IBAction)openCaptureModeChanged:(id)sender
 {
-    if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"] )
-    {
-        if( [[[VLCMain sharedInstance] eyeTVController] eyeTVRunning] == YES )
-        {
-            if( [[[VLCMain sharedInstance] eyeTVController] deviceConnected] == YES )
-            {
+    intf_thread_t * p_intf = VLCIntf;
+
+    if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: @"EyeTV"]) {
+        if ([[[VLCMain sharedInstance] eyeTVController] eyeTVRunning] == YES) {
+            if ([[[VLCMain sharedInstance] eyeTVController] deviceConnected] == YES) {
                 [self showCaptureView: o_eyetv_running_view];
                 [self setupChannelInfo];
             }
             else
-            {
                 setEyeTVUnconnected;
-            }
         }
         else
             [self showCaptureView: o_eyetv_notLaunched_view];
         [self setMRL: @""];
     }
-    else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")] )
-    {
+    else if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Screen")]) {
         [self showCaptureView: o_screen_view];
         [self setMRL: @"screen://"];
-        [o_screen_height_fld setIntValue: config_GetInt( p_intf, "screen-height" )];
-        [o_screen_width_fld setIntValue: config_GetInt( p_intf, "screen-width" )];
-        [o_screen_fps_fld setFloatValue: config_GetFloat( p_intf, "screen-fps" )];
-        [o_screen_left_fld setIntValue: config_GetInt( p_intf, "screen-left" )];
-        [o_screen_top_fld setIntValue: config_GetInt( p_intf, "screen-top" )];
-        [o_screen_follow_mouse_ckb setIntValue: config_GetInt( p_intf, "screen-follow-mouse" )];
-
-        int screen_index = config_GetInt( p_intf, "screen-index" );
-        int display_id = config_GetInt( p_intf, "screen-display-id" );
+        [o_screen_height_fld setIntValue: config_GetInt(p_intf, "screen-height")];
+        [o_screen_width_fld setIntValue: config_GetInt(p_intf, "screen-width")];
+        [o_screen_fps_fld setFloatValue: config_GetFloat(p_intf, "screen-fps")];
+        [o_screen_left_fld setIntValue: config_GetInt(p_intf, "screen-left")];
+        [o_screen_top_fld setIntValue: config_GetInt(p_intf, "screen-top")];
+        [o_screen_follow_mouse_ckb setIntValue: config_GetInt(p_intf, "screen-follow-mouse")];
+
+        int screen_index = config_GetInt(p_intf, "screen-index");
+        int display_id = config_GetInt(p_intf, "screen-display-id");
         unsigned int i, displayCount = 0;
         CGLError returnedError;
         struct display_info_t *item;
         NSValue *v;
 
-        returnedError = CGGetOnlineDisplayList( 0, NULL, &displayCount );
-        if( !returnedError )
-        {
+        returnedError = CGGetOnlineDisplayList(0, NULL, &displayCount);
+        if (!returnedError) {
             CGDirectDisplayID *ids;
-            ids = ( CGDirectDisplayID * )malloc( displayCount * sizeof( CGDirectDisplayID ) );
-            returnedError = CGGetOnlineDisplayList( displayCount, ids, &displayCount );
-            if( !returnedError )
-            {
-                for( i = 0; i < [o_displayInfos count]; i ++ )
-                {
+            ids = (CGDirectDisplayID *)malloc(displayCount * sizeof(CGDirectDisplayID));
+            returnedError = CGGetOnlineDisplayList(displayCount, ids, &displayCount);
+            if (!returnedError) {
+                for (i = 0; i < [o_displayInfos count]; i ++) {
                     v = [o_displayInfos objectAtIndex:i];
-                    free( [v pointerValue] );
+                    free([v pointerValue]);
                 }
                 [o_displayInfos removeAllObjects];
                 [o_screen_screen_pop removeAllItems];
-                for( i = 0; i < displayCount; i ++ )
-                {
-                    item = ( struct display_info_t * )malloc( sizeof( struct display_info_t ) );
+                for (i = 0; i < displayCount; i ++) {
+                    item = (struct display_info_t *)malloc(sizeof(struct display_info_t));
                     item->id = ids[i];
-                    item->rect = CGDisplayBounds( item->id );
+                    item->rect = CGDisplayBounds(item->id);
                     [o_screen_screen_pop addItemWithTitle: [NSString stringWithFormat:@"Screen %d (%dx%d)", i + 1, (int)item->rect.size.width, (int)item->rect.size.height]];
                     v = [NSValue valueWithPointer:item];
                     [o_displayInfos addObject:v];
-                    if( i == 0 || display_id == item->id || screen_index - 1 == i )
-                    {
+                    if (i == 0 || display_id == item->id || screen_index - 1 == i) {
                         [o_screen_screen_pop selectItemAtIndex: i];
                         [o_screen_left_stp setMaxValue: item->rect.size.width];
                         [o_screen_top_stp setMaxValue: item->rect.size.height];
@@ -1474,11 +1378,10 @@ static VLCOpen *_o_sharedMainInstance = nil;
                     }
                 }
             }
-            free( ids );
+            free(ids);
         }
     }
-    else if( [[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")] )
-    {
+    else if ([[[o_capture_mode_pop selectedItem] title] isEqualToString: _NS("Input Devices")]) {
         [self showCaptureView: o_qtk_view];
         if ([o_capture_width_fld intValue] <= 0)
             [self qtkChanged:nil];
@@ -1489,7 +1392,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
         if ([o_qtk_video_ckb state] && qtk_currdevice_uid)
             [self setMRL:[NSString stringWithFormat:@"qtcapture://%@", qtk_currdevice_uid]];
-        else if([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
+        else if ([o_qtk_audio_ckb state] && qtkaudio_currdevice_uid)
             [self setMRL:[NSString stringWithFormat:@"qtsound://%@", qtkaudio_currdevice_uid]];
     }
 }
@@ -1497,33 +1400,27 @@ static VLCOpen *_o_sharedMainInstance = nil;
 - (void)screenFPSfieldChanged:(NSNotification *)o_notification
 {
     [o_screen_fps_stp setFloatValue: [o_screen_fps_fld floatValue]];
-    if( [[o_screen_fps_fld stringValue] isEqualToString: @""] )
+    if ([[o_screen_fps_fld stringValue] isEqualToString: @""])
         [o_screen_fps_fld setFloatValue: 1.0];
     [self setMRL: @"screen://"];
 }
 
 - (IBAction)eyetvSwitchChannel:(id)sender
 {
-    if( sender == o_eyetv_nextProgram_btn )
-    {
+    if (sender == o_eyetv_nextProgram_btn) {
         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: YES];
         [o_eyetv_channels_pop selectItemWithTag:chanNum];
         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
-    }
-    else if( sender == o_eyetv_previousProgram_btn )
-    {
+    } else if (sender == o_eyetv_previousProgram_btn) {
         int chanNum = [[[VLCMain sharedInstance] eyeTVController] switchChannelUp: NO];
         [o_eyetv_channels_pop selectItemWithTag:chanNum];
         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
-    }
-    else if( sender == o_eyetv_channels_pop )
-    {
+    } else if (sender == o_eyetv_channels_pop) {
         int chanNum = [[sender selectedItem] tag];
         [[[VLCMain sharedInstance] eyeTVController] setChannel:chanNum];
         [self setMRL: [NSString stringWithFormat:@"eyetv:// :eyetv-channel=%d", chanNum]];
-    }
-    else
-        msg_Err( VLCIntf, "eyetvSwitchChannel sent by unknown object" );
+    } else
+        msg_Err(VLCIntf, "eyetvSwitchChannel sent by unknown object");
 }
 
 - (IBAction)eyetvLaunch:(id)sender
@@ -1538,29 +1435,22 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (void)eyetvChanged:(NSNotification *)o_notification
 {
-    if( [[o_notification name] isEqualToString: @"DeviceAdded"] )
-    {
-        msg_Dbg( VLCIntf, "eyetv device was added" );
+    if ([[o_notification name] isEqualToString: @"DeviceAdded"]) {
+        msg_Dbg(VLCIntf, "eyetv device was added");
         [self showCaptureView: o_eyetv_running_view];
         [self setupChannelInfo];
-    }
-    else if( [[o_notification name] isEqualToString: @"DeviceRemoved"] )
-    {
+    } else if ([[o_notification name] isEqualToString: @"DeviceRemoved"]) {
         /* leave the channel selection like that,
          * switch to our "no device" tab */
-        msg_Dbg( VLCIntf, "eyetv device was removed" );
+        msg_Dbg(VLCIntf, "eyetv device was removed");
         setEyeTVUnconnected;
-    }
-    else if( [[o_notification name] isEqualToString: @"PluginQuit"] )
-    {
+    } else if ([[o_notification name] isEqualToString: @"PluginQuit"]) {
         /* switch to the "launch eyetv" tab */
-        msg_Dbg( VLCIntf, "eyetv was terminated" );
+        msg_Dbg(VLCIntf, "eyetv was terminated");
         [self showCaptureView: o_eyetv_notLaunched_view];
-    }
-    else if( [[o_notification name] isEqualToString: @"PluginInit"] )
-    {
+    } else if ([[o_notification name] isEqualToString: @"PluginInit"]) {
         /* we got no device yet */
-        msg_Dbg( VLCIntf, "eyetv was launched, no device yet" );
+        msg_Dbg(VLCIntf, "eyetv was launched, no device yet");
         setEyeTVUnconnected;
     }
 }
@@ -1584,18 +1474,14 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [[[o_eyetv_channels_pop menu] addItemWithTitle: _NS("S-Video input")
                                                action: nil
                                         keyEquivalent: @""] setTag:x++];
-    if( channels )
-    {
+    if (channels) {
         NSString *channel;
         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
-        while( channel = [channels nextObject] )
-        {
+        while (channel = [channels nextObject])
             /* we have to add items this way, because we accept duplicates
              * additionally, we save a bit of time */
-            [[[o_eyetv_channels_pop menu] addItemWithTitle: channel
-                                                   action: nil
-                                            keyEquivalent: @""] setTag:++x];
-        }
+            [[[o_eyetv_channels_pop menu] addItemWithTitle: channel action: nil keyEquivalent: @""] setTag:++x];
+
         /* make Tuner the default */
         [o_eyetv_channels_pop selectItemWithTag:[[[VLCMain sharedInstance] eyeTVController] channel]];
     }
@@ -1610,16 +1496,13 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (IBAction)subsChanged:(id)sender
 {
-    if ([o_file_sub_ckbox state] == NSOnState)
-    {
+    if ([o_file_sub_ckbox state] == NSOnState) {
         [o_file_sub_btn_settings setEnabled:YES];
         if (o_sub_path) {
             [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
             [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
         }
-    }
-    else
-    {
+    } else {
         [o_file_sub_btn_settings setEnabled:NO];
         [o_file_subtitles_filename_lbl setStringValue: @""];
         [o_file_subtitles_icon_well setImage: NULL];
@@ -1650,8 +1533,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [o_open_panel setTitle: _NS("Open File")];
     [o_open_panel setPrompt: _NS("Open")];
 
-    if( [o_open_panel runModal] == NSOKButton )
-    {
+    if ([o_open_panel runModal] == NSOKButton) {
         o_sub_path = [[[o_open_panel URLs] objectAtIndex: 0] path];
         [o_sub_path retain];
         [o_file_subtitles_filename_lbl setStringValue: [[NSFileManager defaultManager] displayNameAtPath:o_sub_path]];
@@ -1659,9 +1541,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
         [o_file_sub_path_lbl setHidden: YES];
         [o_file_subtitles_icon_well setImage: [[NSWorkspace sharedWorkspace] iconForFile:o_sub_path]];
         [o_file_sub_icon_view setImage: [o_file_subtitles_icon_well image]];
-    }
-    else
-    {
+    } else {
         [o_file_sub_path_lbl setHidden: NO];
         [o_file_sub_path_fld setStringValue:@""];
         [o_file_subtitles_filename_lbl setStringValue:@""];
@@ -1699,7 +1579,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (IBAction)panelOk:(id)sender
 {
-    if( [[self MRL] length] )
+    if ([[self MRL] length])
         [NSApp stopModalWithCode: 1];
     else
         NSBeep();
@@ -1707,7 +1587,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (NSArray *)qtkvideoDevices
 {
-    if ( !qtkvideoDevices )
+    if (!qtkvideoDevices)
         [self qtkrefreshVideoDevices];
     return qtkvideoDevices;
 }
@@ -1720,7 +1600,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (NSArray *)qtkaudioDevices
 {
-    if ( !qtkaudioDevices )
+    if (!qtkaudioDevices)
         [self qtkrefreshAudioDevices];
     return qtkaudioDevices;
 }