3 #include "export-impress.h"
4 #include "mainwindow.h"
6 extern QString vymName;
7 extern Main *mainWindow;
11 exportName = "Impress";
12 filter = "LibreOffice Impress (*.odp);;All (* *.*)";
13 caption = vymName + " -" +
14 QObject::tr("Export as LibreOffice Impress presentation");
18 ExportOO::~ExportOO() {}
20 QString ExportOO::buildList(TreeItem *current)
25 BranchItem *bi = current->getFirstBranch();
28 r += "<text:list text:style-name=\"vym-list\">\n";
30 if (!bi->hasHiddenExportParent()) {
31 r += "<text:list-item><text:p >";
32 r += quoteMeta(bi->getHeadingPlain());
33 // If necessary, write note
34 if (!bi->isNoteEmpty())
35 r += "<text:line-break/>" + bi->getNoteASCII();
37 r += buildList(bi); // recursivly add deeper branches
38 r += "</text:list-item>\n";
41 bi = current->getBranchNum(i);
43 r += "</text:list>\n";
48 void ExportOO::exportPresentation()
52 BranchItem *firstMCO =
53 (BranchItem *)(model->getRootItem()->getFirstBranch());
55 QMessageBox::critical(0, QObject::tr("Critical Export Error"),
56 QObject::tr("No objects in map!"));
61 // FIXME add extra title in mapinfo for vym 1.13.x
62 content.replace("<!-- INSERT TITLE -->",
63 quoteMeta(firstMCO->getHeadingPlain()));
64 content.replace("<!-- INSERT AUTHOR -->", quoteMeta(model->getAuthor()));
69 BranchItem *sectionBI;
74 int mapcenters = model->getRootItem()->branchCount();
76 // useSections already has been set in setConfigFile
80 sectionBI = firstMCO->getFirstBranch();
83 while (sectionBI && !sectionBI->hasHiddenExportParent()) {
85 // Add page with section title
86 onePage = sectionTemplate;
87 onePage.replace("<!-- INSERT PAGE HEADING -->",
88 quoteMeta(sectionBI->getHeadingPlain()));
90 pagesBI = sectionBI->getFirstBranch();
93 // i=-2; // only use inner loop to
94 // turn mainbranches into pages
95 // sectionBI=firstMCO;
100 while (pagesBI && !pagesBI->hasHiddenExportParent()) {
101 // Add page with list of items
102 onePage = pageTemplate;
103 onePage.replace("<!-- INSERT PAGE HEADING -->",
104 quoteMeta(pagesBI->getHeadingPlain()));
105 list = buildList(pagesBI);
106 onePage.replace("<!-- INSERT LIST -->", list);
108 if (pagesBI != sectionBI) {
110 pagesBI = ((BranchItem *)pagesBI->parent())->getBranchNum(j);
113 pagesBI = NULL; // We are already iterating over the sectionBIs
117 sectionBI = model->getRootItem()->getBranchNum(i);
119 sectionBI = firstMCO->getBranchNum(i);
122 content.replace("<!-- INSERT PAGES -->", allPages);
124 // Write modified content
125 QFile f(contentFile);
126 if (!f.open(QIODevice::WriteOnly)) {
127 QMessageBox::critical(
128 0, QObject::tr("Critical Export Error"),
129 QObject::tr("Could not write %1").arg(contentFile));
130 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
139 // zip tmpdir to destination
140 zipDir(tmpDir, filePath);
142 displayedDestination = filePath;
144 result = ExportBase::Success;
149 completeExport(args);
152 bool ExportOO::setConfigFile(const QString &cf)
155 int i = cf.lastIndexOf("/");
157 configDir = cf.left(i);
160 if (!set.readSettings(configFile)) {
161 QMessageBox::critical(
162 0, QObject::tr("Critical Export Error"),
163 QObject::tr("Couldn't read settings from \"%1\"").arg(configFile));
168 templateDir = configDir + "/" + set.value("Template");
174 QMessageBox::critical(0, QObject::tr("Critical Export Error"),
175 QObject::tr("Check \"%1\" in\n%2")
176 .arg("Template=" + set.value("Template"))
181 contentTemplateFile = templateDir + "content-template.xml";
182 pageTemplateFile = templateDir + "page-template.xml";
183 sectionTemplateFile = templateDir + "section-template.xml";
184 contentFile = tmpDir.path() + "/content.xml";
186 if (set.value("useSections").contains("yes"))
189 // Copy template to tmpdir
190 copyDir(templateDir, tmpDir);
192 // Read content-template
193 if (!loadStringFromDisk(contentTemplateFile, content)) {
194 QMessageBox::critical(
195 0, QObject::tr("Critical Export Error"),
196 QObject::tr("Could not read %1").arg(contentTemplateFile));
200 // Read page-template
201 if (!loadStringFromDisk(pageTemplateFile, pageTemplate)) {
202 QMessageBox::critical(
203 0, QObject::tr("Critical Export Error"),
204 QObject::tr("Could not read %1").arg(pageTemplateFile));
208 // Read section-template
210 !loadStringFromDisk(sectionTemplateFile, sectionTemplate)) {
211 QMessageBox::critical(
212 0, QObject::tr("Critical Export Error"),
213 QObject::tr("Could not read %1").arg(sectionTemplateFile));