Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 408 → Rev 409

/trunk/Scribus/scribus/plugins/newfromtemplateplugin/nftsettings.cpp
3,44 → 3,36
***************************************************************************/
#include "nftsettings.h"
 
nftsettings::nftsettings(QString guilang)
nftsettings::nftsettings(QString guilang, QString templateDir)
{
lang = guilang;
scribusShare = PREL;
scribusShare += "/share/scribus";
scribusUserHome = QDir::convertSeparators(QDir::homeDirPath()+"/.scribus");
nftRCFile = QDir::convertSeparators(scribusUserHome+"/nftrc.xml");
userTemplateDir = templateDir;
if (userTemplateDir.right(1) == "/")
userTemplateDir = userTemplateDir.left(userTemplateDir.length() - 1);
read();
}
 
void nftsettings::read()
{
QDir scribus(scribusUserHome);
if (!scribus.exists("nftrc.xml")) {
getDefaults();
}
handler = new nftrcreader(&templates,scribusUserHome);
QFile* rc = new QFile(nftRCFile);
QXmlInputSource* source = new QXmlInputSource(rc);
reader = new QXmlSimpleReader();
reader->setContentHandler(handler);
reader->parse(source);
delete source;
delete rc;
addTemplates(scribusShare);
addTemplates(scribusUserHome);
 
addTemplates(scribusShare+"/templates");
addTemplates(scribusUserHome+"/templates");
if ((userTemplateDir != NULL) && (userTemplateDir != ""))
addTemplates(userTemplateDir);
}
 
void nftsettings::addTemplates(QString dir) // dir will be searched for a sub folder called templates
{
// Add templates from the dir itself
QString tmplFile = findTemplateXml(dir + "/templates");
QString tmplFile = findTemplateXml(dir);
QFile* tmplxml = new QFile(QDir::convertSeparators(tmplFile));
handler->setSourceDir(dir + "/templates");
handler->setSourceDir(dir);
handler->setSourceFile(tmplFile);
if (tmplxml->exists())
{
52,7 → 44,7
// And from all the subdirectories. template.xml file is only searched one dir level deeper than the dir
QDir tmpldir(dir + "/templates");
QDir tmpldir(dir);
if (tmpldir.exists())
{
tmpldir.setFilter(QDir::Dirs);
60,9 → 52,9
for (uint i = 0; i < dirs.size(); ++i)
{
if ((dirs[i] != ".") && (dirs[i] != "..")) {
tmplFile = findTemplateXml(dir + "/templates/" + dirs[i]);
tmplFile = findTemplateXml(dir + "/" + dirs[i]);
QFile* tmplxml = new QFile(QDir::convertSeparators(tmplFile));
handler->setSourceDir(dir+"/templates/"+dirs[i]);
handler->setSourceDir(dir+"/"+dirs[i]);
handler->setSourceFile(tmplFile);
if (tmplxml->exists())
{
76,32 → 68,6
}
}
 
void nftsettings::write()
{
// QFile rc(nftRCFile);
}
 
void nftsettings::getDefaults()
{
QString tPrel = PREL;
QString tmplDir = tPrel + "/share/scribus/templates";
// Create the defaults ~/.scribus/nft/nftrc.xml file
QString text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
text += "<nft>\n";
text += "\t<settings>\n";
text += "\t</settings>\n";
text += "</nft>\n";
 
QFile rc(nftRCFile);
if ( rc.open( IO_WriteOnly ) )
{
QTextStream stream(&rc);
stream.setEncoding(QTextStream::UnicodeUTF8);
stream << text;
rc.close();
}
}
 
QString nftsettings::findTemplateXml(QString dir)
{
QString tmp = dir + "/template." + lang + ".xml";