insilmaril@0
|
1 |
#include "exports.h"
|
insilmaril@171
|
2 |
#include "file.h"
|
insilmaril@171
|
3 |
#include "linkablemapobj.h"
|
insilmaril@171
|
4 |
#include "misc.h"
|
insilmaril@171
|
5 |
#include "texteditor.h"
|
insilmaril@171
|
6 |
#include "mainwindow.h"
|
insilmaril@0
|
7 |
|
insilmaril@171
|
8 |
extern Main *mainWindow;
|
insilmaril@131
|
9 |
|
insilmaril@171
|
10 |
ExportBase::ExportBase()
|
insilmaril@0
|
11 |
{
|
insilmaril@0
|
12 |
indentPerDepth=" ";
|
insilmaril@0
|
13 |
}
|
insilmaril@0
|
14 |
|
insilmaril@171
|
15 |
void ExportBase::setPath (const QString &p)
|
insilmaril@0
|
16 |
{
|
insilmaril@0
|
17 |
filepath=p;
|
insilmaril@0
|
18 |
}
|
insilmaril@0
|
19 |
|
insilmaril@171
|
20 |
void ExportBase::setMapCenter(MapCenterObj *mc)
|
insilmaril@0
|
21 |
{
|
insilmaril@0
|
22 |
mapCenter=mc;
|
insilmaril@0
|
23 |
}
|
insilmaril@0
|
24 |
|
insilmaril@171
|
25 |
QString ExportBase::getSectionString(BranchObj *bostart)
|
insilmaril@163
|
26 |
{
|
insilmaril@163
|
27 |
QString r;
|
insilmaril@163
|
28 |
BranchObj *bo=bostart;
|
insilmaril@163
|
29 |
int depth=bo->getDepth();
|
insilmaril@163
|
30 |
while (depth>0)
|
insilmaril@163
|
31 |
{
|
insilmaril@163
|
32 |
r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
|
insilmaril@163
|
33 |
bo=(BranchObj*)(bo->getParObj());
|
insilmaril@163
|
34 |
depth=bo->getDepth();
|
insilmaril@163
|
35 |
}
|
insilmaril@163
|
36 |
if (r.isEmpty())
|
insilmaril@163
|
37 |
return r;
|
insilmaril@163
|
38 |
else
|
insilmaril@163
|
39 |
return r + " ";
|
insilmaril@163
|
40 |
}
|
insilmaril@163
|
41 |
|
insilmaril@171
|
42 |
void ExportBase::exportXML()
|
insilmaril@0
|
43 |
{
|
insilmaril@0
|
44 |
QFile file (filepath);
|
insilmaril@0
|
45 |
if ( !file.open( IO_WriteOnly ) )
|
insilmaril@0
|
46 |
{
|
insilmaril@131
|
47 |
// FIXME experimental, testing
|
insilmaril@171
|
48 |
cout << "ExportBase::exportXML couldn't open "<<filepath<<endl;
|
insilmaril@0
|
49 |
return;
|
insilmaril@0
|
50 |
}
|
insilmaril@0
|
51 |
QTextStream ts( &file ); // use LANG decoding here...
|
insilmaril@0
|
52 |
|
insilmaril@0
|
53 |
// Main loop over all branches
|
insilmaril@0
|
54 |
QString s;
|
insilmaril@0
|
55 |
QString actIndent("");
|
insilmaril@160
|
56 |
int i;
|
insilmaril@160
|
57 |
uint j;
|
insilmaril@0
|
58 |
BranchObj *bo;
|
insilmaril@0
|
59 |
bo=mapCenter->first();
|
insilmaril@0
|
60 |
while (bo)
|
insilmaril@0
|
61 |
{
|
insilmaril@0
|
62 |
// Make indentstring
|
insilmaril@0
|
63 |
for (i=0;i<bo->getDepth();i++) actIndent+= indentPerDepth;
|
insilmaril@0
|
64 |
|
insilmaril@0
|
65 |
// Write heading
|
insilmaril@0
|
66 |
// write (actIndent + getSectionString(bo) + bo->getHeading()+ "\n");
|
insilmaril@131
|
67 |
if (bo->getDepth()==0)
|
insilmaril@131
|
68 |
{
|
insilmaril@131
|
69 |
ts << (bo->getHeading()+ "\n");
|
insilmaril@160
|
70 |
for (j=0;j<bo->getHeading().length();j++) ts<<"=";
|
insilmaril@131
|
71 |
ts << "\n";
|
insilmaril@131
|
72 |
} else if (bo->getDepth()==1)
|
insilmaril@131
|
73 |
ts << ("\n"+getSectionString(bo) + bo->getHeading()+ "\n");
|
insilmaril@131
|
74 |
else if (bo->getDepth()==2)
|
insilmaril@131
|
75 |
ts << (actIndent + " o " + bo->getHeading()+ "\n");
|
insilmaril@0
|
76 |
else
|
insilmaril@0
|
77 |
ts << (actIndent + " - " + bo->getHeading()+ "\n");
|
insilmaril@0
|
78 |
|
insilmaril@0
|
79 |
// If necessary, write note
|
insilmaril@0
|
80 |
if (!bo->getNote().isEmpty())
|
insilmaril@0
|
81 |
{
|
insilmaril@131
|
82 |
s =textConvertToASCII(bo->getNote());
|
insilmaril@131
|
83 |
s=s.replace ("\n","\n"+actIndent);
|
insilmaril@131
|
84 |
ts << (s+"\n\n");
|
insilmaril@0
|
85 |
}
|
insilmaril@0
|
86 |
|
insilmaril@0
|
87 |
bo=bo->next();
|
insilmaril@0
|
88 |
actIndent="";
|
insilmaril@0
|
89 |
}
|
insilmaril@0
|
90 |
file.close();
|
insilmaril@0
|
91 |
}
|
insilmaril@0
|
92 |
|
insilmaril@163
|
93 |
// Exports a map to a LaTex file. This file needs to be included or inported into a LaTex document
|
insilmaril@163
|
94 |
// it will not add a preamble, or anything that makes a full LaTex document.
|
insilmaril@171
|
95 |
void ExportLaTeX::exportLaTeX()
|
insilmaril@0
|
96 |
{
|
insilmaril@163
|
97 |
QFile file (filepath);
|
insilmaril@163
|
98 |
if ( !file.open( IO_WriteOnly ) ) {
|
insilmaril@163
|
99 |
// FIXME
|
insilmaril@163
|
100 |
cout << "Export::exportMap couldn't open "<<filepath<<endl;
|
insilmaril@163
|
101 |
return;
|
insilmaril@163
|
102 |
}
|
insilmaril@163
|
103 |
QTextStream ts( &file ); // use LANG decoding here...
|
insilmaril@163
|
104 |
ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
|
insilmaril@163
|
105 |
|
insilmaril@163
|
106 |
// Main loop over all branches
|
insilmaril@163
|
107 |
QString s;
|
insilmaril@163
|
108 |
// QString actIndent("");
|
insilmaril@163
|
109 |
// int i;
|
insilmaril@163
|
110 |
BranchObj *bo;
|
insilmaril@163
|
111 |
bo=mapCenter->first();
|
insilmaril@163
|
112 |
while (bo) {
|
insilmaril@163
|
113 |
if (bo->getDepth()==0);
|
insilmaril@163
|
114 |
else if (bo->getDepth()==1) {
|
insilmaril@163
|
115 |
ts << ("\\chapter{" + bo->getHeading()+ "}\n");
|
insilmaril@163
|
116 |
}
|
insilmaril@163
|
117 |
else if (bo->getDepth()==2) {
|
insilmaril@163
|
118 |
ts << ("\\section{" + bo->getHeading()+ "}\n");
|
insilmaril@163
|
119 |
}
|
insilmaril@163
|
120 |
else if (bo->getDepth()==3) {
|
insilmaril@163
|
121 |
ts << ("\\subsection{" + bo->getHeading()+ "}\n");
|
insilmaril@163
|
122 |
}
|
insilmaril@163
|
123 |
else if (bo->getDepth()==4) {
|
insilmaril@163
|
124 |
ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
|
insilmaril@163
|
125 |
}
|
insilmaril@163
|
126 |
else {
|
insilmaril@163
|
127 |
ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
|
insilmaril@163
|
128 |
}
|
insilmaril@163
|
129 |
|
insilmaril@163
|
130 |
// If necessary, write note
|
insilmaril@163
|
131 |
if (!bo->getNote().isEmpty()) {
|
insilmaril@163
|
132 |
ts << (textConvertToASCII(bo->getNote()));
|
insilmaril@163
|
133 |
ts << ("\n");
|
insilmaril@163
|
134 |
}
|
insilmaril@163
|
135 |
|
insilmaril@163
|
136 |
bo=bo->next();
|
insilmaril@163
|
137 |
}
|
insilmaril@163
|
138 |
file.close();
|
insilmaril@0
|
139 |
}
|
insilmaril@0
|
140 |
|
insilmaril@171
|
141 |
ExportOO::ExportOO()
|
insilmaril@171
|
142 |
{
|
insilmaril@171
|
143 |
// Create tmpdir and set paths
|
insilmaril@171
|
144 |
tmpDir.setPath (makeUniqueDir("/tmp/vym-XXXXXX"));
|
insilmaril@171
|
145 |
templateDir="oo-test/suse-template/";
|
insilmaril@171
|
146 |
contentTemplateFile=templateDir+"content-template.xml";
|
insilmaril@171
|
147 |
contentFile=tmpDir.path()+"/content.xml";
|
insilmaril@171
|
148 |
pageTemplateFile=templateDir+"page-template.xml";
|
insilmaril@171
|
149 |
chapterTemplateFile=templateDir+"chapter-template.xml";
|
insilmaril@163
|
150 |
|
insilmaril@171
|
151 |
outputFile=tmpDir.currentDirPath()+"/out.odp";
|
insilmaril@171
|
152 |
|
insilmaril@163
|
153 |
// Copy template to tmpdir
|
insilmaril@171
|
154 |
system ("cp -r "+templateDir+"* "+tmpDir.path());
|
insilmaril@171
|
155 |
|
insilmaril@163
|
156 |
|
insilmaril@163
|
157 |
// Read content-template
|
insilmaril@171
|
158 |
if (!loadStringFromDisk (contentTemplateFile,content))
|
insilmaril@163
|
159 |
{
|
insilmaril@171
|
160 |
qWarning ("Export::exportOOPresentation() Couldn't load from "+contentTemplateFile);
|
insilmaril@163
|
161 |
return;
|
insilmaril@163
|
162 |
}
|
insilmaril@163
|
163 |
|
insilmaril@171
|
164 |
// Read page-template
|
insilmaril@171
|
165 |
QString pageTemplate;
|
insilmaril@171
|
166 |
if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
|
insilmaril@171
|
167 |
{
|
insilmaril@171
|
168 |
qWarning ("Export::exportOOPresentation() Couldn't load from "+pageTemplateFile);
|
insilmaril@171
|
169 |
return;
|
insilmaril@171
|
170 |
}
|
insilmaril@171
|
171 |
|
insilmaril@171
|
172 |
// Read chapter-template
|
insilmaril@171
|
173 |
QString chapterTemplate;
|
insilmaril@171
|
174 |
if (!loadStringFromDisk (chapterTemplateFile,chapterTemplate))
|
insilmaril@171
|
175 |
{
|
insilmaril@171
|
176 |
qWarning ("Export::exportOOPresentation() Couldn't load from "+chapterTemplateFile);
|
insilmaril@171
|
177 |
return;
|
insilmaril@171
|
178 |
}
|
insilmaril@171
|
179 |
}
|
insilmaril@163
|
180 |
|
insilmaril@171
|
181 |
ExportOO::~ExportOO()
|
insilmaril@171
|
182 |
{
|
insilmaril@171
|
183 |
// Remove tmpdir
|
insilmaril@171
|
184 |
//FIXME removeDir (tmpDir);
|
insilmaril@171
|
185 |
cout << "tmpDir="<<tmpDir.path()<<endl;
|
insilmaril@171
|
186 |
}
|
insilmaril@163
|
187 |
|
insilmaril@171
|
188 |
QString ExportOO::buildList (BranchObj *current)
|
insilmaril@171
|
189 |
{
|
insilmaril@171
|
190 |
QString r;
|
insilmaril@171
|
191 |
BranchObj *bo;
|
insilmaril@171
|
192 |
int i=0;
|
insilmaril@171
|
193 |
bo=current->getFirstBranch();
|
insilmaril@171
|
194 |
if (bo)
|
insilmaril@171
|
195 |
{
|
insilmaril@171
|
196 |
// Start list
|
insilmaril@171
|
197 |
r+="<text:list>\n";
|
insilmaril@171
|
198 |
while (bo)
|
insilmaril@171
|
199 |
{
|
insilmaril@171
|
200 |
r+="<text:list-item><text:p text:style-name=\"P7\">\n "+
|
insilmaril@171
|
201 |
bo->getHeading()+
|
insilmaril@171
|
202 |
"\n</text:p></text:list-item>\n";
|
insilmaril@171
|
203 |
}
|
insilmaril@171
|
204 |
r+="</text:list>\n";
|
insilmaril@171
|
205 |
}
|
insilmaril@171
|
206 |
return r;
|
insilmaril@171
|
207 |
}
|
insilmaril@163
|
208 |
|
insilmaril@171
|
209 |
QString ExportOO::walkPages (BranchObj *current)
|
insilmaril@171
|
210 |
{
|
insilmaril@171
|
211 |
//FIXME Denkfehler: mit current anfangen, nicht mit
|
insilmaril@171
|
212 |
// Kind von current. Sonst erwisch ich nur jede 2. Depth
|
insilmaril@171
|
213 |
//
|
insilmaril@171
|
214 |
|
insilmaril@171
|
215 |
|
insilmaril@171
|
216 |
QString r;
|
insilmaril@171
|
217 |
BranchObj *bo;
|
insilmaril@171
|
218 |
int i=0;
|
insilmaril@171
|
219 |
bo=current->getFirstBranch();
|
insilmaril@171
|
220 |
while(bo)
|
insilmaril@171
|
221 |
{
|
insilmaril@171
|
222 |
r+=quotemeta(bo->getHeading())+"\n";
|
insilmaril@171
|
223 |
if (bo->getFirstBranch())
|
insilmaril@171
|
224 |
r+=walkPages (bo->getFirstBranch());
|
insilmaril@171
|
225 |
i++;
|
insilmaril@171
|
226 |
bo=current->getBranchNum (i);
|
insilmaril@171
|
227 |
}
|
insilmaril@171
|
228 |
return r;
|
insilmaril@171
|
229 |
}
|
insilmaril@171
|
230 |
|
insilmaril@171
|
231 |
|
insilmaril@171
|
232 |
void ExportOO::exportPresentation()
|
insilmaril@171
|
233 |
{
|
insilmaril@171
|
234 |
QString allPages=walkPages (mapCenter);
|
insilmaril@171
|
235 |
|
insilmaril@171
|
236 |
cout << allPages<<endl;
|
insilmaril@163
|
237 |
|
insilmaril@163
|
238 |
// Insert new content
|
insilmaril@171
|
239 |
content.replace ("<!-- INSERT TITLE -->",quotemeta(mapCenter->getHeading()));
|
insilmaril@171
|
240 |
content.replace ("<!-- INSERT AUTHOR -->",quotemeta(mapCenter->getAuthor()));
|
insilmaril@171
|
241 |
content.replace ("<!-- INSERT PAGES -->",allPages);
|
insilmaril@171
|
242 |
|
insilmaril@171
|
243 |
// Write modified content
|
insilmaril@171
|
244 |
QFile f (contentFile);
|
insilmaril@171
|
245 |
if ( !f.open( IO_WriteOnly ) )
|
insilmaril@171
|
246 |
{
|
insilmaril@171
|
247 |
mainWindow->statusMessage(QString(QObject::tr("Could not write to %1")).arg(outputFile));
|
insilmaril@171
|
248 |
return;
|
insilmaril@171
|
249 |
}
|
insilmaril@171
|
250 |
|
insilmaril@171
|
251 |
QTextStream t( &f );
|
insilmaril@171
|
252 |
t << content;
|
insilmaril@171
|
253 |
f.close();
|
insilmaril@171
|
254 |
|
insilmaril@171
|
255 |
mainWindow->statusMessage( QString( QObject::tr("Map exported as %1")).arg( outputFile));
|
insilmaril@171
|
256 |
|
insilmaril@163
|
257 |
|
insilmaril@163
|
258 |
// zip tmpdir to destination
|
insilmaril@171
|
259 |
zipDir (tmpDir,outputFile);
|
insilmaril@163
|
260 |
|
insilmaril@171
|
261 |
/* FIXME not needed
|
insilmaril@171
|
262 |
QString onePage;
|
insilmaril@171
|
263 |
QString allPages;
|
insilmaril@171
|
264 |
QString heading;
|
insilmaril@171
|
265 |
|
insilmaril@171
|
266 |
|
insilmaril@171
|
267 |
// Walk through chapters (mainbranches)
|
insilmaril@171
|
268 |
QString s;
|
insilmaril@171
|
269 |
|
insilmaril@171
|
270 |
QString list;
|
insilmaril@171
|
271 |
BranchObj *bo;
|
insilmaril@171
|
272 |
BranchObj *boLastPage=NULL;
|
insilmaril@171
|
273 |
bo=mapCenter->first();
|
insilmaril@171
|
274 |
int depth;
|
insilmaril@171
|
275 |
int lastDepth=-1;
|
insilmaril@171
|
276 |
int basePageDepth=2;
|
insilmaril@171
|
277 |
while (bo)
|
insilmaril@171
|
278 |
{
|
insilmaril@171
|
279 |
depth=bo->getDepth();
|
insilmaril@171
|
280 |
heading=quotemeta(bo->getHeading());
|
insilmaril@171
|
281 |
if (depth>1)
|
insilmaril@171
|
282 |
{
|
insilmaril@171
|
283 |
if (depth==basePageDepth)
|
insilmaril@171
|
284 |
{
|
insilmaril@171
|
285 |
// Start a new page containing a heading and a list
|
insilmaril@171
|
286 |
if (boLastPage==NULL)
|
insilmaril@171
|
287 |
{
|
insilmaril@171
|
288 |
// Start new single page
|
insilmaril@171
|
289 |
boLastPage=bo;
|
insilmaril@171
|
290 |
onePage=pageTemplate;
|
insilmaril@171
|
291 |
onePage.replace ("<!-- INSERT PAGE HEADING -->", heading);
|
insilmaril@171
|
292 |
list="";
|
insilmaril@171
|
293 |
} else
|
insilmaril@171
|
294 |
{
|
insilmaril@171
|
295 |
// Finish last page, start new one
|
insilmaril@171
|
296 |
onePage.replace ("<!-- INSERT LIST -->", list);
|
insilmaril@171
|
297 |
boLastPage=bo;
|
insilmaril@171
|
298 |
allPages+=onePage;
|
insilmaril@171
|
299 |
onePage=pageTemplate;
|
insilmaril@171
|
300 |
onePage.replace ("<!-- INSERT PAGE HEADING -->", heading);
|
insilmaril@171
|
301 |
list="";
|
insilmaril@171
|
302 |
}
|
insilmaril@171
|
303 |
} else
|
insilmaril@171
|
304 |
{
|
insilmaril@171
|
305 |
if (lastDepth==depth-1)
|
insilmaril@171
|
306 |
// entering deeper branches, new list
|
insilmaril@171
|
307 |
list+="<text:list>";
|
insilmaril@171
|
308 |
// Just add heading to list on current page
|
insilmaril@171
|
309 |
list+="<text:list-item><text:p text:style-name=\"P7\">"+heading+"</text:p></text:list-item>\n";
|
insilmaril@171
|
310 |
if (lastDepth==depth+1)
|
insilmaril@171
|
311 |
// returning from deeper branches, finish list
|
insilmaril@171
|
312 |
list+="</text:list>";
|
insilmaril@171
|
313 |
}
|
insilmaril@171
|
314 |
}
|
insilmaril@171
|
315 |
lastDepth=depth;
|
insilmaril@171
|
316 |
bo=bo->next();
|
insilmaril@171
|
317 |
}
|
insilmaril@171
|
318 |
*/
|
insilmaril@163
|
319 |
}
|
insilmaril@163
|
320 |
|