summaryrefslogtreecommitdiffstats
path: root/smdirmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'smdirmodel.cpp')
-rw-r--r--smdirmodel.cpp29
1 files changed, 27 insertions, 2 deletions
diff --git a/smdirmodel.cpp b/smdirmodel.cpp
index 0a0578b..9b35706 100644
--- a/smdirmodel.cpp
+++ b/smdirmodel.cpp
@@ -8,6 +8,7 @@
#include <QDir>
#include <QDateTime>
#include <QFile>
+#include <QTimer>
#include <sys/stat.h>
@@ -18,10 +19,17 @@
SmDirModel::SmDirModel(const QStringList &headers, QObject *parent) : SmTreeModel(headers, parent), mHeaders(headers){
mWatch = new SmDirWatcher(this);
+ connect(mWatch, SIGNAL(dwEvent(QString,int)), this, SLOT(dirEvent(QString,int)));
+ connect(mWatch, SIGNAL(needRefresh()), this, SLOT(populate()));
+ mRunTimer = new QTimer(this);
+ mRunTimer->setInterval(2000);
+ connect(mRunTimer, SIGNAL(timeout()), mWatch, SLOT(start()));
+ mRunTimer->start();
}
SmDirModel::~SmDirModel(){
delete mWatch;
+ delete mRunTimer;
}
QVariant SmDirModel::data(const QModelIndex &index, int role) const{
@@ -65,9 +73,8 @@ bool SmDirModel::setData(const QModelIndex &index, const QVariant &value, int ro
QString dir = fileInfo(index).absolutePath();
QString newPath = QString("%1/%2").arg(dir).arg(newName);
QFile::rename(old, newPath);
- return true;
}
- return false;
+ return SmTreeModel::setData(index, value, role);
}
bool SmDirModel::isDir(const QModelIndex &idx) const {
@@ -97,6 +104,24 @@ void SmDirModel::setDir(const QString &dir){
mWatch->setDir(dir);
}
+void SmDirModel::dirEvent(const QString &file, int e){
+ QFileInfo fi(file);
+ const QList<QVariant> fData = fileData(fi);
+ if(e == SmDirWatcher::Added){
+ addRow(fData, rootIndex(), true);
+ }
+ QModelIndex idx = find(fData.at(Name), Name, rootIndex());
+ if(e == SmDirWatcher::Deleted){
+ removeRow(idx.row());
+ }
+ if(e == SmDirWatcher::Modified){
+ for(int i = 0; i < mHeaders.count(); ++i){
+ QModelIndex c = index(idx.row(), i, QModelIndex());
+ setData(c, fData.at(i), Qt::EditRole);
+ }
+ }
+}
+
void SmDirModel::populate(){
SmTreeItem *root = new SmTreeItem(mHeaders.size());
QDir d = QDir(mCur);