[vlc-devel] [PATCH 4/7] qt: use vlc_object_get_desc_tree

Thomas Guillem thomas at gllm.fr
Mon May 27 16:45:13 CEST 2019


Refs #21997
---
 include/vlc_objects.h                         |  4 +-
 .../qt/components/complete_preferences.cpp    | 37 +++++---------
 modules/gui/qt/dialogs/messages.cpp           | 50 ++++++++-----------
 modules/gui/qt/dialogs/messages.hpp           |  2 +-
 4 files changed, 37 insertions(+), 56 deletions(-)

diff --git a/include/vlc_objects.h b/include/vlc_objects.h
index 33c6dffdbd..50ffe0f812 100644
--- a/include/vlc_objects.h
+++ b/include/vlc_objects.h
@@ -152,9 +152,9 @@ VLC_API void vlc_object_delete(vlc_object_t *obj);
 VLC_API size_t vlc_list_children(vlc_object_t *, vlc_object_t **, size_t) VLC_USED;
 
 /**
- * Return a tree of object descriptions
+ * Return a tree of object description
  *
- * @param root root object whose children are to be described
+ * @param root object whose children are to be described
  *
  * @return a valid tree description or NULL in case of error, need to be freed
  * with vlc_object_desc_release()
diff --git a/modules/gui/qt/components/complete_preferences.cpp b/modules/gui/qt/components/complete_preferences.cpp
index 3b972aac6c..b6cf4a19a2 100644
--- a/modules/gui/qt/components/complete_preferences.cpp
+++ b/modules/gui/qt/components/complete_preferences.cpp
@@ -397,32 +397,15 @@ bool PrefsTree::collapseUnselectedItems( QTreeWidgetItem *item )
     return collapsed;
 }
 
-static void populateLoadedSet( QSet<QString> *loaded, vlc_object_t *p_node )
+static void populateLoadedSet( QSet<QString> *loaded,
+                               vlc_object_desc_t *node )
 {
     Q_ASSERT( loaded );
-    char *name = vlc_object_get_name( p_node );
-    if ( !EMPTY_STR( name ) ) loaded->insert( QString( name ) );
-    free( name );
+    if ( !EMPTY_STR( node->module_name ) ) loaded->insert( QString( node->module_name ) );
 
-    size_t count = 0, size;
-    vlc_object_t **tab = NULL;
-
-    do
-    {
-        delete[] tab;
-        size = count;
-        tab = new vlc_object_t *[size];
-        count = vlc_list_children(p_node, tab, size);
-    }
-    while (size < count);
-
-    for (size_t i = 0; i < count ; i++)
-    {
-        populateLoadedSet( loaded, tab[i] );
-        vlc_object_release(tab[i]);
-    }
-
-    delete[] tab;
+    vlc_object_desc_t *child;
+    vlc_vector_foreach(child, &node->children)
+        populateLoadedSet( loaded, child );
 }
 
 /* Updates the PrefsItemData loaded status to reflect currently
@@ -436,7 +419,13 @@ void PrefsTree::updateLoadedStatus( QTreeWidgetItem *item = NULL,
     {
         vlc_object_t *p_root = VLC_OBJECT( vlc_object_instance(p_intf) );
         loaded = new QSet<QString>();
-        populateLoadedSet( loaded, p_root );
+
+        vlc_object_desc_t *node = vlc_object_get_desc_tree(p_root);
+        if (node)
+        {
+            populateLoadedSet(loaded, node);
+            vlc_object_desc_release(node);
+        }
         b_release = true;
     }
 
diff --git a/modules/gui/qt/dialogs/messages.cpp b/modules/gui/qt/dialogs/messages.cpp
index a09178d12e..80f9b3f3be 100644
--- a/modules/gui/qt/dialogs/messages.cpp
+++ b/modules/gui/qt/dialogs/messages.cpp
@@ -141,7 +141,12 @@ MessagesDialog::MessagesDialog( intf_thread_t *_p_intf)
 
     vlc_LogSet( vlc, &log_ops, this );
 
-    buildTree( NULL, VLC_OBJECT(vlc) );
+    vlc_object_desc_t *node = vlc_object_get_desc_tree(VLC_OBJECT(vlc));
+    if (node)
+    {
+        buildTree(NULL, node);
+        vlc_object_desc_release(node);
+    }
 }
 
 MessagesDialog::~MessagesDialog()
@@ -299,7 +304,7 @@ bool MessagesDialog::save()
 }
 
 void MessagesDialog::buildTree( QTreeWidgetItem *parentItem,
-                                vlc_object_t *p_obj )
+                                vlc_object_desc_t *node )
 {
     QTreeWidgetItem *item;
 
@@ -308,36 +313,17 @@ void MessagesDialog::buildTree( QTreeWidgetItem *parentItem,
     else
         item = new QTreeWidgetItem( ui.modulesTree );
 
-    char *name = vlc_object_get_name( p_obj );
-    item->setText( 0, QString("%1%2 (0x%3)")
-                   .arg( qfu( vlc_object_typename(p_obj) ) )
-                   .arg( ( name != NULL )
-                         ? QString( " \"%1\"" ).arg( qfu( name ) )
+    item->setText( 0, QString("%1%2")
+                   .arg( qfu( node->type_name ) )
+                   .arg( ( node->module_name != NULL )
+                         ? QString( " \"%1\"" ).arg( qfu( node->module_name ) )
                              : "" )
-                   .arg( (uintptr_t)p_obj, 0, 16 )
                  );
-    free( name );
     item->setExpanded( true );
 
-    size_t count = 0, size;
-    vlc_object_t **tab = NULL;
-
-    do
-    {
-        delete[] tab;
-        size = count;
-        tab = new vlc_object_t *[size];
-        count = vlc_list_children(p_obj, tab, size);
-    }
-    while (size < count);
-
-    for (size_t i = 0; i < count ; i++)
-    {
-        buildTree( item, tab[i] );
-        vlc_object_release(tab[i]);
-    }
-
-    delete[] tab;
+    vlc_object_desc_t *child;
+    vlc_vector_foreach(child, &node->children)
+        buildTree(item, child);
 }
 
 void MessagesDialog::updateOrClear()
@@ -345,7 +331,13 @@ void MessagesDialog::updateOrClear()
     if( ui.mainTab->currentIndex() == 1)
     {
         ui.modulesTree->clear();
-        buildTree( NULL, VLC_OBJECT( vlc_object_instance(p_intf) ) );
+        vlc_object_desc_t *node =
+            vlc_object_get_desc_tree(VLC_OBJECT(vlc_object_instance(p_intf)));
+        if (node)
+        {
+            buildTree(NULL, node);
+            vlc_object_desc_release(node);
+        }
     }
     else if( ui.mainTab->currentIndex() == 0 )
         ui.messages->clear();
diff --git a/modules/gui/qt/dialogs/messages.hpp b/modules/gui/qt/dialogs/messages.hpp
index 32ea0be910..fd19557be3 100644
--- a/modules/gui/qt/dialogs/messages.hpp
+++ b/modules/gui/qt/dialogs/messages.hpp
@@ -61,7 +61,7 @@ private slots:
     void filterMessages();
 
 private:
-    void buildTree( QTreeWidgetItem *, vlc_object_t * );
+    void buildTree( QTreeWidgetItem *, vlc_object_desc_t *node );
 
     friend class    Singleton<MessagesDialog>;
     QPushButton *updateButton;
-- 
2.20.1



More information about the vlc-devel mailing list