[vlc-commits] [Git][videolan/vlc][master] 6 commits: standardise the hidden options hack

Pierre Lamot gitlab at videolan.org
Wed May 5 11:26:48 UTC 2021



Pierre Lamot pushed to branch master at VideoLAN / VLC


Commits:
fa9432f0 by Lyndon Brown at 2021-05-05T11:09:32+00:00
standardise the hidden options hack

(add common defines for specifying hidden category/subcategory)

- - - - -
19ae9468 by Lyndon Brown at 2021-05-05T11:09:32+00:00
qt: add prefs tree design doc notes

- - - - -
3402aca8 by Lyndon Brown at 2021-05-05T11:09:32+00:00
qt: check node before retrieving config

saves wasting effort

- - - - -
25677455 by Lyndon Brown at 2021-05-05T11:09:32+00:00
qt: improve search logic

this includes a fix for the following flaw: if for any reason a
set_subcategory() call followed by no options was ever placed at the end
of the core option set, then this would have dereferenced memory beyond
the end of the set. (Note that such empty entries currently genuinely
exist in order to ensure that respective tree nodes are created for
modules to attach to, which will be fixed later).

- - - - -
61b1d1b0 by Lyndon Brown at 2021-05-05T11:09:32+00:00
qt: ignore cat-hint items in search

as per comment, these have no relevance to GUI prefs

- - - - -
b731340c by Lyndon Brown at 2021-05-05T11:09:32+00:00
qt: prefs optimisation

- - - - -


6 changed files:

- include/vlc_plugin.h
- modules/gui/macosx/preferences/prefs.m
- modules/gui/qt/dialogs/preferences/complete_preferences.cpp
- modules/gui/qt/dialogs/preferences/complete_preferences.hpp
- modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
- src/libvlc-module.c


Changes:

=====================================
include/vlc_plugin.h
=====================================
@@ -134,6 +134,12 @@ enum vlc_module_properties
 
 #define CONFIG_ITEM(x) (((x) & ~0xF) != 0)
 
+/* Hidden categories and subcategories */
+/* Any options under this will be hidden in the GUI preferences, but will be
+   listed in cmdline help output. */
+#define CAT_HIDDEN -1
+#define SUBCAT_HIDDEN -1
+
 /* Categories and subcategories */
 #define CAT_INTERFACE 1
 #define SUBCAT_INTERFACE_GENERAL 101


=====================================
modules/gui/macosx/preferences/prefs.m
=====================================
@@ -510,7 +510,7 @@
             int configType = p_configs[j].i_type;
 
             if (configType == CONFIG_CATEGORY) {
-                if( p_configs[j].value.i == -1 ) {
+                if( p_configs[j].value.i == CAT_HIDDEN ) {
                     categoryItem = nil;
                     continue;
                 }
@@ -525,7 +525,7 @@
 
             if (configType == CONFIG_SUBCATEGORY) {
                 lastsubcat = (int)p_configs[j].value.i;
-                if( lastsubcat == -1 ) {
+                if( lastsubcat == SUBCAT_HIDDEN ) {
                     subCategoryItem = nil;
                     continue;
                 }


=====================================
modules/gui/qt/dialogs/preferences/complete_preferences.cpp
=====================================
@@ -97,7 +97,7 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent,
         {
         /* This is a category */
         case CONFIG_CATEGORY:
-            if( p_item->value.i == -1 ) break;
+            if( p_item->value.i == CAT_HIDDEN ) break;
 
             /* PrefsItemData Init */
             data = new PrefsItemData( this );
@@ -133,7 +133,7 @@ PrefsTree::PrefsTree( intf_thread_t *_p_intf, QWidget *_parent,
 
         /* This is a subcategory */
         case CONFIG_SUBCATEGORY:
-            if( p_item->value.i == -1 ) break;
+            if( p_item->value.i == SUBCAT_HIDDEN ) break;
 
             /* Special cases: move the main subcategories to the parent cat*/
             if( data &&
@@ -491,89 +491,102 @@ PrefsItemData::PrefsItemData( QObject *_parent ) : QObject( _parent )
  * also search the module name and head */
 bool PrefsItemData::contains( const QString &text, Qt::CaseSensitivity cs )
 {
-    /* Find our module */
-    module_t *p_module = NULL;
     if( this->i_type == TYPE_CATEGORY )
         return false;
-    else if( this->i_type == TYPE_MODULE )
+
+    bool is_core = this->i_type != TYPE_MODULE;
+    int id = 0;
+
+    /* find our module */
+    module_t *p_module;
+    if( !is_core )
         p_module = this->p_module;
     else
     {
         p_module = module_get_main();
         assert( p_module );
+
+        if( this->i_type == TYPE_SUBCATEGORY )
+            id = this->i_object_id;
+        else // TYPE_CATSUBCAT
+            id = this->i_subcat_id;
     }
 
+    /* check the node itself (its name/longname/helptext) */
+
+    QString head;
+    if( is_core )
+        head.clear();
+    else
+        head = QString( qfut( module_GetLongName( p_module ) ) );
+
+    if ( name.contains( text, cs )
+         || (!is_core && head.contains( text, cs ))
+         || help.contains( text, cs )
+       )
+    {
+        return true;
+    }
+
+    /* check options belonging to this subcat or module */
+
     unsigned confsize;
     module_config_t *const p_config = module_config_get (p_module, &confsize),
                     *p_item = p_config,
                     *p_end = p_config + confsize;
 
-    if( this->i_type == TYPE_SUBCATEGORY || this->i_type ==  TYPE_CATSUBCAT )
+    if( !p_config )
+        return false;
+
+    bool ret = false;
+
+    if( is_core )
     {
+        /* find start of relevant option block */
         while ( p_item < p_end )
         {
             if( p_item->i_type == CONFIG_SUBCATEGORY &&
-                (
-                    ( this->i_type == TYPE_SUBCATEGORY &&
-                              p_item->value.i == this->i_object_id )
-                    ||
-                    ( this->i_type == TYPE_CATSUBCAT &&
-                              p_item->value.i == this->i_subcat_id )
-                )
+                p_item->value.i == id
               )
                 break;
             p_item++;
         }
+        if( ++p_item >= p_end )
+        {
+            ret = false;
+            goto end;
+        }
     }
 
-    QString head;
-
-    if( this->i_type == TYPE_SUBCATEGORY || this->i_type ==  TYPE_CATSUBCAT )
-    {
-        head.clear();
-        p_item++; // Why that ? +1
-    }
-    else
-    {
-        head = QString( qfut( module_GetLongName( p_module ) ) );
-    }
-
-    if (name.contains( text, cs ) || head.contains( text, cs ) || help.contains( text, cs ))
-    {
-        module_config_free( p_config );
-        return true;
-    }
-
-    if( p_item ) do
+    do
     {
-        if (
-            (
-                ( this->i_type == TYPE_SUBCATEGORY && p_item->value.i != this->i_object_id )
-                ||
-                ( this->i_type == TYPE_CATSUBCAT && p_item->value.i != this->i_subcat_id )
-            ) &&
-            ( p_item->i_type == CONFIG_CATEGORY || p_item->i_type == CONFIG_SUBCATEGORY )
-           ) break;
+        if ( p_item->i_type == CONFIG_CATEGORY || p_item->i_type == CONFIG_SUBCATEGORY )
+        {
+            /* for core, if we hit a cat or subcat, stop */
+            if ( is_core )
+                break;
+            /* a module's options are grouped under one node; we can/should
+               ignore all cat/subcat entries. */
+            continue;
+        }
 
+        /* private options (hidden from GUI but not help output) are not relevant */
         if( p_item->b_internal ) continue;
 
+        /* cat-hint items are not relevant, they are an alternate set of headings for help output */
+        if( p_item->i_type == CONFIG_HINT_CATEGORY ) continue;
+
         if ( p_item->psz_text && qfut( p_item->psz_text ).contains( text, cs ) )
         {
-            module_config_free( p_config );
-            return true;
+            ret = true;
+            goto end;
         }
     }
-    while (
-            !(
-                ( this->i_type == TYPE_SUBCATEGORY || this->i_type == TYPE_CATSUBCAT )
-                &&
-                ( p_item->i_type == CONFIG_CATEGORY || p_item->i_type == CONFIG_SUBCATEGORY )
-             )
-             && ( ++p_item < p_end )
-          );
+    while ( ++p_item < p_end );
 
+end:
     module_config_free( p_config );
-    return false;
+    return ret;
 }
 
 /*********************************************************************


=====================================
modules/gui/qt/dialogs/preferences/complete_preferences.hpp
=====================================
@@ -33,6 +33,24 @@
 #include <QTreeWidget>
 #include <QSet>
 
+/**
+ * Notes:
+ *
+ * 1) Core's use of set_category()/set_subcategory() defines the base tree,
+ *    with its options spread across it.
+ * 2) Certain subcats ('general' type) are not given a node under their cat,
+ *    they represent the top level cat's option panel itself (otherwise cat
+ *    entries would just have empty panels).
+ * 3) Other modules (currently) have their options located under a single tree
+ *    node attached to one of the core cat/subcat nodes. The location for this
+ *    is chosen based upon the first cat and subcat encountered in the module's
+ *    option set. (If the subcat does not belong to the cat, then the node is
+ *    attached directly to the cat; If the module's option set has options
+ *    before the cat/subcat hint entries, this does not matter; If no cat or
+ *    subcat hint is provided in the option set, then no node is created (i.e.
+ *    that module's options will not be available in the prefs GUI).
+ */
+
 class AdvPrefsPanel;
 class QVBoxLayout;
 


=====================================
modules/gui/qt/dialogs/preferences/preferences_widgets.cpp
=====================================
@@ -550,11 +550,14 @@ void ModuleConfigControl::finish( )
             const module_config_t *p_cfg = p_config + i;
             if( p_cfg->i_type == CONFIG_SUBCATEGORY &&
                 p_cfg->value.i == p_item->min.i )
+            {
                 combo->addItem( qfut( module_GetLongName( p_parser )),
                                 QVariant( module_get_object( p_parser ) ) );
-            if( p_item->value.psz && !strcmp( p_item->value.psz,
-                                              module_get_object( p_parser ) ) )
-                combo->setCurrentIndex( combo->count() - 1 );
+                if( p_item->value.psz && !strcmp( p_item->value.psz,
+                                                  module_get_object( p_parser ) ) )
+                    combo->setCurrentIndex( combo->count() - 1 );
+                break;
+            }
         }
         module_config_free (p_config);
     }


=====================================
src/libvlc-module.c
=====================================
@@ -2210,8 +2210,8 @@ vlc_module_begin ()
     add_string( "services-discovery", "", SD_TEXT, SD_LONGTEXT, true )
         change_short('S')
 
-    /* HACK so these don't get displayed in the GUI */
-    set_subcategory( -1 )
+    /* Not displayed in GUI, listed in help output though */
+    set_subcategory( SUBCAT_HIDDEN )
     set_section(N_("Bookmarks"), NULL)
     add_string( "bookmark1", NULL,
              BOOKMARK1_TEXT, BOOKMARK_LONGTEXT, false )
@@ -2812,9 +2812,9 @@ vlc_module_begin ()
             SUBTEXT_SCALEDOWN_KEY_TEXT, SUBTEXT_SCALE_KEY_LONGTEXT)
 
 /* Miscellaneous */
-    /* HACK so these don't get displayed in the GUI */
-    set_category( -1 )
-    set_subcategory( -1 )
+    /* Not displayed in GUI, listed in help output though */
+    set_category( CAT_HIDDEN )
+    set_subcategory( SUBCAT_HIDDEN )
     add_category_hint(N_("Miscellaneous"), NULL)
 
 #define HELP_TEXT \



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/bf81ddc49cf389a0de37077c70d4420ceb58465f...b731340c7a459023ca9aabf11cd36215e4484321

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/bf81ddc49cf389a0de37077c70d4420ceb58465f...b731340c7a459023ca9aabf11cd36215e4484321
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list