Commit 076ff7c9 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt4 - Fix the segfault that can occur when opening directories, especially...

Qt4 - Fix the segfault that can occur when opening directories, especially multiple directories ( known as the thresh bug... )

parent a35dfea7
...@@ -63,6 +63,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m ) ...@@ -63,6 +63,7 @@ void PLItem::init( int _i_id, int _i_input_id, PLItem *parent, PLModel *m )
parentItem = parent; parentItem = parent;
i_id = _i_id; i_input_id = _i_input_id; i_id = _i_id; i_input_id = _i_input_id;
model = m; model = m;
i_type = -1; /* Avoid segfault */
if( parentItem == NULL ) if( parentItem == NULL )
{ {
...@@ -170,7 +171,7 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent ) ...@@ -170,7 +171,7 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
char psz_duration[MSTRTIME_MAX_SIZE]; char psz_duration[MSTRTIME_MAX_SIZE];
assert( p_item->p_input->i_id == i_input_id ); assert( p_item->p_input->i_id == i_input_id );
type = p_item->p_input->i_type; i_type = p_item->p_input->i_type;
current = iscurrent; current = iscurrent;
strings.clear(); strings.clear();
...@@ -203,7 +204,9 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent ) ...@@ -203,7 +204,9 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
if( psz_title ) if( psz_title )
{ {
ADD_META( p_item, Title ); ADD_META( p_item, Title );
} else { }
else if( psz_name )
{
strings.append( qfu( psz_name ) ); strings.append( qfu( psz_name ) );
} }
free( psz_title ); free( psz_title );
...@@ -255,7 +258,7 @@ PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf, ...@@ -255,7 +258,7 @@ PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf,
i_cached_input_id = -1; i_cached_input_id = -1;
i_popup_item = i_popup_parent = -1; i_popup_item = i_popup_parent = -1;
#define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) ); #define ADD_ICON(type, x) icons[ITEM_TYPE_##type] = QIcon( QPixmap( x ) )
ADD_ICON( UNKNOWN , type_unknown_xpm ); ADD_ICON( UNKNOWN , type_unknown_xpm );
ADD_ICON( FILE, ":/pixmaps/type_file.png" ); ADD_ICON( FILE, ":/pixmaps/type_file.png" );
ADD_ICON( DIRECTORY, ":/pixmaps/type_directory.png" ); ADD_ICON( DIRECTORY, ":/pixmaps/type_directory.png" );
...@@ -265,6 +268,7 @@ PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf, ...@@ -265,6 +268,7 @@ PLModel::PLModel( playlist_t *_p_playlist, intf_thread_t *_p_intf,
ADD_ICON( NET, ":/pixmaps/type_net.png" ); ADD_ICON( NET, ":/pixmaps/type_net.png" );
ADD_ICON( PLAYLIST, ":/pixmaps/type_playlist.png" ); ADD_ICON( PLAYLIST, ":/pixmaps/type_playlist.png" );
ADD_ICON( NODE, ":/pixmaps/type_node.png" ); ADD_ICON( NODE, ":/pixmaps/type_node.png" );
#undef ADD_ICON
rootItem = NULL; rootItem = NULL;
addCallbacks(); addCallbacks();
...@@ -458,8 +462,9 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const ...@@ -458,8 +462,9 @@ QVariant PLModel::data( const QModelIndex &index, int role ) const
} }
else if( role == Qt::DecorationRole && index.column() == 0 ) else if( role == Qt::DecorationRole && index.column() == 0 )
{ {
if( item->type >= 0 ) /* Use to segfault here because i_type wasn't always initialized */
return QVariant( PLModel::icons[item->type] ); if( item->i_type >= 0 )
return QVariant( PLModel::icons[item->i_type] );
} }
else if( role == Qt::FontRole ) else if( role == Qt::FontRole )
{ {
...@@ -960,44 +965,39 @@ void PLModel::viewchanged( int meta ) ...@@ -960,44 +965,39 @@ void PLModel::viewchanged( int meta )
switch( meta ) switch( meta )
{ {
case VLC_META_ENGINE_TITLE: case VLC_META_ENGINE_TITLE:
index=0; index=0; break;
break;
case VLC_META_ENGINE_DURATION: case VLC_META_ENGINE_DURATION:
index=1; index=1; break;
break;
case VLC_META_ENGINE_ARTIST: case VLC_META_ENGINE_ARTIST:
index=2; index=2; break;
break;
case VLC_META_ENGINE_GENRE: case VLC_META_ENGINE_GENRE:
index=3; index=3; break;
break;
case VLC_META_ENGINE_COPYRIGHT: case VLC_META_ENGINE_COPYRIGHT:
index=4; index=4; break;
break;
case VLC_META_ENGINE_COLLECTION: case VLC_META_ENGINE_COLLECTION:
index=5; index=5; break;
break;
case VLC_META_ENGINE_SEQ_NUM: case VLC_META_ENGINE_SEQ_NUM:
index=6; index=6; break;
break;
case VLC_META_ENGINE_DESCRIPTION: case VLC_META_ENGINE_DESCRIPTION:
index=7; index=7; break;
break;
default: default:
break; break;
} }
emit layoutAboutToBeChanged(); /* UNUSED emit layoutAboutToBeChanged(); */
index = __MIN( index , rootItem->strings.count() ); index = __MIN( index , rootItem->strings.count() );
QModelIndex parent = createIndex( 0, 0, rootItem ); QModelIndex parent = createIndex( 0, 0, rootItem );
if( rootItem->i_showflags & meta ) if( rootItem->i_showflags & meta )
/* Removing columns */
{ {
beginRemoveColumns( parent , index, index+1 ); beginRemoveColumns( parent, index, index+1 );
rootItem->i_showflags &= ~( meta ); rootItem->i_showflags &= ~( meta );
rootItem->updateview(); rootItem->updateview();
endRemoveColumns(); endRemoveColumns();
} }
else else
{ {
/* Adding columns */
beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 ); beginInsertColumns( createIndex( 0, 0, rootItem), index, index+1 );
rootItem->i_showflags |= meta; rootItem->i_showflags |= meta;
rootItem->updateview(); rootItem->updateview();
...@@ -1111,3 +1111,4 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable, ...@@ -1111,3 +1111,4 @@ static int ItemAppended( vlc_object_t *p_this, const char *psz_variable,
QApplication::postEvent( p_model, static_cast<QEvent*>(event) ); QApplication::postEvent( p_model, static_cast<QEvent*>(event) );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
...@@ -62,7 +62,7 @@ protected: ...@@ -62,7 +62,7 @@ protected:
QList<PLItem*> children; QList<PLItem*> children;
QList<QString> strings; QList<QString> strings;
bool current; bool current;
int type; int i_type;
int i_id; int i_id;
int i_input_id; int i_input_id;
int i_showflags; int i_showflags;
......
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