[vlc-devel] [PATCH 2/5] gui/qt: extended_panels: refactor ChangeFiltersString

Filip Roséen filip at atch.se
Sat Feb 25 07:31:42 CET 2017


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.
---
 modules/gui/qt/components/extended_panels.cpp | 58 ++++-----------------------
 1 file changed, 7 insertions(+), 51 deletions(-)

diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/gui/qt/components/extended_panels.cpp
index 4a3d7d3ade..c2c375d037 100644
--- a/modules/gui/qt/components/extended_panels.cpp
+++ b/modules/gui/qt/components/extended_panels.cpp
@@ -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 )
-- 
2.11.1



More information about the vlc-devel mailing list