1.1 --- a/mainwindow.cpp Tue Jan 03 09:44:41 2006 +0000
1.2 +++ b/mainwindow.cpp Tue Jan 24 15:09:49 2006 +0000
1.3 @@ -23,6 +23,7 @@
1.4 #include "misc.h"
1.5 #include "version.h"
1.6 #include "aboutdialog.h"
1.7 +#include "exportoofiledialog.h"
1.8
1.9 #include "icons/filenew.xpm"
1.10 #include "icons/fileopen.xpm"
1.11 @@ -289,8 +290,8 @@
1.12 settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() );
1.13 settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() );
1.14
1.15 - settings.writeEntry( "/vym/version/version", __VYM_VERSION__ );
1.16 - settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ );
1.17 + settings.writeEntry( "/vym/version/version", __VYM_VERSION );
1.18 + settings.writeEntry( "/vym/version/builddate", __BUILD_DATE );
1.19
1.20 settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() );
1.21 settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() );
1.22 @@ -405,7 +406,7 @@
1.23 connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) );
1.24 a->addTo( menu );
1.25
1.26 - a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" );
1.27 + a = new QAction( tr( "Exit")+" "+__VYM, QPixmap(), tr( "E&xit")+" "+__VYM, CTRL + Key_Q, this, "fileExitVYM" );
1.28 connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) );
1.29 a->addTo( menu );
1.30 }
1.31 @@ -1057,7 +1058,7 @@
1.32 connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) );
1.33 a->addTo( menu );
1.34
1.35 - a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" );
1.36 + a = new QAction( tr( "Information about")+" "__VYM, QPixmap(), tr( "About VYM" ), 0, this, "about" );
1.37 connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) );
1.38 a->addTo( menu );
1.39
1.40 @@ -1161,36 +1162,32 @@
1.41 floatimageContextMenu->insertSeparator();
1.42 actionFormatHideLinkUnselected->addTo( floatimageContextMenu );
1.43
1.44 - // Context menu for exports
1.45 - exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu);
1.46 + a = new QAction( tr( "Export as Open Office 2.0 (Open Document) " ), QPixmap(), "Open Office"+QString("..."), 0, this, "exportOOPresentation" );
1.47 + connect( a, SIGNAL( activated() ), this, SLOT( fileExportOOPresentation() ) );
1.48 + a->addTo (exportMenu);
1.49
1.50 - a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" +QString("...")), 0, this, "exportASCII" );
1.51 + exportMenu->insertItem ( tr("Image"),exportImageFormatMenu);
1.52 +
1.53 + a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), "ASCII...", 0, this, "exportASCII" );
1.54 connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) );
1.55 a->addTo( exportMenu );
1.56
1.57 - a = new QAction( tr( "Export as LaTeX (still experimental)" ), QPixmap(), tr( "Export (LaTeX)" +QString("...")), 0, this, "exportLaTeX" );
1.58 + a = new QAction( tr( "Export as LaTeX (still experimental)" ), QPixmap(), "LaTeX...", 0, this, "exportLaTeX" );
1.59 connect( a, SIGNAL( activated() ), this, SLOT( fileExportLaTeX() ) );
1.60 a->addTo( exportMenu );
1.61
1.62 - if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
1.63 - {
1.64 - a = new QAction( tr( "Export as Open Office 1.3.x Presentation (still experimental)" ), QPixmap(), tr( "Export (OO Presentation)" +QString("...")), 0, this, "exportOOPresentation" );
1.65 - connect( a, SIGNAL( activated() ), this, SLOT( fileExportOOPresentation() ) );
1.66 - a->addTo( exportMenu );
1.67 - }
1.68 -
1.69 - a = new QAction( tr( "Export (XML)" ), QPixmap(), tr( "Export (XML)" )+QString("..."), 0, this, "exportXML" );
1.70 + a = new QAction( tr( "Export (XML)" ), QPixmap(), "XML...", 0, this, "exportXML" );
1.71 connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) );
1.72 a->addTo( exportMenu );
1.73
1.74 if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false))
1.75 {
1.76 - a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export (HTML)" )+QString("..."), 0, this, "exportHTML");
1.77 + a = new QAction( tr( "Export HTML" ), QPixmap(), "HTML...", 0, this, "exportHTML");
1.78 connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) );
1.79 a->addTo( exportMenu );
1.80 }
1.81
1.82 - a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" )+QString("..."), ALT + Key_X, this, "exportXHTML" );
1.83 + a = new QAction( tr( "Export XHTML" ), QPixmap(), "XHTML...", ALT + Key_X, this, "exportXHTML" );
1.84 connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) );
1.85 a->addTo( exportMenu );
1.86
1.87 @@ -1265,7 +1262,7 @@
1.88 if (eList.first() =="..") eList.pop_front(); // remove "."
1.89 if (!eList.isEmpty())
1.90 {
1.91 - QMessageBox mb( "VYM",
1.92 + QMessageBox mb( __VYM,
1.93 tr("The directory %1 is not empty.\nDo you risk to overwrite its contents?").arg(dir),
1.94 QMessageBox::Warning,
1.95 QMessageBox::Yes ,
1.96 @@ -1291,7 +1288,7 @@
1.97 {
1.98 QFileDialog fd(this,caption);
1.99 fd.setMode (QFileDialog::DirectoryOnly);
1.100 - fd.setCaption("VYM - "+caption);
1.101 + fd.setCaption(__VYM " - "+caption);
1.102 fd.show();
1.103
1.104 if ( fd.exec() == QDialog::Accepted )
1.105 @@ -1349,8 +1346,6 @@
1.106
1.107 void Main::fileLoad(QString fn, const LoadMode &lmode)
1.108 {
1.109 - // Error codes
1.110 - enum errorCode {success,aborted};
1.111 errorCode err=success;
1.112
1.113 // fn is usually the archive, mapfile the file after uncompressing
1.114 @@ -1371,7 +1366,7 @@
1.115 if (me->getFilePath() == fn)
1.116 {
1.117 // Already there, ask for confirmation
1.118 - QMessageBox mb( "VYM",
1.119 + QMessageBox mb( __VYM,
1.120 tr("The map %1\nis already opened."
1.121 "Opening the same map in multiple editors may lead \n"
1.122 "to confusion when finishing working with vym."
1.123 @@ -1419,7 +1414,7 @@
1.124 // from command line
1.125 if (!QFile(fn).exists() )
1.126 {
1.127 - QMessageBox mb( "VYM",
1.128 + QMessageBox mb( __VYM,
1.129 tr("This map does not exist:\n %1\nDo you want to create a new one?").arg(fn),
1.130 QMessageBox::Question,
1.131 QMessageBox::Yes ,
1.132 @@ -1456,109 +1451,72 @@
1.133 QString tmpMapDir=mkdtemp(tmpdir1);
1.134
1.135 // Try to unzip file
1.136 - Process *zipProc=new Process ();
1.137 - zipProc->clearArguments();
1.138 - zipProc->setWorkingDirectory (QDir(tmpMapDir));
1.139 - zipProc->addArgument ("unzip");
1.140 - zipProc->addArgument (fn );
1.141 - zipProc->addArgument ("-d");
1.142 - zipProc->addArgument (tmpMapDir);
1.143 -
1.144 - if (!zipProc->start() )
1.145 + err=unzipDir (tmpMapDir,fn);
1.146 + if (err==nozip)
1.147 {
1.148 - QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.149 - tr("Couldn't start unzip to decompress data."));
1.150 - err=aborted;
1.151 -
1.152 + mapfile=fn;
1.153 + me->setZipped(false);
1.154 } else
1.155 {
1.156 - zipProc->waitFinished();
1.157 - if (!zipProc->normalExit() )
1.158 + me->setZipped(true);
1.159 +
1.160 + // Look for mapname.xml
1.161 + mapfile= fn.left(fn.findRev(".",-1,true));
1.162 + mapfile=mapfile.section( '/', -1 );
1.163 + QFile file( tmpMapDir + "/" + mapfile + ".xml");
1.164 + if (!file.exists() )
1.165 {
1.166 - QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.167 - tr("unzip didn't exit normally") +
1.168 - zipProc->getErrout() );
1.169 - err=aborted;
1.170 - } else
1.171 - {
1.172 - if (zipProc->exitStatus()>0)
1.173 + // mapname.xml does not exist, well,
1.174 + // maybe some renamed the mapname.vym file...
1.175 + // Try to find any .xml in the toplevel
1.176 + // directory of the .vym file
1.177 + QStringList flist=QDir (tmpMapDir).entryList("*.xml");
1.178 + if (flist.count()==1)
1.179 {
1.180 - if (zipProc->exitStatus()==9)
1.181 - {
1.182 - // no zipped file, but maybe .xml or old version? Try again.
1.183 - mapfile=fn;
1.184 - me->setZipped(false);
1.185 - }
1.186 - else
1.187 - {
1.188 - QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.189 - QString("unzip exit code: %1").arg(zipProc->exitStatus() ) +
1.190 - zipProc->getErrout() );
1.191 - err=aborted;
1.192 - }
1.193 + // Only one entry, take this one
1.194 + mapfile=tmpMapDir + "/"+flist.first();
1.195 } else
1.196 - { // Uncompressing was successfull,
1.197 - // load from uncompressed temporary directory
1.198 -
1.199 - me->setZipped(true);
1.200 -
1.201 + {
1.202 + for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1.203 + *it=tmpMapDir + "/" + *it;
1.204 + // TODO Multiple entries, load all (but only the first one into this ME)
1.205 + //mainWindow->fileLoadFromTmp (flist);
1.206 + //returnCode=1; // Silently forget this attempt to load
1.207 + qWarning ("MainWindow::load (fn) multimap found...");
1.208 + }
1.209
1.210 - // Look for mapname.xml
1.211 - mapfile= fn.left(fn.findRev(".",-1,true));
1.212 - mapfile=mapfile.section( '/', -1 );
1.213 - QFile file( tmpMapDir + "/" + mapfile + ".xml");
1.214 - if (!file.exists() )
1.215 - {
1.216 - // mapname.xml does not exist, well,
1.217 - // maybe some renamed the mapname.vym file...
1.218 - // Try to find any .xml in the toplevel
1.219 - // directory of the .vym file
1.220 - QStringList flist=QDir (tmpMapDir).entryList("*.xml");
1.221 - if (flist.count()==1)
1.222 - {
1.223 - // Only one entry, take this one
1.224 - mapfile=tmpMapDir + "/"+flist.first();
1.225 - } else
1.226 - {
1.227 - for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it )
1.228 - *it=tmpMapDir + "/" + *it;
1.229 - // TODO Multiple entries, load all (but only the first one into this ME)
1.230 - //mainWindow->fileLoadFromTmp (flist);
1.231 - //returnCode=1; // Silently forget this attempt to load
1.232 - qWarning ("MainWindow::load (fn) multimap found...");
1.233 - }
1.234 -
1.235 - if (flist.isEmpty() )
1.236 - {
1.237 - QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.238 - tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1.239 - err=aborted;
1.240 - }
1.241 - } //file doesn't exist
1.242 - else
1.243 - mapfile=file.name();
1.244 - } // Uncompressing successfull
1.245 - }
1.246 + if (flist.isEmpty() )
1.247 + {
1.248 + QMessageBox::critical( 0, tr( "Critical Load Error" ),
1.249 + tr("Couldn't find a map (*.xml) in .vym archive.\n"));
1.250 + err=aborted;
1.251 + }
1.252 + } //file doesn't exist
1.253 + else
1.254 + mapfile=file.name();
1.255 }
1.256
1.257 + if (err!=aborted)
1.258 + {
1.259 + // Save existing filename in case we import
1.260 + QString fn_org=me->getFilePath();
1.261
1.262 - // Save existing filename
1.263 - QString fn_org=me->getFilePath();
1.264 + // Finally load map into mapEditor
1.265 + me->setFilePath (mapfile,fn);
1.266 + if (me->load(mapfile,lmode))
1.267 + err=aborted;
1.268
1.269 - // Finally load map into mapEditor
1.270 - me->setFilePath (mapfile,fn);
1.271 - if (me->load(mapfile,lmode))
1.272 - err=aborted;
1.273 + // Restore old (maybe empty) filepath, if this is an import
1.274 + if (lmode!=NewMap)
1.275 + me->setFilePath (fn_org);
1.276 + }
1.277
1.278 - // Restore old (maybe empty) filepath, if this is an import
1.279 - if (lmode!=NewMap)
1.280 - me->setFilePath (fn_org);
1.281 -
1.282 - // Delete tmpDir
1.283 - removeDir (QDir(tmpMapDir));
1.284 -
1.285 - // Check for errors
1.286 - if (err==success)
1.287 + // Finally check for errors and go home
1.288 + if (err==aborted)
1.289 + {
1.290 + if (lmode==NewMap) fileCloseMap();
1.291 + statusBar()->message( "Could not load " + fn, statusbarTime );
1.292 + } else
1.293 {
1.294 if (lmode==NewMap)
1.295 {
1.296 @@ -1569,16 +1527,11 @@
1.297 actionFilePrint->setEnabled (true);
1.298 }
1.299 statusBar()->message( "Loaded " + fn, statusbarTime );
1.300 - return;
1.301 - } else
1.302 - {
1.303 - if (lmode==NewMap)
1.304 - fileCloseMap();
1.305 }
1.306
1.307 -
1.308 + // Delete tmpDir
1.309 + removeDir (QDir(tmpMapDir));
1.310 }
1.311 - statusBar()->message( "Could not load " + fn, statusbarTime );
1.312 }
1.313
1.314
1.315 @@ -1587,6 +1540,7 @@
1.316 QFileDialog *fd=new QFileDialog( this);
1.317 if (!lastFileDir.isEmpty())
1.318 fd->setDir (lastFileDir);
1.319 + fd->setMode (QFileDialog::ExistingFiles);
1.320 fd->addFilter ("XML (*.xml)");
1.321 fd->addFilter ("VYM map (*.vym *.vyp)");
1.322 switch (lmode)
1.323 @@ -1607,9 +1561,16 @@
1.324 if ( fd->exec() == QDialog::Accepted )
1.325 {
1.326 lastFileDir=fd->dirPath();
1.327 - fn = fd->selectedFile();
1.328 - fileLoad(fn, lmode);
1.329 + QStringList flist = fd->selectedFiles();
1.330 + QStringList::Iterator it = flist.begin();
1.331 + while( it != flist.end() )
1.332 + {
1.333 + fn = *it;
1.334 + fileLoad(*it, lmode);
1.335 + ++it;
1.336 + }
1.337 }
1.338 + delete (fd);
1.339 }
1.340
1.341 void Main::fileLoad()
1.342 @@ -1654,7 +1615,7 @@
1.343 // Look, if we should zip the data:
1.344 if (!saveZipped)
1.345 {
1.346 - QMessageBox mb( "VYM",
1.347 + QMessageBox mb( __VYM,
1.348 tr("The map %1\ndid not use the compressed "
1.349 "vym file format.\nWriting it uncompressed will also write images \n"
1.350 "and flags and thus may overwrite files in the "
1.351 @@ -1755,7 +1716,7 @@
1.352 // Check for existing file
1.353 if (QFile (fn).exists())
1.354 {
1.355 - QMessageBox mb( "VYM",
1.356 + QMessageBox mb( __VYM,
1.357 tr("The file %1\nexists already. Do you want to").arg(fn),
1.358 QMessageBox::Warning,
1.359 QMessageBox::Yes | QMessageBox::Default,
1.360 @@ -1904,8 +1865,23 @@
1.361
1.362 void Main::fileExportOOPresentation()
1.363 {
1.364 - if (currentMapEditor())
1.365 - currentMapEditor()->exportOOPresentation();
1.366 + ExportOOFileDialog *fd=new ExportOOFileDialog( this,__VYM " - "+tr("Export to Open Office"));
1.367 + // FIXME add extra info in dialog
1.368 + //ImagePreview *p =new ImagePreview (fd);
1.369 + //fd->setContentsPreviewEnabled( TRUE );
1.370 + //fd->setContentsPreview( p, p );
1.371 + //fd->setPreviewMode( QFileDialog::Contents );
1.372 + fd->setCaption(__VYM " - " +tr("Export to Open Office"));
1.373 + //fd->setDir (lastImageDir);
1.374 + fd->show();
1.375 +
1.376 + if ( fd->exec() == QDialog::Accepted )
1.377 + {
1.378 + QString fn=fd->selectedFile();
1.379 + //lastImageDir=fn.left(fn.findRev ("/"));
1.380 + if (currentMapEditor())
1.381 + currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig());
1.382 + }
1.383 }
1.384
1.385 void Main::fileCloseMap()
1.386 @@ -1914,7 +1890,7 @@
1.387 {
1.388 if (currentMapEditor()->hasChanged())
1.389 {
1.390 - QMessageBox mb( "VYM",
1.391 + QMessageBox mb( __VYM,
1.392 tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()),
1.393 QMessageBox::Warning,
1.394 QMessageBox::Yes | QMessageBox::Default,
1.395 @@ -1963,7 +1939,7 @@
1.396 if (me->isUnsaved())
1.397 {
1.398 tabWidget->setCurrentPage(i);
1.399 - QMessageBox mb( "VYM",
1.400 + QMessageBox mb( __VYM,
1.401 tr("This map is not saved yet. Do you want to"),
1.402 QMessageBox::Warning,
1.403 QMessageBox::Yes | QMessageBox::Default,
1.404 @@ -2525,8 +2501,8 @@
1.405
1.406 void Main::testFunction()
1.407 {
1.408 - //textEditor->stackUnder(this);
1.409 - currentMapEditor()->testFunction();
1.410 + fileExportOOPresentation();
1.411 +// currentMapEditor()->testFunction();
1.412 }
1.413
1.414 void Main::helpDoc()