Commit 6c0ceeb3 authored by Clément Stenac's avatar Clément Stenac

Remove playlist info accessors (as they now belong to input_item) and use...

Remove playlist info accessors (as they now belong to input_item) and use vlc_input_item_AddInfo and vlc_input_item_GetInfo instead
parent f2797b3e
......@@ -330,7 +330,6 @@ SOURCES_libvlc_common = \
src/playlist/view.c \
src/playlist/item.c \
src/playlist/item-ext.c \
src/playlist/info.c \
src/playlist/services_discovery.c \
src/input/access.c \
src/input/clock.c \
......
......@@ -158,6 +158,9 @@ static inline void vlc_input_item_Clean( input_item_t *p_i )
vlc_mutex_destroy( &p_i->lock );
}
VLC_EXPORT( char *, vlc_input_item_GetInfo, ( input_item_t *p_i, const char *psz_cat,const char *psz_name ) );
VLC_EXPORT(int, vlc_input_item_AddInfo, ( input_item_t *p_i, const char *psz_cat, const char *psz_name, const char *psz_format, ... ) );
/*****************************************************************************
* Seek point: (generalisation of chapters)
*****************************************************************************/
......
......@@ -331,16 +331,6 @@ VLC_EXPORT( playlist_item_t *, playlist_ItemGetByInput, (playlist_t *,input_item
VLC_EXPORT( playlist_item_t *, playlist_LockItemGetByInput, (playlist_t *,input_item_t * ) );
VLC_EXPORT( int, playlist_GetPositionById, (playlist_t *,int ) );
/* Info functions */
VLC_EXPORT( char * , playlist_GetInfo, ( playlist_t * , int, const char *, const char *) );
VLC_EXPORT( char * , playlist_ItemGetInfo, ( playlist_item_t * , const char *, const char *) );
VLC_EXPORT( info_category_t*, playlist_ItemGetCategory, ( playlist_item_t *, const char *) );
VLC_EXPORT( info_category_t*, playlist_ItemCreateCategory, ( playlist_item_t *, const char *) );
VLC_EXPORT( int, playlist_AddInfo, (playlist_t *, int, const char * , const char *, const char *, ...) );
VLC_EXPORT( int, playlist_ItemAddInfo, (playlist_item_t *, const char * , const char *, const char *, ...) );
VLC_EXPORT( int, playlist_ItemAddOption, (playlist_item_t *, const char *) );
/* Playlist sorting */
......
......@@ -801,7 +801,7 @@ CDDAFormatTitle( const access_t *p_access, track_t i_track )
#define add_playlist_track_info_str(TITLE, FIELD) \
if (FIELD && strlen(FIELD)) \
{ \
playlist_ItemAddInfo( p_item, _("Track"), _(TITLE), \
vlc_input_item_AddInfo( &p_item->input, _("Track"), _(TITLE), \
"%s", FIELD); \
}
......@@ -844,14 +844,14 @@ CDDACreatePlaylistItem( const access_t *p_access, cdda_data_t *p_cdda,
}
int CDDAAddMetaToItem( access_t *p_access, cdda_data_t *p_cdda,
playlist_item_t *p_item, int i_track,
vlc_bool_t b_single )
playlist_item_t *p_item, int i_track,
vlc_bool_t b_single )
{
vlc_mutex_lock( &p_item->input.lock );
add_playlist_track_info_str("Source", p_cdda->psz_source);
playlist_ItemAddInfo( p_item, _("Track"), _("Track Number"),
"%d", i_track );
vlc_input_item_AddInfo( &p_item->input, _("Track"), _("Track Number"),
"%d", i_track );
if (p_cdda->p_cdtext[i_track])
{
......
......@@ -150,7 +150,7 @@
p_item->input.psz_uri = strdup( [[o_uri_txt stringValue] UTF8String] );
p_item->input.psz_name = strdup( [[o_title_txt stringValue] UTF8String] );
playlist_ItemAddInfo( p_item, _("General"), _("Author"), [[o_author_txt stringValue] UTF8String]);
vlc_input_item_AddInfo( &p_item->input, _("General"), _("Author"), [[o_author_txt stringValue] UTF8String]);
vlc_mutex_unlock( &p_item->input.lock );
val.b_bool = VLC_TRUE;
......
......@@ -132,18 +132,6 @@ LRESULT ItemInfoDialog::WndProc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
70, 10 + 15 + 10 - 3, rcClient.right - 70 - 10, 15 + 6,
hwnd, NULL, hInst, NULL);
/* Author Textbox */
author_label = CreateWindow( _T("STATIC"), _T("Author:"),
WS_CHILD | WS_VISIBLE | SS_RIGHT ,
0, 10 + 2*( 15 + 10 ), 60, 15,
hwnd, NULL, hInst, NULL);
author_text = CreateWindow( _T("EDIT"),
_FROMMB(playlist_ItemGetInfo( p_item, _("General"), _("Author") )),
WS_CHILD | WS_VISIBLE | WS_BORDER | SS_LEFT | ES_AUTOHSCROLL,
70, 10 + 2*( 15 + 10 ) - 3, rcClient.right - 70 - 10, 15 + 6,
hwnd, NULL, hInst, NULL );
/* CheckBox */
checkbox_label = CreateWindow( _T("STATIC"), _T("Item Enabled:"),
WS_CHILD | WS_VISIBLE | SS_RIGHT ,
......@@ -290,10 +278,6 @@ void ItemInfoDialog::OnOk()
if( p_item->input.psz_uri ) free( p_item->input.psz_uri );
p_item->input.psz_uri = strdup( _TOMB(psz_uri) );
TCHAR psz_author[MAX_PATH];
Edit_GetText( author_text, psz_author, MAX_PATH );
playlist_ItemAddInfo( p_item, "General", "Author", _TOMB(psz_author) );
vlc_bool_t b_old_enabled = p_item->b_enabled;
playlist_t * p_playlist = (playlist_t *)
......
......@@ -253,9 +253,6 @@ protected:
HWND name_label;
HWND name_text;
HWND author_label;
HWND author_text;
HWND checkbox_label;
HWND enabled_checkbox;
......
......@@ -51,7 +51,6 @@ enum
{
Uri_Event,
Name_Event,
Author_Event,
Enabled_Event,
};
......@@ -155,19 +154,6 @@ wxPanel *ItemInfoDialog::InfoPanel( wxWindow* parent )
sizer->Add( name_label, 0 , wxALIGN_LEFT |wxALL , 5 );
sizer->Add( name_text, 1 , wxALIGN_RIGHT | wxALL , 5 );
/* Author Textbox */
wxStaticText *author_label =
new wxStaticText( info_panel, -1, wxU(_("Author")) );
author_text = new wxTextCtrl( info_panel, Uri_Event,
wxU( playlist_ItemGetInfo( p_item,
_("General"), _("Author") ) ),
wxDefaultPosition, wxSize( 300, -1 ),
wxTE_PROCESS_ENTER);
sizer->Add( author_label, 0 , wxALIGN_LEFT | wxALL , 5 );
sizer->Add( author_text, 1 , wxALIGN_RIGHT | wxALL , 5);
/* Treeview */
info_tree = new wxTreeCtrl( info_panel, -1, wxDefaultPosition,
wxSize(220,200),
......@@ -221,8 +207,6 @@ void ItemInfoDialog::OnOk( wxCommandEvent& WXUNUSED(event) )
vlc_mutex_lock( &p_item->input.lock );
p_item->input.psz_name = strdup( name_text->GetLineText(0).mb_str() );
p_item->input.psz_uri = strdup( uri_text->GetLineText(0).mb_str() );
playlist_ItemAddInfo( p_item,"General","Author",
author_text->GetLineText(0).mb_str() );
vlc_mutex_unlock( &p_item->input.lock );
EndModal( wxID_OK );
}
......
......@@ -517,7 +517,8 @@ void Playlist::UpdateTreeItem( playlist_t *p_playlist, wxTreeItemId item )
wxString msg;
wxString duration = wxU( "" );
char *psz_author = playlist_ItemGetInfo( p_item, _("Meta-information"),
char *psz_author = vlc_input_item_GetInfo( &p_item->input,
_("Meta-information"),
_("Artist"));
char psz_duration[MSTRTIME_MAX_SIZE];
mtime_t dur = p_item->input.i_duration;
......@@ -526,7 +527,7 @@ void Playlist::UpdateTreeItem( playlist_t *p_playlist, wxTreeItemId item )
{
secstotimestr( psz_duration, dur/1000000 );
duration.Append( wxU( " ( " ) + wxString( wxU( psz_duration ) ) +
wxU( ")" ) );
wxU( " )" ) );
}
if( !strcmp( psz_author, "" ) || p_item->input.b_fixed_name == VLC_TRUE )
......
......@@ -940,7 +940,6 @@ private:
wxTextCtrl *uri_text;
wxTextCtrl *name_text;
wxTextCtrl *author_text;
wxTreeCtrl *info_tree;
wxTreeItemId info_root;
......
......@@ -129,6 +129,8 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
case INPUT_ADD_INFO:
{
/* FIXME : Impossible to use vlc_input_item_AddInfo because of
* the ... problem ? */
char *psz_cat = (char *)va_arg( args, char * );
char *psz_name = (char *)va_arg( args, char * );
char *psz_format = (char *)va_arg( args, char * );
......@@ -204,32 +206,8 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
int i;
*ppsz_value = NULL;
vlc_mutex_lock( &p_input->input.p_item->lock );
for( i = 0; i < p_input->input.p_item->i_categories; i++ )
{
if( !strcmp( p_input->input.p_item->pp_categories[i]->psz_name,
psz_cat ) ) break;
}
if( i != p_input->input.p_item->i_categories )
{
info_category_t *p_cat;
p_cat = p_input->input.p_item->pp_categories[i];
for( i = 0; i < p_cat->i_infos; i++ )
{
if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
{
if( p_cat->pp_infos[i]->psz_value )
{
*ppsz_value =strdup(p_cat->pp_infos[i]->psz_value);
i_ret = VLC_SUCCESS;
}
break;
}
}
}
vlc_mutex_unlock( &p_input->input.p_item->lock );
*ppsz_value = vlc_input_item_GetInfo( p_input->input.p_item,
psz_cat, psz_name );
return i_ret;
}
......@@ -442,7 +420,7 @@ int input_vaControl( input_thread_t *p_input, int i_query, va_list args )
int i;
vlc_mutex_lock( &p_input->input.p_item->lock );
/* Check if option already exists */
/* Check if option already exists */
for( i = 0; i < p_input->input.p_item->i_options; i++ )
{
if( !strncmp( p_input->input.p_item->ppsz_options[i],
......
......@@ -2442,3 +2442,104 @@ static void MRLSections( input_thread_t *p_input, char *psz_source,
psz_source, *pi_title_start, *pi_chapter_start,
*pi_title_end, *pi_chapter_end );
}
/***********************************************************************
* Info management functions
***********************************************************************/
char *vlc_input_item_GetInfo( input_item_t *p_i,
const char *psz_cat,
const char *psz_name )
{
int i,j;
vlc_mutex_lock( &p_i->lock );
for( i = 0 ; i< p_i->i_categories ; i++ )
{
info_category_t *p_cat = p_i->pp_categories[i];
if( !psz_cat || strcmp( p_cat->psz_name, psz_cat ) )
continue;
for( j = 0; j < p_cat->i_infos ; j++ )
{
if( !strcmp( p_cat->pp_infos[j]->psz_name, psz_name ) )
{
vlc_mutex_unlock( &p_i->lock );
return strdup( p_cat->pp_infos[j]->psz_value );
}
}
}
vlc_mutex_unlock( &p_i->lock );
return strdup( "" );
}
int vlc_input_item_AddInfo( input_item_t *p_i,
const char *psz_cat,
const char *psz_name,
const char *psz_format, ... )
{
va_list args;
int i;
info_t *p_info = NULL;
info_category_t *p_cat = NULL ;
vlc_mutex_lock( &p_i->lock );
for( i = 0 ; i < p_i->i_categories ; i ++ )
{
if( !strcmp( p_i->pp_categories[i]->psz_name, psz_cat ) )
{
p_cat = p_i->pp_categories[i];
break;
}
}
if( !p_cat )
{
if( ( p_cat = (info_category_t *)malloc(
sizeof( info_category_t ) ) ) == NULL )
{
vlc_mutex_unlock( &p_i->lock );
return VLC_EGENERIC;
}
p_cat->psz_name = strdup( psz_cat );
p_cat->i_infos = 0;
p_cat->pp_infos = 0;
INSERT_ELEM( p_i->pp_categories, p_i->i_categories, p_i->i_categories,
p_cat );
}
for( i = 0; i< p_cat->i_infos; i++ )
{
if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
{
p_info = p_cat->pp_infos[i];
break;
}
}
if( !p_info )
{
if( ( p_info = (info_t *)malloc( sizeof( info_t ) ) ) == NULL )
{
vlc_mutex_unlock( &p_i->lock );
return VLC_EGENERIC;
}
INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
p_info->psz_name = strdup( psz_name );
}
else
{
if( p_info->psz_value ) free( p_info->psz_value );
}
va_start( args, psz_format );
vasprintf( &p_info->psz_value, psz_format, args);
va_end( args );
vlc_mutex_unlock( &p_i->lock );
return VLC_SUCCESS;
}
/*****************************************************************************
* info.c : Playlist info management
*****************************************************************************
* 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"
/**
* Get one special info
* Must be entered with playlist lock
*
* \param p_playlist the playlist to get the info from
* \param i_pos position of the item on
* which we want the info ( -1 for current )
* \param psz_cat the category in which the info is stored
* \param psz_name the name of the info
* \return the info value if any, an empty string else
*/
char * playlist_GetInfo( playlist_t *p_playlist, int i_pos,
const char *psz_cat, const char *psz_name )
{
playlist_item_t *p_item;
char *psz_buffer;
/* Sanity check */
if( p_playlist == NULL) return strdup("");
p_item = playlist_ItemGetByPos( p_playlist, i_pos );
if( !p_item ) return strdup("");
vlc_mutex_lock( &p_item->input.lock );
psz_buffer = playlist_ItemGetInfo( p_item , psz_cat, psz_name );
vlc_mutex_unlock( &p_item->input.lock );
return psz_buffer;
}
/**
* Get one special info, from an item (no need for p_playlist)
*
* \param p_item the item on which we want the info
* \param psz_cat the category in which the info is stored
* \param psz_name the name of the info
* \return the info value if any, an empty string else
*/
char * playlist_ItemGetInfo( playlist_item_t *p_item,
const char * psz_cat, const char *psz_name )
{
int i, j;
for( i = 0 ; i< p_item->input.i_categories ; i++ )
{
info_category_t *p_category = p_item->input.pp_categories[i];
if( !psz_cat || strcmp( p_category->psz_name , psz_cat ) ) continue;
for( j = 0 ; j< p_category->i_infos ; j++ )
{
if( !strcmp( p_category->pp_infos[j]->psz_name, psz_name) )
{
return strdup( p_category->pp_infos[j]->psz_value );
}
}
}
return strdup("");
}
/**
* Get one info category (no p_playlist). Create it if it does not exist
*
* \param p_item the playlist item to get the category from
* \param psz_cat the category we want
* \return the info category.
*/
info_category_t * playlist_ItemGetCategory( playlist_item_t *p_item,
const char *psz_cat )
{
int i;
/* Search the category */
for( i = 0 ; i< p_item->input.i_categories ; i++ )
{
if( !strncmp( p_item->input.pp_categories[i]->psz_name, psz_cat,
strlen(psz_cat) ) )
{
return p_item->input.pp_categories[i];
}
}
/* We did not find the category, create it */
return playlist_ItemCreateCategory( p_item, psz_cat );
}
/**
* Create one info category for an item ( no p_playlist required )
*
* \param p_item the item to create category for
* \param psz_cat the category we want to create
* \return the info category.
*/
info_category_t * playlist_ItemCreateCategory( playlist_item_t *p_item,
const char *psz_cat )
{
info_category_t *p_cat;
int i;
for( i = 0 ; i< p_item->input.i_categories ; i++)
{
if( !strcmp( p_item->input.pp_categories[i]->psz_name,psz_cat ) )
{
return p_item->input.pp_categories[i];
}
}
if( ( p_cat = malloc( sizeof( info_category_t) ) ) == NULL )
{
return NULL;
}
p_cat->psz_name = strdup( psz_cat);
p_cat->i_infos = 0;
p_cat->pp_infos = NULL;
INSERT_ELEM( p_item->input.pp_categories, p_item->input.i_categories,
p_item->input.i_categories, p_cat );
return p_cat;
}
/**
* Add an info item
*
* \param p_playlist the playlist
* \param i_item the position of the item on which we want
* the info ( -1 for current )
* \param psz_cat the category we want to put the info into
* (gets created if needed)
* \param psz_name the name of the info
* \param psz_format printf-style info
* \return VLC_SUCCESS
*/
int playlist_AddInfo( playlist_t *p_playlist, int i_item,
const char * psz_cat, const char *psz_name,
const char * psz_format, ...)
{
va_list args;
int i_ret;
playlist_item_t *p_item;
char *psz_value;
/* Sanity check */
if( p_playlist == NULL) return VLC_EGENERIC;
p_item = playlist_ItemGetByPos( p_playlist, i_item );
if( !p_item ) return VLC_ENOOBJ;
va_start( args, psz_format );
vasprintf( &psz_value, psz_format, args );
va_end( args );
vlc_mutex_lock( &p_item->input.lock );
i_ret = playlist_ItemAddInfo( p_item, psz_cat, psz_name, psz_value );
vlc_mutex_unlock( &p_item->input.lock );
free( psz_value );
return i_ret;
}
/**
* Add info to one item ( no need for p_playlist )
*
* \param p_item the item for which we add the info
* \param psz_cat the category in which the info is stored
* \param psz_name the name of the info
* \param psz_format printf-style info
* \return VLC_SUCCESS on success
*/
int playlist_ItemAddInfo( playlist_item_t *p_item,
const char *psz_cat, const char *psz_name,
const char *psz_format, ... )
{
va_list args;
int i;
int i_new = VLC_TRUE;
info_t *p_info = NULL;
info_category_t *p_cat;
/* Find or create the category */
p_cat = playlist_ItemGetCategory( p_item, psz_cat );
if( p_cat == NULL) return VLC_EGENERIC;
for( i = 0 ; i< p_cat->i_infos ; i++)
{
if( !strcmp( p_cat->pp_infos[i]->psz_name, psz_name ) )
{
/* This info is not new */
p_info = p_cat->pp_infos[i];
i_new = VLC_FALSE;
break;
}
}
/* New info, create it */
if( p_info == NULL )
{
if( ( p_info = malloc( sizeof( info_t) ) ) == NULL )
{
return VLC_EGENERIC;
}
p_info->psz_name = strdup( psz_name);
}
else
{
if( p_info->psz_value != NULL ) free( p_info->psz_value ) ;
}
va_start( args, psz_format );
vasprintf( &p_info->psz_value, psz_format, args );
va_end( args );
/* If this is new, insert it */
if( i_new == VLC_TRUE )
{
INSERT_ELEM( p_cat->pp_infos, p_cat->i_infos, p_cat->i_infos, p_info );
}
return VLC_SUCCESS;
}
......@@ -27,6 +27,7 @@
#include <vlc/vlc.h>
#include <vlc/input.h>
#include "vlc_input.h"
#include "vlc_playlist.h"
static void GuessType( input_item_t *p_item);
......@@ -87,8 +88,6 @@ playlist_item_t * playlist_ItemNewWithType( vlc_object_t *p_obj,
if( p_item->input.i_type == ITEM_TYPE_UNKNOWN )
GuessType( &p_item->input );
playlist_ItemCreateCategory( p_item, _("General") );
return p_item;
}
......@@ -276,8 +275,8 @@ int playlist_ItemSetDuration( playlist_item_t *p_item, mtime_t i_duration )
{
memcpy( psz_buffer, "--:--:--", sizeof("--:--:--") );
}
playlist_ItemAddInfo( p_item, _("General") , _("Duration"),
"%s", psz_buffer );
vlc_input_item_AddInfo( &p_item->input, _("General") , _("Duration"),
"%s", psz_buffer );
return VLC_SUCCESS;
}
......
......@@ -237,7 +237,7 @@ int playlist_NodeGroup( playlist_t * p_playlist , int i_view,
}
else if ( i_mode == SORT_AUTHOR )
{
psz_search = playlist_ItemGetInfo( pp_items[i],
psz_search = vlc_input_item_GetInfo( &pp_items[i]->input,
_("Meta-information"), _( "Artist" ) );
}
......
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