fixed issues with -1 index because deviceCreated was telling the view the wrong index
authorKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 17 Dec 2010 22:49:13 +0000 (14:49 -0800)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Fri, 17 Dec 2010 22:49:13 +0000 (14:49 -0800)
bluetoothdevice.h
bluetoothdevicemodel.cpp
bluetoothdevicemodel.h

index 590bda8..422fb25 100644 (file)
@@ -13,12 +13,12 @@ class BluetoothDevice : public QObject
 {
     Q_OBJECT   
        Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged);
-       /*Q_PROPERTY(QStringList profiles READ profiles)
+       Q_PROPERTY(QStringList profiles READ profiles)
        Q_PROPERTY(QString alias READ alias)
        Q_PROPERTY(QString name READ name)
        Q_PROPERTY(QString address READ address)
        Q_PROPERTY(QString icon READ icon)
-       Q_PROPERTY(QString path READ path)*/
+       Q_PROPERTY(QString path READ path)
 
 public:
        explicit BluetoothDevice(QDBusObjectPath path = QDBusObjectPath(), QObject *parent = 0);
index 91abac9..7b05953 100644 (file)
@@ -37,7 +37,13 @@ int BluetoothDevicesModel::rowCount(const QModelIndex &) const
 
 QVariant BluetoothDevicesModel::data(const QModelIndex &index, int role) const
 {
-       if(index.row() < 0) return QVariant(); ///this is retarded but it has to be done.
+       qDebug()<<"requested role: "<<roleNames()[role];
+
+       if(!index.isValid() || index.row() < 0)
+       {
+               qDebug()<<"index is not valid: "<<index.row()<<","<<index.column();
+               return QVariant(); ///this is retarded but it has to be done.
+       }
 
        if(role == name)
        {
@@ -145,7 +151,7 @@ void BluetoothDevicesModel::deviceCreated(QDBusObjectPath devicepath)
 
        connect(device,SIGNAL(propertyChanged(QString,QVariant)),this,SLOT(devicePropertyChanged(QString,QVariant)));
 
-       beginInsertRows(QModelIndex(),m_devices.size()+1,m_devices.size()+1);
+       beginInsertRows(QModelIndex(),m_devices.size(),m_devices.size());
        m_devices.append(device);
        endInsertRows();
 }
@@ -167,10 +173,17 @@ void BluetoothDevicesModel::deviceRemoved(QDBusObjectPath devicepath)
 
 void BluetoothDevicesModel::devicePropertyChanged(QString name, QVariant value)
 {
+       BluetoothDevice* device = qobject_cast<BluetoothDevice*>(sender());
+
+       qDebug()<<"device property changed for "<<device->address()<<": "<<name<<" "<<value;
+
        if(name == "Paired" && value.toBool() == true)
        {
-               qDebug()<<"device property changed: "<<name<<" "<<value;
-               BluetoothDevice* device = qobject_cast<BluetoothDevice*>(sender());
                emit devicePaired(device);
        }
+
+       int row = m_devices.indexOf(device);
+       if(row == -1) return; ///device doesn't exist.
+
+       dataChanged(createIndex(row, 0),createIndex(row, 0));
 }
index 150a475..f8f2daf 100644 (file)
@@ -40,7 +40,7 @@ private slots:
        void devicePropertyChanged(QString name, QVariant value);
 
 signals:
-       void devicePaired(BluetoothDevice*);
+       void devicePaired(BluetoothDevice* device);
 
 private:
        OrgBluezManagerInterface *manager;