[vlc-commits] Qt4: use QString or QByteArray instead of strdup()/free()

Rémi Denis-Courmont git at videolan.org
Sat Jun 18 11:58:30 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Jun 18 12:53:12 2011 +0300| [20dc6cedb422ce6cc54bbec04d837e7f022b1489] | committer: Rémi Denis-Courmont

Qt4: use QString or QByteArray instead of strdup()/free()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=20dc6cedb422ce6cc54bbec04d837e7f022b1489
---

 modules/gui/qt4/components/extended_panels.cpp    |   28 ++++++++++----------
 modules/gui/qt4/components/simple_preferences.cpp |   13 ++++-----
 modules/gui/qt4/dialogs_provider.cpp              |    8 ++---
 3 files changed, 23 insertions(+), 26 deletions(-)

diff --git a/modules/gui/qt4/components/extended_panels.cpp b/modules/gui/qt4/components/extended_panels.cpp
index b3f5501..cfa162c 100644
--- a/modules/gui/qt4/components/extended_panels.cpp
+++ b/modules/gui/qt4/components/extended_panels.cpp
@@ -615,15 +615,16 @@ void ExtVideo::updateFilterOptions()
     }
     else if( i_type == VLC_VAR_STRING )
     {
-        char *psz_string = NULL;
-        if( lineedit ) psz_string = strdup( qtu( lineedit->text() ) );
-        else if( combobox ) psz_string = strdup( qtu( combobox->itemData(
-                                       combobox->currentIndex() ).toString() ) );
-        else msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
-        config_PutPsz( p_intf, qtu( option ), psz_string );
+        QString val;
+        if( lineedit )
+            val = lineedit->text();
+        else if( combobox )
+            val = combobox->itemData( combobox->currentIndex() ).toString();
+        else
+            msg_Warn( p_intf, "Oops %s %s %d", __FILE__, __func__, __LINE__ );
+        config_PutPsz( p_intf, qtu( option ), qtu( val ) );
         if( b_is_command )
-            var_SetString( p_obj, qtu( option ), psz_string );
-        free( psz_string );
+            var_SetString( p_obj, qtu( option ), qtu( val ) );
     }
     else
         msg_Err( p_intf,
@@ -828,8 +829,8 @@ void ExtV4l2::ValueChange( int value )
     vlc_object_t *p_obj = (vlc_object_t*)vlc_object_find_name( pl_Get(p_intf), "v4l2" );
     if( p_obj )
     {
-        char *psz_var = strdup( qtu( s->objectName() ) );
-        int i_type = var_Type( p_obj, psz_var );
+        QString var = s->objectName();
+        int i_type = var_Type( p_obj, qtu( var ) );
         switch( i_type & VLC_VAR_TYPE )
         {
             case VLC_VAR_INTEGER:
@@ -838,16 +839,15 @@ void ExtV4l2::ValueChange( int value )
                     QComboBox *combobox = qobject_cast<QComboBox*>( s );
                     value = combobox->itemData( value ).toInt();
                 }
-                var_SetInteger( p_obj, psz_var, value );
+                var_SetInteger( p_obj, qtu( var ), value );
                 break;
             case VLC_VAR_BOOL:
-                var_SetBool( p_obj, psz_var, value );
+                var_SetBool( p_obj, qtu( var ), value );
                 break;
             case VLC_VAR_VOID:
-                var_TriggerCallback( p_obj, psz_var );
+                var_TriggerCallback( p_obj, qtu( var ) );
                 break;
         }
-        free( psz_var );
         vlc_object_release( p_obj );
     }
     else
diff --git a/modules/gui/qt4/components/simple_preferences.cpp b/modules/gui/qt4/components/simple_preferences.cpp
index 2a4e6ac..4397337 100644
--- a/modules/gui/qt4/components/simple_preferences.cpp
+++ b/modules/gui/qt4/components/simple_preferences.cpp
@@ -782,14 +782,13 @@ void SPrefsPanel::apply()
     case SPrefsInputAndCodecs:
     {
         /* Device default selection */
-        char *psz_devicepath =
-            strdup( qtu( qobject_cast<QComboBox *>(optionWidgets[inputLE])->currentText() ) );
-        if( !EMPTY_STR( psz_devicepath ) )
+        QByteArray devicepath =
+            qobject_cast<QComboBox *>(optionWidgets[inputLE])->currentText().toUtf8();
+        if( devicepath.size() > 0 )
         {
-            config_PutPsz( p_intf, "dvd", psz_devicepath );
-            config_PutPsz( p_intf, "vcd", psz_devicepath );
-            config_PutPsz( p_intf, "cd-audio", psz_devicepath );
-            free( psz_devicepath );
+            config_PutPsz( p_intf, "dvd", devicepath );
+            config_PutPsz( p_intf, "vcd", devicepath );
+            config_PutPsz( p_intf, "cd-audio", devicepath );
         }
 
 #define CaCi( name, int ) config_PutInt( p_intf, name, int * i_comboValue )
diff --git a/modules/gui/qt4/dialogs_provider.cpp b/modules/gui/qt4/dialogs_provider.cpp
index e73f425..e5db189 100644
--- a/modules/gui/qt4/dialogs_provider.cpp
+++ b/modules/gui/qt4/dialogs_provider.cpp
@@ -726,12 +726,10 @@ void DialogsProvider::menuUpdateAction( QObject *data )
 
 void DialogsProvider::SDMenuAction( const QString& data )
 {
-    char *psz_sd = strdup( qtu( data ) );
-    if( !playlist_IsServicesDiscoveryLoaded( THEPL, psz_sd ) )
-        playlist_ServicesDiscoveryAdd( THEPL, psz_sd );
+    if( !playlist_IsServicesDiscoveryLoaded( THEPL, qtu( data ) ) )
+        playlist_ServicesDiscoveryAdd( THEPL, qtu( data ) );
     else
-        playlist_ServicesDiscoveryRemove( THEPL, psz_sd );
-    free( psz_sd );
+        playlist_ServicesDiscoveryRemove( THEPL, qtu( data ) );
 }
 
 /**



More information about the vlc-commits mailing list