diff --git a/src/app/tape/tmainwindow.cpp b/src/app/tape/tmainwindow.cpp index fa1d7145b..4581ad96d 100644 --- a/src/app/tape/tmainwindow.cpp +++ b/src/app/tape/tmainwindow.cpp @@ -233,12 +233,10 @@ bool TMainWindow::LoadFile(const QString &path) if (not lock->IsLocked()) { - qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); - if (qApp->IsTestMode()) + if (not IgnoreLocking(lock->GetLockError(), path)) { - qApp->exit(V_EX_NOINPUT); + return false; } - return false; } try @@ -2599,12 +2597,10 @@ bool TMainWindow::LoadFromExistingFile(const QString &path) if (not lock->IsLocked()) { - qCCritical(tMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); - if (qApp->IsTestMode()) + if (not IgnoreLocking(lock->GetLockError(), path)) { - qApp->exit(V_EX_NOINPUT); + return false; } - return false; } try @@ -2726,6 +2722,72 @@ void TMainWindow::CreateWindowMenu(QMenu *menu) } } +//--------------------------------------------------------------------------------------------------------------------- +bool TMainWindow::IgnoreLocking(int error, const QString &path) +{ + QMessageBox::StandardButton answer = QMessageBox::Abort; + if (not qApp->IsTestMode()) + { + switch(error) + { + case QLockFile::LockFailedError: + answer = QMessageBox::warning(this, tr("Locking file"), + tr("This file already opened in another window. Ignore if you want " + "to continue (not recommended, can cause a data corruption)."), + QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + break; + case QLockFile::PermissionError: + answer = QMessageBox::question(this, tr("Locking file"), + tr("The lock file could not be created, for lack of permissions. " + "Ignore if you want to continue (not recommended, can cause " + "a data corruption)."), + QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + break; + case QLockFile::UnknownError: + answer = QMessageBox::question(this, tr("Locking file"), + tr("Unknown error happened, for instance a full partition " + "prevented writing out the lock file. Ignore if you want to " + "continue (not recommended, can cause a data corruption)."), + QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + break; + default: + answer = QMessageBox::Abort; + break; + } + } + + if (answer == QMessageBox::Abort) + { + qCDebug(tMainWindow, "Failed to lock %s", qUtf8Printable(path)); + qCDebug(tMainWindow, "Error type: %d", error); + if (qApp->IsTestMode()) + { + switch(error) + { + case QLockFile::LockFailedError: + qCCritical(tMainWindow, "%s", + qUtf8Printable(tr("This file already opened in another window."))); + break; + case QLockFile::PermissionError: + qCCritical(tMainWindow, "%s", + qUtf8Printable(tr("The lock file could not be created, for lack of permissions."))); + break; + case QLockFile::UnknownError: + qCCritical(tMainWindow, "%s", + qUtf8Printable(tr("Unknown error happened, for instance a full partition " + "prevented writing out the lock file."))); + break; + default: + break; + } + + qApp->exit(V_EX_NOINPUT); + } + return false; + } + return true; +} + //--------------------------------------------------------------------------------------------------------------------- void TMainWindow::SetDecimals() { diff --git a/src/app/tape/tmainwindow.h b/src/app/tape/tmainwindow.h index e55f40ffd..e9225a279 100644 --- a/src/app/tape/tmainwindow.h +++ b/src/app/tape/tmainwindow.h @@ -200,6 +200,8 @@ private: bool LoadFromExistingFile(const QString &path); void CreateWindowMenu(QMenu *menu); + + bool IgnoreLocking(int error, const QString &path); }; #endif // TMAINWINDOW_H diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index 05950ad57..6c0712a8a 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -3444,15 +3444,10 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu } else { - qCDebug(vMainWindow, "Failed to lock %s", qUtf8Printable(fileName)); - qCDebug(vMainWindow, "Error type: %d", lock->GetLockError()); - qCCritical(vMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); - Clear(); - if (not VApplication::IsGUIMode()) + if (not IgnoreLocking(lock->GetLockError(), fileName)) { - qApp->exit(V_EX_NOINPUT); + return false; } - return false; } // On this stage scene empty. Fit scene size to view size @@ -4141,3 +4136,70 @@ void MainWindow::UpdateWindowTitle() setWindowIcon(icon); #endif //defined(Q_OS_MAC) } + +//--------------------------------------------------------------------------------------------------------------------- +bool MainWindow::IgnoreLocking(int error, const QString &path) +{ + QMessageBox::StandardButton answer = QMessageBox::Abort; + if (VApplication::IsGUIMode()) + { + switch(error) + { + case QLockFile::LockFailedError: + answer = QMessageBox::warning(this, tr("Locking file"), + tr("This file already opened in another window. Ignore if you want " + "to continue (not recommended, can cause a data corruption)."), + QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + break; + case QLockFile::PermissionError: + answer = QMessageBox::question(this, tr("Locking file"), + tr("The lock file could not be created, for lack of permissions. " + "Ignore if you want to continue (not recommended, can cause " + "a data corruption)."), + QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + break; + case QLockFile::UnknownError: + answer = QMessageBox::question(this, tr("Locking file"), + tr("Unknown error happened, for instance a full partition prevented " + "writing out the lock file. Ignore if you want to continue (not " + "recommended, can cause a data corruption)."), + QMessageBox::Abort|QMessageBox::Ignore, QMessageBox::Abort); + break; + default: + answer = QMessageBox::Abort; + break; + } + } + + if (answer == QMessageBox::Abort) + { + qCDebug(vMainWindow, "Failed to lock %s", qUtf8Printable(path)); + qCDebug(vMainWindow, "Error type: %d", error); + Clear(); + if (not VApplication::IsGUIMode()) + { + switch(error) + { + case QLockFile::LockFailedError: + qCCritical(vMainWindow, "%s", + qUtf8Printable(tr("This file already opened in another window."))); + break; + case QLockFile::PermissionError: + qCCritical(vMainWindow, "%s", + qUtf8Printable(tr("The lock file could not be created, for lack of permissions."))); + break; + case QLockFile::UnknownError: + qCCritical(vMainWindow, "%s", + qUtf8Printable(tr("Unknown error happened, for instance a full partition prevented " + "writing out the lock file."))); + break; + default: + break; + } + + qApp->exit(V_EX_NOINPUT); + } + return false; + } + return true; +} diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index c0926bb6f..3411c3bc1 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -322,6 +322,8 @@ private: QString GetMeasurementFileName(); void UpdateWindowTitle(); + + bool IgnoreLocking(int error, const QString &path); }; #endif // MAINWINDOW_H