insilmaril@0
|
1 |
#include "exports.h"
|
insilmaril@57
|
2 |
#include "file.h"
|
insilmaril@57
|
3 |
#include "linkablemapobj.h"
|
insilmaril@57
|
4 |
#include "misc.h"
|
insilmaril@57
|
5 |
#include "mainwindow.h"
|
insilmaril@57
|
6 |
#include "warningdialog.h"
|
insilmaril@57
|
7 |
#include "xsltproc.h"
|
insilmaril@0
|
8 |
|
insilmaril@57
|
9 |
extern Main *mainWindow;
|
insilmaril@57
|
10 |
extern QDir vymBaseDir;
|
insilmaril@57
|
11 |
extern QString vymName;
|
insilmaril@0
|
12 |
|
insilmaril@57
|
13 |
ExportBase::ExportBase()
|
insilmaril@0
|
14 |
{
|
insilmaril@0
|
15 |
indentPerDepth=" ";
|
insilmaril@57
|
16 |
bool ok;
|
insilmaril@57
|
17 |
tmpDir.setPath (makeTmpDir(ok,"vym-export"));
|
insilmaril@57
|
18 |
if (!tmpDir.exists() || !ok)
|
insilmaril@57
|
19 |
QMessageBox::critical( 0, QObject::tr( "Error" ),
|
insilmaril@57
|
20 |
QObject::tr("Couldn't access temporary directory\n"));
|
insilmaril@57
|
21 |
cancelFlag=false;
|
insilmaril@0
|
22 |
}
|
insilmaril@0
|
23 |
|
insilmaril@57
|
24 |
ExportBase::~ExportBase()
|
insilmaril@0
|
25 |
{
|
insilmaril@57
|
26 |
// Cleanup tmpdir
|
insilmaril@57
|
27 |
removeDir (tmpDir);
|
insilmaril@0
|
28 |
}
|
insilmaril@0
|
29 |
|
insilmaril@57
|
30 |
void ExportBase::setDir(const QDir &d)
|
insilmaril@0
|
31 |
{
|
insilmaril@57
|
32 |
outDir=d;
|
insilmaril@0
|
33 |
}
|
insilmaril@0
|
34 |
|
insilmaril@57
|
35 |
void ExportBase::setFile (const QString &p)
|
insilmaril@0
|
36 |
{
|
insilmaril@57
|
37 |
outputFile=p;
|
insilmaril@0
|
38 |
}
|
insilmaril@0
|
39 |
|
insilmaril@57
|
40 |
QString ExportBase::getFile ()
|
insilmaril@0
|
41 |
{
|
insilmaril@57
|
42 |
return outputFile;
|
insilmaril@0
|
43 |
}
|
insilmaril@0
|
44 |
|
insilmaril@57
|
45 |
void ExportBase::setModel(VymModel *m)
|
insilmaril@0
|
46 |
{
|
insilmaril@57
|
47 |
model=m;
|
insilmaril@57
|
48 |
}
|
insilmaril@57
|
49 |
|
insilmaril@57
|
50 |
void ExportBase::setCaption (const QString &s)
|
insilmaril@57
|
51 |
{
|
insilmaril@57
|
52 |
caption=s;
|
insilmaril@57
|
53 |
}
|
insilmaril@57
|
54 |
|
insilmaril@57
|
55 |
void ExportBase::addFilter(const QString &s)
|
insilmaril@57
|
56 |
{
|
insilmaril@57
|
57 |
filter=s;
|
insilmaril@57
|
58 |
}
|
insilmaril@57
|
59 |
|
insilmaril@57
|
60 |
bool ExportBase::execDialog()
|
insilmaril@57
|
61 |
{
|
insilmaril@57
|
62 |
//MapEditor *me=model.getMapEditor(); FIXME needed?
|
insilmaril@57
|
63 |
// if (model->mapCenters.count() && me)
|
insilmaril@57
|
64 |
{
|
insilmaril@57
|
65 |
QFileDialog *fd=new QFileDialog( 0, caption);
|
insilmaril@57
|
66 |
fd->setFilter (filter);
|
insilmaril@57
|
67 |
fd->setCaption(caption);
|
insilmaril@57
|
68 |
fd->setMode( QFileDialog::AnyFile );
|
insilmaril@57
|
69 |
fd->setDir (outDir);
|
insilmaril@57
|
70 |
fd->show();
|
insilmaril@57
|
71 |
|
insilmaril@57
|
72 |
if ( fd->exec() == QDialog::Accepted )
|
insilmaril@57
|
73 |
{
|
insilmaril@57
|
74 |
if (QFile (fd->selectedFile()).exists() )
|
insilmaril@57
|
75 |
{
|
insilmaril@57
|
76 |
QMessageBox mb( vymName,
|
insilmaril@57
|
77 |
QObject::tr("The file %1 exists already.\nDo you want to overwrite it?").arg(fd->selectedFile()),
|
insilmaril@57
|
78 |
QMessageBox::Warning,
|
insilmaril@57
|
79 |
QMessageBox::Yes | QMessageBox::Default,
|
insilmaril@57
|
80 |
QMessageBox::Cancel | QMessageBox::Escape,
|
insilmaril@57
|
81 |
Qt::NoButton );
|
insilmaril@57
|
82 |
mb.setButtonText( QMessageBox::Yes, QObject::tr("Overwrite") );
|
insilmaril@57
|
83 |
mb.setButtonText( QMessageBox::No, QObject::tr("Cancel"));
|
insilmaril@57
|
84 |
ExportBase ex;
|
insilmaril@57
|
85 |
switch( mb.exec() )
|
insilmaril@57
|
86 |
{
|
insilmaril@57
|
87 |
case QMessageBox::Yes:
|
insilmaril@57
|
88 |
// save
|
insilmaril@57
|
89 |
break;;
|
insilmaril@57
|
90 |
case QMessageBox::Cancel:
|
insilmaril@57
|
91 |
cancelFlag=true;
|
insilmaril@57
|
92 |
return false;
|
insilmaril@57
|
93 |
break;
|
insilmaril@57
|
94 |
}
|
insilmaril@57
|
95 |
}
|
insilmaril@57
|
96 |
outputFile=fd->selectedFile();
|
insilmaril@57
|
97 |
cancelFlag=false;
|
insilmaril@57
|
98 |
return true;
|
insilmaril@57
|
99 |
}
|
insilmaril@57
|
100 |
}
|
insilmaril@57
|
101 |
return false;
|
insilmaril@57
|
102 |
}
|
insilmaril@57
|
103 |
|
insilmaril@57
|
104 |
bool ExportBase::canceled()
|
insilmaril@57
|
105 |
{
|
insilmaril@57
|
106 |
return cancelFlag;
|
insilmaril@57
|
107 |
}
|
insilmaril@57
|
108 |
|
insilmaril@57
|
109 |
QString ExportBase::getSectionString(BranchObj *bostart)
|
insilmaril@57
|
110 |
{
|
insilmaril@57
|
111 |
// Make prefix like "2.5.3" for "bo:2,bo:5,bo:3"
|
insilmaril@0
|
112 |
QString r;
|
insilmaril@0
|
113 |
BranchObj *bo=bostart;
|
insilmaril@0
|
114 |
int depth=bo->getDepth();
|
insilmaril@0
|
115 |
while (depth>0)
|
insilmaril@0
|
116 |
{
|
insilmaril@0
|
117 |
r=QString("%1").arg(1+bo->getNum(),0,10)+"." + r;
|
insilmaril@0
|
118 |
bo=(BranchObj*)(bo->getParObj());
|
insilmaril@0
|
119 |
depth=bo->getDepth();
|
insilmaril@0
|
120 |
}
|
insilmaril@0
|
121 |
if (r.isEmpty())
|
insilmaril@0
|
122 |
return r;
|
insilmaril@0
|
123 |
else
|
insilmaril@0
|
124 |
return r + " ";
|
insilmaril@0
|
125 |
}
|
insilmaril@0
|
126 |
|
insilmaril@57
|
127 |
////////////////////////////////////////////////////////////////////////
|
insilmaril@57
|
128 |
ExportASCII::ExportASCII()
|
insilmaril@0
|
129 |
{
|
insilmaril@57
|
130 |
filter="TXT (*.txt)";
|
insilmaril@57
|
131 |
caption=vymName+ " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
|
insilmaril@57
|
132 |
}
|
insilmaril@57
|
133 |
|
insilmaril@57
|
134 |
void ExportASCII::doExport()
|
insilmaril@57
|
135 |
{
|
insilmaril@57
|
136 |
QFile file (outputFile);
|
insilmaril@57
|
137 |
if ( !file.open( QIODevice::WriteOnly ) )
|
insilmaril@57
|
138 |
{
|
insilmaril@57
|
139 |
qWarning ("ExportBase::exportXML couldn't open "+outputFile);
|
insilmaril@57
|
140 |
return;
|
insilmaril@57
|
141 |
}
|
insilmaril@57
|
142 |
QTextStream ts( &file ); // use LANG decoding here...
|
insilmaril@57
|
143 |
|
insilmaril@0
|
144 |
// Main loop over all branches
|
insilmaril@0
|
145 |
QString s;
|
insilmaril@57
|
146 |
QString curIndent;
|
insilmaril@0
|
147 |
int i;
|
insilmaril@0
|
148 |
BranchObj *bo;
|
insilmaril@57
|
149 |
bo=model->first();
|
insilmaril@0
|
150 |
while (bo)
|
insilmaril@0
|
151 |
{
|
insilmaril@0
|
152 |
// Make indentstring
|
insilmaril@57
|
153 |
curIndent="";
|
insilmaril@57
|
154 |
for (i=0;i<bo->getDepth()-1;i++) curIndent+= indentPerDepth;
|
insilmaril@0
|
155 |
|
insilmaril@57
|
156 |
if (!bo->hasHiddenExportParent() )
|
insilmaril@0
|
157 |
{
|
insilmaril@57
|
158 |
switch (bo->getDepth())
|
insilmaril@57
|
159 |
{
|
insilmaril@57
|
160 |
case 0:
|
insilmaril@57
|
161 |
ts << underline (bo->getHeading(),QString("="));
|
insilmaril@57
|
162 |
ts << "\n";
|
insilmaril@57
|
163 |
break;
|
insilmaril@57
|
164 |
case 1:
|
insilmaril@57
|
165 |
ts << "\n";
|
insilmaril@57
|
166 |
ts << (underline (getSectionString(bo) + bo->getHeading(), QString("-") ) );
|
insilmaril@57
|
167 |
ts << "\n";
|
insilmaril@57
|
168 |
break;
|
insilmaril@57
|
169 |
case 2:
|
insilmaril@57
|
170 |
ts << "\n";
|
insilmaril@57
|
171 |
ts << (curIndent + "* " + bo->getHeading());
|
insilmaril@57
|
172 |
ts << "\n";
|
insilmaril@57
|
173 |
break;
|
insilmaril@57
|
174 |
case 3:
|
insilmaril@57
|
175 |
ts << (curIndent + "- " + bo->getHeading());
|
insilmaril@57
|
176 |
ts << "\n";
|
insilmaril@57
|
177 |
break;
|
insilmaril@57
|
178 |
default:
|
insilmaril@57
|
179 |
ts << (curIndent + "- " + bo->getHeading());
|
insilmaril@57
|
180 |
ts << "\n";
|
insilmaril@57
|
181 |
break;
|
insilmaril@57
|
182 |
}
|
insilmaril@57
|
183 |
|
insilmaril@57
|
184 |
// If necessary, write note
|
insilmaril@57
|
185 |
if (!bo->getNote().isEmpty())
|
insilmaril@57
|
186 |
{
|
insilmaril@57
|
187 |
curIndent +=" | ";
|
insilmaril@57
|
188 |
s=bo->getNoteASCII( curIndent, 80);
|
insilmaril@57
|
189 |
ts << s;
|
insilmaril@57
|
190 |
}
|
insilmaril@57
|
191 |
}
|
insilmaril@57
|
192 |
bo=model->next(bo);
|
insilmaril@57
|
193 |
}
|
insilmaril@57
|
194 |
file.close();
|
insilmaril@57
|
195 |
}
|
insilmaril@57
|
196 |
|
insilmaril@57
|
197 |
QString ExportASCII::underline (const QString &text, const QString &line)
|
insilmaril@57
|
198 |
{
|
insilmaril@57
|
199 |
QString r=text + "\n";
|
insilmaril@57
|
200 |
for (int j=0;j<text.length();j++) r+=line;
|
insilmaril@57
|
201 |
return r;
|
insilmaril@57
|
202 |
}
|
insilmaril@57
|
203 |
|
insilmaril@57
|
204 |
|
insilmaril@57
|
205 |
////////////////////////////////////////////////////////////////////////
|
insilmaril@57
|
206 |
void ExportCSV::doExport()
|
insilmaril@57
|
207 |
{
|
insilmaril@57
|
208 |
QFile file (outputFile);
|
insilmaril@57
|
209 |
if ( !file.open( QIODevice::WriteOnly ) )
|
insilmaril@57
|
210 |
{
|
insilmaril@57
|
211 |
qWarning ("ExportBase::exportXML couldn't open "+outputFile);
|
insilmaril@57
|
212 |
return;
|
insilmaril@57
|
213 |
}
|
insilmaril@57
|
214 |
QTextStream ts( &file ); // use LANG decoding here...
|
insilmaril@57
|
215 |
|
insilmaril@57
|
216 |
// Write header
|
insilmaril@57
|
217 |
ts << "\"Note\"" <<endl;
|
insilmaril@57
|
218 |
|
insilmaril@57
|
219 |
// Main loop over all branches
|
insilmaril@57
|
220 |
QString s;
|
insilmaril@57
|
221 |
QString curIndent("");
|
insilmaril@57
|
222 |
int i;
|
insilmaril@57
|
223 |
BranchObj *bo;
|
insilmaril@57
|
224 |
bo=model->first();
|
insilmaril@57
|
225 |
while (bo)
|
insilmaril@57
|
226 |
{
|
insilmaril@57
|
227 |
if (!bo->hasHiddenExportParent() )
|
insilmaril@57
|
228 |
{
|
insilmaril@57
|
229 |
// If necessary, write note
|
insilmaril@57
|
230 |
if (!bo->getNote().isEmpty())
|
insilmaril@57
|
231 |
{
|
insilmaril@57
|
232 |
s =bo->getNoteASCII();
|
insilmaril@57
|
233 |
s=s.replace ("\n","\n"+curIndent);
|
insilmaril@57
|
234 |
ts << ("\""+s+"\",");
|
insilmaril@57
|
235 |
} else
|
insilmaril@57
|
236 |
ts <<"\"\",";
|
insilmaril@57
|
237 |
|
insilmaril@57
|
238 |
// Make indentstring
|
insilmaril@57
|
239 |
for (i=0;i<bo->getDepth();i++) curIndent+= "\"\",";
|
insilmaril@57
|
240 |
|
insilmaril@57
|
241 |
// Write heading
|
insilmaril@57
|
242 |
ts << curIndent << "\"" << bo->getHeading()<<"\""<<endl;
|
insilmaril@0
|
243 |
}
|
insilmaril@0
|
244 |
|
insilmaril@57
|
245 |
bo=model->next(bo);
|
insilmaril@57
|
246 |
curIndent="";
|
insilmaril@57
|
247 |
}
|
insilmaril@57
|
248 |
file.close();
|
insilmaril@57
|
249 |
}
|
insilmaril@57
|
250 |
|
insilmaril@57
|
251 |
////////////////////////////////////////////////////////////////////////
|
insilmaril@62
|
252 |
void ExportKDE3Bookmarks::doExport()
|
insilmaril@57
|
253 |
{
|
insilmaril@57
|
254 |
MapEditor *me=model->getMapEditor();
|
insilmaril@57
|
255 |
if (me)
|
insilmaril@57
|
256 |
{
|
insilmaril@57
|
257 |
WarningDialog dia;
|
insilmaril@57
|
258 |
dia.showCancelButton (true);
|
insilmaril@57
|
259 |
dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
|
insilmaril@62
|
260 |
dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 3"));
|
insilmaril@57
|
261 |
dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
|
insilmaril@57
|
262 |
if (dia.exec()==QDialog::Accepted)
|
insilmaril@57
|
263 |
{
|
insilmaril@57
|
264 |
me->exportXML(tmpDir.path(),false);
|
insilmaril@57
|
265 |
|
insilmaril@57
|
266 |
XSLTProc p;
|
insilmaril@57
|
267 |
p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
|
insilmaril@57
|
268 |
p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
|
insilmaril@57
|
269 |
p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
|
insilmaril@57
|
270 |
p.process();
|
insilmaril@57
|
271 |
|
insilmaril@57
|
272 |
QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
|
insilmaril@57
|
273 |
QProcess *proc= new QProcess ;
|
insilmaril@57
|
274 |
proc->start( ub);
|
insilmaril@57
|
275 |
if (!proc->waitForStarted())
|
insilmaril@57
|
276 |
{
|
insilmaril@57
|
277 |
QMessageBox::warning(0,
|
insilmaril@57
|
278 |
QObject::tr("Warning"),
|
insilmaril@57
|
279 |
QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
|
insilmaril@57
|
280 |
}
|
insilmaril@57
|
281 |
}
|
insilmaril@57
|
282 |
}
|
insilmaril@62
|
283 |
}
|
insilmaril@62
|
284 |
|
insilmaril@62
|
285 |
////////////////////////////////////////////////////////////////////////
|
insilmaril@62
|
286 |
void ExportKDE4Bookmarks::doExport()
|
insilmaril@62
|
287 |
{
|
insilmaril@62
|
288 |
MapEditor *me=model->getMapEditor();
|
insilmaril@62
|
289 |
if (me)
|
insilmaril@62
|
290 |
{
|
insilmaril@62
|
291 |
WarningDialog dia;
|
insilmaril@62
|
292 |
dia.showCancelButton (true);
|
insilmaril@62
|
293 |
dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("KDE"));
|
insilmaril@62
|
294 |
dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("KDE 4"));
|
insilmaril@62
|
295 |
dia.setShowAgainName("/exports/KDE/overwriteKDEBookmarks");
|
insilmaril@62
|
296 |
if (dia.exec()==QDialog::Accepted)
|
insilmaril@62
|
297 |
{
|
insilmaril@62
|
298 |
me->exportXML(tmpDir.path(),false);
|
insilmaril@62
|
299 |
|
insilmaril@62
|
300 |
XSLTProc p;
|
insilmaril@62
|
301 |
p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
|
insilmaril@62
|
302 |
p.setOutputFile (tmpDir.home().path()+"/.kde4/share/apps/konqueror/bookmarks.xml");
|
insilmaril@62
|
303 |
p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
|
insilmaril@62
|
304 |
p.process();
|
insilmaril@62
|
305 |
|
insilmaril@62
|
306 |
QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
|
insilmaril@62
|
307 |
QProcess *proc= new QProcess ;
|
insilmaril@62
|
308 |
proc->start( ub);
|
insilmaril@62
|
309 |
if (!proc->waitForStarted())
|
insilmaril@62
|
310 |
{
|
insilmaril@62
|
311 |
QMessageBox::warning(0,
|
insilmaril@62
|
312 |
QObject::tr("Warning"),
|
insilmaril@62
|
313 |
QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
|
insilmaril@62
|
314 |
}
|
insilmaril@62
|
315 |
}
|
insilmaril@62
|
316 |
}
|
insilmaril@57
|
317 |
|
insilmaril@57
|
318 |
}
|
insilmaril@57
|
319 |
|
insilmaril@57
|
320 |
////////////////////////////////////////////////////////////////////////
|
insilmaril@57
|
321 |
void ExportFirefoxBookmarks::doExport()
|
insilmaril@57
|
322 |
{
|
insilmaril@57
|
323 |
MapEditor *me=model->getMapEditor();
|
insilmaril@57
|
324 |
if (me)
|
insilmaril@57
|
325 |
{
|
insilmaril@57
|
326 |
WarningDialog dia;
|
insilmaril@57
|
327 |
dia.showCancelButton (true);
|
insilmaril@57
|
328 |
dia.setText(QObject::tr("Exporting the %1 bookmarks will overwrite\nyour existing bookmarks file.").arg("Firefox"));
|
insilmaril@57
|
329 |
dia.setCaption(QObject::tr("Warning: Overwriting %1 bookmarks").arg("Firefox"));
|
insilmaril@57
|
330 |
dia.setShowAgainName("/vym/warnings/overwriteImportBookmarks");
|
insilmaril@57
|
331 |
if (dia.exec()==QDialog::Accepted)
|
insilmaril@57
|
332 |
{
|
insilmaril@57
|
333 |
me->exportXML(tmpDir.path(),false);
|
insilmaril@57
|
334 |
|
insilmaril@57
|
335 |
/*
|
insilmaril@57
|
336 |
XSLTProc p;
|
insilmaril@57
|
337 |
p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
|
insilmaril@57
|
338 |
p.setOutputFile (tmpDir.home().path()+"/.kde/share/apps/konqueror/bookmarks.xml");
|
insilmaril@57
|
339 |
p.setXSLFile (vymBaseDir.path()+"/styles/vym2kdebookmarks.xsl");
|
insilmaril@57
|
340 |
p.process();
|
insilmaril@57
|
341 |
|
insilmaril@57
|
342 |
QString ub=vymBaseDir.path()+"/scripts/update-bookmarks";
|
insilmaril@57
|
343 |
QProcess *proc = new QProcess( );
|
insilmaril@57
|
344 |
proc->addArgument(ub);
|
insilmaril@57
|
345 |
|
insilmaril@57
|
346 |
if ( !proc->start() )
|
insilmaril@57
|
347 |
{
|
insilmaril@57
|
348 |
QMessageBox::warning(0,
|
insilmaril@57
|
349 |
QObject::tr("Warning"),
|
insilmaril@57
|
350 |
QObject::tr("Couldn't find script %1\nto notifiy Browsers of changed bookmarks.").arg(ub));
|
insilmaril@57
|
351 |
}
|
insilmaril@57
|
352 |
|
insilmaril@57
|
353 |
*/
|
insilmaril@57
|
354 |
|
insilmaril@57
|
355 |
}
|
insilmaril@0
|
356 |
}
|
insilmaril@0
|
357 |
}
|
insilmaril@0
|
358 |
|
insilmaril@57
|
359 |
////////////////////////////////////////////////////////////////////////
|
insilmaril@57
|
360 |
void ExportTaskjuggler::doExport()
|
insilmaril@0
|
361 |
{
|
insilmaril@57
|
362 |
MapEditor *me=model->getMapEditor();
|
insilmaril@57
|
363 |
if (me)
|
insilmaril@57
|
364 |
{
|
insilmaril@57
|
365 |
me->exportXML(tmpDir.path(),false);
|
insilmaril@57
|
366 |
|
insilmaril@57
|
367 |
XSLTProc p;
|
insilmaril@57
|
368 |
p.setInputFile (tmpDir.path()+"/"+me->getMapName()+".xml");
|
insilmaril@57
|
369 |
p.setOutputFile (outputFile);
|
insilmaril@57
|
370 |
p.setXSLFile (vymBaseDir.path()+"/styles/vym2taskjuggler.xsl");
|
insilmaril@57
|
371 |
p.process();
|
insilmaril@57
|
372 |
}
|
insilmaril@57
|
373 |
|
insilmaril@0
|
374 |
}
|
insilmaril@0
|
375 |
|
insilmaril@57
|
376 |
////////////////////////////////////////////////////////////////////////
|
insilmaril@57
|
377 |
void ExportLaTeX::doExport()
|
insilmaril@57
|
378 |
{
|
insilmaril@57
|
379 |
// Exports a map to a LaTex file.
|
insilmaril@57
|
380 |
// This file needs to be included
|
insilmaril@57
|
381 |
// or inported into a LaTex document
|
insilmaril@57
|
382 |
// it will not add a preamble, or anything
|
insilmaril@57
|
383 |
// that makes a full LaTex document.
|
insilmaril@57
|
384 |
QFile file (outputFile);
|
insilmaril@57
|
385 |
if ( !file.open( QIODevice::WriteOnly ) ) {
|
insilmaril@57
|
386 |
QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(outputFile));
|
insilmaril@57
|
387 |
mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
|
insilmaril@57
|
388 |
return;
|
insilmaril@57
|
389 |
}
|
insilmaril@57
|
390 |
QTextStream ts( &file ); // use LANG decoding here...
|
insilmaril@57
|
391 |
ts.setEncoding (QTextStream::UnicodeUTF8); // Force UTF8
|
insilmaril@57
|
392 |
|
insilmaril@57
|
393 |
// Main loop over all branches
|
insilmaril@57
|
394 |
QString s;
|
insilmaril@57
|
395 |
// QString curIndent("");
|
insilmaril@57
|
396 |
// int i;
|
insilmaril@57
|
397 |
BranchObj *bo;
|
insilmaril@57
|
398 |
bo=model->first();
|
insilmaril@57
|
399 |
while (bo) {
|
insilmaril@57
|
400 |
if (!bo->hasHiddenExportParent() )
|
insilmaril@57
|
401 |
{
|
insilmaril@57
|
402 |
if (bo->getDepth()==0);
|
insilmaril@57
|
403 |
else if (bo->getDepth()==1) {
|
insilmaril@57
|
404 |
ts << ("\\chapter{" + bo->getHeading()+ "}\n");
|
insilmaril@57
|
405 |
}
|
insilmaril@57
|
406 |
else if (bo->getDepth()==2) {
|
insilmaril@57
|
407 |
ts << ("\\section{" + bo->getHeading()+ "}\n");
|
insilmaril@57
|
408 |
}
|
insilmaril@57
|
409 |
else if (bo->getDepth()==3) {
|
insilmaril@57
|
410 |
ts << ("\\subsection{" + bo->getHeading()+ "}\n");
|
insilmaril@57
|
411 |
}
|
insilmaril@57
|
412 |
else if (bo->getDepth()==4) {
|
insilmaril@57
|
413 |
ts << ("\\subsubsection{" + bo->getHeading()+ "}\n");
|
insilmaril@57
|
414 |
}
|
insilmaril@57
|
415 |
else {
|
insilmaril@57
|
416 |
ts << ("\\paragraph*{" + bo->getHeading()+ "}\n");
|
insilmaril@57
|
417 |
}
|
insilmaril@57
|
418 |
|
insilmaril@57
|
419 |
// If necessary, write note
|
insilmaril@57
|
420 |
if (!bo->getNote().isEmpty()) {
|
insilmaril@57
|
421 |
ts << (bo->getNoteASCII());
|
insilmaril@57
|
422 |
ts << ("\n");
|
insilmaril@57
|
423 |
}
|
insilmaril@57
|
424 |
}
|
insilmaril@57
|
425 |
bo=model->next(bo);
|
insilmaril@57
|
426 |
}
|
insilmaril@57
|
427 |
file.close();
|
insilmaril@57
|
428 |
}
|
insilmaril@57
|
429 |
|
insilmaril@57
|
430 |
////////////////////////////////////////////////////////////////////////
|
insilmaril@57
|
431 |
ExportOO::ExportOO()
|
insilmaril@57
|
432 |
{
|
insilmaril@57
|
433 |
useSections=false;
|
insilmaril@57
|
434 |
}
|
insilmaril@57
|
435 |
|
insilmaril@57
|
436 |
ExportOO::~ExportOO()
|
insilmaril@57
|
437 |
{
|
insilmaril@57
|
438 |
}
|
insilmaril@57
|
439 |
|
insilmaril@57
|
440 |
QString ExportOO::buildList (BranchObj *current)
|
insilmaril@57
|
441 |
{
|
insilmaril@57
|
442 |
QString r;
|
insilmaril@57
|
443 |
BranchObj *bo;
|
insilmaril@57
|
444 |
|
insilmaril@57
|
445 |
uint i=0;
|
insilmaril@57
|
446 |
bo=current->getFirstBranch();
|
insilmaril@57
|
447 |
if (bo)
|
insilmaril@57
|
448 |
{
|
insilmaril@57
|
449 |
if (!bo->hasHiddenExportParent() )
|
insilmaril@57
|
450 |
{
|
insilmaril@57
|
451 |
// Start list
|
insilmaril@57
|
452 |
r+="<text:list text:style-name=\"vym-list\">\n";
|
insilmaril@57
|
453 |
while (bo)
|
insilmaril@57
|
454 |
{
|
insilmaril@57
|
455 |
r+="<text:list-item><text:p >";
|
insilmaril@57
|
456 |
r+=quotemeta(bo->getHeading());
|
insilmaril@57
|
457 |
// If necessary, write note
|
insilmaril@57
|
458 |
if (!bo->getNote().isEmpty())
|
insilmaril@57
|
459 |
r+=bo->getNoteOpenDoc();
|
insilmaril@57
|
460 |
r+="</text:p>";
|
insilmaril@57
|
461 |
r+=buildList (bo); // recursivly add deeper branches
|
insilmaril@57
|
462 |
r+="</text:list-item>\n";
|
insilmaril@57
|
463 |
i++;
|
insilmaril@57
|
464 |
bo=current->getBranchNum(i);
|
insilmaril@57
|
465 |
}
|
insilmaril@57
|
466 |
r+="</text:list>\n";
|
insilmaril@57
|
467 |
}
|
insilmaril@57
|
468 |
}
|
insilmaril@57
|
469 |
return r;
|
insilmaril@57
|
470 |
}
|
insilmaril@57
|
471 |
|
insilmaril@57
|
472 |
|
insilmaril@57
|
473 |
void ExportOO::exportPresentation()
|
insilmaril@57
|
474 |
{
|
insilmaril@57
|
475 |
QString allPages;
|
insilmaril@57
|
476 |
|
insilmaril@57
|
477 |
MapCenterObj *firstMCO=(MapCenterObj*)model->first();
|
insilmaril@57
|
478 |
if (!firstMCO)
|
insilmaril@57
|
479 |
{
|
insilmaril@57
|
480 |
QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("No objects in map!"));
|
insilmaril@57
|
481 |
return;
|
insilmaril@57
|
482 |
}
|
insilmaril@57
|
483 |
|
insilmaril@57
|
484 |
// Insert new content
|
insilmaril@57
|
485 |
// FIXME add extra title in mapinfo for vym 1.13.x
|
insilmaril@57
|
486 |
content.replace ("<!-- INSERT TITLE -->",quotemeta(firstMCO->getHeading()));
|
insilmaril@57
|
487 |
content.replace ("<!-- INSERT AUTHOR -->",quotemeta(model->getAuthor()));
|
insilmaril@57
|
488 |
|
insilmaril@57
|
489 |
QString onePage;
|
insilmaril@57
|
490 |
QString list;
|
insilmaril@57
|
491 |
|
insilmaril@57
|
492 |
BranchObj *sectionBO;
|
insilmaril@57
|
493 |
int i=0;
|
insilmaril@57
|
494 |
BranchObj *pagesBO;
|
insilmaril@57
|
495 |
int j=0;
|
insilmaril@57
|
496 |
|
insilmaril@57
|
497 |
int mapcenters=model->countMapCenters();
|
insilmaril@57
|
498 |
|
insilmaril@57
|
499 |
// useSections already has been set in setConfigFile
|
insilmaril@57
|
500 |
if (mapcenters>1)
|
insilmaril@57
|
501 |
sectionBO=firstMCO;
|
insilmaril@57
|
502 |
else
|
insilmaril@57
|
503 |
sectionBO=firstMCO->getFirstBranch();
|
insilmaril@57
|
504 |
|
insilmaril@57
|
505 |
// Walk sections
|
insilmaril@57
|
506 |
while (sectionBO && !sectionBO->hasHiddenExportParent() )
|
insilmaril@57
|
507 |
{
|
insilmaril@57
|
508 |
if (useSections)
|
insilmaril@57
|
509 |
{
|
insilmaril@57
|
510 |
// Add page with section title
|
insilmaril@57
|
511 |
onePage=sectionTemplate;
|
insilmaril@57
|
512 |
onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta(sectionBO->getHeading() ) );
|
insilmaril@57
|
513 |
allPages+=onePage;
|
insilmaril@57
|
514 |
pagesBO=sectionBO->getFirstBranch();
|
insilmaril@57
|
515 |
} else
|
insilmaril@57
|
516 |
{
|
insilmaril@57
|
517 |
//i=-2; // only use inner loop to
|
insilmaril@57
|
518 |
// turn mainbranches into pages
|
insilmaril@57
|
519 |
//sectionBO=firstMCO;
|
insilmaril@57
|
520 |
pagesBO=sectionBO;
|
insilmaril@57
|
521 |
}
|
insilmaril@57
|
522 |
|
insilmaril@57
|
523 |
j=0;
|
insilmaril@57
|
524 |
while (pagesBO && !pagesBO->hasHiddenExportParent() )
|
insilmaril@57
|
525 |
{
|
insilmaril@57
|
526 |
// Add page with list of items
|
insilmaril@57
|
527 |
onePage=pageTemplate;
|
insilmaril@57
|
528 |
onePage.replace ("<!-- INSERT PAGE HEADING -->", quotemeta (pagesBO->getHeading() ) );
|
insilmaril@57
|
529 |
list=buildList (pagesBO);
|
insilmaril@57
|
530 |
onePage.replace ("<!-- INSERT LIST -->", list);
|
insilmaril@57
|
531 |
allPages+=onePage;
|
insilmaril@57
|
532 |
if (pagesBO!=sectionBO)
|
insilmaril@57
|
533 |
{
|
insilmaril@57
|
534 |
j++;
|
insilmaril@57
|
535 |
pagesBO=((BranchObj*)pagesBO->getParObj())->getBranchNum(j);
|
insilmaril@57
|
536 |
} else
|
insilmaril@57
|
537 |
pagesBO=NULL; // We are already iterating over the sectionBOs
|
insilmaril@57
|
538 |
}
|
insilmaril@57
|
539 |
i++;
|
insilmaril@57
|
540 |
if (mapcenters>1 )
|
insilmaril@57
|
541 |
sectionBO=model->getMapCenterNum (i);
|
insilmaril@57
|
542 |
else
|
insilmaril@57
|
543 |
sectionBO=firstMCO->getBranchNum (i);
|
insilmaril@57
|
544 |
}
|
insilmaril@57
|
545 |
|
insilmaril@57
|
546 |
content.replace ("<!-- INSERT PAGES -->",allPages);
|
insilmaril@57
|
547 |
|
insilmaril@57
|
548 |
// Write modified content
|
insilmaril@57
|
549 |
QFile f (contentFile);
|
insilmaril@57
|
550 |
if ( !f.open( QIODevice::WriteOnly ) )
|
insilmaril@57
|
551 |
{
|
insilmaril@57
|
552 |
QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not write %1").arg(contentFile));
|
insilmaril@57
|
553 |
mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
|
insilmaril@57
|
554 |
return;
|
insilmaril@57
|
555 |
}
|
insilmaril@57
|
556 |
|
insilmaril@57
|
557 |
QTextStream t( &f );
|
insilmaril@57
|
558 |
t << content;
|
insilmaril@57
|
559 |
f.close();
|
insilmaril@57
|
560 |
|
insilmaril@57
|
561 |
// zip tmpdir to destination
|
insilmaril@57
|
562 |
zipDir (tmpDir,outputFile);
|
insilmaril@57
|
563 |
}
|
insilmaril@57
|
564 |
|
insilmaril@57
|
565 |
bool ExportOO::setConfigFile (const QString &cf)
|
insilmaril@57
|
566 |
{
|
insilmaril@57
|
567 |
configFile=cf;
|
insilmaril@57
|
568 |
int i=cf.findRev ("/");
|
insilmaril@57
|
569 |
if (i>=0) configDir=cf.left(i);
|
insilmaril@57
|
570 |
SimpleSettings set;
|
insilmaril@57
|
571 |
set.readSettings(configFile);
|
insilmaril@57
|
572 |
|
insilmaril@57
|
573 |
// set paths
|
insilmaril@57
|
574 |
templateDir=configDir+"/"+set.readEntry ("Template");
|
insilmaril@57
|
575 |
|
insilmaril@57
|
576 |
QDir d (templateDir);
|
insilmaril@57
|
577 |
if (!d.exists())
|
insilmaril@57
|
578 |
{
|
insilmaril@57
|
579 |
QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Check \"%1\" in\n%2").arg("Template="+set.readEntry ("Template")).arg(configFile));
|
insilmaril@57
|
580 |
return false;
|
insilmaril@57
|
581 |
|
insilmaril@57
|
582 |
}
|
insilmaril@57
|
583 |
|
insilmaril@57
|
584 |
contentTemplateFile=templateDir+"content-template.xml";
|
insilmaril@57
|
585 |
contentFile=tmpDir.path()+"/content.xml";
|
insilmaril@57
|
586 |
pageTemplateFile=templateDir+"page-template.xml";
|
insilmaril@57
|
587 |
sectionTemplateFile=templateDir+"section-template.xml";
|
insilmaril@57
|
588 |
|
insilmaril@57
|
589 |
if (model->countMapCenters()>1 ||set.readEntry("useSections").contains("yes"))
|
insilmaril@57
|
590 |
useSections=true;
|
insilmaril@57
|
591 |
|
insilmaril@57
|
592 |
// Copy template to tmpdir
|
insilmaril@57
|
593 |
system ("cp -r "+templateDir+"* "+tmpDir.path());
|
insilmaril@57
|
594 |
|
insilmaril@57
|
595 |
// Read content-template
|
insilmaril@57
|
596 |
if (!loadStringFromDisk (contentTemplateFile,content))
|
insilmaril@57
|
597 |
{
|
insilmaril@57
|
598 |
QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(contentTemplateFile));
|
insilmaril@57
|
599 |
return false;
|
insilmaril@57
|
600 |
}
|
insilmaril@57
|
601 |
|
insilmaril@57
|
602 |
// Read page-template
|
insilmaril@57
|
603 |
if (!loadStringFromDisk (pageTemplateFile,pageTemplate))
|
insilmaril@57
|
604 |
{
|
insilmaril@57
|
605 |
QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(pageTemplateFile));
|
insilmaril@57
|
606 |
return false;
|
insilmaril@57
|
607 |
}
|
insilmaril@57
|
608 |
|
insilmaril@57
|
609 |
// Read section-template
|
insilmaril@57
|
610 |
if (useSections && !loadStringFromDisk (sectionTemplateFile,sectionTemplate))
|
insilmaril@57
|
611 |
{
|
insilmaril@57
|
612 |
QMessageBox::critical (0,QObject::tr("Critical Export Error"),QObject::tr("Could not read %1").arg(sectionTemplateFile));
|
insilmaril@57
|
613 |
return false;
|
insilmaril@57
|
614 |
}
|
insilmaril@57
|
615 |
return true;
|
insilmaril@57
|
616 |
}
|
insilmaril@57
|
617 |
|