⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncurses.c

📁 uclinux 下的vlc播放器源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
    /* Build the new one */    PlaylistAddNode( p_intf, p_view->p_root, 0, "" );    p_sys->b_need_update = VLC_FALSE;    vlc_mutex_unlock( &p_playlist->object_lock );}static void PlaylistAddNode( intf_thread_t *p_intf, playlist_item_t *p_node,                             int i, char *c ){    intf_sys_t *p_sys = p_intf->p_sys;    playlist_item_t *p_child;    char *psz_tmp;    int k;    psz_tmp = (char *)malloc( strlen( c ) + 4 );    if( psz_tmp == NULL ) return;    for( k = 0; k < p_node->i_children; k++ )    {        struct pl_item_t *p_pl_item;        char *buff;        int i_size;        p_child = p_node->pp_children[k];        i_size = strlen( c ) + strlen( p_child->input.psz_name ) + 4;        buff = (char *)malloc( sizeof( char ) * i_size );        p_pl_item = (struct pl_item_t *)malloc( sizeof( struct pl_item_t ) );        if(  p_pl_item == NULL || buff == NULL ) return;        if( strlen( c ) )        {            sprintf( buff, "%s%c-%s", c, k == p_node->i_children - 1 ?                     '`' : '|', p_child->input.psz_name );        }        else        {            sprintf( buff, " %s", p_child->input.psz_name );        }        p_pl_item->psz_display = strdup( buff );        p_pl_item->p_item = p_child;        INSERT_ELEM( p_sys->pp_plist, p_sys->i_plist_entries,                     p_sys->i_plist_entries, p_pl_item );        free( buff );        i++;        if( p_child->i_children > 0 )        {            sprintf( psz_tmp, "%s%c ", c,                     k == p_node->i_children - 1 ? ' ' : '|' );            PlaylistAddNode( p_intf, p_child, i,                             strlen( c ) ? psz_tmp : " " );        }    }    free( psz_tmp );}static int PlaylistChanged( vlc_object_t *p_this, const char *psz_variable,                            vlc_value_t oval, vlc_value_t nval, void *param ){    intf_thread_t *p_intf = (intf_thread_t *)param;    p_intf->p_sys->b_need_update = VLC_TRUE;    return VLC_SUCCESS;}static void FindIndex( intf_thread_t *p_intf ){    intf_sys_t *p_sys = p_intf->p_sys;    int i;    if( p_sys->i_current_view == VIEW_ALL )    {         p_sys->i_box_plidx = p_sys->p_playlist->i_index;    }    else if( ( p_sys->i_box_plidx < p_sys->i_plist_entries &&               p_sys->pp_plist[p_sys->i_box_plidx]->p_item !=               p_sys->p_playlist->status.p_item ) )    {        for( i = 0; i < p_sys->i_plist_entries; i++ )        {            if( p_sys->pp_plist[i]->p_item ==                p_sys->p_playlist->status.p_item )            {                p_sys->i_box_plidx = i;                break;            }        }    }}static void PlaylistDestroy( intf_thread_t *p_intf ){    intf_sys_t *p_sys = p_intf->p_sys;    int i;    for( i = 0; i < p_sys->i_plist_entries; i++ )    {        struct pl_item_t *p_pl_item = p_sys->pp_plist[i];        free( p_pl_item->psz_display );        REMOVE_ELEM( p_sys->pp_plist, p_sys->i_plist_entries, i );        free( p_pl_item );    }    p_sys->pp_plist = NULL;    p_sys->i_plist_entries = 0;}static void Eject( intf_thread_t *p_intf ){    char *psz_device = NULL, *psz_parser, *psz_name;    /*     * Get the active input     * Determine whether we can eject a media, ie it's a DVD, VCD or CD-DA     * If it's neither of these, then return     */    playlist_t * p_playlist = vlc_object_find( p_intf, VLC_OBJECT_PLAYLIST,                                                       FIND_ANYWHERE );    if( p_playlist == NULL )    {        return;    }    vlc_mutex_lock( &p_playlist->object_lock );    if( p_playlist->i_index < 0 )    {        vlc_mutex_unlock( &p_playlist->object_lock );        vlc_object_release( p_playlist );        return;    }    psz_name = p_playlist->pp_items[ p_playlist->i_index ]->input.psz_name;    if( psz_name )    {        if( !strncmp(psz_name, "dvd://", 4) )        {            switch( psz_name[strlen("dvd://")] )            {            case '\0':            case '@':                psz_device = config_GetPsz( p_intf, "dvd" );                break;            default:                /* Omit the first MRL-selector characters */                psz_device = strdup( psz_name + strlen("dvd://" ) );                break;            }        }        else if( !strncmp(psz_name, VCD_MRL, strlen(VCD_MRL)) )        {            switch( psz_name[strlen(VCD_MRL)] )            {            case '\0':            case '@':                psz_device = config_GetPsz( p_intf, VCD_MRL );                break;            default:                /* Omit the beginning MRL-selector characters */                psz_device = strdup( psz_name + strlen(VCD_MRL) );                break;            }        }        else if( !strncmp(psz_name, CDDA_MRL, strlen(CDDA_MRL) ) )        {            switch( psz_name[strlen(CDDA_MRL)] )            {            case '\0':            case '@':                psz_device = config_GetPsz( p_intf, "cd-audio" );                break;            default:                /* Omit the beginning MRL-selector characters */                psz_device = strdup( psz_name + strlen(CDDA_MRL) );                break;            }        }        else        {            psz_device = strdup( psz_name );        }    }    vlc_mutex_unlock( &p_playlist->object_lock );    vlc_object_release( p_playlist );    if( psz_device == NULL )    {        return;    }    /* Remove what we have after @ */    psz_parser = psz_device;    for( psz_parser = psz_device ; *psz_parser ; psz_parser++ )    {        if( *psz_parser == '@' )        {            *psz_parser = '\0';            break;        }    }    /* If there's a stream playing, we aren't allowed to eject ! */    if( p_intf->p_sys->p_input == NULL )    {        msg_Dbg( p_intf, "ejecting %s", psz_device );        intf_Eject( p_intf, psz_device );    }    free(psz_device);    return;}static int comp_dir_entries( const void *pp_dir_entry1,                             const void *pp_dir_entry2 ){    struct dir_entry_t *p_dir_entry1 = *(struct dir_entry_t**)pp_dir_entry1;    struct dir_entry_t *p_dir_entry2 = *(struct dir_entry_t**)pp_dir_entry2;    if ( p_dir_entry1->b_file == p_dir_entry2->b_file ) {        return strcasecmp( p_dir_entry1->psz_path, p_dir_entry2->psz_path );    }    else     {        return ( p_dir_entry1->b_file ? 1 : -1 );    }}static void ReadDir( intf_thread_t *p_intf ){    intf_sys_t     *p_sys = p_intf->p_sys;    DIR *                       p_current_dir;    int i;    if( p_sys->psz_current_dir && *p_sys->psz_current_dir )    {        const char *psz_entry;        /* Open the dir */        p_current_dir = utf8_opendir( p_sys->psz_current_dir );        if( p_current_dir == NULL )        {            /* something went bad, get out of here ! */#ifdef HAVE_ERRNO_H            msg_Warn( p_intf, "cannot open directory `%s' (%s)",                      p_sys->psz_current_dir, strerror(errno));#else            msg_Warn( p_intf, "cannot open directory `%s'", p_sys->psz_current_dir );#endif            return;        }        /* Clean the old shit */        for( i = 0; i < p_sys->i_dir_entries; i++ )        {            struct dir_entry_t *p_dir_entry = p_sys->pp_dir_entries[i];            free( p_dir_entry->psz_path );            REMOVE_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries, i );            free( p_dir_entry );        }        p_sys->pp_dir_entries = NULL;        p_sys->i_dir_entries = 0;        /* get the first directory entry */        psz_entry = utf8_readdir( p_current_dir );        /* while we still have entries in the directory */        while( psz_entry != 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( psz_entry ) + 2;            char *psz_uri;            if( p_sys->b_show_hidden_files == VLC_FALSE &&                 ( strlen( psz_entry ) && psz_entry[0] == '.' ) &&                strcmp( psz_entry, ".." ) )            {                LocaleFree( psz_entry );                psz_entry = utf8_readdir( p_current_dir );                continue;            }            psz_uri = (char *)malloc( sizeof(char)*i_size_entry);            sprintf( psz_uri, "%s/%s", p_sys->psz_current_dir, psz_entry );            if( !( p_dir_entry = malloc( sizeof( struct dir_entry_t) ) ) )            {                free( psz_uri);                return;            }#if defined( S_ISDIR )            utf8_stat( psz_uri, &stat_data );            if( S_ISDIR(stat_data.st_mode) )/*#elif defined( DT_DIR )            if( p_dir_content->d_type & DT_DIR )*/#else            if( 0 )#endif            {                p_dir_entry->psz_path = strdup( psz_entry );                p_dir_entry->b_file = VLC_FALSE;                INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,                     p_sys->i_dir_entries, p_dir_entry );            }            else            {                p_dir_entry->psz_path = strdup( psz_entry );                p_dir_entry->b_file = VLC_TRUE;                INSERT_ELEM( p_sys->pp_dir_entries, p_sys->i_dir_entries,                     p_sys->i_dir_entries, p_dir_entry );            }            free( psz_uri );            LocaleFree( psz_entry );            /* Read next entry */            psz_entry = utf8_readdir( p_current_dir );        }        /* Sort */        qsort( p_sys->pp_dir_entries, p_sys->i_dir_entries,               sizeof(struct dir_entry_t*), &comp_dir_entries );        vlc_closedir_wrapper( p_current_dir );        return;    }    else    {        msg_Dbg( p_intf, "no current dir set" );        return;    }}static void PlayPause( intf_thread_t *p_intf ){    input_thread_t *p_input = p_intf->p_sys->p_input;    vlc_value_t val;    if( p_input )    {        var_Get( p_input, "state", &val );        if( val.i_int != PAUSE_S )        {            val.i_int = PAUSE_S;        }        else        {            val.i_int = PLAYING_S;        }        var_Set( p_input, "state", val );    }    else if( p_intf->p_sys->p_playlist )    {        playlist_Play( p_intf->p_sys->p_playlist );    }}/**************************************************************************** * ****************************************************************************/static void DrawBox( WINDOW *win, int y, int x, int h, int w, const char *title ){    int i;    int i_len;    if( w > 3 && h > 2 )    {        if( title == NULL ) title = "";        i_len = strlen( title );        if( i_len > w - 2 ) i_len = w - 2;        mvwaddch( win, y, x,    ACS_ULCORNER );        mvwhline( win, y, x+1,  ACS_HLINE, ( w-i_len-2)/2 );        mvwprintw( win,y, x+1+(w-i_len-2)/2, "%s", title );        mvwhline( win, y, x+(w-i_len)/2+i_len,  ACS_HLINE, w - 1 - ((w-i_len)/2+i_len) );        mvwaddch( win, y, x+w-1,ACS_URCORNER );        for( i = 0; i < h-2; i++ )        {            mvwaddch( win, y+i+1, x,     ACS_VLINE );            mvwaddch( win, y+i+1, x+w-1, ACS_VLINE );        }        mvwaddch( win, y+h-1, x,     ACS_LLCORNER );        mvwhline( win, y+h-1, x+1,   ACS_HLINE, w - 2 );        mvwaddch( win, y+h-1, x+w-1, ACS_LRCORNER );    }}static void DrawEmptyLine( WINDOW *win, int y, int x, int w ){    if( w > 0 )    {        mvhline( y, x, ' ', w );    }}static void DrawLine( WINDOW *win, int y, int x, int w ){    if( w > 0 )    {        attrset( A_REVERSE );        mvhline( y, x, ' ', w );        attroff( A_REVERSE );    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -