Back to index

scribus-ng  1.3.4.dfsg+svn20071115
nftrcreader.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *   Riku Leino, tsoots@gmail.com                                          *
00009  ***************************************************************************/
00010 #include "nftrcreader.h"
00011 
00012 using namespace std;
00013 
00014 nftrcreader::nftrcreader(std::vector<nfttemplate*> *tmplts,QString sourceDir)
00015 {
00016        templates = tmplts;
00017        currentDir = sourceDir;
00018        setupCategories();
00019 }
00020 
00021 bool nftrcreader::startDocument()
00022 {
00023        inSettings       = false;
00024        inTemplate       = false;
00025        inName           = false;
00026        inFile           = false;
00027        inTNail          = false;
00028        inImg            = false;
00029        inPSize          = false;
00030        inColor          = false;
00031        inDescr          = false;
00032        inUsage          = false;
00033        inScribusVersion = false;
00034        inDate           = false;
00035        inAuthor         = false;
00036        inEmail          = false;
00037        return true;
00038 }
00039 
00040 bool nftrcreader::startElement(const QString&, const QString&, const QString &name, const QXmlAttributes &attrs) 
00041 {
00042        if (name == "name")
00043               inName = true;
00044        else if (name == "file")
00045               inFile = true;
00046        else if (name == "tnail")
00047               inTNail = true;
00048        else if (name == "img")
00049               inImg = true;
00050        else if (name == "psize")
00051               inPSize = true;
00052        else if (name == "color") 
00053               inColor = true;
00054        else if (name == "descr")
00055               inDescr = true;
00056        else if (name == "usage")
00057               inUsage = true;
00058        else if (name == "scribus_version")
00059               inScribusVersion = true;
00060        else if (name == "date")
00061               inDate = true;
00062        else if (name == "author")
00063               inAuthor = true;
00064        else if (name == "email")
00065               inEmail = true;
00066 
00067 
00068        if (name == "template") { // new template starts here
00069               inTemplate = true;
00070               QString category;
00071               QString enCat;
00072               for (int i = 0; i < attrs.count(); i++)
00073               {
00074                      if (attrs.localName(i) == "category")
00075                      {
00076                             category = getCategory(attrs.value(i));
00077                             enCat = attrs.value(i);
00078                      }
00079               }
00080               tmpTemplate = new nfttemplate(new QFile(currentFile), category); // create a new template
00081               tmpTemplate->enCategory = enCat;
00082        }
00083 
00084        if (name == "settings") 
00085               inSettings = true;
00086 
00087        return true;
00088 }
00089 
00090 bool nftrcreader::characters(const QString &ch) 
00091 {
00092        QString tmp(ch);
00093        if (inName)
00094               tmpTemplate->name = tmp;
00095        else if (inFile)
00096        {
00097               if (tmp.left(1) == "/")
00098                      tmpTemplate->file = tmp;
00099               else 
00100                      tmpTemplate->file = currentDir + "/" + tmp;
00101        } else if (inTNail)
00102        {
00103               if (tmp.left(1) == "/")
00104                      tmpTemplate->tnail = tmp;
00105               else
00106                      tmpTemplate->tnail = currentDir + "/" + tmp;
00107        } else if (inImg)
00108        {
00109               if (tmp.left(1) == "/") 
00110                      tmpTemplate->img = tmp;
00111               else
00112                      tmpTemplate->img = currentDir + "/" + tmp;
00113        } else if (inPSize)
00114               tmpTemplate->psize = tmp; 
00115        else if (inColor)
00116               tmpTemplate->color = tmp; 
00117        else if (inDescr)
00118               tmpTemplate->descr = tmp; 
00119        else if (inUsage)
00120               tmpTemplate->usage = tmp;
00121        else if (inScribusVersion)
00122               tmpTemplate->scribusVersion = tmp;
00123        else if (inDate)
00124               tmpTemplate->date = tmp;
00125        else if (inAuthor)
00126               tmpTemplate->author = tmp;
00127        else if (inEmail)
00128               tmpTemplate->email = tmp; 
00129 
00130        return true;
00131 }
00132 
00133 bool nftrcreader::endElement(const QString&, const QString&, const QString &name)
00134 {
00135        if (name == "template")
00136        { // new template starts here
00137               inTemplate = false;
00138               if (tmpTemplate != NULL) // If we have a template already created
00139                      if (tmpTemplate->isValid()) // and the template really exists push
00140                             templates->push_back(tmpTemplate); // it to the templates vector and start a new one
00141        }
00142        if (inTemplate) {
00143               if (inName && name == "name")
00144                      inName = false;
00145               else if (inFile && name == "file")
00146                      inFile = false;
00147               else if (inTNail && name == "tnail")
00148                      inTNail = false;
00149               else if (inImg && name == "img")
00150                      inImg = false;
00151               else if (inPSize && name == "psize")
00152                      inPSize = false;
00153               else if (inColor && name == "color") 
00154                      inColor = false;
00155               else if (inDescr && name == "descr")
00156                      inDescr = false;
00157               else if (inUsage && name == "usage")
00158                      inUsage = false;
00159               else if (inScribusVersion && name == "scribus_version")
00160                      inScribusVersion = false;
00161               else if (inDate && name == "date")
00162                      inDate = false;
00163               else if (inAuthor && name == "author")
00164                      inAuthor = false;
00165               else if (inEmail && name == "email")
00166                      inEmail = false;
00167               else if (inTemplate && name == "template")
00168                      inTemplate = false;
00169        }
00170        
00171        if (inSettings && name == "settings")
00172               inSettings = false;
00173 
00174        return true;
00175 }
00176 
00177 void nftrcreader::setSourceDir(QString source) 
00178 {
00179        currentDir = source;
00180 }
00181 
00182 void nftrcreader::setSourceFile(QString sourceFile)
00183 {
00184        currentFile = sourceFile;
00185 }
00186 
00187 QString nftrcreader::getCategory(QString cat) 
00188 {
00189        for (uint i = 0; i < cats.size(); ++i)
00190        {
00191               if (cat == *cats[i]->first)
00192                      return *cats[i]->second;
00193        }
00194        
00195        return cat;
00196 }
00197 
00198 void nftrcreader::setupCategories()
00199 {
00200        // en will be used in template.xml and it will be then replaced with the lang when used for users
00201        // to get the categories in their language.
00202        QString* en = new QString("Newsletters"); QString* lang = new QString(QObject::tr("Newsletters"));
00203        cats.push_back(new Pair(en,lang));
00204        en = new QString("Brochures"); lang = new QString(QObject::tr("Brochures"));
00205        cats.push_back(new Pair(en,lang));
00206        en = new QString("Catalogs"); lang = new QString(QObject::tr("Catalogs"));
00207        cats.push_back(new Pair(en,lang));
00208        en = new QString("Flyers"); lang = new QString(QObject::tr("Flyers"));
00209        cats.push_back(new Pair(en,lang));
00210        en = new QString("Signs"); lang = new QString(QObject::tr("Signs"));
00211        cats.push_back(new Pair(en,lang));
00212        en = new QString("Cards"); lang = new QString(QObject::tr("Cards"));
00213        cats.push_back(new Pair(en,lang));
00214        en = new QString("Letterheads"); lang = new QString(QObject::tr("Letterheads"));
00215        cats.push_back(new Pair(en,lang));
00216        en = new QString("Envelopes"); lang = new QString(QObject::tr("Envelopes"));
00217        cats.push_back(new Pair(en,lang));
00218        en = new QString("Business Cards"); lang = new QString(QObject::tr("Business Cards"));
00219        cats.push_back(new Pair(en,lang));
00220        en = new QString("Calendars"); lang = new QString(QObject::tr("Calendars"));
00221        cats.push_back(new Pair(en,lang));
00222        en = new QString("Advertisements"); lang = new QString(QObject::tr("Advertisements"));
00223        cats.push_back(new Pair(en,lang));
00224        en = new QString("Labels"); lang = new QString(QObject::tr("Labels"));
00225        cats.push_back(new Pair(en,lang));
00226        en = new QString("Menus"); lang = new QString(QObject::tr("Menus"));
00227        cats.push_back(new Pair(en,lang));
00228        en = new QString("Programs"); lang = new QString(QObject::tr("Programs"));
00229        cats.push_back(new Pair(en,lang));
00230        en = new QString("PDF Forms"); lang = new QString(QObject::tr("PDF Forms"));
00231        cats.push_back(new Pair(en,lang));
00232        en = new QString("PDF Presentations"); lang = new QString(QObject::tr("PDF Presentations"));
00233        cats.push_back(new Pair(en,lang));
00234        en = new QString("Magazines"); lang = new QString(QObject::tr("Magazines"));
00235        cats.push_back(new Pair(en,lang));
00236        en = new QString("Posters"); lang = new QString(QObject::tr("Posters"));
00237        cats.push_back(new Pair(en,lang));
00238        en = new QString("Announcements"); lang = new QString(QObject::tr("Announcements"));
00239        cats.push_back(new Pair(en,lang));
00240        en = new QString("Text Documents"); lang = new QString(QObject::tr("Text Documents"));
00241        cats.push_back(new Pair(en,lang));
00242        en = new QString("Folds"); lang = new QString(QObject::tr("Folds"));
00243        cats.push_back(new Pair(en,lang));
00244        en = new QString("Media Cases"); lang = new QString(QObject::tr("Media Cases"));
00245        cats.push_back(new Pair(en,lang));
00246        en = new QString("Own Templates"); lang = new QString(QObject::tr("Own Templates"));
00247        cats.push_back(new Pair(en,lang));
00248 }
00249 
00250 nftrcreader::~nftrcreader()
00251 {
00252        for (uint i = 0; i < cats.size(); ++i)
00253               delete cats[i];
00254 }