Commit 5f74ae98 authored by Filip Roséen's avatar Filip Roséen Committed by Jean-Baptiste Kempf

gui/qt: extended_panels: refactor ChangeFiltersString

The previous implementation was unnecessary complex, and by using the
utilities available for string manipulation in Qt we can drastically
reduce the lines of code.

These changes also fixes an issue where a user would be unable to
remove a video-filter if the command-line specified the same
video-filter twice.
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 7a728a6f
......@@ -259,61 +259,17 @@ void ExtVideo::clean()
static char *ChangeFiltersString( struct intf_thread_t *p_intf, const char *psz_filter_type, const char *psz_name, bool b_add )
{
char *psz_parser, *psz_string;
char* psz_chain = config_GetPsz( p_intf, psz_filter_type );
psz_string = config_GetPsz( p_intf, psz_filter_type );
QString const chain = QString( psz_chain ? psz_chain : "" );
QStringList list = chain.split( ':', QString::SplitBehavior::SkipEmptyParts );
if( !psz_string ) psz_string = strdup( "" );
if( b_add ) list << psz_name;
else list.removeAll( psz_name );
psz_parser = strstr( psz_string, psz_name );
free( psz_chain );
if( b_add )
{
if( !psz_parser )
{
psz_parser = psz_string;
if( asprintf( &psz_string, ( *psz_string ) ? "%s:%s" : "%s%s",
psz_string, psz_name ) == -1 )
{
free( psz_parser );
return NULL;
}
free( psz_parser );
}
else
{
free( psz_string );
return NULL;
}
}
else
{
if( psz_parser )
{
if( *( psz_parser + strlen( psz_name ) ) == ':' )
{
memmove( psz_parser, psz_parser + strlen( psz_name ) + 1,
strlen( psz_parser + strlen( psz_name ) + 1 ) + 1 );
}
else
{
*psz_parser = '\0';
}
/* Remove trailing : : */
size_t i_len = strlen( psz_string );
if( i_len > 0 && *( psz_string + i_len - 1 ) == ':' )
{
*( psz_string + i_len - 1 ) = '\0';
}
}
else
{
free( psz_string );
return NULL;
}
}
return psz_string;
return strdup( qtu( list.join( ':' ) ) );
}
static void ChangeAFiltersString( struct intf_thread_t *p_intf, const char *psz_name, bool b_add )
......
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