1 /*****************************************************************************
2 * item-ext.c : Playlist item management functions (act on the playlist)
3 *****************************************************************************
4 * Copyright (C) 1999-2004 the VideoLAN team
7 * Authors: Samuel Hocevar <sam@zoy.org>
8 * Clément Stenac <zorglub@videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
24 #include <stdlib.h> /* free(), strtol() */
25 #include <stdio.h> /* sprintf() */
26 #include <string.h> /* strerror() */
29 #include <vlc/input.h>
31 #include "vlc_playlist.h"
33 /***************************************************************************
34 * Item creation/addition functions
35 ***************************************************************************/
38 * Add a MRL into the playlist, duration and options given
40 * \param p_playlist the playlist to add into
41 * \param psz_uri the mrl to add to the playlist
42 * \param psz_name a text giving a name or description of this item
43 * \param i_mode the mode used when adding
44 * \param i_pos the position in the playlist where to add. If this is
45 * PLAYLIST_END the item will be added at the end of the playlist
46 * regardless of it's size
47 * \param i_duration length of the item in milliseconds.
48 * \param ppsz_options an array of options
49 * \param i_options the number of options
50 * \return The id of the playlist item
52 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
53 const char *psz_name, int i_mode, int i_pos,
54 mtime_t i_duration, const char **ppsz_options,
57 playlist_item_t *p_item;
58 p_item = playlist_ItemNew( p_playlist , psz_uri, psz_name );
62 msg_Err( p_playlist, "unable to add item to playlist" );
66 p_item->input.i_duration = i_duration;
67 p_item->input.i_options = i_options;
68 p_item->input.ppsz_options = NULL;
70 for( p_item->input.i_options = 0; p_item->input.i_options < i_options;
71 p_item->input.i_options++ )
73 if( !p_item->input.i_options )
75 p_item->input.ppsz_options = malloc( i_options * sizeof(char *) );
76 if( !p_item->input.ppsz_options ) break;
79 p_item->input.ppsz_options[p_item->input.i_options] =
80 strdup( ppsz_options[p_item->input.i_options] );
83 return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
87 * Add a MRL into the playlist.
89 * \param p_playlist the playlist to add into
90 * \param psz_uri the mrl to add to the playlist
91 * \param psz_name a text giving a name or description of this item
92 * \param i_mode the mode used when adding
93 * \param i_pos the position in the playlist where to add. If this is
94 * PLAYLIST_END the item will be added at the end of the playlist
95 * regardless of it's size
96 * \return The id of the playlist item
98 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
99 const char *psz_name, int i_mode, int i_pos )
101 return playlist_AddExt( p_playlist, psz_uri, psz_name, i_mode, i_pos,
106 * Add a playlist item into a playlist
108 * \param p_playlist the playlist to insert into
109 * \param p_item the playlist item to insert
110 * \param i_mode the mode used when adding
111 * \param i_pos the possition in the playlist where to add. If this is
112 * PLAYLIST_END the item will be added at the end of the playlist
113 * regardless of it's size
114 * \return The id of the playlist item
116 int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
117 int i_mode, int i_pos)
120 vlc_bool_t b_end = VLC_FALSE;
121 playlist_view_t *p_view = NULL;
123 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
125 vlc_mutex_lock( &p_playlist->object_lock );
128 * CHECK_INSERT : checks if the item is already enqued before
132 /* That should not change */
133 if ( i_mode & PLAYLIST_CHECK_INSERT )
137 if ( p_playlist->pp_items )
139 for ( j = 0; j < p_playlist->i_size; j++ )
141 if ( !strcmp( p_playlist->pp_items[j]->input.psz_uri,
142 p_item->input.psz_uri ) )
144 playlist_ItemDelete( p_item );
145 vlc_mutex_unlock( &p_playlist->object_lock );
150 i_mode &= ~PLAYLIST_CHECK_INSERT;
151 i_mode |= PLAYLIST_APPEND;
154 msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )",
155 p_item->input.psz_name, p_item->input.psz_uri );
157 p_item->input.i_id = ++p_playlist->i_last_id;
159 /* Do a few boundary checks and allocate space for the item */
160 if( i_pos == PLAYLIST_END )
163 if( i_mode & PLAYLIST_INSERT )
165 i_mode &= ~PLAYLIST_INSERT;
166 i_mode |= PLAYLIST_APPEND;
169 i_pos = p_playlist->i_size - 1;
172 if( !(i_mode & PLAYLIST_REPLACE)
173 || i_pos < 0 || i_pos >= p_playlist->i_size )
175 /* Additional boundary checks */
176 if( i_mode & PLAYLIST_APPEND )
185 else if( i_pos > p_playlist->i_size )
187 i_pos = p_playlist->i_size;
190 INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size, i_pos, p_item );
191 INSERT_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
192 p_playlist->i_all_size, p_item );
193 p_playlist->i_enabled ++;
195 /* We update the ALL view directly */
196 playlist_ViewUpdate( p_playlist, VIEW_ALL );
198 /* Add the item to the General category */
199 if( b_end == VLC_TRUE )
201 playlist_NodeAppend( p_playlist, VIEW_CATEGORY, p_item,
202 p_playlist->p_general );
203 p_add->i_item = p_item->input.i_id;
204 p_add->i_node = p_playlist->p_general->input.i_id;
205 p_add->i_view = VIEW_CATEGORY;
206 val.p_address = p_add;
207 var_Set( p_playlist, "item-append", val );
211 playlist_NodeInsert( p_playlist, VIEW_CATEGORY, p_item,
212 p_playlist->p_general, i_pos );
216 p_view = playlist_ViewFind( p_playlist, VIEW_ALL );
217 playlist_ItemAddParent( p_item, VIEW_ALL, p_view->p_root );
219 /* FIXME : Update sorted views */
221 if( p_playlist->i_index >= i_pos )
223 p_playlist->i_index++;
228 msg_Err( p_playlist, "Insert mode not implemented" );
231 if( (i_mode & PLAYLIST_GO ) && p_view )
233 p_playlist->request.b_request = VLC_TRUE;
235 p_playlist->request.i_view = VIEW_CATEGORY;
236 p_playlist->request.p_node = p_view->p_root;
237 p_playlist->request.p_item = p_item;
239 if( p_playlist->p_input )
241 input_StopThread( p_playlist->p_input );
243 p_playlist->status.i_status = PLAYLIST_RUNNING;
246 if( i_mode & PLAYLIST_PREPARSE &&
247 var_CreateGetBool( p_playlist, "auto-preparse" ) )
249 playlist_PreparseEnqueue( p_playlist, &p_item->input );
252 vlc_mutex_unlock( &p_playlist->object_lock );
254 if( b_end == VLC_FALSE )
256 val.b_bool = VLC_TRUE;
257 var_Set( p_playlist, "intf-change", val );
262 return p_item->input.i_id;
267 * Add a playlist item to a given node (in the category view )
269 * \param p_playlist the playlist to insert into
270 * \param p_item the playlist item to insert
271 * \param i_view the view for which to add or TODO: ALL_VIEWS
272 * \param p_parent the parent node
273 * \param i_mode the mode used when adding
274 * \param i_pos the possition in the node where to add. If this is
275 * PLAYLIST_END the item will be added at the end of the node
276 ** \return The id of the playlist item
278 int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
279 int i_view,playlist_item_t *p_parent,
280 int i_mode, int i_pos)
284 playlist_view_t *p_view;
286 playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
288 vlc_mutex_lock( &p_playlist->object_lock );
290 if ( i_pos == PLAYLIST_END ) i_pos = -1;
293 if( !p_parent || p_parent->i_children == -1 )
295 msg_Err( p_playlist, "invalid node" );
299 * CHECK_INSERT : checks if the item is already enqued before
302 if ( i_mode & PLAYLIST_CHECK_INSERT )
306 if ( p_playlist->pp_items )
308 for ( j = 0; j < p_playlist->i_size; j++ )
310 if ( !strcmp( p_playlist->pp_items[j]->input.psz_uri,
311 p_item->input.psz_uri ) )
313 playlist_ItemDelete( p_item );
314 vlc_mutex_unlock( &p_playlist->object_lock );
320 i_mode &= ~PLAYLIST_CHECK_INSERT;
321 i_mode |= PLAYLIST_APPEND;
324 msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )",
325 p_item->input.psz_name, p_item->input.psz_uri );
327 p_item->input.i_id = ++p_playlist->i_last_id;
329 /* First, add the item at the right position in the item bank */
331 //i_position = p_playlist->i_index == -1 ? 0 : p_playlist->i_index;
332 i_position = p_playlist->i_size ;
334 INSERT_ELEM( p_playlist->pp_items,
338 INSERT_ELEM( p_playlist->pp_all_items,
339 p_playlist->i_all_size,
340 p_playlist->i_all_size,
342 p_playlist->i_enabled ++;
344 /* TODO: Handle modes */
345 playlist_NodeInsert( p_playlist, i_view, p_item, p_parent, i_pos );
347 p_add->i_item = p_item->input.i_id;
348 p_add->i_node = p_parent->input.i_id;
349 p_add->i_view = i_view;
350 val.p_address = p_add;
351 var_Set( p_playlist, "item-append", val );
353 /* We update the ALL view directly */
354 p_view = playlist_ViewFind( p_playlist, VIEW_ALL );
355 playlist_ItemAddParent( p_item, VIEW_ALL, p_view->p_root );
356 playlist_ViewUpdate( p_playlist, VIEW_ALL );
358 /* TODO : Update sorted views*/
360 if( i_mode & PLAYLIST_GO )
362 p_playlist->request.b_request = VLC_TRUE;
363 p_playlist->request.i_view = VIEW_CATEGORY;
364 p_playlist->request.p_node = p_parent;
365 p_playlist->request.p_item = p_item;
366 if( p_playlist->p_input )
368 input_StopThread( p_playlist->p_input );
370 p_playlist->status.i_status = PLAYLIST_RUNNING;
372 if( i_mode & PLAYLIST_PREPARSE &&
373 var_CreateGetBool( p_playlist, "auto-preparse" ) )
375 playlist_PreparseEnqueue( p_playlist, &p_item->input );
378 vlc_mutex_unlock( &p_playlist->object_lock );
380 val.b_bool = VLC_TRUE;
381 // var_Set( p_playlist, "intf-change", val );
385 return p_item->input.i_id;
388 /***************************************************************************
389 * Item search functions
390 ***************************************************************************/
393 * Search the position of an item by its id
394 * This function must be entered with the playlist lock
396 * \param p_playlist the playlist
397 * \param i_id the id to find
398 * \return the position, or VLC_EGENERIC on failure
400 int playlist_GetPositionById( playlist_t * p_playlist , int i_id )
403 for( i = 0 ; i < p_playlist->i_size ; i++ )
405 if( p_playlist->pp_items[i]->input.i_id == i_id )
415 * Search an item by its position
416 * This function must be entered with the playlist lock
418 * \param p_playlist the playlist
419 * \param i_pos the position of the item to find
420 * \return the item, or NULL on failure
422 playlist_item_t * playlist_ItemGetByPos( playlist_t * p_playlist , int i_pos )
424 if( i_pos >= 0 && i_pos < p_playlist->i_size)
426 return p_playlist->pp_items[i_pos];
428 else if( p_playlist->i_size > 0)
430 return p_playlist->pp_items[p_playlist->i_index];
438 playlist_item_t *playlist_LockItemGetByPos( playlist_t *p_playlist, int i_pos )
440 playlist_item_t *p_ret;
441 vlc_mutex_lock( &p_playlist->object_lock );
442 p_ret = playlist_ItemGetByPos( p_playlist, i_pos );
443 vlc_mutex_unlock( &p_playlist->object_lock );
448 * Search an item by its id
450 * \param p_playlist the playlist
451 * \param i_id the id to find
452 * \return the item, or NULL on failure
454 playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
456 int i, i_top, i_bottom;
457 i_bottom = 0; i_top = p_playlist->i_all_size - 1;
459 while( p_playlist->pp_all_items[i]->input.i_id != i_id &&
462 if( p_playlist->pp_all_items[i]->input.i_id < i_id )
470 i = i_bottom + ( i_top - i_bottom ) / 2;
472 if( p_playlist->pp_all_items[i]->input.i_id == i_id )
474 return p_playlist->pp_all_items[i];
479 playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist, int i_id)
481 playlist_item_t *p_ret;
482 vlc_mutex_lock( &p_playlist->object_lock );
483 p_ret = playlist_ItemGetById( p_playlist, i_id );
484 vlc_mutex_unlock( &p_playlist->object_lock );
489 * Search an item by its input_item_t
491 * \param p_playlist the playlist
492 * \param p_item the input_item_t to find
493 * \return the item, or NULL on failure
495 playlist_item_t * playlist_ItemGetByInput( playlist_t * p_playlist ,
496 input_item_t *p_item )
499 if( &p_playlist->status.p_item->input == p_item )
501 return p_playlist->status.p_item;
504 for( i = 0 ; i < p_playlist->i_size ; i++ )
506 if( &p_playlist->pp_items[i]->input == p_item )
508 return p_playlist->pp_items[i];
514 playlist_item_t *playlist_LockItemGetByInput( playlist_t *p_playlist,
515 input_item_t *p_item )
517 playlist_item_t *p_ret;
518 vlc_mutex_lock( &p_playlist->object_lock );
519 p_ret = playlist_ItemGetByInput( p_playlist, p_item );
520 vlc_mutex_unlock( &p_playlist->object_lock );
525 /***********************************************************************
527 ***********************************************************************/
530 * Transform an item to a node
532 * This function must be entered without the playlist lock
534 * \param p_playlist the playlist object
535 * \param p_item the item to transform
538 int playlist_ItemToNode( playlist_t *p_playlist,playlist_item_t *p_item )
541 if( p_item->i_children == -1 )
543 p_item->i_children = 0;
546 /* Remove it from the array of available items */
547 for( i = 0 ; i < p_playlist->i_size ; i++ )
549 if( p_item == p_playlist->pp_items[i] )
551 REMOVE_ELEM( p_playlist->pp_items, p_playlist->i_size, i );
554 var_SetInteger( p_playlist, "item-change", p_item->input.i_id );
559 int playlist_LockItemToNode( playlist_t *p_playlist, playlist_item_t *p_item )
562 vlc_mutex_lock( &p_playlist->object_lock );
563 i_ret = playlist_ItemToNode( p_playlist, p_item );
564 vlc_mutex_unlock( &p_playlist->object_lock );
569 * Replaces an item with another one
570 * This function must be entered without the playlist lock
572 * \see playlist_Replace
574 int playlist_LockReplace( playlist_t *p_playlist,
575 playlist_item_t *p_olditem,
576 input_item_t *p_new )
579 vlc_mutex_lock( &p_playlist->object_lock );
580 i_ret = playlist_Replace( p_playlist, p_olditem, p_new );
581 vlc_mutex_unlock( &p_playlist->object_lock );
586 * Replaces an item with another one
587 * This function must be entered with the playlist lock:
589 * \param p_playlist the playlist
590 * \param p_olditem the item to replace
591 * \param p_new the new input_item
592 * \return VLC_SUCCESS or an error
594 int playlist_Replace( playlist_t *p_playlist, playlist_item_t *p_olditem,
595 input_item_t *p_new )
600 if( p_olditem->i_children != -1 )
602 msg_Err( p_playlist, "playlist_Replace can only be used on leafs");
606 p_olditem->i_nb_played = 0;
607 memcpy( &p_olditem->input, p_new, sizeof( input_item_t ) );
609 p_olditem->i_nb_played = 0;
611 for( i = 0 ; i< p_olditem->i_parents ; i++ )
613 playlist_item_t *p_parent = p_olditem->pp_parents[i]->p_parent;
615 for( j = 0 ; j< p_parent->i_children ; i++ )
617 if( p_parent->pp_children[j] == p_olditem )
619 p_parent->i_serial++;
627 * Deletes an item from a playlist.
629 * This function must be entered without the playlist lock
631 * \param p_playlist the playlist to remove from.
632 * \param i_id the identifier of the item to delete
633 * \return returns VLC_SUCCESS or an error
635 int playlist_Delete( playlist_t * p_playlist, int i_id )
637 int i, i_top, i_bottom;
639 vlc_bool_t b_flag = VLC_FALSE;
641 playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
647 if( p_item->i_children > -1 )
649 return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
652 var_SetInteger( p_playlist, "item-deleted", i_id );
654 i_bottom = 0; i_top = p_playlist->i_all_size - 1;
656 while( p_playlist->pp_all_items[i]->input.i_id != i_id &&
659 if( p_playlist->pp_all_items[i]->input.i_id < i_id )
667 i = i_bottom + ( i_top - i_bottom ) / 2;
669 if( p_playlist->pp_all_items[i]->input.i_id == i_id )
671 REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size, i );
674 /* Check if it is the current item */
675 if( p_playlist->status.p_item == p_item )
677 /* Hack we don't call playlist_Control for lock reasons */
678 p_playlist->status.i_status = PLAYLIST_STOPPED;
679 p_playlist->request.b_request = VLC_TRUE;
680 p_playlist->request.p_item = NULL;
681 msg_Info( p_playlist, "stopping playback" );
685 /* Get position and update index if needed */
686 i_pos = playlist_GetPositionById( p_playlist, i_id );
688 if( i_pos >= 0 && i_pos <= p_playlist->i_index )
690 p_playlist->i_index--;
693 msg_Dbg( p_playlist, "deleting playlist item `%s'",
694 p_item->input.psz_name );
696 /* Remove the item from all its parent nodes */
697 for ( i= 0 ; i < p_item->i_parents ; i++ )
699 playlist_NodeRemoveItem( p_playlist, p_item,
700 p_item->pp_parents[i]->p_parent );
701 if( p_item->pp_parents[i]->i_view == VIEW_ALL )
703 p_playlist->i_size--;
707 /* TODO : Update views */
709 if( b_flag == VLC_FALSE )
710 playlist_ItemDelete( p_item );
712 p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
717 int playlist_LockDelete( playlist_t * p_playlist, int i_id )
720 vlc_mutex_lock( &p_playlist->object_lock );
721 i_ret = playlist_Delete( p_playlist, i_id );
722 vlc_mutex_unlock( &p_playlist->object_lock );
727 * Clear all playlist items
729 * \param p_playlist the playlist to be cleared.
732 int playlist_Clear( playlist_t * p_playlist )
735 for( i = p_playlist->i_size; i > 0 ; i-- )
737 playlist_Delete( p_playlist, p_playlist->pp_items[0]->input.i_id );
739 for( i = 0 ; i< p_playlist->i_views; i++ )
741 playlist_ViewEmpty( p_playlist, i, VLC_TRUE );
746 int playlist_LockClear( playlist_t *p_playlist )
749 vlc_mutex_lock( &p_playlist->object_lock );
750 i_ret = playlist_Clear( p_playlist );
751 vlc_mutex_unlock( &p_playlist->object_lock );
757 * Disables a playlist item
759 * \param p_playlist the playlist to disable from.
760 * \param i_pos the position of the item to disable
763 int playlist_Disable( playlist_t * p_playlist, playlist_item_t *p_item )
765 if( !p_item ) return VLC_EGENERIC;
767 msg_Dbg( p_playlist, "disabling playlist item `%s'",
768 p_item->input.psz_name );
770 if( p_item->i_flags & PLAYLIST_ENA_FLAG )
772 p_playlist->i_enabled--;
774 p_item->i_flags &= ~PLAYLIST_ENA_FLAG;
776 var_SetInteger( p_playlist, "item-change", p_item->input.i_id );
781 * Enables a playlist item
783 * \param p_playlist the playlist to enable from.
784 * \param i_pos the position of the item to enable
787 int playlist_Enable( playlist_t * p_playlist, playlist_item_t *p_item )
789 if( !p_item ) return VLC_EGENERIC;
791 msg_Dbg( p_playlist, "enabling playlist item `%s'",
792 p_item->input.psz_name );
794 if( p_item->i_flags & ~PLAYLIST_ENA_FLAG )
796 p_playlist->i_enabled++;
798 p_item->i_flags |= PLAYLIST_ENA_FLAG;
800 var_SetInteger( p_playlist, "item-change", p_item->input.i_id );
805 * Move an item in a playlist
807 * This function must be entered without the playlist lock
809 * Move the item in the playlist with position i_pos before the current item
810 * at position i_newpos.
811 * \param p_playlist the playlist to move items in
812 * \param i_pos the position of the item to move
813 * \param i_newpos the position of the item that will be behind the moved item
815 * \return returns VLC_SUCCESS
817 int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos )
820 vlc_mutex_lock( &p_playlist->object_lock );
822 /* take into account that our own row disappears. */
823 if( i_pos < i_newpos ) i_newpos--;
825 if( i_pos >= 0 && i_newpos >=0 && i_pos <= p_playlist->i_size &&
826 i_newpos <= p_playlist->i_size )
828 playlist_item_t * temp;
830 msg_Dbg( p_playlist, "moving playlist item `%s' (%i -> %i)",
831 p_playlist->pp_items[i_pos]->input.psz_name, i_pos, i_newpos);
833 if( i_pos == p_playlist->i_index )
835 p_playlist->i_index = i_newpos;
837 else if( i_pos > p_playlist->i_index &&
838 i_newpos <= p_playlist->i_index )
840 p_playlist->i_index++;
842 else if( i_pos < p_playlist->i_index &&
843 i_newpos >= p_playlist->i_index )
845 p_playlist->i_index--;
848 if ( i_pos < i_newpos )
850 temp = p_playlist->pp_items[i_pos];
851 while ( i_pos < i_newpos )
853 p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos+1];
856 p_playlist->pp_items[i_newpos] = temp;
858 else if ( i_pos > i_newpos )
860 temp = p_playlist->pp_items[i_pos];
861 while ( i_pos > i_newpos )
863 p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos-1];
866 p_playlist->pp_items[i_newpos] = temp;
870 vlc_mutex_unlock( &p_playlist->object_lock );
872 val.b_bool = VLC_TRUE;
873 var_Set( p_playlist, "intf-change", val );
881 * This function must be entered with the playlist lock
883 * \param p_playlist the playlist
884 * \param p_item the item to move
885 * \param p_node the new parent of the item
886 * \param i_newpos the new position under this new parent
887 * \param i_view the view in which the move must be done or ALL_VIEWS
888 * \return VLC_SUCCESS or an error
890 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
891 playlist_item_t *p_node, int i_newpos, int i_view )
894 playlist_item_t *p_detach = NULL;
895 struct item_parent_t *p_parent;
897 if( p_node->i_children == -1 ) return VLC_EGENERIC;
899 /* Detach from the parent */
900 for( i = 0 ; i< p_item->i_parents; i++ )
902 if( p_item->pp_parents[i]->i_view == i_view )
905 p_detach = p_item->pp_parents[i]->p_parent;
906 for( j = 0; j < p_detach->i_children; j++ )
908 if( p_detach->pp_children[j] == p_item ) break;
910 REMOVE_ELEM( p_detach->pp_children, p_detach->i_children, j );
911 p_detach->i_serial++;
912 free( p_item->pp_parents[i] );
913 REMOVE_ELEM( p_item->pp_parents, p_item->i_parents, i );
918 /* Attach to new parent */
919 INSERT_ELEM( p_node->pp_children, p_node->i_children, i_newpos, p_item );
921 p_parent = malloc( sizeof( struct item_parent_t ) );
922 p_parent->p_parent = p_node;
923 p_parent->i_view = i_view;
925 INSERT_ELEM( p_item->pp_parents, p_item->i_parents, p_item->i_parents,