diff options
Diffstat (limited to 'smdirmodel.cpp')
-rw-r--r-- | smdirmodel.cpp | 32 |
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(); } |