[vlc-devel] [PATCH 2/5] Qt: PrefsItemData search

Yuval Tze yuvaltze at gmail.com
Tue Jul 26 23:17:34 CEST 2011


add contains function to search text in item's name, help and in the config items' text
---
 .../gui/qt4/components/complete_preferences.cpp    |   82 ++++++++++++++++++++
 .../gui/qt4/components/complete_preferences.hpp    |    1 +
 2 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/modules/gui/qt4/components/complete_preferences.cpp b/modules/gui/qt4/components/complete_preferences.cpp
index 4f267b8..51f4a35 100644
--- a/modules/gui/qt4/components/complete_preferences.cpp
+++ b/modules/gui/qt4/components/complete_preferences.cpp
@@ -343,6 +343,88 @@ void PrefsTree::doAll( bool doclean )
     }
 }
 
+/* go over the module config items and search text in psz_text
+ * 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 )
+        p_module = module_find( this->psz_name );
+    else
+    {
+        p_module = module_get_main();
+        assert( p_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 )
+    {
+        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 ) ) )
+                break;
+            p_item++;
+        }
+    }
+
+    QString head;
+
+    if( this->i_type == TYPE_SUBCATEGORY || this->i_type ==  TYPE_CATSUBCAT )
+    {
+        head.clear();
+        p_item++; // Why that ? +1
+    }
+    else
+    {
+        head = QString( qtr( module_GetLongName( p_module ) ) );
+    }
+
+    if (name.contains( text, cs ) || head.contains( text, cs ) || help.contains( text, cs ))
+    {
+        module_release( p_module );
+        return true;
+    }
+
+    if( p_item ) 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->b_internal ) continue;
+
+        if ( p_item->psz_text &&
+             qtr( p_item->psz_text ).contains( text, cs ) )
+        {
+            module_release( p_module );
+            return true;
+        }
+    }
+    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 ) );
+
+
+    module_release( p_module );
+    return false;
+}
+
 /*********************************************************************
  * The Panel
  *********************************************************************/
diff --git a/modules/gui/qt4/components/complete_preferences.hpp b/modules/gui/qt4/components/complete_preferences.hpp
index 32ad189..f58b50f 100644
--- a/modules/gui/qt4/components/complete_preferences.hpp
+++ b/modules/gui/qt4/components/complete_preferences.hpp
@@ -51,6 +51,7 @@ public:
     PrefsItemData()
     { panel = NULL; i_object_id = 0; i_subcat_id = -1; psz_name = NULL; };
     virtual ~PrefsItemData() { free( psz_name ); };
+    bool contains( const QString &text, Qt::CaseSensitivity cs );
     AdvPrefsPanel *panel;
     int i_object_id;
     int i_subcat_id;
-- 
1.7.4.1




More information about the vlc-devel mailing list