From 145dd7311354becde29cd16a7876749604971bbe Mon Sep 17 00:00:00 2001 From: dismine Date: Wed, 8 Oct 2014 11:51:17 +0300 Subject: [PATCH] Show message if could not save file. Disable read only permission for measurements file. --HG-- branch : develop --- src/app/dialogs/app/dialogincrements.cpp | 68 +++++++++++++++---- .../app/dialogindividualmeasurements.cpp | 1 + src/app/mainwindow.cpp | 28 +++++++- src/app/options.h | 2 + src/app/xml/vdomdocument.cpp | 21 ++++-- src/app/xml/vdomdocument.h | 2 +- src/app/xml/vpattern.cpp | 4 +- src/app/xml/vpattern.h | 2 +- 8 files changed, 106 insertions(+), 22 deletions(-) diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index 148052628..327464842 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -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 "<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(); diff --git a/src/app/dialogs/app/dialogindividualmeasurements.cpp b/src/app/dialogs/app/dialogindividualmeasurements.cpp index 9055eddd0..ea5f45094 100644 --- a/src/app/dialogs/app/dialogindividualmeasurements.cpp +++ b/src/app/dialogs/app/dialogindividualmeasurements.cpp @@ -123,6 +123,7 @@ void DialogIndividualMeasurements::DialogAccepted() m.save(out, indent); iMeasur.close(); } + iMeasur.setPermissions(QFile::ReadOwner | QFile::WriteOwner); } catch (VException &e) { diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 2edf922ae..5e559f72b 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -42,6 +42,7 @@ #include "core/undoevent.h" #include "undocommands/renamepp.h" #include "vtooloptionspropertybrowser.h" +#include "options.h" #include #include @@ -55,6 +56,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -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(); diff --git a/src/app/options.h b/src/app/options.h index c8bc24b2c..ce8200365 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -34,6 +34,8 @@ #ifdef Q_OS_WIN32 # include + +extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; #endif /*Q_OS_WIN32*/ class QString; diff --git a/src/app/xml/vdomdocument.cpp b/src/app/xml/vdomdocument.cpp index 9177d7b50..51732cd93 100644 --- a/src/app/xml/vdomdocument.cpp +++ b/src/app/xml/vdomdocument.cpp @@ -30,6 +30,7 @@ #include "../exception/vexceptionconversionerror.h" #include "../exception/vexceptionemptyparameter.h" #include "../exception/vexceptionbadid.h" +#include "../options.h" #include #include @@ -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"<