[vlmc-devel] commit: Settings: Add a flag system ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Sun Jun 20 19:21:35 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Sun Jun 20 19:09:16 2010 +0200| [58bd9351a3b046cab97f364c1b1c47d0b0820012] | committer: Hugo Beauzée-Luyssen 

Settings: Add a flag system

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=58bd9351a3b046cab97f364c1b1c47d0b0820012
---

 src/Settings/SettingValue.cpp    |   11 +++++++++--
 src/Settings/SettingValue.h      |   11 ++++++++++-
 src/Settings/SettingsManager.cpp |    7 ++++---
 src/Settings/SettingsManager.h   |   38 +++++++++++++++++++++++---------------
 4 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/src/Settings/SettingValue.cpp b/src/Settings/SettingValue.cpp
index e80590d..86fd8cb 100644
--- a/src/Settings/SettingValue.cpp
+++ b/src/Settings/SettingValue.cpp
@@ -24,12 +24,13 @@
 #include <QtDebug>
 
 SettingValue::SettingValue( SettingValue::Type type, const QVariant& defaultValue,
-                            const char* name, const char* desc ) :
+                            const char* name, const char* desc, SettingValue::Flags flags ) :
         m_val( defaultValue ),
         m_defaultVal( defaultValue ),
         m_name( name ),
         m_desc( desc ),
-        m_type( type )
+        m_type( type ),
+        m_flags( flags )
 {
 }
 
@@ -72,3 +73,9 @@ SettingValue::type() const
 {
     return m_type;
 }
+
+SettingValue::Flags
+SettingValue::flags() const
+{
+    return m_flags;
+}
diff --git a/src/Settings/SettingValue.h b/src/Settings/SettingValue.h
index 68fa27c..c4e5b0f 100644
--- a/src/Settings/SettingValue.h
+++ b/src/Settings/SettingValue.h
@@ -46,6 +46,13 @@ class   SettingValue : public QObject
             Language,
             KeyboardShortcut
         };
+        enum    Flags
+        {
+            Nothing = 0,
+            /// If this flag is used, then the variable should not be shown in the config widgets.
+            Private = 1,
+        };
+
         /**
          *  \brief      Constructs a setting value with its default value and description
          *
@@ -53,7 +60,7 @@ class   SettingValue : public QObject
          *  \param      desc            The setting description
          */
         SettingValue( Type type, const QVariant& defaultValue, const char* name,
-                      const char* desc );
+                      const char* desc, Flags flags = Nothing );
 
         /**
          * \brief setter for the m_val member
@@ -77,6 +84,7 @@ class   SettingValue : public QObject
 
         const char      *name() const;
         Type            type() const;
+        Flags           flags() const;
 
     private:
         /**
@@ -87,6 +95,7 @@ class   SettingValue : public QObject
         const char*     m_name;
         const char*     m_desc;
         Type            m_type;
+        Flags           m_flags;
     signals:
         /**
          * \brief This signal is emmited while the m_val
diff --git a/src/Settings/SettingsManager.cpp b/src/Settings/SettingsManager.cpp
index 24be6ed..67e4c83 100644
--- a/src/Settings/SettingsManager.cpp
+++ b/src/Settings/SettingsManager.cpp
@@ -196,14 +196,15 @@ SettingsManager::load( const QDomElement &root )
 void
 SettingsManager::createVar( SettingValue::Type type, const QString &key,
                             const QVariant &defaultValue, const char *name,
-                            const char *desc, SettingsManager::Type varType /*= Vlmc*/ )
+                            const char *desc, SettingsManager::Type varType /*= Vlmc*/,
+                            SettingValue::Flags flags /*= SettingValue::Nothing*/ )
 {
     QWriteLocker    wlock( &m_rwLock );
 
     if ( varType == Vlmc && m_classicSettings.contains( key ) == false )
-        m_classicSettings.insert( key, new SettingValue( type, defaultValue, name, desc ) );
+        m_classicSettings.insert( key, new SettingValue( type, defaultValue, name, desc, flags ) );
     else if ( varType == Project && m_xmlSettings.contains( key ) == false )
-        m_xmlSettings.insert( key, new SettingValue( type, defaultValue, name, desc ) );
+        m_xmlSettings.insert( key, new SettingValue( type, defaultValue, name, desc, flags ) );
     else
         Q_ASSERT_X( false, __FILE__, "creating an already created variable" );
 }
diff --git a/src/Settings/SettingsManager.h b/src/Settings/SettingsManager.h
index d54b3a6..6fa1067 100644
--- a/src/Settings/SettingsManager.h
+++ b/src/Settings/SettingsManager.h
@@ -51,35 +51,42 @@ class QDomElement;
 #define VLMC_PROJECT_GET_BOOL( key )    SettingsManager::getInstance()->value( key, SettingsManager::Project )->get().toBool()
 
 
-#define VLMC_CREATE_PROJECT_VAR( type, key, defaultValue, name, desc )  \
+#define VLMC_CREATE_PROJECT_VAR( type, key, defaultValue, name, desc, flags )  \
 SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
-                                           desc, SettingsManager::Project );
+                                           desc, SettingsManager::Project, flags );
 
 #define VLMC_CREATE_PROJECT_INT( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PROJECT_VAR( SettingValue::Int, key, defaultValue, name, desc )
+        VLMC_CREATE_PROJECT_VAR( SettingValue::Int, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PROJECT_STRING( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, name, desc )
+        VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PROJECT_DOUBLE( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PROJECT_VAR( SettingValue::Double, key, defaultValue, name, desc )
+        VLMC_CREATE_PROJECT_VAR( SettingValue::Double, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PROJECT_BOOL( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PROJECT_VAR( SettingValue::Bool, key, defaultValue, name, desc )
+        VLMC_CREATE_PROJECT_VAR( SettingValue::Bool, key, defaultValue, name, desc, SettingValue::Nothing )
 
-#define VLMC_CREATE_PREFERENCE( type, key, defaultValue, name, desc )  \
+#define VLMC_CREATE_PREFERENCE( type, key, defaultValue, name, desc, flags )  \
 SettingsManager::getInstance()->createVar( type, key, defaultValue, name,  \
-                                           desc, SettingsManager::Vlmc );
+                                           desc, SettingsManager::Vlmc, flags );
 
+/// Vlmc preferences maccros
 #define VLMC_CREATE_PREFERENCE_INT( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PREFERENCE( SettingValue::Int, key, defaultValue, name, desc )
+        VLMC_CREATE_PREFERENCE( SettingValue::Int, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PREFERENCE_STRING( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, name, desc )
+        VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PREFERENCE_DOUBLE( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PREFERENCE( SettingValue::Double, key, defaultValue, name, desc )
+        VLMC_CREATE_PREFERENCE( SettingValue::Double, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PREFERENCE_LANGUAGE( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PREFERENCE( SettingValue::Language, key, defaultValue, name, desc )
+        VLMC_CREATE_PREFERENCE( SettingValue::Language, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PREFERENCE_KEYBOARD( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PREFERENCE( SettingValue::KeyboardShortcut, key, defaultValue, name, desc )
+        VLMC_CREATE_PREFERENCE( SettingValue::KeyboardShortcut, key, defaultValue, name, desc, SettingValue::Nothing )
 #define VLMC_CREATE_PREFERENCE_BOOL( key, defaultValue, name, desc )  \
-        VLMC_CREATE_PREFERENCE( SettingValue::Bool, key, defaultValue, name, desc )
+        VLMC_CREATE_PREFERENCE( SettingValue::Bool, key, defaultValue, name, desc, SettingValue::Nothing )
+
+//Convenience maccros :
+#define VLMC_CREATE_PRIVATE_PREFERENCE_STRING( key, defaultValue )  \
+        VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, "", "", SettingValue::Private )
+#define VLMC_CREATE_PRIVATE_PROJECT_STRING( key, defaultValue )  \
+        VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, "", "", SettingValue::Private )
 
 class   SettingsManager : public QObject, public Singleton<SettingsManager>
 {
@@ -104,7 +111,8 @@ class   SettingsManager : public QObject, public Singleton<SettingsManager>
         void                        createVar( SettingValue::Type type, const QString &key,
                                                const QVariant &defaultValue,
                                                const char *name, const char *desc,
-                                               Type varType = Vlmc );
+                                               Type varType = Vlmc,
+                                               SettingValue::Flags flags = SettingValue::Nothing );
         bool                        watchValue( const QString &key,
                                                 QObject* receiver,
                                                 const char *method,



More information about the Vlmc-devel mailing list