created NearbyItem with icon property addition
[profile/ivi/bluetooth-qt.git] / asyncagent.cpp
1 /*  -*- Mode: C++ -*-
2  *
3  * meego handset bluetooth
4  * Copyright © 2010, Intel Corporation.
5  *
6  * This program is licensed under the terms and conditions of the
7  * Apache License, version 2.0.  The full text of the Apache License is at
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  */
11
12 #include "asyncagent.h"
13
14 AsyncAgent::AsyncAgent(QString path, QObject *parent) :
15                 BluetoothBaseAgent(path,parent), m_connection(QDBusConnection::systemBus())
16 {
17
18 }
19
20 void AsyncAgent::requestConfirmation(OrgBluezDeviceInterface &device, uint key)
21 {
22         qDebug("requestConfirmation");
23         setDelayedReply(true);
24         pendingMessage = message();
25         m_connection = connection();
26
27         QVariantMap props = device.GetProperties();
28
29         QString alias = props["Alias"].toString();
30
31         deviceToPair = new BluetoothDevice(QDBusObjectPath(device.path()),this);
32
33         QMetaObject::invokeMethod(parent(),"requestConfirmation",
34                                                           Qt::QueuedConnection, Q_ARG(QString, alias), Q_ARG(uint,key));
35
36         return;
37 }
38
39 uint AsyncAgent::requestPasskey(OrgBluezDeviceInterface &device)
40 {
41         qDebug("requestKey");
42         setDelayedReply(true);
43         pendingMessage = message();
44         m_connection = connection();
45
46         QVariantMap props = device.GetProperties();
47
48         QString alias = props["Alias"].toString();
49
50         deviceToPair = new BluetoothDevice(QDBusObjectPath(device.path()),this);
51
52         QMetaObject::invokeMethod(parent(), "requestPasskey", Qt::QueuedConnection, Q_ARG(QString, alias));
53
54         return 0;
55 }
56
57 QString AsyncAgent::requestPidCode(OrgBluezDeviceInterface &device)
58 {
59         qDebug("requestPidCode");
60         setDelayedReply(true);
61         pendingMessage = message();
62         m_connection = connection();
63
64         QVariantMap props = device.GetProperties();
65
66         QString alias = props["Alias"].toString();
67
68         deviceToPair = new BluetoothDevice(QDBusObjectPath(device.path()),this);
69
70         QMetaObject::invokeMethod(parent(), "requestPidCode", Qt::QueuedConnection, Q_ARG(QString, alias));
71
72         return "";
73 }
74
75 void AsyncAgent::release()
76 {
77         qDebug("releasing!");
78         if (!QMetaObject::invokeMethod(parent(), "release", Qt::QueuedConnection))
79                 qDebug("sending relay signal failed!!!");
80 }
81
82
83 void AsyncAgent::replyRequestConfirmation(bool confirmed)
84 {
85         if(!confirmed)
86         {
87                 qDebug("rejecting");
88                 QDBusMessage reply = pendingMessage.createErrorReply("org.bluez.Error.Rejected", "The request was rejected");
89                 m_connection.send(reply);
90         }
91         else
92         {
93                 qDebug("accepting");
94                 QDBusMessage reply = pendingMessage.createReply();
95                 m_connection.send(reply);
96         }
97 }
98
99 void AsyncAgent::replyPasskey(uint passkey)
100 {
101         QDBusMessage reply = pendingMessage.createReply(passkey);
102         m_connection.send(reply);
103 }
104
105 void AsyncAgent::replyRequestPidCode(QString pidCode)
106 {
107         QDBusMessage reply = pendingMessage.createReply(pidCode);
108         m_connection.send(reply);
109 }