/***************************************************************************
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef DCFILEBROWSERSEARCHENGINE_H
#define DCFILEBROWSERSEARCHENGINE_H

#include <QThread>
#include <QTreeView>
#include <QMap>

class FileBrowserItem;
class FileBrowserModel;

typedef QMap<FileBrowserItem*,FileBrowserItem*> FileBrowserItemMap;

class DCFileBrowserSearchEngine : public QThread
{
    Q_OBJECT
public:
    enum Type{
        All=0,
        Files,
        Directories
    };

    enum State{
        INT=0,
        RUN,
        DONE
    };

    DCFileBrowserSearchEngine(FileBrowserModel*);
    ~DCFileBrowserSearchEngine();

    void run();
    void search(QList<FileBrowserItem*>&);
    void stop();
    void reset();

    void setType(Type t);
    void setString(const QString&);

    FileBrowserItem *mapToOldModel(FileBrowserItem*);
    FileBrowserModel *getOldModel();

    State state() const;
signals:
    void modelCreated(FileBrowserModel*);
    void done();
    void newElement(FileBrowserItem*);
    void stateChanged(DCFileBrowserSearchEngine::State);
private:
    QTreeView *view;
    FileBrowserItem *root;
    FileBrowserModel *old_model;
    FileBrowserModel *model;

    Type type;
    State engine_state;

    QString src_str;

    FileBrowserItemMap map;
};

Q_DECLARE_METATYPE(DCFileBrowserSearchEngine::State)

#endif // DCFILEBROWSERSEARCHENGINE_H
