From 03831d3669ea49a99a15aaf5d17724be8c533b85 Mon Sep 17 00:00:00 2001 From: Arno Date: Wed, 20 Mar 2013 21:27:35 +0100 Subject: 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. --- smdirmodel.cpp | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'smdirmodel.cpp') 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 data = fileData(fi); - SmTreeItem *n = new SmTreeItem(data, root); - root->appendChild(n); - } +void SmDirModel::populate(SmTreeItem *root){ setRoot(root); emit needResize(); } -- cgit v1.2.3-70-g09d2