summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-07-29 10:08:33 +0200
committerArno <am@disconnect.de>2013-07-29 10:08:33 +0200
commit06cfadc8386aec27b9c7c43486fc0b057e9fb022 (patch)
treeca0343db7f3363fb35bd4fc0ea72779651e0361e
parent28c7436a71910aabcc37945255fb577f7a032f0d (diff)
downloadSheMov-06cfadc8386aec27b9c7c43486fc0b057e9fb022.tar.gz
SheMov-06cfadc8386aec27b9c7c43486fc0b057e9fb022.tar.bz2
SheMov-06cfadc8386aec27b9c7c43486fc0b057e9fb022.zip
Prevent datacollector from running when operating on files
This stuff was racy from the beginning. It could happen that the model got reset after we fetched the selected indexes. Add a mutex and lock it before operating on the file view. Hopefully this will many, if not all random crashes.
-rw-r--r--filesystemwidget.cpp8
-rw-r--r--newpicsdialog.cpp6
-rw-r--r--smdirmodel.h1
-rw-r--r--smdirwatcher.cpp1
-rw-r--r--smdirwatcher.h4
5 files changed, 16 insertions, 4 deletions
diff --git a/filesystemwidget.cpp b/filesystemwidget.cpp
index 4c05640..79ef2ab 100644
--- a/filesystemwidget.cpp
+++ b/filesystemwidget.cpp
@@ -163,6 +163,7 @@ void FilesystemWidget::directoryEdited(){
}
void FilesystemWidget::fileViewActivated(const QModelIndex &idx){
+ QMutexLocker l(&mFileModel->collector()->hold());
QModelIndex real = mFileProxy->mapToSource(idx);
if(mFileModel->isDir(real)){
if(idx.data().toString() == ".."){
@@ -216,6 +217,7 @@ void FilesystemWidget::goBack(){
}
void FilesystemWidget::deleteFiles(){
+ QMutexLocker l(&mFileModel->collector()->hold());
QSortFilterProxyModel *proxy = qobject_cast<QSortFilterProxyModel*>(mFileView->model());
QModelIndexList selected = mFileView->selectionModel()->selectedRows();
if(selected.isEmpty()){
@@ -233,6 +235,7 @@ void FilesystemWidget::deleteFiles(){
}
void FilesystemWidget::toClipboard(int clipmode){
+ QMutexLocker l(&mFileModel->collector()->hold());
mClipboardMode = clipmode;
QClipboard *clip = qApp->clipboard();
QModelIndexList selected = mFileView->selectionModel()->selectedRows();
@@ -309,6 +312,7 @@ void FilesystemWidget::playSelected(const QString &player){
}
void FilesystemWidget::readSettings(){
+ QMutexLocker l(&mFileModel->collector()->hold());
QSettings s;
QStringList expandedDirs = s.value("paths/expandeddirs").toStringList();
if(expandedDirs.isEmpty()){
@@ -337,6 +341,7 @@ void FilesystemWidget::readSettings(){
}
void FilesystemWidget::writeSettings(){
+ QMutexLocker l(&mFileModel->collector()->hold());
QSettings s;
s.setValue("paths/expandeddirs", mExpandedDirs);
QModelIndex currentDir = mDirView->selectionModel()->currentIndex();
@@ -356,6 +361,7 @@ void FilesystemWidget::configChanged(){
}
void FilesystemWidget::dvdMount(){
+ QMutexLocker l(&mFileModel->collector()->hold());
QSettings s;
QString mountDir = s.value("paths/dvdmount").toString();
if(isMounted()){
@@ -414,6 +420,7 @@ void FilesystemWidget::selectAllPV(){
}
void FilesystemWidget::setWindowTitle(){
+ QMutexLocker l(&mFileModel->collector()->hold());
QModelIndex curIdx = mDirView->selectionModel()->currentIndex();
QString dir = curIdx.data(QFileSystemModel::FilePathRole).toString();
mWindowTitle = QString(tr("Filemanager - [%1]")).arg(dir);
@@ -501,6 +508,7 @@ void FilesystemWidget::copyRecursive(const QFileInfo &start, const QString &dest
}
const QString FilesystemWidget::selectedDir(){
+ QMutexLocker l(&mFileModel->collector()->hold());
const QModelIndexList selected = mDirView->selectionModel()->selectedRows();
if(!selected.isEmpty()){
return selected.at(0).data(QFileSystemModel::FilePathRole).toString();
diff --git a/newpicsdialog.cpp b/newpicsdialog.cpp
index 31e14c4..1914219 100644
--- a/newpicsdialog.cpp
+++ b/newpicsdialog.cpp
@@ -7,10 +7,10 @@
#include <QSqlQuery>
#include <QSortFilterProxyModel>
-#include <QtWidgets/QPushButton>
+#include <QPushButton>
#include <QSettings>
-#include <QtWidgets/QFileDialog>
-#include <QtWidgets/QVBoxLayout>
+#include <QFileDialog>
+#include <QVBoxLayout>
#include "newpicsdialog.h"
#include "smtreeitem.h"
diff --git a/smdirmodel.h b/smdirmodel.h
index 21aab40..1c7e9b2 100644
--- a/smdirmodel.h
+++ b/smdirmodel.h
@@ -34,6 +34,7 @@ class SmDirModel : public SmTreeModel {
QDir dir() const;
QFileInfo fileInfo(const QModelIndex &idx) const;
QTimer *refresTimer() { return mRefreshTimer; }
+ SmDataColletor *collector() { return mCollector; }
public slots:
void setDir(const QString &dir);
diff --git a/smdirwatcher.cpp b/smdirwatcher.cpp
index 371e7cf..83e0efa 100644
--- a/smdirwatcher.cpp
+++ b/smdirwatcher.cpp
@@ -118,6 +118,7 @@ void SmDataColletor::setCheckForPresent(bool present){
void SmDataColletor::run(){
forever {
+ QMutexLocker l(&mHoldMx);
mSemUsed->acquire();
if(mCancel){
QSqlDatabase::database("collectordb").close();
diff --git a/smdirwatcher.h b/smdirwatcher.h
index 77d0d97..dcfc714 100644
--- a/smdirwatcher.h
+++ b/smdirwatcher.h
@@ -1,4 +1,4 @@
- /*
+/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version
@@ -54,6 +54,7 @@ class SmDataColletor : public QThread {
public:
explicit SmDataColletor(const int numFields, QObject *parent = 0);
void init(QSemaphore *set, QSemaphore *get, QQueue<QPair<QString, SmDirWatcher::DWEvent> > *data);
+ QMutex &hold() { return mHoldMx; }
public slots:
void setCheckForPresent(bool present);
@@ -77,6 +78,7 @@ class SmDataColletor : public QThread {
bool mCheckForPresent;
bool mCancel;
QMutex mCheckForPresentMx;
+ QMutex mHoldMx;
QSqlQuery *mPicPresentQ;
QSqlQuery *mMovPresentQ;
};