+ fix possible loss of data with recovery function, show auto-save message in status bar

This commit is contained in:
wmayer 2015-09-09 18:49:45 +02:00
parent 32c96b4267
commit 003199d6df
2 changed files with 37 additions and 12 deletions

View File

@ -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 << "<?xml version='1.0' encoding='utf-8'?>" << endl
<< "<AutoRecovery SchemaVersion=\"1\">" << endl;
str << " <Status>Created</Status>" << endl;
str << " <Label>" << doc->Label.getValue() << "</Label>" << endl; // store the document's current label
str << " <FileName>" << doc->FileName.getValue() << "</FileName>" << endl; // store the document's current filename
str << " <Label>" << QString::fromUtf8(doc->Label.getValue()) << "</Label>" << endl; // store the document's current label
str << " <FileName>" << QString::fromUtf8(doc->FileName.getValue()) << "</FileName>" << endl; // store the document's current filename
str << "</AutoRecovery>" << 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());

View File

@ -30,6 +30,8 @@
#ifndef _PreComp_
# include <QApplication>
# include <QCloseEvent>
# include <QDateTime>
# include <QDebug>
# include <QDir>
# include <QFile>
# include <QHeaderView>
@ -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<Info> 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 << " <Status>Created</Status>" << endl;
break;
case Overage:
str << " <Status>Deprecated</Status>" << endl;
break;
case Success:
str << " <Status>Success</Status>" << 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";
}
}
}
}
}