X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=src%2Fexport-impress.cpp;fp=src%2Fexport-impress.cpp;h=53695594aac00ec8a96179d235a19363dddce268;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/src/export-impress.cpp b/src/export-impress.cpp new file mode 100644 index 0000000..5369559 --- /dev/null +++ b/src/export-impress.cpp @@ -0,0 +1,217 @@ +#include + +#include "export-impress.h" +#include "mainwindow.h" + +extern QString vymName; +extern Main *mainWindow; + +ExportOO::ExportOO() +{ + exportName = "Impress"; + filter = "LibreOffice Impress (*.odp);;All (* *.*)"; + caption = vymName + " -" + + QObject::tr("Export as LibreOffice Impress presentation"); + useSections = false; +} + +ExportOO::~ExportOO() {} + +QString ExportOO::buildList(TreeItem *current) +{ + QString r; + + uint i = 0; + BranchItem *bi = current->getFirstBranch(); + if (bi) { + // Start list + r += "\n"; + while (bi) { + if (!bi->hasHiddenExportParent()) { + r += ""; + r += quoteMeta(bi->getHeadingPlain()); + // If necessary, write note + if (!bi->isNoteEmpty()) + r += "" + bi->getNoteASCII(); + r += ""; + r += buildList(bi); // recursivly add deeper branches + r += "\n"; + } + i++; + bi = current->getBranchNum(i); + } + r += "\n"; + } + return r; +} + +void ExportOO::exportPresentation() +{ + QString allPages; + + BranchItem *firstMCO = + (BranchItem *)(model->getRootItem()->getFirstBranch()); + if (!firstMCO) { + QMessageBox::critical(0, QObject::tr("Critical Export Error"), + QObject::tr("No objects in map!")); + return; + } + + // Insert new content + // FIXME add extra title in mapinfo for vym 1.13.x + content.replace("", + quoteMeta(firstMCO->getHeadingPlain())); + content.replace("", quoteMeta(model->getAuthor())); + + QString onePage; + QString list; + + BranchItem *sectionBI; + int i = 0; + BranchItem *pagesBI; + int j = 0; + + int mapcenters = model->getRootItem()->branchCount(); + + // useSections already has been set in setConfigFile + if (mapcenters > 1) + sectionBI = firstMCO; + else + sectionBI = firstMCO->getFirstBranch(); + + // Walk sections + while (sectionBI && !sectionBI->hasHiddenExportParent()) { + if (useSections) { + // Add page with section title + onePage = sectionTemplate; + onePage.replace("", + quoteMeta(sectionBI->getHeadingPlain())); + allPages += onePage; + pagesBI = sectionBI->getFirstBranch(); + } + else { + // i=-2; // only use inner loop to + // turn mainbranches into pages + // sectionBI=firstMCO; + pagesBI = sectionBI; + } + + j = 0; + while (pagesBI && !pagesBI->hasHiddenExportParent()) { + // Add page with list of items + onePage = pageTemplate; + onePage.replace("", + quoteMeta(pagesBI->getHeadingPlain())); + list = buildList(pagesBI); + onePage.replace("", list); + allPages += onePage; + if (pagesBI != sectionBI) { + j++; + pagesBI = ((BranchItem *)pagesBI->parent())->getBranchNum(j); + } + else + pagesBI = NULL; // We are already iterating over the sectionBIs + } + i++; + if (mapcenters > 1) + sectionBI = model->getRootItem()->getBranchNum(i); + else + sectionBI = firstMCO->getBranchNum(i); + } + + content.replace("", allPages); + + // Write modified content + QFile f(contentFile); + if (!f.open(QIODevice::WriteOnly)) { + QMessageBox::critical( + 0, QObject::tr("Critical Export Error"), + QObject::tr("Could not write %1").arg(contentFile)); + mainWindow->statusMessage(QString(QObject::tr("Export failed."))); + return; + } + + QTextStream t(&f); + t.setCodec("UTF-8"); + t << content; + f.close(); + + // zip tmpdir to destination + zipDir(tmpDir, filePath); + + displayedDestination = filePath; + + result = ExportBase::Success; + + QStringList args; + args << filePath; + args << configFile; + completeExport(args); +} + +bool ExportOO::setConfigFile(const QString &cf) +{ + configFile = cf; + int i = cf.lastIndexOf("/"); + if (i >= 0) + configDir = cf.left(i); + SimpleSettings set; + + if (!set.readSettings(configFile)) { + QMessageBox::critical( + 0, QObject::tr("Critical Export Error"), + QObject::tr("Couldn't read settings from \"%1\"").arg(configFile)); + return false; + } + + // set paths + templateDir = configDir + "/" + set.value("Template"); + + setupTmpDir(); + + QDir d(templateDir); + if (!d.exists()) { + QMessageBox::critical(0, QObject::tr("Critical Export Error"), + QObject::tr("Check \"%1\" in\n%2") + .arg("Template=" + set.value("Template")) + .arg(configFile)); + return false; + } + + contentTemplateFile = templateDir + "content-template.xml"; + pageTemplateFile = templateDir + "page-template.xml"; + sectionTemplateFile = templateDir + "section-template.xml"; + contentFile = tmpDir.path() + "/content.xml"; + + if (set.value("useSections").contains("yes")) + useSections = true; + + // Copy template to tmpdir + copyDir(templateDir, tmpDir); + + // Read content-template + if (!loadStringFromDisk(contentTemplateFile, content)) { + QMessageBox::critical( + 0, QObject::tr("Critical Export Error"), + QObject::tr("Could not read %1").arg(contentTemplateFile)); + return false; + } + + // Read page-template + if (!loadStringFromDisk(pageTemplateFile, pageTemplate)) { + QMessageBox::critical( + 0, QObject::tr("Critical Export Error"), + QObject::tr("Could not read %1").arg(pageTemplateFile)); + return false; + } + + // Read section-template + if (useSections && + !loadStringFromDisk(sectionTemplateFile, sectionTemplate)) { + QMessageBox::critical( + 0, QObject::tr("Critical Export Error"), + QObject::tr("Could not read %1").arg(sectionTemplateFile)); + return false; + } + return true; +}