/***************************************************************************
                publichubsmodel.h - Public Hub List Model header
                             -------------------
    begin                : Mon Nov 5 2007
    copyright            : (C) 2007 by Edward Sheldrake
    email                : ejs1920@yahoo.co.uk
 ***************************************************************************/

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

#include <QAbstractItemModel>
#include <QString>
#include <QList>

#include <dclib/dcos.h>

/**
 * @author Edward Sheldrake - inspired by dc-qt 0.2.0 alpha
 */

class PublicHubItem {

public:
	/** Constructor */
	PublicHubItem( const QString name,
		       const QString server,
		       const QString description,
		       const ulonglong users,
		       const QString country,
		       const ulonglong shared,
		       const ulonglong minshare,
		       const QString extra );
	/** Destructor */
	~PublicHubItem();

	/** Hub name */
	QString name;
	/** Hub address */
	QString server;
	/** Hub description */
	QString description;
	/** Hub user count */
	ulonglong users;
	/** Hub geographic location */
	QString country;
	/** Total shared on the hub */
	ulonglong shared;
	/** Minimum shared needed to join the hub */
	ulonglong minshare;
	/** Any extra fields from the XML hublist */
	QString extra;
};

class PublicHubsModel : public QAbstractItemModel {
Q_OBJECT

public:
	/** Constructor */
	PublicHubsModel();
	/** Destructor */
	~PublicHubsModel();
	
	/** number of rows */
	int rowCount( const QModelIndex & index ) const;
	/** number of columns */
	int columnCount( const QModelIndex & index ) const;
	/** gets data */
	QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const;
	/** gets headings */
	QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
	/** sort list */
	void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
	/** */
	QModelIndex index( int row, int column, const QModelIndex & parent ) const;
	/** */
	QModelIndex parent( const QModelIndex & parent ) const;
	
	/** adds hub */
	void addHub( const QString name,
		     const QString address,
		     const QString desc = "",
		     const ulonglong users = 0,
		     const QString country = "",
		     const ulonglong shared = 0,
		     const ulonglong minshare = 0,
		     const QString extra = "" );
	/** delete all data */
	void clear();
	/** delete the named hub */
	bool deleteHub( const QString name );
	/** get all hubs */
	QList<PublicHubItem*> getAll();
	/** get a hub */
	PublicHubItem * getItem( int row );
	/** get sort order and column */
	void getSorting( int & column, Qt::SortOrder & order ) const;

private:
	/** list of all items */
	QList<PublicHubItem*> itemList;
	/** sort column */
	int sortColumn;
	/** sort order */
	Qt::SortOrder sortOrder;
};

#endif // PUBLICHUBSMODEL_H
