2 #include "resourcelistmodel.h"
6 QString resTypeNames[] = {
14 QString restype2str(unsigned type)
16 if (type < sizeof(resTypeNames)/sizeof(*resTypeNames)) {
17 return resTypeNames[type];
19 return QString("%1").arg(type);
22 ResourceListModel::ResourceListModel(QObject *parent, forb_orb aorb) :
23 QAbstractListModel(parent),
24 orb(aorb), resources(0)
28 int ResourceListModel::update()
30 fres_contract_broker fcb;
32 fres_resource_seq *old;
35 fcb = forb_resolve_reference(orb, fres_contract_broker_reg_name);
37 //QMessageBox::warning(0, tr("Warning"), tr("Could not find contract broker."));
42 fres_contract_broker_get_resources(fcb, &resources, &ev);
43 forb_object_release(fcb);
48 for (i=0; i<resources->_length && i<old->_length; i++) {
49 if (resources->_buffer[i].restype != old->_buffer[i].restype ||
50 resources->_buffer[i].resid != old->_buffer[i].resid) {
51 dataChanged(createIndex(i, 0), createIndex(i, 0));
54 if (old->_length != resources->_length) {
55 // dataChanged(createIndex(min(old->_length, resources->_length), 0),
56 // createIndex(max(old->_length, resources->_length), 0));
59 forb_free(old->_buffer);
66 int ResourceListModel::rowCount(const QModelIndex &parent) const
68 if (resources && !parent.isValid()) {
69 return resources->_length;
74 QVariant ResourceListModel::data(const QModelIndex &index, int role) const
76 if (resources && index.isValid())
81 return QVariant(QString("%1 (%2.%3)")
82 .arg(resources->_buffer[index.row()].desc.name)
83 .arg(restype2str(resources->_buffer[index.row()].restype))
84 .arg(resources->_buffer[index.row()].resid));
86 return qVariantFromValue((void*)resources->_buffer[index.row()].desc.manager);
93 Qt::ItemFlags ResourceListModel::flags(const QModelIndex &index) const
98 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;