Menu

[c54480]: / export-impress.cpp  Maximize  Restore  History

Download this file

213 lines (177 with data), 6.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#include <QMessageBox>
#include "mainwindow.h"
#include "export-impress.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+="<text:list text:style-name=\"vym-list\">\n";
while (bi)
{
if (!bi->hasHiddenExportParent() )
{
r += "<text:list-item><text:p >";
r += quotemeta(bi->getHeadingPlain());
// If necessary, write note
if (! bi->isNoteEmpty())
r += "<text:line-break/>" + bi->getNoteASCII();
r += "</text:p>";
r += buildList (bi); // recursivly add deeper branches
r += "</text:list-item>\n";
}
i++;
bi = current->getBranchNum(i);
}
r += "</text:list>\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 ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeadingPlain()));
content.replace ("<!-- INSERT AUTHOR -->",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 ("<!-- INSERT PAGE HEADING -->", 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 ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBI->getHeadingPlain() ) );
list=buildList (pagesBI);
onePage.replace ("<!-- INSERT LIST -->", 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 ("<!-- INSERT PAGES -->",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);
destination = filePath;
success = true;
QMap <QString, QString> args;
args["filePath"] = filePath;
args["configFile"] = 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");
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;
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.