diff -r 138c2cdc02fd -r 6691000c3262 mainwindow.cpp --- a/mainwindow.cpp Tue Jan 24 15:09:48 2006 +0000 +++ b/mainwindow.cpp Tue Jan 24 15:09:48 2006 +0000 @@ -23,6 +23,7 @@ #include "misc.h" #include "version.h" #include "aboutdialog.h" +#include "exportoofiledialog.h" #include "icons/filenew.xpm" #include "icons/fileopen.xpm" @@ -289,8 +290,8 @@ settings.writeEntry( "/vym/mainwindow/geometry/posX", pos().x() ); settings.writeEntry( "/vym/mainwindow/geometry/posY", pos().y() ); - settings.writeEntry( "/vym/version/version", __VYM_VERSION__ ); - settings.writeEntry( "/vym/version/builddate", __BUILD_DATE__ ); + settings.writeEntry( "/vym/version/version", __VYM_VERSION ); + settings.writeEntry( "/vym/version/builddate", __BUILD_DATE ); settings.writeEntry( "/vym/mapeditor/editmode/autoselectheading",actionSettingsAutoselectHeading->isOn() ); settings.writeEntry( "/vym/mapeditor/editmode/autoselecttext",actionSettingsAutoselectText->isOn() ); @@ -405,7 +406,7 @@ connect( a, SIGNAL( activated() ), this, SLOT( fileCloseMap() ) ); a->addTo( menu ); - a = new QAction( tr( "Exit VYM" ), QPixmap(), tr( "E&xit VYM" ), CTRL + Key_Q, this, "fileExitVYM" ); + a = new QAction( tr( "Exit")+" "+__VYM, QPixmap(), tr( "E&xit")+" "+__VYM, CTRL + Key_Q, this, "fileExitVYM" ); connect( a, SIGNAL( activated() ), this, SLOT( fileExitVYM() ) ); a->addTo( menu ); } @@ -1057,7 +1058,7 @@ connect( a, SIGNAL( activated() ), this, SLOT( helpDoc() ) ); a->addTo( menu ); - a = new QAction( tr( "Information about VYM" ), QPixmap(), tr( "About VYM" ), 0, this, "about" ); + a = new QAction( tr( "Information about")+" "__VYM, QPixmap(), tr( "About VYM" ), 0, this, "about" ); connect( a, SIGNAL( activated() ), this, SLOT( helpAbout() ) ); a->addTo( menu ); @@ -1161,36 +1162,32 @@ floatimageContextMenu->insertSeparator(); actionFormatHideLinkUnselected->addTo( floatimageContextMenu ); - // Context menu for exports - exportMenu->insertItem ( tr("Export map as image"),exportImageFormatMenu); + a = new QAction( tr( "Export as Open Office 2.0 (Open Document) " ), QPixmap(), "Open Office"+QString("..."), 0, this, "exportOOPresentation" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileExportOOPresentation() ) ); + a->addTo (exportMenu); - a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), tr( "Export (ASCII)" +QString("...")), 0, this, "exportASCII" ); + exportMenu->insertItem ( tr("Image"),exportImageFormatMenu); + + a = new QAction( tr( "Export as ASCII (still experimental)" ), QPixmap(), "ASCII...", 0, this, "exportASCII" ); connect( a, SIGNAL( activated() ), this, SLOT( fileExportASCII() ) ); a->addTo( exportMenu ); - a = new QAction( tr( "Export as LaTeX (still experimental)" ), QPixmap(), tr( "Export (LaTeX)" +QString("...")), 0, this, "exportLaTeX" ); + a = new QAction( tr( "Export as LaTeX (still experimental)" ), QPixmap(), "LaTeX...", 0, this, "exportLaTeX" ); connect( a, SIGNAL( activated() ), this, SLOT( fileExportLaTeX() ) ); a->addTo( exportMenu ); - if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) - { - a = new QAction( tr( "Export as Open Office 1.3.x Presentation (still experimental)" ), QPixmap(), tr( "Export (OO Presentation)" +QString("...")), 0, this, "exportOOPresentation" ); - connect( a, SIGNAL( activated() ), this, SLOT( fileExportOOPresentation() ) ); - a->addTo( exportMenu ); - } - - a = new QAction( tr( "Export (XML)" ), QPixmap(), tr( "Export (XML)" )+QString("..."), 0, this, "exportXML" ); + a = new QAction( tr( "Export (XML)" ), QPixmap(), "XML...", 0, this, "exportXML" ); connect( a, SIGNAL( activated() ), this, SLOT( fileExportXML() ) ); a->addTo( exportMenu ); if (settings.readBoolEntry( "/vym/mainwindow/showTestMenu",false)) { - a = new QAction( tr( "Export HTML" ), QPixmap(), tr( "Export (HTML)" )+QString("..."), 0, this, "exportHTML"); + a = new QAction( tr( "Export HTML" ), QPixmap(), "HTML...", 0, this, "exportHTML"); connect( a, SIGNAL( activated() ), this, SLOT( fileExportHTML() ) ); a->addTo( exportMenu ); } - a = new QAction( tr( "Export XHTML" ), QPixmap(), tr( "Export XHTML" )+QString("..."), ALT + Key_X, this, "exportXHTML" ); + a = new QAction( tr( "Export XHTML" ), QPixmap(), "XHTML...", ALT + Key_X, this, "exportXHTML" ); connect( a, SIGNAL( activated() ), this, SLOT( fileExportXHTML() ) ); a->addTo( exportMenu ); @@ -1265,7 +1262,7 @@ if (eList.first() =="..") eList.pop_front(); // remove "." if (!eList.isEmpty()) { - QMessageBox mb( "VYM", + QMessageBox mb( __VYM, tr("The directory %1 is not empty.\nDo you risk to overwrite its contents?").arg(dir), QMessageBox::Warning, QMessageBox::Yes , @@ -1291,7 +1288,7 @@ { QFileDialog fd(this,caption); fd.setMode (QFileDialog::DirectoryOnly); - fd.setCaption("VYM - "+caption); + fd.setCaption(__VYM " - "+caption); fd.show(); if ( fd.exec() == QDialog::Accepted ) @@ -1349,8 +1346,6 @@ void Main::fileLoad(QString fn, const LoadMode &lmode) { - // Error codes - enum errorCode {success,aborted}; errorCode err=success; // fn is usually the archive, mapfile the file after uncompressing @@ -1371,7 +1366,7 @@ if (me->getFilePath() == fn) { // Already there, ask for confirmation - QMessageBox mb( "VYM", + QMessageBox mb( __VYM, tr("The map %1\nis already opened." "Opening the same map in multiple editors may lead \n" "to confusion when finishing working with vym." @@ -1419,7 +1414,7 @@ // from command line if (!QFile(fn).exists() ) { - QMessageBox mb( "VYM", + QMessageBox mb( __VYM, tr("This map does not exist:\n %1\nDo you want to create a new one?").arg(fn), QMessageBox::Question, QMessageBox::Yes , @@ -1456,109 +1451,72 @@ QString tmpMapDir=mkdtemp(tmpdir1); // Try to unzip file - Process *zipProc=new Process (); - zipProc->clearArguments(); - zipProc->setWorkingDirectory (QDir(tmpMapDir)); - zipProc->addArgument ("unzip"); - zipProc->addArgument (fn ); - zipProc->addArgument ("-d"); - zipProc->addArgument (tmpMapDir); - - if (!zipProc->start() ) + err=unzipDir (tmpMapDir,fn); + if (err==nozip) { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't start unzip to decompress data.")); - err=aborted; - + mapfile=fn; + me->setZipped(false); } else { - zipProc->waitFinished(); - if (!zipProc->normalExit() ) + me->setZipped(true); + + // Look for mapname.xml + mapfile= fn.left(fn.findRev(".",-1,true)); + mapfile=mapfile.section( '/', -1 ); + QFile file( tmpMapDir + "/" + mapfile + ".xml"); + if (!file.exists() ) { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("unzip didn't exit normally") + - zipProc->getErrout() ); - err=aborted; - } else - { - if (zipProc->exitStatus()>0) + // mapname.xml does not exist, well, + // maybe some renamed the mapname.vym file... + // Try to find any .xml in the toplevel + // directory of the .vym file + QStringList flist=QDir (tmpMapDir).entryList("*.xml"); + if (flist.count()==1) { - if (zipProc->exitStatus()==9) - { - // no zipped file, but maybe .xml or old version? Try again. - mapfile=fn; - me->setZipped(false); - } - else - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - QString("unzip exit code: %1").arg(zipProc->exitStatus() ) + - zipProc->getErrout() ); - err=aborted; - } + // Only one entry, take this one + mapfile=tmpMapDir + "/"+flist.first(); } else - { // Uncompressing was successfull, - // load from uncompressed temporary directory - - me->setZipped(true); - + { + for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) + *it=tmpMapDir + "/" + *it; + // TODO Multiple entries, load all (but only the first one into this ME) + //mainWindow->fileLoadFromTmp (flist); + //returnCode=1; // Silently forget this attempt to load + qWarning ("MainWindow::load (fn) multimap found..."); + } - // Look for mapname.xml - mapfile= fn.left(fn.findRev(".",-1,true)); - mapfile=mapfile.section( '/', -1 ); - QFile file( tmpMapDir + "/" + mapfile + ".xml"); - if (!file.exists() ) - { - // mapname.xml does not exist, well, - // maybe some renamed the mapname.vym file... - // Try to find any .xml in the toplevel - // directory of the .vym file - QStringList flist=QDir (tmpMapDir).entryList("*.xml"); - if (flist.count()==1) - { - // Only one entry, take this one - mapfile=tmpMapDir + "/"+flist.first(); - } else - { - for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) - *it=tmpMapDir + "/" + *it; - // TODO Multiple entries, load all (but only the first one into this ME) - //mainWindow->fileLoadFromTmp (flist); - //returnCode=1; // Silently forget this attempt to load - qWarning ("MainWindow::load (fn) multimap found..."); - } - - if (flist.isEmpty() ) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't find a map (*.xml) in .vym archive.\n")); - err=aborted; - } - } //file doesn't exist - else - mapfile=file.name(); - } // Uncompressing successfull - } + if (flist.isEmpty() ) + { + QMessageBox::critical( 0, tr( "Critical Load Error" ), + tr("Couldn't find a map (*.xml) in .vym archive.\n")); + err=aborted; + } + } //file doesn't exist + else + mapfile=file.name(); } + if (err!=aborted) + { + // Save existing filename in case we import + QString fn_org=me->getFilePath(); - // Save existing filename - QString fn_org=me->getFilePath(); + // Finally load map into mapEditor + me->setFilePath (mapfile,fn); + if (me->load(mapfile,lmode)) + err=aborted; - // Finally load map into mapEditor - me->setFilePath (mapfile,fn); - if (me->load(mapfile,lmode)) - err=aborted; + // Restore old (maybe empty) filepath, if this is an import + if (lmode!=NewMap) + me->setFilePath (fn_org); + } - // Restore old (maybe empty) filepath, if this is an import - if (lmode!=NewMap) - me->setFilePath (fn_org); - - // Delete tmpDir - removeDir (QDir(tmpMapDir)); - - // Check for errors - if (err==success) + // Finally check for errors and go home + if (err==aborted) + { + if (lmode==NewMap) fileCloseMap(); + statusBar()->message( "Could not load " + fn, statusbarTime ); + } else { if (lmode==NewMap) { @@ -1569,16 +1527,11 @@ actionFilePrint->setEnabled (true); } statusBar()->message( "Loaded " + fn, statusbarTime ); - return; - } else - { - if (lmode==NewMap) - fileCloseMap(); } - + // Delete tmpDir + removeDir (QDir(tmpMapDir)); } - statusBar()->message( "Could not load " + fn, statusbarTime ); } @@ -1587,6 +1540,7 @@ QFileDialog *fd=new QFileDialog( this); if (!lastFileDir.isEmpty()) fd->setDir (lastFileDir); + fd->setMode (QFileDialog::ExistingFiles); fd->addFilter ("XML (*.xml)"); fd->addFilter ("VYM map (*.vym *.vyp)"); switch (lmode) @@ -1607,9 +1561,16 @@ if ( fd->exec() == QDialog::Accepted ) { lastFileDir=fd->dirPath(); - fn = fd->selectedFile(); - fileLoad(fn, lmode); + QStringList flist = fd->selectedFiles(); + QStringList::Iterator it = flist.begin(); + while( it != flist.end() ) + { + fn = *it; + fileLoad(*it, lmode); + ++it; + } } + delete (fd); } void Main::fileLoad() @@ -1654,7 +1615,7 @@ // Look, if we should zip the data: if (!saveZipped) { - QMessageBox mb( "VYM", + QMessageBox mb( __VYM, tr("The map %1\ndid not use the compressed " "vym file format.\nWriting it uncompressed will also write images \n" "and flags and thus may overwrite files in the " @@ -1755,7 +1716,7 @@ // Check for existing file if (QFile (fn).exists()) { - QMessageBox mb( "VYM", + QMessageBox mb( __VYM, tr("The file %1\nexists already. Do you want to").arg(fn), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, @@ -1904,8 +1865,23 @@ void Main::fileExportOOPresentation() { - if (currentMapEditor()) - currentMapEditor()->exportOOPresentation(); + ExportOOFileDialog *fd=new ExportOOFileDialog( this,__VYM " - "+tr("Export to Open Office")); + // FIXME add extra info in dialog + //ImagePreview *p =new ImagePreview (fd); + //fd->setContentsPreviewEnabled( TRUE ); + //fd->setContentsPreview( p, p ); + //fd->setPreviewMode( QFileDialog::Contents ); + fd->setCaption(__VYM " - " +tr("Export to Open Office")); + //fd->setDir (lastImageDir); + fd->show(); + + if ( fd->exec() == QDialog::Accepted ) + { + QString fn=fd->selectedFile(); + //lastImageDir=fn.left(fn.findRev ("/")); + if (currentMapEditor()) + currentMapEditor()->exportOOPresentation(fn,fd->selectedConfig()); + } } void Main::fileCloseMap() @@ -1914,7 +1890,7 @@ { if (currentMapEditor()->hasChanged()) { - QMessageBox mb( "VYM", + QMessageBox mb( __VYM, tr("The map %1 has been modified but not saved yet. Do you want to").arg(currentMapEditor()->getFileName()), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, @@ -1963,7 +1939,7 @@ if (me->isUnsaved()) { tabWidget->setCurrentPage(i); - QMessageBox mb( "VYM", + QMessageBox mb( __VYM, tr("This map is not saved yet. Do you want to"), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, @@ -2525,8 +2501,8 @@ void Main::testFunction() { - //textEditor->stackUnder(this); - currentMapEditor()->testFunction(); + fileExportOOPresentation(); +// currentMapEditor()->testFunction(); } void Main::helpDoc()