#ifndef DCIPFILTER_H
#define DCIPFILTER_H

#include <QObject>
#include <QRegExp>
#include <QHash>

#ifdef _DEBUG_
#include <QtDebug>
#endif

enum eREGEXP_ROLE{
    eMATCH=0,
    eNOMATCH
};

enum eDIRECTION{
    eDIRECTION_IN=0,
    eDIRECTION_OUT,
    eDIRECTION_BOTH
};

class DCIPFilter: public QObject
{
    Q_OBJECT

public:
    DCIPFilter();
    virtual ~DCIPFilter();

    void setRole(eREGEXP_ROLE role);
    eREGEXP_ROLE getRole() const;

    void loadList();
    void saveList();

    void getRules(QHash<QString, eDIRECTION> &list);

    void addToRules  (QString exp, eDIRECTION direction);
    void remFromRules(QString exp);
    void changeRuleDirection  (QString exp, eDIRECTION);
    void clearRules();

    bool OK(QString exp, eDIRECTION direction);
    bool isIP(QString &exp);

    void exportTo  (QString path);
    void importFrom(QString path);

#ifdef _DEBUG_
    void printHash();
#endif

private:

    QHash<QString, eDIRECTION> list;

    QRegExp *basic_ip;

    eREGEXP_ROLE role;

signals:
    void ruleAdded(QString, eDIRECTION);
    void ruleRemoved(QString, eDIRECTION);
    void ruleChanged(QString, eDIRECTION, eDIRECTION);
};

extern DCIPFilter *g_pIPFilter;

#endif // DCIPFILTER_H
