+ fix possible loss of data with recovery function, show auto-save message in status bar
This commit is contained in:
parent
32c96b4267
commit
003199d6df
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include "WaitCursor.h"
|
#include "WaitCursor.h"
|
||||||
#include "Widgets.h"
|
#include "Widgets.h"
|
||||||
|
#include "MainWindow.h"
|
||||||
|
|
||||||
using namespace Gui;
|
using namespace Gui;
|
||||||
|
|
||||||
|
@ -108,8 +109,8 @@ void AutoSaver::saveDocument(const std::string& name)
|
||||||
str << "<?xml version='1.0' encoding='utf-8'?>" << endl
|
str << "<?xml version='1.0' encoding='utf-8'?>" << endl
|
||||||
<< "<AutoRecovery SchemaVersion=\"1\">" << endl;
|
<< "<AutoRecovery SchemaVersion=\"1\">" << endl;
|
||||||
str << " <Status>Created</Status>" << endl;
|
str << " <Status>Created</Status>" << endl;
|
||||||
str << " <Label>" << doc->Label.getValue() << "</Label>" << endl; // store the document's current label
|
str << " <Label>" << QString::fromUtf8(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 << " <FileName>" << QString::fromUtf8(doc->FileName.getValue()) << "</FileName>" << endl; // store the document's current filename
|
||||||
str << "</AutoRecovery>" << endl;
|
str << "</AutoRecovery>" << endl;
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
@ -125,9 +126,10 @@ void AutoSaver::saveDocument(const std::string& name)
|
||||||
bool save = hGrp->GetBool("SaveThumbnail",false);
|
bool save = hGrp->GetBool("SaveThumbnail",false);
|
||||||
hGrp->SetBool("SaveThumbnail",false);
|
hGrp->SetBool("SaveThumbnail",false);
|
||||||
|
|
||||||
Gui::StatusWidget* sw = new Gui::StatusWidget(qApp->activeWindow());
|
//Gui::StatusWidget* sw = new Gui::StatusWidget(qApp->activeWindow());
|
||||||
sw->setStatusText(tr("Please wait until the AutoRecovery file has been saved..."));
|
//sw->setStatusText(tr("Please wait until the AutoRecovery file has been saved..."));
|
||||||
sw->show();
|
//sw->show();
|
||||||
|
getMainWindow()->showMessage(tr("Please wait until the AutoRecovery file has been saved..."), 5000);
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
|
|
||||||
// open extra scope to close ZipWriter properly
|
// open extra scope to close ZipWriter properly
|
||||||
|
@ -152,8 +154,8 @@ void AutoSaver::saveDocument(const std::string& name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sw->hide();
|
//sw->hide();
|
||||||
sw->deleteLater();
|
//sw->deleteLater();
|
||||||
|
|
||||||
std::string str = watch.toString(watch.elapsed());
|
std::string str = watch.toString(watch.elapsed());
|
||||||
Base::Console().Log("Save AutoRecovery file: %s\n", str.c_str());
|
Base::Console().Log("Save AutoRecovery file: %s\n", str.c_str());
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
# include <QApplication>
|
# include <QApplication>
|
||||||
# include <QCloseEvent>
|
# include <QCloseEvent>
|
||||||
|
# include <QDateTime>
|
||||||
|
# include <QDebug>
|
||||||
# include <QDir>
|
# include <QDir>
|
||||||
# include <QFile>
|
# include <QFile>
|
||||||
# include <QHeaderView>
|
# include <QHeaderView>
|
||||||
|
@ -68,8 +70,9 @@ public:
|
||||||
enum Status {
|
enum Status {
|
||||||
Unknown = 0, /*!< The file is not available */
|
Unknown = 0, /*!< The file is not available */
|
||||||
Created = 1, /*!< The file was created but not processed so far*/
|
Created = 1, /*!< The file was created but not processed so far*/
|
||||||
Success = 2, /*!< The file could be recovered */
|
Overage = 2, /*!< The recovery file is older than the actual project file */
|
||||||
Failure = 3, /*!< The file could not be recovered */
|
Success = 3, /*!< The file could be recovered */
|
||||||
|
Failure = 4, /*!< The file could not be recovered */
|
||||||
};
|
};
|
||||||
struct Info {
|
struct Info {
|
||||||
QString projectFile;
|
QString projectFile;
|
||||||
|
@ -84,7 +87,7 @@ public:
|
||||||
QList<Info> recoveryInfo;
|
QList<Info> recoveryInfo;
|
||||||
|
|
||||||
Info getRecoveryInfo(const QFileInfo&) const;
|
Info getRecoveryInfo(const QFileInfo&) const;
|
||||||
void writeRecoveryInfo(const Info&);
|
void writeRecoveryInfo(const Info&) const;
|
||||||
XmlConfig readXmlFile(const QString& fn) 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
|
// Write recovery meta file
|
||||||
QFile file(info.xmlFile);
|
QFile file(info.xmlFile);
|
||||||
|
@ -224,6 +227,9 @@ void DocumentRecoveryPrivate::writeRecoveryInfo(const DocumentRecoveryPrivate::I
|
||||||
case Created:
|
case Created:
|
||||||
str << " <Status>Created</Status>" << endl;
|
str << " <Status>Created</Status>" << endl;
|
||||||
break;
|
break;
|
||||||
|
case Overage:
|
||||||
|
str << " <Status>Deprecated</Status>" << endl;
|
||||||
|
break;
|
||||||
case Success:
|
case Success:
|
||||||
str << " <Status>Success</Status>" << endl;
|
str << " <Status>Success</Status>" << endl;
|
||||||
break;
|
break;
|
||||||
|
@ -269,11 +275,28 @@ DocumentRecoveryPrivate::Info DocumentRecoveryPrivate::getRecoveryInfo(const QFi
|
||||||
|
|
||||||
if (cfg.contains(QString::fromLatin1("Status"))) {
|
if (cfg.contains(QString::fromLatin1("Status"))) {
|
||||||
QString status = cfg[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;
|
info.status = DocumentRecoveryPrivate::Success;
|
||||||
else if (status == QLatin1String("Failure"))
|
else if (status == QLatin1String("Failure"))
|
||||||
info.status = DocumentRecoveryPrivate::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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user