]> git.sesse.net Git - vlc/blobdiff - modules/control/rc.c
Improve playlist drawing with rc.
[vlc] / modules / control / rc.c
index 409606de5a9edf3a0abdbf9cf6d5c439e0e4119b..7f5477642075b1fe63cf7c60d17b8a381ee616ee 100644 (file)
@@ -40,7 +40,6 @@
 #include <vlc_vout.h>
 #include <vlc_osd.h>
 #include <vlc_playlist.h>
-#include <vlc_update.h>
 
 #ifdef HAVE_UNISTD_H
 #    include <unistd.h>
@@ -103,9 +102,6 @@ static int  Statistics   ( vlc_object_t *, char const *,
                            vlc_value_t, vlc_value_t, void * );
 
 static int updateStatistics( intf_thread_t *, input_item_t *);
-#if 0 && defined( UPDATE_CHECK )
-static void checkUpdates( intf_thread_t *p_intf );
-#endif
 
 /* Status Callbacks */
 static int TimeOffsetChanged( vlc_object_t *, char const *,
@@ -126,7 +122,6 @@ struct intf_sys_t
     /* status changes */
     vlc_mutex_t       status_lock;
     playlist_status_t i_last_state;
-    vlc_bool_t        b_statistics;
 
 #ifdef WIN32
     HANDLE hConsoleIn;
@@ -324,7 +319,6 @@ static int Activate( vlc_object_t *p_this )
     p_intf->p_sys->psz_unix_path = psz_unix_path;
     vlc_mutex_init( p_intf, &p_intf->p_sys->status_lock );
     p_intf->p_sys->i_last_state = PLAYLIST_STOPPED;
-    p_intf->p_sys->b_statistics = VLC_FALSE;
 
     /* Non-buffered stdout */
     setvbuf( stdout, (char *)NULL, _IOLBF, 0 );
@@ -583,13 +577,6 @@ static void Run( intf_thread_t *p_intf )
             }
         }
 
-        if( p_input && p_intf->p_sys->b_statistics )
-        {
-            vlc_mutex_lock( &input_GetItem(p_input)->lock );
-            updateStatistics( p_intf, input_GetItem(p_input) );
-            vlc_mutex_unlock( &input_GetItem(p_input)->lock );
-        }
-
         /* Is there something to do? */
         if( !b_complete ) continue;
 
@@ -767,12 +754,6 @@ static void Run( intf_thread_t *p_intf )
 
             Help( p_intf, b_longhelp );
         }
-#if 0 && defined( UPDATE_CHECK )
-        else if( !strcmp( psz_cmd, "check-updates" ) )
-        {
-            checkUpdates( p_intf );
-        }
-#endif
         else if( !strcmp( psz_cmd, "key" ) || !strcmp( psz_cmd, "hotkey" ) )
         {
             var_SetInteger( p_intf->p_libvlc, "key-pressed",
@@ -942,11 +923,6 @@ static void Help( intf_thread_t *p_intf, vlc_bool_t b_longhelp)
         msg_rc(_("| @name mosaic-cols #. . . . . . . . . . .number of cols"));
         msg_rc(_("| @name mosaic-order id(,id)* . . . . order of pictures "));
         msg_rc(_("| @name mosaic-keep-aspect-ratio {0,1} . . .aspect ratio"));
-#if 0 && defined( UPDATE_CHECK )
-        msg_rc(  "| ");
-        msg_rc(_("| check-updates [newer] [equal] [older]\n"
-                 "|               [undef] [info] [source] [binary] [plugin]"));
-#endif
         msg_rc(  "| ");
     }
     msg_rc(_("| help . . . . . . . . . . . . . . . this help message"));
@@ -1279,7 +1255,7 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
                         &val, &text );
             msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
-            if( val_name.psz_string ) free( val_name.psz_string );
+            free( val_name.psz_string );
 
             i_error = VLC_SUCCESS;
         }
@@ -1292,6 +1268,25 @@ static int Input( vlc_object_t *p_this, char const *psz_cmd,
     return VLC_EGENERIC;
 }
 
+static void print_playlist( intf_thread_t *p_intf, playlist_item_t *p_item, int i_level )
+{
+    int i;
+    char psz_buffer[MSTRTIME_MAX_SIZE];
+    for( i = 0; i< p_item->i_children; i++ )
+    {
+        if( p_item->pp_children[i]->p_input->i_duration != -1 )
+        {
+            secstotimestr( psz_buffer, p_item->pp_children[i]->p_input->i_duration / 1000000 );
+            msg_rc( "|%*s- %s (%s)", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name, psz_buffer );
+        }
+        else
+            msg_rc( "|%*s- %s", 2 * i_level, "", p_item->pp_children[i]->p_input->psz_name );
+
+        if( p_item->pp_children[i]->i_children >= 0 )
+            print_playlist( p_intf, p_item->pp_children[i], i_level + 1 );
+    }
+}
+
 static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
                      vlc_value_t oldval, vlc_value_t newval, void *p_data )
 {
@@ -1432,9 +1427,12 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
         if( p_item )
         {
             msg_rc( "Trying to add %s to playlist.", newval.psz_string );
-            playlist_AddInput( p_playlist, p_item,
+            if( playlist_AddInput( p_playlist, p_item,
                      PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
-                     VLC_FALSE );
+                     VLC_FALSE ) != VLC_SUCCESS )
+            {
+                return VLC_EGENERIC;
+            }
         }
     }
     else if( !strcmp( psz_cmd, "enqueue" ) &&
@@ -1445,18 +1443,21 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
         if( p_item )
         {
             msg_rc( "trying to enqueue %s to playlist", newval.psz_string );
-            playlist_AddInput( p_playlist, p_item,
+            if( playlist_AddInput( p_playlist, p_item,
                                PLAYLIST_APPEND, PLAYLIST_END, VLC_TRUE,
-                               VLC_FALSE);
+                               VLC_FALSE ) != VLC_SUCCESS )
+            {
+                return VLC_EGENERIC;
+            }
         }
     }
     else if( !strcmp( psz_cmd, "playlist" ) )
     {
-        msg_Dbg( p_playlist, "Dumping category" );
-        playlist_NodeDump( p_playlist, p_playlist->p_root_category, 0 );
-        msg_Dbg( p_playlist, "Dumping Onelevel" );
-        playlist_NodeDump( p_playlist, p_playlist->p_root_onelevel, 0 );
+        msg_rc( "+----[ Playlist ]" );
+        print_playlist( p_intf, p_playlist->p_root_category, 0 );
+        msg_rc( "+----[ End of playlist ]" );
     }
+
     else if( !strcmp( psz_cmd, "sort" ))
     {
         playlist_RecursiveNodeSort( p_playlist, p_playlist->p_root_onelevel,
@@ -1474,7 +1475,7 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
             msg_rc( STATUS_CHANGE "( audio volume: %d )",
                     config_GetInt( p_intf, "volume" ));
 
-            vlc_mutex_lock( &p_playlist->object_lock );
+            PL_LOCK;
             switch( p_playlist->status.i_status )
             {
                 case PLAYLIST_STOPPED:
@@ -1490,7 +1491,7 @@ static int Playlist( vlc_object_t *p_this, char const *psz_cmd,
                     msg_rc( STATUS_CHANGE "( state unknown )" );
                     break;
             }
-            vlc_mutex_unlock( &p_playlist->object_lock );
+            PL_UNLOCK;
         }
     }
 
@@ -1781,7 +1782,7 @@ static int VideoConfig( vlc_object_t *p_this, char const *psz_cmd,
                     &val, &text );
         msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
-        if( val_name.psz_string ) free( val_name.psz_string );
+        free( val_name.psz_string );
 
         i_error = VLC_SUCCESS;
     }
@@ -1868,7 +1869,7 @@ static int AudioConfig( vlc_object_t *p_this, char const *psz_cmd,
                     &val, &text );
         msg_rc( "+----[ end of %s ]", val_name.psz_string );
 
-        if( val_name.psz_string ) free( val_name.psz_string );
+        free( val_name.psz_string );
         i_error = VLC_SUCCESS;
     }
     else
@@ -1936,12 +1937,12 @@ static int Menu( vlc_object_t *p_this, char const *psz_cmd,
     {
         msg_rc( _("Please provide one of the following parameters:") );
         msg_rc( "[on|off|up|down|left|right|select]" );
-        if( val.psz_string ) free( val.psz_string );
-            return i_error;
+        free( val.psz_string );
+        return i_error;
     }
 
     i_error = VLC_SUCCESS;
-    if( val.psz_string ) free( val.psz_string );
+    free( val.psz_string );
     return i_error;
 }
 
@@ -1959,11 +1960,9 @@ static int Statistics ( vlc_object_t *p_this, char const *psz_cmd,
 
     if( !strcmp( psz_cmd, "stats" ) )
     {
-        p_intf->p_sys->b_statistics = !p_intf->p_sys->b_statistics;
-        if( p_intf->p_sys->b_statistics )
-            msg_rc(_("statistics update on"));
-        else
-            msg_rc(_("statistics update off"));
+        vlc_mutex_lock( &input_GetItem(p_input)->lock );
+        updateStatistics( p_intf, input_GetItem(p_input) );
+        vlc_mutex_unlock( &input_GetItem(p_input)->lock );
     }
     /*
      * sanity check
@@ -2128,8 +2127,11 @@ vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
             p_intf->p_sys->i_socket = -1;
         }
         else
+        {
             /* Standard input closed: exit */
-            vlc_object_kill( p_intf );
+            vlc_value_t empty;
+            Quit( p_intf, NULL, empty, empty, NULL );
+        }
 
         p_buffer[ *pi_size ] = 0;
         return VLC_TRUE;
@@ -2154,7 +2156,7 @@ vlc_bool_t ReadCommand( intf_thread_t *p_intf, char *p_buffer, int *pi_size )
  *****************************************************************************/
 static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
 {
-#define SKIPSPACE( p ) { while( *p && ( *p == ' ' || *p == '\t' ) ) p++; }
+#define SKIPSPACE( p ) { while( *p == ' ' || *p == '\t' ) p++; }
 #define SKIPTRAILINGSPACE( p, d ) \
     { char *e=d; while( e > p && (*(e-1)==' ' || *(e-1)=='\t') ){e--;*e=0;} }
 
@@ -2221,19 +2223,3 @@ static input_item_t *parse_MRL( intf_thread_t *p_intf, char *psz_mrl )
 
     return p_item;
 }
-
-/*****************************************************************************
- * checkUpdates : check for updates
- ****************************************************************************/
-#if 0 && defined( UPDATE_CHECK )
-static void checkUpdates( intf_thread_t *p_intf )
-{
-    /*TODO: - modify this to delete p_update to avoid a memory leak !
-            - complete the function wich is not working obiously !
-    update_t *p_u = update_New( p_intf );
-    var_AddCallback( p_intf->p_libvlc, "update-notify", updatesCallback, p_intf );
-
-    msg_rc( "\nChecking for updates" );
-    update_Check( p_u );*/
-}
-#endif