added some properties and made roles dynamic based on them
authorKevron Rees <kevron_m_rees@linux.intel.com>
Sat, 12 Feb 2011 05:56:33 +0000 (21:56 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Sat, 12 Feb 2011 05:56:33 +0000 (21:56 -0800)
bluetoothdevice.cpp
bluetoothdevicemodel.cpp
bluetoothdevicemodel.h
nearbydevicesmodel.cpp

index d2183da..cd6807d 100644 (file)
@@ -190,6 +190,8 @@ void BluetoothDevice::propertyChanged(QString name,QDBusVariant value)
 {
     emit propertyChanged(name,value.variant());
 
+    qDebug()<<"BluetoothDevice::propertyChanged()";
+
     if(name == "Connected")
     {
        emit connectedChanged(value.variant().toBool());
index 663cb45..b2e6215 100644 (file)
@@ -23,9 +23,13 @@ BluetoothDevicesModel::BluetoothDevicesModel(QObject *parent) :
        adapterAdded(QDBusObjectPath());
 
        QHash<int, QByteArray> roles;
-       roles[name]="name";
-       roles[address]="address";
-       roles[path]="path";
+
+       QMetaObject properties = BluetoothDevice::staticMetaObject;
+
+       for(int i=0; i<properties.propertyCount();i++)
+       {
+               roles[i]=properties.property(i).name();
+       }
 
        setRoleNames(roles);
 }
@@ -45,32 +49,16 @@ QVariant BluetoothDevicesModel::data(const QModelIndex &index, int role) const
                return QVariant(); ///this is retarded but it has to be done.
        }
 
-       if(role == name)
-       {
-               QString rowData;
-               if(index.row() < m_devices.size())
-               {
-                       rowData = m_devices[index.row()]->name();
-               }
-               return QVariant(rowData);
-       }
-       else if(role == address)
-       {
-               QString rowData;
-               if(index.row() < m_devices.size())
-               {
-                       rowData = m_devices[index.row()]->address();
-               }
-               return QVariant(rowData);
-       }
-       else if(role == path)
+       QString roleName = roleNames()[role];
+       QMetaObject object = BluetoothDevice::staticMetaObject;
+
+       for(int i=0; i<object.propertyCount(); i++)
        {
-               QString rowData;
-               if(index.row() < m_devices.size())
+               if(object.property(i).name() == roleName)
                {
-                       rowData = m_devices[index.row()]->path();
+
+                       return object.property(i).read(m_devices[index.row()]);
                }
-               return QVariant(rowData);
        }
        return QVariant();
 }
index 2dd4aee..28a8c05 100644 (file)
@@ -14,13 +14,6 @@ class BluetoothDevicesModel : public QAbstractListModel
 public:
        explicit BluetoothDevicesModel(QObject *parent = 0);
 
-       enum Role
-       {
-               name = Qt::UserRole + 1,
-               address,
-               path
-       };
-
        bool adapterPresent() { return adapter != NULL; }
 
 public slots:
index a8fa3f0..f3e7a30 100644 (file)
@@ -128,7 +128,7 @@ void NearbyDevicesModel::deviceCreated(QString hwaddy, QVariantMap properties)
 
        if(!found)
        {
-               beginInsertRows(QModelIndex(), devices.size()+1, devices.size()+1);
+               beginInsertRows(QModelIndex(), devices.size(), devices.size());
 
                NearbyItem* item = new NearbyItem(properties["Name"].toString(),
                               hwaddy,properties["Icon"].toString(),properties["LegacyPairing"].toBool(),this);