# HG changeset patch # User insilmaril # Date 1185788829 0 # Node ID bc9083a4a7fbdf841c59fee962d7934103f586be # Parent ab83f030285ea63e9c0368806d7d3c7967597713 1.9.4 New base class for XML based file parsing (vym & Freemind) diff -r ab83f030285e -r bc9083a4a7fb mainwindow.cpp --- a/mainwindow.cpp Mon Jul 30 09:47:08 2007 +0000 +++ b/mainwindow.cpp Mon Jul 30 09:47:09 2007 +0000 @@ -310,6 +310,11 @@ connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFirefoxBookmarks() ) ); } + a = new QAction("Freemind...",this); + a->setStatusTip ( tr( "Import %1","status tip file menu").arg(" Freemind") ); + fileImportMenu->addAction (a); + connect( a, SIGNAL( triggered() ), this, SLOT( fileImportFreemind() ) ); + a = new QAction("Mind Manager...",this); a->setStatusTip ( tr( "Import %1","status tip file menu").arg(" Mind Manager") ); fileImportMenu->addAction (a); @@ -1817,13 +1822,13 @@ newME->setSmoothPixmap(actionViewToggleSmoothPixmapTransform->isOn()); // For the very first map we do not have flagrows yet... newME->select("mc:"); - newME->load (clipboardDir+"/"+clipboardFile,ImportReplace); + newME->load (clipboardDir+"/"+clipboardFile,ImportReplace, VymMap); } } } -ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode) +ErrorCode Main::fileLoad(QString fn, const LoadMode &lmode, const FileType &ftype) { ErrorCode err=success; @@ -1990,7 +1995,7 @@ // Finally load map into mapEditor me->setFilePath (mapfile,fn); - err=me->load(mapfile,lmode); + err=me->load(mapfile,lmode,ftype); // Restore old (maybe empty) filepath, if this is an import if (lmode!=NewMap) @@ -2311,7 +2316,7 @@ { im.setFile (*it); if (im.transform() && - success==fileLoad (im.getTransformedFile(),NewMap) && + success==fileLoad (im.getTransformedFile(),NewMap,FreemindMap) && currentMapEditor() ) currentMapEditor()->setFilePath (""); ++it; @@ -2320,6 +2325,37 @@ delete (fd); } +void Main::fileImportFreemind() +{ + QStringList filters; + filters <<"Freemind map (*.mm)"<<"All files (*)"; + QFileDialog *fd=new QFileDialog( this); + fd->setDir (lastFileDir); + fd->setFileMode (QFileDialog::ExistingFiles); + fd->setFilters (filters); + fd->setCaption(vymName+ " - " +tr("Load Freemind map")); + fd->show(); + + QString fn; + if ( fd->exec() == QDialog::Accepted ) + { + lastFileDir=fd->directory().path(); + QStringList flist = fd->selectedFiles(); + QStringList::Iterator it = flist.begin(); + while( it != flist.end() ) + { + fn = *it; + if ( fileLoad (fn,NewMap, FreemindMap) ) + { + currentMapEditor()->setFilePath (""); + } + ++it; + } + } + delete (fd); +} + + void Main::fileImportMM() { ImportMM im; diff -r ab83f030285e -r bc9083a4a7fb mainwindow.h --- a/mainwindow.h Mon Jul 30 09:47:08 2007 +0000 +++ b/mainwindow.h Mon Jul 30 09:47:09 2007 +0000 @@ -10,7 +10,7 @@ #include "mapeditor.h" #include "simplescripteditor.h" #include "texteditor.h" -#include "xml.h" +//#include "xml.h" class Main : public QMainWindow { @@ -60,7 +60,7 @@ private slots: void editorChanged(QWidget*); - ErrorCode fileLoad(QString ,const LoadMode &); + ErrorCode fileLoad(QString ,const LoadMode &, const FileType & ftype=VymMap); void fileLoad(const LoadMode &); void fileLoad(); void fileLoadRecent(); @@ -74,6 +74,7 @@ void fileSaveAs(); void fileImportKDEBookmarks(); void fileImportFirefoxBookmarks(); + void fileImportFreemind(); void fileImportMM(); void fileImportDir(); void fileExportXML(); diff -r ab83f030285e -r bc9083a4a7fb mapeditor.cpp --- a/mapeditor.cpp Mon Jul 30 09:47:08 2007 +0000 +++ b/mapeditor.cpp Mon Jul 30 09:47:09 2007 +0000 @@ -19,8 +19,8 @@ #include "misc.h" #include "texteditor.h" #include "warningdialog.h" -#include "xml.h" -#include "xml-fm.h" +#include "xml-freemind.h" +#include "xml-vym.h" extern TextEditor *textEditor; @@ -1485,10 +1485,20 @@ return destPath; } -ErrorCode MapEditor::load (QString fname, LoadMode lmode) +ErrorCode MapEditor::load (QString fname, const LoadMode &lmode, const FileType &ftype) { ErrorCode err=success; + parseBaseHandler *handler; + switch (ftype) + { + case VymMap: handler=new parseVYMHandler; break; + case FreemindMap : handler=new parseFreemindHandler; break; + default: + QMessageBox::critical( 0, tr( "Critical Parse Error" ), + "Unknown FileType in MapEditor::load()"); + return aborted; + } if (lmode==NewMap) { if (xelection.isEmpty() ) xelection.unselect(); @@ -1513,9 +1523,7 @@ QString("addMapReplace(%1)").arg(fname), QString("Add map %1 to %2").arg(fname).arg(getName(bo))); } - - parseVYMHandler handler; QFile file( fname ); // I am paranoid: file should exist anyway @@ -1532,16 +1540,16 @@ blockSaveState=true; QXmlInputSource source( file); QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - handler.setMapEditor( this ); + reader.setContentHandler( handler ); + reader.setErrorHandler( handler ); + handler->setMapEditor( this ); // We need to set the tmpDir in order to load files with rel. path QString tmpdir= fname.left(fname.findRev("/",-1)); - handler.setTmpDir (tmpdir); - handler.setInputFile (file.name()); - handler.setLoadMode (lmode); + handler->setTmpDir (tmpdir); + handler->setInputFile (file.name()); + handler->setLoadMode (lmode); bool ok = reader.parse( source ); blockReposition=false; blockSaveState=blockSaveStateOrg; @@ -1560,7 +1568,7 @@ } else { QMessageBox::critical( 0, tr( "Critical Parse Error" ), - tr( handler.errorProtocol() ) ); + tr( handler->errorProtocol() ) ); // returnCode=1; // Still return "success": the map maybe at least // partially read by the parser @@ -2208,10 +2216,10 @@ // Use the "historical" buffer QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n)); QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName); - load (bakMapDir+"/"+clipboardFile,ImportAdd); + load (bakMapDir+"/"+clipboardFile,ImportAdd, VymMap); } else // Use the global buffer - load (clipboardDir+"/"+clipboardFile,ImportAdd); + load (clipboardDir+"/"+clipboardFile,ImportAdd, VymMap); blockSaveState=old; } @@ -4111,82 +4119,11 @@ void MapEditor::testFunction1() { - ErrorCode err=success; - LoadMode lmode=NewMap; - - //QString fname="test/freemind/doc/freemind.xml"; - QString fname="test/freemind/doc/icons.mm"; - parseFMHandler handler; - QFile file( fname ); - - // I am paranoid: file should exist anyway - // according to check in mainwindow. - if (!file.exists() ) - { - QMessageBox::critical( 0, tr( "Critical Parse Error" ), - tr("Couldn't open map " +fname)+"."); - err=aborted; - } else - { - bool blockSaveStateOrg=blockSaveState; - blockReposition=true; - blockSaveState=true; - QXmlInputSource source( file); - QXmlSimpleReader reader; - reader.setContentHandler( &handler ); - reader.setErrorHandler( &handler ); - handler.setMapEditor( this ); - - - // We need to set the tmpDir in order to load files with rel. path - QString tmpdir= fname.left(fname.findRev("/",-1)); - handler.setTmpDir (tmpdir); - handler.setInputFile (file.name()); - //handler.setLoadMode (lmode); - bool ok = reader.parse( source ); - blockReposition=false; - blockSaveState=blockSaveStateOrg; - file.close(); - if ( ok ) - { - mapCenter->reposition(); - xelection.update(); - if (lmode==NewMap) - { - mapDefault=false; - mapChanged=false; - mapUnsaved=false; - autosaveTimer->stop(); - } - } else - { - QMessageBox::critical( 0, tr( "Critical Parse Error" ), - tr( handler.errorProtocol() ) ); - // returnCode=1; - // Still return "success": the map maybe at least - // partially read by the parser - } - } - updateActions(); - //return err; /* BranchObj *bo=xelection.getBranch(); if (bo) animObjList.append( bo ); */ -/* - WarningDialog dia; - dia.showCancelButton (true); - dia.setText("This is a longer \nWarning"); - dia.setCaption("Warning: Flux problem"); - dia.setShowAgainName("mapeditor/testDialog"); - if (dia.exec()==QDialog::Accepted) - cout << "accepted!\n"; - else - cout << "canceled!\n"; - return; -*/ - /* TODO Hide hidden stuff temporary, maybe add this as regular function somewhere if (hidemode==HideNone) {