]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/intf.m
Attempt at fixing the soundstick issue (unconfirmed).
[vlc] / modules / gui / macosx / intf.m
index df688e9620e95e791f290fa53911448d8047cfff..a2239b76310cf2f6c10db6aa20dfe5f51f410388 100644 (file)
@@ -2,7 +2,7 @@
  * intf.m: MacOS X interface plugin
  *****************************************************************************
  * Copyright (C) 2002-2003 VideoLAN
- * $Id: intf.m,v 1.44 2003/02/02 23:11:17 massiot Exp $
+ * $Id: intf.m,v 1.68 2003/03/13 16:09:21 hartman Exp $
  *
  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
  *          Christophe Massiot <massiot@via.ecp.fr>
@@ -34,6 +34,7 @@
 #include "vout.h"
 #include "prefs.h"
 #include "playlist.h"
+#include "info.h"
 
 /*****************************************************************************
  * Local prototypes.
@@ -154,6 +155,37 @@ static void Run( intf_thread_t *p_intf )
     return( o_str );
 }
 
+- (char *)delocalizeString:(NSString *)id
+{
+    NSData * o_data = [id dataUsingEncoding: i_encoding
+                          allowLossyConversion: NO];
+    char * psz_string;
+
+    if ( o_data == nil )
+    {
+        o_data = [id dataUsingEncoding: i_encoding
+                     allowLossyConversion: YES];
+        psz_string = malloc( [o_data length] + 1 ); 
+        [o_data getBytes: psz_string];
+        psz_string[ [o_data length] ] = '\0';
+        msg_Err( p_intf, "cannot convert to wanted encoding: %s",
+                 psz_string );
+    }
+    else
+    {
+        psz_string = malloc( [o_data length] + 1 ); 
+        [o_data getBytes: psz_string];
+        psz_string[ [o_data length] ] = '\0';
+    }
+
+    return psz_string;
+}
+
+- (NSStringEncoding)getEncoding
+{
+    return i_encoding;
+}
+
 - (void)setIntf:(intf_thread_t *)_p_intf
 {
     p_intf = _p_intf;
@@ -261,17 +293,17 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
     [o_msgs_panel setDelegate: self];
     [o_msgs_panel setTitle: _NS("Messages")];
     [o_msgs_panel setExcludedFromWindowsMenu: TRUE];
-    [o_msgs_btn_ok setTitle: _NS("Close")];
+    [o_msgs_btn_crashlog setTitle: _NS("Open CrashLog")];
 
     /* main menu */
-    [o_mi_about setTitle: _NS("About VLC Media Player")];
-    [o_mi_prefs setTitle: _NS("Preferences")];
+    [o_mi_about setTitle: _NS("About VLC media player")];
+    [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_mu_file setTitle: _ANS("1:File")];
     [o_mi_open_generic setTitle: _NS("Open...")];
     [o_mi_open_file setTitle: _NS("Open File...")];
     [o_mi_open_disc setTitle: _NS("Open Disc...")];
@@ -294,6 +326,8 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
     [o_mi_previous setTitle: _NS("Previous")];
     [o_mi_next setTitle: _NS("Next")];
     [o_mi_loop setTitle: _NS("Loop")];
+    [o_mi_fwd setTitle: _NS("Step Forward")];
+    [o_mi_bwd setTitle: _NS("Step Backward")];
     [o_mi_program setTitle: _NS("Program")];
     [o_mi_title setTitle: _NS("Title")];
     [o_mi_chapter setTitle: _NS("Chapter")];
@@ -308,6 +342,9 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
     [o_mi_device setTitle: _NS("Device")];
     
     [o_mu_video setTitle: _NS("Video")];
+    [o_mi_half_window setTitle: _NS("Half Size")];
+    [o_mi_normal_window setTitle: _NS("Normal Size")];
+    [o_mi_double_window setTitle: _NS("Double Size")];
     [o_mi_fullscreen setTitle: _NS("Fullscreen")];
     [o_mi_screen setTitle: _NS("Screen")];
     [o_mi_deinterlace setTitle: _NS("Deinterlace")];
@@ -317,19 +354,22 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
     [o_mi_close_window setTitle: _NS("Close Window")];
     [o_mi_controller setTitle: _NS("Controller")];
     [o_mi_playlist setTitle: _NS("Playlist")];
+    [o_mi_info setTitle: _NS("Info")];
     [o_mi_messages setTitle: _NS("Messages")];
 
     [o_mi_bring_atf setTitle: _NS("Bring All to Front")];
 
     [o_mu_help setTitle: _NS("Help")];
     [o_mi_readme setTitle: _NS("ReadMe...")];
-    [o_mi_reportabug setTitle: _NS("Report A Bug")];
+    [o_mi_reportabug setTitle: _NS("Report a Bug")];
     [o_mi_website setTitle: _NS("VideoLAN Website")];
     [o_mi_license setTitle: _NS("License")];
 
     /* dock menu */
     [o_dmi_play setTitle: _NS("Play")];
     [o_dmi_stop setTitle: _NS("Stop")];
+    [o_dmi_next setTitle: _NS("Next")];
+    [o_dmi_previous setTitle: _NS("Previous")];
 
     /* error panel */
     [o_error setTitle: _NS("Error")];
@@ -338,6 +378,8 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
     [o_err_btn_msgs setTitle: _NS("Open Messages Window")];
     [o_err_btn_dismiss setTitle: _NS("Dismiss")];
 
+    [o_info_window setTitle: _NS("Info")];
+
     [self setSubmenusEnabled: FALSE];
     [self manageVolumeSlider];
 }
@@ -357,12 +399,14 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
         addPort: p_intf->p_sys->o_sendport
         forMode: NSDefaultRunLoopMode];
 
-    [NSTimer scheduledTimerWithTimeInterval: 0.1
+    [NSTimer scheduledTimerWithTimeInterval: 0.5
         target: self selector: @selector(manageIntf:)
-        userInfo: nil repeats: TRUE];
+        userInfo: nil repeats: FALSE];
 
     [NSThread detachNewThreadSelector: @selector(manage)
         toTarget: self withObject: nil];
+
+    vlc_thread_set_priority( p_intf, VLC_THREAD_PRIORITY_LOW );
 }
 
 - (BOOL)application:(NSApplication *)o_app openFile:(NSString *)o_filename
@@ -373,6 +417,15 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
     return( TRUE );
 }
 
+- (id)getControls
+{
+    if ( o_controls )
+    {
+        return o_controls;
+    }
+    return nil;
+}
+
 - (void)manage
 {
     NSDate * o_sleep_date;
@@ -393,16 +446,16 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
         if( p_playlist != NULL )
         {
             vlc_mutex_lock( &p_playlist->object_lock );
-
+            
             [self manage: p_playlist];
-
+            
             vlc_mutex_unlock( &p_playlist->object_lock );
             vlc_object_release( p_playlist );
         }
 
         vlc_mutex_unlock( &p_intf->change_lock );
 
-        o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: 0.1];
+        o_sleep_date = [NSDate dateWithTimeIntervalSinceNow: .5];
         [NSThread sleepUntilDate: o_sleep_date];
     }
 
@@ -413,8 +466,17 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
 
 - (void)manage:(playlist_t *)p_playlist
 {
+    vlc_value_t val;
+
     intf_thread_t * p_intf = [NSApp getIntf];
 
+    if( var_Get( (vlc_object_t *)p_playlist, "intf-change", &val ) >= 0 &&
+        val.b_bool )
+    {
+        p_intf->p_sys->b_playlist_update = VLC_TRUE;
+        p_intf->p_sys->b_intf_update = VLC_TRUE;
+    }
+
 #define p_input p_playlist->p_input
 
     if( p_input )
@@ -427,6 +489,8 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
 
         if( !p_input->b_die )
         {
+            audio_volume_t i_volume;
+
             /* New input or stream map change */
             if( p_input->stream.b_changed )
             {
@@ -447,7 +511,6 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
             if( p_aout != NULL )
             {
                 vlc_value_t val;
-                audio_volume_t i_volume;
 
                 if( var_Get( (vlc_object_t *)p_aout, "intf-change", &val )
                     >= 0 && val.b_bool )
@@ -456,12 +519,12 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
                     b_need_menus = VLC_TRUE;
                 }
 
-                aout_VolumeGet( p_aout, &i_volume );
                 vlc_object_release( (vlc_object_t *)p_aout );
-
-                p_intf->p_sys->b_mute = ( i_volume == 0 );
             }
 
+            aout_VolumeGet( p_intf, &i_volume );
+            p_intf->p_sys->b_mute = ( i_volume == 0 );
+
             p_vout = vlc_object_find( p_intf, VLC_OBJECT_VOUT,
                                               FIND_ANYWHERE );
             if( p_vout != NULL )
@@ -507,9 +570,11 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
         p_intf->p_sys->b_chapter_update = 1;
         p_intf->p_sys->b_audio_update = 1;
         p_intf->p_sys->b_spu_update = 1;
+        p_intf->p_sys->b_current_title_update = 1;
         p_intf->p_sys->i_part = 0;
 
         p_playlist->p_input->stream.b_changed = 0;
+        
         msg_Dbg( p_intf, "stream has changed, refreshing interface" );
     }
     else
@@ -525,15 +590,6 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
             vout_Destroy( p_vout );
             vlc_mutex_lock( &p_playlist->object_lock );
         }
-
-        aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT,
-                                                            FIND_ANYWHERE );
-        if( p_aout != NULL )
-        {
-            vlc_object_detach( (vlc_object_t *)p_aout );
-            vlc_object_release( (vlc_object_t *)p_aout );
-            aout_Delete( p_aout ); 
-        }
     }
 
     p_intf->p_sys->b_intf_update = VLC_TRUE;
@@ -557,6 +613,38 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
         return;
     }
 
+    if ( p_intf->p_sys->b_playlist_update )
+    {
+        vlc_value_t val;
+
+        val.b_bool = 0;
+        var_Set( (vlc_object_t *)p_playlist, "intf-change", val );
+
+        [o_playlist playlistUpdated];
+
+        p_intf->p_sys->b_playlist_update = VLC_FALSE;
+    }
+
+    if( p_intf->p_sys->b_current_title_update )
+    {
+        id o_vout_wnd;
+
+        NSEnumerator * o_enum = [[NSApp windows] objectEnumerator];
+        
+        while( ( o_vout_wnd = [o_enum nextObject] ) )
+        {
+            if( [[o_vout_wnd className] isEqualToString: @"VLCWindow"] )
+            {
+                [o_vout_wnd updateTitle];
+            }
+        }
+
+        [o_playlist updateRowSelection];
+        [o_info updateInfo];
+
+        p_intf->p_sys->b_current_title_update = FALSE;
+    }
+
     vlc_mutex_lock( &p_playlist->object_lock );
 
 #define p_input p_playlist->p_input
@@ -635,7 +723,7 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
         {
             if( f_slider == f_slider_old )
             {
-                float f_updated = ( 100. * p_area->i_tell ) /
+                float f_updated = ( 10000. * p_area->i_tell ) /
                                            p_area->i_size;
 
                 if( f_slider != f_updated )
@@ -645,7 +733,7 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
             }
             else
             {
-                off_t i_seek = ( f_slider * p_area->i_size ) / 100;
+                off_t i_seek = ( f_slider * p_area->i_size ) / 10000;
 
                 /* release the lock to be able to seek */
                 vlc_mutex_unlock( &p_input->stream.stream_lock );
@@ -687,6 +775,10 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
     vlc_object_release( p_playlist );
 
     [self updateMessageArray];
+
+    [NSTimer scheduledTimerWithTimeInterval: 0.5
+        target: self selector: @selector(manageIntf:)
+        userInfo: nil repeats: FALSE];
 }
 
 - (void)updateMessageArray
@@ -721,7 +813,7 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
 
             [o_msg_lock lock];
 
-            if( [o_msg_arr count] + 2 > 200 )
+            if( [o_msg_arr count] + 2 > 400 )
             {
                 unsigned rid[] = { 0, 1 };
                 [o_msg_arr removeObjectsFromIndices: (unsigned *)&rid
@@ -802,25 +894,12 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
 - (void)manageVolumeSlider
 {
     audio_volume_t i_volume;
-    vlc_bool_t b_audio = VLC_FALSE;
     intf_thread_t * p_intf = [NSApp getIntf];
 
-    aout_instance_t * p_aout = vlc_object_find( p_intf, VLC_OBJECT_AOUT, 
-                                                        FIND_ANYWHERE );
-    if( p_aout != NULL )
-    {
-        b_audio = VLC_TRUE;
-
-        aout_VolumeGet( p_aout, &i_volume );
-        vlc_object_release( (vlc_object_t *)p_aout );
-    }
-    else
-    {
-        i_volume = (audio_volume_t)config_GetInt( p_intf, "volume" );
-    }
+    aout_VolumeGet( p_intf, &i_volume );
 
     [o_volumeslider setFloatValue: (float)i_volume / AOUT_VOLUME_STEP]; 
-    [o_volumeslider setEnabled: b_audio];
+    [o_volumeslider setEnabled: 1];
 
     p_intf->p_sys->b_mute = ( i_volume == 0 );
 }
@@ -1253,8 +1332,7 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
         NSMenuItem * o_lmi;
         NSString * o_title;
 
-        //o_title = [NSApp localizedString: val.p_list->p_values[i].psz_string];
-        o_title = [NSString stringWithCString: val.p_list->p_values[i].psz_string];
+        o_title = [NSApp localizedString: 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 ! */
@@ -1333,7 +1411,7 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
 
 #define p_area p_playlist->p_input->stream.p_selected_area
         vlc_mutex_lock( &p_playlist->p_input->stream.stream_lock );
-        i_tell = f_updated / 100. * p_area->i_size;
+        i_tell = f_updated / 10000. * p_area->i_size;
         input_OffsetToTime( p_playlist->p_input, psz_time, i_tell );
         vlc_mutex_unlock( &p_playlist->p_input->stream.stream_lock );
 #undef p_area
@@ -1385,6 +1463,24 @@ int ExecuteOnMainThread( id target, SEL sel, void * p_arg )
                                    withApplication: @"TextEdit"];
 }
 
+- (IBAction)openCrashLog:(id)sender
+{
+    NSString * o_path = [@"~/Library/Logs/CrashReporter/VLC.crash.log"
+                                    stringByExpandingTildeInPath]; 
+
+    
+    if ( [[NSFileManager defaultManager] fileExistsAtPath: o_path ] )
+    {
+        [[NSWorkspace sharedWorkspace] openFile: o_path 
+                                    withApplication: @"Console"];
+    }
+    else
+    {
+        NSBeginInformationalAlertSheet(_NS("No CrashLog found"), @"Continue", nil, nil, o_msgs_panel, self, NULL, NULL, nil, _NS("Either you are running Mac OS X pre 10.2 or you haven't experienced any heavy crashes yet.") );
+
+    }
+}
+
 - (void)windowDidBecomeKey:(NSNotification *)o_notification
 {
     if( [o_notification object] == o_msgs_panel )