1 /***************************************************************************
2 * Copyright (C) 2007 by David Cuadrado *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
22 #include "commandparser.h"
24 #include <yamf/model/command/base.h>
25 #include "datasource.h"
27 #include <dcore/debug.h>
31 struct CommandParser::Private
33 Private() : currentSource(0) {}
35 DataSource
*currentSource
;
38 CommandParser::CommandParser() : DCore::XmlParserBase(), d(new Private
)
42 CommandParser::~CommandParser()
47 bool CommandParser::startTag(const QString
&tag
, const QXmlAttributes
&atts
)
49 if( atts
.count() > 0 )
51 DataSource::Values values
;
53 for(int i
= 0; i
< atts
.count(); i
++)
55 QString qname
= atts
.qName(i
);
56 values
[qname
] = atts
.value(qname
);
59 d
->currentSource
->setValues(tag
, values
);
62 if( tag
== "addobject" || tag
== "removeobject" )
64 d
->currentSource
->setType(DataSource::Object
);
66 else if( tag
== "insertscene" || tag
== "removescene" || tag
== "movescene" || tag
== "renamescene" )
68 d
->currentSource
->setType(DataSource::Scene
);
70 else if( tag
== "insertlayer" || tag
== "removelayer" || tag
== "locklayer" || tag
== "changelayervisibility"|| tag
== "movelayer" || tag
== "renamelayer")
72 d
->currentSource
->setType(DataSource::Layer
);
74 else if( tag
== "insertframe" || tag
== "removeframe" || tag
== "lockframe" || tag
== "changeframevisibility" || tag
== "moveframe" || tag
== "renameframe" || tag
== "expandframe" )
76 d
->currentSource
->setType(DataSource::Frame
);
78 else if( tag
== "addlibraryobject" || tag
== "removelibraryobject" )
80 d
->currentSource
->setType(DataSource::Library
);
119 bool CommandParser::endTag(const QString
&tag
)
124 void CommandParser::text(const QString
&text
)
128 DataSource
*CommandParser::build(const YAMF::Command::Base
*command
)
130 QString xml
= command
->toXml();
132 d
->currentSource
= new DataSource
;
133 d
->currentSource
->setData("command", qVariantFromValue(command
) );
134 d
->currentSource
->setData("xml", xml
);
136 if( ! DCore::XmlParserBase::parse(xml
) )
138 dError() << "Failed to parse";
142 d
->currentSource
->setData("root", root());
144 DataSource
*source
= d
->currentSource
;
145 d
->currentSource
= 0;