return "";
}
+void AsyncAgent::release()
+{
+ qDebug("releasing!");
+ if (!QMetaObject::invokeMethod(parent(), "release", Qt::QueuedConnection))
+ qDebug("sending relay signal failed!!!");
+}
+
void AsyncAgent::replyRequestConfirmation(bool confirmed)
{
if(!confirmed)
{
- reject();
+ qDebug("rejecting");
+ QDBusMessage reply = pendingMessage.createErrorReply("org.bluez.Error.Rejected", "The request was rejected");
+ m_connection.send(reply);
}
else
{
+ qDebug("accepting");
QDBusMessage reply = pendingMessage.createReply();
m_connection.send(reply);
}
void requestConfirmation(OrgBluezDeviceInterface &device, uint key);
uint requestPasskey(OrgBluezDeviceInterface &device);
QString requestPidCode(OrgBluezDeviceInterface &device);
+ void release();
signals:
return "";
}
-void BluetoothBaseAgent::accept()
-{
- requestAccepted = true;
-}
-
-void BluetoothBaseAgent::doReject()
-{
- if(requestAccepted)
- {
- requestAccepted=false;
- return;
- }
- reject();
-}
virtual uint requestPasskey(OrgBluezDeviceInterface &device);
virtual QString requestPidCode(OrgBluezDeviceInterface &device);
- virtual void reject() { sendErrorReply("org.bluez.Error.Rejected", "The request was rejected"); }
-
- virtual void accept();
- virtual void doReject();
private:
bool requestAccepted;
};
return props["Connected"].toBool();
}
-QString BluetoothDevice::connectedProfile()
-{
- foreach(QString profile, profiles())
- {
- if(profile == BluetoothProfiles::a2sink)
- {
- OrgBluezAudioSinkInterface sink("org.bluez",m_device->path(),
- QDBusConnection::systemBus());
- if(sink.IsConnected())
- return BluetoothProfiles::a2sink;
- }
- else if(profile == BluetoothProfiles::a2src)
- {
- OrgBluezAudioSourceInterface source("org.bluez",m_device->path(),
- QDBusConnection::systemBus());
- QVariantMap props = source.GetProperties();
-
- if(props["State"].toString() == "connected")
- {
- return BluetoothProfiles::a2src;
- }
-
- }
- else if(profile == BluetoothProfiles::hs)
- {
- OrgBluezHeadsetInterface headset("org.bluez",m_device->path(),
- QDBusConnection::systemBus());
- if(headset.IsConnected())
- {
- return BluetoothProfiles::hs;
- }
- }
- }
-}
-
QString BluetoothDevice::alias()
{
QVariantMap props = m_device->GetProperties();
void BluetoothDevice::propertyChanged(QString name,QDBusVariant value)
{
+ emit propertyChanged(name,value.variant());
+
if(name == "Connected")
{
emit connetedChanged();
signals:
void connetedChanged();
+ void propertyChanged(QString name, QVariant value);
public slots:
void unpair();
QStringList profiles();
bool isProfileSupported(QString profile);
- QString connectedProfile();
///properties:
bool connected();
if(device->path() == path)
return device;
}
+ return NULL;
}
void BluetoothDevicesModel::adapterAdded(QDBusObjectPath path)
QList<QDBusObjectPath> list = adapter->ListDevices();
foreach(QDBusObjectPath item, list)
{
- m_devices.append(new BluetoothDevice(item));
+ deviceCreated(item);
}
}
void BluetoothDevicesModel::deviceCreated(QDBusObjectPath devicepath)
{
+ BluetoothDevice* device = new BluetoothDevice(devicepath,this);
+
+ connect(device,SIGNAL(propertyChanged(QString,QVariant)),this,SLOT(devicePropertyChanged(QString,QVariant)));
beginInsertRows(QModelIndex(),m_devices.size()+1,m_devices.size()+1);
- m_devices.append(new BluetoothDevice(devicepath));
+ m_devices.append(device);
endInsertRows();
}
if(m_devices[i]->path() == devicepath.path())
{
beginRemoveRows(QModelIndex(), i, i);
- delete m_devices[i];
+ m_devices[i]->deleteLater();
m_devices.removeAt(i);
endRemoveRows();
}
}
}
+
+void BluetoothDevicesModel::devicePropertyChanged(QString name, QVariant value)
+{
+ if(name == "Paired" && value.toBool() == true)
+ {
+ qDebug()<<"device property changed: "<<name<<" "<<value;
+ BluetoothDevice* device = qobject_cast<BluetoothDevice*>(sender());
+ emit devicePaired(device);
+ }
+}
void deviceCreated(QDBusObjectPath);
void deviceRemoved(QDBusObjectPath);
+ void devicePropertyChanged(QString name, QVariant value);
+signals:
+ void devicePaired(BluetoothDevice*);
private:
OrgBluezManagerInterface *manager;
qDebug()<<"attempting to pair with "<<hwaddy;
if(!adapter) return;
- agent = new AsyncAgent("/temp/agent",this);
+ agent = new AsyncAgent("/temp/agent", this);
adapter->CreatePairedDevice(hwaddy,
QDBusObjectPath("/temp/agent"),"");
void NearbyDevicesModel::replyRequestConfirmation(bool confirmed)
{
+ qDebug()<<"reply to RequestConfirmation:"<<confirmed;
if(agent) agent->replyRequestConfirmation(confirmed);
}
void requestConfirmation(QString device, uint code);
void requestPasskey(QString device);
void requestPidCode(QString device);
+ void release();
void nearbyDeviceFound(int index);
void nearbyDeviceRemoved(int index);