summaryrefslogtreecommitdiffstats
path: root/smdirwatcher.h
diff options
context:
space:
mode:
authorArno <am@disconnect.de>2013-09-03 06:12:33 +0200
committerArno <am@disconnect.de>2013-09-03 06:12:33 +0200
commit130e0a3115cd66e38ec57846e06f69e7fd284400 (patch)
treedd2a1cd7eaa32d1f515ec45bdc009e7cbbb354aa /smdirwatcher.h
parent3f0a819948d36d06f1ddf07e5a51ff771ddda4da (diff)
downloadSheMov-130e0a3115cd66e38ec57846e06f69e7fd284400.tar.gz
SheMov-130e0a3115cd66e38ec57846e06f69e7fd284400.tar.bz2
SheMov-130e0a3115cd66e38ec57846e06f69e7fd284400.zip
Switch to QRunnable + QThreadPool
Get rid of SmDataCollector and do its job in small, QRunnable tasks and let QThreadPool manage the treads. Works well with a local Filesystem. Yet to see how it works over networked Filesystems. Ah, before I forget: NEVER, EVER USE QPixmap in THREADS -> Random crashes! (Yes, I know, it's documented...)
Diffstat (limited to 'smdirwatcher.h')
-rw-r--r--smdirwatcher.h93
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