Use KAutoSaveFile for the backup system, instead of home made function.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5788 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2019-03-16 10:50:30 +00:00
parent 47b78bfec1
commit 154575d38a
8 changed files with 309 additions and 295 deletions

View File

@@ -21,6 +21,7 @@
#include <limits>
#include <QGraphicsSceneContextMenuEvent>
#include <QAction>
#include <QFileInfo>
/**
Permet de convertir une chaine de caracteres ("n", "s", "e" ou "w")
@@ -645,3 +646,36 @@ QActionGroup *QET::depthActionGroup(QObject *parent)
return action_group;
}
bool QET::writeToFile(QDomDocument &xml_doc, QFile *file, QString *error_message)
{
bool opened_here = file->isOpen() ? false : true;
if (!file->isOpen())
{
bool open_ = file->open(QIODevice::WriteOnly);
if (!open_)
{
if (error_message)
{
QFileInfo info_(*file);
*error_message = QString(
QObject::tr("Impossible d'ouvrir le fichier %1 en écriture, erreur %2 rencontrée.",
"error message when attempting to write an XML file")
).arg(info_.absoluteFilePath()).arg(file->error());
}
return false;
}
}
QTextStream out(file);
out.seek(0);
out.setCodec("UTF-8");
out.setGenerateByteOrderMark(false);
out << xml_doc.toString(4);
if (opened_here) {
file->close();
}
return(true);
}