119 lines
2.6 KiB
C++
119 lines
2.6 KiB
C++
#ifndef QTAVAHIMODEL_H
|
|
#define QTAVAHIMODEL_H
|
|
|
|
#include "qtavahi.h"
|
|
|
|
#include <QAbstractItemModel>
|
|
|
|
namespace Avahi {
|
|
class BrowseModel;
|
|
|
|
namespace model {
|
|
class Row {
|
|
public:
|
|
Row(Row *parent) : m_parent(parent) { }
|
|
Row() : m_parent(0) { }
|
|
virtual ~Row();
|
|
|
|
virtual int columnCount(); /* columns of child rows */
|
|
virtual QVariant data(int col, int role) = 0;
|
|
virtual Row* index(int row);
|
|
virtual int rowCount();
|
|
|
|
Row *parent() { return m_parent; }
|
|
|
|
protected:
|
|
Row *m_parent;
|
|
};
|
|
|
|
class RowList : public Row {
|
|
public:
|
|
typedef QList< Row* > List;
|
|
|
|
RowList(Row *parent) : Row(parent) { }
|
|
RowList() : Row() { }
|
|
|
|
virtual int columnCount() = 0; /* columns of child rows */
|
|
virtual Row* index(int row);
|
|
virtual int rowCount();
|
|
|
|
protected:
|
|
friend class Avahi::BrowseModel;
|
|
|
|
List list;
|
|
};
|
|
|
|
class Entry : public Row {
|
|
public:
|
|
Entry(Row *parent, const Avahi::Service &s) : Row(parent), service(s) { }
|
|
|
|
protected:
|
|
friend class Avahi::BrowseModel;
|
|
|
|
Avahi::Service service;
|
|
};
|
|
|
|
class EntryList : public RowList {
|
|
public:
|
|
EntryList(Row *parent, const Avahi::ServiceKey &k) : RowList(parent), key(k) { }
|
|
|
|
protected:
|
|
friend class Avahi::BrowseModel;
|
|
|
|
virtual Entry* newEntry(const Avahi::Service &s, void *priv) = 0;
|
|
|
|
Avahi::ServiceKey key;
|
|
};
|
|
|
|
class Root : public RowList {
|
|
public:
|
|
virtual QVariant data(int col, int role);
|
|
|
|
virtual QVariant emptyData(int col, int role);
|
|
virtual bool emptyShowData();
|
|
|
|
protected:
|
|
friend class Avahi::BrowseModel;
|
|
|
|
virtual EntryList* newList(const Avahi::ServiceKey &k) = 0;
|
|
};
|
|
}
|
|
|
|
|
|
class BrowseModel : public QAbstractItemModel {
|
|
Q_OBJECT
|
|
|
|
protected:
|
|
typedef Avahi::model::Row Row;
|
|
typedef Avahi::model::RowList RowList;
|
|
typedef Avahi::model::Entry Entry;
|
|
typedef Avahi::model::EntryList EntryList;
|
|
|
|
Avahi::model::Root *m_root;
|
|
|
|
BrowseModel(Avahi::model::Root *root, QObject *parent = 0);
|
|
|
|
Row *getRow(const QModelIndex &index) const;
|
|
|
|
public:
|
|
int columnCount(const QModelIndex & parent) const;
|
|
QVariant data(const QModelIndex & index, int role) const;
|
|
QModelIndex index(int row, int column, const QModelIndex & parent) const;
|
|
QModelIndex parent(const QModelIndex & index) const;
|
|
int rowCount(const QModelIndex & parent) const;
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const = 0;
|
|
|
|
protected:
|
|
virtual Avahi::ServiceKey key(const Avahi::Service &s);
|
|
|
|
void insert(const Avahi::Service &s, void *priv);
|
|
void remove(const Avahi::Service &s);
|
|
|
|
private:
|
|
Avahi::Browse *m_browse;
|
|
QMap<Avahi::ServiceKey, EntryList*> m_services;
|
|
};
|
|
}
|
|
|
|
#endif // QCPMODEL_H
|