Commit f9d5e2ba authored by Clément Stenac's avatar Clément Stenac

Improvements to the playlist core

parent 07ec1808
......@@ -205,17 +205,21 @@ typedef struct msg_subscription_t msg_subscription_t;
* Playlist commands
*/
typedef enum {
PLAYLIST_PLAY, /**< Starts playing. No arg. */
PLAYLIST_PAUSE, /**< Toggles playlist pause. No arg. */
PLAYLIST_STOP, /**< Stops playing. No arg. */
PLAYLIST_SKIP, /**< Skip X items and play. */
PLAYLIST_GOTO, /**< Goto Xth item. */
PLAYLIST_PLAY, /**< No arg. res=can fail*/
PLAYLIST_VIEWPLAY, /**< arg1= int, arg2= playlist_item_t*,*/
/** arg3 = playlist_item_t* , res=can fail */
PLAYLIST_ITEMPLAY, /** <arg1 = playlist_item_t * , res=can fail */
PLAYLIST_PAUSE, /**< No arg res=can fail*/
PLAYLIST_STOP, /**< No arg res=can fail*/
PLAYLIST_SKIP, /**< arg1=int, res=can fail*/
PLAYLIST_GOTO, /**< arg1=int res=can fail */
PLAYLIST_VIEWGOTO, /**< arg1=int res=can fail */
} playlist_command_t;
typedef struct playlist_t playlist_t;
typedef struct playlist_item_t playlist_item_t;
typedef struct playlist_group_t playlist_group_t;
typedef struct playlist_view_t playlist_view_t;
typedef struct playlist_export_t playlist_export_t;
/* Modules */
......
......@@ -53,6 +53,9 @@ struct input_item_t
mtime_t i_duration; /**< A hint about the duration of this
* item, in milliseconds*/
int i_id; /**< Identifier of the item */
uint8_t i_type; /**< Type (file, disc, ...) */
int i_categories; /**< Number of info categories */
info_category_t **pp_categories; /**< Pointer to the first info category */
......@@ -62,14 +65,26 @@ struct input_item_t
vlc_mutex_t lock; /**< Item cannot be changed without this lock */
};
#define ITEM_TYPE_UNKNOWN 0
#define ITEM_TYPE_FILE 1
#define ITEM_TYPE_DIRECTORY 2
#define ITEM_TYPE_DISC 3
#define ITEM_TYPE_CARD 4
#define ITEM_TYPE_NET 5
#define ITEM_TYPE_PLAYLIST 6
static inline void vlc_input_item_Init( vlc_object_t *p_o, input_item_t *p_i )
{
memset( p_i, 0, sizeof(input_item_t) );
p_i->i_options = 0;
p_i->i_es = 0;
p_i->i_categories = 0 ;
p_i->psz_name = 0;
p_i->psz_uri = 0;
p_i->ppsz_options = 0;
p_i->pp_categories = 0;
p_i->es = 0;
p_i->i_type = ITEM_TYPE_UNKNOWN;
vlc_mutex_init( p_o, &p_i->lock );
}
......
......@@ -232,5 +232,7 @@ static inline int StringToKey( char *psz_key )
#define ACTIONID_HISTORY_FORWARD 49
#define ACTIONID_AUDIO_TRACK 50
#define ACTIONID_SUBTITLE_TRACK 51
#define ACTIONID_CUBESPEED_UP 52
#define ACTIONID_CUBESPEED_DOWN 53
#define ACTIONID_INTF_SHOW 52
This diff is collapsed.
......@@ -580,6 +580,7 @@ static int Init( input_thread_t * p_input )
var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
UpdateItemLength( p_input, val.i_time );
p_input->input.p_item->i_duration = val.i_time;
}
/* Start title/chapter */
......@@ -893,6 +894,11 @@ static int Init( input_thread_t * p_input )
msg_Dbg( p_input, "`%s' sucessfully opened",
p_input->input.p_item->psz_uri );
/* Trigger intf update for this item */
/* Playlist has a callback on this variable and will forward
* it to intf */
var_SetInteger( p_input, "item-change", p_input->input.p_item->i_id );
/* initialization is complete */
p_input->i_state = PLAYING_S;
......
......@@ -190,12 +190,14 @@ void input_ControlVarInit ( input_thread_t *p_input )
var_Change( p_input, "length", VLC_VAR_SETVALUE, &val, NULL );
/* Special "intf-change" variable, it allows intf to set up a callback
* to be notified of some changes.
* TODO list all changes warn by this callbacks */
var_Create( p_input, "intf-change", VLC_VAR_BOOL );
var_SetBool( p_input, "intf-change", VLC_TRUE );
/* item-change variable */
var_Create( p_input, "item-change", VLC_VAR_INTEGER );
}
/*****************************************************************************
......
/*****************************************************************************
* playlist.c : Playlist groups management functions
*****************************************************************************
* Copyright (C) 1999-2004 VideoLAN
* $Id$
*
* Authors: Clment Stenac <zorglub@videolan.org>
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
*****************************************************************************/
#include <stdlib.h> /* free(), strtol() */
#include <stdio.h> /* sprintf() */
#include <string.h> /* strerror() */
#include <vlc/vlc.h>
#include <vlc/input.h>
#include "vlc_playlist.h"
/**
* Create a group
*
* Create a new group
* \param p_playlist pointer to a playlist
* \param psz_name the name of the group to be created
* \return a pointer to the created group, or NULL on error
*/
playlist_group_t *playlist_CreateGroup( playlist_t *p_playlist, char *psz_name)
{
playlist_group_t *p_group;
int i;
for( i = 0 ; i < p_playlist->i_groups; i++ )
{
if( !strcasecmp( p_playlist->pp_groups[i]->psz_name , psz_name ) )
{
msg_Info( p_playlist, "this group already exists");
return p_playlist->pp_groups[i];
}
}
/* Allocate the group structure */
if( ( p_group = malloc( sizeof(playlist_group_t) ) ) == NULL )
{
msg_Err( p_playlist, "out of memory" );
return NULL;
}
p_group->psz_name = strdup( psz_name );
p_group->i_id = ++p_playlist->i_last_group;
msg_Dbg(p_playlist,"creating group %s with id %i at position %i",
p_group->psz_name,
p_group->i_id,
p_playlist->i_groups);
INSERT_ELEM ( p_playlist->pp_groups,
p_playlist->i_groups,
p_playlist->i_groups,
p_group );
return p_group;
}
/**
* Destroy a group
*
* \param p_playlist the playlist to remove the group from
* \param i_id the identifier of the group to remove
* \return VLC_SUCCESS
*/
int playlist_DeleteGroup( playlist_t *p_playlist, int i_id )
{
int i;
for( i=0 ; i<= p_playlist->i_groups; i++ )
{
playlist_group_t *p_group = p_playlist->pp_groups[i];
if( p_group->i_id == i_id )
{
if( p_group->psz_name )
{
free( p_group->psz_name );
}
REMOVE_ELEM( p_playlist->pp_groups,
p_playlist->i_groups,
i );
free( p_group );
return VLC_SUCCESS;
}
}
return VLC_SUCCESS;
}
/**
* Find the name of the group given its ID
*
* \param p_playlist the playlist where to find the group
* \param i_id the ID to search for
* \return the name of the group
*/
char *playlist_FindGroup( playlist_t *p_playlist, int i_id )
{
int i;
for( i=0 ; i< p_playlist->i_groups; i++ )
{
if( p_playlist->pp_groups[i]->i_id == i_id )
{
if( p_playlist->pp_groups[i]->psz_name)
return strdup( p_playlist->pp_groups[i]->psz_name );
}
}
return NULL;
}
/**
* Find the id of a group given its name
*
* \param p_playlist the playlist where to find the group
* \param psz_name the name to search for
* \return the id of the group
*/
int playlist_GroupToId( playlist_t *p_playlist, char *psz_name )
{
int i;
for( i = 0 ; i< p_playlist->i_groups; i++ )
{
if( p_playlist->pp_groups[i]->psz_name)
{
if( ! strcasecmp( p_playlist->pp_groups[i]->psz_name, psz_name ) )
{
return p_playlist->pp_groups[i]->i_id;
}
}
}
return VLC_SUCCESS;
}
......@@ -122,7 +122,7 @@ info_category_t * playlist_ItemGetCategory( playlist_item_t *p_item,
* \return the info category.
*/
info_category_t * playlist_ItemCreateCategory( playlist_item_t *p_item,
const char *psz_cat )
const char *psz_cat )
{
info_category_t *p_cat;
int i;
......
This diff is collapsed.
......@@ -29,6 +29,8 @@
#include "vlc_playlist.h"
static void GuessType( input_item_t *p_item);
/**
* Create a new item, without adding it to the playlist
*
......@@ -43,23 +45,37 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
{
playlist_item_t * p_item;
if( psz_uri == NULL ) return NULL;
if( psz_uri == NULL) return NULL;
p_item = malloc( sizeof( playlist_item_t ) );
if( p_item == NULL ) return NULL;
memset( p_item, 0, sizeof( playlist_item_t ) );
vlc_input_item_Init( p_obj, &p_item->input );
p_item->input.i_duration = -1;
p_item->input.psz_uri = strdup( psz_uri );
if( psz_name != NULL ) p_item->input.psz_name = strdup( psz_name );
else p_item->input.psz_name = strdup ( psz_uri );
p_item->b_enabled = VLC_TRUE;
p_item->i_group = PLAYLIST_TYPE_MANUAL;
p_item->i_nb_played = 0;
p_item->i_children = -1;
p_item->pp_children = NULL;
p_item->i_flags = 0;
p_item->i_flags |= PLAYLIST_SKIP_FLAG;
p_item->input.i_duration = -1;
p_item->input.ppsz_options = NULL;
p_item->input.i_options = 0;
vlc_mutex_init( p_obj, &p_item->input.lock );
GuessType( &p_item->input );
playlist_ItemCreateCategory( p_item, _("General") );
return p_item;
}
......@@ -71,136 +87,51 @@ playlist_item_t * __playlist_ItemNew( vlc_object_t *p_obj,
*/
void playlist_ItemDelete( playlist_item_t *p_item )
{
vlc_input_item_Clean( &p_item->input );
free( p_item );
}
/**
* Add a playlist item into a playlist
*
* \param p_playlist the playlist to insert into
* \param p_item the playlist item to insert
* \param i_mode the mode used when adding
* \param i_pos the possition in the playlist where to add. If this is
* PLAYLIST_END the item will be added at the end of the playlist
* regardless of it's size
* \return The id of the playlist item
*/
int playlist_AddItem( playlist_t *p_playlist, playlist_item_t *p_item,
int i_mode, int i_pos)
{
vlc_value_t val;
vlc_mutex_lock( &p_item->input.lock );
vlc_mutex_lock( &p_playlist->object_lock );
if( p_item->input.psz_name ) free( p_item->input.psz_name );
if( p_item->input.psz_uri ) free( p_item->input.psz_uri );
/*
* CHECK_INSERT : checks if the item is already enqued before
* enqueing it
*/
if ( i_mode & PLAYLIST_CHECK_INSERT )
/* Free the info categories */
if( p_item->input.i_categories > 0 )
{
int j;
if ( p_playlist->pp_items )
{
for ( j = 0; j < p_playlist->i_size; j++ )
{
if ( !strcmp( p_playlist->pp_items[j]->input.psz_uri,
p_item->input.psz_uri ) )
{
if ( p_item->input.psz_name )
{
free( p_item->input.psz_name );
}
if ( p_item->input.psz_uri )
{
free ( p_item->input.psz_uri );
}
free( p_item );
vlc_mutex_unlock( &p_playlist->object_lock );
return -1;
}
}
}
i_mode &= ~PLAYLIST_CHECK_INSERT;
i_mode |= PLAYLIST_APPEND;
}
msg_Dbg( p_playlist, "adding playlist item `%s' ( %s )",
p_item->input.psz_name, p_item->input.psz_uri );
p_item->i_id = ++p_playlist->i_last_id;
int i, j;
/* Do a few boundary checks and allocate space for the item */
if( i_pos == PLAYLIST_END )
{
if( i_mode & PLAYLIST_INSERT )
for( i = 0; i < p_item->input.i_categories; i++ )
{
i_mode &= ~PLAYLIST_INSERT;
i_mode |= PLAYLIST_APPEND;
}
info_category_t *p_category = p_item->input.pp_categories[i];
i_pos = p_playlist->i_size - 1;
}
for( j = 0; j < p_category->i_infos; j++)
{
if( p_category->pp_infos[j]->psz_name )
{
free( p_category->pp_infos[j]->psz_name);
}
if( p_category->pp_infos[j]->psz_value )
{
free( p_category->pp_infos[j]->psz_value );
}
free( p_category->pp_infos[j] );
}
if( !(i_mode & PLAYLIST_REPLACE)
|| i_pos < 0 || i_pos >= p_playlist->i_size )
{
/* Additional boundary checks */
if( i_mode & PLAYLIST_APPEND )
{
i_pos++;
if( p_category->i_infos ) free( p_category->pp_infos );
if( p_category->psz_name ) free( p_category->psz_name );
free( p_category );
}
if( i_pos < 0 )
{
i_pos = 0;
}
else if( i_pos > p_playlist->i_size )
{
i_pos = p_playlist->i_size;
}
INSERT_ELEM( p_playlist->pp_items, p_playlist->i_size, i_pos, p_item );
p_playlist->i_enabled ++;
if( p_playlist->i_index >= i_pos )
{
p_playlist->i_index++;
}
}
else
{
/* i_mode == PLAYLIST_REPLACE and 0 <= i_pos < p_playlist->i_size */
if( p_playlist->pp_items[i_pos]->input.psz_name )
{
free( p_playlist->pp_items[i_pos]->input.psz_name );
}
if( p_playlist->pp_items[i_pos]->input.psz_uri )
{
free( p_playlist->pp_items[i_pos]->input.psz_uri );
}
/* XXX: what if the item is still in use? */
free( p_playlist->pp_items[i_pos] );
p_playlist->pp_items[i_pos] = p_item;
free( p_item->input.pp_categories );
}
if( i_mode & PLAYLIST_GO )
for( ; p_item->input.i_options > 0; p_item->input.i_options-- )
{
p_playlist->i_index = i_pos;
if( p_playlist->p_input )
{
input_StopThread( p_playlist->p_input );
}
p_playlist->i_status = PLAYLIST_RUNNING;
free( p_item->input.ppsz_options[p_item->input.i_options - 1] );
if( p_item->input.i_options == 1 ) free( p_item->input.ppsz_options );
}
vlc_mutex_unlock( &p_playlist->object_lock );
val.b_bool = VLC_TRUE;
var_Set( p_playlist, "intf-change", val );
vlc_mutex_unlock( &p_item->input.lock );
vlc_mutex_destroy( &p_item->input.lock );
return p_item->i_id;
free( p_item );
}
/**
......@@ -221,3 +152,127 @@ int playlist_ItemAddOption( playlist_item_t *p_item, const char *psz_option )
return VLC_SUCCESS;
}
/**
* Add a parent to an item
*
* \param p_item the item
* \param i_view the view in which the parent is
* \param p_parent the parent to add
* \return nothing
*/
void playlist_ItemAddParent( playlist_item_t *p_item, int i_view,
playlist_item_t *p_parent )
{
vlc_bool_t b_found = VLC_FALSE;
int i;
for( i= 0; i< p_item->i_parents ; i++ )
{
if( p_item->pp_parents[i]->i_view == i_view )
{
b_found = VLC_TRUE;
break;
}
}
if( b_found == VLC_FALSE )
{
struct item_parent_t *p_ip = (struct item_parent_t *)
malloc(sizeof(struct item_parent_t) );
p_ip->i_view = i_view;
p_ip->p_parent = p_parent;
INSERT_ELEM( p_item->pp_parents,
p_item->i_parents, p_item->i_parents,
p_ip );
}
}
/**********************************************************************
* playlist_item_t structure accessors
* These functions give access to the fields of the playlist_item_t
* structure
**********************************************************************/
/**
* Set the name of a playlist item
*
* \param p_item the item
* \param psz_name the new name
* \return VLC_SUCCESS on success, VLC_EGENERIC on failure
*/
int playlist_ItemSetName( playlist_item_t *p_item, char *psz_name )
{
if( psz_name && p_item )
{
p_item->input.psz_name = strdup( psz_name );
return VLC_SUCCESS;
}
return VLC_EGENERIC;
}
/**
* Set the duration of a playlist item
* This function must be entered with the item lock
*
* \param p_item the item
* \param i_duration the new duration
* \return VLC_SUCCESS on success, VLC_EGENERIC on failure
*/
int playlist_ItemSetDuration( playlist_item_t *p_item, mtime_t i_duration )
{
char psz_buffer[MSTRTIME_MAX_SIZE];
if( p_item )
{
p_item->input.i_duration = i_duration;
if( i_duration != -1 )
{
secstotimestr( psz_buffer, i_duration/1000000 );
}
else
{
memcpy( psz_buffer, "--:--:--", sizeof("--:--:--") );
}
playlist_ItemAddInfo( p_item, _("General") , _("Duration"),
"%s", psz_buffer );
return VLC_SUCCESS;
}
return VLC_EGENERIC;
}
static void GuessType( input_item_t *p_item)
{
int i;
static struct { char *psz_search; int i_type; } types_array[] =
{
{ "http", ITEM_TYPE_NET },
{ "dvd", ITEM_TYPE_DISC },
{ "cdda", ITEM_TYPE_DISC },
{ "mms", ITEM_TYPE_NET },
{ "rtsp", ITEM_TYPE_NET },
{ "udp", ITEM_TYPE_NET },
{ "vcd", ITEM_TYPE_DISC },
{ "v4l", ITEM_TYPE_CARD },
{ "dshow", ITEM_TYPE_CARD },
{ "pvr", ITEM_TYPE_CARD },
{ "dvb", ITEM_TYPE_CARD },
{ "qpsk", ITEM_TYPE_CARD },
{ NULL, 0 }
};
for( i = 0; types_array[i].psz_search != NULL; i++ )
{
if( !strncmp( p_item->psz_uri, types_array[i].psz_search,
strlen( types_array[i].psz_search ) ) )
{
p_item->i_type = types_array[i].i_type;
return;
}
}
return ITEM_TYPE_UNKNOWN;
}
......@@ -34,10 +34,11 @@
#define PLAYLIST_FILE_HEADER "# vlc playlist file version 0.5"
/**
* Import a certain playlist file into the playlist
* Import a certain playlist file into the library
* This file will get inserted as a new category
*
* XXX: TODO
* \param p_playlist the playlist to which the new items will be added
* \param psz_filename the name of the playlistfile to import
* \return VLC_SUCCESS on success
......@@ -68,6 +69,40 @@ int playlist_Import( playlist_t * p_playlist, const char *psz_filename )
return VLC_SUCCESS;
}
/**
* Load a certain playlist file into the playlist
* This file will replace the contents of the "current" view
*
* \param p_playlist the playlist to which the new items will be added
* \param psz_filename the name of the playlistfile to import
* \return VLC_SUCCESS on success
*/
int playlist_Load( playlist_t * p_playlist, const char *psz_filename )
{
playlist_item_t *p_item;
char *psz_uri;
int i_id;
msg_Dbg( p_playlist, "clearing playlist");
playlist_Clear( p_playlist );
psz_uri = (char *)malloc(sizeof(char)*strlen(psz_filename) + 17 );
sprintf( psz_uri, "file/playlist://%s", psz_filename);
i_id = playlist_Add( p_playlist, psz_uri, psz_uri,
PLAYLIST_INSERT , PLAYLIST_END);
vlc_mutex_lock( &p_playlist->object_lock );
p_item = playlist_ItemGetById( p_playlist, i_id );
p_item->b_autodeletion = VLC_TRUE;
vlc_mutex_unlock( &p_playlist->object_lock );
playlist_Play(p_playlist);
return VLC_SUCCESS;
}
/**
* Export a playlist to a certain type of playlistfile
*
......
This diff is collapsed.
......@@ -31,17 +31,22 @@
#include "vlc_playlist.h"
int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
playlist_item_t **pp_items, int i_mode,
int i_type );
/**
* Sort the playlist
* Sort the playlist.
* \param p_playlist the playlist
* \param i_mode: SORT_ID, SORT_TITLE, SORT_GROUP, SORT_AUTHOR, SORT_RANDOM
* \param i_mode: SORT_ID, SORT_TITLE, SORT_AUTHOR, SORT_RANDOM
* \param i_type: ORDER_NORMAL or ORDER_REVERSE (reversed order)
* \return VLC_SUCCESS on success
*/
int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
{
int i , i_small , i_position;
playlist_item_t *p_temp;
int i_id = -1;
vlc_value_t val;
val.b_bool = VLC_TRUE;
......@@ -49,76 +54,105 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
p_playlist->i_sort = i_mode;
p_playlist->i_order = i_type;
/* playlist with one or less items are allways sorted in all
manners, quit fast. */
if( p_playlist->i_size <= 1 )
if( p_playlist->i_index >= 0 )
{
vlc_mutex_unlock( &p_playlist->object_lock );
i_id = p_playlist->pp_items[p_playlist->i_index]->input.i_id;
}
/* Notify the interfaces, is this necessary? */
var_Set( p_playlist, "intf-change", val );
playlist_ItemArraySort( p_playlist, p_playlist->i_size,
p_playlist->pp_items, i_mode, i_type );
return VLC_SUCCESS;
if( i_id != -1 )
{
p_playlist->i_index = playlist_GetPositionById( p_playlist, i_id );
}
/* ensure we are in no-view mode */
p_playlist->status.i_view = -1;
vlc_mutex_unlock( &p_playlist->object_lock );
/* Notify the interfaces */
var_Set( p_playlist, "intf-change", val );
return VLC_SUCCESS;
}
/**
* Sort a node.
* \param p_playlist the playlist
* \param p_node the node to sort
* \param i_mode: SORT_ID, SORT_TITLE, SORT_AUTHOR, SORT_RANDOM
* \param i_type: ORDER_NORMAL or ORDER_REVERSE (reversed order)
* \return VLC_SUCCESS on success
*/
int playlist_NodeSort( playlist_t * p_playlist , playlist_item_t *p_node,
int i_mode, int i_type )
{
int i_id;
vlc_value_t val;
val.b_bool = VLC_TRUE;
vlc_mutex_lock( &p_playlist->object_lock );
playlist_ItemArraySort( p_playlist,p_node->i_children,
p_node->pp_children, i_mode, i_type );
p_node->i_serial++;
vlc_mutex_unlock( &p_playlist->object_lock );
/* Notify the interfaces */
var_Set( p_playlist, "intf-change", val );
return VLC_SUCCESS;
}
int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
playlist_item_t **pp_items, int i_mode,
int i_type )
{
int i , i_small , i_position;
playlist_item_t *p_temp;
vlc_value_t val;
val.b_bool = VLC_TRUE;
if( i_mode == SORT_RANDOM )
{
for( i_position = 0; i_position < p_playlist->i_size ; i_position ++ )
for( i_position = 0; i_position < i_items ; i_position ++ )
{
int i_new = rand() % (p_playlist->i_size - 1);
/* Keep the correct current index */
if( i_new == p_playlist->i_index )
p_playlist->i_index = i_position;
else if( i_position == p_playlist->i_index )
p_playlist->i_index = i_new;
int i_new = rand() % (i_items - 1);
p_temp = p_playlist->pp_items[i_position];
p_playlist->pp_items[i_position] = p_playlist->pp_items[i_new];
p_playlist->pp_items[i_new] = p_temp;
p_temp = pp_items[i_position];
pp_items[i_position] = pp_items[i_new];
pp_items[i_new] = p_temp;
}
vlc_mutex_unlock( &p_playlist->object_lock );
/* Notify the interfaces */
var_Set( p_playlist, "intf-change", val );
return VLC_SUCCESS;
}
for( i_position = 0; i_position < p_playlist->i_size -1 ; i_position ++ )
for( i_position = 0; i_position < i_items -1 ; i_position ++ )
{
i_small = i_position;
for( i = i_position + 1 ; i< p_playlist->i_size ; i++)
for( i = i_position + 1 ; i< i_items ; i++)
{
int i_test = 0;
if( i_mode == SORT_ID )
if( i_mode == SORT_TITLE )
{
i_test = p_playlist->pp_items[i]->i_id -
p_playlist->pp_items[i_small]->i_id;
}
else if( i_mode == SORT_TITLE )
{
i_test = strcasecmp( p_playlist->pp_items[i]->input.psz_name,
p_playlist->pp_items[i_small]->input.psz_name );
}
else if( i_mode == SORT_GROUP )
{
i_test = p_playlist->pp_items[i]->i_group -
p_playlist->pp_items[i_small]->i_group;
i_test = strcasecmp( pp_items[i]->input.psz_name,
pp_items[i_small]->input.psz_name );
}
else if( i_mode == SORT_DURATION )
{
i_test = p_playlist->pp_items[i]->input.i_duration -
p_playlist->pp_items[i_small]->input.i_duration;
i_test = pp_items[i]->input.i_duration -
pp_items[i_small]->input.i_duration;
}
else if( i_mode == SORT_AUTHOR )
{
i_test = strcasecmp(
playlist_GetInfo( p_playlist, i,
_("General") , _("Author") ),
playlist_GetInfo( p_playlist, i_small,
_("General") , _("Author") ) );
msg_Err( p_playlist,"META SORT not implemented" );
}
if( ( i_type == ORDER_NORMAL && i_test < 0 ) ||
......@@ -127,20 +161,77 @@ int playlist_Sort( playlist_t * p_playlist , int i_mode, int i_type )
i_small = i;
}
}
/* Keep the correct current index */
if( i_small == p_playlist->i_index )
p_playlist->i_index = i_position;
else if( i_position == p_playlist->i_index )
p_playlist->i_index = i_small;
p_temp = p_playlist->pp_items[i_position];
p_playlist->pp_items[i_position] = p_playlist->pp_items[i_small];
p_playlist->pp_items[i_small] = p_temp;
p_temp = pp_items[i_position];
pp_items[i_position] = pp_items[i_small];
pp_items[i_small] = p_temp;
}
vlc_mutex_unlock( &p_playlist->object_lock );
return VLC_SUCCESS;
}
/* Notify the interfaces */
var_Set( p_playlist, "intf-change", val );
int playlist_NodeGroup( playlist_t * p_playlist , int i_view,
playlist_item_t *p_root,
playlist_item_t **pp_items,int i_item,
int i_mode, int i_type )
{
char *psz_search = NULL;
int i_nodes = 0;
playlist_item_t **pp_nodes = NULL;
playlist_item_t *p_node;
vlc_bool_t b_found;
int i,j;
for( i = 0; i< i_item ; i++ )
{
if( psz_search ) free( psz_search );
if( i_mode == SORT_TITLE )
{
psz_search = strdup( pp_items[i]->input.psz_name );
}
else if ( i_mode == SORT_AUTHOR )
{
psz_search = playlist_ItemGetInfo( pp_items[i],
_("Meta-information"), _( "Artist" ) );
}
if( psz_search && !strcmp( psz_search, "" ) )
{
free( psz_search );
psz_search = strdup( _("Undefined") );
}
b_found = VLC_FALSE;
for( j = 0 ; j< i_nodes; j++ )
{
if( !strcasecmp( psz_search, pp_nodes[j]->input.psz_name ) )
{
playlist_NodeAppend( p_playlist, i_view,
pp_items[i], pp_nodes[j] );
b_found = VLC_TRUE;
break;
}
}
if( !b_found )
{
p_node = playlist_NodeCreate( p_playlist, i_view,psz_search,
NULL );
INSERT_ELEM( pp_nodes, i_nodes, i_nodes, p_node );
playlist_NodeAppend( p_playlist, i_view,
pp_items[i],p_node );
}
}
/* Now, sort the nodes by name */
playlist_ItemArraySort( p_playlist, i_nodes, pp_nodes, SORT_TITLE,
i_type );
/* Now, sort each node and append it to the root node*/
for( i = 0 ; i< i_nodes ; i++ )
{
playlist_ItemArraySort( p_playlist, pp_nodes[i]->i_children,
pp_nodes[i]->pp_children, SORT_TITLE, i_type );
playlist_NodeAppend( p_playlist, i_view,
pp_nodes[i], p_root );
}
return VLC_SUCCESS;
}
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment