#ifndef DCINOTIFYCONTROL_H
#define DCINOTIFYCONTROL_H

#ifndef WIN32

#include <QDialog>
#include <QWidget>
#include <QList>
#include <QMutex>
#include <QTimer>
#include <QMap>
#include <QMapIterator>
#include <QTreeWidgetItem>
#include <QCloseEvent>

#include <dclib/core/cstring.h>
#include <dclib/core/cdir.h>
#include <dclib/cfilemanager.h>

#include "DCDialogInotify.h"
#include "dcinotify.h"
#include "dcfilelistdecompressor.h"

class DCInotifyControl : public QDialog, private Ui::DCDialogInotify {
    Q_OBJECT

public:
    DCInotifyControl(QWidget *parent = 0);
    ~DCInotifyControl();

    bool isInitialized() const;
    void Shutdown();

    /** */
    static void SetInstance(DCInotifyControl*);
    /** */
    static DCInotifyControl *Instance();

protected:
    virtual void closeEvent(QCloseEvent *e);

private:
    void InitDocument();
    void LoadDirs();
    void ReinitInotify();

    QList<QString> dirs;
    QList<InotifyObject*> events;
    QMap<QString, eIEVENT_OBJ> moved;
    QMap<QString, eIEVENT_OBJ> created;
    QMap<QString, eIEVENT_OBJ> deleted;
    QMap<QString, eIEVENT_OBJ> changed;
    QMap<QString, int> changed_files;

    QTreeWidgetItem *active_item;

    DCInotify *inotify;

    QString eis_path;

    QMutex mutex;

    QTimer *timer;
    QTimer *collector;

    bool m_bIsInitialized;
    bool shutdown;
    bool pending;

    static DCInotifyControl *pInotifyControl;

private slots:
    void slotAccept();
    void slotFSEvent(InotifyObject*);
    void slotTimerDone();
    void slotInotifyActionChange();
    void slotInotifyFilterChange();
    void slotLogOnly();
    void slotTimerIntervalChanged(int m);
    void slotCollectorStart();
    void slotRestoreShareList();
    void slotRemoveSelectedItem();
    void slotTreeWidgetItemClicked(QTreeWidgetItem*, int);
    void slotApply();
    //void slotCurrentTabChanged(int);

};

/** */
inline void DCInotifyControl::SetInstance(DCInotifyControl *ic) {
    pInotifyControl = ic;
}

/** */
inline DCInotifyControl *DCInotifyControl::Instance() {
    return pInotifyControl;
}

#endif //WIN32

#endif
