From 818cf7747ca016017e046d7f1a4cf132aa4d7877 Mon Sep 17 00:00:00 2001 From: dismine Date: Fri, 28 Nov 2014 18:50:22 +0200 Subject: [PATCH] Lock pattern file. Filter list files for restore. --HG-- branch : develop --- src/app/mainwindow.cpp | 52 ++++++++++++++++++++++++++++++++++++++---- src/app/mainwindow.h | 2 ++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index 5b87a3d00..c536ae6a2 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -76,7 +76,7 @@ MainWindow::MainWindow(QWidget *parent) comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0), currentToolBoxIndex(0), drawMode(true), recentFileActs(), separatorAct(nullptr), autoSaveTimer(nullptr), guiEnabled(true), gradationHeights(nullptr), - gradationSizes(nullptr), toolOptions(nullptr) + gradationSizes(nullptr), toolOptions(nullptr), lock(nullptr) { for (int i = 0; i < MaxRecentFiles; ++i) { @@ -1436,6 +1436,7 @@ void MainWindow::Clear() { qCDebug(vMainWindow)<<"Reseting main window"; + delete lock; // Unlock pattern file ui->actionDetails->setChecked(false); ui->actionDetails->setEnabled(false); ui->actionDraw->setChecked(true); @@ -2273,6 +2274,7 @@ MainWindow::~MainWindow() { CancelTool(); + delete lock; // Unlock pattern file delete pattern; delete doc; delete sceneDetails; @@ -2370,13 +2372,57 @@ void MainWindow::LoadPattern(const QString &fileName) ZoomFirstShow(); ui->actionDraw->setChecked(true); + + qCDebug(vMainWindow)<<"Loking file"; + lock = new QLockFile(curFile+".lock"); + lock->setStaleLockTime(0); + if (lock->tryLock()) + { + qCDebug(vMainWindow) << "Log file"<error(); + } } } +//--------------------------------------------------------------------------------------------------------------------- +QStringList MainWindow::GetUnlokedRestoreFileList() const +{ + QStringList restoreFiles; + QStringList files = qApp->getSettings()->GetRestoreFileList(); + if (files.size() > 0) + { + for (int i = 0; i < files.size(); ++i) + { + // Seeking file that realy need reopen + QLockFile *lock = new QLockFile(files.at(i)+".lock"); + lock->setStaleLockTime(0); + if (lock->tryLock()) + { + restoreFiles.append(files.at(i)); + } + delete lock; + } + + // Clearing list after filtering + for (int i = 0; i < restoreFiles.size(); ++i) + { + files.removeAll(restoreFiles.at(i)); + } + + qApp->getSettings()->SetRestoreFileList(files); + + } + return restoreFiles; +} + //--------------------------------------------------------------------------------------------------------------------- void MainWindow::ReopenFilesAfterCrash(QStringList &args) { - QStringList files = qApp->getSettings()->GetRestoreFileList(); + const QStringList files = GetUnlokedRestoreFileList(); if (files.size() > 0) { qCDebug(vMainWindow)<<"Reopen files after crash."; @@ -2390,8 +2436,6 @@ void MainWindow::ReopenFilesAfterCrash(QStringList &args) restoreFiles.append(files.at(i)); } } - files.clear(); - qApp->getSettings()->SetRestoreFileList(files); if (restoreFiles.size() > 0) { diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index 11dba397d..b93d10c41 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -204,6 +204,7 @@ private: QComboBox *gradationHeights; QComboBox *gradationSizes; VToolOptionsPropertyBrowser *toolOptions; + QLockFile *lock; void ToolBarOption(); void ToolBarDraws(); @@ -258,6 +259,7 @@ private: void PropertyBrowser(); void OpenNewValentina(const QString &fileName = QString())const; void FileClosedCorrect(); + QStringList GetUnlokedRestoreFileList()const; }; #endif // MAINWINDOW_H