New lua versions
[ryzomcore.git] / studio / src / plugins / gui_editor / widget_serializer.cpp
blobe897c2fefd121d53b8bc9876d28f9cd29115617e
1 // Object Viewer Qt GUI Editor plugin <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "widget_serializer.h"
22 #include "nel/gui/interface_group.h"
23 #include "nel/gui/widget_manager.h"
25 #include <libxml/xmlstring.h>
26 #include <libxml/tree.h>
28 namespace GUIEditor
30 bool WidgetSerializer::serialize( const std::string &masterGroup )
32 if( fileName.empty() )
33 return false;
35 CInterfaceGroup *mg =
36 CWidgetManager::getInstance()->getMasterGroupFromId( masterGroup );
38 if( mg == NULL )
39 return false;
41 CInterfaceElement *ag =
42 CWidgetManager::getInstance()->getElementFromId( activeGroup );
43 if( ag == NULL )
44 return false;
46 out.open( fileName.c_str() );
47 if( !out.is_open() )
48 return false;
50 xmlNodePtr root = xmlNewNode( NULL, BAD_CAST "interface_config" );
51 if( root == NULL )
53 out.close();
54 return false;
57 if( mg->serializeGroup( root, "root" ) == NULL )
59 xmlFreeNode( root );
60 out.close();
61 return false;
64 if( !CWidgetManager::getInstance()->serializeOptions( root ) )
66 xmlFreeNode( root );
67 out.close();
68 return false;
71 if( !CWidgetManager::getInstance()->getParser()->serializeKeySettings( root ) )
73 xmlFreeNode( root );
74 out.close();
75 return false;
79 if( !CWidgetManager::getInstance()->getParser()->serializePointerSettings( root ) )
81 xmlFreeNode( root );
82 out.close();
83 return false;
87 if( !CWidgetManager::getInstance()->getParser()->serializeVariables( root ) )
89 xmlFreeNode( root );
90 out.close();
91 return false;
95 if( !CWidgetManager::getInstance()->getParser()->serializeProcs( root ) )
97 xmlFreeNode( root );
98 out.close();
99 return false;
102 if( mg->serializeSubGroups( root ) == NULL )
104 ag->setActive( true );
105 xmlFreeNode( root );
106 out.close();
107 return false;
110 if( !mg->serializeLinks( root ) )
112 xmlFreeNode( root );
113 out.close();
114 return false;
117 if( !CWidgetManager::getInstance()->serializeTreeData( root ) )
119 xmlFreeNode( root );
120 out.close();
121 return false;
124 level = -1;
125 serializeTree( root );
128 xmlFreeNode( root );
129 out.close();
131 return true;
134 bool WidgetSerializer::serializeTree( _xmlNode *node )
136 level++;
138 std::string tabs;
139 for( int i = 0; i < level; i++ )
140 tabs.push_back( '\t' );
142 out << tabs << "<" << node->name;
144 xmlAttrPtr prop = node->properties;
145 while( prop != NULL )
147 std::string name =
148 std::string( reinterpret_cast< const char* >( prop->name ) );
150 std::string value =
151 std::string( reinterpret_cast< const char* >( xmlGetProp( node, BAD_CAST name.c_str() ) ) );
153 out << " " << name << "=\"" << value << "\"" << std::endl << tabs;
155 prop = prop->next;
158 if( node->children != NULL )
160 out << tabs << ">" << std::endl << std::endl;
162 xmlNodePtr child = node->children;
163 while( child != NULL )
165 serializeTree( child );
166 child = child->next;
169 out << tabs << "</" << node->name << ">" << std::endl << std::endl;
171 else
173 out << tabs << "/>" << std::endl << std::endl;
176 level--;
178 return true;