]> git.sesse.net Git - vlc/commitdiff
* configure.ac: check xml2-config for skins2
authorCyril Deguet <asmax@videolan.org>
Sat, 24 Jan 2004 13:08:12 +0000 (13:08 +0000)
committerCyril Deguet <asmax@videolan.org>
Sat, 24 Jan 2004 13:08:12 +0000 (13:08 +0000)
* modules/gui/skins2/src/var_manager.cpp: delete the variables in the
  right order to avoid invalid reads in the destructor
* modules/gui/skins2/parser/xmlparser: skeleton of a new parser based
  on the text reader API of libxml2

configure.ac
modules/gui/skins2/Modules.am
modules/gui/skins2/parser/xmlparser.cpp [new file with mode: 0644]
modules/gui/skins2/parser/xmlparser.hpp [new file with mode: 0644]
modules/gui/skins2/src/theme_loader.cpp
modules/gui/skins2/src/var_manager.cpp
modules/gui/skins2/src/var_manager.hpp

index 7f1396f9b3a4d080555dfef22ea4935fec469cea..6bcb11eaf06ef5c26bc5b0f4439a85a5888bd9b7 100644 (file)
@@ -1,5 +1,5 @@
 dnl Autoconf settings for vlc
-dnl $Id: configure.ac,v 1.153 2004/01/23 15:36:23 titer Exp $
+dnl $Id: configure.ac,v 1.154 2004/01/24 13:08:12 asmax Exp $
 
 AC_INIT(vlc,0.7.1-cvs)
 
@@ -2793,19 +2793,29 @@ if test "${enable_skins2}" != "no"; then
     AX_ADD_CXXFLAGS([skins2],[-O2 -fno-rtti])
     AX_ADD_LDFLAGS([skins2],[-loleaut32 -lwinspool -lwinmm -lshell32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 -lcomdlg32 -lole32 -luuid -lcomctl32 -lmsimg32])
 
-  else if test "${enable_skins2}" = "yes"; then
+  else
     AX_ADD_PLUGINS([skins2])
     ALIASES="${ALIASES} svlc"
     AX_ADD_CPPFLAGS([skins2],[-Imodules/gui/skins2 -I${x_includes} -DX11_SKINS])
     AX_ADD_CXXFLAGS([skins2],[-O2 -fno-rtti])
     AX_ADD_LDFLAGS([skins2],[-L${x_libraries} -lXext -lX11])
-  fi fi
+  fi
 
   if test "${FREETYPE_CONFIG}" != "no"
   then
-    AX_ADD_CPPFLAGS([skins2],[`${FREETYPE_CONFIG} --cflags` ${INCICONV}])
-    AX_ADD_LDFLAGS([skins2],[`${FREETYPE_CONFIG} --libs` ${LIBICONV} -lpng])
+    AX_ADD_CPPFLAGS([skins2],[`${FREETYPE_CONFIG} --cflags`])
+    AX_ADD_LDFLAGS([skins2],[`${FREETYPE_CONFIG} --libs`])
   fi
+
+  AC_PATH_PROG(XML2_CONFIG, xml2-config, no)
+  if test "${XML2_CONFIG}" != "no"
+  then
+    AX_ADD_CPPFLAGS([skins2],[`${XML2_CONFIG} --cflags`])
+    AX_ADD_LDFLAGS([skins2],[`${XML2_CONFIG} --libs`])
+  fi
+
+  AX_ADD_CPPFLAGS([skins2],[${INCICONV}])
+  AX_ADD_LDFLAGS([skins2],[${LIBICONV} -lpng])
 fi
 
 
index 2c10fdb2e1b941543b14c68e9a41ec37115c5f92..a67dc035d8f15fc27fbf8ce6f5d9ea657fb6866a 100644 (file)
@@ -73,6 +73,8 @@ SOURCES_skins2 = \
        parser/parser_context.hpp \
        parser/skin.c \
        parser/skin.h \
+       parser/xmlparser.cpp \
+       parser/xmlparser.hpp \
        parser/wrappers.cpp \
        parser/wrappers.h \
        \
diff --git a/modules/gui/skins2/parser/xmlparser.cpp b/modules/gui/skins2/parser/xmlparser.cpp
new file mode 100644 (file)
index 0000000..a098fb5
--- /dev/null
@@ -0,0 +1,105 @@
+/*****************************************************************************
+ * xmlparser.cpp
+ *****************************************************************************
+ * Copyright (C) 2004 VideoLAN
+ * $Id: xmlparser.cpp,v 1.1 2004/01/24 13:08:12 asmax Exp $
+ *
+ * Authors: Cyril Deguet     <asmax@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+#include "xmlparser.hpp"
+
+XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName ):
+    SkinObject( pIntf )
+{
+    m_pReader = xmlNewTextReaderFilename( rFileName.c_str() );
+    if( !m_pReader )
+    {
+        msg_Err( getIntf(), "Failed to open %s for parsing",
+                 rFileName.c_str() );
+    }
+}
+
+
+XMLParser::~XMLParser()
+{
+    if( m_pReader )
+    {
+        xmlFreeTextReader( m_pReader );
+    }
+}
+
+
+int XMLParser::parse()
+{
+    if( !m_pReader )
+    {
+        return -1;
+    }
+
+    int ret = xmlTextReaderRead( m_pReader );
+    while (ret == 1)
+    {
+        // Get the node type
+        int type = xmlTextReaderNodeType( m_pReader );
+        switch (type )
+        {
+            // Error
+            case -1:
+                return -1;
+                break;
+
+            // Begin element
+            case 1:
+                // Read the element name
+                const xmlChar *eltName = xmlTextReaderConstName( m_pReader );
+                if( !eltName )
+                {
+                    return -1;
+                }
+                // Read the attributes
+                AttrList_t attributes;
+                while( xmlTextReaderMoveToNextAttribute( m_pReader ) == 1 )
+                {
+                    const xmlChar *name = xmlTextReaderConstName( m_pReader );
+                    const xmlChar *value = xmlTextReaderConstValue( m_pReader );
+                    if( !name || !value )
+                    {
+                        return -1;
+                    }
+                    attributes[(const char*)name] = (const char*)value;
+                }
+                handleBeginElement( (const char*)eltName, attributes);
+                break;
+        }
+        ret = xmlTextReaderRead( m_pReader );
+    }
+    return 0;
+}
+
+
+void XMLParser::handleBeginElement( const string &rName,
+                                    AttrList_t &attributes )
+{
+    fprintf(stderr,"%s\n", rName.c_str());
+    AttrList_t::const_iterator it;
+    for (it = attributes.begin(); it != attributes.end(); it++)
+    {
+        fprintf(stderr,"  %s = %s\n", (*it).first, (*it).second);
+    }
+}
diff --git a/modules/gui/skins2/parser/xmlparser.hpp b/modules/gui/skins2/parser/xmlparser.hpp
new file mode 100644 (file)
index 0000000..70957b2
--- /dev/null
@@ -0,0 +1,61 @@
+/*****************************************************************************
+ * xmlparser.hpp
+ *****************************************************************************
+ * Copyright (C) 2004 VideoLAN
+ * $Id: xmlparser.hpp,v 1.1 2004/01/24 13:08:12 asmax Exp $
+ *
+ * Authors: Cyril Deguet     <asmax@via.ecp.fr>
+ *          Olivier Teulière <ipkiss@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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *****************************************************************************/
+
+#ifndef XMLPARSER_HPP
+#define XMLPARSER_HPP
+
+#include "../src/skin_common.hpp"
+#include <libxml/xmlreader.h>
+#include <map>
+#include <string>
+
+
+/// XML parser using libxml2 text reader API
+class XMLParser: public SkinObject
+{
+    public:
+        XMLParser( intf_thread_t *pIntf, const string &rFileName );
+        virtual ~XMLParser();
+
+        int parse();
+
+    private:
+        // Key comparison function for type "const char*"
+        struct ltstr
+        {
+            bool operator()(const char* s1, const char* s2) const
+            {
+                return strcmp(s1, s2) < 0;
+            }
+        };
+        /// Type for attribute lists
+        typedef map<const char*, const char*, ltstr> AttrList_t;
+
+        /// Reader context
+        xmlTextReaderPtr m_pReader;
+
+        void handleBeginElement( const string &rName, AttrList_t &attributes );
+};
+
+#endif
index 840970e2acc50f0f7b096e0e3b88fc19dcb10596..380320a15a2d7cc975976de65f8c4a80e38f6bac 100755 (executable)
@@ -2,7 +2,7 @@
  * theme_loader.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: theme_loader.cpp,v 1.4 2004/01/18 00:25:02 asmax Exp $
+ * $Id: theme_loader.cpp,v 1.5 2004/01/24 13:08:12 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -26,6 +26,7 @@
 #include "theme.hpp"
 #include "../parser/builder.hpp"
 #include "../parser/parser_context.hpp"
+#include "../parser/xmlparser.hpp"
 #include "../src/os_factory.hpp"
 #include "../src/window_manager.hpp"
 
@@ -207,6 +208,9 @@ bool ThemeLoader::parse( const string &xmlFile )
         return false;
     }
 
+    XMLParser parser( getIntf(), xmlFile );
+    parser.parse();
+
     // Build and store the theme
     Builder builder( getIntf(), context.m_data );
     getIntf()->p_sys->p_theme = builder.build();
index e4c11bae4141554590dd38555e1d13d2769e5483..24a470a9395fc6a53d6cd0a04721cd78b32e9a27 100644 (file)
@@ -2,7 +2,7 @@
  * var_manager.cpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: var_manager.cpp,v 1.2 2004/01/11 17:12:17 asmax Exp $
+ * $Id: var_manager.cpp,v 1.3 2004/01/24 13:08:12 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -31,6 +31,17 @@ VarManager::VarManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
 }
 
 
+VarManager::~VarManager()
+{
+    // Delete the variables in the reverse order they were added
+    list<string>::const_iterator it;
+    for( it = m_varList.begin(); it != m_varList.end(); it++ )
+    {
+        m_varMap.erase(*it);
+    }
+}
+
+
 VarManager *VarManager::instance( intf_thread_t *pIntf )
 {
     if( ! pIntf->p_sys->p_varManager )
@@ -59,6 +70,7 @@ void VarManager::destroy( intf_thread_t *pIntf )
 void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
 {
     m_varMap[rName] = rcVar;
+    m_varList.push_front(rName);
 }
 
 
index 6bc2238dcc889f23188dc8f870aae9759eacb00b..80d31df7abbd12faa8d228c287c2b5717b357889 100644 (file)
@@ -2,7 +2,7 @@
  * var_manager.hpp
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: var_manager.hpp,v 1.2 2004/01/11 17:12:17 asmax Exp $
+ * $Id: var_manager.hpp,v 1.3 2004/01/24 13:08:12 asmax Exp $
  *
  * Authors: Cyril Deguet     <asmax@via.ecp.fr>
  *          Olivier Teulière <ipkiss@via.ecp.fr>
@@ -26,6 +26,7 @@
 #define VAR_MANAGER_HPP
 
 #include "../utils/var_text.hpp"
+#include <list>
 #include <map>
 
 
@@ -60,10 +61,12 @@ class VarManager: public SkinObject
         VarText m_helpText;
         /// Map of registerd variables
         map<string, VariablePtr> m_varMap;
+        /// List of registed variables
+        list<string> m_varList;
 
         /// Private because it is a singleton
         VarManager( intf_thread_t *pIntf );
-        virtual ~VarManager() {}
+        virtual ~VarManager();
 };