?? ncurses.c
字號:
/***************************************************************************** * ncurses.c : NCurses interface for vlc ***************************************************************************** * Copyright ? 2001-2007 the VideoLAN team * $Id: d93d0a7deefd672fa244674277b3f6b5129f4517 $ * * Authors: Sam Hocevar <sam@zoy.org> * Laurent Aimar <fenrir@via.ecp.fr> * Yoann Peronneau <yoann@videolan.org> * Derk-Jan Hartman <hartman at videolan dot org> * Rafa?l Carré <funman@videolanorg> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************//* * Note that when we use wide characters (and link with libncursesw), * we assume that an UTF8 locale is used (or compatible, such as ASCII). * Other characters encodings are not supported. *//***************************************************************************** * Preamble *****************************************************************************/#ifdef HAVE_CONFIG_H# include "config.h"#endif#include <vlc_common.h>#include <vlc_plugin.h>#ifdef HAVE_NCURSESW# define _XOPEN_SOURCE_EXTENDED 1# include <wchar.h>#endif#include <ncurses.h>#include <vlc_interface.h>#include <vlc_vout.h>#include <vlc_aout.h>#include <vlc_charset.h>#include <vlc_input.h>#include <vlc_es.h>#include <vlc_playlist.h>#include <vlc_meta.h>#include <assert.h>#ifdef HAVE_SYS_STAT_H# include <sys/stat.h>#endif#if (!defined( WIN32 ) || defined(__MINGW32__))/* Mingw has its own version of dirent */# include <dirent.h>#endif#ifdef HAVE_CDDAX#define CDDA_MRL "cddax://"#else#define CDDA_MRL "cdda://"#endif#ifdef HAVE_VCDX#define VCD_MRL "vcdx://"#else#define VCD_MRL "vcd://"#endif#define SEARCH_CHAIN_SIZE 20#define OPEN_CHAIN_SIZE 50/***************************************************************************** * Local prototypes. *****************************************************************************/static int Open ( vlc_object_t * );static void Close ( vlc_object_t * );static void Run ( intf_thread_t * );static void PlayPause ( intf_thread_t * );static void Eject ( intf_thread_t * );static int HandleKey ( intf_thread_t *, int );static void Redraw ( intf_thread_t *, time_t * );static playlist_item_t *PlaylistGetRoot( intf_thread_t * );static void PlaylistRebuild( intf_thread_t * );static void PlaylistAddNode( intf_thread_t *, playlist_item_t *, int, const char *);static void PlaylistDestroy( intf_thread_t * );static int PlaylistChanged( vlc_object_t *, const char *, vlc_value_t, vlc_value_t, void * );static inline bool PlaylistIsPlaying( intf_thread_t *, playlist_item_t * );static void FindIndex ( intf_thread_t * );static void SearchPlaylist ( intf_thread_t *, char * );static int SubSearchPlaylist( intf_thread_t *, char *, int, int );static void ManageSlider ( intf_thread_t * );static void ReadDir ( intf_thread_t * );static void start_color_and_pairs ( intf_thread_t * );/***************************************************************************** * Module descriptor *****************************************************************************/#define BROWSE_TEXT N_("Filebrowser starting point")#define BROWSE_LONGTEXT N_( \ "This option allows you to specify the directory the ncurses filebrowser " \ "will show you initially.")vlc_module_begin(); set_shortname( "Ncurses" ); set_description( N_("Ncurses interface") ); set_capability( "interface", 10 ); set_category( CAT_INTERFACE ); set_subcategory( SUBCAT_INTERFACE_MAIN ); set_callbacks( Open, Close ); add_shortcut( "curses" ); add_directory( "browse-dir", NULL, NULL, BROWSE_TEXT, BROWSE_LONGTEXT, false );vlc_module_end();/***************************************************************************** * intf_sys_t: description and status of ncurses interface *****************************************************************************/enum{ BOX_NONE, BOX_HELP, BOX_INFO, BOX_LOG, BOX_PLAYLIST, BOX_SEARCH, BOX_OPEN, BOX_BROWSE, BOX_META, BOX_OBJECTS, BOX_STATS};enum{ C_DEFAULT = 0, C_TITLE, C_PLAYLIST_1, C_PLAYLIST_2, C_PLAYLIST_3, C_BOX, C_STATUS, C_INFO, C_ERROR, C_WARNING, C_DEBUG, C_CATEGORY, C_FOLDER};enum{ VIEW_CATEGORY, VIEW_ONELEVEL};struct dir_entry_t{ bool b_file; char *psz_path;};struct pl_item_t{ playlist_item_t *p_item; char *psz_display;};struct intf_sys_t{ input_thread_t *p_input; playlist_t *p_playlist; bool b_color; bool b_color_started; float f_slider; float f_slider_old; WINDOW *w; int i_box_type; int i_box_y; int i_box_lines; int i_box_lines_total; int i_box_start; int i_box_plidx; /* Playlist index */ int b_box_plidx_follow; int i_box_bidx; /* browser index */ playlist_item_t *p_node; /* current node */ int b_box_cleared; msg_subscription_t* p_sub; /* message bank subscription */ char *psz_search_chain; /* for playlist searching */ char *psz_old_search; /* for searching next */ int i_before_search; char *psz_open_chain;#ifndef HAVE_NCURSESW char psz_partial_keys[7];#endif char *psz_current_dir; int i_dir_entries; struct dir_entry_t **pp_dir_entries; bool b_show_hidden_files; int i_current_view; /* playlist view */ struct pl_item_t **pp_plist; int i_plist_entries; bool b_need_update; /* for playlist view */ int i_verbose; /* stores verbosity level */};static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title, bool b_color );static void DrawLine( WINDOW *win, int y, int x, int w );static void DrawEmptyLine( WINDOW *win, int y, int x, int w );/***************************************************************************** * Open: initialize and create window *****************************************************************************/static int Open( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys; vlc_value_t val; /* Allocate instance and initialize some members */ p_sys = p_intf->p_sys = malloc( sizeof( intf_sys_t ) ); if( !p_sys ) return VLC_ENOMEM; p_sys->p_node = NULL; p_sys->p_input = NULL; p_sys->f_slider = 0.0; p_sys->f_slider_old = 0.0; p_sys->i_box_type = BOX_PLAYLIST; p_sys->i_box_lines = 0; p_sys->i_box_start= 0; p_sys->i_box_lines_total = 0; p_sys->b_box_plidx_follow = true; p_sys->b_box_cleared = false; p_sys->i_box_plidx = 0; p_sys->i_box_bidx = 0; p_sys->p_sub = msg_Subscribe( p_intf ); p_sys->b_color = var_CreateGetBool( p_intf, "color" ); p_sys->b_color_started = false;#ifndef HAVE_NCURSESW memset( p_sys->psz_partial_keys, 0, sizeof( p_sys->psz_partial_keys ) );#endif /* Initialize the curses library */ p_sys->w = initscr(); if( p_sys->b_color ) start_color_and_pairs( p_intf ); keypad( p_sys->w, TRUE ); /* Don't do NL -> CR/NL */ nonl(); /* Take input chars one at a time */ cbreak(); /* Don't echo */ noecho(); /* Invisible cursor */ curs_set( 0 ); /* Non blocking wgetch() */ wtimeout( p_sys->w, 0 ); clear(); /* exported function */ p_intf->pf_run = Run; /* Remember verbosity level */ var_Get( p_intf->p_libvlc, "verbose", &val ); p_sys->i_verbose = val.i_int; /* Set quiet mode */ val.i_int = -1; var_Set( p_intf->p_libvlc, "verbose", val ); /* Set defaul playlist view */ p_sys->i_current_view = VIEW_CATEGORY; p_sys->pp_plist = NULL; p_sys->i_plist_entries = 0; p_sys->b_need_update = false; /* Initialize search chain */ p_sys->psz_search_chain = (char *)malloc( SEARCH_CHAIN_SIZE + 1 ); p_sys->psz_old_search = NULL; p_sys->i_before_search = 0; /* Initialize open chain */ p_sys->psz_open_chain = (char *)malloc( OPEN_CHAIN_SIZE + 1 ); /* Initialize browser options */ var_Create( p_intf, "browse-dir", VLC_VAR_STRING | VLC_VAR_DOINHERIT ); var_Get( p_intf, "browse-dir", &val); if( val.psz_string && *val.psz_string ) { p_sys->psz_current_dir = strdup( val.psz_string ); } else { p_sys->psz_current_dir = strdup( config_GetHomeDir() ); } free( val.psz_string ); p_sys->i_dir_entries = 0; p_sys->pp_dir_entries = NULL; p_sys->b_show_hidden_files = false; ReadDir( p_intf ); return VLC_SUCCESS;}/***************************************************************************** * Close: destroy interface window *****************************************************************************/static void Close( vlc_object_t *p_this ){ intf_thread_t *p_intf = (intf_thread_t *)p_this; intf_sys_t *p_sys = p_intf->p_sys; PlaylistDestroy( p_intf ); while( p_sys->i_dir_entries ) { struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[0]; free( p_dir_entry->psz_path ); REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, 0 ); free( p_dir_entry ); } p_sys->pp_dir_entries = NULL; free( p_sys->psz_current_dir ); free( p_sys->psz_search_chain ); free( p_sys->psz_old_search ); free( p_sys->psz_open_chain ); if( p_sys->p_input ) { vlc_object_release( p_sys->p_input ); } pl_Release( p_intf ); /* Close the ncurses interface */ endwin(); msg_Unsubscribe( p_intf, p_sys->p_sub ); /* Restores initial verbose setting */ vlc_value_t val; val.i_int = p_sys->i_verbose; var_Set( p_intf->p_libvlc, "verbose", val ); /* Destroy structure */ free( p_sys );}/***************************************************************************** * Run: ncurses thread *****************************************************************************/static void Run( intf_thread_t *p_intf ){ intf_sys_t *p_sys = p_intf->p_sys; playlist_t *p_playlist = pl_Yield( p_intf ); p_sys->p_playlist = p_playlist; int i_key; time_t t_last_refresh; /* * force drawing the interface for the first time */ t_last_refresh = ( time( 0 ) - 1); /* * force building of the playlist array */ PlaylistRebuild( p_intf ); var_AddCallback( p_playlist, "intf-change", PlaylistChanged, p_intf );
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -