* intf.m: MacOS X interface plugin
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: intf.m,v 1.2 2002/08/12 09:34:15 sam Exp $
+ * $Id: intf.m,v 1.10 2002/12/14 19:34:06 gbazin Exp $
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
* Christophe Massiot <massiot@via.ecp.fr>
#include <sys/param.h> /* for MAXPATHLEN */
#include <string.h>
-#include <vlc/vlc.h>
-#include <vlc/intf.h>
-#include <vlc/vout.h>
-
-#include <Cocoa/Cocoa.h>
#include <QuickTime/QuickTime.h>
#include "intf.h"
#include "vout.h"
+#include "prefs.h"
#include "playlist.h"
+#include "asystm.h"
/*****************************************************************************
* Local prototypes.
*****************************************************************************/
@implementation VLCMain
+- (id)init
+{
+ self = [super init];
+
+ if( self != nil )
+ {
+ o_prefs = nil;
+ }
+
+ return( self );
+}
+
- (void)awakeFromNib
{
NSString * pTitle = [NSString
[o_msgs_btn_ok setTitle: _NS("Close")];
[o_mi_about setTitle: _NS("About vlc")];
+ [o_mi_prefs setTitle: _NS("Preferences")];
[o_mi_hide setTitle: _NS("Hide vlc")];
[o_mi_hide_others setTitle: _NS("Hide Others")];
[o_mi_show_all setTitle: _NS("Show All")];
[o_mi_quit setTitle: _NS("Quit vlc")];
[o_mu_file setTitle: _NS("File")];
- [o_mi_open_file setTitle: _NS("Open File")];
- [o_mi_open_disc setTitle: _NS("Open Disc")];
- [o_mi_open_net setTitle: _NS("Open Network")];
- [o_mi_open_quickly setTitle: _NS("Open Quickly...")];
+ [o_mi_open_file setTitle: _NS("Open File...")];
+ [o_mi_open_generic setTitle: _NS("Open Generic...")];
+ [o_mi_open_disc setTitle: _NS("Open Disc...")];
+ [o_mi_open_net setTitle: _NS("Open Network...")];
[o_mi_open_recent setTitle: _NS("Open Recent")];
[o_mi_open_recent_cm setTitle: _NS("Clear Menu")];
[o_mi_previous setTitle: _NS("Prev")];
[o_mi_next setTitle: _NS("Next")];
[o_mi_loop setTitle: _NS("Loop")];
- [o_mi_vol_up setTitle: _NS("Volume Up")];
- [o_mi_vol_down setTitle: _NS("Volume Down")];
+ [o_mi_vol_up setTitle: _NS("Louder")];
+ [o_mi_vol_down setTitle: _NS("Softer")];
[o_mi_mute setTitle: _NS("Mute")];
+ [o_mi_channels setTitle: _NS("Channels")];
[o_mi_fullscreen setTitle: _NS("Fullscreen")];
+ [o_mi_screen setTitle: _NS("Screen")];
[o_mi_deinterlace setTitle: _NS("Deinterlace")];
[o_mi_program setTitle: _NS("Program")];
[o_mi_title setTitle: _NS("Title")];
[[NSRunLoop currentRunLoop]
addPort: p_intf->p_sys->o_sendport
forMode: NSDefaultRunLoopMode];
+
+ // Since we need the sound menu now, it's a good time to create the sound system class
+ asystm=[[MacOSXAudioSystem alloc] initWithGUI:self];
+ [asystm retain];
+
+}
+
+- (void)noopAction:(id)sender {
+ // nothing
}
- (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
p_intf->p_sys->p_input = NULL;
}
- if( p_intf->p_sys->p_input )
+ if( p_intf->p_sys->p_input != NULL )
{
- input_thread_t *p_input = p_intf->p_sys->p_input;
+ vlc_bool_t b_need_menus = 0;
+ input_thread_t * p_input = p_intf->p_sys->p_input;
+ aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
+ FIND_ANYWHERE );
+ vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
+ FIND_ANYWHERE );
vlc_mutex_lock( &p_input->stream.stream_lock );
if( p_input->stream.b_changed )
{
[self manageMode];
- [self setupMenus];
+ b_need_menus = 1;
p_intf->p_sys->b_playing = 1;
}
p_input->stream.p_selected_area->i_part )
{
p_intf->p_sys->b_chapter_update = 1;
- [self setupMenus];
+ b_need_menus = 1;
}
}
+ if ( p_aout != NULL )
+ {
+ vlc_value_t val;
+ if ( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
+ >= 0 && val.b_bool )
+ {
+ p_intf->p_sys->b_aout_update = 1;
+ b_need_menus = 1;
+ }
+ vlc_object_release( (vlc_object_t *)p_aout );
+ }
+
+ if ( p_vout != NULL )
+ {
+ vlc_value_t val;
+ if ( var_Get( (vlc_object_t *)p_vout, "intf-change", &val )
+ >= 0 && val.b_bool )
+ {
+ p_intf->p_sys->b_vout_update = 1;
+ b_need_menus = 1;
+ }
+ vlc_object_release( (vlc_object_t *)p_vout );
+ }
+
+ if ( b_need_menus )
+ [self setupMenus];
+
vlc_mutex_unlock( &p_input->stream.stream_lock );
}
else if( p_intf->p_sys->b_playing && !p_intf->b_die )
{
vlc_object_detach( p_vout );
vlc_object_release( p_vout );
- vout_DestroyThread( p_vout );
+ vout_Destroy( p_vout );
+ }
+
+ if( o_prefs != nil )
+ {
+ [o_prefs release];
+ o_prefs = nil;
}
[NSApp stop: nil];
context: [NSGraphicsContext currentContext] eventNumber: 1
clickCount: 1 pressure: 0.0];
[NSApp postEvent: pEvent atStart: YES];
+
+ [asystm release];
}
- (void)manageMode
vlc_bool_t b_control = 0;
intf_thread_t * p_intf = [NSApp getIntf];
- if( p_intf->p_sys->p_input )
+ if( p_intf->p_sys->p_input != NULL )
{
/* control buttons for free pace streams */
b_control = p_intf->p_sys->p_input->stream.b_pace_control;
[o_mi_chapter setEnabled: FALSE];
[o_mi_language setEnabled: FALSE];
[o_mi_subtitle setEnabled: FALSE];
+ [o_mi_channels setEnabled: FALSE];
+ [o_mi_screen setEnabled: FALSE];
}
}
p_intf->p_sys->b_spu_update = 0;
}
+ if ( p_intf->p_sys->b_aout_update )
+ {
+ aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
+ FIND_ANYWHERE );
+
+ if ( p_aout != NULL )
+ {
+ vlc_value_t val;
+ val.b_bool = 0;
+
+ var_Set( (vlc_object_t *)p_aout, "intf-change", val );
+
+ [self setupVarMenu: o_mi_channels target: (vlc_object_t *)p_aout
+ var: "audio-channels" selector: @selector(toggleVar:)];
+
+ vlc_object_release( (vlc_object_t *)p_aout );
+ }
+
+ p_intf->p_sys->b_aout_update = 0;
+ }
+
+ if ( p_intf->p_sys->b_vout_update )
+ {
+ vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
+ FIND_ANYWHERE );
+
+ if ( p_vout != NULL )
+ {
+ vlc_value_t val;
+ val.b_bool = 0;
+
+ var_Set( (vlc_object_t *)p_vout, "intf-change", val );
+
+ [self setupVarMenu: o_mi_screen target: (vlc_object_t *)p_vout
+ var: "video-device" selector: @selector(toggleVar:)];
+
+ vlc_object_release( (vlc_object_t *)p_vout );
+ }
+
+ p_intf->p_sys->b_vout_update = 0;
+ }
+
vlc_mutex_lock( &p_input->stream.stream_lock );
#undef p_input
[o_menu removeItemAtIndex: 0];
}
+ /* make sensitive : we can't change it after we build the menu, and
+ * before, we don't yet how many items we will have. So make it
+ * always sensitive. --Meuuh */
+ [o_mi setEnabled: TRUE];
+
vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
#define ES p_intf->p_sys->p_input->stream.pp_es[i]
#undef ES
vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
+}
+
+- (void)setupVarMenu:(NSMenuItem *)o_mi
+ target:(vlc_object_t *)p_object
+ var:(const char *)psz_variable
+ selector:(SEL)pf_callback
+{
+ int i, i_nb_items;
+ NSMenu * o_menu = [o_mi submenu];
+ vlc_value_t val;
+ char * psz_value;
+
+ /* remove previous items */
+ i_nb_items = [o_menu numberOfItems];
+ for( i = 0; i < i_nb_items; i++ )
+ {
+ [o_menu removeItemAtIndex: 0];
+ }
+
+ if ( var_Get( p_object, psz_variable, &val ) < 0 )
+ {
+ return;
+ }
+ psz_value = val.psz_string;
+
+ if ( var_Change( p_object, psz_variable,
+ VLC_VAR_GETLIST, &val ) < 0 )
+ {
+ free( psz_value );
+ return;
+ }
/* make (un)sensitive */
- [o_mi setEnabled:
- [o_menu numberOfItems] ? TRUE : FALSE];
+ [o_mi setEnabled: (val.p_list->i_count > 0)];
+
+ for ( i = 0; i < val.p_list->i_count; i++ )
+ {
+ NSMenuItem * o_lmi;
+ NSString * o_title;
+
+ o_title = [NSString stringWithCString: val.p_list->p_values[i].psz_string];
+ o_lmi = [o_menu addItemWithTitle: o_title
+ action: pf_callback keyEquivalent: @""];
+ /* FIXME: this isn't 64-bit clean ! */
+ [o_lmi setTag: (int)psz_variable];
+ [o_lmi setRepresentedObject:
+ [NSValue valueWithPointer: p_object]];
+ [o_lmi setTarget: o_controls];
+
+ if ( !strcmp( psz_value, val.p_list->p_values[i].psz_string ) )
+ [o_lmi setState: NSOnState];
+ }
+
+ var_Change( p_object, psz_variable, VLC_VAR_FREELIST,
+ &val );
+
+ free( psz_value );
}
- (IBAction)clearRecentItems:(id)sender
[self application: nil openFile: [sender title]];
}
+- (IBAction)viewPreferences:(id)sender
+{
+ if( o_prefs == nil )
+ {
+ o_prefs = [[VLCPrefs alloc] init];
+ }
+
+ [o_prefs createPrefPanel: @"main"];
+}
+
+- (id)getMIDevice
+{
+ return o_mi_device;
+}
+
@end
@implementation VLCMain (NSMenuValidation)
- (void)handlePortMessage:(NSPortMessage *)o_msg
{
- NSData * o_req;
- vout_req_t * p_req;
-
- o_req = [[o_msg components] lastObject];
- p_req = *((vout_req_t **)[o_req bytes]);
-
- [p_req->o_lock lock];
-
- if( p_req->i_type == VOUT_REQ_CREATE_WINDOW )
- {
- VLCView * o_view;
-
- p_req->p_vout->p_sys->o_window = [VLCWindow alloc];
- [p_req->p_vout->p_sys->o_window setVout: p_req->p_vout];
- [p_req->p_vout->p_sys->o_window setReleasedWhenClosed: YES];
-
- if( p_req->p_vout->b_fullscreen )
- {
- [p_req->p_vout->p_sys->o_window
- initWithContentRect: [[NSScreen mainScreen] frame]
- styleMask: NSBorderlessWindowMask
- backing: NSBackingStoreBuffered
- defer: NO screen: [NSScreen mainScreen]];
-
- [p_req->p_vout->p_sys->o_window
- setLevel: NSModalPanelWindowLevel];
- }
- else
- {
- unsigned int i_stylemask = NSTitledWindowMask |
- NSMiniaturizableWindowMask |
- NSResizableWindowMask;
-
- [p_req->p_vout->p_sys->o_window
- initWithContentRect: p_req->p_vout->p_sys->s_rect
- styleMask: i_stylemask
- backing: NSBackingStoreBuffered
- defer: NO screen: [NSScreen mainScreen]];
-
- if( !p_req->p_vout->p_sys->b_pos_saved )
- {
- [p_req->p_vout->p_sys->o_window center];
- }
- }
-
- o_view = [[VLCView alloc] init];
- [o_view setVout: p_req->p_vout];
- [o_view setMenu: o_mu_controls];
- [p_req->p_vout->p_sys->o_window setContentView: o_view];
- [o_view autorelease];
-
- [o_view lockFocus];
- p_req->p_vout->p_sys->p_qdport = [o_view qdPort];
- [o_view unlockFocus];
-
- [p_req->p_vout->p_sys->o_window setTitle: [NSString
- stringWithCString: VOUT_TITLE " (QuickTime)"]];
- [p_req->p_vout->p_sys->o_window setAcceptsMouseMovedEvents: YES];
- [p_req->p_vout->p_sys->o_window makeKeyAndOrderFront: nil];
-
- p_req->i_result = 1;
- }
- else if( p_req->i_type == VOUT_REQ_DESTROY_WINDOW )
- {
- if( !p_req->p_vout->b_fullscreen )
- {
- NSRect s_rect;
-
- s_rect = [[p_req->p_vout->p_sys->o_window contentView] frame];
- p_req->p_vout->p_sys->s_rect.size = s_rect.size;
-
- s_rect = [p_req->p_vout->p_sys->o_window frame];
- p_req->p_vout->p_sys->s_rect.origin = s_rect.origin;
-
- p_req->p_vout->p_sys->b_pos_saved = 1;
- }
-
- p_req->p_vout->p_sys->p_qdport = nil;
- [p_req->p_vout->p_sys->o_window close];
- p_req->p_vout->p_sys->o_window = nil;
-
- p_req->i_result = 1;
- }
-
- [p_req->o_lock unlockWithCondition: 1];
+ NSData * o_data;
+ NSValue * o_value;
+ NSInvocation * o_inv;
+ vout_thread_t * p_vout;
+
+ o_data = [[o_msg components] lastObject];
+ o_inv = *((NSInvocation **)[o_data bytes]);
+ [o_inv getArgument: &o_value atIndex: 2];
+ p_vout = (vout_thread_t *)[o_value pointerValue];
+
+ [p_vout->p_sys->o_lock lock];
+ [o_inv invoke];
+ [p_vout->p_sys->o_lock unlockWithCondition: 1];
}
@end
-