/***************************************************************************
 *                                                                         *
 *   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 HUBLISTMODEL_H
#define HUBLISTMODEL_H

#include <QAbstractItemModel>

#define COLUMN_HUB_AUTOCONNECT      0
#define COLUMN_HUB_NAME             1
#define COLUMN_HUB_ADDRESS          2
#define COLUMN_HUB_NICK             3
#define COLUMN_HUB_PASSWORD         4
#define COLUMN_HUB_DESC             5
#define COLUMN_HUB_ENCODING         6

class HubListModelItem{

public:

    HubListModelItem(const QList<QVariant> &data, HubListModelItem *parent = NULL);
    ~HubListModelItem();

    void appendChild(HubListModelItem *child);

    HubListModelItem *child(int row);
    int childCount() const;
    int columnCount() const;
    QVariant data(int column) const;
    int row() const;
    HubListModelItem *parent();

    QList<HubListModelItem*> childItems;

    void updateColumn(unsigned, QVariant);

    int position;

private:
    QList<QVariant> itemData;
    HubListModelItem *parentItem;
};

class HubListModel : public QAbstractItemModel
{
    Q_OBJECT
public:
    HubListModel(QObject *parent = 0);
    virtual ~HubListModel();

    /** */
    QVariant data(const QModelIndex &, int) const;
    /** */
    Qt::ItemFlags flags(const QModelIndex &) const;
    /** */
    QVariant headerData(int section, Qt::Orientation, int role = Qt::DisplayRole) const;
    /** */
    QModelIndex index(int, int, const QModelIndex &parent = QModelIndex()) const;
    /** */
    QModelIndex parent(const QModelIndex &index) const;
    /** */
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    /** */
    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    /** sort list */
    virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);

    /** */
    void addResult(QList<QVariant> &data);
    /** */
    const QList<HubListModelItem*> &getItems();

    /** Clear the model and redraw it*/
    void clearModel();

    /** */
    bool removeItem(const QModelIndex&);

    /** */
    void moveUp(const QModelIndex&);
    /** */
    void moveDown(const QModelIndex&);

    /** */
    void repaint();

private:

    HubListModelItem *rootItem;

};

#endif // HUBLISTMODEL_H
