📄 view.c
字号:
int playlist_NodeRemoveItem( playlist_t *p_playlist, playlist_item_t *p_item, playlist_item_t *p_parent ){ int i; if( !p_parent || p_parent->i_children == -1 ) { msg_Err( p_playlist, "invalid node" ); } for( i= 0; i< p_parent->i_children ; i++ ) { if( p_parent->pp_children[i] == p_item ) { REMOVE_ELEM( p_parent->pp_children, p_parent->i_children, i ); } } /* Let the interface know this has been updated */ p_parent->i_serial++; return VLC_SUCCESS;}/** * Count the children of a node * * \param p_playlist the playlist * \param p_node the node * \return the number of children */int playlist_NodeChildrenCount( playlist_t *p_playlist, playlist_item_t*p_node){ int i; int i_nb = 0; if( p_node->i_children == -1 ) { return 0; } for( i=0 ; i< p_node->i_children;i++ ) { if( p_node->pp_children[i]->i_children == -1 ) { i_nb++; } else { i_nb += playlist_NodeChildrenCount( p_playlist, p_node->pp_children[i] ); } } return i_nb;}/** * Search a child of a node by its name * * \param p_node the node * \param psz_search the name of the child to search * \return the child item or NULL if not found or error */playlist_item_t *playlist_ChildSearchName( playlist_item_t *p_node, const char *psz_search ){ int i; if( p_node->i_children < 0 ) { return NULL; } for( i = 0 ; i< p_node->i_children; i++ ) { if( !strcmp( p_node->pp_children[i]->input.psz_name, psz_search ) ) { return p_node->pp_children[i]; } } return NULL;}/********************************************************************** * Tree functions **********************************************************************//** * Finds the next item to play * * \param p_playlist the playlist * \param i_view the view * \param p_root the root node * \param p_node the node we are playing from * \param p_item the item we were playing (NULL if none ) * \return the next item to play, or NULL if none found */playlist_item_t *playlist_FindNextFromParent( playlist_t *p_playlist, int i_view, /* FIXME: useless */ playlist_item_t *p_root, playlist_item_t *p_node, playlist_item_t *p_item ){ playlist_item_t *p_search, *p_next;#ifdef PLAYLIST_DEBUG if( p_item != NULL ) { msg_Dbg( p_playlist, "finding next of %s within %s - root %s", p_item->input.psz_name, p_node->input.psz_name, p_root->input.psz_name ); } else { msg_Dbg( p_playlist, "finding something to play within %s -root %s", p_node->input.psz_name, p_root->input.psz_name ); msg_Dbg( p_playlist, "%s has %i children", p_node->input.psz_name, p_node->i_children ); }#endif if( !p_node || p_node->i_children == -1 ) { msg_Err( p_playlist,"invalid arguments for FindNextFromParent" ); return NULL; } /* Find the parent node of the item */ if( p_item != NULL ) { p_search = playlist_FindDirectParent( p_playlist, p_item, i_view ); if( p_search == NULL ) { msg_Err( p_playlist, "parent node not found" ); return NULL; } } else { p_search = p_node; } /* Now, go up the tree until we find a suitable next item */ p_next = playlist_RecursiveFindNext( p_playlist,i_view, p_node, p_item, p_search ); /* Not found, do we go past p_node ? */ if( p_next == NULL ) { if( p_playlist->b_go_next ) {#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "Moving on to next node: search from %s", p_root->input.psz_name );#endif p_next = playlist_RecursiveFindNext( p_playlist, i_view, p_root, p_item, p_search ); if( p_next == NULL ) { return NULL; } /* OK, we could continue, so set our current node to the root */ p_playlist->status.p_node = p_root; } else {#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "Not moving on to next node: you loose" );#endif return NULL; } } return p_next;}/** * Finds the previous item to play * * \param p_playlist the playlist * \param i_view the view * \param p_root the root node * \param p_node the node we are playing from * \param p_item the item we were playing (NULL if none ) * \return the next item to play, or NULL if none found */playlist_item_t *playlist_FindPrevFromParent( playlist_t *p_playlist, int i_view, playlist_item_t *p_root, playlist_item_t *p_node, playlist_item_t *p_item ){ playlist_item_t *p_search, *p_next;#ifdef PLAYLIST_DEBUG if( p_item != NULL ) { msg_Dbg( p_playlist, "Finding prev of %s within %s", p_item->input.psz_name, p_node->input.psz_name ); } else { msg_Dbg( p_playlist, "Finding prev from %s",p_node->input.psz_name ); }#endif if( !p_node || p_node->i_children == -1 ) { msg_Err( p_playlist,"invalid arguments for FindPrevFromParent" ); return NULL; } /* Find the parent node of the item */ if( p_item != NULL ) { p_search = playlist_FindDirectParent( p_playlist, p_item, i_view ); if( p_search == NULL ) { msg_Err( p_playlist, "parent node not found" ); return NULL; } } else { p_search = p_node; } /* Now, go up the tree until we find a suitable next item */ p_next = playlist_RecursiveFindPrev( p_playlist,i_view, p_node, p_item, p_search ); if( p_next == NULL ) { if( p_playlist->b_go_next ) { p_next = playlist_RecursiveFindPrev( p_playlist, i_view, p_root, p_item, p_search ); if( p_next == NULL ) { return NULL; } /* OK, we could continue, so set our current node to the root */ p_playlist->status.p_node = p_root; } else { return NULL; } } return p_next;}/************************************************************************ * Following functions are local ***********************************************************************//* Recursively search the tree for next item */playlist_item_t *playlist_RecursiveFindNext( playlist_t *p_playlist, int i_view, playlist_item_t *p_root, playlist_item_t *p_item, playlist_item_t *p_parent ){ int i; playlist_item_t *p_parent_parent; for( i= 0 ; i < p_parent->i_children ; i++ ) { if( p_parent->pp_children[i] == p_item || p_item == NULL ) { if( p_item == NULL ) { i = -1; }#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist,"Current item found, child %i of %s", i , p_parent->input.psz_name );#endif /* We found our item */ if( i+1 >= p_parent->i_children ) { /* Too far... */#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "Going up the tree,at parent of %s", p_parent->input.psz_name );#endif if( p_parent == p_root ) {#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "At root item (%s)", p_root->input.psz_name );#endif /* Hmm, seems it's the end for you, guy ! */ return NULL; } /* Go up one level */ p_parent_parent = playlist_FindDirectParent( p_playlist, p_parent, i_view ); if( p_parent_parent == NULL ) { msg_Warn( p_playlist, "Unable to find parent !"); return NULL; } return playlist_RecursiveFindNext( p_playlist, i_view,p_root, p_parent, p_parent_parent ); } else { if( p_parent->pp_children[i+1]->i_children == -1 ) { /* Cool, we have found a real item to play */#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "Playing child %i of %s", i+1 , p_parent->input.psz_name );#endif return p_parent->pp_children[i+1]; } else if( p_parent->pp_children[i+1]->i_children > 0 ) { /* Select the first child of this node */#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "%s is a node with children, " "playing the first", p_parent->pp_children[i+1]->input.psz_name);#endif if( p_parent->pp_children[i+1]->pp_children[0] ->i_children >= 0 ) { /* first child is a node ! */ return playlist_RecursiveFindNext( p_playlist, i_view, p_root, NULL , p_parent->pp_children[i+1]->pp_children[0]); } return p_parent->pp_children[i+1]->pp_children[0]; } else { /* This node has no child... We must continue */#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "%s is a node with no children", p_parent->pp_children[i+1]->input.psz_name);#endif p_item = p_parent->pp_children[i+1]; } } } } /* Just in case :) */ return NULL;}/* Recursively search the tree for previous item */playlist_item_t *playlist_RecursiveFindPrev( playlist_t *p_playlist, int i_view, playlist_item_t *p_root, playlist_item_t *p_item, playlist_item_t *p_parent ){ int i; playlist_item_t *p_parent_parent; for( i= p_parent->i_children - 1 ; i >= 0 ; i-- ) { if( p_parent->pp_children[i] == p_item || p_item == NULL ) { if( p_item == NULL ) { i = -1; }#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist,"Current item found, child %i of %s", i , p_parent->input.psz_name );#endif /* We found our item */ if( i < 1 ) { /* Too far... */#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "Going up the tree,at parent of %s", p_parent->input.psz_name );#endif if( p_parent == p_root ) {#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "At root item (%s)", p_root->input.psz_name );#endif /* Hmm, seems it's the end for you, guy ! */ return NULL; } /* Go up one level */ p_parent_parent = playlist_FindDirectParent( p_playlist, p_parent, i_view ); if( p_parent_parent == NULL ) {#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "Mmmh, couldn't find parent" );#endif return NULL; } return playlist_RecursiveFindPrev( p_playlist, i_view,p_root, p_parent, p_parent_parent ); } else { if( p_parent->pp_children[i-1]->i_children == -1 ) { /* Cool, we have found a real item to play */#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "Playing child %i of %s", i-1, p_parent->input.psz_name );#endif return p_parent->pp_children[i-1]; } else if( p_parent->pp_children[i-1]->i_children > 0 ) { /* Select the last child of this node */#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "%s is a node with children," " playing the last", p_parent->pp_children[i-1]->input.psz_name);#endif if( p_parent->pp_children[i-1]->pp_children[p_parent-> pp_children[i-1]->i_children-1]->i_children >= 0 ) { /* Last child is a node */ return playlist_RecursiveFindPrev( p_playlist, i_view, p_root,NULL, p_parent->pp_children[i-1]->pp_children[ p_parent->pp_children[i-1]->i_children-1]); } return p_parent->pp_children[i-1]->pp_children[ p_parent->pp_children[i-1]->i_children-1]; } else { /* This node has no child... We must continue */#ifdef PLAYLIST_DEBUG msg_Dbg( p_playlist, "%s is a node with no children", p_parent->pp_children[i-1]->input.psz_name);#endif p_item = p_parent->pp_children[i-1]; } } } } return NULL;}/* This function returns the parent of an item in a view */playlist_item_t *playlist_FindDirectParent( playlist_t *p_playlist, playlist_item_t *p_item, int i_view ){ int i = 0; for( i= 0; i< p_item->i_parents ; i++ ) { if( p_item->pp_parents[i]->i_view == i_view ) { return p_item->pp_parents[i]->p_parent; } } return NULL;}#ifdef PLAYLIST_DEBUG/* This function dumps a node : to be used only for debug*/void playlist_NodeDump( playlist_t *p_playlist, playlist_item_t *p_item, int i_level ){ char str[512]; int i; if( i_level == 1 ) { msg_Dbg( p_playlist, "%s (%i)", p_item->input.psz_name, p_item->i_children ); } if( p_item->i_children == -1 ) { return; } for( i = 0; i< p_item->i_children; i++ ) { memset( str, 32, 512 ); sprintf( str + 2 * i_level , "%s (%i)", p_item->pp_children[i]->input.psz_name, p_item->pp_children[i]->i_children ); msg_Dbg( p_playlist, "%s",str ); if( p_item->pp_children[i]->i_children >= 0 ) { playlist_NodeDump( p_playlist, p_item->pp_children[i], i_level + 1 ); } } return;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -