Allow user to ignore warning "This file already opened in another window".

--HG--
branch : develop
This commit is contained in:
Roman Telezhynskyi 2015-12-23 15:26:29 +02:00
parent d227ce68c2
commit 4d3aeaca08
4 changed files with 143 additions and 15 deletions

View File

@ -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()
{

View File

@ -200,6 +200,8 @@ private:
bool LoadFromExistingFile(const QString &path);
void CreateWindowMenu(QMenu *menu);
bool IgnoreLocking(int error, const QString &path);
};
#endif // TMAINWINDOW_H

View File

@ -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;
}

View File

@ -322,6 +322,8 @@ private:
QString GetMeasurementFileName();
void UpdateWindowTitle();
bool IgnoreLocking(int error, const QString &path);
};
#endif // MAINWINDOW_H