Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

item-ext.c

00001 /*****************************************************************************
00002  * item-ext.c : Playlist item management functions (act on the playlist)
00003  *****************************************************************************
00004  * Copyright (C) 1999-2004 the VideoLAN team
00005  * $Id: item-ext.c 12493 2005-09-08 18:18:54Z bigben $
00006  *
00007  * Authors: Samuel Hocevar <[email protected]>
00008  *          Clément Stenac <[email protected]>
00009  *
00010  * This program is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * This program is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
00023  *****************************************************************************/
00024 #include <stdlib.h>                                      /* free(), strtol() */
00025 #include <stdio.h>                                              /* sprintf() */
00026 #include <string.h>                                            /* strerror() */
00027 
00028 #include <vlc/vlc.h>
00029 #include <vlc/input.h>
00030 
00031 #include "vlc_playlist.h"
00032 
00033 /***************************************************************************
00034  * Item creation/addition functions
00035  ***************************************************************************/
00036 
00052 int playlist_AddExt( playlist_t *p_playlist, const char * psz_uri,
00053                      const char *psz_name, int i_mode, int i_pos,
00054                      mtime_t i_duration, const char **ppsz_options,
00055                      int i_options )
00056 {
00057     playlist_item_t *p_item;
00058     p_item = playlist_ItemNew( p_playlist , psz_uri, psz_name );
00059 
00060     if( p_item == NULL )
00061     {
00062         msg_Err( p_playlist, "unable to add item to playlist" );
00063         return -1;
00064     }
00065 
00066     p_item->input.i_duration = i_duration;
00067     p_item->input.i_options = i_options;
00068     p_item->input.ppsz_options = NULL;
00069 
00070     for( p_item->input.i_options = 0; p_item->input.i_options < i_options;
00071          p_item->input.i_options++ )
00072     {
00073         if( !p_item->input.i_options )
00074         {
00075             p_item->input.ppsz_options = malloc( i_options * sizeof(char *) );
00076             if( !p_item->input.ppsz_options ) break;
00077         }
00078 
00079         p_item->input.ppsz_options[p_item->input.i_options] =
00080             strdup( ppsz_options[p_item->input.i_options] );
00081     }
00082 
00083     return playlist_AddItem( p_playlist, p_item, i_mode, i_pos );
00084 }
00085 
00098 int playlist_Add( playlist_t *p_playlist, const char *psz_uri,
00099                   const char *psz_name, int i_mode, int i_pos )
00100 {
00101     return playlist_AddExt( p_playlist, psz_uri, psz_name, i_mode, i_pos,
00102                             -1, NULL, 0 );
00103 }
00104 
00116 int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
00117                       int i_mode, int i_pos)
00118 {
00119     vlc_value_t val;
00120     vlc_bool_t b_end = VLC_FALSE;
00121     playlist_view_t *p_view = NULL;
00122 
00123     playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
00124 
00125     vlc_mutex_lock( &p_playlist->object_lock );
00126 
00127     /*
00128      * CHECK_INSERT : checks if the item is already enqued before
00129      * enqueing it
00130      */
00131 
00132     /* That should not change */
00133     if ( i_mode & PLAYLIST_CHECK_INSERT )
00134     {
00135          int j;
00136 
00137         if ( p_playlist->pp_items )
00138         {
00139             for ( j = 0; j < p_playlist->i_size; j++ )
00140             {
00141                 if ( !strcmp( p_playlist->pp_items[j]->input.psz_uri,
00142                                p_item->input.psz_uri ) )
00143                 {
00144                     playlist_ItemDelete( p_item );
00145                     vlc_mutex_unlock( &p_playlist->object_lock );
00146                     return -1;
00147                 }
00148              }
00149          }
00150          i_mode &= ~PLAYLIST_CHECK_INSERT;
00151          i_mode |= PLAYLIST_APPEND;
00152     }
00153 
00154     msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )",
00155              p_item->input.psz_name, p_item->input.psz_uri );
00156 
00157     p_item->input.i_id = ++p_playlist->i_last_id;
00158 
00159     /* Do a few boundary checks and allocate space for the item */
00160     if( i_pos == PLAYLIST_END )
00161     {
00162         b_end = VLC_TRUE;
00163         if( i_mode & PLAYLIST_INSERT )
00164         {
00165             i_mode &= ~PLAYLIST_INSERT;
00166             i_mode |= PLAYLIST_APPEND;
00167         }
00168 
00169         i_pos = p_playlist->i_size - 1;
00170     }
00171 
00172     if( !(i_mode & PLAYLIST_REPLACE)
00173          || i_pos < 0 || i_pos >= p_playlist->i_size )
00174     {
00175         /* Additional boundary checks */
00176         if( i_mode & PLAYLIST_APPEND )
00177         {
00178             i_pos++;
00179         }
00180 
00181         if( i_pos < 0 )
00182         {
00183             i_pos = 0;
00184         }
00185         else if( i_pos > p_playlist->i_size )
00186         {
00187             i_pos = p_playlist->i_size;
00188         }
00189 
00190         INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size, i_pos, p_item );
00191         INSERT_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size,
00192                      p_playlist->i_all_size, p_item );
00193         p_playlist->i_enabled ++;
00194 
00195         /* We update the ALL view directly */
00196         playlist_ViewUpdate( p_playlist, VIEW_ALL );
00197 
00198         /* Add the item to the General category */
00199         if( b_end == VLC_TRUE )
00200         {
00201             playlist_NodeAppend( p_playlist, VIEW_CATEGORY, p_item,
00202                                  p_playlist->p_general );
00203             p_add->i_item = p_item->input.i_id;
00204             p_add->i_node = p_playlist->p_general->input.i_id;
00205             p_add->i_view = VIEW_CATEGORY;
00206             val.p_address = p_add;
00207             var_Set( p_playlist, "item-append", val );
00208         }
00209         else
00210         {
00211             playlist_NodeInsert( p_playlist, VIEW_CATEGORY, p_item,
00212                                  p_playlist->p_general, i_pos );
00213         }
00214 
00215 
00216         p_view = playlist_ViewFind( p_playlist, VIEW_ALL );
00217         playlist_ItemAddParent( p_item, VIEW_ALL, p_view->p_root );
00218 
00219         /* FIXME : Update sorted views */
00220 
00221         if( p_playlist->i_index >= i_pos )
00222         {
00223             p_playlist->i_index++;
00224         }
00225     }
00226     else
00227     {
00228         msg_Err( p_playlist, "Insert mode not implemented" );
00229     }
00230 
00231     if( (i_mode & PLAYLIST_GO ) && p_view )
00232     {
00233         p_playlist->request.b_request = VLC_TRUE;
00234         /* FIXME ... */
00235         p_playlist->request.i_view = VIEW_CATEGORY;
00236         p_playlist->request.p_node = p_view->p_root;
00237         p_playlist->request.p_item = p_item;
00238 
00239         if( p_playlist->p_input )
00240         {
00241             input_StopThread( p_playlist->p_input );
00242         }
00243         p_playlist->status.i_status = PLAYLIST_RUNNING;
00244     }
00245 
00246     vlc_mutex_unlock( &p_playlist->object_lock );
00247 
00248     if( b_end == VLC_FALSE )
00249     {
00250         val.b_bool = VLC_TRUE;
00251         var_Set( p_playlist, "intf-change", val );
00252     }
00253 
00254     free( p_add );
00255 
00256     return p_item->input.i_id;
00257 }
00258 
00259 
00272 int playlist_NodeAddItem( playlist_t *p_playlist, playlist_item_t *p_item,
00273                           int i_view,playlist_item_t *p_parent,
00274                           int i_mode, int i_pos)
00275 {
00276     vlc_value_t val;
00277     int i_position;
00278     playlist_view_t *p_view;
00279 
00280     playlist_add_t *p_add = (playlist_add_t *)malloc(sizeof( playlist_add_t));
00281 
00282     vlc_mutex_lock( &p_playlist->object_lock );
00283 
00284     if ( i_pos == PLAYLIST_END ) i_pos = -1;
00285 
00286     /* Sanity checks */
00287     if( !p_parent || p_parent->i_children == -1 )
00288     {
00289         msg_Err( p_playlist, "invalid node" );
00290     }
00291 
00292     /*
00293      * CHECK_INSERT : checks if the item is already enqued before
00294      * enqueing it
00295      */
00296     if ( i_mode & PLAYLIST_CHECK_INSERT )
00297     {
00298          int j;
00299 
00300         if ( p_playlist->pp_items )
00301         {
00302             for ( j = 0; j < p_playlist->i_size; j++ )
00303             {
00304                 if ( !strcmp( p_playlist->pp_items[j]->input.psz_uri,
00305                               p_item->input.psz_uri ) )
00306                 {
00307                     playlist_ItemDelete( p_item );
00308                     vlc_mutex_unlock( &p_playlist->object_lock );
00309                     free( p_add );
00310                     return -1;
00311                 }
00312             }
00313         }
00314         i_mode &= ~PLAYLIST_CHECK_INSERT;
00315         i_mode |= PLAYLIST_APPEND;
00316     }
00317 
00318     msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )",
00319              p_item->input.psz_name, p_item->input.psz_uri );
00320 
00321     p_item->input.i_id = ++p_playlist->i_last_id;
00322 
00323     /* First, add the item at the right position in the item bank */
00324     /* WHY THAT ? */
00325      //i_position = p_playlist->i_index == -1 ? 0 : p_playlist->i_index;
00326     i_position = p_playlist->i_size ;
00327 
00328     INSERT_ELEM( p_playlist->pp_items,
00329                  p_playlist->i_size,
00330                  i_position,
00331                  p_item );
00332     INSERT_ELEM( p_playlist->pp_all_items,
00333                  p_playlist->i_all_size,
00334                  p_playlist->i_all_size,
00335                  p_item );
00336     p_playlist->i_enabled ++;
00337 
00338     /* TODO: Handle modes */
00339     playlist_NodeInsert( p_playlist, i_view, p_item, p_parent, i_pos );
00340 
00341     p_add->i_item = p_item->input.i_id;
00342     p_add->i_node = p_parent->input.i_id;
00343     p_add->i_view = i_view;
00344     val.p_address = p_add;
00345     var_Set( p_playlist, "item-append", val );
00346 
00347     /* We update the ALL view directly */
00348     p_view = playlist_ViewFind( p_playlist, VIEW_ALL );
00349     playlist_ItemAddParent( p_item, VIEW_ALL, p_view->p_root );
00350     playlist_ViewUpdate( p_playlist, VIEW_ALL );
00351 
00352     /* TODO : Update sorted views*/
00353 
00354     if( i_mode & PLAYLIST_GO )
00355     {
00356         p_playlist->request.b_request = VLC_TRUE;
00357         p_playlist->request.i_view = VIEW_CATEGORY;
00358         p_playlist->request.p_node = p_parent;
00359         p_playlist->request.p_item = p_item;
00360         if( p_playlist->p_input )
00361         {
00362             input_StopThread( p_playlist->p_input );
00363         }
00364         p_playlist->status.i_status = PLAYLIST_RUNNING;
00365     }
00366 
00367     vlc_mutex_unlock( &p_playlist->object_lock );
00368 
00369     val.b_bool = VLC_TRUE;
00370 //    var_Set( p_playlist, "intf-change", val );
00371 //
00372     free( p_add );
00373 
00374     return p_item->input.i_id;
00375 }
00376 
00377 /***************************************************************************
00378  * Item search functions
00379  ***************************************************************************/
00380 
00389 int playlist_GetPositionById( playlist_t * p_playlist , int i_id )
00390 {
00391     int i;
00392     for( i =  0 ; i < p_playlist->i_size ; i++ )
00393     {
00394         if( p_playlist->pp_items[i]->input.i_id == i_id )
00395         {
00396             return i;
00397         }
00398     }
00399     return VLC_EGENERIC;
00400 }
00401 
00402 
00411 playlist_item_t * playlist_ItemGetByPos( playlist_t * p_playlist , int i_pos )
00412 {
00413     if( i_pos >= 0 && i_pos < p_playlist->i_size)
00414     {
00415         return p_playlist->pp_items[i_pos];
00416     }
00417     else if( p_playlist->i_size > 0)
00418     {
00419         return p_playlist->pp_items[p_playlist->i_index];
00420     }
00421     else
00422     {
00423         return NULL;
00424     }
00425 }
00426 
00427 playlist_item_t *playlist_LockItemGetByPos( playlist_t *p_playlist, int i_pos )
00428 {
00429     playlist_item_t *p_ret;
00430     vlc_mutex_lock( &p_playlist->object_lock );
00431     p_ret = playlist_ItemGetByPos( p_playlist, i_pos );
00432     vlc_mutex_unlock( &p_playlist->object_lock );
00433     return p_ret;
00434 }
00435 
00443 playlist_item_t * playlist_ItemGetById( playlist_t * p_playlist , int i_id )
00444 {
00445     int i, i_top, i_bottom;
00446     i_bottom = 0; i_top = p_playlist->i_all_size - 1;
00447     i = i_top / 2;
00448     while( p_playlist->pp_all_items[i]->input.i_id != i_id &&
00449            i_top > i_bottom )
00450     {
00451         if( p_playlist->pp_all_items[i]->input.i_id < i_id )
00452         {
00453             i_bottom = i + 1;
00454         }
00455         else
00456         {
00457             i_top = i - 1;
00458         }
00459         i = i_bottom + ( i_top - i_bottom ) / 2;
00460     }
00461     if( p_playlist->pp_all_items[i]->input.i_id == i_id )
00462     {
00463         return p_playlist->pp_all_items[i];
00464     }
00465     return NULL;
00466 }
00467 
00468 playlist_item_t *playlist_LockItemGetById( playlist_t *p_playlist, int i_id)
00469 {
00470     playlist_item_t *p_ret;
00471     vlc_mutex_lock( &p_playlist->object_lock );
00472     p_ret = playlist_ItemGetById( p_playlist, i_id );
00473     vlc_mutex_unlock( &p_playlist->object_lock );
00474     return p_ret;
00475 }
00476 
00484 playlist_item_t * playlist_ItemGetByInput( playlist_t * p_playlist ,
00485                                            input_item_t *p_item )
00486 {
00487     int i;
00488     if( &p_playlist->status.p_item->input == p_item )
00489     {
00490         return p_playlist->status.p_item;
00491     }
00492 
00493     for( i =  0 ; i < p_playlist->i_size ; i++ )
00494     {
00495         if( &p_playlist->pp_items[i]->input == p_item )
00496         {
00497             return p_playlist->pp_items[i];
00498         }
00499     }
00500     return NULL;
00501 }
00502 
00503 playlist_item_t *playlist_LockItemGetByInput( playlist_t *p_playlist,
00504                                                input_item_t *p_item )
00505 {
00506     playlist_item_t *p_ret;
00507     vlc_mutex_lock( &p_playlist->object_lock );
00508     p_ret = playlist_ItemGetByInput( p_playlist, p_item );
00509     vlc_mutex_unlock( &p_playlist->object_lock );
00510     return p_ret;
00511 }
00512 
00513 
00514 /***********************************************************************
00515  * Misc functions
00516  ***********************************************************************/
00517 
00527 int playlist_ItemToNode( playlist_t *p_playlist,playlist_item_t *p_item )
00528 {
00529     int i = 0;
00530     if( p_item->i_children == -1 )
00531     {
00532         p_item->i_children = 0;
00533     }
00534 
00535     /* Remove it from the array of available items */
00536     for( i = 0 ; i < p_playlist->i_size ; i++ )
00537     {
00538         if( p_item == p_playlist->pp_items[i] )
00539         {
00540             REMOVE_ELEM( p_playlist->pp_items, p_playlist->i_size, i );
00541         }
00542     }
00543     var_SetInteger( p_playlist, "item-change", p_item->input.i_id );
00544 
00545     return VLC_SUCCESS;
00546 }
00547 
00548 int playlist_LockItemToNode( playlist_t *p_playlist, playlist_item_t *p_item )
00549 {
00550     int i_ret;
00551     vlc_mutex_lock( &p_playlist->object_lock );
00552     i_ret = playlist_ItemToNode( p_playlist, p_item );
00553     vlc_mutex_unlock( &p_playlist->object_lock );
00554     return i_ret;
00555 }
00556 
00563 int playlist_LockReplace( playlist_t *p_playlist,
00564                              playlist_item_t *p_olditem,
00565                              input_item_t *p_new )
00566 {
00567     int i_ret;
00568     vlc_mutex_lock( &p_playlist->object_lock );
00569     i_ret = playlist_Replace( p_playlist, p_olditem, p_new );
00570     vlc_mutex_unlock( &p_playlist->object_lock );
00571     return i_ret;
00572 }
00573 
00583 int playlist_Replace( playlist_t *p_playlist, playlist_item_t *p_olditem,
00584                        input_item_t *p_new )
00585 {
00586     int i;
00587     int j;
00588 
00589     if( p_olditem->i_children != -1 )
00590     {
00591         msg_Err( p_playlist, "playlist_Replace can only be used on leafs");
00592         return VLC_EGENERIC;
00593     }
00594 
00595     p_olditem->i_nb_played = 0;
00596     memcpy( &p_olditem->input, p_new, sizeof( input_item_t ) );
00597 
00598     p_olditem->i_nb_played = 0;
00599 
00600     for( i = 0 ; i< p_olditem->i_parents ; i++ )
00601     {
00602         playlist_item_t *p_parent = p_olditem->pp_parents[i]->p_parent;
00603 
00604         for( j = 0 ; j< p_parent->i_children ; i++ )
00605         {
00606             if( p_parent->pp_children[j] == p_olditem )
00607             {
00608                 p_parent->i_serial++;
00609             }
00610         }
00611     }
00612     return VLC_SUCCESS;
00613 }
00614 
00624 int playlist_Delete( playlist_t * p_playlist, int i_id )
00625 {
00626     int i, i_top, i_bottom;
00627     int i_pos;
00628     vlc_bool_t b_flag = VLC_FALSE;
00629 
00630     playlist_item_t *p_item = playlist_ItemGetById( p_playlist, i_id );
00631 
00632     if( p_item == NULL )
00633     {
00634         return VLC_EGENERIC;
00635     }
00636     if( p_item->i_children > -1 )
00637     {
00638         return playlist_NodeDelete( p_playlist, p_item, VLC_TRUE, VLC_FALSE );
00639     }
00640 
00641     var_SetInteger( p_playlist, "item-deleted", i_id );
00642 
00643     i_bottom = 0; i_top = p_playlist->i_all_size - 1;
00644     i = i_top / 2;
00645     while( p_playlist->pp_all_items[i]->input.i_id != i_id &&
00646            i_top > i_bottom )
00647     {
00648         if( p_playlist->pp_all_items[i]->input.i_id < i_id )
00649         {
00650             i_bottom = i + 1;
00651         }
00652         else
00653         {
00654             i_top = i - 1;
00655         }
00656         i = i_bottom + ( i_top - i_bottom ) / 2;
00657     }
00658     if( p_playlist->pp_all_items[i]->input.i_id == i_id )
00659     {
00660         REMOVE_ELEM( p_playlist->pp_all_items, p_playlist->i_all_size, i );
00661     }
00662 
00663     /* Check if it is the current item */
00664     if( p_playlist->status.p_item == p_item )
00665     {
00666         /* Hack we don't call playlist_Control for lock reasons */
00667         p_playlist->status.i_status = PLAYLIST_STOPPED;
00668         p_playlist->request.b_request = VLC_TRUE;
00669         p_playlist->request.p_item = NULL;
00670         msg_Info( p_playlist, "stopping playback" );
00671         b_flag = VLC_TRUE;
00672     }
00673 
00674     /* Get position and update index if needed */
00675     i_pos = playlist_GetPositionById( p_playlist, i_id );
00676 
00677     if( i_pos >= 0 && i_pos <= p_playlist->i_index )
00678     {
00679         p_playlist->i_index--;
00680     }
00681 
00682     msg_Dbg( p_playlist, "deleting playlist item `%s'",
00683                           p_item->input.psz_name );
00684 
00685     /* Remove the item from all its parent nodes */
00686     for ( i= 0 ; i < p_item->i_parents ; i++ )
00687     {
00688         playlist_NodeRemoveItem( p_playlist, p_item,
00689                                  p_item->pp_parents[i]->p_parent );
00690         if( p_item->pp_parents[i]->i_view == VIEW_ALL )
00691         {
00692             p_playlist->i_size--;
00693         }
00694     }
00695 
00696     /* TODO : Update views */
00697 
00698     if( b_flag == VLC_FALSE )
00699         playlist_ItemDelete( p_item );
00700     else
00701         p_item->i_flags |= PLAYLIST_REMOVE_FLAG;
00702 
00703     return VLC_SUCCESS;
00704 }
00705 
00706 int playlist_LockDelete( playlist_t * p_playlist, int i_id )
00707 {
00708     int i_ret;
00709     vlc_mutex_lock( &p_playlist->object_lock );
00710     i_ret = playlist_Delete( p_playlist, i_id );
00711     vlc_mutex_unlock( &p_playlist->object_lock );
00712     return i_ret;
00713 }
00714 
00721 int playlist_Clear( playlist_t * p_playlist )
00722 {
00723     int i;
00724     for( i = p_playlist->i_size; i > 0 ; i-- )
00725     {
00726         playlist_Delete( p_playlist, p_playlist->pp_items[0]->input.i_id );
00727     }
00728     for( i = 0 ; i< p_playlist->i_views; i++ )
00729     {
00730         playlist_ViewEmpty( p_playlist, i, VLC_TRUE );
00731     }
00732     return VLC_SUCCESS;
00733 }
00734 
00735 int playlist_LockClear( playlist_t *p_playlist )
00736 {
00737     int i_ret;
00738     vlc_mutex_lock( &p_playlist->object_lock );
00739     i_ret = playlist_Clear( p_playlist );
00740     vlc_mutex_unlock( &p_playlist->object_lock );
00741     return i_ret;
00742 }
00743 
00744 
00752 int playlist_Disable( playlist_t * p_playlist, playlist_item_t *p_item )
00753 {
00754     if( !p_item ) return VLC_EGENERIC;
00755 
00756     msg_Dbg( p_playlist, "disabling playlist item `%s'",
00757                    p_item->input.psz_name );
00758 
00759     if( p_item->i_flags & PLAYLIST_ENA_FLAG )
00760     {
00761         p_playlist->i_enabled--;
00762     }
00763     p_item->i_flags &= ~PLAYLIST_ENA_FLAG;
00764 
00765     var_SetInteger( p_playlist, "item-change", p_item->input.i_id );
00766     return VLC_SUCCESS;
00767 }
00768 
00776 int playlist_Enable( playlist_t * p_playlist, playlist_item_t *p_item )
00777 {
00778     if( !p_item ) return VLC_EGENERIC;
00779 
00780     msg_Dbg( p_playlist, "enabling playlist item `%s'",
00781                    p_item->input.psz_name );
00782 
00783     if( p_item->i_flags & ~PLAYLIST_ENA_FLAG )
00784     {
00785         p_playlist->i_enabled++;
00786     }
00787     p_item->i_flags |= PLAYLIST_ENA_FLAG;
00788 
00789     var_SetInteger( p_playlist, "item-change", p_item->input.i_id );
00790     return VLC_SUCCESS;
00791 }
00792 
00806 int playlist_Move( playlist_t * p_playlist, int i_pos, int i_newpos )
00807 {
00808     vlc_value_t val;
00809     vlc_mutex_lock( &p_playlist->object_lock );
00810 
00811     /* take into account that our own row disappears. */
00812     if( i_pos < i_newpos ) i_newpos--;
00813 
00814     if( i_pos >= 0 && i_newpos >=0 && i_pos <= p_playlist->i_size &&
00815         i_newpos <= p_playlist->i_size )
00816     {
00817         playlist_item_t * temp;
00818 
00819         msg_Dbg( p_playlist, "moving playlist item `%s' (%i -> %i)",
00820                  p_playlist->pp_items[i_pos]->input.psz_name, i_pos, i_newpos);
00821 
00822         if( i_pos == p_playlist->i_index )
00823         {
00824             p_playlist->i_index = i_newpos;
00825         }
00826         else if( i_pos > p_playlist->i_index &&
00827                  i_newpos <= p_playlist->i_index )
00828         {
00829             p_playlist->i_index++;
00830         }
00831         else if( i_pos < p_playlist->i_index &&
00832                  i_newpos >= p_playlist->i_index )
00833         {
00834             p_playlist->i_index--;
00835         }
00836 
00837         if ( i_pos < i_newpos )
00838         {
00839             temp = p_playlist->pp_items[i_pos];
00840             while ( i_pos < i_newpos )
00841             {
00842                 p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos+1];
00843                 i_pos++;
00844             }
00845             p_playlist->pp_items[i_newpos] = temp;
00846         }
00847         else if ( i_pos > i_newpos )
00848         {
00849             temp = p_playlist->pp_items[i_pos];
00850             while ( i_pos > i_newpos )
00851             {
00852                 p_playlist->pp_items[i_pos] = p_playlist->pp_items[i_pos-1];
00853                 i_pos--;
00854             }
00855             p_playlist->pp_items[i_newpos] = temp;
00856         }
00857     }
00858 
00859     vlc_mutex_unlock( &p_playlist->object_lock );
00860 
00861     val.b_bool = VLC_TRUE;
00862     var_Set( p_playlist, "intf-change", val );
00863 
00864     return VLC_SUCCESS;
00865 }
00866 
00877 int playlist_TreeMove( playlist_t * p_playlist, playlist_item_t *p_item,
00878                        playlist_item_t *p_node, int i_newpos, int i_view )
00879 {
00880     int i;
00881     playlist_item_t *p_detach = NULL;
00882 #if 0
00883     if( i_view == ALL_VIEWS )
00884     {
00885         for( i = 0 ; i < p_playlist->i_views; i++ )
00886         {
00887             playlist_TreeMove( p_playlist, p_item, p_node, i_newpos,
00888                                p_playlist->pp_views[i] );
00889         }
00890     }
00891 #endif
00892 
00893     /* Find the parent */
00894     for( i = 0 ; i< p_item->i_parents; i++ )
00895     {
00896         if( p_item->pp_parents[i]->i_view == i_view )
00897         {
00898             p_detach = p_item->pp_parents[i]->p_parent;
00899             break;
00900         }
00901     }
00902     if( p_detach == NULL )
00903     {
00904         msg_Err( p_playlist, "item not found in view %i", i_view );
00905         return VLC_EGENERIC;
00906     }
00907 
00908     /* Detach from the parent */
00909 //    playlist_NodeDetach( p_detach, p_item );
00910 
00911     /* Attach to new parent */
00912 
00913     return VLC_SUCCESS;
00914 }

Generated on Tue Dec 20 10:15:01 2005 for vlc-0.8.4a by  doxygen 1.4.2