diff options
author | Arno <am@disconnect.de> | 2013-03-21 16:14:54 +0100 |
---|---|---|
committer | Arno <am@disconnect.de> | 2013-03-21 16:14:54 +0100 |
commit | ce402f298b2f9733b614fbf1bde99a052d0ab5c0 (patch) | |
tree | 26da14cacb2e4fffcab47cf0a61d066568a15e7a /smdirwatcher.h | |
parent | 03831d3669ea49a99a15aaf5d17724be8c533b85 (diff) | |
download | SheMov-ce402f298b2f9733b614fbf1bde99a052d0ab5c0.tar.gz SheMov-ce402f298b2f9733b614fbf1bde99a052d0ab5c0.tar.bz2 SheMov-ce402f298b2f9733b614fbf1bde99a052d0ab5c0.zip |
Final inotify!
A huge commit, I know, but it was definitely worth it! It makes the
homebrew FilesystemModel work! It's divided up into two threads:
1. The Watcher: it reacts on inotify events and dispatches them to:
2. The Collector: this thread gathers the data and emits the SIGNALS to
the the view.
Now we can actually refresh the View, not possible with
QFileSystemModel, and the data reloads in almost real time without
blocking the GUI.
Unfortunately this uncovered some bugs I had to fix:
1. Helper::md5sum: Don't crash if read fails with -1
2. SmTreeModel::addRow is broken. Even after 5h I couldn't figure out
how or why, so I brute forced it. Reset the moded when a file is added.
3. Get rid of a lot of unneeded #include's
I guess that's about it...
Diffstat (limited to 'smdirwatcher.h')
-rw-r--r-- | smdirwatcher.h | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/smdirwatcher.h b/smdirwatcher.h index 3167aeb..19cd746 100644 --- a/smdirwatcher.h +++ b/smdirwatcher.h @@ -9,18 +9,21 @@ #define SMDIRWATCHER_H #include <QThread> -#include <QMutex> #include <QList> #include <QVariant> #include <QFileInfo> +#include <QQueue> class SmTreeItem; +class QSemaphore; +class SmDataColletor; class SmDirWatcher : public QThread { Q_OBJECT public: - enum DWEvent { Added, Deleted, Modified }; + enum DWEvent { None, Added, Deleted, Modified, Populate }; explicit SmDirWatcher(QObject *parent = 0); + SmDataColletor *collector() { return mCollector; } ~SmDirWatcher(); signals: @@ -34,20 +37,23 @@ class SmDirWatcher : public QThread { private: int mFd; int mDescr; - QMutex mWatchMx; QString mCurrent; + SmDataColletor *mCollector; + QSemaphore *mSemFree; + QSemaphore *mSemUsed; + QQueue<QPair<QString, DWEvent> > *mDataQueue; + char *mINdata; + int mBufLen; }; -class SmDataGatherer : public QThread { +class SmDataColletor : public QThread { Q_OBJECT public: - explicit SmDataGatherer(const int numFields, QObject *parent = 0); - void setCurrent(const QString ¤t, int mode = -1); + explicit SmDataColletor(const int numFields, QObject *parent = 0); + void init(QSemaphore *set, QSemaphore *get, QQueue<QPair<QString, SmDirWatcher::DWEvent> > *data); public slots: void run(); - //void setFile(const QString &fullPath, int event); - //void populate(const QString &dir); signals: void newData(const QList<QVariant>,int); @@ -55,12 +61,12 @@ class SmDataGatherer : public QThread { void needRefresh(); private: - //QList<QList<QVariant> > populate(); - SmTreeItem *populate(); + SmTreeItem *populate(const QString &dir); const QList<QVariant> fileData(const QFileInfo &fi) const; QString mCurrent; - QMutex mRunMx; - QMutex mSetMx; + QSemaphore *mSemFree; + QSemaphore *mSemUsed; + QQueue<QPair<QString, SmDirWatcher::DWEvent> > *mDataQueue; int mMode; const int mNumFields; }; |