# HG changeset patch # User insilmaril # Date 1204128546 0 # Node ID 3dabc6424d731e93f0c5ba2094f477e0b756825b # Parent e524edc45affb2f8717e14263c71453e8fd03e94 autosave fix diff -r e524edc45aff -r 3dabc6424d73 demos/vym-projectplan.vym Binary file demos/vym-projectplan.vym has changed diff -r e524edc45aff -r 3dabc6424d73 mainwindow.cpp --- a/mainwindow.cpp Wed Feb 27 16:09:06 2008 +0000 +++ b/mainwindow.cpp Wed Feb 27 16:09:06 2008 +0000 @@ -1469,18 +1469,15 @@ a = new QAction( "Test function 1" , this); a->setStatusTip( "Call test function 1" ); testMenu->addAction (a); - //a->setShortcut (Qt::Key_F4 ); connect( a, SIGNAL( triggered() ), this, SLOT( testFunction1() ) ); a = new QAction( "Test function 2" , this); a->setStatusTip( "Call test function 2" ); - //a->setShortcut (Qt::Key_F4 ); testMenu->addAction (a); connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) ); a = new QAction( "Command" , this); a->setStatusTip( "Enter command to call in editor" ); - //a->setShortcut (Qt::Key_F5 ); connect( a, SIGNAL( triggered() ), this, SLOT( testCommand() ) ); testMenu->addAction (a); } @@ -1835,70 +1832,14 @@ tabWidget->showPage(me); me->viewport()->setFocus(); - // Create temporary directory for packing - bool ok; - QString tmpZipDir=makeTmpDir (ok,"vym-pack"); - if (!ok) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't create temporary directory before load\n")); - return aborted; - } - - // Try to unzip file - err=unzipDir (tmpZipDir,fn); - if (err==nozip) - { - mapfile=fn; - me->setZipped(false); - } else - { - me->setZipped(true); - - // Look for mapname.xml - mapfile= fn.left(fn.findRev(".",-1,true)); - mapfile=mapfile.section( '/', -1 ); - QFile file( tmpZipDir + "/" + mapfile + ".xml"); - if (!file.exists() ) - { - // mapname.xml does not exist, well, - // maybe someone renamed the mapname.vym file... - // Try to find any .xml in the toplevel - // directory of the .vym file - QStringList flist=QDir (tmpZipDir).entryList("*.xml"); - if (flist.count()==1) - { - // Only one entry, take this one - mapfile=tmpZipDir + "/"+flist.first(); - } else - { - for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) - *it=tmpZipDir + "/" + *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(); - } - if (err!=aborted) { // Save existing filename in case we import QString fn_org=me->getFilePath(); // Finally load map into mapEditor - me->setFilePath (mapfile,fn); - err=me->load(mapfile,lmode,ftype); + me->setFilePath (fn); + err=me->load(fn,lmode,ftype); // Restore old (maybe empty) filepath, if this is an import if (lmode!=NewMap) @@ -1926,9 +1867,6 @@ } statusBar()->message( "Loaded " + fn, statusbarTime ); } - - // Delete tmpDir - removeDir (QDir(tmpZipDir)); } return err; } @@ -2000,125 +1938,133 @@ void Main::fileSave(MapEditor *me, const SaveMode &savemode) { + /* FIXME moved to ME + // Error codes + ErrorCode err=success; + + QString safeFilePath; + + if (!me) return; + bool saveZipped=me->saveZipped(); + // tmp dir for zipping QString tmpZipDir; - // Error codes - ErrorCode err=success; + */ - QString safeFilePath; - - bool saveZipped=me->saveZipped(); - - if (me) - { - QString fn=me->getFilePath(); - // filename=unnamed, filepath="" in constructor of mapEditor - if ( !fn.isEmpty() ) - { - // We have a filepath, go on saving - - // Look, if we should zip the data: - if (!saveZipped) + + if (!me) return; + + // filename=unnamed, filepath="" in constructor of mapEditor + + /* FIXME moved to ME + if ( !fn.isEmpty() ) + { + // We have a filepath, go on saving + + // Look, if we should zip the data: + if (!saveZipped) + { + QMessageBox mb( vymName, + 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 " + "given directory\n\nDo you want to write the map").arg(fn), + QMessageBox::Warning, + QMessageBox::Yes | QMessageBox::Default, + QMessageBox::No , + QMessageBox::Cancel | QMessageBox::Escape); + mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); + mb.setButtonText( QMessageBox::No, tr("uncompressed") ); + mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); + switch( mb.exec() ) { - QMessageBox mb( vymName, - 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 " - "given directory\n\nDo you want to write the map").arg(fn), - QMessageBox::Warning, - QMessageBox::Yes | QMessageBox::Default, - QMessageBox::No , - QMessageBox::Cancel | QMessageBox::Escape); - mb.setButtonText( QMessageBox::Yes, tr("compressed (vym default)") ); - mb.setButtonText( QMessageBox::No, tr("uncompressed") ); - mb.setButtonText( QMessageBox::Cancel, tr("Cancel")); - switch( mb.exec() ) + case QMessageBox::Yes: + // save compressed (default file format) + saveZipped=true; + break; + case QMessageBox::No: + // save uncompressed + saveZipped=false; + break; + case QMessageBox::Cancel: + // do nothing + return; + break; + } + me->setZipped (saveZipped); + } + + // First backup existing file, we + // don't want to add to old zip archives + QFile f(fn); + if (f.exists()) + { + if (actionSettingsWriteBackupFile->isOn()) + { + QString bfn(fn + "~"); + QFile bf(bfn); + if (bf.exists() && !bf.remove()) { - case QMessageBox::Yes: - // save compressed (default file format) - saveZipped=true; - break; - case QMessageBox::No: - // save uncompressed - saveZipped=false; - break; - case QMessageBox::Cancel: - // do nothing - return; - break; + QMessageBox::warning(0, tr("Save Error"), + bfn + tr("\ncould not be removed before saving")); } - me->setZipped (saveZipped); + else if (!f.rename(bfn)) + { + QMessageBox::warning(0, tr("Save Error"), + fn + tr("\ncould not be renamed before saving")); + } } - - // First backup existing file, we - // don't want to add to old zip archives - QFile f(fn); - if (f.exists()) - { - if (actionSettingsWriteBackupFile->isOn()) - { - QString bfn(fn + "~"); - QFile bf(bfn); - if (bf.exists() && !bf.remove()) - { - QMessageBox::warning(0, tr("Save Error"), - bfn + tr("\ncould not be removed before saving")); - } - else if (!f.rename(bfn)) - { - QMessageBox::warning(0, tr("Save Error"), - fn + tr("\ncould not be renamed before saving")); - } - } - } - - if (saveZipped) + } + + if (saveZipped) + { + // Create temporary directory for packing + bool ok; + tmpZipDir=makeTmpDir (ok,"vym-zip"); + if (!ok) { - // Create temporary directory for packing - bool ok; - tmpZipDir=makeTmpDir (ok,"vym-zip"); - if (!ok) - { - QMessageBox::critical( 0, tr( "Critical Load Error" ), - tr("Couldn't create temporary directory before save\n")); - return; - } - - safeFilePath=me->getFilePath(); - me->setFilePath (tmpZipDir+"/"+ - me->getMapName()+ ".xml", - safeFilePath); - me->save (savemode); - me->setFilePath (safeFilePath); - - zipDir (tmpZipDir,fn); - } // save zipped - else - { - // Save unzipped. - safeFilePath=me->getFilePath(); - me->setFilePath (fn, safeFilePath); - me->save (savemode); - me->setFilePath (safeFilePath); - } // save zipped - } // filepath available + QMessageBox::critical( 0, tr( "Critical Load Error" ), + tr("Couldn't create temporary directory before save\n")); + return; + } + + safeFilePath=me->getFilePath(); + me->setFilePath (tmpZipDir+"/"+ + me->getMapName()+ ".xml", + safeFilePath); + me->save (savemode); + me->setFilePath (safeFilePath); + + zipDir (tmpZipDir,fn); + } // save zipped else { - // We have no filepath yet, - // call fileSaveAs() now, this will call fileSave() - // again. - // First switch to editor - tabWidget->setCurrentWidget (me); - fileSaveAs(savemode); - } - } - + // Save unzipped. + safeFilePath=me->getFilePath(); + me->setFilePath (fn, safeFilePath); + me->save (savemode); + me->setFilePath (safeFilePath); + } // save zipped + } // filepath available + else + */ + if ( me->getFilePath().isEmpty() ) + { + // We have no filepath yet, + // call fileSaveAs() now, this will call fileSave() + // again. + // First switch to editor + tabWidget->setCurrentWidget (me); + fileSaveAs(savemode); + } + +/* FIXME moved to ME if (saveZipped && !tmpZipDir.isEmpty()) // Delete tmpDir removeDir (QDir(tmpZipDir)); - - if (err==success) +*/ + if (me->save (savemode)==success) { statusBar()->message( tr("Saved %1").arg(me->getFilePath()), @@ -3438,9 +3384,7 @@ tr("QInputDialog::getInteger()"), tr("Number of seconds before autosave:"), settings.value("/mapeditor/autosave/ms").toInt() / 1000, 10, 10000, 1, &ok); if (ok) - { settings.setValue ("/mapeditor/autosave/ms",i * 1000); - } } void Main::settingsWriteBackupFileToggle() @@ -3801,8 +3745,8 @@ void Main::testFunction1() { if (!currentMapEditor()) return; - currentMapEditor()->testFunction1(); - //editAttribute(); + //currentMapEditor()->testFunction1(); + editAttribute(); } void Main::testFunction2() diff -r e524edc45aff -r 3dabc6424d73 mapeditor.cpp --- a/mapeditor.cpp Wed Feb 27 16:09:06 2008 +0000 +++ b/mapeditor.cpp Wed Feb 27 16:09:06 2008 +0000 @@ -145,6 +145,10 @@ autosaveTimer=new QTimer (this); connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(autosave())); + fileChangedTimer=new QTimer (this); + fileChangedTimer->start(3000); + connect(fileChangedTimer, SIGNAL(timeout()), this, SLOT(fileChanged())); + // Network netstate=Offline; @@ -185,6 +189,7 @@ { //cout <<"Destructor MapEditor\n"; autosaveTimer->stop(); + fileChangedTimer->stop(); // tmpMapDir is in tmpVymDir, so it gets removed automagically when vym closes @@ -1498,7 +1503,7 @@ { filePath=fpath; // becomes absolute path fileName=fpath; // gets stripped of path - destPath=destname; // needed for vymlinks + destPath=destname; // needed for vymlinks and during load to reset fileChangedTime // If fpath is not an absolute path, complete it filePath=QDir(fpath).absPath(); @@ -1543,7 +1548,8 @@ ErrorCode err=success; parseBaseHandler *handler; - switch (ftype) + fileType=ftype; + switch (fileType) { case VymMap: handler=new parseVYMHandler; break; case FreemindMap : handler=new parseFreemindHandler; break; @@ -1575,14 +1581,72 @@ QString("Add map %1 to %2").arg(fname).arg(getName(bo))); } - QFile file( fname ); + + // Create temporary directory for packing + bool ok; + QString tmpZipDir=makeTmpDir (ok,"vym-pack"); + if (!ok) + { + QMessageBox::critical( 0, tr( "Critical Load Error" ), + tr("Couldn't create temporary directory before load\n")); + return aborted; + } + + // Try to unzip file + err=unzipDir (tmpZipDir,fname); + QString xmlfile; + if (err==nozip) + { + xmlfile=fname; + zipped=false; + } else + { + zipped=true; + + // Look for mapname.xml + xmlfile= fname.left(fname.findRev(".",-1,true)); + xmlfile=xmlfile.section( '/', -1 ); + QFile mfile( tmpZipDir + "/" + xmlfile + ".xml"); + if (!mfile.exists() ) + { + // mapname.xml does not exist, well, + // maybe someone renamed the mapname.vym file... + // Try to find any .xml in the toplevel + // directory of the .vym file + QStringList flist=QDir (tmpZipDir).entryList("*.xml"); + if (flist.count()==1) + { + // Only one entry, take this one + xmlfile=tmpZipDir + "/"+flist.first(); + } else + { + for ( QStringList::Iterator it = flist.begin(); it != flist.end(); ++it ) + *it=tmpZipDir + "/" + *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 + xmlfile=mfile.name(); + } + + QFile file( xmlfile); // 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)+"."); + tr(QString("Couldn't open map %1").arg(file.name()))); err=aborted; } else { @@ -1607,7 +1671,7 @@ file.close(); if ( ok ) { - model->reposition(); + model->reposition(); // FIXME reposition the view instead... xelection.update(); if (lmode==NewMap) { @@ -1616,6 +1680,9 @@ mapUnsaved=false; autosaveTimer->stop(); } + + // Reset timestamp to check for later updates of file + fileChangedTime=QFileInfo (destPath).lastModified(); } else { QMessageBox::critical( 0, tr( "Critical Parse Error" ), @@ -1625,22 +1692,102 @@ // partially read by the parser } } + + // Delete tmpDir + removeDir (QDir(tmpZipDir)); + updateActions(); return err; } -int MapEditor::save (const SaveMode &savemode) -{ +ErrorCode MapEditor::save (const SaveMode &savemode) +{ + cout <<"ME::save zipped="<0) return; if (mapUnsaved &&mapChanged && settings.value ("/mapeditor/autosave/use",true).toBool() ) - mainWindow->fileSave (this); + { + if (QFileInfo(filePath).lastModified()<=fileChangedTime) + mainWindow->fileSave (this); + else + if (debug) + cout <<" ME::autosave rejected, file on disk is newer than last save.\n"; + + } +} + +void MapEditor::fileChanged() +{ + // Check if file on disk has changed meanwhile + if (!filePath.isEmpty()) + { + QDateTime tmod=QFileInfo (filePath).lastModified(); + if (tmod>fileChangedTime) + { + + /* FIXME debug message, sometimes there's a glitch in the metrics... + cout << "ME::fileChanged()\n" + << " last saved: "< #define __VYM_NAME "VYM" -#define __VYM_VERSION "1.11.5" +#define __VYM_VERSION "1.11.6" //#define __VYM_CODENAME "Codename: 1.10.0-RC-3" #define __VYM_CODENAME "Codename: development version" -#define __VYM_BUILD_DATE "2008-01-15" +#define __VYM_BUILD_DATE "2008-02-27" bool checkVersion(const QString &); diff -r e524edc45aff -r 3dabc6424d73 vym.pro --- a/vym.pro Wed Feb 27 16:09:06 2008 +0000 +++ b/vym.pro Wed Feb 27 16:09:06 2008 +0000 @@ -27,8 +27,9 @@ aboutdialog.h \ animpoint.h \ attribute.h \ + attributedelegate.h\ + attributedialog.h \ attributewidget.h \ - attributedialog.h \ branchobj.h \ branchpropwindow.h\ editxlinkdialog.h \ @@ -79,8 +80,9 @@ aboutdialog.cpp \ animpoint.cpp \ attribute.cpp \ + attributedelegate.cpp \ + attributedialog.cpp \ attributewidget.cpp \ - attributedialog.cpp \ branchobj.cpp \ branchpropwindow.cpp \ editxlinkdialog.cpp \ diff -r e524edc45aff -r 3dabc6424d73 vymmodel.cpp --- a/vymmodel.cpp Wed Feb 27 16:09:06 2008 +0000 +++ b/vymmodel.cpp Wed Feb 27 16:09:06 2008 +0000 @@ -192,18 +192,6 @@ // View related ////////////////////////////////////////////// - /* FIXME copied from MCO, still needed? -void VymModel::updateLink() -{ - // set childPos to middle of MapCenterObj - childPos.setX( clickBox.topLeft().x() + (int)(clickBox.width())/2 ); - childPos.setY( clickBox.topLeft().y() + (int)(clickBox.height())/2 ); - parPos=childPos; - for (int i=0; iupdateLink(); -} - -*/ void VymModel::updateRelPositions() { for (int i=0; iaddMapCenter(); - //lastBranch=model->first(); // avoid empty pointer + lastBranch=model->addMapCenter(); } else { // Treat the found mapcenter as a branch