]> git.sesse.net Git - vlc/blobdiff - modules/gui/ncurses.c
Add services discovery support and enhance playlist support for lua interface modules...
[vlc] / modules / gui / ncurses.c
index f0d14b5b3f333cd43158dc3dda7cef1ef38859e1..f20e1185b2592cfa3b8e53f440a589732968bc89 100644 (file)
 #include <errno.h>                                                 /* ENOMEM */
 #include <time.h>
 
-#ifdef HAVE_NCURSESW_CURSES_H
-#include <ncursesw/curses.h>
-#else
-#include <curses.h>
+#ifdef HAVE_NCURSESW
+#   define _XOPEN_SOURCE_EXTENDED 1
 #endif
 
+#include <ncurses.h>
+
 #include <vlc_interface.h>
 #include <vlc_vout.h>
 #include <vlc_aout.h>
@@ -437,7 +437,7 @@ static char *KeyToUTF8( int i_key, char *psz_part )
 
     psz_part[len] = (char)i_key;
 
-#ifdef HAVE_NCURSESW_CURSES_H
+#ifdef HAVE_NCURSESW
     psz_utf8 = strdup( psz_part );
 #else
     psz_utf8 = FromLocaleDup( psz_part );
@@ -579,14 +579,24 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
 
             case KEY_ENTER:
             case 0x0d:
+                if( !p_sys->pp_plist || !p_sys->pp_plist[p_sys->i_box_plidx] )
+                {
+                    b_ret = VLC_FALSE;
+                    break;
+                }
                 if( p_sys->pp_plist[p_sys->i_box_plidx]->p_item->i_children
                         == -1 )
                 {
-                    playlist_item_t *p_item =
+                    playlist_item_t *p_item, *p_parent;
+                    p_item = p_parent =
                             p_sys->pp_plist[p_sys->i_box_plidx]->p_item;
+
+                    if( !p_parent )
+                        p_parent = p_sys->p_playlist->p_root_onelevel;
+                    while( p_parent->p_parent )
+                        p_parent = p_parent->p_parent;
                     playlist_Control( p_sys->p_playlist, PLAYLIST_VIEWPLAY,
-                                      VLC_TRUE, p_item->p_parent,
-                        p_sys->pp_plist[p_sys->i_box_plidx]->p_item );
+                                      VLC_TRUE, p_parent, p_item );
                 }
                 else
                 {
@@ -654,11 +664,18 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
                     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_bidx]->psz_path );
-                    /* XXX
-                    playlist_Add( p_sys->p_playlist, psz_uri,
-                                  psz_uri,
-                                  PLAYLIST_APPEND, PLAYLIST_END );
-                    */
+
+                    playlist_item_t *p_parent = p_sys->p_playlist->status.p_node;
+                    if( !p_parent )
+                        p_parent = p_sys->p_playlist->p_root_onelevel;
+
+                    while( p_parent->p_parent )
+                        p_parent = p_parent->p_parent;
+
+                    playlist_Add( p_sys->p_playlist, psz_uri, NULL,
+                                  PLAYLIST_APPEND, PLAYLIST_END,
+                                  p_parent == p_sys->p_playlist->p_root_onelevel
+                                  , VLC_FALSE );
                     p_sys->i_box_type = BOX_PLAYLIST;
                     free( psz_uri );
                 }
@@ -813,11 +830,17 @@ static int HandleKey( intf_thread_t *p_intf, int i_key )
             case 0x0d:
                 if( p_playlist && i_chain_len > 0 )
                 {
-                    /*
-                    playlist_Add( p_playlist, p_sys->psz_open_chain,
-                                  p_sys->psz_open_chain,
-                                  PLAYLIST_GO|PLAYLIST_APPEND, PLAYLIST_END );
-                    */
+                    playlist_item_t *p_parent = p_sys->p_playlist->status.p_node;
+                    if( !p_parent )
+                        p_parent = p_sys->p_playlist->p_root_onelevel;
+
+                    while( p_parent->p_parent )
+                        p_parent = p_parent->p_parent;
+
+                    playlist_Add( p_playlist, p_sys->psz_open_chain, NULL,
+                                  PLAYLIST_APPEND|PLAYLIST_GO, PLAYLIST_END,
+                                  p_parent == p_sys->p_playlist->p_root_onelevel
+                                  , VLC_FALSE );
                     p_sys->b_box_plidx_follow = VLC_TRUE;
                 }
                 p_sys->i_box_type = BOX_PLAYLIST;
@@ -1133,21 +1156,22 @@ static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
     va_list  vl_args;
     char    *p_buf = NULL;
     int      i_len;
-#ifdef HAVE_NCURSESW_CURSES_H
+#ifdef HAVE_NCURSESW
     size_t   i_char_len;    /* UCS character length */
     size_t   i_width;       /* Display width */
     wchar_t *psz_wide;      /* wchar_t representation of p_buf */
 #endif
 
     va_start( vl_args, p_fmt );
-    vasprintf( &p_buf, p_fmt, vl_args );
+    if( vasprintf( &p_buf, p_fmt, vl_args ) == -1 )
+        return;
     va_end( vl_args );
 
     if( ( p_buf == NULL ) || ( w <= 0 ) )
         return;
 
     i_len = strlen( p_buf );
-#ifdef HAVE_NCURSESW_CURSES_H
+#ifdef HAVE_NCURSESW
     psz_wide = (wchar_t *) malloc( sizeof( wchar_t ) * ( i_len + 1 ) );
 
     i_char_len = mbstowcs( psz_wide, p_buf, i_len );
@@ -1180,7 +1204,7 @@ static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
             p_buf[w/2  ] = '.';
             p_buf[w/2+1] = '.';
         }
-#ifdef HAVE_NCURSESW_CURSES_H
+#ifdef HAVE_NCURSESW
         mvprintw( y, x, "%s", p_buf );
 #else
         char *psz_local = ToLocale( p_buf );
@@ -1190,7 +1214,7 @@ static void mvnprintw( int y, int x, int w, const char *p_fmt, ... )
     }
     else
     {
-#ifdef HAVE_NCURSESW_CURSES_H
+#ifdef HAVE_NCURSESW
         mvprintw( y, x, "%s", p_buf );
         mvhline( y, x + i_width, ' ', w - i_width );
 #else
@@ -1214,7 +1238,8 @@ static void MainBoxWrite( intf_thread_t *p_intf, int l, int x, const char *p_fmt
     }
 
     va_start( vl_args, p_fmt );
-    vasprintf( &p_buf, p_fmt, vl_args );
+    if( vasprintf( &p_buf, p_fmt, vl_args ) == -1 )
+        return;
     va_end( vl_args );
 
     if( p_buf == NULL )