summaryrefslogtreecommitdiffstats
path: root/smdirmodel.cpp
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-03-20 21:27:35 +0100
committerArno <am@disconnect.de>2013-03-20 21:27:35 +0100
commit03831d3669ea49a99a15aaf5d17724be8c533b85 (patch)
tree618e3fe63b0430a4dbe604153ab588eb811fd183 /smdirmodel.cpp
parent457e5328c8fbbf236fb163e90d732a35a583fd2d (diff)
downloadSheMov-03831d3669ea49a99a15aaf5d17724be8c533b85.tar.gz
SheMov-03831d3669ea49a99a15aaf5d17724be8c533b85.tar.bz2
SheMov-03831d3669ea49a99a15aaf5d17724be8c533b85.zip
Use a Thread for collecting file data
blocking the GUI isn't nice, so use a separate Thread to gather all the data for SmDirModel. Populating and changing directory works, but modifying a file is most likely broken.
Diffstat (limited to 'smdirmodel.cpp')
-rw-r--r--smdirmodel.cpp32
1 files changed, 12 insertions, 20 deletions
diff --git a/smdirmodel.cpp b/smdirmodel.cpp
index cf2197a..914acff 100644
--- a/smdirmodel.cpp
+++ b/smdirmodel.cpp
@@ -21,14 +21,18 @@
#include "helper.h"
SmDirModel::SmDirModel(const QStringList &headers, QObject *parent) : SmTreeModel(headers, parent), mHeaders(headers){
+ mCollector = new SmDataGatherer(NumFields, this);
+
mWatch = new SmDirWatcher(this);
connect(mWatch, SIGNAL(dwEvent(QString,int)), this, SLOT(dirEvent(QString,int)));
- connect(mWatch, SIGNAL(needRefresh()), this, SLOT(populate()));
+ connect(mWatch, SIGNAL(needRefresh()), this, SLOT(refresh()));
mRunTimer = new QTimer(this);
mRunTimer->setInterval(2000);
connect(mRunTimer, SIGNAL(timeout()), mWatch, SLOT(start()));
mRunTimer->start();
readSettings();
+
+ connect(mCollector, SIGNAL(population(SmTreeItem*)), this, SLOT(populate(SmTreeItem*)));
}
SmDirModel::~SmDirModel(){
@@ -112,13 +116,10 @@ QFileInfo SmDirModel::fileInfo(const QModelIndex &idx) const {
}
void SmDirModel::setDir(const QString &dir){
- QFileInfo fi(dir);
- if(!fi.isDir()){
- return;
- }
- mCur = dir;
- populate();
- mWatch->setDir(dir);
+ mCurrentDir = dir;
+ mCollector->setCurrent(mCurrentDir);
+ mCollector->start();
+ mWatch->setDir(mCurrentDir);
}
void SmDirModel::dirEvent(const QString &file, int e){
@@ -154,20 +155,11 @@ void SmDirModel::readSettings(){
}
void SmDirModel::refresh(){
- populate();
+ mCollector->setCurrent(mCurrentDir);
+ mCollector->start();
}
-void SmDirModel::populate(){
- SmTreeItem *root = new SmTreeItem(mHeaders.size());
- QDir d = QDir(mCur);
- foreach(QFileInfo fi, d.entryInfoList()){
- if(fi.fileName() == "."){
- continue;
- }
- QList<QVariant> data = fileData(fi);
- SmTreeItem *n = new SmTreeItem(data, root);
- root->appendChild(n);
- }
+void SmDirModel::populate(SmTreeItem *root){
setRoot(root);
emit needResize();
}