/*****************************************************************************
* intf.m: MacOS X interface module
*****************************************************************************
- * Copyright (C) 2002-2008 the VideoLAN team
+ * Copyright (C) 2002-2009 the VideoLAN team
* $Id$
*
* Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
#include <stdlib.h> /* malloc(), free() */
#include <sys/param.h> /* for MAXPATHLEN */
#include <string.h>
+#include <vlc_common.h>
#include <vlc_keys.h>
+#include <vlc_dialog.h>
#include <unistd.h> /* execl() */
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
#import "intf.h"
#import "fspanel.h"
#import "vout.h"
#import "simple_prefs.h"
#import "vlm.h"
-#import <vlc_input.h>
-#import <vlc_interface.h>
#import <AddressBook/AddressBook.h>
/*****************************************************************************
p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
if( p_intf->p_sys == NULL )
- {
- return( 1 );
- }
+ return VLC_ENOMEM;
memset( p_intf->p_sys, 0, sizeof( *p_intf->p_sys ) );
p_intf->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
-// p_intf->p_sys->p_sub = msg_Subscribe( p_intf );
+ /* subscribe to LibVLCCore's messages */
+ p_intf->p_sys->p_sub = msg_Subscribe( p_intf->p_libvlc, MsgCallback, NULL );
p_intf->pf_run = Run;
p_intf->b_should_run_on_first_thread = true;
- return( 0 );
+ return VLC_SUCCESS;
}
/*****************************************************************************
{
intf_thread_t *p_intf = (intf_thread_t*) p_this;
-// msg_Unsubscribe( p_intf, p_intf->p_sys->p_sub );
-
[p_intf->p_sys->o_pool release];
free( p_intf->p_sys );
* see applicationWillTerminate: */
if(setjmp(jmpbuffer) == 0)
[NSApp run];
-
+
[o_pool release];
}
#pragma mark -
#pragma mark Variables Callback
+/*****************************************************************************
+ * MsgCallback: Callback triggered by the core once a new debug message is
+ * ready to be displayed. We store everything in a NSArray in our Cocoa part
+ * of this file, so we are forwarding everything through notifications.
+ *****************************************************************************/
+static void MsgCallback( msg_cb_data_t *data, msg_item_t *item, unsigned int i )
+{
+ int canc = vlc_savecancel();
+ NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
+
+ NSDictionary *o_dict = [NSDictionary dictionaryWithObjects:
+ [NSArray arrayWithObjects:
+ [NSString stringWithUTF8String: item->psz_module],
+ [NSString stringWithUTF8String: item->psz_msg],
+ [NSNumber numberWithInt: item->i_type], nil]
+ forKeys:
+ [NSArray arrayWithObjects: @"Module", @"Message", @"Type", nil]];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName: @"VLCCoreMessageReceived"
+ object: nil
+ userInfo: o_dict];
+
+ [o_pool release];
+ vlc_restorecancel( canc );
+}
+
+
/*****************************************************************************
* playlistChanged: Callback triggered by the intf-change playlist
* variable, to let the intf update the playlist.
vlc_value_t old_val, vlc_value_t new_val, void *param )
{
intf_thread_t * p_intf = VLCIntf;
- p_intf->p_sys->b_intf_update = true;
- p_intf->p_sys->b_playlist_update = true;
- p_intf->p_sys->b_playmode_update = true;
- p_intf->p_sys->b_current_title_update = true;
+ if( p_intf && p_intf->p_sys )
+ {
+ p_intf->p_sys->b_intf_update = true;
+ p_intf->p_sys->b_playlist_update = true;
+ p_intf->p_sys->b_playmode_update = true;
+ p_intf->p_sys->b_current_title_update = true;
+ }
return VLC_SUCCESS;
}
vlc_value_t old_val, vlc_value_t new_val, void *param )
{
intf_thread_t * p_intf = VLCIntf;
- p_intf->p_sys->b_intf_show = true;
+ if( p_intf && p_intf->p_sys )
+ p_intf->p_sys->b_intf_show = true;
return VLC_SUCCESS;
}
vlc_value_t old_val, vlc_value_t new_val, void *param )
{
intf_thread_t * p_intf = VLCIntf;
- p_intf->p_sys->b_fullscreen_update = true;
+ if( p_intf && p_intf->p_sys )
+ p_intf->p_sys->b_fullscreen_update = true;
return VLC_SUCCESS;
}
else
_o_sharedMainInstance = [super init];
+ o_msg_lock = [[NSLock alloc] init];
+ o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
+ /* subscribe to LibVLC's debug messages as early as possible (for us) */
+ [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(libvlcMessageReceived:) name: @"VLCCoreMessageReceived" object: nil];
+
o_about = [[VLAboutBox alloc] init];
o_prefs = nil;
o_open = [[VLCOpen alloc] init];
/* Check if we already did this once. Opening the other nibs calls it too, because VLCMain is the owner */
if( nib_main_loaded ) return;
+ /* check whether the user runs a valid version of OS X */
+ if( MACOS_VERSION < 10.5f )
+ {
+ NSAlert *ourAlert;
+ int i_returnValue;
+ NSString *o_blabla;
+ if( MACOS_VERSION == 10.4f )
+ o_blabla = _NS("VLC's last release for your OS is the 0.9 series." );
+ else if( MACOS_VERSION == 10.3f )
+ o_blabla = _NS("VLC's last release for your OS is VLC 0.8.6i, which is prone to known security issues." );
+ else // 10.2 and 10.1, still 3% of the OS X market share
+ o_blabla = _NS("VLC's last release for your OS is VLC 0.7.2, which is highly out of date and prone to " \
+ "known security issues. We recommend you to update your Mac to a modern version of Mac OS X.");
+ ourAlert = [NSAlert alertWithMessageText: _NS("Your version of Mac OS X is no longer supported")
+ defaultButton: _NS("Quit")
+ alternateButton: NULL
+ otherButton: NULL
+ informativeTextWithFormat: _NS("VLC media player %s requires Mac OS X 10.5 or higher.\n\n%@"), VLC_Version(), o_blabla];
+ [ourAlert setAlertStyle: NSCriticalAlertStyle];
+ i_returnValue = [ourAlert runModal];
+ [NSApp performSelectorOnMainThread: @selector(terminate:) withObject:nil waitUntilDone:NO];
+ return;
+ }
+
[self initStrings];
[o_window setExcludedFromWindowsMenu: YES];
- (void)applicationWillFinishLaunching:(NSNotification *)o_notification
{
- o_msg_lock = [[NSLock alloc] init];
- o_msg_arr = [[NSMutableArray arrayWithCapacity: 200] retain];
-
/* FIXME: don't poll */
interfaceTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.5
target: self selector: @selector(manageIntf:)
[o_controls setupVarMenuItem: o_mi_add_intf target: (vlc_object_t *)p_intf
var: "intf-add" selector: @selector(toggleVar:)];
- /* check whether the user runs a valid version of OSX; alert is auto-released */
- if( MACOS_VERSION < 10.4f )
- {
- NSAlert *ourAlert;
- int i_returnValue;
- ourAlert = [NSAlert alertWithMessageText: _NS("Your version of Mac OS X is not supported")
- defaultButton: _NS("Quit")
- alternateButton: NULL
- otherButton: NULL
- informativeTextWithFormat: _NS("VLC media player requires Mac OS X 10.4 or higher.")];
- [ourAlert setAlertStyle: NSCriticalAlertStyle];
- i_returnValue = [ourAlert runModal];
- [NSApp terminate: self];
- }
-
vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
}
/* messages panel */
[o_msgs_panel setTitle: _NS("Messages")];
- [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog...")];
+ [o_msgs_crashlog_btn setTitle: _NS("Open CrashLog...")];
+ [o_msgs_save_btn setTitle: _NS("Save this Log...")];
/* main menu */
[o_mi_about setTitle: [_NS("About VLC media player") \
[o_mu_chapter setTitle: _NS("Chapter")];
[o_mu_audio setTitle: _NS("Audio")];
- [o_mi_vol_up setTitle: _NS("Volume Up")];
- [o_mi_vol_down setTitle: _NS("Volume Down")];
+ [o_mi_vol_up setTitle: _NS("Increase Volume")];
+ [o_mi_vol_down setTitle: _NS("Decrease Volume")];
[o_mi_mute setTitle: _NS("Mute")];
[o_mi_audiotrack setTitle: _NS("Audio Track")];
[o_mu_audiotrack setTitle: _NS("Audio Track")];
[o_mu_screen setTitle: _NS("Fullscreen Video Device")];
[o_mi_subtitle setTitle: _NS("Subtitles Track")];
[o_mu_subtitle setTitle: _NS("Subtitles Track")];
+ [o_mi_addSub setTitle: _NS("Open File...")];
[o_mi_deinterlace setTitle: _NS("Deinterlace")];
[o_mu_deinterlace setTitle: _NS("Deinterlace")];
[o_mi_ffmpeg_pp setTitle: _NS("Post processing")];
[o_img_pause release];
[o_img_play release];
+ /* unsubscribe from libvlc's debug messages */
+ msg_Unsubscribe( p_intf->p_sys->p_sub );
+
[o_msg_arr removeAllObjects];
[o_msg_arr release];
id self;
};
-static void * manage_cleanup( void * args )
+static void manage_cleanup( void * args )
{
struct manage_cleanup_stack * manage_cleanup_stack = args;
intf_thread_t * p_intf = manage_cleanup_stack->p_intf;
id self = manage_cleanup_stack->self;
playlist_t * p_playlist = manage_cleanup_stack->p_playlist;
- var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
+ var_AddCallback( p_playlist, "item-current", PlaylistChanged, self );
var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
- var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
- var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
+ var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, self );
+ var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, self );
pl_Release( p_intf );
if( p_input ) vlc_object_release( p_input );
- return NULL;
}
- (void)manage
p_playlist = pl_Hold( p_intf );
- var_AddCallback( p_playlist, "playlist-current", PlaylistChanged, self );
+ var_AddCallback( p_playlist, "item-current", PlaylistChanged, self );
var_AddCallback( p_playlist, "intf-change", PlaylistChanged, self );
var_AddCallback( p_playlist, "item-change", PlaylistChanged, self );
- var_AddCallback( p_playlist, "item-append", PlaylistChanged, self );
- var_AddCallback( p_playlist, "item-deleted", PlaylistChanged, self );
+ var_AddCallback( p_playlist, "playlist-item-append", PlaylistChanged, self );
+ var_AddCallback( p_playlist, "playlist-item-deleted", PlaylistChanged, self );
struct manage_cleanup_stack stack = { p_intf, &p_input, p_playlist, self };
pthread_cleanup_push(manage_cleanup, &stack);
while( true )
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
- vlc_mutex_lock( &p_intf->change_lock );
if( !p_input )
{
/* Manage volume status */
[self manageVolumeSlider];
- vlc_mutex_unlock( &p_intf->change_lock );
-
msleep( INTF_IDLE_SLEEP );
[pool release];
bool b_chapters = false;
playlist_t * p_playlist = pl_Hold( p_intf );
- /* TODO: fix i_size use */
+
+ /* TODO: fix i_size use */
b_plmul = p_playlist->items.i_size > 1;
p_input = playlist_CurrentInput( p_playlist );
/* update our info-panel to reflect the new item, if we don't show
* the playlist or the selection is empty */
if( [self isPlaylistCollapsed] == YES )
+ {
+ PL_LOCK;
[[self getInfo] updatePanelWithItem: playlist_CurrentPlayingItem( p_playlist )->p_input];
+ PL_UNLOCK;
+ }
/* seekable streams */
b_seekable = var_GetBool( p_input, "can-seek" );
if( p_intf->p_sys->b_intf_show )
{
- [o_window makeKeyAndOrderFront: self];
+ if( [[o_controls voutView] isFullscreen] && config_GetInt( VLCIntf, "macosx-fspanel" ) )
+ [[o_controls getFSPanel] fadeIn];
+ else
+ [o_window makeKeyAndOrderFront: self];
p_intf->p_sys->b_intf_show = false;
}
var_Get( p_input, "time", &time );
- o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
+ mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
+ if( b_time_remaining && dur != -1 )
+ {
+ o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000))];
+ }
+ else
+ o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
[o_timefield setStringValue: o_time];
[[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
}
end:
- [self updateMessageArray];
+ [self updateMessageDisplay];
if( ((i_end_scroll != -1) && (mdate() > i_end_scroll)) || !p_input )
[self resetScrollField];
[o_controls setupVarMenuItem: o_mi_subtitle target: (vlc_object_t *)p_input
var: "spu-es" selector: @selector(toggleVar:)];
- aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
- FIND_ANYWHERE );
+ /* special case for "Open File" inside the subtitles menu item */
+ if( [o_mi_videotrack isEnabled] == YES )
+ [o_mi_subtitle setEnabled: YES];
+
+ aout_instance_t * p_aout = input_GetAout( p_input );
if( p_aout != NULL )
{
[o_controls setupVarMenuItem: o_mi_channels target: (vlc_object_t *)p_aout
vlc_object_release( (vlc_object_t *)p_aout );
}
- vout_thread_t * p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
- FIND_ANYWHERE );
+ vout_thread_t * p_vout = input_GetVout( p_input );
if( p_vout != NULL )
{
[o_controls setupVarMenuItem: o_mi_deinterlace target: (vlc_object_t *)p_vout
var: "deinterlace" selector: @selector(toggleVar:)];
+#if 0
+/* FIXME Post processing. */
p_dec_obj = (vlc_object_t *)vlc_object_find(
(vlc_object_t *)p_vout,
VLC_OBJECT_DECODER,
vlc_object_release(p_dec_obj);
}
+#endif
vlc_object_release( (vlc_object_t *)p_vout );
}
vlc_object_release( p_input );
if( p_input && vlc_object_alive (p_input) )
{
NSString *o_temp;
+ PL_LOCK;
playlist_item_t * p_item = playlist_CurrentPlayingItem( p_playlist );
if( input_item_GetNowPlaying( p_item->p_input ) )
o_temp = [NSString stringWithUTF8String:input_item_GetNowPlaying( p_item->p_input )];
else
o_temp = [NSString stringWithUTF8String:p_item->p_input->psz_name];
+ PL_UNLOCK;
[self setScrollField: o_temp stopAfter:-1];
[[[self getControls] getFSPanel] setStreamTitle: o_temp];
vlc_object_release( p_input );
[o_mi_screen setEnabled: b_enabled];
[o_mi_aspect_ratio setEnabled: b_enabled];
[o_mi_crop setEnabled: b_enabled];
+ [o_mi_teletext setEnabled: b_enabled];
}
- (IBAction)timesliderUpdate:(id)sender
var_Get( p_input, "time", &time );
- o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
+ mtime_t dur = input_item_GetDuration( input_GetItem( p_input ) );
+ if( b_time_remaining && dur != -1 )
+ {
+ o_time = [NSString stringWithFormat: @"-%s", secstotimestr( psz_time, ((dur - time.i_time) / 1000000) )];
+ }
+ else
+ o_time = [NSString stringWithUTF8String: secstotimestr( psz_time, (time.i_time / 1000000) )];
+
[o_timefield setStringValue: o_time];
[[[self getControls] getFSPanel] setStreamPos: f_updated andTime: o_time];
[o_embedded_window setTime: o_time position: f_updated];
pl_Release( p_intf );
}
+- (IBAction)timeFieldWasClicked:(id)sender
+{
+ b_time_remaining = !b_time_remaining;
+}
+
+
#pragma mark -
#pragma mark Recent Items
[o_update showUpdateWindow];
#else
msg_Err( VLCIntf, "Update checker wasn't enabled in this build" );
- intf_UserFatal( VLCIntf, false, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
+ dialog_Fatal( VLCIntf, _("Update check failed"), _("Checking for updates was not enabled in this build.") );
#endif
}
- (void)windowDidBecomeKey:(NSNotification *)o_notification
{
if( [o_notification object] == o_msgs_panel )
+ [self updateMessageDisplay];
+}
+
+- (void)updateMessageDisplay
+{
+ if( [o_msgs_panel isVisible] && b_msg_arr_changed )
{
id o_msg;
NSEnumerator * o_enum;
[o_messages insertText: o_msg];
}
+ b_msg_arr_changed = NO;
[o_msg_lock unlock];
}
}
-- (void)updateMessageArray
+- (void)libvlcMessageReceived: (NSNotification *)o_notification
{
- int i_start, i_stop;
-#if 0
- vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
- i_stop = *p_intf->p_sys->p_sub->pi_stop;
- vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
+ NSColor *o_white = [NSColor whiteColor];
+ NSColor *o_red = [NSColor redColor];
+ NSColor *o_yellow = [NSColor yellowColor];
+ NSColor *o_gray = [NSColor grayColor];
- if( p_intf->p_sys->p_sub->i_start != i_stop )
- {
- NSColor *o_white = [NSColor whiteColor];
- NSColor *o_red = [NSColor redColor];
- NSColor *o_yellow = [NSColor yellowColor];
- NSColor *o_gray = [NSColor grayColor];
+ NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
+ static const char * ppsz_type[4] = { ": ", " error: ",
+ " warning: ", " debug: " };
- NSColor * pp_color[4] = { o_white, o_red, o_yellow, o_gray };
- static const char * ppsz_type[4] = { ": ", " error: ",
- " warning: ", " debug: " };
+ NSString *o_msg;
+ NSDictionary *o_attr;
+ NSAttributedString *o_msg_color;
- for( i_start = p_intf->p_sys->p_sub->i_start;
- i_start != i_stop;
- i_start = (i_start+1) % VLC_MSG_QSIZE )
- {
- NSString *o_msg;
- NSDictionary *o_attr;
- NSAttributedString *o_msg_color;
+ int i_type = [[[o_notification userInfo] objectForKey: @"Type"] intValue];
- int i_type = p_intf->p_sys->p_sub->p_msg[i_start].i_type;
+ [o_msg_lock lock];
- [o_msg_lock lock];
+ if( [o_msg_arr count] + 2 > 400 )
+ {
+ unsigned rid[] = { 0, 1 };
+ [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
+ numIndices: sizeof(rid)/sizeof(rid[0])];
+ }
- if( [o_msg_arr count] + 2 > 400 )
- {
- unsigned rid[] = { 0, 1 };
- [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
- numIndices: sizeof(rid)/sizeof(rid[0])];
- }
+ o_attr = [NSDictionary dictionaryWithObject: o_gray
+ forKey: NSForegroundColorAttributeName];
+ o_msg = [NSString stringWithFormat: @"%@%s",
+ [[o_notification userInfo] objectForKey: @"Module"],
+ ppsz_type[i_type]];
+ o_msg_color = [[NSAttributedString alloc]
+ initWithString: o_msg attributes: o_attr];
+ [o_msg_arr addObject: [o_msg_color autorelease]];
- o_attr = [NSDictionary dictionaryWithObject: o_gray
- forKey: NSForegroundColorAttributeName];
- o_msg = [NSString stringWithFormat: @"%s%s",
- p_intf->p_sys->p_sub->p_msg[i_start].psz_module,
- ppsz_type[i_type]];
- o_msg_color = [[NSAttributedString alloc]
- initWithString: o_msg attributes: o_attr];
- [o_msg_arr addObject: [o_msg_color autorelease]];
-
- o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
- forKey: NSForegroundColorAttributeName];
- o_msg = [[NSString stringWithUTF8String: p_intf->p_sys->p_sub->p_msg[i_start].psz_msg] stringByAppendingString: @"\n"];
- o_msg_color = [[NSAttributedString alloc]
- initWithString: o_msg attributes: o_attr];
- [o_msg_arr addObject: [o_msg_color autorelease]];
-
- [o_msg_lock unlock];
- }
+ o_attr = [NSDictionary dictionaryWithObject: pp_color[i_type]
+ forKey: NSForegroundColorAttributeName];
+ o_msg = [[[o_notification userInfo] objectForKey: @"Message"] stringByAppendingString: @"\n"];
+ o_msg_color = [[NSAttributedString alloc]
+ initWithString: o_msg attributes: o_attr];
+ [o_msg_arr addObject: [o_msg_color autorelease]];
+
+ b_msg_arr_changed = YES;
+ [o_msg_lock unlock];
+}
+
+- (IBAction)saveDebugLog:(id)sender
+{
+ NSOpenPanel * saveFolderPanel = [[NSSavePanel alloc] init];
+
+ [saveFolderPanel setCanChooseDirectories: NO];
+ [saveFolderPanel setCanChooseFiles: YES];
+ [saveFolderPanel setCanSelectHiddenExtension: NO];
+ [saveFolderPanel setCanCreateDirectories: YES];
+ [saveFolderPanel setRequiredFileType: @"rtfd"];
+ [saveFolderPanel beginSheetForDirectory:nil file: [NSString stringWithFormat: _NS("VLC Debug Log (%s).rtfd"), VLC_Version()] modalForWindow: o_msgs_panel modalDelegate:self didEndSelector:@selector(saveDebugLogAsRTF:returnCode:contextInfo:) contextInfo:nil];
+}
- vlc_mutex_lock( p_intf->p_sys->p_sub->p_lock );
- p_intf->p_sys->p_sub->i_start = i_start;
- vlc_mutex_unlock( p_intf->p_sys->p_sub->p_lock );
+- (void)saveDebugLogAsRTF: (NSSavePanel *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
+{
+ BOOL b_returned;
+ if( returnCode == NSOKButton )
+ {
+ b_returned = [o_messages writeRTFDToFile: [sheet filename] atomically: YES];
+ if(! b_returned )
+ msg_Warn( p_intf, "Error while saving the debug log" );
}
-#endif
}
#pragma mark -