]> git.sesse.net Git - vlc/commitdiff
* all: added a INI file parser in skins2. For instance if the file
authorCyril Deguet <asmax@videolan.org>
Mon, 17 Apr 2006 12:46:51 +0000 (12:46 +0000)
committerCyril Deguet <asmax@videolan.org>
Mon, 17 Apr 2006 12:46:51 +0000 (12:46 +0000)
 with id "pledit" (defined in the new tag "<IniFile>" contains:
    [Text]
    Normal=#FFFFFF
 it will create a constant "pledit.Text.Normal" with value "#FFFFFF"
* winamp2.xml: use the "pledit.txt" file to have correct playlist colors

is it ok to backport in 0.8.5 ?

18 files changed:
modules/gui/skins2/Modules.am
modules/gui/skins2/parser/builder.cpp
modules/gui/skins2/parser/builder.hpp
modules/gui/skins2/parser/builder_data.def
modules/gui/skins2/parser/builder_data.hpp
modules/gui/skins2/parser/interpreter.cpp
modules/gui/skins2/parser/interpreter.hpp
modules/gui/skins2/parser/skin_parser.cpp
modules/gui/skins2/parser/skin_parser.hpp
modules/gui/skins2/src/file_bitmap.cpp
modules/gui/skins2/src/ini_file.cpp [new file with mode: 0644]
modules/gui/skins2/src/ini_file.hpp [new file with mode: 0644]
modules/gui/skins2/src/var_manager.cpp
modules/gui/skins2/src/var_manager.hpp
modules/gui/skins2/utils/var_text.cpp
modules/gui/skins2/utils/var_text.hpp
share/skins2/skin.dtd
share/skins2/winamp2.xml

index 515c4c62c57ae256c3e37dacf5a555cd19c51ac0..55d1816e221fd63e6085ca10715a647fb896f954 100644 (file)
@@ -113,6 +113,8 @@ SOURCES_skins2 = \
        src/generic_layout.hpp \
        src/generic_window.cpp \
        src/generic_window.hpp \
+       src/ini_file.cpp \
+       src/ini_file.hpp \
        src/logger.cpp \
        src/logger.hpp \
        src/os_factory.cpp \
index 3a3a762cbfeb137c71624ae8239e18a687d5e95b..bc0d31927eb6a24a952a2acb42fa592c0cec2bfa 100644 (file)
@@ -26,6 +26,7 @@
 #include "builder.hpp"
 #include "builder_data.hpp"
 #include "interpreter.hpp"
+#include "skin_parser.hpp"
 #include "../src/file_bitmap.hpp"
 #include "../src/os_factory.hpp"
 #include "../src/generic_bitmap.hpp"
@@ -33,6 +34,7 @@
 #include "../src/anchor.hpp"
 #include "../src/bitmap_font.hpp"
 #include "../src/ft2_font.hpp"
+#include "../src/ini_file.hpp"
 #include "../src/generic_layout.hpp"
 #include "../src/popup.hpp"
 #include "../src/theme.hpp"
@@ -94,6 +96,7 @@ Theme *Builder::build()
 
     // Create everything from the data in the XML
     ADD_OBJECTS( Theme );
+    ADD_OBJECTS( IniFile );
     ADD_OBJECTS( Bitmap );
     ADD_OBJECTS( SubBitmap );
     ADD_OBJECTS( BitmapFont );
@@ -153,6 +156,14 @@ void Builder::addTheme( const BuilderData::Theme &rData )
 }
 
 
+void Builder::addIniFile( const BuilderData::IniFile &rData )
+{
+    // Parse the INI file
+    IniFile iniFile( getIntf(), rData.m_id, getFilePath( rData.m_file ) );
+    iniFile.parseFile();
+}
+
+
 void Builder::addBitmap( const BuilderData::Bitmap &rData )
 {
     GenericBitmap *pBmp =
@@ -816,10 +827,16 @@ void Builder::addList( const BuilderData::List &rData )
     // XXX check when it is null
     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
 
+    // Get the color values
+    uint32_t fgColor = getColor( rData.m_fgColor );
+    uint32_t playColor = getColor( rData.m_playColor );
+    uint32_t bgColor1 = getColor( rData.m_bgColor1 );
+    uint32_t bgColor2 = getColor( rData.m_bgColor2 );
+    uint32_t selColor = getColor( rData.m_selColor );
+
     // Create the list control
     CtrlList *pList = new CtrlList( getIntf(), *pVar, *pFont, pBgBmp,
-       rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
-       rData.m_bgColor2, rData.m_selColor,
+       fgColor, playColor, bgColor1, bgColor2, selColor,
        UString( getIntf(), rData.m_help.c_str() ), pVisible );
 
     // Compute the position of the control
@@ -873,11 +890,17 @@ void Builder::addTree( const BuilderData::Tree &rData )
     VarBool *pVisible = pInterpreter->getVarBool( rData.m_visible, m_pTheme );
     VarBool *pFlat = pInterpreter->getVarBool( rData.m_flat, m_pTheme );
 
+    // Get the color values
+    uint32_t fgColor = getColor( rData.m_fgColor );
+    uint32_t playColor = getColor( rData.m_playColor );
+    uint32_t bgColor1 = getColor( rData.m_bgColor1 );
+    uint32_t bgColor2 = getColor( rData.m_bgColor2 );
+    uint32_t selColor = getColor( rData.m_selColor );
+
     // Create the list control
     CtrlTree *pTree = new CtrlTree( getIntf(), *pVar, *pFont, pBgBmp,
        pItemBmp, pOpenBmp, pClosedBmp,
-       rData.m_fgColor, rData.m_playColor, rData.m_bgColor1,
-       rData.m_bgColor2, rData.m_selColor,
+       fgColor, playColor, bgColor1, bgColor2, selColor,
        UString( getIntf(), rData.m_help.c_str() ), pVisible, pFlat );
 
     // Compute the position of the control
@@ -1069,3 +1092,14 @@ Bezier *Builder::getPoints( const char *pTag ) const
     return new Bezier( getIntf(), xBez, yBez );
 }
 
+
+uint32_t Builder::getColor( const string &rVal ) const
+{
+    // Check it the value is a registered constant
+    Interpreter *pInterpreter = Interpreter::instance( getIntf() );
+    string val = pInterpreter->getConstant( rVal );
+
+    // Convert to an int value
+    return SkinParser::convertColor( val.c_str() );
+}
+
index d958941373e91e10092fdf3fdfd80095c08b5bd0..d0831b68ab2d16bb05a38b3e8be52f086dc75cd5 100644 (file)
@@ -65,6 +65,7 @@ class Builder: public SkinObject
         Theme *m_pTheme;
 
         void addTheme( const BuilderData::Theme &rData );
+        void addIniFile( const BuilderData::IniFile &rData );
         void addBitmap( const BuilderData::Bitmap &rData );
         void addSubBitmap( const BuilderData::SubBitmap &rData );
         void addBitmapFont( const BuilderData::BitmapFont &rData );
@@ -100,6 +101,9 @@ class Builder: public SkinObject
         /// Function to parse "points" tags
         Bezier *getPoints( const char *pTag ) const;
 
+        /// Compute a color value
+        uint32_t getColor( const string &rVal ) const;
+
         /// Image handler (used to load image files)
         image_handler_t *m_pImageHandler;
 };
index c26f67558c2a24f45e1873c54224de45de4ecd5a..2e69ec659e4b4c00a5063c3f61df012a09407f71 100644 (file)
@@ -12,9 +12,10 @@ Anchor xPos:int yPos:int range:int priority:int points:string layoutId:string
 Button id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string upId:string downId:string overId:string actionId:string tooltip:string help:string layer:int windowId:string layoutId:string
 Checkbox id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string up1Id:string down1Id:string over1Id:string up2Id:string down2Id:string over2Id:string state:string action1:string action2:string tooltip1:string tooltip2:string help:string layer:int windowId:string layoutId:string
 Image id:string xPos:int yPos:int leftTop:string rightBottom:string visible:string bmpId:string actionId:string action2Id:string resize:string help:string layer:int windowId:string layoutId:string
+IniFile id:string file:string
 Text id:string xPos:int yPos:int visible:string fontId:string text:string width:int leftTop:string rightBottom:string color:uint32_t scrolling:string alignment:string help:string layer:int windowId:string layoutId:string
 RadialSlider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string sequence:string nbImages:int minAngle:float maxAngle:float value:string tooltip:string help:string layer:int windowId:string layoutId:string
 Slider id:string visible:string xPos:int yPos:int leftTop:string rightBottom:string upId:string downId:string overId:string points:string thickness:int value:string imageId:string nbHoriz:int nbVert:int padHoriz:int padVert:int tooltip:string help:string layer:int windowId:string layoutId:string
-List id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string fgColor:uint32_t playColor:uint32_t bgColor1:uint32_t bgColor2:uint32_t selColor:uint32_t help:string layer:int windowId:string layoutId:string
-Tree id:string xPos:int yPos:int visible:string flat:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string itemImageId:string openImageId:string closedImageId:string fgColor:uint32_t playColor:uint32_t bgColor1:uint32_t bgColor2:uint32_t selColor:uint32_t help:string layer:int windowId:string layoutId:string
+List id:string xPos:int yPos:int visible:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string fgColor:string playColor:string bgColor1:string bgColor2:string selColor:string help:string layer:int windowId:string layoutId:string
+Tree id:string xPos:int yPos:int visible:string flat:string width:int height:int leftTop:string rightBottom:string fontId:string var:string bgImageId:string itemImageId:string openImageId:string closedImageId:string fgColor:string playColor:string bgColor1:string bgColor2:string selColor:string help:string layer:int windowId:string layoutId:string
 Video id:string xPos:int yPos:int width:int height:int leftTop:string rightBottom:string visible:string autoResize:bool help:string layer:int windowId:string layoutId:string
index 059676db7fb2683fac617fc3a7f03613567cb95a..b3450b770ca5fa0aa03784881647d5e0235aabe8 100644 (file)
@@ -279,6 +279,18 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom(
     /// List
     list<Image> m_listImage;
 
+    /// Type definition
+    struct IniFile
+    {
+        IniFile( const string & id, const string & file ):
+m_id( id ), m_file( file ) {}
+
+        string m_id;
+        string m_file;
+    };
+    /// List
+    list<IniFile> m_listIniFile;
+
     /// Type definition
     struct Text
     {
@@ -366,7 +378,7 @@ m_id( id ), m_visible( visible ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( lef
     /// Type definition
     struct List
     {
-        List( const string & id, int xPos, int yPos, const string & visible, int width, int height, const string & leftTop, const string & rightBottom, const string & fontId, const string & var, const string & bgImageId, uint32_t fgColor, uint32_t playColor, uint32_t bgColor1, uint32_t bgColor2, uint32_t selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
+        List( const string & id, int xPos, int yPos, const string & visible, int width, int height, const string & leftTop, const string & rightBottom, const string & fontId, const string & var, const string & bgImageId, const string & fgColor, const string & playColor, const string & bgColor1, const string & bgColor2, const string & selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
 m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_fontId( fontId ), m_var( var ), m_bgImageId( bgImageId ), m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
@@ -380,11 +392,11 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width
         string m_fontId;
         string m_var;
         string m_bgImageId;
-        uint32_t m_fgColor;
-        uint32_t m_playColor;
-        uint32_t m_bgColor1;
-        uint32_t m_bgColor2;
-        uint32_t m_selColor;
+        string m_fgColor;
+        string m_playColor;
+        string m_bgColor1;
+        string m_bgColor2;
+        string m_selColor;
         string m_help;
         int m_layer;
         string m_windowId;
@@ -396,7 +408,7 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width
     /// Type definition
     struct Tree
     {
-        Tree( const string & id, int xPos, int yPos, const string & visible, const string & flat, int width, int height, const string & leftTop, const string & rightBottom, const string & fontId, const string & var, const string & bgImageId, const string & itemImageId, const string & openImageId, const string & closedImageId, uint32_t fgColor, uint32_t playColor, uint32_t bgColor1, uint32_t bgColor2, uint32_t selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
+        Tree( const string & id, int xPos, int yPos, const string & visible, const string & flat, int width, int height, const string & leftTop, const string & rightBottom, const string & fontId, const string & var, const string & bgImageId, const string & itemImageId, const string & openImageId, const string & closedImageId, const string & fgColor, const string & playColor, const string & bgColor1, const string & bgColor2, const string & selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
 m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_flat( flat ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_fontId( fontId ), m_var( var ), m_bgImageId( bgImageId ), m_itemImageId( itemImageId ), m_openImageId( openImageId ), m_closedImageId( closedImageId ), m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
 
         string m_id;
@@ -414,11 +426,11 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_flat( flat )
         string m_itemImageId;
         string m_openImageId;
         string m_closedImageId;
-        uint32_t m_fgColor;
-        uint32_t m_playColor;
-        uint32_t m_bgColor1;
-        uint32_t m_bgColor2;
-        uint32_t m_selColor;
+        string m_fgColor;
+        string m_playColor;
+        string m_bgColor1;
+        string m_bgColor2;
+        string m_selColor;
         string m_help;
         int m_layer;
         string m_windowId;
index f00f0c70e2d97e4f87165097dccbf4565646e8d6..c6440f6c4a5e254dbbd45c8ad61c84a034d2ec86 100644 (file)
@@ -416,3 +416,17 @@ VarTree *Interpreter::getVarTree( const string &rName, Theme *pTheme )
     VarTree *pVar = (VarTree*)pVarManager->getVar( rName, "tree" );
     return pVar;
 }
+
+
+string Interpreter::getConstant( const string &rValue )
+{
+    // Check if the value is a registered constant
+    string val = VarManager::instance( getIntf() )->getConst( rValue );
+    if( val.empty() )
+    {
+        // if not, keep the value as is
+        val = rValue;
+    }
+    return val;
+}
+
index e8af87e283b041a32ab931433cb119e4d439ccc9..9ae4c1297b4dd47331341709c6190e6ae04690a6 100644 (file)
@@ -63,6 +63,9 @@ class Interpreter: public SkinObject
         /// Returns the tree variable corresponding to the given name
         VarTree *getVarTree( const string &rName, Theme *pTheme );
 
+        /// Get a constant value
+        string getConstant( const string &rValue );
+
     private:
         /// Map of global commands
         map<string, CmdGenericPtr> m_commandMap;
index b666bdad55b57c61fb232331fd5c9bc41d277665..f3ea0c2f748ae811101d2b58512143d8778cbe22 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "skin_parser.hpp"
 #include "../src/os_factory.hpp"
+#include "interpreter.hpp"
 #include <math.h>
 
 SkinParser::SkinParser( intf_thread_t *pIntf, const string &rFileName,
@@ -72,6 +73,16 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         subParser.parse();
     }
 
+    else if( rName == "IniFile" )
+    {
+        RequireDefault( "id" );
+        RequireDefault( "file" );
+
+        const BuilderData::IniFile iniFile( attr["id"],
+                attr["file"] );
+        m_pData->m_listIniFile.push_back( iniFile );
+    }
+
     else if( rName == "Anchor" )
     {
         RequireDefault( "priority" );
@@ -304,13 +315,10 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
         const BuilderData::List listData( m_curListId, atoi( attr["x"] ) +
                 m_xOffset, atoi( attr["y"] ) + m_yOffset, attr["visible"],
                 atoi( attr["width"]), atoi( attr["height"] ),
-                attr["lefttop"], attr["rightbottom"],
-                attr["font"], "playlist", attr["bgimage"],
-                convertColor( attr["fgcolor"] ),
-                convertColor( attr["playcolor"] ),
-                convertColor( attr["bgcolor1"] ),
-                convertColor( attr["bgcolor2"] ),
-                convertColor( attr["selcolor"] ), attr["help"],
+                attr["lefttop"], attr["rightbottom"], attr["font"],
+                "playlist", attr["bgimage"], attr["fgcolor"],
+                attr["playcolor"], attr["bgcolor1"], attr["bgcolor2"],
+                attr["selcolor"], attr["help"],
                 m_curLayer, m_curWindowId, m_curLayoutId );
         m_curLayer++;
         m_pData->m_listList.push_back( listData );
@@ -348,11 +356,9 @@ void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr )
                 attr["font"], "playtree",
                 attr["bgimage"], attr["itemimage"],
                 attr["openimage"], attr["closedimage"],
-                convertColor( attr["fgcolor"] ),
-                convertColor( attr["playcolor"] ),
-                convertColor( attr["bgcolor1"] ),
-                convertColor( attr["bgcolor2"] ),
-                convertColor( attr["selcolor"] ), attr["help"],
+                attr["fgcolor"], attr["playcolor"],
+                attr["bgcolor1"], attr["bgcolor2"],
+                attr["selcolor"], attr["help"],
                 m_curLayer, m_curWindowId, m_curLayoutId );
         m_curLayer++;
         m_pData->m_listTree.push_back( treeData );
@@ -576,8 +582,9 @@ bool SkinParser::convertBoolean( const char *value ) const
 }
 
 
-int SkinParser::convertColor( const char *transcolor ) const
+int SkinParser::convertColor( const char *transcolor )
 {
+    // TODO: move to the builder
     unsigned long iRed, iGreen, iBlue;
     iRed = iGreen = iBlue = 0;
     sscanf( transcolor, "#%2lX%2lX%2lX", &iRed, &iGreen, &iBlue );
index 52feeeab1ec65c06c097beefc173e7d9cc2e1b28..7813d87e444ff03c4a613768d224de9ea81db3d7 100644 (file)
@@ -40,6 +40,8 @@ class SkinParser: public XMLParser
 
         const BuilderData &getData() const { return *m_pData; }
 
+        static int convertColor( const char *transcolor );
+
     private:
         /// Path of the theme
         const string m_path;
@@ -72,7 +74,6 @@ class SkinParser: public XMLParser
         /// Helper functions
         //@{
         bool convertBoolean( const char *value ) const;
-        int convertColor( const char *transcolor ) const;
         /// Transform to int, and check that it is in the given range (if not,
         /// the closest range boundary will be used)
         int convertInRange( const char *value, int minValue, int maxValue,
index e52415d1de2361059253812c1290720e203b6088..b41a79650fc8e90754fc31ad4e1e8f931a11c684 100644 (file)
@@ -37,8 +37,6 @@ FileBitmap::FileBitmap( intf_thread_t *pIntf, image_handler_t *pImageHandler,
 
     fmt_out.i_chroma = VLC_FOURCC('R','V','3','2');
 
-fprintf(stderr,"FILE %s\n", fileName.c_str());
-    
     pPic = image_ReadUrl( pImageHandler, fileName.c_str(), &fmt_in, &fmt_out );
     if( !pPic ) return;
 
diff --git a/modules/gui/skins2/src/ini_file.cpp b/modules/gui/skins2/src/ini_file.cpp
new file mode 100644 (file)
index 0000000..0f2eb5d
--- /dev/null
@@ -0,0 +1,81 @@
+/*****************************************************************************
+ * ini_file.cpp
+ *****************************************************************************
+ * Copyright (C) 2006 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Cyril Deguet     <asmax@via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#include "ini_file.hpp"
+#include "var_manager.hpp"
+#include <fstream>
+
+
+IniFile::IniFile( intf_thread_t *pIntf, const string &rName,
+                  const string &rPath ):
+    SkinObject( pIntf ), m_name( rName ), m_path( rPath )
+{
+}
+
+
+void IniFile::parseFile()
+{
+    VarManager *pVarManager = VarManager::instance( getIntf() );
+
+    // Open the file
+    fstream fs( m_path.c_str(), fstream::in );
+    if( fs.is_open() )
+    {
+        string section;
+        string line;
+        while( !fs.eof() )
+        {
+            // Read the next line
+            fs >> line;
+
+            switch( line[0] )
+            {
+            // "[section]" line ?
+            case '[':
+                section = line.substr( 1, line.size() - 2);
+                break;
+
+            // Comment
+            case ';':
+            case '#':
+                break;
+
+            // Variable declaration
+            default:
+                size_t eqPos = line.find( '=' );
+                string var = line.substr( 0, eqPos );
+                string val = line.substr( eqPos + 1, line.size() - eqPos - 1);
+
+                // register the value in the var manager
+                pVarManager->registerConst( m_name + "." + section + "." + var,
+                                            val );
+            }
+        }
+        fs.close();
+    }
+    else
+    {
+        msg_Err( getIntf(), "Failed to open INI file %s", m_path.c_str() );
+    }
+}
+
diff --git a/modules/gui/skins2/src/ini_file.hpp b/modules/gui/skins2/src/ini_file.hpp
new file mode 100644 (file)
index 0000000..8b2ae32
--- /dev/null
@@ -0,0 +1,49 @@
+/*****************************************************************************
+ * ini_file.hpp
+ *****************************************************************************
+ * Copyright (C) 2006 the VideoLAN team
+ * $Id$
+ *
+ * Authors: Cyril Deguet     <asmax@via.ecp.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef INI_FILE_HPP
+#define INI_FILE_HPP
+
+#include "skin_common.hpp"
+#include <string>
+#include <map>
+
+
+/// INI file parser
+class IniFile: public SkinObject
+{
+    public:
+        IniFile( intf_thread_t *pIntf, const string &rName,
+                 const string &rPath );
+        virtual ~IniFile() {}
+
+        /// Parse the INI file and fill the VarManager
+        void parseFile();
+
+    private:
+        string m_name;
+        string m_path;
+};
+
+
+#endif
index 04718894fa2ae06a797ea9879592b08978f23e9d..50837efaf87e33a00a18bc1c9028df0ae486d5b9 100644 (file)
@@ -131,3 +131,15 @@ Variable *VarManager::getVar( const string &rName, const string &rType )
     }
 }
 
+
+void VarManager::registerConst( const string &rName, const string &rValue)
+{
+    m_constMap[rName] = rValue;
+}
+
+
+string VarManager::getConst( const string &rName )
+{
+    return m_constMap[rName];
+}
+
index ad2346c02c92b47a91237a52db5fa55327ddb3af..18f5209453732b8da1f35e1526d50bfeebb37351 100644 (file)
@@ -57,6 +57,12 @@ class VarManager: public SkinObject
         /// Get the help text variable
         VarText &getHelpText() { return *m_pHelpText; }
 
+        /// Register a constant value
+        void registerConst( const string &rName, const string &rValue);
+
+        /// Get a constant value by its name
+        string getConst( const string &rName );
+
     private:
         /// Tooltip text
         VarText *m_pTooltipText;
@@ -68,6 +74,8 @@ class VarManager: public SkinObject
         list<string> m_varList;
         /// List of anonymous registed variables
         list<VariablePtr> m_anonVarList;
+        /// Map of constant values
+        map<string, string> m_constMap;
 
         /// Private because it is a singleton
         VarManager( intf_thread_t *pIntf );
index e7740d296debcfc0ab888d7dc400e061b06c8ebd..23ac5c72a2588bdcdce18b2f17bd3ab852a9ebba 100644 (file)
@@ -43,15 +43,7 @@ VarText::~VarText()
     if( m_substVars )
     {
         // Remove the observers
-        VlcProc *pVlcProc = VlcProc::instance( getIntf() );
-        pVlcProc->getTimeVar().delObserver( this );
-        pVlcProc->getVolumeVar().delObserver( this );
-        pVlcProc->getStreamURIVar().delObserver( this );
-        pVlcProc->getStreamNameVar().delObserver( this );
-        pVlcProc->getStreamBitRateVar().delObserver( this );
-        pVlcProc->getStreamSampleRateVar().delObserver( this );
-        VarManager *pVarManager = VarManager::instance( getIntf() );
-        pVarManager->getHelpText().delObserver( this );
+        delObservers();
     }
 }
 
@@ -149,15 +141,10 @@ void VarText::set( const UString &rText )
     if( m_substVars )
     {
         // Stop observing other variables
+        delObservers();
+
         VlcProc *pVlcProc = VlcProc::instance( getIntf() );
-        pVlcProc->getTimeVar().delObserver( this );
-        pVlcProc->getVolumeVar().delObserver( this );
-        pVlcProc->getStreamNameVar().delObserver( this );
-        pVlcProc->getStreamURIVar().delObserver( this );
-        pVlcProc->getStreamBitRateVar().delObserver( this );
-        pVlcProc->getStreamSampleRateVar().delObserver( this );
         VarManager *pVarManager = VarManager::instance( getIntf() );
-        pVarManager->getHelpText().delObserver( this );
 
         // Observe needed variables
         if( m_text.find( "$H" ) != UString::npos )
@@ -228,3 +215,18 @@ void VarText::onUpdate( Subject<VarText,void*> &rVariable, void *arg )
     }
 }
 
+
+void VarText::delObservers()
+{
+    // Stop observing other variables
+    VlcProc *pVlcProc = VlcProc::instance( getIntf() );
+    pVlcProc->getTimeVar().delObserver( this );
+    pVlcProc->getVolumeVar().delObserver( this );
+    pVlcProc->getStreamNameVar().delObserver( this );
+    pVlcProc->getStreamURIVar().delObserver( this );
+    pVlcProc->getStreamBitRateVar().delObserver( this );
+    pVlcProc->getStreamSampleRateVar().delObserver( this );
+    VarManager *pVarManager = VarManager::instance( getIntf() );
+    pVarManager->getHelpText().delObserver( this );
+}
+
index 26ab73f9497732462e28502e0b76cbdadc9b7c5e..1bde9262fc05c253a56e86e2a83c19d90b0a3fda 100644 (file)
@@ -53,6 +53,9 @@ class VarText: public Variable, public Subject<VarText, void*>,
         virtual void onUpdate( Subject<VarText, void*> &rVariable, void* );
 
     private:
+        /// Stop observing other variables
+        void delObservers();
+
         /// Variable type
         static const string m_type;
         /// The text of the variable
index 080ad36d1520e56995fcf94e368a9df2d3d8f3cc..703c7f9856db774b27f4e0d3f81b246b0eb03b5a 100644 (file)
@@ -2,7 +2,7 @@
 -->
 
 
-<!ELEMENT Theme (ThemeInfo,(Include|Bitmap|BitmapFont|Font|PopupMenu|Window)*)>
+<!ELEMENT Theme (ThemeInfo,(Include|IniFile|Bitmap|BitmapFont|Font|PopupMenu|Window)*)>
     <!ATTLIST Theme
         version     CDATA   #REQUIRED
         tooltipfont CDATA   "defaultfont"
     >
 
 <!-- main elements -->
+<!ELEMENT IniFile EMPTY>
+    <!ATTLIST IniFile
+        id          CDATA   #REQUIRED
+        file        CDATA   #REQUIRED
+    >
 <!ELEMENT Include EMPTY>
     <!ATTLIST Include
         file        CDATA   #REQUIRED
index 4f244436f3380bcb9ff8e9305a14ff7bb0e97660..10a2dcf166b3ce75deb19ac50a54d8fcd422e5cb 100644 (file)
     <BitmapFont id="digits_font" file="nums_ex.bmp" type="digits" />
     <BitmapFont id="digits_font_2" file="numbers.bmp" type="digits" />
     <BitmapFont id="text_font" file="text.bmp" type="text" />
+    <IniFile id="pledit" file="pledit.txt" />
 
     <Window id="main_window" x="100" y="100">
         <Layout id="small_layout" width="275" height="14">
                 <Image x="255" y="96" image="pl_resize" action="resizeSE" lefttop="rightbottom" rightbottom="rightbottom" />
                 <Button x="254" y="3" up="pl_switch_up" down="pl_switch_down" over="pl_switch_up" action="playlist_window.setLayout(pl_small_layout)" tooltiptext="Switch" lefttop="righttop" rightbottom="righttop" />
                 <Button x="264" y="3" up="pl_close_up" down="pl_close_down" over="pl_close_up" action="playlist_window.hide()" tooltiptext="Close the window" lefttop="righttop" rightbottom="righttop" />
-                <Playlist id="playlist" x="10" y="20" width="240" height="58" lefttop="lefttop" rightbottom="rightbottom" font="playlist_font" fgcolor="#dfdfff" playcolor="#ffffff" bgcolor1="#000000" bgcolor2="#000000" selcolor="#404040" >
+                <Playlist id="playlist" x="10" y="20" width="240" height="58" lefttop="lefttop" rightbottom="rightbottom" font="playlist_font" fgcolor="pledit.Text.Normal" playcolor="pledit.Text.Current" bgcolor1="pledit.Text.NormalBG" bgcolor2="pledit.Text.NormalBG" selcolor="pledit.Text.SelectedBG" >
                     <Slider id="playlist_slider" x="264" y="28" lefttop="righttop" rightbottom="rightbottom" up="pl_slider_up" down="pl_slider_down" points="(0,40),(0,0)" />
                 </Playlist>
                 <Button x="14" y="86" up="pl_add_up" down="pl_add_down" over="pl_add_up" action="playlist.add()" lefttop="leftbottom" rightbottom="leftbottom" />