Commit 517a7e7b authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

input item: use vlc_list for per-category infos

parent 48cd0dd4
......@@ -33,6 +33,7 @@
#include <vlc_meta.h>
#include <vlc_epg.h>
#include <vlc_events.h>
#include <vlc_list.h>
#include <string.h>
......@@ -43,13 +44,15 @@ struct info_t
{
char *psz_name; /**< Name of this info */
char *psz_value; /**< Value of the info */
struct vlc_list node;
};
#define info_foreach(info, cat) vlc_list_foreach(info, cat, node)
struct info_category_t
{
char *psz_name; /**< Name of this category */
int i_infos; /**< Number of infos in the category */
struct info_t **pp_infos; /**< Pointer to an array of infos */
struct vlc_list infos; /**< Infos in the category */
};
/**
......
......@@ -659,21 +659,19 @@ static void *Run( void *data )
{
if( p_sys->p_input )
{
int i, j;
int i;
vlc_mutex_lock( &input_GetItem(p_sys->p_input)->lock );
for ( i = 0; i < input_GetItem(p_sys->p_input)->i_categories; i++ )
{
info_category_t *p_category = input_GetItem(p_sys->p_input)
->pp_categories[i];
info_t *p_info;
msg_rc( "+----[ %s ]", p_category->psz_name );
msg_rc( "| " );
for ( j = 0; j < p_category->i_infos; j++ )
{
info_t *p_info = p_category->pp_infos[j];
info_foreach(p_info, &p_category->infos)
msg_rc( "| %s: %s", p_info->psz_name,
p_info->psz_value );
}
msg_rc( "| " );
}
msg_rc( "+----[ end of stream info ]" );
......
......@@ -297,6 +297,7 @@ FREENULL( psz_##foo );
for (int i = 0; i < p_item->i_categories; i++) {
info_category_t *cat = p_item->pp_categories[i];
info_t *info;
VLCInfoTreeItem *subItem = [[VLCInfoTreeItem alloc] init];
subItem.name = toNSStr(cat->psz_name);
......@@ -304,10 +305,10 @@ FREENULL( psz_##foo );
// Build list of codec details
NSMutableArray *infos = [NSMutableArray array];
for (int j = 0; j < cat->i_infos; j++) {
info_foreach(info, &cat->infos) {
VLCInfoTreeItem *infoItem = [[VLCInfoTreeItem alloc] init];
infoItem.name = toNSStr(cat->pp_infos[j]->psz_name);
infoItem.value = toNSStr(cat->pp_infos[j]->psz_value);
infoItem.name = toNSStr(info->psz_name);
infoItem.value = toNSStr(info->psz_value);
[infos addObject:infoItem];
}
......
......@@ -776,14 +776,14 @@ static int DrawInfo(intf_thread_t *intf, input_thread_t *p_input)
vlc_mutex_lock(&item->lock);
for (int i = 0; i < item->i_categories; i++) {
info_category_t *p_category = item->pp_categories[i];
info_t *p_info;
if (sys->color) color_set(C_CATEGORY, NULL);
MainBoxWrite(sys, l++, _(" [%s]"), p_category->psz_name);
if (sys->color) color_set(C_DEFAULT, NULL);
for (int j = 0; j < p_category->i_infos; j++) {
info_t *p_info = p_category->pp_infos[j];
info_foreach(p_info, &p_category->infos)
MainBoxWrite(sys, l++, _(" %s: %s"),
p_info->psz_name, p_info->psz_value);
}
}
vlc_mutex_unlock(&item->lock);
......
......@@ -502,18 +502,19 @@ void InfoPanel::update( input_item_t *p_item)
for( int i = 0; i< p_item->i_categories ; i++)
{
struct vlc_list *const head = &p_item->pp_categories[i]->infos;
current_item = new QTreeWidgetItem();
current_item->setText( 0, qfu(p_item->pp_categories[i]->psz_name) );
InfoTree->addTopLevelItem( current_item );
for( int j = 0 ; j < p_item->pp_categories[i]->i_infos ; j++ )
for (info_t *info = vlc_list_first_entry_or_null(head, info_t, node);
info != NULL;
info = vlc_list_next_entry_or_null(head, info, info_t, node))
{
child_item = new QTreeWidgetItem ();
child_item->setText( 0,
qfu(p_item->pp_categories[i]->pp_infos[j]->psz_name)
+ ": "
+ qfu(p_item->pp_categories[i]->pp_infos[j]->psz_value));
child_item->setText( 0, qfu(info->psz_name) + ": "
+ qfu(info->psz_value));
current_item->addChild(child_item);
}
InfoTree->setItemExpanded( current_item, true);
......
......@@ -80,13 +80,12 @@ static int vlclua_input_item_info( lua_State *L )
for( i = 0; i < i_cat; i++ )
{
info_category_t *p_category = p_item->pp_categories[i];
int i_infos = p_category->i_infos;
int j;
info_t *p_info;
lua_pushstring( L, p_category->psz_name );
lua_createtable( L, 0, i_infos );
for( j = 0; j < i_infos; j++ )
lua_newtable( L );
info_foreach(p_info, &p_category->infos)
{
info_t *p_info = p_category->pp_infos[j];
lua_pushstring( L, p_info->psz_name );
lua_pushstring( L, p_info->psz_value );
lua_settable( L, -3 );
......
......@@ -50,47 +50,42 @@ static inline info_category_t *info_category_New(const char *name)
if (!cat)
return NULL;
cat->psz_name = strdup(name);
cat->i_infos = 0;
cat->pp_infos = NULL;
vlc_list_init(&cat->infos);
return cat;
}
static inline info_t *info_category_FindInfo(const info_category_t *cat,
int *index, const char *name)
const char *name)
{
for (int i = 0; i < cat->i_infos; i++) {
if (!strcmp(cat->pp_infos[i]->psz_name, name)) {
if (index)
*index = i;
return cat->pp_infos[i];
}
}
info_t *info;
info_foreach(info, &cat->infos)
if (!strcmp(info->psz_name, name))
return info;
return NULL;
}
static inline void info_category_ReplaceInfo(info_category_t *cat,
info_t *info)
{
int index;
info_t *old = info_category_FindInfo(cat, &index, info->psz_name);
info_t *old = info_category_FindInfo(cat, info->psz_name);
if (old) {
info_Delete(cat->pp_infos[index]);
cat->pp_infos[index] = info;
} else
TAB_APPEND(cat->i_infos, cat->pp_infos, info);
vlc_list_remove(&old->node);
info_Delete(old);
}
vlc_list_append(&info->node, &cat->infos);
}
static inline info_t *info_category_VaAddInfo(info_category_t *cat,
const char *name,
const char *format, va_list args)
{
info_t *info = info_category_FindInfo(cat, NULL, name);
info_t *info = info_category_FindInfo(cat, name);
if (!info) {
info = info_New(name);
if (!info)
return NULL;
TAB_APPEND(cat->i_infos, cat->pp_infos, info);
vlc_list_append(&info->node, &cat->infos);
} else
free(info->psz_value);
if (vasprintf(&info->psz_value, format, args) == -1)
......@@ -113,10 +108,10 @@ static inline info_t *info_category_AddInfo(info_category_t *cat,
static inline int info_category_DeleteInfo(info_category_t *cat, const char *name)
{
int index;
if (info_category_FindInfo(cat, &index, name)) {
info_Delete(cat->pp_infos[index]);
TAB_ERASE(cat->i_infos, cat->pp_infos, index);
info_t *info = info_category_FindInfo(cat, name);
if (info != NULL) {
vlc_list_remove(&info->node);
info_Delete(info);
return VLC_SUCCESS;
}
return VLC_EGENERIC;
......@@ -124,9 +119,12 @@ static inline int info_category_DeleteInfo(info_category_t *cat, const char *nam
static inline void info_category_Delete(info_category_t *cat)
{
for (int i = 0; i < cat->i_infos; i++)
info_Delete(cat->pp_infos[i]);
free(cat->pp_infos);
info_t *info;
while ((info = vlc_list_first_entry_or_null(&cat->infos, info_t, node))) {
vlc_list_remove(&info->node);
info_Delete(info);
}
free(cat->psz_name);
free(cat);
}
......
......@@ -731,7 +731,7 @@ char *input_item_GetInfo( input_item_t *p_i,
const info_category_t *p_cat = InputItemFindCat( p_i, NULL, psz_cat );
if( p_cat )
{
info_t *p_info = info_category_FindInfo( p_cat, NULL, psz_name );
info_t *p_info = info_category_FindInfo( p_cat, psz_name );
if( p_info && p_info->psz_value )
{
char *psz_ret = strdup( p_info->psz_value );
......@@ -847,9 +847,11 @@ void input_item_MergeInfos( input_item_t *p_item, info_category_t *p_cat )
info_category_t *p_old = InputItemFindCat( p_item, NULL, p_cat->psz_name );
if( p_old )
{
for( int i = 0; i < p_cat->i_infos; i++ )
info_category_ReplaceInfo( p_old, p_cat->pp_infos[i] );
TAB_CLEAN( p_cat->i_infos, p_cat->pp_infos );
info_t *info;
info_foreach(info, &p_cat->infos)
info_category_ReplaceInfo( p_old, info );
vlc_list_init( &p_cat->infos );
info_category_Delete( p_cat );
}
else
......
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