From 003199d6df58c5af38d1cd6ac0ed184f8a199adf Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 9 Sep 2015 18:49:45 +0200 Subject: [PATCH] + fix possible loss of data with recovery function, show auto-save message in status bar --- src/Gui/AutoSaver.cpp | 16 +++++++++------- src/Gui/DocumentRecovery.cpp | 33 ++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/Gui/AutoSaver.cpp b/src/Gui/AutoSaver.cpp index d38942a9f..8a1170b5a 100644 --- a/src/Gui/AutoSaver.cpp +++ b/src/Gui/AutoSaver.cpp @@ -40,6 +40,7 @@ #include "WaitCursor.h" #include "Widgets.h" +#include "MainWindow.h" using namespace Gui; @@ -108,8 +109,8 @@ void AutoSaver::saveDocument(const std::string& name) str << "" << endl << "" << endl; str << " Created" << endl; - str << " " << endl; // store the document's current label - str << " " << doc->FileName.getValue() << "" << endl; // store the document's current filename + str << " " << endl; // store the document's current label + str << " " << QString::fromUtf8(doc->FileName.getValue()) << "" << endl; // store the document's current filename str << "" << endl; file.close(); } @@ -125,9 +126,10 @@ void AutoSaver::saveDocument(const std::string& name) bool save = hGrp->GetBool("SaveThumbnail",false); hGrp->SetBool("SaveThumbnail",false); - Gui::StatusWidget* sw = new Gui::StatusWidget(qApp->activeWindow()); - sw->setStatusText(tr("Please wait until the AutoRecovery file has been saved...")); - sw->show(); + //Gui::StatusWidget* sw = new Gui::StatusWidget(qApp->activeWindow()); + //sw->setStatusText(tr("Please wait until the AutoRecovery file has been saved...")); + //sw->show(); + getMainWindow()->showMessage(tr("Please wait until the AutoRecovery file has been saved..."), 5000); qApp->processEvents(); // open extra scope to close ZipWriter properly @@ -152,8 +154,8 @@ void AutoSaver::saveDocument(const std::string& name) } } - sw->hide(); - sw->deleteLater(); + //sw->hide(); + //sw->deleteLater(); std::string str = watch.toString(watch.elapsed()); Base::Console().Log("Save AutoRecovery file: %s\n", str.c_str()); diff --git a/src/Gui/DocumentRecovery.cpp b/src/Gui/DocumentRecovery.cpp index da2ecc085..1f9e6db18 100644 --- a/src/Gui/DocumentRecovery.cpp +++ b/src/Gui/DocumentRecovery.cpp @@ -30,6 +30,8 @@ #ifndef _PreComp_ # include # include +# include +# include # include # include # include @@ -68,8 +70,9 @@ public: enum Status { Unknown = 0, /*!< The file is not available */ Created = 1, /*!< The file was created but not processed so far*/ - Success = 2, /*!< The file could be recovered */ - Failure = 3, /*!< The file could not be recovered */ + Overage = 2, /*!< The recovery file is older than the actual project file */ + Success = 3, /*!< The file could be recovered */ + Failure = 4, /*!< The file could not be recovered */ }; struct Info { QString projectFile; @@ -84,7 +87,7 @@ public: QList recoveryInfo; Info getRecoveryInfo(const QFileInfo&) const; - void writeRecoveryInfo(const Info&); + void writeRecoveryInfo(const Info&) const; XmlConfig readXmlFile(const QString& fn) const; }; @@ -211,7 +214,7 @@ void DocumentRecovery::accept() } } -void DocumentRecoveryPrivate::writeRecoveryInfo(const DocumentRecoveryPrivate::Info& info) +void DocumentRecoveryPrivate::writeRecoveryInfo(const DocumentRecoveryPrivate::Info& info) const { // Write recovery meta file QFile file(info.xmlFile); @@ -224,6 +227,9 @@ void DocumentRecoveryPrivate::writeRecoveryInfo(const DocumentRecoveryPrivate::I case Created: str << " Created" << endl; break; + case Overage: + str << " Deprecated" << endl; + break; case Success: str << " Success" << endl; break; @@ -269,11 +275,28 @@ DocumentRecoveryPrivate::Info DocumentRecoveryPrivate::getRecoveryInfo(const QFi if (cfg.contains(QString::fromLatin1("Status"))) { QString status = cfg[QString::fromLatin1("Status")]; - if (status == QLatin1String("Success")) + if (status == QLatin1String("Deprecated")) + info.status = DocumentRecoveryPrivate::Overage; + else if (status == QLatin1String("Success")) info.status = DocumentRecoveryPrivate::Success; else if (status == QLatin1String("Failure")) info.status = DocumentRecoveryPrivate::Failure; } + + if (info.status == DocumentRecoveryPrivate::Created) { + // compare the modification dates + QFileInfo fileInfo(info.fileName); + if (!info.fileName.isEmpty() && fileInfo.exists()) { + QDateTime dateRecv = QFileInfo(file).lastModified(); + QDateTime dateProj = fileInfo.lastModified(); + if (dateRecv < dateProj) { + info.status = DocumentRecoveryPrivate::Overage; + writeRecoveryInfo(info); + qWarning() << "Ignore recovery file " << file.toUtf8() + << " because it is older than the project file" << info.fileName.toUtf8() << "\n"; + } + } + } } }