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);
44 if (forb_exception_occurred(&ev)) {
51 for (i=0; i<resources->_length && i<old->_length; i++) {
52 if (resources->_buffer[i].restype != old->_buffer[i].restype ||
53 resources->_buffer[i].resid != old->_buffer[i].resid) {
54 dataChanged(createIndex(i, 0), createIndex(i, 0));
57 if (old->_length != resources->_length) {
58 // dataChanged(createIndex(min(old->_length, resources->_length), 0),
59 // createIndex(max(old->_length, resources->_length), 0));
62 forb_free(old->_buffer);
69 int ResourceListModel::rowCount(const QModelIndex &parent) const
71 if (resources && !parent.isValid()) {
72 return resources->_length;
77 QVariant ResourceListModel::data(const QModelIndex &index, int role) const
79 if (resources && index.isValid())
84 return QVariant(QString("%1 (%2.%3)")
85 .arg(resources->_buffer[index.row()].desc.name)
86 .arg(restype2str(resources->_buffer[index.row()].restype))
87 .arg(resources->_buffer[index.row()].resid));
89 return qVariantFromValue((void*)resources->_buffer[index.row()].desc.manager);
96 Qt::ItemFlags ResourceListModel::flags(const QModelIndex &index) const
101 return Qt::ItemIsEnabled | Qt::ItemIsSelectable;