diff options
Diffstat (limited to 'smdirwatcher.h')
-rw-r--r-- | smdirwatcher.h | 93 |
1 files changed, 58 insertions, 35 deletions
diff --git a/smdirwatcher.h b/smdirwatcher.h index fccc1ed..9ec9181 100644 --- a/smdirwatcher.h +++ b/smdirwatcher.h @@ -1,4 +1,4 @@ - /* +/* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version @@ -16,73 +16,96 @@ #include <QMutex> #include <QSqlDatabase> #include <QSqlQuery> +#include <QThreadPool> +#include <QRunnable> class SmTreeItem; class QSemaphore; class SmDataColletor; +class AsyncTask; +class Md5Summer; class SmDirWatcher : public QThread { Q_OBJECT public: - enum DWEvent { None, Added, Deleted, Modified, Populate }; + enum DWEvent { None, Added, Deleted, Modified, Populate, CloseWrite }; explicit SmDirWatcher(int numFields, QObject *parent = 0); - SmDataColletor *collector() { return mCollector; } signals: void dwEvent(const QString& file, int event); + void setMd5Sum(QString path, QString md5); + void setFfmpeg(QString path, QVariantMap data); + void setPicSize(QString path, QVariant size); void needRefresh(); + void population(SmTreeItem*); + void newData(const QList<QVariant>,int); public slots: void run(); void stop(); void setDir(const QString &dir); + void startAsyncJobs(); + void gatherAsync(const QString &path); private: + QList<QVariant> generalData(const QString &path); int mFd; int mDescr; QString mCurrent; - SmDataColletor *mCollector; - QSemaphore *mSemFree; - QSemaphore *mSemUsed; - QQueue<QPair<QString, DWEvent> > *mDataQueue; - QMutex *mQueueMx; char *mINdata; int mBufLen; + QThreadPool *mAsyncPool; + int mNumFields; + QList<AsyncTask*> mAsyncTasks; }; -class SmDataColletor : public QThread { +class AsyncTask : public QObject, public QRunnable { Q_OBJECT public: - explicit SmDataColletor(const int numFields, QObject *parent = 0); - void init(QSemaphore *set, QSemaphore *get, QQueue<QPair<QString, SmDirWatcher::DWEvent> > *data, QMutex *queueMx); + explicit AsyncTask(const QString &path = QString()); + bool skipMe(); - public slots: - void setCheckForPresent(bool present); - void run(); - void stop() { mCancel = true; } + protected: + virtual void run() = 0; + bool mSkip; + QMutex mStatusMx; + const QString mPath; +}; + +class Md5Summer : public AsyncTask { + Q_OBJECT + public: + explicit Md5Summer(const QString &path); signals: - void newData(const QList<QVariant>,int); - void population(SmTreeItem*); - void needRefresh(); - void totalFiles(int numFiles); - void progress(); + void md5sumDone(QString, QString); - private: - SmTreeItem *populate(const QString &dir); - const QList<QVariant> fileData(const QFileInfo &fi); - QString mCurrent; - QSemaphore *mSemFree; - QSemaphore *mSemUsed; - QMutex *mQueueMx; - QQueue<QPair<QString, SmDirWatcher::DWEvent> > *mDataQueue; - int mMode; - const int mNumFields; - bool mCheckForPresent; - bool mCancel; - QMutex mCheckForPresentMx; - QSqlQuery *mPicPresentQ; - QSqlQuery *mMovPresentQ; + protected: + virtual void run(); +}; + +class FfmpegGatherer : public AsyncTask { + Q_OBJECT + public: + explicit FfmpegGatherer(const QString &path); + + signals: + void ffmpegDone(QString, QVariantMap); + + protected: + virtual void run(); +}; + +class PicSizeGatherer : public AsyncTask { + Q_OBJECT + public: + explicit PicSizeGatherer(const QString &path); + + signals: + void picSizeDone(QString, QVariant); + + protected: + virtual void run(); }; #endif // SMDIRWATCHER_H |