From a5a9346ce5476119e7fadc5a2c6f7981b1f32ec4 Mon Sep 17 00:00:00 2001 From: Cyril Deguet Date: Mon, 17 Apr 2006 12:46:51 +0000 Subject: [PATCH] * all: added a INI file parser in skins2. For instance if the file with id "pledit" (defined in the new tag "" 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 ? --- modules/gui/skins2/Modules.am | 2 + modules/gui/skins2/parser/builder.cpp | 42 +++++++++-- modules/gui/skins2/parser/builder.hpp | 4 ++ modules/gui/skins2/parser/builder_data.def | 5 +- modules/gui/skins2/parser/builder_data.hpp | 36 ++++++---- modules/gui/skins2/parser/interpreter.cpp | 14 ++++ modules/gui/skins2/parser/interpreter.hpp | 3 + modules/gui/skins2/parser/skin_parser.cpp | 33 +++++---- modules/gui/skins2/parser/skin_parser.hpp | 3 +- modules/gui/skins2/src/file_bitmap.cpp | 2 - modules/gui/skins2/src/ini_file.cpp | 81 ++++++++++++++++++++++ modules/gui/skins2/src/ini_file.hpp | 49 +++++++++++++ modules/gui/skins2/src/var_manager.cpp | 12 ++++ modules/gui/skins2/src/var_manager.hpp | 8 +++ modules/gui/skins2/utils/var_text.cpp | 34 ++++----- modules/gui/skins2/utils/var_text.hpp | 3 + share/skins2/skin.dtd | 7 +- share/skins2/winamp2.xml | 3 +- 18 files changed, 289 insertions(+), 52 deletions(-) create mode 100644 modules/gui/skins2/src/ini_file.cpp create mode 100644 modules/gui/skins2/src/ini_file.hpp diff --git a/modules/gui/skins2/Modules.am b/modules/gui/skins2/Modules.am index 515c4c62c5..55d1816e22 100644 --- a/modules/gui/skins2/Modules.am +++ b/modules/gui/skins2/Modules.am @@ -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 \ diff --git a/modules/gui/skins2/parser/builder.cpp b/modules/gui/skins2/parser/builder.cpp index 3a3a762cbf..bc0d31927e 100644 --- a/modules/gui/skins2/parser/builder.cpp +++ b/modules/gui/skins2/parser/builder.cpp @@ -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() ); +} + diff --git a/modules/gui/skins2/parser/builder.hpp b/modules/gui/skins2/parser/builder.hpp index d958941373..d0831b68ab 100644 --- a/modules/gui/skins2/parser/builder.hpp +++ b/modules/gui/skins2/parser/builder.hpp @@ -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; }; diff --git a/modules/gui/skins2/parser/builder_data.def b/modules/gui/skins2/parser/builder_data.def index c26f67558c..2e69ec659e 100644 --- a/modules/gui/skins2/parser/builder_data.def +++ b/modules/gui/skins2/parser/builder_data.def @@ -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 diff --git a/modules/gui/skins2/parser/builder_data.hpp b/modules/gui/skins2/parser/builder_data.hpp index 059676db7f..b3450b770c 100644 --- a/modules/gui/skins2/parser/builder_data.hpp +++ b/modules/gui/skins2/parser/builder_data.hpp @@ -279,6 +279,18 @@ m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_leftTop( leftTop ), m_rightBottom( /// List list 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 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; diff --git a/modules/gui/skins2/parser/interpreter.cpp b/modules/gui/skins2/parser/interpreter.cpp index f00f0c70e2..c6440f6c4a 100644 --- a/modules/gui/skins2/parser/interpreter.cpp +++ b/modules/gui/skins2/parser/interpreter.cpp @@ -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; +} + diff --git a/modules/gui/skins2/parser/interpreter.hpp b/modules/gui/skins2/parser/interpreter.hpp index e8af87e283..9ae4c1297b 100644 --- a/modules/gui/skins2/parser/interpreter.hpp +++ b/modules/gui/skins2/parser/interpreter.hpp @@ -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 m_commandMap; diff --git a/modules/gui/skins2/parser/skin_parser.cpp b/modules/gui/skins2/parser/skin_parser.cpp index b666bdad55..f3ea0c2f74 100644 --- a/modules/gui/skins2/parser/skin_parser.cpp +++ b/modules/gui/skins2/parser/skin_parser.cpp @@ -23,6 +23,7 @@ #include "skin_parser.hpp" #include "../src/os_factory.hpp" +#include "interpreter.hpp" #include 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 ); diff --git a/modules/gui/skins2/parser/skin_parser.hpp b/modules/gui/skins2/parser/skin_parser.hpp index 52feeeab1e..7813d87e44 100644 --- a/modules/gui/skins2/parser/skin_parser.hpp +++ b/modules/gui/skins2/parser/skin_parser.hpp @@ -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, diff --git a/modules/gui/skins2/src/file_bitmap.cpp b/modules/gui/skins2/src/file_bitmap.cpp index e52415d1de..b41a79650f 100644 --- a/modules/gui/skins2/src/file_bitmap.cpp +++ b/modules/gui/skins2/src/file_bitmap.cpp @@ -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 index 0000000000..0f2eb5d839 --- /dev/null +++ b/modules/gui/skins2/src/ini_file.cpp @@ -0,0 +1,81 @@ +/***************************************************************************** + * ini_file.cpp + ***************************************************************************** + * Copyright (C) 2006 the VideoLAN team + * $Id$ + * + * Authors: Cyril Deguet + * + * 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 + + +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 index 0000000000..8b2ae321bf --- /dev/null +++ b/modules/gui/skins2/src/ini_file.hpp @@ -0,0 +1,49 @@ +/***************************************************************************** + * ini_file.hpp + ***************************************************************************** + * Copyright (C) 2006 the VideoLAN team + * $Id$ + * + * Authors: Cyril Deguet + * + * 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 +#include + + +/// 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 diff --git a/modules/gui/skins2/src/var_manager.cpp b/modules/gui/skins2/src/var_manager.cpp index 04718894fa..50837efaf8 100644 --- a/modules/gui/skins2/src/var_manager.cpp +++ b/modules/gui/skins2/src/var_manager.cpp @@ -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]; +} + diff --git a/modules/gui/skins2/src/var_manager.hpp b/modules/gui/skins2/src/var_manager.hpp index ad2346c02c..18f5209453 100644 --- a/modules/gui/skins2/src/var_manager.hpp +++ b/modules/gui/skins2/src/var_manager.hpp @@ -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 m_varList; /// List of anonymous registed variables list m_anonVarList; + /// Map of constant values + map m_constMap; /// Private because it is a singleton VarManager( intf_thread_t *pIntf ); diff --git a/modules/gui/skins2/utils/var_text.cpp b/modules/gui/skins2/utils/var_text.cpp index e7740d296d..23ac5c72a2 100644 --- a/modules/gui/skins2/utils/var_text.cpp +++ b/modules/gui/skins2/utils/var_text.cpp @@ -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 &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 ); +} + diff --git a/modules/gui/skins2/utils/var_text.hpp b/modules/gui/skins2/utils/var_text.hpp index 26ab73f949..1bde9262fc 100644 --- a/modules/gui/skins2/utils/var_text.hpp +++ b/modules/gui/skins2/utils/var_text.hpp @@ -53,6 +53,9 @@ class VarText: public Variable, public Subject, virtual void onUpdate( Subject &rVariable, void* ); private: + /// Stop observing other variables + void delObservers(); + /// Variable type static const string m_type; /// The text of the variable diff --git a/share/skins2/skin.dtd b/share/skins2/skin.dtd index 080ad36d15..703c7f9856 100644 --- a/share/skins2/skin.dtd +++ b/share/skins2/skin.dtd @@ -2,7 +2,7 @@ --> - + + + + @@ -342,7 +343,7 @@