Hydra 0.20
|
00001 00002 /* 00003 * Copyright (c) 2010 Aleksander B. Demko 00004 * This source code is distributed under the MIT license. 00005 * See the accompanying file LICENSE.MIT.txt for details. 00006 */ 00007 00008 #ifndef __INCLUDED_HYDRA_DIRMONITOR_H__ 00009 #define __INCLUDED_HYDRA_DIRMONITOR_H__ 00010 00011 #include <set> 00012 #include <map> 00013 #include <hydra/TR1.h> 00014 00015 #include <QObject> 00016 #include <QString> 00017 #include <QStringList> 00018 #include <QFileSystemWatcher> 00019 00020 namespace hydra 00021 { 00022 void pruneDirectory(const QString &dirname); 00023 00024 class FileList; 00025 class DirChangeEvent; 00026 class DirMonitor; 00027 00028 class DirDBUpdater; 00029 } 00030 00031 /** 00032 * Emited when a directory changes. 00033 * 00034 * @author Aleksander Demko 00035 */ 00036 class hydra::DirChangeEvent : public QObject 00037 { 00038 public: 00039 QStringList addFiles, removeFiles; 00040 00041 bool isEmpty(void) const { return addFiles.isEmpty() && removeFiles.isEmpty(); } 00042 00043 void debugPrint(void); 00044 }; 00045 00046 /** 00047 * Monitors one or more directories. 00048 * 00049 * @author Aleksander Demko 00050 */ 00051 class hydra::DirMonitor : public QObject 00052 { 00053 Q_OBJECT 00054 00055 protected: 00056 class MarkList;//fwd/internal class 00057 public: 00058 /// constructor 00059 DirMonitor(void); 00060 00061 void addPath(const QString &path); 00062 void removePath(const QString &path); 00063 00064 signals: 00065 void dirChange(const QString &path, const DirChangeEvent &); 00066 00067 private slots: 00068 void onDirChanged(const QString &dir); 00069 void onTimer(void); 00070 00071 private: 00072 void reloadDirs(void); 00073 void reloadDir(MarkList &marklist, DirChangeEvent &outevent); 00074 00075 private: 00076 QFileSystemWatcher dm_watcher; 00077 00078 bool dm_queued; 00079 bool dm_requeue; 00080 00081 typedef std::map<QString, std::shared_ptr<MarkList> > marklists_t; 00082 marklists_t dm_marklists; 00083 }; 00084 00085 /** 00086 * This is a class that can listen to DirChangeEvent events and update 00087 * the DB (via the singleton Engine class). 00088 * 00089 * @author Aleksander Demko 00090 */ 00091 class hydra::DirDBUpdater : public QObject 00092 { 00093 Q_OBJECT 00094 00095 public: 00096 DirDBUpdater(void); 00097 00098 public slots: 00099 /// connect this to dirChange signal of a DirMonitor 00100 void dirChanged(const QString &path, const DirChangeEvent &); 00101 }; 00102 00103 #endif 00104