]> git.sesse.net Git - vlc/blobdiff - modules/gui/ncurses.c
Improvements to preferences
[vlc] / modules / gui / ncurses.c
index 40e0f97665ffd1fcbb42ee2f7c7fee820ef693b2..e78a7d0ac75b09daf732031f127e99d125038631 100644 (file)
@@ -85,12 +85,14 @@ static void ReadDir        ( intf_thread_t * );
 
 #define BROWSE_TEXT N_("Filebrowser starting point")
 #define BROWSE_LONGTEXT N_( \
-    "This option allows you to specify directory the ncurses filebrowser" \
+    "This option allows you to specify the directory the ncurses filebrowser " \
     "will show you initially.")
 
 vlc_module_begin();
     set_description( _("ncurses interface") );
     set_capability( "interface", 10 );
+    set_category( CAT_INTERFACE );
+    set_subcategory( SUBCAT_INTERFACE_GENERAL );
     set_callbacks( Open, Close );
     add_shortcut( "curses" );
     add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, VLC_FALSE );
@@ -133,6 +135,7 @@ struct intf_sys_t
 
     int             i_box_plidx;    /* Playlist index */
     int             b_box_plidx_follow;
+    int             i_box_bidx;    /* browser index */
 
     int             b_box_cleared;
 
@@ -175,6 +178,7 @@ static int Open( vlc_object_t *p_this )
     p_sys->b_box_plidx_follow = VLC_TRUE;
     p_sys->b_box_cleared = VLC_FALSE;
     p_sys->i_box_plidx = 0;
+    p_sys->i_box_bidx = 0;
     p_sys->p_sub = msg_Subscribe( p_intf );
 
     /* Initialize the curses library */
@@ -322,7 +326,6 @@ static void Run( intf_thread_t *p_intf )
             p_sys->i_box_plidx = p_sys->p_playlist->i_index;
         }
 
-
         while( ( i_key = getch()) != -1 )
         {
             /*
@@ -446,37 +449,38 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
     }
     if( p_sys->i_box_type == BOX_BROWSE )
     {
+        vlc_bool_t b_ret = VLC_TRUE;
         /* Browser navigation */
         switch( i_key )
         {
             case KEY_HOME:
-                p_sys->i_box_plidx = 0;
+                p_sys->i_box_bidx = 0;
                 break;
             case KEY_END:
-                p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
+                p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
                 break;
             case KEY_UP:
-                p_sys->i_box_plidx--;
+                p_sys->i_box_bidx--;
                 break;
             case KEY_DOWN:
-                p_sys->i_box_plidx++;
+                p_sys->i_box_bidx++;
                 break;
             case KEY_PPAGE:
-                p_sys->i_box_plidx -= p_sys->i_box_lines;
+                p_sys->i_box_bidx -= p_sys->i_box_lines;
                 break;
             case KEY_NPAGE:
-                p_sys->i_box_plidx += p_sys->i_box_lines;
+                p_sys->i_box_bidx += p_sys->i_box_lines;
                 break;
 
             case KEY_ENTER:
             case 0x0d:
-                if( p_sys->pp_dir_entries[p_sys->i_box_plidx]->b_file )
+                if( p_sys->pp_dir_entries[p_sys->i_box_bidx]->b_file )
                 {
                     int i_size_entry = strlen( p_sys->psz_current_dir ) +
-                                       strlen( p_sys->pp_dir_entries[p_sys->i_box_plidx]->psz_path ) + 2;
+                                       strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
                     char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
 
-                    sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_plidx]->psz_path );
+                    sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
                     playlist_Add( p_sys->p_playlist, psz_uri,
                                   psz_uri,
                                   PLAYLIST_APPEND, PLAYLIST_END );
@@ -486,10 +490,10 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                 else
                 {
                     int i_size_entry = strlen( p_sys->psz_current_dir ) +
-                                       strlen( p_sys->pp_dir_entries[p_sys->i_box_plidx]->psz_path ) + 2;
+                                       strlen( p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path ) + 2;
                     char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
 
-                    sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_plidx]->psz_path );
+                    sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_sys->pp_dir_entries[p_sys->i_box_bidx]->psz_path );
                     
                     p_sys->psz_current_dir = strdup( psz_uri );
                     ReadDir( p_intf );
@@ -497,14 +501,13 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                 }
                 break;
             default:
+                b_ret = VLC_FALSE;
                 break;
-
-            if( p_sys->i_box_plidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
-            if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
-            if( p_sys->i_box_plidx == p_sys->i_dir_entries )
-                p_sys->b_box_plidx_follow = VLC_TRUE;
-            else
-                p_sys->b_box_plidx_follow = VLC_FALSE;
+        }
+        if( b_ret )
+        {
+            if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_bidx = p_sys->i_dir_entries - 1;
+            if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
             return 1;
         }
     }
@@ -618,8 +621,7 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
     }
     else if( p_sys->i_box_type == BOX_OPEN && p_sys->psz_open_chain )
     {
-        int i_chain_len;
-        i_chain_len = strlen( p_sys->psz_open_chain );
+        int i_chain_len = strlen( p_sys->psz_open_chain );
         playlist_t *p_playlist = p_sys->p_playlist;
 
         switch( i_key )
@@ -1017,7 +1019,8 @@ static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
         vlc_value_t val_list;
 
         /* Source */
-        mvnprintw( y++, 0, COLS, " Source   : %s", p_input->psz_source );
+        mvnprintw( y++, 0, COLS, " Source   : %s",
+                   p_input->input.p_item->psz_uri );
 
         /* State */
         var_Get( p_input, "state", &val );
@@ -1172,10 +1175,10 @@ static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
         if( p_input )
         {
             int i,j;
-            vlc_mutex_lock( &p_input->p_item->lock );
-            for ( i = 0; i < p_input->p_item->i_categories; i++ )
+            vlc_mutex_lock( &p_input->input.p_item->lock );
+            for ( i = 0; i < p_input->input.p_item->i_categories; i++ )
             {
-                info_category_t *p_category = p_input->p_item->pp_categories[i];
+                info_category_t *p_category = p_input->input.p_item->pp_categories[i];
                 if( y >= y_end ) break;
                 MainBoxWrite( p_intf, l++, 1, "  [%s]", p_category->psz_name );
                 for ( j = 0; j < p_category->i_infos; j++ )
@@ -1185,7 +1188,7 @@ static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
                     MainBoxWrite( p_intf, l++, 1, "      %s: %s", p_info->psz_name, p_info->psz_value );
                 }
             }
-            vlc_mutex_unlock( &p_input->p_item->lock );
+            vlc_mutex_unlock( &p_input->input.p_item->lock );
         }
         else
         {
@@ -1251,17 +1254,17 @@ static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
         int        i_item;
         DrawBox( p_sys->w, y++, 0, h, COLS, " Browse " );
 
-        if( p_sys->i_box_plidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
-        if( p_sys->i_box_plidx < 0 ) p_sys->i_box_plidx = 0;
+        if( p_sys->i_box_bidx >= p_sys->i_dir_entries ) p_sys->i_box_plidx = p_sys->i_dir_entries - 1;
+        if( p_sys->i_box_bidx < 0 ) p_sys->i_box_bidx = 0;
 
-        if( p_sys->i_box_plidx < (h - 2)/2 )
+        if( p_sys->i_box_bidx < (h - 2)/2 )
         {
             i_start = 0;
             i_stop = h - 2;
         }
-        else if( p_sys->i_dir_entries - p_sys->i_box_plidx > (h - 2)/2 )
+        else if( p_sys->i_dir_entries - p_sys->i_box_bidx > (h - 2)/2 )
         {
-            i_start = p_sys->i_box_plidx - (h - 2)/2;
+            i_start = p_sys->i_box_bidx - (h - 2)/2;
             i_stop = i_start + h - 2;
         }
         else
@@ -1280,7 +1283,7 @@ static void Redraw ( intf_thread_t *p_intf, time_t *t_last_refresh )
 
         for( i_item = i_start; i_item < i_stop; i_item++ )
         {
-            vlc_bool_t b_selected = ( p_sys->i_box_plidx == i_item );
+            vlc_bool_t b_selected = ( p_sys->i_box_bidx == i_item );
 
             if( y >= y_end ) break;
             if( b_selected )
@@ -1556,21 +1559,24 @@ static void ReadDir( intf_thread_t *p_intf )
         /* while we still have entries in the directory */
         while( p_dir_content != NULL )
         {
+#if defined( S_ISDIR )
+            struct stat stat_data;
+#endif
             struct dir_entry_t *p_dir_entry;
             int i_size_entry = strlen( p_sys->psz_current_dir ) +
                                strlen( p_dir_content->d_name ) + 2;
             char *psz_uri = (char *)malloc( sizeof(char)*i_size_entry);
 
-            sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, p_dir_content->d_name );
+            sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir,
+                     p_dir_content->d_name );
 
-            if( ( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) == NULL )
+            if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )
             {
                 free( psz_uri);
                 return;
             }
 
 #if defined( S_ISDIR )
-            struct stat stat_data;
             stat( psz_uri, &stat_data );
             if( S_ISDIR(stat_data.st_mode) )
 #elif defined( DT_DIR )
@@ -1591,6 +1597,7 @@ static void ReadDir( intf_thread_t *p_intf )
                 INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,
                      p_sys->i_dir_entries, p_dir_entry );
             }
+
             free( psz_uri );
             /* Read next entry */
             p_dir_content = readdir( p_current_dir );