diff options
author | Arno <am@disconnect.de> | 2013-03-17 02:18:31 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2013-03-17 02:18:31 +0100 |
commit | 744c94e9a1197068457cc52dde57472cb89e1819 (patch) | |
tree | c63a58130254ce40be1cc77257145fb41524ad63 /smdirmodel.cpp | |
parent | 4c8aae81b91deac9d95a1f0f50ef30641bb8638a (diff) | |
download | SheMov-744c94e9a1197068457cc52dde57472cb89e1819.tar.gz SheMov-744c94e9a1197068457cc52dde57472cb89e1819.tar.bz2 SheMov-744c94e9a1197068457cc52dde57472cb89e1819.zip |
Make SmDirModel/SmDirWatcher do something
I think I got it working! It does what I want it to do :)
Diffstat (limited to 'smdirmodel.cpp')
-rw-r--r-- | smdirmodel.cpp | 29 |
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); |