30 #include "XmlStackedHandlerReader.h" 64 m_path = other.m_path;
65 m_name = other.m_name;
66 m_type = other.m_type;
159 foreach (
Template *currentTemplate, *
this) {
163 if (!m_path.isEmpty()) {
164 QFile::remove(project->
templateRoot() +
"/" + m_path +
"/templates.xml");
198 if (m_type ==
"maps") {
199 stream.writeStartElement(
"mapTemplateList");
201 else if (m_type ==
"registrations") {
202 stream.writeStartElement(
"regTemplateList");
206 QString(
"Attempting to save unsupported template file type: [%1]").arg(m_type),
209 stream.writeAttribute(
"name", m_name);
210 stream.writeAttribute(
"type", m_type);
211 stream.writeAttribute(
"path", m_path);
214 +
"/" + m_type +
"/" + m_name +
"/templates.xml");
216 if (!settingsFileName.
dir().mkpath(settingsFileName.
path())) {
218 QString(
"Failed to create directory [%1]").arg(settingsFileName.
path()),
222 QFile templateListContentsFile(settingsFileName.
toString());
224 if (!templateListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
226 QString(
"Unable to save template information for [%1] because [%2] could not be opened " 228 .arg(m_name).arg(settingsFileName.
original()),
232 QXmlStreamWriter templateDetailsWriter(&templateListContentsFile);
233 templateDetailsWriter.setAutoFormatting(
true);
234 templateDetailsWriter.writeStartDocument();
235 templateDetailsWriter.writeStartElement(
"templates");
237 foreach (
Template *currentTemplate, *
this) {
238 currentTemplate->
save(templateDetailsWriter, project, newProjectRoot);
240 QString newPath = newProjectRoot.
toString() +
"/templates/" + m_type +
"/" + m_name;
244 QFile::copy(currentTemplate->
fileName(),
249 templateDetailsWriter.writeEndElement();
250 templateDetailsWriter.writeEndDocument();
252 stream.writeEndElement();
281 const QString &qName,
const QXmlAttributes &atts) {
282 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
283 if (localName ==
"mapTemplateList" || localName ==
"regTemplateList") {
284 QString
name = atts.value(
"name");
285 QString
type = atts.value(
"type");
286 QString
path = atts.value(
"path");
288 if (!
name.isEmpty()) {
289 m_templateList->setName(
name);
292 if (!
type.isEmpty()) {
293 m_templateList->setType(
type);
296 if (!
path.isEmpty()) {
297 m_templateList->setPath(
path);
300 else if (localName ==
"template") {
301 m_templateList->append(
new Template(m_project->templateRoot(), reader()));
323 const QString &qName) {
324 if (localName ==
"mapTemplateList" || localName ==
"regTemplateList") {
325 XmlHandler handler(m_templateList, m_project);
329 reader.setErrorHandler(&handler);
331 QString templateListXmlPath = m_project->templateRoot() +
"/" + m_templateList->type() +
"/" 332 + m_templateList->name() +
"/templates.xml";
333 templateListXmlPath = QDir::cleanPath(templateListXmlPath);
335 QFile file(templateListXmlPath);
337 if (!file.open(QFile::ReadOnly)) {
339 QString(
"Unable to open [%1] with read access")
340 .arg(templateListXmlPath),
344 QXmlInputSource xmlInputSource(&file);
345 if (!reader.parse(xmlInputSource))
347 tr(
"Failed to open TemplateList XML [%1]").arg(templateListXmlPath),
351 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
static QString templateRoot(QString projectRoot)
Appends the root directory name 'templates' to the project .
void deleteFromDisk()
Delete the template from disk.
QString path() const
Returns the path of the file name.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this TemplateList into XML format for saving/restoring capabilities.
The main project for ipce.
File name manipulation and expansion.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Method to write this Template object's member data to an XML stream.
QString fileName() const
Get the file name that this Template represents.
QString path() const
Get the path to these Templates in the TemplateList (relative to project root).
A type of error that occurred when performing an actual I/O operation.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
Handle an XML start element.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
Handle an XML end element.
void deleteFromDisk(Project *project)
Delete all of the contained Templates from disk.
#define _FILEINFO_
Macro for the filename and line number.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
XmlHandler(TemplateList *templateList, Project *project)
Create an XML Handler (reader/writer) that can populate the TemplateList class data.
~TemplateList()
Destructor.
QString original() const
Returns the full file name including the file path.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
TemplateList(QString name, QString type, QString path, QObject *parent=NULL)
Create a template from a file name, type, and path.
QString name() const
Get the human-readable name of this TemplateList.
Project * m_project
Project that contains the template list.
QString templateRoot() const
Accessor for the root directory of the template data.
TemplateList * m_templateList
TemplateList to be read or written.
QString toString() const
Returns a QString of the full file name including the file path, excluding the attributes with any Is...
QString type() const
Get the type of template in this TemplateList.
Namespace for ISIS/Bullet specific routines.
void setType(QString newType)
Set the type of template for of this TemplateList.
void setPath(QString newPath)
Set the relative path (from the project root) to this TemplateList's folder.
void setName(QString newName)
Set the human-readable name of this TemplateList.
Manage a stack of content handlers for reading XML files.