9#include "TemplateList.h"
13#include "IException.h"
48 m_path = other.m_path;
49 m_name = other.m_name;
50 m_type = other.m_type;
130 foreach (
Template *currentTemplate, *
this) {
131 currentTemplate->deleteFromDisk();
134 if (!m_path.isEmpty()) {
135 QFile::remove(project->
templateRoot() +
"/" + m_path +
"/templates.xml");
169 if (m_type ==
"maps") {
170 stream.writeStartElement(
"mapTemplateList");
172 else if (m_type ==
"registrations") {
173 stream.writeStartElement(
"regTemplateList");
177 QString(
"Attempting to save unsupported template file type: [%1]").arg(m_type),
180 stream.writeAttribute(
"name", m_name);
181 stream.writeAttribute(
"type", m_type);
182 stream.writeAttribute(
"path", m_path);
185 +
"/" + m_type +
"/" + m_name +
"/templates.xml");
187 if (!settingsFileName.
dir().mkpath(settingsFileName.
path())) {
189 QString(
"Failed to create directory [%1]").arg(settingsFileName.
path()),
193 QFile templateListContentsFile(settingsFileName.
toString());
195 if (!templateListContentsFile.open(QIODevice::ReadWrite | QIODevice::Truncate)) {
197 QString(
"Unable to save template information for [%1] because [%2] could not be opened "
199 .arg(m_name).arg(settingsFileName.
original()),
203 QXmlStreamWriter templateDetailsWriter(&templateListContentsFile);
204 templateDetailsWriter.setAutoFormatting(
true);
205 templateDetailsWriter.writeStartDocument();
206 templateDetailsWriter.writeStartElement(
"templates");
208 foreach (
Template *currentTemplate, *
this) {
209 currentTemplate->save(templateDetailsWriter, project, newProjectRoot);
211 QString newPath = newProjectRoot.
toString() +
"/templates/" + m_type +
"/" + m_name;
213 if (currentTemplate->fileName() !=
214 newPath +
"/" +
FileName(currentTemplate->fileName()).
name()) {
215 QFile::copy(currentTemplate->fileName(),
216 newPath +
"/" +
FileName(currentTemplate->fileName()).
name() );
220 templateDetailsWriter.writeEndElement();
221 templateDetailsWriter.writeEndDocument();
223 stream.writeEndElement();
File name manipulation and expansion.
QString path() const
Returns the path of the file name.
QDir dir() const
Returns the path of the file's parent directory as a QDir object.
QString name() const
Returns the name of the file excluding the path and the attributes in the file name.
QString original() const
Returns the full file name including the file path.
QString toString() const
Returns a QString of the full file name including the file path, excluding the attributes with any Is...
@ Io
A type of error that occurred when performing an actual I/O operation.
The main project for ipce.
static QString templateRoot(QString projectRoot)
Appends the root directory name 'templates' to the project .
QString templateRoot() const
Accessor for the root directory of the template data.
void setPath(QString newPath)
Set the relative path (from the project root) to this TemplateList's folder.
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.
~TemplateList()
Destructor.
void deleteFromDisk(Project *project)
Delete all of the contained Templates from disk.
QString path() const
Get the path to these Templates in the TemplateList (relative to project root).
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Convert this TemplateList into XML format for saving/restoring capabilities.
void setName(QString newName)
Set the human-readable name of this TemplateList.
QString type() const
Get the type of template in this TemplateList.
void setType(QString newType)
Set the type of template for of this TemplateList.
This is free and unencumbered software released into the public domain.
This is free and unencumbered software released into the public domain.