Show message if could not save file. Disable read only permission for

measurements file.

--HG--
branch : develop
This commit is contained in:
dismine 2014-10-08 11:51:17 +03:00
parent 58bffd4005
commit 145dd73113
8 changed files with 106 additions and 22 deletions

View File

@ -389,9 +389,16 @@ void DialogIncrements::FullUpdateFromFile()
void DialogIncrements::SaveGivenName()
{
m->setGivenName(ui->lineEditGivenName->text());
if (m->SaveDocument(doc->MPath()) == false)
QString error;
if (m->SaveDocument(doc->MPath(), error) == false)
{
qDebug()<<"Can't save GivenName";
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(tr("Could not save GivenName"));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setDetailedText(error);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
}
}
@ -400,9 +407,16 @@ void DialogIncrements::SaveFamilyName()
{
m->setFamilyName(ui->lineEditFamilyName->text());
if (m->SaveDocument(doc->MPath()) == false)
QString error;
if (m->SaveDocument(doc->MPath(), error) == false)
{
qDebug()<<"Can't save FamilyName";
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(tr("Could not save FamilyName"));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setDetailedText(error);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
}
}
@ -410,9 +424,16 @@ void DialogIncrements::SaveFamilyName()
void DialogIncrements::SaveEmail()
{
m->setMail(ui->lineEditMail->text());
if (m->SaveDocument(doc->MPath()) == false)
QString error;
if (m->SaveDocument(doc->MPath(), error) == false)
{
qDebug()<<"Can't save Email";
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(tr("Could not save Email"));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setDetailedText(error);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
}
}
@ -420,9 +441,16 @@ void DialogIncrements::SaveEmail()
void DialogIncrements::SaveSex(int index)
{
m->setSex(m->StrToGender(ui->comboBoxSex->itemData(index).toString()));
if (m->SaveDocument(doc->MPath()) == false)
QString error;
if (m->SaveDocument(doc->MPath(), error) == false)
{
qDebug()<<"Can't save Sex";
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(tr("Could not save Sex"));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setDetailedText(error);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
}
}
@ -430,9 +458,16 @@ void DialogIncrements::SaveSex(int index)
void DialogIncrements::SaveBirthDate(const QDate & date)
{
m->setBirthDate(date);
if (m->SaveDocument(doc->MPath()) == false)
QString error;
if (m->SaveDocument(doc->MPath(), error) == false)
{
qDebug()<<"Can't save BirthDate";
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(tr("Could not save BirthDate"));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setDetailedText(error);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
}
}
@ -734,7 +769,7 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column)
QDomElement domElement = list.at(0).toElement();
if (domElement.isElement() == false)
{
qDebug()<<"Cant't find measurement "<<tag<<Q_FUNC_INFO;
qDebug()<<"Can't find measurement "<<tag<<Q_FUNC_INFO;
return;
}
@ -755,9 +790,16 @@ void DialogIncrements::MeasurementChanged(qint32 row, qint32 column)
base = VAbstractMeasurements::UnitConvertor(base, qApp->patternUnit(), m->MUnit());
m->SetAttribute(domElement, VIndividualMeasurements::AttrValue, QString("%1").arg(base));
if (m->SaveDocument(doc->MPath()) == false)
QString error;
if (m->SaveDocument(doc->MPath(), error) == false)
{
qDebug()<<"Can't save measurement";
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(tr("Can't save measurement"));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setDetailedText(error);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
}
data->ClearVariables();

View File

@ -123,6 +123,7 @@ void DialogIndividualMeasurements::DialogAccepted()
m.save(out, indent);
iMeasur.close();
}
iMeasur.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
}
catch (VException &e)
{

View File

@ -42,6 +42,7 @@
#include "core/undoevent.h"
#include "undocommands/renamepp.h"
#include "vtooloptionspropertybrowser.h"
#include "options.h"
#include <QInputDialog>
#include <QDebug>
@ -55,6 +56,7 @@
#include <QProcess>
#include <QSettings>
#include <QTimer>
#include <QtGlobal>
//---------------------------------------------------------------------------------------------------------------------
/**
@ -1342,6 +1344,11 @@ void MainWindow::Clear()
QApplication::restoreOverrideCursor();
#endif
Layout();
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup--; // turn it off again
#endif /*Q_OS_WIN32*/
}
void MainWindow::FullParseFile()
@ -1786,7 +1793,8 @@ void MainWindow::MinimumScrollBar()
bool MainWindow::SavePattern(const QString &fileName)
{
QFileInfo tempInfo(fileName);
const bool result = doc->SaveDocument(fileName);
QString error;
const bool result = doc->SaveDocument(fileName, error);
if (result)
{
if (tempInfo.suffix() != "autosave")
@ -1796,6 +1804,16 @@ bool MainWindow::SavePattern(const QString &fileName)
qApp->getUndoStack()->clear();
}
}
else
{
QMessageBox messageBox;
messageBox.setIcon(QMessageBox::Warning);
messageBox.setInformativeText(tr("Could not save file"));
messageBox.setDefaultButton(QMessageBox::Ok);
messageBox.setDetailedText(error);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();
}
return result;
}
@ -2110,6 +2128,10 @@ void MainWindow::LoadPattern(const QString &fileName)
VAbstractTool::NewSceneRect(sceneDraw, ui->view);
VAbstractTool::NewSceneRect(sceneDetails, ui->view);
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup++; // turn checking on
#endif /*Q_OS_WIN32*/
qApp->setOpeningPattern();//Begin opening file
try
{
@ -2155,6 +2177,10 @@ void MainWindow::LoadPattern(const QString &fileName)
return;
}
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup--; // turn it off again
#endif /*Q_OS_WIN32*/
FullParseFile();
bool patternModified = this->isWindowModified();

View File

@ -34,6 +34,8 @@
#ifdef Q_OS_WIN32
# include <Windows.h>
extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;
#endif /*Q_OS_WIN32*/
class QString;

View File

@ -30,6 +30,7 @@
#include "../exception/vexceptionconversionerror.h"
#include "../exception/vexceptionemptyparameter.h"
#include "../exception/vexceptionbadid.h"
#include "../options.h"
#include <QAbstractMessageHandler>
#include <QXmlSchema>
@ -504,7 +505,7 @@ QString VDomDocument::UnitsToStr(const Unit &unit, const bool translate)
}
//---------------------------------------------------------------------------------------------------------------------
bool VDomDocument::SaveDocument(const QString &fileName)
bool VDomDocument::SaveDocument(const QString &fileName, QString &error)
{
if (fileName.isEmpty())
{
@ -525,8 +526,14 @@ bool VDomDocument::SaveDocument(const QString &fileName)
}
//Replace temp file our
bool result = false;
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup++; // turn checking on
#endif /*Q_OS_WIN32*/
QFile patternFile(fileName);
// We need here temporary file because we need restore document after error of copying temp file.
patternFile.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
// We need here temporary file because we want restore document after error of copying temp file.
QTemporaryFile tempOfPattern;
if (tempOfPattern.open())
{
@ -536,8 +543,9 @@ bool VDomDocument::SaveDocument(const QString &fileName)
{
if ( tempFile.copy(patternFile.fileName()) == false )
{
qDebug()<<"Could not copy temp file to document file"<<Q_FUNC_INFO;
error = tr("Could not copy temp file to document file");
tempOfPattern.copy(fileName);
tempFile.remove();
result = false;
}
else
@ -548,9 +556,14 @@ bool VDomDocument::SaveDocument(const QString &fileName)
}
else
{
qDebug()<<"Could not remove document file"<<Q_FUNC_INFO;
error = tr("Could not remove document file");
result = false;
}
#ifdef Q_OS_WIN32
qt_ntfs_permission_lookup--; // turn off check permission again
#endif /*Q_OS_WIN32*/
return result;
}

View File

@ -104,7 +104,7 @@ public:
void setContent(const QString &fileName);
static Unit StrToUnits(const QString &unit);
static QString UnitsToStr(const Unit &unit, const bool translate = false);
virtual bool SaveDocument(const QString &fileName);
virtual bool SaveDocument(const QString &fileName, QString &error);
QString Major() const;
QString Minor() const;
QString Patch() const;

View File

@ -693,7 +693,7 @@ MeasurementsType VPattern::MType() const
}
//---------------------------------------------------------------------------------------------------------------------
bool VPattern::SaveDocument(const QString &fileName)
bool VPattern::SaveDocument(const QString &fileName, QString &error)
{
try
{
@ -706,7 +706,7 @@ bool VPattern::SaveDocument(const QString &fileName)
}
GarbageCollector();
return VDomDocument::SaveDocument(fileName);
return VDomDocument::SaveDocument(fileName, error);
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -158,7 +158,7 @@ public:
static const QString IncrementKgrowth;
static const QString IncrementDescription;
virtual bool SaveDocument(const QString &fileName);
virtual bool SaveDocument(const QString &fileName, QString &error);
QStringList getPatternPieces() const;
QRectF ActiveDrawBoundingRect() const;
quint32 GetParametrId(const QDomElement& domElement) const;