diff options
Diffstat (limited to 'cad/qcad/files/patch-zzz-autosave')
-rw-r--r-- | cad/qcad/files/patch-zzz-autosave | 345 |
1 files changed, 345 insertions, 0 deletions
diff --git a/cad/qcad/files/patch-zzz-autosave b/cad/qcad/files/patch-zzz-autosave new file mode 100644 index 000000000000..8f499b71b354 --- /dev/null +++ b/cad/qcad/files/patch-zzz-autosave @@ -0,0 +1,345 @@ +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcad/src/qc_applicationwindow.cpp ./qcad/src/qc_applicationwindow.cpp +--- ../qcad-2.0.5.0-1-community.src.orig/qcad/src/qc_applicationwindow.cpp Tue Nov 22 12:49:33 2005 ++++ ./qcad/src/qc_applicationwindow.cpp Sat Aug 11 22:47:35 2007 +@@ -162,6 +162,11 @@ + RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: init MDI"); + initMDI(); + ++ // Activate autosave timer ++ autosaveTimer = new QTimer(this, "autosave"); ++ connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(slotFileAutoSave())); ++ autosaveTimer->start(autosaveTime); ++ + // Disable menu and toolbar items + emit windowsChanged(FALSE); + +@@ -2133,6 +2138,9 @@ + name = w->getDocument()->getFilename(); + recentFiles->add(name); + w->setCaption(name); ++ if (!autosaveTimer->isActive()) { ++ autosaveTimer->start(autosaveTime); ++ } + } + } else { + // error +@@ -2148,6 +2156,37 @@ + QString message = tr("Saved drawing: %1").arg(name); + statusBar()->message(message, 2000); + commandWidget->appendHistory(message); ++} ++ ++ ++ ++/** ++ * Autosave. ++ */ ++void QC_ApplicationWindow::slotFileAutoSave() { ++ RS_DEBUG->print("QC_ApplicationWindow::slotFileAutoSave()"); ++ ++ statusBar()->message(tr("Auto-saving drawing...")); ++ ++ QC_MDIWindow* w = getMDIWindow(); ++ QString name; ++ if (w!=NULL) { ++ bool cancelled; ++ if (w->slotFileSave(cancelled, true)) { ++ // auto-save cannot be cancelled by user, so the ++ // "cancelled" parameter is a dummy ++ statusBar()->message(tr("Auto-saved drawing"), 2000); ++ } else { ++ // error ++ autosaveTimer->stop(); ++ QMessageBox::information(this, QMessageBox::tr("Warning"), ++ tr("Cannot auto-save the file\n%1\nPlease " ++ "check the permissions.\n" ++ "Auto-save disabled.") ++ .arg(w->getDocument()->getAutoSaveFilename()), ++ QMessageBox::Ok); ++ } ++ } + } + + +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcad/src/qc_applicationwindow.h ./qcad/src/qc_applicationwindow.h +--- ../qcad-2.0.5.0-1-community.src.orig/qcad/src/qc_applicationwindow.h Tue Nov 22 12:49:34 2005 ++++ ./qcad/src/qc_applicationwindow.h Sat Aug 11 22:47:35 2007 +@@ -37,6 +37,7 @@ + #include <qsplitter.h> + #include <qstatusbar.h> + #include <qtable.h> ++#include <qtimer.h> + #include <qtoolbar.h> + #include <qtoolbutton.h> + #include <qwhatsthis.h> +@@ -148,6 +149,8 @@ + void slotFileSave(); + /** saves a document under a different filename*/ + void slotFileSaveAs(); ++ /** auto-save document */ ++ void slotFileAutoSave(); + /** exports the document as bitmap */ + void slotFileExport(); + bool slotFileExport(const QString& name, const QString& format, +@@ -456,6 +459,9 @@ + QAction *testResize800; + QAction *testResize1024; + ++ QTimer *autosaveTimer; ++ ++ const static int autosaveTime = 60 * 1000; // 1 minute + }; + + +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcad/src/qc_mdiwindow.cpp ./qcad/src/qc_mdiwindow.cpp +--- ../qcad-2.0.5.0-1-community.src.orig/qcad/src/qc_mdiwindow.cpp Tue Nov 22 12:49:37 2005 ++++ ./qcad/src/qc_mdiwindow.cpp Sat Aug 11 22:47:35 2007 +@@ -324,23 +324,32 @@ + /** + * Saves the current file. + * ++ * @param isAutoSave true if this is an "autosave" operation. ++ * false if this is "Save" operation requested ++ * by the user. + * @return true if the file was saved successfully. + * false if the file could not be saved or the document + * is invalid. + */ +-bool QC_MDIWindow::slotFileSave(bool &cancelled) { ++bool QC_MDIWindow::slotFileSave(bool &cancelled, bool isAutoSave) { + RS_DEBUG->print("QC_MDIWindow::slotFileSave()"); + bool ret = false; + cancelled = false; + + if (document!=NULL) { +- if (document->getFilename().isEmpty()) { +- ret = slotFileSaveAs(cancelled); ++ if (isAutoSave) { ++ // Autosave filename is always supposed to be present. ++ // Autosave does not change the cursor. ++ ret = document->save(true); + } else { +- QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); +- ret = document->save(); +- QApplication::restoreOverrideCursor(); +- } ++ if (document->getFilename().isEmpty()) { ++ ret = slotFileSaveAs(cancelled); ++ } else { ++ QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) ); ++ ret = document->save(); ++ QApplication::restoreOverrideCursor(); ++ } ++ } + } + + return ret; +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcad/src/qc_mdiwindow.h ./qcad/src/qc_mdiwindow.h +--- ../qcad-2.0.5.0-1-community.src.orig/qcad/src/qc_mdiwindow.h Tue Nov 22 12:49:37 2005 ++++ ./qcad/src/qc_mdiwindow.h Sat Aug 11 22:47:35 2007 +@@ -69,7 +69,7 @@ + + void slotFileNew(); + bool slotFileOpen(const QString& fileName, RS2::FormatType type); +- bool slotFileSave(bool &cancelled); ++ bool slotFileSave(bool &cancelled, bool isAutoSave=false); + bool slotFileSaveAs(bool &cancelled); + bool slotFileClose(bool force); + void slotFilePrint(); +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_block.cpp ./qcadlib/src/engine/rs_block.cpp +--- ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_block.cpp Tue Nov 22 12:52:35 2005 ++++ ./qcadlib/src/engine/rs_block.cpp Sat Aug 11 22:47:35 2007 +@@ -78,10 +78,10 @@ + } + + +-bool RS_Block::save() { ++bool RS_Block::save(bool isAutoSave) { + RS_Graphic* g = getGraphic(); + if (g!=NULL) { +- return g->save(); ++ return g->save(isAutoSave); + } else { + return false; + } +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_block.h ./qcadlib/src/engine/rs_block.h +--- ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_block.h Tue Nov 22 12:52:38 2005 ++++ ./qcadlib/src/engine/rs_block.h Sat Aug 11 22:47:35 2007 +@@ -128,7 +128,7 @@ + /** + * Reimplementation from RS_Document. Saves the parent graphic document. + */ +- virtual bool save(); ++ virtual bool save(bool isAutoSave = false); + + /** + * Reimplementation from RS_Document. Does nothing. +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_document.cpp ./qcadlib/src/engine/rs_document.cpp +--- ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_document.cpp Tue Nov 22 12:52:38 2005 ++++ ./qcadlib/src/engine/rs_document.cpp Sat Aug 11 22:47:35 2007 +@@ -40,6 +40,7 @@ + RS_DEBUG->print("RS_Document::RS_Document() "); + + filename = ""; ++ autosaveFilename = "Unnamed"; + formatType = RS2::FormatUnknown; + setModified(false); + RS_Color col(RS2::FlagByLayer); +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_document.h ./qcadlib/src/engine/rs_document.h +--- ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_document.h Tue Nov 22 12:52:32 2005 ++++ ./qcadlib/src/engine/rs_document.h Sat Aug 11 22:47:35 2007 +@@ -53,7 +53,7 @@ + virtual RS_BlockList* getBlockList() = 0; + + virtual void newDoc() = 0; +- virtual bool save() = 0; ++ virtual bool save(bool isAutoSave = false) = 0; + virtual bool saveAs(const RS_String &filename, RS2::FormatType type) = 0; + virtual bool open(const RS_String &filename, RS2::FormatType type) = 0; + +@@ -98,6 +98,13 @@ + } + + /** ++ * @return Auto-save file name of the document currently loaded. ++ */ ++ RS_String getAutoSaveFilename() const { ++ return autosaveFilename; ++ } ++ ++ /** + * Sets file name for the document currently loaded. + */ + void setFilename(const RS_String& fn) { +@@ -136,6 +143,8 @@ + RS_Pen activePen; + /** File name of the document or empty for a new document. */ + RS_String filename; ++ /** Auto-save file name of document. */ ++ RS_String autosaveFilename; + /** Format type */ + RS2::FormatType formatType; + }; +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_graphic.cpp ./qcadlib/src/engine/rs_graphic.cpp +--- ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_graphic.cpp Tue Nov 22 12:52:32 2005 ++++ ./qcadlib/src/engine/rs_graphic.cpp Sat Aug 11 22:47:57 2007 +@@ -24,6 +24,8 @@ + ** + **********************************************************************/ + ++#include <qfile.h> ++#include <qfileinfo.h> + + #include "rs_graphic.h" + +@@ -178,21 +180,46 @@ + /** + * Saves this graphic with the current filename and settings. + */ +-bool RS_Graphic::save() { ++bool RS_Graphic::save(bool isAutoSave) { + + bool ret = false; ++ + + RS_DEBUG->print("RS_Graphic::save"); +- RS_DEBUG->print(" file: %s", filename.latin1()); +- RS_DEBUG->print(" format: %d", (int)formatType); +- +- RS_DEBUG->print(" export..."); +- ret = RS_FILEIO->fileExport(*this, filename, formatType); +- +- if (ret) { +- setModified(false); +- layerList.setModified(false); +- blockList.setModified(false); ++ if (isAutoSave && !isModified()) { ++ RS_DEBUG->print(" autsave and not modified => not saved"); ++ ret = true; ++ } else { ++ const RS_String *actualName; ++ RS2::FormatType actualType; ++ ++ actualType = formatType; ++ if (isAutoSave) { ++ actualName = new QString(autosaveFilename); ++ if (formatType == RS2::FormatUnknown) { ++ actualType = RS2::FormatDXF; ++ } ++ } else { ++ actualName = new QString(filename); ++ } ++ RS_DEBUG->print(" file: %s", actualName->latin1()); ++ RS_DEBUG->print(" format: %d", (int)actualType); ++ RS_DEBUG->print(" export..."); ++ ret = RS_FILEIO->fileExport(*this, *actualName, actualType); ++ delete actualName; ++ ++ if (ret && !isAutoSave) { ++ setModified(false); ++ layerList.setModified(false); ++ blockList.setModified(false); ++ // Remove old autosave file ++ QFile f(autosaveFilename); ++ if (f.exists()) { ++ RS_DEBUG->print(" removing old autosave file %s", ++ autosaveFilename.latin1()); ++ f.remove(); ++ } ++ } + } + + RS_DEBUG->print("RS_Graphic::save ok"); +@@ -210,9 +237,28 @@ + RS_DEBUG->print("RS_Graphic::saveAs"); + + this->filename = filename; ++ RS_String *oldAutosaveName = new RS_String(autosaveFilename); ++ QFileInfo finfo(filename); ++ // Construct new autosave filename by prepending # to the filename ++ // part, using the same directory as the destination file. ++ this->autosaveFilename = finfo.dirPath() + "/#" + finfo.fileName(); + this->formatType = type; + +- return save(); ++ bool ret = save(); ++ ++ if (ret) { ++ // save was successful, remove old autosave file ++ QFile f(*oldAutosaveName); ++ if (f.exists()) { ++ RS_DEBUG->print("removing old autosave file %s", ++ oldAutosaveName->latin1()); ++ f.remove(); ++ } ++ } ++ ++ delete oldAutosaveName; ++ ++ return ret; + } + + +@@ -226,6 +272,10 @@ + bool ret = false; + + this->filename = filename; ++ QFileInfo finfo(filename); ++ // Construct new autosave filename by prepending # to the filename ++ // part, using the same directory as the destination file. ++ this->autosaveFilename = finfo.dirPath() + "/#" + finfo.fileName(); + + // clean all: + newDoc(); +diff -ru ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_graphic.h ./qcadlib/src/engine/rs_graphic.h +--- ../qcad-2.0.5.0-1-community.src.orig/qcadlib/src/engine/rs_graphic.h Tue Nov 22 12:52:38 2005 ++++ ./qcadlib/src/engine/rs_graphic.h Sat Aug 11 22:47:35 2007 +@@ -69,7 +69,7 @@ + } + + virtual void newDoc(); +- virtual bool save(); ++ virtual bool save(bool isAutoSave = false); + virtual bool saveAs(const RS_String& filename, RS2::FormatType type); + virtual bool open(const RS_String& filename, RS2::FormatType type); + |